Makefile 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. GLIBC_CFLAGS = -O2 -U_FORTIFY_SOURCE -fno-stack-protector -Wno-unused-value
  29. ifeq ($(DEBUG),1)
  30. GLIBC_CFLAGS += -g
  31. endif
  32. export GLIBC_CFLAGS
  33. .PHONY: all
  34. all: $(GLIBC_TARGET) $(GLIBC_RUNTIME)
  35. $(MAKE) -C $(SHIM_DIR) all
  36. include ../Makefile.rules
  37. .PHONY: format
  38. format:
  39. $(MAKE) -C $(SHIM_DIR) format
  40. ifeq ($(findstring x86_64,$(SYS))$(findstring linux,$(SYS)),x86_64linux)
  41. .SECONDARY: $(BUILD_DIR)/Build.success
  42. $(BUILD_DIR)/Build.success: $(BUILD_DIR)/Makefile
  43. @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."
  44. ($(MAKE) -C $(BUILD_DIR) 2>&1 >> build.log) && touch $@
  45. $(GLIBC_TARGET): $(BUILD_DIR)/Build.success
  46. $(BUILD_DIR)/Makefile: $(GLIBC_SRC)/configure
  47. mkdir -p $(BUILD_DIR)
  48. (cd $(BUILD_DIR) || exit 1; \
  49. CFLAGS=$$GLIBC_CFLAGS ../$< --prefix=$(RUNTIME_DIR) \
  50. --with-tls \
  51. --without-selinux \
  52. --disable-test \
  53. --disable-nscd \
  54. )
  55. define LN_SF_TO_RUNTIME_DIR_template =
  56. $(RUNTIME_DIR)/$(notdir $(1)): $(1)
  57. $$(call cmd,ln_sf)
  58. endef
  59. $(foreach lib,$(GLIBC_TARGET),$(eval $(call LN_SF_TO_RUNTIME_DIR_template,$(lib))))
  60. GLIBC_MIRRORS ?= https://ftp.gnu.org/gnu/ \
  61. https://mirrors.kernel.org/gnu/ \
  62. https://mirrors.ocf.berkeley.edu/gnu/
  63. GLIBC_PATCHES = \
  64. glibc-patches/$(GLIBC_SRC).patch \
  65. glibc-patches/syscalldb-api.patch \
  66. glibc-patches/liblibos.patch \
  67. glibc-patches/malloc-arena-size.patch
  68. GLIBC_PATCHES_2.23 = \
  69. glibc-patches/liblibos-2.23+.patch \
  70. glibc-patches/hp-timing-2.23+.patch \
  71. glibc-patches/dangling-else.patch \
  72. glibc-patches/cvs-common-symbols.patch \
  73. glibc-patches/rpc-format-overflow.patch \
  74. glibc-patches/ieee754-boolean-context.patch \
  75. glibc-patches/nis-bogus-conditional.patch
  76. GLIBC_PATCHES_2.27 = \
  77. glibc-patches/liblibos-2.23+.patch \
  78. glibc-patches/hp-timing-2.23+.patch
  79. ifneq ($(filter %.gold,$(shell readlink -f /usr/bin/ld)),)
  80. GLIBC_PATCHES += glibc-patches/ld-gold.patch
  81. endif
  82. GLIBC_PATCHES += $(GLIBC_PATCHES_$(GLIBC_VERSION))
  83. $(GLIBC_SRC)/configure: $(GLIBC_PATCHES) $(GLIBC_SRC).tar.gz
  84. [ "`sha256sum $(GLIBC_SRC).tar.gz`" = "$(GLIBC_CHECKSUM) $(GLIBC_SRC).tar.gz" ] || \
  85. (echo "*** $(GLIBC_SRC).tar.gz has a wrong checksum ***"; exit 255)
  86. rm -rf $(GLIBC_SRC)
  87. tar -xzf $(GLIBC_SRC).tar.gz
  88. cd $(GLIBC_SRC) && \
  89. for p in $(GLIBC_PATCHES); do \
  90. echo applying $$p; \
  91. patch -p1 < ../$$p || exit 255; \
  92. done
  93. touch $@
  94. $(GLIBC_SRC).tar.gz:
  95. for MIRROR in $(GLIBC_MIRRORS); do \
  96. wget --timeout=10 $${MIRROR}glibc/$(GLIBC_SRC).tar.gz \
  97. && break; \
  98. done
  99. $(GLIBC_SRC)/elf/Versions: $(GLIBC_SRC)/configure
  100. $(GLIBC_SRC)/nptl/Versions: $(GLIBC_SRC)/configure
  101. $(GLIBC_SRC)/dlfcn/Versions: $(GLIBC_SRC)/configure
  102. .PHONY: clean
  103. clean:
  104. $(MAKE) -C $(SHIM_DIR) clean
  105. rm -rf $(BUILD_DIR) $(GLIBC_SRC) build.log
  106. else
  107. .IGNORE: $(GLIBC_TARGET)
  108. $(GLIBC_TARGET):
  109. .PHONY: clean
  110. clean:
  111. rm -rf $(BUILD_DIR)
  112. endif
  113. .PHONY: test
  114. test:
  115. $(MAKE) -C $(SHIM_DIR) test
  116. .PHONY: sgx-tokens
  117. sgx-tokens:
  118. $(MAKE) -C $(SHIM_DIR) sgx-tokens