Makefile 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. SYS ?= $(shell gcc -dumpmachine)
  2. export SYS
  3. export DEBUG
  4. GLIBC_SRC = glibc-2.19
  5. GLIBC_CHECKSUM = 18ad6db70724699d264add80b1f813630d0141cf3a3558b4e1a7c15f6beac796
  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. .PHONY: all
  28. all: $(GLIBC_TARGET) $(GLIBC_RUNTIME)
  29. $(MAKE) -C $(SHIM_DIR) all
  30. include ../Makefile.rules
  31. .PHONY: format
  32. format:
  33. $(MAKE) -C $(SHIM_DIR) format
  34. ifeq ($(findstring x86_64,$(SYS))$(findstring linux,$(SYS)),x86_64linux)
  35. .SECONDARY: $(BUILD_DIR)/Build.success
  36. GLIBC_ADDED_FILES = \
  37. $(GLIBC_SRC)/syscallas.S \
  38. $(GLIBC_SRC)/syscalldb.c \
  39. $(GLIBC_SRC)/syscalldb.h \
  40. $(GLIBC_SRC)/libos/Makefile \
  41. $(GLIBC_SRC)/libos/Versions \
  42. $(GLIBC_SRC)/libos/benchmark.c \
  43. $(GLIBC_SRC)/libos/checkpoint.c \
  44. $(GLIBC_SRC)/libos/msgpersist.c \
  45. $(GLIBC_SRC)/libos/sandbox.c \
  46. $(GLIBC_SRC)/elf/syscalldb.c \
  47. $(GLIBC_SRC)/elf/syscallas.S \
  48. $(GLIBC_SRC)/sysdeps/unix/sysv/linux/x86_64/syscalldb.h
  49. $(BUILD_DIR)/Build.success: $(BUILD_DIR)/Makefile $(GLIBC_ADDED_FILES)
  50. @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."
  51. ($(MAKE) -C $(BUILD_DIR) 2>&1 >> build.log) && touch $@
  52. # 2>&1 | tee -a build.log)
  53. $(GLIBC_TARGET): $(BUILD_DIR)/Build.success
  54. $(BUILD_DIR)/Makefile: $(addprefix $(GLIBC_SRC)/,configure elf/Versions nptl/Versions dlfcn/Versions)
  55. ifeq ($(DEBUG),1)
  56. ./buildglibc.py --quiet --debug
  57. else
  58. ./buildglibc.py --quiet
  59. endif
  60. define LN_SF_TO_RUNTIME_DIR_template =
  61. $(RUNTIME_DIR)/$(notdir $(1)): $(1)
  62. $$(call cmd,ln_sf)
  63. endef
  64. $(foreach lib,$(GLIBC_TARGET),$(eval $(call LN_SF_TO_RUNTIME_DIR_template,$(lib))))
  65. GLIBC_MIRRORS ?= https://ftp.gnu.org/gnu/ \
  66. https://mirrors.kernel.org/gnu/ \
  67. https://mirrors.ocf.berkeley.edu/gnu/
  68. ifeq ($(shell git ls-files $(GLIBC_SRC)/configure),)
  69. GLIBC_PATCHES = \
  70. $(GLIBC_SRC).patch \
  71. glibc-fix-warning.patch \
  72. glibc-no-pie.patch
  73. $(GLIBC_SRC)/configure: $(GLIBC_PATCHES) Makefile
  74. [ -f $(GLIBC_SRC).tar.gz ] || \
  75. for MIRROR in $(GLIBC_MIRRORS); do \
  76. wget --timeout=10 $${MIRROR}glibc/$(GLIBC_SRC).tar.gz \
  77. && break; \
  78. done
  79. [ "`sha256sum $(GLIBC_SRC).tar.gz`" = "$(GLIBC_CHECKSUM) $(GLIBC_SRC).tar.gz" ] || \
  80. (echo "*** $(GLIBC_SRC).tar.gz has a wrong checksum ***"; exit 255)
  81. tar -xzf $(GLIBC_SRC).tar.gz
  82. cd $(GLIBC_SRC) && \
  83. for p in $(GLIBC_PATCHES); do \
  84. echo applying $$p; \
  85. patch -p1 < ../$$p; \
  86. done
  87. endif
  88. .PHONY: clean
  89. clean:
  90. $(MAKE) -C $(SHIM_DIR) clean
  91. rm -rf $(BUILD_DIR)
  92. else
  93. .IGNORE: $(GLIBC_TARGET)
  94. $(GLIBC_TARGET):
  95. .PHONY: clean
  96. clean:
  97. rm -rf $(BUILD_DIR)
  98. endif