lama_byterun/tutorial/gen.ml
Kakadu a91f4824c4 Dunify tutorial
Signed-off-by: Kakadu <Kakadu@pm.me>
2024-09-05 19:12:37 +03:00

44 lines
1.2 KiB
OCaml

#use "topfind";;
#require "str";;
let demos = ["Expressions"; "Functions"; "Hello"; "PatternMatching"; "Values"]
let template = {|
(rule
(targets %DEMO%.exe)
(deps (:lama %DEMOSRC%.lama) %RUNTIME%/runtime.a)
(mode
(promote (until-clean)))
(action
(setenv
LAMA
"%RUNTIME%"
(run
%{project_root}/src/Driver.exe
%EXTRASWITCHES%
%{lama}
-I
%STDLIB%
-I
%RUNTIME%
-o
%{targets}))))
|}
let () =
Out_channel.with_open_text "dune" (fun ch ->
List.iter (fun demo ->
template
|> Str.global_replace (Str.regexp "%DEMO%") (demo^".x32")
|> Str.global_replace (Str.regexp "%DEMOSRC%") demo
|> Str.global_replace (Str.regexp "%RUNTIME%") "../runtime32"
|> Str.global_replace (Str.regexp "%STDLIB%") "../stdlib/x32"
|> Str.global_replace (Str.regexp "%EXTRASWITCHES%") "-march=x86"
|> output_string ch;
template
|> Str.global_replace (Str.regexp "%DEMO%") (demo^".x64")
|> Str.global_replace (Str.regexp "%DEMOSRC%") demo
|> Str.global_replace (Str.regexp "%RUNTIME%") "../runtime"
|> Str.global_replace (Str.regexp "%STDLIB%") "../stdlib/x64"
|> Str.global_replace (Str.regexp "%EXTRASWITCHES%") "-march=x86_64"
|> output_string ch;
) demos)