From: teodor Date: Thu, 26 Oct 2006 12:39:49 +0000 (+0000) Subject: use ftsbenchs Makefile infrastructure X-Git-Url: http://sigaev.ru/git/gitweb.cgi?a=commitdiff_plain;h=fd64d180d3b9e5ffc4922256b9dbe191db35480c;p=tedtools.git use ftsbenchs Makefile infrastructure --- diff --git a/Makefile b/Makefile index 32122d4..6307b40 100644 --- a/Makefile +++ b/Makefile @@ -1,52 +1,25 @@ -CC=gcc -AR=ar rcv -RANLIB=ranlib -LD=ld -x -shared +topbuilddir=. -INCLUDE=-I. -CFLAGS=-Wall -g -O2 -pedantic -ansi -DASSERT_CORE -DHAVE_POLL_H -DHAVE_HSTRERROR +PROGRAM=sfxtest hextest inftest kilter psortex flatdbtest \ + tbtreetest gendata memtest glisttest -ifndef OS -OS=$(shell uname) -endif - -ifeq ($(OS), FreeBSD) -CFLAGS+= -DHAVE_POLL_H -endif - -ifeq ($(OS), Linux) -CFLAGS+= -DHAVE_SYS_POLL_H -D_GNU_SOURCE -D_LARGE_FILES -D_FILE_OFFSET_BITS=64 -endif - -LIB=-g -L. -ltedtools -lm - -OBJS=tlog.o tmalloc.o tools.o prs_hmap.o sfxstr.o \ +LIBRARY=libtedtools.a +LIBOBJ=tlog.o tmalloc.o tools.o prs_hmap.o sfxstr.o \ regis.o prs_inf.o shmem.o tcp.o udp.o connpool.o \ psort.o flatdb.o tbtree.o glist.o -PROGS=sfxtest hextest inftest kilter psortex flatdbtest \ - tbtreetest gendata memtest glisttest - -.SUFFIXES: .o.c - -all: libtedtools.a $(PROGS) - -$(PROGS): %: %.o - $(CC) -o $@ $< $(LIB) -$(PROGS): libtedtools.a +include $(topbuilddir)/Makefile.global -libtedtools.a: $(OBJS) - $(AR) $@ $? - $(RANLIB) $@ - -.c.o: - $(CC) $(CFLAGS) $(INCLUDE) -c $< +clean: clean-test +clean-test: + rm -rf sfxtest.log BTREE + rm -rf results diffs temp test: all - @[ -d results ] || mkdir results - @[ -d diffs ] || mkdir diffs - @[ -d temp ] || mkdir temp + @[ -d results ] || mkdir results + @[ -d diffs ] || mkdir diffs + @[ -d temp ] || mkdir temp @for FILE in btree flatdb hex inf mem psort sfxmem glist ; do \ echo -n $$FILE " ........ " ; \ if sh tests/$$FILE > results/$$FILE 2>results/$$FILE.errout && diff -c expected/$$FILE results/$$FILE > diffs/$$FILE ; then \ @@ -55,12 +28,3 @@ test: all echo FAILED ; \ fi ; \ done - -clean: - rm -rf $(OBJS) - rm -rf $(PROGS) *.o - rm -rf libtedtools.a - rm -rf *core *gmon* nohup.out - rm -rf sfxtest.log BTREE - rm -rf results diffs temp - diff --git a/Makefile.global b/Makefile.global new file mode 100644 index 0000000..3dbeecf --- /dev/null +++ b/Makefile.global @@ -0,0 +1,95 @@ + +ECHO=echo + +ifndef OS +OS=$(shell uname) +endif + +CFLAGS=-Wall -pedantic -ansi -O2 -g -DASSERT_CORE -DHAVE_HSTRERROR +ifeq ($(OS), FreeBSD) +CFLAGS+= -DHAVE_POLL_H +endif + +ifeq ($(OS), Linux) +CFLAGS+= -DHAVE_SYS_POLL_H -D_GNU_SOURCE -D_LARGE_FILES -D_FILE_OFFSET_BITS=64 +endif + +CFLAGS+=$(EXTRAFLAGS) + +CC=gcc +AR=ar +RANLIB=ranlib +LD=ld +LIB=-lm $(EXTRALIB) + + +INCLUDE=-I$(topbuilddir)/include -I. $(EXTRAINCLUDE) +ARFLAGS=rcv +LDFLAGS=-r + +ifdef SUBOBJ +SUBSYS=SUBSYS.o +endif + +ifdef SUBDIRS +SUBDIROBJS := $(SUBDIRS:%=%/SUBSYS.o) +endif + +.SUFFIXES: .o.c + +.c.o: + $(CC) $(CFLAGS) $(INCLUDE) -c $< + +all: $(SUBSYS) $(LIBRARY) $(PROGRAM) + +define prog_dep + $(1): $$(PROGRAMOBJ_$(1)) +endef + +$(foreach prog,$(PROGRAM),$(eval $(call prog_dep,$(prog)))) + +ifdef PROGRAM +ifdef LIBRARY +$(PROGRAM): $(LIBRARY) +endif + +$(PROGRAM): %: %.o + $(CC) -o $@ $< $(PROGRAMOBJ_$(@)) $(LIBRARY) $(LIB) +endif + +ifdef LIBRARY +$(LIBRARY): $(LIBOBJ) $(SUBDIROBJS) + $(AR) $(ARFLAGS) $@ $(LIBOBJ) $(SUBDIROBJS) + $(RANLIB) $@ +endif + +ifdef SUBOBJ +$(SUBSYS): $(SUBOBJ) + $(LD) $(LDFLAGS) -o $@ $(SUBOBJ) +endif + +ifdef SUBDIRS +$(SUBDIROBJS): $(SUBDIRS:%=%-recursive) ; + +$(SUBDIRS:%=%-recursive): + $(MAKE) -C $(subst -recursive,,$@) -f Makefile OS=$(OS) SUBSYS.o +endif + +clean: +ifdef LIBOBJ + rm -rf $(LIBOBJ) +endif +ifdef PROGRAM + rm -rf $(PROGRAM) + rm -rf $(foreach P, $(PROGRAM), $P.o $(PROGRAMOBJ_$(P))) + rm -rf *core core.* +endif +ifdef LIBRARY + rm -rf $(LIBRARY) +endif +ifdef SUBOBJ + rm -rf $(SUBOBJ) $(SUBSYS) +endif +ifdef SUBDIRS + for dir in $(SUBDIRS); do $(MAKE) -f Makefile -C $$dir OS=$(OS) clean || exit; done +endif