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