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 #----------------------------------------------- 6 # Uncomment exactly one of the lines labelled (A), (B), and (C) below 7 # to switch between compilation modes. 8 9 OPT ?= -O2 -DNDEBUG # (A) Production use (optimized mode) 10 # OPT ?= -g2 # (B) Debug mode, w/ full line-level debugging symbols 11 # OPT ?= -O2 -g2 -DNDEBUG # (C) Profiling mode: opt, but w/debugging symbols 12 #----------------------------------------------- 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 20 CFLAGS += -I. -I./include $(PLATFORM_CCFLAGS) $(OPT) 21 CXXFLAGS += -I. -I./include $(PLATFORM_CXXFLAGS) $(OPT) 22 23 LDFLAGS += $(PLATFORM_LDFLAGS) 24 LIBS += $(PLATFORM_LIBS) 25 26 LIBOBJECTS = $(SOURCES:.cc=.o) 27 MEMENVOBJECTS = $(MEMENV_SOURCES:.cc=.o) 28 29 TESTUTIL = ./util/testutil.o 30 TESTHARNESS = ./util/testharness.o $(TESTUTIL) 31 32 TESTS = \ 33 arena_test \ 34 autocompact_test \ 35 bloom_test \ 36 c_test \ 37 cache_test \ 38 coding_test \ 39 corruption_test \ 40 crc32c_test \ 41 db_test \ 42 dbformat_test \ 43 env_test \ 44 filename_test \ 45 filter_block_test \ 46 issue178_test \ 47 issue200_test \ 48 log_test \ 49 memenv_test \ 50 skiplist_test \ 51 table_test \ 52 version_edit_test \ 53 version_set_test \ 54 write_batch_test 55 56 PROGRAMS = db_bench leveldbutil $(TESTS) 57 BENCHMARKS = db_bench_sqlite3 db_bench_tree_db 58 59 LIBRARY = libleveldb.a 60 MEMENVLIBRARY = libmemenv.a 61 62 default: all 63 64 # Should we build shared libraries? 65 ifneq ($(PLATFORM_SHARED_EXT),) 66 67 ifneq ($(PLATFORM_SHARED_VERSIONED),true) 68 SHARED1 = libleveldb.$(PLATFORM_SHARED_EXT) 69 SHARED2 = $(SHARED1) 70 SHARED3 = $(SHARED1) 71 SHARED = $(SHARED1) 72 else 73 # Update db.h if you change these. 74 SHARED_MAJOR = 1 75 SHARED_MINOR = 15 76 SHARED1 = libleveldb.$(PLATFORM_SHARED_EXT) 77 SHARED2 = $(SHARED1).$(SHARED_MAJOR) 78 SHARED3 = $(SHARED1).$(SHARED_MAJOR).$(SHARED_MINOR) 79 SHARED = $(SHARED1) $(SHARED2) $(SHARED3) 80 $(SHARED1): $(SHARED3) 81 ln -fs $(SHARED3) $(SHARED1) 82 $(SHARED2): $(SHARED3) 83 ln -fs $(SHARED3) $(SHARED2) 84 endif 85 86 $(SHARED3): 87 $(CXX) $(LDFLAGS) $(PLATFORM_SHARED_LDFLAGS)$(SHARED2) $(CXXFLAGS) $(PLATFORM_SHARED_CFLAGS) $(SOURCES) -o $(SHARED3) $(LIBS) 88 89 endif # PLATFORM_SHARED_EXT 90 91 all: $(SHARED) $(LIBRARY) 92 93 check: all $(PROGRAMS) $(TESTS) 94 for t in $(TESTS); do echo "***** Running $$t"; ./$$t || exit 1; done 95 96 clean: 97 -rm -f $(PROGRAMS) $(BENCHMARKS) $(LIBRARY) $(SHARED) $(MEMENVLIBRARY) */*.o */*/*.o ios-x86/*/*.o ios-arm/*/*.o build_config.mk 98 -rm -rf ios-x86/* ios-arm/* 99 100 $(LIBRARY): $(LIBOBJECTS) 101 rm -f $@ 102 $(AR) -rs $@ $(LIBOBJECTS) 103 104 db_bench: db/db_bench.o $(LIBOBJECTS) $(TESTUTIL) 105 $(CXX) $(LDFLAGS) db/db_bench.o $(LIBOBJECTS) $(TESTUTIL) -o $@ $(LIBS) 106 107 db_bench_sqlite3: doc/bench/db_bench_sqlite3.o $(LIBOBJECTS) $(TESTUTIL) 108 $(CXX) $(LDFLAGS) doc/bench/db_bench_sqlite3.o $(LIBOBJECTS) $(TESTUTIL) -o $@ -lsqlite3 $(LIBS) 109 110 db_bench_tree_db: doc/bench/db_bench_tree_db.o $(LIBOBJECTS) $(TESTUTIL) 111 $(CXX) $(LDFLAGS) doc/bench/db_bench_tree_db.o $(LIBOBJECTS) $(TESTUTIL) -o $@ -lkyotocabinet $(LIBS) 112 113 leveldbutil: db/leveldb_main.o $(LIBOBJECTS) 114 $(CXX) $(LDFLAGS) db/leveldb_main.o $(LIBOBJECTS) -o $@ $(LIBS) 115 116 arena_test: util/arena_test.o $(LIBOBJECTS) $(TESTHARNESS) 117 $(CXX) $(LDFLAGS) util/arena_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS) 118 119 autocompact_test: db/autocompact_test.o $(LIBOBJECTS) $(TESTHARNESS) 120 $(CXX) $(LDFLAGS) db/autocompact_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS) 121 122 bloom_test: util/bloom_test.o $(LIBOBJECTS) $(TESTHARNESS) 123 $(CXX) $(LDFLAGS) util/bloom_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS) 124 125 c_test: db/c_test.o $(LIBOBJECTS) $(TESTHARNESS) 126 $(CXX) $(LDFLAGS) db/c_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS) 127 128 cache_test: util/cache_test.o $(LIBOBJECTS) $(TESTHARNESS) 129 $(CXX) $(LDFLAGS) util/cache_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS) 130 131 coding_test: util/coding_test.o $(LIBOBJECTS) $(TESTHARNESS) 132 $(CXX) $(LDFLAGS) util/coding_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS) 133 134 corruption_test: db/corruption_test.o $(LIBOBJECTS) $(TESTHARNESS) 135 $(CXX) $(LDFLAGS) db/corruption_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS) 136 137 crc32c_test: util/crc32c_test.o $(LIBOBJECTS) $(TESTHARNESS) 138 $(CXX) $(LDFLAGS) util/crc32c_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS) 139 140 db_test: db/db_test.o $(LIBOBJECTS) $(TESTHARNESS) 141 $(CXX) $(LDFLAGS) db/db_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS) 142 143 dbformat_test: db/dbformat_test.o $(LIBOBJECTS) $(TESTHARNESS) 144 $(CXX) $(LDFLAGS) db/dbformat_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS) 145 146 env_test: util/env_test.o $(LIBOBJECTS) $(TESTHARNESS) 147 $(CXX) $(LDFLAGS) util/env_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS) 148 149 filename_test: db/filename_test.o $(LIBOBJECTS) $(TESTHARNESS) 150 $(CXX) $(LDFLAGS) db/filename_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS) 151 152 filter_block_test: table/filter_block_test.o $(LIBOBJECTS) $(TESTHARNESS) 153 $(CXX) $(LDFLAGS) table/filter_block_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS) 154 155 issue178_test: issues/issue178_test.o $(LIBOBJECTS) $(TESTHARNESS) 156 $(CXX) $(LDFLAGS) issues/issue178_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS) 157 158 issue200_test: issues/issue200_test.o $(LIBOBJECTS) $(TESTHARNESS) 159 $(CXX) $(LDFLAGS) issues/issue200_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS) 160 161 log_test: db/log_test.o $(LIBOBJECTS) $(TESTHARNESS) 162 $(CXX) $(LDFLAGS) db/log_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS) 163 164 table_test: table/table_test.o $(LIBOBJECTS) $(TESTHARNESS) 165 $(CXX) $(LDFLAGS) table/table_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS) 166 167 skiplist_test: db/skiplist_test.o $(LIBOBJECTS) $(TESTHARNESS) 168 $(CXX) $(LDFLAGS) db/skiplist_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS) 169 170 version_edit_test: db/version_edit_test.o $(LIBOBJECTS) $(TESTHARNESS) 171 $(CXX) $(LDFLAGS) db/version_edit_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS) 172 173 version_set_test: db/version_set_test.o $(LIBOBJECTS) $(TESTHARNESS) 174 $(CXX) $(LDFLAGS) db/version_set_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS) 175 176 write_batch_test: db/write_batch_test.o $(LIBOBJECTS) $(TESTHARNESS) 177 $(CXX) $(LDFLAGS) db/write_batch_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS) 178 179 $(MEMENVLIBRARY) : $(MEMENVOBJECTS) 180 rm -f $@ 181 $(AR) -rs $@ $(MEMENVOBJECTS) 182 183 memenv_test : helpers/memenv/memenv_test.o $(MEMENVLIBRARY) $(LIBRARY) $(TESTHARNESS) 184 $(CXX) $(LDFLAGS) helpers/memenv/memenv_test.o $(MEMENVLIBRARY) $(LIBRARY) $(TESTHARNESS) -o $@ $(LIBS) 185 186 ifeq ($(PLATFORM), IOS) 187 # For iOS, create universal object files to be used on both the simulator and 188 # a device. 189 PLATFORMSROOT=/Applications/Xcode.app/Contents/Developer/Platforms 190 SIMULATORROOT=$(PLATFORMSROOT)/iPhoneSimulator.platform/Developer 191 DEVICEROOT=$(PLATFORMSROOT)/iPhoneOS.platform/Developer 192 IOSVERSION=$(shell defaults read $(PLATFORMSROOT)/iPhoneOS.platform/version CFBundleShortVersionString) 193 194 .cc.o: 195 mkdir -p ios-x86/$(dir $@) 196 $(CXX) $(CXXFLAGS) -isysroot $(SIMULATORROOT)/SDKs/iPhoneSimulator$(IOSVERSION).sdk -arch i686 -c $< -o ios-x86/$@ 197 mkdir -p ios-arm/$(dir $@) 198 xcrun -sdk iphoneos $(CXX) $(CXXFLAGS) -isysroot $(DEVICEROOT)/SDKs/iPhoneOS$(IOSVERSION).sdk -arch armv6 -arch armv7 -c $< -o ios-arm/$@ 199 lipo ios-x86/$@ ios-arm/$@ -create -output $@ 200 201 .c.o: 202 mkdir -p ios-x86/$(dir $@) 203 $(CC) $(CFLAGS) -isysroot $(SIMULATORROOT)/SDKs/iPhoneSimulator$(IOSVERSION).sdk -arch i686 -c $< -o ios-x86/$@ 204 mkdir -p ios-arm/$(dir $@) 205 xcrun -sdk iphoneos $(CC) $(CFLAGS) -isysroot $(DEVICEROOT)/SDKs/iPhoneOS$(IOSVERSION).sdk -arch armv6 -arch armv7 -c $< -o ios-arm/$@ 206 lipo ios-x86/$@ ios-arm/$@ -create -output $@ 207 208 else 209 .cc.o: 210 $(CXX) $(CXXFLAGS) -c $< -o $@ 211 212 .c.o: 213 $(CC) $(CFLAGS) -c $< -o $@ 214 endif 215