Makefile 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. SYS ?= $(shell gcc -dumpmachine)
  2. export SYS
  3. export DEBUG
  4. GLIBC_SRC = glibc-2.19
  5. GLIBC_CHECKSUM = 18ad6db70724699d264add80b1f813630d0141cf3a3558b4e1a7c15f6beac796
  6. SHIM_DIR = shim
  7. BUILD_DIR = glibc-build
  8. RUNTIME_DIR = $(CURDIR)/../Runtime
  9. GLIBC_LIBS = \
  10. csu/crt1.o \
  11. csu/crti.o \
  12. csu/crtn.o \
  13. dlfcn/libdl.so.2 \
  14. elf/ld-linux-x86-64.so.2 \
  15. libc.so \
  16. libc.so.6 \
  17. libos/liblibos.so.1 \
  18. login/libutil.so.1 \
  19. math/libm.so.6 \
  20. nptl/libpthread.so.0 \
  21. nptl_db/libthread_db.so.1 \
  22. resolv/libnss_dns.so.2 \
  23. resolv/libresolv.so.2 \
  24. rt/librt.so.1
  25. GLIBC_TARGET = $(addprefix $(BUILD_DIR)/, $(GLIBC_LIBS))
  26. GLIBC_RUNTIME = $(addprefix $(RUNTIME_DIR)/, $(notdir $(GLIBC_TARGET)))
  27. .PHONY: all
  28. all: $(GLIBC_TARGET) $(GLIBC_RUNTIME)
  29. $(MAKE) -C $(SHIM_DIR) all
  30. include ../Makefile.rules
  31. .PHONY: format
  32. format:
  33. $(MAKE) -C $(SHIM_DIR) format
  34. ifeq ($(findstring x86_64,$(SYS))$(findstring linux,$(SYS)),x86_64linux)
  35. .SECONDARY: $(BUILD_DIR)/Build.success
  36. $(BUILD_DIR)/Build.success: $(BUILD_DIR)/Makefile
  37. @echo "Building glibc, may take a while to finish. Warning messages may show up. If this process terminates with failures, see \"$(BUILD_DIR)/build.log\" for more information."
  38. ($(MAKE) PARALLELMFLAGS='-j `nproc`' -C $(BUILD_DIR) 2>&1 >> build.log) && touch $@
  39. # 2>&1 | tee -a build.log)
  40. $(GLIBC_TARGET): $(BUILD_DIR)/Build.success
  41. $(BUILD_DIR)/Makefile: $(GLIBC_SRC)/configure
  42. ifeq ($(DEBUG),1)
  43. ./buildglibc.py --quiet --debug
  44. else
  45. ./buildglibc.py --quiet
  46. endif
  47. define LN_SF_TO_RUNTIME_DIR_template =
  48. $(RUNTIME_DIR)/$(notdir $(1)): $(1)
  49. $$(call cmd,ln_sf)
  50. endef
  51. $(foreach lib,$(GLIBC_TARGET),$(eval $(call LN_SF_TO_RUNTIME_DIR_template,$(lib))))
  52. GLIBC_MIRRORS ?= https://ftp.gnu.org/gnu/ \
  53. https://mirrors.kernel.org/gnu/ \
  54. https://mirrors.ocf.berkeley.edu/gnu/
  55. ifeq ($(shell git ls-files $(GLIBC_SRC)/configure),)
  56. GLIBC_PATCHES = \
  57. $(GLIBC_SRC).patch \
  58. glibc-syscalldb-api.patch \
  59. glibc-fix-warning.patch \
  60. glibc-no-pie.patch \
  61. glibc-liblibos.patch
  62. ifneq ($(filter %.gold,$(shell readlink -f /usr/bin/ld)),)
  63. GLIBC_PATCHES += glibc-ld.gold.patch
  64. endif
  65. $(GLIBC_SRC)/configure: $(GLIBC_PATCHES) $(GLIBC_SRC).tar.gz
  66. [ "`sha256sum $(GLIBC_SRC).tar.gz`" = "$(GLIBC_CHECKSUM) $(GLIBC_SRC).tar.gz" ] || \
  67. (echo "*** $(GLIBC_SRC).tar.gz has a wrong checksum ***"; exit 255)
  68. rm -rf $(GLIBC_SRC)
  69. tar -xzf $(GLIBC_SRC).tar.gz
  70. cd $(GLIBC_SRC) && \
  71. for p in $(GLIBC_PATCHES); do \
  72. echo applying $$p; \
  73. patch -p1 < ../$$p || exit 255; \
  74. done
  75. touch $@
  76. endif
  77. $(GLIBC_SRC).tar.gz:
  78. for MIRROR in $(GLIBC_MIRRORS); do \
  79. wget --timeout=10 $${MIRROR}glibc/$(GLIBC_SRC).tar.gz \
  80. && break; \
  81. done
  82. $(GLIBC_SRC)/elf/Versions: $(GLIBC_SRC)/configure
  83. $(GLIBC_SRC)/nptl/Versions: $(GLIBC_SRC)/configure
  84. $(GLIBC_SRC)/dlfcn/Versions: $(GLIBC_SRC)/configure
  85. .PHONY: clean
  86. clean:
  87. $(MAKE) -C $(SHIM_DIR) clean
  88. rm -rf $(BUILD_DIR)
  89. else
  90. .IGNORE: $(GLIBC_TARGET)
  91. $(GLIBC_TARGET):
  92. .PHONY: clean
  93. clean:
  94. rm -rf $(BUILD_DIR)
  95. endif
  96. .PHONY: test
  97. test:
  98. $(MAKE) -C $(SHIM_DIR) test