Makefile 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. # Copyright (c) 2011 The LevelDB Authors. All rights reserved.
  2. # Use of this source code is governed by a BSD-style license that can be
  3. # found in the LICENSE file. See the AUTHORS file for names of contributors.
  4. #-----------------------------------------------
  5. # Uncomment exactly one of the lines labelled (A), (B), and (C) below
  6. # to switch between compilation modes.
  7. # (A) Production use (optimized mode)
  8. OPT ?= -O2 -DNDEBUG
  9. # (B) Debug mode, w/ full line-level debugging symbols
  10. # OPT ?= -g2
  11. # (C) Profiling mode: opt, but w/debugging symbols
  12. # OPT ?= -O2 -g2 -DNDEBUG
  13. #-----------------------------------------------
  14. # detect what platform we're building on
  15. $(shell CC="$(CC)" CXX="$(CXX)" TARGET_OS="$(TARGET_OS)" \
  16. ./build_detect_platform build_config.mk ./)
  17. # this file is generated by the previous line to set build flags and sources
  18. include build_config.mk
  19. CFLAGS += -I. -I./include $(PLATFORM_CCFLAGS) $(OPT)
  20. CXXFLAGS += -I. -I./include $(PLATFORM_CXXFLAGS) $(OPT)
  21. LDFLAGS += $(PLATFORM_LDFLAGS)
  22. LIBS += $(PLATFORM_LIBS)
  23. LIBOBJECTS = $(SOURCES:.cc=.o)
  24. MEMENVOBJECTS = $(MEMENV_SOURCES:.cc=.o)
  25. TESTUTIL = ./util/testutil.o
  26. TESTHARNESS = ./util/testharness.o $(TESTUTIL)
  27. # Note: iOS should probably be using libtool, not ar.
  28. ifeq ($(PLATFORM), IOS)
  29. AR=xcrun ar
  30. endif
  31. TESTS = \
  32. arena_test \
  33. autocompact_test \
  34. bloom_test \
  35. c_test \
  36. cache_test \
  37. coding_test \
  38. corruption_test \
  39. crc32c_test \
  40. db_test \
  41. dbformat_test \
  42. env_test \
  43. fault_injection_test \
  44. filename_test \
  45. filter_block_test \
  46. hash_test \
  47. issue178_test \
  48. issue200_test \
  49. log_test \
  50. memenv_test \
  51. recovery_test \
  52. skiplist_test \
  53. table_test \
  54. version_edit_test \
  55. version_set_test \
  56. write_batch_test
  57. PROGRAMS = db_bench leveldbutil $(TESTS)
  58. BENCHMARKS = db_bench_sqlite3 db_bench_tree_db
  59. LIBRARY = libleveldb.a
  60. MEMENVLIBRARY = libmemenv.a
  61. default: all
  62. # Should we build shared libraries?
  63. ifneq ($(PLATFORM_SHARED_EXT),)
  64. ifneq ($(PLATFORM_SHARED_VERSIONED),true)
  65. SHARED1 = libleveldb.$(PLATFORM_SHARED_EXT)
  66. SHARED2 = $(SHARED1)
  67. SHARED3 = $(SHARED1)
  68. SHARED = $(SHARED1)
  69. else
  70. # Update db.h if you change these.
  71. SHARED_MAJOR = 1
  72. SHARED_MINOR = 18
  73. SHARED1 = libleveldb.$(PLATFORM_SHARED_EXT)
  74. SHARED2 = $(SHARED1).$(SHARED_MAJOR)
  75. SHARED3 = $(SHARED1).$(SHARED_MAJOR).$(SHARED_MINOR)
  76. SHARED = $(SHARED1) $(SHARED2) $(SHARED3)
  77. $(SHARED1): $(SHARED3)
  78. ln -fs $(SHARED3) $(SHARED1)
  79. $(SHARED2): $(SHARED3)
  80. ln -fs $(SHARED3) $(SHARED2)
  81. endif
  82. $(SHARED3):
  83. $(CXX) $(LDFLAGS) $(PLATFORM_SHARED_LDFLAGS)$(SHARED2) $(CXXFLAGS) $(PLATFORM_SHARED_CFLAGS) $(SOURCES) -o $(SHARED3) $(LIBS)
  84. endif # PLATFORM_SHARED_EXT
  85. all: $(SHARED) $(LIBRARY)
  86. check: all $(PROGRAMS) $(TESTS)
  87. for t in $(TESTS); do echo "***** Running $$t"; ./$$t || exit 1; done
  88. clean:
  89. -rm -f $(PROGRAMS) $(BENCHMARKS) $(LIBRARY) $(SHARED) $(MEMENVLIBRARY) */*.o */*/*.o ios-x86/*/*.o ios-arm/*/*.o build_config.mk
  90. -rm -rf ios-x86/* ios-arm/*
  91. $(LIBRARY): $(LIBOBJECTS)
  92. rm -f $@
  93. $(AR) -rs $@ $(LIBOBJECTS)
  94. db_bench: db/db_bench.o $(LIBOBJECTS) $(TESTUTIL)
  95. $(CXX) $(LDFLAGS) db/db_bench.o $(LIBOBJECTS) $(TESTUTIL) -o $@ $(LIBS)
  96. db_bench_sqlite3: doc/bench/db_bench_sqlite3.o $(LIBOBJECTS) $(TESTUTIL)
  97. $(CXX) $(LDFLAGS) doc/bench/db_bench_sqlite3.o $(LIBOBJECTS) $(TESTUTIL) -o $@ -lsqlite3 $(LIBS)
  98. db_bench_tree_db: doc/bench/db_bench_tree_db.o $(LIBOBJECTS) $(TESTUTIL)
  99. $(CXX) $(LDFLAGS) doc/bench/db_bench_tree_db.o $(LIBOBJECTS) $(TESTUTIL) -o $@ -lkyotocabinet $(LIBS)
  100. leveldbutil: db/leveldb_main.o $(LIBOBJECTS)
  101. $(CXX) $(LDFLAGS) db/leveldb_main.o $(LIBOBJECTS) -o $@ $(LIBS)
  102. arena_test: util/arena_test.o $(LIBOBJECTS) $(TESTHARNESS)
  103. $(CXX) $(LDFLAGS) util/arena_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS)
  104. autocompact_test: db/autocompact_test.o $(LIBOBJECTS) $(TESTHARNESS)
  105. $(CXX) $(LDFLAGS) db/autocompact_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS)
  106. bloom_test: util/bloom_test.o $(LIBOBJECTS) $(TESTHARNESS)
  107. $(CXX) $(LDFLAGS) util/bloom_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS)
  108. c_test: db/c_test.o $(LIBOBJECTS) $(TESTHARNESS)
  109. $(CXX) $(LDFLAGS) db/c_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS)
  110. cache_test: util/cache_test.o $(LIBOBJECTS) $(TESTHARNESS)
  111. $(CXX) $(LDFLAGS) util/cache_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS)
  112. coding_test: util/coding_test.o $(LIBOBJECTS) $(TESTHARNESS)
  113. $(CXX) $(LDFLAGS) util/coding_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS)
  114. corruption_test: db/corruption_test.o $(LIBOBJECTS) $(TESTHARNESS)
  115. $(CXX) $(LDFLAGS) db/corruption_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS)
  116. crc32c_test: util/crc32c_test.o $(LIBOBJECTS) $(TESTHARNESS)
  117. $(CXX) $(LDFLAGS) util/crc32c_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS)
  118. db_test: db/db_test.o $(LIBOBJECTS) $(TESTHARNESS)
  119. $(CXX) $(LDFLAGS) db/db_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS)
  120. dbformat_test: db/dbformat_test.o $(LIBOBJECTS) $(TESTHARNESS)
  121. $(CXX) $(LDFLAGS) db/dbformat_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS)
  122. env_test: util/env_test.o $(LIBOBJECTS) $(TESTHARNESS)
  123. $(CXX) $(LDFLAGS) util/env_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS)
  124. fault_injection_test: db/fault_injection_test.o $(LIBOBJECTS) $(TESTHARNESS)
  125. $(CXX) $(LDFLAGS) db/fault_injection_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS)
  126. filename_test: db/filename_test.o $(LIBOBJECTS) $(TESTHARNESS)
  127. $(CXX) $(LDFLAGS) db/filename_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS)
  128. filter_block_test: table/filter_block_test.o $(LIBOBJECTS) $(TESTHARNESS)
  129. $(CXX) $(LDFLAGS) table/filter_block_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS)
  130. hash_test: util/hash_test.o $(LIBOBJECTS) $(TESTHARNESS)
  131. $(CXX) $(LDFLAGS) util/hash_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS)
  132. issue178_test: issues/issue178_test.o $(LIBOBJECTS) $(TESTHARNESS)
  133. $(CXX) $(LDFLAGS) issues/issue178_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS)
  134. issue200_test: issues/issue200_test.o $(LIBOBJECTS) $(TESTHARNESS)
  135. $(CXX) $(LDFLAGS) issues/issue200_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS)
  136. log_test: db/log_test.o $(LIBOBJECTS) $(TESTHARNESS)
  137. $(CXX) $(LDFLAGS) db/log_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS)
  138. recovery_test: db/recovery_test.o $(LIBOBJECTS) $(TESTHARNESS)
  139. $(CXX) $(LDFLAGS) db/recovery_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS)
  140. table_test: table/table_test.o $(LIBOBJECTS) $(TESTHARNESS)
  141. $(CXX) $(LDFLAGS) table/table_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS)
  142. skiplist_test: db/skiplist_test.o $(LIBOBJECTS) $(TESTHARNESS)
  143. $(CXX) $(LDFLAGS) db/skiplist_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS)
  144. version_edit_test: db/version_edit_test.o $(LIBOBJECTS) $(TESTHARNESS)
  145. $(CXX) $(LDFLAGS) db/version_edit_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS)
  146. version_set_test: db/version_set_test.o $(LIBOBJECTS) $(TESTHARNESS)
  147. $(CXX) $(LDFLAGS) db/version_set_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS)
  148. write_batch_test: db/write_batch_test.o $(LIBOBJECTS) $(TESTHARNESS)
  149. $(CXX) $(LDFLAGS) db/write_batch_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS)
  150. $(MEMENVLIBRARY) : $(MEMENVOBJECTS)
  151. rm -f $@
  152. $(AR) -rs $@ $(MEMENVOBJECTS)
  153. memenv_test : helpers/memenv/memenv_test.o $(MEMENVLIBRARY) $(LIBRARY) $(TESTHARNESS)
  154. $(CXX) $(LDFLAGS) helpers/memenv/memenv_test.o $(MEMENVLIBRARY) $(LIBRARY) $(TESTHARNESS) -o $@ $(LIBS)
  155. ifeq ($(PLATFORM), IOS)
  156. # For iOS, create universal object files to be used on both the simulator and
  157. # a device.
  158. SIMULATORSDK=$(shell xcrun -sdk iphonesimulator --show-sdk-path)
  159. DEVICESDK=$(shell xcrun -sdk iphoneos --show-sdk-path)
  160. IOSARCH=-arch armv6 -arch armv7 -arch armv7s -arch arm64
  161. .cc.o:
  162. mkdir -p ios-x86/$(dir $@)
  163. xcrun -sdk iphonesimulator $(CXX) $(CXXFLAGS) -isysroot "$(SIMULATORSDK)" -arch i686 -arch x86_64 -c $< -o ios-x86/$@
  164. mkdir -p ios-arm/$(dir $@)
  165. xcrun -sdk iphoneos $(CXX) $(CXXFLAGS) -isysroot "$(DEVICESDK)" $(IOSARCH) -c $< -o ios-arm/$@
  166. xcrun lipo ios-x86/$@ ios-arm/$@ -create -output $@
  167. .c.o:
  168. mkdir -p ios-x86/$(dir $@)
  169. xcrun -sdk iphonesimulator $(CC) $(CFLAGS) -isysroot "$(SIMULATORSDK)" -arch i686 -arch x86_64 -c $< -o ios-x86/$@
  170. mkdir -p ios-arm/$(dir $@)
  171. xcrun -sdk iphoneos $(CC) $(CFLAGS) -isysroot "$(DEVICESDK)" $(IOSARCH) -c $< -o ios-arm/$@
  172. xcrun lipo ios-x86/$@ ios-arm/$@ -create -output $@
  173. else
  174. .cc.o:
  175. $(CXX) $(CXXFLAGS) -c $< -o $@
  176. .c.o:
  177. $(CC) $(CFLAGS) -c $< -o $@
  178. endif