Skip to content

Commit

Permalink
predicate macros for building on Windows
Browse files Browse the repository at this point in the history
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 tulip-control/tulip-control#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
  • Loading branch information
slivingston committed Mar 26, 2020
1 parent 9ac957a commit 3287935
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#if defined(_WIN32) || defined(_WIN64)
#include <process.h>
#endif

#include "common.h"
#include "logging.h"
Expand Down Expand Up @@ -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') {
Expand Down

0 comments on commit 3287935

Please sign in to comment.