1##############################################################################
2#	UnixBench v5.1.3
3#  Based on The BYTE UNIX Benchmarks - Release 3
4#          Module: Makefile   SID: 3.9 5/15/91 19:30:15
5#
6##############################################################################
7# Bug reports, patches, comments, suggestions should be sent to:
8#	David C Niemi <niemi@tux.org>
9#
10# Original Contacts at Byte Magazine:
11#	Ben Smith or Tom Yager at BYTE Magazine
12#	bensmith@bytepb.byte.com    tyager@bytepb.byte.com
13#
14##############################################################################
15#  Modification Log: 7/28/89 cleaned out workload files
16#                    4/17/90 added routines for installing from shar mess
17#                    7/23/90 added compile for dhrystone version 2.1
18#                          (this is not part of Run file. still use old)
19#                          removed HZ from everything but dhry.
20#                          HZ is read from the environment, if not
21#                          there, you must define it in this file
22#                    10/30/90 moved new dhrystone into standard set
23#                          new pgms (dhry included) run for a specified
24#                          time rather than specified number of loops
25#                    4/5/91 cleaned out files not needed for
26#                          release 3 -- added release 3 files -ben
27#                    10/22/97 added compiler options for strict ANSI C
28#                          checking for gcc and DEC's cc on
29#                          Digital Unix 4.x (kahn@zk3.dec.com)
30#                    09/26/07 changes for UnixBench 5.0
31#                    09/30/07 adding ubgears, GRAPHIC_TESTS switch
32#                    10/14/07 adding large.txt
33#                    01/13/11 added support for parallel compilation
34#                    01/07/16 [refer to version control commit messages and
35#                              cease using two-digit years in date formats]
36##############################################################################
37
38##############################################################################
39# CONFIGURATION
40##############################################################################
41
42SHELL = /bin/sh
43
44# GRAPHIC TESTS: Uncomment the definition of "GRAPHIC_TESTS" to enable
45# the building of the graphics benchmarks.  This will require the
46# X11 libraries on your system. (e.g. libX11-devel mesa-libGL-devel)
47#
48# Comment the line out to disable these tests.
49# GRAPHIC_TESTS = defined
50
51# Set "GL_LIBS" to the libraries needed to link a GL program.
52GL_LIBS = -lGL -lXext -lX11
53
54
55# COMPILER CONFIGURATION: Set "CC" to the name of the compiler to use
56# to build the binary benchmarks.  You should also set "$cCompiler" in the
57# Run script to the name of the compiler you want to test.
58CC=gcc
59
60# OPTIMISATION SETTINGS:
61# Use gcc option if defined UB_GCC_OPTIONS via "Environment variable" or "Command-line arguments".
62ifdef UB_GCC_OPTIONS
63  OPTON = $(UB_GCC_OPTIONS)
64
65else
66  ## Very generic
67  #OPTON = -O
68
69  ## For Linux 486/Pentium, GCC 2.7.x and 2.8.x
70  #OPTON = -O2 -fomit-frame-pointer -fforce-addr -fforce-mem -ffast-math \
71  #	-m486 -malign-loops=2 -malign-jumps=2 -malign-functions=2
72
73  ## For Linux, GCC previous to 2.7.0
74  #OPTON = -O2 -fomit-frame-pointer -fforce-addr -fforce-mem -ffast-math -m486
75
76  #OPTON = -O2 -fomit-frame-pointer -fforce-addr -fforce-mem -ffast-math \
77  #	-m386 -malign-loops=1 -malign-jumps=1 -malign-functions=1
78
79  ## For Solaris 2, or general-purpose GCC 2.7.x
80  #OPTON = -O2 -fomit-frame-pointer -fforce-addr -ffast-math -Wall
81
82  ## For Digital Unix v4.x, with DEC cc v5.x
83  #OPTON = -O4
84  #CFLAGS = -DTIME -std1 -verbose -w0
85
86  ## gcc optimization flags
87  ## (-ffast-math) disables strict IEEE or ISO rules/specifications for math funcs
88  OPTON = -O3 -ffast-math
89
90  ## OS detection.  Comment out if gmake syntax not supported by other 'make'.
91  OSNAME:=$(shell uname -s)
92  ARCH := $(shell uname -p)
93  ifeq ($(OSNAME),Linux)
94    # Not all CPU architectures support "-march" or "-march=native".
95    #   - Supported    : x86, x86_64, ARM, AARCH64, etc..
96    #   - Not Supported: RISC-V, IBM Power, etc...
97    ifneq ($(ARCH),$(filter $(ARCH),ppc64 ppc64le))
98        OPTON += -march=native -mtune=native
99    else
100        OPTON += -mcpu=native -mtune=native
101    endif
102  endif
103
104  ifeq ($(OSNAME),Darwin)
105    # (adjust flags or comment out this section for older versions of XCode or OS X)
106    # (-mmacosx-versin-min= requires at least that version of SDK be installed)
107    ifneq ($(ARCH),$(filter $(ARCH),ppc64 ppc64le))
108        OPTON += -march=native -mmacosx-version-min=10.10
109    else
110        OPTON += -mcpu=native
111    endif
112    #http://stackoverflow.com/questions/9840207/how-to-use-avx-pclmulqdq-on-mac-os-x-lion/19342603#19342603
113    CFLAGS += -Wa,-q
114  endif
115
116endif
117
118
119## generic gcc CFLAGS.  -DTIME must be included.
120CFLAGS += -Wall -pedantic $(OPTON) -I $(SRCDIR) -DTIME
121
122
123##############################################################################
124# END CONFIGURATION
125##############################################################################
126
127
128# local directories
129PROGDIR = ./pgms
130SRCDIR = ./src
131TESTDIR = ./testdir
132RESULTDIR = ./results
133TMPDIR = ./tmp
134# other directories
135INCLDIR = /usr/include
136LIBDIR = /lib
137SCRIPTS = unixbench.logo multi.sh tst.sh index.base
138SOURCES = arith.c big.c context1.c \
139	dummy.c execl.c \
140	fstime.c hanoi.c \
141	pipe.c spawn.c \
142	syscall.c looper.c timeit.c time-polling.c \
143	dhry_1.c dhry_2.c dhry.h whets.c ubgears.c
144TESTS = sort.src cctest.c dc.dat large.txt
145
146ifneq (,$(GRAPHIC_TESTS))
147GRAPHIC_BINS = $(PROGDIR)/ubgears
148else
149GRAPHIC_BINS =
150endif
151
152# Program binaries.
153BINS = $(PROGDIR)/arithoh $(PROGDIR)/register $(PROGDIR)/short \
154	$(PROGDIR)/int $(PROGDIR)/long $(PROGDIR)/float $(PROGDIR)/double \
155	$(PROGDIR)/hanoi $(PROGDIR)/syscall $(PROGDIR)/context1 \
156	$(PROGDIR)/pipe $(PROGDIR)/spawn $(PROGDIR)/execl \
157	$(PROGDIR)/dhry2 $(PROGDIR)/dhry2reg  $(PROGDIR)/looper \
158	$(PROGDIR)/fstime $(PROGDIR)/whetstone-double $(GRAPHIC_BINS)
159## These compile only on some platforms...
160# $(PROGDIR)/poll $(PROGDIR)/poll2 $(PROGDIR)/select
161
162# Required non-binary files.
163REQD = $(BINS) $(PROGDIR)/unixbench.logo \
164	$(PROGDIR)/multi.sh $(PROGDIR)/tst.sh $(PROGDIR)/index.base \
165	$(PROGDIR)/gfx-x11 \
166	$(TESTDIR)/sort.src $(TESTDIR)/cctest.c $(TESTDIR)/dc.dat \
167	$(TESTDIR)/large.txt
168
169# ######################### the big ALL ############################
170all:
171## Ick!!!  What is this about???  How about let's not chmod everything bogusly.
172#	@chmod 744 * $(SRCDIR)/* $(PROGDIR)/* $(TESTDIR)/* $(DOCDIR)/*
173	$(MAKE) distr
174	$(MAKE) programs
175
176# ####################### a check for Run ######################
177check: $(REQD)
178	$(MAKE) all
179# ##############################################################
180# distribute the files out to subdirectories if they are in this one
181distr:
182	@echo "Checking distribution of files"
183# scripts
184	@if  test ! -d  $(PROGDIR) \
185        ; then  \
186           mkdir $(PROGDIR) \
187           ; mv $(SCRIPTS) $(PROGDIR) \
188        ; else \
189           echo "$(PROGDIR)  exists" \
190        ; fi
191# C sources
192	@if  test ! -d  $(SRCDIR) \
193        ; then  \
194           mkdir $(SRCDIR) \
195           ; mv $(SOURCES) $(SRCDIR) \
196        ; else \
197           echo "$(SRCDIR)  exists" \
198        ; fi
199# test data
200	@if  test ! -d  $(TESTDIR) \
201        ; then  \
202           mkdir $(TESTDIR) \
203           ; mv $(TESTS) $(TESTDIR) \
204        ; else \
205           echo "$(TESTDIR)  exists" \
206        ; fi
207# temporary work directory
208	@if  test ! -d  $(TMPDIR) \
209        ; then  \
210           mkdir $(TMPDIR) \
211        ; else \
212           echo "$(TMPDIR)  exists" \
213        ; fi
214# directory for results
215	@if  test ! -d  $(RESULTDIR) \
216        ; then  \
217           mkdir $(RESULTDIR) \
218        ; else \
219           echo "$(RESULTDIR)  exists" \
220        ; fi
221
222.PHONY: all check distr programs run clean spotless
223
224programs: $(BINS)
225
226# (use $< to link only the first dependency, instead of $^,
227#  since the programs matching this pattern have only
228#  one input file, and others are #include "xxx.c"
229#  within the first.  (not condoning, just documenting))
230# (dependencies could be generated by modern compilers,
231#  but let's not assume modern compilers are present)
232$(PROGDIR)/%:
233	$(CC) -o $@ $(CFLAGS) $< $(LDFLAGS)
234
235# Individual programs
236# Sometimes the same source file is compiled in different ways.
237# This limits the 'make' patterns that can usefully be applied.
238
239$(PROGDIR)/arithoh:  $(SRCDIR)/arith.c $(SRCDIR)/timeit.c
240$(PROGDIR)/arithoh:  CFLAGS += -Darithoh
241$(PROGDIR)/register: $(SRCDIR)/arith.c $(SRCDIR)/timeit.c
242$(PROGDIR)/register: CFLAGS += -Ddatum='register int'
243$(PROGDIR)/short:    $(SRCDIR)/arith.c $(SRCDIR)/timeit.c
244$(PROGDIR)/short:    CFLAGS += -Ddatum=short
245$(PROGDIR)/int:      $(SRCDIR)/arith.c $(SRCDIR)/timeit.c
246$(PROGDIR)/int:      CFLAGS += -Ddatum=int
247$(PROGDIR)/long:     $(SRCDIR)/arith.c $(SRCDIR)/timeit.c
248$(PROGDIR)/long:     CFLAGS += -Ddatum=long
249$(PROGDIR)/float:    $(SRCDIR)/arith.c $(SRCDIR)/timeit.c
250$(PROGDIR)/float:    CFLAGS += -Ddatum=float
251$(PROGDIR)/double:   $(SRCDIR)/arith.c $(SRCDIR)/timeit.c
252$(PROGDIR)/double:   CFLAGS += -Ddatum=double
253
254$(PROGDIR)/poll:     $(SRCDIR)/time-polling.c
255$(PROGDIR)/poll:     CFLAGS += -DUNIXBENCH -DHAS_POLL
256$(PROGDIR)/poll2:    $(SRCDIR)/time-polling.c
257$(PROGDIR)/poll2:    CFLAGS += -DUNIXBENCH -DHAS_POLL2
258$(PROGDIR)/select:   $(SRCDIR)/time-polling.c
259$(PROGDIR)/select:   CFLAGS += -DUNIXBENCH -DHAS_SELECT
260
261$(PROGDIR)/whetstone-double: $(SRCDIR)/whets.c
262$(PROGDIR)/whetstone-double: CFLAGS += -DDP -DGTODay -DUNIXBENCH
263$(PROGDIR)/whetstone-double: LDFLAGS += -lm
264
265$(PROGDIR)/pipe: $(SRCDIR)/pipe.c $(SRCDIR)/timeit.c
266
267$(PROGDIR)/execl: $(SRCDIR)/execl.c $(SRCDIR)/big.c
268
269$(PROGDIR)/spawn: $(SRCDIR)/spawn.c $(SRCDIR)/timeit.c
270
271$(PROGDIR)/hanoi: $(SRCDIR)/hanoi.c $(SRCDIR)/timeit.c
272
273$(PROGDIR)/fstime: $(SRCDIR)/fstime.c
274
275$(PROGDIR)/syscall: $(SRCDIR)/syscall.c $(SRCDIR)/timeit.c
276
277$(PROGDIR)/context1: $(SRCDIR)/context1.c $(SRCDIR)/timeit.c
278
279$(PROGDIR)/looper: $(SRCDIR)/looper.c $(SRCDIR)/timeit.c
280
281$(PROGDIR)/ubgears: $(SRCDIR)/ubgears.c
282$(PROGDIR)/ubgears: LDFLAGS += -lm $(GL_LIBS)
283
284$(PROGDIR)/dhry2: CFLAGS += -DHZ=${HZ}
285$(PROGDIR)/dhry2: $(SRCDIR)/dhry_1.c $(SRCDIR)/dhry_2.c \
286                  $(SRCDIR)/dhry.h $(SRCDIR)/timeit.c
287	$(CC) -o $@ ${CFLAGS} $(SRCDIR)/dhry_1.c $(SRCDIR)/dhry_2.c
288
289$(PROGDIR)/dhry2reg: CFLAGS += -DHZ=${HZ} -DREG=register
290$(PROGDIR)/dhry2reg: $(SRCDIR)/dhry_1.c $(SRCDIR)/dhry_2.c \
291                     $(SRCDIR)/dhry.h $(SRCDIR)/timeit.c
292	$(CC) -o $@ ${CFLAGS} $(SRCDIR)/dhry_1.c $(SRCDIR)/dhry_2.c
293
294# Run the benchmarks and create the reports
295run:
296	sh ./Run
297
298clean:
299	$(RM) $(BINS) core *~ */*~
300
301spotless:	clean
302	$(RM) $(RESULTDIR)/* $(TMPDIR)/*
303
304## END ##
305