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.

compile.mk 2.5KB

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