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
.PHONY: all
all: version
+.PHONY: dep
+dep:
+ if [ -e $(DEPFILE) ]; then rm $(DEPFILE); fi
+ $(MAKE) $@
+
.PHONY: lib
lib:
$(MAKE) $@
.PHONY: all lib exec
all: version deps lib exec
+.PHONY: dep
+dep:
+ if [ -e $(DEPFILE) ]; then rm $(DEPFILE); fi
+ $(MAKE) $@
+
lib:
$(MAKE) $@
# 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) $@
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
};
#tranche-end
-#include "dispatch.h"
+#include "dispatch.lib.h"
// we need the declaration for uid_t etc.
// without this #define execvpe is undefined
}
}
+#tranche dispatch.lib.h
+#endif
+#tranche-end
+
#tranche-end
-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
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;
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 ){
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;
//--------------------------------------------------------------------------------
// 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
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
#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);
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
TESTDIR=test
TMPDIR=tmp
TOOLDIR=$(realpath $(PROJECT_SUBU)/tool)
-TRCDIR=
TRYDIR=try
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
.PHONY: version
version:
- @echo makefile version 5.0
+ @echo makefile version 6.0
@echo "PWD: " $(PWD)
@echo "MAKEFILE_LIST: " $(MAKEFILE_LIST)
@echo "C: " $(C)
@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)
[ ! -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";\
rm $(INCFILE) || true
rm $(LIBFILE) || true
--include $(DEPFILE)
-
# recipes
+-include $(DEPFILE)
$(TMPDIR)/%.o : $(SRCDIR)/%.c
$(C) $(CFLAGS) -o $@ -c $<