1414# license@zephir-lang.com so we can mail you a copy immediately.
1515
1616# Available params:
17- # --arch
1817# --phpize
1918# --php-config
2019#
2120# Example:
2221# ./install --phpize /usr/bin/phpize5.6 --php-config /usr/bin/php-config5.6
2322
23+ set -e
24+
2425CURRENT_DIR=$( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd )
2526
2627GCC_BIN=$( command -v gcc 2> /dev/null)
2728RE2C_BIN=${RE2C_BIN:- $(command -v re2c 2>/ dev/ null)}
2829
2930if [ x" $RE2C_BIN " = x ]; then
3031 echo -e " error: unable to locate the re2c"
31- exit 2
32+ exit 1
3233fi
3334
3435if [ x" $GCC_BIN " = x ]; then
3536 echo -e " error: unable to locate the gcc"
3637 exit 1
3738fi
3839
39- # Check best compilation flags for compiller
40+ # Check best compilation flags for compiler
4041export CC=gcc
4142export CFLAGS=" -march=native -mtune=native -O2 -fomit-frame-pointer"
42- export CPPFLAGS=" -DZEPHIR_PARSER_RELEASE"
4343
4444# Set defaults
4545PHPIZE_BIN=$( command -v phpize 2> /dev/null)
@@ -75,6 +75,11 @@ if [ "${PHP_FULL_VERSION:0:3}" == "5.3" ]; then
7575 exit 1
7676fi
7777
78+ if [ " ${PHP_FULL_VERSION: 0: 3} " == " 5.4" ]; then
79+ echo " php 5.4 is no longer supported"
80+ exit 1
81+ fi
82+
7883# Detect possible flags
7984echo " int main() {}" > t.c
8085gcc ${CFLAGS} t.c -o t 2> t.t
@@ -88,11 +93,13 @@ if [ $? != 0 ]; then
8893 fi
8994fi
9095
96+ # Activate some gcc specific optimizations for gcc >= 4
9197if [ $( gcc -dumpversion | cut -f1 -d.) -ge 4 ]; then
92- gcc ${CFLAGS} -fvisibility=hidden t.c -o t 2> t.t
93- export CFLAGS=" $CFLAGS -fvisibility=hidden"
98+ gcc ${CFLAGS} -fvisibility=hidden t.c -o t 2> t.t && export CFLAGS=" $CFLAGS -fvisibility=hidden"
9499fi
95100
101+ gcc ${CFLAGS} -flto t.c -o t 2> t.t && { export CFLAGS=" $CFLAGS -flto" ; export LDFLAGS=" $LDFLAGS $CFLAGS " ; }
102+
96103rm -f t.t t.c t
97104
98105cd ${CURRENT_DIR} /parser
@@ -109,7 +116,8 @@ rm -f \
109116 parser.php5.out \
110117 parser.php7.c \
111118 parser.php7.h \
112- parser.php7.out
119+ parser.php7.out \
120+ config.h.in~
113121
114122${RE2C_BIN} -o scanner.c scanner.re
115123
147155
148156# Perform the compilation
149157${PHPIZE_BIN}
150- ./configure --silent --with-php-config=${PHPCONFIG_BIN} --enable-zephir_parser
151- make -s -j" $( getconf _NPROCESSORS_ONLN) "
152158
153- echo
159+ # For some reason the libtool script being generated by autogen contains lines referring
160+ # to "$echo message" instead of "echo message".
161+ export echo=echo
154162
155- make -s install
163+ # Detect Gentoo Linux
164+ if [ -f /etc/gentoo-release ]; then
165+ LIBTOOLIZE_BIN=$( command -v libtoolize 2> /dev/null)
166+ aclocal && ${LIBTOOLIZE_BIN} --force && autoheader && autoconf
167+ fi
168+
169+ # Detect macOS
170+ if [ " $( uname -s 2> /dev/null) " = " Darwin" ]; then
171+ LIBTOOLIZE_BIN=$( command -v glibtoolize 2> /dev/null)
172+ aclocal && ${LIBTOOLIZE_BIN} --force && autoheader && autoconf
173+ fi
156174
157- echo
175+ ./configure --silent --with-php-config=${PHPCONFIG_BIN} --enable-zephir_parser
176+
177+ make -s -j" $( getconf _NPROCESSORS_ONLN) "
178+ make -s install
158179
159180# Clean current compilation
160181if [ -f Makefile ]; then
161182 make -s clean
162183 ${PHPIZE_BIN} --clean
163184fi
164185
165-
166186cd ${CURRENT_DIR} /parser
167187
168188# Cleanup
@@ -177,7 +197,8 @@ rm -f \
177197 parser.php5.out \
178198 parser.php7.c \
179199 parser.php7.h \
180- parser.php7.out
200+ parser.php7.out \
201+ config.h.in~
181202
182203echo -e " \nThanks for compiling Zephir Parser!\nBuild succeed: Please restart your web server to complete the installation\n"
183204
0 commit comments