-# Makefile for the Sherlock Library (c) 1997--2002 Martin Mares <mj@ucw.cz>
+# Makefile for the UCW Library (c) 1997--2007 Martin Mares <mj@ucw.cz>
DIRS+=lib
-PROGS+=obj/lib/db-tool obj/lib/buckettool
-
-SHLIB_OBJS=alloc.o alloc_str.o ctmatch.o db.o fastbuf.o fb-file.o fb-mem.o lists.o \
- log.o log2.o md5.o md5hex.o mmap.o pagecache.o patimatch.o patmatch.o pool.o \
- prime.o random.o realloc.o regex.o timer.o url.o wildmatch.o \
- wordsplit.o str_ctype.o str_upper.o bucket.o conf.o object.o sorter.o \
- finger.o proctitle.o ipaccess.o profile.o bitsig.o randomkey.o \
- hashfunc.o base224.o fb-temp.o printf.o
-
-obj/lib/libsh.a: $(addprefix obj/lib/,$(SHLIB_OBJS)) $(CUSTOM_MODULES)
-
-obj/lib/hashfunc.o: CFLAGS += -funroll-loops
-
-obj/lib/db-test: obj/lib/db-test.o obj/lib/libsh.a
-obj/lib/db-tool: obj/lib/db-tool.o obj/lib/libsh.a
-obj/lib/buckettool: obj/lib/buckettool.o obj/lib/libsh.a
-obj/lib/conf-test: obj/lib/conf-test.o obj/lib/libsh.a
-obj/lib/sort-test: obj/lib/sort-test.o obj/lib/libsh.a
-obj/lib/lfs-test: obj/lib/lfs-test.o obj/lib/libsh.a
-obj/lib/regex-test: obj/lib/regex-test.o obj/lib/libsh.a
-obj/lib/hash-test: obj/lib/hash-test.o obj/lib/libsh.a
-obj/lib/str-test: obj/lib/str-test.o obj/lib/libsh.a
+CONFIGS+=library
+LIBUCW=$(o)/lib/libucw.pc
+
+ifdef CONFIG_UCW_DBTOOL
+PROGS+=$(o)/lib/db-tool
+endif
+
+LIBUCW_MODS= \
+ threads \
+ alloc alloc_str realloc bigalloc mempool mempool-str mempool-fmt eltpool \
+ mmap pagecache partmap hashfunc \
+ lists slists simple-lists bitsig \
+ log log-file proctitle \
+ conf-alloc conf-dump conf-input conf-intr conf-journal conf-parse conf-section \
+ ipaccess \
+ profile \
+ fastbuf ff-binary ff-string ff-printf ff-unicode \
+ fb-file carefulio fb-mem fb-temp fb-mmap fb-limfd fb-buffer fb-grow fb-pool fb-atomic fb-param fb-socket \
+ str_ctype str_upper str_lower unicode stkstring \
+ wildmatch wordsplit ctmatch patimatch patmatch regex \
+ prime primetable random timer randomkey \
+ bit-ffs bit-fls \
+ db \
+ url \
+ mainloop exitstatus runcmd sighandler \
+ lizard lizard-safe adler32 \
+ md5 md5hex \
+ base64 base224 \
+ sync \
+ qache \
+ string \
+ bbuf \
+ getopt
+
+LIBUCW_INCLUDES= \
+ lib.h config.h threads.h \
+ mempool.h pagecache.h \
+ arraysort.h \
+ lists.h clists.h slists.h simple-lists.h \
+ unaligned.h prefetch.h \
+ bbuf.h gbuf.h bitarray.h bitsig.h \
+ hashfunc.h hashtable.h \
+ heap.h binheap.h binheap-node.h \
+ redblack.h \
+ binsearch.h \
+ bitops.h \
+ conf.h getopt.h ipaccess.h \
+ profile.h \
+ fastbuf.h lfs.h ff-unicode.h ff-utf8.h ff-binary.h \
+ chartype.h unicode.h stkstring.h \
+ wildmatch.h patmatch.h \
+ db.h \
+ url.h \
+ mainloop.h \
+ lizard.h \
+ md5.h \
+ base64.h base224.h \
+ qache.h \
+ kmp.h kmp-search.h binsearch.h \
+ partmap.h
+
+ifdef CONFIG_UCW_THREADS
+# Some modules require threading
+LIBUCW_MODS+=threads-conf workqueue asio fb-direct
+LIBUCW_INCLUDES+=workqueue.h semaphore.h asio.h
+endif
+
+ifdef CONFIG_OWN_REGEX
+include $(s)/lib/regex/Makefile
+endif
+
+ifdef CONFIG_OWN_GETOPT
+include $(s)/lib/getopt/Makefile
+endif
+
+include $(s)/lib/sorter/Makefile
+
+LIBUCW_MOD_PATHS=$(addprefix $(o)/lib/,$(LIBUCW_MODS))
+
+$(o)/lib/libucw.a: $(addsuffix .o,$(LIBUCW_MOD_PATHS))
+$(o)/lib/libucw.so: $(addsuffix .oo,$(LIBUCW_MOD_PATHS))
+
+$(o)/lib/hashfunc.o $(o)/lib/hashfunc.oo: CFLAGS += -funroll-loops
+$(o)/lib/lizard.o: CFLAGS += $(COPT2) -funroll-loops
+
+$(o)/lib/db-test: $(o)/lib/db-test.o $(LIBUCW)
+$(o)/lib/db-tool: $(o)/lib/db-tool.o $(LIBUCW)
+$(o)/lib/conf-test: $(o)/lib/conf-test.o $(LIBUCW)
+$(o)/lib/lfs-test: $(o)/lib/lfs-test.o $(LIBUCW)
+$(o)/lib/hash-test: $(o)/lib/hash-test.o $(LIBUCW)
+$(o)/lib/str-test: $(o)/lib/str-test.o $(LIBUCW)
+$(o)/lib/asort-test: $(o)/lib/asort-test.o $(LIBUCW)
+$(o)/lib/redblack-test: $(o)/lib/redblack-test.o $(LIBUCW)
+$(o)/lib/binheap-test: $(o)/lib/binheap-test.o $(LIBUCW)
+$(o)/lib/lizard-test: $(o)/lib/lizard-test.o $(LIBUCW)
+$(o)/lib/kmp-test: $(o)/lib/kmp-test.o $(LIBUCW) $(LIBCHARSET)
+$(o)/lib/ipaccess-test: $(o)/lib/ipaccess-test.o $(LIBUCW)
+
+TESTS+=$(addprefix $(o)/lib/,regex.test unicode.test hash-test.test mempool.test stkstring.test \
+ slists.test kmp-test.test bbuf.test getopt.test fastbuf.test ff-unicode.test eltpool.test \
+ fb-socket.test)
+
+$(o)/lib/regex.test: $(o)/lib/regex-t
+$(o)/lib/unicode.test: $(o)/lib/unicode-t
+$(o)/lib/hash-test.test: $(o)/lib/hash-test
+$(o)/lib/mempool.test: $(o)/lib/mempool-t $(o)/lib/mempool-fmt-t $(o)/lib/mempool-str-t
+$(o)/lib/stkstring.test: $(o)/lib/stkstring-t
+$(o)/lib/bitops.test: $(o)/lib/bit-ffs-t $(o)/lib/bit-fls-t
+$(o)/lib/slists.test: $(o)/lib/slists-t
+$(o)/lib/kmp-test.test: $(o)/lib/kmp-test
+$(o)/lib/bbuf.test: $(o)/lib/bbuf-t
+$(o)/lib/getopt.test: $(o)/lib/getopt-t
+$(o)/lib/fastbuf.test: $(o)/lib/fb-file-t $(o)/lib/fb-grow-t $(o)/lib/fb-pool-t
+$(o)/lib/ff-unicode.test: $(o)/lib/ff-unicode-t
+$(o)/lib/eltpool.test: $(o)/lib/eltpool-t
+$(o)/lib/fb-socket.test: $(o)/lib/fb-socket-t
+
+ifdef CONFIG_UCW_THREADS
+TESTS+=$(addprefix $(o)/lib/,asio.test)
+$(o)/lib/asio.test: $(o)/lib/asio-t
+endif
+
+API_LIBS+=libucw
+API_INCLUDES+=$(o)/lib/.include-stamp
+$(o)/lib/.include-stamp: $(addprefix $(s)/lib/,$(LIBUCW_INCLUDES)) obj/autoconf.h
+ $(Q)$(s)/build/install-includes $(<D) run/include/lib $(LIBUCW_INCLUDES)
+ $(Q)$(s)/build/install-includes obj run/include/lib autoconf.h
+ $(Q)touch $@
+run/lib/pkgconfig/libucw.pc: $(o)/lib/libucw.pc
+
+ifdef CONFIG_UCW_PERL
+include $(s)/lib/perl/Makefile
+endif
+
+ifdef CONFIG_UCW_SHELL_UTILS
+include $(s)/lib/shell/Makefile
+endif