stevedonovan / Lake

A Lua-based Build Tool
MIT License
132 stars 16 forks source link

Compile several file based on one source. #33

Open moteus opened 10 years ago

moteus commented 10 years ago

I try write lakefile for luaffi library. This library has generated header files:

lua.exe dynasm\dynasm.lua -LNE -D X32WIN -o call_x86.h call_x86.dasc
lua.exe dynasm\dynasm.lua -LNE -D X64 -o call_x64.h call_x86.dasc
lua.exe dynasm\dynasm.lua -LNE -D X64 -D X64WIN -o call_x64win.h call_x86.dasc
lua.exe dynasm\dynasm.lua -LNE -o call_arm.h call_arm.dasc

So call_x86.h, call_x86.h and call_x64win.h builds based on same file(call_x86.dasc) Because target name depends also from flags i can not use group because of than i try create new languege:

dasc = {ext='.dasc', obj_ext='.~h', exe_ext = '.h'}
dasc.compile            = LUA_EXE .. ' dynasm\\dynasm.lua $(CFLAGS) -o $(TARGET) $(INPUT)'
dasc.link               = '$(COPY) $(SRC) $(TARGET)'
dasc.output_in_same_dir = true

lake.add_prog(dasc)

dasc_h = {
  dasc.program{"call_x86",    src = "call_x86.dasc", cflags = "-LNE -D X32WIN"        };
  dasc.program{"call_x64",    src = "call_x86.dasc", cflags = "-LNE -D X64"           };
  dasc.program{"call_x64win", src = "call_x86.dasc", cflags = "-LNE -D X64 -D X64WIN" };
  dasc.program{"call_arm",    src = "call_arm.dasc", cflags = "-LNE"                  };
}

c.shared{"ffi",
  src = { "call", "ctype", "ffi", "parser" };
  compile_deps = dasc_h;
}

Output

G:\lua\5.1\lua.exe dynasm\dynasm.lua  -LNE -D X32WIN -o call_x86.~h call_x86.dasc
copy  call_x86.exe
copy  call_x64.exe
copy  call_x64win.exe
G:\lua\5.1\lua.exe dynasm\dynasm.lua  -LNE -o call_arm.~h call_arm.dasc
copy  call_arm.exe
gcc -c -O2 -Wall -MMD  call.c -o call.o
gcc -c -O2 -Wall -MMD  ctype.c -o ctype.o
gcc -c -O2 -Wall -MMD  ffi.c -o ffi.o
gcc -c -O2 -Wall -MMD  parser.c -o parser.o
gcc call.o ctype.o ffi.o parser.o  -Wl,-s -shared -o ffi.dll

There 2 problems:

moteus commented 10 years ago

luaffi library also build test_cdecl.dll test_stdcall.dll and test_fastcall.dll based on test.c file. So this is my final variant https://gist.github.com/moteus/7042134 For dasc file i just create target manually and for dll files i copy .c file with different name. But this is not obvious and not easy if you have multiple .c files. May be you have better solution. And i think it worth at least mention about this behavior in documentation.