
# OPTIONS

CC = gcc

CFLAGS = -g -O2

CXXLAGS = $(CFLAGS)

LDFLAGS = -lstdc++

# RULES

all: client server

# link client

client_OBJECTS = test_clnt.o test_xdr.o client.o

client: $(client_OBJECTS)
	 $(CC) $(CXXFLAGS) $^ $(LDFLAGS) -o $@

# link server

server_OBJECTS = test_svc.o test_xdr.o server.o

server: $(server_OBJECTS)
	$(CC) $(CXXFLAGS) $^ $(LDFLAGS) -o $@

# compile

client.o: client.cc

server.o: server.cc

%.o: %.cc
	$(CC) $(CFLAGS) -c $<

%.o: %.cc
	$(CC) $(CXXFLAGS) -c $<

# generate files from test.x

test.h: test.x
	- rm -f test.h
	rpcgen -N -h test.x -o test.h

test_clnt.c: test.x
	- rm -f test_clnt.c
	rpcgen -N -l test.x -o test_clnt.c

test_svc.c: test.x
	- rm -f test_svc.c
	rpcgen -N -m test.x -o test_svc.c

test_xdr.c: test.x
	- rm -f test_xdr.c
	rpcgen -N -c test.x -o test_xdr.c

test_clnt.c: test.h

test_svc.c: test.h

test_xdr.c: test.h

client.cc: test.h

# CLEAN

CLEANFILES += client.o client
CLEANFILES += server.o server
CLEANFILES += test_xdr.o test_clnt.o test_svc.o
CLEANFILES += test.h test_xdr.c test_clnt.c test_svc.c

clean:
	- test -z "$(CLEANFILES)" || rm -f $(CLEANFILES)

# rpcgen ... yum install glibc-common
# example ... rpcgen -a test.x
