#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)) #Targets that don't generate a file .PHONY: $(APPNAME) run push dox doc clean scrub all default move #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) #Build the executable $(APPNAME): $(APP_RULES) $(CDEP) $(COBJ) @mkdir -p $(EXEPATH) $(CC) -o $(EXEPATH)/$(EXE) $(CXXFLAGS) $(CFLAGS) $(APP_FLAGS) core/main.$(OBJFILE) #run the game after making it run: $(APPNAME) $(EXEPATH)/$(EXE) #push to github after successful compile push: $(APPNAME) @printf '\nEnter a commit message:\n'; \ read CMT; \ git commit -am "$$CMT" git push origin master 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)) #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) ################## 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 $@ #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' >> $@