###############################################################################
# Makefile
#
# Build rules for Stacktrace.
#
# ---------------------------------------------------------------------------
# stacktrace - Stacktrace printer.
#   (C) 2008-2009 Gerardo García Peña <gerardo@kung-foo.net>
#
#   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., 51
#   Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
#
###############################################################################

PACKAGE_VERSION=1.1.0
PACKAGE_NAME=stacktrace
PACKAGE_TARNAME=$(PACKAGE_NAME)-$(PACKAGE_VERSION)

# configure your installation here
DOCDIR=/usr/share/doc/$(PACKAGE_TARNAME)
BINDIR=/usr/bin
INCDIR=/usr/include
LIBDIR=/usr/lib

all : libstacktrace.a stacktrace.so libstacktrace.so test stest

%.o : %.c
	gcc -Wall -c -DPACKAGE_NAME='"$(PACKAGE_NAME)"' -DPACKAGE_VERSION='"$(PACKAGE_VERSION)"' -o $@ $<

lib%.a : %.o
	ar r $@ $^

lib%.so : %.o
	gcc -Wall -shared -o $@ $^

%.so : %.o
	gcc -Wall -shared -o $@ $^

stacktrace_dso.o : stacktrace_dso.c
stacktrace.o : stacktrace.c
stacktrace.so : stacktrace.o stacktrace_dso.o
libstacktrace.so : stacktrace.o
libstacktrace.a : stacktrace.o

test : test.c
	gcc -Wall -o $@ $<

stest : test.c libstacktrace.a
	gcc -Wall -o $@ -DLINKED_STACKTRACE test.c -L. -lstacktrace

.PHONY : clean install

clean :
	rm -f stacktrace.o stacktrace_dso.o  \
	      libstacktrace.a                \
	      stacktrace.so libstacktrace.so \
	      test stest

install : all
	install -m 0644 -D BUGS             $(DOCDIR)/BUGS
	install -m 0644 -D ChangeLog        $(DOCDIR)/ChangeLog
	install -m 0644 -D COPYING          $(DOCDIR)/COPYING
	install -m 0644 -D README           $(DOCDIR)/README
	install -m 0755 -D stacktrace       $(BINDIR)/stacktrace
	install -m 0644 -D stacktrace.h     $(INCDIR)/stacktrace.h
	install -m 0755 -D stacktrace.so    $(LIBDIR)/stacktrace.so
	install -m 0755 -D libstacktrace.so $(LIBDIR)/libstacktrace.so
	install -m 0755 -D libstacktrace.a  $(LIBDIR)/libstacktrace.a

