Buildsys2
[henge/webcc.git] / src / .make / buildc.mk
index a1768bb..48e9d0a 100644 (file)
@@ -8,64 +8,70 @@
 #compile C files either to native bc through gcc,
 #or web through emscripten
 ##################################################
-#expand the app source dir last as a module to build
-CMODULES := $(MODULES) $(APPSRC)
-CLIBS    := $(patsubst %,-l%,$(LIBS))
-CSRC     := $(wildcard $(patsubst %,%/*.c,$(CMODULES)))
-CTARG    := $(CSRC:.c=.o)
-
-##################################################
-#Global CFlags
+#Manually defined resources
 ##################################################
-#Warn Level
-CFLAGS := -Wall
-#Include each module's root directory and src/
-CFLAGS += $(patsubst %,-I%, $(CMODULES)) -I.
-#Precompiler Flags
-CFLAGS += -DAPPNAME=$(APPNAME)
+#Libraries to link for the build
+CLIBS    := wolfssl SDL2 SDL2_image SDL2_ttf
+#Modules for C (directories in src/ with C code)
+CMODULES := $(APPMODULE)
+#CFlag defaults
+CFLAGS   := -Wall
 
-##################################################
-#Missing Lib Handler
-##################################################
-LDPIPE := ld $(CLIBS) 2>&1 >/dev/null
-LDGREP := grep "cannot find"
-LDSED  := sed -e 's@ld:.*-l\([^ ]*\).*@\1@'
-MISSINGLIBS := $(shell $(LDPIPE) | $(LDGREP) | $(LDSED))
-#Automake vars for building libs
-AMGEN  := ./autogen.sh
-AMCONF := ./configure
-AMMAKE := make
 
 ##################################################
-#Override C Environment for compiler-specific
-#or OS specific requirements, if present
+#Allow compiler-specific and OS-specific
+#makefiles to override C environment vars
 ##################################################
 -include .make/buildc_$(strip $(notdir $(CC))).mk
 ifdef OS
 -include .make/buildc_$(strip $(OS)).mk
 endif
 
-#Determine suffix (possibly overridden by includes)
-COBJSUF := $(suffix $(firstword $(CTARG)))
+#Link each CLIB with -l
+CFLAGS += $(patsubst %,-l%,$(CLIBS))
+#Include each module's root directory and .
+CFLAGS += $(patsubst %,-I%, $(CMODULES)) -I.
+#C Preprocessor defines
+CFLAGS += -DAPPNAME=$(APPNAME)
 
 ##################################################
-#C Dependency Generator
+#Conditional (may be set in buildc_*.mk files)
 ##################################################
-CGENDEP := $(strip $(CC) -MM -MG $(CXXFLAGS) $(CFLAGS)) $BASE.c
-CGENDEP += | sed -e 's@^.*\.o:@@'
-CGENDEP += | tr '\\' ' '
+#Sources are found in any CMODULE subdir
+CSRC     ?= $(wildcard $(patsubst %,%/*.c,$(CMODULES)))
+#Output format suffix
+COBJSUF  ?= .o
+#Architecture
+CARCH    ?= $(shell uname -m)
+#Application suffix
+APPSUF   ?= .$(CARCH)
+#C binary distribution directory
+CDISTDIR ?= $(DISTDIR)
+#Directory for C binary/executable output files
+CBINDIR  ?= $(CDISTDIR)/bin
+#Set up the final C build targets
+CTARG    ?= $(CSRC:.c=$(COBJSUF))
+
+#Set of shell functions used to determine dependencies
+#for building each c source file
+#$BASE is a keyword replaced in the main Makefile iteratively
+#for each source file.
+CDPIPE ?= $(strip $(CC)) -MM -MG $(CXXFLAXS) $(CFLAGS) $BASE.c
+CDSED  ?= sed -e 's@^.*\.o:@@'
+CDTR   ?= tr '\\' ' '
+#The shell command to execute and evaluate for deps
+CDEPSCOMMAND ?= $(CDPIPE) | $(CDSED) | $(CDTR)
+
+#Set of shell functions used to determine the
+#name of each library the compiler/LD can't find
+LDPIPE ?= $(CC) $(patsubst %,-l%,$(CLIBS)) 2>&1 >/dev/null
+LDGREP ?= grep "cannot find"
+LDSED  ?= sed -e 's@^.*cannot find -l\([a-zA-Z0-9\.]*\).*@\1@g'
+#Calculate missing libs
+MISSINGLIBS ?= $(strip $(shell $(LDPIPE) | $(LDGREP) | $(LDSED)))
 
-#Set up all missing libs to be made in the source directory
+#Include handler for building missing libs, if any
 ifdef MISSINGLIBS
-$(info Static libraries to be built in $(XTLIBDIR):)
-$(info $(patsubst %,lib%.so,$(MISSINGLIBS)))
-STATICLIBS := $(patsubst %,$(XTLIBDIR)/lib%.so,$(MISSINGLIBS))
-CFLAGS     += -L$(XTLIBDIR) $(patsubst %,-I$(XTDIR)/%,$(MISSINGLIBS))
-#Ensure that C files depend on the creation of these static libs
-CDEPS      += $(STATICLIBS)
-#Modify the dependency generator to find the right directory for
-#missing libs (they are in XTDIR/libname)
-CGENDEP    += $(patsubst %, | sed -e 's@ \(%\)/@$(XTDIR)/\1/\1/@',$(MISSINGLIBS))
+include .make/buildclibs.mk
 endif
 
-CFLAGS += $(CLIBS)