-#Mihrtec Standard Makefile
-#Author: ksg
-
-#Project Info
-APPNAME := the_march
-MODULES := core
-CFLAGS := -Wall
-
-#Additional deps and flags for the final executable file
-APP_FLAGS :=
-APP_RULES :=
-
-#Extra cleanup rules
-CLEAN_RULES :=
-SCRUB_RULES :=
-
-
-ifdef EMSCRIPTEN_TOOLS
-#Emscripten build environment
-APP_RULES += move
-HTML := index.html js/the_march.config.js js/auth.js
-EXPORTS := '_em_main', 'auth_encrypt'
-CC := emcc
-EMFLAGS := -I../extern/include
-EMFLAGS += -s USE_SDL=2 -s USE_SDL_TTF=2 -s USE_SDL_IMAGE=2 -s SDL2_IMAGE_FORMATS='["png"]'
-APP_FLAGS += --separate-asm -s ALLOW_MEMORY_GROWTH=1 -s FORCE_FILESYSTEM=1 --pre-js html/js/pre.js
-APP_FLAGS += -s EXPORTED_FUNCTIONS="[$(EXPORTS)]"
-EXEPATH := ../dist/bin/jasm/js
-EXE := $(APPNAME).js
-OBJFILE :=bc
-EMFLAGS += -I/usr/include/google -I../extern/include
-BYPRODUCT := $(APPNAME).asm.js $(APPNAME).js.mem
-APP_FLAGS += $(EMFLAGS) ../extern/lib/libwolfssl.so
-else
-#Native Build Environment
-CC := gcc
-CFLAGS +=
-#LIBS := -lprotobuf-c
-LIBS += SDL2_ttf SDL2_image SDL2main SDL2
-EXEPATH := ../dist/bin/$(shell uname -m)
-#windows mingw build rules
-ifeq ($(OS), Windows_NT)
-LIBS := -lmingw32 -mwindows $(LIBS)
-EXE := $(APPNAME).exe
-else
-EXE := $(APPNAME)
-endif
-OBJFILE :=o
-endif
-
-#-I each of the module directories, include directory, and define APPNAME.
-CFLAGS += $(patsubst %,-I%, $(MODULES))
-CFLAGS += -Iinclude -I.
-CFLAGS += -DAPPNAME=$(APPNAME)
-
-#auto include all .c files
-SRC += $(patsubst %,%/*.c,$(MODULES))
-SRC := $(wildcard $(SRC))
+##################################################
+#Desc: Mihrtec Standard Makefile
+#Author: Mihrtec LLC
+#Date: 2016
+##################################################
+#Application Information
+##################################################
+#Executable name, also passed as -DAPPNAME to compiler
+APPNAME := the_march
+#Directory in which we expect to find main()
+APPSRC := 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 :=
+##################################################
+#Emscripten Info
+##################################################
+#Functions to export for JS Module
+EXPORT_FUNCS := em_main auth_encrypt
+#Flags to always run on emcc/em++
+EMFLAGS :=
+
+#Import the build system setup
+include .make/build.mk
#Targets that don't generate a file
-.PHONY: $(APPNAME) run push dox doc clean scrub all default move
+.PHONY: $(APPNAME) run push dox doc clean scrub all default
#Define default rules to point to APPNAME
-all default: clean $(APPNAME)
-
-#include rules from any .mk file found in a module directory
-include $(wildcard $(patsubst %,%/*.mk,$(MODULES)))
-
-CFLAGS += $(patsubst %,-l% ,$(LIBS))
-
-#populate C objects and dependency files to generate from SRC
-COBJ += $(patsubst %.c,%.$(OBJFILE), $(filter %.c,$(SRC)))
-CDEP += $(COBJ:.$(OBJFILE)=.d)
-
-include $(CDEP)
+all default: $(APPTARG)
#Build the executable
-$(APPNAME): $(APP_RULES) $(CDEP) $(COBJ)
- @mkdir -p $(EXEPATH)
- $(CC) -o $(EXEPATH)/$(EXE) $(CXXFLAGS) $(CFLAGS) $(APP_FLAGS) core/main.$(OBJFILE)
+$(APPNAME) $(APPTARG): $(APPDEPS) | $(APPDIRS)
+ $(CC) -o $(APPTARG) $(APPFLAGS) $(APPDEPS)
+
+#create directories
+$(APPDIRS):
+ @mkdir -p $@
#run the game after making it
run: $(APPNAME)
- $(EXEPATH)/$(EXE)
+ $(APPTARG)
#push to github after successful compile
-push: $(APPNAME)
+push: $(APPTARG)
@printf '\nEnter a commit message:\n'; \
read CMT; \
git commit -am "$$CMT"
- git push origin master
+ git push
dox doc:
doxygen dox.conf
#clean up intermediate dependency files and binaries
-clean: $(CLEAN_RULES)
- @echo "Cleaning .d (deps) and .$(OBJFILE) (obj)"
- @rm -f $(EXEPATH)/$(EXE) $(patsubst %,$(EXEPATH)/%, $(BYPRODUCT))
- @rm -f $(patsubst %,%/*.$(OBJFILE), $(MODULES))
- @rm -f $(patsubst %,%/*.d, $(MODULES))
+clean:
+ @echo "Cleaning build targets"
+ rm -f $(APPTARG) $(WEBTARG) $(CTARG)
#Scrub down to minimal distribution
-scrub: clean $(SCRUB_RULES)
-
-#construct list of move rules for each HTML item
-.PHONY: $(HTML)
-$(HTML):
- @mkdir -p ../dist/bin/jasm/js
- @cp -f html/$@ ../dist/bin/jasm/$@
-#move js/html files
-move: $(HTML)
+scrub: | clean
################## DEFAULTS #####################
#cancel default %.o behavior for %.d dependency
%.o : %.c
-#new default .o for .c files
-%.bc %.o: %.c %.d
- $(CC) -c $(EMFLAGS) $(CPPFLAGS) $(CFLAGS) $< -o $@
+#Generate and evaluate C dependencies
+$(foreach base,$(basename $(sort $(strip $(CTARG)))),\
+ $(eval $(strip $(base)$(COBJSUF): $(shell $(subst $BASE,$(base),$(CGENDEP))))))
-#default for .d dependency files (output from gcc -M)
-%.d: %.c
- @./deps.sh 'dirname $*.c' $(CFLAGS) $*.c > $@
- @sed -i 's/$(*F)[\.]o/$(@D)\/$(*F)\.o/g' $@
- @cat $@ | sed 's/[\.][o]/.bc/g' >> $@
+#new default C build rule
+%.bc %.o: %.c $(CDEPS)
+ $(CC) $(CXXFLAGS) $(CFLAGS) $< -c -o $@
+
+#construct list of cp rules for each web item
+ifdef WEBTARG
+$(WEBTARG): $(HTMLDIR)/$(filter-out $(EXEDIR),$@)
+ cp -f $< $@
+endif
+
+#force including rules for making each lib in this case
+ifdef MISSINGLIBS
+include $(foreach lib,$(MISSINGLIBS),.make/lib$(lib).mk)
+endif