configure 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. #! /bin/bash
  2. OS=`uname -s | tr '[:upper:]' '[:lower:]'`
  3. ARCH=`uname -p`
  4. TARGET=debug
  5. TOOLCHAIN=gcc
  6. HOST=""
  7. EXTERNAL_ZLIB="no"
  8. EXTERNAL_ZLIB_CPPFLAGS=""
  9. EXTERNAL_ZLIB_LDFLAGS=""
  10. EXTERNAL_LIBXML="no"
  11. EXTERNAL_LIBXML_CPPFLAGS=""
  12. EXTERNAL_LIBXML_LDFLAGS=""
  13. while test $# -ge 1
  14. do
  15. case "$1" in
  16. -h* | --help)
  17. echo 'usage:'
  18. echo ' configure [--with-python="PATH TO PYTHON EXECUTABLE"]'
  19. echo ' [--platform="OS-TARGET-TOOLCHAIN", e.g. --platform="linux-debug-gcc-i386"]'
  20. echo ' [--os="OS", e.g. --os="linux"]'
  21. echo ' [--target="TARGET", e.g. --target="release"]'
  22. echo ' [--toolchain="TOOLCHAIN", e.g. --toolchain="clang"]'
  23. echo ' [--arch="ARCH", e.g. --arch="i386"]'
  24. exit 0 ;;
  25. --with-python=*) PYTHON_PATH=`echo $1 | sed 's/.*=//'`; shift ;;
  26. --platform=*) PLATFORM=`echo $1 | sed 's/.*=//'`; shift ;;
  27. --target=*) TARGET=`echo $1 | sed 's/.*=//'`; shift ;;
  28. --toolchain=*) TOOLCHAIN=`echo $1 | sed 's/.*=//'`; shift ;;
  29. --os=*) OS=`echo $1 | sed 's/.*=//'`; shift ;;
  30. --arch=*) ARCH=`echo $1 | sed 's/.*=//'`; shift ;;
  31. --with-zlib=*) EXTERNAL_ZLIB=`echo $1 | sed 's/.*=//'`; shift ;;
  32. --with-zlib-cppflags=*) EXTERNAL_ZLIB_CPPFLAGS=`echo $1 | sed 's/.*=//'`; shift ;;
  33. --with-zlib-ldflags=*) EXTERNAL_ZLIB_LDFLAGS=`echo $1 | sed 's/.*=//'`; shift ;;
  34. --with-libxml=*) EXTERNAL_LIBXML=`echo $1 | sed 's/.*=//'`; shift ;;
  35. --with-libxml-cppflags=*) EXTERNAL_LIBXML_CPPFLAGS=`echo $1 | sed 's/.*=//'`; shift ;;
  36. --with-libxml-ldflags=*) EXTERNAL_LIBXML_LDFLAGS=`echo $1 | sed 's/.*=//'`; shift ;;
  37. *) echo "unknown option: $1"; echo "$0 --help for help"; exit 1 ;;
  38. esac
  39. done
  40. BUILDDIR="build"
  41. PLIBCONFIG=""
  42. PLIBFILES="include/plib/plib.h=>%PACKAGE%/config/%PLATFORM%/plib/include/plib/"
  43. ZLIBCONFIG=""
  44. ZLIBFILES="zconf.h=>config/%PLATFORM%/%PACKAGE%/"
  45. LIBXMLCONFIG="--without-c14n \
  46. --without-catalog \
  47. --without-docbook \
  48. --without-fexceptions \
  49. --without-ftp \
  50. --without-history \
  51. --without-html \
  52. --without-http \
  53. --without-iconv \
  54. --without-iso8859x \
  55. --without-legacy \
  56. --without-output \
  57. --without-pattern \
  58. --without-push \
  59. --without-python \
  60. --with-reader \
  61. --without-regexps \
  62. --without-sax1 \
  63. --without-schemas \
  64. --without-schematron \
  65. --without-threads \
  66. --without-tree \
  67. --without-valid \
  68. --with-writer \
  69. --without-xinclude \
  70. --without-xpath \
  71. --without-xptr \
  72. --without-modules \
  73. --without-zlib"
  74. LIBXMLFILES="config.h=>config/%PLATFORM%/%PACKAGE%/ include/libxml/xmlversion.h=>config/%PLATFORM%/%PACKAGE%/libxml"
  75. execConfigure() {
  76. RET=0
  77. SRCDIR=$1
  78. PACKAGE=$2
  79. OPTIONS=$3
  80. FILES=$4
  81. OPT_HOST=$5
  82. echo "Configuring $SRCDIR/$PACKAGE"
  83. mkdir -p "$BUILDDIR/copy"
  84. rm -rf "$BUILDDIR/copy/$PACKAGE"
  85. rm -rf "$BUILDDIR/$PLATFORM/$PACKAGE"
  86. cp -r "$SRCDIR/$PACKAGE" "$BUILDDIR/copy/$PACKAGE"
  87. if [ -d "$BUILDDIR/copy/$PACKAGE" ]; then
  88. pushd "$BUILDDIR/copy/$PACKAGE" > /dev/null
  89. if [ -x "./configure" ]; then
  90. ./configure $OPT_HOST $OPTIONS
  91. if [ $? -ne 0 ]; then
  92. popd -n > /dev/null
  93. echo "*** error running \"./configure $OPT_HOST $OPTIONS\" in \"$BUILDDIR/$PACKAGE\""
  94. echo "*** please fix this first!"
  95. exit 1
  96. fi
  97. else
  98. echo "configure not found in directory \"$BUILDDIR/$PACKAGE\""
  99. fi
  100. popd > /dev/null
  101. PAIR=$FILES
  102. for PAIR in $FILES; do
  103. FILE=(${PAIR/=>/ })
  104. SRCFILE="$BUILDDIR/copy/$PACKAGE/${FILE[0]}"
  105. if [ ! -f "$SRCFILE" ]; then
  106. echo "*** file \"$SRCFILE\" in has not been generated by configure."
  107. exit 1
  108. fi
  109. TARGETDIR="$BUILDDIR/${FILE[1]}"
  110. TARGETDIR=${TARGETDIR/\%PLATFORM\%/$PLATFORM}
  111. TARGETDIR=${TARGETDIR/\%PACKAGE\%/$PACKAGE}
  112. mkdir -p "$TARGETDIR"
  113. cp "$SRCFILE" "$TARGETDIR"
  114. TARGETFILE="$TARGETDIR/`basename ${FILE[0]}`"
  115. if [ ! -f "$TARGETFILE" ]; then
  116. echo "*** file "$SRCFILE" could not be copied to "$TARGETFILE" (either directory could not be created or copy failed)"
  117. exit 1
  118. fi
  119. done
  120. else
  121. echo "could not create temporary copy of \"$SRCDIR/$PACKAGE\" in \"$BUILDDIR/copy/$PACKAGE\""
  122. fi
  123. rm -rf "$BUILDDIR/copy/$PACKAGE"
  124. }
  125. if [ x$PLATFORM = x ]; then
  126. PLATFORM="$OS-$TARGET-$TOOLCHAIN-$ARCH"
  127. fi
  128. #if [ x$CC = x ]; then
  129. # CC=${PLATFORM##*-}
  130. #fi
  131. #export CC
  132. if [ x$PYTHON_PATH = x ]; then
  133. PYTHON_PATH=python3
  134. fi
  135. if [[ $PLATFORM =~ ^[^-]+-[^-]+-[^-]+-[^-]+$ ]]; then
  136. PYTHON_VERSION="`$PYTHON_PATH -V 2>&1`"
  137. if [[ $PYTHON_VERSION =~ ^"Python 2.6."[1-9][0-9]*$|^"Python 2."[7-9][0-9]*(\.[0-9]*(\+)?)?$|^"Python "[3][0-9]*(\.[0-9]*(\.[0-9]*)(\+)?)?$ ]]; then
  138. FLAGS=`$PYTHON_PATH generate.py --include Makefile.platform.xml --config-dir $BUILDDIR --with-zlib=$EXTERNAL_ZLIB --with-zlib-cppflags="$EXTERNAL_ZLIB_CPPFLAGS" --with-zlib-ldflags="$EXTERNAL_ZLIB_LDFLAGS" --with-libxml=$EXTERNAL_LIBXML --with-libxml-cppflags="$EXTERNAL_LIBXML_CPPFLAGS" --with-libxml-ldflags="$EXTERNAL_LIBXML_LDFLAGS" --print-env $PLATFORM`
  139. eval $FLAGS
  140. CONFIG_OPT=""
  141. if [ x"" != x$HOST ]; then
  142. CONFIG_OPT="--host=$HOST"
  143. fi
  144. execConfigure "." "plib" "$PLIBCONFIG" "$PLIBFILES" "$CONFIG_OPT"
  145. if [ x"no" == x$EXTERNAL_ZLIB ]; then
  146. execConfigure "third_party" "zlib-1.2.5" "$ZLIBCONFIG" "$ZLIBFILES" ""
  147. fi
  148. if [ x"no" == x$EXTERNAL_LIBXML ]; then
  149. execConfigure "third_party" "libxml2-2.7.7" "$LIBXMLCONFIG" "$LIBXMLFILES" "$CONFIG_OPT"
  150. fi
  151. $PYTHON_PATH generate.py --include Makefile.xml --config-dir $BUILDDIR --with-zlib=$EXTERNAL_ZLIB --with-zlib-cppflags="$EXTERNAL_ZLIB_CPPFLAGS" --with-zlib-ldflags="$EXTERNAL_ZLIB_LDFLAGS" --with-libxml=$EXTERNAL_LIBXML --with-libxml-cppflags="$EXTERNAL_LIBXML_CPPFLAGS" --with-libxml-ldflags="$EXTERNAL_LIBXML_LDFLAGS" $PLATFORM
  152. if [ $? -ne 0 ]; then
  153. echo "*** error generating Makefile!"
  154. exit 1
  155. fi
  156. else
  157. echo "Need python version >2.6.1. You have \"$PYTHON_VERSION\"."
  158. fi
  159. else
  160. echo "Can not guess PLATFORM quadruple. It is set to \"$PLATFORM\" but it should be something like \"linux-debug-gcc-i386\"."
  161. fi
  162. echo "Configured platform $PLATFORM."
  163. echo "Executables will be generated in \"build/$PLATFORM\"."