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
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. ifndef RACK_DIR
  2. $(error RACK_DIR is not defined)
  3. endif
  4. ifndef VERSION
  5. $(error VERSION is not defined)
  6. endif
  7. include $(RACK_DIR)/arch.mk
  8. OBJCOPY ?= objcopy
  9. FLAGS += -DVERSION=$(VERSION)
  10. # Generate dependency files alongside the object files
  11. FLAGS += -MMD -MP
  12. FLAGS += -g
  13. # Optimization
  14. FLAGS += -O3 -march=nocona -ffast-math -fno-finite-math-only
  15. FLAGS += -Wall -Wextra -Wno-unused-parameter
  16. ifneq ($(ARCH), mac)
  17. CXXFLAGS += -Wsuggest-override
  18. endif
  19. CXXFLAGS += -std=c++11
  20. ifdef ARCH_LIN
  21. FLAGS += -DARCH_LIN
  22. endif
  23. ifdef ARCH_MAC
  24. FLAGS += -DARCH_MAC
  25. CXXFLAGS += -stdlib=libc++
  26. LDFLAGS += -stdlib=libc++
  27. MAC_SDK_FLAGS = -mmacosx-version-min=10.7
  28. FLAGS += $(MAC_SDK_FLAGS)
  29. LDFLAGS += $(MAC_SDK_FLAGS)
  30. endif
  31. ifdef ARCH_WIN
  32. FLAGS += -DARCH_WIN
  33. FLAGS += -D_USE_MATH_DEFINES
  34. endif
  35. CFLAGS += $(FLAGS)
  36. CXXFLAGS += $(FLAGS)
  37. # Derive object files from sources and place them before user-defined objects
  38. OBJECTS := $(patsubst %, build/%.o, $(SOURCES)) $(OBJECTS)
  39. OBJECTS += $(patsubst %, build/%.bin.o, $(BINARIES))
  40. DEPENDENCIES := $(patsubst %, build/%.d, $(SOURCES))
  41. # Final targets
  42. $(TARGET): $(OBJECTS)
  43. $(CXX) -o $@ $^ $(LDFLAGS)
  44. -include $(DEPENDENCIES)
  45. build/%.c.o: %.c
  46. @mkdir -p $(@D)
  47. $(CC) $(CFLAGS) -c -o $@ $<
  48. build/%.cpp.o: %.cpp
  49. @mkdir -p $(@D)
  50. $(CXX) $(CXXFLAGS) -c -o $@ $<
  51. build/%.cc.o: %.cc
  52. @mkdir -p $(@D)
  53. $(CXX) $(CXXFLAGS) -c -o $@ $<
  54. build/%.m.o: %.m
  55. @mkdir -p $(@D)
  56. $(CC) $(CFLAGS) -c -o $@ $<
  57. build/%.bin.o: %
  58. @mkdir -p $(@D)
  59. ifdef ARCH_LIN
  60. $(OBJCOPY) -I binary -O elf64-x86-64 -B i386:x86-64 --rename-section .data=.rodata,alloc,load,readonly,data,contents $< $@
  61. endif
  62. ifdef ARCH_WIN
  63. $(OBJCOPY) -I binary -O pe-x86-64 -B i386:x86-64 --rename-section .data=.rodata,alloc,load,readonly,data,contents $< $@
  64. endif
  65. ifdef ARCH_MAC
  66. @# Apple makes this needlessly complicated, so just generate a C file with an array.
  67. xxd -i $< | $(CC) $(MAC_SDK_FLAGS) -c -o $@ -xc -
  68. endif