Makefile 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. include ../Scripts/Makefile.configs
  2. include ../Scripts/Makefile.rules
  3. include ../Pal/src/Makefile.Host
  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. .PHONY: format
  37. format:
  38. $(MAKE) -C $(SHIM_DIR) format
  39. ifeq ($(findstring x86_64,$(SYS))$(findstring linux,$(SYS)),x86_64linux)
  40. .SECONDARY: $(BUILD_DIR)/Build.success
  41. $(BUILD_DIR)/Build.success: $(BUILD_DIR)/Makefile
  42. @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."
  43. ($(MAKE) -C $(BUILD_DIR) 2>&1 >> build.log) && touch $@
  44. $(GLIBC_TARGET): $(BUILD_DIR)/Build.success
  45. $(BUILD_DIR)/Makefile: $(GLIBC_SRC)/configure
  46. mkdir -p $(BUILD_DIR)
  47. (cd $(BUILD_DIR) || exit 1; \
  48. CFLAGS=$$GLIBC_CFLAGS ../$< --prefix=$(RUNTIME_DIR) \
  49. --with-tls \
  50. --without-selinux \
  51. --disable-test \
  52. --disable-nscd \
  53. )
  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. GLIBC_PATCHES = \
  63. glibc-patches/$(GLIBC_SRC).patch \
  64. glibc-patches/syscalldb-api.patch \
  65. glibc-patches/liblibos.patch \
  66. glibc-patches/malloc-arena-size.patch
  67. GLIBC_PATCHES_2.23 = \
  68. glibc-patches/liblibos-2.23+.patch \
  69. glibc-patches/hp-timing-2.23+.patch \
  70. glibc-patches/dangling-else.patch \
  71. glibc-patches/cvs-common-symbols.patch \
  72. glibc-patches/rpc-format-overflow.patch \
  73. glibc-patches/ieee754-boolean-context.patch \
  74. glibc-patches/nis-bogus-conditional.patch
  75. GLIBC_PATCHES_2.27 = \
  76. glibc-patches/liblibos-2.23+.patch \
  77. glibc-patches/hp-timing-2.23+.patch
  78. ifneq ($(filter %.gold,$(shell readlink -f /usr/bin/ld)),)
  79. GLIBC_PATCHES += glibc-patches/ld-gold.patch
  80. endif
  81. GLIBC_PATCHES += $(GLIBC_PATCHES_$(GLIBC_VERSION))
  82. $(GLIBC_SRC)/configure: $(GLIBC_PATCHES) $(GLIBC_SRC).tar.gz
  83. rm -rf $(GLIBC_SRC)
  84. tar -xzf $(GLIBC_SRC).tar.gz
  85. cd $(GLIBC_SRC) && \
  86. for p in $(GLIBC_PATCHES); do \
  87. echo applying $$p; \
  88. patch -p1 < ../$$p || exit 255; \
  89. done
  90. touch $@
  91. $(GLIBC_SRC).tar.gz:
  92. ../Scripts/download --output $@ --sha256 $(GLIBC_CHECKSUM) $(foreach mirror,$(GLIBC_MIRRORS),--url $(mirror)glibc/$(GLIBC_SRC).tar.gz)
  93. $(GLIBC_SRC)/elf/Versions: $(GLIBC_SRC)/configure
  94. $(GLIBC_SRC)/nptl/Versions: $(GLIBC_SRC)/configure
  95. $(GLIBC_SRC)/dlfcn/Versions: $(GLIBC_SRC)/configure
  96. .PHONY: clean_
  97. clean_:
  98. rm -rf $(BUILD_DIR) $(GLIBC_SRC) build.log
  99. .PHONY: clean
  100. clean: clean_
  101. $(MAKE) -C $(SHIM_DIR) clean
  102. .PHONY: distclean
  103. distclean: clean_
  104. $(MAKE) -C $(SHIM_DIR) distclean
  105. rm -f $(GLIBC_SRC).tar.gz
  106. else
  107. .IGNORE: $(GLIBC_TARGET)
  108. $(GLIBC_TARGET):
  109. .PHONY: clean
  110. clean:
  111. rm -rf $(BUILD_DIR)
  112. .PHONY: distclean
  113. distclean: clean
  114. endif
  115. .PHONY: test
  116. test:
  117. $(MAKE) -C $(SHIM_DIR) test
  118. .PHONY: sgx-tokens
  119. sgx-tokens:
  120. $(MAKE) -C $(SHIM_DIR) sgx-tokens