BuildSys1
[henge/webcc.git] / src / .make / buildc.mk
1 ##################################################
2 #Desc: C Compiler Setup
3 #Author: Mihrtec LLC
4 #Date: 2016
5 ##################################################
6 #Included from ./build.mk
7 #Defines variables used in the make process to
8 #compile C files either to native bc through gcc,
9 #or web through emscripten
10 ##################################################
11 #expand the app source dir last as a module to build
12 CMODULES := $(MODULES) $(APPSRC)
13 CLIBS := $(patsubst %,-l%,$(LIBS))
14 CSRC := $(wildcard $(patsubst %,%/*.c,$(CMODULES)))
15 CTARG := $(CSRC:.c=.o)
16
17 ##################################################
18 #Global CFlags
19 ##################################################
20 #Warn Level
21 CFLAGS := -Wall
22 #Include each module's root directory and src/
23 CFLAGS += $(patsubst %,-I%, $(CMODULES)) -I.
24 #Precompiler Flags
25 CFLAGS += -DAPPNAME=$(APPNAME)
26
27 ##################################################
28 #Missing Lib Handler
29 ##################################################
30 LDPIPE := ld $(CLIBS) 2>&1 >/dev/null
31 LDGREP := grep "cannot find"
32 LDSED := sed -e 's@ld:.*-l\([^ ]*\).*@\1@'
33 MISSINGLIBS := $(shell $(LDPIPE) | $(LDGREP) | $(LDSED))
34 #Automake vars for building libs
35 AMGEN := ./autogen.sh
36 AMCONF := ./configure
37 AMMAKE := make
38
39 ##################################################
40 #Override C Environment for compiler-specific
41 #or OS specific requirements, if present
42 ##################################################
43 -include .make/buildc_$(strip $(notdir $(CC))).mk
44 ifdef OS
45 -include .make/buildc_$(strip $(OS)).mk
46 endif
47
48 #Determine suffix (possibly overridden by includes)
49 COBJSUF := $(suffix $(firstword $(CTARG)))
50
51 ##################################################
52 #C Dependency Generator
53 ##################################################
54 CGENDEP := $(strip $(CC) -MM -MG $(CXXFLAGS) $(CFLAGS)) $BASE.c
55 CGENDEP += | sed -e 's@^.*\.o:@@'
56 CGENDEP += | tr '\\' ' '
57
58 #Set up all missing libs to be made in the source directory
59 ifdef MISSINGLIBS
60 $(info Static libraries to be built in $(XTLIBDIR):)
61 $(info $(patsubst %,lib%.so,$(MISSINGLIBS)))
62 STATICLIBS := $(patsubst %,$(XTLIBDIR)/lib%.so,$(MISSINGLIBS))
63 CFLAGS += -L$(XTLIBDIR) $(patsubst %,-I$(XTDIR)/%,$(MISSINGLIBS))
64 #Ensure that C files depend on the creation of these static libs
65 CDEPS += $(STATICLIBS)
66 #Modify the dependency generator to find the right directory for
67 #missing libs (they are in XTDIR/libname)
68 CGENDEP += $(patsubst %, | sed -e 's@ \(%\)/@$(XTDIR)/\1/\1/@',$(MISSINGLIBS))
69 endif
70
71 CFLAGS += $(CLIBS)