Updating submodules
[hiphop-php.git] / hphp / system / make_systemlib.sh
blob914512b96b4902c4dc86b64e26ad7d7e4c5700b7
1 #!/bin/sh
3 SYSTEMLIB=$1; shift
5 # If we put the line we're generating into this file, then the linter will think
6 # the generator itself is generated. Encode it into a variable for safe
7 # keeping.
8 AT="@"
10 echo "<?hh // partial" > ${SYSTEMLIB}
11 echo "// ${AT}generated" >> ${SYSTEMLIB}
13 for i in $@; do
14 if [ ! -f "$i" ]; then
15 echo "File '$i' is in system/php.txt, but does not exist" >&2
16 exit 1
19 BN=$(basename $i)
20 BNPHP=$(basename $BN .php)
21 BNNSPHP=$(basename $BN .ns.php)
22 BNHHAS=$(basename $BN .hhas)
23 if [ "$BNPHP.php" = "$BN" ]; then
24 # First, .php files are included with their open tags stripped.
25 if head -1 $i | grep -qv '^<?\(php\|hh\)'; then
26 echo "Unexpected header in file '$i'" >&2
27 exit 1
29 echo "" >> ${SYSTEMLIB}
30 if [ ! "$BNNSPHP.ns.php" = "$BN" ]; then
31 echo "namespace {" >> ${SYSTEMLIB}
33 tail -n +2 $i >> ${SYSTEMLIB}
34 if [ ! "$BNNSPHP.ns.php" = "$BN" ]; then
35 echo "}" >> ${SYSTEMLIB}
37 else
38 if [ ! "$BNHHAS.hhas" = "$BN" ]; then
39 echo "File '$i' is neither PHP nor HHAS source" >&2
40 exit 1
43 done
45 echo "" >> ${SYSTEMLIB}
46 echo "<?hhas" >> ${SYSTEMLIB}
48 # Then .hhas files are included en-masse.
49 for i in $@; do
50 BN=$(basename $i)
51 BNHHAS=$(basename $BN .hhas)
52 if [ "$BNHHAS.hhas" = "$BN" ]; then
53 echo "" >> ${SYSTEMLIB}
54 cat $i >> ${SYSTEMLIB}
56 done