Build System +Tool specific compilers and targets
[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 for GNU
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 B = $(basename $T)
81 $(TOOLTARGS): $(TOOLOBJ)
82 $($TCC) $($TFLG) $($TSRC:.c=.o) -o $@
83
84 #Tools only work on whatever system they're designed for
85 #(typically GNU), so their creation rules are dependent
86 #on each tool (define in .make/.buildtools.mk)
87 $(foreach tool,$(TOOLS),$(tool)/%.o): %.c
88 $($BCC) $(BFLG) $< -c -o $@
89
90 #Put our toolsrc on the ctarg list for generating deps
91 CTARG := $(CTARG) $(TOOLOBJ)
92 endif
93
94 #Generate and evaluate C dependencies
95 $(foreach base,$(basename $(sort $(strip $(CTARG)))),\
96 $(eval $(strip $(base)$(COBJSUF): $(shell $(subst $BASE,$(base),$(CDEPSCOMMAND)))) $(CDEPS)))
97
98 #new default C build rule
99 %.bc %.o: %.c $(CDEPS)
100 $(CC) $(CXXFLAGS) $(CFLAGS) $< -c -o $@
101
102 #construct list of cp rules for each web item
103 ifdef WEBTARG
104 $(WEBTARG): $(subst $(DISTDIR),$(HTSRCDIR),$(WEBTARG))
105 cp -f $(subst $(DISTDIR),$(HTSRCDIR),$@) $@
106 endif
107
108 #force including rules for making each lib if
109 #we have identified any missing libs
110 #(fail if no rule exists)
111 ifdef MISSINGLIBS
112 include $(foreach lib,$(MISSINGLIBS),.make/lib$(lib).mk)
113 endif
114
115 #include rules for making each app
116 ifdef APPTARGS
117 include $(foreach app,$(APPTARGS),.make/app$(app).mk)
118 endif
119