summaryrefslogtreecommitdiffstats
path: root/debian/rules
blob: 71b414ffe1ccfda0685ae625fd15d0267f6405d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
#! /usr/bin/make -f
# -*- makefile -*-

#export DH_VERBOSE=1

unexport LANG LC_ALL LC_CTYPE LC_COLLATE LC_TIME LC_NUMERIC LC_MESSAGES

# architecture dependent variables
vafilt = $(subst $(2)=,,$(filter $(2)=%,$(1)))
DPKG_VARS := $(shell dpkg-architecture)
DEB_BUILD_GNU_TYPE	?= $(call vafilt,$(DPKG_VARS),DEB_BUILD_GNU_TYPE)
DEB_HOST_ARCH		?= $(call vafilt,$(DPKG_VARS),DEB_HOST_ARCH)
DEB_HOST_ARCH_OS	?= $(call vafilt,$(DPKG_VARS),DEB_HOST_ARCH_OS)
DEB_HOST_GNU_CPU	?= $(call vafilt,$(DPKG_VARS),DEB_HOST_GNU_CPU)
DEB_HOST_GNU_SYSTEM	?= $(call vafilt,$(DPKG_VARS),DEB_HOST_GNU_SYSTEM)
DEB_HOST_GNU_TYPE	?= $(call vafilt,$(DPKG_VARS),DEB_HOST_GNU_TYPE)
DEB_HOST_MULTIARCH	?= $(call vafilt,$(DPKG_VARS),DEB_HOST_MULTIARCH)

VERSION		:= 4.2
#PKGVERSION	:= $(shell dpkg-parsechangelog \
#			| sed -n '/Version:/s/\(.* \)\(.*\)-2\(.*\)/\2\3/p')
#PKGVERSION	:= 3.0
#dpkg_ctrl_args := -v$(PKGVERSION) -VBinary-Version=$(PKGVERSION)

with_gfdl	= yes

ifneq ($(DEB_HOST_GNU_TYPE),$(DEB_BUILD_GNU_TYPE))
  CC	= $(DEB_HOST_GNU_TYPE)-gcc
else
  CC	= gcc
endif

ifneq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
  STRIP = :
else
  ifneq ($(DEB_HOST_GNU_TYPE),$(DEB_BUILD_GNU_TYPE))
    STRIP = $(DEB_HOST_GNU_TYPE)-strip
  else
    STRIP = strip
  endif
endif


dpkg_buildflags = DEB_BUILD_MAINT_OPTIONS="hardening=+all" DEB_CFLAGS_MAINT_APPEND="-Wall" dpkg-buildflags
CFLAGS := $(shell $(dpkg_buildflags) --get CFLAGS)
CPPFLAGS := $(shell $(dpkg_buildflags) --get CPPFLAGS)
LDFLAGS := $(shell $(dpkg_buildflags) --get LDFLAGS)

SHELL	= /bin/bash
YACC	= bison -y

IX	= install -o 0 -g 0
ID	= install -o 0 -g 0 -m 644

# built with installed libreadline?
with_installed_rl = no

debflags =

p	= bash
p_stat	= bash-static
p_bins	= bash-builtins
p_doc	= bash-doc

d	= debian/$(p)
d_stat	= debian/$(p_stat)
d_bins	= debian/$(p_bins)
d_doc	= debian/$(p_doc)

termcap_lib := $(if $(wildcard /usr/lib/libtinfo.so /usr/lib/$(DEB_HOST_MULTIARCH)/libtinfo.so), \
		 -ltinfo, \
		 -lncurses)

conf_args = \
	--enable-largefile \
	--prefix=/usr \
	--infodir=/usr/share/info \
	--mandir=/usr/share/man \
	--without-bash-malloc
ifeq ($(with_installed_rl),yes)
    conf_args += --with-installed-readline
endif
ifeq ($(DEB_BUILD_GNU_TYPE), $(DEB_HOST_GNU_TYPE))
    conf_args += --build $(DEB_HOST_GNU_TYPE)
else
    conf_args += --build $(DEB_BUILD_GNU_TYPE) --host $(DEB_HOST_GNU_TYPE)
endif

static_conf_args := $(conf_args) \
	--enable-static-link \

#build: bash-build static-build check
build: before-build bash-build static-build check
build-arch: build
build-indep: build

before-build:
	dh_testdir
#	dh_update_autotools_config
	dh_autotools-dev_updateconfig
	mkdir -p stamps
	: # see #327477, needed to have HAVE_DEV_STDIN defined
	(test -d /dev/fd && test -r /dev/stdin < /dev/null) \
	  || (test -d /proc/self/fd && test -r /dev/stdin < /dev/null)
ifneq (,$(findstring $(DEB_HOST_ARCH_OS), linux freebsd))
	$(CC) $(CFLAGS) $(LDFLAGS) $(CPPFLAGS) -o clear_console \
	    debian/clear_console.c $(termcap_lib)
endif

# ---------------------------------------------------------------------------
# build standard bash

bash-build:
	$(MAKE) -f debian/rules do-build-bash \
	    bash_src=. \
	    build=bash \
	    configure_args="$(conf_args)"
bash-configure:
	$(MAKE) -f debian/rules do-configure-bash \
	    bash_src=. \
	    build=bash \
	    configure_args="$(conf_args)"

# ---------------------------------------------------------------------------
# build static bash

static-build:
	$(MAKE) -f debian/rules do-build-static \
	    bash_src=. \
	    build=static \
	    configure_args="$(static_conf_args)"
static-configure:
	$(MAKE) -f debian/rules do-configure-static \
	    bash_src=. \
	    build=static \
	    configure_args="$(static_conf_args)"

# ---------------------------------------------------------------------------

bash-doc-build: stamps/stamp-build-bash-doc
stamps/stamp-build-bash-doc:
	rm -f bash/doc/bashref.info
	$(MAKE) -C build-bash/doc info html MAN2HTML=/usr/bin/man2html
	$(MAKE) -C build-bash/doc bash.pdf bashref.pdf
	touch stamps/stamp-build-bash-doc

# ---------------------------------------------------------------------------

check: stamps/stamp-check
stamps/stamp-check: bash-build
	@echo BEGIN test
ifeq ($(DEB_BUILD_GNU_TYPE),$(DEB_HOST_GNU_TYPE))
  ifeq (,$(findstring nocheck, $(DEB_BUILD_OPTIONS)))
	-sh debian/locale-gen
	LOCPATH=$(CURDIR)/locales \
		time $(MAKE) -C build-bash test 2>&1 | tee build-bash/test-protocol
  endif
else
	@echo Suppress 'make' test, because this is cross build
endif
	@echo END test
	touch stamps/stamp-check

# ---------------------------------------------------------------------------

clean:
	dh_testdir
	dh_testroot
	rm -rf stamps build-*
	rm -f debian/README.Debian
	rm -rf locales
	rm -f clear_console
	dh_autotools-dev_restoreconfig
	dh_clean

# ---------------------------------------------------------------------------


install: bash-install

bash-install: bash-build stamps/stamp-install-bash
stamps/stamp-install-bash: before-build stamps/stamp-build-bash
	dh_testdir
	dh_testroot
	dh_prep -p$(p) -p$(p_doc) -p$(p_bins)
	dh_installdirs -p$(p) \
		bin \
		etc/skel \
		usr/share/doc/$(p)
	dh_installdirs -p$(p_doc) \
		usr/share/doc/$(p)
	dh_installdirs -p$(p_bins) \
		usr/share/doc/$(p)/examples/loadables

ifeq ($(with_gfdl),yes)
# XXXXX
#	cp -p build-bash/doc/*.info bash/doc/
endif

	: # install it
	$(MAKE) -C build-bash install \
		YACC="$(YACC)" \
		DESTDIR=$(CURDIR)/$(d)
	mv $(d)/usr/bin/bash $(d)/bin/.
	chmod 755 $(d)/usr/bin/bashbug
	$(ID) debian/bashbug.1 $(d)/usr/share/man/man1/
ifneq ($(with_gfdl),yes)
	mkdir -p $(d)/usr/share/man/man1
	cp -p bash/doc/bash.1 $(d)/usr/share/man/man1/bash.1
endif
	rm -f $(d)/usr/share/doc/bash/*.html
	rm -f $(d)/usr/share/info/*.info
	rm -f $(d)/usr/share/info/dir*

	: # extra links
	ln -sf bash $(d)/bin/rbash

	: # skeleton files
	$(ID) debian/etc.bash.bashrc $(d)/etc/bash.bashrc
	$(ID) debian/skel.bashrc $(d)/etc/skel/.bashrc
	$(ID) debian/skel.profile $(d)/etc/skel/.profile
	$(ID) debian/skel.bash_logout $(d)/etc/skel/.bash_logout

	: # clean_console
ifneq (,$(findstring $(DEB_HOST_ARCH_OS), linux freebsd))
	$(IX) clear_console $(d)/usr/bin/
	$(ID) debian/clear_console.1 $(d)/usr/share/man/man1/
endif

	: # /etc/shells integration
	$(ID) -D debian/shells.d/bash $(d)/usr/share/debianutils/shells.d/bash

	: # files for the bash-doc package

	dh_installexamples -p$(p_doc) examples/*
	rm -rf $(d_doc)/usr/share/doc/$(p)/examples/loadables
	mkdir -p $(d_doc)/usr/share/doc/$(p_doc)
	ln -sf ../$(p)/examples $(d_doc)/usr/share/doc/$(p_doc)/examples

	rm -rf $(d_doc)/usr/share/doc/$(p)/examples/obashdb
	cd $(d_doc)/usr/share/doc/$(p)/examples && chmod 755 \
		misc/aliasconv.*sh misc/cshtobash

	cd $(d_doc)/usr/share/doc/$(p)/examples && chmod 644 \
		scripts/shprompt

	: # files for the bash-builtins package
	mv $(d)/usr/include $(d_bins)/usr/.
	mv $(d)/usr/lib $(d_bins)/usr/.
	$(ID) examples/loadables/{README,*.c} \
		$(d_bins)/usr/share/doc/$(p)/examples/loadables
	$(ID) build-bash/examples/loadables/Makefile \
		$(d_bins)/usr/share/doc/$(p)/examples/loadables
	ln -sf bash $(d_bins)/usr/share/doc/$(p_bins)

	sed -i \
		-e 's@-ffile-prefix-map=[^ ]*[ ]*@@g' \
		-e 's@-fdebug-prefix-map=[^ ]*[ ]*@@g' \
		-e 's@^BUILD_DIR =.*@BUILD_DIR = /path/to/build-dir@' \
		$(d)/usr/bin/bashbug \
		$(d_bins)/usr/lib/bash/Makefile.inc \
		$(d_bins)/usr/share/doc/$(p)/examples/loadables/Makefile

#	cat debian/README stamps/stamp-patch > debian/README.Debian
	cat debian/README > debian/README.Debian

	touch stamps/stamp-install-bash

binary-doc: bash-install bash-doc-build
	dh_testdir
	dh_testroot
	mkdir -p $(d_doc)/usr/share/doc/$(p)
ifeq ($(with_gfdl),yes)
	dh_installdocs -p$(p_doc) 
	cp -p build-bash/doc/bashref.{html,pdf} $(d_doc)/usr/share/doc/$(p)/.
	mkdir -p $(d_doc)/usr/share/info
	cp -p build-bash/doc/bash.info $(d_doc)/usr/share/info/.
	dh_link -p$(p_doc) \
	    /usr/share/doc/$(p)/bashref.html /usr/share/doc/$(p_doc)/bashref.html \
	    /usr/share/doc/$(p)/bashref.pdf /usr/share/doc/$(p_doc)/bashref.pdf
else
	dh_installdocs -p$(p_doc) -X.doc-base
	rm -f $(d_doc)/usr/share/doc-base/bashref
endif
	rm -f $(d_doc)/usr/share/info/dir*
	cp -p build-bash/doc/bash.html build-bash/doc/bash.pdf \
	    $(d_doc)/usr/share/doc/$(p)/
	dh_link -p$(p_doc) \
	    /usr/share/doc/$(p)/bash.html /usr/share/doc/$(p_doc)/bash.html \
	    /usr/share/doc/$(p)/bash.pdf /usr/share/doc/$(p_doc)/bash.pdf
	dh_installchangelogs -p$(p_doc) CWRU/changelog
	dh_compress -p$(p_doc) -Xexamples -X.pdf
	dh_fixperms -p$(p_doc)
	dh_installdeb -p$(p_doc)
	dh_gencontrol -p$(p_doc)
	dh_md5sums -p$(p_doc)
	dh_builddeb -p$(p_doc)

binary-bash: bash-install
	dh_testdir
	dh_testroot
	dh_installchangelogs -p$(p)
	dh_installdocs -p$(p) \
		CHANGES NEWS COMPAT doc/INTRO POSIX \
		debian/{README.Debian,README.abs-guide,README.commands} \
		debian/inputrc.arrows
	install -D -m 644 debian/bash.overrides \
		debian/bash/usr/share/lintian/overrides/bash
	install -D -m 644 debian/bash-builtins.overrides \
		debian/bash-builtins/usr/share/lintian/overrides/bash-builtins
	dh_installman -p$(p) doc/rbash.1 debian/bash-builtins.7
	dh_installmenu -p$(p)
	dh_strip -p$(p)
	dh_compress -p$(p)
	dh_fixperms -p$(p)
	dh_shlibdeps -p$(p) -- -dPre-Depends $(d)/bin/bash
	dh_installdeb -p$(p)
	dh_gencontrol -p$(p)
	dh_md5sums -p$(p)
	dh_builddeb -p$(p)

# Even though it contains only headers and example files,
# bash-builtins is NOT arch-independent because the config.h* files
# differ on different archs.
binary-builtins: bash-install
	dh_testdir
	dh_testroot
	dh_strip -p$(p_bins)
	dh_compress -p$(p_bins) -Xexamples
	dh_fixperms -p$(p_bins)
	dh_installdeb -p$(p_bins)
	dh_gencontrol -p$(p_bins)
	dh_md5sums -p$(p_bins)
	dh_builddeb -p$(p_bins)

binary-static: static-build
	dh_testdir
	dh_testroot
	dh_prep -p$(p_stat)
	dh_installdirs -p$(p_stat) \
		bin \
		usr/share/man/man1
	cp -p build-static/bash $(d_stat)/bin/bash-static
	cp -p doc/bash.1 $(d_stat)/usr/share/man/man1/bash-static.1
	$(ID) -D debian/shells.d/bash-static $(d_stat)/usr/share/debianutils/shells.d/bash-static
	dh_installdocs -p$(p_stat)
	dh_installchangelogs -p$(p_stat)
	install -D -m 644 debian/bash-static.overrides \
		debian/bash-static/usr/share/lintian/overrides/bash-static
	dh_strip -p$(p_stat)
	dh_compress -p$(p_stat)
	dh_fixperms -p$(p_stat)
	dh_installdeb -p$(p_stat)
	dh_gencontrol -p$(p_stat) -- \
		'-Vglibc:Source=$(shell dpkg-query -f '$${source:Package} (= $${source:Version}), ' -W libc-bin)'
	dh_md5sums -p$(p_stat)
	dh_builddeb -p$(p_stat)

binary-indep: binary-doc
binary-arch: binary-bash binary-builtins binary-static
binary:	binary-indep binary-arch

# ---------------------------------------------------------------------------
# common rules for all bash build variations

do-build-$(build): stamps/stamp-build-$(build)
stamps/stamp-build-$(build): stamps/stamp-configure-$(build)
	dh_testdir
ifneq (,$(profiled_build))
	$(MAKE) -C build-$(build) \
		CFLAGS='$(CFLAGS) -fprofile-generate' \
		YACC="$(YACC)" \
		TERMCAP_LIB="$(termcap_lib)" \
		deb_builddir=build-$(build)/ \
		$(debflags)
	-sh debian/locale-gen
	cp debian/run-my-gprof bash/tests/
	LOCPATH=$(CURDIR)/locales \
	    time $(MAKE) -C build-$(build) TESTSCRIPT=run-my-gprof test 2>&1 \
		| tee build-bash/profile-protocol
	$(MAKE) -C build-$(build) clean
	rm -f build-$(build)/lib/malloc/malloc*.gc??
	$(MAKE) -C build-$(build) \
		CFLAGS='$(CFLAGS) -fprofile-use' \
		YACC="$(YACC)" \
		TERMCAP_LIB="$(termcap_lib)" \
		deb_builddir=build-$(build)/ \
		$(debflags)
else
	$(MAKE) -C build-$(build) \
		YACC="$(YACC)" \
		TERMCAP_LIB="$(termcap_lib)" \
		deb_builddir=build-$(build)/ \
		$(debflags)
endif
ifeq ($(with_gfdl),yes)
	$(MAKE) -C build-$(build)/doc \
		bash.info
endif
	touch stamps/stamp-build-$(build)

do-configure-$(build): stamps/stamp-configure-$(build)
stamps/stamp-configure-$(build):
	dh_testdir
	rm -rf build-$(build)
	mkdir build-$(build)
	cd build-$(build) && \
	    CC="$(CC)" \
	    CFLAGS="$(CFLAGS)" CPPFLAGS="$(CPPFLAGS)" LDFLAGS="$(LDFLAGS)" \
	    YACC="$(YACC)" \
		../$(bash_src)/configure $(configure_args)
	if ! grep -q '#define HAVE_DEV_STDIN 1' build-$(build)/config.h; then \
	  echo "HAVE_DEV_STDIN not defined, abortig build"; \
	  exit 1; \
	fi
	touch stamps/stamp-configure-$(build)

update-patches:
	export QUILT_PATCHES=$(patchdir); \
	export QUILT_REFRESH_ARGS="--no-timestamps --no-index -p ab"; \
	export QUILT_DIFF_ARGS="--no-timestamps --no-index -p ab"; \
	while quilt push; do quilt refresh; done

#unpack-$(bash_src): stamps/stamp-unpack-$(bash_src)
#stamps/stamp-unpack-$(bash_src):
#	mkdir -p stamps
#	rm -rf bash-$(VERSION) $(bash_src)
#	rm -f stamps/stamp-patch-$(bash_src){,-*}
#	tar xf bash-$(VERSION)*.tar.xz
#	mv bash-$(VERSION) $(bash_src)
#	rm -f bash/y.tab.?
#	cp -p /usr/share/misc/config.* $(bash_src)/.
#	cp -p /usr/share/misc/config.* $(bash_src)/support/.
#	touch stamps/stamp-unpack-$(bash_src)

remove-non-dfsg-files:
	rm -f doc/article.*
	rm -f doc/FAQ
	rm -f doc/aosa-bash*.pdf
	rm -f doc/rose94.*

.NOTPARALLEL: build
.PHONY: unpack binary binary-arch binary-indep clean \
    build bash-build static-build \
    check \
    bash-configure static-configure \
    binary-doc binary-bash binary-builtins binary-static \
    install bash-install

# Local Variables:
# mode: makefile
# end: