diff --git a/.gitignore b/.gitignore index 56e074416..bc76a3aa3 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,9 @@ ehthumbs_vista.db ._* programs/cmm/cmm.code-workspace programs/cmm/menu/.gitignore + +.tup/ + +/build-*/ +/*.config + diff --git a/contrib/sdk/sources/sound/Tupfile.lua b/contrib/sdk/sources/sound/Tupfile.lua new file mode 100644 index 000000000..f3f542cc9 --- /dev/null +++ b/contrib/sdk/sources/sound/Tupfile.lua @@ -0,0 +1,18 @@ +if tup.getconfig("NO_FASM") ~= "" then return end + +SOURCES = { + "src/*.asm", + extra_inputs = { + "src/*.inc" + } +} + +OBJS = { + extra_inputs = { + "symbols" + } +} + +tup.append_table(OBJS, tup.foreach_rule(SOURCES, "fasm %f %o", "%B.o")) + +tup.rule(OBJS, "ar -cvrs %o %f && objcopy -O elf32-i386 --redefine-syms=symbols %o", {"libsound.a", ""}) diff --git a/data/Tupfile.lua b/data/Tupfile.lua index fd3afb2d1..700f54a97 100644 --- a/data/Tupfile.lua +++ b/data/Tupfile.lua @@ -184,7 +184,8 @@ extra_files = { {"kolibrios/develop/oberon07/lib/KolibriOS/", SRC_PROGS .. "/develop/oberon07/lib/KolibriOS/*"}, {"kolibrios/develop/oberon07/lib/Math/", SRC_PROGS .. "/develop/oberon07/lib/Math/*"}, {"kolibrios/develop/oberon07/samples/", SRC_PROGS .. "/develop/oberon07/samples/KolibriOS/*"}, - {"kolibrios/develop/tcc/lib/", SRC_PROGS .. "/develop/ktcc/bin/lib/*"}, + {"kolibrios/develop/tcc/lib/", SRC_PROGS .. "/develop/ktcc/bin/lib/*.def"}, + {"kolibrios/develop/tcc/lib/libSDL.a", SRC_PROGS .. "/develop/ktcc/bin/lib/libSDL.a"}, {"kolibrios/develop/tcc/include/", SRC_PROGS .. "/develop/ktcc/libc.obj/include/*"}, {"kolibrios/develop/tcc/include/clayer/", SRC_PROGS .. "/develop/ktcc/libc.obj/include/clayer/*"}, {"kolibrios/develop/tcc/include/cryptal/", SRC_PROGS .. "/develop/ktcc/libc.obj/include/cryptal/*"}, @@ -634,7 +635,10 @@ tup.append_table(extra_files, { {"kolibrios/utils/AMDtemp", VAR_PROGS .. "/system/amd_temp_view/AMDtemp"}, {"kolibrios/utils/kfm/kfm", VAR_PROGS .. "/fs/kfm/kfm"}, {"kolibrios/utils/tedit/t_edit", VAR_PROGS .. "/other/t_edit/t_edit"}, - {"kolibrios/3D/blocks/block.bin", VAR_PROGS .. "/bcc32/games/blocks/block.bin"} + {"kolibrios/3D/blocks/block.bin", VAR_PROGS .. "/bcc32/games/blocks/block.bin"}, + {"kolibrios/develop/tcc/lib/crt0.o", VAR_PROGS .. "/develop/ktcc/bin/lib/crt0.o", group = "../programs/develop/ktcc/"}, + {"kolibrios/develop/tcc/lib/tiny.o", VAR_PROGS .. "/develop/ktcc/bin/lib/tiny.o", group = "../programs/develop/ktcc/"}, + {"kolibrios/develop/tcc/lib/libsound.a", VAR_PROGS .. "/develop/ktcc/bin/lib/libsound.a", group = "../programs/develop/ktcc/"} }) -- For russian build, add russian-only programs. if build_type == "ru_RU" then tup.append_table(img_files, { @@ -719,29 +723,41 @@ tup.append_table(extra_files, { }) end -- tup.getconfig('NO_MSVC') ~= 'full' --- Programs that require TCC to compile. +-- Programs that require TCC to compile. TCC programs that link executables +-- additionally need FASM (for crt0.o, tiny.o, libtcc1.a). LIBC.OBJ is a +-- relocatable TCC translation unit and does not require FASM. if tup.getconfig('NO_TCC') ~= 'full' then +if tup.getconfig('NO_FASM') ~= 'full' then tup.append_table(img_files, { {"NETWORK/WHOIS", VAR_PROGS .. "/network/whois/whois"}, {"SHELL", VAR_PROGS .. "/system/shell/shell"}, {"GAMES/DINO", VAR_PROGS .. "/games/dino/dino"}, {"GAMES/FLPYBIRD", VAR_PROGS .. "/games/flpybird/flpybird"}, +}) +end -- tup.getconfig('NO_FASM') ~= 'full' +tup.append_table(img_files, { {"LIB/LIBC.OBJ", VAR_PROGS .. "/develop/ktcc/libc.obj/source/libc.obj"}, }) +if tup.getconfig('NO_FASM') ~= 'full' then tup.append_table(extra_files, { {"kolibrios/utils/thashview", VAR_PROGS .. "/other/TinyHashView/thashview"}, {"kolibrios/demos/kmatrix", VAR_PROGS .. "/demos/kmatrix/kmatrix"}, {"kolibrios/utils/graph", VAR_PROGS .. "/other/graph/branches/tcc_current/graph"}, {"kolibrios/develop/TinyBasic/TinyBasic", VAR_PROGS .. "/develop/tinybasic-1.0.4/tinybasic"}, - {"kolibrios/develop/TinyBasic/bas/", SRC_PROGS .. "/develop/tinybasic-1.0.4/bas/*"}, - {"kolibrios/develop/TinyBasic/TinyBasic.man", SRC_PROGS .. "/develop/tinybasic-1.0.4/doc/tinybasic.man"}, {"kolibrios/utils/passwordgen", VAR_PROGS .. "/other/PasswordGen/passwordgen"}, {"kolibrios/utils/kruler", VAR_PROGS .. "/other/kruler/kruler"}, - {"kolibrios/media/qr_tool", SRC_PROGS .. "/media/qr_tool/qr_tool"}, {"kolibrios/utils/weather", VAR_PROGS .. "/other/Weather/weather"}, - {"kolibrios/settings/weather.json", SRC_PROGS .. "/other/Weather/weather.json"}, {"kolibrios/utils/man2html", VAR_PROGS .."/other/man2html/man2html"}, }) +end -- tup.getconfig('NO_FASM') ~= 'full' +tup.append_table(extra_files, { + {"kolibrios/develop/TinyBasic/bas/", SRC_PROGS .. "/develop/tinybasic-1.0.4/bas/*"}, + {"kolibrios/develop/TinyBasic/TinyBasic.man", SRC_PROGS .. "/develop/tinybasic-1.0.4/doc/tinybasic.man"}, + {"kolibrios/media/qr_tool", SRC_PROGS .. "/media/qr_tool/qr_tool"}, + {"kolibrios/settings/weather.json", SRC_PROGS .. "/other/Weather/weather.json"}, + {"kolibrios/develop/tcc/lib/libshell.a", VAR_PROGS .. "/develop/ktcc/bin/lib/libshell.a", group="../programs/develop/ktcc/"}, + {"kolibrios/develop/tcc/lib/libcryptal.a", VAR_PROGS .. "/develop/ktcc/bin/lib/libcryptal.a", group="../programs/develop/ktcc/"} +}) end -- tup.getconfig('NO_TCC') ~= 'full' -- Programs that require oberon07 compiler. @@ -808,6 +824,13 @@ if tup.getconfig('NO_NASM') ~= 'full' then {"kolibrios/emul/dgen/dgenrc.html", SRC_PROGS .. "/emulator/dgen-sdl-1.33/dgenrc.html"}, }) end + +if tup.getconfig("NO_FASM") ~= "full" and tup.getconfig("NO_TCC") ~= "full" then + tup.append_table(extra_files, { + {"kolibrios/develop/tcc/lib/libtcc1.a", VAR_PROGS .. "/develop/ktcc/bin/lib/libtcc1.a", group="../programs/develop/ktcc/"} + }) +end + -- For russian build, add russian-only programs. if build_type == "ru_RU" then tup.append_table(extra_files, { {"kolibrios/games/21days", VAR_PROGS .. "/games/21days/21days"}, diff --git a/programs/demos/kmatrix/Tupfile.lua b/programs/demos/kmatrix/Tupfile.lua index 025efea41..4d2361b8e 100755 --- a/programs/demos/kmatrix/Tupfile.lua +++ b/programs/demos/kmatrix/Tupfile.lua @@ -1,4 +1,4 @@ -if tup.getconfig("NO_TCC") ~= "" then return end +if tup.getconfig("NO_TCC") ~= "" or tup.getconfig("NO_FASM") ~= "" then return end HELPERDIR = (tup.getconfig("HELPERDIR") == "") and "../.." or tup.getconfig("HELPERDIR") tup.include(HELPERDIR .. "/use_tcc.lua") diff --git a/programs/develop/ktcc/Tupfile.lua b/programs/develop/ktcc/Tupfile.lua new file mode 100644 index 000000000..6befab330 --- /dev/null +++ b/programs/develop/ktcc/Tupfile.lua @@ -0,0 +1,36 @@ +local LIBS = {} + +if tup.getconfig("NO_FASM") == "" then + tup.append_table(LIBS, { + tup.getcwd() .. "/libc.obj/source/crt0.o", + tup.getcwd() .. "/lib/tiny/tiny.o", + }) +end + +if tup.getconfig("NO_TCC") == "" then + tup.append_table(LIBS, { + tup.getcwd() .. "/lib/libcryptal/libcryptal.a", + tup.getcwd() .. "/lib/libshell/libshell.a", + }) +end + +if tup.getconfig("NO_FASM") == "" and tup.getconfig("NO_TCC") == "" then + tup.append_table(LIBS, { + tup.getcwd() .. "/libc.obj/source/libtcc1/libtcc1.a", + }) +end + +tup.foreach_rule(LIBS, "cp %f %o", { tup.getcwd() .. "/bin/lib/%b", "<%b>" }) + +-- libsound.a lives in another subtree (contrib/), so reference its group +-- explicitly via extra_inputs to keep Tup ordering correct across trees. +if tup.getconfig("NO_FASM") == "" then + tup.rule( + { + "../../../contrib/sdk/sources/sound/libsound.a", + extra_inputs = { "../../../contrib/sdk/sources/sound/" }, + }, + "cp %f %o", + { tup.getcwd() .. "/bin/lib/libsound.a", "" } + ) +end diff --git a/programs/develop/ktcc/bin/lib/crt0.o b/programs/develop/ktcc/bin/lib/crt0.o deleted file mode 100644 index b857c8056..000000000 Binary files a/programs/develop/ktcc/bin/lib/crt0.o and /dev/null differ diff --git a/programs/develop/ktcc/bin/lib/libcryptal.a b/programs/develop/ktcc/bin/lib/libcryptal.a deleted file mode 100644 index 59467f166..000000000 Binary files a/programs/develop/ktcc/bin/lib/libcryptal.a and /dev/null differ diff --git a/programs/develop/ktcc/bin/lib/libshell.a b/programs/develop/ktcc/bin/lib/libshell.a deleted file mode 100644 index 582aa71f6..000000000 Binary files a/programs/develop/ktcc/bin/lib/libshell.a and /dev/null differ diff --git a/programs/develop/ktcc/bin/lib/libsound.a b/programs/develop/ktcc/bin/lib/libsound.a deleted file mode 100644 index de48e1352..000000000 Binary files a/programs/develop/ktcc/bin/lib/libsound.a and /dev/null differ diff --git a/programs/develop/ktcc/bin/lib/libtcc1.a b/programs/develop/ktcc/bin/lib/libtcc1.a deleted file mode 100644 index 77e05da5e..000000000 Binary files a/programs/develop/ktcc/bin/lib/libtcc1.a and /dev/null differ diff --git a/programs/develop/ktcc/bin/lib/tiny.o b/programs/develop/ktcc/bin/lib/tiny.o deleted file mode 100644 index af83c8ef3..000000000 Binary files a/programs/develop/ktcc/bin/lib/tiny.o and /dev/null differ diff --git a/programs/develop/ktcc/lib/libcryptal/Tupfile.lua b/programs/develop/ktcc/lib/libcryptal/Tupfile.lua new file mode 100644 index 000000000..09194f672 --- /dev/null +++ b/programs/develop/ktcc/lib/libcryptal/Tupfile.lua @@ -0,0 +1,23 @@ +if tup.getconfig("NO_TCC") ~= "" then return end + +HELPERDIR = (tup.getconfig("HELPERDIR") == "") and "../../../.." or tup.getconfig("HELPERDIR") +tup.include(HELPERDIR .. "/use_tcc.lua") + +LIBC_INCLUDE = "../../libc.obj/include" + +CFLAGS += "-c -I. -I" .. LIBC_INCLUDE + +SOURCES = { + "*.c", + extra_inputs = { + "memory.h", + LIBC_INCLUDE .. "/cryptal/*", + LIBC_INCLUDE .. "/string.h", + LIBC_INCLUDE .. "/stdlib.h", + LIBC_INCLUDE .. "/stdio.h", + } +} + +compile_tcc(SOURCES) + +tup.rule(OBJS, "ar -rcs %o %f", "libcryptal.a") diff --git a/programs/develop/ktcc/lib/libshell/Tupfile.lua b/programs/develop/ktcc/lib/libshell/Tupfile.lua new file mode 100644 index 000000000..b34aab08c --- /dev/null +++ b/programs/develop/ktcc/lib/libshell/Tupfile.lua @@ -0,0 +1,24 @@ +if tup.getconfig("NO_TCC") ~= "" then return end + + +HELPERDIR = (tup.getconfig("HELPERDIR") == "") and "../../../.." or tup.getconfig("HELPERDIR") +tup.include(HELPERDIR .. "/use_tcc.lua") + +LIBC_INCLUDE = "../../libc.obj/include" + +CFLAGS += "-c -I. -I" .. LIBC_INCLUDE + +SOURCES = { + "*.c", + extra_inputs = { + LIBC_INCLUDE .. "/shell_api.h", + LIBC_INCLUDE .. "/sys/ksys.h", + LIBC_INCLUDE .. "/string.h", + LIBC_INCLUDE .. "/stdlib.h", + LIBC_INCLUDE .. "/stdio.h" + } +} + +compile_tcc(SOURCES) + +tup.rule(OBJS, "ar -rcs %o %f", "libshell.a") diff --git a/programs/develop/ktcc/lib/tiny/Tupfile.lua b/programs/develop/ktcc/lib/tiny/Tupfile.lua new file mode 100644 index 000000000..7832c5d0d --- /dev/null +++ b/programs/develop/ktcc/lib/tiny/Tupfile.lua @@ -0,0 +1,10 @@ +if tup.getconfig("NO_FASM") ~= "" then return end + +HELPERDIR = (tup.getconfig("HELPERDIR") == "") and "../../../.." or tup.getconfig("HELPERDIR") +tup.include(HELPERDIR .. "/use_fasm.lua") + +FASM_SOURCES = { + "tiny.asm", +} + +tup.rule(FASM_SOURCES, FASM .. " %f %o", "%B.o") diff --git a/programs/develop/ktcc/libc.obj/.gitignore b/programs/develop/ktcc/libc.obj/.gitignore new file mode 100644 index 000000000..0b0ee0ab8 --- /dev/null +++ b/programs/develop/ktcc/libc.obj/.gitignore @@ -0,0 +1,4 @@ +.tup +*.o +*.obj +*.kex diff --git a/programs/develop/ktcc/libc.obj/lib/crt0.o b/programs/develop/ktcc/libc.obj/lib/crt0.o deleted file mode 100644 index 598dbd5fc..000000000 Binary files a/programs/develop/ktcc/libc.obj/lib/crt0.o and /dev/null differ diff --git a/programs/develop/ktcc/libc.obj/source/Tupfile.lua b/programs/develop/ktcc/libc.obj/source/Tupfile.lua index 380289707..1e54ba545 100755 --- a/programs/develop/ktcc/libc.obj/source/Tupfile.lua +++ b/programs/develop/ktcc/libc.obj/source/Tupfile.lua @@ -1,4 +1,8 @@ -if tup.getconfig("NO_TCC") ~= "" then return end +FASM_SRC = { + "crt/crt0.asm", +} + +if tup.getconfig("NO_TCC") == "" then CFLAGS = " -r -nostdinc -nostdlib -DGNUC -D_BUILD_LIBC " INCLUDES = " -I../include" @@ -32,11 +36,17 @@ GAS_SRC = { "string/memmove.s" } -OBJS = {"libc.c"} +OBJS = { "libc.c" } -tup.append_table(OBJS, - tup.foreach_rule(GAS_SRC, "as --32 %f -o %o", "%B.o") -) +tup.append_table(OBJS, tup.foreach_rule(GAS_SRC, "as --32 %f -o %o", "%B.o")) -tup.rule(OBJS, "kos32-tcc" .. CFLAGS .. INCLUDES .. " %f -o %o " .. " && strip %o --strip-unneeded " , "libc.o") +tup.rule(OBJS, "kos32-tcc" .. CFLAGS .. INCLUDES .. " %f -o %o " .. " && strip %o --strip-unneeded ", "libc.o") tup.rule("libc.o", "objconv -fcoff32 %f %o " .. tup.getconfig("KPACK_CMD"), "%B.obj") + +end + +if tup.getconfig("NO_FASM") == "" then + +tup.rule(FASM_SRC, "fasm %f %o", "%B.o") + +end diff --git a/programs/develop/ktcc/libc.obj/source/libtcc1/Tupfile.lua b/programs/develop/ktcc/libc.obj/source/libtcc1/Tupfile.lua new file mode 100644 index 000000000..dc4a0ebdb --- /dev/null +++ b/programs/develop/ktcc/libc.obj/source/libtcc1/Tupfile.lua @@ -0,0 +1,25 @@ +if tup.getconfig("NO_TCC") ~= "" or tup.getconfig("NO_FASM") ~= "" then return end + +local helperPath = "../../../../.." +HELPERDIR = (tup.getconfig("HELPERDIR") == "") and helperPath or tup.getconfig("HELPERDIR") +tup.include(HELPERDIR .. "/use_tcc.lua") +tup.include(HELPERDIR .. "/use_fasm.lua") + +TCC_SOURCES = { + "libtcc1.c", +} + +FASM_SOURCES = { + "memcpy.asm", + "memmove.asm", + "memset.asm", + extra_inputs = { + helperPath .. "/proc32.inc" + } +} + +compile_tcc(TCC_SOURCES) + +tup.append_table(OBJS, tup.foreach_rule(FASM_SOURCES, FASM .. " %f %o", "%B.o")) + +tup.rule(OBJS, "ar -rcs %o %f", "libtcc1.a") diff --git a/programs/develop/libraries/kos_mbedtls/programs/ssl/Tupfile.lua b/programs/develop/libraries/kos_mbedtls/programs/ssl/Tupfile.lua index fe493c6aa..7f9b6b489 100644 --- a/programs/develop/libraries/kos_mbedtls/programs/ssl/Tupfile.lua +++ b/programs/develop/libraries/kos_mbedtls/programs/ssl/Tupfile.lua @@ -1,5 +1,4 @@ -if tup.getconfig("NO_FASM") ~= "" then return end -if tup.getconfig("NO_TCC") ~= "" then return end +if tup.getconfig("NO_FASM") ~= "" or tup.getconfig("NO_TCC") ~= "" then return end if tup.getconfig("HELPERDIR") == "" then HELPERDIR = "../../../../../" diff --git a/programs/develop/tinybasic-1.0.4/Tupfile.lua b/programs/develop/tinybasic-1.0.4/Tupfile.lua index 7693aeb86..e4db2333a 100644 --- a/programs/develop/tinybasic-1.0.4/Tupfile.lua +++ b/programs/develop/tinybasic-1.0.4/Tupfile.lua @@ -1,4 +1,4 @@ -if tup.getconfig("NO_TCC") ~= "" then return end +if tup.getconfig("NO_TCC") ~= "" or tup.getconfig("NO_FASM") ~= "" then return end if tup.getconfig("HELPERDIR") == "" then HELPERDIR = "../../../programs" diff --git a/programs/games/dino/Tupfile.lua b/programs/games/dino/Tupfile.lua index 994138718..431019650 100644 --- a/programs/games/dino/Tupfile.lua +++ b/programs/games/dino/Tupfile.lua @@ -1,4 +1,4 @@ -if tup.getconfig("NO_TCC") ~= "" then return end +if tup.getconfig("NO_TCC") ~= "" or tup.getconfig("NO_FASM") ~= "" then return end if tup.getconfig("HELPERDIR") == "" then HELPERDIR = "../../../programs" diff --git a/programs/games/flpybird/Tupfile.lua b/programs/games/flpybird/Tupfile.lua index 08b0c2c39..ee22dd5cd 100644 --- a/programs/games/flpybird/Tupfile.lua +++ b/programs/games/flpybird/Tupfile.lua @@ -1,4 +1,4 @@ -if tup.getconfig("NO_TCC") ~= "" then return end +if tup.getconfig("NO_TCC") ~= "" or tup.getconfig("NO_FASM") ~= "" then return end if tup.getconfig("HELPERDIR") == "" then HELPERDIR = "../../../programs" diff --git a/programs/network/whois/Tupfile.lua b/programs/network/whois/Tupfile.lua index 5186b20be..c43f581ca 100644 --- a/programs/network/whois/Tupfile.lua +++ b/programs/network/whois/Tupfile.lua @@ -1,4 +1,4 @@ -if tup.getconfig("NO_TCC") ~= "" then return end +if tup.getconfig("NO_TCC") ~= "" or tup.getconfig("NO_FASM") ~= "" then return end if tup.getconfig("HELPERDIR") == "" then HELPERDIR = "../../../programs" diff --git a/programs/other/PasswordGen/Tupfile.lua b/programs/other/PasswordGen/Tupfile.lua index 2b6e84317..1428d9982 100644 --- a/programs/other/PasswordGen/Tupfile.lua +++ b/programs/other/PasswordGen/Tupfile.lua @@ -1,4 +1,4 @@ -if tup.getconfig("NO_TCC") ~= "" then return end +if tup.getconfig("NO_TCC") ~= "" or tup.getconfig("NO_FASM") ~= "" then return end if tup.getconfig("HELPERDIR") == "" then HELPERDIR = "../../../programs" diff --git a/programs/other/TinyHashView/Tupfile.lua b/programs/other/TinyHashView/Tupfile.lua index 53fe9d49b..42a0276bb 100644 --- a/programs/other/TinyHashView/Tupfile.lua +++ b/programs/other/TinyHashView/Tupfile.lua @@ -1,4 +1,4 @@ -if tup.getconfig("NO_TCC") ~= "" then return end +if tup.getconfig("NO_TCC") ~= "" or tup.getconfig("NO_FASM") ~= "" then return end if tup.getconfig("HELPERDIR") == "" then HELPERDIR = "../../../programs" @@ -7,4 +7,4 @@ tup.include(HELPERDIR .. "/use_tcc.lua") LIBS = "-lcryptal -lbox_lib -ldialog" -link_tcc({"thashview.c"}, "thashview"); +link_tcc({"thashview.c"}, "thashview", {"cryptal"}); diff --git a/programs/other/Weather/Tupfile.lua b/programs/other/Weather/Tupfile.lua index 58a05df78..8377b0610 100644 --- a/programs/other/Weather/Tupfile.lua +++ b/programs/other/Weather/Tupfile.lua @@ -1,4 +1,4 @@ -if tup.getconfig("NO_TCC") ~= "" then return end +if tup.getconfig("NO_TCC") ~= "" or tup.getconfig("NO_FASM") ~= "" then return end if tup.getconfig("HELPERDIR") == "" then HELPERDIR = "../../../programs" diff --git a/programs/other/graph/branches/tcc_current/Tupfile.lua b/programs/other/graph/branches/tcc_current/Tupfile.lua index e766b6d78..dd62e1ce3 100755 --- a/programs/other/graph/branches/tcc_current/Tupfile.lua +++ b/programs/other/graph/branches/tcc_current/Tupfile.lua @@ -1,4 +1,4 @@ -if tup.getconfig("NO_TCC") ~= "" then return end +if tup.getconfig("NO_TCC") ~= "" or tup.getconfig("NO_FASM") ~= "" then return end HELPERDIR = (tup.getconfig("HELPERDIR") == "") and "../../../.." or tup.getconfig("HELPERDIR") tup.include(HELPERDIR .. "/use_tcc.lua") diff --git a/programs/other/man2html/Tupfile.lua b/programs/other/man2html/Tupfile.lua index acb3a1b10..91fa1f950 100644 --- a/programs/other/man2html/Tupfile.lua +++ b/programs/other/man2html/Tupfile.lua @@ -1,4 +1,4 @@ -if tup.getconfig("NO_TCC") ~= "" then return end +if tup.getconfig("NO_TCC") ~= "" or tup.getconfig("NO_FASM") ~= "" then return end if tup.getconfig("HELPERDIR") == "" then HELPERDIR = "../../../programs" diff --git a/programs/system/shell/Tupfile.lua b/programs/system/shell/Tupfile.lua index 8519d980a..f8a3da486 100644 --- a/programs/system/shell/Tupfile.lua +++ b/programs/system/shell/Tupfile.lua @@ -1,4 +1,4 @@ -if tup.getconfig("NO_TCC") ~= "" then return end +if tup.getconfig("NO_TCC") ~= "" or tup.getconfig("NO_FASM") ~= "" then return end HELPERDIR = (tup.getconfig("HELPERDIR") == "") and "../.." or tup.getconfig("HELPERDIR") tup.include(HELPERDIR .. "/use_tcc.lua") diff --git a/programs/use_tcc.lua b/programs/use_tcc.lua index 8beb6a793..7e32dc2ca 100644 --- a/programs/use_tcc.lua +++ b/programs/use_tcc.lua @@ -1,19 +1,70 @@ -TCC = "kos32-tcc -B" .. tup.getcwd().. "/develop/ktcc/bin" - -CFLAGS = "-I" .. tup.getcwd().. "/develop/ktcc/libc.obj/include " -LFLAGS = "" -LIBS = "" - -OBJS = {} - -function compile_tcc(input, output) - if not output then output = '%B.o' end - tup.append_table(OBJS, - tup.foreach_rule(input, TCC .. " -c " .. CFLAGS .. " %f -o %o", output) - ) -end - -function link_tcc(input, output) - if not output then input,output = OBJS,input end - tup.rule(input, TCC .. " " .. CFLAGS .. " " .. LFLAGS .. " %f -o %o " .. LIBS .. " " .. tup.getconfig("KPACK_CMD"), output) -end +KTCC_TRUNK = tup.getcwd() .. "/develop/ktcc/" + +TCC = "kos32-tcc -B" .. tup.getvariantdir() .. "/develop/ktcc/bin" + +CFLAGS = "-I" .. KTCC_TRUNK .. "libc.obj/include -L" .. KTCC_TRUNK .. "bin/lib" +LFLAGS = "" +LIBS = "" + +OBJS = {} + +-- Mandatory libs: every TCC-linked program transitively depends on these +-- (kos32-tcc looks them up automatically from -B/lib/). +LIST_OF_LIBS = {} + +-- Optional libs: requested by individual programs via the third argument +-- of link_tcc, e.g. link_tcc(src, out, {"cryptal"}). Only entries that the +-- current toolchain configuration can actually produce are exposed here. +OPTIONAL_LIBS = {} + +if tup.getconfig("NO_FASM") == "" then + tup.append_table(LIST_OF_LIBS, { "crt0.o", "tiny.o" }) + OPTIONAL_LIBS.sound = "libsound.a" +end + +if tup.getconfig("NO_TCC") == "" then + OPTIONAL_LIBS.cryptal = "libcryptal.a" + OPTIONAL_LIBS.shell = "libshell.a" +end + +if tup.getconfig("NO_FASM") == "" and tup.getconfig("NO_TCC") == "" then + tup.append_table(LIST_OF_LIBS, { "libtcc1.a" }) +end + +function compile_tcc(input, output) + if not output then output = '%B.o' end + tup.append_table(OBJS, + tup.foreach_rule(input, TCC .. " -c " .. CFLAGS .. " %f -o %o", output) + ) +end + +function link_tcc(input, output, libs) + if not output then input, output = OBJS, input end + + if type(input) ~= "table" then + input = { input } + end + + if not input.extra_inputs then + input.extra_inputs = {} + end + + for _, lib in pairs(LIST_OF_LIBS) do + table.insert(input.extra_inputs, KTCC_TRUNK .. "<" .. lib .. ">") + end + + if libs then + for _, name in pairs(libs) do + local libfile = OPTIONAL_LIBS[name] + if libfile then + table.insert(input.extra_inputs, KTCC_TRUNK .. "<" .. libfile .. ">") + end + end + end + + table.insert(input.extra_inputs, KTCC_TRUNK .. "bin/lib/*.def") + + tup.rule(input, + TCC .. " " .. CFLAGS .. " " .. LFLAGS .. " " .. "%f -o %o " .. LIBS .. " " .. tup.getconfig("KPACK_CMD"), + output) +end