################################################################################ # Desc: Web Cross Compiler # Author: ksg # Date: 2016 ################################################################################ # This makefile manages a build environment targeting native platforms with gcc # and web platforms with either emscripten or binaryen (js or wasm). ################################################################################ # Each .c file is automatically compiled into an environment-dependent object # file of compiler-specific format (.o for gcc, .bc for llvm/emcc/em++). ################################################################################ # webcc's root ROOT_DIR := . # source directory to find compilable language files in SRC_DIR := $(ROOT_DIR)/src # directory where files with 'main' functions live (can be in SRC_DIR) DRIVER_DIR := $(SRC_DIR)/bin # make configuration directory CONF_DIR := $(ROOT_DIR)/make # include initialization variables include $(CONF_DIR)/init.mk # Include the make libraries include $(CONF_DIR)/lib/*.mk # The default rule to be built if none specified default: all # If available, invoke the premake system ifdef PREMAKE_SOURCE_COMPILER $(eval $(call PREMAKE_SOURCE_COMPILER,)) else $(info No premake system found, source-to-source languages (e.g. ragel) not functional) endif # Backup the CVS password and CVSROOT environment vars in case we change them # during lib downloading $(if $(wildcard ~/.cvspass),\ $(eval CVSPASS_BAK := $(file <~/.cvspass))) $(if $(CVSROOT),\ $(eval CVSROOT_BAK := $(CVSROOT))) # Initialize each language, look for its source files, and generate rules ifdef LANG_INIT $(foreach lang,$(LANGS),\ $(eval $(call LANG_INIT,$(lang)))\ ) else $(error No LANG_INIT available, no languages can be compiled) endif # Create module object rules for each module $(foreach module,$(MODULES),\ $(eval $(call MODULE_ARCRULE,$(module)))\ ) $(if $(c_DBG),$(eval MAKE_DIRS += .$(c_DBG)/)) # Create lang-specific rules for producing final (linked) targets $(foreach lang,$(LANGS),\ $(foreach drvsrc,$($(lang)_DRV_SRC),\ $(eval $(call SRC_LANG_DRVRULE,$(drvsrc),$(lang)))\ )) # Create driver rules for each driver we found, let users call make specifying # the basename of the driver file, and just route to the correct linking rule $(foreach drvsrc,$(DRV_SRC),\ $(eval $(call DRVSRC_DRIVERPHONY,$(drvsrc)))\ ) .PHONY: all all: $(PH_TARGS) # Rule to make any dirs that we're in charge of $(sort $(MAKE_DIRS)): @mkdir -p $@ # Cleaning rules. # Clean destroys all object files and internal module archives. CLEAN_TARGETS := $(sort $(foreach mtarg,$(MAKE_TARGETS),$(if $(wildcard $(mtarg)),$(mtarg)))) clean: $(BUILTLIBS:%=clean_%) $(if $(CLEAN_TARGETS),rm $(CLEAN_TARGETS)) # Scrub destroys all distributable binaries SCRUB_TARGETS := $(sort $(foreach starg,$(SCRUB_TARGETS),$(if $(wildcard $(starg)),$(starg)))) scrub: clean $(if $(SCRUB_TARGETS),rm $(SCRUB_TARGETS)) # Purge destroys all distributables created by a distributable binary # (e.g. assets) # Uninstall destroys all objects and directories that can be recreated by this # make file uninstall: scrub rm -Rf $(MAKE_DIRS)