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

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