crazy klibc experiment (likely to fail)
[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 -msse
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 DEB_CFLAGS_MAINT_STRIP+=-specs=/usr/share/dpkg/no-pie-compile.specs
87 DEB_LDFLAGS_MAINT_STRIP+=-specs=/usr/share/dpkg/no-pie-link.specs
88 # do not use PIE with strange libcs, either
89 DEB_BUILD_MAINT_OPTIONS=hardening=+all,-pie
90 else
91 ifneq (,$(findstring static,${DEB_BUILD_OPTIONS}))
92 # cannot mix PIE with static linkage
93 DEB_BUILD_MAINT_OPTIONS=hardening=+all,-pie
94 else
95 DEB_BUILD_MAINT_OPTIONS=hardening=+all
96 endif
97 endif
98 include /usr/share/dpkg/buildflags.mk
99 else
100 # old-fashioned way to determine build flags
101 ifneq (${USE_LIBC},system)
102 CFLAGS=
103 else
104 CFLAGS=                 -O$(if $(findstring noopt,${DEB_BUILD_OPTIONS}),0,2) -g
105 endif
106 CFLAGS+=                ${EXTRA_CFLAGS}
107 LDFLAGS+=               ${EXTRA_LDFLAGS}
108 endif
109
110 ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
111 NUMJOBS=                $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
112 MAKEFLAGS+=             -j${NUMJOBS}
113 endif
114
115 CONFIGURE_ARGS=         --build=${DEB_BUILD_GNU_TYPE} \
116                         --host=${DEB_HOST_GNU_TYPE} \
117                         --prefix=/usr \
118                         --sysconfdir=/etc \
119                         --mandir=/usr/share/man \
120                         --disable-dependency-tracking
121
122 ifneq (${USE_LIBC},system)
123 # prevent picking up system libraries linked against the system C library
124 CONFIGURE_ARGS+=        --disable-search-libs
125 endif
126
127 ifneq (,$(findstring nopwnam,${DEB_BUILD_OPTIONS}))
128 CONFIGURE_ARGS+=        --disable-getpwnam
129 endif
130
131 CONFIGURE_ARGS+=        --disable-termidx \
132                         --enable-sysconfjoesubdir=/jupp
133
134 debian/.configure_stamp:
135         dh_testdir
136         -rm -f debian/.*_stamp
137         -rm -rf builddir
138         # apply autotools-dev if it exists
139         for x in config.guess config.sub; do \
140                 test -e /usr/share/misc/$$x || continue; \
141                 rm -f $$x; \
142                 cp /usr/share/misc/$$x .; \
143         done
144         mkdir builddir
145         cd builddir && exec env \
146             $(foreach i,CC CFLAGS CPPFLAGS LDFLAGS,$(call shellexport,$i)) \
147             sh ../configure ${CONFIGURE_ARGS}
148         @:>$@
149
150 debian/.build_stamp: debian/.configure_stamp
151         dh_testdir
152         cd builddir && exec ${MAKE}
153         ln -f builddir/joe builddir/jupp
154         ln -f builddir/joe.1 builddir/jupp.1
155         @:>$@
156
157 build: build-arch build-indep
158 build-arch: debian/.build_stamp
159 build-indep: debian/.configure_stamp
160
161 clean:
162         dh_testdir
163         -rm -f debian/.*_stamp
164         -rm -rf builddir
165         # unapply autotools-dev if it exists
166         for x in config.guess config.sub; do \
167                 test -e /usr/share/misc/$$x || continue; \
168                 rm -f $$x; \
169         done
170         dh_clean
171
172 binary-indep: build-indep
173         dh_testdir
174         dh_testroot
175         if test -x "$$(which dh_prep)"; then dh_prep -i; else dh_clean -i -k; fi
176         dh_installchangelogs -i -Njupp
177         dh_install -i
178         dh_installmenu -i
179         # will be replaced by links to jupp
180         rm -rf debian/joe-jupp/usr/share/doc/joe-jupp
181         dh_link -i
182         dh_fixperms -i
183         dh_installdeb -i
184         dh_gencontrol -i
185         dh_md5sums -i
186         dh_builddeb -i
187
188 # no -Njupp because that's the only arch:any package
189 binary-arch: build-arch
190         dh_testdir
191         dh_testroot
192         if test -x "$$(which dh_prep)"; then dh_prep -a; else dh_clean -a -k; fi
193         dh_installchangelogs -pjupp -k NEWS
194         dh_installdocs -a
195         dh_install -a
196         dh_installmenu -a
197         dh_installman -a
198         dh_link -a
199         dh_strip -a
200         dh_compress -a
201         dh_fixperms -a
202         dh_installdeb -a
203         dh_shlibdeps -a
204         dh_gencontrol -a
205         dh_md5sums -a
206         dh_builddeb -a
207
208 binary: binary-arch binary-indep
209
210 .PHONY: binary binary-arch binary-indep build build-arch build-indep clean