Makefile 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. GLIBC_ADDED_FILES = \
  37. $(GLIBC_SRC)/syscallas.S \
  38. $(GLIBC_SRC)/syscalldb.c \
  39. $(GLIBC_SRC)/syscalldb.h \
  40. $(GLIBC_SRC)/elf/syscalldb.c \
  41. $(GLIBC_SRC)/elf/syscallas.S \
  42. $(GLIBC_SRC)/sysdeps/unix/sysv/linux/x86_64/syscalldb.h
  43. $(BUILD_DIR)/Build.success: $(BUILD_DIR)/Makefile $(GLIBC_ADDED_FILES)
  44. @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."
  45. ($(MAKE) -C $(BUILD_DIR) 2>&1 >> build.log) && touch $@
  46. # 2>&1 | tee -a build.log)
  47. $(GLIBC_TARGET): $(BUILD_DIR)/Build.success
  48. $(BUILD_DIR)/Makefile: $(addprefix $(GLIBC_SRC)/,configure elf/Versions nptl/Versions dlfcn/Versions)
  49. ifeq ($(DEBUG),1)
  50. ./buildglibc.py --quiet --debug
  51. else
  52. ./buildglibc.py --quiet
  53. endif
  54. define LN_SF_TO_RUNTIME_DIR_template =
  55. $(RUNTIME_DIR)/$(notdir $(1)): $(1)
  56. $$(call cmd,ln_sf)
  57. endef
  58. $(foreach lib,$(GLIBC_TARGET),$(eval $(call LN_SF_TO_RUNTIME_DIR_template,$(lib))))
  59. GLIBC_MIRRORS ?= https://ftp.gnu.org/gnu/ \
  60. https://mirrors.kernel.org/gnu/ \
  61. https://mirrors.ocf.berkeley.edu/gnu/
  62. ifeq ($(shell git ls-files $(GLIBC_SRC)/configure),)
  63. GLIBC_PATCHES = \
  64. $(GLIBC_SRC).patch \
  65. glibc-fix-warning.patch \
  66. glibc-no-pie.patch \
  67. glibc-liblibos.patch
  68. # USE_clone_FOR_fork = true
  69. ifneq ($(USE_clone_FOR_fork),)
  70. GLIBC_PATCHES += glibc-arch-fork.patch
  71. endif
  72. ifneq ($(filter %.gold,$(shell readlink -f /usr/bin/ld)),)
  73. GLIBC_PATCHES += glibc-ld.gold.patch
  74. endif
  75. $(GLIBC_SRC)/configure: $(GLIBC_PATCHES) Makefile
  76. [ -f $(GLIBC_SRC).tar.gz ] || \
  77. for MIRROR in $(GLIBC_MIRRORS); do \
  78. wget --timeout=10 $${MIRROR}glibc/$(GLIBC_SRC).tar.gz \
  79. && break; \
  80. done
  81. [ "`sha256sum $(GLIBC_SRC).tar.gz`" = "$(GLIBC_CHECKSUM) $(GLIBC_SRC).tar.gz" ] || \
  82. (echo "*** $(GLIBC_SRC).tar.gz has a wrong checksum ***"; exit 255)
  83. tar -xzf $(GLIBC_SRC).tar.gz
  84. cd $(GLIBC_SRC) && \
  85. for p in $(GLIBC_PATCHES); do \
  86. echo applying $$p; \
  87. patch -p1 < ../$$p; \
  88. done
  89. endif
  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