shut musl know-it-all up
[alioth/jupp.git] / debian / rules
1 #!/usr/bin/make -f
2 #-
3 # Possible flavourisation in DEB_BUILD_OPTIONS (in addition
4 # to stock Debian rules):
5 # - static (use with system libc; default for all others)
6 # - shared (use with klibc or musl)
7 # - diet, klibc, musl
8 # - debug (adds -g3)
9 # - nopwnam (aids static linkage)
10 # - nofpu (default with klibc)
11 # - nommu
12 # - nolibs (use with system libc; default for all others)
13 # - noautotools (on systems lacking autotools-dev)
14 # - noselinux
15 # The 'nostrip' and 'parallel=n' options are supported as well.
16 #
17 # Using a non-system libc disables -O0/-O2 and -g and, if unset,
18 # sets CC. Cross-compiling also sets CC if unset.
19 #
20 # Statically linking violates the Policy requirement of having a
21 # Built-Using header, but since that is only used in local rebuilds
22 # and not in the Debian archive, it constitutes no Policy violation.
23
24 shellescape='$(subst ','\'',$(1))'
25 shellexport=$(1)=$(call shellescape,${$(1)})
26
27 USE_LIBC:=
28 ifneq (,$(findstring diet,${DEB_BUILD_OPTIONS}))
29 USE_LIBC+=      dietlibc
30 endif
31 ifneq (,$(findstring klibc,${DEB_BUILD_OPTIONS}))
32 USE_LIBC+=      klibc
33 endif
34 ifneq (,$(findstring musl,${DEB_BUILD_OPTIONS}))
35 USE_LIBC+=      musl
36 endif
37 ifeq (,$(findstring diet,${DEB_BUILD_OPTIONS})$(findstring klibc,${DEB_BUILD_OPTIONS})$(findstring musl,${DEB_BUILD_OPTIONS}))
38 USE_LIBC+=      system
39 endif
40 ifneq ($(strip ${USE_LIBC}),$(firstword ${USE_LIBC}))
41 $(error multiple libcs (${USE_LIBC}) found in (${DEB_BUILD_OPTIONS}))
42 endif
43 USE_LIBC:=$(strip ${USE_LIBC})
44
45 ifeq (${USE_LIBC},system)
46 USE_SHARED:=1
47 USE_LIBS:=1
48 else
49 USE_SHARED:=0
50 USE_LIBS:=0
51 endif
52
53 ifneq (,$(findstring shared,${DEB_BUILD_OPTIONS}))
54 USE_SHARED:=1
55 endif
56 ifneq (,$(findstring static,${DEB_BUILD_OPTIONS}))
57 USE_SHARED:=0
58 endif
59
60 USE_PWNAM:=1
61 ifneq (,$(findstring nopwnam,${DEB_BUILD_OPTIONS}))
62 USE_PWNAM:=0
63 endif
64
65 USE_FPU:=1
66 ifneq (,$(findstring nofpu,${DEB_BUILD_OPTIONS}))
67 USE_FPU:=0
68 endif
69
70 USE_MMU:=1
71 ifneq (,$(findstring nommu,${DEB_BUILD_OPTIONS}))
72 USE_MMU:=0
73 endif
74
75 ifneq (,$(findstring nolibs,${DEB_BUILD_OPTIONS}))
76 USE_LIBS:=0
77 endif
78
79 USE_SELINUX:=1
80 ifneq (,$(findstring noselinux,${DEB_BUILD_OPTIONS}))
81 USE_SELINUX:=0
82 endif
83 ifeq (0,${USE_LIBS})
84 USE_SELINUX:=0
85 endif
86
87 DEB_BUILD_ARCH?=$(shell dpkg-architecture -qDEB_BUILD_ARCH)
88 DEB_BUILD_GNU_TYPE?=$(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
89 DEB_HOST_ARCH?=$(shell dpkg-architecture -qDEB_HOST_ARCH)
90 DEB_HOST_GNU_TYPE?=$(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
91
92 # is ${CC} defined anywhere (other than implicit rules?)
93 ifneq (,$(findstring $(origin CC),default undefined))
94 # no - then default to gcc (or cross-gcc)
95 ifneq (${DEB_BUILD_ARCH},${DEB_HOST_ARCH})
96 CC=                     ${DEB_HOST_GNU_TYPE}-gcc
97 else
98 ifeq (${USE_LIBC},dietlibc)
99 CC=                     diet -Os gcc
100 endif
101 ifeq (${USE_LIBC},klibc)
102 CC=                     klcc
103 endif
104 ifeq (${USE_LIBC},musl)
105 CC=                     musl-gcc
106 endif
107 CC?=                    gcc
108 endif
109 endif
110
111 EXTRA_CFLAGS+=          -Wall -Wformat
112 EXTRA_CFLAGS+=          -fno-omit-frame-pointer -fno-strict-aliasing
113 ifeq (,$(findstring sarge,${DEB_BUILD_OPTIONS}))
114 EXTRA_CFLAGS+=          -fwrapv
115 EXTRA_CFLAGS+=          -Wextra -Wno-pointer-sign -Wno-old-style-definition
116 else
117 EXTRA_CFLAGS+=          -W
118 endif
119 EXTRA_CFLAGS+=          -Wno-unused-parameter -Wno-strict-prototypes \
120                         -Wno-cast-qual \
121                         -Wno-missing-prototypes -Wno-missing-declarations
122 EXTRA_LDFLAGS=          -Wl,--as-needed
123
124 DEBHELPER_VERSION:=     9
125 DSF:=                   3.0 (quilt)
126 SUBST_EP:=              -e '/@PRIO@EXTRA@/d'
127 HOMEPAGE:=              https://www.mirbsd.org/jupp.htm
128 SUBST_HP:=              -e '/@HP@DOT@/d' -e '/@HP@OLD@/d' -e 's\ 1@HP@MODERN@\ 1${HOMEPAGE}\ 1'
129 SELINUX_DEP:=           libselinux1-dev [linux-any]
130 MENU_SUBST:=            cat
131
132 ifneq (,$(findstring lenny,${DEB_BUILD_OPTIONS}))
133 DEBHELPER_VERSION:=     5
134 SELINUX_DEP:=           libselinux1-dev [!kfreebsd-i386 !kfreebsd-amd64 !hurd-i386]
135 endif
136 ifneq (,$(findstring lenny,${DEB_BUILD_OPTIONS})$(findstring sarge,${DEB_BUILD_OPTIONS}))
137 DSF:=                   1.0
138 SUBST_EP:=              -e 's/@PRIO@EXTRA@/Priority: extra/'
139 BREAKS:=                Conflicts
140 endif
141 ifneq (,$(findstring sarge,${DEB_BUILD_OPTIONS}))
142 DEBHELPER_VERSION:=     4
143 SELINUX_DEP:=           libselinux1-dev
144 SUBST_HP:=              -e '/@HP@MODERN@/d' -e '/^VCS-[gB][ir][to][:w]/d' \
145                         -e 's/@HP@DOT@//' -e 's\ 1@HP@OLD@\ 1${HOMEPAGE}\ 1'
146 MENU_SUBST:=            sed 's!"Applications/!"Apps/!'
147 endif
148
149 DSC_DEPS:=              debhelper (>= ${DEBHELPER_VERSION})
150 SUBST_VARS+=            DSC_DEPS
151
152 BREAKS:=                Breaks
153 SUBST_VARS+=            BREAKS
154
155 ifeq (${USE_LIBC},dietlibc)
156 DSC_DEPS:=              ${DSC_DEPS}, dietlibc-dev
157 USE_SHARED:=0
158 EXTRA_CFLAGS+=          -fno-stack-protector
159 endif
160
161 ifeq (${USE_LIBC},klibc)
162 DSC_DEPS:=              ${DSC_DEPS}, libklibc-dev
163 USE_FPU:=0
164 EXTRA_CFLAGS+=          -fno-stack-protector
165 ifeq (1,${USE_SHARED})
166 CC+=                    -shared
167 endif
168 endif
169
170 ifeq (${USE_LIBC},musl)
171 DSC_DEPS:=              ${DSC_DEPS}, musl-tools
172 EXTRA_CFLAGS+=          -Os
173 ifeq (0,${USE_SHARED})
174 EXTRA_LDFLAGS+=         -static
175 endif
176 CONFIGURE_ENV+=         ac_cv_header_sys_termios_h=no
177 endif
178
179 ifeq (${USE_LIBC},system)
180 ifeq (0,${USE_SHARED})
181 EXTRA_LDFLAGS+=         -static
182 endif
183 endif
184
185 ifneq (,$(findstring debug,${DEB_BUILD_OPTIONS}))
186 EXTRA_CFLAGS+=          -g3
187 endif
188
189 ifneq (,$(wildcard /usr/share/dpkg/buildflags.mk))
190 # dpkg-dev (>= 1.16.1~)
191 DEB_CFLAGS_MAINT_APPEND=${EXTRA_CFLAGS}
192 DEB_LDFLAGS_MAINT_APPEND=${EXTRA_LDFLAGS}
193 ifneq (${USE_LIBC},system)
194 DEB_CFLAGS_MAINT_STRIP=-O -O0 -O1 -O2 -O3 -Os -Ofast -Og -g -g1 -g2 -g3 -ggdb -gdwarf -gstabs
195 DEB_CFLAGS_MAINT_STRIP+=-specs=/usr/share/dpkg/no-pie-compile.specs
196 DEB_LDFLAGS_MAINT_STRIP+=-specs=/usr/share/dpkg/no-pie-link.specs
197 # do not use PIE with strange libcs
198 DEB_BUILD_MAINT_OPTIONS=hardening=+all,-pie
199 else
200 ifneq (,$(findstring static,${DEB_BUILD_OPTIONS}))
201 # cannot mix PIE with static linkage
202 DEB_BUILD_MAINT_OPTIONS=hardening=+all,-pie
203 else
204 DEB_BUILD_MAINT_OPTIONS=hardening=+all
205 endif
206 endif
207 include /usr/share/dpkg/buildflags.mk
208 else
209 # old-fashioned way to determine build flags
210 ifneq (${USE_LIBC},system)
211 CFLAGS=
212 else
213 CFLAGS=                 -O$(if $(findstring noopt,${DEB_BUILD_OPTIONS}),0,2) -g
214 endif
215 CFLAGS+=                ${EXTRA_CFLAGS}
216 LDFLAGS+=               ${EXTRA_LDFLAGS}
217 endif
218
219 ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
220 NUMJOBS=                $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
221 MAKEFLAGS+=             -j${NUMJOBS}
222 endif
223
224 CONFIGURE_ARGS=         --build=${DEB_BUILD_GNU_TYPE} \
225                         --host=${DEB_HOST_GNU_TYPE} \
226                         --prefix=/usr \
227                         --sysconfdir=/etc \
228                         --mandir=/usr/share/man \
229                         --disable-dependency-tracking
230
231 ifeq (0,${USE_PWNAM})
232 CONFIGURE_ARGS+=        --disable-getpwnam
233 endif
234
235 ifeq (0,${USE_FPU})
236 CONFIGURE_ARGS+=        --disable-fpu
237 endif
238
239 ifeq (0,${USE_MMU})
240 CONFIGURE_ARGS+=        --disable-fork
241 endif
242
243 ifeq (0,${USE_LIBS})
244 CONFIGURE_ARGS+=        --disable-search-libs \
245                         --disable-terminfo
246 else
247 DSC_DEPS:=              ${DSC_DEPS}, libtinfo-dev | libncurses-dev
248 endif
249
250 ifeq (1,${USE_SELINUX})
251 DSC_DEPS:=              ${DSC_DEPS}, $(strip ${SELINUX_DEP})
252 endif
253
254 ifeq (,$(findstring noautotools,${DEB_BUILD_OPTIONS}))
255 DSC_DEPS:=              ${DSC_DEPS}, autotools-dev
256 endif
257
258 CONFIGURE_ARGS+=        --disable-termidx \
259                         --enable-sysconfjoesubdir=/jupp
260
261 debian/.configure_stamp: debian/.control_stamp
262         dh_testdir
263         -rm -f debian/.*_stamp
264         -rm -rf builddir
265         # apply autotools-dev if it exists
266         for x in config.guess config.sub; do \
267                 test -e /usr/share/misc/$$x || continue; \
268                 rm -f $$x; \
269                 cp /usr/share/misc/$$x .; \
270         done
271         mkdir builddir
272         cd builddir && exec env ${CONFIGURE_ENV} \
273             $(foreach i,CC CFLAGS CPPFLAGS LDFLAGS,$(call shellexport,$i)) \
274             sh ../configure ${CONFIGURE_ARGS}
275         @:>$@
276
277 debian/.build_stamp: debian/.configure_stamp
278         dh_testdir
279         cd builddir && exec ${MAKE}
280         ln -f builddir/joe builddir/jupp
281         ln -f builddir/joe.1 builddir/jupp.1
282         @:>$@
283
284 debian/.control_stamp:
285         @(if test -e debian/control.in; then exit 0; else \
286                 echo 'dh_testdir: "debian/control.in" not found.' \
287                     Are you sure you are in the correct directory\?; \
288                 exit 1; \
289         fi)
290         @mkdir -p debian/source
291         echo '${DSF}' >debian/source/format
292         echo ${DEBHELPER_VERSION} >debian/compat
293         ${MENU_SUBST} <debian/joe-jupp.menu.in >debian/joe-jupp.menu
294         ${MENU_SUBST} <debian/jupp.menu.in >debian/jupp.menu
295         sed ${SUBST_EP} ${SUBST_HP} \
296             $(foreach v,${SUBST_VARS},-e 's\ 1@@'$(call shellescape,$v)'@@\ 1'$(call shellescape,$(strip ${$v}))'\ 1') \
297             <debian/control.in >debian/.gencontrol_stamp
298         : bail out if these differ: in those cases,
299         : retry the build, after regenerating debian/control
300         : with cp debian/.gencontrol_stamp debian/control
301         diff -Nu debian/control debian/.gencontrol_stamp
302         : you made it, no worries
303         @:>$@
304
305 build: build-arch build-indep
306 build-arch: debian/.build_stamp
307 build-indep: debian/.configure_stamp
308
309 clean: debian/.control_stamp
310         dh_testdir
311         -rm -f debian/.*_stamp
312         -rm -rf builddir
313         # unapply autotools-dev if it exists
314         for x in config.guess config.sub; do \
315                 test -e /usr/share/misc/$$x || continue; \
316                 rm -f $$x; \
317         done
318         dh_clean
319
320 binary-indep: build-indep
321         dh_testdir
322         dh_testroot
323         if test -x "$$(which dh_prep)"; then dh_prep -i; else dh_clean -i -k; fi
324         dh_installchangelogs -i -Njupp
325         dh_install -i
326         dh_installmenu -i
327         # will be replaced by links to jupp
328         rm -rf debian/joe-jupp/usr/share/doc/joe-jupp
329         dh_link -i
330         dh_fixperms -i
331         dh_installdeb -i
332         dh_gencontrol -i
333         dh_md5sums -i
334         dh_builddeb -i
335
336 # no -Njupp because that's the only arch:any package
337 binary-arch: build-arch
338         dh_testdir
339         dh_testroot
340         if test -x "$$(which dh_prep)"; then dh_prep -a; else dh_clean -a -k; fi
341         dh_installchangelogs -pjupp -k NEWS
342         dh_installdocs -a
343         dh_install -a
344         dh_installmenu -a
345         dh_installman -a
346         dh_link -a
347         dh_strip -a
348         dh_compress -a
349         dh_fixperms -a
350         dh_installdeb -a
351         dh_shlibdeps -a
352         dh_gencontrol -a
353         dh_md5sums -a
354         dh_builddeb -a
355
356 binary: binary-arch binary-indep
357
358 .PHONY: binary binary-arch binary-indep build build-arch build-indep clean
359
360 ifneq (,$(strip ${___DISPLAY_MAKEVARS}))
361 $(foreach var,${___DISPLAY_MAKEVARS},$(info $(strip ${var})=${$(strip ${var})}))
362 $(error ___DISPLAY_MAKEVARS finished for ${___DISPLAY_MAKEVARS})
363 endif
364
365 # useful combinations to test:
366 # DEB_BUILD_OPTIONS= debian/rules debian/.control_stamp
367 # DEB_BUILD_OPTIONS='diet' debian/rules debian/.control_stamp
368 # DEB_BUILD_OPTIONS='klibc' debian/rules debian/.control_stamp
369 # DEB_BUILD_OPTIONS='musl' debian/rules debian/.control_stamp
370 # DEB_BUILD_OPTIONS='static nopwnam' debian/rules debian/.control_stamp
371 # DEB_BUILD_OPTIONS='static nopwnam nolibs' debian/rules debian/.control_stamp
372 # DEB_BUILD_OPTIONS='nommu nolibs' debian/rules debian/.control_stamp
373 # DEB_BUILD_OPTIONS='nofpu nommu nolibs' debian/rules debian/.control_stamp
374 # DEB_BUILD_OPTIONS='lenny' debian/rules debian/.control_stamp
375 # DEB_BUILD_OPTIONS='lenny diet' debian/rules debian/.control_stamp
376 # DEB_BUILD_OPTIONS='sarge' debian/rules debian/.control_stamp