# Generated automatically from Makefile.in by configure.
# Makefile.in - Xaric makefile template
# Copyright (c) 2000 Rex Feany (laeos@xaric.org)
#
# This file is a part of Xaric, a silly IRC client.
# You can find Xaric at http://www.xaric.org/.
#
# 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.
#
# @(#)Makefile.in 1.19
#


.DELETE_ON_ERROR:

# Paths
srcdir = .
top_srcdir = .
prefix = /usr/local
exec_prefix = ${prefix}

bindir = ${exec_prefix}/bin
sbindir = ${exec_prefix}/sbin
libexecdir = ${exec_prefix}/libexec
datadir = ${prefix}/share
sysconfdir = ${prefix}/etc
sharedstatedir = ${prefix}/com
localstatedir = ${prefix}/var
libdir = ${exec_prefix}/lib
infodir = ${prefix}/info
mandir = ${prefix}/man
includedir = ${prefix}/include
oldincludedir = /usr/include

pkgdatadir = $(datadir)/xaric
pkglibdir = $(libdir)/xaric
pkgincludedir = $(includedir)/xaric

ACLOCAL = aclocal
AUTOCONF = autoconf
AUTOHEADER = autoheader

INSTALL = /usr/bin/install -c
INSTALL_PROGRAM = ${INSTALL} 
INSTALL_DATA = ${INSTALL} -m 644
INSTALL_SCRIPT = ${INSTALL_PROGRAM}

# Where do we install the help files?
INSTALL_HELP = $(pkgdatadir)/help

XARIC_VERS = source/xversion.c

# Programs
SHTOOL	:= $(srcdir)/shtool
RM	:= rm -f
SED	:= sed
SHELL	:= /bin/sh
CC 	:= gcc
CFLAGS 	:=  -D_GNU_SOURCE -pipe -DHAVE_CONFIG_H -Iinclude 
CPP 	:= gcc -E
LDFLAGS := 
LIBS	:= -ltermcap -ltermcap  -lnsl -lresolv -lpthread

# Extra stuff we need to have here
ALLOCA  := 
STRTOUL := 
SETENV  := 

# Find out our version from the xaric version file.
VERSION=`$(SHTOOL) version -d short $(XARIC_VERS)`

# yes, we're including makefiles not asking them to run.
# this is so makefiles in directories work. 
REALLY_INCLUDE := 1

# things that we should ignore when building the distribution tar
TARIGNORE=config.log,config.cache,config.status,SCCS,.depend,BitKeeper,CVS,ChangeSet,\\.cvsignore,\\.[oa]\\$ 

# Header files that get generated automagicly
AUTOHDR= include/xbuild.h include/xformats_gen.h

# Sections
SECTIONS = source extra

# This is the default target, which compiles the xaric binary
all:  xaric


# Include the data from the subdirectories
# Each Makefile in a subdirectory should have:
#
#      section-obj = obj1.o obj2.o obj3.o # extra objects, not compiled from .c source
#      section-src = srcfile.c srcfile3.c 
#
include ${srcdir}/source/Makefile
include ${srcdir}/extra/Makefile

# and our dependancy info
-include .depend

# Figure out ...
# ... what source files we have
O_SRC = $(sort $(foreach i, $(patsubst %,%-src, $(SECTIONS)), $($(i))) )

# ... what object files we have
O_EXTRA = $(sort $(foreach i, $(patsubst %,%-obj, $(SECTIONS)), $($(i))))

# ... what we should depend on
O_OBJ = $(O_SRC:.c=.o) $(O_EXTRA)

# Build xaric!
xaric: Makefile $(AUTOHDR) $(O_OBJ)
	$(CC) -o xaric $(CFLAGS) $(O_OBJ) $(LIBS)

dep: $(O_SRC)
	@touch $(AUTOHDR) # so it works ...
	$(CC) $(CFLAGS) $(INCLUDES) -MM $(O_SRC) | $(SED) -e "s/\(^[^: ]\+\): \([^. ]\+\).c/\2.o: \2.c/"  > .depend
	@rm -f $(AUTOHDR)

install: installxaric installhelp installman
	@echo "run 'make installdata' if you want the default datafiles installed"

installxaric:
	$(SHTOOL) mkdir -f -p -m 755  $(bindir)
	$(SHTOOL) install -c xaric $(bindir)

installhelp:
	$(SHTOOL) mkdir -f -p -m 755 $(INSTALL_HELP)
	cd help; tar -cf - . | ( cd $(INSTALL_HELP); tar -xf - )

installman:
	
	for i in xaric.1; do $(SHTOOL) install -c doc/$$i $(mandir); done

installdata:
	for i in servers; do $(SHTOOL) install -c doc/$$i $(pkgdatadir); done
 
# rebuild makefile and configure
${srcdir}/configure: configure.in aclocal.m4 acinclude.m4
	cd ${srcdir} && $(AUTOCONF)

${srcdir}/include/config.h.in: ${srcdir}/include/stamp-h.in

${srcdir}/include/stamp-h.in: configure.in aclocal.m4 acinclude.m4 acconfig.h include/config.h.in
	cd ${srcdir} && autoheader
	echo timestamp > ${srcdir}/include/stamp-h.in

config.h: stamp-h
stamp-h: config.h.in config.status
	./config.status

Makefile: Makefile.in config.status
	./config.status

config.status: configure
	./config.status --recheck


# generate array indexes automagicly
include/xformats_gen.h: source/fset.c
	cat $< | $(SED) -n -e "/\*--start--\*/,/\*--end--\*/ { s/.*\"\([^\"]\+\)\".*/\1_FSET,/; s/\/\*[^*]*\*\///; p; }" > $@

# Supply some more information to the build
include/xbuild.h: Makefile
	@echo \#define XARIC_DATA_PATH \"$(pkgdatadir)\" >> .ver
	@mv .ver $@

# include/variables_gen.h: engine/variables.c
#      cat engine/variables.c | $(SED) -n -e "/\*--start--\*/,/\*--end--\*/ { s/.*\"\([^\"]\+\)\".*/\1_VAR,/; s/\/\*[^*]*\*\///; p; }" > include/variables_gen.h


clean:
	$(RM) $(O_OBJ)

distclean: clean
	$(RM) Makefile config.status config.log include/config.h .depend include/stamp-h
	$(RM) config.cache $(AUTOHDR)
	$(RM) xaric

mtclean: distclean
	$(RM) aclocal.m4 configure include/config.h.in

dist:
	@echo "Building distribution for Xaric v$(VERSION)"
	@$(RM) include/config.h # sorta broken but i can't seem to make it work in the ignore string :(
	@$(SHTOOL) tarball -o xaric-$(VERSION).tar.gz -c 'gzip -9' -e '$(TARIGNORE)' .
	@/usr/bin/md5sum xaric-$(VERSION).tar.gz > xaric-$(VERSION).tar.gz.md5
	@echo "Done."

.c.o:
	$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<

.o.so:
	$(LD) -shared -o $@ $<

update-tools:
	@if [ ! -w shtool ]; then echo "Maybe you should check tools out first?"; exit 1; fi
	@$(RM) shtool
	$(MAKE) shtool

shtool:
	shtoolize -o shtool echo version mkdir install tarball


# Targets to update xaric version file.
release:
	@$(SHTOOL) version -lc -n xaric -p XARIC  -iv $(XARIC_VERS)
revision:
	@$(SHTOOL) version -lc -n xaric -p XARIC  -ir $(XARIC_VERS)
patch:
	@$(SHTOOL) version -lc -n xaric -p XARIC  -il $(XARIC_VERS)
