changeset 1725:7b9775d4a8ce

'linker' .urp directive
author Adam Chlipala <adam@chlipala.net>
date Sun, 22 Apr 2012 10:57:22 -0400
parents 125f9b01fbf1
children 4df4521fbd3b
files doc/manual.tex src/compiler.sig src/compiler.sml src/demo.sml tests/linker.ur tests/linker.urp
diffstat 6 files changed, 20 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/doc/manual.tex	Sun Apr 22 09:18:21 2012 -0400
+++ b/doc/manual.tex	Sun Apr 22 10:57:22 2012 -0400
@@ -164,6 +164,7 @@
   \item \texttt{transactionals}: maximum number of custom transactional actions (e.g., sending an e-mail) that may be run in a single page generation
   \end{itemize}
 \item \texttt{link FILENAME} adds \texttt{FILENAME} to the list of files to be passed to the linker at the end of compilation.  This is most useful for importing extra libraries needed by new FFI modules.
+\item \texttt{linker CMD} sets \texttt{CMD} as the command line prefix to use for linking C object files.  The command line will be completed with a space-separated list of \texttt{.o} and \texttt{.a} files, \texttt{-L} and \texttt{-l} flags, and finally with a \texttt{-o} flag to set the location where the executable should be written.
 \item \texttt{minHeap NUMBYTES} sets the initial size for thread-local heaps used in handling requests.  These heaps grow automatically as needed (up to any maximum set with \texttt{limit}), but each regrow requires restarting the request handling process.
 \item \texttt{noXsrfProtection URIPREFIX} turns off automatic cross-site request forgery protection for the page handler identified by the given URI prefix.  This will avoid checking cryptographic signatures on cookies, which is generally a reasonable idea for some pages, such as login pages that are going to discard all old cookie values, anyway.
 \item \texttt{onError Module.var} changes the handling of fatal application errors.  Instead of displaying a default, ugly error 500 page, the error page will be generated by calling function \texttt{Module.var} on a piece of XML representing the error message.  The error handler should have type $\mt{xbody} \to \mt{transaction} \; \mt{page}$.  Note that the error handler \emph{cannot} be in the application's main module, since that would register it as explicitly callable via URLs.
--- a/src/compiler.sig	Sun Apr 22 09:18:21 2012 -0400
+++ b/src/compiler.sig	Sun Apr 22 10:57:22 2012 -0400
@@ -40,6 +40,7 @@
          timeout : int,
          ffi : string list,
          link : string list,
+         linker : string option,
          headers : string list,
          scripts : string list,
          clientToServer : Settings.ffi list,
@@ -63,7 +64,7 @@
     val compile : string -> bool
     val compiler : string -> unit
     val compileC : {cname : string, oname : string, ename : string, libs : string,
-                    profile : bool, debug : bool, link : string list} -> bool
+                    profile : bool, debug : bool, linker : string option, link : string list} -> bool
 
     val beforeC : (unit -> unit) ref
     (* This function is called before beginning C compilation.
--- a/src/compiler.sml	Sun Apr 22 09:18:21 2012 -0400
+++ b/src/compiler.sml	Sun Apr 22 10:57:22 2012 -0400
@@ -44,6 +44,7 @@
      timeout : int,
      ffi : string list,
      link : string list,
+     linker : string option,
      headers : string list,
      scripts : string list,
      clientToServer : Settings.ffi list,
@@ -399,6 +400,7 @@
                        timeout = 60,
                        ffi = [],
                        link = [],
+                       linker = NONE,
                        headers = [],
                        scripts = [],
                        clientToServer = [],
@@ -518,6 +520,7 @@
                     val timeout = ref NONE
                     val ffi = ref []
                     val link = ref []
+                    val linker = ref NONE
                     val headers = ref []
                     val scripts = ref []
                     val clientToServer = ref []
@@ -552,6 +555,7 @@
                                 timeout = Option.getOpt (!timeout, 60),
                                 ffi = rev (!ffi),
                                 link = rev (!link),
+                                linker = !linker,
                                 headers = rev (!headers),
                                 scripts = rev (!scripts),
                                 clientToServer = rev (!clientToServer),
@@ -607,6 +611,7 @@
                                 timeout = #timeout old,
                                 ffi = #ffi old @ #ffi new,
                                 link = #link old @ #link new,
+                                linker = mergeO (fn (_, new) => new) (#linker old, #linker new),
                                 headers = #headers old @ #headers new,
                                 scripts = #scripts old @ #scripts new,
                                 clientToServer = #clientToServer old @ #clientToServer new,
@@ -742,6 +747,7 @@
                                     in
                                         link := arg :: !link
                                     end
+                                  | "linker" => linker := SOME arg
                                   | "include" => headers := relifyA arg :: !headers
                                   | "script" => scripts := arg :: !scripts
                                   | "clientToServer" => clientToServer := ffiS () :: !clientToServer
@@ -1356,7 +1362,7 @@
 
 val beforeC = ref (fn () => ())
 
-fun compileC {cname, oname, ename, libs, profile, debug, link = link'} =
+fun compileC {cname, oname, ename, libs, profile, debug, linker, link = link'} =
     let
         val proto = Settings.currentProtocol ()
 
@@ -1375,7 +1381,9 @@
                       ^ " " ^ #compile proto
                       ^ " -c " ^ escapeFilename cname ^ " -o " ^ escapeFilename oname
 
-        val link = Config.ccompiler ^ " -Werror" ^ opt ^ " " ^ Config.ccArgs ^ " " ^ Config.pthreadCflags ^ " " ^ Config.pthreadLibs
+        val linker = Option.getOpt (linker, Config.ccompiler ^ " -Werror" ^ opt ^ " " ^ Config.ccArgs ^ " " ^ Config.pthreadCflags ^ " " ^ Config.pthreadLibs)
+
+        val link = linker
                    ^ " " ^ lib ^ " " ^ escapeFilename oname ^ " " ^ libs ^ " -lm " ^ Config.openssl ^ " -o " ^ escapeFilename ename
 
         val (compile, link) =
@@ -1462,7 +1470,7 @@
                          end;
 
                      compileC {cname = cname, oname = oname, ename = ename, libs = libs,
-                               profile = #profile job, debug = #debug job, link = #link job}
+                               profile = #profile job, debug = #debug job, linker = #linker job, link = #link job}
                      
                      before cleanup ())
             end
--- a/src/demo.sml	Sun Apr 22 09:18:21 2012 -0400
+++ b/src/demo.sml	Sun Apr 22 10:57:22 2012 -0400
@@ -103,6 +103,7 @@
             profile = false,
             ffi = [],
             link = [],
+            linker = NONE,
             headers = [],
             scripts = [],
             clientToServer = [],
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/linker.ur	Sun Apr 22 10:57:22 2012 -0400
@@ -0,0 +1,1 @@
+fun main () : transaction page = return <xml/>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/linker.urp	Sun Apr 22 10:57:22 2012 -0400
@@ -0,0 +1,4 @@
+debug
+linker ld -g
+
+linker