diff --git a/build-MSYS_NT-10.0-22000/Makefile b/build-Mingw/Makefile similarity index 100% rename from build-MSYS_NT-10.0-22000/Makefile rename to build-Mingw/Makefile diff --git a/build-MSYS_NT-10.0-22000/bake.make b/build-Mingw/bake.make similarity index 100% rename from build-MSYS_NT-10.0-22000/bake.make rename to build-Mingw/bake.make diff --git a/drivers/amalgamate/include/bake-amalgamate/bake_config.h b/drivers/amalgamate/include/bake-amalgamate/bake_config.h index a7e412e..91511ec 100644 --- a/drivers/amalgamate/include/bake-amalgamate/bake_config.h +++ b/drivers/amalgamate/include/bake-amalgamate/bake_config.h @@ -1,41 +1,41 @@ -/* - ) - (.) - .|. - | | - _.--| |--._ - .-'; ;`-'& ; `&. - \ & ; & &_/ - |"""---...---"""| - \ | | | | | | | / - `---.|.|.|.---' - - * This file is generated by bake.lang.c for your convenience. Headers of - * dependencies will automatically show up in this file. Include bake_config.h - * in your main project file. Do not edit! */ - -#ifndef BAKE_AMALGAMATE_BAKE_CONFIG_H -#define BAKE_AMALGAMATE_BAKE_CONFIG_H - -/* Headers of public dependencies */ -#ifdef __BAKE__ -#include -#endif - -/* Convenience macro for exporting symbols */ -#ifndef bake_amalgamate_STATIC -#if defined(bake_amalgamate_EXPORTS) && (defined(_MSC_VER) || defined(__MINGW32__)) - #define BAKE_AMALGAMATE_API __declspec(dllexport) -#elif defined(bake_amalgamate_EXPORTS) - #define BAKE_AMALGAMATE_API __attribute__((__visibility__("default"))) -#elif defined(_MSC_VER) - #define BAKE_AMALGAMATE_API __declspec(dllimport) -#else - #define BAKE_AMALGAMATE_API -#endif -#else - #define BAKE_AMALGAMATE_API -#endif - -#endif - +/* + ) + (.) + .|. + | | + _.--| |--._ + .-'; ;`-'& ; `&. + \ & ; & &_/ + |"""---...---"""| + \ | | | | | | | / + `---.|.|.|.---' + + * This file is generated by bake.lang.c for your convenience. Headers of + * dependencies will automatically show up in this file. Include bake_config.h + * in your main project file. Do not edit! */ + +#ifndef BAKE_AMALGAMATE_BAKE_CONFIG_H +#define BAKE_AMALGAMATE_BAKE_CONFIG_H + +/* Headers of public dependencies */ +#ifdef __BAKE__ +#include +#endif + +/* Convenience macro for exporting symbols */ +#ifndef bake_amalgamate_STATIC +#if defined(bake_amalgamate_EXPORTS) && (defined(_MSC_VER) || defined(__MINGW32__)) + #define BAKE_AMALGAMATE_API __declspec(dllexport) +#elif defined(bake_amalgamate_EXPORTS) + #define BAKE_AMALGAMATE_API __attribute__((__visibility__("default"))) +#elif defined(_MSC_VER) + #define BAKE_AMALGAMATE_API __declspec(dllimport) +#else + #define BAKE_AMALGAMATE_API +#endif +#else + #define BAKE_AMALGAMATE_API +#endif + +#endif + diff --git a/drivers/lang/c/build-MSYS_NT-10.0-22000/Makefile b/drivers/lang/c/build-Mingw/Makefile similarity index 100% rename from drivers/lang/c/build-MSYS_NT-10.0-22000/Makefile rename to drivers/lang/c/build-Mingw/Makefile diff --git a/drivers/lang/c/build-MSYS_NT-10.0-22000/bake_lang_c.make b/drivers/lang/c/build-Mingw/bake_lang_c.make similarity index 100% rename from drivers/lang/c/build-MSYS_NT-10.0-22000/bake_lang_c.make rename to drivers/lang/c/build-Mingw/bake_lang_c.make diff --git a/drivers/lang/c/run_premake.sh b/drivers/lang/c/run_premake.sh index aa4d9e6..ab69019 100755 --- a/drivers/lang/c/run_premake.sh +++ b/drivers/lang/c/run_premake.sh @@ -1,9 +1,9 @@ rm -rf build-Darwin rm -rf build-Linux -rm -rf build-MSYS_NT-10.0-22000 +rm -rf build-Mingw ../../../../premake5 --os=macosx gmake mv build build-Darwin ../../../../premake5 --os=linux gmake mv build build-Linux ../../../../premake5 --os=windows gmake2 -mv build build-MSYS_NT-10.0-22000 +mv build build-Mingw diff --git a/drivers/lang/c/src/gcc/driver.c b/drivers/lang/c/src/gcc/driver.c index e82af00..ae16fd8 100644 --- a/drivers/lang/c/src/gcc/driver.c +++ b/drivers/lang/c/src/gcc/driver.c @@ -105,7 +105,7 @@ void gcc_add_flags( /* Enable debugging code */ if (!config->debug) { ut_strbuf_appendstr(cmd, " -DNDEBUG"); - } else if (!is_emcc()) { + } else if (!is_emcc() && !is_mingw()) { ut_strbuf_appendstr(cmd, " -fstack-protector-all"); } @@ -584,7 +584,7 @@ void gcc_link_dynamic_binary( ut_strbuf_appendstr(&cmd, " -fno-stack-protector -shared"); /* Fail when symbols are not found in library */ - if (!is_clang(cpp) && !is_emcc()) { + if (!is_clang(cpp) && !is_emcc() && !is_mingw()) { ut_strbuf_appendstr(&cmd, " -z defs"); } } @@ -830,13 +830,9 @@ char* gcc_artefact_name( bool link_static = driver->get_attr_bool("static"); if (link_static) { - result = ut_asprintf("lib%s.a", id); + result = ut_asprintf(UT_OS_LIB_PREFIX"%s"UT_OS_STATIC_LIB_EXT, id); } else { - if (is_dylib(driver, project)) { - result = ut_asprintf("lib%s.dylib", id); - } else { - result = ut_asprintf("lib%s.so", id); - } + result = ut_asprintf(UT_OS_LIB_PREFIX"%s"UT_OS_LIB_EXT, id); } } } else { @@ -883,19 +879,34 @@ char *gcc_link_to_lib( full_path = NULL; } - /* Try .so */ + /* Try platform default */ if (full_path) { - char *so = ut_asprintf("%s/lib%s.so", full_path, lib_name); + char *so = ut_asprintf("%s/"UT_OS_LIB_PREFIX"%s"UT_OS_LIB_EXT, full_path, lib_name); if (ut_file_test(so)) { result = so; } } else { - char *so = ut_asprintf("lib%s.so", lib_name); + char *so = ut_asprintf(UT_OS_LIB_PREFIX"%s"UT_OS_LIB_EXT, lib_name); if (ut_file_test(so)) { result = so; } } + /* Try .so */ + if (!result) { + if (full_path) { + char *so = ut_asprintf("%s/lib%s.so", full_path, lib_name); + if (ut_file_test(so)) { + result = so; + } + } else { + char *so = ut_asprintf("lib%s.so", lib_name); + if (ut_file_test(so)) { + result = so; + } + } + } + /* Try .dylib */ if (!result && !strcmp(UT_OS_STRING, "darwin")) { if (full_path) { diff --git a/drivers/lang/c/src/main.c b/drivers/lang/c/src/main.c index dfc0ca6..1cc7bb1 100644 --- a/drivers/lang/c/src/main.c +++ b/drivers/lang/c/src/main.c @@ -58,7 +58,7 @@ bool is_cpp( static bool is_darwin(void) { - if (stricmp(UT_OS_STRING, "Darwin")) { + if (stricmp(UT_OS_STRING, "darwin")) { return false; } return true; @@ -67,7 +67,7 @@ bool is_darwin(void) static bool is_linux(void) { - if (stricmp(UT_OS_STRING, "Linux")) { + if (stricmp(UT_OS_STRING, "linux")) { return false; } return true; @@ -76,7 +76,15 @@ bool is_linux(void) static bool is_windows(void) { - if (stricmp(UT_OS_STRING, "Windows")) { + if (stricmp(UT_OS_STRING, "windows")) { + return false; + } + return true; +} + +static +bool is_msys(void) { + if (stricmp(UT_OS_STRING, "mingw")) { return false; } return true; @@ -186,6 +194,11 @@ bool is_msvc(void) { return is_compiler("cl.exe", 0); } +static +bool is_mingw(void) { + return is_compiler("gcc", 0) && is_msys(); +} + /* Is binary a dylib */ static bool is_dylib( diff --git a/drivers/lang/cpp/build-MSYS_NT-10.0-22000/Makefile b/drivers/lang/cpp/build-Mingw/Makefile similarity index 100% rename from drivers/lang/cpp/build-MSYS_NT-10.0-22000/Makefile rename to drivers/lang/cpp/build-Mingw/Makefile diff --git a/drivers/lang/cpp/build-MSYS_NT-10.0-22000/bake_lang_cpp.make b/drivers/lang/cpp/build-Mingw/bake_lang_cpp.make similarity index 100% rename from drivers/lang/cpp/build-MSYS_NT-10.0-22000/bake_lang_cpp.make rename to drivers/lang/cpp/build-Mingw/bake_lang_cpp.make diff --git a/drivers/lang/cpp/run_premake.sh b/drivers/lang/cpp/run_premake.sh index aa4d9e6..ab69019 100755 --- a/drivers/lang/cpp/run_premake.sh +++ b/drivers/lang/cpp/run_premake.sh @@ -1,9 +1,9 @@ rm -rf build-Darwin rm -rf build-Linux -rm -rf build-MSYS_NT-10.0-22000 +rm -rf build-Mingw ../../../../premake5 --os=macosx gmake mv build build-Darwin ../../../../premake5 --os=linux gmake mv build build-Linux ../../../../premake5 --os=windows gmake2 -mv build build-MSYS_NT-10.0-22000 +mv build build-Mingw diff --git a/drivers/test/include/bake-test/bake_config.h b/drivers/test/include/bake-test/bake_config.h index 15f152e..fff5435 100644 --- a/drivers/test/include/bake-test/bake_config.h +++ b/drivers/test/include/bake-test/bake_config.h @@ -1,46 +1,46 @@ -/* - ) - (.) - .|. - | | - _.--| |--._ - .-'; ;`-'& ; `&. - \ & ; & &_/ - |"""---...---"""| - \ | | | | | | | / - `---.|.|.|.---' - - * This file is generated by bake.lang.c for your convenience. Headers of - * dependencies will automatically show up in this file. Include bake_config.h - * in your main project file. Do not edit! */ - -#ifndef BAKE_TEST_BAKE_CONFIG_H -#define BAKE_TEST_BAKE_CONFIG_H - -/* Headers of public dependencies */ -/* No dependencies */ - -/* Headers of private dependencies */ -#ifdef bake_test_EXPORTS -#ifdef __BAKE__ -#include -#endif -#endif - -/* Convenience macro for exporting symbols */ -#ifndef bake_test_STATIC -#if defined(bake_test_EXPORTS) && (defined(_MSC_VER) || defined(__MINGW32__)) - #define BAKE_TEST_API __declspec(dllexport) -#elif defined(bake_test_EXPORTS) - #define BAKE_TEST_API __attribute__((__visibility__("default"))) -#elif defined(_MSC_VER) - #define BAKE_TEST_API __declspec(dllimport) -#else - #define BAKE_TEST_API -#endif -#else - #define BAKE_TEST_API -#endif - -#endif - +/* + ) + (.) + .|. + | | + _.--| |--._ + .-'; ;`-'& ; `&. + \ & ; & &_/ + |"""---...---"""| + \ | | | | | | | / + `---.|.|.|.---' + + * This file is generated by bake.lang.c for your convenience. Headers of + * dependencies will automatically show up in this file. Include bake_config.h + * in your main project file. Do not edit! */ + +#ifndef BAKE_TEST_BAKE_CONFIG_H +#define BAKE_TEST_BAKE_CONFIG_H + +/* Headers of public dependencies */ +/* No dependencies */ + +/* Headers of private dependencies */ +#ifdef bake_test_EXPORTS +#ifdef __BAKE__ +#include +#endif +#endif + +/* Convenience macro for exporting symbols */ +#ifndef bake_test_STATIC +#if defined(bake_test_EXPORTS) && (defined(_MSC_VER) || defined(__MINGW32__)) + #define BAKE_TEST_API __declspec(dllexport) +#elif defined(bake_test_EXPORTS) + #define BAKE_TEST_API __attribute__((__visibility__("default"))) +#elif defined(_MSC_VER) + #define BAKE_TEST_API __declspec(dllimport) +#else + #define BAKE_TEST_API +#endif +#else + #define BAKE_TEST_API +#endif + +#endif + diff --git a/run_premake.sh b/run_premake.sh index ac64a82..3759ba7 100755 --- a/run_premake.sh +++ b/run_premake.sh @@ -1,9 +1,9 @@ rm -rf build-Darwin rm -rf build-Linux -rm -rf build-MSYS_NT-10.0-22000 +rm -rf build-Mingw ../premake5 --os=macosx gmake mv build build-Darwin ../premake5 --os=linux gmake mv build build-Linux ../premake5 --os=windows gmake2 -mv build build-MSYS_NT-10.0-22000 +mv build build-Mingw diff --git a/src/setup.c b/src/setup.c index 90e3f19..10fe8b1 100644 --- a/src/setup.c +++ b/src/setup.c @@ -32,6 +32,15 @@ #endif #define BAKE_REPOSITORY "https://github.com/SanderMertens/bake" +#ifndef _WIN32 +#define BAKE_CMD_PREFIX "."UT_OS_PS +#else +#define BAKE_CMD_PREFIX "" +#endif + +#define BAKE_LIB_EXT UT_OS_LIB_EXT +#define BAKE_LIB_PREFIX UT_OS_LIB_PREFIX + static bool bake_in_path = false; /* Utility function for running a setup command */ @@ -70,7 +79,7 @@ int16_t cmd( return 0; } -#ifdef _WIN32 +#if defined(_WIN32) && !defined(__MINGW32__) int16_t bake_create_upgrade_script(void) { @@ -261,9 +270,14 @@ int16_t bake_create_script(bool local, bool nopass) cp_cmd = ut_asprintf("sudo cp %s %s/bake", script_path, UT_GLOBAL_BIN_PATH); mkdir_cmd = ut_asprintf("sudo mkdir -p %s", UT_GLOBAL_BIN_PATH); } - + +#ifdef __MINGW32__ + ut_mkdir("C:\\msys64\\usr\\local\\bin"); + ut_cp(script_path, "C:\\msys64\\usr\\local\\bin\\bake"); +#else ut_try( cmd(mkdir_cmd), NULL); ut_try( cmd(cp_cmd), NULL); +#endif bake_message(UT_OK, "done", "install bake script to '" UT_GLOBAL_BIN_PATH "'"); @@ -291,7 +305,7 @@ int16_t bake_build_make_project( { /* Install header files to include folder in bake environment */ char *install_cmd = ut_asprintf( - "."UT_OS_PS"bake" UT_OS_BIN_EXT " meta-install %s --id %s --package --includes include", + BAKE_CMD_PREFIX"bake" UT_OS_BIN_EXT " meta-install %s --id %s --package --includes include", path, id); ut_try( cmd(install_cmd), "failed to install '%s' include files", id); @@ -302,7 +316,7 @@ int16_t bake_build_make_project( char *make_cmd; /* Invoke project-specific and platform-specific makefile */ -#ifdef _WIN32 +#if defined(_WIN32) && !defined(__MINGW32__) char *cwd = ut_strdup(ut_cwd()); char *driver_path = ut_asprintf( "%s"UT_OS_PS"%s"UT_OS_PS"build-%s", ut_cwd(), path, UT_OS_STRING); @@ -315,7 +329,7 @@ int16_t bake_build_make_project( free(make_cmd); /* On Windows, restore the working directory to the bake repo root */ -#ifdef _WIN32 +#if defined(_WIN32) && !defined(__MINGW32__) ut_try( ut_chdir(cwd), NULL); free(cwd); #endif @@ -328,22 +342,22 @@ int16_t bake_build_make_project( /* Move binary from project root to bake bin path */ ut_try (ut_rename( - strarg("%s" UT_OS_PS UT_OS_LIB_PREFIX "%s" UT_OS_LIB_EXT, path, artefact), + strarg("%s" UT_OS_PS BAKE_LIB_PREFIX "%s" BAKE_LIB_EXT, path, artefact), strarg("%s" UT_OS_PS UT_OS_LIB_PREFIX "%s" UT_OS_LIB_EXT, bin_path, artefact)), "failed to move '%s' to project bin path", id); /* On Windows, also copy the .lib file */ -#ifdef _WIN32 +#if defined(_WIN32) ut_try(ut_rename( - strarg("%s" UT_OS_PS UT_OS_LIB_PREFIX "%s.lib", path, artefact), - strarg("%s" UT_OS_PS UT_OS_LIB_PREFIX "%s.lib", bin_path, artefact)), + strarg("%s" UT_OS_PS BAKE_LIB_PREFIX "%s.lib", path, artefact), + strarg("%s" UT_OS_PS BAKE_LIB_PREFIX "%s.lib", bin_path, artefact)), "failed to move '%s' to project bin path", id); #endif free(bin_path); /* Install binary to bake environment */ install_cmd = ut_asprintf( - "."UT_OS_PS"bake" UT_OS_BIN_EXT " meta-install %s --id %s --artefact %s --package", + BAKE_CMD_PREFIX"bake" UT_OS_BIN_EXT " meta-install %s --id %s --artefact %s --package", path, id, artefact); ut_try(cmd(install_cmd), "failed to install bake %s library", id); @@ -380,6 +394,10 @@ int16_t bake_setup( { bake_message(UT_LOG, "", "Bake setup, installing to ~/bake"); +#ifdef __MINGW32__ + nopass = true; // msys builds don't have sudo +#endif + /* Move working directory to the location of the invoked bake executable */ char *dir = ut_strdup(bake_cmd); char *last_elem = strrchr(dir, UT_OS_PS[0]); @@ -421,7 +439,7 @@ int16_t bake_setup( "failed to create global bake script, rerun setup with --local"); /* Copy bake executable to bake environment in user working directory */ - ut_try( ut_cp("." UT_OS_PS "bake" UT_OS_BIN_EXT, "~" UT_OS_PS "bake" UT_OS_PS BAKE_EXEC UT_OS_BIN_EXT), + ut_try( ut_cp(BAKE_CMD_PREFIX"bake" UT_OS_BIN_EXT, "~" UT_OS_PS "bake" UT_OS_PS BAKE_EXEC UT_OS_BIN_EXT), "failed to copy bake executable"); bake_message(UT_OK, "done", "copy bake executable"); @@ -431,7 +449,7 @@ int16_t bake_setup( bake_message(UT_OK, "done", "bake environment reset"); /* Install bake header files to bake environment */ - ut_try( cmd("."UT_OS_PS"bake" UT_OS_BIN_EXT " meta-install --id bake --includes include"), + ut_try( cmd(BAKE_CMD_PREFIX"bake" UT_OS_BIN_EXT " meta-install --id bake --includes include"), "failed to install bake include files"); bake_message(UT_OK, "done", "install bake include files"); @@ -446,19 +464,19 @@ int16_t bake_setup( "bake.lang.cpp", "bake_lang_cpp"), NULL); /* Build the bake test framework */ - ut_try(cmd("."UT_OS_PS"bake" UT_OS_BIN_EXT " rebuild drivers/test"), NULL); + ut_try(cmd(BAKE_CMD_PREFIX"bake" UT_OS_BIN_EXT " rebuild drivers/test"), NULL); bake_message(UT_OK, "done", "install test framework"); /* Build the amalgamation driver */ - ut_try(cmd("."UT_OS_PS"bake" UT_OS_BIN_EXT " rebuild drivers/amalgamate"), NULL); + ut_try(cmd(BAKE_CMD_PREFIX"bake" UT_OS_BIN_EXT " rebuild drivers/amalgamate"), NULL); bake_message(UT_OK, "done", "install amalgamate driver"); /* Build the bake libraries (predefined configurations) */ - ut_try(cmd("."UT_OS_PS"bake" UT_OS_BIN_EXT " rebuild libraries"), NULL); + ut_try(cmd(BAKE_CMD_PREFIX"bake" UT_OS_BIN_EXT " rebuild libraries"), NULL); bake_message(UT_OK, "done", "install library configuration packages"); /* Export the bake templates */ - ut_try(cmd("."UT_OS_PS"bake" UT_OS_BIN_EXT " rebuild templates"), NULL); + ut_try(cmd(BAKE_CMD_PREFIX"bake" UT_OS_BIN_EXT " rebuild templates"), NULL); bake_message(UT_OK, "done", "install template packages"); /* diff --git a/util/build-MSYS_NT-10.0-22000/Makefile b/util/build-Mingw/Makefile similarity index 100% rename from util/build-MSYS_NT-10.0-22000/Makefile rename to util/build-Mingw/Makefile diff --git a/util/build-MSYS_NT-10.0-22000/bake_util.make b/util/build-Mingw/bake_util.make similarity index 100% rename from util/build-MSYS_NT-10.0-22000/bake_util.make rename to util/build-Mingw/bake_util.make diff --git a/util/include/bake-util/os.h b/util/include/bake-util/os.h index 8805c09..dfc25c9 100644 --- a/util/include/bake-util/os.h +++ b/util/include/bake-util/os.h @@ -58,7 +58,22 @@ extern "C" { #error "Unsupported CPU architecture" #endif -#ifdef UT_OS_WINDOWS +#ifdef __MINGW32__ +#define UT_OS_STRING "Mingw" +#define UT_OS_LIB_EXT ".dll" +#define UT_OS_STATIC_LIB_EXT ".lib" +#define UT_OS_BIN_EXT ".exe" +#define UT_OS_SCRIPT_EXT ".bat" +#define UT_OS_LIB_PREFIX "" +#define UT_OS_PS "\\" +#define UT_ENV_HOME "HOME" +#define UT_ENV_LIBPATH "PATH" +#define UT_ENV_BINPATH "PATH" +#define UT_ENV_PATH_SEPARATOR ";" +#define UT_GLOBAL_BIN_PATH "/usr/local/bin" +#define UT_GLOBAL_LIB_PATH "/usr/local/lib" +#define UT_LINUX +#elif defined(UT_OS_WINDOWS) #define UT_OS_STRING "Windows" #define UT_OS_LIB_EXT ".dll" #define UT_OS_STATIC_LIB_EXT ".lib" diff --git a/util/run_premake.sh b/util/run_premake.sh index f9b8677..1a16324 100755 --- a/util/run_premake.sh +++ b/util/run_premake.sh @@ -1,9 +1,9 @@ rm -rf build-Darwin rm -rf build-Linux -rm -rf build-MSYS_NT-10.0-22000 +rm -rf build-Mingw ../../premake5 --os=macosx gmake mv build build-Darwin ../../premake5 --os=linux gmake mv build build-Linux ../../premake5 --os=windows gmake2 -mv build build-MSYS_NT-10.0-22000 +mv build build-Mingw diff --git a/util/src/os.c b/util/src/os.c index c3614bd..e0ccd28 100644 --- a/util/src/os.c +++ b/util/src/os.c @@ -30,6 +30,14 @@ char* ut_hostname(void) { bool ut_os_match( const char *os) { +#if defined(__MINGW32__) + if (!stricmp(os, "windows")) { + return true; + } else if (!stricmp(os, "msys")) { + return true; + } +#endif + if (!stricmp(os, UT_OS_STRING) || #if defined(__i386__) || defined(_M_IX86)