Makefile 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. include Makefile.Host
  2. CC = gcc
  3. AR = ar rcs
  4. LD = ld
  5. CFLAGS = -Wall -fPIC -O2 -std=gnu99 -fgnu89-inline -U_FORTIFY_SOURCE \
  6. -fno-omit-frame-pointer \
  7. -fno-stack-protector -fno-builtin
  8. LDFLAGS = -shared -nostdlib -z combreloc -z defs
  9. ARFLAGS =
  10. pal_loader = libpal.so
  11. pal_sec =
  12. pal_lib = libpal.so
  13. pal_lib_deps =
  14. pal_lib_post =
  15. pal_static = libpal.a
  16. include host/$(OS)/Makefile.am
  17. CFLAGS += -I. -I../include -Ihost/$(OS) -I../lib
  18. ifeq ($(PROFILING),1)
  19. CFLAGS += -DPROFILING=1
  20. endif
  21. pal_target = $(pal_lib) $(pal_lib_post) $(pal_static) $(pal_loader) $(pal_sec) pal
  22. defs = -DIN_PAL -D$(OS_MACRO) -DSRCDIR="$(shell pwd)/"
  23. objs = $(addprefix db_,streams memory threading semaphore events process \
  24. object main misc ipc exception rtld) slab printf
  25. graphene_lib = .lib/graphene-lib.a
  26. host_lib = host/$(OS)/libpal-$(OS).a
  27. headers = $(wildcard *.h) $(wildcard ../lib/*.h) host/$(OS)/pal_host.h
  28. ifneq ($(pal_sec),)
  29. pal_target += pal_sec
  30. endif
  31. ifeq ($(SYS),x86_64-linux-gnu)
  32. pal_target += user_start.o user_shared_start.o
  33. endif
  34. all: $(pal_target)
  35. debug: debug = debug
  36. debug: CC = gcc -gdwarf-2 -g3
  37. debug: CFLAGS += -DDEBUG
  38. debug: $(pal_target)
  39. .PHONY: $(host_lib) $(graphene_lib) $(pal_lib) $(pal_sec)
  40. $(graphene_lib): host_endian.h
  41. $(MAKE) -C ../lib $(debug) target=$(shell pwd)/.lib/
  42. host_endian.h: host/$(OS)/host_endian.h
  43. ln -sf $< $@
  44. $(host_lib): $(graphene_lib)
  45. @[ ! -d host/$(OS) ] || $(MAKE) -C host/$(OS) $(debug)
  46. ifneq ($(pal_sec),)
  47. $(pal_sec): $(graphene_lib)
  48. @[ ! -d security/$(OS) ] || $(MAKE) -C security/$(OS) $(debug)
  49. pal_sec: $(pal_sec)
  50. ln -sf $(pal_sec) pal_sec
  51. endif
  52. $(pal_lib): $(addsuffix .o,$(objs)) $(host_lib) $(graphene_lib) $(pal_lib_deps)
  53. @echo [ $@ ]
  54. $(LD) $(LDFLAGS) -o $@ $(filter-out %.map %.lds,$^) $(LDFLAGS-suffix)
  55. pal: $(pal_loader)
  56. ln -sf $(pal_loader) pal
  57. ifneq ($(pal_lib_post),)
  58. $(pal_lib_post): $(pal_lib)
  59. $(MAKE) -C host/$(OS) ../../$@
  60. endif
  61. $(pal_static): $(addsuffix .o,$(objs)) $(host_lib) $(graphene_lib)
  62. @echo [ $@ ]
  63. $(AR) $(ARFLAGS) $@ $^ $(ARFLAGS-suffix)
  64. %.asm: %.c $(headers)
  65. $(CC) $(CFLAGS) $(defs) -c $< -o $<.o
  66. @objdump -S $<.o > $@
  67. @rm $<.o
  68. user_start.o: user_start.S
  69. @echo [ $@ ]
  70. @$(CC) -c $< -o $@
  71. user_shared_start.o: user_start.S
  72. @echo [ $@ ]
  73. @$(CC) -DSHARED -fPIC -c $< -o $@
  74. %.o: %.c $(headers)
  75. @echo [ $@ ]
  76. @$(CC) $(CFLAGS) $(defs) -c $< -o $@ $(CFLAGS-suffix)
  77. %.e: %.c $(headers)
  78. @echo [ $@ ]
  79. @$(CC) $(CFLAGS) $(defs) -E $< -o $@ $(CFLAGS-suffix)
  80. clean:
  81. rm -rf $(addsuffix .o,$(objs)) $(pal_target) host_endian.h .lib
  82. @[ ! -d host/$(OS) ] || $(MAKE) -C host/$(OS) clean
  83. @[ ! -d security/$(OS) ] || $(MAKE) -C security/$(OS) clean