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