CC      = g++
CFLAGS  = -I/usr/local/include -I/usr/local/include/CLucene -Wall -I. -g -DDEBUG
CXXFLAGS= -I/usr/local/include -I/usr/local/include/CLucene -Wall -I. -g -DDEBUG

LDFLAGS= -lconfig++ -lboost_iostreams -lboost_filesystem -lsqlite3 -lclucene 

LDFLAGS_FILELIST= -lconfig++ -lboost_iostreams -lboost_filesystem
LDFLAGS_INDEXER = -lconfig++ -lboost_iostreams -lboost_filesystem -lsqlite3 -lclucene

DEPS       = helper.h indexer.ggo filelist.ggo indexer_cmdline.c helper.cc helper.h filelist.cc indexer_functions.h index.h indexer_functions.cc 
OBJS_LIST  = helper.o cmdline.o filelist.o 
OBJS_INDEX = helper.o indexer_cmdline.o indexer.o indexer_functions.o

cmdline.c: filelist.ggo
	gengetopt < filelist.ggo

cmdline.o: cmdline.c cmdline.h filelist.ggo
	gengetopt < filelist.ggo
	$(CC) $(CFLAGS) -c -o cmdline.o cmdline.c

indexer_cmdline.c: indexer.ggo
	gengetopt < indexer.ggo

indexer_cmdline.o: indexer_cmdline.c indexer_cmdline.h indexer.ggo
	gengetopt < indexer.ggo
	$(CC) $(CFLAGS) -c -o indexer_cmdline.o indexer_cmdline.c

%.s: %.c $(DEPS)
	$(CC) $(CFLAGS) -S -o $@ $<

%.o: %.c $(DEPS)
	$(CC) $(CFLAGS) -c -o $@ $<

%.o: %.cc $(DEPS)
	$(CC) $(CXXFLAGS) -c -o $@ $<

filelist: $(OBJS_LIST)
	$(CC) $(CFLAGS) $(CXXFLAGS) $(LDFLAGS_FILELIST) -o $@ $^

indexer: $(OBJS_INDEX)
	$(CC) $(CFLAGS) $(CXXFLAGS) $(LDFLAGS_INDEXER) -o $@ $^

.PHONY: clean

clean:
	rm -rf *.o filelist indexer indexer_cmdline.{c,h} cmdline.{c,h}

all: cmdline.o indexer_cmdline.o filelist indexer 

