Makefile 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. SYS ?= $(shell gcc -dumpmachine)
  2. export SYS
  3. export DEBUG
  4. GLIBC_VERSION ?= 2.27
  5. GLIBC_SRC = glibc-$(GLIBC_VERSION)
  6. GLIBC_CHECKSUM = $(firstword $(shell grep $(GLIBC_SRC).tar.gz glibc-checksums))
  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) -C $(BUILD_DIR) 2>&1 >> build.log) && touch $@
  40. $(GLIBC_TARGET): $(BUILD_DIR)/Build.success
  41. $(BUILD_DIR)/Makefile: $(GLIBC_SRC)/configure
  42. ifeq ($(DEBUG),1)
  43. ./buildglibc.py --src $(GLIBC_SRC) --quiet --debug
  44. else
  45. ./buildglibc.py --src $(GLIBC_SRC) --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. GLIBC_PATCHES = \
  56. glibc-patches/$(GLIBC_SRC).patch \
  57. glibc-patches/syscalldb-api.patch \
  58. glibc-patches/liblibos.patch \
  59. glibc-patches/malloc-arena-size.patch
  60. GLIBC_PATCHES_2.19 = \
  61. glibc-patches/fix-make-warnings.patch \
  62. glibc-patches/no-pie.patch \
  63. glibc-patches/liblibos-2.19.patch \
  64. glibc-patches/hp-timing-2.19.patch
  65. GLIBC_PATCHES_2.23 = \
  66. glibc-patches/liblibos-2.23+.patch \
  67. glibc-patches/hp-timing-2.23+.patch \
  68. glibc-patches/dangling-else.patch \
  69. glibc-patches/cvs-common-symbols.patch \
  70. glibc-patches/rpc-format-overflow.patch \
  71. glibc-patches/ieee754-boolean-context.patch \
  72. glibc-patches/nis-bogus-conditional.patch
  73. GLIBC_PATCHES_2.27 = \
  74. glibc-patches/liblibos-2.23+.patch \
  75. glibc-patches/hp-timing-2.23+.patch
  76. ifeq ($(GLIBC_DISABLE_VDSO),true)
  77. GLIBC_PATCHES_2.19 += \
  78. glibc-patches/glibc-2.19-remove-vdso.patch
  79. endif
  80. ifneq ($(filter %.gold,$(shell readlink -f /usr/bin/ld)),)
  81. GLIBC_PATCHES += glibc-patches/ld-gold.patch
  82. endif
  83. GLIBC_PATCHES += $(GLIBC_PATCHES_$(GLIBC_VERSION))
  84. $(GLIBC_SRC)/configure: $(GLIBC_PATCHES) $(GLIBC_SRC).tar.gz
  85. [ "`sha256sum $(GLIBC_SRC).tar.gz`" = "$(GLIBC_CHECKSUM) $(GLIBC_SRC).tar.gz" ] || \
  86. (echo "*** $(GLIBC_SRC).tar.gz has a wrong checksum ***"; exit 255)
  87. rm -rf $(GLIBC_SRC)
  88. tar -xzf $(GLIBC_SRC).tar.gz
  89. cd $(GLIBC_SRC) && \
  90. for p in $(GLIBC_PATCHES); do \
  91. echo applying $$p; \
  92. patch -p1 < ../$$p || exit 255; \
  93. done
  94. touch $@
  95. $(GLIBC_SRC).tar.gz:
  96. for MIRROR in $(GLIBC_MIRRORS); do \
  97. wget --timeout=10 $${MIRROR}glibc/$(GLIBC_SRC).tar.gz \
  98. && break; \
  99. done
  100. $(GLIBC_SRC)/elf/Versions: $(GLIBC_SRC)/configure
  101. $(GLIBC_SRC)/nptl/Versions: $(GLIBC_SRC)/configure
  102. $(GLIBC_SRC)/dlfcn/Versions: $(GLIBC_SRC)/configure
  103. .PHONY: clean
  104. clean:
  105. $(MAKE) -C $(SHIM_DIR) clean
  106. rm -rf $(BUILD_DIR) $(GLIBC_SRC) build.log
  107. else
  108. .IGNORE: $(GLIBC_TARGET)
  109. $(GLIBC_TARGET):
  110. .PHONY: clean
  111. clean:
  112. rm -rf $(BUILD_DIR)
  113. endif
  114. .PHONY: test
  115. test:
  116. $(MAKE) -C $(SHIM_DIR) test
  117. .PHONY: sgx-tokens
  118. sgx-tokens:
  119. $(MAKE) -C $(SHIM_DIR) sgx-tokens