bootstrap 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. #!/bin/sh
  2. CMAKE_KNOWN_C_COMPILERS="cc gcc xlc icc tcc"
  3. CMAKE_KNOWN_CXX_COMPILERS="CC g++ c++ xlC icc como aCC"
  4. CMAKE_KNOWN_MAKE_PROCESSORS="make gmake"
  5. CMAKE_SOURCES="\
  6. cmake \
  7. cmakewizard \
  8. cmakemain \
  9. cmMakeDepend \
  10. cmMakefile \
  11. cmDocumentation \
  12. cmGlobalGenerator \
  13. cmLocalGenerator \
  14. cmRegularExpression \
  15. cmSourceFile \
  16. cmSystemTools \
  17. cmDirectory \
  18. cmGlobalUnixMakefileGenerator \
  19. cmLocalUnixMakefileGenerator \
  20. cmCommands \
  21. cmTarget \
  22. cmCustomCommand \
  23. cmCacheManager \
  24. cmListFileCache \
  25. cmVariableWatch \
  26. cmSourceGroup"
  27. cmake_system=`uname`
  28. cmake_source_dir=`echo $0 | sed -n '/\//{s/\/[^\/]*$//;p;}'`
  29. cmake_source_dir=`(cd "${cmake_source_dir}";pwd)`
  30. cmake_binary_dir=`pwd`
  31. cmake_bootstrap_dir="${cmake_binary_dir}/Bootstrap.cmk"
  32. cmake_usage()
  33. {
  34. cat<<EOF
  35. Usage: $0 [options]
  36. Options: [defaults in brackets after descriptions]
  37. Configuration:
  38. --help print this message
  39. --verbose display more information
  40. Directory and file names:
  41. --prefix=PREFIX install architecture-independent files in PREFIX
  42. [/usr/local]
  43. EOF
  44. exit 10
  45. }
  46. cmake_error()
  47. {
  48. echo "---------------------------------------------"
  49. echo "Error when bootstrapping CMake:"
  50. echo "$*"
  51. echo "---------------------------------------------"
  52. if [ -f cmake_bootstrap.log ]; then
  53. echo "Log of errors:"
  54. cat cmake_bootstrap.log
  55. echo "---------------------------------------------"
  56. fi
  57. exit 1
  58. }
  59. cmake_report ()
  60. {
  61. FILE=$1
  62. shift
  63. echo "$*" >> ${FILE}
  64. }
  65. cmake_escape ()
  66. {
  67. echo $1 | sed "s/ /\\\\ /g"
  68. }
  69. cmake_log ()
  70. {
  71. echo "$*" >> cmake_bootstrap.log
  72. }
  73. cmake_tmp_file ()
  74. {
  75. echo "cmake_bootstrap_$$.test"
  76. }
  77. cmake_try_run ()
  78. {
  79. COMPILER=$1
  80. FLAGS=$2
  81. TESTFILE=$3
  82. if [ ! -f "${TESTFILE}" ]; then
  83. echo "Test file ${TESTFILE} missing. Please verify your CMake source tree."
  84. exit 4
  85. fi
  86. TMPFILE=`cmake_tmp_file`
  87. echo "Try: ${COMPILER}"
  88. "${COMPILER}" ${FLAGS} "${TESTFILE}" -o "${TMPFILE}"
  89. RES=$?
  90. if [ "${RES}" -ne "0" ]; then
  91. echo "${COMPILER} does not work";return 1
  92. fi
  93. if [ ! -f "${TMPFILE}" ] && [ ! -f "${TMPFILE}.exe" ]; then
  94. echo "${COMPILER} does not produce output"
  95. return 2
  96. fi
  97. ./${TMPFILE}
  98. RES=$?
  99. rm -f "${TMPFILE}"
  100. if [ "${RES}" -ne "0" ]; then
  101. echo "${COMPILER} produces strange executable"
  102. return 3
  103. fi
  104. echo "${COMPILER} works"
  105. return 0
  106. }
  107. cmake_try_make ()
  108. {
  109. MAKE_PROC=$1
  110. echo "Try: ${MAKE_PROC}"
  111. ${MAKE_PROC}
  112. RES=$?
  113. if [ "${RES}" -ne "0" ]; then
  114. echo "${MAKE_PROC} does not work";return 1
  115. fi
  116. if [ ! -f "test" ] && [ ! -f "test.exe" ]; then
  117. echo "${COMPILER} does not produce output"
  118. return 2
  119. fi
  120. ./test
  121. RES=$?
  122. rm -f "test"
  123. if [ "${RES}" -ne "0" ]; then
  124. echo "${MAKE_PROC} produces strange executable"
  125. return 3
  126. fi
  127. echo "${MAKE_PROC} works"
  128. return 0
  129. }
  130. cmake_verbose=
  131. cmake_prefix_dir="/usr/local"
  132. for a in "$@"; do
  133. if echo $a | grep "^--prefix="; then
  134. cmake_prefix_dir=`echo $a | sed "s/^--prefix=//"`
  135. fi
  136. if echo $a | grep "^--help"; then
  137. cmake_usage
  138. fi
  139. if echo $a | grep "^--verbose"; then
  140. cmake_verbose=TRUE
  141. fi
  142. done
  143. if [ -n "${cmake_verbose}" ]; then
  144. echo "---------------------------------------------"
  145. echo "Source directory: ${cmake_source_dir}"
  146. echo "Binary directory: ${cmake_binary_dir}"
  147. echo "Prefix directory: ${cmake_prefix_dir}"
  148. echo "System: ${cmake_system}"
  149. fi
  150. echo "---------------------------------------------"
  151. [ -d "${cmake_bootstrap_dir}" ] || mkdir "${cmake_bootstrap_dir}"
  152. if [ ! -d "${cmake_bootstrap_dir}" ]; then
  153. cmake_error "Cannot create directory ${cmake_bootstrap_dir} to bootstrap CMake."
  154. fi
  155. cd "${cmake_bootstrap_dir}"
  156. rm -f "${cmake_bootstrap_dir}/cmake_bootstrap.log"
  157. rm -f "${cmake_bootstrap_dir}/cmConfigure.h"
  158. cmake_c_flags=${CFLAGS}
  159. cmake_cxx_flags=${CXXFLAGS}
  160. # Test C compiler
  161. cmake_c_compiler=
  162. if [ -n "${CC}" ]; then
  163. cmake_c_compilers="${CC}"
  164. else
  165. cmake_c_compilers="${CMAKE_KNOWN_C_COMPILERS}"
  166. fi
  167. TMPFILE=`cmake_tmp_file`
  168. cat>"${TMPFILE}.c"<<EOF
  169. #include<stdio.h>
  170. int main()
  171. {
  172. printf("1\n");
  173. return 0;
  174. }
  175. EOF
  176. for a in ${cmake_c_compilers}; do
  177. if [ -z "${cmake_c_compiler}" ] && cmake_try_run "${a}" "${cmake_c_flags}" "${TMPFILE}.c" >> cmake_bootstrap.log 2>&1; then
  178. cmake_c_compiler="${a}"
  179. fi
  180. done
  181. rm -f "${TMPFILE}.c"
  182. if [ -z "${cmake_c_compiler}" ]; then
  183. cmake_error "Cannot find apropriate C compiler on this system.
  184. Please specify one using environment variable CC."
  185. fi
  186. echo "C compiler on this system is: ${cmake_c_compiler} ${cmake_c_flags}"
  187. # Test CXX compiler
  188. cmake_cxx_compiler=
  189. if [ -n "${CXX}" ]; then
  190. cmake_cxx_compilers="${CXX}"
  191. else
  192. cmake_cxx_compilers="${CMAKE_KNOWN_CXX_COMPILERS}"
  193. fi
  194. TMPFILE=`cmake_tmp_file`
  195. cat>"${TMPFILE}.cxx"<<EOF
  196. #include<iostream.h>
  197. int main()
  198. {
  199. cout << 1 << endl;
  200. return 0;
  201. }
  202. EOF
  203. for a in ${cmake_cxx_compilers}; do
  204. if [ -z "${cmake_cxx_compiler}" ] && cmake_try_run "${a}" "${cmake_cxx_flags}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
  205. cmake_cxx_compiler="${a}"
  206. fi
  207. done
  208. rm -f "${TMPFILE}.cxx"
  209. if [ -z "${cmake_cxx_compiler}" ]; then
  210. cmake_error "Cannot find apropriate C++ compiler on this system.
  211. Please specify one using environment variable CXX."
  212. fi
  213. echo "C++ compiler on this system is: ${cmake_cxx_compiler} ${cmake_cxx_flags}"
  214. # Test Make
  215. cmake_make_processor=
  216. if [ -n "${MAKE}" ]; then
  217. cmake_make_processors="${MAKE}"
  218. else
  219. cmake_make_processors="${CMAKE_KNOWN_MAKE_PROCESSORS}"
  220. fi
  221. TMPFILE="`cmake_tmp_file`_dir"
  222. rm -rf "${cmake_bootstrap_dir}/${TMPFILE}"
  223. mkdir "${cmake_bootstrap_dir}/${TMPFILE}"
  224. cd "${cmake_bootstrap_dir}/${TMPFILE}"
  225. cat>"Makefile"<<EOF
  226. test: test.c
  227. ${cmake_c_compiler} -o test test.c
  228. EOF
  229. cat>"test.c"<<EOF
  230. #include <stdio.h>
  231. int main(){ printf("1\n"); return 0; }
  232. EOF
  233. for a in ${cmake_make_processors}; do
  234. if [ -z "${cmake_make_processor}" ] && cmake_try_make "${a}" >> cmake_bootstrap.log 2>&1; then
  235. cmake_make_processor="${a}"
  236. fi
  237. done
  238. cd "${cmake_bootstrap_dir}"
  239. rm -rf "${cmake_bootstrap_dir}/${TMPFILE}"
  240. echo "Make processor on this system is: ${cmake_make_processor}"
  241. # Test C++ compiler features
  242. if [ "x${cmake_system}" = "xIRIX64" ]; then
  243. TMPFILE=`cmake_tmp_file`
  244. cat>${TMPFILE}.cxx<<EOF
  245. #include <iostream>
  246. int main() { std::cout << "No need for -LANG:std" << std::endl; return 0;}
  247. EOF
  248. cmake_need_lang_std=0
  249. if cmake_try_run "${cmake_cxx_compiler}" "${cmake_cxx_flags}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
  250. :
  251. else
  252. if cmake_try_run "${cmake_cxx_compiler}" "${cmake_cxx_flags} -LANG:std" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
  253. cmake_need_lang_std=1
  254. fi
  255. fi
  256. if [ "x${cmake_need_lang_std}" = "x1" ]; then
  257. cmake_cxx_flags="${cmake_cxx_flags} -LANG:std"
  258. echo "${cmake_cxx_compiler} needs -LANG:std"
  259. else
  260. echo "${cmake_cxx_compiler} does not need -LANG:std"
  261. fi
  262. rm -f "${TMPFILE}.cxx"
  263. fi
  264. if cmake_try_run "${cmake_cxx_compiler}" "${cmake_cxx_flags}" "${cmake_source_dir}/Modules/TestForSTDNamespace.cxx" >> cmake_bootstrap.log 2>&1; then
  265. cmake_report cmConfigure.h "/* #undef CMAKE_NO_STD_NAMESPACE */"
  266. echo "${cmake_cxx_compiler} has STD namespace"
  267. else
  268. cmake_report cmConfigure.h "#define CMAKE_NO_STD_NAMESPACE 1"
  269. echo "${cmake_cxx_compiler} does not have STD namespace"
  270. fi
  271. if cmake_try_run "${cmake_cxx_compiler}" "${cmake_cxx_flags}" "${cmake_source_dir}/Modules/TestForANSIStreamHeaders.cxx" >> cmake_bootstrap.log 2>&1; then
  272. cmake_report cmConfigure.h "/* #undef CMAKE_NO_ANSI_STREAM_HEADERS */"
  273. echo "${cmake_cxx_compiler} has ANSI stream headers"
  274. else
  275. cmake_report cmConfigure.h "#define CMAKE_NO_ANSI_STREAM_HEADERS 1"
  276. echo "${cmake_cxx_compiler} does not have ANSI stream headers"
  277. fi
  278. TMPFILE=`cmake_tmp_file`
  279. cat>${TMPFILE}.cxx<<EOF
  280. #include <sstream>
  281. int main() { return 0;}
  282. EOF
  283. if cmake_try_run "${cmake_cxx_compiler}" "${cmake_cxx_flags}" "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
  284. cmake_report cmConfigure.h "/* #undef CMAKE_NO_ANSI_STRING_STREAM */"
  285. echo "${cmake_cxx_compiler} has ANSI string streams"
  286. else
  287. cmake_report cmConfigure.h "#define CMAKE_NO_ANSI_STRING_STREAM 1"
  288. echo "${cmake_cxx_compiler} does not have ANSI string streams"
  289. fi
  290. rm -f "${TMPFILE}.cxx"
  291. if cmake_try_run "${cmake_cxx_compiler}" "${cmake_cxx_flags}" "${cmake_source_dir}/Modules/TestForAnsiForScope.cxx" >> cmake_bootstrap.log 2>&1; then
  292. cmake_report cmConfigure.h "/* #undef CMAKE_NO_ANSI_FOR_SCOPE */"
  293. echo "${cmake_cxx_compiler} has ANSI for scoping"
  294. else
  295. cmake_report cmConfigure.h "#define CMAKE_NO_ANSI_FOR_SCOPE 1"
  296. echo "${cmake_cxx_compiler} does not have ANSI for scoping"
  297. fi
  298. # Get CMake version
  299. for a in MAJOR MINOR PATCH; do
  300. CMake_VERSION=`cat "${cmake_source_dir}/CMakeLists.txt" | grep "SET(CMake_VERSION_${a} *[0-9]*)" | sed "s/SET(CMake_VERSION_${a} *\([0-9]*\))/\1/"`
  301. cmake_report cmConfigure.h "#define CMake_VERSION_${a} ${CMake_VERSION}"
  302. done
  303. # Generate Makefile
  304. dep="cmConfigure.h `cmake_escape \"${cmake_source_dir}\"`/Source/*.h"
  305. objs=""
  306. for a in ${CMAKE_SOURCES}; do
  307. objs="${objs} ${a}.o"
  308. done
  309. cmake_cxx_flags="${cmake_ansi_cxx_flags} ${cmake_cxx_flags} -DCMAKE_ROOT_DIR='\"${cmake_source_dir}\"' -DCMAKE_BOOTSTRAP -I`cmake_escape \"${cmake_source_dir}/Source\"` -I`cmake_escape \"${cmake_bootstrap_dir}\"`"
  310. echo "cmake: ${objs}" > "${cmake_bootstrap_dir}/Makefile"
  311. echo " ${cmake_cxx_compiler} ${LDFLAGS} ${cmake_cxx_flags} ${objs} -o cmake" >> "${cmake_bootstrap_dir}/Makefile"
  312. for a in ${CMAKE_SOURCES}; do
  313. src=`cmake_escape "${cmake_source_dir}/Source/${a}.cxx"`
  314. echo "${a}.o : ${src} ${dep}" >> "${cmake_bootstrap_dir}/Makefile"
  315. echo " ${cmake_cxx_compiler} ${cmake_cxx_flags} -c ${src} -o ${a}.o" >> "${cmake_bootstrap_dir}/Makefile"
  316. done
  317. # Write prefix to Bootstrap.cmk/InitialConfigureFlags.cmake
  318. echo "SET (CMAKE_CONFIGURE_INSTALL_PREFIX \"${cmake_prefix_dir}\" CACHE PATH \"Install path prefix, prepended onto install directories, For CMake this will always override CMAKE_INSTALL_PREFIX in the cache.\")" > "${cmake_bootstrap_dir}/InitialConfigureFlags.cmake"
  319. echo "---------------------------------------------"
  320. ${cmake_make_processor}
  321. RES=$?
  322. if [ "${RES}" -ne "0" ]; then
  323. cmake_error "Problem while bootstrapping CMake"
  324. fi
  325. cd "${cmake_binary_dir}"
  326. "${cmake_bootstrap_dir}/cmake" "${cmake_source_dir}"
  327. echo "---------------------------------------------"