1 # These deliberately use `=` and not `:=` so that client makefiles can
2 # augment HOST_RPATH_DIR / TARGET_RPATH_DIR.
4 $(LD_LIB_PATH_ENVVAR)="$(TMPDIR):$(HOST_RPATH_DIR):$($(LD_LIB_PATH_ENVVAR))"
6 $(LD_LIB_PATH_ENVVAR)="$(TMPDIR):$(TARGET_RPATH_DIR):$($(LD_LIB_PATH_ENVVAR))"
8 RUSTC_ORIGINAL := $(RUSTC)
9 BARE_RUSTC := $(HOST_RPATH_ENV) '$(RUSTC)'
10 BARE_RUSTDOC := $(HOST_RPATH_ENV) '$(RUSTDOC)'
11 RUSTC := $(BARE_RUSTC) --out-dir $(TMPDIR) -L $(TMPDIR) $(RUSTFLAGS)
12 RUSTDOC := $(BARE_RUSTDOC) -L $(TARGET_RPATH_DIR)
14 RUSTC := $(RUSTC) -Clinker='$(RUSTC_LINKER)'
15 RUSTDOC := $(RUSTDOC) -Clinker='$(RUSTC_LINKER)'
17 #CC := $(CC) -L $(TMPDIR)
18 HTMLDOCCK := '$(PYTHON)' '$(S)/src/etc/htmldocck.py'
19 CGREP := "$(S)/src/etc/cat-and-grep.sh"
21 # diff with common flags for multi-platform diffs against text output
22 DIFF := diff -u --strip-trailing-cr
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
33 ifndef IS_WINDOWS # dash interprets backslashes in executable paths incorrectly
34 ifneq (,$(wildcard /bin/dash))
39 # This is the name of the binary we will generate and run; use this
40 # e.g. for `$(CC) -o $(RUN_BINFILE)`.
41 RUN_BINFILE = $(TMPDIR)/$(1)
43 # RUN and FAIL are basic way we will invoke the generated binary. On
44 # non-windows platforms, they set the LD_LIBRARY_PATH environment
45 # variable before running the binary.
47 RLIB_GLOB = lib$(1)*.rlib
50 UNAME = $(shell uname)
52 ifeq ($(UNAME),Darwin)
53 RUN = $(TARGET_RPATH_ENV) $(RUN_BINFILE)
54 FAIL = $(TARGET_RPATH_ENV) $(RUN_BINFILE) && exit 1 || exit 0
55 DYLIB_GLOB = lib$(1)*.dylib
56 DYLIB = $(TMPDIR)/lib$(1).dylib
57 STATICLIB = $(TMPDIR)/lib$(1).a
58 STATICLIB_GLOB = lib$(1)*.a
61 RUN = PATH="$(PATH):$(TARGET_RPATH_DIR)" $(RUN_BINFILE)
62 FAIL = PATH="$(PATH):$(TARGET_RPATH_DIR)" $(RUN_BINFILE) && exit 1 || exit 0
63 DYLIB_GLOB = $(1)*.dll
64 DYLIB = $(TMPDIR)/$(1).dll
66 STATICLIB = $(TMPDIR)/$(1).lib
67 STATICLIB_GLOB = $(1)*.lib
69 IMPLIB = $(TMPDIR)/lib$(1).dll.a
70 STATICLIB = $(TMPDIR)/lib$(1).a
71 STATICLIB_GLOB = lib$(1)*.a
74 LLVM_FILECHECK := $(shell cygpath -u "$(LLVM_FILECHECK)")
76 RUN = $(TARGET_RPATH_ENV) $(RUN_BINFILE)
77 FAIL = $(TARGET_RPATH_ENV) $(RUN_BINFILE) && exit 1 || exit 0
78 DYLIB_GLOB = lib$(1)*.so
79 DYLIB = $(TMPDIR)/lib$(1).so
80 STATICLIB = $(TMPDIR)/lib$(1).a
81 STATICLIB_GLOB = lib$(1)*.a
86 COMPILE_OBJ = $(CC) -c -Fo:`cygpath -w $(1)` $(2)
87 COMPILE_OBJ_CXX = $(CXX) -EHs -c -Fo:`cygpath -w $(1)` $(2)
88 NATIVE_STATICLIB_FILE = $(1).lib
89 NATIVE_STATICLIB = $(TMPDIR)/$(call NATIVE_STATICLIB_FILE,$(1))
90 OUT_EXE=-Fe:`cygpath -w $(TMPDIR)/$(call BIN,$(1))` \
91 -Fo:`cygpath -w $(TMPDIR)/$(1).obj`
93 COMPILE_OBJ = $(CC) -v -c -o $(1) $(2)
94 COMPILE_OBJ_CXX = $(CXX) -c -o $(1) $(2)
95 NATIVE_STATICLIB_FILE = lib$(1).a
96 NATIVE_STATICLIB = $(call STATICLIB,$(1))
97 OUT_EXE=-o $(TMPDIR)/$(1)
101 # Extra flags needed to compile a working executable with the standard library
104 EXTRACFLAGS := ws2_32.lib userenv.lib advapi32.lib bcrypt.lib
106 EXTRACFLAGS := -lws2_32 -luserenv -lbcrypt
107 EXTRACXXFLAGS := -lstdc++
108 # So this is a bit hacky: we can't use the DLL version of libstdc++ because
109 # it pulls in the DLL version of libgcc, which means that we end up with 2
110 # instances of the DW2 unwinding implementation. This is a problem on
111 # i686-pc-windows-gnu because each module (DLL/EXE) needs to register its
112 # unwind information with the unwinding implementation, and libstdc++'s
113 # __cxa_throw won't see the unwinding info we registered with our statically
116 # Now, simply statically linking libstdc++ would fix this problem, except
117 # that it is compiled with the expectation that pthreads is dynamically
118 # linked as a DLL and will fail to link with a statically linked libpthread.
120 # So we end up with the following hack: we link use static:-bundle to only
121 # link the parts of libstdc++ that we actually use, which doesn't include
122 # the dependency on the pthreads DLL.
123 EXTRARSCXXFLAGS := -l static:-bundle=stdc++
126 ifeq ($(UNAME),Darwin)
127 EXTRACFLAGS := -lresolv
128 EXTRACXXFLAGS := -lc++
129 EXTRARSCXXFLAGS := -lc++
131 ifeq ($(UNAME),FreeBSD)
132 EXTRACFLAGS := -lm -lpthread -lgcc_s
134 ifeq ($(UNAME),SunOS)
135 EXTRACFLAGS := -lm -lpthread -lposix4 -lsocket -lresolv
137 ifeq ($(UNAME),OpenBSD)
138 EXTRACFLAGS := -lm -lpthread -lc++abi
139 RUSTC := $(RUSTC) -C linker="$(word 1,$(CC:ccache=))"
141 EXTRACFLAGS := -lm -lrt -ldl -lpthread
142 EXTRACXXFLAGS := -lstdc++
143 EXTRARSCXXFLAGS := -lstdc++
150 REMOVE_DYLIBS = rm $(TMPDIR)/$(call DYLIB_GLOB,$(1))
151 REMOVE_RLIBS = rm $(TMPDIR)/$(call RLIB_GLOB,$(1))
157 $(MSVC_LIB) -out:`cygpath -w $@` $<
163 $(CC) -dynamiclib -Wl,-dylib -o $@ $<
165 $(CC) -o $@ $< -shared
169 $(CC) $< -link -dll -out:`cygpath -w $@`
172 $(CC) -o $@ $< -shared -Wl,--out-implib=$@.a
175 $(TMPDIR)/lib%.o: %.c
176 $(call COMPILE_OBJ,$@,$<)