From ffaacccda0f647a99806160fe90db4b012219603 Mon Sep 17 00:00:00 2001 From: Xuqiang Chen Date: Wed, 16 Aug 2023 23:52:43 +0800 Subject: murmurhash: add dynamic library build process (#3) Signed-off-by: chenxuqiang --- Makefile | 15 ++++++++++++++- murmurhash_example.c | 13 +++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 murmurhash_example.c diff --git a/Makefile b/Makefile index 64a54f1..7dcc77e 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,13 @@ CFLAGS += -std=c99 -Wall -I. PREFIX ?= /usr/local MANPREFIX ?= $(PREFIX)/share/man MAN_FILES = $(wildcard man/*.md) +LIB ?= libmurmurhash.so +INCLUDE ?= murmurhash.h + +all: $(LIB) $(BIN) + +$(LIB): + $(CC) -shared $(SRC) $(CFLAGS) -o $(LIB) $(BIN): $(CC) main.c $(SRC) $(CFLAGS) -o $(BIN) @@ -12,13 +19,19 @@ $(BIN): clean: rm -f test rm -f $(BIN) + rm -f $(LIB) + +example: + $(CC) murmurhash_example.c -lmurmurhash -o murmurhash_example test: $(CC) test.c $(SRC) $(CFLAGS) -o test ./test -install: $(BIN) +install: $(BIN) $(LIB) install $(BIN) $(PREFIX)/bin + install $(LIB) $(PREFIX)/lib + install $(INCLUDE) $(PREFIX)/include install man/*.1 $(MANPREFIX)/man1 docs: $(MAN_FILES) diff --git a/murmurhash_example.c b/murmurhash_example.c new file mode 100644 index 0000000..e8a840c --- /dev/null +++ b/murmurhash_example.c @@ -0,0 +1,13 @@ +#include +#include +#include +#include + +int main(void) +{ + uint32_t seed = 0; + const char *key = "kinkajou"; // // 0xb6d99cf8 + uint32_t hash = murmurhash(key, (uint32_t)strlen(key), seed); + printf("murmurhash(%s) = 0x%x\n", key, hash); + return 0; +} \ No newline at end of file -- cgit v1.2.3