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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. # Define compiler/linker target if cross-compiling
  20. ifdef CROSS_COMPILE
  21. FLAGS += --target=$(MACHINE)
  22. endif
  23. # Architecture-independent flags
  24. ifdef ARCH_X64
  25. FLAGS += -march=nehalem
  26. endif
  27. ifdef ARCH_ARM64
  28. FLAGS += -march=armv8-a+fp+simd
  29. endif
  30. ifdef ARCH_LIN
  31. CXXFLAGS += -Wsuggest-override
  32. endif
  33. ifdef ARCH_MAC
  34. CXXFLAGS += -stdlib=libc++
  35. MAC_SDK_FLAGS := -mmacosx-version-min=10.9
  36. FLAGS += $(MAC_SDK_FLAGS)
  37. endif
  38. ifdef ARCH_WIN
  39. FLAGS += -D_USE_MATH_DEFINES
  40. FLAGS += -municode
  41. CXXFLAGS += -Wsuggest-override
  42. endif
  43. # Allow *appending* rather than prepending to common flags.
  44. # This is useful to force-redefine compiler settings instead of merely setting defaults that may be overwritten.
  45. FLAGS += $(EXTRA_FLAGS)
  46. CFLAGS += $(EXTRA_CFLAGS)
  47. CXXFLAGS += $(EXTRA_CXXFLAGS)
  48. LDFLAGS += $(EXTRA_LDFLAGS)
  49. # Apply FLAGS to language-specific flags
  50. CFLAGS += $(FLAGS)
  51. CXXFLAGS += $(FLAGS)
  52. # Derive object files from sources and place them before user-defined objects
  53. OBJECTS := $(patsubst %, build/%.o, $(SOURCES)) $(OBJECTS)
  54. OBJECTS += $(patsubst %, build/%.bin.o, $(BINARIES))
  55. DEPENDENCIES := $(patsubst %, build/%.d, $(SOURCES))
  56. # Final targets
  57. $(TARGET): $(OBJECTS)
  58. $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $^
  59. -include $(DEPENDENCIES)
  60. build/%.c.o: %.c
  61. @mkdir -p $(@D)
  62. $(CC) $(CFLAGS) -c -o $@ $<
  63. build/%.cpp.o: %.cpp
  64. @mkdir -p $(@D)
  65. $(CXX) $(CXXFLAGS) -c -o $@ $<
  66. build/%.cc.o: %.cc
  67. @mkdir -p $(@D)
  68. $(CXX) $(CXXFLAGS) -c -o $@ $<
  69. build/%.m.o: %.m
  70. @mkdir -p $(@D)
  71. $(CC) $(CFLAGS) -c -o $@ $<
  72. build/%.mm.o: %.mm
  73. @mkdir -p $(@D)
  74. $(CC) $(CXXFLAGS) -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 $< > $@