Makefile 2.49 KB
Newer Older
1 2
TARGET?=

Jeremy Soller's avatar
Jeremy Soller committed
3 4 5
CARGO?=cargo
CARGOFLAGS?=

Jeremy Soller's avatar
Jeremy Soller committed
6
BUILD=target
7
ifneq ($(TARGET),)
Jeremy Soller's avatar
Jeremy Soller committed
8
	BUILD="target/$(TARGET)"
9
	CARGOFLAGS+="--target=$(TARGET)"
Jeremy Soller's avatar
Jeremy Soller committed
10 11 12
endif

ifeq ($(TARGET),aarch64-unknown-linux-gnu)
Jeremy Soller's avatar
Jeremy Soller committed
13
	CC?=aarch64-linux-gnu-gcc
Jeremy Soller's avatar
Jeremy Soller committed
14 15 16
endif

ifeq ($(TARGET),x86_64-unknown-redox)
Jeremy Soller's avatar
Jeremy Soller committed
17
	CC?=x86_64-unknown-redox-gcc
18 19
endif

20
SRC=\
Jeremy Soller's avatar
Jeremy Soller committed
21
	Cargo.* \
22 23 24 25 26
	src/* \
	src/*/* \
	src/*/*/* \
	src/*/*/*/*

Jeremy Soller's avatar
Jeremy Soller committed
27
.PHONY: all clean fmt include install libc libm test
Jeremy Soller's avatar
Jeremy Soller committed
28

29
all: | libc libm
Jeremy Soller's avatar
Jeremy Soller committed
30 31

clean:
Jeremy Soller's avatar
Jeremy Soller committed
32
	$(CARGO) clean
Jeremy Soller's avatar
Jeremy Soller committed
33 34
	make -C tests clean

35
check:
Jeremy Soller's avatar
Jeremy Soller committed
36
	$(CARGO) check
37

Jeremy Soller's avatar
Jeremy Soller committed
38 39 40
fmt:
	./fmt.sh

Jeremy Soller's avatar
Jeremy Soller committed
41 42 43 44
install: all
	mkdir -pv "$(DESTDIR)/lib"
	mkdir -pv "$(DESTDIR)/include"
	cp -rv "include"/* "$(DESTDIR)/include"
Jeremy Soller's avatar
Jeremy Soller committed
45
	cp -rv "$(BUILD)/include"/* "$(DESTDIR)/include"
Jeremy Soller's avatar
Jeremy Soller committed
46 47
	cp -v "$(BUILD)/release/libc.a" "$(DESTDIR)/lib"
	cp -v "$(BUILD)/release/crt0.o" "$(DESTDIR)/lib"
jD91mZM2's avatar
jD91mZM2 committed
48 49
	cp -v "$(BUILD)/release/crti.o" "$(DESTDIR)/lib"
	cp -v "$(BUILD)/release/crtn.o" "$(DESTDIR)/lib"
jD91mZM2's avatar
jD91mZM2 committed
50 51
	cp -rv "openlibm/include"/* "$(DESTDIR)/include"
	cp -rv "openlibm/src"/*.h "$(DESTDIR)/include"
jD91mZM2's avatar
jD91mZM2 committed
52
	cp -v "$(BUILD)/openlibm/libopenlibm.a" "$(DESTDIR)/lib/libm.a"
Jeremy Soller's avatar
Jeremy Soller committed
53

jD91mZM2's avatar
jD91mZM2 committed
54
libc: $(BUILD)/release/libc.a $(BUILD)/release/crt0.o $(BUILD)/release/crti.o $(BUILD)/release/crtn.o $(BUILD)/include
Jeremy Soller's avatar
Fix CI  
Jeremy Soller committed
55 56 57

libm: $(BUILD)/openlibm/libopenlibm.a

58
sysroot: all
jD91mZM2's avatar
jD91mZM2 committed
59
	rm -rf $@
60 61 62 63 64 65
	rm -rf $@.partial
	mkdir -p $@.partial
	make install DESTDIR=$@.partial
	mv $@.partial $@
	touch $@

jD91mZM2's avatar
jD91mZM2 committed
66
test: sysroot
Jeremy Soller's avatar
Jeremy Soller committed
67 68
	make -C tests run

69
$(BUILD)/debug/libc.a: $(SRC)
Jeremy Soller's avatar
Jeremy Soller committed
70
	$(CARGO) build $(CARGOFLAGS)
Jeremy Soller's avatar
Jeremy Soller committed
71
	touch $@
72

Jeremy Soller's avatar
Jeremy Soller committed
73
$(BUILD)/debug/crt0.o: $(SRC)
Jeremy Soller's avatar
Jeremy Soller committed
74
	CARGO_INCREMENTAL=0 $(CARGO) rustc --manifest-path src/crt0/Cargo.toml $(CARGOFLAGS) -- --emit obj=$@
Jeremy Soller's avatar
Jeremy Soller committed
75
	touch $@
Jeremy Soller's avatar
Jeremy Soller committed
76

77
$(BUILD)/release/libc.a: $(SRC)
Jeremy Soller's avatar
Jeremy Soller committed
78
	$(CARGO) build --release $(CARGOFLAGS)
Jeremy Soller's avatar
Jeremy Soller committed
79
	touch $@
Jeremy Soller's avatar
Jeremy Soller committed
80

Jeremy Soller's avatar
Jeremy Soller committed
81
$(BUILD)/release/crt0.o: $(SRC)
Jeremy Soller's avatar
Jeremy Soller committed
82
	CARGO_INCREMENTAL=0 $(CARGO) rustc --release --manifest-path src/crt0/Cargo.toml $(CARGOFLAGS) -- --emit obj=$@
Jeremy Soller's avatar
Jeremy Soller committed
83
	touch $@
Jeremy Soller's avatar
Jeremy Soller committed
84

jD91mZM2's avatar
jD91mZM2 committed
85
$(BUILD)/release/crti.o: $(SRC)
Jeremy Soller's avatar
Jeremy Soller committed
86
	CARGO_INCREMENTAL=0 $(CARGO) rustc --release --manifest-path src/crti/Cargo.toml $(CARGOFLAGS) -- --emit obj=$@
jD91mZM2's avatar
jD91mZM2 committed
87 88 89
	touch $@

$(BUILD)/release/crtn.o: $(SRC)
Jeremy Soller's avatar
Jeremy Soller committed
90
	CARGO_INCREMENTAL=0 $(CARGO) rustc --release --manifest-path src/crtn/Cargo.toml $(CARGOFLAGS) -- --emit obj=$@
jD91mZM2's avatar
jD91mZM2 committed
91 92
	touch $@

Jeremy Soller's avatar
Jeremy Soller committed
93 94 95 96 97
$(BUILD)/include: $(SRC)
	rm -rf $@ $@.partial
	mkdir -p $@.partial
	./include.sh $@.partial
	mv $@.partial $@
98
	touch $@
Jeremy Soller's avatar
Jeremy Soller committed
99

100 101
$(BUILD)/openlibm: openlibm
	rm -rf $@ $@.partial
102
	mkdir -p $(BUILD)
103 104
	cp -r $< $@.partial
	mv $@.partial $@
Jeremy Soller's avatar
Jeremy Soller committed
105
	touch $@
Jeremy Soller's avatar
Jeremy Soller committed
106

Jeremy Soller's avatar
Jeremy Soller committed
107
$(BUILD)/openlibm/libopenlibm.a: $(BUILD)/openlibm $(BUILD)/include
Jeremy Soller's avatar
Jeremy Soller committed
108
	make CC=$(CC) CPPFLAGS="-fno-stack-protector -I$(shell pwd)/include -I $(shell pwd)/$(BUILD)/include" -C $< libopenlibm.a