GNUmakefile 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. SHELL = /bin/sh
  2. .SUFFIXES:
  3. .SUFFIXES: .cpp .o .d .h
  4. OS := $(shell uname | sed 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/')
  5. x64 := $(shell uname -m)
  6. ENDIAN := $(shell uname -m)
  7. ENDIAN := $(patsubst i%86,LITTLE_ENDIAN,$(ENDIAN))
  8. ENDIAN := $(patsubst x86_64,LITTLE_ENDIAN,$(ENDIAN))
  9. ENDIAN := $(patsubst Power Macintosh,BIG_ENDIAN,$(ENDIAN))
  10. CXX=g++ -std=c++11 -Wno-deprecated
  11. ##########################################################
  12. ########### Platform specific stuff #####################
  13. ##########################################################
  14. ifeq ($(OS),LINUX)
  15. ### Raspbian is reported as a Linux OS
  16. ### and reports 'armv6l' via uname -m
  17. ### so we check -m to detect it properly
  18. ifeq ($(x64),armv6l)
  19. #PLATFORM_DEFINES=-DPLATFORM_ARMv6
  20. # this is for GCC 4.6.x to make a legacy compatible compile ??
  21. PLATFORM_DEFINES=-DPLATFORM_ARMv6 -mcpu=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -ffunction-sections -fdata-sections -Wl,--gc-sections
  22. PLATFORM_LIBS=\
  23. libs/Aol_XML/ARMv6/libexpat.a\
  24. libs/libcurl/ARMv6/libcurl.a\
  25. libs/libcurl/ARMv6/libssl.a\
  26. libs/libcurl/ARMv6/libcrypto.a\
  27. libs/zlib/ARMv6/libz.a\
  28. -lrt\
  29. -lpthread\
  30. -ldl
  31. ### the RPi2 is reported as a Linux OS
  32. ### and reports 'armv7l' via uname -m
  33. ### so we check -m to detect it properly
  34. else ifeq ($(x64),armv7l)
  35. # https://www.raspberrypi.org/forums/viewtopic.php?p=684549#p684549
  36. # this is for GCC 4.6.x
  37. #PLATFORM_DEFINES=-DPLATFORM_ARMv7 -march=armv7-a -mfpu=neon-vfpv4 -mfloat-abi=hard
  38. # this is for GCC 4.8.x (default is 4.6.x on Raspbian)
  39. PLATFORM_DEFINES=-DPLATFORM_ARMv7 -mcpu=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard -Wno-unused-result -Wno-ignored-qualifiers -Wno-long-long -Wno-missing-field-initializers -ffunction-sections -fdata-sections -Wl,--gc-sections
  40. # this is for GCC 4.6.x to make a legacy compatible compile ??
  41. #PLATFORM_DEFINES=-DPLATFORM_ARMv6 -mcpu=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard
  42. PLATFORM_LIBS=\
  43. libs/Aol_XML/ARMv7/libexpat.a\
  44. libs/libcurl/ARMv7/libcurl.a\
  45. libs/libcurl/ARMv7/libssl.a\
  46. libs/libcurl/ARMv7/libcrypto.a\
  47. libs/zlib/ARMv7/libz.a\
  48. -lrt\
  49. -lpthread\
  50. -ldl
  51. else
  52. PLATFORM_DEFINES=-DPLATFORM_LINUX -Wno-unused-result -Wno-ignored-qualifiers -Wno-long-long -Wno-missing-field-initializers -ffunction-sections -fdata-sections -Wl,--gc-sections
  53. ### Linux platform specific includes
  54. ### with 32-bit and 64-bit handling
  55. ifeq ($(x64),x86_64)
  56. INCLUDES=-Ideps/x86_64/include
  57. PLATFORM_LIBS=\
  58. -Ldeps/x86_64/lib -lexpat -lcurl -lssl -lcrypto -lpthread -lz -lrt -ldl
  59. else
  60. CXX += -m32
  61. INCLUDES=-Ideps/i686/include
  62. PLATFORM_LIBS=\
  63. -Ldeps/i686/lib -lexpat -lcurl -lssl -lcrypto -lpthread -lz -lrt -ldl
  64. endif
  65. endif
  66. ###################################
  67. else
  68. ifeq ($(OS),FREEBSD)
  69. # CXX=g++44
  70. PLATFORM_DEFINES=-DPLATFORM_BSD -Wno-long-long -Wno-missing-field-initializers
  71. PLATFORM_LIBS=\
  72. libs/Aol_XML/BSD/libexpat.a\
  73. libs/libcurl/BSD/libcurl.a\
  74. libs/libcurl/BSD/libssl.a\
  75. libs/libcurl/BSD/libcrypto.a\
  76. libs/zlib/BSD/libz.a\
  77. -lpthread\
  78. # -R /usr/local/lib/gcc44
  79. else
  80. ifeq ($(OS),DARWIN)
  81. PLATFORM_DEFINES=-DPLATFORM_MAC -Wno-long-long -Wno-missing-field-initializers
  82. PLATFORM_LIBS=\
  83. libs/Aol_XML/Darwin/libexpat.a\
  84. libs/libcurl/Darwin/libcurl.a\
  85. libs/libcurl/Darwin/libssl.a\
  86. libs/libcurl/Darwin/libcrypto.a\
  87. libs/zlib/Darwin/libz.a\
  88. -lpthread
  89. else
  90. ERR = $(error Unknown operating system $(OS))
  91. endif
  92. endif
  93. endif
  94. ifneq ($(ENDIAN),LITTLE_ENDIAN)
  95. ifneq ($(ENDIAN),BIG_ENDIAN)
  96. ERR = $(error Unknown endian $(ENDIAN))
  97. endif
  98. endif
  99. ##########################################################
  100. ##########################################################
  101. ##########################################################
  102. ##########################################################
  103. ##########################################################
  104. INCLUDES += -I. -InmrCommon
  105. #INCLUDES=-I. -InmrCommon -Izlib -Ilibcurl/include -IGeoIP/libGeoIP
  106. LIBS=$(PLATFORM_LIBS)
  107. CPPFLAGS=$(PLATFORM_DEFINES) -MMD -MP -D_REENTRANT -DCURL_STATICLIB -Wno-unused-function -Wno-sign-compare -Wno-unknown-pragmas -Wall -Wextra -pedantic
  108. CFLAGS_RELEASE=-O2 -static-libgcc -static-libstdc++ -rdynamic
  109. CPPFLAGS_RELEASE=$(CPPFLAGS) -O2 -DNDEBUG -g
  110. CFLAGS_DEBUG=-static-libgcc -static-libstdc++ -rdynamic
  111. CPPFLAGS_DEBUG=$(CPPFLAGS) -ggdb -DDEBUG
  112. VPATH=nmrCommon/threading nmrCommon/stacktrace nmrCommon/services nmrCommon/file nmrCommon/unicode webNet aolxml
  113. #VPATH=nmrCommon/threading nmrCommon/stacktrace nmrCommon/services nmrCommon/file nmrCommon/unicode webNet aolxml GeoIP/libGeoIP
  114. C_SOURCES=\
  115. $(wildcard *.c)
  116. #C_SOURCES=\
  117. # $(wildcard *.c)\
  118. # $(wildcard GeoIP/libGeoIP/*.c)
  119. CXX_SOURCES=\
  120. $(wildcard *.cpp)\
  121. $(wildcard nmrCommon/threading/thread.cpp)\
  122. $(wildcard nmrCommon/stacktrace/StackTrace.cpp)\
  123. $(wildcard nmrCommon/services/logger.cpp)\
  124. $(wildcard nmrCommon/services/serviceMain.cpp)\
  125. $(wildcard nmrCommon/services/stdServiceImpl.cpp)\
  126. $(wildcard nmrCommon/file/fileUtils.cpp)\
  127. $(wildcard nmrCommon/unicode/*.cpp)\
  128. $(wildcard webNet/*.cpp)\
  129. $(wildcard aolxml/*.cpp)
  130. SOURCE_FILES=$(C_SOURCES) $(CXX_SOURCES)
  131. OBJECT_FILES=$(addsuffix .o,$(basename $(notdir $(SOURCE_FILES))))
  132. DEBUG_OBJECTS=$(addprefix debug/,$(OBJECT_FILES))
  133. RELEASE_OBJECTS=$(addprefix release/,$(OBJECT_FILES))
  134. .PHONY: default
  135. default: release
  136. release/config.o debug/config.o: unixversion.h
  137. release/serviceMain.o debug/serviceMain.o: unixversion.h
  138. ##############################################################
  139. ### Create unix version header from Win32 resource file
  140. unixversion.h: sc_serv.rc
  141. @grep --text 'PRODUCTVERSION' sc_serv.rc | sed 's/PRODUCTVERSION/static int & \[VENT\]=\{/' | sed 's/[0-9]*,[0-9]*,[0-9]*,[0-9]*/&\};/' > unixversion_tmp.h
  142. @echo '#define VENT 4' | cat - unixversion_tmp.h > unixversion.h
  143. @rm -f unixversion_tmp.h
  144. ################# File rules #########################3
  145. debug/%.o: %.cpp
  146. $(CXX) $(CPPFLAGS_DEBUG) $(INCLUDES) -c $< -o $@
  147. debug/%.o: %.c
  148. $(CXX) $(CPPFLAGS_DEBUG) $(INCLUDES) -c $< -o $@
  149. release/%.o: %.cpp
  150. $(CXX) $(CPPFLAGS_RELEASE) $(INCLUDES) -c $< -o $@
  151. release/%.o: %.c
  152. $(CXX) $(CPPFLAGS_RELEASE) $(INCLUDES) -c $< -o $@
  153. #release/%.o: GeoIP/libGeoIP/%.c
  154. # $(CXX) $(CPPFLAGS_RELEASE) $(INCLUDES) -c $< -o $@
  155. ############################################################
  156. sc_serv_debug: $(DEBUG_OBJECTS)
  157. $(CXX) -o sc_serv_debug $(CFLAGS_DEBUG) $(DEBUG_OBJECTS) $(LIBS)
  158. @./sc_serv_debug -v
  159. @echo
  160. sc_serv: sc_serv_notstripped
  161. strip -o sc_serv sc_serv_notstripped
  162. @echo
  163. sc_serv_notstripped: $(RELEASE_OBJECTS)
  164. $(CXX) -o sc_serv_notstripped $(CFLAGS_RELEASE) $(RELEASE_OBJECTS) $(LIBS)
  165. @./sc_serv_notstripped -v
  166. releasedir:
  167. @mkdir -p release
  168. debugdir:
  169. @mkdir -p debug
  170. .PHONY: clean
  171. .PHONY: release
  172. .PHONY: debug
  173. release: releasedir sc_serv
  174. release_nostrip: releasedir sc_serv_notstripped
  175. debug: debugdir sc_serv_debug
  176. clean:
  177. @rm -rf debug
  178. @rm -rf release
  179. @rm -f unixversion.h
  180. .PHONY: err
  181. err: ; $(ERR)
  182. ##################################################3
  183. ifeq ($(MAKECMDGOALS),release)
  184. -include $(RELEASE_OBJECTS:.o=.d)
  185. else
  186. ifneq ($(MAKECMDGOALS),clean)
  187. -include $(DEBUG_OBJECTS:.o=.d)
  188. endif
  189. endif