From cb172922e50c606a4db248618674cfffa00e688f Mon Sep 17 00:00:00 2001 From: Chris Hanson Date: Wed, 9 May 2007 02:06:22 +0000 Subject: [PATCH] Restructure liarc to use shell scripts to compile and link its C output files. These scripts are customized by the microcode's configure script to have the right invocations. Removing this knowledge from the compiler eliminates redundancy. --- v7/src/Setup.sh | 9 +- v7/src/compiler/machines/C/compiler.pkg | 6 +- v7/src/compiler/machines/C/ctop.scm | 197 +++--------------------- v7/src/configure.ac | 18 ++- v7/src/microcode/configure.ac | 10 +- v7/src/microcode/liarc-cc.in | 34 ++++ v7/src/microcode/liarc-ld.in | 37 +++++ v7/src/microcode/makegen/Makefile.in.in | 8 +- 8 files changed, 123 insertions(+), 196 deletions(-) create mode 100755 v7/src/microcode/liarc-cc.in create mode 100644 v7/src/microcode/liarc-ld.in diff --git a/v7/src/Setup.sh b/v7/src/Setup.sh index ed3a0e89a..60d6d01bb 100755 --- a/v7/src/Setup.sh +++ b/v7/src/Setup.sh @@ -1,6 +1,6 @@ #!/bin/sh # -# $Id: Setup.sh,v 1.22 2007/05/06 04:45:18 cph Exp $ +# $Id: Setup.sh,v 1.23 2007/05/09 02:05:38 cph Exp $ # # Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, # 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, @@ -37,6 +37,7 @@ fi # lib maybe_mkdir lib +maybe_mkdir lib/lib maybe_link lib/SRC .. maybe_link lib/include ../microcode maybe_link lib/optiondb.scm ../etc/optiondb.scm @@ -51,12 +52,6 @@ maybe_link lib/edwin/etc/TUTORIAL ../../../etc/TUTORIAL maybe_link lib/edwin/etc/mime.types ../../../etc/mime.types maybe_link lib/edwin/autoload ../../edwin -# lib/lib -maybe_mkdir lib/lib -for BUNDLE in 6001 compiler cref edwin imail sf sos ssp star-parser xdoc xml; do - maybe_link "lib/lib/${BUNDLE}.so" "../../microcode/${BUNDLE}.so" -done - for SUBDIR in 6001 compiler cref edwin imail rcs runtime \ sf sos ssp star-parser win32 xdoc xml microcode; do echo "setting up ${SUBDIR}" diff --git a/v7/src/compiler/machines/C/compiler.pkg b/v7/src/compiler/machines/C/compiler.pkg index 4bde2b431..d7ae693ad 100644 --- a/v7/src/compiler/machines/C/compiler.pkg +++ b/v7/src/compiler/machines/C/compiler.pkg @@ -1,6 +1,6 @@ #| -*-Scheme-*- -$Id: compiler.pkg,v 1.25 2007/04/15 18:02:15 cph Exp $ +$Id: compiler.pkg,v 1.26 2007/05/09 02:05:44 cph Exp $ Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, @@ -244,10 +244,6 @@ USA. compile-file:sf-only? compile-procedure compile-scode - compiler:c-compiler-name - compiler:c-compiler-switches - compiler:c-linker-name - compiler:c-linker-switches compiler:invoke-c-compiler? compiler:reset! ;; cross-compile-bin-file diff --git a/v7/src/compiler/machines/C/ctop.scm b/v7/src/compiler/machines/C/ctop.scm index 15d825811..3a2a886aa 100644 --- a/v7/src/compiler/machines/C/ctop.scm +++ b/v7/src/compiler/machines/C/ctop.scm @@ -1,6 +1,6 @@ #| -*-Scheme-*- -$Id: ctop.scm,v 1.26 2007/04/15 17:36:30 cph Exp $ +$Id: ctop.scm,v 1.27 2007/05/09 02:05:50 cph Exp $ Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, @@ -35,10 +35,6 @@ USA. (define compiled-output-extension "c") (define compiler:invoke-c-compiler? #t) (define compiler:invoke-verbose? #t) -(define compiler:c-compiler-name #f) -(define compiler:c-compiler-switches #f) -(define compiler:c-linker-name #f) -(define compiler:c-linker-switches #f) (define (compiler-file-output object pathname) (let ((pair (vector-ref object 1))) @@ -108,186 +104,41 @@ USA. )))))) (define (c-compile pathname) - (let ((source (enough-namestring pathname)) - (object (enough-namestring (pathname-new-type pathname "o"))) - (run - (lambda items - (let ((command-line - (decorated-string-append "" " " "" - (let flatten ((items items)) - (append-map! (lambda (item) - (if (list? item) - (flatten item) - (list item))) - items))))) + (let ((run + (lambda tokens + (let ((command + (decorated-string-append + "" " " "" + (map (lambda (token) + (let ((s + (if (pathname? token) + (enough-namestring token) + token))) + (if (string-find-next-char s #\space) + (string-append "\"" s "\"") + s))) + tokens)))) (maybe-with-notification compiler:invoke-verbose? (lambda (port) (write-string "Executing " port) - (write command-line port)) + (write command port)) (lambda () - (run-shell-command command-line))))))) - (maybe-with-notification compiler:noisy? - (lambda (port) - (write-string "Compiling " port) - (write-string source port)) - (lambda () - (run (c-compiler-name) - (c-compiler-switches) - "-DCOMPILE_FOR_DYNAMIC_LOADING" - "-o" - object - source))) - (maybe-with-notification compiler:noisy? - (lambda (port) - (write-string "Linking " port) - (write-string object port)) - (lambda () - (run (c-linker-name) - "-o" - (enough-namestring - (pathname-new-type pathname (c-output-extension))) - (c-linker-switches) - object))) - (delete-file object))) + (run-shell-command command))))))) + (run (system-library-pathname "liarc-cc") + (pathname-new-type pathname "o") + pathname) + (run (system-library-pathname "liarc-ld") + (pathname-new-type pathname (c-output-extension)) + (pathname-new-type pathname "o")))) (define (maybe-with-notification flag message thunk) (if flag (with-notification message thunk) (thunk))) - -(define c-compiler-switch-table - `( - ;; 32-bit PowerPC MacOSX - ("MacOSX" ; "MacOSX-PowerPC-32" - "dylib" - ("-g" "-O2" "-fno-common" "-DPIC" "-c") - ("-dylib" "-flat_namespace" "-undefined" "suppress") - "cc" - "ld") - ;; 64-bit PowerPC MacOSX - ("MacOSX-PowerPC-64" - "dylib" - ("-m64" "-g" "-O2" "-fno-common" "-DPIC" "-c") - ("-m64" "-dylib" "-flat_namespace" "-undefined" "suppress") - "gcc-4.0" - "ld") - ;; 32-bit i386 Linux - ("GNU/Linux" ; "GNU/Linux-IA-32" - "so" - ("-m32" "-g" "-O2" "-fPIC" "-c") - ("-m32" "-shared") - "cc" - "ld") - ;; 64-bit x86_64 Linux - ("GNU/Linux-x86-64" - "so" - ("-m64" "-g" "-O2" "-fPIC" "-c") - ("-m64" "-shared") - "cc" - "ld") - ("GNU/Linux-ia64" - "so" - ("-g" "-O2" "-fPIC" "-c") - ("-shared") - "cc" - "ld") - ("NETBSD-x86-64" - "so" - ("-g" "-O2" "-fPIC" "-c") - ("-shared") - "cc" - "ld") - #| - ;; All the following are old stuff that probably no longer works - ("AIX" - "so" - ("-c" "-O" "-D_AIX") - ,(lambda (dir) - (list "-bM:SRE" - (string-append "-bE:" - (->namestring (merge-pathnames dir "liarc.exp"))) - (string-append "-bI:" - (->namestring (merge-pathnames dir "scheme.imp"))) - "-edload_initialize_file")) - - "cc" - "cc") - ("HP-UX" - "sl" - ("-c" "+z" "-O" "-Ae" "-D_HPUX") - ("-b") - "cc" - "ld") - ("OSF" - "so" - ("-c" "-std1" "-O") - ("-shared" "-expect_unresolved" "'*'") - "cc" - "ld") - ("SunOS" - "so" - ("-c" "-pic" "-O" "-Dsun4" "-D_SUNOS4" "-w") - () - "cc" - "ld") - |# - )) - -(define (find-switches fail-name) - (or (assoc (string-append microcode-id/operating-system-variant - "-" - microcode-id/machine-type) - c-compiler-switch-table) - (assoc microcode-id/operating-system-variant - c-compiler-switch-table) - (and fail-name - (error fail-name "Unknown OS/machine")))) - + (define (c-output-extension) - ;; Always use .so -- this simplifies logic for built-in objects. - ;;(list-ref (find-switches 'c-output-extension) 1) "so") -(define (c-compiler-name) - (or compiler:c-compiler-name - (let ((p (find-switches #f))) - (if p - (list-ref p 4) - "cc")))) - -(define (c-compiler-switches) - (or compiler:c-compiler-switches - (let ((p (find-switches 'c-compiler-switches)) - (dir (system-library-directory-pathname "include"))) - (if (not dir) - (error 'c-compiler-switches - "Cannot find \"include\" directory")) - (append (list-ref p 2) - (list - (string-append - "-I" - (->namestring (directory-pathname-as-file dir)))))))) - -(define (c-linker-name) - (or compiler:c-linker-name - (let ((p (find-switches #f))) - (if p - (list-ref p 5) - "ld")))) - -(define (c-linker-switches) - (or compiler:c-linker-switches - (let ((p (find-switches 'c-linker-switches))) - (let ((switches (list-ref p 3))) - (if (not (procedure? switches)) - switches - (let ((dir (system-library-directory-pathname - "include"))) - (if (not dir) - (error 'c-linker-switches - "Cannot find \"include\" directory")) - (switches dir))))))) - (define (recursive-compilation-results) (sort *recursive-compilation-results* (lambda (x y) diff --git a/v7/src/configure.ac b/v7/src/configure.ac index f8ba024b8..6a92bb6ee 100644 --- a/v7/src/configure.ac +++ b/v7/src/configure.ac @@ -1,7 +1,7 @@ dnl Process this file with autoconf to produce a configure script. AC_INIT([MIT/GNU Scheme], [7.7.91], [bug-mit-scheme@gnu.org], [mit-scheme]) -AC_REVISION([$Id: configure.ac,v 1.11 2007/05/08 12:54:52 cph Exp $]) +AC_REVISION([$Id: configure.ac,v 1.12 2007/05/09 02:05:32 cph Exp $]) AC_CONFIG_SRCDIR([microcode/boot.c]) AC_PROG_MAKE_SET @@ -49,9 +49,11 @@ c) SYSTEM_BASE_NAME=mit-scheme ;; esac +AUXDIR='$(libdir)'/${SYSTEM_BASE_NAME} AC_SUBST([ALL_TARGET]) AC_SUBST([INSTALL_COM]) +AC_SUBST([AUXDIR]) AC_PROG_INSTALL AC_PROG_LN_S @@ -60,9 +62,6 @@ then INSTALL="${INSTALL} --preserve-timestamps" fi -AUXDIR='$(libdir)'/${SYSTEM_BASE_NAME} -AC_SUBST([AUXDIR]) - AC_CONFIG_SUBDIRS([microcode compiler]) AC_CONFIG_FILES([ Makefile @@ -77,3 +76,14 @@ xdoc/Makefile xml/Makefile ]) AC_OUTPUT + +if test x${enable_native_code} = xc; then + BN=liarcc-cc + (cd lib; rm -f ${BN}; ${LN_S} ../microcode/${BN} ${BN}) + BN=liarcc-ld + (cd lib; rm -f ${BN}; ${LN_S} ../microcode/${BN} ${BN}) + for BUNDLE in compiler cref edwin imail sf sos ssp star-parser xdoc xml; do + BN=${BUNDLE}.so + (cd lib/lib; rm -f ${BN}; ${LN_S} ../../microcode/${BN} ${BN}) + done +fi diff --git a/v7/src/microcode/configure.ac b/v7/src/microcode/configure.ac index 30e0197d6..856c9df3f 100644 --- a/v7/src/microcode/configure.ac +++ b/v7/src/microcode/configure.ac @@ -1,7 +1,7 @@ dnl Process this file with autoconf to produce a configure script. AC_INIT([MIT/GNU Scheme microcode], [15.1], [bug-mit-scheme@gnu.org], [mit-scheme]) -AC_REVISION([$Id: configure.ac,v 1.45 2007/05/06 04:43:01 cph Exp $]) +AC_REVISION([$Id: configure.ac,v 1.46 2007/05/09 02:05:56 cph Exp $]) AC_CONFIG_SRCDIR([boot.c]) AC_CONFIG_HEADERS([config.h]) AC_PROG_MAKE_SET @@ -185,13 +185,13 @@ STATIC_PREFIX= STATIC_SUFFIX= PRBFISH_LIBS= PRMD5_LIBS= -SCHEME_DEFS= +SCHEME_DEFS=-DMIT_SCHEME SCHEME_LDFLAGS= MODULE_BASES= MODULE_LIBS= MODULE_TARGETS= MODULE_RULES=/dev/null -MODULE_CFLAGS="-DCOMPILE_AS_MODULE" +MODULE_CFLAGS= MODULE_LDFLAGS= LIARC_VARS=/dev/null LIARC_RULES=/dev/null @@ -250,6 +250,7 @@ FOO=`${INSTALL} --help 2> /dev/null | fgrep -e --preserve-timestamps` if test "x${FOO}" != x; then INSTALL="${INSTALL} --preserve-timestamps" fi +CCLD=${CC} dnl Checks for libraries. AC_CHECK_LIB([m], [exp]) @@ -927,6 +928,8 @@ none) c) AC_MSG_RESULT([yes, using portable C code]) AC_CONFIG_LINKS([cmpauxmd.c:cmpauxmd/c.c]) + AC_CONFIG_FILES([liarc-cc], [chmod +x liarc-cc]) + AC_CONFIG_FILES([liarc-ld], [chmod +x liarc-ld]) AC_DEFINE([COMPILE_FOR_STATIC_LINKING], [1], [Define to 1 for static compilation of C native code.]) OPTIONAL_BASES="${OPTIONAL_BASES} cmpauxmd unstackify compinit" @@ -994,6 +997,7 @@ AC_SUBST_FILE([LIARC_VARS]) AC_SUBST_FILE([LIARC_RULES]) AC_SUBST([SYSTEM_BASE_NAME]) AC_SUBST([INSTALL_INCLUDE]) +AC_SUBST([CCLD]) AC_CONFIG_FILES([Makefile]) AC_OUTPUT diff --git a/v7/src/microcode/liarc-cc.in b/v7/src/microcode/liarc-cc.in new file mode 100755 index 000000000..c75c0dc32 --- /dev/null +++ b/v7/src/microcode/liarc-cc.in @@ -0,0 +1,34 @@ +#!/bin/sh +# +# $Id: liarc-cc.in,v 1.1 2007/05/09 02:06:02 cph Exp $ +# +# Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, +# 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, +# 2005, 2006, 2007 Massachusetts Institute of Technology +# +# This file is part of MIT/GNU Scheme. +# +# MIT/GNU Scheme is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of the +# License, or (at your option) any later version. +# +# MIT/GNU Scheme is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with MIT/GNU Scheme; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA +# 02110-1301, USA. + +set -e + +if [ ${#} -ne 2 ]; then + echo "usage: ${0} OUTPUT INPUT" + exit 1 +fi + +@CC@ @DEFS@ @SCHEME_DEFS@ @CPPFLAGS@ @CFLAGS@ @MODULE_CFLAGS@ \ + -DCOMPILE_FOR_DYNAMIC_LOADING -o "${1}" "${2}" diff --git a/v7/src/microcode/liarc-ld.in b/v7/src/microcode/liarc-ld.in new file mode 100644 index 000000000..e48b0a968 --- /dev/null +++ b/v7/src/microcode/liarc-ld.in @@ -0,0 +1,37 @@ +#!/bin/sh +# +# $Id: liarc-ld.in,v 1.1 2007/05/09 02:06:16 cph Exp $ +# +# Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, +# 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, +# 2005, 2006, 2007 Massachusetts Institute of Technology +# +# This file is part of MIT/GNU Scheme. +# +# MIT/GNU Scheme is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of the +# License, or (at your option) any later version. +# +# MIT/GNU Scheme is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with MIT/GNU Scheme; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA +# 02110-1301, USA. + +set -e + +if [ ${#} -lt 2 ]; then + echo "usage: ${0} SOFILE OFILE ..." + exit 1 +fi + +OUTPUT=${1} +shift + +@CCLD@ @LDFLAGS@ @MODULE_LDFLAGS@ -o "${OUTPUT}" "${@}" +rm -f "${@}" diff --git a/v7/src/microcode/makegen/Makefile.in.in b/v7/src/microcode/makegen/Makefile.in.in index 6b2acfaa6..c624e5677 100644 --- a/v7/src/microcode/makegen/Makefile.in.in +++ b/v7/src/microcode/makegen/Makefile.in.in @@ -1,6 +1,6 @@ # -*- Makefile -*- # -# $Id: Makefile.in.in,v 1.53 2007/05/06 04:43:06 cph Exp $ +# $Id: Makefile.in.in,v 1.54 2007/05/09 02:06:22 cph Exp $ # # Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, # 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, @@ -68,12 +68,13 @@ SYSTEM_BASE_NAME = @SYSTEM_BASE_NAME@ AUXDIR = $(libdir)/$(SYSTEM_BASE_NAME) CC = @CC@ +CCLD = @CCLD@ M4 = $(srcdir)/makegen/m4.sh AS = as TAR = tar GZIP_ENV = --best -DEFS = @DEFS@ @SCHEME_DEFS@ -DMIT_SCHEME -DDEFAULT_LIBRARY_PATH=\"$(AUXDIR)\" +DEFS = @DEFS@ @SCHEME_DEFS@ -DDEFAULT_LIBRARY_PATH=\"$(AUXDIR)\" CFLAGS = @CFLAGS@ CPPFLAGS = @CPPFLAGS@ -I. -I$(srcdir) LDFLAGS = @LDFLAGS@ @@ -82,7 +83,6 @@ M4_FLAGS = @M4_FLAGS@ AS_FLAGS = @AS_FLAGS@ COMPILE = $(CC) $(DEFS) $(CPPFLAGS) $(CFLAGS) -CCLD = $(CC) LINK = $(CCLD) $(LDFLAGS) -o $@ EXPAND = $(M4) $(M4_FLAGS) ASSEMBLE = $(AS) $(AS_FLAGS) @@ -108,7 +108,7 @@ PRMD5_LIBS = @PRMD5_LIBS@ MODULE_TARGETS = @MODULE_TARGETS@ MODULE_CFLAGS = @MODULE_CFLAGS@ MODULE_LDFLAGS = @MODULE_LDFLAGS@ -COMPILE_MODULE = $(COMPILE) $(MODULE_CFLAGS) +COMPILE_MODULE = $(COMPILE) -DCOMPILE_AS_MODULE $(MODULE_CFLAGS) LINK_MODULE = $(LINK) $(MODULE_LDFLAGS) MODULE_LIBS = -lc -- 2.25.1