]> git.lizzy.rs Git - rust.git/blob - src/test/run-make/tools.mk
d4862e1570434ae960563e9324351eef328c38e4
[rust.git] / src / test / run-make / 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)="$(HOST_RPATH_DIR):$($(LD_LIB_PATH_ENVVAR))"
5 TARGET_RPATH_ENV = \
6     $(LD_LIB_PATH_ENVVAR)="$(TARGET_RPATH_DIR):$($(LD_LIB_PATH_ENVVAR))"
7
8 RUSTC := $(HOST_RPATH_ENV) $(RUSTC) --out-dir $(TMPDIR) -L $(TMPDIR)
9 CC := $(CC) -L $(TMPDIR)
10
11 # This is the name of the binary we will generate and run; use this
12 # e.g. for `$(CC) -o $(RUN_BINFILE)`.
13 RUN_BINFILE = $(TMPDIR)/$(1)
14
15 # RUN and FAIL are basic way we will invoke the generated binary.  On
16 # non-windows platforms, they set the LD_LIBRARY_PATH environment
17 # variable before running the binary.
18
19 RLIB_GLOB = lib$(1)*.rlib
20 STATICLIB = $(TMPDIR)/lib$(1).a
21 STATICLIB_GLOB = lib$(1)*.a
22 BIN = $(1)
23
24 UNAME = $(shell uname)
25 ifneq (,$(findstring MINGW,$(UNAME)))
26 IS_WINDOWS=1
27 endif
28
29 ifeq ($(UNAME),Darwin)
30 RUN = $(TARGET_RPATH_ENV) $(RUN_BINFILE)
31 FAIL = $(TARGET_RPATH_ENV) $(RUN_BINFILE) && exit 1 || exit 0
32 DYLIB_GLOB = lib$(1)*.dylib
33 DYLIB = $(TMPDIR)/lib$(1).dylib
34 RPATH_LINK_SEARCH =
35 else
36 ifdef IS_WINDOWS
37 RUN = PATH="$(PATH):$(TARGET_RPATH_DIR)" $(RUN_BINFILE)
38 FAIL = PATH="$(PATH):$(TARGET_RPATH_DIR)" $(RUN_BINFILE) && exit 1 || exit 0
39 DYLIB_GLOB = $(1)*.dll
40 DYLIB = $(TMPDIR)/$(1).dll
41 BIN = $(1).exe
42 RPATH_LINK_SEARCH =
43 else
44 RUN = $(TARGET_RPATH_ENV) $(RUN_BINFILE)
45 FAIL = $(TARGET_RPATH_ENV) $(RUN_BINFILE) && exit 1 || exit 0
46 DYLIB_GLOB = lib$(1)*.so
47 DYLIB = $(TMPDIR)/lib$(1).so
48 RPATH_LINK_SEARCH = -Wl,-rpath-link=$(1)
49 endif
50 endif
51
52 # Extra flags needed to compile a working executable with the standard library
53 ifdef IS_WINDOWS
54         EXTRACFLAGS :=
55 else
56 ifeq ($(shell uname),Darwin)
57 else
58 ifeq ($(shell uname),FreeBSD)
59         EXTRACFLAGS := -lm -lpthread -lgcc_s
60 else
61         EXTRACFLAGS := -lm -lrt -ldl -lpthread
62 endif
63 endif
64 endif
65
66 REMOVE_DYLIBS     = rm $(TMPDIR)/$(call DYLIB_GLOB,$(1))
67 REMOVE_RLIBS      = rm $(TMPDIR)/$(call RLIB_GLOB,$(1))
68
69 %.a: %.o
70         ar crus $@ $<
71 %.dylib: %.o
72         $(CC) -dynamiclib -Wl,-dylib -o $@ $<
73 %.so: %.o
74         $(CC) -o $@ $< -shared
75 %.dll: lib%.o
76         $(CC) -o $@ $< -shared
77
78 $(TMPDIR)/lib%.o: %.c
79         $(CC) -c -o $@ $<
80