GENWRAPS = read write recv recvfrom recvmsg send sendto sendmsg accept connect
GENWRAPSOURCE = $(GENWRAPS:=.c)

WRAPPERS=open socket pipe close select execve fork wait waitpid $(GENWRAPS)

WRAPPERSOURCE=$(WRAPPERS:=.c)

SOURCE=syscallWrap.c fdesc.c signals.c scout_synch.c $(WRAPPERSOURCE)

OBJS=$(SOURCE:.c=.o)

CFLAGS=-I.. -O -g -DUSER_LEVEL

all: system.o

system.o: $(OBJS) ccflags ldflags
	ld -r $(OBJS) -o $@

$(GENWRAPSOURCE): wrapper_template.c make_wrappers
	./make_wrappers $(GENWRAPS)


ccflags: Makefile $(WRAPPERSOURCE)
	rm -f ccflags
	echo -n "-Wl" >> ccflags
	for i in $(WRAPPERS); do \
	    echo -n ",--wrap,$$i" >> ccflags; \
	done

ldflags: Makefile $(WRAPPERSOURCE)
	rm -f ldflags
	for i in $(WRAPPERS); do \
	    echo -n "--wrap $$i " >> ldflags; \
	done

testprog: testprog.o $(OBJS) ccflags
	$(CC) $(CFLAGS) `cat ccflags` -o $@ ../scout_*.o testprog.o $(OBJS)

clean: 
	rm -f testprog *.o $(GENWRAPSOURCE) ldflags ccflags
