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.

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