Makefile +Tools
[henge/webcc.git] / src / Makefile
1 ##################################################
2 #Desc: Mihrtec Standard Makefile
3 #Author: Mihrtec LLC
4 #Date: 2016
5 ##################################################
6 #Application Information
7 ##################################################
8 #Executable name, also passed as -DAPPNAME to compiler
9 APPNAME := the_march
10 #Directory in which we expect to find main()
11 APPMODULE := core
12 #Compiler flags for the final executable
13 APPFLAGS :=
14 #Object files statically linked for the executable
15 APPOBJ :=
16 #Dependencies which must be built before the executable
17 APPDEPS :=
18 #Directories containing independent tools
19 TOOLS := apc
20 ##################################################
21 #Emscripten Info
22 ##################################################
23 #Functions to export for JS Module
24 EXPORT_FUNCS := em_main auth_encrypt
25 #Flags to always run on emcc/em++
26 EMFLAGS :=
27
28 #Import the build system setup
29 include .make/build.mk
30
31 #Directories to be constructed
32 DIRS := $(sort $(dir $(APPDEPS) $(APPTARG)))
33
34 #Targets that don't generate a file
35 .PHONY: $(APPNAME) run push dox doc clean scrub all default
36 #Define default rules to point to APPNAME
37 all default: $(APPTARG)
38
39 #Build the executable
40 $(APPNAME) $(APPTARG): $(DIRS) $(APPDEPS)
41 $(APPC) -o $(APPTARG) $(APPFLAGS) $(APPSRC)
42
43 #create directories
44 $(DIRS):
45 @mkdir -p $@
46
47 #run the game after making it
48 run: $(APPNAME)
49 $(APPTARG)
50
51 #push to github after successful compile
52 push: $(APPTARG)
53 @printf '\nEnter a commit message:\n'; \
54 read CMT; \
55 git commit -am "$$CMT"
56 git push
57
58 dox doc:
59 doxygen dox.conf
60
61 #clean up intermediate dependency files and binaries
62 clean:
63 @echo "Cleaning build targets"
64 rm -f $(APPTARG) $(WEBTARG) $(CTARG)
65
66 #Scrub down to minimal distribution
67 scrub: | clean
68
69 ################## DEFAULTS #####################
70 #cancel default %.o behavior for %.d dependency
71 %.o : %.c
72
73 #construct list of make rules for tools
74 ifdef TOOLS
75 TOOLTARGS := $(foreach tool,$(TOOLS),$(tool)/$(tool))
76 .phony: $(TOOLS)
77 $(TOOLS): $(TOOLTARGS)
78
79 T = $(notdir $@)
80 $(TOOLTARGS): $(TOOLOBJ)
81 $($TCC) $($TFLG) $($TSRC:.c=.o) -o $@
82
83 #Put our toolsrc on the ctarg list for generating deps
84 CTARG := $(CTARG) $(TOOLOBJ)
85 endif
86
87 #Generate and evaluate C dependencies
88 $(foreach base,$(basename $(sort $(strip $(CTARG)))),\
89 $(eval $(strip $(base)$(COBJSUF): $(shell $(subst $BASE,$(base),$(CDEPSCOMMAND)))) $(CDEPS)))
90
91 #new default C build rule
92 %.bc %.o: %.c $(CDEPS)
93 $(CC) $(CXXFLAGS) $(CFLAGS) $< -c -o $@
94
95 #construct list of cp rules for each web item
96 ifdef WEBTARG
97 $(WEBTARG): $(subst $(DISTDIR),$(HTSRCDIR),$(WEBTARG))
98 cp -f $(subst $(DISTDIR),$(HTSRCDIR),$@) $@
99 endif
100
101 #force including rules for making each lib if
102 #we have identified any missing libs
103 #(fail if no rule exists)
104 ifdef MISSINGLIBS
105 include $(foreach lib,$(MISSINGLIBS),.make/lib$(lib).mk)
106 endif
107
108 #include rules for making each app
109 ifdef APPTARGS
110 include $(foreach app,$(APPTARGS),.make/app$(app).mk)
111 endif
112