first dev commit - add build system, add debug and release builds, use static linked libraries for now
+86 −4 · 10 files changed
-
Tupfile+1 −0 -
Tuprules.tup+22 −0 -
bin/Tupfile+19 −0 -
include/square.h+2 −0 -
lib/Tupfile+10 −0 -
obj/Tupfile+8 −0 -
src/main.c+4 −4 -
src/square.c+8 −0 -
test/Tupfile+12 −0 -
test/testfile+0 −0
@@ -0,0 +1 @@ +include_rules @@ -0,0 +1,22 @@ +&libdir = include/ +&objdir = obj/ +&bindir = bin/ +CDEBUG += -Weverything +CDEBUG += -g +CDEBUG += -Og +CDEBUG += -ggdb + +CRELEASE += -O2 +CRELEASE += -D_FORTIFY_SOURCE=2 +CRELEASE += -fexceptions +CRELEASE += -fvisibility=hidden +CRELEASE += -Werror + +# Do the object files +!ccodbg = |> clang $(CDEBUG) -I&(libdir) -c %f -o &(objdir)/%o |> %B_debug.o +!ccorel = |> clang $(CRELEASE) -I&(libdir) -c %f -o &(objdir)/%o |> %B_release.o +# macro for the archive command +!ar = |> ar crs %o %f |> +!ccbdbg = |> clang $(CDEBUG) %f -o &(bindir)/%o |> %B +!ccbrel = |> clang $(CRELEASE) %f -o &(bindir)/%o |> %B + @@ -0,0 +1,19 @@ +include_rules +#&Libs = +#CXFLAGS += -lc +#CXFLAGS += -lm +#CXFLAGS += ../lib/*.a + +#: *.c |> !cc |> ../obj/*.o +#: *.c |> !cc |> ../obj/*.o | clang %f $(CXFLAGS) -o %f |> %B +#: ../obj/*.o | ../lib/*.a |> clang %f $(CXFLAGS) -o testfile |> %B +#: foreach ../lib/*.a |> clang -v %f $(CXFLAGS) -o %f |> %B +#: |> echo first > %o && echo second > %o.2 |> out/file.txt | %O.txt.2 +# produces test binary +#: |> clang ../src/main.c -v -o %o |> test +# works with static library +#: ../lib/mylib.a |> clang %f -v -o %o |> %B +# make {bin} placeholder +#: foreach ../lib/*.a |> clang %f -v -o %o |> program +: foreach ../lib/*_debug.a |> !ccbdbg |> program_debug +: foreach ../lib/*_release.a |> !ccbrel |> program_release @@ -0,0 +1,2 @@ +#include <stdio.h> +extern int squares(int x,int y); @@ -0,0 +1,10 @@ +# 3. Create an archive file - static library +# TODO: Static libary - for own code, maybe not +# required for others +include_rules +#: ../obj/*.o |> !ar |> mylib.a +#: foreach ../obj/*.o |> !ar |> %B.a {obj} +# not foreach .. for all object files into a single archive - for now not .so file +#: foreach ../obj/*.o |> !ar |> +: ../obj/*_debug.o |> !ar |> mylib_debug.a +: ../obj/*_release.o |> !ar |> mylib_release.a @@ -0,0 +1,8 @@ +# 1. Build the source code in C +# will grab the libraries included +# in the include definitions +# and call the !cc macro to build + +include_rules +: foreach ../src/*.c |> !ccodbg |> +: foreach ../src/*.c |> !ccorel |> @@ -1,10 +1,8 @@ #include <stdio.h> #include <stdlib.h> #include <errno.h> - -#include "sds/sds.h" - - +#include "../lib/sds/sds.h" +#include "../include/square.h" int main (int argc, char** argv) { @@ -14,5 +12,7 @@ int main (int argc, char** argv) { fprintf(stdout, "The number of arguments is: %d\n",argc); fprintf(stdout, "%s\n","correct" ); + int rc = square(4,5); + fprintf(stdout, "%d\n",rc); return EXIT_SUCCESS; } @@ -0,0 +1,8 @@ +#include "../include/square.h" + +extern int square(int x, int y) { + + fprintf(stdout, "Square of %d and %d is: %d\n",x,y,x*y ); + + return 0; +} @@ -0,0 +1,12 @@ +include_rules +#&Libs = +CXFLAGS += -lc +CXFLAGS += -lm +CXFLAGS += ../lib/*.a + +#: *.c |> !cc |> ../obj/*.o +#: *.c |> !cc |> ../obj/*.o | clang %f $(CXFLAGS) -o %f |> %B +#: ../obj/*.o | ../lib/*.a |> clang %f $(CXFLAGS) -o testfile |> %B +#: foreach ../lib/*.a |> clang -v %f $(CXFLAGS) -o %f |> %B +: |> echo first > %o && echo second > %o.2 |> out/file.txt | %O.txt.2 +