configure 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. #!/bin/bash
  2. if ROOT=$(pwd) && HOST_SYSTEM=$(uname -s) && HOST_ARCH=$(uname -p)
  3. then
  4. #
  5. # Rewrite uname values to a pair from these sets
  6. #
  7. # HOST_SYSTEM := { MacOSX, Linux, Nt, Solaris, FreeBSD, NetBSD, Irix, Plan9 }
  8. #
  9. # HOST_ARCH := { 386, mips, power, sparc }
  10. #
  11. case ${HOST_SYSTEM} in
  12. Windows*|CYGWIN*|MINGW*)
  13. HOST_SYSTEM="Nt"
  14. ;;
  15. Darwin)
  16. HOST_SYSTEM="MacOSX"
  17. ;;
  18. SunOS)
  19. HOST_SYSTEM="Solaris"
  20. ;;
  21. esac
  22. if [ "unknown" = "${HOST_ARCH}" ]
  23. then
  24. HOST_ARCH=$(uname -m)
  25. fi
  26. case ${HOST_ARCH} in
  27. ppc|powerpc)
  28. HOST_ARCH="power"
  29. ;;
  30. x86|x86_32|i386|i586|i686|486|586|686|x86_64)
  31. HOST_ARCH="386"
  32. ;;
  33. esac
  34. #
  35. # Initialize configuration
  36. #
  37. SYSHOST=${HOST_SYSTEM}
  38. SYSTARG=${HOST_SYSTEM}
  39. OBJTYPE=${HOST_ARCH}
  40. #
  41. # Optionally modify configuration
  42. #
  43. while [ -n "${1}" ]
  44. do
  45. case $1 in
  46. *clean)
  47. rm -f mkconfig env bin
  48. #1>&2 echo ok
  49. exit 0
  50. ;;
  51. --host)
  52. shift
  53. HOST_SYSTEM=$1
  54. shift
  55. SYSHOST=${HOST_SYSTEM}
  56. SYSTARG=${HOST_SYSTEM}
  57. ;;
  58. --target)
  59. shift
  60. SYSTARG=$1
  61. shift
  62. ;;
  63. --object)
  64. shift
  65. OBJTYPE=$1
  66. shift
  67. ;;
  68. --help|-help|-h|-?)
  69. cat<<EOF>&2
  70. Configuration options (in order)
  71. --host <Host system type> (eg, MacOSX, Linux, Nt, Solaris, FreeBSD, NetBSD, Plan9)
  72. --target <Target system type> (eg, MacOSX, Linux, Nt, Solaris, FreeBSD, NetBSD, Irix, Plan9)
  73. --object <Target object type> (eg, 386, mips, power, sparc)
  74. Usage
  75. Configuration options must be employed in the order shown above.
  76. Running with no arguments should produce a valid result.
  77. Please contribute to this project by ensuring that any found bugs
  78. have been reported via
  79. http://code.google.com/p/ken-cc/issues/list
  80. for your configuration
  81. HOST_SYSTEM=${HOST_SYSTEM}
  82. HOST_ARCH=${HOST_ARCH}
  83. Cleaning (or unconfiguring)
  84. Run
  85. ./configure clean
  86. or
  87. ./configure --clean
  88. to remove the products of this script.
  89. EOF
  90. exit 1
  91. ;;
  92. esac
  93. done
  94. #
  95. # Host bin
  96. #
  97. BINDIR=${HOST_SYSTEM}/${HOST_ARCH}
  98. #
  99. # Target bin
  100. #
  101. OBJDIR=${SYSTARG}/${OBJTYPE}
  102. #
  103. # Sanity testing...
  104. #
  105. if [ -z "${SYSHOST}" ]||[ -z "${SYSTARG}" ]||[ -z "${OBJTYPE}" ]
  106. then
  107. cat<<EOF>&2
  108. Input error
  109. EOF
  110. exit 1
  111. elif [ ! -d "${BINDIR}" ]
  112. then
  113. cat<<EOF>&2
  114. Host type selection error in one or both of
  115. HOST_SYSTEM '${HOST_SYSTEM}'
  116. HOST_ARCH '${HOST_ARCH}'
  117. EOF
  118. exit 1
  119. elif [ ! -d "${OBJDIR}" ]
  120. then
  121. cat<<EOF>&2
  122. Target type selection error in one or both of
  123. TARGET '${SYSTARG}'
  124. OBJECT '${OBJTYPE}'
  125. EOF
  126. exit 1
  127. else
  128. #
  129. # Generate configuration
  130. #
  131. cat<<EOF>mkconfig
  132. #
  133. # Set the following 4 variables. The host system is the system where
  134. # the software will be built; the target system is where it will run.
  135. # They are almost always the same.
  136. # On Nt systems, the ROOT path MUST be of the form 'drive:/path'
  137. ROOT=${ROOT}
  138. # build system OS type
  139. SYSHOST=${SYSHOST}
  140. # target system OS type
  141. SYSTARG=${SYSTARG}
  142. # target system object type
  143. OBJTYPE=${OBJTYPE}
  144. #
  145. # no changes required beyond this point
  146. #
  147. OBJDIR=\$SYSTARG/\$OBJTYPE
  148. <\$ROOT/mkfiles/mkhost-\$SYSHOST # variables appropriate for host system
  149. <\$ROOT/mkfiles/mkfile-\$SYSTARG-\$OBJTYPE # variables used to build target object type
  150. EOF
  151. fi
  152. #
  153. # Report product
  154. #
  155. cat<<EOF
  156. Successfully configured and wrote 'mkconfig'
  157. EOF
  158. #
  159. # Configure host binaries into 'env' path
  160. #
  161. if [ -e bin ]
  162. then
  163. rm -f bin
  164. fi
  165. if ln -s ${BINDIR}/bin bin
  166. then
  167. cat<<EOF
  168. Successfully configured host path '$(pwd)/bin'
  169. EOF
  170. else
  171. cat<<EOF>&2
  172. Error linking host path 'ln -s ${BINDIR}/bin bin'
  173. EOF
  174. exit 1
  175. fi
  176. #
  177. # Configure 'env' script
  178. #
  179. ewd=$(pwd)
  180. ebp=${ewd}/bin
  181. cat<<EOF>env
  182. #
  183. # Generated by ${ewd}/configure. See ./configure --help.
  184. #
  185. # Usage
  186. # Run
  187. # . ./env
  188. # or
  189. # source ./env
  190. #
  191. # in this directory
  192. # to initialize this development environment
  193. #
  194. PATH=${ebp}:\$(echo \${PATH} | sed 's%${ebp}:%%g; s%:${ebp}%%g')
  195. #
  196. # Convenience for running commands outside 'mk'...
  197. #
  198. ROOT=${ROOT}
  199. #
  200. # Conveniences for sourcing and targeting commands as in 'mk'...
  201. #
  202. SYSTARG=${SYSTARG}
  203. OBJTYPE=${OBJTYPE}
  204. OBJDIR=\${SYSTARG}/\${OBJTYPE}
  205. EOF
  206. cat<<EOF>&2
  207. Employ command ". ./env" in this directory to initialize usage,
  208. or PREPEND "$(pwd)/bin" to your PATH.
  209. EOF
  210. exit 0
  211. else
  212. cat<<EOF>&2
  213. Error running commands 'pwd' or 'uname'.
  214. Unable to configure.
  215. EOF
  216. exit 1
  217. fi