--- /dev/null
+1.
+
+For the following makefile, the .PHONEY 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
+be added that give an explicit exec target.
+
+
+.PHONY: all version deps lib exec
+all: version deps lib exec
+
+lib:
+ $(MAKE) $@
+ cp src/tranche.lib.h include/tranche.h
+
+#exec:
+# $(MAKE) $@
+
+%::
+ $(MAKE) $@
# da/makefile
+
SHELL=/bin/bash
-MAKE=
+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
#CFLAGS=-std=gnu11 -fPIC -I. -Werror
LINKFLAGS=-Llib -lda
-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
# da/test
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
-.PHONY: all
+.PHONY: all lib exec
all: version deps lib exec
-.PHONY: lib
lib:
$(MAKE) $@
-.PHONY: exec
exec:
$(MAKE) $@
#CFLAGS=-std=gnu11 -fPIC -I../include -Werror
LINKFLAGS= -Llib -L../lib -ltest -lda
-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 0_makefile_flags
SUID_TOOL=$(TOOLSDIR)/bin/setuid_root.sh
-MAKE=/usr/bin/make -f $(PROJECT_SUBU)/tools/lib/makefile_cc
+MAKE=/usr/bin/make -f $(PROJECT_SUBU)/tools/lib/makefile-cc
SOURCES=$(wildcard *.c)
HFILES=$(wildcard *.h)
-include 0_makefile_flags
SUID_TOOL=$(TOOLSDIR)/bin/setuid_root.sh
-MAKE=/usr/bin/make -f $(PROJECT_SUBU)/tools/lib/makefile_cc
+MAKE=/usr/bin/make -f $(PROJECT_SUBU)/tools/lib/makefile-cc
SOURCES=$(wildcard *.c)
HFILES=$(wildcard *.h)
-include 0_makefile_flags
-MAKE=/usr/bin/make -f $(PROJECT_SUBU)/tools/lib/makefile_cc
+MAKE=/usr/bin/make -f $(PROJECT_SUBU)/tools/lib/makefile-cc
SOURCES=$(wildcard *.c)
HFILES=$(wildcard *.h)
--- /dev/null
+sed -i -e 's/makefile_cc/makefile-cc/g' ./db/0_makefile
+sed -i -e 's/makefile_cc/makefile-cc/g' ./subu-0/1_tests/0_makefile
+sed -i -e 's/makefile_cc/makefile-cc/g' ./subu-0/0_makefile
+sed -i -e 's/makefile_cc/makefile-cc/g' ./tranche/deprecated/0_makefile
+sed -i -e 's/makefile_cc/makefile-cc/g' ./tranche/makefile-flags
+sed -i -e 's/makefile_cc/makefile-cc/g' ./tranche/makefile-flags
+sed -i -e 's/makefile_cc/makefile-cc/g' ./da/test/makefile-flags
+sed -i -e 's/makefile_cc/makefile-cc/g' ./da/test/makefile-flags
+sed -i -e 's/makefile_cc/makefile-cc/g' ./da/makefile-flags
+sed -i -e 's/makefile_cc/makefile-cc/g' ./da/makefile-flags
-include 0_makefile_flags
SUID_TOOL=$(TOOLSDIR)/bin/setuid_root.sh
-MAKE=/usr/bin/make -f $(PROJECT_SUBU)/tools/lib/makefile_cc
+MAKE=/usr/bin/make -f $(PROJECT_SUBU)/tools/lib/makefile-cc
SOURCES=$(wildcard *.c)
HFILES=$(wildcard *.h)
# tranche/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
exec:
$(MAKE) $@
+share:
+ if [ ! -z "$(wildcard $(EXECDIR)/*)" ]; then cp $(EXECDIR)/* $(PROJECT_SUBU)/tool/bin; fi
+
%::
$(MAKE) $@
# directories used by this makefile, these could all be set to dot for
# the simplest source directory structure
-#LIDBIR, EXECDIR, INCDIR hold the make results that might later be shared
-#$(PWD) is the directory that make was called from, this is already build in
-#set to dot to use the same directory as the source code
-#leave blank to ommit
-DEPRDIR=deprecated
-DOCDIR=doc
-EXECDIR=exec
-INCDIR=include
-LIBDIR=lib
-SRCDIR=src
-TESTDIR=test
-TMPDIR=tmp
-TOOLDIR=$(realpath $(PROJECT_SUBU)/tool)
-TRYDIR=try
-
C=gcc
CFLAGS=-std=gnu11 -fPIC -I. -I../share/include -ggdb -Werror -DDEBUG -DDEBUGDB
#CFLAGS=-std=gnu11 -fPIC -I. -Werror
LINKFLAGS=-Llib -L../share/lib/ -lda -ltranche
-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
/*
-.. don't think I need sdir, just pass src_file_path through as the source,
-need to add -tdir option to the tranche call, an mod tranche to take it.
-sname then becomes also becomes a path to src.
-
usage:
- argv[0] [<src_file_path>] [-sname <sname>] [-sdir <dir>] [-tdir <dir>] [-mfile <mfile_path>]
+ argv[0] [<src_file_path>] [-sname <sname>] [-tdir <tdir>] [-mfile <mfile_path>]
gets the names of all the targets from the source file, then appends
to the mfile a couple of lines of the form:
options
<src_file_path> the trc file to be read
--sdir <sdir> prepend <sdir> to <src> in the makefile deps line that is printed
--tdir <tdir> prepend <tdir> to each <target> "
+-tdir <tdir> prepend <tdir>/ to each <target> "
-mfile <mfile_path> where to send the output, defaults to stdout
-sname <sname> replaces sourcename as the name to write as the source - useful for pipes
user does not want this behavior, give a value of "." for -sdir.
.. should modify this to allow multiple source files on the command line ..
-
+.. should check that tdir is an existing directory
*/
#include <sys/types.h>
char *src_file_path = 0;
char *sname = 0;
- char *sdir = 0;
char *tdir = 0;
char *mfile_path = 0;
mfile_path = value;
goto endif;
}
- if( !strcmp(option, "sdir") ){
- sdir = value;
- goto endif;
- }
if( !strcmp(option, "tdir") ){
tdir = value;
goto endif;
if(args_cnt > 1) src_file_path = *(char **)da_index(argsp, 1);
// arg contracts
- if(da_length(argsp) > 2){
+ if(args_cnt > 2){
fprintf(stderr, "too many args\n");
err_cnt++;
}
if(!src_file_path && !sname){
- fprintf(stderr, "must specify at least one eof a src_file_path or an sname\n");
+ fprintf(stderr, "must specify at least one of a src_file_path or an sname\n");
err_cnt++;
}
if(err_cnt > 0){
- fprintf(stderr, "usage: %s [<src_file_path>] [-sname <sname>] [-sdir <dir>] [-tdir <dir>] [-mfile <mfile_path>]\n", argv[0]);
+ fprintf(stderr, "usage: %s [<src_file_path>] [-sname <sname>] [-tdir <dir>] [-mfile <mfile_path>]\n", argv[0]);
return TRANCHE_ERR_ARG_PARSE;
}
da_free(argsp); // this only frees the array itself, not the things it points to
if(err) return err;
}
- char *file_name_part;
- if(src_file_path){
- // we are guaranteed a filename part, otherwise the fopen above would have failed
- file_name_part = path_chop(src_file_path);
- if(!sname) sname = file_name_part;
- if(!sdir && file_name_part != src_file_path) sdir = src_file_path; // note the file name has been chopped from src_file_path
- }
- tranche_make(src_file, sname, mfile_fd, sdir, tdir);
+ if(sname)src_file_path = sname;
+ path_trim_slashes(tdir);
+ tranche_make(src_file, src_file_path, mfile_fd, tdir);
{ // deallocate resources instead of just existing, so as to catch any errors
int err_cnt = 0;
.. currently tranche_send will probably mess up if the user nests a tranche to
the same file as one already open in the containing tranche ..
+
+.. should allow multiple source file args
*/
#include <stdio.h>
#include <unistd.h>
+#include <string.h>
#include <da.h>
#include "tranche.lib.h"
int main(int argc, char **argv, char **envp){
- if(argc != 2){
- fprintf(stderr, "usage: %s <source-file>\n",argv[0]);
- return TRANCHE_ERR_ARG_PARSE;
- }
- FILE *file = fopen(argv[1], "r");
- if(!file){
- fprintf(stderr,"could not open file %s\n", argv[1]);
- return TRANCHE_ERR_SRC_OPEN;
+ char *src_file_path = 0;
+ char *tdir = 0;
+
+ { // argument parse
+ Da args; // we will queue the non option args here
+ Da *argsp = &args;
+ da_alloc(argsp, sizeof(char *));
+
+ int err_cnt = 0;
+ char **pt = argv;
+ char *option;
+ char *value; // currently all our tranche options have exactly one value
+ while(*pt){
+ if( **pt == '-' ){
+ option = *pt + 1;
+ if(!*option){
+ fprintf(stderr, "Currently there is no lone '-' option.\n");
+ err_cnt++;
+ goto endif;
+ }
+ pt++; if(!*pt || **pt == '-'){
+ fprintf(stderr, "Missing value for option %s.\n", option);
+ err_cnt++;
+ if(!*pt) break; // then nothing more to parse
+ goto endif;
+ }
+ value = *pt;
+ if( !strcmp(option, "tdir") ){
+ tdir = value;
+ goto endif;
+ }
+ fprintf(stderr, "Unrecognized option %s.", option);
+ err_cnt++;
+ goto endif;
+ }
+ // else clause
+ da_push(argsp, pt);
+ endif:
+ pt++;
+ }
+ int args_cnt = da_length(argsp);
+ if(args_cnt > 1) src_file_path = *(char **)da_index(argsp, 1);
+
+ // arg contracts
+ if(args_cnt > 2){
+ fprintf(stderr, "too many arguments\n");
+ err_cnt++;
+ }
+ if(err_cnt > 0){
+ fprintf(stderr, "usage: %s [<src_file_path>] [-tdir <dir>]\n", argv[0]);
+ return TRANCHE_ERR_ARG_PARSE;
+ }
+ da_free(argsp); // this only frees the array itself, not the things it points to
+
+ }// end of argument parse
+
+ FILE *src_file;
+ { //source and mfile open
+ if(!src_file_path)
+ src_file = stdin;
+ else
+ src_file = fopen(src_file_path, "r");
+
+ int err = 0;
+ if(!src_file){
+ fprintf(stderr,"could not open tranche source file %s\n", src_file_path);
+ err+= TRANCHE_ERR_SRC_OPEN;
+ }
+ if(err) return err;
}
+
Da targets;
da_alloc(&targets, sizeof(int));
int fd = STDOUT_FILENO;
da_push(&targets, &fd);
- tranche_send(file, &targets);
+ if(tdir)chdir(tdir);
+
+ tranche_send(src_file, &targets);
+
da_free(&targets);
- fclose(file);
+ fclose(src_file);
return 0;
}
return 0;
}
-// Inserts a zero to chop off the filename similar to the old basename.
-// Returns a pointer to the first character after the inserted zero, i.e. to the filename.
-char *path_chop(char *path){
- char *file = path + strlen(path);
- if(file == path) return file;
- file--;
- if(file == path){
- if(*file == '.') file++; // lone '.' case
- return file;
- }
- file--;
- if(file == path){
- if(*file == '.' && *(file+1)=='.') file+=2; // lone '..' case
- return file;
- }
- do{
- file--;
- }while(file != path && *file != '/');
- if( *file == '/' ){
- *file = 0;
- file++;
+// replaces trailing slashes with zeros
+void path_trim_slashes(char *path){
+ if(!path || !*path) return;
+ char *pt = path + strlen(path) - 1;
+ loop:
+ if(*pt == '/'){
+ *pt = 0;
+ if(pt != path){
+ pt--;
+ goto loop;
+ }
}
- return file;
+ return;
}
// write a make file rule for making the tranche targets
-void tranche_make(FILE *src_file, char *src_name, int mfile_fd, char *sdir, char *tdir){
+void tranche_make(FILE *src_file, char *src_name, int mfile_fd, char *tdir){
// target list
Da ta;
char tab = '\t';
char terminator = 0;
- // output the dependency line ----------------------------------------
+ // construct then output the dependency line ----------------------------------------
Da dla;
Da *dlap=&dla; // dependency line array pointer
da_alloc(dlap, sizeof(char));
}
da_push(dlap, &colon);
da_push(dlap, &sp);
- if(sdir){
- da_push_string(dlap, sdir);
- da_push(dlap, &slash);
- }
da_push_string(dlap, src_name);
da_push(dlap, &newline);
write(mfile_fd, dlap->base, dlap->end - dlap->base);
da_rewind(dlap); // reuse the line buffer
da_push(dlap, &tab);
da_push_string(dlap, "tranche $<");
+ if(tdir){
+ da_push_string(dlap, " -tdir ");
+ da_push_string(dlap, tdir);
+ }
da_push(dlap, &newline);
da_push(dlap, &newline);
write(mfile_fd, dlap->base, dlap->end - dlap->base);
#define TRANCHE_ERR_DST_OPEN 4
#define TRANCHE_ERR_FCLOSE 8
-char *path_chop(char *path);
+void path_trim_slashes(char *path);
int tranche_send(FILE *src, Da *arg_fds);
int tranche_target(FILE *src, Da *targets);
-void tranche_make(FILE *src_file, char *src_file_name, int mfile_fd, char *sdir, char *tdir);
+void tranche_make(FILE *src_file, char *src_name, int mfile_fd, char *tdir);
#endif
#!/bin/bash -x
./tranche test1.dat >test1stdout.dat
-diff test11.dat test11.dat.expected
-diff test12.dat test12.dat.expected
-diff test13.dat test13.dat.expected
-diff test14.dat test14.dat.expected
-diff test15.dat test15.dat.expected
-diff test1stdout.dat test1stdout.dat.expected
+diff -q test11.dat test11.dat.expected
+diff -q test12.dat test12.dat.expected
+diff -q test13.dat test13.dat.expected
+diff -q test14.dat test14.dat.expected
+diff -q test15.dat test15.dat.expected
+diff -q test1stdout.dat test1stdout.dat.expected
rm test11.dat test12.dat test13.dat test14.dat test15.dat test1stdout.dat
#!/bin/bash -x
./tranche test2.trc.c >test2stdout.dat
-diff test2.c test2.c.expected
-diff test2.h test2.h.expected
-diff test2stdout.dat test2stdout.dat.expected
+diff -q test2.c test2.c.expected
+diff -q test2.h test2.h.expected
+diff -q test2stdout.dat test2stdout.dat.expected
rm test2.c test2.h
#!/bin/bash -x
./tranche-target test1.dat > test3.out
-diff test3.out test3.out.expected
+diff -q test3.out test3.out.expected
rm test3.out
#!/bin/bash -x
./tranche-target test2.trc.c > test4.out
-diff test4.out test4.out.expected
+diff -q test4.out test4.out.expected
rm test4.out
--- /dev/null
+
+# This makefile is usually called through a local makefile rather than directly.
+
+# should add test that incdir is not pwd before deleting the include
+# file. Currently it is working for us despite this problem because dist-clean is
+# looking for $(module).h while the include file is always $(module).lib.h.
+
+SHELL=/bin/bash
+
+#--------------------------------------------------------------------------------
+# defaults
+
+# these are the sources edited by the programmer
+C_SOURCE_LIB= $(wildcard $(SRCDIR)/*.lib.c)
+C_SOURCE_CLI= $(wildcard $(SRCDIR)/*.cli.c)
+CC_SOURCE_LIB= $(wildcard $(SRCDIR)/*.lib.cc)
+CC_SOURCE_CLI= $(wildcard $(SRCDIR)/*.cli.cc)
+
+#remove the suffix to get base name
+C_BASE_LIB= $(sort $(patsubst %.lib.c, %, $(notdir $(C_SOURCE_LIB))))
+C_BASE_CLI= $(sort $(patsubst %.cli.c, %, $(notdir $(C_SOURCE_CLI))))
+CC_BASE_LIB= $(sort $(patsubst %.lib.cc, %, $(notdir $(CC_SOURCE_LIB))))
+CC_BASE_CLI= $(sort $(patsubst %.cli.cc, %, $(notdir $(CC_SOURCE_CLI))))
+
+# two sets of object files, one for the lib, and one for the command line interface progs
+OBJECT_LIB= $(patsubst %, $(TMPDIR)/%.lib.o, $(C_BASE_LIB) $(CC_BASE_LIB))
+OBJECT_CLI= $(patsubst %, $(TMPDIR)/%.cli.o, $(C_BASE_CLI) $(CC_BASE_CLI))
+
+# executables are made from CLI sources
+EXEC= $(patsubst %, $(EXECDIR)/%, $(C_BASE_CLI) $(CC_BASE_CLI))
+
+DEPRDIR=deprecated
+DOCDIR=doc
+EXECDIR=exec
+INCDIR=include
+LIBDIR=lib
+SHAREDIR=../share
+SRCDIR=src
+TESTDIR=test
+TMPDIR=tmp
+TOOLDIR=$(realpath $(PROJECT_SUBU)/tool)
+TRYDIR=try
+
+# a single space literal, for example if you wanted to subsitute commas to
+# spaces: $(subst $(space),;,$(string))
+blank :=
+space :=$(blank) $(blank)
+
+# prevent make from subsittuing its default for CC
+C=
+CC=
+
+#--------------------------------------------------------------------------------
+# local customization
+# user must define things needed by the local makefile, the compiler, and flags
+
+-include makefile-flags
+
+DEPFILE=$(TMPDIR)/makefile-cc.deps
+LIBFILE=$(LIBDIR)/lib$(MODULE).a
+INCFILE=$(INCDIR)/$(MODULE).h
+
+#--------------------------------------------------------------------------------
+# targets
+
+.PHONY: all
+all: version dep lib exec
+
+.PHONY: version
+version:
+ @echo makefile version 4.0
+ @echo "PWD: " $(PWD)
+ @echo "MAKEFILE_LIST: " $(MAKEFILE_LIST)
+ @echo "C: " $(C)
+ @echo "CFLAGS: " $(CFLAGS)
+ @echo "CC: " $(CC)
+ @echo "CCFLAGS: " $(CCFLAGS)
+ @echo "LINKFLAGS: " $(LINKFLAGS)
+
+.PHONY: info
+info:
+ @echo "DEPRDIR: " $(DEPRDIR)
+ @echo "DOCDIR: " $(DOCDIR)
+ @echo "EXECDIR: " $(EXECDIR)
+ @echo "INCDIR: " $(INCDIR)
+ @echo "LIBDIR: " $(LIBDIR)
+ @echo "TESTDIR: " $(TESTDIR)
+ @echo "TMPDIR: " $(TMPDIR)
+ @echo "TOOLDIR: " $(TOOLDIR)
+ @echo "TRYDIR: " $(TRYDIR)
+ @echo "DEPFILE: " $(DEPFILE)
+ @echo "LIBFILE: " $(LIBFILE)
+ @echo "INCFILE: " $(INCFILE)
+ @echo "C_SOURCE_LIB: " $(C_SOURCE_LIB)
+ @echo "C_SOURCE_CLI: " $(C_SOURCE_CLI)
+ @echo "CC_SOURCE_LIB: " $(CC_SOURCE_LIB)
+ @echo "CC_SOURCE_CLI: " $(CC_SOURCE_CLI)
+ @echo "C_BASE_LIB: " $(C_BASE_LIB)
+ @echo "C_BASE_CLI: " $(C_BASE_CLI)
+ @echo "CC_BASE_LIB: " $(CC_BASE_LIB)
+ @echo "CC_BASE_CLI: " $(CC_BASE_CLI)
+ @echo "OBJECT_LIB: " $(OBJECT_LIB)
+ @echo "OBJECT_CLI: " $(OBJECT_CLI)
+ @echo "EXEC: " $(EXEC)
+
+# should be safe to run this in an already setup or partially setup directory
+.PHONY: setup
+setup:
+ [ ! -e $(DEPRDIR) ] && mkdir $(DEPRDIR) || true
+ [ ! -e $(DOCDIR) ] && mkdir $(DOCDIR) || true
+ [ ! -e $(EXECDIR) ] && mkdir $(EXECDIR) || true
+ [ ! -e $(INCDIR) ] && mkdir $(INCDIR) || true
+ [ ! -e $(LIBDIR) ] && mkdir $(LIBDIR) || true
+ [ ! -e $(SRCDIR) ] && mkdir $(SRCDIR) || true
+ [ ! -e $(TESTDIR) ] && mkdir $(TESTDIR) || true
+ [ ! -e $(TMPDIR) ] && mkdir $(TMPDIR) || true
+ [ ! -e $(TRYDIR) ] && mkdir $(TRYDIR) || true
+
+#better to put the dependency generation into a loop on the source file and specify -MT for the target
+#also should be redirecting only stdout so stderr messages will be displayed >>1 depfile
+.PHONY: dep
+dep:
+ @if [ -z "$(CC)" ]; then\
+ if [ -z "$C()" ]; then\
+ echo "No compiler specified";\
+ exit 1;\
+ else\
+ echo "C compiler only deps" ;\
+ $(C) $(CFLAGS) -MM $(C_SOURCE_LIB) $(C_SOURCE_CLI) | sed 's|^.*\.o|$(TMPDIR)/&|' > $(DEPFILE);\
+ echo "deps for C linking";\
+ for i in $(C_BASE_CLI) ; do\
+ $(ECHO) >> $(DEPFILE);\
+ $(ECHO) "$(EXECDIR)/$$i : $(TMPDIR)/$$i.cli.o $(LIBFILE)" >> $(DEPFILE);\
+ $(ECHO) " $(C) -o $(EXECDIR)/$$i $(TMPDIR)/$$i.cli.o $(LINKFLAGS)" >> $(DEPFILE);\
+ done;\
+ fi;\
+ else\
+ $(CC) $(CCFLAGS) -MM $(CC_SOURCE_LIB) $(CC_SOURCE_CLI) | sed 's|^.*\.o|$(TMPDIR)/&|' > $(DEPFILE);\
+ if [ -z "$C()" ]; then\
+ echo "CC compiler only deps" ;\
+ else\
+ echo "CC and C mixed compile deps" ;\
+ $(C) $(CFLAGS) -MM $(C_SOURCE_LIB) $(C_SOURCE_CLI) | sed 's|^.*\.o|$(TMPDIR)/&|' > $(DEPFILE);\
+ fi;\
+ echo "deps for CC linking";\
+ for i in $(CC_BASE_CLI) $(C_BASE_CLI) ; do\
+ $(ECHO) >> $(DEPFILE);\
+ $(ECHO) "$(EXECDIR)/$$i : $(TMPDIR)/$$i.cli.o $(LIBFILE)" >> $(DEPFILE);\
+ $(ECHO) " $(CC) -o $(EXECDIR)/$$i $(TMPDIR)/$$i.cli.o $(LINKFLAGS)" >> $(DEPFILE);\
+ done;\
+ fi
+
+.PHONY: lib
+lib: $(LIBFILE)
+
+$(LIBFILE): $(OBJECT_LIB)
+ ar rcs $(LIBFILE) $(OBJECT_LIB)
+
+.PHONY: exec
+exec: $(LIBFILE)
+ make sub_exec
+
+.PHONY: sub_exec
+sub_exec: $(EXEC)
+
+.PHONY: share
+share:
+ if [ ! -z "$(wildcard $(LIBDIR)/*)" ]; then cp $(LIBDIR)/* $(SHAREDIR)/lib; fi
+ if [ ! -z "$(wildcard $(INCDIR)/*)" ]; then cp $(INCDIR)/* $(SHAREDIR)/include; fi
+ if [ ! -z "$(wildcard $(EXECDIR)/*)" ]; then cp $(EXECDIR)/* $(SHAREDIR)/bin; fi
+
+.PHONY: clean
+clean:
+ for i in $(wildcard tmp/*); do rm $$i || true; done
+
+.PHONY: dist-clean
+dist-clean: clean
+ for i in $(EXEC); do [ -e $$i ] && rm $$i || true; done
+ rm $(INCFILE) || true
+ rm $(LIBFILE) || true
+
+-include $(DEPFILE)
+
+# recipes
+
+$(TMPDIR)/%.o : $(SRCDIR)/%.c
+ $(C) $(CFLAGS) -o $@ -c $<
+
+$(TMPDIR)/%.o : $(SRCDIR)/%.cc
+ $(CC) $(CCFLAGS) -o $@ -c $<
+
--- /dev/null
+
+# This makefile is usually called through a local makefile rather than directly.
+# The purpose of this makefile is to expand out the tranched C/CC sources, and
+# otherwise to fall through to makefile_cc.
+
+SHELL=/bin/bash
+
+TRCDIR=trc
+
+# these are the sources edited by the programmer
+TRC_FILE= $(wildcard $(TRCDIR)/*.trc.c) $(wildcard $(TRCDIR)/*.trc.cc)
+
+-include makefile-flags
+
+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
+
+DEPFILE=$(TMPDIR)/makefile-trc.deps
+
+all: version deps lib execs
+
+.PHONY: all version deps lib exec
+all: version deps lib exec
+
+lib:
+ $(MAKE) $@
+
+exec:
+ $(MAKE) $@
+
+share:
+ if [ ! -z "$(wildcard $(EXECDIR)/*)" ]; then cp $(EXECDIR)/* $(PROJECT_SUBU)/tool/bin; fi
+
+%::
+ $(MAKE) $@
+
+dep:
\ No newline at end of file
+++ /dev/null
-
-# this makefile is usually called from via make from a local makefile
-
-
-#should add test that incdir is not pwd before deleting the include file in
-#dist-clean currently make is looking for module.h while the include file is
-#always module.lib.h so the lib include is not getting clobbered
-
-SHELL=/bin/bash
-
-#--------------------------------------------------------------------------------
-# defaults
-
-# these are the sources edited by the programmer
-C_SOURCE_LIB= $(wildcard $(SRCDIR)/*.lib.c)
-C_SOURCE_CLI= $(wildcard $(SRCDIR)/*.cli.c)
-CC_SOURCE_LIB= $(wildcard $(SRCDIR)/*.lib.cc)
-CC_SOURCE_CLI= $(wildcard $(SRCDIR)/*.cli.cc)
-
-#remove the suffix to get base name
-C_BASE_LIB= $(sort $(patsubst %.lib.c, %, $(notdir $(C_SOURCE_LIB))))
-C_BASE_CLI= $(sort $(patsubst %.cli.c, %, $(notdir $(C_SOURCE_CLI))))
-CC_BASE_LIB= $(sort $(patsubst %.lib.cc, %, $(notdir $(CC_SOURCE_LIB))))
-CC_BASE_CLI= $(sort $(patsubst %.cli.cc, %, $(notdir $(CC_SOURCE_CLI))))
-
-# two sets of object files, one for the lib, and one for the command line interface progs
-OBJECT_LIB= $(patsubst %, $(TMPDIR)/%.lib.o, $(C_BASE_LIB) $(CC_BASE_LIB))
-OBJECT_CLI= $(patsubst %, $(TMPDIR)/%.cli.o, $(C_BASE_CLI) $(CC_BASE_CLI))
-
-# executables are made from CLI sources
-EXEC= $(patsubst %, $(EXECDIR)/%, $(C_BASE_CLI) $(CC_BASE_CLI))
-
-DEPRDIR=deprecated
-DOCDIR=doc
-EXECDIR=exec
-INCDIR=include
-LIBDIR=lib
-SHAREDIR=../share
-SRCDIR=src
-TESTDIR=test
-TMPDIR=tmp
-TOOLDIR=$(realpath $(PROJECT_SUBU)/tool)
-TRYDIR=try
-
-# a single space literal, for example if you wanted to subsitute commas to
-# spaces: $(subst $(space),;,$(string))
-blank :=
-space :=$(blank) $(blank)
-
-# prevent make from subsittuing its default for CC
-C=
-CC=
-
-#--------------------------------------------------------------------------------
-# local customization
-# user must define things needed by the local makefile, the compiler, and flags
-
--include makefile-flags
-
-DEPFILE=$(TMPDIR)/makefile-dep
-LIBFILE=$(LIBDIR)/lib$(MODULE).a
-INCFILE=$(INCDIR)/$(MODULE).h
-
-#--------------------------------------------------------------------------------
-# targets
-
-.PHONY: all
-all: version dep lib exec
-
-.PHONY: version
-version:
- @echo makefile version 4.0
- @echo "PWD: " $(PWD)
- @echo "MAKEFILE_LIST: " $(MAKEFILE_LIST)
- @echo "C: " $(C)
- @echo "CFLAGS: " $(CFLAGS)
- @echo "CC: " $(CC)
- @echo "CCFLAGS: " $(CCFLAGS)
- @echo "LINKFLAGS: " $(LINKFLAGS)
-
-.PHONY: info
-info:
- @echo "DEPRDIR: " $(DEPRDIR)
- @echo "DOCDIR: " $(DOCDIR)
- @echo "EXECDIR: " $(EXECDIR)
- @echo "INCDIR: " $(INCDIR)
- @echo "LIBDIR: " $(LIBDIR)
- @echo "TESTDIR: " $(TESTDIR)
- @echo "TMPDIR: " $(TMPDIR)
- @echo "TOOLDIR: " $(TOOLDIR)
- @echo "TRYDIR: " $(TRYDIR)
- @echo "DEPFILE: " $(DEPFILE)
- @echo "LIBFILE: " $(LIBFILE)
- @echo "INCFILE: " $(INCFILE)
- @echo "C_SOURCE_LIB: " $(C_SOURCE_LIB)
- @echo "C_SOURCE_CLI: " $(C_SOURCE_CLI)
- @echo "CC_SOURCE_LIB: " $(CC_SOURCE_LIB)
- @echo "CC_SOURCE_CLI: " $(CC_SOURCE_CLI)
- @echo "C_BASE_LIB: " $(C_BASE_LIB)
- @echo "C_BASE_CLI: " $(C_BASE_CLI)
- @echo "CC_BASE_LIB: " $(CC_BASE_LIB)
- @echo "CC_BASE_CLI: " $(CC_BASE_CLI)
- @echo "OBJECT_LIB: " $(OBJECT_LIB)
- @echo "OBJECT_CLI: " $(OBJECT_CLI)
- @echo "EXEC: " $(EXEC)
-
-# should be safe to run this in an already setup or partially setup directory
-.PHONY: setup
-setup:
- [ ! -e $(DEPRDIR) ] && mkdir $(DEPRDIR) || true
- [ ! -e $(DOCDIR) ] && mkdir $(DOCDIR) || true
- [ ! -e $(EXECDIR) ] && mkdir $(EXECDIR) || true
- [ ! -e $(INCDIR) ] && mkdir $(INCDIR) || true
- [ ! -e $(LIBDIR) ] && mkdir $(LIBDIR) || true
- [ ! -e $(SRCDIR) ] && mkdir $(SRCDIR) || true
- [ ! -e $(TESTDIR) ] && mkdir $(TESTDIR) || true
- [ ! -e $(TMPDIR) ] && mkdir $(TMPDIR) || true
- [ ! -e $(TRYDIR) ] && mkdir $(TRYDIR) || true
-
-#better to put the dependency generation into a loop on the source file and specify -MT for the target
-#also should be redirecting only stdout so stderr messages will be displayed >>1 depfile
-.PHONY: dep
-dep:
- @if [ -z "$(CC)" ]; then\
- if [ -z "$C()" ]; then\
- echo "No compiler specified";\
- exit 1;\
- else\
- echo "C compiler only deps" ;\
- $(C) $(CFLAGS) -MM $(C_SOURCE_LIB) $(C_SOURCE_CLI) | sed 's|^.*\.o|$(TMPDIR)/&|' > $(DEPFILE);\
- echo "deps for C linking";\
- for i in $(C_BASE_CLI) ; do\
- $(ECHO) >> $(DEPFILE);\
- $(ECHO) "$(EXECDIR)/$$i : $(TMPDIR)/$$i.cli.o $(LIBFILE)" >> $(DEPFILE);\
- $(ECHO) " $(C) -o $(EXECDIR)/$$i $(TMPDIR)/$$i.cli.o $(LINKFLAGS)" >> $(DEPFILE);\
- done;\
- fi;\
- else\
- $(CC) $(CCFLAGS) -MM $(CC_SOURCE_LIB) $(CC_SOURCE_CLI) | sed 's|^.*\.o|$(TMPDIR)/&|' > $(DEPFILE);\
- if [ -z "$C()" ]; then\
- echo "CC compiler only deps" ;\
- else\
- echo "CC and C mixed compile deps" ;\
- $(C) $(CFLAGS) -MM $(C_SOURCE_LIB) $(C_SOURCE_CLI) | sed 's|^.*\.o|$(TMPDIR)/&|' > $(DEPFILE);\
- fi;\
- echo "deps for CC linking";\
- for i in $(CC_BASE_CLI) $(C_BASE_CLI) ; do\
- $(ECHO) >> $(DEPFILE);\
- $(ECHO) "$(EXECDIR)/$$i : $(TMPDIR)/$$i.cli.o $(LIBFILE)" >> $(DEPFILE);\
- $(ECHO) " $(CC) -o $(EXECDIR)/$$i $(TMPDIR)/$$i.cli.o $(LINKFLAGS)" >> $(DEPFILE);\
- done;\
- fi
-
-.PHONY: lib
-lib: $(LIBFILE)
-
-$(LIBFILE): $(OBJECT_LIB)
- ar rcs $(LIBFILE) $(OBJECT_LIB)
-
-.PHONY: exec
-exec: $(LIBFILE)
- make sub_exec
-
-.PHONY: sub_exec
-sub_exec: $(EXEC)
-
-.PHONY: share
-share:
- if [ ! -z "$(wildcard $(LIBDIR)/*)" ]; then cp $(LIBDIR)/* $(SHAREDIR)/lib; fi
- if [ ! -z "$(wildcard $(INCDIR)/*)" ]; then cp $(INCDIR)/* $(SHAREDIR)/include; fi
- if [ ! -z "$(wildcard $(EXECDIR)/*)" ]; then cp $(EXECDIR)/* $(SHAREDIR)/bin; fi
-
-.PHONY: clean
-clean:
- for i in $(wildcard tmp/*); do rm $$i || true; done
-
-.PHONY: dist-clean
-dist-clean: clean
- for i in $(EXEC); do [ -e $$i ] && rm $$i || true; done
- rm $(INCFILE) || true
- rm $(LIBFILE) || true
-
--include $(DEPFILE)
-
-# recipes
-
-$(TMPDIR)/%.o : $(SRCDIR)/%.c
- $(C) $(CFLAGS) -o $@ -c $<
-
-$(TMPDIR)/%.o : $(SRCDIR)/%.cc
- $(CC) $(CCFLAGS) -o $@ -c $<
-
+++ /dev/null
-
-# Ideally we would read the tranche sources and see what files they output, and then
-# build the deps accordingly, but this makefile is more primitive approach.
-# Here the programmer must have one output .c file or .cc file per input tranche
-# file and it must be name <base>.{lib,cli}.{c,cc} and the {.c,.cc} output
-# tranche must be named <base>.trc.{c,cc}
-
-# usually we have a bunch of source files and one target, here we have one source
-# file, the tranch file, and a bunch of targets.
-
-# will re-orgnaize the directory structure .. will name the src-da .. etc. to the
-# name of the module, then have a source dir inside that has only the stuff
-# programmer's edit, then get rid of the numbers
-
-SHELL=/bin/bash
-
-TRCDIR=trc
-
-# these are the sources edited by the programmer
-C_TRC_LIB= $(wildcard $(TRCDIR)/*.lib.c)
-C_TRC_CLI= $(wildcard $(TRCDIR)/*.cli.c)
-CC_TRC_LIB= $(wildcard $(TRCDIR)/*.lib.cc)
-CC_TRC_CLI= $(wildcard $(TRCDIR)/*.cli.cc)
-
-#remove the suffix to get base name
-C_BASE_LIB= $(sort $(patsubst %.lib.c, %, $(notdir $(C_SOURCE_LIB))))
-C_BASE_CLI= $(sort $(patsubst %.cli.c, %, $(notdir $(C_SOURCE_CLI))))
-CC_BASE_LIB= $(sort $(patsubst %.lib.cc, %, $(notdir $(CC_SOURCE_LIB))))
-CC_BASE_CLI= $(sort $(patsubst %.cli.cc, %, $(notdir $(CC_SOURCE_CLI))))
-
-# the progreammer must name the c and cc tranches accordingly:
-C_TRC_LIB= $(patasubst %, $(TMPDIR)/%.trc.c, C_BASE_LIB)
-C_TRC_CLI= $(patasubst %, $(TMPDIR)/%.trc.c, C_BASE_CLI)
-CC_TRC_LIB= $(patasubst %, $(TMPDIR)/%.trc.cc, CC_BASE_LIB)
-CC_TRC_CLI= $(patasubst %, $(TMPDIR)/%.trc.cc, CC_BASE_CLI)
-
-# two sets of object files, one for the lib, and one for the command line interface progs
-OBJECT_LIB= $(patsubst %, $(TMDIR)/%.o, $(C_BASE_LIB) $(CC_BASE_LIB))
-OBJECT_CLI= $(patsubst %, $(TMDIR)/%.o, $(C_BASE_CLI) $(CC_BASE_CLI))
-
-# executables are made from CLI sources
-EXEC= (patsubst %, $(EXECDIR)/%, $(C_BASE_CLI) $(CC_BASE_CLI))
-
-#otherwise make provides default values for these
-C=
-CC=
-
--include makefile-flags
-
-DEPFILE=$(TMPDIR)/makefile_dep
-
-# a single space literal, for example if you wanted to subsitute commas to
-# spaces: $(subst $(space),;,$(string)) we ran into this out of a need to send
-# multiple separate command arguments to a shell script from one variable value
-blank :=
-space :=$(blank) $(blank)
-
-all: version deps lib execs
-
-version:
- @echo makefile version 3.0
- @echo "PWD: " $(PWD)
- @echo "MAKEFILE_LIST: " $(MAKEFILE_LIST)
- @echo "C: " $(C)
- @echo "CFLAGS: " $(CFLAGS)
- @echo "CC: " $(CC)
- @echo "CCFLAGS: " $(CCFLAGS)
- @echo "LINKFLAGS: " $(LINKFLAGS)
-
-info:
- @echo "DEPDIR: " $(DEPDIR)
- @echo "DOCDIR: " $(DOCDIR)
- @echo "EXECSDIR: " $(EXECSDIR)
- @echo "INCDIR: " $(INCDIR)
- @echo "LIBDIR: " $(LIBDIR)
- @echo "TESTDIR: " $(TESTDIR)
- @echo "TMPDIR: " $(TMPDIR)
- @echo "TOOLSDIR: " $(TOOLSDIR)
- @echo "TRYDIR: " $(TRYDIR)
- @echo "DEPSFILE: " $(DEPSFILE)
- @echo "LIBFILE: " $(LIBFILE)
- @echo "TRC_TRC: " $(TRC_TRC)
- @echo "C_BASE_LIB: " $(C_BASE_LIB)
- @echo "C_BASE_CLI: " $(C_BASE_CLI)
- @echo "CC_BASE_LIB: " $(CC_BASE_LIB)
- @echo "CC_BASE_CLI: " $(CC_BASE_CLI)
-
-# should be safe to run this in an already setup or partially setup directory
-setup:
- if [ ! -e $(DEPRDIR) ]; then mkdir $(DEPRDIR); fi
- if [ ! -e $(DOCDIR) ]; then mkdir $(DOCDIR); fi
- if [ ! -e $(EXECSDIR) ]; then mkdir $(EXECSDIR); fi
- if [ ! -e $(INCDIR) ]; then mkdir $(INCDIR); fi
- if [ ! -e $(LIBDIR) ]; then mkdir $(LIBDIR); fi
- if [ ! -e $(SRCDIR) ]; then mkdir $(SRCDIR); fi
- if [ ! -e $(TESTDIR) ]; then mkdir $(TESTDIR); fi
- if [ ! -e $(TMPDIR) ]; then mkdir $(TMPDIR); fi
- if [ ! -e $(TRYDIR) ]; then mkdir $(TRYDIR); fi
-
-dep: $(C_TRC_LIB) $(C_TRC_CLI) $(CC_TRC_LIB) $(CC_TRC_CLI)
- if [ -z "$(CC)" ]; then\
- if [ -z "$C()" ]; then\
- echo "No compiler specified";\
- exit 1;\
- else\
- echo "C compiler only deps" ;\
- $(C) $(CFLAGS) -MM $(C_TRC_LIB) $(C_TRC_CLI) 1> $(DEPSFILE);\
- echo "deps for C linking";\
- for i in $(EXECS) ; do\
- $(ECHO) >> $(DEPSFILE);\
- $(ECHO) "$(EXECSDIR)/$$i : $$i.cli.o $(LIBDIR)/$(LIBFILE)" >> $(DEPSFILE);\
- $(ECHO) " $(C) -o $(EXECSDIR)/$$i $$i.cli.o $(LINKFLAGS)" >> $(DEPSFILE);\
- done;\
- fi;\
- else\
- $(CC) $(CCFLAGS) -MM $(CC_TRC_LIB) $(CC_TRC_CLI) 1> $(DEPSFILE);\
- if [ -z "$C()" ]; then\
- echo "CC compiler only deps" ;\
- else\
- echo "CC and C mixed compile deps" ;\
- $(C) $(CFLAGS) -MM $(C_TRC_LIB) $(C_TRC_CLI) 1>> $(DEPSFILE);\
- fi;\
- echo "deps for CC linking";\
- for i in $(EXECS) ; do\
- $(ECHO) >> $(DEPSFILE);\
- $(ECHO) "$(EXECSDIR)/$$i : $$i.cli.o $(LIBDIR)/$(LIBFILE)" >> $(DEPSFILE);\
- $(ECHO) " $(CC) -o $(EXECSDIR)/$$i $$i.cli.o $(LINKFLAGS)" >> $(DEPSFILE);\
- done;\
- fi
-
-lib:
- make $(LIBDIR)/$(LIBFILE)
-
-$(LIBDIR)/$(LIBFILE) : $(OBJECTS_LIB)
- ar rcs $(LIBDIR)/$(LIBFILE) $(OBJECTS_LIB)
-
-exec: $(LIBDIR)/$(LIBFILE)
- make sub_exec
-
-sub_exec: $(patsubst %, $(EXECSDIR)/%, $(EXECS))
-
-stage:
- if [ -f $(LIBDIR)/$(LIBFILE) ]; then cp $(LIBDIR)/$(LIBFILE) $(PROJECT_SUBU)/stage/lib; fi
- if [ -f $(INCDIR)/$(INCFILE) ]; then cp $(INCDIR)/$(INCFILE) $(PROJECT_SUBU)/stage/include; fi
- -cp $(EXECSDIR)/* $(PROJECT_SUBU)/stage/bin
-
-clean:
- for i in $(wildcard *~); do mv $$i $(TMPDIR); done
- for i in $(wildcard *.lib.o) $(wildcard *.cli.o); do rm $$i; done
- for i in $(EXECS); do if [ -e $(EXECSDIR)/$$i ]; then rm $(EXECSDIR)/$$i; fi; done
- if [ -f $(LIBDIR)/$(LIBFILE) ]; then rm $(LIBDIR)/$(LIBFILE); fi
- if [ -f $(DEPSFILE) ]; then rm $(DEPSFILE); fi
-
--include $(DEPSFILE)
-
-# recipes
-#
-%.trc.c : %.lib.c
- $(TRANCHE) $<
-
-%.trc.c : %.cli.c
- $(TRANCHE) $<
-
-%.trc.cc : %.lib.cc
- $(TRANCHE) $<
-
-%.trc.cc : %.cli.cc
- $(TRANCHE) $<
-
-%.o : %.c
- $(C) $(CFLAGS) -c $<
-
-%.o : %.cc
- $(CC) $(CCFLAGS) -c $<
-