1 # These deliberately use `=` and not `:=` so that client makefiles can
2 # augment HOST_RPATH_DIR / TARGET_RPATH_DIR.
4 $(LD_LIB_PATH_ENVVAR
)="$(TMPDIR):$(HOST_RPATH_DIR):$($(LD_LIB_PATH_ENVVAR))"
6 $(LD_LIB_PATH_ENVVAR
)="$(TMPDIR):$(TARGET_RPATH_DIR):$($(LD_LIB_PATH_ENVVAR))"
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
)
14 RUSTC
:= $(RUSTC
) -Clinker
=$(RUSTC_LINKER
)
15 RUSTDOC
:= $(RUSTDOC
) -Clinker
=$(RUSTC_LINKER
)
17 #CC := $(CC) -L $(TMPDIR)
18 HTMLDOCCK
:= '$(PYTHON)' '$(S)/src/etc/htmldocck.py'
19 CGREP
:= "$(S)/src/etc/cat-and-grep.sh"
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)
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.
29 RLIB_GLOB
= lib
$(1)*.rlib
32 UNAME
= $(shell uname
)
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
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
48 STATICLIB
= $(TMPDIR
)/$(1).lib
49 STATICLIB_GLOB
= $(1)*.lib
51 STATICLIB
= $(TMPDIR
)/lib
$(1).a
52 STATICLIB_GLOB
= lib
$(1)*.a
55 LLVM_FILECHECK
:= $(shell cygpath
-u
"$(LLVM_FILECHECK)")
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
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`
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)
82 # Extra flags needed to compile a working executable with the standard library
85 EXTRACFLAGS
:= ws2_32.lib userenv.lib advapi32.lib
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
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.
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
++
107 ifeq ($(UNAME
),Darwin
)
108 EXTRACFLAGS
:= -lresolv
109 EXTRACXXFLAGS
:= -lc
++
110 EXTRARSCXXFLAGS
:= -lc
++
112 ifeq ($(UNAME
),FreeBSD
)
113 EXTRACFLAGS
:= -lm
-lpthread
-lgcc_s
115 ifeq ($(UNAME
),SunOS
)
116 EXTRACFLAGS
:= -lm
-lpthread
-lposix4
-lsocket
-lresolv
118 ifeq ($(UNAME
),OpenBSD
)
119 EXTRACFLAGS
:= -lm
-lpthread
-lc
++abi
120 RUSTC
:= $(RUSTC
) -C linker
="$(word 1,$(CC:ccache=))"
122 EXTRACFLAGS
:= -lm
-lrt
-ldl
-lpthread
123 EXTRACXXFLAGS
:= -lstdc
++
124 EXTRARSCXXFLAGS
:= -lstdc
++
131 REMOVE_DYLIBS
= rm $(TMPDIR
)/$(call DYLIB_GLOB
,$(1))
132 REMOVE_RLIBS
= rm $(TMPDIR
)/$(call RLIB_GLOB
,$(1))
138 $(MSVC_LIB
) -out
:`cygpath -w $@` $<
144 $(CC
) -dynamiclib
-Wl
,-dylib
-o
$@
$<
146 $(CC
) -o
$@
$< -shared
150 $(CC
) $< -link
-dll
-out
:`cygpath -w $@`
153 $(CC
) -o
$@
$< -shared
156 $(TMPDIR
)/lib
%.o
: %.c
157 $(call COMPILE_OBJ
,$@
,$<)