comparison src/compiler.sml @ 432:5de838fb0950

Avoid using libpq when unneeded
author Adam Chlipala <adamc@hcoop.net>
date Sun, 26 Oct 2008 08:41:17 -0400
parents 777317e8b2ae
children f7b25375c0cf
comparison
equal deleted inserted replaced
431:24d22b843729 432:5de838fb0950
504 print = CjrPrint.p_sql CjrEnv.empty 504 print = CjrPrint.p_sql CjrEnv.empty
505 } 505 }
506 506
507 val toSqlify = transform sqlify "sqlify" o toMono_opt2 507 val toSqlify = transform sqlify "sqlify" o toMono_opt2
508 508
509 fun compileC {cname, oname, ename} = 509 fun compileC {cname, oname, ename, libs} =
510 let 510 let
511 val urweb_o = clibFile "urweb.o" 511 val urweb_o = clibFile "urweb.o"
512 val driver_o = clibFile "driver.o" 512 val driver_o = clibFile "driver.o"
513 513
514 val compile = "gcc -Wstrict-prototypes -Werror -O3 -I include -c " ^ cname ^ " -o " ^ oname 514 val compile = "gcc -Wstrict-prototypes -Werror -O3 -I include -c " ^ cname ^ " -o " ^ oname
515 val link = "gcc -Werror -O3 -lm -pthread -lpq " ^ urweb_o ^ " " ^ oname ^ " " ^ driver_o ^ " -o " ^ ename 515 val link = "gcc -Werror -O3 -lm -pthread " ^ libs ^ " " ^ urweb_o ^ " " ^ oname ^ " " ^ driver_o ^ " -o " ^ ename
516 in 516 in
517 if not (OS.Process.isSuccess (OS.Process.system compile)) then 517 if not (OS.Process.isSuccess (OS.Process.system compile)) then
518 print "C compilation failed\n" 518 print "C compilation failed\n"
519 else if not (OS.Process.isSuccess (OS.Process.system link)) then 519 else if not (OS.Process.isSuccess (OS.Process.system link)) then
520 print "C linking failed\n" 520 print "C linking failed\n"
551 val ename = #exe job 551 val ename = #exe job
552 in 552 in
553 let 553 let
554 val outf = TextIO.openOut cname 554 val outf = TextIO.openOut cname
555 val s = TextIOPP.openOut {dst = outf, wid = 80} 555 val s = TextIOPP.openOut {dst = outf, wid = 80}
556
557 val hasDb = List.exists (fn (Cjr.DDatabase _, _) => true | _ => false) (#1 file)
558 val libs =
559 if hasDb then
560 "-lpq"
561 else
562 ""
556 in 563 in
557 Print.fprint s (CjrPrint.p_file CjrEnv.empty file); 564 Print.fprint s (CjrPrint.p_file CjrEnv.empty file);
558 TextIO.output1 (outf, #"\n"); 565 TextIO.output1 (outf, #"\n");
559 TextIO.closeOut outf; 566 TextIO.closeOut outf;
560 567
567 in 574 in
568 Print.fprint s (CjrPrint.p_sql CjrEnv.empty file); 575 Print.fprint s (CjrPrint.p_sql CjrEnv.empty file);
569 TextIO.closeOut outf 576 TextIO.closeOut outf
570 end; 577 end;
571 578
572 compileC {cname = cname, oname = oname, ename = ename}; 579 compileC {cname = cname, oname = oname, ename = ename, libs = libs};
573 580
574 cleanup () 581 cleanup ()
575 end 582 end
576 handle ex => (((cleanup ()) handle _ => ()); raise ex) 583 handle ex => (((cleanup ()) handle _ => ()); raise ex)
577 end 584 end