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.

101 lines
2.4KB

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