7478b4ae5df63c41afd537a3b55184e212ab64bc
[alioth/rs.git] / debian / rules
1 #!/usr/bin/make -f
2
3 DEB_BUILD_ARCH=$(shell dpkg-architecture -qDEB_BUILD_ARCH)
4 DEB_HOST_ARCH=$(shell dpkg-architecture -qDEB_HOST_ARCH)
5 ifneq (${DEB_BUILD_ARCH},${DEB_HOST_ARCH})
6 DEB_HOST_GNU_TYPE=$(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
7 endif
8
9 # is ${CC} defined anywhere (other than implicit rules?)
10 ifneq (,$(findstring $(origin CC),default undefined))
11 # no - then default to gcc (or cross-gcc)
12 ifneq (${DEB_BUILD_ARCH},${DEB_HOST_ARCH})
13 CC=                     ${DEB_HOST_GNU_TYPE}-gcc
14 else
15 CC=                     gcc
16 endif
17 endif
18
19 EXTRA_CFLAGS=           -Wall -Wextra -Wformat
20 EXTRA_CPPFLAGS=         -DUSE_LIBBSD
21 EXTRA_LDFLAGS=          -Wl,--as-needed
22
23 ifneq (,$(wildcard /usr/share/dpkg/buildflags.mk))
24 # dpkg-dev (>= 1.16.1~)
25 dpkgbuildflagsmkescape=$(subst \,\\\,$(1))
26 DEB_CFLAGS_MAINT_APPEND=$(call dpkgbuildflagsmkescape,${EXTRA_CFLAGS})
27 DEB_CPPFLAGS_MAINT_APPEND=$(call dpkgbuildflagsmkescape,${EXTRA_CPPFLAGS})
28 DEB_LDFLAGS_MAINT_APPEND=$(call dpkgbuildflagsmkescape,${EXTRA_LDFLAGS})
29 DEB_BUILD_MAINT_OPTIONS=hardening=+all
30 include /usr/share/dpkg/buildflags.mk
31 else
32 # old-fashioned way to determine build flags
33 CFLAGS=                 -O$(if $(findstring noopt,${DEB_BUILD_OPTIONS}),0,2) -g
34 CFLAGS+=                ${EXTRA_CFLAGS}
35 CPPFLAGS+=              ${EXTRA_CPPFLAGS}
36 LDFLAGS+=               ${EXTRA_LDFLAGS}
37 endif
38
39 LDADD+=                 -lbsd
40
41 build build-arch: rs
42 build-indep:
43
44 rs:
45         dh_testdir
46         -rm -f rs
47         ${CC} ${CPPFLAGS} ${CFLAGS} ${LDFLAGS} -o rs rs.c ${LDADD}
48         test -x rs
49 ifeq (,$(filter nocheck,${DEB_BUILD_OPTIONS}))
50         case $$(for i in 1 2 3 4 5 6 7 8 9; do echo $$i; done | \
51             ./rs 3 3 | md5sum) in \
52         d37c2eb45172c55279711a8e53041912*) echo pass test;; \
53         *) rm -f rs; echo FAIL test;; \
54         esac; test -x rs
55 endif
56
57 clean:
58         dh_testdir
59         -rm -f rs
60         dh_clean
61
62 binary-indep: build-indep
63
64 binary-arch: build-arch
65         dh_testdir
66         dh_testroot
67         if test -x "$$(which dh_prep)"; then dh_prep; else dh_clean -k; fi
68         dh_installchangelogs
69         dh_installdocs
70         dh_install
71         dh_installman
72         dh_link
73         dh_strip
74         dh_compress
75         dh_fixperms
76         dh_installdeb
77         dh_shlibdeps
78         dh_gencontrol
79         dh_md5sums
80         dh_builddeb
81
82 binary: binary-indep binary-arch
83 .PHONY: binary binary-arch binary-indep build build-arch build-indep clean