]> git.lizzy.rs Git - rust.git/blob - src/test/run-make-fulldeps/tools.mk
Auto merge of #99509 - lcnr:commit_unconditionally, r=jackh726
[rust.git] / src / test / run-make-fulldeps / tools.mk
1 # These deliberately use `=` and not `:=` so that client makefiles can
2 # augment HOST_RPATH_DIR / TARGET_RPATH_DIR.
3 HOST_RPATH_ENV = \
4     $(LD_LIB_PATH_ENVVAR)="$(TMPDIR):$(HOST_RPATH_DIR):$($(LD_LIB_PATH_ENVVAR))"
5 TARGET_RPATH_ENV = \
6     $(LD_LIB_PATH_ENVVAR)="$(TMPDIR):$(TARGET_RPATH_DIR):$($(LD_LIB_PATH_ENVVAR))"
7
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)
13 ifdef RUSTC_LINKER
14 RUSTC := $(RUSTC) -Clinker='$(RUSTC_LINKER)'
15 RUSTDOC := $(RUSTDOC) -Clinker='$(RUSTC_LINKER)'
16 endif
17 #CC := $(CC) -L $(TMPDIR)
18 HTMLDOCCK := '$(PYTHON)' '$(S)/src/etc/htmldocck.py'
19 CGREP := "$(S)/src/etc/cat-and-grep.sh"
20
21 # diff with common flags for multi-platform diffs against text output
22 DIFF := 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:
33 ifndef IS_WINDOWS # dash interprets backslashes in executable paths incorrectly
34 ifneq (,$(wildcard /bin/dash))
35 SHELL := /bin/dash
36 endif
37 endif
38
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)
42
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.
46
47 RLIB_GLOB = lib$(1)*.rlib
48 BIN = $(1)
49
50 UNAME = $(shell uname)
51
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
59 else
60 ifdef IS_WINDOWS
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
65 ifdef IS_MSVC
66 STATICLIB = $(TMPDIR)/$(1).lib
67 STATICLIB_GLOB = $(1)*.lib
68 else
69 IMPLIB = $(TMPDIR)/lib$(1).dll.a
70 STATICLIB = $(TMPDIR)/lib$(1).a
71 STATICLIB_GLOB = lib$(1)*.a
72 endif
73 BIN = $(1).exe
74 LLVM_FILECHECK := $(shell cygpath -u "$(LLVM_FILECHECK)")
75 else
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
82 endif
83 endif
84
85 ifdef IS_MSVC
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`
92 else
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)
98 endif
99
100
101 # Extra flags needed to compile a working executable with the standard library
102 ifdef IS_WINDOWS
103 ifdef IS_MSVC
104         EXTRACFLAGS := ws2_32.lib userenv.lib advapi32.lib bcrypt.lib
105 else
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
114         # linked libgcc.
115         #
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.
119         #
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++
124 endif
125 else
126 ifeq ($(UNAME),Darwin)
127         EXTRACFLAGS := -lresolv
128         EXTRACXXFLAGS := -lc++
129         EXTRARSCXXFLAGS := -lc++
130 else
131 ifeq ($(UNAME),FreeBSD)
132         EXTRACFLAGS := -lm -lpthread -lgcc_s
133 else
134 ifeq ($(UNAME),SunOS)
135         EXTRACFLAGS := -lm -lpthread -lposix4 -lsocket -lresolv
136 else
137 ifeq ($(UNAME),OpenBSD)
138         EXTRACFLAGS := -lm -lpthread -lc++abi
139         RUSTC := $(RUSTC) -C linker="$(word 1,$(CC:ccache=))"
140 else
141         EXTRACFLAGS := -lm -lrt -ldl -lpthread
142         EXTRACXXFLAGS := -lstdc++
143         EXTRARSCXXFLAGS := -lstdc++
144 endif
145 endif
146 endif
147 endif
148 endif
149
150 REMOVE_DYLIBS     = rm $(TMPDIR)/$(call DYLIB_GLOB,$(1))
151 REMOVE_RLIBS      = rm $(TMPDIR)/$(call RLIB_GLOB,$(1))
152
153 %.a: %.o
154         $(AR) crus $@ $<
155 ifdef IS_MSVC
156 %.lib: lib%.o
157         $(MSVC_LIB) -out:`cygpath -w $@` $<
158 else
159 %.lib: lib%.o
160         $(AR) crus $@ $<
161 endif
162 %.dylib: %.o
163         $(CC) -dynamiclib -Wl,-dylib -o $@ $<
164 %.so: %.o
165         $(CC) -o $@ $< -shared
166
167 ifdef IS_MSVC
168 %.dll: lib%.o
169         $(CC) $< -link -dll -out:`cygpath -w $@`
170 else
171 %.dll: lib%.o
172         $(CC) -o $@ $< -shared -Wl,--out-implib=$@.a
173 endif
174
175 $(TMPDIR)/lib%.o: %.c
176         $(call COMPILE_OBJ,$@,$<)