# Makefile for sigsegv

#### Start of system configuration section. ####

# Directories used by "make":
srcdir = @srcdir@

# Directories used by "make install":
prefix = @prefix@
local_prefix = /usr/local
exec_prefix = $(prefix)
libdir = $(exec_prefix)/lib
includedir = $(prefix)/include
mandir = $(exec_prefix)/man

# Programs used by "make":
CC = @CC@
CFLAGS = @CFLAGS@
CPP = @CPP@
INCLUDES = -I. -I$(srcdir)
LIBTOOL = @LIBTOOL@
LIBTOOL_COMPILE = $(LIBTOOL) --mode=compile
LIBTOOL_LINK = $(LIBTOOL) --mode=link
LIBTOOL_INSTALL = $(LIBTOOL) --mode=install
LIBTOOL_UNINSTALL = $(LIBTOOL) --mode=uninstall
AR = ar
AR_FLAGS = rc
RANLIB = @RANLIB@
MV = mv
LN = ln
RM = rm -f

# Programs used by "make install":
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@

#### End of system configuration section. ####

SHELL = /bin/sh

# Needed by $(LIBTOOL).
top_builddir = .

OBJECTS = handler.lo dispatcher.lo

all : sigsegv.h libsigsegv.la

SEDPREPARE0 = sharp=`echo x | tr x '\043'`
SEDPREPARE1 = if grep "$${sharp}define HAVE_SIGALTSTACK" config.h > /dev/null 2>/dev/null; then sedcommand1='s,^/\* \(.*\) ifdef HAVE_SIGALTSTACK in config.h \*/$$,\1,' ; else sedcommand1='s/x/x/' ; fi
SEDCOMMAND1 = -e "$$sedcommand1"
SEDCOMMAND2 = -e "s,^.*if test1 crashes.*\$$,$${sharp}undef HAVE_SIGSEGV_RECOVERY,"
SEDCOMMAND3 = -e "s,^.*if test3 crashes.*\$$,$${sharp}undef HAVE_STACK_OVERFLOW_RECOVERY,"

sigsegv.h : config.h
	$(SEDPREPARE0) ; $(SEDPREPARE1) ; sed $(SEDCOMMAND1) < $(srcdir)/sigsegv.h.in > sigsegv.h
	$(CC) $(CFLAGS) $(INCLUDES) $(srcdir)/test1.c $(srcdir)/handler.c -o test1
	if ./test1 > /dev/null 2> /dev/null ; then : ; else $(SEDPREPARE0) ; sed $(SEDCOMMAND2) < sigsegv.h > sigsegv.tmp ; mv sigsegv.tmp sigsegv.h ; fi
	$(RM) test1 *.o core
	$(CC) $(CFLAGS) $(INCLUDES) $(srcdir)/test3.c $(srcdir)/handler.c -o test3
	if ./test3 > /dev/null 2> /dev/null ; then : ; else $(SEDPREPARE0) ; sed $(SEDCOMMAND3) < sigsegv.h > sigsegv.tmp ; mv sigsegv.tmp sigsegv.h ; fi
	$(RM) test3 *.o core

handler.lo : $(srcdir)/handler.c sigsegv.h
	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS) $(INCLUDES) -c $(srcdir)/handler.c

dispatcher.lo : $(srcdir)/dispatcher.c sigsegv.h
	$(LIBTOOL_COMPILE) $(CC) $(CFLAGS) $(INCLUDES) -c $(srcdir)/dispatcher.c

libsigsegv.la : $(OBJECTS)
	$(LIBTOOL_LINK) $(CC) -o libsigsegv.la -rpath $(libdir) $(OBJECTS)

# Installs the library and include files only. Typically called with only
# $(libdir) and $(includedir) - don't use $(prefix) and $(exec_prefix) here.
install-lib : all force
	if [ ! -d $(libdir) ] ; then mkdir $(libdir) ; fi
	$(LIBTOOL_INSTALL) $(INSTALL_DATA) libsigsegv.la $(libdir)/libsigsegv.la
	if [ ! -d $(includedir) ] ; then mkdir $(includedir) ; fi
	$(INSTALL_DATA) sigsegv.h $(includedir)/sigsegv.h

install : all force
	if [ ! -d $(prefix) ] ; then mkdir $(prefix) ; fi
	if [ ! -d $(exec_prefix) ] ; then mkdir $(exec_prefix) ; fi
	if [ ! -d $(libdir) ] ; then mkdir $(libdir) ; fi
	$(LIBTOOL_INSTALL) $(INSTALL_DATA) libsigsegv.la $(libdir)/libsigsegv.la
	if [ ! -d $(includedir) ] ; then mkdir $(includedir) ; fi
	$(INSTALL_DATA) sigsegv.h $(includedir)/sigsegv.h

installdirs : force
	if [ ! -d $(prefix) ] ; then mkdir $(prefix) ; fi
	if [ ! -d $(exec_prefix) ] ; then mkdir $(exec_prefix) ; fi
	if [ ! -d $(libdir) ] ; then mkdir $(libdir) ; fi
	if [ ! -d $(includedir) ] ; then mkdir $(includedir) ; fi

uninstall : force
	$(LIBTOOL_UNINSTALL) $(RM) $(libdir)/libsigsegv.la
	$(RM) $(includedir)/sigsegv.h

test1 : $(srcdir)/test1.c sigsegv.h libsigsegv.la
	$(LIBTOOL_LINK) $(CC) $(CFLAGS) $(INCLUDES) $(srcdir)/test1.c @GCC_X_NONE@ libsigsegv.la -o test1

test2 : $(srcdir)/test2.c sigsegv.h libsigsegv.la
	$(LIBTOOL_LINK) $(CC) $(CFLAGS) $(INCLUDES) $(srcdir)/test2.c @GCC_X_NONE@ libsigsegv.la -o test2

test3 : $(srcdir)/test3.c sigsegv.h libsigsegv.la
	$(LIBTOOL_LINK) $(CC) $(CFLAGS) $(INCLUDES) $(srcdir)/test3.c @GCC_X_NONE@ libsigsegv.la -o test3

check : all test1 test2 test3
	./test1
	./test2
	./test3

mostlyclean : clean

clean : force
	$(RM) sigsegv.h sigsegv.tmp *.o *.lo *.a *.la core
	$(RM) -r .libs _libs
	$(RM) test1 test2 test3

distclean : clean
	$(RM) config.status config.log config.cache Makefile config.h libtool

maintainer-clean : distclean

force :

