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 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 filename_test \ 44 filter_block_test \ 45 issue178_test \ 46 log_test \ 47 memenv_test \ 48 skiplist_test \ 49 table_test \ 50 version_edit_test \ 51 version_set_test \ 52 write_batch_test 53 54 PROGRAMS = db_bench leveldbutil $(TESTS) 55 BENCHMARKS = db_bench_sqlite3 db_bench_tree_db 56 57 LIBRARY = libleveldb.a 58 MEMENVLIBRARY = libmemenv.a 59 60 default: all 61 62 # Should we build shared libraries? 63 ifneq ($(PLATFORM_SHARED_EXT),) 64 65 ifneq ($(PLATFORM_SHARED_VERSIONED),true) 66 SHARED1 = libleveldb.$(PLATFORM_SHARED_EXT) 67 SHARED2 = $(SHARED1) 68 SHARED3 = $(SHARED1) 69 SHARED = $(SHARED1) 70 else 71 # Update db.h if you change these. 72 SHARED_MAJOR = 1 73 SHARED_MINOR = 12 74 SHARED1 = libleveldb.$(PLATFORM_SHARED_EXT) 75 SHARED2 = $(SHARED1).$(SHARED_MAJOR) 76 SHARED3 = $(SHARED1).$(SHARED_MAJOR).$(SHARED_MINOR) 77 SHARED = $(SHARED1) $(SHARED2) $(SHARED3) 78 $(SHARED1): $(SHARED3) 79 ln -fs $(SHARED3) $(SHARED1) 80 $(SHARED2): $(SHARED3) 81 ln -fs $(SHARED3) $(SHARED2) 82 endif 83 84 $(SHARED3): 85 $(CXX) $(LDFLAGS) $(PLATFORM_SHARED_LDFLAGS)$(SHARED2) $(CXXFLAGS) $(PLATFORM_SHARED_CFLAGS) $(SOURCES) -o $(SHARED3) $(LIBS) 86 87 endif # PLATFORM_SHARED_EXT 88 89 all: $(SHARED) $(LIBRARY) 90 91 check: all $(PROGRAMS) $(TESTS) 92 for t in $(TESTS); do echo "***** Running $$t"; ./$$t || exit 1; done 93 94 clean: 95 -rm -f $(PROGRAMS) $(BENCHMARKS) $(LIBRARY) $(SHARED) $(MEMENVLIBRARY) */*.o */*/*.o ios-x86/*/*.o ios-arm/*/*.o build_config.mk 96 -rm -rf ios-x86/* ios-arm/* 97 98 $(LIBRARY): $(LIBOBJECTS) 99 rm -f $@ 100 $(AR) -rs $@ $(LIBOBJECTS) 101 102 db_bench: db/db_bench.o $(LIBOBJECTS) $(TESTUTIL) 103 $(CXX) $(LDFLAGS) db/db_bench.o $(LIBOBJECTS) $(TESTUTIL) -o $@ $(LIBS) 104 105 db_bench_sqlite3: doc/bench/db_bench_sqlite3.o $(LIBOBJECTS) $(TESTUTIL) 106 $(CXX) $(LDFLAGS) doc/bench/db_bench_sqlite3.o $(LIBOBJECTS) $(TESTUTIL) -o $@ -lsqlite3 $(LIBS) 107 108 db_bench_tree_db: doc/bench/db_bench_tree_db.o $(LIBOBJECTS) $(TESTUTIL) 109 $(CXX) $(LDFLAGS) doc/bench/db_bench_tree_db.o $(LIBOBJECTS) $(TESTUTIL) -o $@ -lkyotocabinet $(LIBS) 110 111 leveldbutil: db/leveldb_main.o $(LIBOBJECTS) 112 $(CXX) $(LDFLAGS) db/leveldb_main.o $(LIBOBJECTS) -o $@ $(LIBS) 113 114 arena_test: util/arena_test.o $(LIBOBJECTS) $(TESTHARNESS) 115 $(CXX) $(LDFLAGS) util/arena_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS) 116 117 bloom_test: util/bloom_test.o $(LIBOBJECTS) $(TESTHARNESS) 118 $(CXX) $(LDFLAGS) util/bloom_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS) 119 120 c_test: db/c_test.o $(LIBOBJECTS) $(TESTHARNESS) 121 $(CXX) $(LDFLAGS) db/c_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS) 122 123 cache_test: util/cache_test.o $(LIBOBJECTS) $(TESTHARNESS) 124 $(CXX) $(LDFLAGS) util/cache_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS) 125 126 coding_test: util/coding_test.o $(LIBOBJECTS) $(TESTHARNESS) 127 $(CXX) $(LDFLAGS) util/coding_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS) 128 129 corruption_test: db/corruption_test.o $(LIBOBJECTS) $(TESTHARNESS) 130 $(CXX) $(LDFLAGS) db/corruption_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS) 131 132 crc32c_test: util/crc32c_test.o $(LIBOBJECTS) $(TESTHARNESS) 133 $(CXX) $(LDFLAGS) util/crc32c_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS) 134 135 db_test: db/db_test.o $(LIBOBJECTS) $(TESTHARNESS) 136 $(CXX) $(LDFLAGS) db/db_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS) 137 138 dbformat_test: db/dbformat_test.o $(LIBOBJECTS) $(TESTHARNESS) 139 $(CXX) $(LDFLAGS) db/dbformat_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS) 140 141 env_test: util/env_test.o $(LIBOBJECTS) $(TESTHARNESS) 142 $(CXX) $(LDFLAGS) util/env_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS) 143 144 filename_test: db/filename_test.o $(LIBOBJECTS) $(TESTHARNESS) 145 $(CXX) $(LDFLAGS) db/filename_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS) 146 147 filter_block_test: table/filter_block_test.o $(LIBOBJECTS) $(TESTHARNESS) 148 $(CXX) $(LDFLAGS) table/filter_block_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS) 149 150 issue178_test: issues/issue178_test.o $(LIBOBJECTS) $(TESTHARNESS) 151 $(CXX) $(LDFLAGS) issues/issue178_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS) 152 153 log_test: db/log_test.o $(LIBOBJECTS) $(TESTHARNESS) 154 $(CXX) $(LDFLAGS) db/log_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS) 155 156 table_test: table/table_test.o $(LIBOBJECTS) $(TESTHARNESS) 157 $(CXX) $(LDFLAGS) table/table_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS) 158 159 skiplist_test: db/skiplist_test.o $(LIBOBJECTS) $(TESTHARNESS) 160 $(CXX) $(LDFLAGS) db/skiplist_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS) 161 162 version_edit_test: db/version_edit_test.o $(LIBOBJECTS) $(TESTHARNESS) 163 $(CXX) $(LDFLAGS) db/version_edit_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS) 164 165 version_set_test: db/version_set_test.o $(LIBOBJECTS) $(TESTHARNESS) 166 $(CXX) $(LDFLAGS) db/version_set_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS) 167 168 write_batch_test: db/write_batch_test.o $(LIBOBJECTS) $(TESTHARNESS) 169 $(CXX) $(LDFLAGS) db/write_batch_test.o $(LIBOBJECTS) $(TESTHARNESS) -o $@ $(LIBS) 170 171 $(MEMENVLIBRARY) : $(MEMENVOBJECTS) 172 rm -f $@ 173 $(AR) -rs $@ $(MEMENVOBJECTS) 174 175 memenv_test : helpers/memenv/memenv_test.o $(MEMENVLIBRARY) $(LIBRARY) $(TESTHARNESS) 176 $(CXX) $(LDFLAGS) helpers/memenv/memenv_test.o $(MEMENVLIBRARY) $(LIBRARY) $(TESTHARNESS) -o $@ $(LIBS) 177 178 ifeq ($(PLATFORM), IOS) 179 # For iOS, create universal object files to be used on both the simulator and 180 # a device. 181 PLATFORMSROOT=/Applications/Xcode.app/Contents/Developer/Platforms 182 SIMULATORROOT=$(PLATFORMSROOT)/iPhoneSimulator.platform/Developer 183 DEVICEROOT=$(PLATFORMSROOT)/iPhoneOS.platform/Developer 184 IOSVERSION=$(shell defaults read $(PLATFORMSROOT)/iPhoneOS.platform/version CFBundleShortVersionString) 185 186 .cc.o: 187 mkdir -p ios-x86/$(dir $@) 188 $(CXX) $(CXXFLAGS) -isysroot $(SIMULATORROOT)/SDKs/iPhoneSimulator$(IOSVERSION).sdk -arch i686 -c $< -o ios-x86/$@ 189 mkdir -p ios-arm/$(dir $@) 190 $(DEVICEROOT)/usr/bin/$(CXX) $(CXXFLAGS) -isysroot $(DEVICEROOT)/SDKs/iPhoneOS$(IOSVERSION).sdk -arch armv6 -arch armv7 -c $< -o ios-arm/$@ 191 lipo ios-x86/$@ ios-arm/$@ -create -output $@ 192 193 .c.o: 194 mkdir -p ios-x86/$(dir $@) 195 $(CC) $(CFLAGS) -isysroot $(SIMULATORROOT)/SDKs/iPhoneSimulator$(IOSVERSION).sdk -arch i686 -c $< -o ios-x86/$@ 196 mkdir -p ios-arm/$(dir $@) 197 $(DEVICEROOT)/usr/bin/$(CC) $(CFLAGS) -isysroot $(DEVICEROOT)/SDKs/iPhoneOS$(IOSVERSION).sdk -arch armv6 -arch armv7 -c $< -o ios-arm/$@ 198 lipo ios-x86/$@ ios-arm/$@ -create -output $@ 199 200 else 201 .cc.o: 202 $(CXX) $(CXXFLAGS) -c $< -o $@ 203 204 .c.o: 205 $(CC) $(CFLAGS) -c $< -o $@ 206 endif 207