diff options
author | Adam Chlipala <adamc@hcoop.net> | 2008-10-26 08:41:17 -0400 |
---|---|---|
committer | Adam Chlipala <adamc@hcoop.net> | 2008-10-26 08:41:17 -0400 |
commit | 5badaf182a69fc7d67f9ae2e5a0a8e5bf7edea36 (patch) | |
tree | 063e92eebe8bb8761687451b45c15d9101af60b3 /src | |
parent | 978e1439b5b985f1483f7eb1edfc954e3f2bf1c2 (diff) |
Avoid using libpq when unneeded
Diffstat (limited to 'src')
-rw-r--r-- | src/cjr_print.sml | 15 | ||||
-rw-r--r-- | src/compiler.sig | 2 | ||||
-rw-r--r-- | src/compiler.sml | 13 |
3 files changed, 23 insertions, 7 deletions
diff --git a/src/cjr_print.sml b/src/cjr_print.sml index 26f6149e..e26293ab 100644 --- a/src/cjr_print.sml +++ b/src/cjr_print.sml @@ -1341,6 +1341,7 @@ fun p_decl env (dAll as (d, _) : decl) = string "}", newline] + | DPreparedStatements [] => box [] | DPreparedStatements ss => box [string "static void uw_db_prepare(uw_context ctx) {", newline, @@ -2182,6 +2183,8 @@ fun p_file env (ds, ps) = end) sequences, string "}"] + + val hasDb = List.exists (fn (DDatabase _, _) => true | _ => false) ds in box [string "#include <stdio.h>", newline, @@ -2191,8 +2194,11 @@ fun p_file env (ds, ps) = 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 @@ fun p_file env (ds, ps) = string "}", newline, newline, - validate, + if hasDb then + validate + else + box [], newline, if List.exists (fn (DDatabase _, _) => true | _ => false) ds then box [] diff --git a/src/compiler.sig b/src/compiler.sig index f0914d0f..0c95934a 100644 --- a/src/compiler.sig +++ b/src/compiler.sig @@ -38,7 +38,7 @@ signature COMPILER = sig 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 diff --git a/src/compiler.sml b/src/compiler.sml index df4ee48d..5d48287b 100644 --- a/src/compiler.sml +++ b/src/compiler.sml @@ -506,13 +506,13 @@ val sqlify = { 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 @@ fun compile job = 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 @@ fun compile job = TextIO.closeOut outf end; - compileC {cname = cname, oname = oname, ename = ename}; + compileC {cname = cname, oname = oname, ename = ename, libs = libs}; cleanup () end |