Makefile 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. TARGET?=
  2. CARGO?=cargo
  3. CARGOFLAGS=
  4. RUSTCFLAGS=
  5. BUILD=target
  6. ifneq ($(TARGET),)
  7. BUILD="target/$(TARGET)"
  8. CARGOFLAGS="--target=$(TARGET)"
  9. endif
  10. ifeq ($(TARGET),aarch64-unknown-linux-gnu)
  11. export CC=aarch64-linux-gnu-gcc
  12. endif
  13. ifeq ($(TARGET),aarch64-unknown-redox)
  14. export CC=aarch64-unknown-redox-gcc
  15. endif
  16. ifeq ($(TARGET),x86_64-unknown-redox)
  17. export CC=x86_64-unknown-redox-gcc
  18. endif
  19. SRC=\
  20. Cargo.* \
  21. src/* \
  22. src/*/* \
  23. src/*/*/* \
  24. src/*/*/*/*
  25. .PHONY: all clean fmt include install libc libm test
  26. all: | libc libm libpthread
  27. clean:
  28. $(CARGO) clean
  29. make -C tests clean
  30. rm -rf sysroot
  31. check:
  32. $(CARGO) check
  33. fmt:
  34. ./fmt.sh
  35. install: all
  36. mkdir -pv "$(DESTDIR)/include"
  37. cp -rv "include"/* "$(DESTDIR)/include"
  38. cp -rv "$(BUILD)/include"/* "$(DESTDIR)/include"
  39. cp -v "openlibm/include"/*.h "$(DESTDIR)/include"
  40. cp -v "openlibm/src"/*.h "$(DESTDIR)/include"
  41. cp -v "pthreads-emb/"*.h "$(DESTDIR)/include"
  42. mkdir -pv "$(DESTDIR)/lib"
  43. cp -v "$(BUILD)/release/libc.a" "$(DESTDIR)/lib"
  44. cp -v "$(BUILD)/release/crt0.o" "$(DESTDIR)/lib"
  45. cp -v "$(BUILD)/release/crti.o" "$(DESTDIR)/lib"
  46. cp -v "$(BUILD)/release/crtn.o" "$(DESTDIR)/lib"
  47. cp -v "$(BUILD)/openlibm/libopenlibm.a" "$(DESTDIR)/lib/libm.a"
  48. cp -v "$(BUILD)/pthreads-emb/libpthread.a" "$(DESTDIR)/lib/libpthread.a"
  49. libc: $(BUILD)/release/libc.a $(BUILD)/release/crt0.o $(BUILD)/release/crti.o $(BUILD)/release/crtn.o $(BUILD)/include
  50. libm: $(BUILD)/openlibm/libopenlibm.a
  51. libpthread: $(BUILD)/pthreads-emb/libpthread.a
  52. sysroot: all
  53. rm -rf $@
  54. rm -rf $@.partial
  55. mkdir -p $@.partial
  56. make install DESTDIR=$@.partial
  57. mv $@.partial $@
  58. touch $@
  59. test: sysroot
  60. make -C tests run
  61. $(BUILD)/debug/libc.a: $(SRC)
  62. $(CARGO) rustc $(CARGOFLAGS) -- $(RUSTCFLAGS)
  63. touch $@
  64. $(BUILD)/debug/crt0.o: $(SRC)
  65. CARGO_INCREMENTAL=0 $(CARGO) rustc --manifest-path src/crt0/Cargo.toml $(CARGOFLAGS) -- --emit obj=$@ $(RUSTCFLAGS)
  66. touch $@
  67. $(BUILD)/release/libc.a: $(SRC)
  68. $(CARGO) rustc --release $(CARGOFLAGS) -- $(RUSTCFLAGS)
  69. touch $@
  70. $(BUILD)/release/crt0.o: $(SRC)
  71. CARGO_INCREMENTAL=0 $(CARGO) rustc --release --manifest-path src/crt0/Cargo.toml $(CARGOFLAGS) -- --emit obj=$@ $(RUSTCFLAGS)
  72. touch $@
  73. $(BUILD)/release/crti.o: $(SRC)
  74. CARGO_INCREMENTAL=0 $(CARGO) rustc --release --manifest-path src/crti/Cargo.toml $(CARGOFLAGS) -- --emit obj=$@ $(RUSTCFLAGS)
  75. touch $@
  76. $(BUILD)/release/crtn.o: $(SRC)
  77. CARGO_INCREMENTAL=0 $(CARGO) rustc --release --manifest-path src/crtn/Cargo.toml $(CARGOFLAGS) -- --emit obj=$@ $(RUSTCFLAGS)
  78. touch $@
  79. $(BUILD)/include: $(SRC)
  80. rm -rf $@ $@.partial
  81. mkdir -p $@.partial
  82. ./include.sh $@.partial
  83. mv $@.partial $@
  84. touch $@
  85. $(BUILD)/openlibm: openlibm
  86. rm -rf $@ $@.partial
  87. mkdir -p $(BUILD)
  88. cp -r $< $@.partial
  89. mv $@.partial $@
  90. touch $@
  91. $(BUILD)/openlibm/libopenlibm.a: $(BUILD)/openlibm $(BUILD)/include
  92. make CC=$(CC) CPPFLAGS="-fno-stack-protector -I$(shell pwd)/include -I $(shell pwd)/$(BUILD)/include" -C $< libopenlibm.a
  93. $(BUILD)/pthreads-emb: pthreads-emb
  94. rm -rf $@ $@.partial
  95. mkdir -p $(BUILD)
  96. cp -r $< $@.partial
  97. mv $@.partial $@
  98. touch $@
  99. $(BUILD)/pthreads-emb/libpthread.a: $(BUILD)/pthreads-emb $(BUILD)/include
  100. make CC=$(CC) CFLAGS="-fno-stack-protector -I$(shell pwd)/include -I $(shell pwd)/$(BUILD)/include" -C $< libpthread.a