Browse Source

added hlc.json generation (instead of Makefile)

Nicolas Cannasse 8 years ago
parent
commit
f291e7ce58
2 changed files with 12 additions and 6 deletions
  1. 1 1
      src/generators/genhl.ml
  2. 11 5
      src/generators/hl2c.ml

+ 1 - 1
src/generators/genhl.ml

@@ -3649,7 +3649,7 @@ let generate com =
 	end;
 	let t = Common.timer ["write";"hl"] in
 	if file_extension com.file = "c" then
-		Hl2c.write_c com.Common.version com.file code
+		Hl2c.write_c com com.file code
 	else begin
 		let ch = IO.output_string() in
 		write_code ch code true;

+ 11 - 5
src/generators/hl2c.ml

@@ -242,7 +242,7 @@ let open_file ctx file =
 	let version_major = ctx.version / 1000 in
 	let version_minor = (ctx.version mod 1000) / 100 in
 	let version_revision = (ctx.version mod 100) in
-	line ctx (sprintf "%s Generated by HLC %d.%d.%d (HL v%d)" (if file = "Makefile" then "#" else "//") version_major version_minor version_revision ctx.hlcode.version);
+	if file <> "hlc.json" then line ctx (sprintf "// Generated by HLC %d.%d.%d (HL v%d)" version_major version_minor version_revision ctx.hlcode.version);
 	ctx.curfile <- file
 
 let string_data_limit = 64
@@ -963,12 +963,12 @@ let generate_function ctx f =
 	line "}";
 	line ""
 
-let write_c version file (code:code) =
+let write_c com file (code:code) =
 
 	let all_types, htypes = gather_types code in
 
 	let ctx = {
-		version = version;
+		version = com.Common.version;
 		out = Buffer.create 1024;
 		tabs = "";
 		hlcode = code;
@@ -1402,9 +1402,15 @@ let write_c version file (code:code) =
 	line "}";
 	line "";
 
-	open_file ctx "Makefile";
+	open_file ctx "hlc.json";
 
-	line ("FILES = " ^ (String.concat " " (ctx.cfiles)));
+	line "{";
+	block ctx;
+	sline "\"version\" : %d," ctx.version;
+	sline "\"defines\" : {%s\n\t}," (String.concat "," (PMap.foldi (fun k v acc -> sprintf "\n\t\t\"%s\" : \"%s\"" k v :: acc) com.Common.defines []));
+	sline "\"files\" : [%s\n\t]" (String.concat "," (List.map (sprintf "\n\t\t\"%s\"") ctx.cfiles));
+	unblock ctx;
+	line "}";
 
 	close_file ctx