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