]> git.lizzy.rs Git - rust.git/blob - tests/run-make-fulldeps/tools.mk
add (currently ICEing) test
[rust.git] / tests / 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 # 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.
45 ifdef 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).
49 EXECUTE = $(REMOTE_TEST_CLIENT) run 0 $(RUN_BINFILE)
50 else
51 EXECUTE = $(RUN_BINFILE)
52 endif
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
58 RLIB_GLOB = lib$(1)*.rlib
59 BIN = $(1)
60
61 UNAME = $(shell uname)
62
63 ifeq ($(UNAME),Darwin)
64 RUN = $(TARGET_RPATH_ENV) $(EXECUTE)
65 FAIL = $(TARGET_RPATH_ENV) $(EXECUTE) && exit 1 || exit 0
66 DYLIB_GLOB = lib$(1)*.dylib
67 DYLIB = $(TMPDIR)/lib$(1).dylib
68 STATICLIB = $(TMPDIR)/lib$(1).a
69 STATICLIB_GLOB = lib$(1)*.a
70 else
71 ifdef IS_WINDOWS
72 RUN = PATH="$(PATH):$(TARGET_RPATH_DIR)" $(EXECUTE)
73 FAIL = PATH="$(PATH):$(TARGET_RPATH_DIR)" $(EXECUTE) && exit 1 || exit 0
74 DYLIB_GLOB = $(1)*.dll
75 DYLIB = $(TMPDIR)/$(1).dll
76 ifdef IS_MSVC
77 STATICLIB = $(TMPDIR)/$(1).lib
78 STATICLIB_GLOB = $(1)*.lib
79 else
80 IMPLIB = $(TMPDIR)/lib$(1).dll.a
81 STATICLIB = $(TMPDIR)/lib$(1).a
82 STATICLIB_GLOB = lib$(1)*.a
83 endif
84 BIN = $(1).exe
85 LLVM_FILECHECK := $(shell cygpath -u "$(LLVM_FILECHECK)")
86 else
87 RUN = $(TARGET_RPATH_ENV) $(EXECUTE)
88 FAIL = $(TARGET_RPATH_ENV) $(EXECUTE) && exit 1 || exit 0
89 DYLIB_GLOB = lib$(1)*.so
90 DYLIB = $(TMPDIR)/lib$(1).so
91 STATICLIB = $(TMPDIR)/lib$(1).a
92 STATICLIB_GLOB = lib$(1)*.a
93 endif
94 endif
95
96 ifdef IS_MSVC
97 COMPILE_OBJ = $(CC) -c -Fo:`cygpath -w $(1)` $(2)
98 COMPILE_OBJ_CXX = $(CXX) -EHs -c -Fo:`cygpath -w $(1)` $(2)
99 NATIVE_STATICLIB_FILE = $(1).lib
100 NATIVE_STATICLIB = $(TMPDIR)/$(call NATIVE_STATICLIB_FILE,$(1))
101 OUT_EXE=-Fe:`cygpath -w $(TMPDIR)/$(call BIN,$(1))` \
102         -Fo:`cygpath -w $(TMPDIR)/$(1).obj`
103 else
104 COMPILE_OBJ = $(CC) -v -c -o $(1) $(2)
105 COMPILE_OBJ_CXX = $(CXX) -c -o $(1) $(2)
106 NATIVE_STATICLIB_FILE = lib$(1).a
107 NATIVE_STATICLIB = $(call STATICLIB,$(1))
108 OUT_EXE=-o $(TMPDIR)/$(1)
109 endif
110
111
112 # Extra flags needed to compile a working executable with the standard library
113 ifdef IS_WINDOWS
114 ifdef IS_MSVC
115         EXTRACFLAGS := ws2_32.lib userenv.lib advapi32.lib bcrypt.lib
116 else
117         EXTRACFLAGS := -lws2_32 -luserenv -lbcrypt
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++
135 endif
136 else
137 ifeq ($(UNAME),Darwin)
138         EXTRACFLAGS := -lresolv
139         EXTRACXXFLAGS := -lc++
140         EXTRARSCXXFLAGS := -lc++
141 else
142 ifeq ($(UNAME),FreeBSD)
143         EXTRACFLAGS := -lm -lpthread -lgcc_s
144 else
145 ifeq ($(UNAME),SunOS)
146         EXTRACFLAGS := -lm -lpthread -lposix4 -lsocket -lresolv
147 else
148 ifeq ($(UNAME),OpenBSD)
149         EXTRACFLAGS := -lm -lpthread -lc++abi
150         RUSTC := $(RUSTC) -C linker="$(word 1,$(CC:ccache=))"
151 else
152         EXTRACFLAGS := -lm -lrt -ldl -lpthread
153         EXTRACXXFLAGS := -lstdc++
154         EXTRARSCXXFLAGS := -lstdc++
155 endif
156 endif
157 endif
158 endif
159 endif
160
161 REMOVE_DYLIBS     = rm $(TMPDIR)/$(call DYLIB_GLOB,$(1))
162 REMOVE_RLIBS      = rm $(TMPDIR)/$(call RLIB_GLOB,$(1))
163
164 %.a: %.o
165         $(AR) crus $@ $<
166 ifdef IS_MSVC
167 %.lib: lib%.o
168         $(MSVC_LIB) -out:`cygpath -w $@` $<
169 else
170 %.lib: lib%.o
171         $(AR) crus $@ $<
172 endif
173 %.dylib: %.o
174         $(CC) -dynamiclib -Wl,-dylib -o $@ $<
175 %.so: %.o
176         $(CC) -o $@ $< -shared
177
178 ifdef IS_MSVC
179 %.dll: lib%.o
180         $(CC) $< -link -dll -out:`cygpath -w $@`
181 else
182 %.dll: lib%.o
183         $(CC) -o $@ $< -shared -Wl,--out-implib=$@.a
184 endif
185
186 $(TMPDIR)/lib%.o: %.c
187         $(call COMPILE_OBJ,$@,$<)