Makefile (7335B)
1 CFLAGS = -Wall -Wno-misleading-indentation -Wno-unused-function -Werror -O2 -g -Isrc -Ideps/secp256k1/include -Ideps/lmdb -Ideps/flatcc/include -Isrc/bolt11/ -Iccan/ -DCCAN_TAL_NEVER_RETURN_NULL=1 2 BOLT11_HDRS := src/bolt11/amount.h src/bolt11/bech32.h src/bolt11/bech32_util.h src/bolt11/bolt11.h src/bolt11/debug.h src/bolt11/error.h src/bolt11/hash_u5.h src/bolt11/node_id.h src/bolt11/overflows.h 3 CCAN_SRCS := ccan/ccan/utf8/utf8.c ccan/ccan/tal/tal.c ccan/ccan/tal/str/str.c ccan/ccan/list/list.c ccan/ccan/mem/mem.c ccan/ccan/crypto/sha256/sha256.c ccan/ccan/take/take.c 4 CCAN_HDRS := ccan/ccan/utf8/utf8.h ccan/ccan/container_of/container_of.h ccan/ccan/check_type/check_type.h ccan/ccan/str/str.h ccan/ccan/tal/str/str.h ccan/ccan/tal/tal.h ccan/ccan/list/list.h ccan/ccan/structeq/structeq.h ccan/ccan/typesafe_cb/typesafe_cb.h ccan/ccan/short_types/short_types.h ccan/ccan/mem/mem.h ccan/ccan/likely/likely.h ccan/ccan/alignof/alignof.h ccan/ccan/crypto/sha256/sha256.h ccan/ccan/array_size/array_size.h ccan/ccan/endian/endian.h ccan/ccan/take/take.h ccan/ccan/build_assert/build_assert.h ccan/ccan/cppmagic/cppmagic.h 5 HEADERS = deps/lmdb/lmdb.h deps/secp256k1/include/secp256k1.h src/nostrdb.h src/cursor.h src/hex.h src/jsmn.h src/config.h src/random.h src/memchr.h src/cpu.h src/nostr_bech32.h src/block.h src/str_block.h $(C_BINDINGS) $(CCAN_HDRS) $(BOLT11_HDRS) 6 FLATCC_SRCS=deps/flatcc/src/runtime/json_parser.c deps/flatcc/src/runtime/verifier.c deps/flatcc/src/runtime/builder.c deps/flatcc/src/runtime/emitter.c deps/flatcc/src/runtime/refmap.c 7 BOLT11_SRCS = src/bolt11/bolt11.c src/bolt11/bech32.c src/bolt11/amount.c src/bolt11/hash_u5.c 8 SRCS = src/nostrdb.c src/invoice.c src/nostr_bech32.c src/content_parser.c src/block.c $(BOLT11_SRCS) $(FLATCC_SRCS) $(CCAN_SRCS) 9 LDS = $(OBJS) $(ARS) 10 OBJS = $(SRCS:.c=.o) 11 DEPS = $(OBJS) $(HEADERS) $(ARS) 12 ARS = deps/lmdb/liblmdb.a deps/secp256k1/.libs/libsecp256k1.a 13 LMDB_VER=0.9.31 14 FLATCC_VER=05dc16dc2b0316e61063bb1fc75426647badce48 15 PREFIX ?= /usr/local 16 SUBMODULES = deps/secp256k1 17 BINDINGS=src/bindings 18 C_BINDINGS_PROFILE=$(BINDINGS)/c/profile_builder.h $(BINDINGS)/c/profile_reader.h $(BINDINGS)/c/profile_verifier.h $(BINDINGS)/c/profile_json_parser.h 19 C_BINDINGS_META=$(BINDINGS)/c/meta_builder.h $(BINDINGS)/c/meta_reader.h $(BINDINGS)/c/meta_verifier.h $(BINDINGS)/c/meta_json_parser.h 20 C_BINDINGS_COMMON=$(BINDINGS)/c/flatbuffers_common_builder.h $(BINDINGS)/c/flatbuffers_common_reader.h 21 C_BINDINGS=$(C_BINDINGS_COMMON) $(C_BINDINGS_PROFILE) $(C_BINDINGS_META) 22 BIN=ndb 23 24 # Detect operating system 25 UNAME_S := $(shell uname -s) 26 27 # macOS-specific flags 28 ifeq ($(UNAME_S),Darwin) 29 LDFLAGS += -framework Security 30 endif 31 32 CHECKDATA=testdata/db/v0/data.mdb 33 34 all: $(BIN) lib bench 35 36 $(OBJS): $(HEADERS) 37 38 %.o: %.c 39 $(CC) $(CFLAGS) -c -o $@ $< 40 41 libnostrdb.a: $(OBJS) 42 ar rcs $@ $(OBJS) 43 44 lib: libnostrdb.a 45 46 ndb: ndb.c $(DEPS) 47 $(CC) $(CFLAGS) ndb.c $(LDS) $(LDFLAGS) -o $@ 48 49 bindings: bindings-swift bindings-rust bindings-c 50 51 check: test 52 rm -rf testdata/db/*.mdb 53 ./test 54 rm -rf testdata/db/*.mdb 55 56 clean: 57 rm -rf test bench bench-ingest bench-ingest-many $(OBJS) 58 59 distclean: clean 60 rm -rf deps 61 62 tags: 63 find src -name '*.c' -or -name '*.h' | xargs ctags 64 65 configurator: src/configurator.c 66 $(CC) $< -o $@ 67 68 src/config.h: configurator 69 ./configurator > $@ 70 71 bindings-c: $(C_BINDINGS) 72 73 src/bindings/%/.dir: 74 mkdir -p $(shell dirname $@) 75 touch $@ 76 77 src/bindings/c/%_builder.h: schemas/%.fbs $(BINDINGS)/c/.dir 78 flatcc --builder $< -o $(BINDINGS)/c 79 80 src/bindings/c/%_verifier.h bindings/c/%_reader.h: schemas/%.fbs $(BINDINGS)/c/.dir 81 flatcc --verifier -o $(BINDINGS)/c $< 82 83 src/bindings/c/flatbuffers_common_reader.h: $(BINDINGS)/c/.dir 84 flatcc --common_reader -o $(BINDINGS)/c 85 86 src/bindings/c/flatbuffers_common_builder.h: $(BINDINGS)/c/.dir 87 flatcc --common_builder -o $(BINDINGS)/c 88 89 src/bindings/c/%_json_parser.h: schemas/%.fbs $(BINDINGS)/c/.dir 90 flatcc --json-parser $< -o $(BINDINGS)/c 91 92 bindings-rust: $(BINDINGS)/rust/ndb_profile.rs $(BINDINGS)/rust/ndb_meta.rs 93 94 $(BINDINGS)/rust/ndb_profile.rs: schemas/profile.fbs $(BINDINGS)/rust 95 flatc --gen-json-emit --rust $< 96 @mv profile_generated.rs $@ 97 98 $(BINDINGS)/rust/ndb_meta.rs: schemas/meta.fbs $(BINDINGS)/swift 99 flatc --rust $< 100 @mv meta_generated.rs $@ 101 102 bindings-swift: $(BINDINGS)/swift/NdbProfile.swift $(BINDINGS)/swift/NdbMeta.swift 103 104 $(BINDINGS)/swift/NdbProfile.swift: schemas/profile.fbs $(BINDINGS)/swift 105 flatc --gen-json-emit --swift $< 106 @mv profile_generated.swift $@ 107 108 $(BINDINGS)/swift/NdbMeta.swift: schemas/meta.fbs $(BINDINGS)/swift 109 flatc --swift $< 110 @mv meta_generated.swift $@ 111 112 deps/.dir: 113 @mkdir -p deps 114 touch deps/.dir 115 116 deps/LMDB_$(LMDB_VER).tar.gz: deps/.dir 117 curl -L https://github.com/LMDB/lmdb/archive/refs/tags/LMDB_$(LMDB_VER).tar.gz -o $@ 118 119 deps/flatcc_$(FLATCC_VER).tar.gz: deps/.dir 120 curl -L https://github.com/jb55/flatcc/archive/$(FLATCC_VER).tar.gz -o $@ 121 122 #deps/flatcc/src/runtime/json_parser.c: deps/flatcc_$(FLATCC_VER).tar.gz deps/.dir 123 # tar xf $< 124 # rm -rf deps/flatcc 125 # mv flatcc-$(FLATCC_VER) deps/flatcc 126 # touch $@ 127 128 #deps/lmdb/lmdb.h: deps/LMDB_$(LMDB_VER).tar.gz deps/.dir 129 # tar xf $< 130 # rm -rf deps/lmdb 131 # mv lmdb-LMDB_$(LMDB_VER)/libraries/liblmdb deps/lmdb 132 # rm -rf lmdb-LMDB_$(LMDB_VER) 133 # touch $@ 134 135 deps/secp256k1/.git: deps/.dir 136 @devtools/refresh-submodules.sh $(SUBMODULES) 137 138 deps/secp256k1/include/secp256k1.h: deps/secp256k1/.git 139 140 deps/secp256k1/configure: deps/secp256k1/.git 141 cd deps/secp256k1; \ 142 ./autogen.sh 143 144 deps/secp256k1/.libs/libsecp256k1.a: deps/secp256k1/config.log 145 cd deps/secp256k1; \ 146 make -j libsecp256k1.la 147 148 deps/secp256k1/config.log: deps/secp256k1/configure 149 cd deps/secp256k1; \ 150 ./configure --disable-shared --enable-module-ecdh --enable-module-schnorrsig --enable-module-extrakeys 151 152 deps/lmdb/liblmdb.a: deps/lmdb/lmdb.h 153 $(MAKE) -C deps/lmdb liblmdb.a 154 155 testdata/db/ndb-v0.tar.zst: 156 curl https://cdn.jb55.com/s/ndb-v0.tar.zst -o $@ 157 158 testdata/db/ndb-v0.tar: testdata/db/ndb-v0.tar.zst 159 zstd -d < $< > $@ 160 161 testdata/db/v0/data.mdb: testdata/db/ndb-v0.tar 162 tar xf $< 163 rm -rf testdata/db/v0 164 mv v0 testdata/db 165 166 testdata/many-events.json.zst: 167 curl https://cdn.jb55.com/s/many-events.json.zst -o $@ 168 169 testdata/many-events.json: testdata/many-events.json.zst 170 zstd -d $< 171 172 bench: bench-ingest-many.c $(DEPS) 173 $(CC) $(CFLAGS) $< $(LDS) $(LDFLAGS) -o $@ 174 175 perf.out: fake 176 perf script > $@ 177 178 perf.folded: perf.out 179 stackcollapse-perf.pl $< > $@ 180 181 ndb.svg: perf.folded 182 flamegraph.pl $< > $@ 183 184 flamegraph: ndb.svg 185 browser $< 186 187 run-bench: testdata/many-events.json bench 188 ./bench 189 190 testdata/db/.dir: 191 @mkdir -p testdata/db 192 touch testdata/db/.dir 193 194 test: test.c $(DEPS) testdata/db/.dir 195 $(CC) $(CFLAGS) test.c $(LDS) $(LDFLAGS) -o $@ 196 197 # Call this with CCAN_NEW="mod1 mod2..." to add new ccan modules. 198 update-ccan: 199 mv ccan ccan.old 200 DIR=$$(pwd)/ccan; cd ../ccan && ./tools/create-ccan-tree -a $$DIR `cd $$DIR.old/ccan && find * -name _info | sed s,/_info,, | LC_ALL=C sort` $(CCAN_NEW) 201 mkdir -p ccan/tools/configurator 202 cp ../ccan/tools/configurator/configurator.c ../ccan/doc/configurator.1 ccan/tools/configurator/ 203 $(MAKE) src/config.h 204 grep -v '^CCAN version:' ccan.old/README > ccan/README 205 echo CCAN version: `git -C ../ccan describe` >> ccan/README 206 $(RM) -r ccan/ccan/hash/ ccan/ccan/tal/talloc/ # Unnecessary deps 207 $(RM) -r ccan.old 208 209 .PHONY: tags clean fake update-ccan