4f460576badb628929a77ab8f3045a8d2d5b582d
[henge/webcc.git] / make / init.mk
1 ################################################################################
2 # Desc: Environment initialization for webcc
3 # Author: ksg
4 # Date: 2016
5 ################################################################################
6 # This file reads default Make vars and environment vars to produce a standard
7 # set of variables to compile with
8 ################################################################################
9 # Source languages handled by this build system. These languages are capable of
10 # being compiled to an intermediary format for binary output by one of the
11 # provided compilers for each language
12 LANGS := c cpp go
13 # Language-specific compilers and flags passed in from environment
14 c_C := $(strip $(notdir $(CC)))
15 c_FLAGS := $(strip $(CFLAGS)) -I$(SRC_DIR)
16 c_SRCL := y
17 cpp_C := $(strip $(notdir $(CXX)))
18 cpp_FLAGS := $(strip $(CXXFLAGS)) $(c_FLAGS)
19 go_C := gccgo
20 go_FLAGS := $(c_FLAGS)
21 # Source-to-source languages handled by this build system
22 SLANGS := y rl
23 # Yacc
24 y_C := bison
25 y_FLAGS := -d
26 y_TRG := c h
27 y_STEM := tab
28 # Ragel
29 rl_C := ragel
30 rl_FLAGS := -C
31 rl_TRG := c
32 rl_STEM := fsm
33 # Compiler-specific associations. Each compiler has a binary object suffix
34 # (OBJ), an archiver (AR), and an archiver object suffix (AROBJ). Each compiler
35 # may optionally have defined a linker (LD), and a binary output suffix (OUT).
36 cc_OBJ := o
37 cc_LD := $(LD)
38 cc_AR := $(AR)
39 cc_AROBJ := a
40 cc_DBG := gdb
41 $(cpp_C)_LD := $(cc_LD)
42 gcc_OBJ := $(cc_OBJ)
43 gcc_LD := $(cc_LD)
44 ngcc_AR := $(cc_AR)
45 gcc_AROBJ := $(cc_AROBJ)
46 gcc_DBG := $(cc_DBG)
47 emcc_OBJ := bc
48 emcc_AR := emar
49 emcc_AROBJ := $(emcc_OBJ) #emar is just a python script that reparses shit for emcc
50 emcc_OUT := .js
51 g++_OBJ := $(cc_OBJ)
52 em++_OBJ := $(emcc_OBJ)
53 em++_AR := $(emcc_AR)
54 em++_AROBJ := $(emcc_AROBJ)
55 em++_OUT := $(emcc_OUT)
56 gccgo_OBJ := o
57 gccgo_LD := $(cc_LD)
58 gccgo_AR := $(cc_AR)
59 gccgo_AROBJ := $(cc_AROBJ)
60 # Shell functions to determine what libraries can be linked by the compiler
61 cc_LDLIBS := $(shell ldconfig -p | sed -e 's@\-*[0-9\.]*\.so.*$$@@g' -e 's@\tlib@@g' -e '/[\t ]/d')
62 gcc_LDLIBS := $(cc_LDLIBS)
63 emcc_LDLIBS :=
64 g++_LDLIBS := $(cc_LDLIBS)
65 em++_LDLIBS :=
66 go_LDLIBS := $(cc_LDLIBS)
67 # location to build cross-compilation libraries in, not intended to be installed
68 # in the host system
69 LIB_DIR := $(ROOT_DIR)/lib$(shell uname -m)/$($(c_C)_OBJ)
70 LIBDL_DIR := $(LIB_DIR)/.cache
71 LIBINC_DIR := $(ROOT_DIR)/include
72 # The makefile MUST be capable of generating these directories and all of their
73 # contents. These directories are removed during the 'scrub' rule
74 MAKE_DIRS := $(LIB_DIR) $(LIBDL_DIR)
75 # Set up lib inclusions, and scan for built libs
76 c_FLAGS += -I$(LIBINC_DIR)
77 c_OBJ := $($(c_C)_OBJ)
78 # Modules are any directories other than 'DRIVER_MODULE' in 'SRC_DIR' and
79 # produce a single archive in 'SRC_DIR' containing all of the module's symbols
80 MODULES := $(patsubst $(SRC_DIR)/%/,%,$(filter-out $(DRIVER_DIR)/%,$(shell ls -d $(SRC_DIR)/*/)))