forked from phpbrew/phpbrew
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVariantBuilder.php
1068 lines (882 loc) · 36.4 KB
/
VariantBuilder.php
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
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
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
namespace PhpBrew;
use Exception;
use PhpBrew\Exception\OopsException;
use PhpBrew\PrefixFinder\BrewPrefixFinder;
use PhpBrew\PrefixFinder\ExecutablePrefixFinder;
use PhpBrew\PrefixFinder\IncludePrefixFinder;
use PhpBrew\PrefixFinder\LibPrefixFinder;
use PhpBrew\PrefixFinder\PkgConfigPrefixFinder;
use PhpBrew\PrefixFinder\UserProvidedPrefix;
function first_existing_executable($possiblePaths)
{
$existingPaths = array_filter(
array_filter(
array_filter($possiblePaths, 'file_exists'),
'is_file'
),
'is_executable'
);
if (!empty($existingPaths)) {
return realpath($existingPaths[0]);
}
return false;
}
function exec_line($command)
{
$output = array();
exec($command, $output, $retval);
if ($retval === 0) {
$output = array_filter($output);
return end($output);
}
return false;
}
/**
* VariantBuilder build variants to `./configure' parameters.
*/
class VariantBuilder
{
/**
* Available variant definitions.
*
* @var array<string,string|array<string>|callable>
*/
private $variants = array();
private $conflicts = array(
// PHP Version lower than 5.4.0 can only built one SAPI at the same time.
'apxs2' => array('fpm', 'cgi'),
'editline' => array('readline'),
'readline' => array('editline'),
// dtrace is not compatible with phpdbg: https://github.com/krakjoe/phpdbg/issues/38
'dtrace' => array('phpdbg'),
);
/**
* @var array is for checking built variants
*
* contains ['-pdo','mysql','-sqlite','-debug']
*/
private $builtList = array();
public $virtualVariants = array(
'dbs' => array(
'sqlite',
'mysql',
'pgsql',
'pdo',
),
'mb' => array(
'mbstring',
'mbregex',
),
// provide no additional feature
'neutral' => array(),
'small' => array(
'bz2',
'cli',
'dom',
'filter',
'ipc',
'json',
'mbregex',
'mbstring',
'pcre',
'phar',
'posix',
'readline',
'xml',
'curl',
'openssl',
),
// provide all basic features
'default' => array(
'bcmath',
'bz2',
'calendar',
'cli',
'ctype',
'dom',
'fileinfo',
'filter',
'ipc',
'json',
'mbregex',
'mbstring',
'mhash',
'pcntl',
'pcre',
'pdo',
'pear',
'phar',
'posix',
'readline',
'sockets',
'tokenizer',
'xml',
'curl',
'openssl',
'zip',
),
// variant for DiscordPHP
'dphp' => array(
'bcmath',
'bz2',
'calendar',
'cli',
'ctype',
'dom',
'fileinfo',
'filter',
'ipc',
'json',
'mbregex',
'mbstring',
'mhash',
'pcntl',
'pcre',
'pdo',
'pear',
'phar',
'posix',
'readline',
'sockets',
'tokenizer',
'xml',
'curl',
'openssl',
'zip',
'iconv',
'sodium',
'zlib',
),
);
public function __construct()
{
// init variant builders
$this->variants['all'] = '--enable-all';
$this->variants['dba'] = '--enable-dba';
$this->variants['ipv6'] = '--enable-ipv6';
$this->variants['dom'] = '--enable-dom';
$this->variants['calendar'] = '--enable-calendar';
$this->variants['wddx'] = '--enable-wddx';
$this->variants['static'] = '--enable-static';
$this->variants['inifile'] = '--enable-inifile';
$this->variants['inline'] = '--enable-inline-optimization';
$this->variants['cli'] = '--enable-cli';
$this->variants['ftp'] = '--enable-ftp';
$this->variants['filter'] = '--enable-filter';
$this->variants['gcov'] = '--enable-gcov';
$this->variants['zts'] = function (ConfigureParameters $params, Build $build) {
if ($build->compareVersion('8.0') < 0) {
return $params->withOption('--enable-maintainer-zts');
}
return $params->withOption('--enable-zts');
};
$this->variants['json'] = '--enable-json';
$this->variants['hash'] = '--enable-hash';
$this->variants['exif'] = '--enable-exif';
$this->variants['mbstring'] = function (ConfigureParameters $params, Build $build, $value) {
$params = $params->withOption('--enable-mbstring');
if ($build->compareVersion('7.4') >= 0 && !$build->isDisabledVariant('mbregex')) {
$prefix = Utils::findPrefix(array(
new UserProvidedPrefix($value),
new IncludePrefixFinder('oniguruma.h'),
new BrewPrefixFinder('oniguruma'),
));
if ($prefix !== null) {
$params = $params->withPkgConfigPath($prefix . '/lib/pkgconfig');
}
}
return $params;
};
$this->variants['mbregex'] = '--enable-mbregex';
$this->variants['libgcc'] = '--enable-libgcc';
$this->variants['pdo'] = '--enable-pdo';
$this->variants['posix'] = '--enable-posix';
$this->variants['embed'] = '--enable-embed';
$this->variants['sockets'] = '--enable-sockets';
$this->variants['debug'] = '--enable-debug';
$this->variants['phpdbg'] = '--enable-phpdbg';
$this->variants['zip'] = function (ConfigureParameters $params, Build $build) {
if ($build->compareVersion('7.4') < 0) {
return $params->withOption('--enable-zip');
}
return $params->withOption('--with-zip');
};
$this->variants['bcmath'] = '--enable-bcmath';
$this->variants['fileinfo'] = '--enable-fileinfo';
$this->variants['ctype'] = '--enable-ctype';
$this->variants['cgi'] = '--enable-cgi';
$this->variants['soap'] = '--enable-soap';
$this->variants['gcov'] = '--enable-gcov';
$this->variants['pcntl'] = '--enable-pcntl';
$this->variants['phar'] = '--enable-phar';
$this->variants['session'] = '--enable-session';
$this->variants['tokenizer'] = '--enable-tokenizer';
$this->variants['opcache'] = '--enable-opcache';
$this->variants['imap'] = function (ConfigureParameters $params, Build $build, $value) {
$imapPrefix = Utils::findPrefix(array(
new UserProvidedPrefix($value),
new BrewPrefixFinder('imap-uw'),
));
$kerberosPrefix = Utils::findPrefix(array(
new BrewPrefixFinder('krb5'),
));
$opensslPrefix = Utils::findPrefix(array(
new BrewPrefixFinder('openssl'),
new PkgConfigPrefixFinder('openssl'),
new IncludePrefixFinder('openssl/opensslv.h'),
));
return $params->withOption('--with-imap', $imapPrefix)
->withOptionOrPkgConfigPath($build, '--with-kerberos', $kerberosPrefix)
->withOptionOrPkgConfigPath($build, '--with-imap-ssl', $opensslPrefix);
};
$this->variants['ldap'] = function (ConfigureParameters $params, Build $_, $value) {
$prefix = Utils::findPrefix(array(
new UserProvidedPrefix($value),
new IncludePrefixFinder('ldap.h'),
new BrewPrefixFinder('openldap'),
));
if ($prefix !== null) {
$params = $params->withOption('--with-ldap', $prefix);
}
return $params;
};
$this->variants['tidy'] = '--with-tidy';
$this->variants['kerberos'] = '--with-kerberos';
$this->variants['xmlrpc'] = '--with-xmlrpc';
$this->variants['fpm'] = function (ConfigureParameters $params) {
$params = $params->withOption('--enable-fpm');
if ($bin = Utils::findBin('systemctl') && Utils::findIncludePrefix('systemd/sd-daemon.h')) {
$params = $params->withOption('--with-fpm-systemd');
}
return $params;
};
$this->variants['dtrace'] = function (ConfigureParameters $params) {
return $params->withOption('--enable-dtrace');
};
$this->variants['pcre'] = function (ConfigureParameters $params, Build $build, $value) {
if ($build->compareVersion('7.4') >= 0) {
return $params;
}
$params = $params->withOption('--with-pcre-regex');
$prefix = Utils::findPrefix(array(
new UserProvidedPrefix($value),
new IncludePrefixFinder('pcre.h'),
new BrewPrefixFinder('pcre'),
));
if ($prefix !== null) {
$params = $params->withOption('--with-pcre-dir', $prefix);
}
return $params;
};
$this->variants['mhash'] = function (ConfigureParameters $params, Build $build, $value) {
$prefix = Utils::findPrefix(array(
new UserProvidedPrefix($value),
new IncludePrefixFinder('mhash.h'),
new BrewPrefixFinder('mhash'),
));
return $params->withOption('--with-mhash', $prefix);
};
$this->variants['mcrypt'] = function (ConfigureParameters $params, Build $build, $value) {
$prefix = Utils::findPrefix(array(
new UserProvidedPrefix($value),
new IncludePrefixFinder('mcrypt.h'),
new BrewPrefixFinder('mcrypt'),
));
return $params->withOption('--with-mcrypt', $prefix);
};
$this->variants['zlib'] = function (ConfigureParameters $params, Build $build, $value) {
$prefix = Utils::findPrefix(array(
new UserProvidedPrefix($value),
new BrewPrefixFinder('zlib'),
new IncludePrefixFinder('zlib.h'),
));
return $params->withOptionOrPkgConfigPath($build, '--with-zlib', $prefix);
};
$this->variants['curl'] = function (ConfigureParameters $params, Build $build, $value) {
$prefix = Utils::findPrefix(array(
new UserProvidedPrefix($value),
new BrewPrefixFinder('curl'),
new PkgConfigPrefixFinder('libcurl'),
new IncludePrefixFinder('curl/curl.h'),
));
return $params->withOptionOrPkgConfigPath($build, '--with-curl', $prefix);
};
/*
Users might prefer readline over libedit because only readline supports
readline_list_history() (http://www.php.net/readline-list-history).
On the other hand we want libedit to be the default because its license
is compatible with PHP's which means PHP can be distributable.
related issue https://github.com/phpbrew/phpbrew/issues/497
The default libreadline version that comes with OS X is too old and
seems to be missing symbols like rl_mark, rl_pending_input,
rl_history_list, rl_on_new_line. This is not detected by ./configure
So we should prefer macports/homebrew library than the system readline library.
@see https://bugs.php.net/bug.php?id=48608
*/
$this->variants['readline'] = function (ConfigureParameters $params, Build $build, $value) {
$prefix = Utils::findPrefix(array(
new UserProvidedPrefix($value),
new BrewPrefixFinder('readline'),
new IncludePrefixFinder('readline/readline.h'),
));
return $params->withOption('--with-readline', $prefix);
};
/*
* editline is conflict with readline
*
* one must tap the homebrew/dupes to use this formula
*
* brew tap homebrew/dupes
*/
$this->variants['editline'] = function (ConfigureParameters $parameters, Build $build, $value) {
$prefix = Utils::findPrefix(array(
new UserProvidedPrefix($value),
new IncludePrefixFinder('editline/readline.h'),
new BrewPrefixFinder('libedit'),
));
return $parameters->withOption('--with-libedit', $prefix);
};
/*
* It looks like gd won't be compiled without "shared"
*
* Suggested options is +gd=shared,{prefix}
*
* Issue: gd.so: undefined symbol: gdImageCreateFromWebp might happend
*
* Adding --with-libpath=lib or --with-libpath=lib/x86_64-linux-gnu
* might solve the gd issue.
*
* The configure script in ext/gd detects libraries by something like
* test -f $PREFIX/$LIBPATH/libxxx.a, where $PREFIX is what you passed
* in --with-xxxx-dir and $LIBPATH can varies in different OS.
*
* By adding --with-libpath, you can set it up properly.
*
* @see https://github.com/phpbrew/phpbrew/issues/461
*/
$this->variants['gd'] = function (ConfigureParameters $parameters, Build $build, $value) {
$prefix = Utils::findPrefix(array(
new UserProvidedPrefix($value),
new IncludePrefixFinder('gd.h'),
new BrewPrefixFinder('gd'),
));
if ($build->compareVersion('7.4') < 0) {
$option = '--with-gd';
} else {
$option = '--enable-gd';
}
$value = 'shared';
if ($prefix !== null) {
$value .= ',' . $prefix;
}
$parameters = $parameters->withOption($option, $value);
if ($build->compareVersion('5.5') < 0) {
$parameters = $parameters->withOption('--enable-gd-native-ttf');
}
if (
($prefix = Utils::findPrefix(array(
new IncludePrefixFinder('jpeglib.h'),
new BrewPrefixFinder('libjpeg'),
))) !== null
) {
if ($build->compareVersion('7.4') < 0) {
$option = '--with-jpeg-dir';
} else {
$option = '--with-jpeg';
}
$parameters = $parameters->withOption($option, $prefix);
}
if (
$build->compareVersion('7.4') < 0 && ($prefix = Utils::findPrefix(array(
new IncludePrefixFinder('png.h'),
new IncludePrefixFinder('libpng12/pngconf.h'),
new BrewPrefixFinder('libpng'),
))) !== null
) {
$parameters = $parameters->withOption('--with-png-dir', $prefix);
}
// the freetype-dir option does not take prefix as its value,
// it takes the freetype.h directory as its value.
//
// from configure:
// for path in $i/include/freetype2/freetype/freetype.h
if (
($prefix = Utils::findPrefix(array(
new IncludePrefixFinder('freetype2/freetype.h'),
new IncludePrefixFinder('freetype2/freetype/freetype.h'),
new BrewPrefixFinder('freetype'),
))) !== null
) {
if ($build->compareVersion('7.4') < 0) {
$option = '--with-freetype-dir';
} else {
$option = '--with-freetype';
}
$parameters = $parameters->withOption($option, $prefix);
}
return $parameters;
};
/*
--enable-intl
To build the extension you need to install the » ICU library, version
4.0.0 or newer is required.
This extension is bundled with PHP as of PHP version 5.3.0.
Alternatively, the PECL version of this extension may be used with all
PHP versions greater than 5.2.0 (5.2.4+ recommended).
This requires --with-icu-dir=/....
Please note prefix must provide {prefix}/bin/icu-config for autoconf
to find the related icu-config binary, or the configure will fail.
Issue: https://github.com/phpbrew/phpbrew/issues/433
*/
$this->variants['intl'] = function (ConfigureParameters $parameters, Build $build) {
$parameters = $parameters->withOption('--enable-intl');
$prefix = Utils::findPrefix(array(
new PkgConfigPrefixFinder('icu-i18n'),
new BrewPrefixFinder('icu4c'),
));
if ($build->compareVersion('7.4') < 0) {
if ($prefix !== null) {
$parameters = $parameters->withOption('--with-icu-dir', $prefix);
}
} else {
if ($prefix !== null) {
$parameters = $parameters->withPkgConfigPath($prefix . '/lib/pkgconfig');
}
}
return $parameters;
};
$this->variants['sodium'] = function (ConfigureParameters $parameters, Build $build, $value) {
$prefix = Utils::findPrefix(array(
new UserProvidedPrefix($value),
new BrewPrefixFinder('libsodium'),
new PkgConfigPrefixFinder('libsodium'),
new IncludePrefixFinder('sodium.h'),
new LibPrefixFinder('libsodium.a'),
));
return $parameters->withOption('--with-sodium', $prefix);
};
/*
* --with-openssl option
*
* --with-openssh=shared
* --with-openssl=[dir]
*
* On ubuntu you need to install libssl-dev
*/
$this->variants['openssl'] = function (ConfigureParameters $parameters, Build $build, $value) {
$prefix = Utils::findPrefix(array(
new UserProvidedPrefix($value),
new BrewPrefixFinder('openssl'),
new PkgConfigPrefixFinder('openssl'),
new IncludePrefixFinder('openssl/opensslv.h'),
));
return $parameters->withOptionOrPkgConfigPath($build, '--with-openssl', $prefix);
};
/*
quote from the manual page:
> MySQL Native Driver is a replacement for the MySQL Client Library
> (libmysqlclient). MySQL Native Driver is part of the official PHP
> sources as of PHP 5.3.0.
> The MySQL database extensions MySQL extension, mysqli and PDO MYSQL all
> communicate with the MySQL server. In the past, this was done by the
> extension using the services provided by the MySQL Client Library. The
> extensions were compiled against the MySQL Client Library in order to
> use its client-server protocol.
> With MySQL Native Driver there is now an alternative, as the MySQL
> database extensions can be compiled to use MySQL Native Driver instead
> of the MySQL Client Library.
mysqlnd should be prefered over the native client library.
--with-mysql[=DIR] Include MySQL support. DIR is the MySQL base
directory. If mysqlnd is passed as DIR,
the MySQL native driver will be used [/usr/local]
--with-mysqli[=FILE] Include MySQLi support. FILE is the path
to mysql_config. If mysqlnd is passed as FILE,
the MySQL native driver will be used [mysql_config]
--with-pdo-mysql[=DIR] PDO: MySQL support. DIR is the MySQL base directoy
If mysqlnd is passed as DIR, the MySQL native
native driver will be used [/usr/local]
--with-mysql deprecated in 7.0
--enable-mysqlnd Enable mysqlnd explicitly, will be done implicitly
when required by other extensions
mysqlnd was added since php 5.3
*/
$this->variants['mysql'] = function (ConfigureParameters $parameters, Build $build, $value) {
if ($value === null) {
$value = 'mysqlnd';
}
if ($build->compareVersion('7.0') < 0) {
$parameters = $parameters->withOption('--with-mysql', $value);
}
$parameters = $parameters->withOption('--with-mysqli', $value);
if ($build->isEnabledVariant('pdo')) {
$parameters = $parameters->withOption('--with-pdo-mysql', $value);
}
$foundSock = false;
if ($bin = Utils::findBin('mysql_config')) {
if ($output = exec_line("$bin --socket")) {
$foundSock = true;
$parameters = $parameters->withOption('--with-mysql-sock', $output);
}
}
if (!$foundSock) {
$possiblePaths = array(
/* macports mysql ... */
'/opt/local/var/run/mysql57/mysqld.sock',
'/opt/local/var/run/mysql56/mysqld.sock',
'/opt/local/var/run/mysql55/mysqld.sock',
'/opt/local/var/run/mysql54/mysqld.sock',
'/tmp/mysql.sock', /* homebrew mysql sock */
'/var/run/mysqld/mysqld.sock', /* ubuntu */
'/var/mysql/mysql.sock',
);
foreach ($possiblePaths as $path) {
if (file_exists($path)) {
$parameters = $parameters->withOption('--with-mysql-sock', $path);
break;
}
}
}
return $parameters;
};
$this->variants['sqlite'] = function (ConfigureParameters $parameters, Build $build, $value) {
$parameters = $parameters->withOption('--with-sqlite3', $value);
if ($build->isEnabledVariant('pdo')) {
$parameters = $parameters->withOption('--with-pdo-sqlite', $value);
}
return $parameters;
};
/**
* The --with-pgsql=[DIR] and --with-pdo-pgsql=[DIR] requires [DIR]/bin/pg_config to be found.
*/
$this->variants['pgsql'] = function (ConfigureParameters $parameters, Build $build, $value) {
$prefix = Utils::findPrefix(array(
new UserProvidedPrefix($value),
new ExecutablePrefixFinder('pg_config'),
new BrewPrefixFinder('libpq'),
));
$parameters = $parameters->withOption('--with-pgsql', $prefix);
if ($build->isEnabledVariant('pdo')) {
$parameters = $parameters->withOption('--with-pdo-pgsql', $prefix);
}
return $parameters;
};
$this->variants['xml'] = function (ConfigureParameters $parameters, Build $build, $value) {
$parameters = $parameters->withOption('--enable-dom');
$prefix = Utils::findPrefix(array(
new UserProvidedPrefix($value),
new BrewPrefixFinder('libxml2'),
new PkgConfigPrefixFinder('libxml'),
new IncludePrefixFinder('libxml2/libxml/globals.h'),
new LibPrefixFinder('libxml2.a'),
));
if ($build->compareVersion('7.4') < 0) {
$parameters = $parameters->withOption('--enable-libxml');
if ($prefix !== null) {
$parameters = $parameters->withOption('--with-libxml-dir', $prefix);
}
} else {
$parameters = $parameters->withOption('--with-libxml');
if ($prefix !== null) {
$parameters = $parameters->withPkgConfigPath($prefix . '/lib/pkgconfig');
}
}
return $parameters
->withOption('--enable-simplexml')
->withOption('--enable-xml')
->withOption('--enable-xmlreader')
->withOption('--enable-xmlwriter')
->withOption('--with-xsl');
};
$this->variants['apxs2'] = function (ConfigureParameters $parameters, Build $build, $value) {
if ($value) {
return $parameters->withOption('--with-apxs2', $value);
}
if ($bin = Utils::findBinByPrefix('apxs2')) {
return $parameters->withOption('--with-apxs2', $bin);
}
if ($bin = Utils::findBinByPrefix('apxs')) {
return $parameters->withOption('--with-apxs2', $bin);
}
/* Special paths for homebrew */
$possiblePaths = array(
// macports apxs path
'/usr/local/opt/httpd24/bin/apxs',
'/usr/local/opt/httpd23/bin/apxs',
'/usr/local/opt/httpd22/bin/apxs',
'/usr/local/opt/httpd21/bin/apxs',
'/usr/local/sbin/apxs', // homebrew apxs prefix
'/usr/local/bin/apxs',
'/usr/sbin/apxs', // it's possible to find apxs under this path (OS X)
'/usr/bin/apxs', // not sure if this one helps
);
$path = first_existing_executable($possiblePaths);
return $parameters->withOption('--with-apxs2', $path);
};
$this->variants['gettext'] = function (ConfigureParameters $parameters, Build $build, $value) {
$prefix = Utils::findPrefix(array(
new UserProvidedPrefix($value),
new IncludePrefixFinder('libintl.h'),
new BrewPrefixFinder('gettext'),
));
return $parameters->withOption('--with-gettext', $prefix);
};
$this->variants['iconv'] = function (ConfigureParameters $parameters, Build $build, $value) {
$prefix = Utils::findPrefix(array(
// PHP can't be compiled with --with-iconv=/usr because it uses giconv
// https://bugs.php.net/bug.php?id=48451
new UserProvidedPrefix($value),
new BrewPrefixFinder('libiconv'),
));
return $parameters->withOption('--with-iconv', $prefix);
};
$this->variants['bz2'] = function (ConfigureParameters $parameters, Build $build, $value) {
$prefix = Utils::findPrefix(array(
new UserProvidedPrefix($value),
new BrewPrefixFinder('bzip2'),
new IncludePrefixFinder('bzlib.h'),
));
return $parameters->withOption('--with-bz2', $prefix);
};
$this->variants['ipc'] = function (ConfigureParameters $parameters, Build $build) {
return $parameters
->withOption('--enable-shmop')
->withOption('--enable-sysvsem')
->withOption('--enable-sysvshm')
->withOption('--enable-sysvmsg');
};
$this->variants['gmp'] = function (ConfigureParameters $parameters, Build $build, $value) {
$prefix = Utils::findPrefix(array(
new UserProvidedPrefix($value),
new IncludePrefixFinder('gmp.h'),
));
return $parameters->withOption('--with-gmp', $prefix);
};
$this->variants['pear'] = function (ConfigureParameters $parameters, Build $build, $value) {
if ($value === null) {
$value = $build->getInstallPrefix() . '/lib/php/pear';
}
return $parameters->withOption('--with-pear', $value);
};
// merge virtual variants with config file
$customVirtualVariants = Config::getConfigParam('variants');
$customVirtualVariantsToAdd = array();
if (!empty($customVirtualVariants)) {
foreach ($customVirtualVariants as $key => $extension) {
// The extension might be null
if (!empty($extension)) {
$customVirtualVariantsToAdd[$key] = array_keys($extension);
}
}
}
$this->virtualVariants = array_merge($customVirtualVariantsToAdd, $this->virtualVariants);
// create +everything variant
$this->virtualVariants['everything'] = array_diff(
array_keys($this->variants),
array('apxs2', 'all') // <- except these ones
);
}
private function getConflict(Build $build, $feature)
{
if (isset($this->conflicts[ $feature ])) {
$conflicts = array();
foreach ($this->conflicts[ $feature ] as $f) {
if ($build->isEnabledVariant($f)) {
$conflicts[] = $f;
}
}
return $conflicts;
}
return false;
}
private function checkConflicts(Build $build)
{
if ($build->isEnabledVariant('apxs2') && version_compare($build->getVersion(), '5.4.0') < 0) {
if ($conflicts = $this->getConflict($build, 'apxs2')) {
$msgs = array();
$msgs[] = 'PHP Version lower than 5.4.0 can only build one SAPI at the same time.';
$msgs[] = '+apxs2 is in conflict with ' . implode(',', $conflicts);
foreach ($conflicts as $c) {
$msgs[] = "Disabling $c";
$build->disableVariant($c);
}
echo implode("\n", $msgs) . "\n";
}
}
return true;
}
public function getVariantNames()
{
return array_keys($this->variants);
}
/**
* Build `./configure' parameters from an enabled variant.
*
* @param string $variant Variant name
* @param string|null $value User-provided value for the variant
*
* @return ConfigureParameters
*
* @throws Exception
*/
private function buildEnabledVariant(Build $build, $variant, $value, ConfigureParameters $parameters)
{
if (!isset($this->variants[$variant])) {
throw new Exception(sprintf('Variant "%s" is not defined', $variant));
}
// Skip if we've built it
if (in_array($variant, $this->builtList)) {
return $parameters;
}
// Skip if we've disabled it
if (isset($this->disables[$variant])) {
return $parameters;
}
$this->builtList[] = $variant;
return $this->buildVariantFromDefinition($build, $this->variants[$variant], $value, $parameters);
}
/**
* Build `./configure' parameters from a disabled variant.
*
* @param string $variant Variant name
*
* @return ConfigureParameters
*
* @throws Exception
*/
private function buildDisabledVariant(Build $build, $variant, ConfigureParameters $parameters)
{
if (!isset($this->variants[$variant])) {
throw new Exception(sprintf('Variant "%s" is not defined', $variant));
}
// Skip if we've built it
if (in_array('-' . $variant, $this->builtList)) {
return $parameters;
}
$this->builtList[] = '-' . $variant;
$disabledParameters = $this->buildVariantFromDefinition(
$build,
$this->variants[$variant],
null,
new ConfigureParameters()
);
foreach ($disabledParameters->getOptions() as $option => $_) {
// convert --enable-xxx to --disable-xxx
$option = preg_replace('/^--enable-/', '--disable-', $option);
// convert --with-xxx to --without-xxx
$option = preg_replace('/^--with-/', '--without-', $option);
$parameters = $parameters->withOption($option);
}
return $parameters;
}
/**
* Build `./configure' parameters from a variant definition.
*
* @param string|array<string>|callable $definition Variant definition
* @param string|null $value User-provided value for the variant
*
* @return ConfigureParameters
*
* @throws Exception
*/
private function buildVariantFromDefinition(Build $build, $definition, $value, ConfigureParameters $parameters)
{
if (is_string($definition)) {
$parameters = $parameters->withOption($definition);
} elseif (is_array($definition)) {
foreach ($definition as $option => $value) {
$parameters = $parameters->withOption($option, $value);
}
} elseif (is_callable($definition)) {
$parameters = call_user_func_array($definition, array(
$parameters,
$build,
$value,
));
} else {
throw new OopsException();
}
return $parameters;
}
/**
* Build variants to configure options from php build object.
*
* @param Build $build The build object, contains version information
*
* @return ConfigureParameters
*
* @throws Exception
*/
public function build(Build $build, ConfigureParameters $parameters = null)
{
$customVirtualVariants = Config::getConfigParam('variants');
foreach (array_keys($build->getEnabledVariants()) as $variantName) {
if (isset($customVirtualVariants[$variantName])) {
foreach ($customVirtualVariants[$variantName] as $lib => $params) {
if (is_array($params)) {
$this->variants[$lib] = $params;
}
}
}
}
if ($parameters === null) {
$parameters = new ConfigureParameters();
}
// reset builtList
$this->builtList = array();