scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 14e32d4a1c837567c152a72e74a1dc6306b00f4f
parent 4904da0e4387644faf7fb6e0b813fbb1486f5df0
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon, 31 Dec 2018 15:41:50 +0000

[scripts] Add mklib script

This script uses lorder to get a correct order in the library
and it uses -q or -ru to make faster the creation of the library.
Some build options of GNU make make make not POSIX compliant
and the libc is fully replaced in the archive every time.
Send a patch to GNU to solve that problem.

Diffstat:
MLICENSE | 31+++----------------------------
MMakefile | 17++++++++++++++---
Mconfig/amd64-linux.mk | 1+
Mconfig/i386-linux.mk | 1+
Adoc/caldera.txt | 53+++++++++++++++++++++++++++++++++++++++++++++++++++++
Adoc/isc.txt | 30++++++++++++++++++++++++++++++
Ascripts/.gitignore | 1+
Ascripts/lorder | 47+++++++++++++++++++++++++++++++++++++++++++++++
Ascripts/mklib | 43+++++++++++++++++++++++++++++++++++++++++++
Msrc/driver/posix/Makefile | 5++---
Msrc/libc/Makefile | 9++++-----
Msrc/libc/arch/amd64/darwin/Makefile | 2+-
Msrc/libc/arch/amd64/dragonfly/Makefile | 2+-
Msrc/libc/arch/amd64/linux/Makefile | 2+-
Msrc/libc/arch/amd64/netbsd/Makefile | 2+-
Msrc/libc/arch/amd64/openbsd/Makefile | 2+-
Msrc/libc/arch/arm32/linux/Makefile | 2+-
Msrc/libc/arch/arm64/linux/Makefile | 2+-
Msrc/libc/libc.h | 14++++++--------
Dsrc/libc/mklst | 12------------
Msrc/libcoff32/Makefile | 3+--
Msrc/libscc/Makefile | 3+--
Mtests/ar/execute/Makefile | 2+-
Mtests/as/execute/Makefile | 2+-
Mtests/libc/execute/Makefile | 2+-
Mtests/nm/execute/Makefile | 2+-
Mtests/scc/error/Makefile | 2+-
Mtests/scc/execute/Makefile | 2+-
28 files changed, 220 insertions(+), 76 deletions(-)

diff --git a/LICENSE b/LICENSE @@ -1,29 +1,4 @@ -ISC License +All the files in this project are covered by the ISC license +except the next files: -(c) 2012-2017 Roberto E. Vargas Caballero <k0ga@shike2.com> - -(c) 2017 Michael Forney <mforney@mforney.org> -(c) 2015-2016 Dimitris Papastamos <sin@2f30.org> -(c) 2015-2016 Hiltjo Posthuma <hiltjo@codemadness.org> -(c) 2015-2016 Laslo Hunhold <dev@frign.de> -(c) 2015 Evan Gates <evan.gates@gmail.com> -(c) 2015-2017 Quentin Rameau <quinq@fifth.space> -(c) 2016-2017 Andrew Chambers <andrewchamberss@gmail.com> -(c) 2015 Sören Tempel <soeren+git@soeren-tempel.net> -(c) 2015-2017 Quentin Carbonneaux <quentin@c9x.me> -(c) 2016 Pekka Jylhä-Ollila <pekka.jylha.ollila@gmail.com> -(c) 2016 Alexander Krotov <ilabdsf@yandex.ru> -(c) 2016 Lucas Gabriel Vuotto <l.vuotto92@gmail.com> -(c) 2016 Raymond Nicholson <rain1@openmailbox.org> - -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +scripts/lorder Caldera diff --git a/Makefile b/Makefile @@ -4,6 +4,7 @@ PROJECTDIR = . include $(PROJECTDIR)/scripts/rules.mk DIRS = src include/scc/scc tests +ENV = $(SCRIPTDIR)/env.sh all: src @@ -13,15 +14,25 @@ dirs: $(SCRIPTDIR)/libc-proto xargs mkdir -p < $(SCRIPTDIR)/libc-proto touch dirs -$(DIRS): FORCE - +@cd $@ && $(MAKE) +$(DIRS): $(ENV) FORCE + . $(ENV) && cd $@ && $(MAKE) + +$(ENV): + @rm -f $@; \ + trap 'r=$?;rm -f $$$$.tmp;exit $r' EXIT HUP INT QUIT TERM; \ + (echo PATH=$$PWD/scripts:$$PATH:.; \ + echo NM=\"$(NM)\"; \ + echo AR=\"$(AR)\"; \ + echo RL=\"$(RL)\"; \ + echo RLFLAGS=\"$(RLFLAGS)\"; \ + echo export PATH RLFLAGS NM AR RL) > $$$$.tmp && mv $$$$.tmp $@ dep: $(FORALL) clean: $(FORALL) - rm -rf lib bin libexec dirs + rm -rf lib bin libexec dirs $(ENV) distclean: clean +@cd include/scc/scc && $(MAKE) distclean diff --git a/config/amd64-linux.mk b/config/amd64-linux.mk @@ -7,3 +7,4 @@ PREFIX = $(PWD)/$(PROJECTDIR)/root MANPREFIX = $(PREFIX)/share/man AS = as RANLIB = ranlib +NM = nm diff --git a/config/i386-linux.mk b/config/i386-linux.mk @@ -4,3 +4,4 @@ PREFIX = $(PWD)/$(PROJECTDIR)/root MANPREFIX = $(PREFIX)/share/man AS = as RANLIB = ranlib +NM = nm diff --git a/doc/caldera.txt b/doc/caldera.txt @@ -0,0 +1,53 @@ +Caldera International, Inc. hereby grants a fee free license that includes +the rights use, modify and distribute this named source code, including +creating derived binary products created from the source code. The source +code for which Caldera International, Inc. grants rights are limited +to the following UNIX Operating Systems that operate on the 16-Bit +PDP-11 CPU and early versions of the 32-Bit UNIX Operating System, with +specific exclusion of UNIX System III and UNIX System V and successor +operating systems: + +32-bit 32V UNIX + +16 bit UNIX Versions 1, 2, 3, 4, 5, 6, 7 + +Caldera International, Inc. makes no guarantees or commitments that any +source code is available from Caldera International, Inc. + +The following copyright notice applies to the source code files for +which this license is granted. + +Copyright(C) Caldera International Inc. 2001-2002. 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 and documentation 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. + +All advertising materials mentioning features or use of this software +must display the following acknowledgement: + +This product includes software developed or owned by Caldera +International, Inc. + +Neither the name of Caldera International, Inc. nor the names of other +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA +INTERNATIONAL, INC. 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 CALDERA INTERNATIONAL, INC. 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. diff --git a/doc/isc.txt b/doc/isc.txt @@ -0,0 +1,30 @@ +ISC License + +(c) 2012-2019 Roberto E. Vargas Caballero <k0ga@shike2.com> + +(c) 2017 Michael Forney <mforney@mforney.org> +(c) 2015-2016 Dimitris Papastamos <sin@2f30.org> +(c) 2015-2016 Hiltjo Posthuma <hiltjo@codemadness.org> +(c) 2015-2016 Laslo Hunhold <dev@frign.de> +(c) 2015 Evan Gates <evan.gates@gmail.com> +(c) 2015-2019 Quentin Rameau <quinq@fifth.space> +(c) 2016-2017 Andrew Chambers <andrewchamberss@gmail.com> +(c) 2015 Sören Tempel <soeren+git@soeren-tempel.net> +(c) 2015-2017 Quentin Carbonneaux <quentin@c9x.me> +(c) 2016 Pekka Jylhä-Ollila <pekka.jylha.ollila@gmail.com> +(c) 2016 Alexander Krotov <ilabdsf@yandex.ru> +(c) 2016 Lucas Gabriel Vuotto <l.vuotto92@gmail.com> +(c) 2016 Raymond Nicholson <rain1@openmailbox.org> +(c) 2018-2019 zerous Naveen Narayanan <zerous@nocebo.space> + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/scripts/.gitignore b/scripts/.gitignore @@ -0,0 +1 @@ +env.sh diff --git a/scripts/lorder b/scripts/lorder @@ -0,0 +1,47 @@ +#!/bin/sh + +set -e +trap 'r=$?;rm -f $$sym?ef; exit $r' EXIT HUP INT QUIT TERM + +case $# in +0) + echo usage: lorder file ... >&2 + exit 1 +esac + +rm -f $$sym?ef + +(echo $1: + ${NM:-nm} -g "$@") | sed -n ' + /\.o:$/ { + s/:// + h + s/.*/& &/ + p + } + / [ADTR] / { + s/.* // + G + s/\n/ / + w '$$symdef' + } + / C / { + s/.* // + G + s/\n/ / + w '$$symcef' + } + / U / { + s/.* // + G + s/\n/ / + w '$$symref' + } +' +sort $$symdef -o $$symdef +sort $$symref -o $$symref +sort $$symcef -o $$symcef +(join $$symref $$symdef + join $$symref $$symcef + join $$symcef $$symdef) | +sed 's/[^ ]* *//' diff --git a/scripts/mklib b/scripts/mklib @@ -0,0 +1,43 @@ +#!/bin/sh + +set -e + +usage() +{ + echo usage: mklib [-o library] file ... >&2 + exit 1 +} + +for i +do + case "$1" in + -o) + out=$2 + shift 2 + ;; + --) + shift + break; + ;; + -*) + usage + ;; + esac +done + +case $# in +0) + usage + ;; +esac + +lib=${out-a.out} + +if ! test -f $lib +then + ${AR:-ar} -qv $lib $(lorder $@ | tsort) +else + ${AR:-ar} -ruv $lib $(lorder $@ | tsort) +fi + +${RL:-ranlib} $RLFLAGS $lib diff --git a/src/driver/posix/Makefile b/src/driver/posix/Makefile @@ -27,10 +27,9 @@ $(BINDIR)/scpp: cpp.sh config.h mv $$$$.sh $@ config.h: - PREFIX=$(PREFIX) ./config.sh $(SYSLST) + PREFIX=$(PREFIX) config.sh $(SYSLST) -dep: - $(PROJECTDIR)/mkdep.sh +dep: inc-dep clean: rm -f scc scpp *.o diff --git a/src/libc/Makefile b/src/libc/Makefile @@ -19,12 +19,11 @@ all: $(DIRS) $(DIRS): FORCE +@cd $@ && $(MAKE) -objlst: FORCE - ./mklst $(TARGET) +objlst: + find . -name '*.o' > $@ -$(TARGET): objlst - xargs $(AR) $(ARFLAGS) $@ < objlst - $(RL) $(RANLIBFLAGS) $@ +$(TARGET): objlst FORCE + mklib -o $@ `cat objlst` clean: $(FORALL) diff --git a/src/libc/arch/amd64/darwin/Makefile b/src/libc/arch/amd64/darwin/Makefile @@ -26,7 +26,7 @@ all: syscall objs: $(OBJS) syscall: syscall.lst - ./gensys.sh syscall.lst + gensys.sh syscall.lst touch syscall clean: diff --git a/src/libc/arch/amd64/dragonfly/Makefile b/src/libc/arch/amd64/dragonfly/Makefile @@ -27,7 +27,7 @@ all: syscall objs: $(OBJS) syscall: syscall.lst - ./gensys.sh syscall.lst + gensys.sh syscall.lst touch syscall clean: diff --git a/src/libc/arch/amd64/linux/Makefile b/src/libc/arch/amd64/linux/Makefile @@ -29,7 +29,7 @@ all: syscall objs: $(OBJS) syscall: syscall.lst - ./gensys.sh syscall.lst + gensys.sh syscall.lst touch syscall clean: diff --git a/src/libc/arch/amd64/netbsd/Makefile b/src/libc/arch/amd64/netbsd/Makefile @@ -30,7 +30,7 @@ all: syscall objs: $(OBJS) syscall: syscall.lst - ./gensys.sh syscall.lst + gensys.sh syscall.lst touch syscall clean: diff --git a/src/libc/arch/amd64/openbsd/Makefile b/src/libc/arch/amd64/openbsd/Makefile @@ -27,7 +27,7 @@ all: syscall objs: $(OBJS) syscall: syscall.lst - ./gensys.sh syscall.lst + gensys.sh syscall.lst touch syscall clean: diff --git a/src/libc/arch/arm32/linux/Makefile b/src/libc/arch/arm32/linux/Makefile @@ -29,7 +29,7 @@ all: syscall objs: $(OBJS) syscall: syscall.lst - ./gensys.sh syscall.lst + gensys.sh syscall.lst touch syscall clean: diff --git a/src/libc/arch/arm64/linux/Makefile b/src/libc/arch/arm64/linux/Makefile @@ -29,7 +29,7 @@ all: syscall objs: $(OBJS) syscall: syscall.lst - ./gensys.sh syscall.lst + gensys.sh syscall.lst touch syscall clean: diff --git a/src/libc/libc.h b/src/libc/libc.h @@ -16,12 +16,6 @@ #define SECHOUR (60 * SECMIN) /* 3600 */ #define SECDAY (24 * SECHOUR) /* 86400 */ -#ifdef stdin -extern FILE *_fpopen(const char * restrict fname, - const char * restrict mode, - FILE * restrict fp); -#endif - struct tzone { char *name; int gmtoff; @@ -35,9 +29,13 @@ extern int _daysyear(int year); extern int _newyear(int year); extern void *_getheap(void); extern int _dtoi(char); -#ifdef FILE + +#ifdef stdin extern int _flsbuf(FILE *fp); -extern void _allocbuf(FILE *fp); +extern int _allocbuf(FILE *fp); +extern FILE *_fpopen(const char * restrict fname, + const char * restrict mode, + FILE * restrict fp); #endif extern int _daysmon[12]; diff --git a/src/libc/mklst b/src/libc/mklst @@ -1,12 +0,0 @@ -#!/bin/sh - -set -e -trap 'r=$?;rm -f $$.tmp;exit $r' EXIT HUP QUIT INT TERM -archive=${1?'First parameter must be the archive name'} - -if test -f $archive -then - newer="-newer $archive" -fi - -find . -name '*.o' $newer > $$.tmp && mv $$.tmp objlst diff --git a/src/libcoff32/Makefile b/src/libcoff32/Makefile @@ -17,8 +17,7 @@ TARGET = $(LIBDIR)/libcoff32.a all: $(TARGET) $(TARGET): $(OBJS) - $(AR) $(ARFLAGS) $@ $? - ranlib $@ + mklib -o $@ $? dep: inc-dep diff --git a/src/libscc/Makefile b/src/libscc/Makefile @@ -24,8 +24,7 @@ TARGET = $(LIBDIR)/libscc.a all: $(TARGET) $(TARGET): $(OBJS) - $(AR) $(ARFLAGS) $@ $? - ranlib $@ + mklib -o $@ $(OBJS) dep: inc-dep diff --git a/tests/ar/execute/Makefile b/tests/ar/execute/Makefile @@ -6,7 +6,7 @@ ROOT=$(PROJECTDIR)/root all: tests tests: master.a - @TZ=UTC PATH=$(ROOT)/bin:$$PATH ./chktest.sh + @TZ=UTC PATH=$(ROOT)/bin:$$PATH chktest.sh master.a: ./mkmaster.sh diff --git a/tests/as/execute/Makefile b/tests/as/execute/Makefile @@ -6,7 +6,7 @@ ROOT=$(PROJECTDIR)/root all: tests tests: - @PATH=$(ROOT)/bin:$$PATH ./chktest.sh + @PATH=$(ROOT)/bin:$$PATH chktest.sh clean: rm -f test.log diff --git a/tests/libc/execute/Makefile b/tests/libc/execute/Makefile @@ -10,7 +10,7 @@ CC = SCCPREFIX=$(ROOT) ./cc.sh all: tests tests: - @CFLAGS='' SCCPREFIX=$(ROOT) ./chktest.sh libc-tests.lst + @CFLAGS='' SCCPREFIX=$(ROOT) chktest.sh libc-tests.lst clean: rm -f *.o *core a.out test.log diff --git a/tests/nm/execute/Makefile b/tests/nm/execute/Makefile @@ -7,7 +7,7 @@ OUT = z80.out all: tests tests: $(OUT) - @PATH=$(ROOT)/bin:$$PATH ./chktest.sh + @PATH=$(ROOT)/bin:$$PATH chktest.sh z80.out: master.s z80-unknown-coff-as -o $@ master.s diff --git a/tests/scc/error/Makefile b/tests/scc/error/Makefile @@ -5,7 +5,7 @@ ROOT=../../../root all: tests tests: - @CFLAGS='' SCCPREFIX=$(ROOT) PATH=$(ROOT)/bin:$$PATH ./chktest.sh scc-tests.lst + @CFLAGS='' SCCPREFIX=$(ROOT) PATH=$(ROOT)/bin:$$PATH chktest.sh scc-tests.lst clean: rm -f *.as *.o *.ir *.qbe *core test.log diff --git a/tests/scc/execute/Makefile b/tests/scc/execute/Makefile @@ -5,7 +5,7 @@ ROOT=../../../root all: tests tests: - @CFLAGS='' SCCPREFIX=$(ROOT) PATH=$(ROOT)/bin:$$PATH ./chktest.sh scc-tests.lst + @CFLAGS='' SCCPREFIX=$(ROOT) PATH=$(ROOT)/bin:$$PATH chktest.sh scc-tests.lst clean: rm -f *.as *.o *.ir *.qbe *core test.log