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