From 14cd93911230bc2306d548eb7393f01a36d801b4 Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Fri, 22 Dec 2006 11:43:50 +0100 Subject: [PATCH] Make git compile under MinGW. These changes are courtesy Johannes Schindelin. --- Makefile | 24 +++++- builtin-count-objects.c | 4 + compat/mingw.c | 164 ++++++++++++++++++++++++++++++++++++++++ git-compat-util.h | 108 ++++++++++++++++++++++++-- help.c | 2 +- ident.c | 22 ++++++ path.c | 11 +++ 7 files changed, 324 insertions(+), 11 deletions(-) create mode 100644 compat/mingw.c diff --git a/Makefile b/Makefile index 963a8f64e9..64d7f49019 100644 --- a/Makefile +++ b/Makefile @@ -192,9 +192,8 @@ SCRIPTS = $(patsubst %.sh,%,$(SCRIPT_SH)) \ # ... and all the rest that could be moved out of bindir to gitexecdir PROGRAMS = \ - git-convert-objects$X git-fetch-pack$X git-fsck-objects$X \ + git-fetch-pack$X git-fsck-objects$X \ git-hash-object$X git-index-pack$X git-local-fetch$X \ - git-daemon$X \ git-merge-index$X git-mktag$X git-mktree$X git-patch-id$X \ git-peek-remote$X git-receive-pack$X \ git-send-pack$X git-shell$X \ @@ -203,7 +202,7 @@ PROGRAMS = \ git-update-server-info$X \ git-upload-pack$X git-verify-pack$X \ git-pack-redundant$X git-var$X \ - git-merge-tree$X git-imap-send$X \ + git-merge-tree$X \ git-merge-recursive$X \ $(EXTRA_PROGRAMS) @@ -412,6 +411,25 @@ ifeq ($(uname_S),IRIX64) # for now, build 32-bit version BASIC_LDFLAGS += -L/usr/lib32 endif +ifneq (,$(findstring MINGW,$(uname_S))) + SHELL_PATH = $(shell cd /bin && pwd -W)/sh + NO_MMAP=YesPlease + NO_PREAD=YesPlease + NO_OPENSSL=YesPlease + NO_CURL=YesPlease + NO_SYMLINK_HEAD=YesPlease + NO_IPV6=YesPlease + NO_ETC_PASSWD=YesPlease + NO_SETENV=YesPlease + NO_UNSETENV=YesPlease + NO_STRCASESTR=YesPlease + NO_STRLCPY=YesPlease + NO_ICONV=YesPlease + COMPAT_CFLAGS += -DNO_ETC_PASSWD -DNO_ST_BLOCKS + COMPAT_OBJS += compat/mingw.o + EXTLIBS += -lws2_32 + X = .exe +endif ifneq (,$(findstring arm,$(uname_M))) ARM_SHA1 = YesPlease endif diff --git a/builtin-count-objects.c b/builtin-count-objects.c index f5b22bb80e..a2df569a0d 100644 --- a/builtin-count-objects.c +++ b/builtin-count-objects.c @@ -44,7 +44,11 @@ static void count_objects(DIR *d, char *path, int len, int verbose, if (lstat(path, &st) || !S_ISREG(st.st_mode)) bad = 1; else +#ifndef NO_ST_BLOCKS (*loose_size) += st.st_blocks; +#else + (*loose_size) += (st.st_size+511)/512; +#endif } if (bad) { if (verbose) { diff --git a/compat/mingw.c b/compat/mingw.c new file mode 100644 index 0000000000..0f7077983f --- /dev/null +++ b/compat/mingw.c @@ -0,0 +1,164 @@ +#include +#include "../git-compat-util.h" + +int readlink(const char *path, char *buf, size_t bufsiz) +{ + errno = EINVAL; + return -1; +} + +int symlink(const char *oldpath, const char *newpath) +{ + errno = EFAULT; + return -1; +} + +int fchmod(int fildes, mode_t mode) +{ + errno = EBADF; + return -1; +} + +int lstat(const char *file_name, struct stat *buf) +{ + return stat(file_name, buf); +} + +/* missing: link, mkstemp, fchmod, getuid (?), gettimeofday */ +int socketpair(int d, int type, int protocol, int sv[2]) +{ + return -1; +} +int syslog(int type, char *bufp, ...) +{ + return -1; +} +unsigned int alarm(unsigned int seconds) +{ + return 0; +} +#include +int fork() +{ + return -1; +} +typedef int pid_t; +pid_t waitpid(pid_t pid, int *status, int options) +{ + errno = ECHILD; + return -1; +} + +int kill(pid_t pid, int sig) +{ + return -1; +} +int sigaction(int p1, const struct sigaction *p2, struct sigaction *p3) +{ + return -1; +} +int sigemptyset(sigset_t *p1) +{ + return -1; +} +int setitimer(int __which, const struct itimerval *__value, + struct itimerval *__ovalue) +{ + return -1; +} +unsigned int sleep (unsigned int __seconds) +{ + return 0; +} +const char *inet_ntop(int af, const void *src, + char *dst, size_t cnt) +{ + return NULL; +} +int mkstemp (char *__template) +{ + return -1; +} +int gettimeofday(struct timeval *tv, void *tz) +{ + return -1; +} +int pipe(int filedes[2]) +{ + return -1; +} + +int poll(struct pollfd *ufds, unsigned int nfds, int timeout) +{ + return -1; +} + +int fnmatch(const char *pattern, const char *string, int flags) +{ + return -1; +} + +int regcomp(regex_t *preg, const char *regex, int cflags) +{ + return -1; +} +size_t regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size) +{ + return 0; +} +void regfree(regex_t *preg) +{ +} + +int regexec(const regex_t *preg, const char *string, size_t nmatch, regmatch_t pmatch[], int eflags) +{ + return -1; +} + +#undef mkdir +int git_mkdir(const char *path, int mode) +{ + return mkdir(path); +} + +#include + +struct tm *gmtime_r(const time_t *timep, struct tm *result) +{ + memcpy(result, gmtime(timep), sizeof(struct tm)); + return result; +} + +struct tm *localtime_r(const time_t *timep, struct tm *result) +{ + memcpy(result, localtime(timep), sizeof(struct tm)); + return result; +} + +#undef getcwd +char *mingw_getcwd(char *pointer, int len) +{ + char *ret = getcwd(pointer, len); + if (!ret) + return ret; + if (pointer[0] != 0 && pointer[1] == ':') { + int i; + pointer[1] = pointer[0]; + pointer[0] = '/'; + for (i = 2; pointer[i]; i++) + /* Thanks, Bill. You'll burn in hell for that. */ + if (pointer[i] == '\\') + pointer[i] = '/'; + } + return ret; +} +const char *strptime(char *buf, const char *format, struct tm *tm) +{ + die("MinGW does not yet support strptime!"); +} +void sync(void) +{ +} +void openlog(const char *ident, int option, int facility) +{ +} diff --git a/git-compat-util.h b/git-compat-util.h index bf3ceb8027..2bdae6725d 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -35,21 +35,23 @@ #include #include #include -#include -#include -#include -#include +//#include +//#include +//#include +//#include #include #include -#include -#include -#include +//#include +//#include +//#include +#ifndef NO_ETC_PASSWD #include #include #include #undef _ALL_SOURCE /* AIX 5.3L defines a struct list with _ALL_SOURCE. */ #include #define _ALL_SOURCE 1 +#endif #ifndef NO_ICONV #include @@ -271,4 +273,96 @@ static inline int sane_case(int x, int high) return x; } +// MinGW + +#ifndef S_ISLNK +#define S_ISLNK(x) 0 +#define S_IFLNK 0 +#endif + +#ifndef S_ISGRP +#define S_ISGRP(x) 0 +#define S_IRGRP 0 +#define S_IWGRP 0 +#define S_IXGRP 0 +#define S_ISGID 0 +#define S_IROTH 0 +#define S_IXOTH 0 +#endif + +int readlink(const char *path, char *buf, size_t bufsiz); +int symlink(const char *oldpath, const char *newpath); +#define link symlink +int fchmod(int fildes, mode_t mode); +int lstat(const char *file_name, struct stat *buf); + +/* missing: link, mkstemp, fchmod, getuid (?), gettimeofday */ +int socketpair(int d, int type, int protocol, int sv[2]); +#define AF_UNIX 0 +#define SOCK_STREAM 0 +int syslog(int type, char *bufp, ...); +#define LOG_ERR 1 +#define LOG_INFO 2 +#define LOG_DAEMON 4 +unsigned int alarm(unsigned int seconds); +#include +int fork(); +typedef int pid_t; +pid_t waitpid(pid_t pid, int *status, int options); +#define WIFEXITED(x) 0 +#define WEXITSTATUS(x) 1 +#define WIFSIGNALED(x) -1 +#define WTERMSIG(x) 0 +#define WNOHANG 0 +#define SIGKILL 0 +#define SIGCHLD 0 +#define SIGALRM 0 +#define ECONNABORTED 0 + +int kill(pid_t pid, int sig); +unsigned int sleep (unsigned int __seconds); +const char *inet_ntop(int af, const void *src, + char *dst, size_t cnt); +int mkstemp (char *__template); +int gettimeofday(struct timeval *tv, void *tz); +int pipe(int filedes[2]); + +struct pollfd { + int fd; /* file descriptor */ + short events; /* requested events */ + short revents; /* returned events */ +}; +int poll(struct pollfd *ufds, unsigned int nfds, int timeout); +#define POLLIN 1 +#define POLLHUP 2 +int fnmatch(const char *pattern, const char *string, int flags); +#define FNM_PATHNAME 1 + +typedef int siginfo_t; +struct sigaction { + void (*sa_handler)(int); + void (*sa_sigaction)(int, siginfo_t *, void *); + sigset_t sa_mask; + int sa_flags; + void (*sa_restorer)(void); +}; +#define SA_RESTART 0 +#define ITIMER_REAL 0 + +struct itimerval { struct timeval it_interval, it_value; }; + +int git_mkdir(const char *path, int mode); +#define mkdir git_mkdir + +#include +struct tm *gmtime_r(const time_t *timep, struct tm *result); +struct tm *localtime_r(const time_t *timep, struct tm *result); +#define hstrerror strerror + +char *mingw_getcwd(char *pointer, int len); +#define getcwd mingw_getcwd + +#define setlinebuf(x) +#define fsync(x) + #endif diff --git a/help.c b/help.c index 341b9e370e..2f7ef39661 100644 --- a/help.c +++ b/help.c @@ -7,7 +7,7 @@ #include "builtin.h" #include "exec_cmd.h" #include "common-cmds.h" -#include +//#include /* most GUI terminals set COLUMNS (although some don't export it) */ static int term_columns(void) diff --git a/ident.c b/ident.c index 6ad8fedd60..83ce631a06 100644 --- a/ident.c +++ b/ident.c @@ -9,6 +9,8 @@ static char git_default_date[50]; +#ifndef NO_ETC_PASSWD + static void copy_gecos(struct passwd *w, char *name, int sz) { char *src, *dst; @@ -77,6 +79,8 @@ int setup_ident(void) return 0; } +#else /* NO_ETC_PASSWD */ + static int add_raw(char *buf, int size, int offset, const char *str) { int len = strlen(str); @@ -152,6 +156,13 @@ static int copy(char *buf, int size, int offset, const char *src) return offset; } +int setup_ident(void) +{ + return 0; +} + +#endif + static const char au_env[] = "GIT_AUTHOR_NAME"; static const char co_env[] = "GIT_COMMITTER_NAME"; static const char *env_hint = @@ -219,6 +230,8 @@ const char *git_committer_info(int error_on_no_name) error_on_no_name); } +#ifndef NO_ETC_PASSWD + void ignore_missing_committer_name() { /* If we did not get a name from the user's gecos entry then @@ -233,3 +246,12 @@ void ignore_missing_committer_name() strlcpy(git_default_name, pw->pw_name, sizeof(git_default_name)); } } + +#else + +void ignore_missing_committer_name() +{ + strcpy(git_default_name, "unknown"); +} + +#endif diff --git a/path.c b/path.c index c5d25a4b90..d66d6a1ec1 100644 --- a/path.c +++ b/path.c @@ -140,6 +140,8 @@ int validate_headref(const char *path) return -1; } +#ifndef NO_ETC_PASSWD + static char *user_path(char *buf, char *path, int sz) { struct passwd *pw; @@ -179,6 +181,15 @@ static char *user_path(char *buf, char *path, int sz) return buf; } +#else + +static char *user_path(char *buf, char *path, int sz) +{ + return getenv("HOME"); +} + +#endif + /* * First, one directory to try is determined by the following algorithm. *