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.

92 lines
2.2KB

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