Make git compile under MinGW.

These changes are courtesy Johannes Schindelin.
This commit is contained in:
Johannes Sixt
2006-12-22 11:43:50 +01:00
parent 9983977758
commit 14cd939112
7 changed files with 324 additions and 11 deletions

View File

@@ -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

View File

@@ -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) {

164
compat/mingw.c Normal file
View File

@@ -0,0 +1,164 @@
#include <stdint.h>
#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 <winsock2.h>
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 <time.h>
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)
{
}

View File

@@ -35,21 +35,23 @@
#include <sys/time.h>
#include <time.h>
#include <signal.h>
#include <sys/wait.h>
#include <fnmatch.h>
#include <sys/poll.h>
#include <sys/socket.h>
//#include <sys/wait.h>
//#include <fnmatch.h>
//#include <sys/poll.h>
//#include <sys/socket.h>
#include <assert.h>
#include <regex.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
//#include <netinet/in.h>
//#include <netinet/tcp.h>
//#include <arpa/inet.h>
#ifndef NO_ETC_PASSWD
#include <netdb.h>
#include <pwd.h>
#include <stdint.h>
#undef _ALL_SOURCE /* AIX 5.3L defines a struct list with _ALL_SOURCE. */
#include <grp.h>
#define _ALL_SOURCE 1
#endif
#ifndef NO_ICONV
#include <iconv.h>
@@ -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 <winsock2.h>
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 <time.h>
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

2
help.c
View File

@@ -7,7 +7,7 @@
#include "builtin.h"
#include "exec_cmd.h"
#include "common-cmds.h"
#include <sys/ioctl.h>
//#include <sys/ioctl.h>
/* most GUI terminals set COLUMNS (although some don't export it) */
static int term_columns(void)

22
ident.c
View File

@@ -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

11
path.c
View File

@@ -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.
*