bootstrap 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981
  1. #!/bin/sh
  2. #=========================================================================
  3. #
  4. # Program: CMake - Cross-Platform Makefile Generator
  5. # Module: $RCSfile$
  6. # Language: Bourne Shell
  7. # Date: $Date$
  8. # Version: $Revision$
  9. #
  10. # Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  11. # See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  12. #
  13. # This software is distributed WITHOUT ANY WARRANTY; without even
  14. # the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. # PURPOSE. See the above copyright notices for more information.
  16. #
  17. #=========================================================================
  18. CMAKE_KNOWN_C_COMPILERS="cc gcc xlc icc tcc"
  19. CMAKE_KNOWN_CXX_COMPILERS="aCC xlC CC g++ c++ icc como "
  20. CMAKE_KNOWN_MAKE_PROCESSORS="gmake make"
  21. CMAKE_PROBLEMATIC_FILES="\
  22. CMakeCache.txt \
  23. CMakeSystem.cmake \
  24. CMakeCCompiler.cmake \
  25. CMakeCXXCompiler.cmake \
  26. Source/cmConfigure.h \
  27. Source/CTest/Curl/config.h \
  28. Utilities/cmexpat/expatConfig.h \
  29. Utilities/cmexpat/expatDllConfig.h \
  30. "
  31. CMAKE_CXX_SOURCES="\
  32. cmake \
  33. cmakewizard \
  34. cmakemain \
  35. cmDepends \
  36. cmDependsC \
  37. cmMakeDepend \
  38. cmMakefile \
  39. cmGeneratedFileStream \
  40. cmGlobalGenerator \
  41. cmLocalGenerator \
  42. cmSourceFile \
  43. cmSystemTools \
  44. cmGlobalUnixMakefileGenerator \
  45. cmGlobalXCodeGenerator \
  46. cmLocalXCodeGenerator \
  47. cmXCodeObject \
  48. cmLocalUnixMakefileGenerator2 \
  49. cmBootstrapCommands \
  50. cmCommands \
  51. cmTarget \
  52. cmCustomCommand \
  53. cmCacheManager \
  54. cmListFileCache \
  55. cmOrderLinkDirectories \
  56. cmSourceGroup"
  57. CMAKE_C_SOURCES="\
  58. cmListFileLexer \
  59. "
  60. KWSYS_C_SOURCES="\
  61. ProcessUNIX"
  62. KWSYS_CXX_SOURCES="\
  63. Directory \
  64. RegularExpression \
  65. SystemTools"
  66. KWSYS_FILES="\
  67. Directory.hxx \
  68. Process.h \
  69. RegularExpression.hxx \
  70. SystemTools.hxx"
  71. KWSYS_IOS_FILES="
  72. fstream \
  73. iosfwd \
  74. iostream \
  75. sstream"
  76. cmake_system=`uname`
  77. cmake_source_dir=`echo $0 | sed -n '/\//{s/\/[^\/]*$//;p;}'`
  78. cmake_source_dir=`(cd "${cmake_source_dir}";pwd)`
  79. cmake_binary_dir=`pwd`
  80. cmake_bootstrap_dir="${cmake_binary_dir}/Bootstrap.cmk"
  81. cmake_data_dir="/share/CMake"
  82. cmake_doc_dir="/doc/CMake"
  83. cmake_man_dir="/man"
  84. cmake_init_file=""
  85. # Display CMake bootstrap usage
  86. cmake_usage()
  87. {
  88. cat <<EOF
  89. Usage: $0 [options]
  90. Options: [defaults in brackets after descriptions]
  91. Configuration:
  92. --help print this message
  93. --version only print version information
  94. --verbose display more information
  95. --parallel=n bootstrap cmake in parallel, where n is
  96. number of nodes [1]
  97. --init=FILE use FILE for cmake initialization
  98. Directory and file names:
  99. --prefix=PREFIX install files in tree rooted at PREFIX
  100. [/usr/local]
  101. --datadir=DIR install data files in PREFIX/DIR
  102. [/share/CMake]
  103. --docdir=DIR install documentation files in PREFIX/DIR
  104. [/doc/CMake]
  105. --mandir=DIR install man pages files in PREFIX/DIR/manN
  106. [/man]
  107. EOF
  108. exit 10
  109. }
  110. # Display CMake bootstrap usage
  111. cmake_version()
  112. {
  113. # Get CMake version
  114. CMAKE_VERSION=""
  115. for a in MAJOR MINOR PATCH; do
  116. CMake_VERSION=`cat "${cmake_source_dir}/CMakeLists.txt" | \
  117. grep "SET(CMake_VERSION_${a} *[0-9]*)" | sed "s/SET(CMake_VERSION_${a} *\([0-9]*\))/\1/"`
  118. CMAKE_VERSION="${CMAKE_VERSION}.${CMake_VERSION}"
  119. done
  120. CMAKE_VERSION=`echo $CMAKE_VERSION | sed "s/\.\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\)/\1.\2-\3/"`
  121. echo "CMake ${CMAKE_VERSION}, Copyright (c) 2002 Kitware, Inc., Insight Consortium"
  122. }
  123. # Display CMake bootstrap error, display the log file and exit
  124. cmake_error()
  125. {
  126. res=$1
  127. shift 1
  128. echo "---------------------------------------------"
  129. echo "Error when bootstrapping CMake:"
  130. echo "$*"
  131. echo "---------------------------------------------"
  132. if [ -f cmake_bootstrap.log ]; then
  133. echo "Log of errors: `pwd`/cmake_bootstrap.log"
  134. #cat cmake_bootstrap.log
  135. echo "---------------------------------------------"
  136. fi
  137. exit ${res}
  138. }
  139. # Replace KWSYS_NAMESPACE with cmsys
  140. cmake_replace_string ()
  141. {
  142. INFILE="$1"
  143. OUTFILE="$2"
  144. SEARCHFOR="$3"
  145. REPLACEWITH="$4"
  146. if [ -f "${INFILE}" ]; then
  147. cat "${INFILE}" |
  148. sed "s/\@${SEARCHFOR}\@/${REPLACEWITH}/g" > "${OUTFILE}.tmp"
  149. if [ -f "${OUTFILE}.tmp" ]; then
  150. if diff "${OUTFILE}" "${OUTFILE}.tmp" > /dev/null 2> /dev/null ; then
  151. #echo "Files are the same"
  152. rm -f "${OUTFILE}.tmp"
  153. else
  154. mv -f "${OUTFILE}.tmp" "${OUTFILE}"
  155. fi
  156. fi
  157. else
  158. cmake_error 1 "Cannot find file ${INFILE}"
  159. fi
  160. }
  161. cmake_kwsys_config_replace_string ()
  162. {
  163. INFILE="$1"
  164. OUTFILE="$2"
  165. shift 2
  166. APPEND="$*"
  167. if [ -f "${INFILE}" ]; then
  168. echo "${APPEND}" > "${OUTFILE}.tmp"
  169. cat "${INFILE}" |
  170. sed "/./ {s/\@KWSYS_NAMESPACE\@/cmsys/g;
  171. s/@KWSYS_BUILD_SHARED@/${KWSYS_BUILD_SHARED}/g;
  172. s/@KWSYS_NAME_IS_KWSYS@/${KWSYS_NAME_IS_KWSYS}/g;
  173. s/@KWSYS_IOS_USE_ANSI@/${KWSYS_IOS_USE_ANSI}/g;
  174. s/@KWSYS_IOS_HAVE_STD@/${KWSYS_IOS_HAVE_STD}/g;
  175. s/@KWSYS_IOS_USE_SSTREAM@/${KWSYS_IOS_USE_SSTREAM}/g;
  176. s/@KWSYS_IOS_USE_STRSTREAM_H@/${KWSYS_IOS_USE_STRSTREAM_H}/g;
  177. s/@KWSYS_IOS_USE_STRSTREA_H@/${KWSYS_IOS_USE_STRSTREA_H}/g;
  178. s/@KWSYS_STL_HAVE_STD@/${KWSYS_STL_HAVE_STD}/g;
  179. s/@KWSYS_STAT_HAS_ST_MTIM@/${KWSYS_STAT_HAS_ST_MTIM}/g;}" >> "${OUTFILE}.tmp"
  180. if [ -f "${OUTFILE}.tmp" ]; then
  181. if diff "${OUTFILE}" "${OUTFILE}.tmp" > /dev/null 2> /dev/null ; then
  182. #echo "Files are the same"
  183. rm -f "${OUTFILE}.tmp"
  184. else
  185. mv -f "${OUTFILE}.tmp" "${OUTFILE}"
  186. fi
  187. fi
  188. else
  189. cmake_error 2 "Cannot find file ${INFILE}"
  190. fi
  191. }
  192. # Write string into a file
  193. cmake_report ()
  194. {
  195. FILE=$1
  196. shift
  197. echo "$*" >> ${FILE}
  198. }
  199. # Escape spaces in strings
  200. cmake_escape ()
  201. {
  202. echo $1 | sed "s/ /\\\\ /g"
  203. }
  204. # Write message to the log
  205. cmake_log ()
  206. {
  207. echo "$*" >> cmake_bootstrap.log
  208. }
  209. # Return temp file
  210. cmake_tmp_file ()
  211. {
  212. echo "cmake_bootstrap_$$.test"
  213. }
  214. # Run a compiler test. First argument is compiler, second one are compiler
  215. # flags, third one is test source file to be compiled
  216. cmake_try_run ()
  217. {
  218. COMPILER=$1
  219. FLAGS=$2
  220. TESTFILE=$3
  221. if [ ! -f "${TESTFILE}" ]; then
  222. echo "Test file ${TESTFILE} missing. Please verify your CMake source tree."
  223. exit 4
  224. fi
  225. TMPFILE=`cmake_tmp_file`
  226. echo "Try: ${COMPILER}"
  227. echo "Line: ${COMPILER} ${FLAGS} ${TESTFILE} -o ${TMPFILE}"
  228. echo "---------- file -----------------------"
  229. cat ${TESTFILE}
  230. echo "------------------------------------------"
  231. "${COMPILER}" ${FLAGS} "${TESTFILE}" -o "${TMPFILE}"
  232. RES=$?
  233. if [ "${RES}" -ne "0" ]; then
  234. echo "Test failed to compile"
  235. return 1
  236. fi
  237. if [ ! -f "${TMPFILE}" ] && [ ! -f "${TMPFILE}.exe" ]; then
  238. echo "Test failed to produce executable"
  239. return 2
  240. fi
  241. ./${TMPFILE}
  242. RES=$?
  243. rm -f "${TMPFILE}"
  244. if [ "${RES}" -ne "0" ]; then
  245. echo "Test produced non-zero return code"
  246. return 3
  247. fi
  248. echo "Test succeded"
  249. return 0
  250. }
  251. # Run a make test. First argument is the make interpreter.
  252. cmake_try_make ()
  253. {
  254. MAKE_PROC="$1"
  255. MAKE_FLAGS="$2"
  256. echo "Try: ${MAKE_PROC}"
  257. "${MAKE_PROC}" ${MAKE_FLAGS}
  258. RES=$?
  259. if [ "${RES}" -ne "0" ]; then
  260. echo "${MAKE_PROC} does not work"
  261. return 1
  262. fi
  263. if [ ! -f "test" ] && [ ! -f "test.exe" ]; then
  264. echo "${COMPILER} does not produce output"
  265. return 2
  266. fi
  267. ./test
  268. RES=$?
  269. rm -f "test"
  270. if [ "${RES}" -ne "0" ]; then
  271. echo "${MAKE_PROC} produces strange executable"
  272. return 3
  273. fi
  274. echo "${MAKE_PROC} works"
  275. return 0
  276. }
  277. # Parse arguments
  278. cmake_verbose=
  279. cmake_parallel_make=
  280. cmake_prefix_dir="/usr/local"
  281. for a in "$@"; do
  282. if echo $a | grep "^--prefix=" > /dev/null 2> /dev/null; then
  283. cmake_prefix_dir=`echo $a | sed "s/^--prefix=//"`
  284. fi
  285. if echo $a | grep "^--parallel=" > /dev/null 2> /dev/null; then
  286. cmake_parallel_make=`echo $a | sed "s/^--parallel=//" | grep "[0-9][0-9]*"`
  287. fi
  288. if echo $a | grep "^--datadir=" > /dev/null 2> /dev/null; then
  289. cmake_data_dir=`echo $a | sed "s/^--datadir=//"`
  290. fi
  291. if echo $a | grep "^--docdir=" > /dev/null 2> /dev/null; then
  292. cmake_doc_dir=`echo $a | sed "s/^--docdir=//"`
  293. fi
  294. if echo $a | grep "^--mandir=" > /dev/null 2> /dev/null; then
  295. cmake_man_dir=`echo $a | sed "s/^--mandir=//"`
  296. fi
  297. if echo $a | grep "^--init=" > /dev/null 2> /dev/null; then
  298. cmake_init_file=`echo $a | sed "s/^--init=//"`
  299. fi
  300. if echo $a | grep "^--help" > /dev/null 2> /dev/null; then
  301. cmake_usage
  302. fi
  303. if echo $a | grep "^--version" > /dev/null 2> /dev/null; then
  304. cmake_version
  305. exit 2
  306. fi
  307. if echo $a | grep "^--verbose" > /dev/null 2> /dev/null; then
  308. cmake_verbose=TRUE
  309. fi
  310. done
  311. # If verbose, display some information about bootstrap
  312. if [ -n "${cmake_verbose}" ]; then
  313. echo "---------------------------------------------"
  314. echo "Source directory: ${cmake_source_dir}"
  315. echo "Binary directory: ${cmake_binary_dir}"
  316. echo "Prefix directory: ${cmake_prefix_dir}"
  317. echo "System: ${cmake_system}"
  318. if [ "x${cmake_parallel_make}" != "x" ]; then
  319. echo "Doing parallel make: ${cmake_parallel_make}"
  320. fi
  321. echo ""
  322. fi
  323. echo "---------------------------------------------"
  324. # Get CMake version
  325. echo "`cmake_version`"
  326. # Check for in-source build
  327. cmake_in_source_build=
  328. if [ -f "${cmake_binary_dir}/Source/cmake.cxx" -a \
  329. -f "${cmake_binary_dir}/Source/cmake.h" ]; then
  330. if [ -n "${cmake_verbose}" ]; then
  331. echo "Warning: This is an in-source build"
  332. fi
  333. cmake_in_source_build=TRUE
  334. fi
  335. # If this is not an in-source build, then Bootstrap stuff should not exist.
  336. if [ -z "${cmake_in_source_build}" ]; then
  337. # Did somebody bootstrap in the source tree?
  338. if [ -d "${cmake_source_dir}/Bootstrap.cmk" ]; then
  339. cmake_error 10 "Found directory \"${cmake_source_dir}/Bootstrap.cmk\".
  340. Looks like somebody did bootstrap CMake in the source tree, but now you are
  341. trying to do bootstrap in the binary tree. Please remove Bootstrap.cmk
  342. directory from the source tree."
  343. fi
  344. # Is there a cache in the source tree?
  345. for cmake_problematic_file in ${CMAKE_PROBLEMATIC_FILES}; do
  346. if [ -f "${cmake_source_dir}/${cmake_problematic_file}" ]; then
  347. cmake_error 10 "Found \"${cmake_source_dir}/${cmake_problematic_file}\".
  348. Looks like somebody tried to build CMake in the source tree, but now you are
  349. trying to do bootstrap in the binary tree. Please remove \"${cmake_problematic_file}\"
  350. from the source tree."
  351. fi
  352. done
  353. fi
  354. # Make bootstrap directory
  355. [ -d "${cmake_bootstrap_dir}" ] || mkdir "${cmake_bootstrap_dir}"
  356. if [ ! -d "${cmake_bootstrap_dir}" ]; then
  357. cmake_error 3 "Cannot create directory ${cmake_bootstrap_dir} to bootstrap CMake."
  358. fi
  359. cd "${cmake_bootstrap_dir}"
  360. [ -d "cmsys" ] || mkdir "cmsys"
  361. if [ ! -d "cmsys" ]; then
  362. cmake_error 4 "Cannot create directory ${cmake_bootstrap_dir}/cmsys"
  363. fi
  364. for a in stl ios; do
  365. [ -d "cmsys/${a}" ] || mkdir "cmsys/${a}"
  366. if [ ! -d "cmsys/${a}" ]; then
  367. cmake_error 5 "Cannot create directory ${cmake_bootstrap_dir}/cmsys/${a}"
  368. fi
  369. done
  370. # Delete all the bootstrap files
  371. rm -f "${cmake_bootstrap_dir}/cmake_bootstrap.log"
  372. rm -f "${cmake_bootstrap_dir}/cmConfigure.h.tmp"
  373. # If exist compiler flags, set them
  374. cmake_c_flags=${CFLAGS}
  375. cmake_cxx_flags=${CXXFLAGS}
  376. # Test C compiler
  377. cmake_c_compiler=
  378. # If CC is set, use that for compiler, otherwise use list of known compilers
  379. if [ -n "${CC}" ]; then
  380. cmake_c_compilers="${CC}"
  381. else
  382. cmake_c_compilers="${CMAKE_KNOWN_C_COMPILERS}"
  383. fi
  384. # Check if C compiler works
  385. TMPFILE=`cmake_tmp_file`
  386. cat > "${TMPFILE}.c" <<EOF
  387. #include<stdio.h>
  388. int main()
  389. {
  390. printf("1\n");
  391. return 0;
  392. }
  393. EOF
  394. for a in ${cmake_c_compilers}; do
  395. if [ -z "${cmake_c_compiler}" ] && \
  396. cmake_try_run "${a}" "${cmake_c_flags}" "${TMPFILE}.c" >> cmake_bootstrap.log 2>&1; then
  397. cmake_c_compiler="${a}"
  398. fi
  399. done
  400. rm -f "${TMPFILE}.c"
  401. if [ -z "${cmake_c_compiler}" ]; then
  402. cmake_error 6 "Cannot find appropriate C compiler on this system.
  403. Please specify one using environment variable CC.
  404. See cmake_bootstrap.log for compilers attempted.
  405. "
  406. fi
  407. echo "C compiler on this system is: ${cmake_c_compiler} ${cmake_c_flags}"
  408. # Test CXX compiler
  409. cmake_cxx_compiler=
  410. # On Mac OSX, CC is the same as cc, so make sure not to try CC as c++ compiler.
  411. # If CC is set, use that for compiler, otherwise use list of known compilers
  412. if [ -n "${CXX}" ]; then
  413. cmake_cxx_compilers="${CXX}"
  414. else
  415. cmake_cxx_compilers="${CMAKE_KNOWN_CXX_COMPILERS}"
  416. fi
  417. # Check if C++ compiler works
  418. TMPFILE=`cmake_tmp_file`
  419. cat > "${TMPFILE}.cxx" <<EOF
  420. #if defined(TEST1)
  421. # include <iostream>
  422. #else
  423. # include <iostream.h>
  424. #endif
  425. class NeedCXX
  426. {
  427. public:
  428. NeedCXX() { this->Foo = 1; }
  429. int GetFoo() { return this->Foo; }
  430. private:
  431. int Foo;
  432. };
  433. int main()
  434. {
  435. NeedCXX c;
  436. #ifdef TEST3
  437. cout << c.GetFoo() << endl;
  438. #else
  439. std::cout << c.GetFoo() << std::endl;
  440. #endif
  441. return 0;
  442. }
  443. EOF
  444. for a in ${cmake_cxx_compilers}; do
  445. for b in 1 2 3; do
  446. if [ -z "${cmake_cxx_compiler}" ] && \
  447. cmake_try_run "${a}" "${cmake_cxx_flags} -DTEST${b}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
  448. cmake_cxx_compiler="${a}"
  449. fi
  450. done
  451. done
  452. rm -f "${TMPFILE}.cxx"
  453. if [ -z "${cmake_cxx_compiler}" ]; then
  454. cmake_error 7 "Cannot find appropriate C++ compiler on this system.
  455. Please specify one using environment variable CXX.
  456. See cmake_bootstrap.log for compilers attempted."
  457. fi
  458. echo "C++ compiler on this system is: ${cmake_cxx_compiler} ${cmake_cxx_flags}"
  459. # Test Make
  460. cmake_make_processor=
  461. cmake_make_flags=
  462. # If MAKE is set, use that for make processor, otherwise use list of known make
  463. if [ -n "${MAKE}" ]; then
  464. cmake_make_processors="${MAKE}"
  465. else
  466. cmake_make_processors="${CMAKE_KNOWN_MAKE_PROCESSORS}"
  467. fi
  468. TMPFILE="`cmake_tmp_file`_dir"
  469. rm -rf "${cmake_bootstrap_dir}/${TMPFILE}"
  470. mkdir "${cmake_bootstrap_dir}/${TMPFILE}"
  471. cd "${cmake_bootstrap_dir}/${TMPFILE}"
  472. cat>"Makefile"<<EOF
  473. test: test.c
  474. "${cmake_c_compiler}" -o test test.c
  475. EOF
  476. cat>"test.c"<<EOF
  477. #include <stdio.h>
  478. int main(){ printf("1\n"); return 0; }
  479. EOF
  480. cmake_original_make_flags="${cmake_make_flags}"
  481. if [ "x${cmake_parallel_make}" != "x" ]; then
  482. cmake_make_flags="${cmake_make_flags} -j ${cmake_parallel_make}"
  483. fi
  484. for a in ${cmake_make_processors}; do
  485. if [ -z "${cmake_make_processor}" ] && cmake_try_make "${a}" "${cmake_make_flags}" >> cmake_bootstrap.log 2>&1; then
  486. cmake_make_processor="${a}"
  487. fi
  488. done
  489. cmake_full_make_flags="${cmake_make_flags}"
  490. if [ "x${cmake_original_make_flags}" != "x${cmake_make_flags}" ]; then
  491. if [ -z "${cmake_make_processor}" ]; then
  492. cmake_make_flags="${cmake_original_make_flags}"
  493. for a in ${cmake_make_processors}; do
  494. if [ -z "${cmake_make_processor}" ] && cmake_try_make "${a}" "${cmake_make_flags}" >> cmake_bootstrap.log 2>&1; then
  495. cmake_make_processor="${a}"
  496. fi
  497. done
  498. fi
  499. fi
  500. cd "${cmake_bootstrap_dir}"
  501. rm -rf "${cmake_bootstrap_dir}/${TMPFILE}"
  502. if [ -z "${cmake_make_processor}" ]; then
  503. cmake_error 8 "Cannot find appropriate Makefile processor on this system.
  504. Please specify one using environment variable MAKE."
  505. fi
  506. echo "Makefile processor on this system is: ${cmake_make_processor}"
  507. if [ "x${cmake_full_make_flags}" != "x${cmake_make_flags}" ]; then
  508. echo "---------------------------------------------"
  509. echo "Makefile processor ${cmake_make_processor} does not support parallel build"
  510. echo "---------------------------------------------"
  511. fi
  512. # Ok, we have CC, CXX, and MAKE.
  513. # Test C++ compiler features
  514. # Are we GCC?
  515. TMPFILE=`cmake_tmp_file`
  516. cat > ${TMPFILE}.cxx <<EOF
  517. #if defined(__GNUC__) && !defined(__INTEL_COMPILER)
  518. #include <iostream>
  519. int main() { std::cout << "This is GNU" << std::endl; return 0;}
  520. #endif
  521. EOF
  522. cmake_cxx_compiler_is_gnu=0
  523. if cmake_try_run "${cmake_cxx_compiler}" \
  524. "${cmake_cxx_flags}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
  525. cmake_cxx_compiler_is_gnu=1
  526. fi
  527. if [ "x${cmake_cxx_compiler_is_gnu}" = "x1" ]; then
  528. echo "${cmake_cxx_compiler} is GNU compiler"
  529. else
  530. echo "${cmake_cxx_compiler} is not GNU compiler"
  531. fi
  532. rm -f "${TMPFILE}.cxx"
  533. if [ "x${cmake_cxx_compiler_is_gnu}" != "x1" ]; then
  534. # Check for non-GNU compiler flags
  535. # If we are on IRIX, check for -LANG:std
  536. cmake_test_flags="-LANG:std"
  537. if [ "x${cmake_system}" = "xIRIX64" ]; then
  538. TMPFILE=`cmake_tmp_file`
  539. cat > ${TMPFILE}.cxx <<EOF
  540. #include <iostream>
  541. int main() { std::cout << "No need for ${cmake_test_flags}" << std::endl; return 0;}
  542. EOF
  543. cmake_need_lang_std=0
  544. if cmake_try_run "${cmake_cxx_compiler}" \
  545. "${cmake_cxx_flags}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
  546. :
  547. else
  548. if cmake_try_run "${cmake_cxx_compiler}" \
  549. "${cmake_cxx_flags} ${cmake_test_flags}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
  550. cmake_need_lang_std=1
  551. fi
  552. fi
  553. if [ "x${cmake_need_lang_std}" = "x1" ]; then
  554. cmake_cxx_flags="${cmake_cxx_flags} ${cmake_test_flags}"
  555. echo "${cmake_cxx_compiler} needs ${cmake_test_flags}"
  556. else
  557. echo "${cmake_cxx_compiler} does not need ${cmake_test_flags}"
  558. fi
  559. rm -f "${TMPFILE}.cxx"
  560. fi
  561. cmake_test_flags=
  562. # If we are on OSF, check for -timplicit_local -no_implicit_include
  563. cmake_test_flags="-timplicit_local -no_implicit_include"
  564. if [ "x${cmake_system}" = "xOSF1" ]; then
  565. TMPFILE=`cmake_tmp_file`
  566. cat > ${TMPFILE}.cxx <<EOF
  567. #include <iostream>
  568. int main() { std::cout << "We need ${cmake_test_flags}" << std::endl; return 0;}
  569. EOF
  570. cmake_need_flags=1
  571. if cmake_try_run "${cmake_cxx_compiler}" \
  572. "${cmake_cxx_flags} ${cmake_test_flags}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
  573. :
  574. else
  575. cmake_need_flags=0
  576. fi
  577. if [ "x${cmake_need_flags}" = "x1" ]; then
  578. cmake_cxx_flags="${cmake_cxx_flags} ${cmake_test_flags}"
  579. echo "${cmake_cxx_compiler} needs ${cmake_test_flags}"
  580. else
  581. echo "${cmake_cxx_compiler} does not need ${cmake_test_flags}"
  582. fi
  583. rm -f "${TMPFILE}.cxx"
  584. fi
  585. cmake_test_flags=
  586. # If we are on OSF, check for -std strict_ansi -nopure_cname
  587. cmake_test_flags="-std strict_ansi -nopure_cname"
  588. if [ "x${cmake_system}" = "xOSF1" ]; then
  589. TMPFILE=`cmake_tmp_file`
  590. cat > ${TMPFILE}.cxx <<EOF
  591. #include <iostream>
  592. int main() { std::cout << "We need ${cmake_test_flags}" << std::endl; return 0;}
  593. EOF
  594. cmake_need_flags=1
  595. if cmake_try_run "${cmake_cxx_compiler}" \
  596. "${cmake_cxx_flags} ${cmake_test_flags}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
  597. :
  598. else
  599. cmake_need_flags=0
  600. fi
  601. if [ "x${cmake_need_flags}" = "x1" ]; then
  602. cmake_cxx_flags="${cmake_cxx_flags} ${cmake_test_flags}"
  603. echo "${cmake_cxx_compiler} needs ${cmake_test_flags}"
  604. else
  605. echo "${cmake_cxx_compiler} does not need ${cmake_test_flags}"
  606. fi
  607. rm -f "${TMPFILE}.cxx"
  608. fi
  609. cmake_test_flags=
  610. # If we are on HP-UX, check for -Ae for the C compiler.
  611. cmake_test_flags="-Ae"
  612. if [ "x${cmake_system}" = "xHP-UX" ]; then
  613. TMPFILE=`cmake_tmp_file`
  614. cat > ${TMPFILE}.c <<EOF
  615. int main(int argc, char** argv) { (void)argc; (void)argv; return 0; }
  616. EOF
  617. cmake_need_Ae=0
  618. if cmake_try_run "${cmake_c_compiler}" "${cmake_c_flags}" "${TMPFILE}.c" >> cmake_bootstrap.log 2>&1; then
  619. :
  620. else
  621. if cmake_try_run "${cmake_c_compiler}" \
  622. "${cmake_c_flags} ${cmake_test_flags}" "${TMPFILE}.c" >> cmake_bootstrap.log 2>&1; then
  623. cmake_need_Ae=1
  624. fi
  625. fi
  626. if [ "x${cmake_need_Ae}" = "x1" ]; then
  627. cmake_c_flags="${cmake_c_flags} ${cmake_test_flags}"
  628. echo "${cmake_c_compiler} needs ${cmake_test_flags}"
  629. else
  630. echo "${cmake_c_compiler} does not need ${cmake_test_flags}"
  631. fi
  632. rm -f "${TMPFILE}.c"
  633. fi
  634. cmake_test_flags=
  635. fi
  636. # Test for kwsys features
  637. KWSYS_NAME_IS_KWSYS=0
  638. KWSYS_BUILD_SHARED=0
  639. KWSYS_IOS_USE_STRSTREAM_H=0
  640. KWSYS_IOS_USE_STRSTREA_H=0
  641. KWSYS_IOS_HAVE_STD=0
  642. KWSYS_IOS_USE_SSTREAM=0
  643. KWSYS_IOS_USE_ANSI=0
  644. KWSYS_STL_HAVE_STD=0
  645. KWSYS_STAT_HAS_ST_MTIM=0
  646. if cmake_try_run "${cmake_cxx_compiler}" \
  647. "${cmake_cxx_flags} -DTEST_KWSYS_STL_HAVE_STD" \
  648. "${cmake_source_dir}/Source/kwsys/kwsysPlatformCxxTests.cxx" >> cmake_bootstrap.log 2>&1; then
  649. KWSYS_STL_HAVE_STD=1
  650. echo "${cmake_cxx_compiler} has STL in std:: namespace"
  651. else
  652. echo "${cmake_cxx_compiler} does not have STL in std:: namespace"
  653. fi
  654. if cmake_try_run "${cmake_cxx_compiler}" \
  655. "${cmake_cxx_flags} -DTEST_KWSYS_IOS_USE_ANSI" \
  656. "${cmake_source_dir}/Source/kwsys/kwsysPlatformCxxTests.cxx" >> cmake_bootstrap.log 2>&1; then
  657. KWSYS_IOS_USE_ANSI=1
  658. echo "${cmake_cxx_compiler} has ANSI streams"
  659. else
  660. echo "${cmake_cxx_compiler} does not have ANSI streams"
  661. fi
  662. if [ "x$KWSYS_IOS_USE_ANSI" = "x1" ]; then
  663. if cmake_try_run "${cmake_cxx_compiler}" \
  664. "${cmake_cxx_flags} -DTEST_KWSYS_IOS_HAVE_STD" \
  665. "${cmake_source_dir}/Source/kwsys/kwsysPlatformCxxTests.cxx" >> cmake_bootstrap.log 2>&1; then
  666. KWSYS_IOS_HAVE_STD=1
  667. echo "${cmake_cxx_compiler} has streams in std:: namespace"
  668. else
  669. echo "${cmake_cxx_compiler} does not have streams in std:: namespace"
  670. fi
  671. if cmake_try_run "${cmake_cxx_compiler}" \
  672. "${cmake_cxx_flags} -DTEST_KWSYS_IOS_USE_SSTREAM" \
  673. "${cmake_source_dir}/Source/kwsys/kwsysPlatformCxxTests.cxx" >> cmake_bootstrap.log 2>&1; then
  674. KWSYS_IOS_USE_SSTREAM=1
  675. echo "${cmake_cxx_compiler} has sstream"
  676. else
  677. echo "${cmake_cxx_compiler} does not have sstream"
  678. fi
  679. fi
  680. if [ "x$KWSYS_IOS_USE_SSTREAM" = "x0" ]; then
  681. if cmake_try_run "${cmake_cxx_compiler}" \
  682. "${cmake_cxx_flags} -DTEST_KWSYS_IOS_USE_STRSTREAM_H" \
  683. "${cmake_source_dir}/Source/kwsys/kwsysPlatformCxxTests.cxx" >> cmake_bootstrap.log 2>&1; then
  684. KWSYS_IOS_USE_STRSTREAM_H=1
  685. echo "${cmake_cxx_compiler} has strstream.h"
  686. else
  687. echo "${cmake_cxx_compiler} does not have strstream.h"
  688. fi
  689. if [ "x$KWSYS_IOS_USE_STRSTREAM_H" = "x0" ]; then
  690. if cmake_try_run "${cmake_cxx_compiler}" \
  691. "${cmake_cxx_flags} -DTEST_KWSYS_IOS_USE_STRSTREA_H" \
  692. "${cmake_source_dir}/Source/kwsys/kwsysPlatformCxxTests.cxx" >> cmake_bootstrap.log 2>&1; then
  693. KWSYS_IOS_USE_STRSTREA_H=1
  694. echo "${cmake_cxx_compiler} has strstrea.h"
  695. else
  696. echo "${cmake_cxx_compiler} does not have strstrea.h"
  697. fi
  698. fi
  699. fi
  700. if cmake_try_run "${cmake_cxx_compiler}" \
  701. "${cmake_cxx_flags} -DTEST_KWSYS_STAT_HAS_ST_MTIM" \
  702. "${cmake_source_dir}/Source/kwsys/kwsysPlatformCxxTests.cxx" >> cmake_bootstrap.log 2>&1; then
  703. KWSYS_STAT_HAS_ST_MTIM=1
  704. echo "${cmake_cxx_compiler} has struct stat with st_mtim member"
  705. else
  706. echo "${cmake_cxx_compiler} does not have struct stat with st_mtim member"
  707. fi
  708. # Just to be safe, let us store compiler and flags to the header file
  709. cmake_bootstrap_version='$Revision$'
  710. cmake_compiler_settings_comment="/*
  711. * Generated by ${cmake_source_dir}/bootstrap
  712. * Version: ${cmake_bootstrap_version}
  713. *
  714. * Source directory: ${cmake_source_dir}
  715. * Binary directory: ${cmake_bootstrap_dir}
  716. *
  717. * C compiler: ${cmake_c_compiler}
  718. * C flags: ${cmake_c_flags}
  719. *
  720. * C++ compiler: ${cmake_cxx_compiler}
  721. * C++ flags: ${cmake_cxx_flags}
  722. *
  723. * Make: ${cmake_make_processor}
  724. *
  725. * Sources:
  726. * ${CMAKE_CXX_SOURCES} ${CMAKE_C_SOURCES}
  727. * kwSys Sources:
  728. * ${KWSYS_CXX_SOURCES} ${KWSYS_C_SOURCES}
  729. */
  730. "
  731. cmake_report cmConfigure.h.tmp "${cmake_compiler_settings_comment}"
  732. if [ "x$KWSYS_STL_HAVE_STD" = "x1" ]; then
  733. cmake_report cmConfigure.h.tmp "/* #undef CMAKE_NO_STD_NAMESPACE */"
  734. else
  735. cmake_report cmConfigure.h.tmp "#define CMAKE_NO_STD_NAMESPACE 1"
  736. fi
  737. if [ "x$KWSYS_IOS_USE_ANSI" = "x1" ]; then
  738. cmake_report cmConfigure.h.tmp "/* #undef CMAKE_NO_ANSI_STREAM_HEADERS */"
  739. else
  740. cmake_report cmConfigure.h.tmp "#define CMAKE_NO_ANSI_STREAM_HEADERS 1"
  741. fi
  742. if [ "x$KWSYS_IOS_USE_SSTREAM" = "x1" ]; then
  743. cmake_report cmConfigure.h.tmp "/* #undef CMAKE_NO_ANSI_STRING_STREAM */"
  744. else
  745. cmake_report cmConfigure.h.tmp "#define CMAKE_NO_ANSI_STRING_STREAM 1"
  746. fi
  747. # Test for ansi FOR scope
  748. if cmake_try_run "${cmake_cxx_compiler}" \
  749. "${cmake_cxx_flags}" \
  750. "${cmake_source_dir}/Modules/TestForAnsiForScope.cxx" >> cmake_bootstrap.log 2>&1; then
  751. cmake_report cmConfigure.h.tmp "/* #undef CMAKE_NO_ANSI_FOR_SCOPE */"
  752. echo "${cmake_cxx_compiler} has ANSI for scoping"
  753. else
  754. cmake_report cmConfigure.h.tmp "#define CMAKE_NO_ANSI_FOR_SCOPE 1"
  755. echo "${cmake_cxx_compiler} does not have ANSI for scoping"
  756. fi
  757. # Write CMake version
  758. for a in MAJOR MINOR PATCH; do
  759. CMake_VERSION=`cat "${cmake_source_dir}/CMakeLists.txt" | \
  760. grep "SET(CMake_VERSION_${a} *[0-9]*)" | sed "s/SET(CMake_VERSION_${a} *\([0-9]*\))/\1/"`
  761. cmake_report cmConfigure.h.tmp "#define CMake_VERSION_${a} ${CMake_VERSION}"
  762. done
  763. cmake_report cmConfigure.h.tmp "#define CMAKE_ROOT_DIR \"${cmake_source_dir}\""
  764. cmake_report cmConfigure.h.tmp "#define CMAKE_DATA_DIR \"${cmake_data_dir}\""
  765. cmake_report cmConfigure.h.tmp "#define CMAKE_BOOTSTRAP"
  766. # Regenerate real cmConfigure.h
  767. if diff cmConfigure.h cmConfigure.h.tmp > /dev/null 2> /dev/null; then
  768. rm -f cmConfigure.h.tmp
  769. else
  770. mv -f cmConfigure.h.tmp cmConfigure.h
  771. fi
  772. # Prepare KWSYS
  773. cmake_kwsys_config_replace_string \
  774. "${cmake_source_dir}/Source/kwsys/Configure.hxx.in" \
  775. "${cmake_bootstrap_dir}/cmsys/Configure.hxx" \
  776. "${cmake_compiler_settings_comment}"
  777. cmake_kwsys_config_replace_string \
  778. "${cmake_source_dir}/Source/kwsys/Configure.h.in" \
  779. "${cmake_bootstrap_dir}/cmsys/Configure.h" \
  780. "${cmake_compiler_settings_comment}"
  781. for a in ${KWSYS_FILES}; do
  782. cmake_replace_string "${cmake_source_dir}/Source/kwsys/${a}.in" \
  783. "${cmake_bootstrap_dir}/cmsys/${a}" KWSYS_NAMESPACE cmsys
  784. done
  785. for a in ${KWSYS_IOS_FILES}; do
  786. cmake_replace_string "${cmake_source_dir}/Source/kwsys/kwsys_ios_${a}.h.in" \
  787. "${cmake_bootstrap_dir}/cmsys/ios/${a}" KWSYS_NAMESPACE cmsys
  788. done
  789. cmake_replace_string "${cmake_source_dir}/Source/kwsys/kwsys_stl.h.in" \
  790. "${cmake_bootstrap_dir}/cmsys/stl/stl.h.in" KWSYS_NAMESPACE cmsys
  791. for a in string vector map; do
  792. cmake_replace_string "${cmake_bootstrap_dir}/cmsys/stl/stl.h.in" \
  793. "${cmake_bootstrap_dir}/cmsys/stl/${a}" KWSYS_STL_HEADER ${a}
  794. done
  795. # Generate Makefile
  796. dep="cmConfigure.h cmsys/Configure.hxx cmsys/Configure.h `cmake_escape \"${cmake_source_dir}\"`/Source/*.h"
  797. objs=""
  798. for a in ${CMAKE_CXX_SOURCES} ${CMAKE_C_SOURCES} ${KWSYS_CXX_SOURCES} ${KWSYS_C_SOURCES}; do
  799. objs="${objs} ${a}.o"
  800. done
  801. # Generate dependencies for cmBootstrapCommands.cxx
  802. for file in `grep "#include.*cm[^.]*.cxx" "${cmake_source_dir}/Source/cmBootstrapCommands.cxx" | sed "s/.* \"\(.*\)\"/\1/"`; do
  803. cmBootstrapCommandsDeps="${cmBootstrapCommandsDeps} `cmake_escape "${cmake_source_dir}/Source/$file"`"
  804. done
  805. cmBootstrapCommandsDeps=`echo $cmBootstrapCommandsDeps`
  806. if [ "x${cmake_ansi_cxx_flags}" != "x" ]; then
  807. cmake_cxx_flags="${cmake_ansi_cxx_flags} ${cmake_cxx_flags}"
  808. fi
  809. if [ "x${cmake_c_flags}" != "x" ]; then
  810. cmake_c_flags="${cmake_c_flags} "
  811. fi
  812. if [ "x${cmake_cxx_flags}" != "x" ]; then
  813. cmake_cxx_flags="${cmake_cxx_flags} "
  814. fi
  815. cmake_c_flags="${cmake_c_flags}-I`cmake_escape \"${cmake_source_dir}/Source\"` \
  816. -I`cmake_escape \"${cmake_bootstrap_dir}\"`"
  817. cmake_cxx_flags="${cmake_cxx_flags}-I`cmake_escape \"${cmake_source_dir}/Source\"` \
  818. -I`cmake_escape \"${cmake_bootstrap_dir}\"`"
  819. echo "cmake: ${objs}" > "${cmake_bootstrap_dir}/Makefile"
  820. echo " ${cmake_cxx_compiler} ${LDFLAGS} ${cmake_cxx_flags} ${objs} -o cmake" >> "${cmake_bootstrap_dir}/Makefile"
  821. for a in ${CMAKE_CXX_SOURCES}; do
  822. src=`cmake_escape "${cmake_source_dir}/Source/${a}.cxx"`
  823. echo "${a}.o : ${src} ${dep}" >> "${cmake_bootstrap_dir}/Makefile"
  824. echo " ${cmake_cxx_compiler} ${cmake_cxx_flags} -c ${src} -o ${a}.o" >> "${cmake_bootstrap_dir}/Makefile"
  825. done
  826. echo "cmBootstrapCommands.o : $cmBootstrapCommandsDeps" >> "${cmake_bootstrap_dir}/Makefile"
  827. for a in ${CMAKE_C_SOURCES}; do
  828. src=`cmake_escape "${cmake_source_dir}/Source/${a}.c"`
  829. echo "${a}.o : ${src} ${dep}" >> "${cmake_bootstrap_dir}/Makefile"
  830. echo " ${cmake_c_compiler} ${cmake_c_flags} -c ${src} -o ${a}.o" >> "${cmake_bootstrap_dir}/Makefile"
  831. done
  832. for a in ${KWSYS_C_SOURCES}; do
  833. src=`cmake_escape "${cmake_source_dir}/Source/kwsys/${a}.c"`
  834. echo "${a}.o : ${src} ${dep}" >> "${cmake_bootstrap_dir}/Makefile"
  835. echo " ${cmake_c_compiler} ${cmake_c_flags} -DKWSYS_NAMESPACE=cmsys -c ${src} -o ${a}.o" >> "${cmake_bootstrap_dir}/Makefile"
  836. done
  837. for a in ${KWSYS_CXX_SOURCES}; do
  838. src=`cmake_escape "${cmake_source_dir}/Source/kwsys/${a}.cxx"`
  839. echo "${a}.o : ${src} ${dep}" >> "${cmake_bootstrap_dir}/Makefile"
  840. echo " ${cmake_cxx_compiler} ${cmake_cxx_flags} -DKWSYS_NAMESPACE=cmsys -c ${src} -o ${a}.o" >> "${cmake_bootstrap_dir}/Makefile"
  841. done
  842. cat>>"${cmake_bootstrap_dir}/Makefile"<<EOF
  843. rebuild_cache:
  844. cd "${cmake_binary_dir}" && "${cmake_source_dir}/bootstrap"
  845. EOF
  846. # Write our default settings to Bootstrap.cmk/InitialCacheFlags.cmake.
  847. cat > "${cmake_bootstrap_dir}/InitialCacheFlags.cmake" <<EOF
  848. # Generated by ${cmake_source_dir}/bootstrap
  849. # Default cmake settings. These may be overridden any settings below.
  850. SET (CMAKE_INSTALL_PREFIX "${cmake_prefix_dir}" CACHE PATH "Install path prefix, prepended onto install directories." FORCE)
  851. SET (CMAKE_DOC_DIR "${cmake_doc_dir}" CACHE PATH "Install location for documentation (relative to prefix)." FORCE)
  852. SET (CMAKE_MAN_DIR "${cmake_man_dir}" CACHE PATH "Install location for man pages (relative to prefix)." FORCE)
  853. SET (CMAKE_DATA_DIR "${cmake_data_dir}" CACHE PATH "Install location for data (relative to prefix)." FORCE)
  854. EOF
  855. # Add user-specified settings. Handle relative-path case for
  856. # specification of cmake_init_file.
  857. (
  858. cd "${cmake_binary_dir}"
  859. if [ -f "${cmake_init_file}" ]; then
  860. cat "${cmake_init_file}" >> "${cmake_bootstrap_dir}/InitialCacheFlags.cmake"
  861. fi
  862. )
  863. echo "---------------------------------------------"
  864. # Run make to build bootstrap cmake
  865. if [ "x${cmake_parallel_make}" != "x" ]; then
  866. ${cmake_make_processor} ${cmake_make_flags}
  867. else
  868. ${cmake_make_processor}
  869. fi
  870. RES=$?
  871. if [ "${RES}" -ne "0" ]; then
  872. cmake_error 9 "Problem while running ${cmake_make_processor}"
  873. fi
  874. cd "${cmake_binary_dir}"
  875. # Set C, CXX, and MAKE environment variables, so that real real cmake will be
  876. # build with same compiler and make
  877. CC="${cmake_c_compiler}"
  878. CXX="${cmake_cxx_compiler}"
  879. MAKE="${cmake_make_processor}"
  880. export CC
  881. export CXX
  882. export MAKE
  883. # Run bootstrap CMake to configure real CMake
  884. "${cmake_bootstrap_dir}/cmake" "${cmake_source_dir}" "-C${cmake_bootstrap_dir}/InitialCacheFlags.cmake"
  885. RES=$?
  886. if [ "${RES}" -ne "0" ]; then
  887. cmake_error 11 "Problem while running initial CMake"
  888. fi
  889. echo "---------------------------------------------"
  890. # And we are done. Now just run make
  891. echo "CMake has bootstrapped. Now run ${cmake_make_processor}."