Makefile 3.7 KB

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