Makefile 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 ../Scripts/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. rm -rf $(GLIBC_SRC)
  85. tar -xzf $(GLIBC_SRC).tar.gz
  86. cd $(GLIBC_SRC) && \
  87. for p in $(GLIBC_PATCHES); do \
  88. echo applying $$p; \
  89. patch -p1 < ../$$p || exit 255; \
  90. done
  91. touch $@
  92. $(GLIBC_SRC).tar.gz:
  93. ../Scripts/download --output $@ --sha256 $(GLIBC_CHECKSUM) $(foreach mirror,$(GLIBC_MIRRORS),--url $(mirror)glibc/$(GLIBC_SRC).tar.gz)
  94. $(GLIBC_SRC)/elf/Versions: $(GLIBC_SRC)/configure
  95. $(GLIBC_SRC)/nptl/Versions: $(GLIBC_SRC)/configure
  96. $(GLIBC_SRC)/dlfcn/Versions: $(GLIBC_SRC)/configure
  97. .PHONY: clean_
  98. clean_:
  99. rm -rf $(BUILD_DIR) $(GLIBC_SRC) build.log
  100. .PHONY: clean
  101. clean: clean_
  102. $(MAKE) -C $(SHIM_DIR) clean
  103. .PHONY: distclean
  104. distclean: clean_
  105. $(MAKE) -C $(SHIM_DIR) distclean
  106. rm -f $(GLIBC_SRC).tar.gz
  107. else
  108. .IGNORE: $(GLIBC_TARGET)
  109. $(GLIBC_TARGET):
  110. .PHONY: clean
  111. clean:
  112. rm -rf $(BUILD_DIR)
  113. .PHONY: distclean
  114. distclean: clean
  115. endif
  116. .PHONY: test
  117. test:
  118. $(MAKE) -C $(SHIM_DIR) test
  119. .PHONY: sgx-tokens
  120. sgx-tokens:
  121. $(MAKE) -C $(SHIM_DIR) sgx-tokens