Makefile 3.0 KB

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