fork/rust
git clone https://git.julia.blue/fork/rust
f3e1a954d2e
1.41.1
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) 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# This is the name of the binary we will generate and run; use this 22# e.g. for `$(CC) -o $(RUN_BINFILE)`. 23RUN_BINFILE = $(TMPDIR)/$(1) 24 25# RUN and FAIL are basic way we will invoke the generated binary. On 26# non-windows platforms, they set the LD_LIBRARY_PATH environment 27# variable before running the binary. 28 29RLIB_GLOB = lib$(1)*.rlib 30BIN = $(1) 31 32UNAME = $(shell uname) 33 34ifeq ($(UNAME),Darwin) 35RUN = $(TARGET_RPATH_ENV) $(RUN_BINFILE) 36FAIL = $(TARGET_RPATH_ENV) $(RUN_BINFILE) && exit 1 || exit 0 37DYLIB_GLOB = lib$(1)*.dylib 38DYLIB = $(TMPDIR)/lib$(1).dylib 39STATICLIB = $(TMPDIR)/lib$(1).a 40STATICLIB_GLOB = lib$(1)*.a 41else 42ifdef IS_WINDOWS 43RUN = PATH="$(PATH):$(TARGET_RPATH_DIR)" $(RUN_BINFILE) 44FAIL = PATH="$(PATH):$(TARGET_RPATH_DIR)" $(RUN_BINFILE) && exit 1 || exit 0 45DYLIB_GLOB = $(1)*.dll 46DYLIB = $(TMPDIR)/$(1).dll 47STATICLIB = $(TMPDIR)/$(1).lib 48STATICLIB_GLOB = $(1)*.lib 49BIN = $(1).exe 50LLVM_FILECHECK := $(shell cygpath -u "$(LLVM_FILECHECK)") 51else 52RUN = $(TARGET_RPATH_ENV) $(RUN_BINFILE) 53FAIL = $(TARGET_RPATH_ENV) $(RUN_BINFILE) && exit 1 || exit 0 54DYLIB_GLOB = lib$(1)*.so 55DYLIB = $(TMPDIR)/lib$(1).so 56STATICLIB = $(TMPDIR)/lib$(1).a 57STATICLIB_GLOB = lib$(1)*.a 58endif 59endif 60 61ifdef IS_MSVC 62COMPILE_OBJ = $(CC) -c -Fo:`cygpath -w $(1)` $(2) 63COMPILE_OBJ_CXX = $(CXX) -EHs -c -Fo:`cygpath -w $(1)` $(2) 64NATIVE_STATICLIB_FILE = $(1).lib 65NATIVE_STATICLIB = $(TMPDIR)/$(call NATIVE_STATICLIB_FILE,$(1)) 66OUT_EXE=-Fe:`cygpath -w $(TMPDIR)/$(call BIN,$(1))` \ 67 -Fo:`cygpath -w $(TMPDIR)/$(1).obj` 68else 69COMPILE_OBJ = $(CC) -c -o $(1) $(2) 70COMPILE_OBJ_CXX = $(CXX) -c -o $(1) $(2) 71NATIVE_STATICLIB_FILE = lib$(1).a 72NATIVE_STATICLIB = $(call STATICLIB,$(1)) 73OUT_EXE=-o $(TMPDIR)/$(1) 74endif 75 76 77# Extra flags needed to compile a working executable with the standard library 78ifdef IS_WINDOWS 79ifdef IS_MSVC 80 EXTRACFLAGS := ws2_32.lib userenv.lib advapi32.lib 81else 82 EXTRACFLAGS := -lws2_32 -luserenv 83 EXTRACXXFLAGS := -lstdc++ 84 # So this is a bit hacky: we can't use the DLL version of libstdc++ because 85 # it pulls in the DLL version of libgcc, which means that we end up with 2 86 # instances of the DW2 unwinding implementation. This is a problem on 87 # i686-pc-windows-gnu because each module (DLL/EXE) needs to register its 88 # unwind information with the unwinding implementation, and libstdc++'s 89 # __cxa_throw won't see the unwinding info we registered with our statically 90 # linked libgcc. 91 # 92 # Now, simply statically linking libstdc++ would fix this problem, except 93 # that it is compiled with the expectation that pthreads is dynamically 94 # linked as a DLL and will fail to link with a statically linked libpthread. 95 # 96 # So we end up with the following hack: we link use static-nobundle to only 97 # link the parts of libstdc++ that we actually use, which doesn't include 98 # the dependency on the pthreads DLL. 99 EXTRARSCXXFLAGS := -l static-nobundle=stdc++ 100endif 101else 102ifeq ($(UNAME),Darwin) 103 EXTRACFLAGS := -lresolv 104 EXTRACXXFLAGS := -lc++ 105 EXTRARSCXXFLAGS := -lc++ 106else 107ifeq ($(UNAME),FreeBSD) 108 EXTRACFLAGS := -lm -lpthread -lgcc_s 109else 110ifeq ($(UNAME),SunOS) 111 EXTRACFLAGS := -lm -lpthread -lposix4 -lsocket -lresolv 112else 113ifeq ($(UNAME),OpenBSD) 114 EXTRACFLAGS := -lm -lpthread -lc++abi 115 RUSTC := $(RUSTC) -C linker="$(word 1,$(CC:ccache=))" 116else 117 EXTRACFLAGS := -lm -lrt -ldl -lpthread 118 EXTRACXXFLAGS := -lstdc++ 119 EXTRARSCXXFLAGS := -lstdc++ 120endif 121endif 122endif 123endif 124endif 125 126REMOVE_DYLIBS = rm $(TMPDIR)/$(call DYLIB_GLOB,$(1)) 127REMOVE_RLIBS = rm $(TMPDIR)/$(call RLIB_GLOB,$(1)) 128 129%.a: %.o 130 $(AR) crus $@ $< 131ifdef IS_MSVC 132%.lib: lib%.o 133 $(MSVC_LIB) -out:`cygpath -w $@` $< 134else 135%.lib: lib%.o 136 $(AR) crus $@ $< 137endif 138%.dylib: %.o 139 $(CC) -dynamiclib -Wl,-dylib -o $@ $< 140%.so: %.o 141 $(CC) -o $@ $< -shared 142 143ifdef IS_MSVC 144%.dll: lib%.o 145 $(CC) $< -link -dll -out:`cygpath -w $@` 146else 147%.dll: lib%.o 148 $(CC) -o $@ $< -shared 149endif 150 151$(TMPDIR)/lib%.o: %.c 152 $(call COMPILE_OBJ,$@,$<)