#
# $Id: Makefile,v 1.7 2005/12/02 13:52:29 ldv Exp $
# Copyright (C) 2002-2005  Dmitry V. Levin <ldv@altlinux.org>
# 
# Makefile for the slocate project.
#
# This file 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
#

LFS_CFLAGS = $(shell getconf LFS_CFLAGS)
WARNINGS = -Wall -W -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings \
	-Wconversion -Waggregate-return -Wstrict-prototypes -Werror \
	-Wmissing-prototypes -Wmissing-declarations -Wmissing-noreturn \
	-Wmissing-format-attribute -Wredundant-decls -Wdisabled-optimization
CPPFLAGS = -std=gnu99 $(WARNINGS) -D_GNU_SOURCE
CFLAGS = -pipe -Wall -Werror -W -O2
INSTALL = install
BINDIR=/usr/bin
SBINDIR=/usr/sbin
MANDIR=/usr/share/man
CONFDIR=/etc
CRONDIR=$(CONFDIR)/cron.daily

SRC = frencode.c fstypes.c getstr.c glob.c lists.c locate.c match.c \
	mklocatedb.c nextelem.c regex.c scantree.c substr.c updatedb.c \
	xmalloc.c
OBJ = $(SRC:.c=.o)
DEP = $(SRC:.c=.d)


TARGETS = locate mklocatedb
.PHONY:	all install clean indent

all: $(TARGETS)

%.o: %.c
	$(COMPILE.c) $(LFS_CFLAGS) $(OUTPUT_OPTION) $<

scantree.o: scantree.c
	$(COMPILE.c) $(OUTPUT_OPTION) $<

locate: getstr.o glob.o locate.o match.c nextelem.o regex.o substr.o xmalloc.o

mklocatedb: frencode.o fstypes.o lists.o mklocatedb.o scantree.o updatedb.o xmalloc.o
	$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -lcap $(OUTPUT_OPTION)

install: all
	$(INSTALL) -pD -m2711 locate $(RPM_BUILD_ROOT)$(BINDIR)/slocate
	ln -s slocate $(RPM_BUILD_ROOT)$(BINDIR)/locate
	$(INSTALL) -pD -m755 mklocatedb $(RPM_BUILD_ROOT)$(SBINDIR)/mklocatedb
	$(INSTALL) -pD -m700 updatedb.sh $(RPM_BUILD_ROOT)$(SBINDIR)/updatedb
	$(INSTALL) -pD -m700 updatedb.cron $(RPM_BUILD_ROOT)$(CRONDIR)/updatedb
	$(INSTALL) -pD -m600 updatedb.conf $(RPM_BUILD_ROOT)$(CONFDIR)/updatedb.conf
	$(INSTALL) -pD -m644 slocate.1 $(RPM_BUILD_ROOT)$(MANDIR)/man1/slocate.1
	$(INSTALL) -pD -m644 locate.1 $(RPM_BUILD_ROOT)$(MANDIR)/man1/locate.1
	$(INSTALL) -pD -m644 locatedb.5 $(RPM_BUILD_ROOT)$(MANDIR)/man5/locatedb.5
	$(INSTALL) -pD -m644 mklocatedb.8 $(RPM_BUILD_ROOT)$(MANDIR)/man8/mklocatedb.8
	$(INSTALL) -pD -m644 updatedb.8 $(RPM_BUILD_ROOT)$(MANDIR)/man8/updatedb.8

clean:
	$(RM) $(DEP) $(OBJ) $(TARGETS) core *~

indent:
	indent *.h *.c

# We need dependencies only if goal isn't "indent" or "clean".
ifneq ($(MAKECMDGOALS),indent)
ifneq ($(MAKECMDGOALS),clean)

%.d:	%.c
	@echo Making dependences for $<
	@$(SHELL) -ec "$(CC) -MM $(CPPFLAGS) $< | sed 's|\($*\)\.o[ :]*|\1.o $@ : |g' > $@; [ -s $@ ] || $(RM) $@"

ifneq ($(DEP),)
-include $(DEP)
endif

endif # clean
endif # indent
