# HG changeset patch # User Adam Chlipala # Date 1225024877 14400 # Node ID 5de838fb09501200bcb33cab5683710fc5ecb6fa # Parent 24d22b843729884ffe17cc592784606a49973778 Avoid using libpq when unneeded diff -r 24d22b843729 -r 5de838fb0950 src/cjr_print.sml --- 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 ", newline, @@ -2191,8 +2194,11 @@ newline, string "#include ", newline, - string "#include ", - newline, + if hasDb then + box [string "#include ", + 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 [] diff -r 24d22b843729 -r 5de838fb0950 src/compiler.sig --- 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 diff -r 24d22b843729 -r 5de838fb0950 src/compiler.sml --- 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