fork/rust
git clone https://git.julia.blue/fork/rust
3bcad65fbf6
master
1# These deliberately use `=` and not `:=` so that client makefiles can 2# augment HOST_RPATH_DIR / TARGET_RPATH_DIR. 3HOST_RPATH_ENV = \ 4 $(LD_LIB_PATH_ENVVAR)="$(TMPDIR):$(HOST_RPATH_DIR):$($(LD_LIB_PATH_ENVVAR))" 5TARGET_RPATH_ENV = \ 6 $(LD_LIB_PATH_ENVVAR)="$(TMPDIR):$(TARGET_RPATH_DIR):$($(LD_LIB_PATH_ENVVAR))" 7 8RUSTC_ORIGINAL := $(RUSTC) 9BARE_RUSTC := $(HOST_RPATH_ENV) '$(RUSTC)' 10BARE_RUSTDOC := $(HOST_RPATH_ENV) '$(RUSTDOC)' 11RUSTC := $(BARE_RUSTC) --out-dir $(TMPDIR) -L $(TMPDIR) $(RUSTFLAGS) -Ainternal_features 12RUSTDOC := $(BARE_RUSTDOC) -L $(TARGET_RPATH_DIR) 13ifdef RUSTC_LINKER 14RUSTC := $(RUSTC) -Clinker='$(RUSTC_LINKER)' 15RUSTDOC := $(RUSTDOC) -Clinker='$(RUSTC_LINKER)' 16endif 17#CC := $(CC) -L $(TMPDIR) 18HTMLDOCCK := '$(PYTHON)' '$(S)/src/etc/htmldocck.py' 19CGREP := "$(S)/src/etc/cat-and-grep.sh" 20 21# diff with common flags for multi-platform diffs against text output 22DIFF := diff -u --strip-trailing-cr 23 24# Some of the Rust CI platforms use `/bin/dash` to run `shell` script in 25# Makefiles. Other platforms, including many developer platforms, default to 26# `/bin/bash`. (In many cases, `make` is actually using `/bin/sh`, but `sh` 27# is configured to execute one or the other shell binary). `dash` features 28# support only a small subset of `bash` features, so `dash` can be thought of as 29# the lowest common denominator, and tests should be validated against `dash` 30# whenever possible. Most developer platforms include `/bin/dash`, but to ensure 31# tests still work when `/bin/dash`, if not available, this `SHELL` override is 32# conditional: 33ifndef IS_WINDOWS # dash interprets backslashes in executable paths incorrectly 34ifneq (,$(wildcard /bin/dash)) 35SHELL := /bin/dash 36endif 37endif 38 39# This is the name of the binary we will generate and run; use this 40# e.g. for `$(CC) -o $(RUN_BINFILE)`. 41RUN_BINFILE = $(TMPDIR)/$(1) 42 43# Invoke the generated binary on the remote machine if compiletest was 44# configured to use a remote test device, otherwise run it on the current host. 45ifdef REMOTE_TEST_CLIENT 46# FIXME: if a test requires additional files, this will need to be changed to 47# also push them (by changing the 0 to the number of additional files, and 48# providing the path of the additional files as the last arguments). 49EXECUTE = $(REMOTE_TEST_CLIENT) run 0 $(RUN_BINFILE) 50else 51EXECUTE = $(RUN_BINFILE) 52endif 53 54# RUN and FAIL are basic way we will invoke the generated binary. On 55# non-windows platforms, they set the LD_LIBRARY_PATH environment 56# variable before running the binary. 57 58RLIB_GLOB = lib$(1)*.rlib 59BIN = $(1) 60 61UNAME = $(shell uname) 62 63ifeq ($(UNAME),Darwin) 64RUN = $(TARGET_RPATH_ENV) $(EXECUTE) 65FAIL = $(TARGET_RPATH_ENV) $(EXECUTE) && exit 1 || exit 0 66DYLIB_GLOB = lib$(1)*.dylib 67DYLIB = $(TMPDIR)/lib$(1).dylib 68STATICLIB = $(TMPDIR)/lib$(1).a 69STATICLIB_GLOB = lib$(1)*.a 70else 71ifdef IS_WINDOWS 72RUN = PATH="$(PATH):$(TARGET_RPATH_DIR)" $(EXECUTE) 73FAIL = PATH="$(PATH):$(TARGET_RPATH_DIR)" $(EXECUTE) && exit 1 || exit 0 74DYLIB_GLOB = $(1)*.dll 75DYLIB = $(TMPDIR)/$(1).dll 76ifdef IS_MSVC 77STATICLIB = $(TMPDIR)/$(1).lib 78STATICLIB_GLOB = $(1)*.lib 79else 80IMPLIB = $(TMPDIR)/lib$(1).dll.a 81STATICLIB = $(TMPDIR)/lib$(1).a 82STATICLIB_GLOB = lib$(1)*.a 83endif 84BIN = $(1).exe 85LLVM_FILECHECK := $(shell cygpath -u "$(LLVM_FILECHECK)") 86else 87RUN = $(TARGET_RPATH_ENV) $(EXECUTE) 88FAIL = $(TARGET_RPATH_ENV) $(EXECUTE) && exit 1 || exit 0 89DYLIB_GLOB = lib$(1)*.so 90DYLIB = $(TMPDIR)/lib$(1).so 91STATICLIB = $(TMPDIR)/lib$(1).a 92STATICLIB_GLOB = lib$(1)*.a 93endif 94endif 95 96ifdef IS_MSVC 97COMPILE_OBJ = $(CC) -c -Fo:`cygpath -w $(1)` $(2) 98COMPILE_OBJ_CXX = $(CXX) -EHs -c -Fo:`cygpath -w $(1)` $(2) 99NATIVE_STATICLIB_FILE = $(1).lib 100NATIVE_STATICLIB = $(TMPDIR)/$(call NATIVE_STATICLIB_FILE,$(1)) 101OUT_EXE=-Fe:`cygpath -w $(TMPDIR)/$(call BIN,$(1))` \ 102 -Fo:`cygpath -w $(TMPDIR)/$(1).obj` 103else 104COMPILE_OBJ = $(CC) -v -c -o $(1) $(2) 105COMPILE_OBJ_CXX = $(CXX) -c -o $(1) $(2) 106NATIVE_STATICLIB_FILE = lib$(1).a 107NATIVE_STATICLIB = $(call STATICLIB,$(1)) 108OUT_EXE=-o $(TMPDIR)/$(1) 109endif 110 111 112# Extra flags needed to compile a working executable with the standard library 113ifdef IS_WINDOWS 114ifdef IS_MSVC 115 EXTRACFLAGS := ws2_32.lib userenv.lib advapi32.lib bcrypt.lib ntdll.lib 116else 117 EXTRACFLAGS := -lws2_32 -luserenv -lbcrypt -lntdll 118 EXTRACXXFLAGS := -lstdc++ 119 # So this is a bit hacky: we can't use the DLL version of libstdc++ because 120 # it pulls in the DLL version of libgcc, which means that we end up with 2 121 # instances of the DW2 unwinding implementation. This is a problem on 122 # i686-pc-windows-gnu because each module (DLL/EXE) needs to register its 123 # unwind information with the unwinding implementation, and libstdc++'s 124 # __cxa_throw won't see the unwinding info we registered with our statically 125 # linked libgcc. 126 # 127 # Now, simply statically linking libstdc++ would fix this problem, except 128 # that it is compiled with the expectation that pthreads is dynamically 129 # linked as a DLL and will fail to link with a statically linked libpthread. 130 # 131 # So we end up with the following hack: we link use static:-bundle to only 132 # link the parts of libstdc++ that we actually use, which doesn't include 133 # the dependency on the pthreads DLL. 134 EXTRARSCXXFLAGS := -l static:-bundle=stdc++ 135endif 136else 137ifeq ($(UNAME),Darwin) 138 EXTRACFLAGS := -lresolv 139 EXTRACXXFLAGS := -lc++ 140 EXTRARSCXXFLAGS := -lc++ 141else 142ifeq ($(UNAME),FreeBSD) 143 EXTRACFLAGS := -lm -lpthread -lgcc_s 144else 145ifeq ($(UNAME),SunOS) 146 EXTRACFLAGS := -lm -lpthread -lposix4 -lsocket -lresolv 147else 148ifeq ($(UNAME),OpenBSD) 149 EXTRACFLAGS := -lm -lpthread -lc++abi 150 RUSTC := $(RUSTC) -C linker="$(word 1,$(CC:ccache=))" 151else 152 EXTRACFLAGS := -lm -lrt -ldl -lpthread 153 EXTRACXXFLAGS := -lstdc++ 154 EXTRARSCXXFLAGS := -lstdc++ 155endif 156endif 157endif 158endif 159endif 160 161REMOVE_DYLIBS = rm $(TMPDIR)/$(call DYLIB_GLOB,$(1)) 162REMOVE_RLIBS = rm $(TMPDIR)/$(call RLIB_GLOB,$(1)) 163 164%.a: %.o 165 $(AR) crus $@ $< 166ifdef IS_MSVC 167%.lib: lib%.o 168 $(MSVC_LIB) -out:`cygpath -w $@` $< 169else 170%.lib: lib%.o 171 $(AR) crus $@ $< 172endif 173%.dylib: %.o 174 $(CC) -dynamiclib -Wl,-dylib -o $@ $< 175%.so: %.o 176 $(CC) -o $@ $< -shared 177 178ifdef IS_MSVC 179%.dll: lib%.o 180 $(CC) $< -link -dll -out:`cygpath -w $@` 181else 182%.dll: lib%.o 183 $(CC) -o $@ $< -shared -Wl,--out-implib=$@.a 184endif 185 186$(TMPDIR)/lib%.o: %.c 187 $(call COMPILE_OBJ,$@,$<)