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

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