-
Notifications
You must be signed in to change notification settings - Fork 0
/
GNUmakefile
176 lines (133 loc) · 3.25 KB
/
GNUmakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#
# Makefile for Clockperf
#
MAKEFLAGS += -Rr
uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
uname_O := $(shell sh -c 'uname -o 2>/dev/null || echo not')
prefix := /usr/local
bindir := $(prefix)/bin
ifneq ($(findstring MINGW,$(uname_S)),)
win32 = Yep
endif
ifdef win32
EXT := .exe
else
EXT :=
endif
ifneq ($(findstring $(MAKEFLAGS),s),s)
ifndef V
QUIET_DEPEND = @echo ' ' DEPEND $@;
QUIET_CC = @echo ' ' CC $@;
QUIET_GEN = @echo ' ' GEN $@;
QUIET_LINK = @echo ' ' LD $@;
QUIET = @
export V
endif
endif
PROJECT := clockperf
BINARY := $(PROJECT)$(EXT)
all: $(BINARY)
ifdef DEBUG
OPTLEVEL := -O0 -ggdb3 -D_DEBUG
else
OPTLEVEL := -O3
endif
CC := gcc
CP := cp -L
COMPILER_ACCEPTS_OPENMP := $(shell $(CC) -c -fopenmp -xc /dev/null -o /dev/null &>/dev/null && echo yes || echo no)
ifeq ($(COMPILER_ACCEPTS_OPENMP),yes)
OPENMP_ARG := -fopenmp
endif
CFLAGS := \
$(OPTLEVEL) \
$(OPENMP_ARG) \
-fno-strict-aliasing \
-std=gnu11 \
-Werror=implicit \
-Werror=undef \
-Wall \
-Wextra \
-Wdeclaration-after-statement \
-Wimplicit-function-declaration \
-Wmissing-declarations \
-Wmissing-prototypes \
-Wno-long-long \
-Wno-overlength-strings \
-Wold-style-definition \
-Wstrict-prototypes \
-Wno-deprecated-declarations
LDFLAGS := -lm
OBJECTS := affinity.o clock.o drift.o main.o util.o version.o
ifdef NO_GNU_GETOPT
CFLAGS += -Igetopt
OBJECTS += getopt/getopt_long.o
endif
ifneq ($(CC),clang)
CFLAGS += -fPIC
LDFLAGS += -fPIC
endif
ifeq ($(uname_S),Linux)
CFLAGS += -pthread
LDFLAGS += -pthread -lrt
endif
ifeq ($(uname_S),FreeBSD)
CFLAGS += -pthread
LDFLAGS += -pthread
endif
ifneq ($(findstring MINGW,$(uname_S)),)
LDFLAGS += -lpthread -lwinmm
endif
ifneq ($(findstring CYGWIN,$(uname_S)),)
LDFLAGS += -lwinmm
endif
ifneq ($(findstring -flto,$(CFLAGS)),)
LDFLAGS += $(CFLAGS)
endif
ifeq (,$(findstring clean,$(MAKECMDGOALS)))
ifeq (,$(findstring distclean,$(MAKECMDGOALS)))
DEPS := $(shell ls $(OBJECTS:.o=.d) 2>/dev/null)
ifneq ($(DEPS),)
-include $(DEPS)
endif
endif
endif
.PHONY: all depend clean distclean install
install: $(BINARY)
install -D -m0755 $(BINARY) $(DESTDIR)$(bindir)/$(BINARY)
depend: $(DEPS)
$(BINARY): $(OBJECTS)
+$(QUIET_LINK)$(CC) -o $@ $(OBJECTS) $(LDFLAGS) $(CFLAGS)
distclean: clean
clean:
$(QUIET)rm -f .cflags
$(QUIET)rm -f $(BINARY)
$(QUIET)rm -f $(OBJECTS) build.h license.h
$(QUIET)rm -f $(OBJECTS:.o=.d)
ifdef NO_INLINE_DEPGEN
$(OBJECTS): $(OBJECTS:.o=.d)
endif
%.d: %.c .cflags
$(QUIET_DEPEND)$(CC) -MM $(CFLAGS) -MT $*.o $< > $*.d
%.o: %.c .cflags
ifdef NO_INLINE_DEPGEN
$(QUIET_CC)$(CC) $(CFLAGS) -c -o $@ $<
else
$(QUIET_CC)$(CC) $(CFLAGS) -MD -c -o $@ $<
endif
build.h: .force-regen
$(QUIET_GEN)tools/build.pl build.h
.PHONY: .force-regen
license.h: COPYING
$(QUIET_GEN)tools/license.pl COPYING license.h
version.d: license.h build.h
version.o: license.h build.h
ifeq (,$(findstring clean,$(MAKECMDGOALS)))
TRACK_CFLAGS = $(subst ','\'',$(CC) $(CFLAGS) $(uname_S) $(uname_O) $(prefix))
.cflags: .force-cflags
@FLAGS='$(TRACK_CFLAGS)'; \
if test x"$$FLAGS" != x"`cat .cflags 2>/dev/null`" ; then \
echo " * rebuilding $(PROJECT): new build flags or prefix"; \
echo "$$FLAGS" > .cflags; \
fi
.PHONY: .force-cflags
endif