-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
46 lines (35 loc) · 1.21 KB
/
Copy pathMakefile
File metadata and controls
46 lines (35 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Build helpers for rustlibc.
#
# make lib build the static + shared libs (release) for $(ARCH)
# make hello build examples/hello.c linked against the static lib
# make run build and run the hello example
# make test run the Rust unit tests
# make clean remove build artifacts
#
# Cross-compile by overriding ARCH, e.g.:
# make hello ARCH=aarch64-unknown-linux-gnu
ARCH ?= x86_64-unknown-linux-gnu
PROFILE ?= release
LIBDIR := target/$(ARCH)/$(PROFILE)
STATICLIB := $(LIBDIR)/librustlibc.a
# Freestanding link: no system headers, no system libc, no system crt — rustlibc
# provides the headers (-Iinclude), the C functions, and _start.
CFLAGS := -nostdinc -Iinclude -Wall -O2
LDFLAGS := -nostdlib -nostartfiles -no-pie -static
.PHONY: all lib hello sysprobe run test clean
all: lib
lib:
cargo build --$(PROFILE) --target $(ARCH)
$(STATICLIB): lib
hello: examples/hello.c $(STATICLIB)
cc $(CFLAGS) $(LDFLAGS) $< $(STATICLIB) -o hello
sysprobe: examples/sysprobe.c $(STATICLIB)
cc $(CFLAGS) $(LDFLAGS) $< $(STATICLIB) -o sysprobe
run: hello sysprobe
@echo "=== hello ==="; ./hello
@echo "=== sysprobe ==="; ./sysprobe
test:
cargo test --lib
clean:
cargo clean
rm -f hello sysprobe