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

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