# $Id: Makefile,v 1.1.1.1 1998/12/02 16:51:39 roca Exp $
#
# Makefile
#
#	Modified by : V.Roca
#	Date	    : dec 1997
#



###### Variables ######

# Which OS do you want bench/benchd to execute ?
# Change the LIBRARIES variable too...
#
OSFLAGS = -DLINUX
#OSFLAGS = -DSOLARIS

CC = gcc
LD = gcc

# List of source and object files that comprise a program.
# VR 31/05/94:	Add chstksiz.o for real-time option.
#
bench_OFILES    = common.o stats.o bench.o  bench_sock.o  bench_var.o chstksiz.o
bench_SRCFILES  = common.c stats.c bench.c  bench_sock.c  bench_var.c chstksiz.c

benchd_OFILES   = common.o stats.o benchd.o benchd_sock.o bench_var.o chstksiz.o
benchd_SRCFILES = common.c stats.c benchd.c benchd_sock.c bench_var.c chstksiz.c

INC_FILES = bench.h bench_proto.h

# Local CFLAGS.
# 
CFLAGS_bench  = -O -Wall -DCLIENT -DFAST_SYNC ${OSFLAGS} -DDEBUG -g
CFLAGS_benchd = -O -Wall -DSERVER -DFAST_SYNC ${OSFLAGS} -DDEBUG -g


# Linux version
#
LIBRARIES = -lc -lm

# Solaris version: requires -lsocket -lnsl and -L/usr/ucblib -lucb
#
#LIBRARIES = -lc -lsocket -lnsl -L/usr/ucblib -lucb -lm


###### Dependancies ######

all: bench benchd

bench : ${bench_SRCFILES} ${INC_FILES}
	@echo "** Compile ${bench_SRCFILES} files..."
	@for f in ${bench_SRCFILES} ; do \
		of=`basename $${f} '.c'`.o; \
		echo "${CC} ${CFLAGS_bench} -c $${f}"; \
		${CC} ${CFLAGS_bench} -c $${f}; \
	done
	@echo "done"
	@echo "** Now create bench..."
	${LD} ${LDFLAGS_bench} ${LIBRARIES} ${bench_OFILES} -o bench
	@echo "done"
	@echo "** Remove useless ${bench_OFILES} files..."
	@for f in ${bench_OFILES} ; do \
		if [ -f "$${f}" ] ; then \
			rm "$${f}"; \
		fi \
	done
	@echo "done"

benchd : ${benchd_SRCFILES} ${INC_FILES}
	@echo "** Compile ${benchd_SRCFILES} files..."
	@for f in ${benchd_SRCFILES} ; do \
		of=`basename $${f} '.c'`.o; \
		echo "${CC} ${CFLAGS_benchd} -c $${f}"; \
		${CC} ${CFLAGS_benchd} -c $${f} ; \
	done
	@echo "done"
	@echo "** Now create benchd..."
	${LD} ${LDFLAGS_benchd} ${LIBRARIES} ${benchd_OFILES} -o benchd
	@echo "done"
	@echo "** Remove useless ${benchd_OFILES} files..."
	@for f in ${benchd_OFILES} ; do \
		if [ -f "$${f}" ] ; then \
			rm "$${f}"; \
		fi \
	done
	@echo "done"

clean :
	rm *.o
	if [ -f "core" ] ; then \
		rm core; \
	fi

cleanall :
	@for f in "core bench.linux benchd.linux bench.solaris benchd.solaris" ; do \
		if [ -f $${f} ] ; then \
			rm $${f} ; \
		fi \
	done
	rm *.o

linux : all
	mv bench  bench.linux
	mv benchd benchd.linux
	@if [ -L ${HOME}/bin/bench.linux -o -f ${HOME}/bin/bench.linux ] ; then \
		rm ${HOME}/bin/bench.linux ; \
		rm ${HOME}/bin/benchd.linux ; \
	fi
	ln -s "`pwd`/bench.linux"  ${HOME}/bin/bench.linux  
	ln -s "`pwd`/benchd.linux" ${HOME}/bin/benchd.linux

solaris : all
	mv bench bench.solaris
	mv benchd benchd.solaris
	# NB: error below to fix, not crucial since most of the
	#     work has been done !
	@if [ -L ${HOME}/bin/bench.solaris -o -f ${HOME}/bin/bench.linux ] then \
		rm ${HOME}/bin/bench.solaris \
		rm ${HOME}/bin/benchd.solaris \
	fi
	ln -s "`pwd`/bench.solaris"  ${HOME}/bin/bench.solaris
	ln -s "`pwd`/benchd.solaris" ${HOME}/bin/benchd.solaris
