#!/usr/bin/make -f
#-
-# Possible flavourisation (in addition to stock Debian rules):
-# export DEB_BUILD_OPTIONS=diet
-# export DEB_BUILD_OPTIONS=klibc
-# export DEB_BUILD_OPTIONS=klibc CC='klcc -shared'
-# export DEB_BUILD_OPTIONS='diet debug' (or 'klibc debug')
-# export DEB_BUILD_OPTIONS=static (for eglibc)
-# All can be combined with 'nopwnam' (aids static linkage).
+# 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 -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.
#
-# Setting diet or klibc disables -O0/-O2 and -g and, if unset,
-# sets CC. Adding debug enables -g3. Cross-compiling also sets
-# CC if unset.
+# 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
shellescape='$(subst ','\'',$(1))'
shellexport=$(1)=$(call shellescape,${$(1)})
-ifeq (,$(findstring diet,${DEB_BUILD_OPTIONS}))
-ifeq (,$(findstring klibc,${DEB_BUILD_OPTIONS}))
-USE_LIBC:=system
-else
-USE_LIBC:=klibc
+USE_LIBC:=
+ifneq (,$(findstring diet,${DEB_BUILD_OPTIONS}))
+USE_LIBC+= dietlibc
+endif
+ifneq (,$(findstring klibc,${DEB_BUILD_OPTIONS}))
+USE_LIBC+= klibc
+endif
+ifneq (,$(findstring musl,${DEB_BUILD_OPTIONS}))
+USE_LIBC+= musl
+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_LIBC:=dietlibc
+USE_SHARED:=0
+USE_LIBS:=0
+endif
+
+ifneq (,$(findstring shared,${DEB_BUILD_OPTIONS}))
+USE_SHARED:=1
+endif
+ifneq (,$(findstring static,${DEB_BUILD_OPTIONS}))
+USE_SHARED:=0
+endif
+
+USE_PWNAM:=1
+ifneq (,$(findstring nopwnam,${DEB_BUILD_OPTIONS}))
+USE_PWNAM:=0
+endif
+
+USE_FPU:=1
+ifneq (,$(findstring nofpu,${DEB_BUILD_OPTIONS}))
+USE_FPU:=0
+endif
+
+USE_MMU:=1
+ifneq (,$(findstring nommu,${DEB_BUILD_OPTIONS}))
+USE_MMU:=0
+endif
+
+ifneq (,$(findstring nolibs,${DEB_BUILD_OPTIONS}))
+USE_LIBS:=0
+endif
+
+USE_SELINUX:=1
+ifneq (,$(findstring 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)
ifneq (${DEB_BUILD_ARCH},${DEB_HOST_ARCH})
CC= ${DEB_HOST_GNU_TYPE}-gcc
else
-ifeq (,$(findstring diet,${DEB_BUILD_OPTIONS}))
-ifeq (,$(findstring klibc,${DEB_BUILD_OPTIONS}))
-CC= gcc
-else
-# export CC='klcc -shared' manually if you want that
+ifeq (${USE_LIBC},dietlibc)
+CC= diet -Os gcc
+endif
+ifeq (${USE_LIBC},klibc)
CC= klcc
endif
-else
-CC= diet -Os gcc
+ifeq (${USE_LIBC},musl)
+CC= musl-gcc
endif
+CC?= gcc
endif
endif
EXTRA_CFLAGS+= -fno-omit-frame-pointer -fwrapv -fno-strict-aliasing
# adjust when backporting
EXTRA_CFLAGS+= -Wextra -Wno-pointer-sign -Wno-unused-parameter \
- -Wno-missing-field-initializers \
-Wno-old-style-definition -Wno-strict-prototypes \
-Wno-cast-qual \
-Wno-missing-prototypes -Wno-missing-declarations
EXTRA_LDFLAGS= -Wl,--as-needed
-ifneq (${USE_LIBC},system)
-ifneq (,$(findstring debug,${DEB_BUILD_OPTIONS}))
-EXTRA_CFLAGS+= -g3
+# 5 is enough
+DEBHELPER_VERSION:= 9
+DSC_DEPS:= debhelper (>= ${DEBHELPER_VERSION})
+
+ifeq (${USE_LIBC},dietlibc)
+DSC_DEPS:= ${DSC_DEPS}, dietlibc-dev
+USE_SHARED:=0
+EXTRA_CFLAGS+= -fno-stack-protector
endif
-# SSP currently works with neither dietlibc nor klibc
+
+ifeq (${USE_LIBC},klibc)
+DSC_DEPS:= ${DSC_DEPS}, libklibc-dev
+USE_FPU:=0
EXTRA_CFLAGS+= -fno-stack-protector
-else
-ifneq (,$(findstring static,${DEB_BUILD_OPTIONS}))
+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
endif
+ifeq (${USE_LIBC},system)
+ifeq (0,${USE_SHARED})
+EXTRA_LDFLAGS+= -static
+endif
+endif
+
+ifneq (,$(findstring debug,${DEB_BUILD_OPTIONS}))
+EXTRA_CFLAGS+= -g3
+endif
+
ifneq (,$(wildcard /usr/share/dpkg/buildflags.mk))
# dpkg-dev (>= 1.16.1~)
DEB_CFLAGS_MAINT_APPEND=${EXTRA_CFLAGS}
DEB_LDFLAGS_MAINT_APPEND=${EXTRA_LDFLAGS}
ifneq (${USE_LIBC},system)
-# the diet and klcc wrappers take care of optimisation for us
DEB_CFLAGS_MAINT_STRIP=-O -O0 -O1 -O2 -O3 -Os -Ofast -Og -g -g1 -g2 -g3 -ggdb -gdwarf -gstabs
DEB_CFLAGS_MAINT_STRIP+=-specs=/usr/share/dpkg/no-pie-compile.specs
DEB_LDFLAGS_MAINT_STRIP+=-specs=/usr/share/dpkg/no-pie-link.specs
-# do not use PIE with strange libcs, either
+# do not use PIE with strange libcs
DEB_BUILD_MAINT_OPTIONS=hardening=+all,-pie
else
ifneq (,$(findstring static,${DEB_BUILD_OPTIONS}))
--mandir=/usr/share/man \
--disable-dependency-tracking
-ifneq (${USE_LIBC},system)
-# prevent picking up system libraries linked against the system C library
-CONFIGURE_ARGS+= --disable-search-libs
-endif
-
-ifneq (,$(findstring nopwnam,${DEB_BUILD_OPTIONS}))
+ifeq (0,${USE_PWNAM})
CONFIGURE_ARGS+= --disable-getpwnam
endif
-ifeq (${USE_LIBC},klibc)
+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
+DSC_DEPS:= ${DSC_DEPS}, libtinfo-dev | libncurses-dev
+endif
+
+ifeq (1,${USE_SELINUX})
+#DSC_DEPS:= ${DSC_DEPS}, libselinux1-dev [!kfreebsd-i386 !kfreebsd-amd64 !hurd-i386]
+DSC_DEPS:= ${DSC_DEPS}, libselinux1-dev [linux-any]
+endif
+
+ifneq (,$(findstring noautotools,${DEB_BUILD_OPTIONS}))
+DSC_DEPS:= ${DSC_DEPS}, autotools-dev
+endif
+
CONFIGURE_ARGS+= --disable-termidx \
--enable-sysconfjoesubdir=/jupp