summaryrefslogtreecommitdiff
path: root/debian/rules
blob: 87d92ddbfdf835a714cb61e89d8e37483658fe1a (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
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
#!/usr/bin/make -f
# Sample debian/rules that uses debhelper. 
# GNU copyright 1997 by Joey Hess.
#
# This version is for a hypothetical package that builds an
# architecture-dependant package, as well as an architecture-independent
# package.

# Uncomment this to turn on verbose mode. 
#export DH_VERBOSE=1

# This has to be exported to make some magic below work.
export DH_OPTIONS

# Set this flag to 'yes' if you want to disable all modifications breaking abi 
# compatibility to upstream
PHP5_COMPAT=no

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

PHP5_SOURCE_VERSION   = $(shell dpkg-parsechangelog | grep ^Version | sed "s/Version: //")
PHP5_UPSTREAM_VERSION = $(shell echo $(PHP5_SOURCE_VERSION) | sed -e "s/-.*//" -e "s/.*://")
PHP5_DEBIAN_REVISION  = $(shell echo $(PHP5_SOURCE_VERSION) | sed "s/.*-//")

# specify some options to our patch system
QUILT_DIFF_OPTS=-p
QUILT_NO_DIFF_TIMESTAMPS=1 
export QUILT_DIFF_OPTS QUILT_NO_DIFF_TIMESTAMPS

PROG_SENDMAIL = /usr/sbin/sendmail
ifeq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
  CFLAGS += -O2
endif
CFLAGS += -Wall -fsigned-char -fno-strict-aliasing 
# LFS support
ifneq (yes,$(PHP5_COMPAT))
  CFLAGS += $(shell getconf LFS_CFLAGS)
endif

# Enable IEEE-conformant floating point math on alphas (not the default)
ifeq (alpha-linux-gnu,$(DEB_HOST_GNU_TYPE))
  CFLAGS += -mieee
endif

ifeq ($(DEB_HOST_GNU_TYPE), $(findstring $(DEB_HOST_GNU_TYPE), ia64-linux-gnu powerpc64-linux-gnu avr32-linux-gnu))
  CFLAGS += -g
else
  CFLAGS += -gstabs
endif

# Old magic.mime location:
ifeq ($(wildcard /usr/share/misc/file/magic.mime), /usr/share/misc/file/magic.mime)
MAGIC_MIME = /usr/share/misc/file/magic.mime
endif
# New magic.mime location:
ifeq ($(wildcard /usr/share/file/magic.mime), /usr/share/file/magic.mime)
MAGIC_MIME = /usr/share/file/magic.mime
endif

# some other helpful (for readability at least) shorthand variables
PHPIZE_BUILDDIR = debian/php5-dev/usr/lib/php5/build

# support new (>= 2.2) and older versions of libtool for backporting ease
LIBTOOL_DIRS = /usr/share/libtool/config /usr/share/libtool
LTMAIN = $(firstword $(wildcard $(foreach d,$(LIBTOOL_DIRS),$d/ltmain.sh)))
LTMAIN_DIR = $(dir $(LTMAIN))

ifeq ($(LTMAIN_DIR), /usr/share/libtool/)
LIBTOOL_CONFLICTS:=libtool (>= 2.2)
else ifeq ($(LTMAIN_DIR), /usr/share/libtool/config/)
LIBTOOL_CONFLICTS:=libtool (<< 2.2)
else
LIBTOOL_CONFLICTS:=$(error "could not resolve path to ltmain.sh")
endif

# only enable interbase support for i386/amd64/powerpc/sparc
ifneq (,$(filter $(DEB_HOST_ARCH),amd64 i386 powerpc sparc))
	IBFLAGS=--with-interbase=shared,/usr \
		--with-pdo-firebird=shared,/usr
endif

COMMON_CONFIG=--build=$(DEB_BUILD_GNU_TYPE) \
		--host=$(DEB_HOST_GNU_TYPE) \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--disable-debug \
		--with-regex=php \
		--disable-rpath \
		--disable-static \
		--with-pic \
		--with-layout=GNU \
		--with-pear=/usr/share/php \
		--enable-calendar \
		--enable-sysvsem \
		--enable-sysvshm \
		--enable-sysvmsg \
		--enable-bcmath \
		--with-bz2 \
		--enable-ctype \
		--with-db4 \
		--without-gdbm \
		--with-iconv \
		--enable-exif \
		--enable-ftp \
		--with-gettext \
		--enable-mbstring \
		--with-pcre-regex=/usr \
		--enable-shmop \
		--enable-sockets \
		--enable-wddx \
		--with-libxml-dir=/usr \
		--with-zlib \
		--with-kerberos=/usr \
		--with-openssl=/usr \
		--enable-soap \
		--enable-zip \
		--with-mime-magic=$(MAGIC_MIME) \
		--with-exec-dir=/usr/lib/php5/libexec \
		--with-system-tzdata

BUILTIN_EXTENSION_CHECK=$$e=get_loaded_extensions(); natcasesort($$e); \
			$$s="The following extensions are built in:"; \
			foreach($$e as $$i) { $$s .= " $$i"; } \
			echo("php:Extensions=" . wordwrap($$s . ".\n", 75, "\$${Newline} "));

# include the patch/unpatch rules from quilt
include /usr/share/quilt/quilt.make

prepared: prepared-stamp
prepared-stamp: $(QUILT_STAMPFN)
	dh_testdir
	sed -i -e 's/EXTRA_VERSION=""/EXTRA_VERSION="-$(PHP5_DEBIAN_REVISION)"/' configure.in
	./buildconf --force
	touch prepared-stamp

unprepared:
	dh_testdir
	sed -i -e 's/EXTRA_VERSION="-$(PHP5_DEBIAN_REVISION)"/EXTRA_VERSION=""/' configure.in
	rm -f prepared-stamp

test-results.txt: build-apache2-stamp build-cli-stamp build-cgi-stamp
ifeq (,$(findstring nocheck,$(DEB_BUILD_OPTIONS)))
	mkdir -p temp_session_store
	env NO_INTERACTION=1 TEST_PHP_CGI_EXECUTABLE=./cgi-build/sapi/cgi/cgi-bin.php5 TEST_PHP_EXECUTABLE=./apache2-build/sapi/cli/php ./apache2-build/sapi/cli/php run-tests.php > test-results.txt
	rm -rf temp_session_store
else
	echo 'nocheck found in DEB_BUILD_OPTIONS' > test-results.txt
endif
	cat test-results.txt

build: build-apache2-stamp build-apache2filter-stamp build-cgi-stamp build-cli-stamp build-pear-stamp test-results.txt

build-apache2-stamp: configure-apache2-stamp
	dh_testdir
	cd apache2-build && $(MAKE)

	touch build-apache2-stamp

build-apache2filter-stamp: configure-apache2filter-stamp
	dh_testdir
	cd apache2filter-build && $(MAKE)

	touch build-apache2filter-stamp

build-cli-stamp: configure-cli-stamp
	dh_testdir
	cd cli-build && $(MAKE)

	touch build-cli-stamp


build-cgi-stamp: configure-cgi-stamp
	dh_testdir
	cd cgi-build && $(MAKE) && mv sapi/cgi/php-cgi sapi/cgi/cgi-bin.php5

	# Dirty hack to not rebuild everything twice
	cd cgi-build/main && \
		sed -i -e 's/FORCE_CGI_REDIRECT 1/FORCE_CGI_REDIRECT 0/' \
		       -e 's/DISCARD_PATH 0/DISCARD_PATH 1/' php_config.h && \
		sed -i -e 's/--enable-force-cgi-redirect/--enable-discard-path/' build-defs.h && \
		touch ../../ext/standard/info.c && \
		touch ../../sapi/cgi/cgi_main.c

	cd cgi-build && $(MAKE) && mv sapi/cgi/php-cgi sapi/cgi/usr.bin.php5-cgi

	touch build-cgi-stamp

build-pear-stamp: build-cgi-stamp
	dh_testdir
	-mkdir pear-build
	-mkdir pear-build-download
	cd cgi-build && PHP_PEAR_DOWNLOAD_DIR=$(CURDIR)/pear-build-download $(MAKE) install-pear PHP_PEAR_PHP_BIN=/usr/bin/php PHP_PEAR_INSTALL_DIR=/usr/share/php PHP_PEAR_SYSCONF_DIR=/etc/pear PHP_PEAR_SIG_BIN=/usr/bin/gpg INSTALL_ROOT=$(CURDIR)/pear-build
	sed -i -e 's/-d output_buffering=1 -d open_basedir="" -d safe_mode=0/-d output_buffering=1 -d open_basedir="" -d safe_mode=0 -d memory_limit="-1"/' \
	       $(CURDIR)/pear-build/usr/bin/pear && \
	sed -i -e 's/-d output_buffering=1 -d safe_mode=0/-d output_buffering=1 -d open_basedir="" -d safe_mode=0 -d memory_limit="-1"/' \
	       $(CURDIR)/pear-build/usr/bin/pecl && \
	sed -i -e 's/-d memory_limit="-1"//' \
	       -e 's/-d output_buffering=1 -d open_basedir="" -d safe_mode=0/-d output_buffering=1 -d open_basedir="" -d safe_mode=0 -d memory_limit="-1"/' \
	       $(CURDIR)/pear-build/usr/bin/peardev
	sed -i -re "s#('PEAR_CONFIG_SYSCONFDIR', PHP_SYSCONFDIR)#\1 . '/pear'#" $(CURDIR)/pear-build/usr/share/php/PEAR/Config.php
	touch build-pear-stamp

configure: configure-apache2-stamp configure-apache2filter-stamp configure-cli-stamp configure-cgi-stamp

configure-apache2-stamp: prepared-stamp
	dh_testdir
	if [ -d apache2-build ]; then rm -rf apache2-build; fi
	-mkdir apache2-build
	cd apache2-build && \
        CFLAGS="$(CFLAGS)" PROG_SENDMAIL="$(PROG_SENDMAIL)" ../configure \
		--prefix=/usr --with-apxs2=/usr/bin/apxs2 \
		--with-config-file-path=/etc/php5/apache2 \
		--with-config-file-scan-dir=/etc/php5/apache2/conf.d \
		$(COMMON_CONFIG) \
		--without-mm \
		--with-curl=shared,/usr \
		--with-zlib-dir=/usr \
		--with-gd=shared,/usr --enable-gd-native-ttf \
		--with-gmp=shared,/usr \
		--with-jpeg-dir=shared,/usr \
		--with-xpm-dir=shared,/usr/X11R6 \
		--with-png-dir=shared,/usr \
		--with-freetype-dir=shared,/usr \
		--with-imap=shared,/usr \
		--with-imap-ssl \
		$(IBFLAGS) \
		--with-ttf=shared,/usr \
		--with-t1lib=shared,/usr \
		--with-ldap=shared,/usr \
		--with-ldap-sasl=/usr \
		--with-mcrypt=shared,/usr \
		--with-mhash=shared,/usr \
		--with-mysql=shared,/usr \
		--with-mysqli=shared,/usr/bin/mysql_config \
		--with-pspell=shared,/usr \
		--with-unixODBC=shared,/usr \
		--with-recode=shared,/usr \
		--with-xsl=shared,/usr \
		--with-snmp=shared,/usr \
		--with-sqlite=shared,/usr \
		--with-mssql=shared,/usr \
		--with-tidy=shared,/usr \
		--with-xmlrpc=shared \
		--with-pgsql=shared,/usr PGSQL_INCLUDE=`pg_config --includedir` \
		--enable-pdo=shared \
		--without-pdo-dblib \
		--with-pdo-mysql=shared,/usr \
		--with-pdo-odbc=shared,unixODBC,/usr \
		--with-pdo-pgsql=shared,/usr/bin/pg_config \
		--with-pdo-sqlite=shared,/usr \
		--with-pdo-dblib=shared,/usr
	cd apache2-build && \
	cp ../Zend/zend_ini_scanner.c ../Zend/zend_language_scanner.c \
	   ../Zend/zend_ini_parser.h ../Zend/zend_language_parser.h \
	   ../Zend/zend_ini_parser.c ../Zend/zend_language_parser.c \
	   Zend/
	touch configure-apache2-stamp

configure-apache2filter-stamp: prepared-stamp
	dh_testdir
	if [ -d apache2filter-build ]; then rm -rf apache2filter-build; fi
	-mkdir apache2filter-build
	cd apache2filter-build && \
        CFLAGS="$(CFLAGS)" PROG_SENDMAIL="$(PROG_SENDMAIL)" ../configure \
		--prefix=/usr --with-apxs2filter=/usr/bin/apxs2 \
		--with-config-file-path=/etc/php5/apache2filter \
		--with-config-file-scan-dir=/etc/php5/apache2filter/conf.d \
		$(COMMON_CONFIG) \
		--without-mm \
		--disable-pdo \
		--without-mysql --without-sybase-ct --without-mssql \
		--without-sqlite
	cd apache2filter-build && \
	cp ../Zend/zend_ini_scanner.c ../Zend/zend_language_scanner.c \
	   ../Zend/zend_ini_parser.h ../Zend/zend_language_parser.h \
	   ../Zend/zend_ini_parser.c ../Zend/zend_language_parser.c \
	   Zend/
	touch configure-apache2filter-stamp

configure-cgi-stamp: prepared-stamp
	dh_testdir
	if [ -d cgi-build ]; then rm -rf cgi-build; fi
	-mkdir cgi-build
	cd cgi-build && \
        CFLAGS="$(CFLAGS)" PROG_SENDMAIL="$(PROG_SENDMAIL)" ../configure \
		--prefix=/usr --enable-force-cgi-redirect --enable-fastcgi \
		--with-config-file-path=/etc/php5/cgi \
		--with-config-file-scan-dir=/etc/php5/cgi/conf.d \
		$(COMMON_CONFIG) \
		--without-mm \
		--disable-pdo \
		--without-mysql --without-sybase-ct --without-mssql \
		--without-sqlite
	cd cgi-build && \
	cp ../Zend/zend_ini_scanner.c ../Zend/zend_language_scanner.c \
	   ../Zend/zend_ini_parser.h ../Zend/zend_language_parser.h \
	   ../Zend/zend_ini_parser.c ../Zend/zend_language_parser.c \
	   Zend/
	touch configure-cgi-stamp

configure-cli-stamp: prepared-stamp
	dh_testdir
	if [ -d cli-build ]; then rm -rf cli-build; fi
	-mkdir cli-build
	cd cli-build && \
        CFLAGS="$(CFLAGS)" PROG_SENDMAIL="$(PROG_SENDMAIL)" ../configure \
		--prefix=/usr --disable-cgi \
		--with-config-file-path=/etc/php5/cli \
		--with-config-file-scan-dir=/etc/php5/cli/conf.d \
		$(COMMON_CONFIG) \
		--without-mm \
		--disable-pdo \
		--without-mysql --without-sybase-ct --without-sqlite \
		--without-mssql --enable-pcntl \
		--with-ncurses=/usr
	cd cli-build && \
	cp ../Zend/zend_ini_scanner.c ../Zend/zend_language_scanner.c \
	   ../Zend/zend_ini_parser.h ../Zend/zend_language_parser.h \
	   ../Zend/zend_ini_parser.c ../Zend/zend_language_parser.c \
	   Zend/
	touch configure-cli-stamp

clean: unprepared unpatch
	dh_testdir
	dh_testroot


	rm -f configure-apache2-stamp build-apache2-stamp
	rm -f configure-apache2filter-stamp build-apache2filter-stamp
	rm -f configure-cgi-stamp build-cgi-stamp
	rm -f configure-cli-stamp build-cli-stamp
	rm -f build-pear-stamp
	rm -f install-stamp
	rm -rf apache2-build
	rm -rf apache2filter-build
	rm -rf cgi-build
	rm -rf cli-build
	rm -rf pear-build pear-build-download
	rm -f debian/copyright
	rm -f test-results.txt
	dh_clean -Xorig

	# clean up autogenerated cruft
	cat debian/modulelist | while read package extname dsoname; do \
		rm -f debian/php5-$$package.postinst; \
	done
	for sapi in libapache2-mod-php5 libapache2-mod-php5filter php5-cgi php5-cli; do \
		for cruft in postrm links; do \
			rm -f debian/$${sapi}.$${cruft}; \
		done; \
	done

install: DH_OPTIONS=
install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	chmod 01733 debian/php5-common/var/lib/php5

	# Add here commands to install the package into debian/php5.
	# install apache2 DSO module
	cp apache2-build/.libs/libphp5.so \
		debian/libapache2-mod-php5/`apxs2 -q LIBEXECDIR`/
	cp debian/libapache2-mod-php5.load \
		debian/libapache2-mod-php5/etc/apache2/mods-available/php5.load
	cp debian/libapache2-mod-php5.conf \
		debian/libapache2-mod-php5/etc/apache2/mods-available/php5.conf

	# Add here commands to install the package into debian/php5.
	# install apache2 DSO filter module
	cp apache2filter-build/.libs/libphp5.so \
		debian/libapache2-mod-php5filter/`apxs2 -q LIBEXECDIR`/libphp5filter.so
	cp debian/libapache2-mod-php5filter.load \
		debian/libapache2-mod-php5filter/etc/apache2/mods-available/php5filter.load
	cp debian/libapache2-mod-php5filter.conf \
		debian/libapache2-mod-php5filter/etc/apache2/mods-available/php5filter.conf

	# sanitize php.ini file
	cat php.ini-dist | tr "\t" " " > debian/php5-common/usr/share/php5/php.ini-dist
	cat php.ini-dist | tr "\t" " " | sed -e'/memory_limit =/ s/128M/32M/g' > debian/php5-common/usr/share/php5/php.ini-dist.cli
	cat php.ini-dist | tr "\t" " " > debian/php5-common/usr/share/doc/php5-common/examples/php.ini-dist
	cat php.ini-recommended | tr "\t" " " > debian/php5-common/usr/share/doc/php5-common/examples/php.ini-recommended
	cat php.ini-paranoid | tr "\t" " " > debian/php5-common/usr/share/doc/php5-common/examples/php.ini-paranoid
	cp test-results.txt debian/php5-common/usr/share/doc/php5-common/

	# install the apache modules' files
	cd apache2-build && $(MAKE) install-headers install-build install-modules install-programs INSTALL_ROOT=$(CURDIR)/debian/libapache2-mod-php5
	# remove netware and win32 headers that we don't want
	cd debian/libapache2-mod-php5/usr/include/php5/ && \
		  $(RM) TSRM/readdir.h \
			TSRM/tsrm_config.nw.h TSRM/tsrm_config.w32.h\
			TSRM/tsrm_nw.h TSRM/tsrm_win32.h\
			Zend/zend_config.nw.h Zend/zend_config.w32.h\
			main/config.nw.h main/config.w32.h\
			main/win95nt.h

	# install PEAR
	cp -a pear-build/* debian/php-pear/

	# everything under usr/share/php/data except 'PEAR' is b0rken
	# and actually needs to be fixed
	[ ! -f debian/php-pear/usr/share/php/data/Structures_Graph/LICENSE ] || \
		$(RM) debian/php-pear/usr/share/php/data/Structures_Graph/LICENSE
	[ ! -f debian/php-pear/usr/share/php/doc/PEAR/INSTALL ] || \
		$(RM) debian/php-pear/usr/share/php/doc/PEAR/INSTALL
	for f in Structures_Graph/publish.sh Structures_Graph/package.sh \
		Structures_Graph/genpackage.xml.pl; do \
		$(RM) debian/php-pear/usr/share/php/data/$$f; \
	done
	# we don't want test suites
	$(RM) -r debian/php-pear/usr/share/php/test/
	[ -d debian/php-pear/usr/share/php/doc ] && { \
		mv debian/php-pear/usr/share/php/doc/* \
			debian/php-pear/usr/share/doc/php-pear/PEAR/; \
		$(RM) -r debian/php-pear/usr/share/php/doc; \
		ln -s ../doc/php-pear/PEAR debian/php-pear/usr/share/php/doc; \
	}
	# add /usr/share/doc/php-pear/PEAR
	touch /usr/share/doc/php-pear/PEAR/.placeholder

	# install extensions
	ext=`./debian/libapache2-mod-php5/usr/bin/php-config --extension-dir`;\
	for i in libapache2-mod-php5 libapache2-mod-php5filter php5-cgi php5-cli; do \
		mkdir -p debian/$$i/$${ext}; \
	done; \
	cat debian/modulelist debian/extramodulelist | while read package extname dsoname; do \
		if [ -z "$$dsoname" ]; then dsoname=$$package; fi; \
		mkdir -p debian/php5-$$package$${ext}; \
		chrpath debian/libapache2-mod-php5/$${ext}/$$dsoname.so; \
		chrpath -d debian/libapache2-mod-php5/$${ext}/$$dsoname.so; \
		install -m 644 -o root -g root \
			debian/libapache2-mod-php5/$${ext}/$$dsoname.so \
			debian/php5-$$package$${ext}/$$dsoname.so; \
		rm debian/libapache2-mod-php5/$${ext}/$$dsoname.so; \
	done

	# install CGI
	cp cgi-build/sapi/cgi/cgi-bin.php5 debian/php5-cgi/usr/lib/cgi-bin/php5
	cp cgi-build/sapi/cgi/usr.bin.php5-cgi debian/php5-cgi/usr/bin/php5-cgi
	cp cli-build/sapi/cli/php.1 debian/php5-cgi/usr/share/man/man1/php5-cgi.1

	# install CLI
	cp cli-build/sapi/cli/php debian/php5-cli/usr/bin/php5
	cp cli-build/sapi/cli/php.1 debian/php5-cli/usr/share/man/man1/php5.1

	# move and install -dev files
	dh_movefiles --sourcedir=debian/libapache2-mod-php5
	rm -rf debian/libapache2-mod-php5/usr/lib/php5/build/ \
	       debian/libapache2-mod-php5/usr/include/ \
	       debian/libapache2-mod-php5/usr/bin/
	rm -rf debian/libapache2-mod-php5filter/usr/lib/php5/build/ \
	       debian/libapache2-mod-php5filter/usr/include/ \
	       debian/libapache2-mod-php5filter/usr/bin/
	for i in Makefile.global acinclude.m4 mkdep.awk phpize.m4 scan_makefile_in.awk; do \
		chmod 644 debian/php5-dev/usr/lib/php5/build/$$i; \
	done
	# shipping duplicate files from other packages is hell for security audits
	ln -sf /usr/share/misc/config.guess $(PHPIZE_BUILDDIR)/config.guess
	ln -sf /usr/share/misc/config.sub $(PHPIZE_BUILDDIR)/config.sub
	ln -sf /usr/share/aclocal/libtool.m4 $(PHPIZE_BUILDDIR)/libtool.m4
	ln -sf $(LTMAIN_DIR)ltmain.sh $(PHPIZE_BUILDDIR)/ltmain.sh
	ln -sf /usr/bin/shtool $(PHPIZE_BUILDDIR)/shtool
	# make php-dev stuff versioned
	for i in php-config phpize; do \
		mv debian/php5-dev/usr/bin/$$i debian/php5-dev/usr/bin/"$$i"5; \
		mv debian/php5-dev/usr/share/man/man1/"$$i".1 debian/php5-dev/usr/share/man/man1/"$$i"5.1; \
	done

	# install common files
	install -m755 debian/maxlifetime debian/php5-common/usr/lib/php5

	# install lintian overrides
	cp debian/php5.lintian-overrides $(CURDIR)/debian/php5-common/usr/share/lintian/overrides/php5-common
	cp debian/php5-dev.lintian-overrides $(CURDIR)/debian/php5-dev/usr/share/lintian/overrides/php5-dev

	# install some generic lintian overrides
	ext=`debian/php5-dev/usr/bin/php-config5 --extension-dir | cut -b2- `; \
	for sapi in php5-cli php5-cgi libapache2-mod-php5 libapache2-mod-php5filter; do \
		mkdir -p $(CURDIR)/debian/"$$sapi"/usr/share/lintian/overrides/; \
		sed "s/@sapi@/$$sapi/g;s,@extdir@,$$ext,g" \
		    < $(CURDIR)/debian/php5-sapi.lintian-overrides \
		    >> $(CURDIR)/debian/"$$sapi"/usr/share/lintian/overrides/"$$sapi"; \
	done

	# directories cleanup:
	-rmdir -p debian/libapache2-mod-php5/usr/share/man/man1
	-find debian/php-pear -type d -exec rmdir --ignore-fail-on-non-empty -p '{}' \; >/dev/null 2>&1

	touch install-stamp

# Build architecture-independent files here.
# Pass -i to all debhelper commands in this target to reduce clutter.
binary-indep: DH_OPTIONS=-i
binary-indep: build install
	# Need this version of debhelper for DH_OPTIONS to work.
	dh_testdir
	dh_testroot
	cat debian/copyright.header LICENSE Zend/LICENSE > debian/copyright

	dh_installdocs

	for package in php5 php-pear; do \
		rm -rf debian/$$package/usr/share/doc/$$package; \
		ln -s php5-common debian/$$package/usr/share/doc/$$package; \
	done

	dh_link
	dh_compress -Xphp.ini
	dh_fixperms
	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb

# Build architecture-dependent files here.
binary-arch: build install
	# Need this version of debhelper for DH_OPTIONS to work.
	dh_testdir
	dh_testroot
	# Do this first so we don't overwrite any debhelper-generated files
	#
	# generate the maintscripts for various php
	# modules from the templates.
	cat debian/modulelist | while read package extname dsoname; do \
		if [ -z "$$dsoname" ]; then dsoname=$$package; fi; \
		sed -e"s/@extname@/$$extname/g; s/@dsoname@/$$dsoname/g; \
		       /#EXTRA#/ r debian/php5-$${package}.postinst.extra" \
		  < debian/php5-module.postinst \
		| sed -e'/#EXTRA#/ d' \
		  > debian/php5-$${package}.postinst; \
	done

	# generate the config snippets for various php
	# modules from the templates.
	cat debian/modulelist debian/extramodulelist | while read package extname dsoname; do \
		if [ -z "$$dsoname" ]; then dsoname=$$package; fi; \
		mkdir -p debian/php5-$$package/etc/php5/conf.d; \
		sed -e"s/@extname@/$$extname/g; s/@dsoname@/$$dsoname/g" \
		  < debian/php5-module.ini \
		  > debian/php5-$${package}/etc/php5/conf.d/$${dsoname}.ini; \
	done

	# likewise, for the different sapi implementations
	for tmpl in postrm links; do \
		for sapi in apache2 apache2filter cgi cli; do \
			sed -e "s/@sapi@/$$sapi/g" \
		  	< debian/php5-sapi.$$tmpl \
		  	> debian/php5-$${sapi}.$$tmpl; \
		done; \
		mv debian/php5-apache2.$$tmpl debian/libapache2-mod-php5.$$tmpl; \
		mv debian/php5-apache2filter.$$tmpl debian/libapache2-mod-php5filter.$$tmpl; \
	done

	cat debian/copyright.header LICENSE Zend/LICENSE > debian/copyright
	dh_installdocs -s

	cat debian/modulelist | while read package extname dsoname; do \
		rm -rf debian/php5-$$package/usr/share/doc/php5-$$package; \
		ln -s php5-common debian/php5-$$package/usr/share/doc/php5-$$package; \
	done

	for package in php5-dbg php5-dev php5-cgi php5-cli libapache2-mod-php5 libapache2-mod-php5filter; do \
		rm -rf debian/$$package/usr/share/doc/$$package; \
		ln -s php5-common debian/$$package/usr/share/doc/$$package; \
	done
	dh_installcron -pphp5-common --name=php5
	dh_installchangelogs -pphp5-common NEWS
	dh_strip -s --dbg-package=php5-dbg
	dh_link -s
	dh_compress -s -Xphp.ini
	dh_fixperms -s -X /var/lib/php5
	dh_installdeb -s
	dh_shlibdeps -s

	phpapi=`./debian/php5-dev/usr/bin/php-config5 --phpapi`; \
	for i in libapache2-mod-php5 libapache2-mod-php5filter php5-cgi php5-cli; do \
		echo "php:Provides=phpapi-$${phpapi}" >> debian/$$i.substvars; \
	done; \
	cat debian/modulelist | while read package extname dsoname; do \
		echo "php:Depends=php5 | phpapi-$${phpapi}" >> debian/php5-$$package.substvars; \
	done

	for i in cgi cli; do \
		"$$i"-build/sapi/cli/php -n -r '$(BUILTIN_EXTENSION_CHECK)' \
			>> debian/php5-"$$i".substvars; \
	done
	for i in apache2; do \
		"$$i"-build/sapi/cli/php -n -r '$(BUILTIN_EXTENSION_CHECK)' \
			>> debian/lib"$$i"-mod-php5.substvars; \
		"$$i"-build/sapi/cli/php -n -r '$(BUILTIN_EXTENSION_CHECK)' \
			>> debian/lib"$$i"-mod-php5filter.substvars; \
	done

	echo "apache2:Depends=apache2-mpm-prefork (>> 2.0.52) | apache2-mpm-itk, apache2.2-common" >>debian/libapache2-mod-php5.substvars
	echo "apache2:Depends=apache2-mpm-prefork (>> 2.0.52) | apache2-mpm-itk, apache2.2-common" >>debian/libapache2-mod-php5filter.substvars

	echo "libtool:Conflicts=$(LIBTOOL_CONFLICTS)" >>debian/php5-dev.substvars
	dh_gencontrol -s
	dh_md5sums -s
	dh_builddeb -s

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