medfall

A super great game engine
Log | Files | Refs

commit bb428975a4e248145cae40b6e11bb93d656c5564
parent 8be0048f2e6936a0def3706187a175a878deed4a
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Sun Jun 25 14:04:10 +0300

Set CXXFLAGS etc based on toolchain instead of OS

Diffstat:
libs/glfw.lua | 7++++---
libs/imgui.lua | 4++--
libs/lz4.lua | 8++++----
libs/squish.lua | 4++--
libs/stb.lua | 12++++++------
libs/tinyobjloader.lua | 2+-
libs/whereami.lua | 2+-
make.lua | 24++++++++++++------------
scripts/gen_makefile.lua | 53+++++++++++++++++++++++------------------------------
9 files changed, 55 insertions(+), 61 deletions(-)
diff --git a/libs/glfw.lua b/libs/glfw.lua @@ -10,13 +10,14 @@ if OS == "windows" then "libs/glfw/src/win32_joystick", "libs/glfw/src/win32_time", "libs/glfw/src/win32_tls", "libs/glfw/src/wgl_context", } ) + + obj_cxxflags( "libs/glfw/src/%", "/c /O2 /TC /D_GLFW_WIN32 /wd4152 /wd4204 /wd4244" ) -- compile as c elseif OS == "linux" then lib( "glfw", { "libs/glfw/src/x11_init", "libs/glfw/src/x11_monitor", "libs/glfw/src/x11_window", "libs/glfw/src/xkb_unicode", "libs/glfw/src/linux_joystick", "libs/glfw/src/posix_time", "libs/glfw/src/posix_tls", "libs/glfw/src/glx_context", } ) -end -windows_obj_cxxflags( "libs/glfw/src/%", "/c /O2 /TC /D_GLFW_WIN32 /wd4152 /wd4204 /wd4244" ) -- compile as c -linux_obj_replace_cxxflags( "libs/glfw/src/%", "-c -x c -O2 -D_GLFW_X11" ) + obj_replace_cxxflags( "libs/glfw/src/%", "-c -x c -O2 -D_GLFW_X11" ) +end diff --git a/libs/imgui.lua b/libs/imgui.lua @@ -1,3 +1,3 @@ lib( "imgui", { "libs/imgui/imgui", "libs/imgui/imgui_draw", "libs/imgui/imgui_impl_glfw_gl3" } ) -linux_obj_cxxflags( "libs/imgui/imgui_draw", "-Wno-maybe-uninitialized -DIMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION -DIMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION" ) -windows_obj_cxxflags( "libs/imgui/imgui_draw", "/DIMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION /DIMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION" ) +msvc_obj_cxxflags( "libs/imgui/imgui_draw", "/DIMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION /DIMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION" ) +gcc_obj_cxxflags( "libs/imgui/imgui_draw", "-Wno-maybe-uninitialized -DIMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION -DIMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION" ) diff --git a/libs/lz4.lua b/libs/lz4.lua @@ -1,5 +1,5 @@ lib( "lz4", { "libs/lz4/lz4", "libs/lz4/lz4hc" } ) -windows_obj_cxxflags( "libs/lz4/lz4", "/O2 /g0" ) -windows_obj_cxxflags( "libs/lz4/lz4hc", "/O2 /g0" ) -linux_obj_cxxflags( "libs/lz4/lz4", "-O3 -g0" ) -linux_obj_cxxflags( "libs/lz4/lz4hc", "-O3 -g0" ) +msvc_obj_cxxflags( "libs/lz4/lz4", "/O2 /g0" ) +msvc_obj_cxxflags( "libs/lz4/lz4hc", "/O2 /g0" ) +gcc_obj_cxxflags( "libs/lz4/lz4", "-O3 -g0" ) +gcc_obj_cxxflags( "libs/lz4/lz4hc", "-O3 -g0" ) diff --git a/libs/squish.lua b/libs/squish.lua @@ -4,5 +4,5 @@ lib( "squish", { "libs/squish/colourblock", "libs/squish/maths", "libs/squish/squish", } ) -windows_obj_cxxflags( "libs/squish/%", "/O2" ) -linux_obj_cxxflags( "libs/squish/%", "-O3" ) +msvc_obj_cxxflags( "libs/squish/%", "/O2" ) +gcc_obj_cxxflags( "libs/squish/%", "-O3" ) diff --git a/libs/stb.lua b/libs/stb.lua @@ -1,14 +1,14 @@ lib( "stb_image", { "libs/stb/stb_image" } ) obj( "libs/stb/stb_image", "libs/stb/stb_image.h" ) -windows_obj_cxxflags( "libs/stb/stb_image", "/DSTB_IMAGE_IMPLEMENTATION /wd4244 /wd4456" ) -linux_obj_cxxflags( "libs/stb/stb_image", "-DSTB_IMAGE_IMPLEMENTATION -Wno-shadow" ) +msvc_obj_cxxflags( "libs/stb/stb_image", "/DSTB_IMAGE_IMPLEMENTATION /wd4244 /wd4456" ) +gcc_obj_cxxflags( "libs/stb/stb_image", "-DSTB_IMAGE_IMPLEMENTATION -Wno-shadow" ) lib( "stb_image_write", { "libs/stb/stb_image_write" } ) obj( "libs/stb/stb_image_write", "libs/stb/stb_image_write.h" ) -windows_obj_cxxflags( "libs/stb/stb_image_write", "/DSTB_IMAGE_WRITE_IMPLEMENTATION" ) -linux_obj_cxxflags( "libs/stb/stb_image_write", "-DSTB_IMAGE_WRITE_IMPLEMENTATION" ) +msvc_obj_cxxflags( "libs/stb/stb_image_write", "/DSTB_IMAGE_WRITE_IMPLEMENTATION" ) +gcc_obj_cxxflags( "libs/stb/stb_image_write", "-DSTB_IMAGE_WRITE_IMPLEMENTATION" ) lib( "stb_truetype", { "libs/stb/stb_truetype" } ) obj( "libs/stb/stb_truetype", "libs/stb/stb_truetype.h" ) -windows_obj_cxxflags( "libs/stb/stb_truetype", "/DSTB_TRUETYPE_IMPLEMENTATION /DSTB_RECT_PACK_IMPLEMENTATION" ) -linux_obj_cxxflags( "libs/stb/stb_truetype", "-DSTB_TRUETYPE_IMPLEMENTATION -DSTB_RECT_PACK_IMPLEMENTATION" ) +msvc_obj_cxxflags( "libs/stb/stb_truetype", "/DSTB_TRUETYPE_IMPLEMENTATION /DSTB_RECT_PACK_IMPLEMENTATION" ) +gcc_obj_cxxflags( "libs/stb/stb_truetype", "-DSTB_TRUETYPE_IMPLEMENTATION -DSTB_RECT_PACK_IMPLEMENTATION" ) diff --git a/libs/tinyobjloader.lua b/libs/tinyobjloader.lua @@ -1,3 +1,3 @@ lib( "tinyobjloader", { "libs/tinyobjloader/tinyobjloader" } ) -windows_obj_cxxflags( "libs/tinyobjloader/tinyobjloader", "/wd4267 /wd4706" ) +msvc_obj_cxxflags( "libs/tinyobjloader/tinyobjloader", "/wd4267 /wd4706" ) diff --git a/libs/whereami.lua b/libs/whereami.lua @@ -1,2 +1,2 @@ lib( "whereami", { "libs/whereami/whereami" } ) -windows_obj_cxxflags( "libs/whereami/whereami", "/wd4005" ) +msvc_obj_cxxflags( "libs/whereami/whereami", "/wd4005" ) diff --git a/make.lua b/make.lua @@ -5,12 +5,12 @@ local game_objs = { "work_queue", "renderer", "shaders", "gl", "glad", "immediat local game_libs = { "glfw", "stb_truetype", "tinyobjloader" } bin( "medfall", { "main", "hm", "heightmap", "terrain_manager", "btt", "gpubtt", "skybox", "http", game_objs }, { "lz4", game_libs } ) -windows_bin_ldflags( "medfall", "opengl32.lib gdi32.lib Ws2_32.lib" ) -linux_bin_ldflags( "medfall", "-lX11 -lXrandr -lXinerama -lXcursor" ) +msvc_bin_ldflags( "medfall", "opengl32.lib gdi32.lib Ws2_32.lib" ) +gcc_bin_ldflags( "medfall", "-lX11 -lXrandr -lXinerama -lXcursor" ) bin( "launch", { "launcher/main", "http", "sha2", "patterns", game_objs }, { "imgui", "monocypher", "whereami", game_libs } ) -windows_bin_ldflags( "launch", "opengl32.lib gdi32.lib Ws2_32.lib" ) -linux_bin_ldflags( "launch", "-lX11 -lXrandr -lXinerama -lXcursor" ) +msvc_bin_ldflags( "launch", "opengl32.lib gdi32.lib Ws2_32.lib" ) +gcc_bin_ldflags( "launch", "-lX11 -lXrandr -lXinerama -lXcursor" ) require( "libs/imgui" ) require( "libs/glfw" ) @@ -30,15 +30,15 @@ bin( "bsp", { "main", "bsp", "bsp_renderer", game_objs }, { game_libs } ) -- bin( "btt", { "main", "mod_btt", "btt", "heightmap", "skybox", "lz4", game_objs }, { "stb_image", game_libs } ) bin( "sm", { "main", "shadow_map", game_objs }, { game_libs } ) -windows_bin_ldflags( "bsp", "opengl32.lib gdi32.lib" ) -linux_bin_ldflags( "bsp", "-lX11 -lXrandr -lXinerama -lXcursor" ) -windows_bin_ldflags( "btt", "opengl32.lib gdi32.lib" ) -linux_bin_ldflags( "btt", "-lX11 -lXrandr -lXinerama -lXcursor" ) -windows_bin_ldflags( "sm", "opengl32.lib gdi32.lib" ) -linux_bin_ldflags( "sm", "-lX11 -lXrandr -lXinerama -lXcursor" ) +msvc_bin_ldflags( "bsp", "opengl32.lib gdi32.lib" ) +gcc_bin_ldflags( "bsp", "-lX11 -lXrandr -lXinerama -lXcursor" ) +msvc_bin_ldflags( "btt", "opengl32.lib gdi32.lib" ) +gcc_bin_ldflags( "btt", "-lX11 -lXrandr -lXinerama -lXcursor" ) +msvc_bin_ldflags( "sm", "opengl32.lib gdi32.lib" ) +gcc_bin_ldflags( "sm", "-lX11 -lXrandr -lXinerama -lXcursor" ) bin( "sound", { "audio", "mixer", "wave", "platform_audio_output", common_objs } ) -windows_bin_ldflags( "sound", "ole32.lib" ) +msvc_bin_ldflags( "sound", "ole32.lib" ) bin( "pp", { "pp", "heightmap", common_objs }, { "lz4", "squish", "stb_image" } ) @@ -49,5 +49,5 @@ if OS ~= "windows" then bin( "utils/genkeys/sign", { "utils/genkeys/sign", common_objs }, { "monocypher" } ) -- bin( "test_lockfree", { "relacy" } ) - -- linux_obj_cxxflags( "relacy", "-std=c++98 -fexceptions -frtti -Wno-shadow -Wno-missing-field-initializers" ) + -- gcc_obj_cxxflags( "relacy", "-std=c++98 -fexceptions -frtti -Wno-shadow -Wno-missing-field-initializers" ) end diff --git a/scripts/gen_makefile.lua b/scripts/gen_makefile.lua @@ -4,8 +4,7 @@ local configs = { obj_suffix = ".obj", lib_suffix = ".lib", - cxx = "...", - lib = "...", + toolchain = "msvc", cxxflags = "/I . /c /Oi /Gm- /GR- /EHa- /EHsc /nologo /DNOMINMAX /D_USE_MATH_DEFINES /DWIN32_LEAN_AND_MEAN", -- ldflags = "user32.lib shell32.lib opengl32.lib gdi32.lib Ws2_32.lib", @@ -29,6 +28,8 @@ local configs = { lib_prefix = "lib", lib_suffix = ".a", + toolchain = "gcc", + cxxflags = "-I . -c -x c++ -std=c++11 -msse2 -ffast-math -fno-exceptions -fno-rtti -fno-strict-aliasing -fno-strict-overflow -D_USE_MATH_DEFINES", ldflags = "-lm -lpthread -ldl", warnings = "-Wall -Wextra -Wno-unused-parameter -Wno-unused-function -Wshadow -Wcast-align -Wstrict-overflow -Wvla", -- -Wconversion @@ -103,6 +104,8 @@ local lib_suffix = rightmost( "lib_suffix" ) local cxxflags = concat( "cxxflags" ) .. " " .. concat( "warnings" ) local ldflags = concat( "ldflags" ) +toolchain = rightmost( "toolchain" ) + local dir = "build/" .. triple local output = { } @@ -151,44 +154,34 @@ function lib( lib_name, objs ) printf( "%s/%s%s%s: %s", dir, lib_prefix, lib_name, lib_suffix, join( objs, obj_suffix ) ) end --- TODO: this should be split by windows/linux and also by msvc/gcc -function linux_bin_ldflags( bin_name, ldflags ) - if OS == "linux" then - local bin_path = ( "%s%s%s" ):format( bin_prefix, bin_name, bin_suffix ) - printf( "%s: LDFLAGS += %s", bin_path, ldflags ) - end +function bin_ldflags( bin_name, ldflags ) + local bin_path = ( "%s%s%s" ):format( bin_prefix, bin_name, bin_suffix ) + printf( "%s: LDFLAGS += %s", bin_path, ldflags ) end -function linux_obj_cxxflags( obj_name, cxxflags ) - if OS == "linux" then - printf( "%s/%s%s: CXXFLAGS += %s", dir, obj_name, obj_suffix, cxxflags ) - end +function obj_cxxflags( obj_name, cxxflags ) + printf( "%s/%s%s: CXXFLAGS += %s", dir, obj_name, obj_suffix, cxxflags ) end -function linux_obj_replace_cxxflags( obj_name, cxxflags ) - if OS == "linux" then - printf( "%s/%s%s: CXXFLAGS := %s", dir, obj_name, obj_suffix, cxxflags ) - end +function obj_replace_cxxflags( obj_name, cxxflags ) + printf( "%s/%s%s: CXXFLAGS := %s", dir, obj_name, obj_suffix, cxxflags ) end -function windows_bin_ldflags( bin_name, ldflags ) - if OS == "windows" then - local bin_path = ( "%s%s%s" ):format( bin_prefix, bin_name, bin_suffix ) - printf( "%s: LDFLAGS += %s", bin_path, ldflags ) +local function toolchain_helper( t, f ) + return function( ... ) + if toolchain == t then + f( ... ) + end end end -function windows_obj_cxxflags( obj_name, cxxflags ) - if OS == "windows" then - printf( "%s/%s%s: CXXFLAGS += %s", dir, obj_name, obj_suffix, cxxflags ) - end -end +msvc_bin_ldflags = toolchain_helper( "msvc", bin_ldflags ) +msvc_obj_cxxflags = toolchain_helper( "msvc", obj_cxxflags ) +msvc_obj_replace_cxxflags = toolchain_helper( "msvc", obj_replace_cxxflags ) -function windows_obj_replace_cxxflags( obj_name, cxxflags ) - if OS == "windows" then - printf( "%s/%s%s: CXXFLAGS := %s", dir, obj_name, obj_suffix, cxxflags ) - end -end +gcc_bin_ldflags = toolchain_helper( "gcc", bin_ldflags ) +gcc_obj_cxxflags = toolchain_helper( "gcc", obj_cxxflags ) +gcc_obj_replace_cxxflags = toolchain_helper( "gcc", obj_replace_cxxflags ) printf( "CXXFLAGS := %s", cxxflags ) printf( "LDFLAGS := %s", ldflags )