makefile updates checkpoint
authorThomas Walker Lynch <thomas.lynch@reasoningtechnology.com>
Tue, 19 Mar 2019 22:10:38 +0000 (23:10 +0100)
committerThomas Walker Lynch <thomas.lynch@reasoningtechnology.com>
Tue, 19 Mar 2019 22:10:38 +0000 (23:10 +0100)
14 files changed:
src/0_makefile
src/0_makefile_flags [new file with mode: 0644]
src/1_tests/0_makefile [new file with mode: 0755]
src/1_tests/da.c [new file with mode: 0644]
src/1_tests/subudb [new file with mode: 0644]
src/1_tmp/da.lib.h
src/1_tmp/subu.lib.h
src/1_try/voidptr [new file with mode: 0755]
src/1_try/voidptr.c [new file with mode: 0644]
src/da.lib.c
src/subu-bind-all.cli.c
src/subu-mk-0.cli.c
tools/lib/7_makefile [deleted file]
tools/lib/makefile [new file with mode: 0755]

index 528caae..92c6beb 100755 (executable)
@@ -1,32 +1,10 @@
 
 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
+-include 0_makefile_flags
 
-# directories used by this makefile, these could all be set to dot for
-# the simplest source directory structure
-
-#$(PWD) is the directory that make was called from, this is already build in
-TMPDIR=1_tmp
-EXECSDIR=1_execs
-HDIR=1_headers
-LIBDIR=1_lib
-TOOLSDIR=$(realpath ../tools)
-
-# some important files
 DEPS_FILE=$(TMPDIR)/makefile_deps
-LIB_FILE=$(LIBDIR)/libsubu.a
-
-# external tools called out in this makefile
-SUID_TOOL=$(TOOLSDIR)/bin/setuid_root.sh
 
-# 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
 
 ### end of user defined variables
 ###--------------------------------------------------------------------------------
@@ -85,14 +63,14 @@ lists:
 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 1_deprecated ]; then mkdir 1_deprecated; fi
-       if [ ! -e 1_doc ]; then mkdir 1_doc; fi
-       if [ ! -e 1_execs ]; then mkdir 1_execs; fi
-       if [ ! -e 1_headers ]; then mkdir 1_headers; fi
-       if [ ! -e 1_lib ]; then mkdir 1_lib; fi
-       if [ ! -e 1_tests ]; then mkdir 1_tests; fi
-       if [ ! -e 1_try ]; then mkdir 1_try; fi
+       if [ ! -e $(TRYDIR) ]; then mkdir $(TRYDIR); fi
        @echo '______end make $@_____'
 
 deps:
diff --git a/src/0_makefile_flags b/src/0_makefile_flags
new file mode 100644 (file)
index 0000000..23dbc66
--- /dev/null
@@ -0,0 +1,33 @@
+
+# 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=1_deprecated
+DOCDIR=1_doc
+EXECSDIR=1_execs
+HDIR=1_headers
+LIBDIR=1_lib
+TESTDIR=1_tests
+TMPDIR=1_tmp
+TOOLSDIR=$(realpath $(PROJECT_SUBU)/tools)
+TRYDIR=1_try
+
+
+# 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
+
+LIB_FILE=$(LIBDIR)/libsubu.a
+
+# external tools called out in this makefile
+SUID_TOOL=$(TOOLSDIR)/bin/setuid_root.sh
diff --git a/src/1_tests/0_makefile b/src/1_tests/0_makefile
new file mode 100755 (executable)
index 0000000..77cc689
--- /dev/null
@@ -0,0 +1,196 @@
+
+
+
+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
+
+# external tools called out in this makefile
+SUID_TOOL=$(TOOLSDIR)/bin/setuid_root.sh
+
+### 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)))
+
+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:
+
+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 $@_____'
+
+#
+$(LIB_FILE) : $(OBJECTS_LIB)
+       ar rcs $(LIB_FILE) $(OBJECTS_LIB)
+
+-include $(DEPS_FILE)
+
+# recipe for making object files:
+#
+%.o : %.c
+       $(CC) $(CFLAGS) -c $<
+
+
diff --git a/src/1_tests/da.c b/src/1_tests/da.c
new file mode 100644 (file)
index 0000000..12fb551
--- /dev/null
@@ -0,0 +1,17 @@
+/*
+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 ){
+
+  }
+
+}
diff --git a/src/1_tests/subudb b/src/1_tests/subudb
new file mode 100644 (file)
index 0000000..348a99d
Binary files /dev/null and b/src/1_tests/subudb differ
index 0f5bb47..4702189 100644 (file)
@@ -5,16 +5,16 @@
 void daps_map(char **base,char **end_pt,void f(void *));
 #define RETURN(rc) \
   { daps_map(mrs, mrs_end, free); return rc; }
-void daps_alloc(char **base,size_t *s);
+void daps_alloc(char ***base,size_t *s);
 #define MK_MRS \
   char **mrs;  \
   char **mrs_end; \
   size_t mrs_size; \
-  daps_alloc(mrs, &mrs_size);\
+  daps_alloc(&mrs, &mrs_size);\
   mrs_end = mrs;
-void daps_push(char **base,char **pt,size_t *s,char *item);
+void daps_push(char ***base,char ***pt,size_t *s,char *item);
 bool daps_bound(char **base,char **pt,size_t s);
-void daps_expand(char **base,char **pt,size_t *s);
+void daps_expand(char ***base,char ***pt,size_t *s);
 void da_map(void *base,void *end_pt,void f(void *),size_t item_size);
 void da_push(void **base,void **pt,size_t *s,void *item,size_t item_size);
 bool da_bound(void *base,void *pt,size_t s);
index 5d072e7..69c5da7 100644 (file)
@@ -27,14 +27,14 @@ int dispatch_f_euid_egid(char *fname,int(*f)(void *arg),void *f_arg,uid_t euid,g
 void daps_map(char **base,char **end_pt,void f(void *));
 #define RETURN(rc) \
   { daps_map(mrs, mrs_end, free); return rc; }
-void daps_push(char **base,char **pt,size_t *s,char *item);
+void daps_push(char ***base,char ***pt,size_t *s,char *item);
 int dbprintf(const char *format,...);
-void daps_alloc(char **base,size_t *s);
+void daps_alloc(char ***base,size_t *s);
 #define MK_MRS \
   char **mrs;  \
   char **mrs_end; \
   size_t mrs_size; \
-  daps_alloc(mrs, &mrs_size);\
+  daps_alloc(&mrs, &mrs_size);\
   mrs_end = mrs;
 int subu_mk_0(char **mess,sqlite3 *db,char *subuname);
 extern char Subuland_Extension[];
diff --git a/src/1_try/voidptr b/src/1_try/voidptr
new file mode 100755 (executable)
index 0000000..3849b74
Binary files /dev/null and b/src/1_try/voidptr differ
diff --git a/src/1_try/voidptr.c b/src/1_try/voidptr.c
new file mode 100644 (file)
index 0000000..bd9c3e5
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+They say a cast is not required passing a typed pointer to a void * argument,
+but What about void **?
+
+gcc -std=gnu11 -o voidptr voidptr.c
+voidptr.c: In function ‘main’:
+voidptr.c:28:5: warning: passing argument 1 of ‘g’ from incompatible pointer type [-Wincompatible-pointer-types]
+   g(&pt, y);
+     ^~~
+voidptr.c:13:15: note: expected ‘void **’ but argument is of type ‘int **’
+ void g(void **pt0, void *pt1){
+        ~~~~~~~^~~
+
+*/
+#include <stdio.h>
+
+int f(void *pt){
+  return *(int *)pt;
+}
+
+/* fails
+void g(void **pt0, int *pt1){
+  *pt0 = pt1;
+}
+*/
+
+// passes
+void g(void *pt0, int *pt1){
+  *(int **)pt0 = pt1;
+}
+
+int main(){
+  int x = 5;
+  int *xp = &x;
+  printf("%d\n",f(xp));
+
+  int y[3];
+  y[0] = 10;
+  y[1] = 11;
+  y[2] = 12;
+
+  int *pt;
+  g(&pt, y);
+  printf("%d\n",*pt);
+
+  printf("that's all folks\n");
+  return 0;
+}
index f2cabcb..e571caf 100644 (file)
@@ -13,83 +13,72 @@ Dynamic Array
 
 //--------------------------------------------------------------------------------
 // generic
+// We manipulate pointers to a smallest addressable unit. The sizeof operator
+// returns counts in these addressable units. Sizeof(char) is defined to be 1.
+
+struct da{
+  char *base;
+  char *end; // one byte/one item off the end of the array
+  size_t *size; // size >= (end - base) + 1;
+  size_t item_size;
+};
+
+void da_alloc(da *dap, size_t item_size){
+  dap->size = 4 * item_size;
+  dap->item_size = item_size;
+  dap->end = 0;
+  dap->base = malloc(dap->size);
+}
 
-// s is the size of the array in bytes
-void da_alloc(void **base, size_t *s, size_t item_size){
-  *s = 4 * item_size;
-  *base = malloc(*s);
+// Doubles size of of da.  Returns old base, so that existing pointers into the
+// array can be moved to the new array
+char *da_expand(da *dap){
+  size_t end_offset = ((char *)dap->end - (char *)dap->base);
+  size_t new_size = dap->size << 1;
+  char *old_base = dap->base;
+  char *new_base = malloc( new_size );
+  memcpy( new_base, dap->base, end_offset + 1);
+  free(old_base);
+  dap->base = new_base;
+  dap->end = new_base + offset;
+  dap->size = new_size;
+  return old_base;
 }
 
-// doubles size of an array
-void da_expand(void **base, void **pt, size_t *s){
-  size_t offset = ((unsigned char *)*pt - (unsigned char *)*base);
-  size_t new_s = *s << 1;
-  void *new_base = malloc( new_s );
-  memcpy( new_base, *base, offset + 1);
-  free(base);
-  *base = new_base;
-  *pt = new_base + offset;
-  *s = new_s;
+void da_rebase(da *dap, char *old_base, void *pta){
+  char **pt = (char **)pta;
+  size_t offset = *pt - old_base;
+  *pt = dap->base + offset;
 }
 
 // true when pt has run off the end of the area currently allocated for the array
-bool da_bound(void *base, void *pt, size_t s){
-  return pt >= base + s;
+bool da_endq(da *dap, void *pt){
+  return (char *)pt >= dap->end;
 }
 
-void da_push(void **base, void **pt, size_t *s, void *item, size_t item_size){
-  while( *pt + item_size >= *base + *s ){
-    da_expand(base, pt, s);
+void da_push(da *dap, void *item){
+  if( dap->end + dap->item_size >= dap->base + dap->size ){
+    da_expand(dap);
   }
-  memcpy(*pt, item, item_size);
-  *pt += item_size;
+  memcpy(dap->end, item, dap->item_size);
+  dap->end += item_size;
 }
 
-void da_map(void *base, void *end_pt, void f(void *), size_t item_size){
-  void *pt = base;
-  while( pt != end_pt ){
-    f(pt);
+// passed in f(item_pt, arg_pt)
+// Curring is difficult in C, so we allow that we might like to have an
+// additional arg.  The additional arg may be set to NULL if it is not needed.
+void da_map(da *dap, void f(void *, void *), void *arg){
+  char *pt = dap->base;
+  while( pt != dap->end ){
+    f(pt, arg);
   pt += item_size;
   }
 }
 
-//--------------------------------------------------------------------------------
-// dynamic array of pointers to strings
-
-// s is still the length of the array in bytes
-void daps_alloc(char **base, size_t *s){
-  da_alloc((void **)base, s, sizeof(char *));
-}
-
-void daps_expand(char **base, char **pt, size_t *s){
-  da_expand((void **)base, (void **)pt, s);
-}
-
-bool daps_bound(char **base, char **pt, size_t s){
-  return da_bound( (void *) base, (void *)pt, s);
-}
-
-void daps_push(char **base, char **pt, size_t *s, char *item){
-  da_push((void **)base, (void **)pt, s, (void *)item, sizeof(char *));
-}
-
-void daps_map(char **base, char **end_pt, void f(void *)){
-  da_map((void *)base, (void *)end_pt, f, sizeof(char *));
-}
-
-// one use for an array of string pointers is to keep list of
-// strings that must be freed.  I.e. 'managed' strings
 #if INTERFACE
 
-#define MK_MRS \
-  char **mrs;  \
-  char **mrs_end; \
-  size_t mrs_size; \
-  daps_alloc(mrs, &mrs_size);\
-  mrs_end = mrs;
-
-#define RETURN(rc) \
-  { daps_map(mrs, mrs_end, free); return rc; }
+#define RETURN(r) \
+  { daps_map(mrs, mrs_end, free); return r; }
 
 #endif
   
index 4754d55..e942909 100644 (file)
@@ -8,7 +8,7 @@ uses unmount to undo this
 #include <stdlib.h>
 
 int main(int argc, char **argv){
-  if( argc != 2){
+  if( argc != 1){
     fprintf(stderr, "%s does not take arguments\n",argv[0]);
     return SUBU_ERR_ARG_CNT;
   }
index d9f9c74..af0888b 100644 (file)
@@ -18,7 +18,8 @@ int main(int argc, char **argv){
   sqlite3 *db;
   rc = sqlite3_open_v2(DB_File, &db, SQLITE_OPEN_READWRITE, NULL);
   if( rc != SQLITE_OK ){
-    fprintf(stderr, "error exit, could not open db file\n");
+    fprintf(stderr, "error when opening db, %s\n", DB_File);
+    fprintf(stderr, "sqlite3 says: %s\n", sqlite3_errmsg(db));
     sqlite3_close(db);
     return SUBU_ERR_DB_FILE;
   }
diff --git a/tools/lib/7_makefile b/tools/lib/7_makefile
deleted file mode 100755 (executable)
index ae06d60..0000000
+++ /dev/null
@@ -1,156 +0,0 @@
-# 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)
diff --git a/tools/lib/makefile b/tools/lib/makefile
new file mode 100755 (executable)
index 0000000..ae06d60
--- /dev/null
@@ -0,0 +1,156 @@
+# 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)