PageRenderTime 29ms CodeModel.GetById 2ms app.highlight 22ms RepoModel.GetById 1ms app.codeStats 0ms

/mk/platform.mk

http://github.com/jruderman/rust
Makefile | 285 lines | 231 code | 27 blank | 27 comment | 1 complexity | 32f17aa7ed83d54e411c6502ded6dd9f MD5 | raw file
  1
  2# Create variables HOST_<triple> containing the host part
  3# of each target triple.  For example, the triple i686-darwin-macos
  4# would create a variable HOST_i686-darwin-macos with the value 
  5# i386.
  6define DEF_HOST_VAR
  7  HOST_$(1) = $(subst i686,i386,$(word 1,$(subst -, ,$(1))))
  8endef
  9$(foreach t,$(CFG_TARGET_TRIPLES),$(eval $(call DEF_HOST_VAR,$(t))))
 10$(foreach t,$(CFG_TARGET_TRIPLES),$(info cfg: host for $(t) is $(HOST_$(t))))
 11
 12# FIXME: no-omit-frame-pointer is just so that task_start_wrapper
 13# has a frame pointer and the stack walker can understand it. Turning off
 14# frame pointers everywhere is overkill
 15CFG_GCCISH_CFLAGS += -fno-omit-frame-pointer
 16
 17# On Darwin, we need to run dsymutil so the debugging information ends
 18# up in the right place.  On other platforms, it automatically gets
 19# embedded into the executable, so use a no-op command.
 20CFG_DSYMUTIL := true
 21
 22ifneq ($(findstring freebsd,$(CFG_OSTYPE)),)
 23  CFG_LIB_NAME=lib$(1).so
 24  CFG_LIB_GLOB=lib$(1)-*.so
 25  CFG_GCCISH_CFLAGS += -fPIC -I/usr/local/include
 26  CFG_GCCISH_LINK_FLAGS += -shared -fPIC -lpthread -lrt
 27  CFG_GCCISH_DEF_FLAG := -Wl,--export-dynamic,--dynamic-list=
 28  CFG_GCCISH_PRE_LIB_FLAGS := -Wl,-whole-archive
 29  CFG_GCCISH_POST_LIB_FLAGS := -Wl,-no-whole-archive
 30  CFG_GCCISH_CFLAGS_i386 += -m32
 31  CFG_GCCISH_LINK_FLAGS_i386 += -m32
 32  CFG_GCCISH_CFLAGS_x86_64 += -m64
 33  CFG_GCCISH_LINK_FLAGS_x86_64 += -m64
 34  CFG_UNIXY := 1
 35  CFG_LDENV := LD_LIBRARY_PATH
 36  CFG_DEF_SUFFIX := .bsd.def
 37  CFG_INSTALL_NAME =
 38  CFG_PERF_TOOL := /usr/bin/time
 39endif
 40
 41ifneq ($(findstring linux,$(CFG_OSTYPE)),)
 42  CFG_LIB_NAME=lib$(1).so
 43  CFG_LIB_GLOB=lib$(1)-*.so
 44  CFG_GCCISH_CFLAGS += -fPIC
 45  CFG_GCCISH_LINK_FLAGS += -shared -fPIC -ldl -lpthread -lrt
 46  CFG_GCCISH_DEF_FLAG := -Wl,--export-dynamic,--dynamic-list=
 47  CFG_GCCISH_PRE_LIB_FLAGS := -Wl,-whole-archive
 48  # -znoexecstack is here because librt is for some reason being created
 49  # with executable stack and Fedora (or SELinux) doesn't like that (#798)
 50  CFG_GCCISH_POST_LIB_FLAGS := -Wl,-no-whole-archive -Wl,-znoexecstack
 51  CFG_GCCISH_CFLAGS_i386 = -m32
 52  CFG_GCCISH_LINK_FLAGS_i386 = -m32
 53  CFG_GCCISH_CFLAGS_x86_64 = -m64
 54  CFG_GCCISH_LINK_FLAGS_x86_64 = -m64
 55  CFG_UNIXY := 1
 56  CFG_LDENV := LD_LIBRARY_PATH
 57  CFG_DEF_SUFFIX := .linux.def
 58  ifdef CFG_PERF
 59    ifneq ($(CFG_PERF_WITH_LOGFD),)
 60        CFG_PERF_TOOL := $(CFG_PERF) stat -r 3 --log-fd 2
 61    else
 62        CFG_PERF_TOOL := $(CFG_PERF) stat -r 3
 63    endif
 64  else
 65    ifdef CFG_VALGRIND
 66      CFG_PERF_TOOL :=\
 67        $(CFG_VALGRIND) --tool=cachegrind --cache-sim=yes --branch-sim=yes
 68    else
 69      CFG_PERF_TOOL := /usr/bin/time --verbose
 70    endif
 71  endif
 72  CFG_INSTALL_NAME =
 73  # Linux requires LLVM to be built like this to get backtraces into Rust code
 74  CFG_LLVM_BUILD_ENV="CXXFLAGS=-fno-omit-frame-pointer"
 75endif
 76
 77ifneq ($(findstring darwin,$(CFG_OSTYPE)),)
 78  CFG_LIB_NAME=lib$(1).dylib
 79  CFG_LIB_GLOB=lib$(1)-*.dylib
 80  CFG_LIB_DSYM_GLOB=lib$(1)-*.dylib.dSYM
 81  CFG_UNIXY := 1
 82  CFG_LDENV := DYLD_LIBRARY_PATH
 83  CFG_GCCISH_LINK_FLAGS += -dynamiclib -lpthread -framework CoreServices -Wl,-no_compact_unwind
 84  CFG_GCCISH_DEF_FLAG := -Wl,-exported_symbols_list,
 85  # Darwin has a very blurry notion of "64 bit", and claims it's running
 86  # "on an i386" when the whole userspace is 64-bit and the compiler
 87  # emits 64-bit binaries by default. So we just force -m32 here. Smarter
 88  # approaches welcome!
 89  #
 90  # NB: Currently GCC's optimizer breaks rustrt (task-comm-1 hangs) on Darwin.
 91  CFG_GCCISH_CFLAGS_i386 := -m32 -arch i386
 92  CFG_GCCISH_CFLAGS_x86_64 := -m64 -arch x86_64
 93  CFG_GCCISH_LINK_FLAGS_i386 := -m32
 94  CFG_GCCISH_LINK_FLAGS_x86_64 := -m64
 95  CFG_DSYMUTIL := dsymutil
 96  CFG_DEF_SUFFIX := .darwin.def
 97  # Mac requires this flag to make rpath work
 98  CFG_INSTALL_NAME = -Wl,-install_name,@rpath/$(1)
 99endif
100
101# Hack: not sure how to test if a file exists in make other than this
102OS_SUPP = $(patsubst %,--suppressions=%,\
103	    $(wildcard $(CFG_SRC_DIR)src/etc/$(CFG_OSTYPE).supp*))
104
105ifneq ($(findstring mingw,$(CFG_OSTYPE)),)
106  CFG_WINDOWSY := 1
107endif
108
109ifdef CFG_DISABLE_OPTIMIZE_CXX
110  $(info cfg: disabling C++ optimization (CFG_DISABLE_OPTIMIZE_CXX))
111  CFG_GCCISH_CFLAGS += -O0
112else
113  CFG_GCCISH_CFLAGS += -O2
114endif
115
116CFG_TESTLIB=$(CFG_BUILD_DIR)/$(2)/$(strip \
117 $(if $(findstring stage0,$(1)), \
118       stage0/$(CFG_LIBDIR), \
119      $(if $(findstring stage1,$(1)), \
120           stage1/$(CFG_LIBDIR), \
121          $(if $(findstring stage2,$(1)), \
122               stage2/$(CFG_LIBDIR), \
123               $(if $(findstring stage3,$(1)), \
124                    stage3/$(CFG_LIBDIR), \
125               )))))/rustc/$(CFG_HOST_TRIPLE)/$(CFG_LIBDIR)
126
127ifdef CFG_UNIXY
128  CFG_INFO := $(info cfg: unix-y environment)
129
130  CFG_PATH_MUNGE := true
131  CFG_EXE_SUFFIX :=
132  CFG_LDPATH :=
133  CFG_RUN=$(2)
134  CFG_RUN_TARG=$(call CFG_RUN,,$(2))
135  CFG_RUN_TEST=$(call CFG_RUN,,$(CFG_VALGRIND) $(1))
136  CFG_LIBUV_LINK_FLAGS=-lpthread
137
138  ifdef CFG_ENABLE_MINGW_CROSS
139    CFG_WINDOWSY := 1
140    CFG_INFO := $(info cfg: mingw-cross)
141    CFG_GCCISH_CROSS := i586-mingw32msvc-
142    ifdef CFG_VALGRIND
143      CFG_VALGRIND += wine
144    endif
145
146    CFG_GCCISH_CFLAGS := -march=i586
147    CFG_GCCISH_PRE_LIB_FLAGS :=
148    CFG_GCCISH_POST_LIB_FLAGS :=
149    CFG_GCCISH_DEF_FLAG :=
150    CFG_GCCISH_LINK_FLAGS := -shared
151
152    ifeq ($(CFG_CPUTYPE), x86_64)
153      CFG_GCCISH_CFLAGS += -m32
154      CFG_GCCISH_LINK_FLAGS += -m32
155    endif
156  endif
157  ifdef CFG_VALGRIND
158    CFG_VALGRIND += --error-exitcode=100 \
159                    --quiet \
160                    --suppressions=$(CFG_SRC_DIR)src/etc/x86.supp \
161                    $(OS_SUPP)
162    ifdef CFG_ENABLE_HELGRIND
163      CFG_VALGRIND += --tool=helgrind
164    else
165      CFG_VALGRIND += --tool=memcheck \
166                      --leak-check=full
167    endif
168  endif
169endif
170
171
172ifdef CFG_WINDOWSY
173  CFG_INFO := $(info cfg: windows-y environment)
174
175  CFG_EXE_SUFFIX := .exe
176  CFG_LIB_NAME=$(1).dll
177  CFG_LIB_GLOB=$(1)-*.dll
178  CFG_DEF_SUFFIX := .def
179ifdef MSYSTEM
180  CFG_LDPATH :=$(CFG_LDPATH):$$PATH
181  CFG_RUN=PATH="$(CFG_LDPATH):$(1)" $(2)
182else
183  CFG_LDPATH :=
184  CFG_RUN=$(2)
185endif
186  CFG_RUN_TARG=$(call CFG_RUN,$(HLIB$(1)_H_$(CFG_HOST_TRIPLE)),$(2))
187  CFG_RUN_TEST=$(call CFG_RUN,$(call CFG_TESTLIB,$(1),$(3)),$(1))
188  CFG_LIBUV_LINK_FLAGS=-lWs2_32
189
190  ifndef CFG_ENABLE_MINGW_CROSS
191    CFG_PATH_MUNGE := $(strip perl -i.bak -p             \
192                             -e 's@\\(\S)@/\1@go;'       \
193                             -e 's@^/([a-zA-Z])/@\1:/@o;')
194    CFG_GCCISH_CFLAGS += -march=i686
195    CFG_GCCISH_LINK_FLAGS += -shared -fPIC
196  endif
197  CFG_INSTALL_NAME =
198endif
199
200
201CFG_INFO := $(info cfg: using $(CFG_C_COMPILER))
202ifeq ($(CFG_C_COMPILER),clang)
203  ifeq ($(origin CC),default)
204    CC=clang
205  endif
206  ifeq ($(origin CXX),default)
207    CXX=clang++
208  endif
209  ifeq ($(origin CPP),default)
210    CPP=clang -E
211  endif
212  CFG_GCCISH_CFLAGS += -Wall -Werror -fno-rtti -g
213  CFG_GCCISH_LINK_FLAGS += -g
214  # These flags will cause the compiler to produce a .d file
215  # next to the .o file that lists header deps.
216  CFG_DEPEND_FLAGS = -MMD -MP -MT $(1) -MF $(1:%.o=%.d)
217
218  define CFG_MAKE_CC
219	CFG_COMPILE_C_$(1) = $$(CFG_GCCISH_CROSS)$$(CXX)	\
220		$$(CFG_GCCISH_CFLAGS) $$(CFG_CLANG_CFLAGS)		\
221		$$(CFG_GCCISH_CFLAGS_$$(HOST_$(1)))				\
222	    $$(CFG_CLANG_CFLAGS_$$(HOST_$(1)))				\
223        $$(CFG_DEPEND_FLAGS)                            \
224		-c -o $$(1) $$(2)
225    CFG_LINK_C_$(1) = $$(CFG_GCCISH_CROSS)$$(CXX)	\
226		$$(CFG_GCCISH_LINK_FLAGS) -o $$(1)			\
227		$$(CFG_GCCISH_LINK_FLAGS_$$(HOST_$(1)))		\
228        $$(CFG_GCCISH_DEF_FLAG)$$(3) $$(2)			\
229	    $$(call CFG_INSTALL_NAME,$$(4))
230  endef
231
232  $(foreach target,$(CFG_TARGET_TRIPLES), \
233    $(eval $(call CFG_MAKE_CC,$(target))))
234else
235ifeq ($(CFG_C_COMPILER),gcc)
236  ifeq ($(origin CC),default)
237    CC=gcc
238  endif
239  ifeq ($(origin CXX),default)
240    CXX=g++
241  endif
242  ifeq ($(origin CPP),default)
243    CPP=gcc -E
244  endif
245  CFG_GCCISH_CFLAGS += -Wall -Werror -fno-rtti -g
246  CFG_GCCISH_LINK_FLAGS += -g
247  # These flags will cause the compiler to produce a .d file
248  # next to the .o file that lists header deps.
249  CFG_DEPEND_FLAGS = -MMD -MP -MT $(1) -MF $(1:%.o=%.d)
250
251  define CFG_MAKE_CC
252	CFG_COMPILE_C_$(1) = $$(CFG_GCCISH_CROSS)$$(CXX)	\
253        $$(CFG_GCCISH_CFLAGS)							\
254	    $$(CFG_GCCISH_CFLAGS_$$(HOST_$(1)))				\
255        $$(CFG_GCC_CFLAGS)								\
256        $$(CFG_GCC_CFLAGS_$$(HOST_$(1)))				\
257        $$(CFG_DEPEND_FLAGS)                            \
258        -c -o $$(1) $$(2)
259    CFG_LINK_C_$(1) = $$(CFG_GCCISH_CROSS)$$(CXX)	\
260        $$(CFG_GCCISH_LINK_FLAGS) -o $$(1)			\
261		$$(CFG_GCCISH_LINK_FLAGS_$$(HOST_$(1)))		\
262        $$(CFG_GCCISH_DEF_FLAG)$$(3) $$(2)			\
263        $$(call CFG_INSTALL_NAME,$$(4))
264  endef
265
266  $(foreach target,$(CFG_TARGET_TRIPLES), \
267    $(eval $(call CFG_MAKE_CC,$(target))))
268else
269  CFG_ERR := $(error please try on a system with gcc or clang)
270endif
271endif
272
273# We're using llvm-mc as our assembler because it supports
274# .cfi pseudo-ops on mac
275define CFG_MAKE_ASSEMBLER
276  CFG_ASSEMBLE_$(1)=$$(CPP) $$(CFG_DEPEND_FLAGS) $$(2) | \
277                    $$(LLVM_MC_$$(CFG_HOST_TRIPLE)) \
278                    -assemble \
279                    -filetype=obj \
280                    -triple=$(1) \
281                    -o=$$(1)
282endef
283
284$(foreach target,$(CFG_TARGET_TRIPLES),\
285  $(eval $(call CFG_MAKE_ASSEMBLER,$(target))))