From 3287935d895c8847b0a3e989a2b8e2b173b46b23 Mon Sep 17 00:00:00 2001 From: "Scott C. Livingston" Date: Thu, 26 Mar 2020 15:46:57 -0700 Subject: [PATCH] predicate macros for building on Windows With this changeset, building gr1c for Windows is operational but not fully tested. To do it, first install a cross-compiler from the mingw-w64 project (http://mingw-w64.org/). Major GNU/Linux distributions have this available in respective package repositories; e.g., on Fedora or RedHat, `dnf install mingw64-gcc`, and on Ubuntu, `apt-get install gcc-mingw-w64`. Then, export CC=x86_64-w64-mingw32-gcc export LD="x86_64-w64-mingw32-ld -r" Then, for building CUDD, ./configure --prefix=`pwd`/../.. --host=x86_64-w64-mingw32 and for gr1c, make -e This is part of work for issue #34 and https://github.com/tulip-control/tulip-control/issues/197 * about _WIN32 and _WIN64 macros, https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=vs-2019 * about _spawnvp(), https://docs.microsoft.com/en-us/cpp/c-runtime-library/spawn-wspawn-functions?view=vs-2019 --- src/main.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/main.c b/src/main.c index b9fbe9f..64ad729 100644 --- a/src/main.c +++ b/src/main.c @@ -11,6 +11,9 @@ #include #include #include +#if defined(_WIN32) || defined(_WIN64) +#include +#endif #include "common.h" #include "logging.h" @@ -94,43 +97,55 @@ int main( int argc, char **argv ) /* Pass arguments after rg */ command_argv = malloc( sizeof(char *)*argc ); - command_argv[0] = strdup( "gr1c rg" ); + command_argv[0] = strdup( "\"gr1c rg\"" ); command_argv[argc-1] = NULL; for (i = 1; i < argc-1; i++) command_argv[i] = argv[i+1]; +#if defined(_WIN32) || defined(_WIN64) + return _spawnvp( _P_WAIT, "gr1c-rg", command_argv ); +#else if (execvp( "gr1c-rg", command_argv ) < 0) { perror( __FILE__ ", execvp" ); return -1; } +#endif } else if (!strncmp( argv[1], "patch", strlen( "patch" ) ) && argv[1][strlen("patch")] == '\0') { command_argv = malloc( sizeof(char *)*argc ); - command_argv[0] = strdup( "gr1c patch" ); + command_argv[0] = strdup( "\"gr1c patch\"" ); command_argv[argc-1] = NULL; for (i = 1; i < argc-1; i++) command_argv[i] = argv[i+1]; +#if defined(_WIN32) || defined(_WIN64) + return _spawnvp( _P_WAIT, "gr1c-patch", command_argv ); +#else if (execvp( "gr1c-patch", command_argv ) < 0) { perror( __FILE__ ", execvp" ); return -1; } +#endif } else if (!strncmp( argv[1], "autman", strlen( "autman" ) ) && argv[1][strlen("autman")] == '\0') { command_argv = malloc( sizeof(char *)*argc ); - command_argv[0] = strdup( "gr1c autman" ); + command_argv[0] = strdup( "\"gr1c autman\"" ); command_argv[argc-1] = NULL; for (i = 1; i < argc-1; i++) command_argv[i] = argv[i+1]; +#if defined(_WIN32) || defined(_WIN64) + return _spawnvp( _P_WAIT, "gr1c-autman", command_argv ); +#else if (execvp( "gr1c-autman", command_argv ) < 0) { perror( __FILE__ ", execvp" ); return -1; } +#endif } else if (!strncmp( argv[1], "help", strlen( "help" ) ) && argv[1][strlen("help")] == '\0') {