#!/usr/bin/make -f # Sample debian/rules that uses debhelper. # GNU copyright 1997 to 1999 by Joey Hess. SHELL = bash # Uncomment this to turn on verbose mode. #export DH_VERBOSE=1 DEB_HOST_ARCH_OS ?= $(shell dpkg-architecture -qDEB_HOST_ARCH_OS) DEB_HOST_ARCH_CPU ?= $(shell dpkg-architecture -qDEB_HOST_ARCH_CPU) source := $(shell dpkg-parsechangelog | grep ^Source: | sed -e 's/^.*: //g') full_version := $(shell dpkg-parsechangelog | grep ^Version: | sed -e 's/^.*: //g') tar_version := $(shell echo $(full_version) | sed -e 's/-.*//g') svn_revision := $(shell echo $(full_version) | sed -e 's/.*~svn\([0-9]*\)-[0-9]\+.*/\1/g' -e 's/^$(full_version)$$/HEAD/g') version := $(shell echo $(full_version) | sed -e 's/[~+-].*//g') major := $(shell echo $(version) | sed -e 's/\..*//g') revision := $(shell echo $(full_version) | sed -e 's/^[^+-]*//g') cpu := $(shell dpkg-architecture -qDEB_HOST_ARCH_CPU) config_files := $(wildcard debian/arch/$(cpu)/*.config) flavours := $(config_files:debian/arch/$(cpu)/%.config=%) ld_target := $(shell ld --help | sed -ne "s/[^ :]*: supported targets: \([^ ]*\) .*/\1/p") configfile := DEBCUSTOM # Whether to enable extra debug features, at the expense of performance # Not recommended for release builds debug := no # Putting ~debug in the Version field enbles this automatically ifneq ($(findstring ~debug,$(full_version)),) debug := yes endif # Produce a DFSG-free package by default, stripping out sourceless # (non-free) blobs. Put +nonfree or +sourceless in the Version field # to keep the non-free parts and build non-free drivers nonfree := $(findstring +nonfree,$(full_version))$(findstring +sourceless,$(full_version)) abiname := 0 # Clearly indicate if the build is non-free, and make it # co-installable with DFSG-free versions abiname := $(abiname)$(nonfree) ifeq ($(cpu), mipsel) kfreebsd_cpu := mips else kfreebsd_cpu := $(cpu) endif SVN_BASE := https://svn.freebsd.org/base #SVN := $(SVN_BASE)/release/$(version).0 SVN := $(SVN_BASE)/releng/$(version) #SVN := $(SVN_BASE)/stable/$(major) #SVN := $(SVN_BASE)/head SOURCE_PACKAGE := $(CURDIR)/debian/kfreebsd-source-$(version) IMAGE_PACKAGE := $(CURDIR)/debian/kfreebsd-image-$(version)-$(abiname) HEADERS_PACKAGE := $(CURDIR)/debian/kfreebsd-headers-$(version)-$(abiname) SRC_TAR := kfreebsd-source-$(version).tar.xz SRC_DIR := kfreebsd-source-$(version) HEADERS_DIR := kfreebsd-headers-$(version)-$(abiname) FLAVOR_DIR := flavor-$(version)-$(abiname) ORIG_DIR := $(source)-$(tar_version) ORIG_TAR := $(source)_$(tar_version).orig.tar.xz PATH := /usr/lib/freebsd:$(PATH) SOURCE_DATE_EPOCH ?= $(shell date -d "$$(dpkg-parsechangelog -SDate)" +%s) ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS))) NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS))) # Do not mess with MAKEFLAGS until we transfer control to BSD make (see below) BSD_MAKEFLAGS += -j$(NUMJOBS) endif MAKE := \ MAKEFLAGS=$(BSD_MAKEFLAGS) \ make \ MACHINE_ARCH=$(kfreebsd_cpu) ifeq ($(nonfree),) # Disable non-free drivers MAKE += -DWITHOUT_SOURCELESS endif # Clang is the default compiler on these architectures (see src/share/mk/bsd.own.mk) clang_cpus := # i386 amd64 arm # Experimentally build all arches with GCC for now cc_pkg := gcc-8 #cc_pkg := clang-3.5 [$(foreach cpu,$(clang_cpus),any-$(cpu))], \ # gcc-6 [$(foreach cpu,$(clang_cpus),!any-$(cpu))] ifneq (, $(filter $(clang_cpus), $(DEB_HOST_ARCH_CPU))) cc_cmd := clang-3.5 else cc_cmd := gcc-8 endif ifeq ($(cc_cmd), clang) MAKE += -DWITH_CLANG_IS_CC else MAKE += -DWITHOUT_CLANG_IS_CC MAKE += WERROR= endif MAKE += -DWITHOUT_CTF # Disable install of *.ko.symbols files (their presence would trigger an # "unstripped-binary-or-object" lintian error). MAKE += -DWITHOUT_KERNEL_SYMBOLS # Prevent improper #include of mm_malloc.h by GCC headers CFLAGS += -D_MM_MALLOC_H_INCLUDED get-orig-source: rm -rf $(ORIG_DIR) svn export --ignore-keywords -r $(svn_revision) $(SVN)/sys $(ORIG_DIR)/sys ifeq ($(nonfree),) # Removing non-free blobs to make source package DFSG-free cd $(ORIG_DIR) && $(CURDIR)/debian/prune.sh # Replace file with a DFSG-free re-implementation cp -af debian/local/ar9300_devid.h $(ORIG_DIR)/sys/contrib/dev/ath/ath_hal/ar9300/ cp -af debian/local/ar9300_devid.h $(ORIG_DIR)/sys/dev/ath/ath_hal/ar9003/ else # WARNING: orig source tarball will contain non-free blobs endif # Clamp timestamps to be no newer than last upstream revision, see # https://wiki.debian.org/ReproducibleBuilds/TimestampsInTarball REVISION_DATE_EPOCH=`date -d \`svn info -r $(svn_revision) $(SVN)/sys \ --show-item last-changed-date\` +%s` && \ find $(ORIG_DIR) -newermt "@$$REVISION_DATE_EPOCH" -print0 \ | xargs -0r touch --no-dereference --date="@$$REVISION_DATE_EPOCH" # Create tarball with files sorted in a stable order, see # https://wiki.debian.org/ReproducibleBuilds/FileOrderInTarballs find $(ORIG_DIR) -print0 | LC_ALL=C sort -z \ | tar --null --no-recursion --files-from - \ --numeric-owner --owner 0 --group 0 \ -cJf ../$(ORIG_TAR) rm -rf $(ORIG_DIR) control: clean for arch in `ls $(CURDIR)/debian/arch/` ; do \ KW_CONFIG_DIR=debian/installer/$$arch ; \ if test -e $$KW_CONFIG_DIR ; then \ for config in `ls $(CURDIR)/debian/arch/$$arch/ | grep \.config` ; do \ flavor=$${config/.config/} ; \ if test -e debian/arch/$$arch/$$flavor.installer ; then \ echo "kfreebsd-$$arch $(version)-$(abiname) $$flavor $(version)-$(abiname)-$$flavor - -" ; \ fi ; \ done > $$KW_CONFIG_DIR/kernel-versions ; \ fi ; \ echo ; \ done sed -e "s/@major@/$(major)/g" -e "s/@version@/$(version)/g" -e "s/@abiname@/$(abiname)/g" -e "s/@flavor@/$$flavor/g" \ -e "s/@cc_pkg@/$(cc_pkg)/g" \ $(CURDIR)/debian/control.in > $(CURDIR)/debian/control echo >> $(CURDIR)/debian/control for arch in `ls $(CURDIR)/debian/arch/` ; do \ for config in `ls $(CURDIR)/debian/arch/$$arch/ | grep \.config` ; do \ flavor=$${config/.config/} ; \ recommends= ; \ test -f $(CURDIR)/debian/arch/$$arch/$$flavor.defines && recommends=`awk '/^Recommends: / {print $$2}' $(CURDIR)/debian/arch/$$arch/$$flavor.defines` ; \ sed -e "s/@major@/$(major)/g" -e "s/@version@/$(version)/g" -e "s/@abiname@/$(abiname)/g" -e "s/@flavor@/$$flavor/g" -e "s/@arch@/$$arch/g" -e "s/@recommends@/$$recommends/g" \ $(CURDIR)/debian/control.flavor.in ; \ echo ; \ done ; \ export KW_DEFCONFIG_DIR=debian/installer ; \ export KW_CONFIG_DIR=debian/installer/$$arch ; \ if test -e $$KW_CONFIG_DIR/kernel-versions ; then \ kernel-wedge gen-control ; \ fi ; \ echo ; \ done >> $(CURDIR)/debian/control clean: dh_testdir dh_testroot rm -rf kfreebsd-source-* flavor-* rm -f debian/kfreebsd-image-*.preinst rm -f debian/kfreebsd-image-*.prerm rm -f debian/kfreebsd-image-*.postinst rm -f debian/kfreebsd-image-*.postrm dh_clean build-indep: build-indep-stamp build-indep-stamp: dh_testdir mkdir -p $(SRC_DIR) cp -af sys $(SRC_DIR)/ touch build-indep-stamp build: build-arch build-indep install-indep: install-indep-stamp install-indep-stamp: build-indep dh_testdir dh_testroot dh_prep dh_installdirs -i mkdir -p $(SOURCE_PACKAGE)/usr/src chown -R root.src $(SRC_DIR) # Clamp timestamps to be no newer than last changelog entry, see # https://wiki.debian.org/ReproducibleBuilds/TimestampsInTarball find $(SRC_DIR) -newermt "@$(SOURCE_DATE_EPOCH)" -print0 \ | xargs -0r touch --no-dereference --date="@$(SOURCE_DATE_EPOCH)" # Create tarball with files sorted in a stable order, see # https://wiki.debian.org/ReproducibleBuilds/FileOrderInTarballs # and normalised file permissions regardless of umask, see # https://wiki.debian.org/ReproducibleBuilds/VaryingPermissionsInTarballs find $(SRC_DIR) -print0 | LC_ALL=C sort -z \ | tar --null --no-recursion --files-from - \ --mode=go=rX,u+rw,a-s \ -cJf $(SOURCE_PACKAGE)/usr/src/$(SRC_TAR) touch install-indep-stamp build-arch: $(foreach flavor,$(flavours),build-flavor-$(flavor)-stamp) src-flavor-%-stamp: mkdir -p $(FLAVOR_DIR)-$* cp -af sys $(FLAVOR_DIR)-$*/ # Compile objects with relative, not absolute paths, to avoid embedding # full build tree paths into modules (Bug #757629) find $(FLAVOR_DIR)-$*/sys/modules/ \ \( -name Makefile -o -name Makefile.inc \) \ -exec sed -i 's@$${.CURDIR}/@@g' \{\} \; ifneq ($(nonfree),) # Use appropriate syntax for GNU uudecode, # only needed for non-free blobs find $(FLAVOR_DIR)-$*/sys/modules/ \ \( -name Makefile -o -name Makefile.inc \) \ -exec sed -i 's/uudecode -p/uudecode -o -/' \{\} \; endif touch $@ build-flavor-%-stamp: src-flavor-%-stamp # Add the abiname and the flavor to the kernel version sed -i -e 's/^RELEASE=".*"/RELEASE="$(version)-$(abiname)-$*"/g' $(FLAVOR_DIR)-$*/sys/conf/newvers.sh # Change ident to the kernel version sed -i -e 's/^i=.*/i="Debian $* ($(full_version))"/g' $(FLAVOR_DIR)-$*/sys/conf/newvers.sh # Set /boot/modules/${RELEASE} as module dir sed -i -e 's,^KODIR?=.*,KODIR="/boot/modules/$(version)-$(abiname)-$*",g' $(FLAVOR_DIR)-$*/sys/conf/kern.pre.mk # Always set explicit link target to match with ld's implicit target (needed # to build on non-kFreeBSD) sed -i \ -e 's/elf32-i386-freebsd/$(ld_target)/g' \ -e 's/elf64-x86-64-freebsd/$(ld_target)/g' \ -e 's/elf32-tradlittlemips-freebsd/$(ld_target)/g' \ -e 's/elf32-tradbigmips-freebsd/$(ld_target)/g' \ $(FLAVOR_DIR)-$*/sys/conf/ldscript.$(kfreebsd_cpu) # Configure the kernel cp -af debian/arch/$(cpu)/$*.config $(FLAVOR_DIR)-$*/sys/$(kfreebsd_cpu)/conf/ echo "# Debian package build options" >> \ $(FLAVOR_DIR)-$*/sys/$(kfreebsd_cpu)/conf/$*.config ifneq ($(debug),no) # Extra debugging options are enabled echo "include DEBIAN_DEBUG" >> \ $(FLAVOR_DIR)-$*/sys/$(kfreebsd_cpu)/conf/$*.config else # Extra debugging options are disabled echo "include DEBIAN_NODEBUG" >> \ $(FLAVOR_DIR)-$*/sys/$(kfreebsd_cpu)/conf/$*.config endif ifeq ($(nonfree),) # Disable non-free drivers echo "include WITHOUT_SOURCELESS" >> \ $(FLAVOR_DIR)-$*/sys/$(kfreebsd_cpu)/conf/$*.config endif ln -sf $*.config $(FLAVOR_DIR)-$*/sys/$(kfreebsd_cpu)/conf/$(configfile) cd $(FLAVOR_DIR)-$*/sys/$(kfreebsd_cpu)/conf \ && config $(configfile) # We must rebuild firmware from sources, per the DFSG CFLAGS='-D_GNU_SOURCE -isystem /usr/include/freebsd' LDFLAGS='-ldb -lbsd' \ $(MAKE) CC=$(cc_cmd) -C $(FLAVOR_DIR)-$*/sys/modules/aic7xxx/ firmware # Build it $(MAKE) CC=$(cc_cmd) -C $(FLAVOR_DIR)-$*/sys/$(kfreebsd_cpu)/compile/$(configfile)/ depend CFLAGS='$(CFLAGS)' \ $(MAKE) CC=$(cc_cmd) -C $(FLAVOR_DIR)-$*/sys/$(kfreebsd_cpu)/compile/$(configfile)/ touch build-flavor-$*-stamp install-common-stamp: dh_testdir dh_testroot mkdir -p $(HEADERS_PACKAGE)/usr/src/$(HEADERS_DIR) find sys -type f -name "*.h" -not -regex ".*modules.*" -not -regex ".*sys/$(kfreebsd_cpu)/.*" -exec cp --parents {} $(HEADERS_PACKAGE)/usr/src/$(HEADERS_DIR) \; mkdir -p $(HEADERS_PACKAGE)/usr/src/$(HEADERS_DIR)/conf cp --parents \ sys/conf/kern.mk \ sys/conf/kmod.mk \ sys/conf/kmod_syms.awk \ sys/kern/bus_if.m \ sys/dev/pci/pci_if.m \ sys/kern/device_if.m \ sys/kern/vnode_if.src \ sys/tools/vnode_if.awk \ sys/tools/makeobjops.awk \ $(HEADERS_PACKAGE)/usr/src/$(HEADERS_DIR) find $(HEADERS_PACKAGE)/usr/src/$(HEADERS_DIR) -type f -exec chmod 644 {} \; find $(HEADERS_PACKAGE)/usr/src/$(HEADERS_DIR)/sys/tools -type f -name "*.awk" -exec chmod 755 {} \; touch install-common-stamp install-arch: $(foreach flavor,$(flavours),install-flavor-$(flavor)-stamp) install-udeb-stamp install-flavor-%-stamp: install-common-stamp build-flavor-%-stamp dh_testdir dh_testroot dh_prep -pkfreebsd-image-$(version)-$(abiname)-$* mkdir -p $(IMAGE_PACKAGE)-$*/{lib/modules,boot/modules/$(version)-$(abiname)-$*} # make the install target happy install -o root -g root -m 644 \ $(FLAVOR_DIR)-$*/sys/$(kfreebsd_cpu)/conf/GENERIC.hints \ $(IMAGE_PACKAGE)-$*/boot/device.hints || touch $(IMAGE_PACKAGE)-$*/boot/device.hints install -o root -g root -m 644 \ $(FLAVOR_DIR)-$*/sys/boot/forth/loader.conf \ $(IMAGE_PACKAGE)-$*/boot/loader.conf mkdir -p $(IMAGE_PACKAGE)-$*/boot/defaults install -o root -g root -m 644 \ $(FLAVOR_DIR)-$*/sys/boot/forth/loader.conf \ $(IMAGE_PACKAGE)-$*/boot/defaults/loader.conf # install the config file install -o root -g root -m 644 \ $(FLAVOR_DIR)-$*/sys/$(kfreebsd_cpu)/conf/$*.config \ $(IMAGE_PACKAGE)-$*/boot/config-$(version)-$(abiname)-$* # now install the kernel $(MAKE) CC=$(cc_cmd) -C $(FLAVOR_DIR)-$*/sys/$(kfreebsd_cpu)/compile/$(configfile) DESTDIR=$(IMAGE_PACKAGE)-$* install mv $(IMAGE_PACKAGE)-$*/boot/modules/$(version)-$(abiname)-$*/kernel $(IMAGE_PACKAGE)-$*/boot/kfreebsd-$(version)-$(abiname)-$* chmod 644 $(IMAGE_PACKAGE)-$*/boot/kfreebsd-$(version)-$(abiname)-$* # Brand kernel image and modules as FreeBSD type, in case not building # on kfreebsd find $(IMAGE_PACKAGE)-$*/boot/modules/$(version)-$(abiname)-$*/ \ -name '*.ko' -exec brandelf -t FreeBSD \{\} \; brandelf -t FreeBSD $(IMAGE_PACKAGE)-$*/boot/kfreebsd-$(version)-$(abiname)-$* gzip -9 -n $(IMAGE_PACKAGE)-$*/boot/kfreebsd-$(version)-$(abiname)-$* -chmod 644 $(IMAGE_PACKAGE)-$*/boot/modules/$(version)-$(abiname)-$*/* ln -sf \ ../../boot/modules/$(version)-$(abiname)-$* \ $(IMAGE_PACKAGE)-$*/lib/modules/$(version)-$(abiname)-$* ifeq ($(DEB_HOST_ARCH_OS), kfreebsd) # Assert linker.hints presence (upstream build system silently skips it when # it can't find kldxref). test -e $(IMAGE_PACKAGE)-$*/lib/modules/$(version)-$(abiname)-$*/linker.hints # FIXME: We're not ready yet. We need to decide what to do about the regressions (e.g. #732692) rm -f $(IMAGE_PACKAGE)-$*/lib/modules/$(version)-$(abiname)-$*/linker.hints endif # Symlink to drm2.ko as provider of drmn.ko dependency, for *kms # modules (#731182) ln -sf drm2.ko $(IMAGE_PACKAGE)-$*/lib/modules/$(version)-$(abiname)-$*/drmn.ko # remove loader.conf (part of kfreebsd-loader) rm -f $(IMAGE_PACKAGE)-$*/boot/loader.conf rm -rf $(IMAGE_PACKAGE)-$*/boot/defaults # remove device.hints (built into kernel) rm -f $(IMAGE_PACKAGE)-$*/boot/device.hints # README file mkdir -p $(IMAGE_PACKAGE)-$*/usr/share/doc/kfreebsd-image-$(version)-$(abiname)-$* install -p -o root -g root -m 644 \ debian/kfreebsd-image.README.Debian \ $(IMAGE_PACKAGE)-$*/usr/share/doc/kfreebsd-image-$(version)-$(abiname)-$*/README.Debian # override file mkdir -p $(IMAGE_PACKAGE)-$*/usr/share/lintian/overrides install -p -o root -g root -m 644 \ debian/kfreebsd-image.overrides \ $(IMAGE_PACKAGE)-$*/usr/share/lintian/overrides/kfreebsd-image-$(version)-$(abiname)-$* # scripts for script in preinst prerm postinst postrm ; do \ sed -e "s/@VERSION@/$(version)/g" \ -e "s/@RELEASE@/$(version)-$(abiname)-$*/g" \ debian/kfreebsd-image.$$script.in \ > debian/kfreebsd-image-$(version)-$(abiname)-$*.$$script ; \ done # headers package mkdir -p $(HEADERS_PACKAGE)-$*/usr/src/$(HEADERS_DIR)-$*/sys/$(kfreebsd_cpu) cd $(FLAVOR_DIR)-$*/sys/$(kfreebsd_cpu) \ && find . -type f -name "*.h" -not -regex ".*modules.*" -exec cp --parents {} $(HEADERS_PACKAGE)-$*/usr/src/$(HEADERS_DIR)-$*/sys/$(kfreebsd_cpu) \; \ && cp -d --parents compile/$(configfile)/machine $(HEADERS_PACKAGE)-$*/usr/src/$(HEADERS_DIR)-$*/sys/$(kfreebsd_cpu) \ && cp -d --parents conf/$(configfile) $(HEADERS_PACKAGE)-$*/usr/src/$(HEADERS_DIR)-$*/sys/$(kfreebsd_cpu) find $(HEADERS_PACKAGE)-$*/usr/src/$(HEADERS_DIR)-$*/sys/$(kfreebsd_cpu) -type f -exec chmod 644 {} \; for dir in `ls $(HEADERS_PACKAGE)/usr/src/$(HEADERS_DIR)/sys` ; do \ ln -s ../../$(HEADERS_DIR)/sys/$$dir $(HEADERS_PACKAGE)-$*/usr/src/$(HEADERS_DIR)-$*/sys/$$dir ; \ done ln -s $(kfreebsd_cpu)/include $(HEADERS_PACKAGE)-$*/usr/src/$(HEADERS_DIR)-$*/sys/machine touch install-flavor-$*-stamp install-udeb-stamp: $(foreach flavor,$(flavours),install-flavor-$(flavor)-stamp) ifeq ($(DEB_HOST_ARCH_OS), kfreebsd) dh_testdir dh_testroot for i in debian/arch/$(DEB_HOST_ARCH_CPU)/*.installer ; do \ subarch=`basename $$i .installer` ; \ dh_prep -pkernel-image-$(version)-$(abiname)-$${subarch}-di ; \ done export KW_DEFCONFIG_DIR=debian/installer ; \ KW_CONFIG_DIR=debian/installer/$(DEB_HOST_ARCH_CPU) kernel-wedge install-files \ $(version)-$(abiname) debian/installer/$(DEB_HOST_ARCH_CPU) for i in debian/arch/$(DEB_HOST_ARCH_CPU)/*.installer ; do \ subarch=`basename $$i .installer` ; \ # override file \n\ mkdir -p $(CURDIR)/debian/zlib-modules-$(version)-$(abiname)-$${subarch}-di/usr/share/lintian/overrides ; \ install -p -o root -g root -m 644 \ debian/zlib-modules.overrides \ $(CURDIR)/debian/zlib-modules-$(version)-$(abiname)-$${subarch}-di/usr/share/lintian/overrides/zlib-modules-$(version)-$(abiname)-$${subarch}-di ; \ # override file \n\ mkdir -p $(CURDIR)/debian/zfs-modules-$(version)-$(abiname)-$${subarch}-di/usr/share/lintian/overrides ; \ install -p -o root -g root -m 644 \ debian/zfs-modules.overrides \ $(CURDIR)/debian/zfs-modules-$(version)-$(abiname)-$${subarch}-di/usr/share/lintian/overrides/zfs-modules-$(version)-$(abiname)-$${subarch}-di ; \ \ # fixup kernel path (so that this udeb can be installed alongside other major versions of kfreebsd) \n\ mv debian/kernel-image-$(version)-$(abiname)-$${subarch}-di/boot/kfreebsd{,-$(major)}.gz ; \ done endif touch $@ # Build architecture-independent files here. binary-indep: build-indep install-indep dh_testdir dh_testroot dh_installdocs -i dh_installchangelogs -i dh_link -i dh_strip -i dh_compress -i dh_fixperms -i dh_makeshlibs -i dh_installdeb -i dh_shlibdeps -i dh_gencontrol -i dh_md5sums -i dh_builddeb -i # Build architecture-dependent files here. binary-arch: build-arch install-arch dh_testdir dh_testroot dh_installdocs -a dh_installchangelogs -a dh_link -a dh_strip -a -X/boot -X/lib/modules dh_compress -a dh_fixperms -a dh_makeshlibs -a dh_installdeb -a dh_shlibdeps -a -X/boot -X/lib/modules dh_gencontrol -a dh_md5sums -a dh_builddeb -a -- -Zxz binary: binary-indep binary-arch .PHONY: clean build build-indep .PHONY: binary-indep binary-arch binary-indep binary-arch binary