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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. 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. CXXFLAGS += -Wsuggest-override
  34. endif
  35. # Allow *appending* rather than prepending to common flags.
  36. # This is useful to force-redefine compiler settings instead of merely setting defaults that may be overwritten.
  37. FLAGS += $(EXTRA_FLAGS)
  38. CFLAGS += $(EXTRA_CFLAGS)
  39. CXXFLAGS += $(EXTRA_CXXFLAGS)
  40. LDFLAGS += $(EXTRA_LDFLAGS)
  41. # Apply FLAGS to language-specific flags
  42. CFLAGS += $(FLAGS)
  43. CXXFLAGS += $(FLAGS)
  44. # Derive object files from sources and place them before user-defined objects
  45. OBJECTS := $(patsubst %, build/%.o, $(SOURCES)) $(OBJECTS)
  46. OBJECTS += $(patsubst %, build/%.bin.o, $(BINARIES))
  47. DEPENDENCIES := $(patsubst %, build/%.d, $(SOURCES))
  48. # Final targets
  49. $(TARGET): $(OBJECTS)
  50. $(CXX) -o $@ $^ $(LDFLAGS)
  51. -include $(DEPENDENCIES)
  52. build/%.c.o: %.c
  53. @mkdir -p $(@D)
  54. $(CC) $(CFLAGS) -c -o $@ $<
  55. build/%.cpp.o: %.cpp
  56. @mkdir -p $(@D)
  57. $(CXX) $(CXXFLAGS) -c -o $@ $<
  58. build/%.cc.o: %.cc
  59. @mkdir -p $(@D)
  60. $(CXX) $(CXXFLAGS) -c -o $@ $<
  61. build/%.m.o: %.m
  62. @mkdir -p $(@D)
  63. $(CC) $(CFLAGS) -c -o $@ $<
  64. build/%.bin.o: %
  65. @mkdir -p $(@D)
  66. ifdef ARCH_LIN
  67. $(OBJCOPY) -I binary -O elf64-x86-64 -B i386:x86-64 --rename-section .data=.rodata,alloc,load,readonly,data,contents $< $@
  68. endif
  69. ifdef ARCH_WIN
  70. $(OBJCOPY) -I binary -O pe-x86-64 -B i386:x86-64 --rename-section .data=.rodata,alloc,load,readonly,data,contents $< $@
  71. endif
  72. ifdef ARCH_MAC
  73. @# Apple makes this needlessly complicated, so just generate a C file with an array.
  74. xxd -i $< | $(CC) $(MAC_SDK_FLAGS) -c -o $@ -xc -
  75. endif