avoid a lintian warning for using debhelper 9, meh…
[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
116 else
117 EXTRA_CFLAGS+=          -W
118 endif
119 EXTRA_CFLAGS+=          -Wno-unused-parameter -Wno-cast-qual
120 EXTRA_CFLAGS+=          -Wno-strict-prototypes
121 EXTRA_LDFLAGS=          -Wl,--as-needed
122
123 DEBHELPER_VERSION:=     11
124 DSF:=                   3.0 (quilt)
125 SUBST_EP:=              -e '/@PRIO@EXTRA@/d'
126 HOMEPAGE:=              http://www.mirbsd.org/jupp.htm
127 SUBST_HP:=              -e '/@HP@DOT@/d' -e '/@HP@OLD@/d' -e 's\ 1@HP@MODERN@\ 1${HOMEPAGE}\ 1'
128 SELINUX_DEP:=           libselinux1-dev [linux-any]
129 MENU_SUBST:=            cat
130
131 # wheezy, jessie, stretch
132 ifneq (,$(findstring wheezy,${DEB_BUILD_OPTIONS}))
133 DEBHELPER_VERSION:=     9
134 endif
135 # lenny, squeeze
136 ifneq (,$(findstring lenny,${DEB_BUILD_OPTIONS}))
137 DEBHELPER_VERSION:=     5
138 SELINUX_DEP:=           libselinux1-dev [!kfreebsd-i386 !kfreebsd-amd64 !hurd-i386]
139 endif
140 ifneq (,$(findstring lenny,${DEB_BUILD_OPTIONS})$(findstring sarge,${DEB_BUILD_OPTIONS}))
141 DSF:=                   1.0
142 SUBST_EP:=              -e 's/@PRIO@EXTRA@/Priority: extra/'
143 BREAKS:=                Conflicts
144 endif
145 # sarge, etch (although etch has debhelper 5)
146 ifneq (,$(findstring sarge,${DEB_BUILD_OPTIONS}))
147 DEBHELPER_VERSION:=     4
148 SELINUX_DEP:=           libselinux1-dev
149 SUBST_HP:=              -e '/@HP@MODERN@/d' -e '/^VCS-[gB][ir][to][:w]/d' \
150                         -e 's/@HP@DOT@//' -e 's\ 1@HP@OLD@\ 1${HOMEPAGE}\ 1'
151 MENU_SUBST:=            sed 's!"Applications/!"Apps/!'
152 endif
153
154 DSC_DEPS:=              debhelper (>= ${DEBHELPER_VERSION})
155 SUBST_VARS+=            DSC_DEPS
156
157 BREAKS:=                Breaks
158 SUBST_VARS+=            BREAKS
159
160 ifeq (${USE_LIBC},dietlibc)
161 DSC_DEPS:=              ${DSC_DEPS}, dietlibc-dev
162 USE_SHARED:=0
163 EXTRA_CFLAGS+=          -fno-stack-protector
164 endif
165
166 ifeq (${USE_LIBC},klibc)
167 DSC_DEPS:=              ${DSC_DEPS}, libklibc-dev
168 USE_FPU:=0
169 EXTRA_CFLAGS+=          -fno-stack-protector
170 ifeq (1,${USE_SHARED})
171 CC+=                    -shared
172 endif
173 endif
174
175 ifeq (${USE_LIBC},musl)
176 DSC_DEPS:=              ${DSC_DEPS}, musl-tools
177 EXTRA_CFLAGS+=          -Os
178 ifeq (0,${USE_SHARED})
179 EXTRA_LDFLAGS+=         -static
180 endif
181 CONFIGURE_ENV+=         ac_cv_header_sys_termios_h=no
182 endif
183
184 ifeq (${USE_LIBC},system)
185 ifeq (0,${USE_SHARED})
186 EXTRA_LDFLAGS+=         -static
187 endif
188 endif
189
190 ifneq (,$(findstring debug,${DEB_BUILD_OPTIONS}))
191 EXTRA_CFLAGS+=          -g3
192 endif
193
194 ifneq (,$(wildcard /usr/share/dpkg/buildflags.mk))
195 # dpkg-dev (>= 1.16.1~)
196 DEB_CFLAGS_MAINT_APPEND=${EXTRA_CFLAGS}
197 DEB_LDFLAGS_MAINT_APPEND=${EXTRA_LDFLAGS}
198 ifneq (${USE_LIBC},system)
199 DEB_CFLAGS_MAINT_STRIP=-O -O0 -O1 -O2 -O3 -Os -Ofast -Og -g -g1 -g2 -g3 -ggdb -gdwarf -gstabs
200 DEB_CFLAGS_MAINT_STRIP+=-specs=/usr/share/dpkg/no-pie-compile.specs
201 DEB_LDFLAGS_MAINT_STRIP+=-specs=/usr/share/dpkg/no-pie-link.specs
202 # do not use PIE with strange libcs
203 DEB_BUILD_MAINT_OPTIONS=hardening=+all,-pie
204 else
205 ifneq (,$(findstring static,${DEB_BUILD_OPTIONS}))
206 # cannot mix PIE with static linkage
207 DEB_BUILD_MAINT_OPTIONS=hardening=+all,-pie
208 else
209 DEB_BUILD_MAINT_OPTIONS=hardening=+all
210 endif
211 endif
212 include /usr/share/dpkg/buildflags.mk
213 else
214 # old-fashioned way to determine build flags
215 ifneq (${USE_LIBC},system)
216 CFLAGS=
217 else
218 CFLAGS=                 -O$(if $(findstring noopt,${DEB_BUILD_OPTIONS}),0,2) -g
219 endif
220 CFLAGS+=                ${EXTRA_CFLAGS}
221 LDFLAGS+=               ${EXTRA_LDFLAGS}
222 endif
223
224 ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
225 NUMJOBS=                $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
226 MAKEFLAGS+=             -j${NUMJOBS}
227 endif
228
229 CONFIGURE_ARGS=         --build=${DEB_BUILD_GNU_TYPE} \
230                         --host=${DEB_HOST_GNU_TYPE} \
231                         --prefix=/usr \
232                         --sysconfdir=/etc \
233                         --mandir=/usr/share/man \
234                         --disable-dependency-tracking
235
236 ifeq (0,${USE_PWNAM})
237 CONFIGURE_ARGS+=        --disable-getpwnam
238 endif
239
240 ifeq (0,${USE_FPU})
241 CONFIGURE_ARGS+=        --disable-fpu
242 endif
243
244 ifeq (0,${USE_MMU})
245 CONFIGURE_ARGS+=        --disable-fork
246 endif
247
248 ifeq (0,${USE_LIBS})
249 CONFIGURE_ARGS+=        --disable-search-libs \
250                         --disable-terminfo
251 else
252 DSC_DEPS:=              ${DSC_DEPS}, libtinfo-dev | libncurses-dev
253 endif
254
255 ifeq (1,${USE_SELINUX})
256 DSC_DEPS:=              ${DSC_DEPS}, $(strip ${SELINUX_DEP})
257 endif
258
259 ifeq (,$(findstring noautotools,${DEB_BUILD_OPTIONS}))
260 DSC_DEPS:=              ${DSC_DEPS}, autotools-dev
261 endif
262
263 CONFIGURE_ARGS+=        --disable-termidx \
264                         --enable-sysconfjoesubdir=/jupp
265
266 debian/.configure_stamp: debian/.control_stamp
267         dh_testdir
268         -rm -f debian/.*_stamp
269         -rm -rf builddir
270         # apply autotools-dev if it exists
271         for x in config.guess config.sub; do \
272                 test -e /usr/share/misc/$$x || continue; \
273                 rm -f $$x; \
274                 cp /usr/share/misc/$$x .; \
275         done
276         mkdir builddir
277         cd builddir && exec env ${CONFIGURE_ENV} \
278             $(foreach i,CC CFLAGS CPPFLAGS LDFLAGS,$(call shellexport,$i)) \
279             sh ../configure ${CONFIGURE_ARGS}
280         @:>$@
281
282 debian/.build_stamp: debian/.configure_stamp
283         dh_testdir
284         cd builddir && exec ${MAKE}
285         ln -f builddir/joe builddir/jupp
286         ln -f builddir/joe.1 builddir/jupp.1
287         @:>$@
288
289 debian/.control_stamp:
290         @(if test -e debian/control.in; then exit 0; else \
291                 echo 'dh_testdir: "debian/control.in" not found.' \
292                     Are you sure you are in the correct directory\?; \
293                 exit 1; \
294         fi)
295         @mkdir -p debian/source
296         echo '${DSF}' >debian/source/format
297         echo ${DEBHELPER_VERSION} >debian/compat
298         ${MENU_SUBST} <debian/joe-jupp.menu.in >debian/joe-jupp.menu
299         ${MENU_SUBST} <debian/jupp.menu.in >debian/jupp.menu
300         sed ${SUBST_EP} ${SUBST_HP} \
301             $(foreach v,${SUBST_VARS},-e 's\ 1@@'$(call shellescape,$v)'@@\ 1'$(call shellescape,$(strip ${$v}))'\ 1') \
302             <debian/control.in >debian/.gencontrol_stamp
303         : bail out if these differ: in those cases,
304         : retry the build, after regenerating debian/control
305         : with cp debian/.gencontrol_stamp debian/control
306         diff -Nu debian/control debian/.gencontrol_stamp
307         : you made it, no worries
308         @:>$@
309
310 build: build-arch build-indep
311 build-arch: debian/.build_stamp
312 build-indep: debian/.configure_stamp
313
314 clean: debian/.control_stamp
315         dh_testdir
316         -rm -f debian/.*_stamp
317         -rm -rf builddir
318         # unapply autotools-dev if it exists
319         for x in config.guess config.sub; do \
320                 test -e /usr/share/misc/$$x || continue; \
321                 rm -f $$x; \
322         done
323         dh_clean
324
325 binary-indep: build-indep
326         dh_testdir
327         dh_testroot
328         if test -x "$$(which dh_prep)"; then dh_prep -i; else dh_clean -i -k; fi
329         dh_installchangelogs -i -Njupp
330         dh_install -i
331         dh_installmenu -i
332         # will be replaced by links to jupp
333         rm -rf debian/joe-jupp/usr/share/doc/joe-jupp
334         dh_link -i
335         dh_fixperms -i
336         dh_installdeb -i
337         dh_gencontrol -i
338         dh_md5sums -i
339         dh_builddeb -i
340
341 # no -Njupp because that's the only arch:any package
342 binary-arch: build-arch
343         dh_testdir
344         dh_testroot
345         if test -x "$$(which dh_prep)"; then dh_prep -a; else dh_clean -a -k; fi
346         dh_installchangelogs -pjupp -k NEWS
347         dh_installdocs -a
348         dh_install -a
349         dh_installmenu -a
350         dh_installman -a
351         dh_link -a
352         dh_strip -a
353         dh_compress -a
354         dh_fixperms -a
355         dh_installdeb -a
356         dh_shlibdeps -a
357         dh_gencontrol -a
358         dh_md5sums -a
359         dh_builddeb -a
360
361 binary: binary-arch binary-indep
362
363 .PHONY: binary binary-arch binary-indep build build-arch build-indep clean
364
365 ifneq (,$(strip ${___DISPLAY_MAKEVARS}))
366 $(foreach var,${___DISPLAY_MAKEVARS},$(info $(strip ${var})=${$(strip ${var})}))
367 $(error ___DISPLAY_MAKEVARS finished for ${___DISPLAY_MAKEVARS})
368 endif
369
370 # useful combinations to test:
371 # DEB_BUILD_OPTIONS= debian/rules debian/.control_stamp
372 # DEB_BUILD_OPTIONS='diet' debian/rules debian/.control_stamp
373 # DEB_BUILD_OPTIONS='klibc' debian/rules debian/.control_stamp
374 # DEB_BUILD_OPTIONS='musl' debian/rules debian/.control_stamp
375 # DEB_BUILD_OPTIONS='static nopwnam' debian/rules debian/.control_stamp
376 # DEB_BUILD_OPTIONS='static nopwnam nolibs' debian/rules debian/.control_stamp
377 # DEB_BUILD_OPTIONS='nommu nolibs' debian/rules debian/.control_stamp
378 # DEB_BUILD_OPTIONS='nofpu nommu nolibs' debian/rules debian/.control_stamp
379 # DEB_BUILD_OPTIONS='lenny' debian/rules debian/.control_stamp
380 # DEB_BUILD_OPTIONS='lenny diet' debian/rules debian/.control_stamp
381 # DEB_BUILD_OPTIONS='sarge' debian/rules debian/.control_stamp