os161.config.mk 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  1. #
  2. # OS/161 build environment base definitions
  3. #
  4. # Proper usage:
  5. # TOP=../.. # or however many levels needed
  6. # .include "$(TOP)/mk/os161.config.mk"
  7. #
  8. # This file takes care of including $(TOP)/defs.mk and sets defaults
  9. # for things that can be defined there.
  10. #
  11. # It and defs.mk collaboratively set various make variables that
  12. # control the build environment.
  13. #
  14. ############################################################
  15. #
  16. # These build variables are meant to be user-settable:
  17. #
  18. # (Locations.)
  19. #
  20. # OSTREE The root directory you run OS/161 in.
  21. # Default is ~/os161/root.
  22. #
  23. # WORKDIR Top of a tree to use for compiling.
  24. # Default is $(TOP)/build.
  25. #
  26. # BUILDSYMLINKS If set to "yes", symlinks in each directory
  27. # will be made to point into $(BUILDTOP).
  28. # Default is "yes".
  29. #
  30. # By default the system will be built within the source tree and
  31. # installed to ~/os161/root. It is expected this will be sufficient
  32. # for most uses. If your root directory is somewhere else, set OSTREE
  33. # in defs.mk. If you're running on a large computing cluster with
  34. # networked home directories, setting WORKDIR to point somewhere on a
  35. # local disk will probably make your builds quite a bit faster, at the
  36. # cost of having to recompile if you switch to a different machine.
  37. # If you want the source tree to be completely read-only, which is
  38. # occasionally useful for tracking down build glitches, you can set
  39. # WORKDIR and also set BUILDSYMLINKS to no.
  40. #
  41. # (Platform.)
  42. #
  43. # PLATFORM The type of system we're building for.
  44. # Should always be set by defs.mk.
  45. #
  46. # MACHINE The processor type we're building for.
  47. # Should always be set by defs.mk.
  48. #
  49. # The target machine type is set when you configure the source tree.
  50. # If you change it, be sure to make distclean and recompile everything.
  51. # Not all possible combinations of PLATFORM and MACHINE are allowed.
  52. # See the logic at the bottom of this file for a list of supported
  53. # combinations. If you are trying to port OS/161 to a new machine, the
  54. # first step is to update that list.
  55. #
  56. # (Compilation.)
  57. #
  58. # DEBUG Compiler option for debug vs. optimize.
  59. # Default: -O2
  60. #
  61. # WARNINGS Compiler options for warnings.
  62. # Default: -Wall -Wextra -Wwrite-strings
  63. # -Wmissing-prototypes
  64. #
  65. # WERROR Compiler option to make warnings fatal.
  66. # Default: -Werror
  67. #
  68. # Since debugging of user-level programs is not supported in OS/161
  69. # (and not really supportable without a lot of work on your part)
  70. # there's usually not much reason to change DEBUG. If you want to,
  71. # however, the easiest way is to usually set it on the make command
  72. # line:
  73. # make clean
  74. # make DEBUG=-g all
  75. # recompiles the current directory with debug info.
  76. #
  77. # Similarly, if you have a lot of warnings and you want to temporarily
  78. # ignore them while you fix more serious problems, you can turn off
  79. # the error-on-warning behavior on the fly by setting WERROR to empty:
  80. # make WERROR=
  81. #
  82. # This convenience is why these variables are separately defined
  83. # rather than just being rolled into CFLAGS.
  84. #
  85. ############################################################
  86. #
  87. # These build variables can be set explicitly for further control if
  88. # desired, but should in general not need attention.
  89. #
  90. # (Locations.)
  91. #
  92. # BUILDTOP Top of tree where .o files go.
  93. # Default is $(WORKDIR).
  94. #
  95. # TOOLDIR Place for compiled programs used in
  96. # the build. Default is $(WORKDIR)/tooldir.
  97. #
  98. # INSTALLTOP Staging directory for installation.
  99. # Default is $(WORKDIR)/install
  100. #
  101. # Probably the only reason to change these would be if you're short on
  102. # diskspace in $(WORKDIR).
  103. #
  104. # (Platform.)
  105. #
  106. # GNUTARGET The GNU gcc/binutils name for the
  107. # target we're building for.
  108. # Defaults to $(MACHINE)-harvard-os161.
  109. #
  110. # This should not need to be changed.
  111. #
  112. # (Programs.)
  113. #
  114. # CC (Cross-)compiler.
  115. # Default is $(GNUTARGET)-gcc.
  116. #
  117. # LDCC (Cross-)compiler when invoked for linking.
  118. # Default is $(CC).
  119. #
  120. # AS (Cross-)assembler.
  121. # Default is $(GNUTARGET)-as.
  122. #
  123. # LD (Cross-)linker.
  124. # Default is $(GNUTARGET)-ld.
  125. #
  126. # AR Archiver (librarian).
  127. # Default is $(GNUTARGET)-ar.
  128. #
  129. # RANLIB Library postprocessor/indexer.
  130. # Default is $(GNUTARGET)-ranlib.
  131. #
  132. # NM Tool to print symbol tables.
  133. # Default is $(GNUTARGET)-nm.
  134. #
  135. # SIZE Tool to print sizes of binaries.
  136. # Default is $(GNUTARGET)-size.
  137. #
  138. # STRIP Tool to remove debugging information.
  139. # Default is $(GNUTARGET)-strip.
  140. #
  141. # The above are the compilation tools for OS/161. They create programs
  142. # that run on OS/161. Since OS/161 is not meant to be self-hosting,
  143. # programs that we need to run during the build, or run manually
  144. # outside of the machine simulator, need to be compiled with a
  145. # different compiler that creates programs that run for the "host" OS,
  146. # whatever that is (Linux, NetBSD, FreeBSD, MacOS X, Solaris, etc.)
  147. # The host compilation tools are prefixed with HOST_ as follows:
  148. #
  149. #
  150. # HOST_CC Host compiler.
  151. # Default is gcc.
  152. #
  153. # HOST_LDCC Host compiler when invoked for linking.
  154. # Default is $(HOST_CC).
  155. #
  156. # HOST_AS Host assembler.
  157. # Default is as.
  158. #
  159. # HOST_LD Host linker.
  160. # Default is ld.
  161. #
  162. # HOST_AR Host archiver (librarian).
  163. # Default is ar.
  164. #
  165. # HOST_RANLIB Host library postprocessor/indexer.
  166. # Default is ranlib.
  167. #
  168. # HOST_NM Host tool to print symbol tables.
  169. # Default is nm.
  170. #
  171. # HOST_SIZE Host tool to print sizes of binaries.
  172. # Default is size.
  173. #
  174. # HOST_STRIP Host tool to remove debugging information.
  175. # Default is strip.
  176. #
  177. # In general there should be no need to change the cross-compiler
  178. # variables, unless you are e.g. trying to build OS/161 with something
  179. # other than gcc, or you want to supply an explicit location for a
  180. # specific copy of gcc somewhere rather than use the one on your
  181. # $PATH.
  182. #
  183. # However, on some systems it might conceivably be necessary to change
  184. # the host tool variables. For example, there are some (now extremely
  185. # old) systems where "ranlib" is not only not needed but also corrupts
  186. # libraries, in which case you might set HOST_RANLIB=true. If your
  187. # host machine doesn't have "gcc" you may be able to set HOST_CC=cc
  188. # and fiddle with HOST_WARNINGS and HOST_CFLAGS (below) and have
  189. # things still more or less work.
  190. #
  191. # (Compilation.)
  192. #
  193. # HOST_DEBUG Like DEBUG, but for programs to be
  194. # built to run on the host OS.
  195. # Default is $(DEBUG).
  196. #
  197. # HOST_WARNINGS Like WARNINGS, but for programs to be
  198. # built to run on the host OS.
  199. # Default is $(WARNINGS).
  200. #
  201. # HOST_WERROR Like WERROR, but for programs to be
  202. # built to run on the host OS.
  203. # Default is $(WERROR).
  204. #
  205. ############################################################
  206. #
  207. # These build variables should probably not be tinkered with in
  208. # defs.mk and serve as baseline values to be added to by individual
  209. # program makefiles and used by other os161.*.mk files.
  210. #
  211. # (Compilation.)
  212. #
  213. # CFLAGS Full baseline compile flags.
  214. # Default is $(DEBUG) $(WARNINGS) $(WERROR),
  215. # plus what's needed for -nostdinc.
  216. #
  217. # KCFLAGS Like CFLAGS, but for the kernel, which
  218. # configures debug/optimize separately.
  219. # Default is $(KDEBUG) $(WARNINGS) $(WERROR).
  220. # (KDEBUG is set by the kernel config script.)
  221. #
  222. # HOST_CFLAGS Like CFLAGS, but for programs to be
  223. # built to run on the host OS. Default is
  224. # $(HOST_DEBUG) $(HOST_WARNINGS) $(HOST_WERROR).
  225. #
  226. # LDFLAGS Baseline link-time flags.
  227. # Default is empty plus what's needed for
  228. # -nostdlib.
  229. #
  230. # KLDFLAGS Baseline link-time flags for kernel.
  231. # Default is empty.
  232. #
  233. # HOST_LDFLAGS Like LDFLAGS, but for programs to be
  234. # built to run on the host OS.
  235. # Default is empty.
  236. #
  237. # LIBS Baseline list of libraries to link to.
  238. # Default is empty plus what's needed for
  239. # -nostdlib.
  240. #
  241. # HOST_LIBS Like LIBS, but for programs to be
  242. # built to run on the host OS.
  243. # Default is empty.
  244. #
  245. ############################################################
  246. #
  247. # These variables should not be changed directly, or by individual
  248. # program makefiles either, and are for use by other os161.*.mk files.
  249. #
  250. # (Locations.)
  251. #
  252. # MYDIR Name of current source directory, relative
  253. # to $(TOP); e.g. bin/sh.
  254. #
  255. # MYBUILDDIR Build directory for current source directory.
  256. #
  257. # MKDIRS Directories to create, mostly for installing.
  258. #
  259. # ABSTOP_PATTERN, ABSTOP Private, used to compute other locations.
  260. #
  261. # (Compilation.)
  262. #
  263. # MORECFLAGS Same as CFLAGS but comes later on the
  264. # compile command line. In general individual
  265. # makefiles shouldn't touch this.
  266. # Default is empty plus what's needed for
  267. # -nostdinc.
  268. #
  269. # MORELIBS Same as LIBS but comes after on the link
  270. # line. In general individual makefiles
  271. # shouldn't touch this.
  272. # Default is empty plus what's needed for
  273. # -nostdlib.
  274. #
  275. ############################################################
  276. # Some further vars that currently exist but should be moved
  277. # around elsewhere:
  278. #
  279. # COMPAT_CFLAGS
  280. # COMPAT_TARGETS
  281. ############################################################
  282. # Establish defaults.
  283. # (Variables are set in the order documented above.)
  284. #
  285. # These definitions are set firmly here (that is, not with ?=) because
  286. # some of them, like CC, are predefined by make. Because defs.mk is
  287. # included afterwards it can override any of these settings.
  288. #
  289. #
  290. # User-settable configuration
  291. #
  292. # Locations of things.
  293. OSTREE=$(HOME)/os161/root # Root directory to install into.
  294. WORKDIR=$(TOP)/build # Top of tree to build into.
  295. BUILDSYMLINKS=yes # yes => link build -> $(BUILDTOP)/$(HERE).
  296. # Platform we're building for.
  297. PLATFORM=sys161
  298. MACHINE=mips
  299. # Compilation
  300. DEBUG=-O2
  301. WARNINGS=-Wall -W -Wwrite-strings -Wmissing-prototypes
  302. WERROR=-Werror
  303. #
  304. # Less-likely-to-need-setting
  305. #
  306. # Locations of things.
  307. BUILDTOP=$(WORKDIR) # Top of directory for compiler output.
  308. TOOLDIR=$(WORKDIR)/tooldir # Place for host progs used in the build.
  309. INSTALLTOP=$(WORKDIR)/install # Staging area for installation.
  310. # Platform.
  311. GNUTARGET=$(MACHINE)-harvard-os161
  312. # Programs and tools.
  313. CC=$(GNUTARGET)-gcc # Compiler.
  314. LDCC=$(CC) # Compiler when used for linking.
  315. AS=$(GNUTARGET)-as # Assembler.
  316. LD=$(GNUTARGET)-ld # Linker.
  317. AR=$(GNUTARGET)-ar # Archiver.
  318. RANLIB=$(GNUTARGET)-ranlib # Library indexer.
  319. NM=$(GNUTARGET)-nm # Symbol dumper.
  320. SIZE=$(GNUTARGET)-size # Size tool.
  321. STRIP=$(GNUTARGET)-strip # Debug strip tool.
  322. HOST_CC=gcc # Host compiler.
  323. HOST_LDCC=$(HOST_CC) # Host compiler when used for linking.
  324. HOST_AS=as # Host assembler.
  325. HOST_LD=ld # Host linker.
  326. HOST_AR=ar # Host archiver.
  327. HOST_RANLIB=ranlib # Host library indexer.
  328. HOST_NM=nm # Host symbol dumper.
  329. HOST_SIZE=size # Host size tool.
  330. HOST_STRIP=strip # Host debug strip tool.
  331. # Compilation.
  332. HOST_DEBUG=$(DEBUG)
  333. HOST_WARNINGS=$(WARNINGS)
  334. HOST_WERROR=$(WERROR)
  335. #
  336. # Probably-shouldn't-be-touched
  337. #
  338. CFLAGS=$(DEBUG) $(WARNINGS) $(WERROR) -std=gnu99
  339. KCFLAGS=$(KDEBUG) $(WARNINGS) $(WERROR) -std=gnu99
  340. HOST_CFLAGS=$(HOST_DEBUG) $(HOST_WARNINGS) $(HOST_WERROR) \
  341. -I$(INSTALLTOP)/hostinclude
  342. LDFLAGS=
  343. KLDFLAGS=
  344. HOST_LDFLAGS=
  345. LIBS=
  346. HOST_LIBS=
  347. #
  348. # Don't touch.
  349. #
  350. MORECFLAGS=
  351. MORELIBS=
  352. # lib/hostcompat.
  353. COMPAT_CFLAGS=
  354. COMPAT_TARGETS=
  355. ############################################################
  356. # Get defs.mk to get the real configuration for this tree.
  357. # If it doesn't exist, we'll go with the defaults.
  358. .-include "$(TOP)/defs.mk"
  359. # UW Mod
  360. # This needs to come after the above include.
  361. .if defined(TOOLPREFIX)
  362. CC=$(TOOLPREFIX)gcc # Compiler.
  363. LDCC=$(CC) # Compiler when used for linking.
  364. AS=$(TOOLPREFIX)as # Assembler.
  365. LD=$(TOOLPREFIX)ld # Linker.
  366. AR=$(TOOLPREFIX)ar # Archiver.
  367. RANLIB=$(TOOLPREFIX)ranlib # Library indexer.
  368. NM=$(TOOLPREFIX)nm # Symbol dumper.
  369. SIZE=$(TOOLPREFIX)size # Size tool.
  370. STRIP=$(TOOLPREFIX)strip # Debug strip tool.
  371. .endif
  372. ############################################################
  373. # Make sure we have a supported PLATFORM and MACHINE.
  374. # We support mips on system/161.
  375. SUPPORTED_TARGETS=sys161 mips
  376. _OK_=0
  377. .for _P_ _M_ in $(SUPPORTED_TARGETS)
  378. .if "$(PLATFORM)" == "$(_P_)" && "$(MACHINE)" == "$(_M_)"
  379. _OK_=1
  380. .endif
  381. .endfor
  382. .if "$(_OK_)" != "1"
  383. .init:
  384. @echo "Platform $(PLATFORM) and machine $(MACHINE) not supported"
  385. @false
  386. .endif
  387. ############################################################
  388. # Get any machine-dependent flags or makefile definitions
  389. .-include "$(TOP)/mk/os161.config-$(MACHINE).mk"
  390. ############################################################
  391. # Establish some derived locations.
  392. #
  393. # Absolute location of the top of the source tree. This should only be
  394. # used to un-absolutize other paths; the tree ought to be independent
  395. # of where it happens to live.
  396. #
  397. # This works by turning $(TOP) into a regexp and substituting it into
  398. # the current directory. Note that it doesn't escape all regexp
  399. # metacharacters -- if you make a directory named "foo*bar" or
  400. # something you deserve the consequences.
  401. #
  402. # .CURDIR is a make builtin.
  403. #
  404. ABSTOP_PATTERN=$(TOP:S/./\\./g:S/\\.\\./[^\/]*/g)
  405. ABSTOP=$(.CURDIR:C/$(ABSTOP_PATTERN)\$//)
  406. # Find the name of the current directory relative to TOP.
  407. # This works by removing ABSTOP from the front of .CURDIR.
  408. MYDIR=$(.CURDIR:S/^$(ABSTOP)//)
  409. # Find the build directory corresponding to the current source dir.
  410. .if "$(MYDIR)" == ""
  411. # avoid stray slash
  412. MYBUILDDIR=$(BUILDTOP)
  413. .else
  414. MYBUILDDIR=$(BUILDTOP)/$(MYDIR)
  415. .endif
  416. ############################################################
  417. # Ensure we compile a consistent tree.
  418. #
  419. # Traditionally in Unix the first step of recompiling the system is to
  420. # install new header files. Furthermore, the second step is to compile
  421. # and install new libraries, before continuing on to the rest of the
  422. # OS, which can then be compiled with those new headers and new
  423. # libraries.
  424. #
  425. # Combining the compile and install phases like this is simpler and
  426. # uses less disk space on extra copies of things (which mattered, back
  427. # in the day) but has a number of problems. Chief among these is that
  428. # if the build bombs out halfway through you end up with a partly
  429. # updated and maybe broken system. It also means that once you start
  430. # recompiling the system you can't easily back out. And the behavior
  431. # violates the principle of least surprise.
  432. #
  433. # OS/161 1.x had, intentionally, a very traditional build environment.
  434. # In OS/161 2.x, however, we use a staging area to avoid mixing build
  435. # and install. This means that we must compile only against the
  436. # staging area, $(INSTALLTOP), and never use the headers or libraries
  437. # installed in $(OSTREE) until install time.
  438. #
  439. # This means that regardless of whether we have a gcc configured so it
  440. # includes from our $(OSTREE) by default or not, we must use -nostdinc
  441. # and -nostdlib and explicitly link with materials from $(INSTALLTOP).
  442. #
  443. # Use MORECFLAGS and MORELIBS, which are supported by os161.compile.mk
  444. # for this purpose, so the include paths and library list come out in
  445. # the right order.
  446. #
  447. CFLAGS+=-nostdinc
  448. MORECFLAGS+=-I$(INSTALLTOP)/include
  449. LDFLAGS+=-nostdlib -L$(INSTALLTOP)/lib $(INSTALLTOP)/lib/crt0.o
  450. MORELIBS+=-lc
  451. LIBDEPS+=$(INSTALLTOP)/lib/crt0.o $(INSTALLTOP)/lib/libc.a
  452. ############################################################
  453. # end.