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