#subdirectories=$(shell /usr/bin/find . -maxdepth 1 -printf "%f " | sed y/\./\ /)
-#subdirectories=src src/1_tests src/1_try
subdirectories=src
all :
- $(foreach dir, $(subdirectories), \
- if [ -f $(dir)/7_makefile ]; then \
- make -C $(dir) all && make -C $(dir) install; \
- fi;\
- )
-
-clean :
- $(foreach dir, $(subdirectories), \
- cd $(dir);\
- make clean;\
- )
+# $(foreach dir, $(subdirectories), \
+# if [ -f $(dir)/0_makefile ]; then \
+# make -C $(dir) all && make -C $(dir) install; \
+# fi;\
+# )
dist-clean :
$(foreach dir, $(subdirectories), \
+# src/0_makefile
SHELL=/bin/bash
-include 0_makefile_flags
-DEPS_FILE=$(TMPDIR)/makefile_deps
+SUID_TOOL=$(TOOLSDIR)/bin/setuid_root.sh
+MAKE=/usr/bin/make -f $(PROJECT_SUBU)/tools/lib/makefile_cc
-
-### end of user defined variables
-###--------------------------------------------------------------------------------
-
-# 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)
-
-# files used by the compiler
-SOURCES_LIB= $(wildcard *.lib.c)
-SOURCES_CLI= $(wildcard *.cli.c)
-SOURCES= $(SOURCES_LIB) $(SOURCES_CLI)
-
-HFILES = $(wildcard *.lib.h) $(wildcard *.cli.h)
-
-OBJECTS_LIB= $(patsubst %.c, %.o, $(SOURCES_LIB))
-OBJECTS_CLI= $(patsubst %.c, %.o, $(SOURCES_CLI))
-OBJECTS= $(OBJECTS_LIB) $(OBJECTS_CLI)
-
-EXECS= $(sort $(patsubst %.cli.c, %, $(wildcard *.cli.c)))
+SOURCES=$(wildcard *.c)
+HFILES=$(wildcard *.h)
all: version deps lib execs
version:
- @echo '---- make $@:------------------------------------------------------------'
- @echo makefile version 3.0
- @echo "PWD: " $(PWD)
- @echo "MAKEFILE_LIST: " $(MAKEFILE_LIST)
- @echo "TMPDIR: " $(TMPDIR)
- @echo "EXECSDIR: " $(EXECSDIR)
- @echo "HDIR: " $(HDIR)
- @echo "LIBDIR: " $(LIBDIR)
- @echo "DEPS_FILE: " $(DEPS_FILE)
- @echo "LIB_FILE: " $(LIB_FILE)
- @echo "CC: " $(CC)
- @echo "CFLAGS: " $(CFLAGS)
- @echo "LINKFLAGS: " $(LINKFLAGS)
+ $(MAKE) $@
@echo "SUID_TOOL: " $(SUID_TOOL)
- @echo '______end make $@_____'
-
-lists:
- @echo '---- make $@:------------------------------------------------------------'
- @echo "SOURCES_LIB: " $(SOURCES_LIB)
- @echo "SOURCES_CLI: " $(SOURCES_CLI)
- @echo "SOURCES: " $(SOURCES)
- @echo "HFILES: " $(HFILES)
- @echo "OBJECTS_LIB: " $(OBJECTS_LIB)
- @echo "OBJECTS_CLI: " $(OBJECTS_CLI)
- @echo "OBJECTS: " $(OBJECTS)
- @echo "EXECS: " $(EXECS)
- @echo '______end make $@_____'
-
-# should be safe to run this in an already setup or partially setup directory
-setup:
- @echo '---- make $@:------------------------------------------------------------'
- @echo `pwd`'>'
- if [ ! -e $(DEPRDIR) ]; then mkdir $(DEPRDIR); fi
- if [ ! -e $(DOCDIR) ]; then mkdir $(DOCDIR); fi
- if [ ! -e $(EXECSDIR) ]; then mkdir $(EXECSDIR); fi
- if [ ! -e $(HDIR) ]; then mkdir $(HDIR); fi
- if [ ! -e $(LIBDIR) ]; then mkdir $(LIBDIR); fi
- if [ ! -e $(TESTDIR) ]; then mkdir $(TESTDIR); fi
- if [ ! -e $(TMPDIR) ]; then mkdir $(TMPDIR); fi
- if [ ! -e $(TRYDIR) ]; then mkdir $(TRYDIR); fi
- @echo '______end make $@_____'
deps:
- @echo '---- make $@:------------------------------------------------------------'
- @echo `pwd`'>'
makeheaders $(SOURCES) $(HFILES)
sed -i '/^ *int *main *(.*)/d' *.h
- $(CC) $(CFLAGS) -MM $(SOURCES) 1> $(DEPS_FILE)
- for i in $(EXECS) ; do\
- $(ECHO) >> $(DEPS_FILE);\
- $(ECHO) "$(EXECSDIR)/$$i : $$i.cli.o $(LIB_FILE)" >> $(DEPS_FILE);\
- $(ECHO) " $(CC) -o $(EXECSDIR)/$$i $$i.cli.o $(LINKFLAGS)" >> $(DEPS_FILE);\
- done
- @echo '______end make $@_____'
+ $(MAKE) $@
-lib:
- @echo '---- make $@:------------------------------------------------------------'
- @echo `pwd`'>'
- if [ ! -e $(DEPS_FILE) ]; then make deps; fi
- make sub_lib
- @echo '______end make $@_____'
-
-sub_lib: $(LIB_FILE)
-
-
-execs: $(LIB_FILE)
- @echo '---- make $@:------------------------------------------------------------'
- @echo `pwd`'>'
- if [ ! -e $(DEPS_FILE) ]; then make deps; fi
- make sub_execs
+execs:
+ $(MAKE) $@
@echo "-> $(SUID_TOOL) $(EXECSDIR)/subu-mk-0 $(EXECSDIR)/subu-rm-0 $(EXECSDIR)/subu-bind-all"
cat $(SUID_TOOL)
@echo -n "Are you sure? [y/N] " && read ans && [ $${ans:-N} == y ]
sudo $(SUID_TOOL) $(EXECSDIR)/subu-mk-0 $(EXECSDIR)/subu-rm-0 $(EXECSDIR)/subu-bind-all
- @echo '______end make $@_____'
-
-sub_execs: $(patsubst %, $(EXECSDIR)/%, $(EXECS))
-
-#not ready yet
-install: all
- @echo '---- make $@:------------------------------------------------------------'
- @echo `pwd`'>'
- @if[ ! -e 1_tests_passed ]; then echo "can't install as tests have not passed"; fi
- @test -e test_passed
- for i in $(EXECSDIR); do cp $$i $(RT_BASE)/bin; done
- cp $(LIB_FILE) $(RT_BASE)/lib
- cp $(APPLICATION).h $(RT_BASE)/include
- if [ -d $(APPLICATION) ]; then cp $(APPLICATION)/*.h $(RT_BASE)/include/$(APPLICATION); fi
- @echo '______end make $@_____'
-
-# not written yet
-# copies stuff from the src dir to the stage dirs
-# stage:
clean:
- @echo '---- make $@:------------------------------------------------------------'
- @echo `pwd`'>'
- if [ -f subudb ]; then rm subudb; fi
- 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 $(HFILES); do mv $$i $(TMPDIR); done # just in case someone wrote a header file
- for i in $(EXECS); do if [ -e $(EXECSDIR)/$$i ]; then rm $(EXECSDIR)/$$i; fi; done
- if [ -f $(LIB_FILE) ]; then rm $(LIB_FILE); fi
- if [ -f $(DEPS_FILE) ]; then rm $(DEPS_FILE); fi
- @echo '______end make $@_____'
-
-
-# not ready ...
-# dist_clean is used to clean thing up before doing a checkin, hg add should be safe after a dist_clean
-# dist_clean will recurse into the include directory = $(APPLICATION), tests, and try if they are present
-#
-dist-clean:
- @echo '---- make $@:------------------------------------------------------------'
- @echo `pwd`'>'
- make clean
-# if [ -d $(APPLICATION) ]; then cd $(APPLICATION); make clean; fi
-# if [ -d 1_tests ]; then cd 1_tests; make dist_clean; fi
-# if [ -d 1_try ] ; then cd 1_try; make dist_clean; fi
- @echo '______end make $@_____'
+ $(MAKE) $@
+ for i in $(HFILES); do rm $$i; done
-#
-$(LIB_FILE) : $(OBJECTS_LIB)
- ar rcs $(LIB_FILE) $(OBJECTS_LIB)
+%::
+ $(MAKE) $@
--include $(DEPS_FILE)
-# recipe for making object files:
-#
-%.o : %.c
- $(CC) $(CFLAGS) -c $<
LIB_FILE=$(LIBDIR)/libsubu.a
-# external tools called out in this makefile
-SUID_TOOL=$(TOOLSDIR)/bin/setuid_root.sh
-
-
+# src/1_tests/0_makefile
SHELL=/bin/bash
-# some versions of Linux need a -e option others complain if there is a -e .. and it isn't the binary for echo ..
-ECHO= echo
-#ECHO= echo -e
-
-# directories used by this makefile, these could all be set to dot for
-# the simplest source directory structure
-
-#LIDBIR, EXECSDIR, HDIR hold the make results that might later be staged
-#$(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 or use dot to ommit
-DEPRDIR=.
-DOCDIR=.
-EXECSDIR=.
-HDIR=.
-LIBDIR=.
-TESTDIR=.
-TMPDIR=1_tmp
-TOOLSDIR=$(realpath $(PROJECT_SUBU)/tools)
-TRYDIR=
-
-# some important files
-DEPS_FILE=$(TMPDIR)/makefile_deps
-LIB_FILE=$(LIBDIR)/libsubu.a
-
-# compiler and flags
-CC=gcc
-CFLAGS=-std=gnu11 -fPIC -I. -ggdb -Werror -DDEBUG -DDEBUGDB
-#CFLAGS=-std=gnu11 -fPIC -I. -Werror
-LINKFLAGS=-L1_lib -lsubu -lsqlite3
+-include 0_makefile_flags
-# external tools called out in this makefile
-SUID_TOOL=$(TOOLSDIR)/bin/setuid_root.sh
+MAKE=/usr/bin/make -f $(PROJECT_SUBU)/tools/lib/makefile_cc
-### end of user defined variables
-###--------------------------------------------------------------------------------
-
-# 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)
-
-# files used by the compiler
-SOURCES_LIB= $(wildcard *.lib.c)
-SOURCES_CLI= $(wildcard *.cli.c)
-SOURCES= $(SOURCES_LIB) $(SOURCES_CLI)
-
-HFILES = $(wildcard *.lib.h) $(wildcard *.cli.h)
-
-OBJECTS_LIB= $(patsubst %.c, %.o, $(SOURCES_LIB))
-OBJECTS_CLI= $(patsubst %.c, %.o, $(SOURCES_CLI))
-OBJECTS= $(OBJECTS_LIB) $(OBJECTS_CLI)
-
-EXECS= $(sort $(patsubst %.cli.c, %, $(wildcard *.cli.c)))
+SOURCES=$(wildcard *.c)
+HFILES=$(wildcard *.h)
all: version deps lib execs
-version:
- @echo '---- make $@:------------------------------------------------------------'
- @echo makefile version 3.0
- @echo "PWD: " $(PWD)
- @echo "MAKEFILE_LIST: " $(MAKEFILE_LIST)
- @echo "TMPDIR: " $(TMPDIR)
- @echo "EXECSDIR: " $(EXECSDIR)
- @echo "HDIR: " $(HDIR)
- @echo "LIBDIR: " $(LIBDIR)
- @echo "DEPS_FILE: " $(DEPS_FILE)
- @echo "LIB_FILE: " $(LIB_FILE)
- @echo "CC: " $(CC)
- @echo "CFLAGS: " $(CFLAGS)
- @echo "LINKFLAGS: " $(LINKFLAGS)
- @echo "SUID_TOOL: " $(SUID_TOOL)
- @echo '______end make $@_____'
-
-lists:
- @echo '---- make $@:------------------------------------------------------------'
- @echo "SOURCES_LIB: " $(SOURCES_LIB)
- @echo "SOURCES_CLI: " $(SOURCES_CLI)
- @echo "SOURCES: " $(SOURCES)
- @echo "HFILES: " $(HFILES)
- @echo "OBJECTS_LIB: " $(OBJECTS_LIB)
- @echo "OBJECTS_CLI: " $(OBJECTS_CLI)
- @echo "OBJECTS: " $(OBJECTS)
- @echo "EXECS: " $(EXECS)
- @echo '______end make $@_____'
-
-# should be safe to run this in an already setup or partially setup directory
-setup:
- @echo '---- make $@:------------------------------------------------------------'
- @echo `pwd`'>'
- if [ ! -e $(DEPRDIR) ]; then mkdir $(DEPRDIR); fi
- if [ ! -e $(DOCDIR) ]; then mkdir $(DOCDIR); fi
- if [ ! -e $(EXECSDIR) ]; then mkdir $(EXECSDIR); fi
- if [ ! -e $(HDIR) ]; then mkdir $(HDIR); fi
- if [ ! -e $(LIBDIR) ]; then mkdir $(LIBDIR); fi
- if [ ! -e $(TESTDIR) ]; then mkdir $(TESTDIR); fi
- if [ ! -e $(TMPDIR) ]; then mkdir $(TMPDIR); fi
- if [ ! -e $(TRYDIR) ]; then mkdir $(TRYDIR); fi
- @echo '______end make $@_____'
-
deps:
- @echo '---- make $@:------------------------------------------------------------'
- @echo `pwd`'>'
makeheaders $(SOURCES) $(HFILES)
sed -i '/^ *int *main *(.*)/d' *.h
- $(CC) $(CFLAGS) -MM $(SOURCES) 1> $(DEPS_FILE)
- for i in $(EXECS) ; do\
- $(ECHO) >> $(DEPS_FILE);\
- $(ECHO) "$(EXECSDIR)/$$i : $$i.cli.o $(LIB_FILE)" >> $(DEPS_FILE);\
- $(ECHO) " $(CC) -o $(EXECSDIR)/$$i $$i.cli.o $(LINKFLAGS)" >> $(DEPS_FILE);\
- done
- @echo '______end make $@_____'
-
-lib:
- @echo '---- make $@:------------------------------------------------------------'
- @echo `pwd`'>'
- if [ ! -e $(DEPS_FILE) ]; then make deps; fi
- make sub_lib
- @echo '______end make $@_____'
-
-sub_lib: $(LIB_FILE)
-
-
-execs: $(LIB_FILE)
- @echo '---- make $@:------------------------------------------------------------'
- @echo `pwd`'>'
- if [ ! -e $(DEPS_FILE) ]; then make deps; fi
- make sub_execs
- @echo "-> $(SUID_TOOL) $(EXECSDIR)/subu-mk-0 $(EXECSDIR)/subu-rm-0 $(EXECSDIR)/subu-bind-all"
- cat $(SUID_TOOL)
- @echo -n "Are you sure? [y/N] " && read ans && [ $${ans:-N} == y ]
- sudo $(SUID_TOOL) $(EXECSDIR)/subu-mk-0 $(EXECSDIR)/subu-rm-0 $(EXECSDIR)/subu-bind-all
- @echo '______end make $@_____'
-
-sub_execs: $(patsubst %, $(EXECSDIR)/%, $(EXECS))
-
-#not ready yet
-install: all
- @echo '---- make $@:------------------------------------------------------------'
- @echo `pwd`'>'
- @if[ ! -e 1_tests_passed ]; then echo "can't install as tests have not passed"; fi
- @test -e test_passed
- for i in $(EXECSDIR); do cp $$i $(RT_BASE)/bin; done
- cp $(LIB_FILE) $(RT_BASE)/lib
- cp $(APPLICATION).h $(RT_BASE)/include
- if [ -d $(APPLICATION) ]; then cp $(APPLICATION)/*.h $(RT_BASE)/include/$(APPLICATION); fi
- @echo '______end make $@_____'
-
-# not written yet
-# copies stuff from the src dir to the stage dirs
-# stage:
+ $(MAKE) $@
clean:
- @echo '---- make $@:------------------------------------------------------------'
- @echo `pwd`'>'
- if [ -f subudb ]; then rm subudb; fi
- 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 $(HFILES); do mv $$i $(TMPDIR); done # just in case someone wrote a header file
- for i in $(EXECS); do if [ -e $(EXECSDIR)/$$i ]; then rm $(EXECSDIR)/$$i; fi; done
- if [ -f $(LIB_FILE) ]; then rm $(LIB_FILE); fi
- if [ -f $(DEPS_FILE) ]; then rm $(DEPS_FILE); fi
- @echo '______end make $@_____'
-
+ $(MAKE) $@
+ for i in $(HFILES); do rm $$i; done
-# not ready ...
-# dist_clean is used to clean thing up before doing a checkin, hg add should be safe after a dist_clean
-# dist_clean will recurse into the include directory = $(APPLICATION), tests, and try if they are present
-#
dist-clean:
- @echo '---- make $@:------------------------------------------------------------'
- @echo `pwd`'>'
- make clean
-# if [ -d $(APPLICATION) ]; then cd $(APPLICATION); make clean; fi
-# if [ -d 1_tests ]; then cd 1_tests; make dist_clean; fi
-# if [ -d 1_try ] ; then cd 1_try; make dist_clean; fi
- @echo '______end make $@_____'
+ $(MAKE) $@
+ if [ -f subudb ]; then rm subudb; fi
-#
-$(LIB_FILE) : $(OBJECTS_LIB)
- ar rcs $(LIB_FILE) $(OBJECTS_LIB)
+%::
+ $(MAKE) $@
--include $(DEPS_FILE)
-# recipe for making object files:
-#
-%.o : %.c
- $(CC) $(CFLAGS) -c $<
--- /dev/null
+
+# some versions of Linux need a -e option others complain if there is a -e .. and it isn't the binary for echo ..
+ECHO= echo
+#ECHO= echo -e
+
+# directories used by this makefile, these could all be set to dot for
+# the simplest source directory structure
+
+#LIDBIR, EXECSDIR, HDIR hold the make results that might later be staged
+#$(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=
+DOCDIR=
+EXECSDIR=.
+HDIR=.
+LIBDIR=.
+TESTDIR=.
+TMPDIR=1_tmp
+TOOLSDIR=$(realpath $(PROJECT_SUBU)/tools)
+TRYDIR=
+
+
+# compiler and flags
+CC=gcc
+CFLAGS=-std=gnu11 -fPIC -I. -ggdb -Werror -DDEBUG -DDEBUGDB
+#CFLAGS=-std=gnu11 -fPIC -I. -Werror
+LINKFLAGS=-L$(PROJECT_SUBU)/src/$(LIBDIR) -L. -lsubu -lsqlite3 -lsubutests
+
+LIB_FILE=$(LIBDIR)/libtests.a
+
+++ /dev/null
-/*
-Tests for da.
-
-*/
-
-#include <da.lib.h>
-
-int main(int argc, char **argv){
- da da0;
- da_alloc(&da0, sizeof(int));
- int i = 0;
- int *pt = da0->base;
- while( i < 10 ){
-
- }
-
-}
--- /dev/null
+/*
+Tests for da.
+
+*/
+
+#include <da.cli.h>
+#include <stdbool.h>
+
+int test_da_0(){
+ da da0;
+ da_alloc(&da0, sizeof(int)); // leaves room for 4 ints
+ int i = 0;
+ int *pt = da0->base;
+ // will double, 4 -> 8, then double 8 -> 16
+ while( i < 10 ){
+ if(da_boundq(&da0, pt)){
+ char *old_base = da_expand(&da);
+ da_rebase(&da, old_base, pt);
+ }
+ *pt = i;
+ i++;
+ pt++;
+ }
+
+ bool f0 = da.size == sizof(int) * 16;
+ bool f1 = 10 == (da.end - da.base) / sizeof(int);
+ bool f2 = true;
+ pt = da0->base;
+ while( i < 10 ){
+ f2 = f2 && *pt == i && !da_endq(&da, pt);
+ i++;
+ pt++;
+ }
+ bool f3 = da_endq(&da, pt);
+
+ return f0 && f1 && f2 && f3;
+}
+
+
+int main(){
+
+ bool da_0_passed = test_da_0();
+ if( da_0_passed ){
+ printf("da_0_passed");
+ return 0;
+ }
+ printf("da_0_failed");
+ return 1;
+
+}
return (char *)pt >= dap->end;
}
+// true when pt has run off the end of the area allocated for the array
+bool da_boundq(da *dap, void *pt){
+ return (char *)pt >= dap->base + dap->size
+}
+
void da_push(da *dap, void *item){
- if( dap->end + dap->item_size >= dap->base + dap->size ){
- da_expand(dap);
- }
+ if( dap->end + dap->item_size >= dap->base + dap->size ) da_expand(dap);
memcpy(dap->end, item, dap->item_size);
- dap->end += item_size;
+ dap->end += dap->item_size;
}
// passed in f(item_pt, arg_pt)
+++ /dev/null
-# Copyright 2011 (C) Reasoning Technology Ltd. All Rights Reserved
-#
-# 2010 11 20 TWL Created
-# 2019 02 24 TWL modified for subu project and placed under MIT license
-
-# 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)
-
-# some versions of Linux need a -e option others complain if there is a -e .. and it isn't the binary for echo ..
-ECHO= echo
-#ECHO= echo -e
-
-SHELL=/bin/bash
-SCRATCHDIR= 5_scratch # clean and others put things here
-CC=gcc
-CFLAGS=-std=gnu11 -fPIC -I. -ggdb -Werror -DDEBUG -DDEBUGDB
-#CFLAGS=-std=gnu11 -fPIC -I. -Werror
-LIB="2_lib/libsubu.a"
-LINKFLAGS=-L2_lib -lsubu -lsqlite3
-
-#these are the source files that exist
-SOURCES_LIB= $(wildcard *.lib.c)
-SOURCES_CLI= $(wildcard *.cli.c)
-SOURCES= $(SOURCES_LIB) $(SOURCES_CLI)
-
-#these are the object files to be made
-OBJECTS_LIB= $(patsubst %.c, %.o, $(SOURCES_LIB))
-OBJECTS_CLI= $(patsubst %.c, %.o, $(SOURCES_CLI))
-OBJECTS= $(OBJECTS_LIB) $(OBJECTS_CLI)
-
-#these are the header files that exist, makeheaders will want to see them
-HFILES = $(wildcard *.lib.h) $(wildcard *.cli.h)
-
-# sort causes compiles to go in lexical order by file name, this is used to order the tests e.g.
-EXECS= $(sort $(patsubst %.cli.c, %, $(wildcard *.cli.c)))
-
-all: version deps lib execs
-
-version:
- @echo '---- make $@:------------------------------------------------------------'
- @echo `pwd`'>'
- @echo makefile version 2.0
- @echo "CC: " $(CC)
- @echo "CFLAGS: " $(CFLAGS)
- @echo "LIB: " $(LIB)
- @echo "LINKFLAGS: " $(LINKFLAGS)
- @echo '______end make $@_____'
-
-# safe to run this in an already setup or partially setup directory
-setup:
- @echo '---- make $@:------------------------------------------------------------'
- @echo `pwd`'>'
- if [ ! -e $(SCRATCHDIR) ]; then mkdir $(SCRATCHDIR); fi
- if [ ! -e 1_tests ]; then mkdir 1_tests; fi
- if [ ! -e 1_try ]; then mkdir 1_try; fi
- if [ ! -e 2_bin ]; then mkdir 2_bin; fi
- if [ ! -e 2_lib ]; then mkdir 2_lib; fi
- if [ ! -e 2_doc ]; then mkdir 2_doc; fi
- if [ ! -e 2_include ]; then mkdir 2_include; fi
- if [ ! -e 5_deprecated ]; then mkdir 5_deprecated; fi
- if [ ! -e 5_scratch ]; then mkdir 5_scratch; fi
- @echo '______end make $@_____'
-
-
-deps:
- @echo '---- make $@:------------------------------------------------------------'
- @echo `pwd`'>'
- makeheaders $(SOURCES) $(HFILES)
- sed -i '/^ *int *main *(.*)/d' *.h
- $(CC) $(CFLAGS) -MM $(SOURCES) 1> 7_makefile_deps
- for i in $(EXECS) ; do\
- $(ECHO) >> 7_makefile_deps;\
- $(ECHO) "2_bin/$$i : $$i.cli.o $(LIB)" >> 7_makefile_deps;\
- $(ECHO) " $(CXX) -o 2_bin/$$i $$i.cli.o $(LINKFLAGS)" >> 7_makefile_deps;\
- done
- @echo '______end make $@_____'
-
-lib:
- @echo '---- make $@:------------------------------------------------------------'
- @echo `pwd`'>'
- if [ ! -e 7_makefile_deps ]; then make deps; fi
- make sub_lib
- @echo '______end make $@_____'
-
-sub_lib: $(LIB)
-
-
-execs: $(LIB)
- @echo '---- make $@:------------------------------------------------------------'
- @echo `pwd`'>'
- if [ ! -e 7_makefile_deps ]; then make deps; fi
- make sub_execs
- @echo '-> sudo 2_bin/setuid_root.sh subu-mk-0 subu-rm-0'
- cat 2_bin/setuid_root.sh
- @echo -n "Are you sure? [y/N] " && read ans && [ $${ans:-N} == y ]
- sudo 2_bin/setuid_root.sh subu-mk-0 subu-rm-0
- @echo '______end make $@_____'
-
-sub_execs: $(patsubst %, 2_bin/%, $(EXECS))
-
-#not ready yet
-install: all
- @echo '---- make $@:------------------------------------------------------------'
- @echo `pwd`'>'
- @if[ ! -e 1_tests_passed ]; then echo "can't install as tests have not passed"; fi
- @test -e test_passed
- for i in $(BIN); do cp $$i $(RT_BASE)/bin; done
- cp $(LIB) $(RT_BASE)/lib
- cp $(APPLICATION).h $(RT_BASE)/include
- if [ -d $(APPLICATION) ]; then cp $(APPLICATION)/*.h $(RT_BASE)/include/$(APPLICATION); fi
- @echo '______end make $@_____'
-
-clean:
- @echo '---- make $@:------------------------------------------------------------'
- @echo `pwd`'>'
- if [ -f subudb ]; then rm subudb; fi
- for i in $(wildcard *~); do mv $$i $(SCRATCHDIR); done
- for i in $(wildcard *.lib.o) $(wildcard *.cli.o); do rm $$i; done
- for i in $(HFILES); do mv $$i 5_scratch; done # just in case someone wrote a header file
- if [ -f 7_makefile_deps ]; then rm 7_makefile_deps; fi
- @echo '______end make $@_____'
-
-
-# not ready ...
-# dist_clean is used to clean thing up before doing a checkin, hg add should be safe after a dist_clean
-# dist_clean will recurse into the include directory = $(APPLICATION), tests, and try if they are present
-#
-dist_clean:
- @echo '---- make $@:------------------------------------------------------------'
- @echo `pwd`'>'
- make clean
- if [ -d $(APPLICATION) ]; then cd $(APPLICATION); make clean; fi
- if [ -f $(LIB) ]; then rm $(LIB); fi
- for i in $(EXECS); do if [ -e 2_bin/$$i ]; then rm 2_bin/$$i; fi; done
- if [ -d 1_tests ]; then cd 1_tests; make dist_clean; fi
- if [ -d 1_try ] ; then cd 1_try; make dist_clean; fi
- @echo '______end make $@_____'
-
-# not written yet
-# copies stuff from the src dir to the stage dirs
-# stage:
-
-
--include 7_makefile_deps
-
-# recipe for making object files:
-#
-%.o : %.c
- $(CC) $(CFLAGS) -c $<
-
-#
-$(LIB) : $(OBJECTS_LIB)
- ar rcs $(LIB) $(OBJECTS_LIB)
--- /dev/null
+
+SHELL=/bin/bash
+
+-include 0_makefile_flags
+
+DEPS_FILE=$(TMPDIR)/makefile_deps
+
+# 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)
+
+# files used by the compiler
+SOURCES_LIB= $(wildcard *.lib.c)
+SOURCES_CLI= $(wildcard *.cli.c)
+SOURCES= $(SOURCES_LIB) $(SOURCES_CLI)
+
+HFILES = $(wildcard *.lib.h) $(wildcard *.cli.h)
+
+OBJECTS_LIB= $(patsubst %.c, %.o, $(SOURCES_LIB))
+OBJECTS_CLI= $(patsubst %.c, %.o, $(SOURCES_CLI))
+OBJECTS= $(OBJECTS_LIB) $(OBJECTS_CLI)
+
+EXECS= $(sort $(patsubst %.cli.c, %, $(wildcard *.cli.c)))
+
+all: version deps lib execs
+
+version:
+ @echo '---- make $@:------------------------------------------------------------'
+ @echo makefile version 3.0
+ @echo "PWD: " $(PWD)
+ @echo "MAKEFILE_LIST: " $(MAKEFILE_LIST)
+ @echo "CC: " $(CC)
+ @echo "CFLAGS: " $(CFLAGS)
+ @echo "LINKFLAGS: " $(LINKFLAGS)
+ @echo '______end make $@_____'
+
+info:
+ @echo '---- make $@:------------------------------------------------------------'
+ @echo "DEPDIR: " $(DEPDIR)
+ @echo "DOCDIR: " $(DOCDIR)
+ @echo "EXECSDIR: " $(EXECSDIR)
+ @echo "HDIR: " $(HDIR)
+ @echo "LIBDIR: " $(LIBDIR)
+ @echo "TESTDIR: " $(TESTDIR)
+ @echo "TMPDIR: " $(TMPDIR)
+ @echo "TOOLSDIR: " $(TOOLSDIR)
+ @echo "TRYDIR: " $(TRYDIR)
+ @echo "DEPS_FILE: " $(DEPS_FILE)
+ @echo "LIB_FILE: " $(LIB_FILE)
+ @echo "SOURCES_LIB: " $(SOURCES_LIB)
+ @echo "SOURCES_CLI: " $(SOURCES_CLI)
+ @echo "SOURCES: " $(SOURCES)
+ @echo "HFILES: " $(HFILES)
+ @echo "OBJECTS_LIB: " $(OBJECTS_LIB)
+ @echo "OBJECTS_CLI: " $(OBJECTS_CLI)
+ @echo "OBJECTS: " $(OBJECTS)
+ @echo "EXECS: " $(EXECS)
+ @echo '______end make $@_____'
+
+# should be safe to run this in an already setup or partially setup directory
+setup:
+ @echo '---- make $@:------------------------------------------------------------'
+ @echo `pwd`'>'
+ if [ ! -e $(DEPRDIR) ]; then mkdir $(DEPRDIR); fi
+ if [ ! -e $(DOCDIR) ]; then mkdir $(DOCDIR); fi
+ if [ ! -e $(EXECSDIR) ]; then mkdir $(EXECSDIR); fi
+ if [ ! -e $(HDIR) ]; then mkdir $(HDIR); fi
+ if [ ! -e $(LIBDIR) ]; then mkdir $(LIBDIR); fi
+ if [ ! -e $(TESTDIR) ]; then mkdir $(TESTDIR); fi
+ if [ ! -e $(TMPDIR) ]; then mkdir $(TMPDIR); fi
+ if [ ! -e $(TRYDIR) ]; then mkdir $(TRYDIR); fi
+ @echo '______end make $@_____'
+
+deps:
+ @echo '---- make $@:------------------------------------------------------------'
+ @echo `pwd`'>'
+ $(CC) $(CFLAGS) -MM $(SOURCES) 1> $(DEPS_FILE)
+ for i in $(EXECS) ; do\
+ $(ECHO) >> $(DEPS_FILE);\
+ $(ECHO) "$(EXECSDIR)/$$i : $$i.cli.o $(LIB_FILE)" >> $(DEPS_FILE);\
+ $(ECHO) " $(CC) -o $(EXECSDIR)/$$i $$i.cli.o $(LINKFLAGS)" >> $(DEPS_FILE);\
+ done
+ @echo '______end make $@_____'
+
+lib:
+ @echo '---- make $@:------------------------------------------------------------'
+ @echo `pwd`'>'
+ if [ ! -e $(DEPS_FILE) ]; then make deps; fi
+ make sub_lib
+ @echo '______end make $@_____'
+
+sub_lib: $(LIB_FILE)
+
+
+execs: $(LIB_FILE)
+ @echo '---- make $@:------------------------------------------------------------'
+ @echo `pwd`'>'
+ if [ ! -e $(DEPS_FILE) ]; then make deps; fi
+ make sub_execs
+ @echo '______end make $@_____'
+
+sub_execs: $(patsubst %, $(EXECSDIR)/%, $(EXECS))
+
+clean:
+ @echo '---- make $@:------------------------------------------------------------'
+ @echo `pwd`'>'
+ 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 $(LIB_FILE) ]; then rm $(LIB_FILE); fi
+ if [ -f $(DEPS_FILE) ]; then rm $(DEPS_FILE); fi
+ @echo '______end make $@_____'
+
+dist-clean:
+ @echo '---- make $@:------------------------------------------------------------'
+ @echo `pwd`'>'
+ make clean
+ if [ -d $(TESTDIR) ]; then cd $(TESTDIR); make dist_clean; fi
+ if [ -d $(TRYDIR) ] ; then cd $(TRYDIR); make dist_clean; fi
+ @echo '______end make $@_____'
+
+#
+$(LIB_FILE) : $(OBJECTS_LIB)
+ ar rcs $(LIB_FILE) $(OBJECTS_LIB)
+
+-include $(DEPS_FILE)
+
+# recipe for making object files:
+#
+%.o : %.c
+ $(CC) $(CFLAGS) -c $<
+
+