# Makefile for CLucene 0.8.9 perl extension and wrapper module on RedHat 9.3
# 
# Ought to be redone so clucene libraries are provided by an rpm and the perl
# wrapper and extension is built using h2xs and ExtUtils::MakeMaker
#
# Copyright(c) 2004 Peter Edwards
# All rights reserved. This package is free software; you can redistribute
# it and/or modify it under the same terms as Perl itself.

LIBDIR=$(HOME)/clucene.output/lib
INCDIR=-I../../src -I.
LIBCL=-L$(LIBDIR) -lclucene
INCCL=$(INCDIR)
CFLAGS=$(INCCL)
LDFLAGS=-lstdc++
LIBCLUCENE=$(LIBDIR)/libclucene.so
LIBCLUCENE_CYGWIN=-L$(LIBDIR) -lclucene
PERLCORE := $(shell ./check.pl -perl)
#PERLCORE=/usr/lib/perl5/5.8.0/i386-linux-thread-multi/CORE
SWIGCFLAGS=-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGING -fno-strict-aliasing -I/usr/local/include -I/usr/include/gdbm -fpic

# run test perl program against perl wrapper
main: CLuceneWrap.so

test: main
	LD_LIBRARY_PATH=$(LIBDIR) perl tlucene.pl

# clucene_dll.cpp, clucene_dll.h copied from wrappers/dll
clucene_dll.o: clucene_dll.cpp
	c++ -c clucene_dll.cpp $(CFLAGS)

clucene_dll.cpp: ../dll/clucene_dll.cpp
	cp ../dll/clucene_dll.cpp .
	cp ../dll/clucene_dll.h .

clucene_wrap.o: clucene.i clucene_perl.h
	@perl check.pl
	swig -perl clucene.i
	mv CLuceneWrap.pm FulltextSearch/
	${CC} -c clucene_wrap.c $(CFLAGS) -I${PERLCORE} -Dbool=char ${SWIGCFLAGS}

cygwin: clucene_dll.o clucene_wrap.o
	${CC} ${LIBCLUCENE_CYGWIN} $(LDFLAGS) /usr/bin/cygperl5_8_2.dll /usr/bin/cygcrypt-0.dll clucene_dll.o clucene_wrap.o -o CLuceneWrap.so

CLuceneWrap.so: clucene_dll.o clucene_wrap.o
	${CC} -static $(LIBCLUCENE) clucene_dll.o clucene_wrap.o -o CLuceneWrap.so $(LDFLAGS)

clean:
	rm -f t *.o clucene_dll.cpp clucene_dll.h clucene_wrap.* CLuceneWrap.* clucene_dll.so swig.ver

# old tests

t: t.o clucene_dll.o
	c++ -o t t.o clucene_dll.o $(LIBCL) $(LDFLAGS)

