~ chicken-core (chicken-5) 654ca18f5cfc1ea7daa3cf697b7300b0f400bee6


commit 654ca18f5cfc1ea7daa3cf697b7300b0f400bee6
Author:     Erik Falor (fadein) <ewfalor@gmail.com>
AuthorDate: Mon Aug 12 16:27:44 2013 -0600
Commit:     Mario Domenech Goulart <mario.goulart@gmail.com>
CommitDate: Mon Oct 28 08:46:51 2013 -0200

    Add support for AIX
    
    Signed-off-by: Peter Bex <peter.bex@xs4all.nl>
    Signed-off-by: Mario Domenech Goulart <mario.goulart@gmail.com>

diff --git a/Makefile.aix b/Makefile.aix
new file mode 100644
index 00000000..d4534994
--- /dev/null
+++ b/Makefile.aix
@@ -0,0 +1,114 @@
+# Makefile.aix - configuration for AIX -*- Makefile -*-
+#
+# Copyright (c) 2008-2013, The Chicken Team
+# Copyright (c) 2007, Felix L. Winkelmann
+# Copyright (c) 2013, Erik W. Falor
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following
+# conditions are met:
+#
+#   Redistributions of source code must retain the above copyright notice, this list of conditions and the following
+#     disclaimer.
+#   Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
+#     disclaimer in the documentation and/or other materials provided with the distribution.
+#   Neither the name of the author nor the names of its contributors may be used to endorse or promote
+#     products derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
+# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+# AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+ifneq ($(CONFIG),)
+include $(CONFIG)
+endif
+
+SRCDIR ?= ./
+
+# platform configuration
+
+ARCH ?= $(shell sh $(SRCDIR)/config-arch.sh)
+
+# options
+
+C_COMPILER = gcc
+C_COMPILER_OPTIONS ?= -fno-strict-aliasing -fwrapv -DHAVE_CHICKEN_CONFIG_H -maix64 -Os
+ifdef DEBUGBUILD
+C_COMPILER_OPTIMIZATION_OPTIONS ?= -g -Wall -Wno-unused
+else
+ifdef OPTIMIZE_FOR_SPEED
+C_COMPILER_OPTIMIZATION_OPTIONS ?= -O3 -fomit-frame-pointer
+else
+C_COMPILER_OPTIMIZATION_OPTIONS ?= -Os -fomit-frame-pointer
+endif
+endif
+
+CXX_COMPILER = g++
+
+LINKER_OPTIONS = -maix64 -Wl,-bsvr4 -Wl,-bbigtoc
+LINKER_LINK_SHARED_DLOADABLE_OPTIONS = -L. -shared
+LINKER_EXECUTABLE_OPTIONS = -L. -Wl,-R"$(RUNTIME_LINKER_PATH)"
+LINKER_LINK_SHARED_LIBRARY_OPTIONS = -shared
+
+LIBRARIAN_OPTIONS = -rv -X 64
+LIBRARIES = -lm -ldl
+NEEDS_RELINKING = yes
+USES_SONAME = yes
+
+# special files
+
+CHICKEN_CONFIG_H = chicken-config.h
+
+# select default and internal settings
+
+include $(SRCDIR)/defaults.make
+
+chicken-config.h: chicken-defaults.h
+	echo "/* GENERATED */" >$@
+	echo "#define HAVE_DIRENT_H 1" >>$@
+	echo "#define HAVE_DLFCN_H 1" >>$@
+	echo "#define HAVE_INTTYPES_H 1" >>$@
+	echo "#define HAVE_LIMITS_H 1" >>$@
+	echo "#define HAVE_LONG_LONG 1" >>$@
+	echo "#define HAVE_MEMMOVE 1" >>$@
+	echo "#define HAVE_MEMORY_H 1" >>$@
+	echo "#define HAVE_POSIX_POLL 1" >>$@
+	echo "#define HAVE_SIGACTION 1" >>$@
+	echo "#define HAVE_SIGSETJMP 1" >>$@
+	echo "#define HAVE_STDINT_H 1" >>$@
+	echo "#define HAVE_STDLIB_H 1" >>$@
+	echo "#define HAVE_STRERROR 1" >>$@
+	echo "#define HAVE_STRINGS_H 1" >>$@
+	echo "#define HAVE_STRING_H 1" >>$@
+	echo "#define HAVE_STRTOLL 1" >>$@
+	echo "#define HAVE_STRTOQ 0" >>$@
+	echo "#define HAVE_SYS_STAT_H 1" >>$@
+	echo "#define HAVE_SYS_TYPES_H 1" >>$@
+	echo "#define HAVE_UNISTD_H 1" >>$@
+	echo "#define HAVE_UNSIGNED_LONG_LONG 1" >>$@
+	echo "#define STDC_HEADERS 1" >>$@
+	echo "#define HAVE_ALLOCA 1" >>$@
+	echo "#define HAVE_ALLOCA_H 1" >>$@
+	echo "#define HAVE_GRP_H 1" >>$@
+	echo "#define HAVE_ERRNO_H 1" >>$@
+	echo "#define HAVE_GCVT 1" >>$@
+	echo "#define HAVE_SYSEXITS_H 1" >>$@
+	echo "#define C_STACK_GROWS_DOWNWARD 1" >>$@
+ifdef GCHOOKS
+	echo "#define C_GC_HOOKS" >>$@
+endif
+ifdef SYMBOLGC
+	echo "#define C_COLLECT_ALL_SYMBOLS" >>$@
+endif
+ifneq ($(HACKED_APPLY),)
+	echo "#define C_HACKED_APPLY" >>$@
+endif
+	cat chicken-defaults.h >>$@
+
+include $(SRCDIR)/rules.make
diff --git a/NEWS b/NEWS
index c28a9b3f..7fd5e04a 100644
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,9 @@
      implicitly depends on extras.  This may break programs which don't
      use modules and forgot to require ports but use procedures from it.
 
+- Build system
+  - CHICKEN can now be built on AIX (contributed by Erik Falor)
+
 4.8.2
 
 - Security fixes
diff --git a/README b/README
index 2a2929b5..a7289e17 100644
--- a/README
+++ b/README
@@ -416,6 +416,10 @@
 	    % showrev -p | grep 106950    # solaris 7
 	    % showrev -p | grep 109147    # solaris 8
 
+        AIX:
+
+	  - Currently, deployment mode is unsupported on AIX.
+
 	Mac OS X:
 
 	  - On 10.6 and 10.7, Chicken may incorrectly select a 32-bit build
diff --git a/chicken.h b/chicken.h
index cb9320ee..89b8cc44 100644
--- a/chicken.h
+++ b/chicken.h
@@ -653,9 +653,9 @@ static inline int isinf_ld (long double x)
 # define C_MACHINE_TYPE "ultrasparc"
 #elif defined(__sparc__)
 # define C_MACHINE_TYPE "sparc"
-#elif defined(__powerpc64__)
+#elif defined(__powerpc64__) || defined(_ARCH_PPC64)
 # define C_MACHINE_TYPE "ppc64"
-#elif defined(__ppc__) || defined(__powerpc__)
+#elif defined(__ppc__) || defined(__powerpc__) || defined(_ARCH_PPC)
 # define C_MACHINE_TYPE "ppc"
 #elif defined(_M_IX86) || defined(__i386__)
 # define C_MACHINE_TYPE "x86"
@@ -671,7 +671,7 @@ static inline int isinf_ld (long double x)
 
 #if defined(__CYGWIN__) || defined(__MINGW32__) || defined(_WIN32) || defined(__WINNT__)
 # define C_SOFTWARE_TYPE "windows"
-#elif defined(__unix__) || defined(C_XXXBSD)
+#elif defined(__unix__) || defined(C_XXXBSD) || defined(_AIX)
 # define C_SOFTWARE_TYPE "unix"
 #elif defined(ECOS)
 # define C_SOFTWARE_TYPE "ecos"
@@ -687,6 +687,8 @@ static inline int isinf_ld (long double x)
 # define C_BUILD_PLATFORM "mingw32"
 #elif defined(__clang__)
 # define C_BUILD_PLATFORM "clang"
+#elif defined(_AIX)
+# define C_BUILD_PLATFORM "aix"
 #elif defined(__GNUC__)
 # define C_BUILD_PLATFORM "gnu"
 #elif defined(__MWERKS__)
@@ -721,6 +723,8 @@ static inline int isinf_ld (long double x)
 # else
 #   define C_SOFTWARE_VERSION "sunos"
 # endif
+#elif defined(_AIX)
+# define C_SOFTWARE_VERSION "aix"
 #else
 # define C_SOFTWARE_VERSION "unknown"
 #endif
@@ -2951,7 +2955,7 @@ C_path_to_executable(C_char *fname)
     return buffer;
   }
   else return NULL;  
-# elif defined(__unix__) || defined(__unix) || defined(C_XXXBSD)
+# elif defined(__unix__) || defined(__unix) || defined(C_XXXBSD) || defined(_AIX)
   int i, j, k, l;
   C_char *path, *dname;
 
diff --git a/csc.scm b/csc.scm
index a54c14c9..1582e2de 100644
--- a/csc.scm
+++ b/csc.scm
@@ -70,6 +70,7 @@
 (define win mingw)
 (define netbsd (eq? (software-version) 'netbsd))
 (define cygwin (eq? (build-platform) 'cygwin))
+(define aix (eq? (build-platform) 'aix))
 
 (define elf
   (memq (software-version) '(linux netbsd freebsd solaris openbsd)))
@@ -271,6 +272,8 @@
 				 INSTALL_LIB_HOME
 				 TARGET_RUN_LIB_HOME)))
 		 "\"")) )
+		 (aix
+		  (list (conc "-Wl,-R\"" library-dir "\"")))
 	 (else
 	  (list (conc "-L\"" library-dir "\""))))
    (if (and deployed (eq? (software-version) 'freebsd))
diff --git a/distribution/manifest b/distribution/manifest
index 4d47e8a8..c16826ed 100644
--- a/distribution/manifest
+++ b/distribution/manifest
@@ -216,6 +216,7 @@ apply-hack.ppc.darwin.S
 apply-hack.ppc.sysv.S
 chicken.pdf
 Makefile
+Makefile.aix
 Makefile.linux
 Makefile.macosx
 Makefile.mingw
diff --git a/manual/Deployment b/manual/Deployment
index 61fd9321..dd1f8661 100644
--- a/manual/Deployment
+++ b/manual/Deployment
@@ -168,6 +168,8 @@ the same directory is supported on FreeBSD, OpenBSD and Solaris.
 NetBSD supports this from version 5.0 onwards - this is currently
 disabled in {{csc}} for this particular platform.
 
+On AIX, deployment is currently unsupported.
+
 === Deploying source code
 
 An alternative to deploying binaries is deployment as compiled
diff --git a/posixunix.scm b/posixunix.scm
index 0de95a78..7f6d739e 100644
--- a/posixunix.scm
+++ b/posixunix.scm
@@ -292,7 +292,7 @@ static C_TLS sigset_t C_sigset;
 
 #define C_ctime(n)          (C_secs = (n), ctime(&C_secs))
 
-#if defined(__SVR4) || defined(C_MACOSX)
+#if defined(__SVR4) || defined(C_MACOSX) || defined(_AIX)
 /* Seen here: http://lists.samba.org/archive/samba-technical/2002-November/025571.html */
 
 static time_t C_timegm(struct tm *t)
@@ -1600,7 +1600,7 @@ EOF
 
 (define local-timezone-abbreviation
   (foreign-lambda* c-string ()
-   "\n#if !defined(__CYGWIN__) && !defined(__SVR4) && !defined(__uClinux__) && !defined(__hpux__)\n"
+   "\n#if !defined(__CYGWIN__) && !defined(__SVR4) && !defined(__uClinux__) && !defined(__hpux__) && !defined(_AIX)\n"
    "time_t clock = time(NULL);"
    "struct tm *ltm = C_localtime(&clock);"
    "char *z = ltm ? (char *)ltm->tm_zone : 0;"
diff --git a/tcp.scm b/tcp.scm
index 8e058bc7..c3689ae9 100644
--- a/tcp.scm
+++ b/tcp.scm
@@ -160,7 +160,7 @@ EOF
     "struct sockaddr_in sa;"
     "unsigned char *ptr;"
     "unsigned int len = sizeof(struct sockaddr_in);"
-    "if(getpeername(s, (struct sockaddr *)&sa, ((unsigned int *)&len)) != 0) C_return(NULL);"
+    "if(getpeername(s, (struct sockaddr *)&sa, ((socklen_t *)&len)) != 0) C_return(NULL);"
     "ptr = (unsigned char *)&sa.sin_addr;"
     "sprintf(addr_buffer, \"%d.%d.%d.%d\", ptr[ 0 ], ptr[ 1 ], ptr[ 2 ], ptr[ 3 ]);"
     "C_return(addr_buffer);") )
diff --git a/tests/runtests.sh b/tests/runtests.sh
index 3c82d259..43dd3922 100755
--- a/tests/runtests.sh
+++ b/tests/runtests.sh
@@ -13,6 +13,13 @@ LD_LIBRARY_PATH=${TEST_DIR}/..
 LIBRARY_PATH=${TEST_DIR}/..:${LIBRARY_PATH}
 export DYLD_LIBRARY_PATH LD_LIBRARY_PATH LIBRARY_PATH
 
+case `uname` in
+	AIX)
+		DIFF_OPTS=-b ;;
+	*)
+		DIFF_OPTS=-bu ;;
+esac
+
 rm -fr test-repository
 mkdir -p test-repository
 
@@ -83,7 +90,7 @@ if test \! -f scrutiny.expected; then
     cp scrutiny.out scrutiny.expected
 fi
 
-diff -bu scrutiny.expected scrutiny.out
+diff $DIFF_OPTS scrutiny.expected scrutiny.out
 
 $compile scrutiny-tests-2.scm -A -scrutinize -analyze-only -ignore-repository -types $TYPESDB 2>scrutiny-2.out -verbose
 
@@ -96,7 +103,7 @@ if test \! -f scrutiny-2.expected; then
     cp scrutiny-2.out scrutiny-2.expected
 fi
 
-diff -bu scrutiny-2.expected scrutiny-2.out
+diff $DIFF_OPTS scrutiny-2.expected scrutiny-2.out
 
 $compile scrutiny-tests-3.scm -specialize -block -ignore-repository -types $TYPESDB
 ./a.out
@@ -152,10 +159,10 @@ $interpret -s reader-tests.scm
 
 echo "======================================== dynamic-wind tests ..."
 $interpret -s dwindtst.scm >dwindtst.out
-diff -bu dwindtst.expected dwindtst.out
+diff $DIFF_OPTS dwindtst.expected dwindtst.out
 $compile dwindtst.scm
 ./a.out >dwindtst.out
-diff -bu dwindtst.expected dwindtst.out
+diff $DIFF_OPTS dwindtst.expected dwindtst.out
 echo "*** Skipping \"feeley-dynwind\" for now ***"
 # $interpret -s feeley-dynwind.scm
 
@@ -255,7 +262,7 @@ if test -n "$MSYSTEM"; then
     # the windows runtime library prints flonums differently
     tail r4rstest.log
 else
-    diff -bu r4rstest.out r4rstest.log
+    diff $DIFF_OPTS r4rstest.out r4rstest.log
 fi
 
 echo "======================================== syntax tests (r5rs_pitfalls) ..."
@@ -405,14 +412,18 @@ CHICKEN_REPOSITORY=$CHICKEN_REPOSITORY $CHICKEN_INSTALL -t local -l $TEST_DIR -r
  -csi ${TEST_DIR}/../csi
 CHICKEN_REPOSITORY=$CHICKEN_REPOSITORY $interpret -bnq rev-app.scm 1.0
 
-echo "======================================== deployment tests"
-mkdir rev-app
-CHICKEN_REPOSITORY=$CHICKEN_REPOSITORY $CHICKEN_INSTALL -t local -l $TEST_DIR reverser
-CHICKEN_REPOSITORY=$CHICKEN_REPOSITORY $compile2 -deploy rev-app.scm
-CHICKEN_REPOSITORY=$CHICKEN_REPOSITORY $CHICKEN_INSTALL -deploy -prefix rev-app -t local -l $TEST_DIR reverser
-unset LD_LIBRARY_PATH DYLD_LIBRARY_PATH CHICKEN_REPOSITORY
-rev-app/rev-app 1.1
-mv rev-app rev-app-2
-rev-app-2/rev-app 1.1
+if test $OS_NAME != AIX; then
+	echo "======================================== deployment tests"
+	mkdir rev-app
+	CHICKEN_REPOSITORY=$CHICKEN_REPOSITORY $CHICKEN_INSTALL -t local -l $TEST_DIR reverser
+	CHICKEN_REPOSITORY=$CHICKEN_REPOSITORY $compile2 -deploy rev-app.scm
+	CHICKEN_REPOSITORY=$CHICKEN_REPOSITORY $CHICKEN_INSTALL -deploy -prefix rev-app -t local -l $TEST_DIR reverser
+	unset LD_LIBRARY_PATH DYLD_LIBRARY_PATH CHICKEN_REPOSITORY
+	rev-app/rev-app 1.1
+	mv rev-app rev-app-2
+	rev-app-2/rev-app 1.1
+else
+	echo "Disabling deployment tests, as deployment is currently unsupported on AIX."
+fi
 
 echo "======================================== done."
Trap