9f9c91fce608a05075f13df97e01f0fc2e4460c6
[alioth/jupp.git] / debian / rules
1 #!/usr/bin/make -f
2 #-
3 # Possible flavourisation (in addition to stock Debian rules):
4 # export DEB_BUILD_OPTIONS=diet
5 # export DEB_BUILD_OPTIONS=klibc
6 # export DEB_BUILD_OPTIONS=klibc CC='klcc -shared'
7 # export DEB_BUILD_OPTIONS='diet debug' (or 'klibc debug')
8 # export DEB_BUILD_OPTIONS=static (for eglibc)
9 # All can be combined with 'nopwnam' (aids static linkage).
10 # The 'nostrip' and 'parallel=n' options are supported as well.
11 #
12 # Setting diet or klibc disables -O0/-O2 and -g and, if unset,
13 # sets CC. Adding debug enables -g3. Cross-compiling also sets
14 # CC if unset.
15 #
16 # Statically linking violates the Policy requirement of having a
17 # Built-Using header, but since that is only used in local rebuilds
18 # and not in the Debian archive, it constitutes no Policy violation.
19
20 shellescape='$(subst ','\'',$(1))'
21 shellexport=$(1)=$(call shellescape,${$(1)})
22
23 ifeq (,$(findstring diet,${DEB_BUILD_OPTIONS}))
24 ifeq (,$(findstring klibc,${DEB_BUILD_OPTIONS}))
25 USE_LIBC:=system
26 else
27 USE_LIBC:=klibc
28 endif
29 else
30 USE_LIBC:=dietlibc
31 endif
32
33 DEB_BUILD_ARCH=$(shell dpkg-architecture -qDEB_BUILD_ARCH)
34 DEB_HOST_ARCH=$(shell dpkg-architecture -qDEB_HOST_ARCH)
35 DEB_HOST_GNU_TYPE=$(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
36
37 # is ${CC} defined anywhere (other than implicit rules?)
38 ifneq (,$(findstring $(origin CC),default undefined))
39 # no - then default to gcc (or cross-gcc)
40 ifneq (${DEB_BUILD_ARCH},${DEB_HOST_ARCH})
41 CC=                     ${DEB_HOST_GNU_TYPE}-gcc
42 else
43 ifeq (,$(findstring diet,${DEB_BUILD_OPTIONS}))
44 ifeq (,$(findstring klibc,${DEB_BUILD_OPTIONS}))
45 CC=                     gcc
46 else
47 # export CC='klcc -shared' manually if you want that
48 CC=                     klcc
49 endif
50 else
51 CC=                     diet -Os gcc
52 endif
53 endif
54 endif
55
56 EXTRA_CFLAGS+=          -Wall -Wformat
57 EXTRA_CFLAGS+=          -fno-omit-frame-pointer -fwrapv -fno-strict-aliasing
58 # adjust when backporting
59 EXTRA_CFLAGS+=          -Wextra -Wno-pointer-sign -Wno-unused-parameter \
60                         -Wno-missing-field-initializers \
61                         -Wno-old-style-definition -Wno-strict-prototypes \
62                         -Wno-cast-qual \
63                         -Wno-missing-prototypes -Wno-missing-declarations
64 EXTRA_LDFLAGS=          -Wl,--as-needed
65
66 ifneq (${USE_LIBC},system)
67 ifneq (,$(findstring debug,${DEB_BUILD_OPTIONS}))
68 EXTRA_CFLAGS+=          -g3
69 endif
70 # SSP currently works with neither dietlibc nor klibc
71 EXTRA_CFLAGS+=          -fno-stack-protector
72 else
73 ifneq (,$(findstring static,${DEB_BUILD_OPTIONS}))
74 EXTRA_LDFLAGS+=         -static
75 endif
76 endif
77
78 ifneq (,$(wildcard /usr/share/dpkg/buildflags.mk))
79 # dpkg-dev (>= 1.16.1~)
80 DEB_CFLAGS_MAINT_APPEND=${EXTRA_CFLAGS}
81 DEB_LDFLAGS_MAINT_APPEND=${EXTRA_LDFLAGS}
82 ifneq (${USE_LIBC},system)
83 # the diet and klcc wrappers take care of optimisation for us
84 DEB_CFLAGS_MAINT_STRIP=-O -O0 -O1 -O2 -O3 -Os -Ofast -Og -g -g1 -g2 -g3 -ggdb -gdwarf -gstabs
85 # do not use PIE with strange libcs, either
86 DEB_BUILD_MAINT_OPTIONS=hardening=+all,-pie
87 else
88 ifneq (,$(findstring static,${DEB_BUILD_OPTIONS}))
89 # cannot mix PIE with static linkage
90 DEB_BUILD_MAINT_OPTIONS=hardening=+all,-pie
91 else
92 DEB_BUILD_MAINT_OPTIONS=hardening=+all
93 endif
94 endif
95 include /usr/share/dpkg/buildflags.mk
96 else
97 # old-fashioned way to determine build flags
98 ifneq (${USE_LIBC},system)
99 CFLAGS=
100 else
101 CFLAGS=                 -O$(if $(findstring noopt,${DEB_BUILD_OPTIONS}),0,2) -g
102 endif
103 CFLAGS+=                ${EXTRA_CFLAGS}
104 LDFLAGS+=               ${EXTRA_LDFLAGS}
105 endif
106
107 ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
108 NUMJOBS=                $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
109 MAKEFLAGS+=             -j${NUMJOBS}
110 endif
111
112 CONFIGURE_ARGS=         --prefix=/usr \
113                         --sysconfdir=/etc \
114                         --mandir=/usr/share/man \
115                         --disable-dependency-tracking
116
117 ifneq (${USE_LIBC},system)
118 # prevent picking up system libraries linked against the system C library
119 CONFIGURE_ARGS+=        --disable-search-libs
120 endif
121
122 ifneq (,$(findstring nopwnam,${DEB_BUILD_OPTIONS}))
123 CONFIGURE_ARGS+=        --disable-getpwnam
124 endif
125
126 CONFIGURE_ARGS+=        --disable-termidx \
127                         --enable-sysconfjoesubdir=/jupp
128
129 debian/.configure_stamp:
130         dh_testdir
131         -rm -f debian/.*_stamp
132         -rm -rf builddir
133         # apply autotools-dev if it exists
134         for x in config.guess config.sub; do \
135                 test -e /usr/share/misc/$$x || continue; \
136                 rm -f $$x; \
137                 cp /usr/share/misc/$$x .; \
138         done
139         mkdir builddir
140         cd builddir && env \
141             $(foreach i,CC CFLAGS CPPFLAGS LDFLAGS,$(call shellexport,$i)) \
142             sh ../configure ${CONFIGURE_ARGS}
143         @:>$@
144
145 debian/.build_stamp: debian/.configure_stamp
146         dh_testdir
147         cd builddir && ${MAKE}
148         ln -f builddir/joe builddir/jupp
149         ln -f builddir/joe.1 builddir/jupp.1
150         @:>$@
151
152 build: build-arch build-indep
153 build-arch: debian/.build_stamp
154 build-indep: debian/.configure_stamp
155
156 clean:
157         dh_testdir
158         -rm -f debian/.*_stamp
159         -rm -rf builddir
160         # unapply autotools-dev if it exists
161         for x in config.guess config.sub; do \
162                 test -e /usr/share/misc/$$x || continue; \
163                 rm -f $$x; \
164         done
165         dh_clean
166
167 binary-indep: build-indep
168         dh_testdir
169         dh_testroot
170         if test -x "$$(which dh_prep)"; then dh_prep -i; else dh_clean -i -k; fi
171         dh_installchangelogs -i -Njupp
172         dh_install -i
173         dh_installmenu -i
174         # will be replaced by links to jupp
175         rm -rf debian/joe-jupp/usr/share/doc/joe-jupp
176         dh_link -i
177         dh_fixperms -i
178         dh_installdeb -i
179         dh_gencontrol -i
180         dh_md5sums -i
181         dh_builddeb -i
182
183 # no -Njupp because that's the only arch:any package
184 binary-arch: build-arch
185         dh_testdir
186         dh_testroot
187         if test -x "$$(which dh_prep)"; then dh_prep -a; else dh_clean -a -k; fi
188         dh_installchangelogs -pjupp -k NEWS
189         dh_installdocs -a
190         dh_install -a
191         dh_installmenu -a
192         dh_installman -a
193         dh_link -a
194         dh_strip -a
195         dh_compress -a
196         dh_fixperms -a
197         dh_installdeb -a
198         dh_shlibdeps -a
199         dh_gencontrol -a
200         dh_md5sums -a
201         dh_builddeb -a
202
203 binary: binary-arch binary-indep
204
205 .PHONY: binary binary-arch binary-indep build build-arch build-indep clean