fork/rust

git clone https://git.julia.blue/fork/rust

borsAuto merge of #72883 - Mark-Simulacrum:stable-next, r=Mark-Simulacrum49cae55760d

1.44.0
4.6 KiB157 linesraw
1# These deliberately use `=` and not `:=` so that client makefiles can
2# augment HOST_RPATH_DIR / TARGET_RPATH_DIR.
3HOST_RPATH_ENV = \
4    $(LD_LIB_PATH_ENVVAR)="$(TMPDIR):$(HOST_RPATH_DIR):$($(LD_LIB_PATH_ENVVAR))"
5TARGET_RPATH_ENV = \
6    $(LD_LIB_PATH_ENVVAR)="$(TMPDIR):$(TARGET_RPATH_DIR):$($(LD_LIB_PATH_ENVVAR))"
7
8RUSTC_ORIGINAL := $(RUSTC)
9BARE_RUSTC := $(HOST_RPATH_ENV) '$(RUSTC)'
10BARE_RUSTDOC := $(HOST_RPATH_ENV) '$(RUSTDOC)'
11RUSTC := $(BARE_RUSTC) --out-dir $(TMPDIR) -L $(TMPDIR) $(RUSTFLAGS)
12RUSTDOC := $(BARE_RUSTDOC) -L $(TARGET_RPATH_DIR)
13ifdef RUSTC_LINKER
14RUSTC := $(RUSTC) -Clinker=$(RUSTC_LINKER)
15RUSTDOC := $(RUSTDOC) -Clinker=$(RUSTC_LINKER)
16endif
17#CC := $(CC) -L $(TMPDIR)
18HTMLDOCCK := '$(PYTHON)' '$(S)/src/etc/htmldocck.py'
19CGREP := "$(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)`.
23RUN_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
29RLIB_GLOB = lib$(1)*.rlib
30BIN = $(1)
31
32UNAME = $(shell uname)
33
34ifeq ($(UNAME),Darwin)
35RUN = $(TARGET_RPATH_ENV) $(RUN_BINFILE)
36FAIL = $(TARGET_RPATH_ENV) $(RUN_BINFILE) && exit 1 || exit 0
37DYLIB_GLOB = lib$(1)*.dylib
38DYLIB = $(TMPDIR)/lib$(1).dylib
39STATICLIB = $(TMPDIR)/lib$(1).a
40STATICLIB_GLOB = lib$(1)*.a
41else
42ifdef IS_WINDOWS
43RUN = PATH="$(PATH):$(TARGET_RPATH_DIR)" $(RUN_BINFILE)
44FAIL = PATH="$(PATH):$(TARGET_RPATH_DIR)" $(RUN_BINFILE) && exit 1 || exit 0
45DYLIB_GLOB = $(1)*.dll
46DYLIB = $(TMPDIR)/$(1).dll
47ifdef IS_MSVC
48STATICLIB = $(TMPDIR)/$(1).lib
49STATICLIB_GLOB = $(1)*.lib
50else
51STATICLIB = $(TMPDIR)/lib$(1).a
52STATICLIB_GLOB = lib$(1)*.a
53endif
54BIN = $(1).exe
55LLVM_FILECHECK := $(shell cygpath -u "$(LLVM_FILECHECK)")
56else
57RUN = $(TARGET_RPATH_ENV) $(RUN_BINFILE)
58FAIL = $(TARGET_RPATH_ENV) $(RUN_BINFILE) && exit 1 || exit 0
59DYLIB_GLOB = lib$(1)*.so
60DYLIB = $(TMPDIR)/lib$(1).so
61STATICLIB = $(TMPDIR)/lib$(1).a
62STATICLIB_GLOB = lib$(1)*.a
63endif
64endif
65
66ifdef IS_MSVC
67COMPILE_OBJ = $(CC) -c -Fo:`cygpath -w $(1)` $(2)
68COMPILE_OBJ_CXX = $(CXX) -EHs -c -Fo:`cygpath -w $(1)` $(2)
69NATIVE_STATICLIB_FILE = $(1).lib
70NATIVE_STATICLIB = $(TMPDIR)/$(call NATIVE_STATICLIB_FILE,$(1))
71OUT_EXE=-Fe:`cygpath -w $(TMPDIR)/$(call BIN,$(1))` \
72	-Fo:`cygpath -w $(TMPDIR)/$(1).obj`
73else
74COMPILE_OBJ = $(CC) -c -o $(1) $(2)
75COMPILE_OBJ_CXX = $(CXX) -c -o $(1) $(2)
76NATIVE_STATICLIB_FILE = lib$(1).a
77NATIVE_STATICLIB = $(call STATICLIB,$(1))
78OUT_EXE=-o $(TMPDIR)/$(1)
79endif
80
81
82# Extra flags needed to compile a working executable with the standard library
83ifdef IS_WINDOWS
84ifdef IS_MSVC
85	EXTRACFLAGS := ws2_32.lib userenv.lib advapi32.lib
86else
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++
105endif
106else
107ifeq ($(UNAME),Darwin)
108	EXTRACFLAGS := -lresolv
109	EXTRACXXFLAGS := -lc++
110	EXTRARSCXXFLAGS := -lc++
111else
112ifeq ($(UNAME),FreeBSD)
113	EXTRACFLAGS := -lm -lpthread -lgcc_s
114else
115ifeq ($(UNAME),SunOS)
116	EXTRACFLAGS := -lm -lpthread -lposix4 -lsocket -lresolv
117else
118ifeq ($(UNAME),OpenBSD)
119	EXTRACFLAGS := -lm -lpthread -lc++abi
120	RUSTC := $(RUSTC) -C linker="$(word 1,$(CC:ccache=))"
121else
122	EXTRACFLAGS := -lm -lrt -ldl -lpthread
123	EXTRACXXFLAGS := -lstdc++
124	EXTRARSCXXFLAGS := -lstdc++
125endif
126endif
127endif
128endif
129endif
130
131REMOVE_DYLIBS     = rm $(TMPDIR)/$(call DYLIB_GLOB,$(1))
132REMOVE_RLIBS      = rm $(TMPDIR)/$(call RLIB_GLOB,$(1))
133
134%.a: %.o
135	$(AR) crus $@ $<
136ifdef IS_MSVC
137%.lib: lib%.o
138	$(MSVC_LIB) -out:`cygpath -w $@` $<
139else
140%.lib: lib%.o
141	$(AR) crus $@ $<
142endif
143%.dylib: %.o
144	$(CC) -dynamiclib -Wl,-dylib -o $@ $<
145%.so: %.o
146	$(CC) -o $@ $< -shared
147
148ifdef IS_MSVC
149%.dll: lib%.o
150	$(CC) $< -link -dll -out:`cygpath -w $@`
151else
152%.dll: lib%.o
153	$(CC) -o $@ $< -shared
154endif
155
156$(TMPDIR)/lib%.o: %.c
157	$(call COMPILE_OBJ,$@,$<)