changeset 432:5de838fb0950

Avoid using libpq when unneeded
author Adam Chlipala <adamc@hcoop.net>
date Sun, 26 Oct 2008 08:41:17 -0400
parents 24d22b843729
children 659c17441250
files src/cjr_print.sml src/compiler.sig src/compiler.sml
diffstat 3 files changed, 23 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/cjr_print.sml	Sat Oct 25 18:58:45 2008 -0400
+++ b/src/cjr_print.sml	Sun Oct 26 08:41:17 2008 -0400
@@ -1341,6 +1341,7 @@
                             string "}",
                             newline]
 
+      | DPreparedStatements [] => box []
       | DPreparedStatements ss =>
         box [string "static void uw_db_prepare(uw_context ctx) {",
              newline,
@@ -2182,6 +2183,8 @@
                                 end) sequences,
 
                  string "}"]
+
+        val hasDb = List.exists (fn (DDatabase _, _) => true | _ => false) ds
     in
         box [string "#include <stdio.h>",
              newline,
@@ -2191,8 +2194,11 @@
              newline,
              string "#include <math.h>",
              newline,
-             string "#include <postgresql/libpq-fe.h>",
-             newline,
+             if hasDb then
+                 box [string "#include <postgresql/libpq-fe.h>",
+                      newline]
+             else
+                 box [],
              newline,
              string "#include \"",
              string (OS.Path.joinDirFile {dir = Config.includ,
@@ -2222,7 +2228,10 @@
              string "}",
              newline,
              newline,
-             validate,
+             if hasDb then
+                 validate
+             else
+                 box [],
              newline,
              if List.exists (fn (DDatabase _, _) => true | _ => false) ds then
                  box []
--- a/src/compiler.sig	Sat Oct 25 18:58:45 2008 -0400
+++ b/src/compiler.sig	Sun Oct 26 08:41:17 2008 -0400
@@ -38,7 +38,7 @@
          debug : bool
     }
     val compile : string -> unit
-    val compileC : {cname : string, oname : string, ename : string} -> unit
+    val compileC : {cname : string, oname : string, ename : string, libs : string} -> unit
 
     type ('src, 'dst) phase
     type ('src, 'dst) transform
--- a/src/compiler.sml	Sat Oct 25 18:58:45 2008 -0400
+++ b/src/compiler.sml	Sun Oct 26 08:41:17 2008 -0400
@@ -506,13 +506,13 @@
 
 val toSqlify = transform sqlify "sqlify" o toMono_opt2
 
-fun compileC {cname, oname, ename} =
+fun compileC {cname, oname, ename, libs} =
     let
         val urweb_o = clibFile "urweb.o"
         val driver_o = clibFile "driver.o"
 
         val compile = "gcc -Wstrict-prototypes -Werror -O3 -I include -c " ^ cname ^ " -o " ^ oname
-        val link = "gcc -Werror -O3 -lm -pthread -lpq " ^ urweb_o ^ " " ^ oname ^ " " ^ driver_o ^ " -o " ^ ename
+        val link = "gcc -Werror -O3 -lm -pthread " ^ libs ^ " " ^ urweb_o ^ " " ^ oname ^ " " ^ driver_o ^ " -o " ^ ename
     in
         if not (OS.Process.isSuccess (OS.Process.system compile)) then
             print "C compilation failed\n"
@@ -553,6 +553,13 @@
             let
                 val outf = TextIO.openOut cname
                 val s = TextIOPP.openOut {dst = outf, wid = 80}
+
+                val hasDb = List.exists (fn (Cjr.DDatabase _, _) => true | _ => false) (#1 file)
+                val libs =
+                    if hasDb then
+                        "-lpq"
+                    else
+                        ""
             in
                 Print.fprint s (CjrPrint.p_file CjrEnv.empty file);
 		TextIO.output1 (outf, #"\n");
@@ -569,7 +576,7 @@
                         TextIO.closeOut outf
                     end;
 
-                compileC {cname = cname, oname = oname, ename = ename};
+                compileC {cname = cname, oname = oname, ename = ename, libs = libs};
                 
                 cleanup ()
             end