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.

84 lines
1.9KB

  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. # Generate dependency files alongside the object files
  8. FLAGS += -MMD -MP
  9. # Debugger symbols. These are removed with `strip`.
  10. FLAGS += -g
  11. # Optimization
  12. FLAGS += -O3 -march=nocona -funsafe-math-optimizations
  13. # Warnings
  14. FLAGS += -Wall -Wextra -Wno-unused-parameter
  15. # C++ standard
  16. CXXFLAGS += -std=c++11
  17. # Architecture-independent flags
  18. ifdef ARCH_LIN
  19. FLAGS += -DARCH_LIN
  20. CXXFLAGS += -Wsuggest-override
  21. endif
  22. ifdef ARCH_MAC
  23. FLAGS += -DARCH_MAC
  24. CXXFLAGS += -stdlib=libc++
  25. LDFLAGS += -stdlib=libc++
  26. MAC_SDK_FLAGS = -mmacosx-version-min=10.7
  27. FLAGS += $(MAC_SDK_FLAGS)
  28. LDFLAGS += $(MAC_SDK_FLAGS)
  29. endif
  30. ifdef ARCH_WIN
  31. FLAGS += -DARCH_WIN
  32. FLAGS += -D_USE_MATH_DEFINES
  33. CXXFLAGS += -Wsuggest-override
  34. endif
  35. CFLAGS += $(FLAGS)
  36. CXXFLAGS += $(FLAGS)
  37. # Derive object files from sources and place them before user-defined objects
  38. OBJECTS := $(patsubst %, build/%.o, $(SOURCES)) $(OBJECTS)
  39. OBJECTS += $(patsubst %, build/%.bin.o, $(BINARIES))
  40. DEPENDENCIES := $(patsubst %, build/%.d, $(SOURCES))
  41. # Final targets
  42. $(TARGET): $(OBJECTS)
  43. $(CXX) -o $@ $^ $(LDFLAGS)
  44. -include $(DEPENDENCIES)
  45. build/%.c.o: %.c
  46. @mkdir -p $(@D)
  47. $(CC) $(CFLAGS) -c -o $@ $<
  48. build/%.cpp.o: %.cpp
  49. @mkdir -p $(@D)
  50. $(CXX) $(CXXFLAGS) -c -o $@ $<
  51. build/%.cc.o: %.cc
  52. @mkdir -p $(@D)
  53. $(CXX) $(CXXFLAGS) -c -o $@ $<
  54. build/%.m.o: %.m
  55. @mkdir -p $(@D)
  56. $(CC) $(CFLAGS) -c -o $@ $<
  57. build/%.bin.o: %
  58. @mkdir -p $(@D)
  59. ifdef ARCH_LIN
  60. $(OBJCOPY) -I binary -O elf64-x86-64 -B i386:x86-64 --rename-section .data=.rodata,alloc,load,readonly,data,contents $< $@
  61. endif
  62. ifdef ARCH_WIN
  63. $(OBJCOPY) -I binary -O pe-x86-64 -B i386:x86-64 --rename-section .data=.rodata,alloc,load,readonly,data,contents $< $@
  64. endif
  65. ifdef ARCH_MAC
  66. @# Apple makes this needlessly complicated, so just generate a C file with an array.
  67. xxd -i $< | $(CC) $(MAC_SDK_FLAGS) -c -o $@ -xc -
  68. endif