From 0de5cafb5aac72a28f8da554bef24570dc51771c Mon Sep 17 00:00:00 2001 From: Thomas Walker Lynch Date: Tue, 19 Mar 2019 23:10:38 +0100 Subject: [PATCH] makefile updates checkpoint --- src/0_makefile | 38 ++---- src/0_makefile_flags | 33 +++++ src/1_tests/0_makefile | 196 +++++++++++++++++++++++++++++ src/1_tests/da.c | 17 +++ src/1_tests/subudb | Bin 0 -> 12288 bytes src/1_tmp/da.lib.h | 8 +- src/1_tmp/subu.lib.h | 6 +- src/1_try/voidptr | Bin 0 -> 18432 bytes src/1_try/voidptr.c | 48 +++++++ src/da.lib.c | 109 ++++++++-------- src/subu-bind-all.cli.c | 2 +- src/subu-mk-0.cli.c | 3 +- tools/lib/{7_makefile => makefile} | 0 13 files changed, 361 insertions(+), 99 deletions(-) create mode 100644 src/0_makefile_flags create mode 100755 src/1_tests/0_makefile create mode 100644 src/1_tests/da.c create mode 100644 src/1_tests/subudb create mode 100755 src/1_try/voidptr create mode 100644 src/1_try/voidptr.c rename tools/lib/{7_makefile => makefile} (100%) diff --git a/src/0_makefile b/src/0_makefile index 528caae..92c6beb 100755 --- a/src/0_makefile +++ b/src/0_makefile @@ -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 index 0000000..23dbc66 --- /dev/null +++ b/src/0_makefile_flags @@ -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 index 0000000..77cc689 --- /dev/null +++ b/src/1_tests/0_makefile @@ -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 index 0000000..12fb551 --- /dev/null +++ b/src/1_tests/da.c @@ -0,0 +1,17 @@ +/* +Tests for da. + +*/ + +#include + +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 index 0000000000000000000000000000000000000000..348a99d8bb01c97d4d02085d3018b1a5ae4453e0 GIT binary patch literal 12288 zcmeI&F-yZh6u|MjM0ApfOV?XU8>}vV0jp#vw4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dCepZR_r-98Bkc*T%00%yBI~aWQs*LS;Rha{1`Y5 z8H^v>^E@f6SQ>*Cv5)TZe+H6Dd!A3tD3(bWg%!zN{yC5Z;YZ!go_F!zr*P{t&lJD? z!8HxG=kae#1VBivXK`ho@z+3reTVIN9;cA~WvV~-FSg_J_!qE66}IR3-VzPaSPxWW zVtb~41+>!Mo)@-T`eBRMN48`7uFIasv0<`zpD${T?eBfap)amKj~BPzr2U6fKB?P& z+5V7?SQ###DgNOPUeiYnp0^$+hllvaL4Inrhx;z6NOEO|#l1!+4)5dJ;m2{~`!BvP j;I>;9*73|2E&5}ZbFMe*;u>x(`-$C_#+@z$7c2e?1+`LF literal 0 HcmV?d00001 diff --git a/src/1_try/voidptr.c b/src/1_try/voidptr.c new file mode 100644 index 0000000..bd9c3e5 --- /dev/null +++ b/src/1_try/voidptr.c @@ -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 + +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; +} diff --git a/src/da.lib.c b/src/da.lib.c index f2cabcb..e571caf 100644 --- a/src/da.lib.c +++ b/src/da.lib.c @@ -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 diff --git a/src/subu-bind-all.cli.c b/src/subu-bind-all.cli.c index 4754d55..e942909 100644 --- a/src/subu-bind-all.cli.c +++ b/src/subu-bind-all.cli.c @@ -8,7 +8,7 @@ uses unmount to undo this #include 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; } diff --git a/src/subu-mk-0.cli.c b/src/subu-mk-0.cli.c index d9f9c74..af0888b 100644 --- a/src/subu-mk-0.cli.c +++ b/src/subu-mk-0.cli.c @@ -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/makefile similarity index 100% rename from tools/lib/7_makefile rename to tools/lib/makefile -- 2.20.1