Makefile 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. RUNTIME_DIR = $(CURDIR)/../../../Runtime
  2. SYS ?= $(shell gcc -dumpmachine)
  3. export SYS
  4. CC = gcc
  5. AS = gcc
  6. AR = ar rcs
  7. LD = ld
  8. OMIT_FRAME_POINTER = no
  9. CFLAGS = -Wall -fPIC -std=gnu99 -fgnu89-inline -Winline -Wwrite-strings \
  10. -fmerge-all-constants -Wstrict-prototypes \
  11. -Werror=implicit-function-declaration \
  12. -fno-stack-protector -fno-builtin -Wno-inline \
  13. -I../include -I../../../Pal/lib -I../../../Pal/include/pal
  14. ifeq ($(OMIT_FRAME_POINTER),yes)
  15. CFLAGS += -DOMIT_FRAME_POINTER=1
  16. else
  17. CFLAGS += -fno-omit-frame-pointer -DOMIT_FRAME_POINTER=0
  18. endif
  19. ASFLAGS = -Wa,--noexecstack -x assembler-with-cpp -I../include
  20. LDFLAGS = -shared -nostdlib --version-script shim.map -T shim.lds \
  21. -z combreloc -z relro -z defs \
  22. -dynamic-link=libpal.so \
  23. -rpath-link=$(abspath ../../../Pal/src)
  24. LDFLAGS-debug = $(patsubst shim.map,shim-debug.map,$(LDFLAGS))
  25. ARFLAGS =
  26. files_to_build = libsysdb.a libsysdb.so libsysdb_debug.so
  27. files_to_install = $(addprefix $(RUNTIME_DIR)/,$(files_to_build))
  28. defs = -DIN_SHIM
  29. fs = chroot str pipe socket proc dev
  30. ipcns = pid sysv
  31. objs = $(addprefix bookkeep/shim_,handle vma thread signal) \
  32. $(patsubst %.c,%,$(wildcard utils/*.c)) \
  33. $(addprefix fs/shim_,dcache namei fs_hash fs) \
  34. $(patsubst %.c,%,$(foreach f,$(fs),$(wildcard fs/$(f)/*.c))) \
  35. $(addprefix ipc/shim_,ipc ipc_helper ipc_child) \
  36. $(addprefix ipc/shim_ipc_,$(ipcns)) \
  37. elf/shim_rtld \
  38. $(addprefix shim_,init table syscalls checkpoint random malloc \
  39. async parser debug) syscallas start \
  40. $(patsubst %.c,%,$(wildcard sys/*.c))
  41. graphene_lib = .lib/graphene-lib.a
  42. pal_lib = $(abspath ../../../Pal/src/libpal.so)
  43. headers = ../include/*.h ../../../Pal/lib/*.h ../../../Pal/include/pal/*.h
  44. all: $(files_to_build) $(files_to_install)
  45. ifeq ($(DEBUG),1)
  46. CC += -gdwarf-2 -g3
  47. CFLAGS += -DDEBUG
  48. ASFLAGS += -DDEBUG
  49. endif
  50. export DEBUG
  51. ifeq ($(PROFILING), 1)
  52. CFLAGS += -DPROFILE
  53. endif
  54. $(files_to_install): $(RUNTIME_DIR)/%: %
  55. cp -f $< $@
  56. ifeq ($(SYS),x86_64-linux-gnu)
  57. libsysdb.so: $(addsuffix .o,$(objs)) $(filter %.map %.lds,$(LDFLAGS)) \
  58. $(graphene_lib) $(pal_lib)
  59. @echo [ $@ ]
  60. $(LD) $(LDFLAGS) -o $@ $(filter-out %.map %.lds,$^) -soname $@ \
  61. -e shim_start
  62. libsysdb_debug.so: $(addsuffix .o,$(filter-out syscallas,$(objs))) \
  63. $(filter %.map %.lds,$($LDFLAGS-debug)) \
  64. $(graphene_lib) $(pal_lib)
  65. @echo [ $@ ]
  66. $(LD) $(LDFLAGS-debug) -o $@ $(filter-out %.map %.lds,$^) -soname $@ \
  67. -e shim_start
  68. .PHONY: $(graphene_lib)
  69. $(graphene_lib):
  70. $(MAKE) -C ../../../Pal/lib $(debug) target=$(shell pwd)/.lib/
  71. libsysdb.a: $(addsuffix .o,$(objs))
  72. @echo [ $@ ]
  73. $(AR) $(ARFLAGS) $@ $^
  74. .PHONY: pack
  75. pack: $(shim_target) $(addsuffix .o,$(objs))
  76. @../../../Scripts/pack_binaries.sh shim $^
  77. else
  78. $(shim_target): .packed/shim.tar.gz
  79. tar -xmozf $< $@
  80. endif
  81. %.asm: %.c $(headers)
  82. @echo [ $@ ]
  83. @$(CC) $(CFLAGS) $(defs) -c $< -o $<.o
  84. @objdump -S $<.o > $@
  85. @rm $<.o
  86. $(addsuffix .o,$(addprefix ipc/shim_ipc_,$(ipcns))): $(wildcard ipc/*.h)
  87. elf/shim_rtld.o: $(wildcard elf/*.h)
  88. %.o: %.c $(headers)
  89. @echo [ $@ ]
  90. @$(CC) $(CFLAGS) $(defs) -c $< -o $@
  91. %.e: %.c $(headers)
  92. @echo [ $@ ]
  93. @$(CC) $(CFLAGS) $(defs) -E $< -o $@
  94. %.o: %.S $(headers)
  95. @echo [ $@ ]
  96. @$(AS) $(ASFLAGS) $(defs) -c $< -o $@
  97. %.e: %.S $(headers)
  98. @echo [ $@ ]
  99. @$(AS) $(ASFLAGS) $(defs) -E $< -o $@
  100. clean:
  101. rm -rf $(addsuffix .o,$(objs)) $(shim_target) .lib