Makefile 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. # USE_clone_FOR_fork = true
  74. ifneq ($(USE_clone_FOR_fork),)
  75. GLIBC_PATCHES += glibc-arch-fork.patch
  76. endif
  77. $(GLIBC_SRC)/configure: $(GLIBC_PATCHES) Makefile
  78. [ -f $(GLIBC_SRC).tar.gz ] || \
  79. for MIRROR in $(GLIBC_MIRRORS); do \
  80. wget --timeout=10 $${MIRROR}glibc/$(GLIBC_SRC).tar.gz \
  81. && break; \
  82. done
  83. [ "`sha256sum $(GLIBC_SRC).tar.gz`" = "$(GLIBC_CHECKSUM) $(GLIBC_SRC).tar.gz" ] || \
  84. (echo "*** $(GLIBC_SRC).tar.gz has a wrong checksum ***"; exit 255)
  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; \
  90. done
  91. endif
  92. .PHONY: clean
  93. clean:
  94. $(MAKE) -C $(SHIM_DIR) clean
  95. rm -rf $(BUILD_DIR)
  96. else
  97. .IGNORE: $(GLIBC_TARGET)
  98. $(GLIBC_TARGET):
  99. .PHONY: clean
  100. clean:
  101. rm -rf $(BUILD_DIR)
  102. endif