From: Thomas Walker Lynch Date: Mon, 1 Apr 2019 22:30:29 +0000 (+0200) Subject: trc make example working X-Git-Url: https://git.reasoningtechnology.com/style/static/gitweb.js?a=commitdiff_plain;h=b15f6fca8a6b9fa01723f8b881b749bd0a29929d;p=subu trc make example working --- diff --git a/doc/makefile-issue b/doc/makefile-issue index 859cf77..8916de0 100644 --- a/doc/makefile-issue +++ b/doc/makefile-issue @@ -1,6 +1,6 @@ 1. -For the following makefile, the .PHONEY tag is ignored unless there +For the following makefile, the .PHONY tag is ignored unless there is an explicit target with that name. The %:: target is not enough. So for expample, if there is an exec directory, the exec target caught through the %:: will never fire. The commented lines must diff --git a/module/da/makefile b/module/da/makefile index e3947d9..6f535ea 100644 --- a/module/da/makefile +++ b/module/da/makefile @@ -10,6 +10,11 @@ MAKE=/usr/bin/make --no-print-directory -f $(PROJECT_SUBU)/tool/lib/makefile-cc .PHONY: all all: version +.PHONY: dep +dep: + if [ -e $(DEPFILE) ]; then rm $(DEPFILE); fi + $(MAKE) $@ + .PHONY: lib lib: $(MAKE) $@ diff --git a/module/da/test/makefile b/module/da/test/makefile index 292b456..b538ac2 100644 --- a/module/da/test/makefile +++ b/module/da/test/makefile @@ -9,6 +9,11 @@ MAKE=/usr/bin/make --no-print-directory -f $(PROJECT_SUBU)/tool/lib/makefile-cc .PHONY: all lib exec all: version deps lib exec +.PHONY: dep +dep: + if [ -e $(DEPFILE) ]; then rm $(DEPFILE); fi + $(MAKE) $@ + lib: $(MAKE) $@ diff --git a/module/dispatch/makefile b/module/dispatch/makefile index 175b683..0714330 100644 --- a/module/dispatch/makefile +++ b/module/dispatch/makefile @@ -1,10 +1,41 @@ # src-dispatch/makefile SHELL=/bin/bash +MAKE=/usr/bin/make --no-print-directory -f $(PROJECT_SUBU)/tool/lib/makefile-cc +#MAKE=/usr/bin/make -f $(PROJECT_SUBU)/tool/lib/makefile-cc -include makefile-flags +DEPFILE=$(TMPDIR)/makefile-cc.deps -all: version dep lib +.PHONY: all +all: version + +.PHONY: info +info: + @echo "TRCDIR: " $(TRCDIR) + $(MAKE) $@ + +.PHONY: setup +setup: + [ ! -e $(TRCDIR) ] && mkdir $(TRCDIR) || true + $(MAKE) $@ + +.PHONY: dep +dep: + if [ -e $(DEPFILE) ]; then rm $(DEPFILE); fi + trcsources=$(wildcard $(TRCDIR)/*.trc.c)$(wildcard $(TRCDIR)/*.trc.cc);\ + $(ECHO) $$trcsources;\ + if [ ! -z "$$trcsources" ]; then\ + trctargets=$$(tranche-target $$trcsources -sep " " -tdir $(SRCDIR) );\ + $(ECHO) $$trctargets;\ + tranche-make $$trcsources -tdir $(SRCDIR) -mfile $(DEPFILE);\ + $(MAKE) $$trctargets;\ + fi + $(MAKE) $@ + +.PHONY: lib +lib: + $(MAKE) $@ %:: $(MAKE) $@ diff --git a/module/dispatch/makefile-flags b/module/dispatch/makefile-flags index eb127fc..b493dae 100644 --- a/module/dispatch/makefile-flags +++ b/module/dispatch/makefile-flags @@ -15,9 +15,8 @@ CFLAGS=-std=gnu11 -fPIC -I. -ggdb -Werror -DDEBUG -DDEBUGDB LINKFLAGS=-L1_lib -lda +TMPDIR=tmp SRCDIR=tmp TRCDIR=trc -MAKE=/usr/bin/make --no-print-directory -f $(PROJECT_SUBU)/tool/lib/makefile-cc -#MAKE=/usr/bin/make -f $(PROJECT_SUBU)/tool/lib/makefile-cc diff --git a/module/dispatch/tranche b/module/dispatch/tranche new file mode 100755 index 0000000..ad95624 Binary files /dev/null and b/module/dispatch/tranche differ diff --git a/module/dispatch/trc/dispatch.trc.c b/module/dispatch/trc/dispatch.trc.c index 3b594a7..24d7cd3 100644 --- a/module/dispatch/trc/dispatch.trc.c +++ b/module/dispatch/trc/dispatch.trc.c @@ -30,7 +30,7 @@ struct dispatch_ctx{ }; #tranche-end -#include "dispatch.h" +#include "dispatch.lib.h" // we need the declaration for uid_t etc. // without this #define execvpe is undefined @@ -163,4 +163,8 @@ int dispatch_exec(char **argv, char **envp){ } } +#tranche dispatch.lib.h +#endif +#tranche-end + #tranche-end diff --git a/module/share/lib/libda.a b/module/share/lib/libda.a index 67e5e14..0ca94fb 100644 Binary files a/module/share/lib/libda.a and b/module/share/lib/libda.a differ diff --git a/module/tranche/makefile b/module/tranche/makefile index 18f8fc7..24e7cfa 100644 --- a/module/tranche/makefile +++ b/module/tranche/makefile @@ -6,16 +6,24 @@ MAKE=/usr/bin/make --no-print-directory -f $(PROJECT_SUBU)/tool/lib/makefile-cc -include makefile-flags -.PHONY: all version deps lib exec -all: version deps lib exec +.PHONY: all +all: version +.PHONY: dep +dep: + if [ -e $(DEPFILE) ]; then rm $(DEPFILE); fi + $(MAKE) $@ + +.PHONY: lib lib: $(MAKE) $@ cp src/tranche.lib.h include/tranche.h +.PHONY: exec exec: $(MAKE) $@ +.PHONY: share share: if [ -d $(EXECDIR) ]; then if [ ! -z "$(wildcard $(EXECDIR)/*)" ]; then cp $(EXECDIR)/* $(PROJECT_SUBU)/tool/bin; fi; fi diff --git a/module/tranche/src/tranche.cli.c b/module/tranche/src/tranche.cli.c index 597a191..447a78b 100644 --- a/module/tranche/src/tranche.cli.c +++ b/module/tranche/src/tranche.cli.c @@ -85,7 +85,6 @@ int main(int argc, char **argv, char **envp){ da_alloc(target_arrp, sizeof(int)); int fd = STDOUT_FILENO; da_push(target_arrp, &fd); - if(tdir)chdir(tdir); Da src_arr; Da *src_arrp = &src_arr; @@ -96,7 +95,7 @@ int main(int argc, char **argv, char **envp){ char *src_file_path; FILE *src_file; if(da_emptyq(src_arrp)) - tranche_send(stdin, target_arrp); + tranche_send(stdin, target_arrp, tdir); else{ char *pt = src_arrp->base; while( pt < src_arrp->end ){ @@ -106,7 +105,7 @@ int main(int argc, char **argv, char **envp){ fprintf(stderr,"Could not open source file %s.\n", src_file_path); err |= TRANCHE_ERR_SRC_OPEN; }else{ - tranche_send(src_file, target_arrp); + tranche_send(src_file, target_arrp, tdir); if( fclose(src_file) == -1 ){perror(NULL); err |= TRANCHE_ERR_FCLOSE;} } pt += src_arrp->element_size; diff --git a/module/tranche/src/tranche.lib.c b/module/tranche/src/tranche.lib.c index a039723..787ff4f 100644 --- a/module/tranche/src/tranche.lib.c +++ b/module/tranche/src/tranche.lib.c @@ -100,7 +100,7 @@ static void tranche_puts_all(Da *fdap, char *string){ //-------------------------------------------------------------------------------- // does the work of tranching a source file -int tranche_send(FILE *src, Da *arg_fdap){ +int tranche_send(FILE *src, Da *arg_fdap, char *tdir){ char *pt; Da line; // buffer holding the characters from a line Da file_name_arr; // an array of file name parameters parsed from a #tranche line @@ -114,10 +114,10 @@ int tranche_send(FILE *src, Da *arg_fdap){ if( is_tranche_end(line.base) ) break; pt = is_tranche_begin(line.base); if(pt){ // then this line is the start of a nested tranche block - parse_file_list(&file_name_arr, pt, NULL); + parse_file_list(&file_name_arr, pt, tdir); tranche_open_fds(&file_name_arr, &fda); da_free_elements(&file_name_arr); - tranche_send(src, &fda); + tranche_send(src, &fda, tdir); tranche_close_fds(&fda); }else{ da_pop(&line, NULL); // pop the terminating zero diff --git a/module/tranche/src/tranche.lib.h b/module/tranche/src/tranche.lib.h index 7ec3720..575c97f 100644 --- a/module/tranche/src/tranche.lib.h +++ b/module/tranche/src/tranche.lib.h @@ -9,7 +9,7 @@ #define TRANCHE_ERR_SNAME 32 void path_trim_slashes(char *path); -int tranche_send(FILE *src, Da *arg_fds); +int tranche_send(FILE *src, Da *arg_fds, char *tdir); int tranche_target(FILE *src, Da *targets, char *tdir); void tranche_make(FILE *src_file, char *src_name, int mfile_fd, char *tdir); diff --git a/tool/bin/tranche b/tool/bin/tranche index ad95624..79da91b 100755 Binary files a/tool/bin/tranche and b/tool/bin/tranche differ diff --git a/tool/bin/tranche-make b/tool/bin/tranche-make index 79dd3aa..655e088 100755 Binary files a/tool/bin/tranche-make and b/tool/bin/tranche-make differ diff --git a/tool/bin/tranche-target b/tool/bin/tranche-target index a79e844..29765df 100755 Binary files a/tool/bin/tranche-target and b/tool/bin/tranche-target differ diff --git a/tool/lib/makefile-cc b/tool/lib/makefile-cc index 581b444..de023af 100755 --- a/tool/lib/makefile-cc +++ b/tool/lib/makefile-cc @@ -30,7 +30,6 @@ OBJECT_CLI= $(patsubst %, $(TMPDIR)/%.cli.o, $(C_BASE_CLI) $(CC_BASE_CLI)) EXEC= $(patsubst %, $(EXECDIR)/%, $(C_BASE_CLI) $(CC_BASE_CLI)) # default directory seteup -# For TRC projects define TRDIR (even if it is just '.'), and typically set SRCDIR to tmp # DEPRDIR=deprecated @@ -43,7 +42,6 @@ SRCDIR=src TESTDIR=test TMPDIR=tmp TOOLDIR=$(realpath $(PROJECT_SUBU)/tool) -TRCDIR= TRYDIR=try @@ -66,17 +64,6 @@ DEPFILE=$(TMPDIR)/makefile-cc.deps LIBFILE=$(LIBDIR)/lib$(MODULE).a INCFILE=$(INCDIR)/$(MODULE).h -#-------------------------------------------------------------------------------- -# when local customizations set a TRCDIR, then these are the actual sources - -ifneq ($TRCDIR,) - TRCSOURCES=$(wildcard $(TRCDIR)/*.trc.c)$(wildcard $(TRCDIR)/*.trc.cc) - TRCTARGETS= -else - TRCSOURCES= - TRCTARGETS= -endif - #-------------------------------------------------------------------------------- # targets @@ -86,7 +73,7 @@ all: version .PHONY: version version: - @echo makefile version 5.0 + @echo makefile version 6.0 @echo "PWD: " $(PWD) @echo "MAKEFILE_LIST: " $(MAKEFILE_LIST) @echo "C: " $(C) @@ -105,12 +92,10 @@ info: @echo "TESTDIR: " $(TESTDIR) @echo "TMPDIR: " $(TMPDIR) @echo "TOOLDIR: " $(TOOLDIR) - @echo "TRCDIR: " $(TRCDIR) @echo "TRYDIR: " $(TRYDIR) @echo "DEPFILE: " $(DEPFILE) @echo "LIBFILE: " $(LIBFILE) @echo "INCFILE: " $(INCFILE) - @echo "TRCSOURCES: " $(TRCSOURCES) @echo "C_SOURCE_LIB: " $(C_SOURCE_LIB) @echo "C_SOURCE_LIB: " $(C_SOURCE_LIB) @echo "C_SOURCE_CLI: " $(C_SOURCE_CLI) @@ -136,37 +121,10 @@ setup: [ ! -e $(SRCDIR) ] && mkdir $(SRCDIR) || true [ ! -e $(TESTDIR) ] && mkdir $(TESTDIR) || true [ ! -e $(TMPDIR) ] && mkdir $(TMPDIR) || true - [ ! -e $(TRCDIR) ] && mkdir $(TRCDIR) || true [ ! -e $(TRYDIR) ] && mkdir $(TRYDIR) || true -# gee this script could be better, particlarly in gathering the targets -# it would be simplified if the tranche commands took multiple source arguments -# if [ -e $(DEPFILE) ]; then rm $(DEPFILE); fi -# if [ ! -z "$(TRCSOURCES)" ]; then\ -# targets="";\ -# for i in $(TRCSOURCES); do\ -# tranche-make $$i -tdir $(SRCDIR) -mfile $(DEPFILE);\ -# targets+=$$(tranche-target $$i);\ -# targets+=" ";\ -# done;\ -# echo $$targets;\ -# fi - - .PHONY: dep dep: - if [ -e $(DEPFILE) ]; then rm $(DEPFILE); fi -ifneq ($(TRCDIR),) - $(ECHO) TRC deps - @trcsources=$(wildcard $(TRCDIR)/*.trc.c)$(wildcard $(TRCDIR)/*.trc.cc);\ - $(ECHO) $$trcsources;\ - if [ ! -z "$$trcsources" ]; then\ - trctargets=$$(tranche-target $$trcsources -sep " ");\ - echo $$trctargets;\ - tranche-make $$trcsources -tdir $(SRCDIR) -mfile $(DEPFILE);\ - $(MAKE) $$trctargets;\ - fi -endif @if [ -z "$(CC)" ]; then\ if [ -z "$C()" ]; then\ $(ECHO) "No compiler specified";\ @@ -226,9 +184,8 @@ dist-clean: clean rm $(INCFILE) || true rm $(LIBFILE) || true --include $(DEPFILE) - # recipes +-include $(DEPFILE) $(TMPDIR)/%.o : $(SRCDIR)/%.c $(C) $(CFLAGS) -o $@ -c $<