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 1.9KB

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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. ifneq ($(ARCH), mac)
  16. CXXFLAGS += -Wsuggest-override
  17. endif
  18. CXXFLAGS += -std=c++11
  19. ifdef ARCH_LIN
  20. FLAGS += -DARCH_LIN
  21. endif
  22. ifdef ARCH_MAC
  23. FLAGS += -DARCH_MAC
  24. CXXFLAGS += -stdlib=libc++
  25. LDFLAGS += -stdlib=libc++
  26. MAC_SDK_FLAGS = -mmacosx-version-min=10.7
  27. FLAGS += $(MAC_SDK_FLAGS)
  28. LDFLAGS += $(MAC_SDK_FLAGS)
  29. endif
  30. ifdef ARCH_WIN
  31. FLAGS += -DARCH_WIN
  32. FLAGS += -D_USE_MATH_DEFINES
  33. endif
  34. CFLAGS += $(FLAGS)
  35. CXXFLAGS += $(FLAGS)
  36. # Derive object files from sources and place them before user-defined objects
  37. OBJECTS := $(patsubst %, build/%.o, $(SOURCES)) $(OBJECTS)
  38. OBJECTS += $(patsubst %, build/%.bin.o, $(BINARIES))
  39. DEPENDENCIES := $(patsubst %, build/%.d, $(SOURCES))
  40. # Final targets
  41. $(TARGET): $(OBJECTS)
  42. $(CXX) -o $@ $^ $(LDFLAGS)
  43. -include $(DEPENDENCIES)
  44. build/%.c.o: %.c
  45. @mkdir -p $(@D)
  46. $(CC) $(CFLAGS) -c -o $@ $<
  47. build/%.cpp.o: %.cpp
  48. @mkdir -p $(@D)
  49. $(CXX) $(CXXFLAGS) -c -o $@ $<
  50. build/%.cc.o: %.cc
  51. @mkdir -p $(@D)
  52. $(CXX) $(CXXFLAGS) -c -o $@ $<
  53. build/%.m.o: %.m
  54. @mkdir -p $(@D)
  55. $(CC) $(CFLAGS) -c -o $@ $<
  56. build/%.bin.o: %
  57. @mkdir -p $(@D)
  58. ifdef ARCH_LIN
  59. $(OBJCOPY) -I binary -O elf64-x86-64 -B i386:x86-64 --rename-section .data=.rodata,alloc,load,readonly,data,contents $< $@
  60. endif
  61. ifdef ARCH_WIN
  62. $(OBJCOPY) -I binary -O pe-x86-64 -B i386:x86-64 --rename-section .data=.rodata,alloc,load,readonly,data,contents $< $@
  63. endif
  64. ifdef ARCH_MAC
  65. @# Apple makes this needlessly complicated, so just generate a C file with an array.
  66. xxd -i $< | $(CC) $(MAC_SDK_FLAGS) -c -o $@ -xc -
  67. endif