####################
# version tested with:
# Distro: RedHat 6.2, RedHat 7.0, Mandrak 7.2
# libc: 2.2, 2.1.3 

####################
# marcros

CC = g++
INCLUDES =  -I/usr/include
CCFLAGS = -ldl -lc libcommon.so $(INCLUDES)

####################
# targets

default: common mainprog death message

mainprog:
	$(CC) -olibcbug libcbug.c $(CCFLAGS)

death:
	ln -s libcommon.so nonexistantlib.so
	$(CC) -olibdeath.so death.c $(CCFLAGS) -fPIC -shared nonexistantlib.so
	rm nonexistantlib.so

common:
	$(CC) -olibcommon.so common.c -fPIC -shared

clean:
	-rm libcbug libcommon.so libdeath.so

message:
	@echo
	@echo NOTE: make sure that libcommon.so and libdeath.so can be found on LD_LIBRARY_PATH
	@echo run ./libcbug to see the seg fault
	@echo

.PHONY: default clean mainprog depends common death message
