You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
2.7KB

  1. ifndef RACK_DIR
  2. $(error RACK_DIR is not defined)
  3. endif
  4. include $(RACK_DIR)/arch.mk
  5. OBJCOPY ?= objcopy
  6. STRIP ?= strip
  7. INSTALL_NAME_TOOL ?= install_name_tool
  8. OTOOL ?= otool
  9. # Generate dependency files alongside the object files
  10. FLAGS += -MMD -MP
  11. # Debugger symbols. These are removed with `strip`.
  12. FLAGS += -g
  13. # Optimization
  14. FLAGS += -O3 -funsafe-math-optimizations -fno-omit-frame-pointer
  15. # Warnings
  16. FLAGS += -Wall -Wextra -Wno-unused-parameter
  17. # C++ standard
  18. CXXFLAGS += -std=c++11
  19. # Define compiler/linker target if cross-compiling
  20. ifdef CROSS_COMPILE
  21. FLAGS += --target=$(MACHINE)
  22. LDFLAGS += --target=$(MACHINE)
  23. endif
  24. # Architecture-independent flags
  25. ifdef ARCH_X64
  26. FLAGS += -DARCH_X64
  27. FLAGS += -march=nehalem
  28. endif
  29. ifdef ARCH_ARM64
  30. FLAGS += -DARCH_ARM64
  31. FLAGS += -march=armv8-a+fp+simd
  32. endif
  33. ifdef ARCH_LIN
  34. FLAGS += -DARCH_LIN
  35. CXXFLAGS += -Wsuggest-override
  36. endif
  37. ifdef ARCH_MAC
  38. FLAGS += -DARCH_MAC
  39. CXXFLAGS += -stdlib=libc++
  40. LDFLAGS += -stdlib=libc++
  41. MAC_SDK_FLAGS := -mmacosx-version-min=10.9
  42. FLAGS += $(MAC_SDK_FLAGS)
  43. LDFLAGS += $(MAC_SDK_FLAGS)
  44. endif
  45. ifdef ARCH_WIN
  46. FLAGS += -DARCH_WIN
  47. FLAGS += -D_USE_MATH_DEFINES
  48. FLAGS += -municode
  49. CXXFLAGS += -Wsuggest-override
  50. endif
  51. # Allow *appending* rather than prepending to common flags.
  52. # This is useful to force-redefine compiler settings instead of merely setting defaults that may be overwritten.
  53. FLAGS += $(EXTRA_FLAGS)
  54. CFLAGS += $(EXTRA_CFLAGS)
  55. CXXFLAGS += $(EXTRA_CXXFLAGS)
  56. LDFLAGS += $(EXTRA_LDFLAGS)
  57. # Apply FLAGS to language-specific flags
  58. CFLAGS += $(FLAGS)
  59. CXXFLAGS += $(FLAGS)
  60. # Derive object files from sources and place them before user-defined objects
  61. OBJECTS := $(patsubst %, build/%.o, $(SOURCES)) $(OBJECTS)
  62. OBJECTS += $(patsubst %, build/%.bin.o, $(BINARIES))
  63. DEPENDENCIES := $(patsubst %, build/%.d, $(SOURCES))
  64. # Final targets
  65. $(TARGET): $(OBJECTS)
  66. $(CXX) -o $@ $^ $(LDFLAGS)
  67. -include $(DEPENDENCIES)
  68. build/%.c.o: %.c
  69. @mkdir -p $(@D)
  70. $(CC) $(CFLAGS) -c -o $@ $<
  71. build/%.cpp.o: %.cpp
  72. @mkdir -p $(@D)
  73. $(CXX) $(CXXFLAGS) -c -o $@ $<
  74. build/%.cc.o: %.cc
  75. @mkdir -p $(@D)
  76. $(CXX) $(CXXFLAGS) -c -o $@ $<
  77. build/%.m.o: %.m
  78. @mkdir -p $(@D)
  79. $(CC) $(CFLAGS) -c -o $@ $<
  80. build/%.mm.o: %.mm
  81. @mkdir -p $(@D)
  82. $(CC) $(CXXFLAGS) -c -o $@ $<
  83. build/%.bin.o: %
  84. @mkdir -p $(@D)
  85. ifdef ARCH_LIN
  86. $(OBJCOPY) -I binary -O elf64-x86-64 -B i386:x86-64 --rename-section .data=.rodata,alloc,load,readonly,data,contents $< $@
  87. endif
  88. ifdef ARCH_WIN
  89. $(OBJCOPY) -I binary -O pe-x86-64 -B i386:x86-64 --rename-section .data=.rodata,alloc,load,readonly,data,contents $< $@
  90. endif
  91. ifdef ARCH_MAC
  92. @# Apple makes this needlessly complicated, so just generate a C file with an array.
  93. xxd -i $< | $(CC) $(MAC_SDK_FLAGS) -c -o $@ -xc -
  94. endif
  95. build/%.html: %.md
  96. markdown $< > $@