configure 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. #!/bin/sh
  2. #
  3. # tcc configure script (c) 2003 Fabrice Bellard
  4. # set temporary file name
  5. # if test ! -z "$TMPDIR" ; then
  6. # TMPDIR1="${TMPDIR}"
  7. # elif test ! -z "$TEMPDIR" ; then
  8. # TMPDIR1="${TEMPDIR}"
  9. # else
  10. # TMPDIR1="/tmp"
  11. # fi
  12. #
  13. # bashism: TMPN="${TMPDIR1}/tcc-conf-${RANDOM}-$$-${RANDOM}.c"
  14. TMPN="./conftest-$$"
  15. TMPH=$TMPN.h
  16. # default parameters
  17. prefix=""
  18. execprefix=""
  19. bindir=""
  20. libdir=""
  21. tccdir=""
  22. includedir=""
  23. mandir=""
  24. infodir=""
  25. sysroot=""
  26. cross_prefix=""
  27. cc="gcc"
  28. ar="ar"
  29. strip="strip"
  30. bigendian="no"
  31. mingw32="no"
  32. LIBSUF=".a"
  33. EXESUF=""
  34. DLLSUF=".so"
  35. tcc_sysincludepaths=""
  36. tcc_libpaths=""
  37. tcc_crtprefix=""
  38. tcc_elfinterp=""
  39. triplet=
  40. tcc_lddir=
  41. confvars=
  42. suggest="yes"
  43. cpu=
  44. cpuver=
  45. gcc_major=0
  46. gcc_minor=0
  47. # OS specific
  48. targetos=`uname`
  49. case $targetos in
  50. Darwin)
  51. confvars="$confvars OSX"
  52. DLLSUF=".dylib"
  53. ;;
  54. MINGW*|MSYS*|CYGWIN*)
  55. mingw32=yes
  56. ;;
  57. DragonFly|OpenBSD|FreeBSD|NetBSD)
  58. confvars="$confvars ldl=no"
  59. ;;
  60. *)
  61. ;;
  62. esac
  63. # find source path
  64. source_path=${0%configure}
  65. source_path=${source_path%/}
  66. source_path_used="yes"
  67. if test -z "$source_path" -o "$source_path" = "." ; then
  68. source_path=`pwd`
  69. source_path_used="no"
  70. fi
  71. for opt do
  72. eval opt=\"$opt\"
  73. case "$opt" in
  74. --prefix=*) prefix=`echo $opt | cut -d '=' -f 2`
  75. ;;
  76. --exec-prefix=*) execprefix=`echo $opt | cut -d '=' -f 2`
  77. ;;
  78. --tccdir=*) tccdir=`echo $opt | cut -d '=' -f 2`
  79. ;;
  80. --bindir=*) bindir=`echo $opt | cut -d '=' -f 2`
  81. ;;
  82. --libdir=*) libdir=`echo $opt | cut -d '=' -f 2`
  83. ;;
  84. --includedir=*) includedir=`echo $opt | cut -d '=' -f 2`
  85. ;;
  86. --sharedir=*) sharedir=`echo $opt | cut -d '=' -f 2`
  87. ;;
  88. --mandir=*) mandir=`echo $opt | cut -d '=' -f 2`
  89. ;;
  90. --infodir=*) infodir=`echo $opt | cut -d '=' -f 2`
  91. ;;
  92. --docdir=*) docdir=`echo $opt | cut -d '=' -f 2`
  93. ;;
  94. --sysroot=*) sysroot=`echo $opt | cut -d '=' -f 2`
  95. ;;
  96. --source-path=*) source_path=`echo $opt | cut -d '=' -f 2`
  97. ;;
  98. --cross-prefix=*) cross_prefix=`echo $opt | cut -d '=' -f 2`
  99. ;;
  100. --cc=*) cc=`echo $opt | cut -d '=' -f 2`
  101. ;;
  102. --ar=*) ar=`echo $opt | cut -d '=' -f 2`
  103. ;;
  104. --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}"
  105. ;;
  106. --extra-ldflags=*) LDFLAGS="${opt#--extra-ldflags=}"
  107. ;;
  108. --extra-libs=*) extralibs="${opt#--extra-libs=}"
  109. ;;
  110. --sysincludepaths=*) tcc_sysincludepaths=`echo $opt | cut -d '=' -f 2`
  111. ;;
  112. --libpaths=*) tcc_libpaths=`echo $opt | cut -d '=' -f 2`
  113. ;;
  114. --crtprefix=*) tcc_crtprefix=`echo $opt | cut -d '=' -f 2`
  115. ;;
  116. --elfinterp=*) tcc_elfinterp=`echo $opt | cut -d '=' -f 2`
  117. ;;
  118. --triplet=*) triplet=`echo $opt | cut -d '=' -f 2`
  119. ;;
  120. --cpu=*) cpu=`echo $opt | cut -d '=' -f 2`
  121. ;;
  122. --enable-cross) confvars="$confvars cross"
  123. ;;
  124. --disable-static) confvars="$confvars static=no"
  125. ;;
  126. --enable-static) confvars="$confvars static"
  127. ;;
  128. --disable-rpath) confvars="$confvars rpath=no"
  129. ;;
  130. --strip-binaries) confvars="$confvars strip"
  131. ;;
  132. --with-libgcc) confvars="$confvars libgcc"
  133. ;;
  134. --with-selinux) confvars="$confvars selinux"
  135. ;;
  136. --config-mingw32*) mingw32=$(echo "$opt=yes" | cut -d '=' -f 2)
  137. ;;
  138. --config-*) confvars="$confvars ${opt#--config-}"; suggest="no"
  139. ;;
  140. --help|-h) show_help="yes"
  141. ;;
  142. *) echo "configure: WARNING: unrecognized option $opt"
  143. ;;
  144. esac
  145. done
  146. if test -z "$cpu" ; then
  147. if test -n "$ARCH" ; then
  148. cpu="$ARCH"
  149. else
  150. cpu=`uname -m`
  151. fi
  152. fi
  153. case "$cpu" in
  154. x86|i386|i486|i586|i686|i86pc|BePC|i686-AT386)
  155. cpu="i386"
  156. ;;
  157. x86_64|amd64|x86-64)
  158. cpu="x86_64"
  159. ;;
  160. arm*)
  161. case "$cpu" in
  162. arm|armv4l)
  163. cpuver=4
  164. ;;
  165. armv5tel|armv5tejl)
  166. cpuver=5
  167. ;;
  168. armv6j|armv6l)
  169. cpuver=6
  170. ;;
  171. armv7a|armv7l)
  172. cpuver=7
  173. ;;
  174. esac
  175. cpu="arm"
  176. ;;
  177. aarch64)
  178. cpu="aarch64"
  179. ;;
  180. alpha)
  181. cpu="alpha"
  182. ;;
  183. "Power Macintosh"|ppc|ppc64)
  184. cpu="ppc"
  185. ;;
  186. mips)
  187. cpu="mips"
  188. ;;
  189. s390)
  190. cpu="s390"
  191. ;;
  192. *)
  193. echo "Unsupported CPU"
  194. exit 1
  195. ;;
  196. esac
  197. # Checking for CFLAGS
  198. if test -z "$CFLAGS"; then
  199. CFLAGS="-Wall -g -O2"
  200. fi
  201. if test "$mingw32" = "yes" ; then
  202. if test "$source_path_used" = "no"; then
  203. source_path="."
  204. fi
  205. if test "$cc" = gcc; then
  206. test -z "$LDFLAGS" && LDFLAGS="-static"
  207. fi
  208. test -z "$prefix" && prefix="C:/Program Files/tcc"
  209. test -z "$tccdir" && tccdir="${prefix}"
  210. test -z "$bindir" && bindir="${tccdir}"
  211. test -z "$docdir" && docdir="${tccdir}/doc"
  212. test -z "$libdir" && libdir="${tccdir}/libtcc"
  213. confvars="$confvars WIN32"
  214. LIBSUF=".lib"
  215. EXESUF=".exe"
  216. DLLSUF=".dll"
  217. else
  218. if test -z "$prefix" ; then
  219. prefix="/usr/local"
  220. fi
  221. if test -z "$sharedir" ; then
  222. sharedir="${prefix}/share"
  223. fi
  224. if test x"$execprefix" = x""; then
  225. execprefix="${prefix}"
  226. fi
  227. if test x"$libdir" = x""; then
  228. libdir="${execprefix}/lib"
  229. fi
  230. if test x"$bindir" = x""; then
  231. bindir="${execprefix}/bin"
  232. fi
  233. if test x"$docdir" = x""; then
  234. docdir="${sharedir}/doc"
  235. fi
  236. if test x"$mandir" = x""; then
  237. mandir="${sharedir}/man"
  238. fi
  239. if test x"$infodir" = x""; then
  240. infodir="${sharedir}/info"
  241. fi
  242. if test x"$tccdir" = x""; then
  243. tccdir="${libdir}/tcc"
  244. fi
  245. if test x"$includedir" = x""; then
  246. includedir="${prefix}/include"
  247. fi
  248. fi # mingw32
  249. if test x"$show_help" = "xyes" ; then
  250. cat << EOF
  251. Usage: configure [options]
  252. Options: [defaults in brackets after descriptions]
  253. Standard options:
  254. --help print this message
  255. --prefix=PREFIX install in PREFIX [$prefix]
  256. --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
  257. [same as prefix]
  258. --bindir=DIR user executables in DIR [EPREFIX/bin]
  259. --libdir=DIR object code libraries in DIR [EPREFIX/lib]
  260. --tccdir=DIR installation directory [EPREFIX/lib/tcc]
  261. --includedir=DIR C header files in DIR [PREFIX/include]
  262. --sharedir=DIR documentation root DIR [PREFIX/share]
  263. --docdir=DIR documentation in DIR [SHAREDIR/doc/tcc]
  264. --mandir=DIR man documentation in DIR [SHAREDIR/man]
  265. --infodir=DIR info documentation in DIR [SHAREDIR/info]
  266. Advanced options (experts only):
  267. --source-path=PATH path of source code [$source_path]
  268. --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]
  269. --sysroot=PREFIX prepend PREFIX to library/include paths []
  270. --cc=CC use C compiler CC [$cc]
  271. --ar=AR create archives using AR [$ar]
  272. --extra-cflags= specify compiler flags [$CFLAGS]
  273. --extra-ldflags= specify linker options []
  274. --cpu=CPU CPU [$cpu]
  275. --strip-binaries strip symbol tables from resulting binaries
  276. --disable-static make libtcc.so instead of libtcc.a
  277. --enable-static make libtcc.a instead of libtcc.dll (win32)
  278. --disable-rpath disable use of -rpath with the above
  279. --with-libgcc use libgcc_s.so.1 instead of libtcc1.a
  280. --enable-cross build cross compilers
  281. --with-selinux use mmap for executable memory (with tcc -run)
  282. --sysincludepaths=... specify system include paths, colon separated
  283. --libpaths=... specify system library paths, colon separated
  284. --crtprefix=... specify locations of crt?.o, colon separated
  285. --elfinterp=... specify elf interpreter
  286. --triplet=... specify system library/include directory triplet
  287. --config-uClibc,-musl,-mingw32... enable system specific configurations
  288. EOF
  289. #echo "NOTE: The object files are build at the place where configure is launched"
  290. exit 1
  291. fi
  292. cc="${cross_prefix}${cc}"
  293. ar="${cross_prefix}${ar}"
  294. strip="${cross_prefix}${strip}"
  295. if test -z "$cross_prefix" ; then
  296. CONFTEST=./conftest$EXESUF
  297. if ! $cc -o $CONFTEST $source_path/conftest.c 2>/dev/null ; then
  298. echo "configure: error: '$cc' failed to compile conftest.c."
  299. else
  300. gcc_major="$($CONFTEST version)"
  301. gcc_minor="$($CONFTEST minor)"
  302. fi
  303. bigendian="$($CONFTEST bigendian)"
  304. if test "$mingw32" = "no" ; then
  305. if test -z "$triplet"; then
  306. tt="$($CONFTEST triplet)"
  307. if test -n "$tt" -a -f "/usr/lib/$tt/crti.o" ; then
  308. triplet="$tt"
  309. fi
  310. fi
  311. if test -z "$triplet"; then
  312. if test $cpu = "x86_64" -o $cpu = "aarch64" ; then
  313. if test -f "/usr/lib64/crti.o" ; then
  314. tcc_lddir="lib64"
  315. fi
  316. fi
  317. fi
  318. if test "$cpu" = "arm" ; then
  319. if test "${triplet%eabihf}" != "$triplet" ; then
  320. confvars="$confvars arm_eabihf arm_vfp"
  321. elif test "${triplet%eabi}" != "$triplet" ; then
  322. confvars="$confvars arm_eabi"
  323. fi
  324. if grep -s -q "^Features.* \(vfp\|iwmmxt\) " /proc/cpuinfo ; then
  325. confvars="$confvars arm_vfp"
  326. fi
  327. fi
  328. if test "$suggest" = "yes"; then
  329. if test -f "/lib/ld-uClibc.so.0" ; then
  330. echo "Perhaps you want ./configure --config-uClibc"
  331. fi
  332. if test -f "/lib/ld-musl-$cpu.so.1"; then
  333. echo "Perhaps you want ./configure --config-musl"
  334. fi
  335. fi
  336. fi
  337. else
  338. # if cross compiling, cannot launch a program, so make a static guess
  339. case $cpu in
  340. ppc|mips|s390) bigendian=yes;;
  341. esac
  342. fi
  343. if test "$bigendian" = "yes" ; then
  344. confvars="$confvars BIGENDIAN"
  345. fi
  346. # a final configuration tuning
  347. if ! echo "$cc" | grep -q "tcc"; then
  348. OPT1="-Wdeclaration-after-statement -fno-strict-aliasing"
  349. # we want -Wno- but gcc does not always reject unknown -Wno- options
  350. OPT2="-Wpointer-sign -Wsign-compare -Wunused-result"
  351. if echo "$cc" | grep -q "clang"; then
  352. OPT1="$OPT1 -fheinous-gnu-extensions"
  353. OPT2="$OPT2 -Wstring-plus-int"
  354. fi
  355. $cc $OPT1 $OPT2 -o a.out -c -xc - < /dev/null > cc_msg.txt 2>&1
  356. for o in $OPT1; do # enable these options
  357. if ! grep -q -- $o cc_msg.txt; then CFLAGS="$CFLAGS $o"; fi
  358. done
  359. for o in $OPT2; do # disable these options
  360. if ! grep -q -- $o cc_msg.txt; then CFLAGS="$CFLAGS -Wno-${o#-W*}"; fi
  361. done
  362. # cat cc_msg.txt
  363. # echo $CFLAGS
  364. rm -f cc_msg.txt a.out
  365. fi
  366. fcho() { if test -n "$2"; then echo "$1$2"; fi }
  367. fcho "Binary directory " "$bindir"
  368. fcho "TinyCC directory " "$tccdir"
  369. fcho "Library directory " "$libdir"
  370. fcho "Include directory " "$includedir"
  371. fcho "Manual directory " "$mandir"
  372. fcho "Info directory " "$infodir"
  373. fcho "Doc directory " "$docdir"
  374. fcho "Target root prefix " "$sysroot"
  375. echo "Source path $source_path"
  376. echo "C compiler $cc ($gcc_major.$gcc_minor)"
  377. echo "Target OS $targetos"
  378. echo "CPU $cpu"
  379. fcho "Triplet " "$triplet"
  380. fcho "Config " "${confvars# }"
  381. echo "Creating config.mak and config.h"
  382. cat >config.mak <<EOF
  383. # Automatically generated by configure - do not modify
  384. prefix=$prefix
  385. bindir=\$(DESTDIR)$bindir
  386. tccdir=\$(DESTDIR)$tccdir
  387. libdir=\$(DESTDIR)$libdir
  388. includedir=\$(DESTDIR)$includedir
  389. mandir=\$(DESTDIR)$mandir
  390. infodir=\$(DESTDIR)$infodir
  391. docdir=\$(DESTDIR)$docdir
  392. CC=$cc
  393. GCC_MAJOR=$gcc_major
  394. GCC_MINOR=$gcc_minor
  395. AR=$ar
  396. STRIP=$strip -s -R .comment -R .note
  397. CFLAGS=$CFLAGS
  398. LDFLAGS=$LDFLAGS
  399. LIBSUF=$LIBSUF
  400. EXESUF=$EXESUF
  401. DLLSUF=$DLLSUF
  402. EOF
  403. print_inc() {
  404. if test -n "$2"; then
  405. echo "#ifndef $1" >> $TMPH
  406. echo "# define $1 \"$2\"" >> $TMPH
  407. echo "#endif" >> $TMPH
  408. fi
  409. }
  410. print_mak() {
  411. if test -n "$2"; then
  412. echo "NATIVE_DEFINES+=-D$1=\"\\\"$2\\\"\"" >> config.mak
  413. fi
  414. }
  415. print_mak_int() {
  416. if test -n "$2"; then
  417. echo "NATIVE_DEFINES+=-D$1=$2" >> config.mak
  418. fi
  419. }
  420. echo "/* Automatically generated by configure - do not modify */" > $TMPH
  421. print_inc CONFIG_SYSROOT "$sysroot"
  422. print_inc CONFIG_TCCDIR "$tccdir"
  423. print_mak CONFIG_TCC_SYSINCLUDEPATHS "$tcc_sysincludepaths"
  424. print_mak CONFIG_TCC_LIBPATHS "$tcc_libpaths"
  425. print_mak CONFIG_TCC_CRTPREFIX "$tcc_crtprefix"
  426. print_mak CONFIG_TCC_ELFINTERP "$tcc_elfinterp"
  427. print_mak CONFIG_LDDIR "$tcc_lddir"
  428. print_mak CONFIG_TRIPLET "$triplet"
  429. print_mak_int TCC_CPU_VERSION "$cpuver"
  430. if test "$cpu" = "aarch64" ; then
  431. echo "ARCH=arm64" >> config.mak
  432. else
  433. echo "ARCH=$cpu" >> config.mak
  434. fi
  435. echo "TARGETOS=$targetos" >> config.mak
  436. for v in $confvars ; do
  437. if test "${v%=*}" = "$v"; then
  438. echo "CONFIG_$v=yes" >> config.mak
  439. else
  440. echo "CONFIG_$v" >> config.mak
  441. fi
  442. done
  443. version=`head $source_path/VERSION`
  444. echo "VERSION = $version" >> config.mak
  445. echo "#define TCC_VERSION \"$version\"" >> $TMPH
  446. echo "@set VERSION $version" > config.texi
  447. if test "$source_path_used" = "yes" ; then
  448. case $source_path in
  449. /*) echo "TOPSRC=$source_path";;
  450. *) echo "TOPSRC=\$(TOP)/$source_path";;
  451. esac >>config.mak
  452. else
  453. echo 'TOPSRC=$(TOP)' >>config.mak
  454. fi
  455. diff $TMPH config.h >/dev/null 2>&1
  456. if test $? -ne 0 ; then
  457. mv -f $TMPH config.h
  458. else
  459. echo "config.h is unchanged"
  460. fi
  461. rm -f $TMPN* $CONFTEST
  462. # ---------------------------------------------------------------------------
  463. # build tree in object directory if source path is different from current one
  464. fn_makelink()
  465. {
  466. tgt=$1/$2
  467. case $2 in
  468. */*) dn=${2%/*}
  469. test -d $dn || mkdir -p $dn
  470. case $1 in
  471. /*) ;;
  472. *) while test $dn ; do
  473. tgt=../$tgt; dn=${dn#${dn%%/*}}; dn=${dn#/}
  474. done
  475. ;;
  476. esac
  477. ;;
  478. esac
  479. ln -sfn $tgt $2 || ( echo "ln failed. Using cp instead."; cp -f $1/$2 $2 )
  480. }
  481. if test "$source_path_used" = "yes" ; then
  482. FILES="Makefile lib/Makefile tests/Makefile tests/tests2/Makefile tests/pp/Makefile"
  483. for f in $FILES ; do
  484. fn_makelink $source_path $f
  485. done
  486. fi
  487. # ---------------------------------------------------------------------------