CC	= gcc
CC_G	= -g
CC_O	=
CC_W	=
CC_I	= -I../include
CC_D	=
CFLAGS	= $(CC_O) $(CC_G) $(CC_W) $(CC_I) $(CC_D)
#CC_LINUX= -Wl,-export-dynamic# Linux specific way to make LD_PRELOAD work

METHOD  = itimer
PCT_O   = ../collect/$(METHOD).o
PCT_A   = ../collect/lib$(METHOD).a
PCT_SO  = ../collect/lib$(METHOD).so
PCT_L   = -L../collect

.PHONY: check clean

check:  argv layout o-test a-test l-test so-test g-test ng-test s-test
	./layout 1 2 3 4 5 6 7 8 9 loooooooooooooooooooooong_arg | sort -r
	./argv 1 2 3 4 5 6 7 8 9
	./argv 1 2 3 4 5 6 7 8 9 loooooooooooooooooooooong_arg
#PCT='vo/tmp/pct/ct' ./o-test
	PCT='vq1000r5o/tmp/pct/ct' ./a-test
	PCT='vq1000r5o/tmp/pct/ct' LD_LIBRARY_PATH=../collect ./l-test
	PCT='vq1000r5o/tmp/pct/ct' LD_LIBRARY_PATH=../collect ./so-test
	PCT='vq1000r5o/tmp/pct/ct' LD_PRELOAD=../collect/lib$(METHOD).so ./g-test
	PCT='vq1000r5o/tmp/pct/ct' LD_PRELOAD=../collect/lib$(METHOD).so ./ng-test
	PCT='vq1000r5o/tmp/pct/ct' LD_PRELOAD=../collect/lib$(METHOD).so ./s-test

# This program is for debugging _argv() if the below program fails

layout:	layout.c
	$(CC) $(CFLAGS) -o layout layout.c

# This program tests how well argv[] can be inferred from environ[].

argv:	argv.c ../include/_argv.c
	$(CC) $(CFLAGS) -o argv argv.c

# These programs test the various styles of linking PCT into programs.
# PCT is usable if any of these work.  The letters are mnuemonic for:
# Object one link line, Archive on link line, -L on link line, Shared Object
# on link line, debuG data, No debug data, Stripped.

o-test:	test.c $(PCT_O)
	$(CC) $(CFLAGS) -o o-test test.c $(PCT_O) -ldl

a-test:	test.c $(PCT_A)
	$(CC) $(CFLAGS) -DCALL_PCT -o a-test test.c $(PCT_A) -ldl

l-test:	test.c $(PCT_A) $(PCT_SO)
	$(CC) $(CFLAGS) -o l-test test.c $(PCT_L) -l$(METHOD) -ldl

so-test: test.c $(PCT_SO)
	$(CC) $(CFLAGS) -o so-test test.c $(PCT_SO)

g-test:	test.c
	$(CC) $(CFLAGS) $(CC_LINUX) -o g-test test.c

ng-test: test.c
	$(CC) $(CC_O) $(CC_W) $(CC_LINUX) -o ng-test test.c

s-test:	test.c
	$(CC) $(CC_O) $(CC_W) $(CC_LINUX) -o s-test test.c
	strip s-test

clean:
	rm -rf argv layout *-test *.o *.a *.so core *.pct *.s
