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.

96 lines
2.3KB

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