comparison seqrequester/src/Makefile @ 1:1085e094cf5f draft

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/microsatbed commit 7ceb6658309a7ababe622b5d92e729e5470e22f0-dirty
author fubar
date Sat, 13 Jul 2024 12:39:06 +0000
parents
children
comparison
equal deleted inserted replaced
0:dd71d3167476 1:1085e094cf5f
1 # -*- Makefile -*-
2 #
3 # boilermake: A reusable, but flexible, boilerplate Makefile.
4 #
5 # Copyright 2008, 2009, 2010 Dan Moulding, Alan T. DeKok
6 #
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20 #
21 # Significantly modified for Marbl projects. Get the original from
22 # https://github.com/dmoulding/boilermake
23 #
24
25 include Makefile.boilermake
26
27 #
28 # Check that Make and git are compatible, fail if not.
29 #
30
31 define TEST_VERSION
32 path := $$(shell which ${1})
33 vers := $$(shell ${1} --version | head -n 1 | cut -d\ -f ${2})
34 versn := $$(shell echo $${vers} | sed -e 's/\.\([0-9][0-9]\)/\1/g' -e 's/\.\([0-9]\)/0\1/g' -e 's/^[0-9]\{3,4\}$$$$/&00/')
35 min := $$(shell echo ${3} | sed -e 's/\.\([0-9][0-9]\)/\1/g' -e 's/\.\([0-9]\)/0\1/g' -e 's/^[0-9]\{3,4\}$$$$/&00/')
36
37 ifeq ($$(shell expr $${versn} \>= $${min}), 0)
38 $$(error '$${path}' version '$${vers}' too old; at least version $3 is required)
39 endif
40 endef
41
42 $(eval $(call TEST_VERSION, git, 3, 2.12))
43 $(eval $(call TEST_VERSION, ${MAKE}, 3, 3.81))
44
45 #
46 # Initialize submodules if they aren't here yet.
47 # - if the submodule directory exists and it is empty, then have
48 # git fetch the submodule (with some fancy logging).
49 #
50
51 define INIT_SUBMODULE
52 ifeq ($$(wildcard ${1}),${1})
53 ifeq ($$(wildcard ${1}/*),)
54 $$(info Fetching submodule '${1}')
55 $$(shell cd $$(dir ${1}) ; git submodule update --init ${2} $$(notdir ${1}) 2>&1 | awk '{ print " - "$$$$0 }' 1>&2)
56 $$(info )
57 endif
58 endif
59 endef
60
61 $(eval $(call INIT_SUBMODULE,utility,))
62 #(eval $(call INIT_SUBMODULE,meryl,))
63 #(eval $(call INIT_SUBMODULE,seqrequester,))
64
65 #
66 # Set compiler and flags based on operating system and compiler toolchain.
67 # This must be called AFTER the compiler is chosen, and after the decision
68 # to include stack trace support is make.
69 #
70 # User-supplied flags are handled:
71 # If a parameter to make ("make CXXFLAGS=whatever"):
72 # flags are used exclusively; no default flags are supplied
73 # If an environment variable ("CXXFLAGS=whatever make"):
74 # flags are appended to the end of the default flags.
75 #
76 # Parameters to the function:
77 # $1 - extra flags for CFLAGS/CXXFLAGS (e.g., -I/path)
78 # $2 - extra flags for LDFLAGS (e.g., -L/path)
79 #
80 # Options:
81 # BUILDOPTIMIZED will disable debug symbols (leaving it just optimized)
82 # BUILDDEBUG will disable optimization (leaving it just with debug symbols)
83 # BUILDSTACKTRACE will enable stack trace on crashes, only works for Linux
84 # set to 0 on command line to disable (it's enabled by default for Linux)
85 #
86 # BUILDPROFILE used to add -pg to LDFLAGS, and remove -D_GLIBCXX_PARALLE from CXXFLAGS and LDFLAGS,
87 # and remove -fomit-frame-pointer from CXXFLAGS. It added a bunch of complication and wasn't
88 # really used.
89 #
90 # BUILDJEMALLOC will enable jemalloc library support.
91 #
92 define SET_DEFAULT_FLAGS
93 CFLAGSUSER := $${CFLAGS}
94 CXXFLAGSUSER := $${CXXFLAGS}
95 LDFLAGSUSER := $${LDFLAGS}
96
97 # Figure out which tool chain we're using and set up initial flags.
98 # - GCC seems to want '-dumpfullversion' instead of '-dumpversion'
99 # to return the full X.Y.Z version number.
100 # - GCC has deprecated c++2a but gcc-9 doesn't know the correct
101 # option c++20.
102
103 ifeq ($$(shell echo `$$(CXX) --version 2>&1 | grep -c clang`), 0)
104 TOOLCHAIN := GNU
105 TOOLCHAINV := $$(shell ${CXX} -dumpfullversion)
106 CFLAGS := -pthread -fopenmp -fPIC -std=c17 ${1}
107 CXXFLAGS := -pthread -fopenmp -fPIC -std=c++2a ${1}
108 LDFLAGS := -pthread -fopenmp ${2} -lm
109 else
110 TOOLCHAIN := LLVM
111 TOOLCHAINV := $$(shell ${CXX} -dumpversion)
112 CFLAGS := -pthread -fopenmp -fPIC -std=c17 ${1}
113 CXXFLAGS := -pthread -fopenmp -fPIC -std=c++20 ${1}
114 LDFLAGS := -pthread -fopenmp ${2} -lm
115 endif
116
117 # Build up our preferred set of flags.
118
119 ifeq ($$(BUILDOPTIMIZED), 1) # Enable debugging and add debug-aware
120 else # optimization unless BUILDOPTIMIZED is set.
121 CXXFLAGS += -Og -g3
122 CFLAGS += -Og -g3
123 endif
124
125 ifeq ($$(BUILDDEBUG), 1) # Add full optimization unless BUILDDEBUG is set.
126 else ifeq ($$(TOOLCHAIN), GNU)
127 CXXFLAGS += -O4 -funroll-loops -finline-functions -fomit-frame-pointer -fexpensive-optimizations
128 CFLAGS += -O4 -funroll-loops -finline-functions -fomit-frame-pointer -fexpensive-optimizations
129 else ifeq ($$(TOOLCHAIN), LLVM)
130 CXXFLAGS += -O3 -funroll-loops -finline-functions -fomit-frame-pointer
131 CFLAGS += -O3 -funroll-loops -finline-functions -fomit-frame-pointer
132 else
133 CXXFLAGS += -O3
134 CFLAGS += -O3
135 endif
136
137 ifeq ($${BUILDSTACKTRACE}, 1) # Add (or disable) stacktrace support.
138 CXXFLAGS += -DLIBBACKTRACE
139 CFLAGS += -DLIBBACKTRACE
140 else
141 CXXFLAGS += -DNOBACKTRACE
142 CFLAGS += -DNOBACKTRACE
143 endif
144
145 ifeq ($$(BUILDJEMALLOC), 1) # Add jemalloc support.
146 CXXFLAGS += -DJEMALLOC -I`jemalloc-config --includedir`
147 LDFLAGS += -L`jemalloc-config --libdir` -Wl,-rpath,`jemalloc-config --libdir` -ljemalloc `jemalloc-config --libs`
148 endif
149
150 ifeq ($$(MACHINETYPE), amd64) # Add SIMD support (htslib and meryl-utility need this)
151 CFLAGS += -mxsave
152 CXXFLAGS += -mxsave
153 endif
154
155 # Enable gobs of warnings, but then disable some of the annoying ones, a
156 # few of which are compiler dependent.
157
158 DEFAULTWARNINGS =
159 #EFAULTWARNINGS += -DMACHINETYPE_${MACHINETYPE}
160 #EFAULTWARNINGS += -pedantic
161 DEFAULTWARNINGS += -Wall -Wextra -Wformat
162 DEFAULTWARNINGS += -Wno-char-subscripts
163 DEFAULTWARNINGS += -Wno-sign-compare
164 DEFAULTWARNINGS += -Wno-unused-function
165 DEFAULTWARNINGS += -Wno-unused-parameter
166 DEFAULTWARNINGS += -Wno-unused-variable
167 DEFAULTWARNINGS += -Wno-deprecated-declarations
168 #EFAULTWARNINGS += -Wno-format -Wno-format-truncation # Disable 'sprintf() into possibly smaller buffer'
169
170 ifeq ($$(TOOLCHAIN), LLVM)
171 CFLAGS += $${DEFAULTWARNINGS} -Wno-format
172 CXXFLAGS += $${DEFAULTWARNINGS} -Wno-format
173 endif
174
175 ifeq ($$(TOOLCHAIN), GNU)
176 CFLAGS += $${DEFAULTWARNINGS} -Wno-format-truncation
177 CXXFLAGS += $${DEFAULTWARNINGS} -Wno-format-truncation
178 endif
179
180 DEFAULTWARNINGS =
181
182 # Append user-supplied flags, if any exist.
183
184 ifneq ($${CFLAGSUSER}, )
185 CFLAGS += $${CFLAGSUSER}
186 endif
187 ifneq ($${CXXFLAGSUSER}, )
188 CXXFLAGS += $${CXXFLAGSUSER}
189 endif
190 ifneq ($${LDFLAGSUSER}, )
191 LDFLAGS += $${LDFLAGSUSER}
192 endif
193 endef
194
195
196 #
197 # Linux config.
198 #
199 ifeq (${OSTYPE}, Linux)
200 CC ?= gcc
201 CXX ?= g++
202
203 BUILDSTACKTRACE ?= 1
204
205 $(eval $(call SET_DEFAULT_FLAGS,,))
206 endif
207
208
209 #
210 # FreeBSD config.
211 #
212 # If building in the FreeBSD ports system, use the architecture as defined
213 # there (technically, -p, not -m) and assume compiler and most options are
214 # already defined correctly.
215 #
216 # We used to (for non-ports builds) default to gcc, mostly because the rpath
217 # was necessary. But clang is working well, and rpath doesn't seem to be
218 # necessary on FreeBSD13.
219 # ifeq ($(origin CXX), default)
220 # CC = gcc9
221 # CXX = g++9
222 # CCLIB = -rpath /usr/local/lib/gcc9
223 # endif
224 #
225 ifeq (${OSTYPE}, FreeBSD)
226 ifeq (${CANU_BUILD_ENV}, ports)
227 MACHINETYPE=${ARCH}
228
229 CXXFLAGS += -pthread -fopenmp -fPIC
230 CFLAGS += -pthread -fopenmp -fPIC
231 LDFLAGS += -pthread -fopenmp -lm
232 else
233 CC ?= cc
234 CXX ?= c++
235
236 BUILDSTACKTRACE ?= 1
237
238 $(eval $(call SET_DEFAULT_FLAGS,,))
239 endif
240 endif
241
242
243 #
244 # MacOS config.
245 #
246 # The default compiler in MacOS _still_ doesn't support OpenMP, so
247 # we try a bunch of common alternate compiler names and use the first
248 # one that exists.
249 #
250 # If from MacPorts: If from homebrew:
251 # port install gcc9 brew install gcc
252 # port select gcc mp-gcc9 brew install llvm
253 #
254 # Homebrew calls its binaries clang and clang++ and uses directories to
255 # differentiate. (While there is clang-16, there is no clang++-16, and we
256 # use clang/clang++ for consistency.)
257 # /opt/homebrew/opt/gcc@11/bin/gcc-12 /opt/homebrew/opt/llvm@16/bin/clang
258 # /opt/homebrew/opt/gcc@11/bin/g++-12 /opt/homebrew/opt/llvm@16/bin/clang++
259 #
260 # MacPorts puts its binaries in the global bin directory with a suffix to
261 # differentiate.
262 # /opt/local/bin/gcc-mp-16 /opt/local/bin/clang-mp-16
263 # /opt/local/bin/g++-mp-16 /opt/local/bin/clang++-mp-16
264 #
265 define FIND_MACOS_COMPILER
266 ifeq ($$(CC), cc)
267 ifneq ($$(wildcard $${BREW}/opt/gcc@${1}/bin/gcc-${1}), )
268 ifneq ($$(wildcard $${BREW}/opt/gcc@${1}/bin/g++-${1}), )
269 #$$(info Detected gcc-${1} installed via Homebrew.)
270 CC=$$(abspath $${BREW}/opt/gcc@${1}/bin/gcc-${1})
271 CXX=$$(abspath $${BREW}/opt/gcc@${1}/bin/g++-${1})
272 endif
273 endif
274 endif
275
276 ifeq ($$(CC), cc)
277 ifneq ($$(wildcard $${BREW}/opt/llvm@${1}/bin/clang), )
278 ifneq ($$(wildcard $${BREW}/opt/llvm@${1}/bin/clang++), )
279 #$$(info Detected llvm-${1} installed via Homebrew.)
280 CC=$$(abspath $${BREW}/opt/llvm@${1}/bin/clang)
281 CXX=$$(abspath $${BREW}/opt/llvm@${1}/bin/clang++)
282 endif
283 endif
284 endif
285
286 ifeq ($$(CC), cc)
287 ifneq ($$(wildcard $${PORT}/bin/gcc-mp-${1}), )
288 ifneq ($$(wildcard $${PORT}/bin/g++-mp-${1}), )
289 #$$(info Detected gcc-${1} installed via MacPorts.)
290 CC=$$(abspath $${PORT}/bin/gcc-mp-${1})
291 CXX=$$(abspath $${PORT}/bin/g++-mp-${1})
292 endif
293 endif
294 endif
295
296 ifeq ($$(CC), cc)
297 ifneq ($$(wildcard $${PORT}/bin/clang-mp-${1}), )
298 ifneq ($$(wildcard $${PORT}/bin/clang++-mp-${1}), )
299 #$$(info Detected llvm-${1} installed via MacPorts.)
300 CC=$$(abspath $${PORT}/bin/clang-mp-${1})
301 CXX=$$(abspath $${PORT}/bin/clang++-mp-${1})
302 endif
303 endif
304 endif
305 endef
306
307 ifeq (${OSTYPE}, Darwin)
308 BREW := $(abspath $(lastword $(shell brew 2>/dev/null config | grep HOMEBREW_PREFIX)))
309 PORT := $(abspath $(dir $(abspath $(dir $(shell which port)))))
310
311 #$(info Detected Homebrew in '${BREW}')
312 #$(info Detected MacPorts in '${PORT}')
313
314 $(eval $(call FIND_MACOS_COMPILER,20))
315 $(eval $(call FIND_MACOS_COMPILER,19))
316 $(eval $(call FIND_MACOS_COMPILER,18))
317 $(eval $(call FIND_MACOS_COMPILER,17))
318 $(eval $(call FIND_MACOS_COMPILER,16))
319 $(eval $(call FIND_MACOS_COMPILER,15))
320 $(eval $(call FIND_MACOS_COMPILER,14))
321 $(eval $(call FIND_MACOS_COMPILER,13))
322 $(eval $(call FIND_MACOS_COMPILER,12))
323 $(eval $(call FIND_MACOS_COMPILER,11))
324 $(eval $(call FIND_MACOS_COMPILER,10))
325 $(eval $(call FIND_MACOS_COMPILER,9))
326 $(eval $(call FIND_MACOS_COMPILER,8))
327
328 $(eval $(call SET_DEFAULT_FLAGS,,))
329 endif
330
331
332 #
333 # Cygwin config.
334 #
335 ifneq (,$(findstring CYGWIN, ${OSTYPE}))
336 CC ?= gcc
337 CXX ?= g++
338
339 $(eval $(call SET_DEFAULT_FLAGS,,))
340 endif
341
342
343 #
344 # Test a small compile.
345 #
346 # This has only failed on MacOS with default compilers that do not support
347 # -fopenmp.
348 #
349 # Note that .SHELLSTATUS was introduced in Make 4.2 but stupid MacOS ships
350 # with make 3.81, so we need to do the success/fail test the hard way. On
351 # the otherhand, this does mean we can clean up temporary files right after.
352 #
353
354 COMPILETEST := $(shell echo "int main(void) { return 0; }" | ${CXX} ${CXXFLAGS} ${LDFLAGS} -x c++ -o /tmp/test-fopenmp - && echo pass ; rm -f /tmp/test-fopenmp /tmp/test-fopenmp.C)
355
356 ifneq ($(COMPILETEST), pass)
357 $(warning )
358 $(warning Unable to compile OpenMP programs with with:)
359 $(warning $_ ${TOOLCHAIN} ${CXX} ${TOOLCHAINV}.)
360 $(warning $_ CXXFLAGS flags:)
361 $(foreach FLAG,${CXXFLAGS},$(warning $_ ${FLAG}))
362 $(warning $_ LDFLAGS flags:)
363 $(foreach FLAG,${LDFLAGS},$(warning $_ ${FLAG}))
364 $(warning Please install GCC or LLVM with OpenMP support and)
365 $(warning specify this compiler on the command line, e.g.,)
366 $(warning $_ make CC=/path/to/gcc CXX=/path/to/g++)
367 $(warning )
368 $(error Unsupported compiler)
369 endif
370
371 #
372 # Define the two exported targets, 'all' and 'clean' as phony rules that
373 # point to the real rules. This is done before including main.mk so that it
374 # can define any weird one-off special-case targets without them becoming the
375 # first (and thus default) rule.
376 #
377 # Then recursively include user-supplied submakefiles.
378 #
379 # Then define the real 'all' and 'clean' targets.
380 #
381 # Targets 'doall' and 'doclean' are used internally to add more targets to
382 # the global build. 'doclean-final' is a trouble maker because it needs to
383 # run after all the other 'doclean' steps, and the only way to ensure that is
384 # to give it a new target.
385 #
386
387 .PHONY: all
388 all: doall
389
390 .PHONY: clean
391 clean: doclean-final
392
393 $(eval $(call INCLUDE_SUBMAKEFILE,main.mk))
394
395 .PHONY: doall
396 doall: $(addprefix ${TARGET_DIR}/,${ALL_TGTS})
397 @echo ""
398 @echo "Success!"
399 @echo "${MODULE} installed in ${TARGET_DIR}/bin/${MODULE}"
400 @echo ""
401
402 .PHONY: doclean-final
403 doclean-final: doclean
404 if [ -d ${TARGET_DIR} ] ; then find ${TARGET_DIR} -type d -print | sort -r | xargs -n 100 rmdir ; fi
405 @echo ""
406 @echo "Cleaned."
407 @echo ""
408
409 .PHONY: doclean
410 doclean:
411
412 #
413 # Let boilermake do its thing.
414 #
415
416 $(eval $(call BOILERMAKE))
417
418 #
419 # Generate a version number. This needs to come AFTER submakefiles are
420 # included (so we know what ${MODULE} is) but before we build anything
421 # (because this generates 'version.H' and also prints information about
422 # submodule versions).
423 #
424 # But, because make helpfully squashes all the lines to a single line we
425 # need to do something funky and write the version information for C++ and
426 # for make to one file - which then is included here and in source files.
427 # Makefile.boilermake adds this file as a dependency to ALL source files.
428 #
429 # For projects that include meryl-utility as a submodule (the usual case)
430 # write version.H in the submodule src/ directory; for meryl-utility itself,
431 # write in the current directory.
432 # - This _should_ be indentifying if the submodule exists in
433 # utility/src, but on the very first build (when the submodules
434 # are initialized above) a file-based detection was reliably failing,
435 # as if `ifeq ($(wildcard utility/src), utility/src)` was tested
436 # before the submodule was init'd. Rather than deal with all
437 # that baloney, we just assume that any build using this build
438 # system is either meryl-utility itself or something that uses it.
439 #
440
441 VERSION_H := $(shell ./${VERSION_H:.H=.pl} ${MODULE} ${VERSION} ${VERSION_H})
442
443 ifeq (${VERSION_H}, )
444 $(error Failed to create version.H, possibly missing the 'meryl-utility' submodule)
445 endif
446
447 include ${VERSION_H}
448
449 #
450 # Log what compiler we're using and start the build.
451 #
452
453 $(info ${BUILDING})
454 $(info For '${OSTYPE}' '${OSVERSION}' as '${MACHINETYPE}' into '${TARGET_DIR}/{bin,obj}'.)
455 $(info Using ${TOOLCHAIN} '$(shell which ${CXX})' version '${TOOLCHAINV}'.)
456 ifneq (${CFLAGSUSER},)
457 $(info Using user-supplied CFLAGS '${CFLAGSUSER}'.)
458 endif
459 ifneq (${CXXFLAGSUSER},)
460 $(info Using user-supplied CXXFLAGS '${CXXFLAGSUSER}'.)
461 endif
462 ifneq (${LDFLAGSUSER},)
463 $(info Using user-supplied LDFLAGS '${LDFLAGSUSER}'.)
464 endif
465 $(info )