File: rules

package info (click to toggle)
perl 5.24.1-3+deb9u5
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 103,716 kB
  • sloc: perl: 559,611; ansic: 293,886; sh: 67,316; pascal: 7,632; cpp: 3,895; makefile: 2,436; xml: 2,410; yacc: 989; sed: 6; lisp: 1
file content (619 lines) | stat: -rwxr-xr-x 22,185 bytes parent folder | download
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
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
#!/usr/bin/make -f

#
# debian/rules for perl.
#
# Note that although this rules file currently invokes tools from dpkg-dev
# implemented in perl (such as dpkg-architecture and so on), it aspires
# to not use perl at all, so that a new architecture can easily be
# bootstrapped. This aspiration should be considered when changing this
# file.
#
# <http://lists.alioth.debian.org/pipermail/perl-maintainers/2012-January/002870.html>

# we use bash-specific functionality, at least "shopt -s globstar"
export SHELL = /bin/bash

# at least LOCALTIME_{MIN,MAX} are affected by this
export TZ=UTC

# Configure output is sorted and varies with LC_COLLATE
export LC_ALL=C

# use the timestamp from debian/changelog for Pod::Man generated man pages
# this may end up in dpkg-buildpackage eventually but it's not there yet
export SOURCE_DATE_EPOCH = $(shell date -d "$$(dpkg-parsechangelog -SDate)" +%s)

fullversion := $(shell /bin/bash debian/config.debian --full-version)
nextversion := $(shell /bin/bash debian/config.debian --next-version)
version     := $(shell /bin/bash debian/config.debian --version)
installtype := $(shell /bin/bash debian/config.debian --install-type)
test_target := $(shell /bin/bash debian/config.debian --test-target)
strip	    := $(shell /bin/bash debian/config.debian --strip)
archtriplet := $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
arch        := $(shell dpkg-architecture -qDEB_HOST_ARCH)
srcdir      := $(shell pwd)
packages    := $(shell sed -n 's/^Package: *//p' debian/control)
arch_pkgs   := $(shell sed -n '/^Package:/ { s/^Package: *//; h }; /^Architecture: any/ { x; p }' debian/control)
indep_pkgs  := $(shell sed -n '/^Package:/ { s/^Package: *//; h }; /^Architecture: all/ { x; p }' debian/control)
build_date  := $(shell dpkg-parsechangelog | sed -n -e 's/^Date: //p')
tmp	    = debian/tmp
bin         = $(tmp)/usr/bin
man         = $(tmp)/usr/share/man
lib         = $(tmp)/usr/lib/$(archtriplet)/perl/$(version)
share       = $(tmp)/usr/share/perl/$(version)
build	    = debian/build
debug       = $(build)/perl-debug/usr/lib/debug
patches     = debian/patches/series
patchlevel  = patchlevel-debian.h

# we put the generated config.sh files here
pcd         = $(tmp)/usr/lib/$(archtriplet)/perl/debian-config-data-$(fullversion)

# If nonempty, this will determine $Config{debian_abi} and Provides: entries
# (otherwise, the Provides: entries will be generated by debian/mkprovides)
perlabi =

checkdir    = test -d debian
checkroot   = test `id -u` -eq 0
checkperl   = $(SHELL) debian/checkperl

DEB_BUILD_GNU_TYPE      ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
DEB_HOST_GNU_TYPE       ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)

OBJCOPY = $(DEB_HOST_GNU_TYPE)-objcopy
STRIP = $(DEB_HOST_GNU_TYPE)-strip

# Invoking PERL_TO_USE is expected to find its standard library
# without additional command line arguments, so include lib/ here
# in its definition.
ifeq ($(DEB_HOST_GNU_TYPE), $(DEB_BUILD_GNU_TYPE))
	PERL_TO_USE = $(srcdir)/perl.static -I $(srcdir)/lib
else
	PERL_TO_USE = $(shell which perl)
	export TIME_HIRES_DONT_RUN_PROBES=1
endif

# this may differ from $(fullversion) for release candidates and the like
package_upstream_version = $(shell dpkg-parsechangelog | \
        sed -ne 's/-[^-]\+$$//; s/^Version: *\([0-9]\+:\)*//p')

package_version = $(shell dpkg-parsechangelog | sed -n 's/^Version: *//p')

# this gets prepended to the patch names in patchlevel.h
patchprefix = DEBPKG:

# control file substitutions
subst_upstream = -VUpstream-Version=$(package_upstream_version)
subst_next_upstream = -VNext-Upstream-Version=$(nextversion)

ifeq (,$(perlabi))
subst_perlapi  = -Vperlapi:Provides="`$(PERL_TO_USE) debian/mkprovides`"
else
subst_perlapi  = -Vperlapi:Provides="perlapi-$(perlabi)"
endif

# for cpan/Compress-Raw-Zlib
export BUILD_ZLIB=False
export ZLIB_INCLUDE=/usr/include
export ZLIB_LIB=/usr/lib

# for cpan/Compress-Raw-Bzip2
export BUILD_BZIP2=0
export BZIP2_INCLUDE=/usr/include
export BZIP2_LIB=/usr/lib

build: build-stamp
install: install-stamp

build-arch: build
build-indep: build

build-stamp: $(patchlevel) perl.static perl.debug libperl.so.$(fullversion)
	touch $@

$(patchlevel): $(patches)
	$(checkdir)
	test -f $<	# maintainer sanity check
	debian/gen-patchlevel -p $(patchprefix) -v $(package_version) $< > $@
	# $patchlevel_date in perlbug is extracted from patchlevel.h mtime, let's set
	# it to highest mtime of Debian patches for build reproducibility
	patchdate=`debian/gen-patchlevel -d`; touch --date="@$$patchdate" patchlevel.h

perl.static:
	$(checkdir)
	rm -f libperl.so* # must be built last
	[ ! -f Makefile ] || $(MAKE) distclean
	[ -f $(patchlevel) ] || touch $(patchlevel)
	$(SHELL) debian/config.debian --static

	# stash generated config.sh
	cp config.sh config.sh.static

	$(MAKE) perl $(test_target)
	mv libperl.a libperl-static
	mv perl perl.static

ifeq ($(DEB_HOST_GNU_TYPE), $(DEB_BUILD_GNU_TYPE))
	# for the build log
	$(PERL_TO_USE) -Ilib -V
endif

	# save these for the perl-base package
	cp lib/Config.pm lib/Config.pm.static
	cp lib/Config_heavy.pl lib/Config_heavy.pl.static

perl.debug:
	$(checkdir)
	rm -f libperl.so* # must be built last
	[ ! -f Makefile ] || $(MAKE) distclean
	[ -f $(patchlevel) ] || touch $(patchlevel)
	$(SHELL) debian/config.debian --debug

	# stash generated config.sh
	cp config.sh config.sh.debug

	$(MAKE) perl
	mv perl perl.debug

libperl.so.$(fullversion):
	$(checkdir)
	[ ! -f Makefile ] || $(MAKE) distclean
	[ -f $(patchlevel) ] || touch $(patchlevel)
	$(SHELL) debian/config.debian --shared

	# stash generated config.sh
	cp config.sh config.sh.shared

	$(MAKE) SHRPLDFLAGS='$$(LDDLFLAGS) -Wl,-soname,libperl.so.$(version)' $@
	ln -s libperl.so.$(fullversion) libperl.so.$(version)
	ln -s libperl.so.$(version) libperl.so
	$(MAKE) all $(test_target) || { rm -f libperl.so*; exit 1; }

clean:
	$(checkdir)
	$(checkroot)
	test -f $(patches)	# maintainer sanity check
	[ ! -f Makefile ] || $(MAKE) distclean
	rm -rf config.over perl.static perl.debug libperl-static libperl.so* \
	    $(patchlevel) build-stamp install-stamp t/auto debian/shlibs.local \
	    debian/perl-base.shlibs debian/libperl$(version).shlibs \
	    build-miniperl build-generate_uudmap optdef.sh config.sh.* \
	    debian/substvars debian/files debian/list.tmp $(tmp) $(build)

install-stamp: build-stamp
	$(checkdir)
	$(checkroot)
	$(checkperl)
	rm -rf $(tmp) $(build)

	$(MAKE) install DESTDIR="$(tmp)"

	# these end up in the wrong place
	mv $(share)/Config.pm.static $(lib)
	mv $(share)/Config_heavy.pl.static $(lib)

	# switch man extensions to 1p and 3pm for vendor module installs
	$(PERL_TO_USE) -i -p \
	    -e 's/^(man1ext=).*/$$1'\''1p'\''/;' \
	    -e 's/^(man3ext=).*/$$1'\''3pm'\''/;' \
		$(lib)/Config.pm $(lib)/Config_heavy.pl \
		$(lib)/Config.pm.static $(lib)/Config_heavy.pl.static

ifeq (,$(perlabi))
else
	# add \$Config{debian_abi}
	sed -i -e "/version =>/i\    debian_abi => '$(perlabi)'," \
		$(lib)/Config.pm $(lib)/Config.pm.static
endif

	# avoid exposing the point release in libperl names, to
	# avoid unnecessary breakage
	# see #759989
	$(PERL_TO_USE) -i -p \
	    -e 's/^(libperl='\''libperl\.so)\.$(fullversion)'\''/$$1.$(version)'\''/' \
		$(lib)/Config.pm $(lib)/Config_heavy.pl \
		$(lib)/Config.pm.static $(lib)/Config_heavy.pl.static

	# remove dpkg-buildflags effects from %Config
	# see #657853
	if which dpkg-buildflags >/dev/null 2>&1; then \
		for flag in $(shell dpkg-buildflags --get CPPFLAGS) \
		         $(shell dpkg-buildflags --get CFLAGS); do \
			case "$$flag" in -fstack-protector) ;; \
			     *) export flag; $(PERL_TO_USE) -i -pe "/^(cc|cpp)flags/ and \
			          s/(['\s])\Q\$$ENV{flag}\E(['\s])/\1\2/ and s/  +/ /" \
		            $(lib)/Config.pm $(lib)/Config_heavy.pl \
		            $(lib)/Config.pm.static $(lib)/Config_heavy.pl.static ;; \
		    esac; done; \
		for flag in $(shell dpkg-buildflags --get LDFLAGS); do \
			export flag; $(PERL_TO_USE) -i -pe "/^ld(dl)?flags/ and \
			          s/(['\s])\Q\$$ENV{flag}\E(['\s])/\1\2/ and s/  +/ /" \
		          $(lib)/Config.pm $(lib)/Config_heavy.pl \
		          $(lib)/Config.pm.static $(lib)/Config_heavy.pl.static ; \
		done; \
	fi

	# convert required header files
	-cd /usr/include; \
	    $(srcdir)/debian/fake-config $(srcdir)/lib $(PERL_TO_USE) \
	    $(srcdir)/utils/h2ph -a -d $(srcdir)/$(lib) \
		`cat $(srcdir)/debian/headers`

	# fix up generated headers
	$(PERL_TO_USE) debian/fixheaders $(lib)

	# simple wrapper around Errno module
	cp debian/errno.ph $(lib)

ifeq (,$(findstring nocheck,$(DEB_BUILD_OPTIONS)))
ifeq (,$(findstring x-perl-notest,$(DEB_BUILD_OPTIONS)))
	# Verify that the headers are usable
	for ph in `< debian/headers sed -e 's/\.h$$/.ph/'`; do \
		if [ ! -f $(lib)/$$ph ]; then \
			echo "$$ph: missing"; else \
			echo $$ph | $(PERL_TO_USE) debian/check-require $(tmp) \
				|| exit 1; \
		fi; \
	done
endif
endif

	# remove some cruft
	rm -f $(lib)/.packlist

	# installperl copies the symlinks as a files
	rm -f $(lib)/CORE/libperl.so $(lib)/CORE/libperl.so.$(version)

	# remove versioned binary, relink after moving files
	rm -f $(bin)/perl$(fullversion)

	# relocate perl libraries and create links
	cp libperl-static $(tmp)/usr/lib/$(archtriplet)/libperl.a
	mv $(lib)/CORE/libperl.so.$(fullversion) $(tmp)/usr/lib/$(archtriplet)

	ln -s libperl.so.$(fullversion) $(tmp)/usr/lib/$(archtriplet)/libperl.so.$(version)
	ln -s libperl.so.$(version) $(tmp)/usr/lib/$(archtriplet)/libperl.so

	# move to full version (symlinks created in libperl5.* below)
	mv $(lib) $(tmp)/usr/lib/$(archtriplet)/perl/$(fullversion)
	mv $(share) $(tmp)/usr/share/perl/$(fullversion)

ifeq ($(installtype),static)
	cp perl.static $(bin)/perl
endif

	# install debug binary as debugperl
	cp perl.debug $(bin)/debugperl

	# install the stashed config.sh files
	mkdir -p $(pcd)
	cp config.sh.* $(pcd)
	gzip -n $(pcd)/config.sh.*
	cp debian/cross/README $(pcd)

	# split packages
	# Note: this relies on the order of debian/control
	for p in $(packages); \
	do \
	    mkdir -p $(build)/$$p; \
	    (cd $(tmp); \
	    	for sfx in '' .$(installtype); \
		do \
		    list=../$$p.files$$sfx; \
		    test -s $$list || continue; \
		    shopt -s globstar; \
		    find `grep -v '^#' $$list` ! -type d; \
		done) >debian/list.tmp; \
	    (cd $(tmp); cpio -vdumpl ../build/$$p) <debian/list.tmp 2>&1 | \
		grep -v ' linked to '; \
	    (cd $(tmp); $(PERL_TO_USE) -nle unlink) <debian/list.tmp; \
	done

	# ensure that all file have been moved from debian/tmp
	FILESLEFT=`find $(tmp) ! -type d`; \
	 if [ -n "$$FILESLEFT" ]; then \
		echo "error:files left in debian/tmp:"; \
		echo "$$FILESLEFT"; \
	    exit 1; \
	 fi

	# move pod out of -base modules and into .pod files in -doc
	$(PERL_TO_USE) debian/splitdoc $(build)/perl-base

	# copy the essential parts of the standard library into a perl-base specific path
	for d in $(build)/perl-base/usr/lib/$(archtriplet)/perl/$(fullversion) \
	         $(build)/perl-base/usr/share/perl/$(fullversion); do \
	    (cd $$d && find . -print0 | \
	      cpio -0vdump $(srcdir)/$(build)/perl-base/usr/lib/$(archtriplet)/perl-base); \
	done
	# then move the original ones into libperl5.xx and perl-modules-5.xx
	(cd $(build)/perl-base && \
	 find usr/lib/$(archtriplet)/perl/$(fullversion) -print0 | \
	      cpio -0vdump $(srcdir)/$(build)/libperl$(version); \
	     rm -rf usr/lib/$(archtriplet)/perl/$(fullversion); \
	 find usr/share/perl/$(fullversion) -print0 | \
	      cpio -0vdump $(srcdir)/$(build)/perl-modules-$(version); \
	     rm -rf usr/share/perl/$(fullversion); \
	     rmdir usr/share/perl; \
	 )

	# install a separate cpan binary in libperl5.xx with a modified hashbang
	lp=$(build)/libperl$(version); \
	 mkdir -p $$lp/usr/bin; \
	 cp -p perl $$lp/usr/bin/perl$(version)-$(archtriplet); \
	 cp -p $(build)/perl/usr/bin/cpan $$lp/usr/bin/cpan$(version)-$(archtriplet); \
	 sed -i "1 s,/usr/bin/perl,/usr/bin/perl$(version)-$(archtriplet)," \
	  $$lp/usr/bin/cpan$(version)-$(archtriplet)

ifeq ($(installtype),static)
	# make the static configuration available to /usr/bin/perl
	mkdir -p $(build)/perl-base/usr/lib/$(archtriplet)/perl-base
	mv $(build)/libperl$(version)/usr/lib/$(archtriplet)/perl/$(fullversion)/Config.pm.static $(build)/perl-base/usr/lib/$(archtriplet)/perl-base/Config.pm
	mv $(build)/libperl$(version)/usr/lib/$(archtriplet)/perl/$(fullversion)/Config_heavy.pl.static $(build)/perl-base/usr/lib/$(archtriplet)/perl-base/Config_heavy.pl
else
	rm $(build)/libperl$(version)/usr/lib/$(archtriplet)/perl/$(fullversion)/Config.pm.static $(build)/perl/usr/lib/$(archtriplet)/perl/$(fullversion)/Config_heavy.pl.static
endif

	# create symlinks to match @INC
	ln -s $(fullversion) $(build)/libperl$(version)/usr/lib/$(archtriplet)/perl/$(version)
	ln -s $(fullversion) $(build)/perl-modules-$(version)/usr/share/perl/$(version)

ifeq (,$(findstring nocheck,$(DEB_BUILD_OPTIONS)))
ifeq (,$(findstring x-perl-notest,$(DEB_BUILD_OPTIONS)))
	# Verify that perl-base stays self contained

	( cd $(build)/perl-base && find . -name '*.p[hlm]' ) | \
	  $(PERL_TO_USE) $(srcdir)/debian/check-require $(build)/perl-base
endif
endif

	# move section 1 manual pages back to perl for installed programs
	mkdir -p $(build)/perl/usr/share/man/man1
	find $(build)/perl/usr/bin -type f -printf "%f\n" | \
	    while read prog; \
	    do \
		m=$(build)/perl-doc/usr/share/man/man1/$$prog.1; \
		if test -f $$m; \
		then \
		    mv $$m $(build)/perl/usr/share/man/man1; \
		else \
		    echo "warning: no manual page for $$prog" >&2; \
		fi; \
	    done

	# copy manual pages for {perl,cpan}<version>-<arch>
	test -d     $(build)/libperl$(version)/usr/share/man/man1 || \
	   mkdir -p $(build)/libperl$(version)/usr/share/man/man1
	cp $(build)/perl-base/usr/share/man/man1/perl.1 \
	   $(build)/libperl$(version)/usr/share/man/man1/perl$(version)-$(archtriplet).1
	cp $(build)/perl/usr/share/man/man1/cpan.1 \
	   $(build)/libperl$(version)/usr/share/man/man1/cpan$(version)-$(archtriplet).1

	# remove some linked man pages (symlinked later and cause
	# problems as-is when compressing)
	rm -f $(build)/perl/usr/share/man/man1/pstruct.1 \
	    $(build)/perl/usr/share/man/man1/perlthanks.1

	# the diagnostics module needs perldiag.pod
	mkdir $(build)/perl-modules-$(version)/usr/share/perl/$(fullversion)/pod
	mv $(build)/perl-doc/usr/share/perl/$(fullversion)/pod/perldiag.pod \
	    $(build)/perl-modules-$(version)/usr/share/perl/$(fullversion)/pod

	# copy dummy perldoc to perl package
	cp debian/perl.perldoc $(build)/perl/usr/bin/perldoc
	chmod 755 $(build)/perl/usr/bin/perldoc

	# install rename script to bin (as prename, alternative configured)
	cp debian/rename $(build)/perl/usr/bin/prename
	chmod 755 $(build)/perl/usr/bin/prename

	$(PERL_TO_USE) $(build)/perl/usr/bin/pod2man --official \
	    debian/rename >$(build)/perl/usr/share/man/man1/prename.1

	# install docs
	for p in $(packages); \
	do \
	    doc=$(build)/$$p/usr/share/doc; \
	    test -d $$doc || mkdir -p $$doc; \
	    if test -f debian/$$p.docs; \
	    then \
		while read src target; \
		do \
		    d=`echo $$target | sed 's,/[^/]*$$,,'`; \
		    test -d $$doc/$$d || mkdir -p $$doc/$$d; \
		    if [ "$$src" = "debian/changelog" ] && \
		       head -1 $$src | grep -iq 'binary-only=yes'; \
		    then \
		        # split out binNMU changelog entries \
		        debian/split-binnmu $$src > $$doc/$$target \
		                                 2> $$doc/$${target}.$(arch); \
		    else \
		        cp -p $$src $$doc/$$target; \
		    fi; \
		done <debian/$$p.docs; \
	    fi; \
	    test -d $$doc/$$p || ln -s perl $$doc/$$p; \
	done

	# lintian overrides
	for p in $(packages); \
	do \
	    if test -f debian/$$p.lintian-overrides; \
	    then \
	    d="$(build)/$$p/usr/share/lintian/overrides"; \
	    mkdir -p $$d; \
	    cp debian/$$p.lintian-overrides $$d/$$p; \
	    fi; \
	done

	# remove empty directories left after moving module docs
	find $(build)/perl-modules-$(version)/usr/share/perl/$(fullversion) \
	    -depth -type d -empty | xargs -r rmdir

	# want these in /etc since /usr may not be writable
	mkdir -p $(build)/perl/etc/perl/CPAN \
	    $(build)/perl/etc/perl/Net

	# default configuration for libnet
	cp debian/libnet.cfg $(build)/perl/etc/perl/Net

	# symlinks for perl-cross-config
	ccdir=$(build)/libperl$(version)/usr/lib/$(archtriplet)/perl/cross-config-$(fullversion); \
	  mkdir -p $$ccdir; \
	  ln -s ../$(fullversion)/Config.pm $$ccdir; \
	  ln -s ../$(fullversion)/Config_heavy.pl $$ccdir

	# example to strip "." from @INC (CVE-2016-1238)
	cp debian/sitecustomize.pl $(build)/perl/etc/perl

	# compress
	find $(build)/*/usr/share/man -type f -print | xargs -r gzip -n9
	find $(build)/*/usr/share/doc -type f \
	    \( -name changelog\* -o \( -size +4k ! -name copyright \) \) \
	    -print | xargs -r gzip -n9

ifeq ($(strip),yes)
	# strip
	find $(build)/*/usr/bin $(build)/*/usr/lib -type f \
	    \( -name \*.so\* -o -name \*.a -o -perm /111 \) -print | \
	    grep -v ^$(build)/perl-debug/ | \
	    while read f; \
	    do \
		type=`file $$f`; \
		extra=; \
		case "$$type" in \
		    *ELF*shared\ object*) \
		    	extra=--strip-unneeded;; \
		esac; \
		case "$$type" in \
		    *ELF*) \
			path=/$${f#$(build)/*/}; \
			dir=$${path%/*}; \
			test -d $(debug)$$dir || mkdir -p $(debug)$$dir; \
			# stash debugging symbols \
			$(OBJCOPY) --only-keep-debug $$f $(debug)$$path; \
			# strip \
			$(STRIP) --remove-section=.comment --remove-section=.note \
			    $$extra $$f; \
			# add debuglink \
			$(OBJCOPY) --add-gnu-debuglink=$(debug)$$path $$f; \
		esac; \
	    done
	    # versioned hardlink for the detached debug symbols
	    ln $(debug)/usr/bin/perl \
	        $(debug)/usr/bin/perl$(fullversion)
endif
	# re-create versioned link
	# this has to go after the stripping part if there are other links
	# to the file (like perl-suid used to)
	ln $(build)/perl-base/usr/bin/perl \
	    $(build)/perl-base/usr/bin/perl$(fullversion)

	# links
	mkdir -p $(build)/perl-debug/usr/share/man/man1

	ln -s perl.1.gz $(build)/perl-debug/usr/share/man/man1/debugperl.1.gz
	ln -s perl.1.gz $(build)/perl-base/usr/share/man/man1/perl$(fullversion).1.gz
	ln -s c2ph.1.gz $(build)/perl/usr/share/man/man1/pstruct.1.gz
	ln -s perlbug.1.gz $(build)/perl/usr/share/man/man1/perlthanks.1.gz

	ln -s changelog.gz $(build)/perl/usr/share/doc/perl/Changes.gz

	# fixperms
	find $(build) -print | xargs -r chown -h root:root
	find $(build) -type d -print | xargs -r chmod 755
	find $(build) -type f -print | xargs -r chmod go=rX,u+rw,a-s
	find $(build)/*/usr/bin -type f -print | xargs -r chmod a+x
	find $(build)/*/usr/lib -type f -name \*.so\* -print | xargs -r chmod a-x
	find $(build)/*/usr/share/doc $(build)/*/usr/share/man -type f \
	    -print | xargs -r chmod 644

	touch $@

# Build architecture-independent files here.
binary-indep: build-stamp install-stamp
	$(checkdir)
	$(checkroot)
	rm -f debian/substvars
	for p in $(indep_pkgs); \
	do \
	    rm -rf $(build)/$$p/DEBIAN; \
	    mkdir $(build)/$$p/DEBIAN; \
	    chmod 755 $(build)/$$p/DEBIAN; \
	    for c in preinst postinst prerm postrm; \
	    do \
		test -f debian/$$p.$$c || continue; \
		cp debian/$$p.$$c $(build)/$$p/DEBIAN/$$c; \
		chmod 755 $(build)/$$p/DEBIAN/$$c; \
	    done; \
	    test -d $(build)/$$p/etc && find $(build)/$$p/etc -type f \
		-printf '/etc/%P\n' | LC_ALL=C sort >$(build)/$$p/DEBIAN/conffiles; \
	    chmod 644 $(build)/$$p/DEBIAN/conffiles; \
	    (cd $(build)/$$p; find usr -type f -print | LC_ALL=C sort | xargs -r md5sum) \
		>$(build)/$$p/DEBIAN/md5sums; \
	    chmod 644 $(build)/$$p/DEBIAN/md5sums; \
	    dpkg-gencontrol -p$$p -P$(build)/$$p $(subst_upstream) $(subst_next_upstream); \
	    find $(build)/$$p -depth -newermt '$(build_date)' -print0 | \
	        xargs -0r touch --no-dereference --date='$(build_date)'; \
	    dpkg --build $(build)/$$p ..; \
	done

# Build architecture-dependent files here.
binary-arch: build-stamp install-stamp
	$(checkdir)
	$(checkroot)
ifeq ($(installtype),static)
	echo 'libperl $(version) libperl$(version) (= $${binary:Version})' \
	    >debian/shlibs.local

	echo 'libperl $(version) libperl$(version) (>= $(package_upstream_version))' \
	    >debian/libperl$(version).shlibs
else
	echo 'libperl $(version)' >debian/shlibs.local
	echo 'libperl $(version) libperl$(version) (>= $(package_upstream_version))' \
	    >debian/perl-base.shlibs
endif

	for p in $(arch_pkgs); \
	do \
	    rm -rf $(build)/$$p/DEBIAN debian/substvars; \
	    mkdir $(build)/$$p/DEBIAN; \
	    for c in preinst postinst prerm postrm shlibs triggers; \
	    do \
		test -f debian/$$p.$$c || continue; \
		cp debian/$$p.$$c $(build)/$$p/DEBIAN/$$c; \
		chmod 755 $(build)/$$p/DEBIAN/$$c; \
	    done; \
	    ! test -f $(build)/$$p/DEBIAN/shlibs || chmod 644 $(build)/$$p/DEBIAN/shlibs; \
	    ! test -f $(build)/$$p/DEBIAN/triggers || chmod 644 $(build)/$$p/DEBIAN/triggers; \
	    test -d $(build)/$$p/etc && find $(build)/$$p/etc -type f \
		-printf '/etc/%P\n' | LC_ALL=C sort >$(build)/$$p/DEBIAN/conffiles; \
	    chmod 644 $(build)/$$p/DEBIAN/conffiles; \
	    (cd $(build)/$$p; find usr -type f -print | LC_ALL=C sort | xargs -r md5sum) \
		>$(build)/$$p/DEBIAN/md5sums; \
	    chmod 644 $(build)/$$p/DEBIAN/md5sums; \
	done
ifeq ($(installtype),static)
	dpkg-gensymbols -plibperl$(version) -P$(build)/libperl$(version)
endif
	# dpkg-shlibdeps needs to be run only after all the shlibs are present
	for p in $(arch_pkgs); \
	do \
	    find $(build)/$$p/usr -type f \
		\( -perm /111 -o -name \*.so\* \) -print | \
		fgrep -v /usr/lib/debug/ | \
		xargs -r dpkg-shlibdeps -S$(srcdir)/$(build)/libperl$(version) \
		                        -S$(srcdir)/$(build)/perl-base 2>&1 | \
		fgrep -v 'File format not recognized'; # scripts \
	    dpkg-gencontrol -p$$p -P$(build)/$$p $(subst_perlapi) $(subst_upstream); \
	    find $(build)/$$p -depth -newermt '$(build_date)' -print0 | \
	        xargs -0r touch --no-dereference --date='$(build_date)'; \
	    dpkg --build $(build)/$$p ..; \
	done

binary: binary-indep binary-arch

.NOTPARALLEL:

.PHONY: build clean binary-indep binary-arch binary install build-arch build-indep