Makefile 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. # Kohi.Plugin.Renderer.Vulkan makefile
  2. ASSEMBLY_NAME=kohi.plugin.renderer.vulkan
  3. # All compiler flags/rules used across the board.
  4. CFLAGS =-std=gnu11 -Wall -Wextra -Werror -Wno-error=deprecated-declarations -Wno-error=unused-function
  5. CFLAGS +=-Wvla -Werror=vla -Wgnu-folding-constant -Wno-missing-braces -Wstrict-prototypes -Wno-unused-parameter
  6. CFLAGS +=-Wno-missing-field-initializers -Wno-tautological-compare
  7. # NOTE: -fvisibility=hidden hides all symbols by default, and only those that explicitly say otherwise are exported (i.e. via KAPI).
  8. CFLAGS +=-fvisibility=hidden
  9. # Base linker flags
  10. LDFLAGS = -Lbin -Llib -L../kohi.core/bin -L../kohi.runtime/bin -lkohi.core -lkohi.runtime
  11. LDFLAGS += -lshaderc_shared
  12. # Base include flags
  13. INCLUDE_FLAGS = -Isrc -I../kohi.core/src -I../kohi.runtime/src
  14. INCLUDE_FLAGS += -I$(VULKAN_SDK)/include
  15. DEFINES =-DKEXPORT
  16. OUTPUT_NAME =
  17. UNAME_S :=
  18. ifneq ($(OS),Windows_NT)
  19. UNAME_S = $(shell uname -s)
  20. endif
  21. ifeq ($(OS),Windows_NT)
  22. PLATFORM := win32
  23. # Make does not offer a recursive wildcard function, and Windows needs one, so here it is:
  24. rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))
  25. DIR := $(subst /,\,${CURDIR})
  26. SRC_FILES := $(call rwildcard,src,*.c)
  27. DIRECTORIES := \src $(subst $(DIR),,$(shell dir src /S /AD /B | findstr /i src))
  28. OBJ_FILES := $(SRC_FILES:%=obj/%.o)
  29. INCLUDE_FLAGS += -I$(VULKAN_SDK)\include
  30. else ifeq ($(UNAME_S),Linux)
  31. PLATFORM := linux
  32. SRC_FILES := $(shell find src -name "*.c")
  33. DIRECTORIES := $(shell find src -type d)
  34. OBJ_FILES := $(SRC_FILES:%=obj/%.o)
  35. else ifeq ($(UNAME_S),Darwin)
  36. PLATFORM := macos
  37. SRC_FILES := $(shell find src -type f \( -name "*.c" \))
  38. DIRECTORIES := $(shell find src -type d)
  39. OBJ_FILES := $(SRC_FILES:%=obj/%.o)
  40. else
  41. $(error Unsupported platform)
  42. endif
  43. # =========================================================
  44. # BEGIN TARGET RECIPES
  45. # =========================================================
  46. .PHONY: all-release all-debug flags-debug flags-release
  47. .PHONY: genversion genversion-win32 genversion-linux genversion-macos
  48. .PHONY: scaffold scaffold-win32 scaffold-linux scaffold-macos
  49. .PHONY: link link-win32 link-linux link-macos
  50. all-release: scaffold genversion gen_compile_flags-release flags-release compile link
  51. all-debug: scaffold genversion gen_compile_flags-debug flags-debug compile link
  52. flags-debug: DEFINES += -D_DEBUG
  53. flags-debug: CFLAGS += -g -MD -O0 -fno-omit-frame-pointer
  54. flags-debug: LDFLAGS += -g
  55. flags-debug: link compile
  56. flags-release: DEFINES += -DKRELEASE
  57. flags-release: CFLAGS += -MD -O2
  58. flags-release: LDFLAGS +=
  59. flags-release: link compile
  60. scaffold: scaffold-$(PLATFORM)
  61. .NOTPARALLEL: scaffold
  62. scaffold-win32:
  63. -@mkdir $(addprefix obj\\, $(DIRECTORIES)) 2>nul
  64. @if not exist bin mkdir bin
  65. scaffold-linux scaffold-macos:
  66. @mkdir -p bin
  67. @mkdir -p $(addprefix obj/,$(DIRECTORIES))
  68. genversion: genversion-$(PLATFORM)
  69. genversion-win32:
  70. @..\misc\versiongen.exe version.txt -outfile=src\$(ASSEMBLY_NAME)_version.h
  71. genversion-linux genversion-macos:
  72. @../misc/versiongen version.txt -outfile=src/$(ASSEMBLY_NAME)_version.h
  73. .PHONY: clean
  74. clean: clean-$(PLATFORM)
  75. clean-win32:
  76. if exist bin del /s /q bin\*.*
  77. if exist obj del /s /q obj\*.*
  78. clean-linux clean-macos:
  79. @rm -rf bin/*
  80. @rm -rf obj/*
  81. link: link-$(PLATFORM)
  82. link-win32: LDFLAGS += -L$(VULKAN_SDK)\Lib -fdeclspec -Wno-cast-function-type-mismatch -Xlinker /INCREMENTAL
  83. link-win32: DEFINES += -D_CRT_SECURE_NO_WARNINGS -DUNICODE
  84. link-win32: OUTPUT_NAME = bin\$(ASSEMBLY_NAME).dll
  85. # NOTE: --no-undefined and --no-allow-shlib-undefined ensure that symbols linking against are resolved.
  86. # These are linux-specific, as the default behaviour is the opposite of this, allowing code to compile
  87. # here that would not on other platforms from not being exported (i.e. Windows)
  88. # Discovered the solution here for this: https://github.com/ziglang/zig/issues/8180
  89. link-linux: CFLAGS += -Wno-cast-function-type-mismatch -fPIC
  90. link-linux: LDFLAGS +=
  91. link-linux: OUTPUT_NAME = bin/lib$(ASSEMBLY_NAME).so
  92. link-macos: LDFLAGS += -dynamiclib -install_name @rpath/lib$(ASSEMBLY_NAME).dylib -Wl,-rpath,/usr/local/lib
  93. link-macos: OUTPUT_NAME = bin/lib$(ASSEMBLY_NAME).dylib
  94. link-win32 link-linux link-macos: link-common
  95. link-common: $(OBJ_FILES)
  96. @clang $(OBJ_FILES) -o $(OUTPUT_NAME) -shared $(LDFLAGS)
  97. .PHONY: compile
  98. compile:
  99. -include $(OBJ_FILES:.o=.d)
  100. # compile .c to .o object for windows, linux and mac
  101. obj/%.c.o: %.c
  102. @echo $<...
  103. @clang $< $(CFLAGS) -c -o $@ $(DEFINES) $(INCLUDE_FLAGS)
  104. -include $(OBJ_FILES:.o=.d)
  105. .PHONY: gen_compile_flags-debug
  106. gen_compile_flags-debug: DEFINES += -D_DEBUG
  107. gen_compile_flags-debug: gen_compile_flags
  108. gen_compile_flags-release: gen_compile_flags
  109. .PHONY: gen_compile_flags
  110. gen_compile_flags:
  111. ifeq ($(BUILD_PLATFORM),windows)
  112. @..\misc\cfgen -outfile=compile_flags.txt $(INCLUDE_FLAGS) $(DEFINES) -ferror-limit=0
  113. else
  114. @../misc/cfgen -outfile=compile_flags.txt $(INCLUDE_FLAGS) $(DEFINES) -ferror-limit=0
  115. endif