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