#!/bin/sh PACKAGE=newlisp VERSION=10.7.0 rm -f config.h makefile_build makefile_install # this script tries to discover the OS platform and configuration # and then makes newLISP using the appropiate makefile # if this script fails and for other special flavors, like # making shared libraries etc., type: # # make help # to see all options specified in Makefile # # to change $(prefix) edit prefix in Makefile # Generate a config.h file with all our different option settings that are set # by #define # Now we set the default values for our new Makefile DEFAULT_CC="cc" DARWIN_CC="${DEFAULT_CC}" LINUX_CC="gcc" BSD_CC="${DEFAULT_CC}" SUNOS_CC="gcc" AIX_CC="xlc_r" TRU64_CC="cc" WIN32_CC="gcc" OS2_CC="${DEFAULT_CC}" DEFAULT_CFLAGS=" -Wall -Wno-uninitialized -fno-strict-aliasing -O2 -c" DARWIN_CFLAGS=" -Wall -Wno-long-long -Wno-strict-aliasing -O2 -c" LINUX_CFLAGS=" -Wall -Wno-long-long -Wno-strict-aliasing -O2 -c" BSD_CFLAGS=" -Wall -Wno-uninitialized -Wno-long-long -fno-strict-aliasing -O2 -c" SUNOS_CFLAGS=" -Wall -pedantic -Wno-uninitialized -Wno-long-long -fno-strict-aliasing -O2 -c" AIX_XLCFLAGS=" -O2 -c" AIX_GCCFLAGS=" -Wall -pedantic -Wno-uninitialized -Wno-long-long -fno-strict-aliasing -O2 -c" TRU64_CFLAGS=" -ieee -pedantic -O3 -c -D_POSIX_PII_SOCKET" WIN32_CFLAGS=" -Wall -Wno-uninitialized -Wno-long-long -O1 -c" OS2_CFLAGS=" -Wall -pedantic -Wno-uninitialized -Wno-long-long -Wno-strict-aliasing -O2 -c -s" DEFAULT_LDFLAGS="-lm" DARWIN_LDFLAGS="${DEFAULT_LDFLAGS}" LINUX_LDFLAGS="-lm -ldl" BSD_LDFLAGS="${DEFAULT_LDFLAGS}" SUNOS_LDFLAGS="-lm -ldl -lrt -lsocket -lnsl" AIX_LDFLAGS="-lm -ldl -lrt -lnsl" TRU64_LDFLAGS="-lm -lrt -ldb -lbsd" WIN32_LDFLAGS="-lws2_32" OS2_LDFLAGS="-Zomf -Zmt -lm -ldl" DEFAULT_OBJS="newlisp.o nl-symbol.o nl-math.o nl-list.o nl-liststr.o nl-string.o nl-filesys.o \ nl-sock.o nl-import.o nl-xml-json.o nl-web.o nl-matrix.o nl-debug.o pcre.o" DEFAULT_STRIP="strip" WIN32_STRIP="strip" DEFAULT_TARG="newlisp" WIN32_TARG="newlisp.exe" OS2_TARG="newlisp.exe" echo case `uname` in Darwin) true ${os_type:=MAC_OSX} ;; Linux) true ${os_type:=LINUX} ;; FreeBSD) true ${os_type:=_BSD} ;; NetBSD) true ${os_type:=_BSD} ;; OpenBSD) true ${os_type:=_BSD} ;; SunOS) true ${os_type:=SUNOS} ;; AIX) true ${os_type:=AIX} ;; OSF1) true ${os_type:=TRU64} ;; MINGW*) true ${os_type:=WINDOWS} ;; OS/2) true ${os_type:=OS2} ;; *) echo Could not discover your OS platform use one of the following commands: make help exit ;; esac echo "Detected Operating System ${os_type}" if [ ${os_type} = MAC_OSX ] ; then DEFAULT_CFLAGS="${DARWIN_CFLAGS}" elif [ ${os_type} = LINUX ] ; then DEFAULT_CFLAGS="${LINUX_CFLAGS}" DEFAULT_LDFLAGS="${LINUX_LDFLAGS}" elif [ ${os_type} = _BSD ] ; then DEFAULT_CFLAGS="${BSD_CFLAGS}" elif [ ${os_type} = SUNOS ] ; then DEFAULT_CFLAGS="${SUNOS_CFLAGS}" DEFAULT_LDFLAGS="${SUNOS_LDFLAGS}" elif [ ${os_type} = AIX ] ; then DEFAULT_CC="${AIX_CC}" DEFAULT_CFLAGS="${AIX_XLCFLAGS}" true ${enable_readline:=no}; elif [ ${os_type} = TRU64 ] ; then DEFAULT_CC="${TRU64_CC}" DEFAULT_CFLAGS="${TRU64_CFLAGS}" DEFAULT_LDFLAGS="${TRU64_LDFLAGS}" elif [ ${os_type} = WINDOWS ] ; then DEFAULT_CC="${WIN32_CC}" DEFAULT_CFLAGS="${WIN32_CFLAGS}" DEFAULT_LDFLAGS="${WIN32_LDFLAGS}" DEFAULT_OBJS="${DEFAULT_OBJS} win-util.o win-path.o" DEFAULT_STRIP="${WIN32_STRIP}" DEFAULT_TARG="${WIN32_TARG}" true ${enable_readline:=no}; true ${enable_utf8:=no}; elif [ ${os_type} = OS2 ] ; then DEFAULT_CFLAGS="${OS2_CFLAGS}" DEFAULT_LDFLAGS="${OS2_LDFLAGS}" DEFAULT_TARG="${OS2_TARG}" true ${enable_readline:=yes}; fi # Only LP64 and ILP32 memory models are officially supported, but we'll try to # support the others too. cat > test-memorymodel.c < * * return a string with the type of memory model the current compiler is using. */ #include int main(int argc, char** argv) { short sc = sizeof(char) * 8; short ss = sizeof(short) * 8; short si = sizeof(int) * 8; short sl = sizeof(long) * 8; short sp = sizeof(void*) * 8; if (si == 32 && sl == 64 && sp == 64) { printf("LP64\n"); return 0; } if (si == 64 && sl == 64 && sp == 64) { printf("ILP64\n"); return 0; } if (si == 32 && sl == 32 && sp == 64) { printf("LLP64\n"); return 0; } if (si == 32 && sl == 32 && sp == 32) { printf("ILP32\n"); return 0; } if (si == 16 && sl == 32 && sp == 32) { printf("LP32\n"); return 0; } printf("UNKNOWN\n"); return 1; } EOF ${CC:-${DEFAULT_CC}} test-memorymodel.c -o test-memorymodel 2>/dev/null true ${memory_model:=`./test-memorymodel`} echo "Detected memory model `./test-memorymodel`" rm -f test-memorymodel* # time_t is 64 bits on modern platforms. Support this. cat > test-time-t.c < #include int main(int argc, char** argv) { short bits = sizeof(time_t) * 8; if (bits == 64) { printf("64BIT"); return 0; } if (bits == 32) { printf("32BIT"); return 0; } printf("UNSUPPORTED\n"); return 1; } EOF ${CC:-${DEFAULT_CC}} test-time-t.c -o test-time-t 2>/dev/null true ${time_t_size:=`./test-time-t`} echo "Detected time_t size `./test-time-t`" rm -f test-time-t* # If we can't compile with readline, and the environment variables don't # specify otherwise, we will disable it. cat > test-readline.c < * * code for testing the compiler options to use for libreadline */ #include #include #include #include char ** test_completion (char * text, int start, int end) { return NULL; } int main(int argc, char** argv) { rl_readline_name = "test"; rl_attempted_completion_function = (CPPFunction *)test_completion; readline(NULL); add_history("test"); exit(0); } EOF for cclibreadline in "-lreadline" "-lreadline -lncurses" "-lreadline -ltermcap" "-lreadline -lterminfo"; do if ${CC:-${DEFAULT_CC}} test-readline.c ${cclibreadline} -o test-readline 2>/dev/null ; then true ${enable_readline:=yes}; DEFAULT_RLFLAGS="${cclibreadline}"; echo "Detected readline flags: ${cclibreadline}"; break; fi done true ${enable_readline:=no}; rm -f test-readline* # If we can't compile with ffi, and the environment variables don't # specify otherwise, we will disable it. cat > test-ffi.c < * * code for testing the compiler options to use for libffi */ #include #include int main(int argc, char** argv) { ffi_cif cif; ffi_type *args[1]; void *values[1]; char *s; int rc; args[0] = &ffi_type_pointer; values[0] = &s; if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, &ffi_type_uint, args) == FFI_OK) { s = "Hello World!"; ffi_call(&cif, puts, &rc, values); } return 0; } EOF for cclibffi in "-lffi"; do if ${CC:-${DEFAULT_CC}} test-ffi.c ${DEFAULT_LDFLAGS} ${cclibffi} -o test-ffi 2>/dev/null ; then true ${enable_ffi:=yes}; DEFAULT_FFIFLAGS="${cclibffi}"; echo "Detected ffi flags: ${cclibffi}"; break; fi done true ${enable_ffi:=no}; rm -f test-ffi* # Safe defaults; true ${enable_utf8:=yes}; # Default values to control how the Makefile is generated true ${enable_static:=no}; true ${enable_debug:=no}; for nlc_arg in "$@"; do if test -n "$nlc_prev"; then eval "$nlc_prev=\$nlc_arg" nlc_prev= continue fi case "${nlc_arg}" in --*=*) nlc_optarg=`echo "$nlc_arg" | sed 's/[-_a-zA-Z0-9]*=//'` ;; *) nlc_optarg= ;; esac case "${nlc_arg}" in --enable-utf8) enable_utf8=yes; ;; --disable-utf8) enable_utf8=no; ;; --enable-readline) enable_readline=yes; ;; --disable-readline) enable_readline=no; ;; --enable-ffi) enable_ffi=yes; ;; --disable-ffi) enable_ffi=no; ;; --enable-static) enable_static=yes; ;; --disable-static) enable_static=no; ;; --enable-debug) enable_debug=yes; ;; --disable-debug) enable_debug=no; ;; --LP64) memory_model=LP64; ;; --ILP64) memory_model=ILP64; ;; --LLP64) memory_model=LLP64; ;; --LP32) memory_model=LP32; ;; --ILP32) memory_model=ILP32; ;; --prefix) nlc_prev=prefix ;; --prefix=*) prefix="$nlc_optarg" ;; --exec-prefix) nlc_prev=exec_prefix ;; --exec-prefix=*) exec_prefix="$nlc_optarg" ;; --bindir) nlc_prev=bindir ;; --bindir=*) bindir="$nlc_optarg" ;; --mandir) nlc_prev=mandir ;; --mandir=*) mandir="$nlc_optarg" ;; --man1dir) nlc_prev=man1dir ;; --man1dir=*) man1dir="$nlc_optarg" ;; --docdir) nlc_prev=docdir ;; --docdir=*) docdir="$nlc_optarg" ;; --datadir) nlc_prev=datadir ;; --datadir=*) datadir="$nlc_optarg" ;; --help) cat <> config.h <> config.h <> config.h <> config.h <> config.h <> config.h <> config.h <> config.h if [ $enable_static = yes ] ; then DEFAULT_LDFLAGS="${DEFAULT_LDFLAGS} -static" echo "Static linking enabled" fi if [ $enable_debug = yes ] ; then DEFAULT_CFLAGS="${DEFAULT_CFLAGS} -g" DEFAULT_LDFLAGS="${DEFAULT_LDFLAGS} -g" echo "Debugging enabled" fi cat >test-archflag.c < int main(int argc, char** argv) { printf("Hello World.\n"); } EOF DEFAULT_ARCHFLAGS="" if [ $memory_model = LP64 ] ; then if [ $os_type = AIX -a ${CC:-${DEFAULT_CC}} = xlc_r ] ; then DEFAULT_ARCHFLAGS="-q64" elif [ $os_type = AIX -a ${CC:-${DEFAULT_CC}} = gcc ] ; then DEFAULT_ARCHFLAGS="-maix64" else if ${CC:-${DEFAULT_CC}} -m64 -o test-archflag test-archflag.c 2>/dev/null; then DEFAULT_ARCHFLAGS="-m64" fi fi elif [ $memory_model = ILP32 ] ; then if ${CC:-${DEFAULT_CC}} -m32 -o test-archflag test-archflag.c 2>/dev/null; then DEFAULT_ARCHFLAGS="-m32" fi fi rm -f test-archflag* STRIPBINARY=" \$(STRIP) \$(TARG)" LINKSTAGE=" \$(CC) \$(OBJS) \$(ARCHFLAGS) \$(LDFLAGS) \$(RLFLAGS) \$(FFIFLAGS) -o \$(TARG)" COMPILEOBJS=" \$(CC) \$(ARCHFLAGS) \$(CFLAGS) -DNEWCONFIG $<" if [ $os_type = OS2 ] ; then STRIPBINARY="" elif [ $os_type = AIX -a $memory_model = LP64 ] ; then LINKSTAGE=" OBJECT_MODE=64 \$(CC) \$(OBJS) \$(ARCHFLAGS) \$(LDFLAGS) \$(RLFLAGS) \$(FFIFLAGS) -o \$(TARG)" fi # Now let us make the Makefile (makefile_build) cat > makefile_build < makefile_install <