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.6KB

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