preprocess .li and .c in one pass.
authorPierre Habouzit <madcoder@debian.org>
Thu, 24 May 2007 21:54:13 +0000 (23:54 +0200)
committerPierre Habouzit <madcoder@debian.org>
Thu, 24 May 2007 21:54:13 +0000 (23:54 +0200)
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
cmake/Cpkg2c.cmake
tools/cpkg2c.mll

index ad01413..23d6d58 100644 (file)
@@ -9,16 +9,10 @@ macro (MADMUTT_SOURCES _result _gen)
         set(_c  ${CMAKE_CURRENT_SOURCE_DIR}/${_basename}.c)
         if (_ext STREQUAL ".cpkg")
             add_custom_command(
-                OUTPUT ${_li}
+                OUTPUT ${_li} ${_c}
                 MAIN_DEPENDENCY ${_abs}
-                COMMAND ${madmutt_SOURCE_DIR}/tools/cpkg2c -h ${_abs} -o ${_li}
-                COMMENT "Generating ${_li} from ${_abs}"
-            )
-            add_custom_command(
-                OUTPUT ${_c}
-                MAIN_DEPENDENCY ${_abs}
-                COMMAND ${madmutt_SOURCE_DIR}/tools/cpkg2c -c ${_abs} -o ${_c}
-                COMMENT "Generating ${_c} from ${_abs}"
+                COMMAND ${madmutt_SOURCE_DIR}/tools/cpkg2c ${_abs} ${_li} ${_c}
+                COMMENT "Preprocessing ${_abs}"
             )
             list(APPEND ${_result} ${_li} ${_c})
             list(APPEND ${_gen} ${_li} ${_c})
index 129004b..0abfe8b 100644 (file)
@@ -621,22 +621,21 @@ int luaopen_%s(lua_State *L)
 (* }}} *)
 
   let usage () =
-    output_string stderr "usage: cpkg2c (-h | -c) file.cpkg -o output\n";
+    output_string stderr "usage: cpkg2c file.cpkg header.out source.out\n";
     exit 1
 
+  let warn ob = output_endline ob "/*** THIS FILE IS AUTOGENERATED !!! ***/"
+
+  let process fn file l =
+    try Unix.unlink file with _ -> ();
+    let ob = open_out_gen  [ Open_trunc ; Open_wronly; Open_creat ] 0o444 file in
+    warn ob; fn ob l; close_out ob
+
   let _ =
-    let warn ob = output_endline ob "/*** THIS FILE IS AUTOGENERATED !!! ***/" in
-    if Array.length Sys.argv != 5 then usage();
-    let file   = Sys.argv.(2) in
+    if Array.length Sys.argv != 4 then usage();
+    let file   = Sys.argv.(1) in
     let lexbuf = L.from_channel (open_in file) in
     let l      = (startchunk cLine file lexbuf) in
-    if Sys.argv.(3) = "-o" then (
-      try Unix.unlink Sys.argv.(4) with _ -> ();
-      let ob = open_out_gen [ Open_trunc ; Open_wronly; Open_creat ] 0o444 Sys.argv.(4) in
-      match Sys.argv.(1) with
-      | "-h" -> warn ob; do_h ob l; close_out ob
-      | "-c" -> warn ob; do_c ob l; close_out ob
-      | _    -> usage ()
-    ) else
-      usage();
+    process do_h Sys.argv.(2) l;
+    process do_c Sys.argv.(3) l
 }