summaryrefslogtreecommitdiff
path: root/debian/config.debian
blob: c425499abdac90f5d93d35d03b3b16ab25935661 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#!/bin/bash

eval $(echo '#include "./patchlevel.h"
SETver=PERL_REVISION.PERL_VERSION;
SETsubver= PERL_SUBVERSION' | gcc -E -DPERL_PATCHLEVEL_H_IMPLICIT - \
 | sed -n '/^SET/{s///;s/ //gp;}')

fullver="$ver.$subver"
nextver="$ver."$(($subver+1))
ccflags=-DDEBIAN
ldflags=
host_arch=${DEB_HOST_ARCH:-$(dpkg-architecture -qDEB_HOST_ARCH)}
host_arch_cpu=${DEB_HOST_ARCH_CPU:-$(dpkg-architecture -qDEB_HOST_ARCH_CPU)}
host_gnu_type=${DEB_HOST_GNU_TYPE:-$(dpkg-architecture -qDEB_HOST_GNU_TYPE)}
build_gnu_type=${DEB_BUILD_GNU_TYPE:-$(dpkg-architecture -qDEB_BUILD_GNU_TYPE)}
optimize=-O2
debugging=-g

archtriplet=${DEB_HOST_MULTIARCH:-$(dpkg-architecture -qDEB_HOST_MULTIARCH)}

# this goes in config.h to make perl -V output reproducible
PERL_BUILD_DATE=$(LC_ALL=C date '+%b %e %Y %T' --utc -d "$(dpkg-parsechangelog | sed -n -e 's/^Date: //p')")

case "$1" in
    --static) # static perl
    	build_type=static
	opts="-Uuseshrplib -Dotherlibdirs=\"/usr/lib/$archtriplet/perl-base\"";;

    --debug) # debugperl
    	build_type=debug
	debugging=both # add -DDEBUGGING
	opts="-Uuseshrplib";;

    --shared) # shared library
    	build_type=shared
	opts="-Duseshrplib -Dlibperl=libperl.so.$fullver";;

    --version)
	exec echo $ver;;

    --full-version)
	exec echo $fullver;;

    --next-version)
	exec echo $nextver;;

    *)	echo "$0: need --shared, --static, or --debug option"
    	exit 2;;
esac

case "$host_arch_cpu:$build_type" in
    sh4:*) # required to correctly handle floating point on sh4
    	ccflags="$ccflags -mieee";;

    m68k:shared) # work around an optimiser bug
	ccflags="$ccflags -fno-regmove";;
esac

case ",$DEB_BUILD_OPTIONS," in
    *[,\ ]noopt[,\ ]*)
	optimize="$optimize${optimize:+ }-O0";;
esac

cc=${CC:-${host_gnu_type}-gcc}
cpp=${CPP:-${host_gnu_type}-cpp}
ld=${LD:-${host_gnu_type}-gcc}

if which dpkg-buildflags >/dev/null 2>&1; then
    ccflags="$ccflags $(dpkg-buildflags --get CPPFLAGS)"
    ccflags="$ccflags $(dpkg-buildflags --get CFLAGS)"
    ldflags="$ldflags $(dpkg-buildflags --get LDFLAGS)"
fi

mkdir build-$build_type
cd build-$build_type

# post-configure tweaks
cp ../debian/config.over .

if [ "$build_gnu_type" = "$host_gnu_type" ]
then
    # native builds
    # need bash when sourcing config.over
    eval /bin/bash ../Configure			\
    -Dmksymlinks                \
    -Dusethreads				\
    -Duselargefiles				\
    -Dcc=$cc					\
    -Dcpp=$cpp					\
    -Dld=$ld					\
    -Dccflags=\'$ccflags\'			\
    -Dldflags=\'$ldflags\'			\
    -Dlddlflags=\'-shared $ldflags\'			\
    -Dcccdlflags=-fPIC				\
    -Darchname=$host_gnu_type			\
    -Dprefix=/usr				\
    -Dprivlib=/usr/share/perl/$ver		\
    -Darchlib=/usr/lib/$archtriplet/perl/$ver		\
    -Dvendorprefix=/usr				\
    -Dvendorlib=/usr/share/perl5		\
    -Dvendorarch=/usr/lib/$archtriplet/perl5/$ver			\
    -Dsiteprefix=/usr/local			\
    -Dsitelib=/usr/local/share/perl/$fullver	\
    -Dsitearch=/usr/local/lib/$archtriplet/perl/$fullver	\
    -Dman1dir=/usr/share/man/man1		\
    -Dman3dir=/usr/share/man/man3		\
    -Dsiteman1dir=/usr/local/man/man1		\
    -Dsiteman3dir=/usr/local/man/man3		\
    -Duse64bitint                               \
    -Dman1ext=1					\
    -Dman3ext=3perl				\
    -Dpager=/usr/bin/sensible-pager		\
    -Uafs					\
    -Ud_csh					\
    -Ud_ualarm					\
    -Uusesfio					\
    -Uusenm					\
    -Ui_libutil					\
    -Ui_xlocale					\
    -Uversiononly \
    -DDEBUGGING=$debugging			\
    -Doptimize=\"$optimize\"			\
    $extra_path					\
    -dEs $opts

	# note about the debian/cross files for the build log
	crossconfig=../debian/cross/${host_arch}/config.sh.static
	if [ "$build_type" = "static" ]; then
	 if [ -f $crossconfig ]; then
	  if ! diff --ignore-matching-lines="cf_time" \
	          --ignore-matching-lines="Configuration time" \
	          --ignore-matching-lines="Extracted from Debian package" \
	          $crossconfig config.sh >/dev/null
	  then
	    echo "Note: source package config.sh for cross building differs from generated one"
	    echo "Note: consider refreshing with debian/cross/extract-config-sh after the build"
	    diff -u0 $crossconfig config.sh | head -100
	    echo --------------------------------------------------
	  else
	    echo "Note: source package config.sh for cross building is up to date with the generated one (good!)"
	  fi
	 else
	    echo "Note: no source package config.sh for cross building"
	    echo "Note: consider including it with debian/cross/extract-config-sh after the build"
	 fi
	fi

    # for the Configure -S call below
    crossargs=
else
	# cross builds

	# find a ready made config.sh, currently in debian/cross/<arch>
	basedir=../debian/cross/${host_arch}
	baseconfig=${basedir}/config.sh.static
	if [ ! -f $baseconfig ]; then
	    echo "need $baseconfig for cross build!" 1>&2
	    exit 1
	fi

	# check for a new upstream version, invalidating old config.sh files
	crossversion=$(sed -n "s/^version='\(.*\)'/\1/ p" $baseconfig)
	if [ "$fullver" != "$crossversion" ]; then
	    echo "Fatal: need $baseconfig for cross build but it needs refreshing from $crossversion to $fullver!" 1>&2
	    echo "To fix: make a native build and run debian/cross/extract-config-sh on the results" 1>&2
	    echo "        (or fix $baseconfig by hand)" 1>&2
	    exit 1
	fi

	# arch-specific REFRESH files can be used to invalidate the old config.sh
	# files regardless of the version
	#   there can be a comment inside the REFRESH file
	#   example use case: changed Configure parameters
	if [ -e $basedir/REFRESH ]; then
	    echo "Fatal: need $baseconfig for cross build but it needs refreshing!" 1>&2
	    cat $basedir/REFRESH 1>&2
	    echo "To fix: make a native build and run debian/cross/extract-config-sh on the results" 1>&2
	    echo "        (or fix $baseconfig by hand)" 1>&2
	    echo "Then remove $basedir/REFRESH" 1>&2
	    exit 1
	fi

	# Next, ask Configure to compile a build system miniperl and
	# generate_uudmap executable in host/
	#
	# It's tempting to use the system perl for this, but that fails
	# when building extensions because it tries to dynamically load
	# XS modules from lib/, particularly as <*> uses File::Glob on
	# full perls (but not miniperl)
	if [ ! -x ../build-miniperl ]; then
	    echo "Cross build: making a native miniperl for the build process"
	    cd ..
	    ./Configure -dE -Dusecrosscompile
	    # host/ gets cleaned between builds by 'make distclean', so
	    # stash the results
	    cp host/miniperl build-miniperl
	    cp host/generate_uudmap build-generate_uudmap
	    cd build-$build_type
	fi

	# create symlinks for build directory
	# we can't seem to make Configure create these symlinks without probing
	# so make a separate mksymlinks helper for now
	sed '/^\?/d' ../regen-configure/U/perl/Mksymlinks.U > ../mksymlinks
	src=$(pwd)/..
	mkdir UU
	cd UU
	src="$src" lns="ln -s" issymlink="test -h" bash ../../mksymlinks 4>&2
	cd ..

	# override configuration for cross building

	# Actually use the old config.sh files,
	# removing the absolute build path in 'src'
	sed 's/^src=.*/src=./' $baseconfig > ./config.sh

	if [ "$build_type" = "static" ]; then
		# notes for the build log
		echo "Cross build: recycling old probed configuration from $baseconfig"
		grep '^cf_time' $baseconfig
		md5sum $baseconfig
		# debian/cross/extract-config-sh appends a comment so show that
		grep "Extracted from Debian package version" $baseconfig
	else
		patchconfig=${basedir}/config.sh.$build_type.patch
		if [ ! -f "$patchconfig" ]; then
			echo "need $patchconfig for cross build!" 1>&2
			exit 1
		fi
		patch config.sh < $patchconfig
		echo "Cross build: recycling old probed configuration from $patchconfig"
		md5sum $patchconfig
	fi

	crossargs="-Dusecrosscompile \
               -Dhostgenerate=../build-generate_uudmap \
               -Dhostperl=../build-miniperl \
               -Dperl=/usr/bin/perl"
fi

# now continue with extracting Makefile et al.
/bin/bash ./Configure -S $crossargs

# append PERL_BUILD_DATE before the last #endif in config.h
# massive quoting problems prevent passing this to Configure
sed -i "\$i #define PERL_BUILD_DATE \"$PERL_BUILD_DATE\"" config.h