##
#	SWISH++
#	Makefile
#
#	Copyright (C) 1998  Paul J. Lucas
#
#	This program is free software; you can redistribute it and/or modify
#	it under the terms of the GNU General Public License as published by
#	the Free Software Foundation; either version 2 of the License, or
#	(at your option) any later version.
# 
#	This program is distributed in the hope that it will be useful,
#	but WITHOUT ANY WARRANTY; without even the implied warranty of
#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#	GNU General Public License for more details.
# 
#	You should have received a copy of the GNU General Public License
#	along with this program; if not, write to the Free Software
#	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
##

########## You shouldn't have to change anything below this line. #############

ROOT=		.
include		$(ROOT)/config/config.mk

TARGET=		index search extract
CFLAGS=		$(CCFLAGS) # -DDEBUG_is_ok_word -DDEBUG_parse_query

I_LINK=		-lm
I_OBJS=		directory$(CCOEXT) \
		entities$(CCOEXT) \
		file_vector$(CCOEXT) \
		file_info$(CCOEXT) \
		word_index$(CCOEXT) \
		file_list$(CCOEXT) \
		html$(CCOEXT) \
		stop_words$(CCOEXT) \
		util$(CCOEXT) \
		index$(CCOEXT)

S_LINK=		
S_OBJS=		file_vector$(CCOEXT) \
		file_index$(CCOEXT) \
		word_index$(CCOEXT) \
		file_list$(CCOEXT) \
		token$(CCOEXT) \
		search$(CCOEXT)

E_LINK=
E_OBJS=		directory$(CCOEXT) \
		entities$(CCOEXT) \
		ext_proc$(CCOEXT) \
		file_vector$(CCOEXT) \
		postscript$(CCOEXT) \
		stop_words$(CCOEXT) \
		util$(CCOEXT) \
		extract$(CCOEXT)

##
# Build rules
##

all:: $(TARGET)

extract: $(E_OBJS)
	$(CC) $(CFLAGS) $(LPATHS) -o $@ $(E_OBJS) $(E_LINK)

index: $(I_OBJS)
	$(CC) $(CFLAGS) $(LPATHS) -o $@ $(I_OBJS) $(I_LINK)

search: $(S_OBJS)
	$(CC) $(CFLAGS) $(LPATHS) -o $@ $(S_OBJS) $(S_LINK)

directory$(CCOEXT): \
	directory$(CCHEXT) \
	fake_ansi$(CCHEXT) \
		$(PLATFORM_H)

entities$(CCOEXT): \
	entities$(CCHEXT) \
		less$(CCHEXT) \
			fake_ansi$(CCHEXT) \
				$(PLATFORM_H)

ext_proc$(CCOEXT): \
	config$(CCHEXT) \
	ext_proc$(CCHEXT) \
		fake_ansi$(CCHEXT) \
			$(PLATFORM_H) \
		less$(CCHEXT)

extract$(CCOEXT): \
	config$(CCHEXT) \
	directory$(CCHEXT) \
	fake_ansi$(CCHEXT) \
		$(PLATFORM_H) \
	file_vector$(CCHEXT) \
	postscript$(CCHEXT) \
	string_set$(CCHEXT) \
		less$(CCHEXT) \
	util$(CCHEXT) \
	version$(CCHEXT)

file_index$(CCOEXT): \
	fake_ansi$(CCHEXT) \
		$(PLATFORM_H) \
	file_index$(CCHEXT) \
		file_vector$(CCHEXT)

file_info$(CCOEXT): \
	config$(CCHEXT) \
	file_info$(CCHEXT)

file_list$(CCOEXT): \
	fake_ansi$(CCHEXT) \
		$(PLATFORM_H) \
	file_list$(CCHEXT) \
		word_index$(CCHEXT) \
			file_vector$(CCHEXT)

file_vector$(CCOEXT): \
	file_vector$(CCHEXT) \
		fake_ansi$(CCHEXT) \
			$(PLATFORM_H)

html$(CCOEXT): \
	config$(CCHEXT) \
	entities$(CCHEXT) \
		less$(CCHEXT) \
	html$(CCHEXT) \
		file_vector$(CCHEXT) \
	fake_ansi$(CCHEXT) \
		$(PLATFORM_H) \
	util$(CCHEXT)

index$(CCOEXT): \
	config$(CCHEXT) \
	directory$(CCHEXT) \
	fake_ansi$(CCHEXT) \
		$(PLATFORM_H) \
	file_info$(CCHEXT) \
	file_list$(CCHEXT) \
	file_vector$(CCHEXT) \
	html$(CCHEXT) \
	string_set$(CCHEXT) \
		less$(CCHEXT) \
	util$(CCHEXT) \
	version$(CCHEXT) \
	word_info$(CCHEXT) \
	word_index$(CCHEXT)

postscript$(CCOEXT): \
	postscript$(CCHEXT) \
		string_set$(CCHEXT) \
			fake_ansi$(CCHEXT) \
				$(PLATFORM_H) \
			less$(CCHEXT)

search$(CCOEXT): \
	config$(CCHEXT) \
	fake_ansi$(CCHEXT) \
		$(PLATFORM_H) \
	file_index$(CCHEXT) \
		file_vector$(CCHEXT) \
	file_list$(CCHEXT) \
	less$(CCHEXT) \
	token$(CCHEXT) \
	util$(CCHEXT) \
	version$(CCHEXT) \
	word_index$(CCHEXT)

token$(CCOEXT): \
	config$(CCHEXT) \
	fake_ansi$(CCHEXT) \
		$(PLATFORM_H) \
	token$(CCHEXT) \
	util$(CCHEXT)

util$(CCOEXT): \
	config$(CCHEXT) \
	entities$(CCHEXT) \
		less$(CCHEXT) \
	fake_ansi$(CCHEXT) \
		$(PLATFORM_H) \
	string_set$(CCHEXT) \
		less$(CCHEXT) \
	util$(CCHEXT)

word_index$(CCOEXT): \
	fake_ansi$(CCHEXT) \
		$(PLATFORM_H) \
	word_index$(CCHEXT) \
		file_vector$(CCHEXT)

$(PLATFORM_H):
	@cd config && $(MAKE)

##
# Install rules
##

install: $(TARGET)
	$(INSTALL) $(I_OWNER) $(I_GROUP) $(I_XMODE) $(TARGET) $(I_BIN)
	cd $(I_BIN) && $(STRIP) $(TARGET)
	@cd man && $(MAKE) $@

uninstall::
	cd $(I_BIN) && $(RM) $(TARGET)
	@cd man && $(MAKE) $@

##
# Utility rules
##

clean::
	$(RM) *$(CCOEXT) core the.index

dist distclean:: clean
	$(RM) $(TARGET) $(PLATFORM_H)
	@cd man && $(MAKE) $@
