#
# Makefile - NILFS tool inspector
#
# Copyright (C) 2005, 2006 Nippon Telegraph and Telephone Corporation.
#
# This file is part of NILFS.
#
# NILFS 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.
#
# NILFS 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 NILFS; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#
# Makefile,v 1.16 2006/07/03 07:53:54 kihara Exp
#
# Written by Amagai Yoshiji <amagai@osrg.net>

# make inspect without readline, comment out this line
# you need readline_dev package
GNU_READLINE=y

BINDIR  = /sbin

CC	= gcc
CFLAGS	= -Wall -g -O
LIB	= -luuid
SCRIPTS = listcp listpseg
TARGETS = inspect $(SCRIPTS)

READLINE_DEV := $(shell test -s /usr/include/readline/readline.h -o \
		-s /usr/local/include/readline/readline.h; echo $$?)
ifeq ("$(GNU_READLINE)","y")
  ifeq ("$(READLINE_DEV)","0")
    CFLAGS += -DREADLINE
    LIB += -lreadline -lhistory -lncurses
  endif
endif

SUFFIXES += .sh
%: %.sh
	cat $< >$@
	chmod a+x $@

all: $(TARGETS)

super.o: ../newfs/newfs.h inspect.h super.c
	$(CC) $(CFLAGS) -c -o super.o super.c

parse.o: ../newfs/newfs.h inspect.h parse.c
	$(CC) $(CFLAGS) -c -o parse.o parse.c

inspect.o: ../newfs/newfs.h inspect.h inspect.c
	$(CC) $(CFLAGS) -c -o inspect.o inspect.c

crc.o: crc.c
	$(CC) $(CFLAGS) -c -o crc.o crc.c

inspect: inspect.o parse.o super.o crc.o
	$(CC) $(CFLAGS) -o inspect inspect.o parse.o super.o crc.o $(LIB)

clean:
	rm -f $(TARGETS) *.o *# *~

install:
	install -d $(BINDIR)
	install -m 755 $(TARGETS) $(BINDIR)

uninstall:
	rm -f ${TARGETS:%=$(BINDIR)/%}

reinstall: uninstall install
