Makefile 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. export PAL_DIR = $(CURDIR)
  2. export RUNTIME_DIR = $(CURDIR)/../../Runtime
  3. include Makefile.Host
  4. -include Makefile.Status
  5. ifeq ($(DEBUG),1)
  6. BUILD_TARGET = $(PAL_HOST)-debug
  7. else
  8. BUILD_TARGET = $(PAL_HOST)
  9. endif
  10. # Customizable PAL Targets
  11. # (specify in Makefile.am in host-specific directories)
  12. pal_loader =
  13. pal_sec =
  14. pal_lib =
  15. pal_lib_deps =
  16. pal_lib_post =
  17. pal_static =
  18. pal_gdb =
  19. include host/$(PAL_HOST)/Makefile.am
  20. CFLAGS += -I. -I../include -Ihost/$(PAL_HOST) -I../lib
  21. ifeq ($(PROFILING),1)
  22. CFLAGS += -DPROFILING=1
  23. endif
  24. files_to_build = $(pal_lib) $(pal_lib_post) $(pal_static) \
  25. $(pal_loader) $(pal_sec)
  26. defs = -DIN_PAL -DHOST_TYPE="$(PAL_HOST)" -D$(PAL_HOST_MACRO) -DPAL_DIR=$(PAL_DIR) \
  27. -DRUNTIME_DIR=$(RUNTIME_DIR)
  28. objs = $(addprefix db_,streams memory threading mutex events process \
  29. object main misc ipc exception rtld) slab printf
  30. graphene_lib = .lib/graphene-lib.a
  31. host_lib = host/$(PAL_HOST)/libpal-$(PAL_HOST).a
  32. headers = $(wildcard *.h) $(wildcard ../lib/*.h) host/$(PAL_HOST)/pal_host.h
  33. ifeq ($(SYS),x86_64-linux-gnu)
  34. files_to_build += user_start.o user_shared_start.o
  35. endif
  36. ifeq ($(DEBUG),1)
  37. CC += -gdwarf-2 -g3
  38. CFLAGS += -DDEBUG
  39. endif
  40. export DEBUG
  41. runtime_loader = $(RUNTIME_DIR)/pal-$(PAL_HOST)
  42. ifneq ($(pal_lib),)
  43. runtime_lib += $(RUNTIME_DIR)/libpal-$(PAL_HOST)$(suffix $(pal_lib))
  44. endif
  45. ifneq ($(pal_sec),)
  46. runtime_sec += $(RUNTIME_DIR)/pal_sec-$(PAL_HOST)
  47. endif
  48. ifneq ($(pal_gdb),)
  49. runtime_gdb += $(RUNTIME_DIR)/pal_gdb-$(PAL_HOST)
  50. endif
  51. files_to_install = $(runtime_loader) $(runtime_lib) $(runtime_sec) $(runtime_gdb)
  52. .PHONY: all
  53. all: | check_target $(files_to_build) $(files_to_install)
  54. ifndef SAVED_TARGET
  55. SAVED_TARGET = $(BUILD_TARGET)
  56. endif
  57. SAVED_OS = $(patsubst %-debug,%,$(SAVED_TARGET))
  58. .PHONY: check_target
  59. check_target:
  60. @echo "Building target: $(BUILD_TARGET)"
  61. ifneq ($(SAVED_TARGET),$(BUILD_TARGET))
  62. $(error "A different target is built earlier. Prune the directory first.")
  63. endif
  64. @echo "SAVED_TARGET = $(BUILD_TARGET)" > Makefile.Status
  65. .PHONY: $(host_lib) $(graphene_lib) $(pal_lib) $(pal_sec)
  66. $(graphene_lib): host_endian.h
  67. $(MAKE) -C ../lib target=$(shell pwd)/.lib/
  68. host_endian.h: host/$(PAL_HOST)/host_endian.h
  69. ln -sf $< $@
  70. $(host_lib): $(graphene_lib)
  71. @[ ! -d host/$(PAL_HOST) ] || $(MAKE) -C host/$(PAL_HOST)
  72. $(pal_loader) $(pal_sec): $(host_lib)
  73. $(runtime_loader): $(pal_loader)
  74. cp -f $< $@
  75. ifneq ($(pal_lib),)
  76. $(pal_lib): $(addsuffix .o,$(objs)) $(host_lib) $(graphene_lib) $(pal_lib_deps)
  77. @echo [ $@ ]
  78. $(LD) $(LDFLAGS) -o $@ $(filter-out %.map %.lds,$^) $(LDFLAGS-suffix)
  79. $(runtime_lib): $(pal_lib)
  80. cp -f $< $@
  81. endif
  82. ifneq ($(pal_sec),)
  83. $(pal_sec): $(graphene_lib)
  84. @[ ! -d security/$(PAL_HOST) ] || $(MAKE) -C security/$(PAL_HOST)
  85. $(runtime_sec): $(pal_sec)
  86. cp -f $< $@
  87. endif
  88. ifneq ($(pal_gdb),)
  89. $(runtime_gdb): $(pal_gdb)
  90. ifeq ($(abspath $(pal_gdb)),$(pal_gdb))
  91. ln -sf $< $@
  92. else
  93. ln -sf ../Pal/src/$< $@
  94. endif
  95. endif
  96. ifneq ($(pal_lib_post),)
  97. $(pal_lib_post): $(pal_lib)
  98. $(MAKE) -C host/$(PAL_HOST) ../../$@
  99. endif
  100. $(pal_static): $(addsuffix .o,$(objs)) $(host_lib) $(graphene_lib)
  101. @echo [ $@ ]
  102. $(AR) $(ARFLAGS) $@ $^ $(ARFLAGS-suffix)
  103. %.asm: %.c $(headers)
  104. $(CC) $(CFLAGS) $(defs) -c $< -o $<.o
  105. @objdump -S $<.o > $@
  106. @rm $<.o
  107. user_start.o: user_start.S
  108. @echo [ $@ ]
  109. @$(CC) -c $< -o $@
  110. user_shared_start.o: user_start.S
  111. @echo [ $@ ]
  112. @$(CC) -DSHARED -fPIC -c $< -o $@
  113. %.o: %.c $(headers)
  114. @echo [ $@ ]
  115. @$(CC) $(CFLAGS) $(defs) -c $< -o $@ $(CFLAGS-suffix)
  116. %.e: %.c $(headers)
  117. @echo [ $@ ]
  118. @$(CC) $(CFLAGS) $(defs) -E $< -o $@ $(CFLAGS-suffix)
  119. .PHONY: clean
  120. clean:
  121. ifneq ($(SAVED_OS),$(PAL_HOST))
  122. $(MAKE) clean PAL_HOST=$(SAVED_OS)
  123. endif
  124. rm -rf $(addsuffix .o,$(objs)) $(files_to_build) host_endian.h .lib Makefile.Status
  125. @[ ! -d host/$(PAL_HOST) ] || $(MAKE) -C host/$(PAL_HOST) clean
  126. @[ ! -d security/$(PAL_HOST) ] || $(MAKE) -C security/$(PAL_HOST) clean