# as governed by the terms of the Lisp Lesser GNU Public License
# (http://opensource.franz.com/preamble.html), also known as the LLGPL.
-SUBDIRS:=
+SUBDIRS=
include ../Makefile.common
-.PHONY: distclean
-distclean: clean
- rm -f $(base).dylib $(base).dylib $(base).so $(base).o
-
-base=uffi-c-test-lib
+base=uffi-c-test
source=$(base).c
object=$(base).o
shared_lib=$(base).so
.PHONY: all
-all:
- echo "you need to specify a platform"
+all: $(shared_lib)
-linux: $(source) Makefile
- gcc -fPIC -DPIC -c $(source) -o $(object)
- gcc -shared $(object) -o $(shared_lib)
- #gcc -shared -Wl,-soname,uffi-c-test-lib $(object) -o $(shared_lib)
+$(shared_lib): $(source) Makefile
+ BASE=$(base) OBJECT=$(object) SOURCE=$(source) SHARED_LIB=$(shared_lib) sh make.sh
rm $(object)
-mac:
- cc -dynamic -c $(source) -o $(object)
- ld -bundle /usr/lib/bundle1.o -flat_namespace -undefined suppress -o $(base).dylib $(object)
- ld -bundle /usr/lib/bundle1.o -flat_namespace -undefined suppress /usr/lib/libz.dylib -o z.dylib
-
-mac-alt:
- gcc -bundle -c $(source) -o $(base).bundle
- ld -bundle /usr/lib/bundle1.o -flat_namespace -undefined suppress /usr/lib/libz.dylib -o z.bundle
-
-solaris:
- cc -KPIC -c $(source) -o $(object)
- cc -G $(object) -o $(shared_lib)
-
-aix-acl:
- gcc -c -D_BSD -D_NO_PROTO -D_NONSTD_TYPES -D_MBI=void $(source)
- make_shared -o $(shared_lib) $(object)
+.PHONY: distclean
+distclean: clean
+ rm -f $(base).dylib $(base).dylib $(base).so $(base).o
(unless (uffi:load-foreign-library
(uffi:find-foreign-library
- "uffi-c-test-lib"
+ "uffi-c-test"
(list (pathname-directory *load-truename*)
"/usr/lib/uffi/"))
:supporting-libraries '("c")
:module "uffi_tests")
- (warn "Unable to load uffi-c-test-lib library"))
+ (warn "Unable to load uffi-c-test library"))
--- /dev/null
+#!/bin/sh
+
+UNAME=`uname -a`
+LINUX=`expr "$UNAME" : '.*Linux.*'`
+DARWIN=`expr "$UNAME" : '.*Darwin.*'`
+SOLARIS=`expr "$UNAME" : '.*sun4u.*'`
+AIX=`expr "$UNAME" : '.*aix.*'`
+
+
+if [ $LINUX -ne 0 ]; then
+ gcc -fPIC -DPIC -c $SOURCE -o $OBJECT
+ gcc -shared $OBJECT -o $SHARED_LIB
+ #gcc -shared -Wl,-soname,uffi-c-test-lib $OBJECT -o $SHARED_LIB
+elif [ $DARWIN -ne 0 ]; then
+ cc -dynamic -c $SOURCE -o $OBJECT
+ ld -bundle /usr/lib/bundle1.o -flat_namespace -undefined suppress -o $BASE.dylib $OBJECT
+ ld -bundle /usr/lib/bundle1.o -flat_namespace -undefined suppress /usr/lib/libz.dylib -o z.dylib
+elif [ $SOLARIS -ne 0 ]; then
+ cc -KPIC -c $SOURCE -o $OBJECT
+ cc -G $OBJECT -o $SHARED_LIB
+elif [ $AIX -ne 0 ]; then
+ gcc -c -D_BSD -D_NO_PROTO -D_NONSTD_TYPES -D_MBI=void $SOURCE
+ make_shared -o $SHARED_LIB $OBJECT
+fi
+
+
+++ /dev/null
-/***************************************************************************
- * FILE IDENTIFICATION
- *
- * Name: c-test-fns.c
- * Purpose: Test functions in C for UFFI library
- * Programer: Kevin M. Rosenberg
- * Date Started: Mar 2002
- *
- * CVS Id: $Id$
- *
- * This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
- *
- * UFFI users are granted the rights to distribute and use this software
- * as governed by the terms of the Lisp Lesser GNU Public License
- * (http://opensource.franz.com/preamble.html), also known as the LLGPL.
-
- * These variables are correct for GCC
- * you'll need to modify these for other compilers
- ***************************************************************************/
-
-#ifdef WIN32
-#include <windows.h>
-
-BOOL WINAPI DllEntryPoint(HINSTANCE hinstdll,
- DWORD fdwReason,
- LPVOID lpvReserved)
-{
- return 1;
-}
-
-#define DLLEXPORT __declspec(dllexport)
-
-#else
-#define DLLEXPORT
-#endif
-
-#include <ctype.h>
-#include <stdlib.h>
-#include <math.h>
-
-
-DLLEXPORT unsigned char uchar_13 = 13;
-DLLEXPORT signed char schar_neg_120 = -120;
-DLLEXPORT unsigned short uword_257 = 257;
-DLLEXPORT signed short sword_neg_321 = -321;
-DLLEXPORT unsigned int uint_1234567 = 1234567;
-DLLEXPORT signed int sint_neg_123456 = -123456;
-DLLEXPORT double double_3_1 = 3.1;
-DLLEXPORT float float_neg_4_5 = -4.5;
-
-/* Test of constant input string */
-DLLEXPORT
-int
-cs_count_upper (char* psz)
-{
- int count = 0;
-
- if (psz) {
- while (*psz) {
- if (isupper (*psz))
- ++count;
- ++psz;
- }
- return count;
- } else
- return -1;
-}
-
-/* Test of input and output of a string */
-DLLEXPORT
-void
-cs_to_upper (char* psz)
-{
- if (psz) {
- while (*psz) {
- *psz = toupper (*psz);
- ++psz;
- }
- }
-}
-
-/* Test of an output only string */
-DLLEXPORT
-void
-cs_make_random (int size, char* buffer)
-{
- int i;
- for (i = 0; i < size; i++)
- buffer[i] = 'A' + (rand() % 26);
-}
-
-
-/* Test of input/output vector */
-DLLEXPORT
-void
-half_double_vector (int size, double* vec)
-{
- int i;
- for (i = 0; i < size; i++)
- vec[i] /= 2.;
-}
-
-
-
-DLLEXPORT
-void *
-cast_test_int () {
- int *x = (int *) malloc(sizeof(int));
- *x = 23;
- return x;
-}
-
-DLLEXPORT
-void *
-cast_test_float ()
-{
- double *y = (double *) malloc(sizeof(double));
- *y = 3.21;
- return y;
-}
-
-DLLEXPORT int fvar_addend = 3;
-
-typedef struct {
- int i;
- double d;
-} fvar_struct_type;
-
-fvar_struct_type fvar_struct = {42, 3.2};
-
-DLLEXPORT
-int fvar_struct_int () {
- return (fvar_addend + fvar_struct.i);
-}
-
-DLLEXPORT
-double fvar_struct_double () {
- return fvar_struct.d;
-}
-
-
--- /dev/null
+/***************************************************************************
+ * FILE IDENTIFICATION
+ *
+ * Name: c-test-fns.c
+ * Purpose: Test functions in C for UFFI library
+ * Programer: Kevin M. Rosenberg
+ * Date Started: Mar 2002
+ *
+ * CVS Id: $Id$
+ *
+ * This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
+ *
+ * UFFI users are granted the rights to distribute and use this software
+ * as governed by the terms of the Lisp Lesser GNU Public License
+ * (http://opensource.franz.com/preamble.html), also known as the LLGPL.
+
+ * These variables are correct for GCC
+ * you'll need to modify these for other compilers
+ ***************************************************************************/
+
+#ifdef WIN32
+#include <windows.h>
+
+BOOL WINAPI DllEntryPoint(HINSTANCE hinstdll,
+ DWORD fdwReason,
+ LPVOID lpvReserved)
+{
+ return 1;
+}
+
+#define DLLEXPORT __declspec(dllexport)
+
+#else
+#define DLLEXPORT
+#endif
+
+#include <ctype.h>
+#include <stdlib.h>
+#include <math.h>
+
+
+DLLEXPORT unsigned char uchar_13 = 13;
+DLLEXPORT signed char schar_neg_120 = -120;
+DLLEXPORT unsigned short uword_257 = 257;
+DLLEXPORT signed short sword_neg_321 = -321;
+DLLEXPORT unsigned int uint_1234567 = 1234567;
+DLLEXPORT signed int sint_neg_123456 = -123456;
+DLLEXPORT double double_3_1 = 3.1;
+DLLEXPORT float float_neg_4_5 = -4.5;
+
+/* Test of constant input string */
+DLLEXPORT
+int
+cs_count_upper (char* psz)
+{
+ int count = 0;
+
+ if (psz) {
+ while (*psz) {
+ if (isupper (*psz))
+ ++count;
+ ++psz;
+ }
+ return count;
+ } else
+ return -1;
+}
+
+/* Test of input and output of a string */
+DLLEXPORT
+void
+cs_to_upper (char* psz)
+{
+ if (psz) {
+ while (*psz) {
+ *psz = toupper (*psz);
+ ++psz;
+ }
+ }
+}
+
+/* Test of an output only string */
+DLLEXPORT
+void
+cs_make_random (int size, char* buffer)
+{
+ int i;
+ for (i = 0; i < size; i++)
+ buffer[i] = 'A' + (rand() % 26);
+}
+
+
+/* Test of input/output vector */
+DLLEXPORT
+void
+half_double_vector (int size, double* vec)
+{
+ int i;
+ for (i = 0; i < size; i++)
+ vec[i] /= 2.;
+}
+
+
+
+DLLEXPORT
+void *
+cast_test_int () {
+ int *x = (int *) malloc(sizeof(int));
+ *x = 23;
+ return x;
+}
+
+DLLEXPORT
+void *
+cast_test_float ()
+{
+ double *y = (double *) malloc(sizeof(double));
+ *y = 3.21;
+ return y;
+}
+
+DLLEXPORT int fvar_addend = 3;
+
+typedef struct {
+ int i;
+ double d;
+} fvar_struct_type;
+
+fvar_struct_type fvar_struct = {42, 3.2};
+
+DLLEXPORT
+int fvar_struct_int () {
+ return (fvar_addend + fvar_struct.i);
+}
+
+DLLEXPORT
+double fvar_struct_double () {
+ return fvar_struct.d;
+}
+
+
(:use #:asdf #:cl))
(in-package #:uffi-tests-system)
+(defvar *asd-file-dir* (pathname-directory *load-truename*))
+
+(defclass uffi-test-source-file (c-source-file)
+ ())
+
+(defmethod output-files ((o compile-op) (c uffi-test-source-file))
+ (let ((searched (or
+ (probe-file #p"/usr/lib/uffi/uffi-c-test.so")
+ (probe-file (make-pathname
+ :directory *asd-file-dir*
+ :name "uffi-c-test"
+ :type "so")))))
+ (if searched
+ (list searched)
+ (list (merge-pathnames
+ (make-pathname :name (component-name c)
+ :type "so"
+ :directory '(:relative "tests"))
+ (make-pathname :directory *asd-file-dir*))))))
+
+(defmethod perform ((o load-op) (c uffi-test-source-file))
+ (dolist (f (asdf::input-files o c))
+ (funcall (intern (symbol-name '#:load-foreign-library)
+ (symbol-name '#:uffi))
+ f :module "uffi_tests")))
+
+(defmethod perform ((o compile-op) (c uffi-test-source-file))
+ (unless (zerop (run-shell-command "cd ~A; make"
+ (namestring (merge-pathnames
+ (make-pathname
+ :name nil
+ :type nil
+ :directory '(:relative "tests"))
+ (make-pathname
+ :directory *asd-file-dir*)))))
+ (error 'operation-error :component c :operation o)))
+
+
(defsystem uffi-tests
:depends-on (:uffi)
:components
((:module tests
:components
((:file "rt")
+ (:uffi-test-source-file "uffi-c-test")
(:file "package" :depends-on ("rt"))
(:file "strtol" :depends-on ("package"))
(:file "atoifl" :depends-on ("package"))
(:file "structs" :depends-on ("package"))
(:file "pointers" :depends-on ("package"))
(:file "time" :depends-on ("package"))
- (:file "foreign-loader" :depends-on ("package"))
+ (:file "foreign-loader" :depends-on ("package" "uffi-c-test"))
(:file "uffi-c-test-lib" :depends-on ("foreign-loader"))
(:file "compress" :depends-on ("foreign-loader"))
(:file "casts" :depends-on ("foreign-loader"))