Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

152 строки
3.7KB

  1. RELEASE ?= 0 # default debug
  2. UNICODE ?= 0 # default ansi
  3. VERSION ?= 0
  4. FILENAME ?= 1
  5. ARCHBITS ?= # 32/64 bits
  6. ifeq ($(shell uname -m), x86_64)
  7. ARCHBITS = 64
  8. else ifeq ($(shell getconf LONG_BIT), 64)
  9. ARCHBITS = 64
  10. else ifeq ($(shell arch), x86_64)
  11. ARCHBITS = 64
  12. endif
  13. ifdef PLATFORM
  14. CROSS:=$(PLATFORM)-
  15. else
  16. CROSS:=
  17. PLATFORM:=linux$(ARCHBITS)
  18. endif
  19. ifeq ($(RELEASE),1)
  20. BUILD:=release
  21. else
  22. BUILD:=debug
  23. endif
  24. KERNEL := $(shell uname -s)
  25. ifeq ($(KERNEL),Linux)
  26. DEFINES += OS_LINUX
  27. endif
  28. ifeq ($(KERNEL),Darwin)
  29. DEFINES += OS_MAC
  30. endif
  31. #--------------------------------Compile-----------------------------
  32. #
  33. #--------------------------------------------------------------------
  34. AR := $(CROSS)ar
  35. CC := $(CROSS)gcc
  36. CXX := $(CROSS)g++
  37. CFLAGS += -Wall -fPIC
  38. CXXFLAGS += -Wall
  39. ifeq ($(RELEASE),1)
  40. CFLAGS += -Wall -O2
  41. CXXFLAGS += $(CFLAGS)
  42. DEFINES += NDEBUG
  43. else
  44. CFLAGS += -g -Wall
  45. # CFLAGS += -fsanitize=address
  46. CXXFLAGS += $(CFLAGS)
  47. DEFINES += DEBUG _DEBUG
  48. endif
  49. ifeq ($(FILENAME),1)
  50. CFLAGS += -Wno-builtin-macro-redefined -D'__FILE_NAME__="$(notdir $<)"'
  51. endif
  52. ifeq ($(VERSION),1)
  53. VERSIONFILE = version.o
  54. endif
  55. # default don't export anything
  56. CFLAGS += -fvisibility=hidden
  57. COMPILE.CC = $(CC) $(addprefix -I,$(INCLUDES)) $(addprefix -D,$(DEFINES)) $(CFLAGS)
  58. COMPILE.CXX = $(CXX) $(addprefix -I,$(INCLUDES)) $(addprefix -D,$(DEFINES)) $(CXXFLAGS)
  59. #-------------------------Link---------------------------
  60. #
  61. #--------------------------------------------------------------------
  62. ifeq ($(STATIC_LINK),1)
  63. LDFLAGS += -static
  64. endif
  65. #-------------------------Compile Output---------------------------
  66. #
  67. #--------------------------------------------------------------------
  68. ifeq ($(UNICODE),1)
  69. OUTPATH += unicode.$(BUILD).$(PLATFORM)
  70. else
  71. OUTPATH += $(BUILD).$(PLATFORM)
  72. endif
  73. OBJSPATH = $(OUTPATH)/objs
  74. OBJECT_FILES := $(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(SOURCE_FILES)))
  75. OBJECT_FILES := $(addprefix $(OBJSPATH)/,$(OBJECT_FILES))
  76. DEPENDENCE_FILES := $(OBJECT_FILES:%.o=%.d)
  77. MKDIR = @mkdir -p $(dir $@)
  78. #--------------------------Makefile Rules----------------------------
  79. #
  80. #--------------------------------------------------------------------
  81. $(OUTPATH)/$(OUTFILE): $(OBJECT_FILES) $(STATIC_LIBS) $(VERSIONFILE)
  82. ifeq ($(OUTTYPE),0)
  83. $(CXX) -o $@ -Wl,-rpath=. $(LDFLAGS) $^ $(addprefix -L,$(LIBPATHS)) $(addprefix -l,$(LIBS))
  84. else
  85. ifeq ($(OUTTYPE),1)
  86. $(CXX) -o $@ -shared -fPIC -rdynamic -Wl,-rpath=. $(LDFLAGS) $^ $(addprefix -L,$(LIBPATHS)) $(addprefix -l,$(LIBS))
  87. else
  88. @echo -e "\033[35m AR $(notdir $@)\033[0m"
  89. @$(AR) -rc $@ $^
  90. endif
  91. endif
  92. @echo make ok, output: $(OUTPATH)/$(OUTFILE)
  93. $(OBJSPATH)/%.o : %.c
  94. $(MKDIR)
  95. @$(COMPILE.CC) -c -o $@ $<
  96. @echo -e "\033[35m CC $(notdir $@)\033[0m"
  97. $(OBJSPATH)/%.o : %.cpp
  98. $(MKDIR)
  99. @$(COMPILE.CXX) -c -o $@ $<
  100. @echo -e "\033[35m CXX $(notdir $@)\033[0m"
  101. $(OBJSPATH)/%.d: %.c
  102. $(MKDIR)
  103. @echo -e "\033[32m CREATE $(notdir $@)\033[0m"
  104. @rm -f $@; \
  105. $(COMPILE.CC) -MM $(CFLAGS) $< > $@.$$$$; \
  106. sed 's,\($(notdir $*)\)\.o[ :]*,$*\.o $@ : ,g' < $@.$$$$ > $@; \
  107. rm -f $@.$$$$
  108. $(OBJSPATH)/%.d: %.cpp
  109. $(MKDIR)
  110. @echo -e "\033[32m CREATE $(notdir $@)\033[0m"
  111. @rm -f $@; \
  112. $(COMPILE.CXX) -MM $(CXXFLAGS) $< > $@.$$$$; \
  113. sed 's,\($(notdir $*)\)\.o[ :]*,$*\.o $@ : ,g' < $@.$$$$ > $@; \
  114. rm -f $@.$$$$
  115. ifeq ($(MAKECMDGOALS), clean)
  116. else ifeq ($(MAKECMDGOALS), debug)
  117. else
  118. sinclude $(DEPENDENCE_FILES)
  119. endif
  120. version.o: version.ver $(OBJECT_FILES) $(STATIC_LIBS)
  121. $(ROOT)/gitver.sh version.ver version.c
  122. @$(COMPILE.CXX) -c -o $@ version.c
  123. .PHONY: clean
  124. clean:
  125. @echo -e "\033[35m rm -rf *.o *.d version.h $(OUTPATH)/$(OUTFILE) \033[0m"
  126. @rm -f $(OBJECT_FILES) $(OUTPATH)/$(OUTFILE) $(DEPENDENCE_FILES)
  127. @rm -f version.c version.o
  128. debug:
  129. echo $(OUTPATH)/$(OUTFILE)
  130. echo $(OBJECT_FILES)
  131. echo $(DEPENDENCE_FILES)