################################################## #Desc: C Compiler Setup #Author: Mihrtec LLC #Date: 2016 ################################################## #Included from ./build.mk #Defines variables used in the make process to #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 ################################################## #Warn Level CFLAGS := -Wall #Include each module's root directory and src/ CFLAGS += $(patsubst %,-I%, $(CMODULES)) -I. #Precompiler Flags CFLAGS += -DAPPNAME=$(APPNAME) ################################################## #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 ################################################## -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))) ################################################## #C Dependency Generator ################################################## CGENDEP := $(strip $(CC) -MM -MG $(CXXFLAGS) $(CFLAGS)) $BASE.c CGENDEP += | sed -e 's@^.*\.o:@@' CGENDEP += | tr '\\' ' ' #Set up all missing libs to be made in the source directory 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)) endif CFLAGS += $(CLIBS)