diff options
author | Simon Howard | 2009-11-19 21:07:31 +0000 |
---|---|---|
committer | Simon Howard | 2009-11-19 21:07:31 +0000 |
commit | e62fdd771f01ef7b50fe3cb8f456eae5d7db3748 (patch) | |
tree | e5ff1d68bac51a9c9312554bf5f988b0a90a557d /setup | |
parent | 9ea3cb62c94b2f293cc5dbc95518b8312434e093 (diff) | |
download | chocolate-doom-e62fdd771f01ef7b50fe3cb8f456eae5d7db3748.tar.gz chocolate-doom-e62fdd771f01ef7b50fe3cb8f456eae5d7db3748.tar.bz2 chocolate-doom-e62fdd771f01ef7b50fe3cb8f456eae5d7db3748.zip |
Make chocolate-setup use its own location in the filesystem to find the
location of the chocolate-doom executable. Remove INSTALL_DIR define.
Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 1729
Diffstat (limited to 'setup')
-rw-r--r-- | setup/Makefile.am | 2 | ||||
-rw-r--r-- | setup/execute.c | 38 |
2 files changed, 37 insertions, 3 deletions
diff --git a/setup/Makefile.am b/setup/Makefile.am index 22bcb224..af80d525 100644 --- a/setup/Makefile.am +++ b/setup/Makefile.am @@ -1,7 +1,7 @@ gamesdir = $(prefix)/games -AM_CFLAGS = -I../textscreen -I../src -DINSTALL_DIR="\"$(gamesdir)\"" +AM_CFLAGS = -I../textscreen -I../src games_PROGRAMS = chocolate-setup diff --git a/setup/execute.c b/setup/execute.c index ae23bf2e..9672a334 100644 --- a/setup/execute.c +++ b/setup/execute.c @@ -55,7 +55,7 @@ #ifdef _WIN32 #define DOOM_BINARY PACKAGE_TARNAME ".exe" #else -#define DOOM_BINARY INSTALL_DIR "/" PACKAGE_TARNAME +#define DOOM_BINARY PACKAGE_TARNAME #endif #ifdef _WIN32 @@ -269,11 +269,41 @@ static int ExecuteCommand(const char *program, const char *arg) #else +// Given the specified program name, get the full path to the program, +// assuming that it is in the same directory as this program is. + +static char *GetFullExePath(const char *program) +{ + char *result; + char *sep; + unsigned int path_len; + + sep = strrchr(myargv[0], DIR_SEPARATOR); + + if (sep == NULL) + { + result = strdup(program); + } + else + { + path_len = sep - myargv[0] + 1; + + result = malloc(strlen(program) + path_len + 1); + + strncpy(result, myargv[0], path_len); + result[path_len] = '\0'; + + strcat(result, program); + } + + return result; +} + static int ExecuteCommand(const char *program, const char *arg) { pid_t childpid; int result; - const char *argv[] = { program, arg, NULL }; + const char *argv[3]; childpid = fork(); @@ -281,6 +311,10 @@ static int ExecuteCommand(const char *program, const char *arg) { // This is the child. Execute the command. + argv[0] = GetFullExePath(program); + argv[1] = arg; + argv[2] = NULL; + execv(argv[0], (char **) argv); exit(-1); |