# PR port-vax/44155: exceptions crossing a shared library boundary.
# Works with NetBSD make and GNU make.  Try other levels: make OPT=-O0

CXX?=		c++
OPT?=		-O2
WARN=		-Wall -Wextra
FLAGS=		${OPT} -g ${WARN}

LIB=		libthrower.so
PROG=		exc_shlib

all: ${LIB} ${PROG}

${LIB}: libthrower.cc libthrower.h
	${CXX} ${FLAGS} -fPIC -shared -Wl,-soname,${LIB} -o $@ libthrower.cc

# $ORIGIN lets the program find libthrower.so next to itself.
${PROG}: exc_shlib.cc libthrower.h ${LIB}
	${CXX} ${FLAGS} -o $@ exc_shlib.cc -L. -lthrower -Wl,-rpath,'$$ORIGIN'

run: all
	./${PROG}; echo "exit status $$?"

clean:
	rm -f ${LIB} ${PROG} *.core core

.PHONY: all run clean
