1 ##################################################
2 #Desc: C Compiler Setup
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
)
17 ##################################################
19 ##################################################
22 #Include each module's root directory and src/
23 CFLAGS
+= $(patsubst %,-I
%, $(CMODULES
)) -I.
25 CFLAGS
+= -DAPPNAME
=$(APPNAME
)
27 ##################################################
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
39 ##################################################
40 #Override C Environment for compiler-specific
41 #or OS specific requirements, if present
42 ##################################################
43 -include .make
/buildc_
$(strip $(notdir $(CC
))).mk
45 -include .make
/buildc_
$(strip $(OS
)).mk
48 #Determine suffix (possibly overridden by includes)
49 COBJSUF
:= $(suffix $(firstword $(CTARG
)))
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
'\\' ' '
58 #Set up all missing libs to be made in the source directory
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
))