1 ################################################################################
2 # Desc: Web Cross Compiler
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 # The default rule to be built if none specified
16 # source directory to find compilable language files in
17 SRC_DIR
:= $(ROOT_DIR
)/src
18 # directory where files with 'main' functions live (can be in SRC_DIR)
19 DRIVER_DIR
:= $(SRC_DIR
)/bin
20 # make configuration directory
21 CONF_DIR
:= $(ROOT_DIR
)/make
22 # Source languages handled by this build system. These languages are capable of
23 # being compiled to an intermediary format for binary output by one of the
24 # provided compilersfor each language
26 # Source-to-source languages handled by this build system
28 # Language-specific compilers and flags passed in from environment
29 c_C
:= $(strip $(notdir $(CC
)))
30 c_FLAGS
:= $(strip $(CFLAGS
)) -I
$(SRC_DIR
)
32 cpp_C
:= $(strip $(notdir $(CXX
)))
33 cpp_FLAGS
:= $(strip $(CXXFLAGS
)) $(c_FLAGS
)
35 go_FLAGS
:= $(c_FLAGS
)
36 # Source to source languages
46 # Compiler-specific associations. Each compiler has a binary object suffix
47 # (OBJ), an archiver (AR), and an archiver object suffix (AROBJ). Each compiler
48 # may optionally have defined a linker (LD), and a binary output suffix (OUT).
54 $(cpp_C
)_LD
:= $(cc_LD
)
58 gcc_AROBJ
:= $(cc_AROBJ
)
62 emcc_AROBJ
:= $(emcc_OBJ
) #emar is just a python script that reparses shit for emcc
65 em
++_OBJ
:= $(emcc_OBJ
)
67 em
++_AROBJ
:= $(emcc_AROBJ
)
68 em
++_OUT
:= $(emcc_OUT
)
72 gccgo_AROBJ
:= $(cc_AROBJ
)
73 # Shell functions to determine what libraries can be linked by the compiler
74 cc_LDLIBS
:= $(shell ldconfig
-p | sed
-e
's@\-*[0-9\.]*\.so.*$$@@g' -e
's@\tlib@@g' -e
'/[\t ]/d')
75 gcc_LDLIBS
:= $(cc_LDLIBS
)
77 g
++_LDLIBS
:= $(cc_LDLIBS
)
79 go_LDLIBS
:= $(cc_LDLIBS
)
80 # location to build cross-compilation libraries in, not intended to be installed
82 LIB_DIR
:= $(ROOT_DIR
)/lib
$(shell uname
-m
)/$($(c_C
)_OBJ
)
83 LIBDL_DIR
:= $(LIB_DIR
)/.cache
84 LIBINC_DIR
:= $(ROOT_DIR
)/include
85 # The makefile MUST be capable of generating these directories and all of their
86 # contents. These directories are removed during the 'scrub' rule
87 MAKE_DIRS
:= $(LIB_DIR
) $(LIBDL_DIR
)
88 # Set up lib inclusions, and scan for built libs
89 c_FLAGS
+= -I
$(LIBINC_DIR
)
90 c_OBJ
:= $($(c_C
)_OBJ
)
91 # Modules are any directories other than 'DRIVER_MODULE' in 'SRC_DIR' and
92 # produce a single archive in 'SRC_DIR' containing all of the module's symbols
93 MODULES
:= $(patsubst $(SRC_DIR
)/%/,%,$(filter-out $(DRIVER_DIR
)/%,$(shell ls
-d
$(SRC_DIR
)/*/)))
95 # Include the make libraries
98 # If available, invoke the premake system
99 ifdef PREMAKE_SOURCE_COMPILER
100 $(eval
$(call PREMAKE_SOURCE_COMPILER
,))
102 $(info Warning
: No premake system found
, source-to-source languages
(e.g. bison
) not functional
)
105 # Backup the CVS password and CVSROOT environment vars in case we change them
106 $(if
$(wildcard ~
/.cvspass
),\
107 $(eval CVSPASS_BAK
:= $(file
<~
/.cvspass
)))
109 $(eval CVSROOT_BAK
:= $(CVSROOT
)))
111 # The recursive library dependecy traversal constructs a tree ordered by nested
112 # dependency depth. when linking, this order is reversed.
113 # Initialize each language and look for its files
115 $(foreach lang
,$(LANGS
),\
116 $(eval
$(call LANG_INIT
,$(lang
)))\
119 $(error No LANG_INIT available
, no languages can be compiled
)
122 # Create module object rules for each module
123 $(foreach module
,$(MODULES
),\
124 $(eval
$(call MODULE_ARCRULE
,$(module
)))\
126 $(if
$(c_DBG
),$(eval MAKE_DIRS
+= .
$(c_DBG
)/))
128 # Create lang-specific rules for producing final (linked) targets
129 $(foreach lang
,$(LANGS
),\
130 $(foreach drvsrc
,$($(lang
)_DRV_SRC
),\
131 $(eval
$(call SRC_LANG_DRVRULE
,$(drvsrc
),$(lang
)))\
134 # Create driver rules for each driver we found, let users call make specifying
135 # the basename of the driver file, and just route to the correct e we
136 # made in the last paragraph
137 DRV_FNAMES
:= $(notdir $(DRV_SRC
))
138 .PHONY
: all $(basename $(DRV_NAMES
))
139 $(foreach fname
,$(DRV_FNAMES
),\
140 $(eval
$(basename $(fname
)): \
141 $(filter %/$(basename $(fname
))$($(lastword
$(subst .
, ,$(fname
))_OUT
)),$(DRV_TRG
)))\
143 all: $(basename $(DRV_FNAMES
))
146 # Rule to make any dirs that we're in charge of
147 $(sort $(MAKE_DIRS
)):
151 # Clean destroys all object files and internal module archives.
152 CLEAN_TARGETS
:= $(sort $(foreach mtarg
,$(MAKE_TARGETS
),$(if
$(wildcard $(mtarg
)),$(mtarg
))))
153 clean: $(BUILTLIBS
:%=clean_
%)
154 $(if
$(CLEAN_TARGETS
),rm $(CLEAN_TARGETS
))
156 # Scrub destroys all distributable binaries
157 SCRUB_TARGETS
:= $(sort $(foreach starg
,$(SCRUB_TARGETS
),$(if
$(wildcard $(starg
)),$(starg
))))
159 $(if
$(SCRUB_TARGETS
),rm $(SCRUB_TARGETS
))
161 # Purge destroys all distributables created by a distributable binary
164 # Uninstall destroys all objects and directories that cannot be recreated by