Build System =Tool Compiler Fix
[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 ################## DEFAULTS #####################
62 #cancel default %.o behavior for %.d dependency
63 %.o : %.c
64
65 #construct list of make rules for tools
66 ifdef TOOLS
67 TOOLTRG := $(foreach tool,$(TOOLS),$(tool)/$(tool))
68 .phony: $(TOOLS)
69 $(TOOLS): $(TOOLTRG)
70
71 T = $(notdir $@)
72 D = $(dir $@)
73 B = $(basename $D)
74 $(TOOLTRG): $(TOOLOBJ)
75 $($TCC) $($TFLG) $($TSRC:.c=.o) -o $@
76
77 #Tools only work on whatever system they're designed for
78 #(typically GNU), so their creation rules are dependent
79 #on each tool (define in .make/.buildtools.mk)
80 $(foreach tool,$(TOOLS),$(tool)/%.o): $(dir $@)%.c
81 $($BCC) $(BFLG) $< -c -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
113 #clean up intermediate dependency files and binaries
114 clean:
115 @echo "Cleaning build targets"
116 rm -f $(APPTARG) $(WEBTARG) $(CTARG)
117
118 #Scrub down to minimal distribution
119 scrub: | clean
120