Makefile 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 -D$(PAL_HOST_MACRO) -DPAL_DIR=$(PAL_DIR) \
  27. -DRUNTIME_DIR=$(RUNTIME_DIR)
  28. objs = $(addprefix db_,streams memory threading semaphore 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. all: | check_target $(files_to_build) $(files_to_install)
  53. ifndef SAVED_TARGET
  54. SAVED_TARGET = $(BUILD_TARGET)
  55. endif
  56. SAVED_OS = $(patsubst %-debug,%,$(SAVED_TARGET))
  57. .PHONY: check_target
  58. check_target:
  59. @echo "Building target: $(BUILD_TARGET)"
  60. ifneq ($(SAVED_TARGET),$(BUILD_TARGET))
  61. $(error "A different target is built earlier. Prune the directory first.")
  62. endif
  63. @echo "SAVED_TARGET = $(BUILD_TARGET)" > Makefile.Status
  64. .PHONY: $(host_lib) $(graphene_lib) $(pal_lib) $(pal_sec)
  65. $(graphene_lib): host_endian.h
  66. $(MAKE) -C ../lib target=$(shell pwd)/.lib/
  67. host_endian.h: host/$(PAL_HOST)/host_endian.h
  68. ln -sf $< $@
  69. $(host_lib): $(graphene_lib)
  70. @[ ! -d host/$(PAL_HOST) ] || $(MAKE) -C host/$(PAL_HOST)
  71. $(pal_loader) $(pal_sec): $(host_lib)
  72. $(runtime_loader): $(pal_loader)
  73. cp -f $< $@
  74. ifneq ($(pal_lib),)
  75. $(pal_lib): $(addsuffix .o,$(objs)) $(host_lib) $(graphene_lib) $(pal_lib_deps)
  76. @echo [ $@ ]
  77. $(LD) $(LDFLAGS) -o $@ $(filter-out %.map %.lds,$^) $(LDFLAGS-suffix)
  78. $(runtime_lib): $(pal_lib)
  79. cp -f $< $@
  80. endif
  81. ifneq ($(pal_sec),)
  82. $(pal_sec): $(graphene_lib)
  83. @[ ! -d security/$(PAL_HOST) ] || $(MAKE) -C security/$(PAL_HOST)
  84. $(runtime_sec): $(pal_sec)
  85. cp -f $< $@
  86. endif
  87. ifneq ($(pal_gdb),)
  88. $(runtime_gdb): $(pal_gdb)
  89. ifeq ($(abspath $(pal_gdb)),$(pal_gdb))
  90. ln -sf $< $@
  91. else
  92. ln -sf ../Pal/src/$< $@
  93. endif
  94. endif
  95. ifneq ($(pal_lib_post),)
  96. $(pal_lib_post): $(pal_lib)
  97. $(MAKE) -C host/$(PAL_HOST) ../../$@
  98. endif
  99. $(pal_static): $(addsuffix .o,$(objs)) $(host_lib) $(graphene_lib)
  100. @echo [ $@ ]
  101. $(AR) $(ARFLAGS) $@ $^ $(ARFLAGS-suffix)
  102. %.asm: %.c $(headers)
  103. $(CC) $(CFLAGS) $(defs) -c $< -o $<.o
  104. @objdump -S $<.o > $@
  105. @rm $<.o
  106. user_start.o: user_start.S
  107. @echo [ $@ ]
  108. @$(CC) -c $< -o $@
  109. user_shared_start.o: user_start.S
  110. @echo [ $@ ]
  111. @$(CC) -DSHARED -fPIC -c $< -o $@
  112. %.o: %.c $(headers)
  113. @echo [ $@ ]
  114. @$(CC) $(CFLAGS) $(defs) -c $< -o $@ $(CFLAGS-suffix)
  115. %.e: %.c $(headers)
  116. @echo [ $@ ]
  117. @$(CC) $(CFLAGS) $(defs) -E $< -o $@ $(CFLAGS-suffix)
  118. clean:
  119. ifneq ($(SAVED_OS),$(PAL_HOST))
  120. $(MAKE) clean PAL_HOST=$(SAVED_OS)
  121. endif
  122. rm -rf $(addsuffix .o,$(objs)) $(files_to_build) host_endian.h .lib Makefile.Status
  123. @[ ! -d host/$(PAL_HOST) ] || $(MAKE) -C host/$(PAL_HOST) clean
  124. @[ ! -d security/$(PAL_HOST) ] || $(MAKE) -C security/$(PAL_HOST) clean