++unistring
[henge/webcc.git] / Makefile
1 ################################################################################
2 # Desc: Web Cross Compiler
3 # Author: ksg
4 # Date: 2016
5 ################################################################################
6 # This makefile manages a build environment targeting native platforms with gcc
7 # and web platforms with either emscripten or binaryen (js or wasm).
8 ################################################################################
9 # Each .c file is automatically compiled into an environment-dependent object
10 # file of compiler-specific format (.o for gcc, .bc for llvm/emcc/em++).
11 ################################################################################
12 # webcc's root
13 ROOT_DIR := .
14 # source directory to find compilable language files in
15 SRC_DIR := $(ROOT_DIR)/src
16 # directory where files with 'main' functions live (can be in SRC_DIR)
17 DRIVER_DIR := $(SRC_DIR)/bin
18 # make configuration directory
19 CONF_DIR := $(ROOT_DIR)/make
20 # include initialization variables
21 include $(CONF_DIR)/init.mk
22 # Include the make libraries
23 include $(CONF_DIR)/lib/*.mk
24
25 # The default rule to be built if none specified
26 default: all
27
28 # If available, invoke the premake system
29 ifdef PREMAKE_SOURCE_COMPILER
30 $(eval $(call PREMAKE_SOURCE_COMPILER,))
31 else
32 $(info No premake system found, source-to-source languages (e.g. ragel) not functional)
33 endif
34
35 # Backup the CVS password and CVSROOT environment vars in case we change them
36 # during lib downloading
37 $(if $(wildcard ~/.cvspass),\
38 $(eval CVSPASS_BAK := $(file <~/.cvspass)))
39 $(if $(CVSROOT),\
40 $(eval CVSROOT_BAK := $(CVSROOT)))
41
42 # Initialize each language, look for its source files, and generate rules
43 ifdef LANG_INIT
44 $(foreach lang,$(LANGS),\
45 $(eval $(call LANG_INIT,$(lang)))\
46 )
47 else
48 $(error No LANG_INIT available, no languages can be compiled)
49 endif
50
51 # Create module object rules for each module
52 $(foreach module,$(MODULES),\
53 $(eval $(call MODULE_ARCRULE,$(module)))\
54 )
55 $(if $(c_DBG),$(eval MAKE_DIRS += .$(c_DBG)/))
56
57 # Create lang-specific rules for producing final (linked) targets
58 $(foreach lang,$(LANGS),\
59 $(foreach drvsrc,$($(lang)_DRV_SRC),\
60 $(eval $(call SRC_LANG_DRVRULE,$(drvsrc),$(lang)))\
61 ))
62
63 # Create driver rules for each driver we found, let users call make specifying
64 # the basename of the driver file, and just route to the correct linking rule
65 $(foreach drvsrc,$(DRV_SRC),\
66 $(eval $(call DRVSRC_DRIVERPHONY,$(drvsrc)))\
67 )
68
69 .PHONY: all
70 all: $(PH_TARGS)
71
72 # Rule to make any dirs that we're in charge of
73 $(sort $(MAKE_DIRS)):
74 @mkdir -p $@
75
76 # Cleaning rules.
77 # Clean destroys all object files and internal module archives.
78 CLEAN_TARGETS := $(sort $(foreach mtarg,$(MAKE_TARGETS),$(if $(wildcard $(mtarg)),$(mtarg))))
79 clean: $(BUILTLIBS:%=clean_%)
80 $(if $(CLEAN_TARGETS),rm $(CLEAN_TARGETS))
81
82 # Scrub destroys all distributable binaries
83 SCRUB_TARGETS := $(sort $(foreach starg,$(SCRUB_TARGETS),$(if $(wildcard $(starg)),$(starg))))
84 scrub: clean
85 $(if $(SCRUB_TARGETS),rm $(SCRUB_TARGETS))
86
87 # Purge destroys all distributables created by a distributable binary
88 # (e.g. assets)
89
90 # Uninstall destroys all objects and directories that can be recreated by this
91 # make file
92 uninstall: scrub
93 rm -Rf $(MAKE_DIRS)