# This file is part of Practical Distributed Processing
# Copyright (C) 2006-2007 Phillip J. Brooke and Richard F. Paige

.PHONY:	all allplus cexamples adaexamples cspsimexamples clean realclean FORCE

CFLAGS=-Wall -D_GNU_SOURCE -g

CEXAMPLES=fork1 \
	fork1b \
	forking-server \
	ngadmin \
	ngclient1 \
	ngmap1 \
	pthread \
	pthread-condition \
	pthread-mutex \
	semaphore \
	skt1-client \
	skt1-client2 \
	skt1-server \
	skt2-client \
	skt2-server \
	skt3-client \
	skt3-server \
	skt4-client \
	skt4-client3 \
	skt4-server \
	skt4-server2 \
	skt4-server3 \
	skt5-server \
	thread1

ADAEXAMPLES=tasks \
	pc \
	pc_ex \
	pc_ex2 \
	philo

CSPSIMEXAMPLES=deadlock

# cspsim should be a symlink to the CSPsim directory.
cspsimdir=cspsim
simconfig=$(cspsimdir)/sim-config

all:	cexamples adaexamples

allplus:	all cspsimexamples

cexamples: $(CEXAMPLES)

adaexamples: $(ADAEXAMPLES)

cspsimexamples: $(CSPSIMEXAMPLES)

deadlock:	deadlock.adb $(shell $(simconfig) adadeps)
	gnatmake deadlock `$(simconfig) client gnat clientlargs`
	strip deadlock

tasks pc pc_ex pc_ex2 philo:	FORCE
	gnatmake $@

fork1 fork1b:	%:	%.c netstr.h netstr.o
	gcc $(CFLAGS) -o $@ $< netstr.o

forking-server skt3-server skt4-server skt4-server2 skt4-server3 skt5-server:	%:	%.c compat.h compat.o constants.h netstr.h netstr.o
	gcc $(CFLAGS) -o $@ $< compat.o netstr.o

skt1-server skt2-server:	%:	%.c constants.h netstr.h netstr.o
	gcc $(CFLAGS) -o $@ $< netstr.o

skt1-client skt1-client2 skt2-client skt3-client skt4-client skt4-client3:	%:	%.c constants.h readloop.h readloop.o netstr.h netstr.o
	gcc $(CFLAGS) -o $@ $< readloop.o netstr.o

pthread pthread-condition pthread-mutex thread1:	%:	%.c
	gcc $(CFLAGS) -o $@ $< -lpthread

semaphore: %: %.c
	gcc $(CFLAGS) -o $@ $< -lpthread

ngadmin ngmap1: %: %.c netstr.h ngcommon.h ngcommon2.h netstr.o ngcommon.o ngcommon2.o
	gcc $(CFLAGS) -o $@ $< netstr.o ngcommon.o ngcommon2.o -lcrypto -lpthread -lm

ngclient1: %: %.c netstr.h ngclient1.h ngcommon.h netstr.o ngcommon.o
	gcc $(CFLAGS) -o $@ $< netstr.o ngcommon.o -lpthread -lm -lncurses

compat.o netstr.o:	%.o: %.c
	gcc $(CFLAGS) -c $<

ngcommon.o ngcommon2.o:	%.o: %.c ngcommon.h
	gcc $(CFLAGS) -c $<

readloop.o:	%.o: %.c constants.h
	gcc $(CFLAGS) -c $<

clean:
	-rm $(CEXAMPLES)
	-rm $(ADAEXAMPLES)
	-rm $(CSPSIMEXAMPLES)
	-rm *.o
	-rm *~
	-rm *.ali
	-rm *.exe

realclean:	clean

FORCE:

