Makefile +Tools
[henge/webcc.git] / src / Makefile
index 4e22f2f..89aba0e 100644 (file)
@@ -8,13 +8,15 @@
 #Executable name, also passed as -DAPPNAME to compiler
 APPNAME   := the_march
 #Directory in which we expect to find main()
-APPSRC    := core
+APPMODULE := core
 #Compiler flags for the final executable
 APPFLAGS  :=
 #Object files statically linked for the executable
 APPOBJ    :=
 #Dependencies which must be built before the executable
 APPDEPS   :=
+#Directories containing independent tools
+TOOLS     := apc
 ##################################################
 #Emscripten Info
 ##################################################
@@ -26,17 +28,20 @@ EMFLAGS      :=
 #Import the build system setup
 include .make/build.mk
 
+#Directories to be constructed
+DIRS := $(sort $(dir $(APPDEPS) $(APPTARG)))
+
 #Targets that don't generate a file
 .PHONY: $(APPNAME) run push dox doc clean scrub all default
 #Define default rules to point to APPNAME
 all default: $(APPTARG)
 
 #Build the executable
-$(APPNAME) $(APPTARG): $(APPDEPS) | $(APPDIRS)
-       $(CC) -o $(APPTARG) $(APPFLAGS) $(APPDEPS)
+$(APPNAME) $(APPTARG): $(DIRS) $(APPDEPS)
+       $(APPC) -o $(APPTARG) $(APPFLAGS) $(APPSRC)
 
 #create directories
-$(APPDIRS):
+$(DIRS):
        @mkdir -p $@
 
 #run the game after making it
@@ -65,9 +70,23 @@ scrub: | clean
 #cancel default %.o behavior for %.d dependency
 %.o : %.c
 
+#construct list of make rules for tools
+ifdef TOOLS
+TOOLTARGS := $(foreach tool,$(TOOLS),$(tool)/$(tool))
+.phony: $(TOOLS)
+$(TOOLS): $(TOOLTARGS)
+
+T = $(notdir $@)
+$(TOOLTARGS): $(TOOLOBJ)
+       $($TCC) $($TFLG) $($TSRC:.c=.o) -o $@
+
+#Put our toolsrc on the ctarg list for generating deps
+CTARG := $(CTARG) $(TOOLOBJ)
+endif
+
 #Generate and evaluate C dependencies
 $(foreach base,$(basename $(sort $(strip $(CTARG)))),\
-       $(eval $(strip $(base)$(COBJSUF): $(shell $(subst $BASE,$(base),$(CGENDEP))))))
+       $(eval $(strip $(base)$(COBJSUF): $(shell $(subst $BASE,$(base),$(CDEPSCOMMAND)))) $(CDEPS)))
 
 #new default C build rule
 %.bc %.o: %.c $(CDEPS)
@@ -75,12 +94,19 @@ $(foreach base,$(basename $(sort $(strip $(CTARG)))),\
 
 #construct list of cp rules for each web item
 ifdef WEBTARG
-$(WEBTARG): $(HTMLDIR)/$(filter-out $(EXEDIR),$@)
-       cp -f $< $@
+$(WEBTARG): $(subst $(DISTDIR),$(HTSRCDIR),$(WEBTARG))
+       cp -f $(subst $(DISTDIR),$(HTSRCDIR),$@) $@
 endif
 
-#force including rules for making each lib in this case
+#force including rules for making each lib if
+#we have identified any missing libs
+#(fail if no rule exists)
 ifdef MISSINGLIBS
 include $(foreach lib,$(MISSINGLIBS),.make/lib$(lib).mk)
 endif
 
+#include rules for making each app
+ifdef APPTARGS
+include $(foreach app,$(APPTARGS),.make/app$(app).mk)
+endif
+