354f9fb7da4b40362643afe2891a0c6ccd14a70d
[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 -fwrapv -fno-strict-aliasing
113 # adjust when backporting
114 EXTRA_CFLAGS+=          -Wextra -Wno-pointer-sign -Wno-unused-parameter \
115                         -Wno-old-style-definition -Wno-strict-prototypes \
116                         -Wno-cast-qual \
117                         -Wno-missing-prototypes -Wno-missing-declarations
118 EXTRA_LDFLAGS=          -Wl,--as-needed
119
120 # 5 is enough
121 DEBHELPER_VERSION:=     9
122 DSC_DEPS:=              debhelper (>= ${DEBHELPER_VERSION})
123
124 ifeq (${USE_LIBC},dietlibc)
125 DSC_DEPS:=              ${DSC_DEPS}, dietlibc-dev
126 USE_SHARED:=0
127 EXTRA_CFLAGS+=          -fno-stack-protector
128 endif
129
130 ifeq (${USE_LIBC},klibc)
131 DSC_DEPS:=              ${DSC_DEPS}, libklibc-dev
132 USE_FPU:=0
133 EXTRA_CFLAGS+=          -fno-stack-protector
134 ifeq (1,${USE_SHARED})
135 CC+=                    -shared
136 endif
137 endif
138
139 ifeq (${USE_LIBC},musl)
140 DSC_DEPS:=              ${DSC_DEPS}, musl-tools
141 EXTRA_CFLAGS+=          -Os
142 ifeq (0,${USE_SHARED})
143 EXTRA_LDFLAGS+=         -static
144 endif
145 endif
146
147 ifeq (${USE_LIBC},system)
148 ifeq (0,${USE_SHARED})
149 EXTRA_LDFLAGS+=         -static
150 endif
151 endif
152
153 ifneq (,$(findstring debug,${DEB_BUILD_OPTIONS}))
154 EXTRA_CFLAGS+=          -g3
155 endif
156
157 ifneq (,$(wildcard /usr/share/dpkg/buildflags.mk))
158 # dpkg-dev (>= 1.16.1~)
159 DEB_CFLAGS_MAINT_APPEND=${EXTRA_CFLAGS}
160 DEB_LDFLAGS_MAINT_APPEND=${EXTRA_LDFLAGS}
161 ifneq (${USE_LIBC},system)
162 DEB_CFLAGS_MAINT_STRIP=-O -O0 -O1 -O2 -O3 -Os -Ofast -Og -g -g1 -g2 -g3 -ggdb -gdwarf -gstabs
163 DEB_CFLAGS_MAINT_STRIP+=-specs=/usr/share/dpkg/no-pie-compile.specs
164 DEB_LDFLAGS_MAINT_STRIP+=-specs=/usr/share/dpkg/no-pie-link.specs
165 # do not use PIE with strange libcs
166 DEB_BUILD_MAINT_OPTIONS=hardening=+all,-pie
167 else
168 ifneq (,$(findstring static,${DEB_BUILD_OPTIONS}))
169 # cannot mix PIE with static linkage
170 DEB_BUILD_MAINT_OPTIONS=hardening=+all,-pie
171 else
172 DEB_BUILD_MAINT_OPTIONS=hardening=+all
173 endif
174 endif
175 include /usr/share/dpkg/buildflags.mk
176 else
177 # old-fashioned way to determine build flags
178 ifneq (${USE_LIBC},system)
179 CFLAGS=
180 else
181 CFLAGS=                 -O$(if $(findstring noopt,${DEB_BUILD_OPTIONS}),0,2) -g
182 endif
183 CFLAGS+=                ${EXTRA_CFLAGS}
184 LDFLAGS+=               ${EXTRA_LDFLAGS}
185 endif
186
187 ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
188 NUMJOBS=                $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
189 MAKEFLAGS+=             -j${NUMJOBS}
190 endif
191
192 CONFIGURE_ARGS=         --build=${DEB_BUILD_GNU_TYPE} \
193                         --host=${DEB_HOST_GNU_TYPE} \
194                         --prefix=/usr \
195                         --sysconfdir=/etc \
196                         --mandir=/usr/share/man \
197                         --disable-dependency-tracking
198
199 ifeq (0,${USE_PWNAM})
200 CONFIGURE_ARGS+=        --disable-getpwnam
201 endif
202
203 ifeq (0,${USE_FPU})
204 CONFIGURE_ARGS+=        --disable-fpu
205 endif
206
207 ifeq (0,${USE_MMU})
208 CONFIGURE_ARGS+=        --disable-fork
209 endif
210
211 ifeq (0,${USE_LIBS})
212 CONFIGURE_ARGS+=        --disable-search-libs \
213                         --disable-terminfo
214 else
215 DSC_DEPS:=              ${DSC_DEPS}, libtinfo-dev | libncurses-dev
216 endif
217
218 ifeq (1,${USE_SELINUX})
219 #DSC_DEPS:=             ${DSC_DEPS}, libselinux1-dev [!kfreebsd-i386 !kfreebsd-amd64 !hurd-i386]
220 DSC_DEPS:=              ${DSC_DEPS}, libselinux1-dev [linux-any]
221 endif
222
223 ifeq (,$(findstring noautotools,${DEB_BUILD_OPTIONS}))
224 DSC_DEPS:=              ${DSC_DEPS}, autotools-dev
225 endif
226
227 CONFIGURE_ARGS+=        --disable-termidx \
228                         --enable-sysconfjoesubdir=/jupp
229
230 debian/.configure_stamp: debian/.control_stamp
231         dh_testdir
232         -rm -f debian/.*_stamp
233         -rm -rf builddir
234         # apply autotools-dev if it exists
235         for x in config.guess config.sub; do \
236                 test -e /usr/share/misc/$$x || continue; \
237                 rm -f $$x; \
238                 cp /usr/share/misc/$$x .; \
239         done
240         mkdir builddir
241         cd builddir && exec env \
242             $(foreach i,CC CFLAGS CPPFLAGS LDFLAGS,$(call shellexport,$i)) \
243             sh ../configure ${CONFIGURE_ARGS}
244         @:>$@
245
246 debian/.build_stamp: debian/.configure_stamp
247         dh_testdir
248         cd builddir && exec ${MAKE}
249         ln -f builddir/joe builddir/jupp
250         ln -f builddir/joe.1 builddir/jupp.1
251         @:>$@
252
253 debian/.control_stamp:
254         @(if test -e debian/control.in; then exit 0; else \
255                 echo 'dh_testdir: "debian/control.in" not found.' \
256                     Are you sure you are in the correct directory\?; \
257                 exit 1; \
258         fi)
259         echo ${DEBHELPER_VERSION} >debian/compat
260         sed -e 's\ 1@@DEPS@@\ 1$(strip ${DSC_DEPS})\ 1' \
261             <debian/control.in >debian/.gencontrol_stamp
262         : bail out if these differ: in those cases,
263         : you are to regenerate debian/control and retry
264         diff -Nu debian/control debian/.gencontrol_stamp
265         @:>$@
266
267 build: build-arch build-indep
268 build-arch: debian/.build_stamp
269 build-indep: debian/.configure_stamp
270
271 clean: debian/.control_stamp
272         dh_testdir
273         -rm -f debian/.*_stamp
274         -rm -rf builddir
275         # unapply autotools-dev if it exists
276         for x in config.guess config.sub; do \
277                 test -e /usr/share/misc/$$x || continue; \
278                 rm -f $$x; \
279         done
280         dh_clean
281
282 binary-indep: build-indep
283         dh_testdir
284         dh_testroot
285         if test -x "$$(which dh_prep)"; then dh_prep -i; else dh_clean -i -k; fi
286         dh_installchangelogs -i -Njupp
287         dh_install -i
288         dh_installmenu -i
289         # will be replaced by links to jupp
290         rm -rf debian/joe-jupp/usr/share/doc/joe-jupp
291         dh_link -i
292         dh_fixperms -i
293         dh_installdeb -i
294         dh_gencontrol -i
295         dh_md5sums -i
296         dh_builddeb -i
297
298 # no -Njupp because that's the only arch:any package
299 binary-arch: build-arch
300         dh_testdir
301         dh_testroot
302         if test -x "$$(which dh_prep)"; then dh_prep -a; else dh_clean -a -k; fi
303         dh_installchangelogs -pjupp -k NEWS
304         dh_installdocs -a
305         dh_install -a
306         dh_installmenu -a
307         dh_installman -a
308         dh_link -a
309         dh_strip -a
310         dh_compress -a
311         dh_fixperms -a
312         dh_installdeb -a
313         dh_shlibdeps -a
314         dh_gencontrol -a
315         dh_md5sums -a
316         dh_builddeb -a
317
318 binary: binary-arch binary-indep
319
320 .PHONY: binary binary-arch binary-indep build build-arch build-indep clean
321
322 ifneq (,$(strip ${___DISPLAY_MAKEVARS}))
323 $(foreach var,${___DISPLAY_MAKEVARS},$(info $(strip ${var})=${$(strip ${var})}))
324 $(error ___DISPLAY_MAKEVARS finished for ${___DISPLAY_MAKEVARS})
325 endif