PageRenderTime 53ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/os161/configure

http://azurespider.googlecode.com/
Shell | 387 lines | 153 code | 76 blank | 158 comment | 9 complexity | 00ab561e2b4bc2f55b886c978758b1a4 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. #!/bin/sh
  2. #
  3. # Configure script for OS/161 tree.
  4. # This generates the file "defs.mk" at the top level of the tree.
  5. #
  6. # Usage: ./configure [options]
  7. # where you can get a list of the options by doing ./configure --help.
  8. #
  9. # Must be run with the top of the OS/161 tree as its current directory.
  10. #
  11. # Note: while this superficially acts like a GNU Autoconf configure
  12. # script, it was not generated by autoconf. Scripts generated by
  13. # autoconf are much harder to read. :-)
  14. #
  15. # gcc warnings to use.
  16. # (If you change this, rerun the script to propagate it to defs.mk.)
  17. # -Werror will be added if the --werror argument is given.
  18. WARNINGS='-Wall -W -Wwrite-strings'
  19. # Target hardware platform.
  20. PLATFORM='mips'
  21. # Default optimize/debug flag: optimize.
  22. OPTFLAGS='-O2'
  23. # Default location of the root of the installed system.
  24. # Note that we quote it such that the reference to the home directory
  25. # is a make variable, not a shell variable. This means it gets expanded
  26. # when make runs rather than when this script runs.
  27. OSTREE='$(HOME)/cs161/root'
  28. # Default toolchain name.
  29. TOOLPREFIX="cs161-"
  30. ##################################################
  31. #
  32. # Check to make sure we're in the right place.
  33. if [ ! -d kern/userprog ]; then
  34. echo 'Please run configure from the top of the OS/161 tree.'
  35. exit 1
  36. fi
  37. #
  38. # Process the command-line options.
  39. while [ "x$1" != x ]; do
  40. case "$1" in
  41. --debug) OPTFLAGS='-g';;
  42. --werror|--Werror) WARNINGS="$WARNINGS -Werror";;
  43. --ostree=*) OSTREE=`echo $1 | sed 's,^[^=]*=,,'`;;
  44. --toolprefix=*) TOOLPREFIX=`echo $1 | sed 's,^[^=]*=,,'`;;
  45. --help|*)
  46. more <<EOF
  47. Usage: ./configure [options]
  48. where the options are:
  49. --help Print this message.
  50. --debug Compile the user-level programs with debug info.
  51. This is disabled by default because there's no
  52. support for userlevel source debugging in OS/161.
  53. (Note: debug info in the kernel is controlled by
  54. the kernel config file.)
  55. --werror Compile with -Werror, so that compiler warnings
  56. are turned into errors and cause the build to
  57. stop. Recommended, because on long builds you
  58. don't always notice warnings as they go by, but
  59. disabled by default.
  60. --ostree=PATH Install the compiled system in a directory tree
  61. rooted at PATH. Default is \$HOME/cs161/root.
  62. --toolprefix=NAME Set up to use compiler and tools named with a
  63. prefix of NAME. The default is "cs161-", so the
  64. tools used are called cs161-gcc, cs161-ld, etc.
  65. The directory with these tools should be on your
  66. shell's search path.
  67. EOF
  68. exit
  69. ;;
  70. esac
  71. shift
  72. done
  73. ####################
  74. # Assume gcc on the host. It would be nice to probe this, but for now
  75. # it doesn't seem worthwhile.
  76. HOST_CC=gcc
  77. ####################
  78. # Figure out if the host system needs us to use ranlib or not. Assume
  79. # that if it exists, we should use it. This is a bad assumption on
  80. # BSD/OS 2.1, but hopefully that won't come up, as BSD/OS 2.1 is quite
  81. # out of date now.
  82. echo -n 'Checking for ranlib... '
  83. STUFF=`(ranlib) 2>&1`
  84. if echo $STUFF | grep 'not found' >/dev/null 2>&1; then
  85. echo 'no'
  86. HOST_RANLIB=true
  87. else
  88. echo 'yes'
  89. HOST_RANLIB=ranlib
  90. fi
  91. ####################
  92. # Check if the host system supports 4.4BSD <err.h>.
  93. echo -n "Checking for <err.h>... "
  94. cat > __conftest.c <<EOF
  95. #include <err.h>
  96. int
  97. main()
  98. {
  99. err(0, "works");
  100. return 1;
  101. }
  102. EOF
  103. OK=0
  104. if $HOST_CC __conftest.c -o __conftest >/dev/null 2>&1; then
  105. if ./__conftest >/dev/null 2>&1; then
  106. OK=1
  107. fi
  108. fi
  109. rm -f __conf*
  110. if [ $OK = 1 ]; then
  111. echo 'yes'
  112. else
  113. echo 'no'
  114. COMPAT_CFLAGS="${COMPATCFLAGS} -DNEED_ERR"
  115. COMPAT_TARGETS="${HOSTTARGETS} install-errh"
  116. fi
  117. ####################
  118. # Now generate defs.mk.
  119. echo 'Generating defs.mk.'
  120. (
  121. # First, put an explanatory comment at the top.
  122. cat <<EOF
  123. # This file was generated by configure. Edits will disappear if you rerun
  124. # configure. If you find that you need to edit this file to make things
  125. # work, let the course staff know and we'll try to fix the configure script.
  126. #
  127. #
  128. # The purpose of this file is to hold all the makefile definitions
  129. # needed to adjust the OS/161 build process to any particular
  130. # environment. If I've done it right, all you need to do is rerun the
  131. # configure script and make clean if you decide to work from Linux or
  132. # BSD instead of Digital Unix. If I've done it mostly right, you may
  133. # need to edit this file but you still hopefully won't need to edit
  134. # any of the makefiles.
  135. #
  136. EOF
  137. # Initialize various variables.
  138. cat <<EOF
  139. #
  140. # Initialize various variables that we set only with += in case some make
  141. # has a default value we weren't expecting.
  142. #
  143. CFLAGS=
  144. KCFLAGS=
  145. HOST_CFLAGS=
  146. LDFLAGS=
  147. KLDFLAGS=
  148. HOST_LDFLAGS=
  149. LIBS=
  150. HOST_LIBS=
  151. EOF
  152. # Define OSTREE.
  153. cat <<EOF
  154. #
  155. # Location of installed runnable system tree.
  156. #
  157. # This must be an absolute path, because it is used from different
  158. # levels of the source tree.
  159. #
  160. OSTREE=${OSTREE}
  161. EOF
  162. # Define PLATFORM.
  163. cat <<EOF
  164. #
  165. # Name of the platform we're building OS/161 to run on.
  166. #
  167. PLATFORM=${PLATFORM}
  168. EOF
  169. if [ "x$PLATFORM" = xmips ]; then
  170. cat <<EOF
  171. #
  172. # As of cs161-toolchain-1.2 the MIPS toolchain is a mips-linux one
  173. # that generates more or less SVR4 ELF ABI compliant code. This means
  174. # that by default all code is PIC (position-independent code), which
  175. # is all very well but not what we want. So we use -fno-pic to turn
  176. # this behavior off. It turns out you need -mno-abicalls too to turn
  177. # it off completely.
  178. #
  179. CFLAGS+=-mno-abicalls -fno-pic
  180. KCFLAGS+=-mno-abicalls -fno-pic
  181. # If using an older cs161-toolchain for MIPS, you'll need this instead:
  182. #LDFLAGS+=-Ttext 0x1000
  183. EOF
  184. fi
  185. # Long explanatory comment about the two sets of compiler tools.
  186. cat <<EOF
  187. #
  188. # Because OS/161 runs on one architecture (probably MIPS or ANT32) and
  189. # is compiled on another (probably Alpha or i386) it is important to
  190. # make sure the right compiler (and assembler, linker, etc.) is used
  191. # at every point.
  192. #
  193. # A compiler compiles *running on* one platform, and *generates code*
  194. # that may run on a different platform. Thus, supposing that you are
  195. # building MIPS OS/161 on i386 Linux, there are four possible compilers.
  196. # (If you are building some other OS/161 or building on some other
  197. # platform, make the appropriate substitutions.) These four are:
  198. #
  199. # (1) runs on i386 Linux, generates code for i386 Linux
  200. # (2) runs on i386 Linux, generates code for MIPS OS/161
  201. # (3) runs on MIPS OS/161, generates code for i386 Linux
  202. # (4) runs on MIPS OS/161, generates code for MIPS OS/161
  203. #
  204. # Note that when building on i386 Linux, there is no use for a
  205. # compiler that runs on MIPS OS/161; you can't run it. Thus cases
  206. # (3) and (4) do not interest us.
  207. #
  208. # However, in the course of the build, there are places where it is
  209. # necessary to compile and run programs on the machine the build is
  210. # happening on. Thus, the makefiles need to be able to access *both*
  211. # compiler (1) and compiler (2).
  212. #
  213. # We do this by defining the make variable CC to be the common case,
  214. # compiler (2), and the make variable HOST_CC to be compiler (1).
  215. # Similar variables are defined for the other bits of the toolchain,
  216. # like AS (assembler), LD (linker), and SIZE (size program).
  217. #
  218. # Then, programs to be run during the build can be compiled with
  219. # HOST_CC, and components of the system can be built with CC.
  220. #
  221. EOF
  222. # define CC, LDCC, AS, LD, AR, RANLIB, SIZE, STRIP,
  223. # the tools for building OS/161.
  224. cat <<EOF
  225. # CC: compiler, when compiling to object files
  226. CC=${TOOLPREFIX}gcc
  227. # LDCC: compiler, when linking
  228. LDCC=${TOOLPREFIX}gcc
  229. # AS: assembler.
  230. AS=${TOOLPREFIX}as
  231. # LD: linker
  232. LD=${TOOLPREFIX}ld
  233. # AR: archiver (librarian)
  234. AR=${TOOLPREFIX}ar
  235. # RANLIB: library postprocessor
  236. RANLIB=${TOOLPREFIX}ranlib
  237. # NM: prints symbol tables
  238. NM=${TOOLPREFIX}nm
  239. # SIZE: prints size of binaries
  240. SIZE=${TOOLPREFIX}size
  241. # STRIP: strips debug info
  242. STRIP=${TOOLPREFIX}strip
  243. EOF
  244. # define HOST_CC, HOST_LDCC, HOST_AS, HOST_LD, HOST_AR, HOST_RANLIB,
  245. # HOST_NM, HOST_SIZE, HOST_STRIP, the tools for building programs
  246. # that run on the host system.
  247. cat <<EOF
  248. # compiler for host system
  249. HOST_CC=${HOST_CC}
  250. # compiler for host system, when linking
  251. HOST_LDCC=${HOST_CC}
  252. # assembler for host system
  253. HOST_AS=as
  254. # linker for host system
  255. HOST_LD=ld
  256. # archiver (librarian) for host system
  257. HOST_AR=ar
  258. # ranlib (library postprocessor) for host system... or "true" to skip it
  259. HOST_RANLIB=${HOST_RANLIB}
  260. # nm for host system
  261. HOST_NM=nm
  262. # size for host system
  263. HOST_SIZE=size
  264. # strip for host system
  265. HOST_STRIP=strip
  266. EOF
  267. # Define compiler and linker flags we're going to use based on the
  268. # requests above.
  269. # This keeps the shell from interpreting the $() inside the here-document.
  270. HINC='-I$(OSTREE)/hostinclude'
  271. cat <<EOF
  272. # The HOST_... versions are for compiling/linking for the host system.
  273. # The K... versions are for the kernel build.
  274. # Compile flags.
  275. # The kernel has its own debug/optimize setting in the kernel config, so
  276. # we don't include ours.
  277. CFLAGS+=${WARNINGS} ${OPTFLAGS}
  278. KCFLAGS+=${WARNINGS}
  279. HOST_CFLAGS+=${WARNINGS} ${OPTFLAGS} ${HINC}
  280. # Linker flags
  281. LDFLAGS+=
  282. KLDFLAGS+=
  283. HOST_LDFLAGS+=
  284. # Libraries
  285. #
  286. LIBS+=
  287. HOST_LIBS+=
  288. EOF
  289. # Config information for the hostcompat library
  290. cat <<EOF
  291. # These are cflags used to conditionally compile src/lib/hostcompat.
  292. COMPAT_CFLAGS=${COMPAT_CFLAGS}
  293. # These are make targets that we conditionally enable when installing
  294. # in src/lib/hostcompat.
  295. COMPAT_TARGETS=${COMPAT_TARGETS}
  296. EOF
  297. # Define additional flags for making the toolchain do what we want.
  298. cat <<EOF
  299. # When we compile OS/161 programs, we want to use the OS/161 header files
  300. # and libraries. By default, gcc will look in some include directory and
  301. # some lib directory that it was told to use when it was compiled. We
  302. # assume that directory isn't ours. (If it is, all these variables can
  303. # be set to empty, but everything will still work if you don't.)
  304. EOF
  305. echo 'TREE_CFLAGS=-nostdinc -I$(OSTREE)/include'
  306. echo 'TREE_LDFLAGS=-nostdlib -L$(OSTREE)/lib $(OSTREE)/lib/crt0.o'
  307. echo 'TREE_LIBS=-lc'
  308. ) > defs.mk