# Makefile.in for yash: yet another shell
# (C) 2007-2010 magicant
#
# 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, see <http://www.gnu.org/licenses/>.

.POSIX:
.SUFFIXES: .c .h .d .o .a

CC = @CC@
CFLAGS = @CFLAGS@
LDFLAGS = @LDFLAGS@
LDLIBS = @LDLIBS@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
DIRS = @DIRS@
SOURCES = alias.c arith.c builtin.c exec.c expand.c hashtable.c history.c input.c job.c mail.c mksignum.c option.c parser.c path.c plist.c redir.c sig.c strbuf.c util.c variable.c xfnmatch.c yash.c
HEADERS = alias.h arith.h builtin.h common.h exec.h expand.h hashtable.h history.h input.h job.h mail.h option.h parser.h path.h plist.h redir.h sig.h siglist.h strbuf.h util.h variable.h xfnmatch.h yash.h
MAIN_OBJS = arith.o builtin.o exec.o expand.o hashtable.o input.o job.o mail.o option.o parser.o path.o plist.o redir.o sig.o strbuf.o util.o variable.o xfnmatch.o yash.o
ALIAS_OBJS = alias.o
HISTORY_OBJS = history.o
BUILTINS_ARCHIVE = builtins/builtins.a
LINEEDIT_ARCHIVE = lineedit/lineedit.a
OBJS = @OBJS@
TARGET = yash
BYPRODUCTS = mksignum.o mksignum signum.h *.dSYM

all: $(TARGET)

.c:
	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LDLIBS)
.c.o:
	@rm -f $@
	$(CC) $(CFLAGS) -c $<

$(TARGET): $(OBJS)
	$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LDLIBS)
$(BUILTINS_ARCHIVE): _PHONY
	@+cd builtins && $(MAKE)
$(LINEEDIT_ARCHIVE): _PHONY
	@+cd lineedit && $(MAKE)
signum.h: mksignum
	./mksignum > $@
sig.o: signum.h

test check:
	@+cd tests && $(MAKE)

DESTDIR =
BINDIR = @BINDIR@
install: install-binary install-doc
install-strip:
	@+$(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' install-binary
	@+$(MAKE) install-doc
install-binary: $(TARGET) $(DESTDIR)$(BINDIR)
	$(INSTALL_PROGRAM) -c $(TARGET) $(DESTDIR)$(BINDIR)/$(TARGET)
install-doc:
	@+cd doc && $(MAKE) install
installdirs: $(DESTDIR)$(BINDIR)
	@+cd doc && $(MAKE) installdirs
$(DESTDIR)$(BINDIR):
	$(INSTALL_PROGRAM) -d $@
uninstall:
	rm -f $(DESTDIR)$(BINDIR)/$(TARGET)
	@+cd doc && $(MAKE) uninstall

VERSION = @VERSION@
DISTDIR = yash-$(VERSION)
DISTS = $(DISTDIR).tar.Z $(DISTDIR).tar.gz $(DISTDIR).tar.bz2 $(DISTDIR).shar.gz $(DISTDIR).zip
DISTCONTENTS = $(SOURCES) $(SOURCES:.c=.d) $(HEADERS) README README.ja COPYING INSTALL INSTALL.ja NEWS NEWS.ja configure Makefile.in install-sh
# "distcontents" depends on "$(OBJS)" to ensure all *.d files up-to-date
distcontents: $(DISTCONTENTS) $(OBJS)
$(DISTDIR):
	rm -fr $@
	mkdir -m 755 $@
	@+base=$$PWD; umask 022; \
	for d in $(DIRS); do \
		(cd $$d && $(MAKE) DISTTARGETDIR=$$base/$@/$$d copy-distcontents) || \
		exit; \
	done
copy-distcontents: distcontents
	mkdir -p $(DISTTARGETDIR)
	cp $(DISTCONTENTS) $(DISTTARGETDIR)
# Only pax and compress comform to POSIX.
dist-tarZ: $(DISTDIR).tar.Z
	-rm -rf $(DISTDIR)
dist dist-gzip: $(DISTDIR).tar.gz
	-rm -rf $(DISTDIR)
dist-bzip2: $(DISTDIR).tar.bz2
	-rm -rf $(DISTDIR)
dist-shar: $(DISTDIR).shar.gz
	-rm -rf $(DISTDIR)
dist-zip: $(DISTDIR).zip
	-rm -rf $(DISTDIR)
dist-all: $(DISTS)
	-rm -rf $(DISTDIR)
$(DISTDIR).tar.Z: $(DISTDIR)
	pax -w -x ustar $(DISTDIR) | compress -c > $@
$(DISTDIR).tar.gz: $(DISTDIR)
	tar -c -f - $(DISTDIR) | gzip -c > $@
$(DISTDIR).tar.bz2: $(DISTDIR)
	tar -c -f - $(DISTDIR) | bzip2 -9 -c > $@
$(DISTDIR).shar.gz: $(DISTDIR)
	shar $(DISTDIR) | gzip -c > $@
$(DISTDIR).zip: $(DISTDIR)
	zip -rq $@ $(DISTDIR)

# ctags conforms to POSIX, but etags and cscope do not.
CTAGS = @CTAGS@
CTAGSARGS = @CTAGSARGS@
ETAGS = @ETAGS@
ETAGSARGS = @ETAGSARGS@
CSCOPE = @CSCOPE@
CSCOPEARGS = @CSCOPEARGS@
tags: $(SOURCES) $(HEADERS)
	$(CTAGS) $(CTAGSARGS)
TAGS: $(SOURCES) $(HEADERS)
	$(ETAGS) $(ETAGSARGS)
cscope: cscope.out
cscope.out: $(SOURCES) $(HEADERS)
	$(CSCOPE) $(CSCOPEARGS)

mostlyclean: _mostlyclean
	-@+cd builtins && $(MAKE) mostlyclean
	-@+cd lineedit && $(MAKE) mostlyclean
_mostlyclean:
	-rm -rf $(OBJS) $(BYPRODUCTS) $(DISTDIR)
	-@+cd tests && $(MAKE) clean
clean: _clean
	-@+cd builtins && $(MAKE) clean
	-@+cd lineedit && $(MAKE) clean
_clean: _mostlyclean
	-rm -rf $(TARGET) $(DISTS)
distclean: _distclean
	-@+cd builtins && $(MAKE) distclean
	-@+cd lineedit && $(MAKE) distclean
	-@+cd tests    && $(MAKE) distclean
	-@+cd doc      && $(MAKE) distclean
_distclean: _clean
	-rm -rf Makefile config.log config.h version.h tags TAGS cscope.out
maintainer-clean:
	@echo 'This command is intended for maintainers to use;'
	@echo 'it deletes files that may need special tools to rebuild.'
	@+$(MAKE) _distclean
	-@+cd builtins && $(MAKE) maintainer-clean
	-@+cd lineedit && $(MAKE) maintainer-clean
	-@+cd tests    && $(MAKE) maintainer-clean
	-rm -rf $(SOURCES:.c=.d)

reconfigure:
	@script=$$(echo '/# Invocation command line was:/ {'; \
	echo 'n'; echo 's/^% //'; echo 'p'; echo 'q'; echo '}'); \
	if line=$$(sed -n "$$script" config.log); \
	then printf '%s\n' "sh $$line"; eval exec sh "$$line"; \
	else echo 'Cannot reconfigure.' >&2; false; \
	fi

.PHONY: all test check install install-strip install-binary install-doc installdirs uninstall dist distcontents copy-distcontents dist-tarZ dist-gzip dist-bzip2 dist-shar dist-zip dist-all cscope mostlyclean _mostlyclean clean _clean distclean _distclean maintainer-clean reconfigure
_PHONY:

@MAKE_INCLUDE@ alias.d
@MAKE_INCLUDE@ arith.d
@MAKE_INCLUDE@ builtin.d
@MAKE_INCLUDE@ exec.d
@MAKE_INCLUDE@ expand.d
@MAKE_INCLUDE@ hashtable.d
@MAKE_INCLUDE@ history.d
@MAKE_INCLUDE@ input.d
@MAKE_INCLUDE@ job.d
@MAKE_INCLUDE@ mail.d
@MAKE_INCLUDE@ mksignum.d
@MAKE_INCLUDE@ option.d
@MAKE_INCLUDE@ parser.d
@MAKE_INCLUDE@ path.d
@MAKE_INCLUDE@ plist.d
@MAKE_INCLUDE@ redir.d
@MAKE_INCLUDE@ sig.d
@MAKE_INCLUDE@ strbuf.d
@MAKE_INCLUDE@ util.d
@MAKE_INCLUDE@ variable.d
@MAKE_INCLUDE@ xfnmatch.d
@MAKE_INCLUDE@ yash.d
