makefile 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. ###############################################################################
  2. #
  3. # Copyright 2010 Jonathan Wallace. All rights reserved.
  4. #
  5. # Redistribution and use in source and binary forms, with or without
  6. # modification, are permitted provided that the following conditions are met:
  7. #
  8. # 1. Redistributions of source code must retain the above copyright
  9. # notice, this list of conditions and the following disclaimer.
  10. #
  11. # 2. Redistributions in binary form must reproduce the above copyright
  12. # notice, this list of conditions and the following disclaimer in the
  13. # documentation and/or other materials provided with the distribution.
  14. #
  15. # THIS SOFTWARE IS PROVIDED BY JONATHAN WALLACE ``AS IS'' AND ANY
  16. # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  18. # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JONATHAN WALLACE OR
  19. # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  20. # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
  21. # TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  22. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  23. # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  24. # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  25. # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  26. # DAMAGE.
  27. #
  28. # The views and conclusions contained in the software and documentation are
  29. # those of the authors and should not be interpreted as representing official
  30. # policies, either expressed or implied, of Jonathan Wallace....
  31. #
  32. #
  33. # Author Bernhard Fluehmann
  34. #
  35. # [email protected]
  36. #
  37. #
  38. # TARGETS
  39. # all
  40. # Builds either a shared or a static library, depending of the value
  41. # of the SHARED variable.
  42. # Default: static
  43. #
  44. # banner
  45. # Displays the library version and the target
  46. #
  47. # install
  48. # Installs either the shared of the static library, depending of the value
  49. # of the SHARED variable. Installs the header files as well.
  50. # Builds the library before installing if it does not exist already.
  51. # Ececutes ldconfig in case of the shared library.
  52. # Default locations:
  53. # library: $(exec_prefix)/$(libdir) => /usr/lib
  54. # headers: $(prefix)/$(includedir) => /usr/include
  55. #
  56. # install_headers
  57. # Installs the header files.
  58. # Default location: $(prefix)/$(includedir) => /usr/include
  59. #
  60. # clean
  61. # Removes the shared or the static library, depending of the value
  62. # of the SHARED variable, from this folder and all the folders and objects
  63. # which were created to build it.
  64. #
  65. # uninstall
  66. # Removes the shared or the static library, depending of the value
  67. # of the SHARED variable from the system. In case of the shared library,
  68. # removes the symbolic links as well and executes ldconfig.
  69. #
  70. # uninstall_headers
  71. # Remove the headers from the system.
  72. #
  73. # Variables
  74. # prefix
  75. # The general installation root directory. Default: /usr
  76. #
  77. # exec_prefix
  78. # The installation root directory to place executables and libraries.
  79. # Default: prefix
  80. #
  81. # libdir
  82. # The directory where the libraries are installed, as a subdirectory of
  83. # exec_prefix. Default: lib
  84. #
  85. # includedir
  86. # The directory where the header files are installed, as a subdirectory of
  87. # prefix. Default: include
  88. #
  89. # srcdir
  90. # The directory where the object source files are located.
  91. # Default: _internal/Source
  92. #
  93. # CXX
  94. # The compiler to be used. Default: c++
  95. #
  96. # CXXFLAGS
  97. # The compiler flags used to compile the object files.
  98. # Default:
  99. # cxxflags_default for default
  100. # cxxflags_small for BUILD_TYPE=small
  101. # cxxflags_debug for BUILD_TYPE=debug
  102. #
  103. # AR
  104. # The archiver to be used. Default: ar
  105. #
  106. # PIC
  107. # The PIC to be used. Default: PIC
  108. #
  109. # BUILD_TYPE
  110. # Used to select a specific set of predefined configuration parameters.
  111. # Default: undefined: The default settings are used
  112. # Options:
  113. # small
  114. # debug
  115. #
  116. # SHARED
  117. # Used to select if the library is a shared or a dynamic one
  118. # Default: undefined: static
  119. # Options:
  120. # 0: static
  121. # 1: shared
  122. #
  123. #
  124. #
  125. # JSON source files to build
  126. objects = internalJSONNode.o JSONAllocator.o JSONChildren.o \
  127. JSONDebug.o JSONIterators.o JSONMemory.o JSONNode.o \
  128. JSONNode_Mutex.o JSONPreparse.o JSONStream.o JSONValidator.o \
  129. JSONWorker.o JSONWriter.o libjson.o
  130. OS=$(shell uname)
  131. # Defaults
  132. ifeq ($(OS), Darwin)
  133. cxxflags_default = -fast -ffast-math -fexpensive-optimizations -DNDEBUG
  134. else
  135. cxxflags_default = -O3 -ffast-math -fexpensive-optimizations -DNDEBUG
  136. endif
  137. cxxflags_small = -Os -ffast-math -DJSON_LESS_MEMORY -DNDEBUG
  138. cxxflags_debug = -g -DJSON_SAFE -DJSON_DEBUG
  139. cxxflags_shared = -f$(PIC)
  140. libname = libjson
  141. libname_hdr := $(libname)
  142. libname_debug = $(libname)_dbg
  143. suffix_shared = so
  144. suffix_static = a
  145. major_version = 7
  146. minor_version = 6.1
  147. objdir = Objects
  148. # Variables
  149. prefix ?= /usr
  150. exec_prefix ?= $(prefix)
  151. libdir ?= lib
  152. includedir ?= include
  153. srcdir ?= _internal/Source
  154. CXX ?= c++
  155. AR ?= ar
  156. PIC ?= PIC
  157. BUILD_TYPE ?= "default"
  158. SHARED ?= "1"
  159. # Internal Variables
  160. inst_path = $(exec_prefix)/$(libdir)
  161. include_path = $(prefix)/$(includedir)
  162. # Usage check
  163. ifdef CXXFLAGS
  164. ifdef BUILD_TYPE
  165. $(error CXXFLAGS and BUILD_TYPE are mutually exclusive)
  166. endif
  167. endif
  168. # BUILD_TYPE specific settings
  169. ifeq ($(BUILD_TYPE), small)
  170. CXXFLAGS = $(cxxflags_small)
  171. else ifeq ($(BUILD_TYPE), debug)
  172. CXXFLAGS = $(cxxflags_debug)
  173. libname := $(libname_debug)
  174. else
  175. CXXFLAGS ?= $(cxxflags_default)
  176. endif
  177. # SHARED specific settings
  178. ifeq ($(SHARED), 1)
  179. libname_shared = $(libname).$(suffix_shared)
  180. libname_shared_major_version = $(libname_shared).$(major_version)
  181. lib_target = $(libname_shared_major_version).$(minor_version)
  182. objdir := $(objdir)_shared
  183. CXXFLAGS := $(CXXFLAGS) $(cxxflags_shared)
  184. else
  185. lib_target = $(libname).$(suffix_static)
  186. objdir := $(objdir)_static
  187. endif
  188. # Phony targets
  189. .PHONY: all banner installdirs install install_headers clean uninstall \
  190. uninstall_headers
  191. # Targets
  192. all: $(lib_target)
  193. @echo "============================================================"
  194. @echo "Done"
  195. @echo "============================================================"
  196. banner:
  197. @echo "============================================================"
  198. @echo "libjson version: "$(major_version).$(minor_version) "target: "$(target) "OS: "$(OS)
  199. @echo "============================================================"
  200. installdirs: banner
  201. mkdir -p $(objdir)
  202. # Libraries
  203. ifeq ($(SHARED),1)
  204. $(lib_target): banner installdirs $(addprefix $(objdir)/, $(objects))
  205. @echo "Link "
  206. cd $(objdir) ; \
  207. if test "$(OS)" = "Darwin" ; then \
  208. $(CXX) -shared -Wl,-dylib_install_name -Wl,$(libname_shared_major_version) -o $@ $(objects) ; \
  209. else \
  210. $(CXX) -shared -Wl,-soname,$(libname_shared_major_version) -o $@ $(objects) ; \
  211. fi ; \
  212. mv -f $@ ../
  213. @echo "Link: Done"
  214. else
  215. $(lib_target): banner installdirs $(addprefix $(objdir)/, $(objects))
  216. @echo "Archive"
  217. cd $(objdir) ; \
  218. $(AR) -cvq $@ $(objects) ; \
  219. mv -f $@ ../
  220. @echo "Archive: Done"
  221. endif
  222. # Compile object files
  223. $(objdir)/%.o: $(srcdir)/%.cpp
  224. $(CXX) $< -o $@ -c $(CXXFLAGS)
  225. ifeq ($(SHARED),1)
  226. install: banner install_headers $(lib_target)
  227. @echo "Install shared library"
  228. cp -f ./$(lib_target) $(inst_path)
  229. cd $(inst_path) ; \
  230. ln -sf $(lib_target) $(libname_shared_major_version) ; \
  231. ln -sf $(libname_shared_major_version) $(libname_shared)
  232. ifneq ($(OS),Darwin)
  233. ldconfig
  234. endif
  235. @echo "Install shared library: Done."
  236. else
  237. install: banner install_headers $(lib_target)
  238. @echo "Install static library"
  239. cp -f ./$(lib_target) $(inst_path)
  240. @echo "Install static library: Done."
  241. endif
  242. install_headers: banner
  243. @echo "Install header files"
  244. mkdir -p $(include_path)/$(libname_hdr)
  245. cp -f ./*.h $(include_path)/$(libname_hdr)
  246. mkdir -p $(include_path)/$(libname_hdr)/$(srcdir)
  247. cp -f ./$(srcdir)/*.h $(include_path)/$(libname_hdr)/$(srcdir)
  248. cp -r ./$(srcdir)/JSONDefs $(include_path)/$(libname_hdr)/$(srcdir)
  249. chmod -R a+r $(include_path)/$(libname_hdr)
  250. find $(include_path)/$(libname_hdr) -type d -exec chmod a+x {} \;
  251. cp -rv $(srcdir)/Dependencies/ $(include_path)/$(libname_hdr)/$(srcdir)
  252. @echo "Install header files: Done."
  253. clean: banner
  254. @echo "Clean library and object folder"
  255. rm -rf $(objdir)
  256. rm -f $(lib_target)
  257. @echo "Clean library and object folder: Done"
  258. ifeq ($(SHARED),1)
  259. uninstall: banner uninstall_headers
  260. @echo "Uninstall shared library"
  261. rm -f $(inst_path)/$(libname_shared)
  262. rm -f $(inst_path)/$(libname_shared_major_version)
  263. rm -f $(inst_path)/$(lib_target)
  264. ifneq ($(OS),Darwin)
  265. ldconfig
  266. endif
  267. @echo "Uninstall shared library: Done"
  268. else
  269. uninstall: banner uninstall_headers
  270. @echo "Uninstall static library"
  271. rm -f $(inst_path)/$(lib_target)
  272. @echo "Uninstall static library: Done"
  273. endif
  274. uninstall_headers: banner
  275. @echo "Uninstall header files"
  276. rm -rf $(include_path)/$(libname_hdr)
  277. @echo "Uninstall header files: Done"
  278. test:
  279. $(CXX) _internal/TestSuite/main.cpp _internal/TestSuite/TestAssign.cpp _internal/TestSuite/TestChildren.cpp \
  280. _internal/TestSuite/TestComments.cpp _internal/TestSuite/TestConverters.cpp _internal/TestSuite/TestCtors.cpp \
  281. _internal/TestSuite/TestEquality.cpp _internal/TestSuite/TestFunctions.cpp _internal/TestSuite/TestInequality.cpp \
  282. _internal/TestSuite/TestInspectors.cpp _internal/TestSuite/TestIterators.cpp _internal/TestSuite/TestMutex.cpp \
  283. _internal/TestSuite/TestNamespace.cpp _internal/TestSuite/TestRefCounting.cpp _internal/TestSuite/TestSuite.cpp \
  284. _internal/TestSuite/TestWriter.cpp _internal/TestSuite/TestString.cpp _internal/TestSuite/UnitTest.cpp \
  285. _internal/TestSuite/TestValidator.cpp _internal/TestSuite/TestStreams.cpp _internal/TestSuite/TestBinary.cpp \
  286. _internal/TestSuite/RunTestSuite2.cpp _internal/TestSuite/TestSharedString.cpp \
  287. _internal/Source/internalJSONNode.cpp _internal/Source/JSONPreparse.cpp _internal/Source/JSONChildren.cpp \
  288. _internal/Source/JSONDebug.cpp _internal/Source/JSONIterators.cpp _internal/Source/JSONMemory.cpp \
  289. _internal/Source/JSONNode_Mutex.cpp _internal/Source/JSONNode.cpp _internal/Source/JSONWorker.cpp \
  290. _internal/Source/JSONWriter.cpp _internal/Source/libjson.cpp _internal/Source/JSONValidator.cpp \
  291. _internal/Source/JSONStream.cpp _internal/Source/JSONAllocator.cpp \
  292. _internal/TestSuite/TestSuite2/JSON_Base64/json_decode64.cpp \
  293. _internal/TestSuite/TestSuite2/JSON_Base64/json_encode64.cpp \
  294. _internal/TestSuite/TestSuite2/JSONDebug/JSON_ASSERT_SAFE.cpp \
  295. _internal/TestSuite/TestSuite2/JSONDebug/JSON_ASSERT.cpp \
  296. _internal/TestSuite/TestSuite2/JSONDebug/JSON_FAIL_SAFE.cpp \
  297. _internal/TestSuite/TestSuite2/JSONDebug/JSON_FAIL.cpp \
  298. _internal/TestSuite/TestSuite2/JSONGlobals/jsonSingleton.cpp \
  299. _internal/TestSuite/TestSuite2/JSONValidator/isValidArray.cpp \
  300. _internal/TestSuite/TestSuite2/JSONValidator/isValidMember.cpp \
  301. _internal/TestSuite/TestSuite2/JSONValidator/isValidNamedObject.cpp \
  302. _internal/TestSuite/TestSuite2/JSONValidator/isValidNumber.cpp \
  303. _internal/TestSuite/TestSuite2/JSONValidator/isValidObject.cpp \
  304. _internal/TestSuite/TestSuite2/JSONValidator/isValidPartialRoot.cpp \
  305. _internal/TestSuite/TestSuite2/JSONValidator/isValidRoot.cpp \
  306. _internal/TestSuite/TestSuite2/JSONValidator/isValidString.cpp \
  307. _internal/TestSuite/TestSuite2/JSONValidator/securityTest.cpp \
  308. _internal/TestSuite/TestSuite2/NumberToString/_areFloatsEqual.cpp \
  309. _internal/TestSuite/TestSuite2/NumberToString/_atof.cpp \
  310. _internal/TestSuite/TestSuite2/NumberToString/_ftoa.cpp \
  311. _internal/TestSuite/TestSuite2/NumberToString/_itoa.cpp \
  312. _internal/TestSuite/TestSuite2/NumberToString/_uitoa.cpp \
  313. _internal/TestSuite/TestSuite2/NumberToString/getLenSize.cpp \
  314. _internal/TestSuite/TestSuite2/NumberToString/isNumeric.cpp \
  315. $(CXXFLAGS) -o ./testapp
  316. ./testapp