################################################## #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 ################################################## #Manually defined resources ################################################## #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 ################################################## #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 #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) ################################################## #Conditional (may be set in buildc_*.mk files) ################################################## #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))) #Include handler for building missing libs, if any ifdef MISSINGLIBS include .make/buildclibs.mk endif