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
)
31 c_LIBS
:= SDL2 wolfssl unistring
33 cpp_C
:= $(strip $(notdir $(CXX
)))
34 cpp_FLAGS
:= $(strip $(CXXFLAGS
)) $(c_FLAGS
)
37 go_FLAGS
:= $(c_FLAGS
)
38 # Source to source languages
48 # Compiler-specific associations. Each compiler has a binary object suffix
49 # (OBJ), an archiver (AR), and an archiver object suffix (AROBJ). Each compiler
50 # may optionally have defined a linker (LD), and a binary output suffix (OUT).
56 $(cpp_C
)_LD
:= $(cc_LD
)
60 gcc_AROBJ
:= $(cc_AROBJ
)
64 emcc_AROBJ
:= $(emcc_OBJ
) #emar is just a python script that reparses shit for emcc
67 em
++_OBJ
:= $(emcc_OBJ
)
69 em
++_AROBJ
:= $(emcc_AROBJ
)
70 em
++_OUT
:= $(emcc_OUT
)
74 gccgo_AROBJ
:= $(cc_AROBJ
)
75 # Shell functions to determine what libraries can be linked by the compiler
76 cc_LDLIBS
:= $(shell ls
/usr
/lib | grep
".o" | sed
-e
's@^.*lib\([_\+a-zA-Z0-9\-]*\)\..*@\1@g')
77 gcc_LDLIBS
:= $(cc_LDLIBS
)
79 g
++_LDLIBS
:= $(cc_LDLIBS
)
81 go_LDLIBS
:= $(cc_LDLIBS
)
82 # location to build cross-compilation libraries in, not intended to be installed
84 LIB_DIR
:= $(ROOT_DIR
)/lib
$(shell uname
-m
)/$($(c_C
)_OBJ
)
85 LIBDL_DIR
:= $(LIB_DIR
)/.cache
86 LIBINC_DIR
:= $(ROOT_DIR
)/include
87 # The makefile MUST be capable of generating these directories and all of their
88 # contents. These directories are removed during the 'scrub' rule
89 MAKE_DIRS
:= $(LIB_DIR
) $(LIBDL_DIR
)
90 # Set up lib inclusions, and scan for built libs
91 c_FLAGS
+= -I
$(LIBINC_DIR
)
92 c_OBJ
:= $($(c_C
)_OBJ
)
93 # Modules are any directories other than 'DRIVER_MODULE' in 'SRC_DIR' and
94 # produce a single archive in 'SRC_DIR' containing all of the module's symbols
95 MODULES
:= $(patsubst $(SRC_DIR
)/%/,%,$(filter-out $(DRIVER_DIR
)/%,$(shell ls
-d
$(SRC_DIR
)/*/)))
97 # Include the make libraries
100 # If available, invoke the premake system
101 ifdef PREMAKE_SOURCE_COMPILER
102 $(eval
$(call PREMAKE_SOURCE_COMPILER
,))
104 $(info Warning
: No premake system found
, source-to-source languages
(e.g. bison
) not functional
)
107 # Backup the CVS password and CVSROOT environment vars in case we change them
108 $(if
$(wildcard ~
/.cvspass
),\
109 $(eval CVSPASS_BAK
:= $(file
<~
/.cvspass
)))
111 $(eval CVSROOT_BAK
:= $(CVSROOT
)))
113 # The recursive library dependecy traversal constructs a tree ordered by nested
114 # dependency depth. when linking, this order is reversed.
115 # Initialize each language and look for its files
117 $(foreach lang
,$(LANGS
),\
118 $(eval
$(call LANG_INIT
,$(lang
)))\
119 $(eval
$(lang
)_LIBS
:= $(shell echo
$($(lang
)_LIBS |
$(call AWK_REVERSE_SQUASH
))))\
122 $(error No LANG_INIT available
, no languages can be compiled
)
125 # Create module object rules for each module
126 $(foreach module
,$(MODULES
),\
127 $(eval
$(call MODULE_ARCRULE
,$(module
)))\
129 $(if
$(c_DBG
),$(eval MAKE_DIRS
+= .
$(c_DBG
)/))
131 # Create lang-specific rules for producing final (linked) targets
132 $(foreach lang
,$(LANGS
),\
133 $(foreach drvsrc
,$($(lang
)_DRV_SRC
),\
134 $(eval
$(call SRC_LANG_DRVRULE
,$(drvsrc
),$(lang
)))\
137 # Create driver rules for each driver we found, let users call make specifying
138 # the basename of the driver file, and just route to the correct e we
139 # made in the last paragraph
140 DRV_FNAMES
:= $(notdir $(DRV_SRC
))
141 .PHONY
: all $(basename $(DRV_NAMES
))
142 $(foreach fname
,$(DRV_FNAMES
),\
143 $(eval
$(basename $(fname
)): \
144 $(filter %/$(basename $(fname
))$($(lastword
$(subst .
, ,$(fname
))_OUT
)),$(DRV_TRG
)))\
146 all: $(basename $(DRV_FNAMES
))
149 # Rule to make any dirs that we're in charge of
150 $(sort $(MAKE_DIRS
)):
154 # Clean destroys all object files and internal module archives.
155 CLEAN_TARGETS
:= $(sort $(foreach mtarg
,$(MAKE_TARGETS
),$(if
$(wildcard $(mtarg
)),$(mtarg
))))
156 clean: $(BUILTLIBS
:%=clean_
%)
157 $(if
$(CLEAN_TARGETS
),rm $(CLEAN_TARGETS
))
159 # Scrub destroys all distributable binaries
160 SCRUB_TARGETS
:= $(sort $(foreach starg
,$(SCRUB_TARGETS
),$(if
$(wildcard $(starg
)),$(starg
))))
162 $(if
$(SCRUB_TARGETS
),rm $(SCRUB_TARGETS
))
164 # Purge destroys all distributables created by a distributable binary
167 # Uninstall destroys all objects and directories that cannot be recreated by