summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile8
-rw-r--r--src/tools/lcc/etc/lcc.c68
2 files changed, 67 insertions, 9 deletions
diff --git a/Makefile b/Makefile
index c533f577..47bd645d 100644
--- a/Makefile
+++ b/Makefile
@@ -172,11 +172,13 @@ LIBSDIR=$(MOUNT_DIR)/libs
MASTERDIR=$(MOUNT_DIR)/master
TEMPDIR=/tmp
+bin_path=$(shell which $(1) 2> /dev/null)
+
# We won't need this if we only build the server
ifneq ($(BUILD_CLIENT),0)
# set PKG_CONFIG_PATH to influence this, e.g.
# PKG_CONFIG_PATH=/opt/cross/i386-mingw32msvc/lib/pkgconfig
- ifeq ($(shell which pkg-config > /dev/null; echo $$?),0)
+ ifneq ($(call bin_path, pkg-config),)
CURL_CFLAGS=$(shell pkg-config --silence-errors --cflags libcurl)
CURL_LIBS=$(shell pkg-config --silence-errors --libs libcurl)
OPENAL_CFLAGS=$(shell pkg-config --silence-errors --cflags openal)
@@ -187,7 +189,7 @@ ifneq ($(BUILD_CLIENT),0)
endif
# Use sdl-config if all else fails
ifeq ($(SDL_CFLAGS),)
- ifeq ($(shell which sdl-config > /dev/null; echo $$?),0)
+ ifneq ($(call bin_path, sdl-config),)
SDL_CFLAGS=$(shell sdl-config --cflags)
SDL_LIBS=$(shell sdl-config --libs)
endif
@@ -429,7 +431,7 @@ ifeq ($(PLATFORM),mingw32)
# Some MinGW installations define CC to cc, but don't actually provide cc,
# so explicitly use gcc instead (which is the only option anyway)
- ifeq ($(shell which $(CC) > /dev/null; echo $$?),1)
+ ifeq ($(call bin_path, $(CC)),)
CC=gcc
endif
diff --git a/src/tools/lcc/etc/lcc.c b/src/tools/lcc/etc/lcc.c
index 13ed690b..a1688525 100644
--- a/src/tools/lcc/etc/lcc.c
+++ b/src/tools/lcc/etc/lcc.c
@@ -217,14 +217,74 @@ char *basename(char *name) {
#ifdef WIN32
#include <process.h>
+
+static char *escapeDoubleQuotes(const char *string) {
+ int stringLength = strlen(string);
+ int bufferSize = stringLength + 1;
+ int i, j;
+ char *newString;
+
+ if (string == NULL)
+ return NULL;
+
+ for (i = 0; i < stringLength; i++) {
+ if (string[i] == '"')
+ bufferSize++;
+ }
+
+ newString = (char*)malloc(bufferSize);
+
+ if (newString == NULL)
+ return NULL;
+
+ for (i = 0, j = 0; i < stringLength; i++) {
+ if (string[i] == '"')
+ newString[j++] = '\\';
+
+ newString[j++] = string[i];
+ }
+
+ newString[j] = '\0';
+
+ return newString;
+}
+
+static int spawn(const char *cmdname, char **argv) {
+ int argc = 0;
+ char **newArgv = argv;
+ int i;
+ intptr_t exitStatus;
+
+ // _spawnvp removes double quotes from arguments, so we
+ // have to escape them manually
+ while (*newArgv++ != NULL)
+ argc++;
+
+ newArgv = (char **)malloc(sizeof(char*) * (argc + 1));
+
+ for (i = 0; i < argc; i++)
+ newArgv[i] = escapeDoubleQuotes(argv[i]);
+
+ newArgv[argc] = NULL;
+
+ exitStatus = _spawnvp(_P_WAIT, cmdname, (const char *const *)newArgv);
+
+ for (i = 0; i < argc; i++)
+ free(newArgv[i]);
+
+ free(newArgv);
+ return exitStatus;
+}
+
#else
+
#define _P_WAIT 0
#ifndef __sun
extern int fork(void);
#endif
extern int wait(int *);
-static int _spawnvp(int mode, const char *cmdname, char *argv[]) {
+static int spawn(const char *cmdname, char **argv) {
int pid, n, status;
switch (pid = fork()) {
@@ -292,11 +352,7 @@ static int callsys(char **av) {
fprintf(stderr, "\n");
}
if (verbose < 2)
-#ifndef WIN32
- status = _spawnvp(_P_WAIT, executable, argv);
-#else
- status = _spawnvp(_P_WAIT, executable, (const char* const*)argv);
-#endif
+ status = spawn(executable, argv);
if (status == -1) {
fprintf(stderr, "%s: ", progname);
perror(argv[0]);