Repository navigation
Expand file tree
/
Copy pathGNUmakefile
More file actions
196 lines (150 loc) · 4.02 KB
/
Copy pathGNUmakefile
File metadata and controls
196 lines (150 loc) · 4.02 KB
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#
# 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
ifeq ($(uname_S),OpenBSD)
CC := clang
endif
# Expand to $(1) if $(CC) accepts it, and to nothing otherwise. Some compilers
# only warn about command line flags they don't understand, so -Werror is needed
# to turn that diagnostic into a non-zero exit status.
#
# CFLAGS += $(call cc-option,-fsomething)
cc-option = $(shell $(CC) $(1) -Werror -c -xc /dev/null -o /dev/null >/dev/null 2>&1 && echo '$(1)')
# Expand to -Wno-$(1) if $(CC) knows about the warning -W$(1), and to nothing
# otherwise. The positive form is what gets probed, because compilers commonly
# accept -Wno-whatever for warnings they've never heard of (GCC only mentions
# such a flag if some other diagnostic happens to fire later in the build).
#
# CFLAGS += $(call cc-disable-warning,deprecated-openmp)
cc-disable-warning = $(if $(call cc-option,-W$(1)),-Wno-$(1))
OPENMP_ARG := $(call cc-option,-fopenmp)
ifeq ($(uname_S),OpenBSD)
OPENMP_ARG :=
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 \
$(call cc-disable-warning,deprecated-openmp)
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