# Makefile for GNU locate.
# Do not use this makefile directly, but only from `../Makefile'.
# Copyright (C) 1990 Free Software Foundation, Inc.

# 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, 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.

SHELL = /bin/sh

srcdir = @srcdir@
VPATH = @srcdir@

LIBPROGS = updatedb bigram code
SOURCES = locate.c bigram.c code.c
DISTFILES = Makefile.in updatedb.sh $(SOURCES)

all: locate $(LIBPROGS)
.PHONY: all

.c.o:
	$(CC) -c $(CFLAGS) $(CPPFLAGS) $(DEFS) -I$(srcdir)/../lib $<

install: all
	$(INSTALL_PROGRAM) locate $(bindir)/$(binprefix)locate
	-mkdir $(libdir)
	-mkdir $(datadir)
	for f in $(LIBPROGS); do $(INSTALL_PROGRAM) $$f $(libdir)/$$f; done
.PHONY: install

TAGS: $(SOURCES)
	etags $(SOURCES)

clean:
	rm -f locate $(LIBPROGS) *.o core
.PHONEY: clean

mostlyclean: clean
.PHONY: mostlyclean

distclean: clean
	rm -f Makefile
.PHONY: distclean

realclean: distclean
	rm -f TAGS
.PHONY: realclean

dist:
	ln $(DISTFILES) ../`cat ../.fname`/locate
.PHONY: dist

locate:	locate.o ../lib/libfind.a
	$(CC) -o $@ $(LDFLAGS) locate.o ../lib/libfind.a $(LIBS)

locate.o: locate.c
	$(CC) -c $(CFLAGS) $(CPPFLAGS) $(DEFS) -I$(srcdir)/../lib -DLOCATE_DB=\"$(LOCATE_DB)\" $(srcdir)/locate.c

bigram: bigram.o ../lib/libfind.a
	$(CC) -o $@ $(LDFLAGS) bigram.o ../lib/libfind.a $(LIBS)

code: code.o ../lib/libfind.a
	$(CC) -o $@ $(LDFLAGS) code.o ../lib/libfind.a $(LIBS)

updatedb: updatedb.sh
	rm -f $@
	sed -e "s,@libdir@,$(libdir)," -e "s,@LOCATE_DB@,$(LOCATE_DB)," \
	-e "s,@bindir@,$(bindir)," -e "s,@binprefix@,$(binprefix)," \
	$(srcdir)/updatedb.sh > $@
	chmod +x $@

bigram.o code.o locate.o: ../lib/pathmax.h
locate.o: ../lib/fnmatch.h ../lib/getopt.h

# Prevent GNU make v3 from overflowing arg limit on SysV.
.NOEXPORT:
