Skip to content

Commit c22488d

Browse files
committed
Merge pull request kdlucas#34 from gstrauss/Makefile-modernization
Makefile modernization. Looks good. Let's merge and see if anyone finds issues they cannot resolve.
2 parents e80d3f3 + 274c178 commit c22488d

File tree

9 files changed

+158
-113
lines changed

9 files changed

+158
-113
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
UnixBench/pgms
2+
UnixBench/results
3+
UnixBench/tmp

UnixBench/Makefile

Lines changed: 92 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
# 09/30/07 adding ubgears, GRAPHIC_TESTS switch
3232
# 10/14/07 adding large.txt
3333
# 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]
3436
##############################################################################
3537

3638
##############################################################################
@@ -39,9 +41,9 @@
3941

4042
SHELL = /bin/sh
4143

42-
# GRAPHICS TESTS: Uncomment the definition of "GRAPHIC_TESTS" to enable
44+
# GRAPHIC TESTS: Uncomment the definition of "GRAPHIC_TESTS" to enable
4345
# the building of the graphics benchmarks. This will require the
44-
# X11 libraries on your system.
46+
# X11 libraries on your system. (e.g. libX11-devel mesa-libGL-devel)
4547
#
4648
# Comment the line out to disable these tests.
4749
# GRAPHIC_TESTS = defined
@@ -71,14 +73,33 @@ CC=gcc
7173
# -m386 -malign-loops=1 -malign-jumps=1 -malign-functions=1
7274

7375
## For Solaris 2, or general-purpose GCC 2.7.x
74-
OPTON = -O2 -fomit-frame-pointer -fforce-addr -ffast-math -Wall
76+
#OPTON = -O2 -fomit-frame-pointer -fforce-addr -ffast-math -Wall
7577

7678
## For Digital Unix v4.x, with DEC cc v5.x
7779
#OPTON = -O4
7880
#CFLAGS = -DTIME -std1 -verbose -w0
7981

82+
## gcc optimization flags
83+
## (-ffast-math) disables strict IEEE or ISO rules/specifications for math funcs
84+
OPTON = -O3 -ffast-math
85+
86+
## OS detection. Comment out if gmake syntax not supported by other 'make'.
87+
OSNAME:=$(shell uname -s)
88+
89+
ifeq ($(OSNAME),Linux)
90+
OPTON += -march=native -mtune=native
91+
endif
92+
ifeq ($(OSNAME),Darwin)
93+
# (adjust flags or comment out this section for older versions of XCode or OS X)
94+
# (-mmacosx-versin-min= requires at least that version of SDK be installed)
95+
OPTON += -march=native -mmacosx-version-min=10.10
96+
#http://stackoverflow.com/questions/9840207/how-to-use-avx-pclmulqdq-on-mac-os-x-lion/19342603#19342603
97+
CFLAGS += -Wa,-q
98+
endif
99+
100+
80101
## generic gcc CFLAGS. -DTIME must be included.
81-
CFLAGS = -DTIME -Wall -pedantic -ansi
102+
CFLAGS = -Wall -pedantic $(OPTON) -I $(SRCDIR) -DTIME
82103

83104

84105
##############################################################################
@@ -104,7 +125,7 @@ SOURCES = arith.c big.c context1.c \
104125
dhry_1.c dhry_2.c dhry.h whets.c ubgears.c
105126
TESTS = sort.src cctest.c dc.dat large.txt
106127

107-
ifdef GRAPHIC_TESTS
128+
ifneq (,$(GRAPHIC_TESTS))
108129
GRAPHIC_BINS = $(PROGDIR)/ubgears
109130
else
110131
GRAPHIC_BINS =
@@ -128,13 +149,15 @@ REQD = $(BINS) $(PROGDIR)/unixbench.logo \
128149
$(TESTDIR)/large.txt
129150

130151
# ######################### the big ALL ############################
131-
all: distr programs
152+
all:
132153
## Ick!!! What is this about??? How about let's not chmod everything bogusly.
133154
# @chmod 744 * $(SRCDIR)/* $(PROGDIR)/* $(TESTDIR)/* $(DOCDIR)/*
155+
$(MAKE) distr
156+
$(MAKE) programs
134157

135158
# ####################### a check for Run ######################
136159
check: $(REQD)
137-
make all
160+
$(MAKE) all
138161
# ##############################################################
139162
# distribute the files out to subdirectories if they are in this one
140163
distr:
@@ -178,76 +201,86 @@ distr:
178201
echo "$(RESULTDIR) exists" \
179202
; fi
180203

204+
.PHONY: all check distr programs run clean spotless
205+
181206
programs: $(BINS)
182207

208+
# (use $< to link only the first dependency, instead of $^,
209+
# since the programs matching this pattern have only
210+
# one input file, and others are #include "xxx.c"
211+
# within the first. (not condoning, just documenting))
212+
# (dependencies could be generated by modern compilers,
213+
# but let's not assume modern compilers are present)
214+
$(PROGDIR)/%:
215+
$(CC) -o $@ $(CFLAGS) $< $(LDFLAGS)
216+
183217
# Individual programs
184-
$(PROGDIR)/arithoh: $(SRCDIR)/arith.c
185-
$(CC) -o $(PROGDIR)/arithoh ${CFLAGS} ${OPTON} -Darithoh $(SRCDIR)/arith.c
186-
$(PROGDIR)/register: $(SRCDIR)/arith.c
187-
$(CC) -o $(PROGDIR)/register ${CFLAGS} ${OPTON} -Ddatum='register int' $(SRCDIR)/arith.c
188-
$(PROGDIR)/short: $(SRCDIR)/arith.c
189-
$(CC) -o $(PROGDIR)/short ${CFLAGS} ${OPTON} -Ddatum=short $(SRCDIR)/arith.c
190-
$(PROGDIR)/int: $(SRCDIR)/arith.c
191-
$(CC) -o $(PROGDIR)/int ${CFLAGS} ${OPTON} -Ddatum=int $(SRCDIR)/arith.c
192-
$(PROGDIR)/long: $(SRCDIR)/arith.c
193-
$(CC) -o $(PROGDIR)/long ${CFLAGS} ${OPTON} -Ddatum=long $(SRCDIR)/arith.c
194-
$(PROGDIR)/float: $(SRCDIR)/arith.c
195-
$(CC) -o $(PROGDIR)/float ${CFLAGS} ${OPTON} -Ddatum=float $(SRCDIR)/arith.c
196-
$(PROGDIR)/double: $(SRCDIR)/arith.c
197-
$(CC) -o $(PROGDIR)/double ${CFLAGS} ${OPTON} -Ddatum=double $(SRCDIR)/arith.c
218+
# Sometimes the same source file is compiled in different ways.
219+
# This limits the 'make' patterns that can usefully be applied.
220+
221+
$(PROGDIR)/arithoh: $(SRCDIR)/arith.c $(SRCDIR)/timeit.c
222+
$(PROGDIR)/arithoh: CFLAGS += -Darithoh
223+
$(PROGDIR)/register: $(SRCDIR)/arith.c $(SRCDIR)/timeit.c
224+
$(PROGDIR)/register: CFLAGS += -Ddatum='register int'
225+
$(PROGDIR)/short: $(SRCDIR)/arith.c $(SRCDIR)/timeit.c
226+
$(PROGDIR)/short: CFLAGS += -Ddatum=short
227+
$(PROGDIR)/int: $(SRCDIR)/arith.c $(SRCDIR)/timeit.c
228+
$(PROGDIR)/int: CFLAGS += -Ddatum=int
229+
$(PROGDIR)/long: $(SRCDIR)/arith.c $(SRCDIR)/timeit.c
230+
$(PROGDIR)/long: CFLAGS += -Ddatum=long
231+
$(PROGDIR)/float: $(SRCDIR)/arith.c $(SRCDIR)/timeit.c
232+
$(PROGDIR)/float: CFLAGS += -Ddatum=float
233+
$(PROGDIR)/double: $(SRCDIR)/arith.c $(SRCDIR)/timeit.c
234+
$(PROGDIR)/double: CFLAGS += -Ddatum=double
235+
236+
$(PROGDIR)/poll: $(SRCDIR)/time-polling.c
237+
$(PROGDIR)/poll: CFLAGS += -DUNIXBENCH -DHAS_POLL
238+
$(PROGDIR)/poll2: $(SRCDIR)/time-polling.c
239+
$(PROGDIR)/poll2: CFLAGS += -DUNIXBENCH -DHAS_POLL2
240+
$(PROGDIR)/select: $(SRCDIR)/time-polling.c
241+
$(PROGDIR)/select: CFLAGS += -DUNIXBENCH -DHAS_SELECT
242+
198243
$(PROGDIR)/whetstone-double: $(SRCDIR)/whets.c
199-
$(CC) -o $(PROGDIR)/whetstone-double ${CFLAGS} ${OPTON} -DDP -DUNIX -DUNIXBENCH $(SRCDIR)/whets.c -lm
200-
$(PROGDIR)/hanoi: $(SRCDIR)/hanoi.c
201-
$(CC) -o $(PROGDIR)/hanoi ${CFLAGS} ${OPTON} $(SRCDIR)/hanoi.c
244+
$(PROGDIR)/whetstone-double: CFLAGS += -DDP -DUNIX -DUNIXBENCH
245+
$(PROGDIR)/whetstone-double: LDFLAGS += -lm
202246

203-
$(PROGDIR)/poll: $(SRCDIR)/time-polling.c
204-
$(CC) -DHAS_POLL -DUNIXBENCH -o $(PROGDIR)/poll ${CFLAGS} ${OPTON} $(SRCDIR)/time-polling.c
247+
$(PROGDIR)/pipe: $(SRCDIR)/pipe.c $(SRCDIR)/timeit.c
205248

206-
$(PROGDIR)/poll2: $(SRCDIR)/time-polling.c
207-
$(CC) -DHAS_POLL2 -DUNIXBENCH -o $(PROGDIR)/poll2 ${CFLAGS} ${OPTON} $(SRCDIR)/time-polling.c
249+
$(PROGDIR)/execl: $(SRCDIR)/execl.c $(SRCDIR)/big.c
250+
251+
$(PROGDIR)/spawn: $(SRCDIR)/spawn.c $(SRCDIR)/timeit.c
208252

209-
$(PROGDIR)/select: $(SRCDIR)/time-polling.c
210-
$(CC) -DHAS_SELECT -DUNIXBENCH -o $(PROGDIR)/select ${CFLAGS} ${OPTON} $(SRCDIR)/time-polling.c
253+
$(PROGDIR)/hanoi: $(SRCDIR)/hanoi.c $(SRCDIR)/timeit.c
211254

212255
$(PROGDIR)/fstime: $(SRCDIR)/fstime.c
213-
$(CC) -o $(PROGDIR)/fstime ${CFLAGS} ${OPTON} $(SRCDIR)/fstime.c
214-
215-
$(PROGDIR)/syscall: $(SRCDIR)/syscall.c
216-
$(CC) -o $(PROGDIR)/syscall ${CFLAGS} ${OPTON} $(SRCDIR)/syscall.c
217-
$(PROGDIR)/context1: $(SRCDIR)/context1.c
218-
$(CC) -o $(PROGDIR)/context1 ${CFLAGS} ${OPTON} $(SRCDIR)/context1.c
219-
$(PROGDIR)/pipe: $(SRCDIR)/pipe.c
220-
$(CC) -o $(PROGDIR)/pipe ${CFLAGS} ${OPTON} $(SRCDIR)/pipe.c
221-
$(PROGDIR)/spawn: $(SRCDIR)/spawn.c
222-
$(CC) -o $(PROGDIR)/spawn ${CFLAGS} ${OPTON} $(SRCDIR)/spawn.c
223-
$(PROGDIR)/execl: $(SRCDIR)/execl.c $(SRCDIR)/big.c
224-
$(CC) -o $(PROGDIR)/execl ${CFLAGS} ${OPTON} $(SRCDIR)/execl.c
225-
226-
$(PROGDIR)/dhry2: $(SRCDIR)/dhry_1.c $(SRCDIR)/dhry_2.c $(SRCDIR)/dhry.h
227-
cd $(SRCDIR); $(CC) -c ${CFLAGS} -DHZ=${HZ} ${OPTON} dhry_1.c
228-
cd $(SRCDIR); $(CC) -c ${CFLAGS} -DHZ=${HZ} ${OPTON} dhry_2.c
229-
$(CC) -o $(PROGDIR)/dhry2 ${CFLAGS} ${OPTON} $(SRCDIR)/dhry_1.o $(SRCDIR)/dhry_2.o
230-
cd $(SRCDIR); rm -f dhry_1.o dhry_2.o
231-
$(PROGDIR)/dhry2reg: $(SRCDIR)/dhry_1.c $(SRCDIR)/dhry_2.c $(SRCDIR)/dhry.h
232-
cd $(SRCDIR); $(CC) -c ${CFLAGS} -DREG=register -DHZ=${HZ} ${OPTON} dhry_1.c -o dhry_1_reg.o
233-
cd $(SRCDIR); $(CC) -c ${CFLAGS} -DREG=register -DHZ=${HZ} ${OPTON} dhry_2.c -o dhry_2_reg.o
234-
$(CC) -o $(PROGDIR)/dhry2reg ${CFLAGS} ${OPTON} $(SRCDIR)/dhry_1_reg.o $(SRCDIR)/dhry_2_reg.o
235-
cd $(SRCDIR); rm -f dhry_1_reg.o dhry_2_reg.o
236-
237-
$(PROGDIR)/looper: $(SRCDIR)/looper.c
238-
$(CC) -o $(PROGDIR)/looper ${CFLAGS} ${OPTON} $(SRCDIR)/looper.c
256+
257+
$(PROGDIR)/syscall: $(SRCDIR)/syscall.c $(SRCDIR)/timeit.c
258+
259+
$(PROGDIR)/context1: $(SRCDIR)/context1.c $(SRCDIR)/timeit.c
260+
261+
$(PROGDIR)/looper: $(SRCDIR)/looper.c $(SRCDIR)/timeit.c
239262

240263
$(PROGDIR)/ubgears: $(SRCDIR)/ubgears.c
241-
$(CC) -o $(PROGDIR)/ubgears ${CFLAGS} ${OPTON} $(SRCDIR)/ubgears.c $(GL_LIBS)
264+
$(PROGDIR)/ubgears: LDFLAGS += -lm $(GL_LIBS)
265+
266+
$(PROGDIR)/dhry2: CFLAGS += -DHZ=${HZ}
267+
$(PROGDIR)/dhry2: $(SRCDIR)/dhry_1.c $(SRCDIR)/dhry_2.c \
268+
$(SRCDIR)/dhry.h $(SRCDIR)/timeit.c
269+
$(CC) -o $@ ${CFLAGS} $(SRCDIR)/dhry_1.c $(SRCDIR)/dhry_2.c
270+
271+
$(PROGDIR)/dhry2reg: CFLAGS += -DHZ=${HZ} -DREG=register
272+
$(PROGDIR)/dhry2reg: $(SRCDIR)/dhry_1.c $(SRCDIR)/dhry_2.c \
273+
$(SRCDIR)/dhry.h $(SRCDIR)/timeit.c
274+
$(CC) -o $@ ${CFLAGS} $(SRCDIR)/dhry_1.c $(SRCDIR)/dhry_2.c
242275

243276
# Run the benchmarks and create the reports
244277
run:
245278
sh ./Run
246279

247280
clean:
248-
rm -f $(BINS) core *~ */*~
281+
$(RM) $(BINS) core *~ */*~
249282

250283
spotless: clean
251-
rm -f $(RESULTDIR)/* $(TMPDIR)/*
284+
$(RM) $(RESULTDIR)/* $(TMPDIR)/*
252285

253286
## END ##

UnixBench/Run

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -672,30 +672,48 @@ sub processCpuFlags {
672672
# these fields:
673673
# describing the model etc. Returns undef if the information can't be got.
674674
sub getCpuInfo {
675-
open(my $fd, "<", "/proc/cpuinfo") || return undef;
675+
if (!("$^O" eq "darwin")) {
676+
open(my $fd, "<", "/proc/cpuinfo") || return undef;
677+
678+
my $cpus = [ ];
679+
my $cpu = 0;
680+
while (<$fd>) {
681+
chomp;
682+
my ( $field, $val ) = split(/[ \t]*:[ \t]*/);
683+
next if (!$field || !$val);
684+
if ($field eq "processor") {
685+
$cpu = $val;
686+
} elsif ($field eq "model name") {
687+
my $model = $val;
688+
$model =~ s/ +/ /g;
689+
$cpus->[$cpu]{'model'} = $model;
690+
} elsif ($field eq "bogomips") {
691+
$cpus->[$cpu]{'bogo'} = $val;
692+
} elsif ($field eq "flags") {
693+
$cpus->[$cpu]{'flags'} = processCpuFlags($val);
694+
}
695+
}
676696

677-
my $cpus = [ ];
678-
my $cpu = 0;
679-
while (<$fd>) {
680-
chomp;
681-
my ( $field, $val ) = split(/[ \t]*:[ \t]*/);
682-
next if (!$field || !$val);
683-
if ($field eq "processor") {
684-
$cpu = $val;
685-
} elsif ($field eq "model name") {
686-
my $model = $val;
687-
$model =~ s/ +/ /g;
697+
close($fd);
698+
699+
$cpus;
700+
701+
} else {
702+
703+
my $model = getCmdOutput("sysctl -n machdep.cpu.brand_string");
704+
my $flags = getCmdOutput("sysctl -n machdep.cpu.features | tr [A-Z] [a-z]");
705+
my $ncpu = getCmdOutput("sysctl -n hw.ncpu");
706+
707+
my $cpus = [ ];
708+
my $cpu = 0;
709+
710+
for ($cpu = 0; $cpu < $ncpu; $cpu++) {
688711
$cpus->[$cpu]{'model'} = $model;
689-
} elsif ($field eq "bogomips") {
690-
$cpus->[$cpu]{'bogo'} = $val;
691-
} elsif ($field eq "flags") {
692-
$cpus->[$cpu]{'flags'} = processCpuFlags($val);
712+
$cpus->[$cpu]{'bogo'} = 0;
713+
$cpus->[$cpu]{'flags'} = processCpuFlags($flags);
693714
}
715+
$cpus;
694716
}
695-
696-
close($fd);
697-
698-
$cpus;
699717
}
700718

701719

@@ -723,7 +741,7 @@ sub getSystemInfo {
723741
$info->{'osRel'} = getCmdOutput("uname -r");
724742
$info->{'osVer'} = getCmdOutput("uname -v");
725743
$info->{'mach'} = getCmdOutput("uname -m");
726-
$info->{'platform'} = getCmdOutput("uname -i");
744+
$info->{'platform'} = getCmdOutput("uname -i") || "unknown";
727745

728746
# Get the system name (SUSE, Red Hat, etc.) if possible.
729747
$info->{'system'} = $info->{'os'};
@@ -735,9 +753,9 @@ sub getSystemInfo {
735753

736754
# Get the language info.
737755
my $lang = getCmdOutput("printenv LANG");
738-
my $map = getCmdOutput("locale -k LC_CTYPE | grep charmap");
756+
my $map = getCmdOutput("locale -k LC_CTYPE | grep charmap") || "";
739757
$map =~ s/.*=//;
740-
my $coll = getCmdOutput("locale -k LC_COLLATE | grep collate-codeset");
758+
my $coll = getCmdOutput("locale -k LC_COLLATE | grep collate-codeset") || "";
741759
$coll =~ s/.*=//;
742760
$info->{'language'} = sprintf "%s (charmap=%s, collate=%s)",
743761
$lang, $map, $coll;
@@ -753,7 +771,7 @@ sub getSystemInfo {
753771
$info->{'graphics'} = getCmdOutput("3dinfo | cut -f1 -d\'(\'");
754772

755773
# Get system run state, load and usage info.
756-
$info->{'runlevel'} = getCmdOutput("runlevel | cut -f2 -d\" \"");
774+
$info->{'runlevel'} = getCmdOutput("who -r | awk '{print \$3}'");
757775
$info->{'load'} = getCmdOutput("uptime");
758776
$info->{'numUsers'} = getCmdOutput("who | wc -l");
759777

UnixBench/src/big.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,15 @@
4545
#define MAXCHILD 12
4646
#define MAXWORK 10
4747

48-
/* Can't seem to get this declared in the headers... */
49-
extern int kill(pid_t pid, int sig);
50-
51-
void wrapup(char *);
48+
void wrapup(const char *);
5249
void onalarm(int);
5350
void pipeerr();
5451
void grunt();
5552
void getwork(void);
5653
#if debug
5754
void dumpwork(void);
5855
#endif
59-
void fatal(char *s);
56+
void fatal(const char *s);
6057

6158
float thres;
6259
float est_rate = DEF_RATE;
@@ -420,7 +417,7 @@ void pipeerr()
420417
sigpipe++;
421418
}
422419

423-
void wrapup(char *reason)
420+
void wrapup(const char *reason)
424421
{
425422
int i;
426423
int killed = 0;
@@ -449,7 +446,6 @@ void getwork(void)
449446
char *q = (void *)0;
450447
struct st_work *w = (void *)0;
451448
char line[MAXLINE];
452-
char c;
453449

454450
while (fgets(line, MAXLINE, stdin) != NULL) {
455451
if (nwork >= MAXWORK) {
@@ -492,7 +488,6 @@ void getwork(void)
492488
/* standard input for this job */
493489
q = ++lp;
494490
while (*lp && *lp != ' ') lp++;
495-
c = *lp;
496491
*lp = '\0';
497492
if ((f = open(q, 0)) == -1) {
498493
fprintf(stderr, "cannot open input file (%s) for job %d\n",
@@ -580,10 +575,10 @@ void dumpwork(void)
580575
}
581576
#endif
582577

583-
void fatal(char *s)
578+
void fatal(const char *s)
584579
{
585580
int i;
586-
fprintf(stderr, s);
581+
fprintf(stderr, "%s", s);
587582
fflush(stderr);
588583
perror("Reason?");
589584
fflush(stderr);

0 commit comments

Comments
 (0)