Mercurial > urweb
comparison src/compiler.sml @ 1739:c414850f206f
Add support for -boot flag, which allows in-tree execution of Ur/Web
The boot flag rewrites most hardcoded paths to point to the build
directory, and also forces static compilation. This is convenient
for developing Ur/Web, or if you cannot 'sudo make install' Ur/Web.
The following changes were made:
* Header files were moved to include/urweb instead of include;
this lets FFI users point their C_INCLUDE_PATH at this directory
at write <urweb/urweb.h>. For internal Ur/Web executables,
we simply pass -I$PATH/include/urweb as normal.
* Differentiate between LIB and SRCLIB; SRCLIB is Ur and JavaScript
source files, while LIB is compiled products from libtool. For
in-tree compilation these live in different places.
* No longer reference Config for paths; instead use Settings; these
settings can be changed dynamically by Compiler.enableBoot ()
(TODO: add a disableBoot function.)
* config.h is now generated directly in include/urweb/config.h,
for consistency's sake (especially since it gets installed
along with the rest of the headers!)
* All of the autotools build products got updated.
* The linkStatic field in protocols now only contains the name of the
build product, and not the absolute path.
Future users have to be careful not to reference the Settings files
to early, lest they get an old version (this was the source of two
bugs during development of this patch.)
author | Edward Z. Yang <ezyang@mit.edu> |
---|---|
date | Wed, 02 May 2012 17:17:57 -0400 |
parents | 1a35e75b6967 |
children | 1e940643a5f0 |
comparison
equal
deleted
inserted
replaced
1738:1a35e75b6967 | 1739:c414850f206f |
---|---|
324 structure M = BinaryMapFn(struct | 324 structure M = BinaryMapFn(struct |
325 type ord_key = string | 325 type ord_key = string |
326 val compare = String.compare | 326 val compare = String.compare |
327 end) | 327 end) |
328 | 328 |
329 val pathmap = ref (M.insert (M.empty, "", Config.libUr)) | 329 (* XXX ezyang: pathmap gets initialized /really early/, before |
330 * we do any options parsing. So libUr will always point to the | |
331 * default. We override it explicitly in enableBoot *) | |
332 val pathmap = ref (M.insert (M.empty, "", Settings.libUr ())) | |
330 | 333 |
331 fun addPath (k, v) = pathmap := M.insert (!pathmap, k, v) | 334 fun addPath (k, v) = pathmap := M.insert (!pathmap, k, v) |
335 | |
336 (* XXX ezyang: this is not right; it probably doesn't work in | |
337 * the case of separate build and src trees *) | |
338 fun enableBoot () = | |
339 (Settings.configBin := OS.Path.joinDirFile {dir = Config.builddir, file = "bin"}; | |
340 Settings.configSrcLib := OS.Path.joinDirFile {dir = Config.builddir, file = "lib"}; | |
341 (* joinDirFile is annoying... (ArcError; it doesn't like | |
342 * slashes in file) *) | |
343 Settings.configLib := Config.builddir ^ "/src/c/.libs"; | |
344 Settings.configInclude := OS.Path.joinDirFile {dir = Config.builddir ^ "/include", file = "urweb"}; | |
345 Settings.configSitelisp := Config.builddir ^ "/src/elisp"; | |
346 addPath ("", Settings.libUr ())) | |
332 | 347 |
333 fun capitalize "" = "" | 348 fun capitalize "" = "" |
334 | capitalize s = str (Char.toUpper (String.sub (s, 0))) ^ String.extract (s, 1, NONE) | 349 | capitalize s = str (Char.toUpper (String.sub (s, 0))) ^ String.extract (s, 1, NONE) |
335 | 350 |
336 fun institutionalizeJob (job : job) = | 351 fun institutionalizeJob (job : job) = |
1096 print = SourcePrint.p_file | 1111 print = SourcePrint.p_file |
1097 } | 1112 } |
1098 | 1113 |
1099 val toParse = transform parse "parse" o toParseJob | 1114 val toParse = transform parse "parse" o toParseJob |
1100 | 1115 |
1101 fun libFile s = OS.Path.joinDirFile {dir = Config.libUr, | |
1102 file = s} | |
1103 fun clibFile s = OS.Path.joinDirFile {dir = Config.libC, | |
1104 file = s} | |
1105 | |
1106 val elaborate = { | 1116 val elaborate = { |
1107 func = fn file => let | 1117 func = fn file => let |
1108 val basisF = libFile "basis.urs" | 1118 val basisF = Settings.libFile "basis.urs" |
1109 val topF = libFile "top.urs" | 1119 val topF = Settings.libFile "top.urs" |
1110 val topF' = libFile "top.ur" | 1120 val topF' = Settings.libFile "top.ur" |
1111 | 1121 |
1112 val basis = #func parseUrs basisF | 1122 val basis = #func parseUrs basisF |
1113 val topSgn = #func parseUrs topF | 1123 val topSgn = #func parseUrs topF |
1114 val topStr = #func parseUr topF' | 1124 val topStr = #func parseUr topF' |
1115 | 1125 |
1387 fun compileC {cname, oname, ename, libs, profile, debug, linker, link = link'} = | 1397 fun compileC {cname, oname, ename, libs, profile, debug, linker, link = link'} = |
1388 let | 1398 let |
1389 val proto = Settings.currentProtocol () | 1399 val proto = Settings.currentProtocol () |
1390 | 1400 |
1391 val lib = if Settings.getStaticLinking () then | 1401 val lib = if Settings.getStaticLinking () then |
1392 #linkStatic proto ^ " " ^ Config.lib ^ "/../liburweb.a" | 1402 " " ^ !Settings.configLib ^ "/" ^ #linkStatic proto ^ " " ^ !Settings.configLib ^ "/liburweb.a" |
1393 else | 1403 else |
1394 "-L" ^ Config.lib ^ "/.. " ^ #linkDynamic proto ^ " -lurweb" | 1404 "-L" ^ !Settings.configLib ^ " " ^ #linkDynamic proto ^ " -lurweb" |
1395 | 1405 |
1396 val opt = if debug then | 1406 val opt = if debug then |
1397 "" | 1407 "" |
1398 else | 1408 else |
1399 " -O3" | 1409 " -O3" |
1400 | 1410 |
1401 val compile = Config.ccompiler ^ " " ^ Config.ccArgs ^ " " ^ Config.pthreadCflags ^ " -Wimplicit -Werror -Wno-unused-value" | 1411 val compile = Config.ccompiler ^ " " ^ Config.ccArgs ^ " " ^ Config.pthreadCflags ^ " -Wimplicit -Werror -Wno-unused-value" |
1402 ^ opt ^ " -I " ^ Config.includ | 1412 ^ opt ^ " -I " ^ !Settings.configInclude |
1403 ^ " " ^ #compile proto | 1413 ^ " " ^ #compile proto |
1404 ^ " -c " ^ escapeFilename cname ^ " -o " ^ escapeFilename oname | 1414 ^ " -c " ^ escapeFilename cname ^ " -o " ^ escapeFilename oname |
1405 | 1415 |
1406 val linker = Option.getOpt (linker, Config.ccompiler ^ " -Werror" ^ opt ^ " " ^ Config.ccArgs ^ " " ^ Config.pthreadCflags ^ " " ^ Config.pthreadLibs) | 1416 val linker = Option.getOpt (linker, Config.ccompiler ^ " -Werror" ^ opt ^ " " ^ Config.ccArgs ^ " " ^ Config.pthreadCflags ^ " " ^ Config.pthreadLibs) |
1407 | 1417 |