#!/usr/bin/make -f #- # Possible flavourisation in DEB_BUILD_OPTIONS (in addition # to stock Debian rules): # - static (use with system libc; default for all others) # - shared (use with klibc or musl) # - diet, klibc, musl # - debug (adds -Og -g3) # - nopwnam (aids static linkage) # - nofpu (default with klibc) # - nommu # - nolibs (use with system libc; default for all others) # - noautotools (on systems lacking autotools-dev) # - noselinux # The 'nostrip' and 'parallel=n' options are supported as well. # # Targetting: # - (none) ⇒ sid, bullseye # - buster ⇒ buster-backports; focal # - stretch ⇒ stretch; bionic # - wheezy ⇒ wheezy, jessie; trusty, xenial # - lenny ⇒ lenny, squeeze; precise # - sarge ⇒ sarge, etch # # Using a non-system libc disables -O0/-O2 and -g and, if unset, # sets CC. Cross-compiling also sets CC if unset. # # Statically linking violates the Policy requirement of having a # Built-Using header, but since that is only used in local rebuilds # and not in the Debian archive, it constitutes no Policy violation. ifeq (,$(filter terse,${DEB_BUILD_OPTIONS})) export DH_VERBOSE=1 export V=1 export VERBOSE=1 endif LC_ALL:=C export LC_ALL shellescape='$(subst ','\'',$(1))' shellexport=$(1)=$(call shellescape,${$(1)}) USE_LIBC:= ifneq (,$(filter diet,${DEB_BUILD_OPTIONS})) USE_LIBC+= dietlibc endif ifneq (,$(filter klibc,${DEB_BUILD_OPTIONS})) USE_LIBC+= klibc endif ifneq (,$(filter musl,${DEB_BUILD_OPTIONS})) USE_LIBC+= musl endif ifeq (,$(filter diet,${DEB_BUILD_OPTIONS})$(filter klibc,${DEB_BUILD_OPTIONS})$(filter musl,${DEB_BUILD_OPTIONS})) USE_LIBC+= system endif ifneq ($(strip ${USE_LIBC}),$(firstword ${USE_LIBC})) $(error multiple libcs (${USE_LIBC}) found in (${DEB_BUILD_OPTIONS})) endif USE_LIBC:=$(strip ${USE_LIBC}) ifeq (${USE_LIBC},system) USE_SHARED:=1 USE_LIBS:=1 else USE_SHARED:=0 USE_LIBS:=0 endif ifneq (,$(filter shared,${DEB_BUILD_OPTIONS})) USE_SHARED:=1 endif ifneq (,$(filter static,${DEB_BUILD_OPTIONS})) USE_SHARED:=0 endif USE_PWNAM:=1 ifneq (,$(filter nopwnam,${DEB_BUILD_OPTIONS})) USE_PWNAM:=0 endif USE_FPU:=1 ifneq (,$(filter nofpu,${DEB_BUILD_OPTIONS})) USE_FPU:=0 endif USE_MMU:=1 ifneq (,$(filter nommu,${DEB_BUILD_OPTIONS})) USE_MMU:=0 endif ifneq (,$(filter nolibs,${DEB_BUILD_OPTIONS})) USE_LIBS:=0 endif USE_SELINUX:=1 ifneq (,$(filter noselinux,${DEB_BUILD_OPTIONS})) USE_SELINUX:=0 endif ifeq (0,${USE_LIBS}) USE_SELINUX:=0 endif DEB_BUILD_ARCH?=$(shell dpkg-architecture -qDEB_BUILD_ARCH) DEB_BUILD_GNU_TYPE?=$(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE) DEB_HOST_ARCH?=$(shell dpkg-architecture -qDEB_HOST_ARCH) DEB_HOST_GNU_TYPE?=$(shell dpkg-architecture -qDEB_HOST_GNU_TYPE) ifneq (,$(wildcard /usr/share/dpkg/buildtools.mk)) include /usr/share/dpkg/buildtools.mk else # is ${CC} defined anywhere (other than implicit rules?) ifneq (,$(filter $(origin CC),default undefined)) # no - then default to gcc (or cross-gcc) ifneq (${DEB_BUILD_ARCH},${DEB_HOST_ARCH}) CC= ${DEB_HOST_GNU_TYPE}-gcc else CC= gcc endif endif endif # other libc choices override this ifeq (${USE_LIBC},dietlibc) CC= diet -Os gcc endif ifeq (${USE_LIBC},klibc) CC= klcc endif ifeq (${USE_LIBC},musl) CC= musl-gcc endif EXTRA_CFLAGS:= EXTRA_LDFLAGS:= -Wl,--as-needed ifneq (,$(filter debug,${DEB_BUILD_OPTIONS})) EXTRA_CFLAGS+= -Og -g3 endif EXTRA_CFLAGS+= -Wall -Wformat EXTRA_CFLAGS+= -fno-omit-frame-pointer -fno-strict-aliasing ifeq (,$(filter sarge,${DEB_BUILD_OPTIONS})) EXTRA_CFLAGS+= -fwrapv EXTRA_CFLAGS+= -Wextra EXTRA_CFLAGS+= -Wno-pointer-sign else EXTRA_CFLAGS+= -W endif EXTRA_CFLAGS+= -Wno-unused-parameter EXTRA_CFLAGS+= -Wno-strict-prototypes DSF:= 3.0 (quilt) SUBST_EP:= -e '/@PRIO@EXTRA@/d' HOMEPAGE:= http://www.mirbsd.org/jupp.htm SUBST_HP:= -e '/@HP@DOT@/d' -e '/@HP@OLD@/d' -e 's@HP@MODERN@${HOMEPAGE}' SELINUX_DEP:= libselinux1-dev [linux-any] MENU_SUBST:= cat USE_MENU:= 0 BREAKS:= Breaks SUBST_VARS+= BREAKS # buster, bullseye, sid DEBHELPER_COMPAT:= 13 SUBST_R3:= -e 's/@@R3@@/Rules-Requires-Root: no/' # focal ifneq (,$(filter buster,${DEB_BUILD_OPTIONS})) DEBHELPER_COMPAT:= 12 endif # stretch ifneq (,$(filter stretch,${DEB_BUILD_OPTIONS})) DEBHELPER_COMPAT:= 10 SUBST_R3:= -e 's/@@R3@@/Rules-Requires-Root: binary-targets/' endif # wheezy, jessie ifneq (,$(filter wheezy,${DEB_BUILD_OPTIONS})) DEBHELPER_COMPAT:= 9 USE_MENU:= 1 SUBST_R3:= -e '/@@R3@@/d' endif # lenny, squeeze, sarge, etch ifneq (,$(filter lenny,${DEB_BUILD_OPTIONS})$(filter sarge,${DEB_BUILD_OPTIONS})) DEBHELPER_COMPAT:= 5 USE_MENU:= 1 DSF:= 1.0 SUBST_EP:= -e 's/@PRIO@EXTRA@/Priority: extra/' BREAKS:= Conflicts SUBST_R3:= -e '/@@R3@@/d' SELINUX_DEP:= libselinux1-dev [!kfreebsd-i386 !kfreebsd-amd64 !hurd-i386] # sarge, etch ifneq (,$(filter sarge,${DEB_BUILD_OPTIONS})) SELINUX_DEP:= libselinux1-dev SUBST_HP:= -e '/@HP@MODERN@/d' -e '/^VCS-[gB][ir][to][:w]/d' \ -e 's/@HP@DOT@//' -e 's@HP@OLD@${HOMEPAGE}' MENU_SUBST:= sed 's!"Applications/!"Apps/!' endif endif ifeq (12,${DEBHELPER_COMPAT}) DEBHELPER_VERSION= 12.9~ endif DEBHELPER_VERSION?= ${DEBHELPER_COMPAT} ifeq (,$(filter ${DEBHELPER_COMPAT},10 9 5 4)) DSC_DEPS:= debhelper-compat (= ${DEBHELPER_COMPAT}) ifneq (${DEBHELPER_VERSION},${DEBHELPER_COMPAT}) DSC_DEPS:= ${DSC_DEPS}, debhelper (>= ${DEBHELPER_VERSION}) endif else DSC_DEPS:= debhelper (>= ${DEBHELPER_VERSION}) endif SUBST_VARS+= DSC_DEPS ifeq (${USE_LIBC},dietlibc) DSC_DEPS:= ${DSC_DEPS}, dietlibc-dev USE_SHARED:=0 EXTRA_CFLAGS+= -fno-stack-protector endif ifeq (${USE_LIBC},klibc) DSC_DEPS:= ${DSC_DEPS}, libklibc-dev USE_FPU:=0 EXTRA_CFLAGS+= -fno-stack-protector ifeq (1,${USE_SHARED}) CC+= -shared endif endif ifeq (${USE_LIBC},musl) DSC_DEPS:= ${DSC_DEPS}, musl-tools EXTRA_CFLAGS+= -Os ifeq (0,${USE_SHARED}) EXTRA_LDFLAGS+= -static endif CONFIGURE_ENV+= ac_cv_header_sys_termios_h=no endif ifeq (${USE_LIBC},system) ifeq (0,${USE_SHARED}) EXTRA_LDFLAGS+= -static endif endif ifneq (,$(wildcard /usr/share/dpkg/buildflags.mk)) # dpkg-dev (>= 1.16.1~) dpkgbuildflagsmkescape=$(subst \,\\\,$(1)) export DEB_CFLAGS_MAINT_APPEND:=$(call dpkgbuildflagsmkescape,${EXTRA_CFLAGS}) export DEB_LDFLAGS_MAINT_APPEND:=$(call dpkgbuildflagsmkescape,${EXTRA_LDFLAGS}) ifneq (${USE_LIBC},system) export DEB_CFLAGS_MAINT_STRIP=-O -O0 -O1 -O2 -O3 -Os -Ofast -Og -g -g1 -g2 -g3 -ggdb -gdwarf -gstabs export DEB_CFLAGS_MAINT_STRIP+=-specs=/usr/share/dpkg/no-pie-compile.specs export DEB_LDFLAGS_MAINT_STRIP+=-specs=/usr/share/dpkg/no-pie-link.specs # do not use PIE with strange libcs export DEB_BUILD_MAINT_OPTIONS=hardening=+all,-pie else ifneq (,$(filter static,${DEB_BUILD_OPTIONS})) # cannot mix PIE with static linkage export DEB_BUILD_MAINT_OPTIONS=hardening=+all,-pie else export DEB_BUILD_MAINT_OPTIONS=hardening=+all endif endif include /usr/share/dpkg/buildflags.mk else # old-fashioned way to determine build flags ifneq (${USE_LIBC},system) CFLAGS= else CFLAGS= -O$(if $(filter noopt,${DEB_BUILD_OPTIONS}),0,2) -g endif CFLAGS+= ${EXTRA_CFLAGS} LDFLAGS+= ${EXTRA_LDFLAGS} endif ifneq (,$(filter parallel,${DEB_BUILD_OPTIONS})) MAKE_ARGS+= -j else ifneq (,$(filter parallel=%,${DEB_BUILD_OPTIONS})) MAKE_ARGS+= -j$(patsubst parallel=%,%,$(filter parallel=%,${DEB_BUILD_OPTIONS})) endif CONFIGURE_ARGS= --build=${DEB_BUILD_GNU_TYPE} \ --host=${DEB_HOST_GNU_TYPE} \ --prefix=/usr \ --sysconfdir=/etc \ --mandir=/usr/share/man \ --disable-dependency-tracking ifeq (0,${USE_PWNAM}) CONFIGURE_ARGS+= --disable-getpwnam endif ifeq (0,${USE_FPU}) CONFIGURE_ARGS+= --disable-fpu endif ifeq (0,${USE_MMU}) CONFIGURE_ARGS+= --disable-fork endif ifeq (0,${USE_LIBS}) CONFIGURE_ARGS+= --disable-search-libs \ --disable-terminfo else ifneq (,$(filter ${DEBHELPER_COMPAT},10 9 5 4)) DSC_DEPS:= ${DSC_DEPS}, libtinfo-dev | libncurses-dev else DSC_DEPS:= ${DSC_DEPS}, libncurses-dev endif endif ifeq (1,${USE_SELINUX}) DSC_DEPS:= ${DSC_DEPS}, $(strip ${SELINUX_DEP}) endif ifeq (,$(filter noautotools,${DEB_BUILD_OPTIONS})) ifneq (,$(filter ${DEBHELPER_COMPAT},10 9 5 4)) DSC_DEPS:= ${DSC_DEPS}, autotools-dev endif endif CONFIGURE_ARGS+= --disable-termidx \ --enable-sysconfjoesubdir=/jupp debian/.configure_stamp: debian/.control_stamp dh_testdir -rm -f debian/.*_stamp :>debian/.control_stamp # to avoid building twice -rm -rf builddir # apply autotools-dev if it exists for x in config.guess config.sub; do \ test -e /usr/share/misc/$$x || continue; \ rm -f $$x; \ cp /usr/share/misc/$$x .; \ done mkdir builddir cd builddir && exec env ${CONFIGURE_ENV} \ $(foreach i,CC CFLAGS CPPFLAGS LDFLAGS,$(call shellexport,$i)) \ sh ../configure ${CONFIGURE_ARGS} @:>$@ debian/.build_stamp: debian/.configure_stamp dh_testdir cd builddir && exec ${MAKE} ln -f builddir/joe builddir/jupp ln -f builddir/joe.1 builddir/jupp.1 @:>$@ debian/.control_stamp: @(if test -e debian/control.in; then exit 0; else \ echo 'dh_testdir: "debian/control.in" not found.' \ Are you sure you are in the correct directory\?; \ exit 1; \ fi) @mkdir -p debian/source echo '${DSF}' >debian/source/format ifneq (,$(filter ${DEBHELPER_COMPAT},10 9 5 4)) echo ${DEBHELPER_COMPAT} >debian/compat endif -rm -f debian/source.lintian-overrides ifneq (,$(filter ${DEBHELPER_COMPAT},10 9 5 4)) sed --posix \ -e 's! debian-watch-does-not-check-gpg-signature! debian-watch-may-check-gpg-signature!g' \ debian/source.lintian-overrides endif ifneq (,$(filter 1,${USE_MENU})) ${MENU_SUBST} debian/joe-jupp.menu ${MENU_SUBST} debian/jupp.menu endif sed ${SUBST_EP} ${SUBST_HP} ${SUBST_R3} \ $(foreach v,${SUBST_VARS},-e 's@@'$(call shellescape,$v)'@@'$(call shellescape,$(strip ${$v}))'') \ debian/.gencontrol_stamp : bail out if these differ: in those cases, : retry the build, after regenerating debian/control : with cp debian/.gencontrol_stamp debian/control diff -Nu debian/control debian/.gencontrol_stamp : you made it, no worries @:>$@ debian/control: -debian/rules debian/.control_stamp cp debian/.gencontrol_stamp debian/control -rm -f debian/.control_stamp debian/.gencontrol_stamp remove/control: -rm -f debian/.control_stamp debian/.gencontrol_stamp \ debian/source/format debian/compat debian/control \ debian/source.lintian-overrides \ debian/joe-jupp.menu debian/jupp.menu ifeq (,$(filter ${DEBHELPER_COMPAT},10 9 5 4)) # dh7-style build-ish %: dh $@ override_dh_auto_configure: debian/.configure_stamp @: override_dh_auto_build-arch: debian/.build_stamp @: override_dh_auto_build-indep: debian/.configure_stamp cd builddir && exec ${MAKE} jmacsrc joerc jpicorc jstarrc rjoerc execute_after_dh_auto_clean: -rm -f debian/.*_stamp -rm -rf builddir # unapply autotools-dev if it exists for x in config.guess config.sub; do \ test -e /usr/share/misc/$$x || continue; \ rm -f $$x; \ done ifeq (,$(filter 1,${USE_MENU})) override_dh_installmenu-indep: dh_install -pjoe-jupp \ debian/menu/org.mirbsd.Jupp.jmacs.desktop \ debian/menu/org.mirbsd.Jupp.joe.desktop \ debian/menu/org.mirbsd.Jupp.jpico.desktop \ debian/menu/org.mirbsd.Jupp.jstar.desktop \ usr/share/applications/ override_dh_installmenu-arch: dh_install -pjupp \ debian/menu/org.mirbsd.Jupp.jupp.desktop \ usr/share/applications/ endif execute_before_dh_link-indep: # will be replaced by links to jupp rm -rf debian/joe-jupp/usr/share/doc/joe-jupp else # dh5-style build build: build-arch build-indep build-arch: debian/.build_stamp build-indep: debian/.configure_stamp cd builddir && exec ${MAKE} jmacsrc joerc jpicorc jstarrc rjoerc clean: debian/.control_stamp dh_testdir -rm -f debian/.*_stamp -rm -rf builddir # unapply autotools-dev if it exists for x in config.guess config.sub; do \ test -e /usr/share/misc/$$x || continue; \ rm -f $$x; \ done dh_clean binary-indep: build-indep dh_testdir dh_testroot if command -v dh_prep >/dev/null 2>&1; then dh_prep -i; else dh_clean -i -k; fi dh_installchangelogs -i dh_install -i ifneq (,$(filter 1,${USE_MENU})) dh_installmenu -i else dh_install -pjoe-jupp \ debian/menu/org.mirbsd.Jupp.jmacs.desktop \ debian/menu/org.mirbsd.Jupp.joe.desktop \ debian/menu/org.mirbsd.Jupp.jpico.desktop \ debian/menu/org.mirbsd.Jupp.jstar.desktop \ usr/share/applications/ endif # will be replaced by links to jupp rm -rf debian/joe-jupp/usr/share/doc/joe-jupp if command -v dh_lintian >/dev/null 2>&1; then dh_lintian -i; fi dh_link -i dh_fixperms -i dh_installdeb -i dh_gencontrol -i dh_md5sums -i dh_builddeb -i # no -Njupp because that's the only arch:any package binary-arch: build-arch dh_testdir dh_testroot if command -v dh_prep >/dev/null 2>&1; then dh_prep -a; else dh_clean -a -k; fi dh_installchangelogs -a dh_installdocs -a dh_install -a ifneq (,$(filter 1,${USE_MENU})) dh_installmenu -a else dh_install -pjupp \ debian/menu/org.mirbsd.Jupp.jupp.desktop \ usr/share/applications/ endif dh_installman -a if command -v dh_lintian >/dev/null 2>&1; then dh_lintian -a; fi dh_link -a dh_strip -a dh_compress -a dh_fixperms -a dh_installdeb -a dh_shlibdeps -a dh_gencontrol -a dh_md5sums -a dh_builddeb -a binary: binary-arch binary-indep .PHONY: binary binary-arch binary-indep build build-arch build-indep clean endif ifneq (,$(strip ${___DISPLAY_MAKEVARS})) $(foreach var,${___DISPLAY_MAKEVARS},$(info $(strip ${var})=${$(strip ${var})})) $(error ___DISPLAY_MAKEVARS finished for ${___DISPLAY_MAKEVARS}) endif # useful combinations to test: # DEB_BUILD_OPTIONS= debian/rules debian/.control_stamp # DEB_BUILD_OPTIONS='diet' debian/rules debian/.control_stamp # DEB_BUILD_OPTIONS='klibc' debian/rules debian/.control_stamp # DEB_BUILD_OPTIONS='musl' debian/rules debian/.control_stamp # DEB_BUILD_OPTIONS='static nopwnam' debian/rules debian/.control_stamp # DEB_BUILD_OPTIONS='static nopwnam nolibs' debian/rules debian/.control_stamp # DEB_BUILD_OPTIONS='nommu nolibs' debian/rules debian/.control_stamp # DEB_BUILD_OPTIONS='nofpu nommu nolibs' debian/rules debian/.control_stamp # DEB_BUILD_OPTIONS='buster' debian/rules debian/.control_stamp # DEB_BUILD_OPTIONS='stretch' debian/rules debian/.control_stamp # DEB_BUILD_OPTIONS='wheezy' debian/rules debian/.control_stamp # DEB_BUILD_OPTIONS='lenny' debian/rules debian/.control_stamp # DEB_BUILD_OPTIONS='lenny diet' debian/rules debian/.control_stamp # DEB_BUILD_OPTIONS='sarge' debian/rules debian/.control_stamp