| 12
 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
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 
 | #!/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
# enable dpkg build flags
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk
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)
DEB_HOST_ARCH_OS     ?= $(shell dpkg-architecture -qDEB_HOST_ARCH_OS)
DEB_HOST_MULTIARCH   ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
export DEB_HOST_MULTIARCH
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/.*-//")
RUN_TESTS = yes
ifeq (nocheck,$(findstring nocheck,$(DEB_BUILD_OPTIONS)))
  $(warning Disabling checks due DEB_BUILD_OPTIONS)
  RUN_TESTS = no
endif
ifeq ($(DEB_HOST_ARCH),$(filter $(DEB_HOST_ARCH),hurd-i386 mips mipsel ppc64 ppc64el))
  $(warning Disabling checks on $(DEB_HOST_ARCH))
  RUN_TESTS = no
endif
ifneq ($(DEB_HOST_ARCH),$(filter $(DEB_HOST_ARCH),hurd-i386 m68k hppa ppc64))
  CONFIGURE_APACHE_ARGS = --with-interbase=shared,/usr --with-pdo-firebird=shared,/usr
else
  CONFIGURE_APACHE_ARGS = --without-interbase --without-pdo-firebird
endif
ifeq (yes,$(RUN_TESTS))
  MYSQL_PORT := $(shell for i in $$(seq 1025 3600 | sort -R); do nc -z localhost $$i || { echo $$i; exit; } ; done)
  MYSQL_DATA_DIR ?= $(shell readlink -f mysql_db)
  ifeq (,$(MYSQL_PORT))
      $(error Could not find available port for mysql server)
  endif
  MYSQL_SOCKET = $(MYSQL_DATA_DIR)/mysql.sock
endif
ifeq (linux,$(DEB_HOST_ARCH_OS))
  CONFIGURE_SYSTEMD = --with-fpm-systemd
else
  CONFIGURE_SYSTEMD = --without-fpm-systemd
endif
ifeq ($(DEB_HOST_ARCH),$(filter $(DEB_HOST_ARCH),amd64 armel armhf i386 ia64 powerpc))
  CONFIGURE_DTRACE_ARGS = --enable-dtrace
else
  CONFIGURE_DTRACE_ARGS = --disable-dtrace
endif
# 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
else
  CFLAGS += -O0
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
# Enable producing of debugging information
CFLAGS += -g
# 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
ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
    NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
    MAKEFLAGS += -j$(NUMJOBS)
endif
COMMON_CONFIG=--build=$(DEB_BUILD_GNU_TYPE) \
		--host=$(DEB_HOST_GNU_TYPE) \
		--sysconfdir=/etc \
		--localstatedir=/var \
		--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 \
		--with-qdbm=/usr \
		--without-gdbm \
		--with-iconv \
		--enable-exif \
		--enable-ftp \
		--with-gettext \
		--enable-mbstring \
		--with-onig=/usr \
		--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-mhash=yes \
		--with-system-tzdata \
		--with-mysql-sock=/var/run/mysqld/mysqld.sock \
		$(CONFIGURE_DTRACE_ARGS)
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}"));
prepared: prepared-stamp
prepared-stamp:
	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 build-phpdbg-stamp
ifeq (yes,$(RUN_TESTS))
	mkdir -p temp_session_store
	# start our own mysql server for the tests
	$(SHELL) -x debian/setup-mysql.sh $(MYSQL_PORT) $(MYSQL_DATA_DIR)
	extensions=""; \
	for f in $(CURDIR)/apache2-build/modules/*.so; do \
	    ext=`basename "$$f"`; \
	    test -d "$(CURDIR)/ext/$${ext%.so}/tests" || continue; \
	    test "$$ext" != "imap.so" || continue; \
	    test "$$ext" != "interbase.so" || continue; \
	    test "$$ext" != "ldap.so" || continue; \
	    test "$$ext" != "odbc.so" || continue; \
	    test "$$ext" != "pgsql.so" || continue; \
	    test "$$ext" != "pdo_dblib.so" || continue; \
	    test "$$ext" != "pdo_firebird.so" || continue; \
	    test "$$ext" != "pdo_odbc.so" || continue; \
	    test "$$ext" != "pdo_pgsql.so" || continue; \
	    test "$$ext" != "snmp.so" || continue; \
	    test "$$ext" != "opcache.so" || continue; \
	    extensions="$$extensions -d extension=$$ext"; \
	done; \
	[ "$$extensions" ] || { echo "extensions list is empty"; exit 1; }; \
	env MYSQL_TEST_HOST=127.0.0.1 MYSQL_TEST_PORT=$(MYSQL_PORT) MYSQL_TEST_SOCKET=$(MYSQL_SOCKET) PDO_MYSQL_TEST_HOST=127.0.0.1 PDO_MYSQL_TEST_PORT=$(MYSQL_PORT) PDO_MYSQL_TEST_SOCKET=$(MYSQL_SOCKET) NO_INTERACTION=1 TEST_PHP_CGI_EXECUTABLE=$(CURDIR)/cgi-build/sapi/cgi/cgi-bin.php5 TEST_PHP_EXECUTABLE=$(CURDIR)/cli-build/sapi/cli/php \
	$(CURDIR)/cli-build/sapi/cli/php run-tests.php -n -d mysql.default_host=127.0.0.1 -d mysql.default_socket=$(MYSQL_SOCKET) -d mysqli.default_socket=$(MYSQL_SOCKET) -d extension_dir=$(CURDIR)/apache2-build/modules/ $$extensions| tee test-results.txt
	rm -rf temp_session_store
	@for test in `find . -name '*.log' -a '!' -name 'config.log' -a '!' -name 'bootstrap.log' -a '!' -name 'run.log'`; do \
	    echo; \
	    echo -n "$${test#./}:"; \
	    cat $$test; \
	    echo; \
	done | tee -a test-results.txt
	$(SHELL) -x debian/setup-mysql.sh $(MYSQL_PORT) $(MYSQL_DATA_DIR) stop
else
	echo 'nocheck found in DEB_BUILD_OPTIONS or unsupported architecture' | tee test-results.txt
endif
build: build-apache2-stamp build-apache2filter-stamp build-cgi-stamp build-cli-stamp build-phpdbg-stamp build-embed-stamp build-fpm-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-phpdbg-stamp: configure-phpdbg-stamp
	dh_testdir
	cd phpdbg-build && $(MAKE)
	touch build-phpdbg-stamp
build-embed-stamp: configure-embed-stamp
	dh_testdir
	cd embed-build && $(MAKE)
	touch build-embed-stamp
build-fpm-stamp: configure-fpm-stamp
	dh_testdir
	cd fpm-build && $(MAKE)
	touch build-fpm-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
	patch -s -d $(CURDIR)/pear-build/usr/share/php/ -p1 -i $(CURDIR)/debian/PEAR-Builder-print-info-about-php5-dev.patch
	touch build-pear-stamp
configure: configure-apache2-stamp configure-apache2filter-stamp configure-cli-stamp configure-phpdbg-stamp configure-embed-stamp configure-fpm-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-enchant=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-vpx-dir=shared,/usr \
		--with-imap=shared,/usr \
		--with-imap-ssl \
		--enable-intl=shared \
		--without-t1lib \
		--with-ldap=shared,/usr \
		--with-ldap-sasl=/usr \
		--with-mcrypt=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-sqlite3=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 \
		$(CONFIGURE_APACHE_ARGS)
	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-sqlite3
	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 \
		--enable-pdo=shared \
		--enable-mysqlnd=shared \
		--with-mysql=shared,mysqlnd \
		--with-mysqli=shared,mysqlnd \
		--with-pdo-mysql=shared,mysqlnd \
		--without-pdo-sqlite \
		--without-sybase-ct --without-mssql \
		--without-sqlite3 \
		--enable-pcntl
	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-mssql --without-sqlite3 --enable-pcntl \
		--with-libedit=shared
	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
configure-phpdbg-stamp: prepared-stamp
	dh_testdir
	if [ -d phpdbg-build ]; then rm -rf phpdbg-build; fi
	-mkdir phpdbg-build
	cd phpdbg-build && \
        CFLAGS="$(CFLAGS)" PROG_SENDMAIL="$(PROG_SENDMAIL)" ../configure \
		--prefix=/usr --disable-cgi --enable-phpdbg \
		--with-config-file-path=/etc/php5/phpdbg \
		--with-config-file-scan-dir=/etc/php5/phpdbg/conf.d \
		$(COMMON_CONFIG) \
		--without-mm \
		--disable-pdo \
		--without-mysql --without-sybase-ct \
		--without-mssql --without-sqlite3 --enable-pcntl \
		--with-libedit=shared
	cd phpdbg-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-phpdbg-stamp
configure-embed-stamp: prepared-stamp
	dh_testdir
	if [ -d embed-build ]; then rm -rf embed-build; fi
	-mkdir embed-build
	cd embed-build && \
        CFLAGS="$(CFLAGS)" PROG_SENDMAIL="$(PROG_SENDMAIL)" ../configure \
		--prefix=/usr --enable-embed --disable-cgi \
		--with-config-file-path=/etc/php5/embed \
		--with-config-file-scan-dir=/etc/php5/embed/conf.d \
		$(COMMON_CONFIG) \
		--without-mm \
		--disable-pdo \
		--without-mysql --without-sybase-ct \
		--without-mssql --without-sqlite3 --enable-pcntl
	cd embed-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-embed-stamp
configure-fpm-stamp: prepared-stamp
	dh_testdir
	if [ -d fpm-build ]; then rm -rf fpm-build; fi
	-mkdir fpm-build
	cd fpm-build && \
        CFLAGS="$(CFLAGS)" PROG_SENDMAIL="$(PROG_SENDMAIL)" ../configure \
		--prefix=/usr --enable-fpm --disable-cgi \
		--with-fpm-user=www-data --with-fpm-group=www-data \
		--with-config-file-path=/etc/php5/fpm \
		--with-config-file-scan-dir=/etc/php5/fpm/conf.d \
		$(COMMON_CONFIG) \
		--with-libevent-dir=/usr \
		--without-mm \
		--disable-pdo \
		--without-mysql --without-sybase-ct \
		--without-mssql --without-sqlite3 \
		$(CONFIGURE_SYSTEMD)
	cd fpm-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-fpm-stamp
clean: unprepared
	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 configure-phpdbg-stamp build-phpdbg-stamp
	rm -f configure-embed-stamp build-embed-stamp
	rm -f configure-fpm-stamp build-fpm-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 phpdbg-build
	rm -rf embed-build
	rm -rf fpm-build
	rm -rf pear-build pear-build-download
	# just in case the build tests failed, kill the running mysqld
	$(SHELL) debian/setup-mysql.sh $(MYSQL_PORT) $(MYSQL_DATA_DIR) stop > /dev/null 2>&1 || exit 0
	rm -rf test-results.txt $(MYSQL_DATA_DIR)
	dh_clean -Xorig
	# clean up autogenerated cruft
	cat debian/modulelist | while read package extname dsoname priority; do \
		rm -f debian/php5-$$package.postinst; \
		rm -f debian/php5-$$package.preinst; \
		rm -f debian/php5-$$package.prerm; \
		rm -f debian/php5-$$package.postrm; \
	done
	for sapi in libapache2-mod-php5 libapache2-mod-php5filter php5-cgi php5-cli php5-phpdbg libphp5-embed php5-fpm; do \
		for cruft in postrm links; do \
			rm -f debian/$${sapi}.$${cruft}; \
		done; \
	done
PCNTL_FUNCTIONS := $(shell < ext/pcntl/php_pcntl.h sed -ne "/^PHP_FUNCTION/ s/PHP_FUNCTION(\(.*\));/\1/;t end;d;:end p" | tr '\n' ',')
install: DH_OPTIONS=
install: build
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs
	chmod 01733 debian/php5-common/var/lib/php5/sessions/
	# Mangle apache2filter DSO name before running dh_apache2
	mv apache2filter-build/.libs/libphp5.so apache2filter-build/.libs/libphp5filter.so
	# install apache2 DSO module
	dh_apache2 --conditional=php5_enable
	# sanitize php.ini file
	cat php.ini-production | tr "\t" " " | \
	sed -e'/session.gc_probability =/ s/1/0/g;' \
	    -e'/disable_functions =/ s/$$/ $(PCNTL_FUNCTIONS)/g;' \
	    -e'/expose_php =/ s/On/Off/g;' \
	  > debian/php5-common/usr/share/php5/php.ini-production
	cat php.ini-production | tr "\t" " " | \
	sed -e'/memory_limit =/ s/128M/-1/g;' \
	    -e'/session.gc_probability =/ s/1/0/g' \
	  > debian/php5-common/usr/share/php5/php.ini-production.cli
	cat php.ini-development | tr "\t" " " | \
	sed -e'/session.gc_probability =/ s/1/0/g;' \
	    -e'/disable_functions =/ s/$$/ $(PCNTL_FUNCTIONS)/g;' \
	  > debian/php5-common/usr/share/php5/php.ini-development
ifeq (yes,$(RUN_TESTS))
	cp test-results.txt debian/php5-common/usr/share/doc/php5-common/
endif
	# Install reportbug for php5 package
	mkdir -p debian/php5/usr/share/bug/php5
	install -m644 debian/php5.bug.control debian/php5/usr/share/bug/php5/control
	ln -s ../php5-common/script debian/php5/usr/share/bug/php5/script
	# Install helper shell fragment
	install -m644 debian/php5-helper $(CURDIR)/debian/php5-common/usr/share/php5/
	install -m644 debian/debhelper/php5-maintscript-helper $(CURDIR)/debian/php5-common/usr/share/php5/
	# install embed SAPI
	cd embed-build && make install-headers install-build install-sapi install-programs INSTALL_ROOT=$(CURDIR)/debian/libphp5-embed
	# install the apache modules' files
	cd apache2-build && $(MAKE) install-headers install-build install-modules install-programs INSTALL_ROOT=$(CURDIR)/debian/libapache2-mod-php5
	# install the headers from cgi-build
	cd cgi-build && $(MAKE) install-headers INSTALL_ROOT=$(CURDIR)/debian/php5-dev
	# 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
	[ ! -f debian/php-pear/usr/share/php/doc/Structures_Graph/docs/generate.sh ] || \
		$(RM) debian/php-pear/usr/share/php/doc/Structures_Graph/docs/generate.sh
	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 ] && { \
		mkdir -p debian/php-pear/usr/share/doc/php5-common/PEAR; \
		mv debian/php-pear/usr/share/php/doc/* \
			debian/php-pear/usr/share/doc/php5-common/PEAR/; \
		$(RM) -r debian/php-pear/usr/share/php/doc; \
		ln -s ../doc/php-pear/PEAR debian/php-pear/usr/share/php/doc; \
		echo "Dummy placeholder to prevent the directory's deletion" > \
			debian/php-pear/usr/share/doc/php5-common/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 php5-phpdbg libphp5-embed php5-fpm; do \
		mkdir -p debian/$$i/$${ext}; \
	done; \
	cat debian/modulelist debian/extramodulelist | while read package extname dsoname priority; do \
		if [ "$$package" = "mysqlnd" ]; then \
			modulepath=cgi-build/modules; \
		elif [ "$$package" = "readline" ]; then \
			modulepath=cli-build/modules; \
		else \
			modulepath=debian/libapache2-mod-php5/$${ext}; \
		fi; \
		if [ -z "$$dsoname" ]; then dsoname=$$package; fi; \
		mkdir -p debian/php5-$$package$${ext}; \
		install -m 644 -o root -g root \
			$${modulepath}/$$dsoname.so \
			debian/php5-$$package$${ext}/$$dsoname.so; \
		rm $${modulepath}/$$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
	cp cli-build/ext/phar/phar.phar debian/php5-cli/usr/bin/phar5
	cp cli-build/ext/phar/phar.1 debian/php5-cli/usr/share/man/man1/phar5.1
	# install PHPDBG
	cp phpdbg-build/sapi/phpdbg/phpdbg debian/php5-phpdbg/usr/bin/php5dbg
	cp debian/php5dbg.1 debian/php5-phpdbg/usr/share/man/man1/php5dbg.1
	# install FPM
	mkdir -p debian/php5-fpm/usr/sbin debian/php5-fpm/usr/share/man/man8/ debian/php5-fpm/etc/php5/fpm/pool.d
	cp fpm-build/sapi/fpm/php-fpm debian/php5-fpm/usr/sbin/php5-fpm
	cp fpm-build/sapi/fpm/php-fpm.8 debian/php5-fpm/usr/share/man/man8/php5-fpm.8
	# we don't want the pool definitions on the main file itself:
	sed -r '/('"'"'|\[)www('"'"'|\])/Q' < fpm-build/sapi/fpm/php-fpm.conf | \
	sed -e's{pid = /var/run/php5-fpm.pid{pid = /run/php5-fpm.pid{' \
	    > debian/php5-fpm/etc/php5/fpm/php-fpm.conf
	# extract the first pool, called "www," from the config file:
	sed -nr '/('"'"'|\[)www('"'"'|\])/{h;p;d};x;/www/{x;p}' < fpm-build/sapi/fpm/php-fpm.conf | \
	sed -e's{^;listen\.owner{listen.owner{;' \
            -e's{^;listen\.group{listen.group{;' \
	    > debian/php5-fpm/etc/php5/fpm/pool.d/www.conf
	# install a helper script for checking PHP FPM configuration
	install -m 755 debian/php5-fpm-checkconf debian/php5-fpm/usr/lib/php5/
	install -m 755 debian/php5-fpm-reopenlogs debian/php5-fpm/usr/lib/php5/
	# move and install -dev files
	dh_movefiles --sourcedir=debian/libphp5-embed
	dh_movefiles --sourcedir=debian/libapache2-mod-php5
	rm -rf debian/libphp5-embed/usr/include/ \
	       debian/libphp5-embed/usr/bin/
	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
	mkdir -p debian/php5-dev/usr/share/php5
	cp -a ext/skeleton ext/ext_skel debian/php5-dev/usr/share/php5
	sed -i 's/skel_dir="skeleton"/skel_dir="\/usr\/share\/php5\/skeleton"/' \
	    debian/php5-dev/usr/share/php5/ext_skel
	# 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
	# remove windows devel file
	rm $(CURDIR)/debian/php5-dev/usr/share/php5/skeleton/skeleton.dsp
	# install common files
	install -m755 debian/sessionclean debian/php5-common/usr/lib/php5
	install -m755 debian/php5enmod debian/php5-common/usr/sbin/php5enmod
	ln -s php5enmod debian/php5-common/usr/sbin/php5dismod
	install -m755 debian/php5query $(CURDIR)/debian/php5-common/usr/sbin/php5query
	# remove libtool files
	rm $(CURDIR)/debian/libphp5-embed/usr/lib/php5/libphp5.la
	mv $(CURDIR)/debian/libphp5-embed/usr/lib/php5/* $(CURDIR)/debian/libphp5-embed/usr/lib/
	# install lintian overrides
	cp debian/php5-common.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
	cp debian/php-pear.lintian-overrides $(CURDIR)/debian/php-pear/usr/share/lintian/overrides/php-pear
	# install some generic lintian overrides
	ext=`debian/php5-dev/usr/bin/php-config5 --extension-dir | cut -b2- `; \
	for sapi in php5-cli php5-phpdbg php5-fpm php5-cgi libapache2-mod-php5 libapache2-mod-php5filter libphp5-embed; 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 | \
		grep -E "^$${sapi}: " \
		    >> $(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
	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 config snippets for various php
	# modules from the templates.
	cat debian/modulelist debian/extramodulelist | while read package extname dsoname priority extension; do \
		if [ -z "$${dsoname}" ]; then dsoname=$$package; fi; \
		if [ -z "$${priority}" ]; then priority=20; fi; \
		if [ -z "$${extension}" ]; then extension=extension; fi; \
		mkdir -p debian/php5-$$package/usr/share/php5/$$package; \
		sed -e"s|@extname@|$${extname}|g; \
		       s/@dsoname@/$${dsoname}/g; \
		       s/@extension@/$${extension}/g; \
		       s/@priority@/$${priority}/g" \
		  < debian/php5-module.ini \
		  > debian/php5-$$package/usr/share/php5/$$package/$${dsoname}.ini; \
		echo -n "$$dsoname " >> debian/php5-$$package.modules; \
	done
	# generate the maintscripts for various php
	# modules from the templates.
	cat debian/modulelist | while read package extname dsoname priority; do \
	    modules=$$(cat debian/php5-$$package.modules); \
	    for script in postinst preinst postrm prerm; do \
	        sed -e"s/@package@/$${package}/g; \
	               s/@modules@/$${modules}/g; \
	                /#EXTRA#/ r debian/php5-$${package}.$${script}.extra" \
	          < debian/php5-module.$${script} \
	        | sed -e'/#EXTRA#/ d' \
	          > debian/php5-$${package}.$${script}; \
	    done; \
	    cp debian/php5-module.triggers debian/php5-$${package}.triggers; \
	    rm debian/php5-$$package.modules; \
	    mkdir -p debian/php5-$$package/usr/share/bug/php5-$$package; \
	    sed -e"s/@package@/$${package}/g; \
	           s/@modules@/$${modules}/g;" \
	      < debian/php5-module.bug.script \
	      > debian/php5-$$package/usr/share/bug/php5-$$package/script; \
	    chmod 755 debian/php5-$$package/usr/share/bug/php5-$$package/script; \
	    cp debian/php5-module.bug.control debian/php5-$$package/usr/share/bug/php5-$$package/control; \
	done
	# likewise, for the different sapi implementations
	for tmpl in postrm prerm postinst; do \
		for sapi in cgi cli fpm phpdbg; do \
			sed -e "s/@sapi@/$${sapi}/g; \
	                        s/@package@/php5-$${sapi}/g; \
	                         /#EXTRA#/ r debian/php5-$${sapi}.$${tmpl}.extra" \
		  	< debian/php5-sapi.$${tmpl} \
	                | sed -e'/#EXTRA#/ d' \
		  	> debian/php5-$${sapi}.$${tmpl}; \
			mkdir -p "$(CURDIR)/debian/php5-$$sapi/usr/share/php5/sapi/"; \
			touch "$(CURDIR)/debian/php5-$$sapi/usr/share/php5/sapi/$$sapi"; \
			mkdir -p debian/php5-$$sapi/usr/share/bug/php5-$$sapi; \
			sed -e "s/@sapi@/$${sapi}/g; \
	                        s/@package@/php5-$${sapi}/g;" \
			  < debian/php5-sapi.bug.script \
			  > debian/php5-$$sapi/usr/share/bug/php5-$$sapi/script; \
			chmod 755 debian/php5-$$sapi/usr/share/bug/php5-$$sapi/script; \
			cp debian/php5-sapi.bug.control debian/php5-$$sapi/usr/share/bug/php5-$$sapi/control; \
		done; \
		for sapi in embed; do \
			sed -e "s/@sapi@/$${sapi}/g; \
	                        s/@package@/libphp5-$${sapi}/g; \
	                         /#EXTRA#/ r debian/libphp5-$${sapi}.$${tmpl}.extra" \
		  	< debian/php5-sapi.$${tmpl} \
	                | sed -e'/#EXTRA#/ d' \
		  	> debian/libphp5-$${sapi}.$${tmpl}; \
			mkdir -p "$(CURDIR)/debian/libphp5-$$sapi/usr/share/php5/sapi/"; \
			touch "$(CURDIR)/debian/libphp5-$$sapi/usr/share/php5/sapi/$$sapi"; \
			mkdir -p debian/libphp5-$$sapi/usr/share/bug/libphp5-$$sapi; \
			sed -e "s/@sapi@/$${sapi}/g; \
	                        s/@package@/libphp5-$${sapi}/g;" \
			  < debian/php5-sapi.bug.script \
			  > debian/libphp5-$$sapi/usr/share/bug/libphp5-$$sapi/script; \
			chmod 755 debian/libphp5-$$sapi/usr/share/bug/libphp5-$$sapi/script; \
			cp debian/php5-sapi.bug.control debian/libphp5-$$sapi/usr/share/bug/libphp5-$$sapi/control; \
		done; \
	        for sapi in "" "filter"; do \
		        sed -e "s/@sapi@/apache2$${sapi}/g; \
	                        s/@package@/libapache2-mod-php5$${sapi}/g; \
	                         /#EXTRA#/ r debian/libapache2-mod-php5$${sapi}.$${tmpl}.extra" \
		        < debian/php5-sapi.$${tmpl} \
	                | sed -e'/#EXTRA#/ d' \
		        > debian/libapache2-mod-php5$${sapi}.$${tmpl}; \
			mkdir -p "$(CURDIR)/debian/libapache2-mod-php5$$sapi/usr/share/php5/sapi/"; \
			touch "$(CURDIR)/debian/libapache2-mod-php5$$sapi/usr/share/php5/sapi/apache2$$sapi"; \
			mkdir -p debian/libapache2-mod-php5$$sapi/usr/share/bug/libapache2-mod-php5$$sapi; \
		        sed -e "s/@sapi@/apache2$${sapi}/g; \
	                        s/@package@/libapache2-mod-php5$${sapi}/g;" \
			  < debian/php5-sapi.bug.script \
			  > debian/libapache2-mod-php5$$sapi/usr/share/bug/libapache2-mod-php5$$sapi/script; \
			chmod 755 debian/libapache2-mod-php5$$sapi/usr/share/bug/libapache2-mod-php5$$sapi/script; \
			cp debian/php5-sapi.bug.control debian/libapache2-mod-php5$$sapi/usr/share/bug/libapache2-mod-php5$$sapi/control; \
	        done; \
	done
	dh_installdocs -s
	cat debian/modulelist | grep -v common | while read package extname dsoname priority; 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 php5-phpdbg php5-fpm libapache2-mod-php5 libapache2-mod-php5filter libphp5-embed; do \
		rm -rf debian/$$package/usr/share/doc/$$package; \
		ln -s php5-common debian/$$package/usr/share/doc/$$package; \
	done
	dh_perl
	dh_installlogrotate -pphp5-fpm
	dh_installcron -pphp5-common --name=php5
	dh_installchangelogs -pphp5-common NEWS
	dh_systemd_enable
	dh_installinit
	dh_systemd_start
	dh_link -s
	dh_compress -s -Xphp.ini
	dh_fixperms -s -X/var/lib/php5
	dh_strip -s --dbg-package=php5-dbg
	dh_makeshlibs -s -plibphp5-embed -V 'libphp5-embed (>= 5.6.0)'
	dh_shlibdeps -s
	dh_installdeb -s
	phpapi=`./debian/php5-dev/usr/bin/php-config5 --phpapi`; \
	stored=`cat debian/phpapi`; \
	if [ "$${phpapi}" != "$${stored}" ]; then echo "PHPAPI has changed, please modify debian/phpapi"; exit 1; fi; \
	for i in php5-common; do \
		echo "php:Provides=phpapi-$${phpapi}" >> debian/$$i.substvars; \
	done; \
	cat debian/modulelist | while read package extname dsoname priority; do \
		echo "php:Depends=phpapi-$${phpapi}" >> debian/php5-$$package.substvars; \
	done
	for i in cgi cli fpm phpdbg; do \
		"$$i"-build/sapi/cli/php -n -r '$(BUILTIN_EXTENSION_CHECK)' \
			>> debian/php5-"$$i".substvars; \
	done
	for i in embed; do \
		"$$i"-build/sapi/cli/php -n -r '$(BUILTIN_EXTENSION_CHECK)' \
			>> debian/libphp5-"$$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"filter-build/sapi/cli/php -n -r '$(BUILTIN_EXTENSION_CHECK)' \
			>> debian/lib"$$i"-mod-php5filter.substvars; \
	done
	echo "libtool:Conflicts=$(LIBTOOL_CONFLICTS)" >>debian/php5-dev.substvars
	dh_gencontrol -s
	dh_md5sums -s
	dh_builddeb -s
binary: binary-arch binary-indep
build-arch: build
build-indep: build
.PHONY: build build-arch build-indep clean binary-indep binary-arch binary install configure
 |