From: Chris Hanson Date: Fri, 12 Jan 2007 02:57:10 +0000 (+0000) Subject: Merge in most changes from pre-v15 branch. In particular, the new X-Git-Tag: 20090517-FFI~797 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=2f79dd0a7ac053333e9ca815a04eec3c914153ec;p=mit-scheme.git Merge in most changes from pre-v15 branch. In particular, the new mechanism for configuring the C back end. --- diff --git a/v7/src/microcode/configure.ac b/v7/src/microcode/configure.ac index b7019a2d6..83566a17b 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], [14.18], [bug-mit-scheme@gnu.org], [mit-scheme]) -AC_REVISION([$Id: configure.ac,v 1.27 2007/01/12 02:22:06 cph Exp $]) +AC_REVISION([$Id: configure.ac,v 1.28 2007/01/12 02:57:10 cph Exp $]) AC_CONFIG_SRCDIR([boot.c]) AC_CONFIG_HEADERS([config.h]) AC_PROG_MAKE_SET @@ -184,9 +184,8 @@ MODULE_TARGETS= MODULE_RULES=/dev/null MODULE_CFLAGS="-DCOMPILE_AS_MODULE" MODULE_LDFLAGS= -COMPILED_SOURCES= -COMPILED_OBJECTS= -CBE_RULES=/dev/null +LIARC_RULES_1=/dev/null +LIARC_RULES_2=/dev/null dnl Checks for programs. AC_PROG_CC @@ -817,14 +816,8 @@ c) AC_DEFINE([COMPILE_FOR_STATIC_LINKING], [1], [Define to 1 for static compilation of C native code.]) OPTIONAL_BASES="${OPTIONAL_BASES} cmpauxmd unstackify compinit" - COMPILED_SOURCES="utabmd.c" - for D in runtime sf cref star-parser compiler; do - COMPILED_SOURCES="${COMPILED_SOURCES} \$(wildcard ../${D}/*.c)" - done - for D in back base fggen fgopt machines/C rtlbase rtlgen rtlopt; do - COMPILED_SOURCES="${COMPILED_SOURCES} \$(wildcard ../compiler/${D}/*.c)" - done - CBE_RULES=makegen/cbe-rules + LIARC_RULES_1=liarc-rules-1 + LIARC_RULES_2=makegen/liarc-rules-2 ;; *) AC_MSG_RESULT([yes, for ${SCM_ARCH}]) @@ -877,9 +870,8 @@ AC_SUBST([MODULE_TARGETS]) AC_SUBST_FILE([MODULE_RULES]) AC_SUBST([MODULE_CFLAGS]) AC_SUBST([MODULE_LDFLAGS]) -AC_SUBST([COMPILED_SOURCES]) -AC_SUBST([COMPILED_OBJECTS]) -AC_SUBST_FILE([CBE_RULES]) +AC_SUBST_FILE([LIARC_RULES_1]) +AC_SUBST_FILE([LIARC_RULES_2]) AC_CONFIG_FILES([Makefile]) AC_OUTPUT diff --git a/v7/src/microcode/liarc-gendeps.c b/v7/src/microcode/liarc-gendeps.c new file mode 100644 index 000000000..598f20204 --- /dev/null +++ b/v7/src/microcode/liarc-gendeps.c @@ -0,0 +1 @@ +#include "liarc.h" diff --git a/v7/src/microcode/makegen/Makefile.in.in b/v7/src/microcode/makegen/Makefile.in.in index e5726c442..8e5ac90aa 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.40 2007/01/12 02:16:47 cph Exp $ +# $Id: Makefile.in.in,v 1.41 2007/01/12 02:57:10 cph Exp $ # # Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, # 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, @@ -62,10 +62,6 @@ mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs # **** END BOILERPLATE **** -# **** C back end stuff (I) **** -COMPILED_SOURCES = @COMPILED_SOURCES@ -COMPILED_OBJECTS = $(COMPILED_SOURCES:.c=.o) - # **** Tool configuration **** AUXDIR = $(libdir)/mit-scheme @@ -76,10 +72,9 @@ AS = as TAR = tar GZIP_ENV = --best -DEFS = -DMIT_SCHEME -DDEFAULT_LIBRARY_PATH=\"$(AUXDIR)\" @DEFS@ \ - @SCHEME_DEFS@ -I. -I$(srcdir) -I. +DEFS = @DEFS@ @SCHEME_DEFS@ -DMIT_SCHEME -DDEFAULT_LIBRARY_PATH=\"$(AUXDIR)\" CFLAGS = @CFLAGS@ -CPPFLAGS = @CPPFLAGS@ +CPPFLAGS = @CPPFLAGS@ -I. -I$(srcdir) LDFLAGS = @LDFLAGS@ LIBS = @LIBS@ M4_FLAGS = @M4_FLAGS@ @@ -87,15 +82,30 @@ AS_FLAGS = @AS_FLAGS@ COMPILE = $(CC) $(DEFS) $(CPPFLAGS) $(CFLAGS) CCLD = $(CC) -LINK = $(CCLD) $(CFLAGS) $(LDFLAGS) -o $@ +LINK = $(CCLD) $(LDFLAGS) -o $@ EXPAND = $(M4) $(M4_FLAGS) ASSEMBLE = $(AS) $(AS_FLAGS) -# **** Configured files **** +# **** File configuration **** + +SHARED_SOURCES = @(write-sources "files-core")@ \ + @(write-sources "files-os-prim")@ \ + @(write-sources "files-unix")@ \ + $(OPTIONAL_SOURCES) +SHARED_OBJECTS = @(write-objects "files-core")@ \ + @(write-objects "files-os-prim")@ \ + @(write-objects "files-unix")@ \ + $(OPTIONAL_OBJECTS) + +STD_SOURCES = $(SHARED_SOURCES) @(write-sources "files-gc-std")@ +STD_OBJECTS = $(SHARED_OBJECTS) @(write-objects "files-gc-std")@ + +BCH_SOURCES = $(SHARED_SOURCES) @(write-sources "files-gc-bch")@ +BCH_OBJECTS = $(SHARED_OBJECTS) @(write-objects "files-gc-bch")@ GC_HEAD_FILES = @GC_HEAD_FILES@ -OPTIONAL_SOURCES = @OPTIONAL_SOURCES@ $(COMPILED_SOURCES) -OPTIONAL_OBJECTS = @OPTIONAL_OBJECTS@ $(COMPILED_OBJECTS) +OPTIONAL_SOURCES = @OPTIONAL_SOURCES@ +OPTIONAL_OBJECTS = @OPTIONAL_OBJECTS@ STATIC_LIBS = @STATIC_PREFIX@ @STATIC_LIBS@ @STATIC_SUFFIX@ PRBFISH_LIBS = @PRBFISH_LIBS@ PRMD5_LIBS = @PRMD5_LIBS@ @@ -107,25 +117,9 @@ COMPILE_MODULE = $(COMPILE) $(MODULE_CFLAGS) LINK_MODULE = $(LINK) $(MODULE_LDFLAGS) MODULE_LIBS = -lc -# **** Non-configured files **** +# **** Rules for C back end (part 1) **** -CORE_SOURCES = @(write-sources "files-core")@ -OS_PRIM_SOURCES = @(write-sources "files-os-prim")@ -UNIX_SOURCES = @(write-sources "files-unix")@ -STD_GC_SOURCES = @(write-sources "files-gc-std")@ -BCH_GC_SOURCES = @(write-sources "files-gc-bch")@ - -CORE_OBJECTS = @(write-objects "files-core")@ -OS_PRIM_OBJECTS = @(write-objects "files-os-prim")@ -UNIX_OBJECTS = @(write-objects "files-unix")@ -STD_GC_OBJECTS = @(write-objects "files-gc-std")@ -BCH_GC_OBJECTS = @(write-objects "files-gc-bch")@ - -SHARED_SOURCES = $(CORE_SOURCES) $(OS_PRIM_SOURCES) $(UNIX_SOURCES) \ - $(OPTIONAL_SOURCES) - -SHARED_OBJECTS = $(CORE_OBJECTS) $(OS_PRIM_OBJECTS) $(UNIX_OBJECTS) \ - $(OPTIONAL_OBJECTS) +@LIARC_RULES_1@ # **** Program definitions **** @@ -135,14 +129,14 @@ aux_LIBS = $(MODULE_TARGETS) aux_DATA = utabmd.bin EXTRA_PROGRAMS = findprim bintopsb psbtobin -scheme_SOURCES = $(SHARED_SOURCES) $(STD_GC_SOURCES) usrdef.c -scheme_OBJECTS = $(SHARED_OBJECTS) $(STD_GC_OBJECTS) usrdef.o +scheme_SOURCES = $(STD_SOURCES) usrdef.c $(LIARC_SOURCES) +scheme_OBJECTS = $(STD_OBJECTS) usrdef.o $(LIARC_OBJECTS) scheme_DEPENDENCIES = scheme_LDFLAGS = @DLD_LDFLAGS@ scheme_LIBS = $(STATIC_LIBS) $(LIBS) -bchscheme_SOURCES = $(SHARED_SOURCES) $(BCH_GC_SOURCES) bchdef.c -bchscheme_OBJECTS = $(SHARED_OBJECTS) $(BCH_GC_OBJECTS) bchdef.o +bchscheme_SOURCES = $(BCH_SOURCES) bchdef.c $(LIARC_SOURCES) +bchscheme_OBJECTS = $(BCH_OBJECTS) bchdef.o $(LIARC_OBJECTS) bchscheme_DEPENDENCIES = bchscheme_LDFLAGS = @DLD_LDFLAGS@ bchscheme_LIBS = $(STATIC_LIBS) $(LIBS) @@ -181,15 +175,16 @@ ALL_PROGRAMS = $(bin_PROGRAMS) $(aux_PROGRAMS) ALL_LIBS = $(aux_LIBS) ALL_DATA = $(aux_DATA) -MOSTLYCLEAN_FILES = *.o cmpauxmd.s usrdef.c bchdef.c \ - compinit.h utabmd.c utabmd.bci *.tch +MOSTLYCLEAN_FILES = *.o cmpauxmd.s usrdef.c compinit.h utabmd.c utabmd.bci \ + bchdef.c CLEAN_FILES = $(ALL_PROGRAMS) $(ALL_LIBS) $(ALL_DATA) $(EXTRA_PROGRAMS) DISTCLEAN_FILES = Makefile config.h config.cache config.log config.status \ - cmpauxmd.m4 cmpauxmd.c cmpintmd.h TAGS makegen-cc + cmpauxmd.m4 cmpauxmd.c cmpintmd.h makegen-cc -MAINTAINER_CLEAN_FILES = Makefile.in Makefile.deps config.h.in configure +MAINTAINER_CLEAN_FILES = Makefile.in Makefile.deps liarc-rules-1 \ + config.h.in configure TAGS # **** Implicit rules **** @@ -215,17 +210,17 @@ scheme: $(scheme_OBJECTS) $(scheme_DEPENDENCIES) -rm -f $@ $(LINK) $(scheme_LDFLAGS) $(scheme_OBJECTS) $(scheme_LIBS) -usrdef.c: $(SHARED_SOURCES) $(STD_GC_SOURCES) findprim Makefile +usrdef.c: $(STD_SOURCES) findprim Makefile -rm -f $@ - ./findprim $(SHARED_SOURCES) $(STD_GC_SOURCES) > usrdef.c + ./findprim $(STD_SOURCES) > usrdef.c bchscheme: $(bchscheme_OBJECTS) $(bchscheme_DEPENDENCIES) -rm -f $@ $(LINK) $(bchscheme_LDFLAGS) $(bchscheme_OBJECTS) $(bchscheme_LIBS) -bchdef.c: $(SHARED_SOURCES) $(BCH_GC_SOURCES) findprim Makefile +bchdef.c: $(BCH_SOURCES) findprim Makefile -rm -f $@ - ./findprim $(SHARED_SOURCES) $(BCH_GC_SOURCES) > bchdef.c + ./findprim $(BCH_SOURCES) > bchdef.c gcdrone: $(bchdrn_OBJECTS) $(bchdrn_DEPENDENCIES) -rm -f $@ @@ -275,7 +270,8 @@ prpgsql.so: prpgsql.o tags: TAGS TAGS: - etags -r '/^DEF[A-Za-z_ \t(]+"\([^"]+\)"/' *.[ch] + etags -r '/^DEF[A-Z0-9_]*[ \t]*(\("[^"]+"\|[a-zA-Z_][a-zA-Z0-9_]*\)/' \ + *.[ch] */*.[ch] mostlyclean: -rm -f $(MOSTLYCLEAN_FILES) @@ -299,7 +295,7 @@ install-binPROGRAMS: $(bin_PROGRAMS) @list='$(bin_PROGRAMS)'; \ for p in $$list; do \ if test -f $$p; then \ - echo " $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/."; \ + echo "$(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/."; \ $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/.; \ fi; \ done @@ -309,7 +305,7 @@ install-auxPROGRAMS: $(aux_PROGRAMS) @list='$(aux_PROGRAMS)'; \ for p in $$list; do \ if test -f $$p; then \ - echo " $(INSTALL_PROGRAM) $$p $(DESTDIR)$(AUXDIR)/."; \ + echo "$(INSTALL_PROGRAM) $$p $(DESTDIR)$(AUXDIR)/."; \ $(INSTALL_PROGRAM) $$p $(DESTDIR)$(AUXDIR)/.; \ fi; \ done @@ -319,7 +315,7 @@ install-auxLIBS: $(aux_LIBS) @list='$(aux_LIBS)'; \ for p in $$list; do \ if test -f $$p; then \ - echo " $(INSTALL_DATA) $$p $(DESTDIR)$(AUXDIR)/lib/."; \ + echo "$(INSTALL_DATA) $$p $(DESTDIR)$(AUXDIR)/lib/."; \ $(INSTALL_DATA) $$p $(DESTDIR)$(AUXDIR)/lib/.; \ fi; \ done @@ -329,7 +325,7 @@ install-auxDATA: $(aux_DATA) @list='$(aux_DATA)'; \ for p in $$list; do \ if test -f $$p; then \ - echo " $(INSTALL_DATA) $$p $(DESTDIR)$(AUXDIR)/."; \ + echo "$(INSTALL_DATA) $$p $(DESTDIR)$(AUXDIR)/."; \ $(INSTALL_DATA) $$p $(DESTDIR)$(AUXDIR)/.; \ fi; \ done @@ -342,7 +338,9 @@ install-auxDATA: $(aux_DATA) @(write-dependencies)@ -@CBE_RULES@ +# **** Rules for C back end (part 2) **** + +@LIARC_RULES_2@ # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. diff --git a/v7/src/microcode/makegen/cbe-rules b/v7/src/microcode/makegen/cbe-rules deleted file mode 100644 index d9dc200dc..000000000 --- a/v7/src/microcode/makegen/cbe-rules +++ /dev/null @@ -1,69 +0,0 @@ -# -*- Makefile -*- -# -# $Id: cbe-rules,v 1.2 2007/01/08 14:55:22 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. - -# **** C back end rules **** - -cmpauxmd.o: cmpauxmd.c liarc.tch prims.h bignum.h bitstr.h avltree.h \ - outf.h extern.h - -compinit.o: compinit.c compinit.h liarc.tch - -unstackify.o: unstackify.c stackops.h liarc.tch - -LIARC_HEAD_FILES = \ -ansidecl.h \ -config.h \ -dstack.h \ -default.h \ -object.h \ -sdata.h \ -types.h \ -errors.h \ -const.h \ -interp.h \ -prim.h \ -trap.h \ -outf.h \ -extern.h \ -$(GC_HEAD_FILES) - -# The following includes liarc.tch in case COMPILED_SOURCES is empty, -# to prevent grep from reading stdin. - -compinit.h: $(COMPILED_SOURCES) liarc.tch Makefile - rm -f $@ - grep \^DECLARE_COMPILED_CODE liarc.tch $(COMPILED_SOURCES) \ - | sed -e 's/.*:/ /' > $@ - grep \^DECLARE_COMPILED_DATA liarc.tch $(COMPILED_SOURCES) \ - | sed -e 's/.*:/ /' >> $@ - grep \^DECLARE_DATA_OBJECT liarc.tch $(COMPILED_SOURCES) \ - | sed -e 's/.*:/ /' >> $@ - -foo $(COMPILED_OBJECTS): liarc.tch -liarc.tch: liarc.h $(LIARC_HEAD_FILES) - rm -f $@ - echo "touch" > $@ - -# **** End C back end rules *** diff --git a/v7/src/microcode/makegen/dirs-liarc.scm b/v7/src/microcode/makegen/dirs-liarc.scm new file mode 100644 index 000000000..4eac7fd8a --- /dev/null +++ b/v7/src/microcode/makegen/dirs-liarc.scm @@ -0,0 +1,45 @@ +#| -*-Scheme-*- + +$Id: dirs-liarc.scm,v 1.2 2007/01/12 02:57:10 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. + +|# + +;;;; Directories holding statically-linked C files. + +;;; Format is a list with the directory in the car and a list of +;;; exclusions in the cdr. + +("../runtime") +("../sf") +("../cref") +("../compiler") +("../compiler/back") +("../compiler/base") +("../compiler/fggen") +("../compiler/fgopt") +("../compiler/machines/C") +("../compiler/rtlbase") +("../compiler/rtlgen") +("../compiler/rtlopt") +("../star-parser" "compile" "ed-ffi" "load" "test-parser") diff --git a/v7/src/microcode/makegen/liarc-rules-2 b/v7/src/microcode/makegen/liarc-rules-2 new file mode 100644 index 000000000..de1cb9832 --- /dev/null +++ b/v7/src/microcode/makegen/liarc-rules-2 @@ -0,0 +1,35 @@ +# -*- Makefile -*- +# +# $Id: liarc-rules-2,v 1.2 2007/01/12 02:57:10 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. + +# Makefile rules for C back end + +$(LIARC_OBJECTS): $(LIARC_HEAD_FILES) +cmpauxmd.o: cmpauxmd.c $(LIARC_HEAD_FILES) prims.h bignum.h bitstr.h avltree.h +compinit.o: compinit.c compinit.h $(LIARC_HEAD_FILES) +unstackify.o: unstackify.c stackops.h $(LIARC_HEAD_FILES) + +compinit.h: $(LIARC_SOURCES) Makefile + rm -f $@ + ./make-compinit $(LIARC_SOURCES) > $@ diff --git a/v7/src/microcode/makegen/makegen.scm b/v7/src/microcode/makegen/makegen.scm index 827d27680..3e269c24a 100644 --- a/v7/src/microcode/makegen/makegen.scm +++ b/v7/src/microcode/makegen/makegen.scm @@ -1,6 +1,6 @@ #| -*-Scheme-*- -$Id: makegen.scm,v 1.14 2007/01/05 21:19:26 cph Exp $ +$Id: makegen.scm,v 1.15 2007/01/12 02:57:10 cph Exp $ Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, @@ -32,27 +32,20 @@ USA. (load-option 'REGULAR-EXPRESSION) (load-option 'SYNCHRONOUS-SUBPROCESS) -(define (generate-makefile template deps-filename makefile) +(define (generate-makefile) (let ((file-lists (map (lambda (pathname) (cons (pathname-name pathname) (read-file pathname))) - (list-transform-positive (directory-read "makegen/") + (keep-matching-items (directory-read "makegen/") (lambda (pathname) (re-string-match "^files-.+\\.scm$" (file-namestring pathname))))))) - (call-with-input-file template + (call-with-input-file "makegen/Makefile.in.in" (lambda (input) - (call-with-output-file makefile + (call-with-output-file "Makefile.in" (lambda (output) - (write-string "# This file automatically generated from " output) - (write-string (file-namestring template) output) - (newline output) - (write-string "# on " output) - (write-string (universal-time->string (get-universal-time)) output) - (write-string "." output) - (newline output) - (newline output) + (write-header output) (let loop ((column 0)) (let ((char (read-char input))) (if (not (eof-object? char)) @@ -62,17 +55,42 @@ USA. (if (eqv? #\@ (peek-char input)) (read-char input) (error "Missing @ at end of command:" command)) - (loop (interpret-command command column - file-lists deps-filename + (loop (interpret-command command column file-lists output))) (begin (write-char char output) (loop (if (char=? #\newline char) 0 - (+ column 1)))))))))))))) - -(define (interpret-command command column file-lists deps-filename output) + (+ column 1))))))))))))) + (call-with-output-file "liarc-rules-1" + (lambda (output) + (write-header output) + (write-rule "LIARC_HEAD_FILES" + "=" + (cddr (generate-rule "liarc-gendeps.c")) + output) + (newline output) + (newline output) + (let ((files + (cons "utabmd" + (enumerate-directories + (read-file "makegen/dirs-liarc.scm"))))) + (write-rule "LIARC_SOURCES" "=" (files+suffix files ".c") output) + (newline output) + (newline output) + (write-rule "LIARC_OBJECTS" "=" (files+suffix files ".o") output) + (newline output))))) + +(define (write-header output) + (write-string "# This file automatically generated at " output) + (write-string (universal-time->local-iso8601-string (get-universal-time)) + output) + (write-string "." output) + (newline output) + (newline output)) + +(define (interpret-command command column file-lists output) (let ((malformed (lambda () (error "Malformed command:" command)))) (if (not (and (pair? command) (symbol? (car command)) @@ -82,26 +100,73 @@ USA. (lambda (n) (if (not (= n (length (cdr command)))) (malformed))))) - (let ((map-over-entries - (lambda (procedure) + (let ((write-suffixed + (lambda (suffix) (guarantee-nargs 1) (let ((entry (assoc (cadr command) file-lists))) (if (not entry) (malformed)) - (write-items (map procedure (cdr entry)) + (write-items (files+suffix (cdr entry) suffix) column - output) - 0)))) - (case (car command) - ((WRITE-SOURCES) - (map-over-entries (lambda (entry) (string-append entry ".c")))) - ((WRITE-OBJECTS) - (map-over-entries (lambda (entry) (string-append entry ".o")))) - ((WRITE-DEPENDENCIES) - (guarantee-nargs 0) - (write-dependencies file-lists deps-filename output)) - (else - (error "Unknown command:" command))))))) + output))))) + (case (car command) + ((WRITE-SOURCES) + (write-suffixed ".c")) + ((WRITE-OBJECTS) + (write-suffixed ".o")) + ((WRITE-DEPENDENCIES) + (guarantee-nargs 0) + (write-dependencies file-lists "Makefile.deps" output)) + (else + (error "Unknown command:" command))))))) + +(define (enumerate-directories specs) + (map (lambda (path) + (enough-namestring (pathname-new-type path #f))) + (append-map (lambda (spec) + (let ((dir (pathname-as-directory (car spec)))) + (if (file-directory? dir) + (delete-matching-items + (directory-read (merge-pathnames "*.scm" dir)) + (lambda (path) + (member (pathname-name path) (cdr spec)))) + (begin + (warn "Can't read directory:" dir) + '())))) + specs))) + +(define (files+suffix files suffix) + (map (lambda (file) + (string-append file suffix)) + files)) + +(define (write-rule lhs op rhs port) + (write-string lhs port) + (write-string " " port) + (write-string op port) + (write-string " " port) + (write-items rhs (+ (string-length lhs) (string-length op) 2) port)) + +(define (write-items items start-column port) + (let loop ((items* items) (column start-column)) + (if (pair? items*) + (let ((column + (if (eq? items* items) + column + (begin + (write-string " " port) + (+ column 1)))) + (delta (string-length (car items*)))) + (let ((new-column (+ column delta))) + (if (>= new-column 78) + (begin + (write-string "\\\n\t" port) + (write-string (car items*) port) + (loop (cdr items*) (+ 8 delta))) + (begin + (write-string (car items*) port) + (loop (cdr items*) new-column))))) + column))) (define (write-dependencies file-lists deps-filename output) (maybe-update-dependencies @@ -110,7 +175,7 @@ USA. (map (lambda (base) (string-append base ".c")) (cdr file-list))) file-lists) - string= new-column 78) - (begin - (write-string "\\\n\t" port) - (write-string (car items*) port) - (loop (cdr items*) (+ 8 delta))) - (begin - (write-string (car items*) port) - (loop (cdr items*) new-column))))) - column))) + string