use more pre-baked dpkg Makefile snippets in rules file
[debian/gzip] / debian / rules
index 931925b2451278f3f55bac8632c5fd6376f8635f..47273f11eb2c029a3cb46af718e51960a884ab94 100755 (executable)
 #!/usr/bin/make -f
 #      Debian rules file for gzip, requires the debhelper package.
 #      Crafted by Bdale Garbee, bdale@gag.com, 5 November 2000
+#      Cleanup by Thorsten Glaser, tg@debian.org, 20 June 2012
+#      based on the rules file of the jupp package
 
 # Comment this to turn off debhelper verbose mode.
 export DH_VERBOSE=1
 
-DEB_BUILD_GNU_TYPE = $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
-DEB_HOST_GNU_TYPE = $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
-ifneq ($(DEB_BUILD_GNU_TYPE),$(DEB_HOST_GNU_TYPE))
-CONFARGS = --host=$(DEB_HOST_GNU_TYPE)
+shellescape='$(subst ','\'',$(1))'
+shellexport=$(1)=$(call shellescape,${$(1)})
+
+include /usr/share/dpkg/architecture.mk
+
+# Automatic ${CC} selection for cross-compiles
+
+# is ${CC} defined anywhere (other than implicit rules?)
+ifneq (,$(findstring $(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
+
+export DEFS=NO_ASM # Avoid TEXTRELs on i386
+DEB_CFLAGS_MAINT_APPEND := -Wall
+DEB_CPPFLAGS_MAINT_APPEND := -DUNALIGNED_OK
+
+# Automatic dpkg-buildflags selection, backport-friendly
+
+# maybe turn this on later
+#DEB_BUILD_MAINT_OPTIONS=hardening=+all
+include /usr/share/dpkg/buildflags.mk
+
+# maybe turn this on later
+#ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
+#NUMJOBS=              $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
+#MAKEFLAGS+=           -j${NUMJOBS}
+#endif
+
+# whitespace-safe path to source directory
+_topdir=$(call shellescape,$(shell pwd))
+
+CONFIGURE_ARGS=                --prefix=/usr \
+                       --bindir=/bin \
+                       --infodir=${_topdir}/debian/gzip/usr/share/info \
+                       --mandir=${_topdir}/debian/gzip/usr/share/man \
+                       --disable-silent-rules
+
+ifneq (${DEB_BUILD_ARCH},${DEB_HOST_ARCH})
+CONFIGURE_ARGS+=       --host=${DEB_HOST_GNU_TYPE}
 endif
 
-CFLAGS="-g -O2 -Wall" 
+reconf-stamp:
+       cp -f /usr/share/misc/config.sub build-aux/config.sub
+       cp -f /usr/share/misc/config.guess build-aux/config.guess
+       autoreconf -v
+       :>$@
 
 configure: configure-stamp
-configure-stamp:
+configure-stamp: reconf-stamp
        dh_testdir
-       CFLAGS=$(CFLAGS) ./configure \
-               --prefix=/usr --bindir=/bin \
-               --infodir=`pwd`/debian/gzip/usr/share/info \
-               --mandir=`pwd`/debian/gzip/usr/share/man $(CONFARGS)
-       touch configure-stamp
-
-build: configure-stamp build-stamp
-build-stamp:
+       mkdir -p builddir
+       cd builddir && env \
+           $(foreach i,CC CFLAGS CPPFLAGS LDFLAGS,$(call shellexport,$i)) \
+           CONFIG_SHELL=/bin/sh GREP=grep ../configure ${CONFIGURE_ARGS}
+       :>$@
+
+configure-indep: configure-indep-stamp
+configure-indep-stamp: reconf-stamp
+       dh_testdir
+       mkdir -p builddir-indep
+       cd builddir-indep && ../configure --host=i686-w64-mingw32 \
+               LIBS="-Wl,--as-needed -lssp" --disable-silent-rules
+       :>$@
+
+build: build-stamp build-indep-stamp
+
+build-arch: build-stamp
+build-stamp: configure-stamp
+       dh_testdir
+       ${MAKE} -C builddir
+ifeq (,$(filter nocheck,${DEB_BUILD_OPTIONS}))
+ifeq (${DEB_BUILD_ARCH},${DEB_HOST_ARCH})
+       ${MAKE} -C builddir check
+endif
+endif
+       :>$@
+
+build-indep: build-indep-stamp
+build-indep-stamp: configure-indep-stamp
        dh_testdir
-       $(MAKE)
-       touch build-stamp
+       ${MAKE} -C builddir-indep
+       :>$@
 
 clean:
        dh_testdir
        dh_testroot
-       -rm -f build-stamp configure-stamp
-       make distclean || exit 0
+       -rm -f build-stamp build-indep-stamp configure-stamp configure-indep-stamp reconf-stamp
+       -rm -rf builddir builddir-indep
        dh_clean
 
-install: build
+binary: binary-arch binary-indep
+
+binary-indep: build-indep-stamp
        dh_testdir
        dh_testroot
-       dh_clean -k
+       dh_prep
        dh_installdirs
+       i686-w64-mingw32-strip builddir-indep/gzip.exe
+       install -m 0755 builddir-indep/gzip.exe \
+           debian/gzip-win32/usr/share/win32/
+       dh_installdocs -i README* TODO NEWS
+       dh_installchangelogs -i ChangeLog
+       dh_lintian -i
+       dh_compress -i
+       dh_fixperms -i
+       dh_installdeb -i
+       dh_gencontrol -i
+       dh_md5sums -i
+       dh_builddeb -i
 
-       make install prefix=debian/gzip/usr bindir=debian/gzip/bin 
-       install -o root -g root -m 0644 debian/gzip.lintian \
-               debian/gzip/usr/share/lintian/overrides/gzip
-
-binary-indep:  build install
-
-binary-arch:   build install
+binary-arch: build-stamp
        dh_testdir
        dh_testroot
-       dh_installdocs README* TODO
-       dh_installmanpages
-       dh_installinfo doc/gzip.info
-       dh_installchangelogs ChangeLog
-       dh_link
-       dh_strip
-       dh_compress
+       dh_prep
+       dh_installdirs
+       ${MAKE} -C builddir install \
+           prefix=${_topdir}/debian/gzip/usr \
+           bindir=${_topdir}/debian/gzip/bin
+       dh_testdir -a
+       dh_testroot -a
+       dh_installdocs -a README* TODO NEWS
+       dh_installman *.1
+       dh_installinfo -a doc/gzip.info
+       dh_installchangelogs -a ChangeLog
+       dh_link -a
+       dh_lintian -a
+       dh_strip -a
+       dh_compress -a
        ln -s gunzip.1.gz debian/gzip/usr/share/man/man1/uncompress.1.gz
        ln -s zgrep.1.gz debian/gzip/usr/share/man/man1/zegrep.1.gz
        ln -s zgrep.1.gz debian/gzip/usr/share/man/man1/zfgrep.1.gz
-       dh_fixperms
-       # You may want to make some executables suid here.
-       dh_makeshlibs
-       dh_installdeb
-       dh_shlibdeps
-       dh_gencontrol
-       dh_md5sums
-       dh_builddeb
-
-binary: binary-indep binary-arch
-.PHONY: build clean binary-indep binary-arch binary install configure
+       rm -f ${_topdir}/debian/gzip/usr/share/info/dir.gz
+       dh_fixperms -a
+       dh_makeshlibs -a
+       dh_installdeb -a
+       dh_shlibdeps -a
+       dh_gencontrol -a
+       dh_md5sums -a
+       dh_builddeb -a
 
+.PHONY: binary binary-arch binary-indep build build-arch build-indep clean
+.PHONY: configure configure-indep