# $Id: Makefile,v 1.5 1994/11/26 00:42:09 lm Exp $

# Make targets:
#
# lmbench	[default] builds the benchmark suite for the current os/arch
# results	builds, configures run parameters, and runs the benchmark
# rerun		reruns the benchmark using the same parameters as last time
# clean		cleans out sources and run configuration
# clobber	clean and removes the bin directories
# shar		obsolete, use cd .. && make shar
# depend	builds make dependencies (needs gcc)
#
# This is largely self configuring.  Most stuff is pretty portable.  You
# may have problems with the mhz program.  It needs a C compiler smart
# enough to use "register" when running in unoptimized mode.  gcc does
# this.  cc may not.  Look at the output of mhz and see if it is close
# (within a few percent).  If not, try a different compiler and send me
# mail with the info.
#
# OS config.  If you aren't one of the known OS's (see ../scripts/os)
# then you need to make a target in this makefile with the flags that
# you need.  First fix os to spit out your os and then create a target
# here.  Please mail me that info so I can update the makefile.
#
# If you don't have gcc, try make CC=cc and see if that works.

# I finally know why Larry Wall's Makefile says "Grrrr".
SHELL=/bin/sh

CC = cc
O= ../bin/unknown
OS=`../scripts/os`
BINDIR=../bin/$(OS)
RESULTS=Results/$(OS)
SAMPLES=lmbench/Results/aix/rs6000 lmbench/Results/hpux/snake \
	lmbench/Results/irix/indigo2 lmbench/Results/linux/pentium \
	lmbench/Results/osf1/alpha lmbench/Results/solaris/ss20* 

SYS5=
CFLAGS = -xO2  $(SYS5)

COMPILE=$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS)

SRCS =  bench.h bw_file_rd.c bw_mem_cp.c bw_mem_rd.c bw_mem_wr.c	\
	bw_mmap_rd.c bw_pipe.c bw_tcp.c hello.c lat_connect.c lat_ctx.c	\
	lat_fs.c lat_mem_rd.c lat_mmap.c lat_pagefault.c lat_pipe.c	\
	lat_proc.c lat_rpc.c lat_syscall.c lat_tcp.c lat_udp.c		\
	lib_tcp.c lib_udp.c lmdd.c mhz.c timing.c

EXES = 	$O/bw_file_rd $O/bw_mem_cp $O/bw_mem_rd $O/bw_mem_wr		\
	$O/bw_mmap_rd $O/bw_pipe $O/bw_tcp $O/hello $O/lmdd $O/lat_ctx	\
	$O/lat_mem_rd $O/lat_pipe $O/lat_rpc $O/lat_syscall $O/lat_tcp	\
	$O/lat_udp $O/lat_mmap $O/mhz $O/lat_proc $O/lat_pagefault \
	$O/lat_connect $O/lat_fs

lmbench:
	@echo Building for $(OS)
	@if [ ! -d $(BINDIR) ]; then mkdir -p $(BINDIR); fi
	$(MAKE) CC=$(CC) O=$(BINDIR) $(OS)

results: 
	@$(MAKE) lmbench CC=$(CC) O=$(BINDIR) $(OS)
	@../scripts/config-run $(BINDIR)/CONFIG
	@../scripts/results

rerun: 
	@if [ ! -f $(BINDIR)/CONFIG ]; \
	then	../scripts/config-run $(BINDIR)/CONFIG; \
	fi
	@../scripts/results

# No special handling for all these
all linux sunos: $(EXES)

# System specific stuff.
solaris:
	$(MAKE) O=$O CC=cc LDLIBS="-lnsl -lsocket" SYS5=-DSYS5 all

# HPUX needs gcc; their C compiler screws up mhz.c.
hpux:
	$(MAKE) CC=$(CC) O=$O CFLAGS="$(CFLAGS)" all

# Really specific to the alpha, not osf.
osf1:
	$(MAKE) O=$O CC=cc CFLAGS="$(CFLAGS)" all

irix:
	$(MAKE) O=$O CC=$(CC) CFLAGS="$(CFLAGS) -Dvfork=fork" all

aix:
	$(MAKE) O=$O CC=cc CFLAGS="$(CFLAGS) -Dvfork=fork" all

bsd:
	$(MAKE) O=$O CC=$(CC) CFLAGS="$CFLAGS -Duint='unsigned int'" all

Wall:
	@$(MAKE) clean
	@$(MAKE) CFLAGS=-Wall 

get $(SRCS):
	rccs get -s $(SRCS)

clean:
	/bin/rm -f ../bin/*/CONFIG
	rccs clean -e -s

clobber:
	/bin/rm -rf ../bin* SHAR
	rccs clean -e -s

shar:
	cd ../.. && shar lmbench/Results/Makefile $(SAMPLES) lmbench/scripts/* lmbench/src/Makefile lmbench/src/*.[ch] > lmbench/SHAR

depend:
	../scripts/depend

# No optimization for these.
$O/mhz: mhz.c timing.c bench.h
	$(CC) $(SYS5) -o $O/mhz mhz.c

$O/lat_ctx: lat_ctx.c timing.c bench.h
	$(CC) $(SYS5) -o $O/lat_ctx lat_ctx.c

# Do not remove the next line, make depend needs it
# MAKEDEPEND follows
$O/bw_file_rd:  bw_file_rd.c timing.c bench.h
	$(COMPILE) -o $O/bw_file_rd bw_file_rd.c $(LDLIBS)

$O/bw_mem_cp:  bw_mem_cp.c timing.c bench.h
	$(COMPILE) -o $O/bw_mem_cp bw_mem_cp.c $(LDLIBS)

$O/bw_mem_rd:  bw_mem_rd.c timing.c bench.h
	$(COMPILE) -o $O/bw_mem_rd bw_mem_rd.c $(LDLIBS)

$O/bw_mem_wr:  bw_mem_wr.c timing.c bench.h
	$(COMPILE) -o $O/bw_mem_wr bw_mem_wr.c $(LDLIBS)

$O/bw_mmap_rd:  bw_mmap_rd.c timing.c bench.h
	$(COMPILE) -o $O/bw_mmap_rd bw_mmap_rd.c $(LDLIBS)

$O/bw_pipe:  bw_pipe.c timing.c bench.h
	$(COMPILE) -o $O/bw_pipe bw_pipe.c $(LDLIBS)

$O/bw_tcp:  bw_tcp.c lib_tcp.c bench.h timing.c
	$(COMPILE) -o $O/bw_tcp bw_tcp.c $(LDLIBS)

$O/hello:  hello.c
	$(COMPILE) -o $O/hello hello.c $(LDLIBS)

$O/lat_connect:  lat_connect.c bench.h lib_tcp.c timing.c
	$(COMPILE) -o $O/lat_connect lat_connect.c $(LDLIBS)

$O/lat_fs:  lat_fs.c timing.c bench.h
	$(COMPILE) -o $O/lat_fs lat_fs.c $(LDLIBS)

$O/lat_mem_rd:  lat_mem_rd.c timing.c bench.h
	$(COMPILE) -o $O/lat_mem_rd lat_mem_rd.c $(LDLIBS)

$O/lat_mmap:  lat_mmap.c timing.c bench.h
	$(COMPILE) -o $O/lat_mmap lat_mmap.c $(LDLIBS)

$O/lat_pagefault:  lat_pagefault.c timing.c bench.h
	$(COMPILE) -o $O/lat_pagefault lat_pagefault.c $(LDLIBS)

$O/lat_pipe:  lat_pipe.c timing.c bench.h
	$(COMPILE) -o $O/lat_pipe lat_pipe.c $(LDLIBS)

$O/lat_proc:  lat_proc.c timing.c bench.h
	$(COMPILE) -o $O/lat_proc lat_proc.c $(LDLIBS)

$O/lat_rpc:  lat_rpc.c timing.c bench.h
	$(COMPILE) -o $O/lat_rpc lat_rpc.c $(LDLIBS)

$O/lat_syscall:  lat_syscall.c timing.c bench.h
	$(COMPILE) -o $O/lat_syscall lat_syscall.c $(LDLIBS)

$O/lat_tcp:  lat_tcp.c bench.h lib_tcp.c timing.c
	$(COMPILE) -o $O/lat_tcp lat_tcp.c $(LDLIBS)

$O/lat_udp:  lat_udp.c bench.h lib_udp.c timing.c
	$(COMPILE) -o $O/lat_udp lat_udp.c $(LDLIBS)

$O/lib_tcp:  lib_tcp.c bench.h
	$(COMPILE) -o $O/lib_tcp lib_tcp.c $(LDLIBS)

$O/lib_udp:  lib_udp.c bench.h
	$(COMPILE) -o $O/lib_udp lib_udp.c $(LDLIBS)

$O/lmdd:  lmdd.c timing.c bench.h
	$(COMPILE) -o $O/lmdd lmdd.c $(LDLIBS)

$O/timing:  timing.c bench.h
	$(COMPILE) -o $O/timing timing.c $(LDLIBS)

