forked from icl-utk-edu/testsweeper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGNUmakefile
245 lines (197 loc) · 6.47 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# Copyright (c) 2017-2023, University of Tennessee. All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
# This program is free software: you can redistribute it and/or modify it under
# the terms of the BSD 3-Clause license. See the accompanying LICENSE file.
#
# See INSTALL.md for usage.
#-------------------------------------------------------------------------------
# Configuration
# Variables defined in make.inc, or use make's defaults:
# CXX, CXXFLAGS -- C compiler and flags
# LD, LDFLAGS, LIBS -- Linker, options, library paths, and libraries
# AR, RANLIB -- Archiver, ranlib updates library TOC
# prefix -- where to install TestSweeper
#
# OpenMP is optional; used only for timer and flushing caches.
ifeq ($(MAKECMDGOALS),config)
# For `make config`, don't include make.inc with previous config;
# force re-creating make.inc.
.PHONY: config
config: make.inc
make.inc: force
else ifneq ($(findstring clean,$(MAKECMDGOALS)),clean)
# For `make clean` or `make distclean`, don't include make.inc,
# which could generate it. Otherwise, include make.inc.
include make.inc
endif
python ?= python3
force: ;
make.inc:
${python} configure.py
# Defaults if not given in make.inc. GNU make doesn't have defaults for these.
RANLIB ?= ranlib
prefix ?= /opt/slate
# Default LD=ld won't work; use CXX. Can override in make.inc or environment.
ifeq ($(origin LD),default)
LD = $(CXX)
endif
# auto-detect OS
# $OSTYPE may not be exported from the shell, so echo it
ostype := $(shell echo $${OSTYPE})
ifneq ($(findstring darwin, $(ostype)),)
# MacOS is darwin
macos = 1
endif
#-------------------------------------------------------------------------------
# if shared
ifneq ($(static),1)
CXXFLAGS += -fPIC
LDFLAGS += -fPIC
lib_ext = so
else
lib_ext = a
endif
#-------------------------------------------------------------------------------
# MacOS needs shared library's path set
ifeq ($(macos),1)
install_name = -install_name @rpath/$(notdir $@)
else
install_name =
endif
#-------------------------------------------------------------------------------
# Files
lib_src = testsweeper.cc version.cc
lib_obj = $(addsuffix .o, $(basename $(lib_src)))
dep += $(addsuffix .d, $(basename $(lib_src)))
tester_src = test/test.cc test/test_sort.cc
tester_obj = $(addsuffix .o, $(basename $(tester_src)))
dep += $(addsuffix .d, $(basename $(tester_src)))
tester = test/tester
#-------------------------------------------------------------------------------
# Get Mercurial id, and make version.o depend on it via .id file.
ifneq ($(wildcard .git),)
id := $(shell git rev-parse --short HEAD)
version.o: CXXFLAGS += -DTESTSWEEPER_ID='"$(id)"'
endif
last_id := $(shell [ -e .id ] && cat .id || echo 'NA')
ifneq ($(id),$(last_id))
.id: force
endif
.id:
echo $(id) > .id
version.o: .id
#-------------------------------------------------------------------------------
# TestSweeper specific flags and libraries
# additional flags and libraries for testers
TEST_CXXFLAGS += -I.
TEST_LDFLAGS += -L. -Wl,-rpath,$(abspath .)
TEST_LIBS += -ltestsweeper
$(tester_obj): CXXFLAGS += $(TEST_CXXFLAGS)
#-------------------------------------------------------------------------------
# Rules
.DELETE_ON_ERROR:
.SUFFIXES:
.PHONY: all lib src test tester headers include docs clean distclean
.DEFAULT_GOAL = all
all: lib tester
install: lib
mkdir -p $(DESTDIR)$(prefix)/include
mkdir -p $(DESTDIR)$(prefix)/lib$(LIB_SUFFIX)
cp $(headers) $(DESTDIR)$(prefix)/include
cp $(lib) $(DESTDIR)$(prefix)/lib$(LIB_SUFFIX)
uninstall:
$(RM) $(addprefix $(DESTDIR)$(prefix)/include/, $(headers))
$(RM) $(DESTDIR)$(prefix)/lib$(LIB_SUFFIX)/libtestsweeper.*
#-------------------------------------------------------------------------------
# if re-configured, recompile everything
$(lib_obj) $(tester_obj): make.inc
#-------------------------------------------------------------------------------
# TestSweeper library
lib_a = libtestsweeper.a
lib_so = libtestsweeper.so
lib = libtestsweeper.$(lib_ext)
$(lib_so): $(lib_obj)
$(LD) $(LDFLAGS) -shared $(install_name) $(lib_obj) $(LIBS) -o $@
$(lib_a): $(lib_obj)
$(RM) $@
$(AR) cr $@ $(lib_obj)
$(RANLIB) $@
lib: $(lib)
#-------------------------------------------------------------------------------
# tester
$(tester): $(tester_obj) $(lib)
$(LD) $(TEST_LDFLAGS) $(LDFLAGS) $(tester_obj) \
$(TEST_LIBS) $(LIBS) -o $@
# sub-directory rules
test: $(tester)
tester: $(tester)
check:
cd test; ${python} run_tests.py
#-------------------------------------------------------------------------------
# headers
# precompile headers to verify self-sufficiency
headers = testsweeper.hh
headers_gch = $(addsuffix .gch, $(basename $(headers)))
headers: $(headers_gch)
headers/clean:
$(RM) $(headers_gch)
#-------------------------------------------------------------------------------
# documentation
docs:
@echo "Doxygen not yet implemented."
docs-todo:
doxygen docs/doxygen/doxyfile.conf
@echo ========================================
cat docs/doxygen/errors.txt
@echo ========================================
@echo "Documentation available in docs/html/index.html"
@echo ========================================
#-------------------------------------------------------------------------------
# general rules
clean:
$(RM) $(lib_a) $(lib_so) $(lib_obj) $(tester_obj) $(dep) $(headers_gch) $(tester)
distclean: clean
$(RM) make.inc
%.o: %.cc
$(CXX) $(CXXFLAGS) -c $< -o $@
# preprocess source
%.i: %.cc
$(CXX) $(CXXFLAGS) -E $< -o $@
# precompile header to check for errors
%.gch: %.h
$(CXX) $(CXXFLAGS) -c $< -o $@
%.gch: %.hh
$(CXX) $(CXXFLAGS) -c $< -o $@
-include $(dep)
#-------------------------------------------------------------------------------
# debugging
echo:
@echo "static = '$(static)'"
@echo "id = '$(id)'"
@echo "last_id = '$(last_id)'"
@echo
@echo "lib_a = $(lib_a)"
@echo "lib_so = $(lib_so)"
@echo "lib = $(lib)"
@echo
@echo "lib_src = $(lib_src)"
@echo
@echo "lib_obj = $(lib_obj)"
@echo
@echo "tester_src = $(tester_src)"
@echo
@echo "tester_obj = $(tester_obj)"
@echo
@echo "tester = $(tester)"
@echo
@echo "dep = $(dep)"
@echo
@echo "CXX = $(CXX)"
@echo "CXXFLAGS = $(CXXFLAGS)"
@echo
@echo "LD = $(LD)"
@echo "LDFLAGS = $(LDFLAGS)"
@echo "LIBS = $(LIBS)"
@echo
@echo "TEST_LDFLAGS = $(TEST_LDFLAGS)"
@echo "TEST_LIBS = $(TEST_LIBS)"