From 380395d094b49834c3ec804407853fd6e81de702 Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Thu, 2 May 2013 20:26:08 +0100 Subject: mingw: rename WIN32 cpp macro to GIT_WINDOWS_NATIVE Throughout git, it is assumed that the WIN32 preprocessor symbol is defined on native Windows setups (mingw and msvc) and not on Cygwin. On Cygwin, most of the time git can pretend this is just another Unix machine, and Windows-specific magic is generally counterproductive. Unfortunately Cygwin *does* define the WIN32 symbol in some headers. Best to rely on a new git-specific symbol GIT_WINDOWS_NATIVE instead, defined as follows: #if defined(WIN32) && !defined(__CYGWIN__) # define GIT_WINDOWS_NATIVE #endif After this change, it should be possible to drop the CYGWIN_V15_WIN32API setting without any negative effect. [rj: %s/WINDOWS_NATIVE/GIT_WINDOWS_NATIVE/g ] Signed-off-by: Jonathan Nieder Signed-off-by: Ramsay Jones Signed-off-by: Junio C Hamano --- abspath.c | 2 +- compat/terminal.c | 4 ++-- compat/win32.h | 2 +- diff-no-index.c | 2 +- git-compat-util.h | 3 ++- help.c | 2 +- run-command.c | 10 +++++----- test-chmtime.c | 2 +- thread-utils.c | 2 +- 9 files changed, 15 insertions(+), 14 deletions(-) diff --git a/abspath.c b/abspath.c index 40cdc4621..64adbe2a1 100644 --- a/abspath.c +++ b/abspath.c @@ -216,7 +216,7 @@ const char *absolute_path(const char *path) const char *prefix_filename(const char *pfx, int pfx_len, const char *arg) { static char path[PATH_MAX]; -#ifndef WIN32 +#ifndef GIT_WINDOWS_NATIVE if (!pfx_len || is_absolute_path(arg)) return arg; memcpy(path, pfx, pfx_len); diff --git a/compat/terminal.c b/compat/terminal.c index 9b5e3d1bb..313897d58 100644 --- a/compat/terminal.c +++ b/compat/terminal.c @@ -3,7 +3,7 @@ #include "sigchain.h" #include "strbuf.h" -#if defined(HAVE_DEV_TTY) || defined(WIN32) +#if defined(HAVE_DEV_TTY) || defined(GIT_WINDOWS_NATIVE) static void restore_term(void); @@ -53,7 +53,7 @@ error: return -1; } -#elif defined(WIN32) +#elif defined(GIT_WINDOWS_NATIVE) #define INPUT_PATH "CONIN$" #define OUTPUT_PATH "CONOUT$" diff --git a/compat/win32.h b/compat/win32.h index 8ce91048d..a97e88075 100644 --- a/compat/win32.h +++ b/compat/win32.h @@ -2,7 +2,7 @@ #define WIN32_H /* common Win32 functions for MinGW and Cygwin */ -#ifndef WIN32 /* Not defined by Cygwin */ +#ifndef GIT_WINDOWS_NATIVE /* Not defined for Cygwin */ #include #endif diff --git a/diff-no-index.c b/diff-no-index.c index 74da65936..e66fdf33d 100644 --- a/diff-no-index.c +++ b/diff-no-index.c @@ -45,7 +45,7 @@ static int get_mode(const char *path, int *mode) if (!path || !strcmp(path, "/dev/null")) *mode = 0; -#ifdef _WIN32 +#ifdef GIT_WINDOWS_NATIVE else if (!strcasecmp(path, "nul")) *mode = 0; #endif diff --git a/git-compat-util.h b/git-compat-util.h index e955bb5e8..eeed50697 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -85,13 +85,14 @@ #define _NETBSD_SOURCE 1 #define _SGI_SOURCE 1 -#ifdef WIN32 /* Both MinGW and MSVC */ +#if defined(WIN32) && !defined(__CYGWIN__) /* Both MinGW and MSVC */ # if defined (_MSC_VER) # define _WIN32_WINNT 0x0502 # endif #define WIN32_LEAN_AND_MEAN /* stops windows.h including winsock.h */ #include #include +#define GIT_WINDOWS_NATIVE #endif #include diff --git a/help.c b/help.c index 02ba04331..3d70d7a3f 100644 --- a/help.c +++ b/help.c @@ -106,7 +106,7 @@ static int is_executable(const char *name) !S_ISREG(st.st_mode)) return 0; -#if defined(WIN32) || defined(__CYGWIN__) +#if defined(GIT_WINDOWS_NATIVE) || defined(__CYGWIN__) #if defined(__CYGWIN__) if ((st.st_mode & S_IXUSR) == 0) #endif diff --git a/run-command.c b/run-command.c index 1b32a12a2..aece872e3 100644 --- a/run-command.c +++ b/run-command.c @@ -72,7 +72,7 @@ static inline void close_pair(int fd[2]) close(fd[1]); } -#ifndef WIN32 +#ifndef GIT_WINDOWS_NATIVE static inline void dup_devnull(int to) { int fd = open("/dev/null", O_RDWR); @@ -159,7 +159,7 @@ static const char **prepare_shell_cmd(const char **argv) die("BUG: shell command is empty"); if (strcspn(argv[0], "|&;<>()$`\\\"' \t\n*?[#~=%") != strlen(argv[0])) { -#ifndef WIN32 +#ifndef GIT_WINDOWS_NATIVE nargv[nargc++] = SHELL_PATH; #else nargv[nargc++] = "sh"; @@ -182,7 +182,7 @@ static const char **prepare_shell_cmd(const char **argv) return nargv; } -#ifndef WIN32 +#ifndef GIT_WINDOWS_NATIVE static int execv_shell_cmd(const char **argv) { const char **nargv = prepare_shell_cmd(argv); @@ -193,7 +193,7 @@ static int execv_shell_cmd(const char **argv) } #endif -#ifndef WIN32 +#ifndef GIT_WINDOWS_NATIVE static int child_err = 2; static int child_notifier = -1; @@ -334,7 +334,7 @@ fail_pipe: trace_argv_printf(cmd->argv, "trace: run_command:"); fflush(NULL); -#ifndef WIN32 +#ifndef GIT_WINDOWS_NATIVE { int notify_pipe[2]; if (pipe(notify_pipe)) diff --git a/test-chmtime.c b/test-chmtime.c index 02b42badd..1cffa1265 100644 --- a/test-chmtime.c +++ b/test-chmtime.c @@ -87,7 +87,7 @@ int main(int argc, const char *argv[]) return -1; } -#ifdef WIN32 +#ifdef GIT_WINDOWS_NATIVE if (!(sb.st_mode & S_IWUSR) && chmod(argv[i], sb.st_mode | S_IWUSR)) { fprintf(stderr, "Could not make user-writable %s: %s", diff --git a/thread-utils.c b/thread-utils.c index 7f4b76a95..97396a75a 100644 --- a/thread-utils.c +++ b/thread-utils.c @@ -24,7 +24,7 @@ int online_cpus(void) long ncpus; #endif -#ifdef _WIN32 +#ifdef GIT_WINDOWS_NATIVE SYSTEM_INFO info; GetSystemInfo(&info); -- cgit v1.2.1 From 83ff1da3e81824eebf0425ad9200248ea7205c35 Mon Sep 17 00:00:00 2001 From: Ramsay Jones Date: Thu, 2 May 2013 20:29:04 +0100 Subject: cygwin: Remove the CYGWIN_V15_WIN32API build variable Commit 380a4d92 ("Update cygwin.c for new mingw-64 win32 api headers", 11-11-2012) solved an header include order problem on cygwin 1.7 when using the new mingw-64 WIN32 API headers. The solution involved using a new build variable (V15_MINGW_HEADERS) to conditionally compile the cygwin.c source file to use an include order appropriate for the old and new header files. (The build variable was later renamed in commit 9fca6cff to CYGWIN_V15_WIN32API). The include order used for cygwin 1.7 includes the "win32.h" header before "../git-compat-util.h". This order was problematic on cygwin 1.5, since it lead to the WIN32 symbol being defined along with the inclusion of some WIN32 API headers (e.g. ) which cause compilation errors. The header include order problem on cygwin 1.5 has since been fixed (see commit "mingw: rename WIN32 cpp macro to GIT_WINDOWS_NATIVE"), so we can now remove the conditional compilation along with the associated CYGWIN_V15_WIN32API build variable. Signed-off-by: Ramsay Jones Signed-off-by: Junio C Hamano --- Makefile | 7 ------- compat/cygwin.c | 5 ----- config.mak.uname | 1 - 3 files changed, 13 deletions(-) diff --git a/Makefile b/Makefile index 0f931a203..32c49ba16 100644 --- a/Makefile +++ b/Makefile @@ -290,10 +290,6 @@ all:: # # Define NO_REGEX if you have no or inferior regex support in your C library. # -# Define CYGWIN_V15_WIN32API if you are using Cygwin v1.7.x but are not -# using the current w32api packages. The recommended approach, however, -# is to update your installation if compilation errors occur. -# # Define HAVE_DEV_TTY if your system can open /dev/tty to interact with the # user. # @@ -1449,9 +1445,6 @@ ifdef NO_REGEX COMPAT_CFLAGS += -Icompat/regex COMPAT_OBJS += compat/regex/regex.o endif -ifdef CYGWIN_V15_WIN32API - COMPAT_CFLAGS += -DCYGWIN_V15_WIN32API -endif ifdef USE_NED_ALLOCATOR COMPAT_CFLAGS += -Icompat/nedmalloc diff --git a/compat/cygwin.c b/compat/cygwin.c index 871b41d23..91ce5d4c7 100644 --- a/compat/cygwin.c +++ b/compat/cygwin.c @@ -1,14 +1,9 @@ #define CYGWIN_C #define WIN32_LEAN_AND_MEAN -#ifdef CYGWIN_V15_WIN32API -#include "../git-compat-util.h" -#include "win32.h" -#else #include #include #include "win32.h" #include "../git-compat-util.h" -#endif #include "../cache.h" /* to read configuration */ /* diff --git a/config.mak.uname b/config.mak.uname index d78fd3df5..28aa239be 100644 --- a/config.mak.uname +++ b/config.mak.uname @@ -158,7 +158,6 @@ ifeq ($(uname_O),Cygwin) NO_SYMLINK_HEAD = YesPlease NO_IPV6 = YesPlease OLD_ICONV = UnfortunatelyYes - CYGWIN_V15_WIN32API = YesPlease endif NO_THREAD_SAFE_PREAD = YesPlease NEEDS_LIBICONV = YesPlease -- cgit v1.2.1