Commit 96ef3d84629ef72fb662d95abbab3de634921678

Chris Young 2012-06-13T23:16:14

Make this more generic and mergeable. Needs AmigaOS.cmake now from CMake package at OS4Depot, or contents below: --8<-- SET(AMIGA 1) SET(CMAKE_SHARED_LIBRARY_C_FLAGS "-fPIC") SET(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-shared") --8<--

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 969a5e6..fdc103e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -11,7 +11,7 @@
 # Install:
 # > cmake --build . --target install
 
-SET(CMAKE_SYSTEM_NAME "Generic")
+SET(CMAKE_SYSTEM_NAME "AmigaOS")
 
 PROJECT(libgit2 C)
 CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
@@ -23,8 +23,10 @@ STRING(REGEX REPLACE "^.*LIBGIT2_VERSION \"[0-9]+\\.([0-9]+).*$" "\\1" LIBGIT2_V
 STRING(REGEX REPLACE "^.*LIBGIT2_VERSION \"[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" LIBGIT2_VERSION_REV "${GIT2_HEADER}")
 SET(LIBGIT2_VERSION_STRING "${LIBGIT2_VERSION_MAJOR}.${LIBGIT2_VERSION_MINOR}.${LIBGIT2_VERSION_REV}")
 
-# Uncomment out the line below to use PowerPC SHA1
-SET(SHA1_TYPE "ppc")
+IF (AMIGA)
+	# Default AmigaOS to use the PowerPC SHA1
+	SET(SHA1_TYPE "ppc")
+ENDIF()
 
 # Find required dependencies
 INCLUDE_DIRECTORIES(src include deps/http-parser)
@@ -33,15 +35,15 @@ FILE(GLOB SRC_HTTP deps/http-parser/*.c)
 
 # Specify sha1 implementation
 IF (SHA1_TYPE STREQUAL "ppc")
-    ADD_DEFINITIONS(-DPPC_SHA1)
-    FILE(GLOB SRC_SHA1 src/ppc/*.c src/ppc/*.S)
+	ADD_DEFINITIONS(-DPPC_SHA1)
+	FILE(GLOB SRC_SHA1 src/ppc/*.c src/ppc/*.S)
 ELSE ()
 	SET (SRC_SHA1)
 ENDIF()
 
 IF (NOT WIN32)
 	FIND_PACKAGE(ZLIB)
-	IF (CMAKE_SYSTEM_NAME MATCHES "Generic")
+	IF (CMAKE_SYSTEM_NAME STREQUAL "AmigaOS")
 		INCLUDE_DIRECTORIES(deps/regex)
 		SET(SRC_REGEX deps/regex/regex.c)
 	ENDIF()
@@ -68,7 +70,7 @@ SET(INSTALL_INC include CACHE PATH "Where to install headers to.")
 # Build options
 OPTION (BUILD_SHARED_LIBS "Build Shared Library (OFF for Static)" OFF)
 OPTION (THREADSAFE "Build libgit2 as threadsafe" OFF)
-OPTION (BUILD_CLAR "Build Tests using the Clar suite" ON)
+OPTION (BUILD_CLAR "Build Tests using the Clar suite" OFF)
 OPTION (BUILD_EXAMPLES "Build library usage example apps" OFF)
 OPTION (TAGS "Generate tags" OFF)
 OPTION (PROFILE "Generate profiling information" OFF)
@@ -106,14 +108,11 @@ IF (NOT CMAKE_BUILD_TYPE)
 	SET(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
 ENDIF ()
 
-IF (CMAKE_SYSTEM_NAME MATCHES "Generic")
-ELSE ()
-	FIND_PACKAGE(OpenSSL)
-	IF (OPENSSL_FOUND)
-	  ADD_DEFINITIONS(-DGIT_SSL)
-	  INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR})
-	  SET(SSL_LIBRARIES ${OPENSSL_LIBRARIES})
-	ENDIF()
+FIND_PACKAGE(OpenSSL)
+IF (OPENSSL_FOUND)
+  ADD_DEFINITIONS(-DGIT_SSL)
+  INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR})
+  SET(SSL_LIBRARIES ${OPENSSL_LIBRARIES})
 ENDIF()
 
 IF (THREADSAFE)
@@ -133,8 +132,11 @@ FILE(GLOB SRC_H include/git2/*.h)
 IF (WIN32 AND NOT CYGWIN)
 	ADD_DEFINITIONS(-DWIN32 -D_DEBUG -D_WIN32_WINNT=0x0501)
 	FILE(GLOB SRC src/*.c src/transports/*.c src/xdiff/*.c src/win32/*.c src/compat/*.c)
-ELSEIF (CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS|Generic)")
+ELSEIF (CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)")
 	FILE(GLOB SRC src/*.c src/transports/*.c src/xdiff/*.c src/unix/*.c src/compat/*.c)
+ELSEIF (AMIGA)
+	ADD_DEFINITIONS(-DNO_ADDRINFO -DNO_READDIR_R)
+	FILE(GLOB SRC src/*.c src/transports/*.c src/xdiff/*.c src/amiga/*.c src/compat/*.c)
 ELSE()
 	FILE(GLOB SRC src/*.c src/transports/*.c src/xdiff/*.c src/unix/*.c)
 ENDIF ()
diff --git a/src/amiga/map.c b/src/amiga/map.c
new file mode 100755
index 0000000..d36bcbc
--- /dev/null
+++ b/src/amiga/map.c
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2009-2012 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
+#include <git2/common.h>
+
+#ifndef GIT_WIN32
+
+#include "posix.h"
+#include "map.h"
+#include <errno.h>
+
+int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offset)
+{
+	int mprot = 0;
+	int mflag = 0;
+
+	GIT_MMAP_VALIDATE(out, len, prot, flags);
+
+	out->data = NULL;
+	out->len = 0;
+
+	if ((prot & GIT_PROT_WRITE) && ((flags & GIT_MAP_TYPE) == GIT_MAP_SHARED)) {
+		printf("Trying to map shared-writeable file!!!\n");
+	}
+
+	if(out->data = malloc(len)) {
+		p_lseek(fd, offset, SEEK_SET);
+		p_read(fd, out->data, len);
+	}
+
+	if (!out->data || out->data == MAP_FAILED) {
+		giterr_set(GITERR_OS, "Failed to mmap. Could not write data");
+		return -1;
+	}
+
+	out->len = len;
+
+	return 0;
+}
+
+int p_munmap(git_map *map)
+{
+	assert(map != NULL);
+	free(map->data);
+
+	return 0;
+}
+
+#endif
+
diff --git a/src/netops.c b/src/netops.c
index 6808c8e..11295c5 100644
--- a/src/netops.c
+++ b/src/netops.c
@@ -376,7 +376,7 @@ static int ssl_setup(git_transport *t, const char *host)
 
 int gitno_connect(git_transport *t, const char *host, const char *port)
 {
-#ifndef __amigaos4__
+#ifndef NO_ADDRINFO
 	struct addrinfo *info = NULL, *p;
 	struct addrinfo hints;
 #else
@@ -388,7 +388,7 @@ int gitno_connect(git_transport *t, const char *host, const char *port)
 #endif
 	int ret;
 	GIT_SOCKET s = INVALID_SOCKET;
-#ifndef __amigaos4__
+#ifndef NO_ADDRINFO
 	memset(&hints, 0x0, sizeof(struct addrinfo));
 	hints.ai_family = AF_UNSPEC;
 	hints.ai_socktype = SOCK_STREAM;
@@ -407,7 +407,7 @@ int gitno_connect(git_transport *t, const char *host, const char *port)
 		port_num = atol(port);
 #endif
 
-#ifndef __amigaos4__
+#ifndef NO_ADDRINFO
 	for (p = info; p != NULL; p = p->ai_next) {
 		s = socket(p->ai_family, p->ai_socktype, p->ai_protocol);
 #else
@@ -418,7 +418,7 @@ int gitno_connect(git_transport *t, const char *host, const char *port)
 			net_set_error("error creating socket");
 			break;
 		}
-#ifndef __amigaos4__
+#ifndef NO_ADDRINFO
 		if (connect(s, p->ai_addr, (socklen_t)p->ai_addrlen) == 0)
 #else
 		memcpy(&saddr.sin_addr, hent->h_addr_list[p], hent->h_length);
@@ -435,7 +435,7 @@ int gitno_connect(git_transport *t, const char *host, const char *port)
 
 	/* Oops, we couldn't connect to any address */
 	if (s == INVALID_SOCKET &&
-#ifndef __amigaos4__
+#ifndef NO_ADDRINFO
 		p == NULL) {
 #else
 		hent->h_addr_list[p] == NULL) {
@@ -445,7 +445,7 @@ int gitno_connect(git_transport *t, const char *host, const char *port)
 	}
 
 	t->socket = s;
-#ifndef __amigaos4__
+#ifndef NO_ADDRINFO
 	freeaddrinfo(info);
 #endif
 	if (t->encrypt && ssl_setup(t, host) < 0)
diff --git a/src/path.c b/src/path.c
index eb9bc06..596dad1 100644
--- a/src/path.c
+++ b/src/path.c
@@ -517,7 +517,7 @@ int git_path_direach(
 	de_buf = git__malloc(sizeof(struct dirent));
 #endif
 
-#ifdef __amigaos4__
+#ifdef NO_READDIR_R
 	while (de = readdir(dir)) {
 #else
 	while (p_readdir_r(dir, de_buf, de) == 0 && de != NULL) {
diff --git a/src/posix.h b/src/posix.h
index 8e8b394..35118f9 100644
--- a/src/posix.h
+++ b/src/posix.h
@@ -74,7 +74,7 @@ typedef SOCKET GIT_SOCKET;
 #	include "unix/posix.h"
 #endif
 
-#ifndef __amigaos4__
+#ifndef NO_READDIR_R
 #define p_readdir_r(d,e,r) readdir_r(d,e,&r)
 #else
 #define p_readdir_r(d,e,r) r = readdir(d)
diff --git a/src/unix/map.c b/src/unix/map.c
index b04e95a..9dcae58 100644
--- a/src/unix/map.c
+++ b/src/unix/map.c
@@ -9,9 +9,7 @@
 #ifndef GIT_WIN32
 
 #include "map.h"
-#ifndef __amigaos4__
 #include <sys/mman.h>
-#endif
 #include <errno.h>
 
 int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offset)
@@ -24,7 +22,6 @@ int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offs
 	out->data = NULL;
 	out->len = 0;
 
-#ifndef __amigaos4__
 	if (prot & GIT_PROT_WRITE)
 		mprot = PROT_WRITE;
 	else if (prot & GIT_PROT_READ)
@@ -36,16 +33,6 @@ int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offs
 		mflag = MAP_PRIVATE;
 
 	out->data = mmap(NULL, len, mprot, mflag, fd, offset);
-#else
-	if ((prot & GIT_PROT_WRITE) && ((flags & GIT_MAP_TYPE) == GIT_MAP_SHARED)) {
-		printf("Trying to map shared-writeable file!!!\n");
-	}
-
-	if(out->data = malloc(len)) {
-		lseek(fd, offset, SEEK_SET);
-		p_read(fd, out->data, len);
-	}
-#endif
 
 	if (!out->data || out->data == MAP_FAILED) {
 		giterr_set(GITERR_OS, "Failed to mmap. Could not write data");
@@ -60,11 +47,8 @@ int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offs
 int p_munmap(git_map *map)
 {
 	assert(map != NULL);
-#ifndef __amigaos4__
 	munmap(map->data, map->len);
-#else
-	free(map->data);
-#endif
+
 	return 0;
 }