From 698613cd7d9d2c17688473fe11e09257940eb266 Mon Sep 17 00:00:00 2001 From: David Given Date: Mon, 18 Jun 2018 22:17:38 +0200 Subject: [PATCH] Turns out that the compiler needs access to the libpc headers too; refactor into a separate target to avoid build loops and make it work. --- lang/pc/comp/build.lua | 1 + lang/pc/comp/proto.main | 65 ----------- lang/pc/comp/proto.make | 154 --------------------------- lang/pc/include/build.lua | 4 + lang/pc/{libpc => include}/pc.h | 58 +++++----- lang/pc/{libpc => include}/pc_err.h | 0 lang/pc/{libpc => include}/pc_file.h | 0 lang/pc/{libpc => include}/pc_math.h | 0 lang/pc/libpc/Makefile | 13 --- lang/pc/libpc/build.lua | 8 +- plat/build.lua | 4 +- 11 files changed, 41 insertions(+), 266 deletions(-) delete mode 100644 lang/pc/comp/proto.main delete mode 100644 lang/pc/comp/proto.make create mode 100644 lang/pc/include/build.lua rename lang/pc/{libpc => include}/pc.h (100%) rename lang/pc/{libpc => include}/pc_err.h (100%) rename lang/pc/{libpc => include}/pc_file.h (100%) rename lang/pc/{libpc => include}/pc_math.h (100%) delete mode 100644 lang/pc/libpc/Makefile diff --git a/lang/pc/comp/build.lua b/lang/pc/comp/build.lua index c10c1793f..d856709a3 100644 --- a/lang/pc/comp/build.lua +++ b/lang/pc/comp/build.lua @@ -111,6 +111,7 @@ cprogram { "+scope_h", "+type_h", "h+emheaders", + "lang/pc/include+headers", "modules+headers", "modules/src/alloc+lib", "modules/src/em_code+lib_k", diff --git a/lang/pc/comp/proto.main b/lang/pc/comp/proto.main deleted file mode 100644 index eb470ddd4..000000000 --- a/lang/pc/comp/proto.main +++ /dev/null @@ -1,65 +0,0 @@ -# $Id$ - -# C compilation part. Not to be called directly. -# Instead, it is to be called by the Makefile. -# SRC_DIR, UTIL_HOME, TARGET_HOME, CC, COPTIONS, LINT, LINTOPTIONS, LDOPTIONS, -# CC_AND_MKDEP, SUF, LIBSUF should be set here. - -#PARAMS do not remove this line! - -# PRODUCE is either e (readable EM) or k (compact EM) -PRODUCE = k - -MDIR = $(TARGET_HOME)/modules -LIBDIR = $(MDIR)/lib -LINTLIBDIR = $(UTIL_HOME)/modules/lib - -MALLOC = $(LIBDIR)/malloc.$(SUF) - -EMLIB = $(LIBDIR)/libem_mes.$(LIBSUF) \ - $(LIBDIR)/libem$(PRODUCE).$(LIBSUF) \ - $(TARGET_HOME)/lib.bin/em_data.$(LIBSUF) - -MODLIB = $(LIBDIR)/libinput.$(LIBSUF) \ - $(LIBDIR)/libassert.$(LIBSUF) \ - $(LIBDIR)/liballoc.$(LIBSUF) \ - $(MALLOC) \ - $(LIBDIR)/libflt.$(LIBSUF) \ - $(LIBDIR)/libprint.$(LIBSUF) \ - $(LIBDIR)/libstring.$(LIBSUF) \ - $(LIBDIR)/libsystem.$(LIBSUF) - -LIBS = $(EMLIB) $(MODLIB) - -LINTLIBS = $(LINTLIBDIR)/$(LINTPREF)em_mes.$(LINTSUF) \ - $(LINTLIBDIR)/$(LINTPREF)emk.$(LINTSUF) \ - $(LINTLIBDIR)/$(LINTPREF)input.$(LINTSUF) \ - $(LINTLIBDIR)/$(LINTPREF)assert.$(LINTSUF) \ - $(LINTLIBDIR)/$(LINTPREF)alloc.$(LINTSUF) \ - $(LINTLIBDIR)/$(LINTPREF)flt.$(LINTSUF) \ - $(LINTLIBDIR)/$(LINTPREF)print.$(LINTSUF) \ - $(LINTLIBDIR)/$(LINTPREF)string.$(LINTSUF) \ - $(LINTLIBDIR)/$(LINTPREF)system.$(LINTSUF) - -PROFILE = -INCLUDES = -I. -I$(SRC_DIR) -I$(TARGET_HOME)/modules/h -I$(TARGET_HOME)/h -I$(TARGET_HOME)/modules/pkg -CFLAGS = $(PROFILE) $(INCLUDES) $(COPTIONS) -DSTATIC=static -LINTFLAGS = $(INCLUDES) $(LINTOPTIONS) -DNORCSID -DSTATIC=static -LDFLAGS = $(PROFILE) $(LDOPTIONS) - -# C_SRC and OBJ should be set here. -#LISTS do not remove this line! - -all: main - -clean: - rm -f *.$(SUF) main - -lint: - $(LINT) $(LINTFLAGS) $(C_SRC) $(LINTLIBS) - -main: $(OBJ) - $(CC) $(LDFLAGS) $(OBJ) $(LIBS) -o main - -# do not remove the next line; it is used for generating dependencies -#DEPENDENCIES diff --git a/lang/pc/comp/proto.make b/lang/pc/comp/proto.make deleted file mode 100644 index e4c9e1721..000000000 --- a/lang/pc/comp/proto.make +++ /dev/null @@ -1,154 +0,0 @@ -# $Id$ - -# make Pascal compiler - -#PARAMS do not remove this line! - -UTIL_BIN = \ - $(UTIL_HOME)/bin -SRC_DIR = \ - $(SRC_HOME)/lang/pc/comp - -TABGEN= $(UTIL_BIN)/tabgen -LLGEN = $(UTIL_BIN)/LLgen -LLGENOPTIONS = \ - -v - -SRC_G = $(SRC_DIR)/program.g $(SRC_DIR)/declar.g \ - $(SRC_DIR)/expression.g $(SRC_DIR)/statement.g -GEN_G = tokenfile.g -GFILES= $(GEN_G) $(SRC_G) - -SRC_C = $(SRC_DIR)/LLlex.c $(SRC_DIR)/LLmessage.c $(SRC_DIR)/body.c \ - $(SRC_DIR)/error.c $(SRC_DIR)/label.c $(SRC_DIR)/readwrite.c \ - $(SRC_DIR)/main.c $(SRC_DIR)/tokenname.c $(SRC_DIR)/idf.c \ - $(SRC_DIR)/input.c $(SRC_DIR)/type.c $(SRC_DIR)/def.c \ - $(SRC_DIR)/misc.c $(SRC_DIR)/enter.c $(SRC_DIR)/progs.c \ - $(SRC_DIR)/typequiv.c $(SRC_DIR)/node.c $(SRC_DIR)/cstoper.c \ - $(SRC_DIR)/chk_expr.c $(SRC_DIR)/options.c $(SRC_DIR)/scope.c \ - $(SRC_DIR)/desig.c $(SRC_DIR)/code.c $(SRC_DIR)/lookup.c \ - $(SRC_DIR)/stab.c -GEN_C = tokenfile.c program.c declar.c expression.c statement.c \ - symbol2str.c char.c Lpars.c casestat.c tmpvar.c next.c -CFILES= $(SRC_C) $(GEN_C) - -SRC_H = $(SRC_DIR)/LLlex.h $(SRC_DIR)/chk_expr.h $(SRC_DIR)/class.h \ - $(SRC_DIR)/const.h $(SRC_DIR)/debug.h $(SRC_DIR)/f_info.h \ - $(SRC_DIR)/idf.h $(SRC_DIR)/input.h $(SRC_DIR)/main.h \ - $(SRC_DIR)/misc.h $(SRC_DIR)/required.h $(SRC_DIR)/tokenname.h - -GEN_H = errout.h idfsize.h numsize.h strsize.h target_sizes.h \ - inputtype.h density.h nocross.h def.h debugcst.h \ - type.h Lpars.h node.h dbsymtab.h scope.h desig.h - -HFILES= $(GEN_H) $(SRC_H) - -NEXTFILES = \ - $(SRC_DIR)/def.H $(SRC_DIR)/type.H $(SRC_DIR)/node.H \ - $(SRC_DIR)/scope.H $(SRC_DIR)/desig.H \ - $(SRC_DIR)/tmpvar.C $(SRC_DIR)/casestat.C - -all: make.main - make -f make.main main - -install: all - cp main $(TARGET_HOME)/lib.bin/em_pc - -cmp: all - -cmp main $(TARGET_HOME)/lib.bin/em_pc - -opr: - make pr | opr - -pr: - @pr $(SRC_DIR)/proto.make $(SRC_DIR)/proto.main Parameters \ - $(SRC_DIR)/char.tab $(SRC_G) $(SRC_H) $(NEXTFILES) $(SRC_C) - -lint: make.main - make -f make.main lint - -Cfiles: hfiles LLfiles $(GEN_C) $(GEN_H) Makefile - echo $(CFILES) | tr ' ' '\012' > Cfiles - echo $(HFILES) | tr ' ' '\012' >> Cfiles - -resolved: Cfiles - CC="$(CC)" UTIL_HOME="$(UTIL_HOME)" do_resolve `cat Cfiles` > Cfiles.new - -if cmp -s Cfiles Cfiles.new ; then rm -f Cfiles.new ; else mv Cfiles.new Cfiles ; fi - touch resolved - -# there is no file called "dependencies"; we want dependencies checked -# every time. This means that make.main is made every time. Oh well ... -# it does not take much time. -dependencies: resolved - do_deps `grep '.c$$' Cfiles` - -make.main: dependencies make_macros lists $(SRC_DIR)/proto.main - rm_deps $(SRC_DIR)/proto.main | sed -e '/^.PARAMS/r make_macros' -e '/^.LISTS/r lists' > make.main - cat *.dep >> make.main - -make_macros: Makefile - echo 'SRC_DIR=$(SRC_DIR)' > make_macros - echo 'UTIL_HOME=$(UTIL_HOME)' >> make_macros - echo 'TARGET_HOME=$(TARGET_HOME)' >> make_macros - echo 'CC=$(CC)' >> make_macros - echo 'COPTIONS=$(COPTIONS)' >> make_macros - echo 'LDOPTIONS=$(LDOPTIONS)' >> make_macros - echo 'LINT=$(LINT)' >> make_macros - echo 'LINTSUF=$(LINTSUF)' >> make_macros - echo 'LINTPREF=$(LINTPREF)' >> make_macros - echo 'LINTOPTIONS=$(LINTOPTIONS)' >> make_macros - echo 'SUF=$(SUF)' >> make_macros - echo 'LIBSUF=$(LIBSUF)' >> make_macros - echo 'CC_AND_MKDEP=$(CC_AND_MKDEP)' >> make_macros - -lists: Cfiles - echo "C_SRC = \\" > lists - echo $(CFILES) >> lists - echo "OBJ = \\" >> lists - echo $(CFILES) | sed -e 's|[^ ]*/||g' -e 's/\.c/.$$(SUF)/g' >> lists - -clean: - -make -f make.main clean - rm -f $(GEN_C) $(GEN_G) $(GEN_H) hfiles LLfiles Cfiles LL.output - rm -f resolved *.dep lists make.main make_macros - -LLfiles: $(GFILES) - $(LLGEN) $(LLGENOPTIONS) $(GFILES) - @touch LLfiles - -hfiles: Parameters $(SRC_DIR)/make.hfiles - $(SRC_DIR)/make.hfiles Parameters - touch hfiles - -tokenfile.g: $(SRC_DIR)/tokenname.c $(SRC_DIR)/make.tokfile - $(SRC_DIR)/make.tokfile <$(SRC_DIR)/tokenname.c >tokenfile.g - -symbol2str.c: $(SRC_DIR)/tokenname.c $(SRC_DIR)/make.tokcase - $(SRC_DIR)/make.tokcase <$(SRC_DIR)/tokenname.c >symbol2str.c - -def.h: $(SRC_DIR)/make.allocd $(SRC_DIR)/def.H - $(SRC_DIR)/make.allocd < $(SRC_DIR)/def.H > def.h - -type.h: $(SRC_DIR)/make.allocd $(SRC_DIR)/type.H - $(SRC_DIR)/make.allocd < $(SRC_DIR)/type.H > type.h - -scope.h: $(SRC_DIR)/make.allocd $(SRC_DIR)/scope.H - $(SRC_DIR)/make.allocd < $(SRC_DIR)/scope.H > scope.h - -node.h: $(SRC_DIR)/make.allocd $(SRC_DIR)/node.H - $(SRC_DIR)/make.allocd < $(SRC_DIR)/node.H > node.h - -desig.h: $(SRC_DIR)/make.allocd $(SRC_DIR)/desig.H - $(SRC_DIR)/make.allocd < $(SRC_DIR)/desig.H > desig.h - -tmpvar.c: $(SRC_DIR)/make.allocd $(SRC_DIR)/tmpvar.C - $(SRC_DIR)/make.allocd < $(SRC_DIR)/tmpvar.C > tmpvar.c - -casestat.c: $(SRC_DIR)/make.allocd $(SRC_DIR)/casestat.C - $(SRC_DIR)/make.allocd < $(SRC_DIR)/casestat.C > casestat.c - -next.c: $(NEXTFILES) $(SRC_DIR)/make.next - $(SRC_DIR)/make.next $(NEXTFILES) > next.c - -char.c: $(SRC_DIR)/char.tab - $(TABGEN) -f$(SRC_DIR)/char.tab >char.c diff --git a/lang/pc/include/build.lua b/lang/pc/include/build.lua new file mode 100644 index 000000000..24f43084a --- /dev/null +++ b/lang/pc/include/build.lua @@ -0,0 +1,4 @@ +clibrary { + name = "headers", + hdrs = {"./*.h"} +} diff --git a/lang/pc/libpc/pc.h b/lang/pc/include/pc.h similarity index 100% rename from lang/pc/libpc/pc.h rename to lang/pc/include/pc.h index a38c62637..12ca27359 100644 --- a/lang/pc/libpc/pc.h +++ b/lang/pc/include/pc.h @@ -36,32 +36,35 @@ extern char *_fcvt(double value, int ndigit, int *decpt, int *sign); extern char *_wdw(struct file *f); extern char *argv(int i); extern char *strbuf(char *s); +extern char* _hol0(void); extern double _abr(double r); extern double _atn(double x); extern double _cos(double x); extern double _exp(double x); +extern double _fef(double fl, int* res); +extern double _fif(double f1, double f2, double* f3); extern double _log(double x); extern double _rdr(struct file *f); extern double _rnd(double r); -extern void _sig(void (*)(unsigned int)); extern double _sin(double x); extern double _sqt(double x); -extern void _xcls(struct file *f); +extern int _abi(int i); +extern int _asz(struct descr *dp); +extern int _bcp(int sz, unsigned char *y, unsigned char *x); +extern int _dvi(unsigned int j, unsigned int i); +extern int _efl(struct file *f); +extern int _eln(struct file *f); +extern int _fstdig(struct file *f); +extern int _getint(struct file *f); +extern int _getsig(struct file *f); +extern int _mdi(int j, int i); +extern int _nxtdig(struct file *f); +extern int _rdc(struct file *f); +extern int _rdi(struct file *f); extern int argc(void); -extern void argshift(void); -extern void buff(struct file *f); -extern void diag(struct file *f); -extern void nobuff(struct file *f); -extern void notext(struct file *f); -extern void pclose(struct file *f); -extern void pcreat(struct file *f, char *s); extern int perrno(void); -extern void popen(struct file *f, char *s); -extern void procentry(char *name); -extern void procexit(char *name); extern int strfetch(char *s, int i); extern int strlen(char *s); -extern void strstore(char *s, int i, int c); extern int strtobuf(char *s, char *b, int l); extern int uread(int fd, char *b, int n); extern int uwrite(int fd, char *b, int n); @@ -70,41 +73,27 @@ extern long _dvil(unsigned long j, unsigned long i); extern long _mdil(long j, long i); extern long _mdl(long j, long i); extern long _rdl(struct file *f); -extern int _abi(int i); extern void _ass(int line, int bool); -extern int _asz(struct descr *dp); -extern int _bcp(int sz, unsigned char *y, unsigned char *x); extern void _catch(unsigned erno); extern void _cls(struct file *f); extern void _cre(int sz, struct file *f); extern void _dis(int n, void **ptr); -extern int _dvi(unsigned int j, unsigned int i); -extern int _efl(struct file *f); -extern int _eln(struct file *f); -extern double _fef(double fl, int* res); -extern double _fif(double f1, double f2, double* f3); extern void _flush(struct file *f); -extern int _fstdig(struct file *f); extern void _get(struct file *f); -extern int _getint(struct file *f); -extern int _getsig(struct file *f); extern void _hlt(int ecode); extern void _incpt(struct file *f); extern void _ini(char *args, int c, struct file **p, char *mainlb); -extern int _mdi(int j, int i); extern void _new(int n, void **ptr); extern void _nfa(int bool); -extern int _nxtdig(struct file *f); extern void _opn(int sz, struct file *f); extern void _outcpt(struct file *f); extern void _pac(struct descr *ad, struct descr *zd, char *zp, int i, char *ap); extern void _pag(struct file *f); extern void _put(struct file *f); extern void _rcka(struct array_descr *descr, int index); -extern int _rdc(struct file *f); -extern int _rdi(struct file *f); extern void _rf(struct file *f); extern void _rln(struct file *f); +extern void _sig(void (*)(unsigned int)); extern void _skipsp(struct file *f); extern void _trp(int trapno); extern void _unp(struct descr *ad, struct descr *zd, int i, char *ap, char *zp, int noext); @@ -126,6 +115,17 @@ extern void _wsr(int w, double r, struct file *f); extern void _wss(int w, int len, char* s, struct file* f); extern void _wstrin(int width, int len, char* buf, struct file* f); extern void _wsz(int w, char* s, struct file* f); -extern char* _hol0(void); +extern void _xcls(struct file *f); +extern void argshift(void); +extern void buff(struct file *f); +extern void diag(struct file *f); +extern void nobuff(struct file *f); +extern void notext(struct file *f); +extern void pclose(struct file *f); +extern void pcreat(struct file *f, char *s); +extern void popen(struct file *f, char *s); +extern void procentry(char *name); +extern void procexit(char *name); +extern void strstore(char *s, int i, int c); #endif diff --git a/lang/pc/libpc/pc_err.h b/lang/pc/include/pc_err.h similarity index 100% rename from lang/pc/libpc/pc_err.h rename to lang/pc/include/pc_err.h diff --git a/lang/pc/libpc/pc_file.h b/lang/pc/include/pc_file.h similarity index 100% rename from lang/pc/libpc/pc_file.h rename to lang/pc/include/pc_file.h diff --git a/lang/pc/libpc/pc_math.h b/lang/pc/include/pc_math.h similarity index 100% rename from lang/pc/libpc/pc_math.h rename to lang/pc/include/pc_math.h diff --git a/lang/pc/libpc/Makefile b/lang/pc/libpc/Makefile deleted file mode 100644 index 4a57a28f5..000000000 --- a/lang/pc/libpc/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -# $Id$ - -head: - echo This Makefile needs arguments - -clean: - rm -f *.old - -opr: - make pr | opr - -pr: - @pr Makefile *.[ec] diff --git a/lang/pc/libpc/build.lua b/lang/pc/libpc/build.lua index 0fb5faea5..08c3ef187 100644 --- a/lang/pc/libpc/build.lua +++ b/lang/pc/libpc/build.lua @@ -17,9 +17,10 @@ for _, plat in ipairs(vars.plats) do }, hdrs = {}, -- must be empty deps = { - "lang/cem/libcc.ansi/headers+pkg", - "plat/"..plat.."/include+pkg", "h+emheaders", + "lang/cem/libcc.ansi/headers+pkg", + "lang/pc/include+headers", + "plat/"..plat.."/include+pkg", }, vars = { plat = plat } } @@ -29,7 +30,8 @@ for _, plat in ipairs(vars.plats) do srcs = { "./head_pc.e" }, vars = { plat = plat }, deps = { - "h+emheaders" + "h+emheaders", + "lang/pc/include+headers", } } diff --git a/plat/build.lua b/plat/build.lua index 451ba4af9..017628abe 100644 --- a/plat/build.lua +++ b/plat/build.lua @@ -11,7 +11,7 @@ definerule("ackfile", suffix = { type="string", optional=true }, }, function (e) - local em = e.vars.plat:find("^em") + local em = (e.vars.plat or ""):find("^em") local suffix = e.suffix or (em and ".m" or ".o") local c = "-c"..suffix local plat = e.vars.plat @@ -47,7 +47,7 @@ definerule("acklibrary", deps = { type="targets", default={} }, }, function (e) - local em = e.vars.plat:find("^em") + local em = (e.vars.plat or ""):find("^em") return clibrary { name = e.name, srcs = e.srcs,