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.

111 lines
2.6KB

  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 += -march=nehalem
  27. endif
  28. ifdef ARCH_ARM64
  29. FLAGS += -march=armv8-a+fp+simd
  30. endif
  31. ifdef ARCH_LIN
  32. CXXFLAGS += -Wsuggest-override
  33. endif
  34. ifdef ARCH_MAC
  35. CXXFLAGS += -stdlib=libc++
  36. LDFLAGS += -stdlib=libc++
  37. MAC_SDK_FLAGS := -mmacosx-version-min=10.9
  38. FLAGS += $(MAC_SDK_FLAGS)
  39. LDFLAGS += $(MAC_SDK_FLAGS)
  40. endif
  41. ifdef ARCH_WIN
  42. FLAGS += -D_USE_MATH_DEFINES
  43. FLAGS += -municode
  44. CXXFLAGS += -Wsuggest-override
  45. endif
  46. # Allow *appending* rather than prepending to common flags.
  47. # This is useful to force-redefine compiler settings instead of merely setting defaults that may be overwritten.
  48. FLAGS += $(EXTRA_FLAGS)
  49. CFLAGS += $(EXTRA_CFLAGS)
  50. CXXFLAGS += $(EXTRA_CXXFLAGS)
  51. LDFLAGS += $(EXTRA_LDFLAGS)
  52. # Apply FLAGS to language-specific flags
  53. CFLAGS += $(FLAGS)
  54. CXXFLAGS += $(FLAGS)
  55. # Derive object files from sources and place them before user-defined objects
  56. OBJECTS := $(patsubst %, build/%.o, $(SOURCES)) $(OBJECTS)
  57. OBJECTS += $(patsubst %, build/%.bin.o, $(BINARIES))
  58. DEPENDENCIES := $(patsubst %, build/%.d, $(SOURCES))
  59. # Final targets
  60. $(TARGET): $(OBJECTS)
  61. $(CXX) -o $@ $^ $(LDFLAGS)
  62. -include $(DEPENDENCIES)
  63. build/%.c.o: %.c
  64. @mkdir -p $(@D)
  65. $(CC) $(CFLAGS) -c -o $@ $<
  66. build/%.cpp.o: %.cpp
  67. @mkdir -p $(@D)
  68. $(CXX) $(CXXFLAGS) -c -o $@ $<
  69. build/%.cc.o: %.cc
  70. @mkdir -p $(@D)
  71. $(CXX) $(CXXFLAGS) -c -o $@ $<
  72. build/%.m.o: %.m
  73. @mkdir -p $(@D)
  74. $(CC) $(CFLAGS) -c -o $@ $<
  75. build/%.mm.o: %.mm
  76. @mkdir -p $(@D)
  77. $(CC) $(CXXFLAGS) -c -o $@ $<
  78. build/%.bin.o: %
  79. @mkdir -p $(@D)
  80. ifdef ARCH_LIN
  81. $(OBJCOPY) -I binary -O elf64-x86-64 -B i386:x86-64 --rename-section .data=.rodata,alloc,load,readonly,data,contents $< $@
  82. endif
  83. ifdef ARCH_WIN
  84. $(OBJCOPY) -I binary -O pe-x86-64 -B i386:x86-64 --rename-section .data=.rodata,alloc,load,readonly,data,contents $< $@
  85. endif
  86. ifdef ARCH_MAC
  87. @# Apple makes this needlessly complicated, so just generate a C file with an array.
  88. xxd -i $< | $(CC) $(MAC_SDK_FLAGS) -c -o $@ -xc -
  89. endif
  90. build/%.html: %.md
  91. markdown $< > $@