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)
9 # - nopwnam (aids static linkage)
10 # - nofpu (default with klibc)
12 # - nolibs (use with system libc; default for all others)
13 # - noautotools (on systems lacking autotools-dev)
15 # The 'nostrip' and 'parallel=n' options are supported as well.
17 # Using a non-system libc disables -O0/-O2 and -g and, if unset,
18 # sets CC. Cross-compiling also sets CC if unset.
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.
24 shellescape='$(subst ','\'',$(1))'
25 shellexport=$(1)=$(call shellescape,${$(1)})
28 ifneq (,$(findstring diet,${DEB_BUILD_OPTIONS}))
31 ifneq (,$(findstring klibc,${DEB_BUILD_OPTIONS}))
34 ifneq (,$(findstring musl,${DEB_BUILD_OPTIONS}))
37 ifeq (,$(findstring diet,${DEB_BUILD_OPTIONS})$(findstring klibc,${DEB_BUILD_OPTIONS})$(findstring musl,${DEB_BUILD_OPTIONS}))
40 ifneq ($(strip ${USE_LIBC}),$(firstword ${USE_LIBC}))
41 $(error multiple libcs (${USE_LIBC}) found in (${DEB_BUILD_OPTIONS}))
43 USE_LIBC:=$(strip ${USE_LIBC})
45 ifeq (${USE_LIBC},system)
53 ifneq (,$(findstring shared,${DEB_BUILD_OPTIONS}))
56 ifneq (,$(findstring static,${DEB_BUILD_OPTIONS}))
61 ifneq (,$(findstring nopwnam,${DEB_BUILD_OPTIONS}))
66 ifneq (,$(findstring nofpu,${DEB_BUILD_OPTIONS}))
71 ifneq (,$(findstring nommu,${DEB_BUILD_OPTIONS}))
75 ifneq (,$(findstring nolibs,${DEB_BUILD_OPTIONS}))
80 ifneq (,$(findstring noselinux,${DEB_BUILD_OPTIONS}))
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)
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
98 ifeq (${USE_LIBC},dietlibc)
101 ifeq (${USE_LIBC},klibc)
104 ifeq (${USE_LIBC},musl)
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
119 EXTRA_CFLAGS+= -Wno-unused-parameter -Wno-strict-prototypes \
121 -Wno-missing-prototypes -Wno-missing-declarations
122 EXTRA_LDFLAGS= -Wl,--as-needed
124 DEBHELPER_VERSION:= 9
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]
132 ifneq (,$(findstring lenny,${DEB_BUILD_OPTIONS}))
133 DEBHELPER_VERSION:= 5
134 SELINUX_DEP:= libselinux1-dev [!kfreebsd-i386 !kfreebsd-amd64 !hurd-i386]
136 ifneq (,$(findstring lenny,${DEB_BUILD_OPTIONS})$(findstring sarge,${DEB_BUILD_OPTIONS}))
138 SUBST_EP:= -e 's/@PRIO@EXTRA@/Priority: extra/'
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/!'
149 DSC_DEPS:= debhelper (>= ${DEBHELPER_VERSION})
150 SUBST_VARS+= DSC_DEPS
155 ifeq (${USE_LIBC},dietlibc)
156 DSC_DEPS:= ${DSC_DEPS}, dietlibc-dev
158 EXTRA_CFLAGS+= -fno-stack-protector
161 ifeq (${USE_LIBC},klibc)
162 DSC_DEPS:= ${DSC_DEPS}, libklibc-dev
164 EXTRA_CFLAGS+= -fno-stack-protector
165 ifeq (1,${USE_SHARED})
170 ifeq (${USE_LIBC},musl)
171 DSC_DEPS:= ${DSC_DEPS}, musl-tools
173 ifeq (0,${USE_SHARED})
174 EXTRA_LDFLAGS+= -static
176 CONFIGURE_ENV+= ac_cv_header_sys_termios_h=no
179 ifeq (${USE_LIBC},system)
180 ifeq (0,${USE_SHARED})
181 EXTRA_LDFLAGS+= -static
185 ifneq (,$(findstring debug,${DEB_BUILD_OPTIONS}))
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
200 ifneq (,$(findstring static,${DEB_BUILD_OPTIONS}))
201 # cannot mix PIE with static linkage
202 DEB_BUILD_MAINT_OPTIONS=hardening=+all,-pie
204 DEB_BUILD_MAINT_OPTIONS=hardening=+all
207 include /usr/share/dpkg/buildflags.mk
209 # old-fashioned way to determine build flags
210 ifneq (${USE_LIBC},system)
213 CFLAGS= -O$(if $(findstring noopt,${DEB_BUILD_OPTIONS}),0,2) -g
215 CFLAGS+= ${EXTRA_CFLAGS}
216 LDFLAGS+= ${EXTRA_LDFLAGS}
219 ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
220 NUMJOBS= $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
221 MAKEFLAGS+= -j${NUMJOBS}
224 CONFIGURE_ARGS= --build=${DEB_BUILD_GNU_TYPE} \
225 --host=${DEB_HOST_GNU_TYPE} \
228 --mandir=/usr/share/man \
229 --disable-dependency-tracking
231 ifeq (0,${USE_PWNAM})
232 CONFIGURE_ARGS+= --disable-getpwnam
236 CONFIGURE_ARGS+= --disable-fpu
240 CONFIGURE_ARGS+= --disable-fork
244 CONFIGURE_ARGS+= --disable-search-libs \
247 DSC_DEPS:= ${DSC_DEPS}, libtinfo-dev | libncurses-dev
250 ifeq (1,${USE_SELINUX})
251 DSC_DEPS:= ${DSC_DEPS}, $(strip ${SELINUX_DEP})
254 ifeq (,$(findstring noautotools,${DEB_BUILD_OPTIONS}))
255 DSC_DEPS:= ${DSC_DEPS}, autotools-dev
258 CONFIGURE_ARGS+= --disable-termidx \
259 --enable-sysconfjoesubdir=/jupp
261 debian/.configure_stamp: debian/.control_stamp
263 -rm -f debian/.*_stamp
265 # apply autotools-dev if it exists
266 for x in config.guess config.sub; do \
267 test -e /usr/share/misc/$$x || continue; \
269 cp /usr/share/misc/$$x .; \
272 cd builddir && exec env ${CONFIGURE_ENV} \
273 $(foreach i,CC CFLAGS CPPFLAGS LDFLAGS,$(call shellexport,$i)) \
274 sh ../configure ${CONFIGURE_ARGS}
277 debian/.build_stamp: debian/.configure_stamp
279 cd builddir && exec ${MAKE}
280 ln -f builddir/joe builddir/jupp
281 ln -f builddir/joe.1 builddir/jupp.1
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\?; \
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
305 build: build-arch build-indep
306 build-arch: debian/.build_stamp
307 build-indep: debian/.configure_stamp
309 clean: debian/.control_stamp
311 -rm -f debian/.*_stamp
313 # unapply autotools-dev if it exists
314 for x in config.guess config.sub; do \
315 test -e /usr/share/misc/$$x || continue; \
320 binary-indep: build-indep
323 if test -x "$$(which dh_prep)"; then dh_prep -i; else dh_clean -i -k; fi
324 dh_installchangelogs -i -Njupp
327 # will be replaced by links to jupp
328 rm -rf debian/joe-jupp/usr/share/doc/joe-jupp
336 # no -Njupp because that's the only arch:any package
337 binary-arch: build-arch
340 if test -x "$$(which dh_prep)"; then dh_prep -a; else dh_clean -a -k; fi
341 dh_installchangelogs -pjupp -k NEWS
356 binary: binary-arch binary-indep
358 .PHONY: binary binary-arch binary-indep build build-arch build-indep clean
360 ifneq (,$(strip ${___DISPLAY_MAKEVARS}))
361 $(foreach var,${___DISPLAY_MAKEVARS},$(info $(strip ${var})=${$(strip ${var})}))
362 $(error ___DISPLAY_MAKEVARS finished for ${___DISPLAY_MAKEVARS})
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