comparison seqrequester/src/Makefile.boilermake @ 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
26 #
27 # Set paths for building and installing. If DESTDIR is defined,
28 # use that, otherwise, use the directory just above us.
29 #
30 # We used to use "OSTYPE-MACHINETYPE" instead of "build" to allow
31 # multi-platform builds. We now make the user set DESTDIR for that
32 # functionality. The three variables are now just diagnostic info with some
33 # historical baggage (but even more was removed, like "Power Macintosh"
34 # detection).
35 #
36 ifeq "$(strip ${DESTDIR})" ""
37 BUILD_DIR := $(realpath ..)/build/obj
38 TARGET_DIR := $(realpath ..)/build
39 else
40 BUILD_DIR := $(DESTDIR)/build/obj
41 TARGET_DIR := $(DESTDIR)/build
42 endif
43
44 OSTYPE := $(shell echo `uname`)
45 OSVERSION := $(shell echo `uname -r`))
46 MACHINETYPE := $(subst x86_64,amd64,$(shell echo `uname -m`))
47
48 #
49 # Define the source file extensions that we know how to handle.
50 #
51 C_SRC_EXTS := %.c
52 CXX_SRC_EXTS := %.C %.cc %.cp %.cpp %.CPP %.cxx %.c++
53 JAVA_EXTS := %.jar %.tar
54 ALL_SRC_EXTS := ${C_SRC_EXTS} ${CXX_SRC_EXTS} ${JAVA_EXTS}
55
56 #
57 # Initialize internal variables.
58 #
59 ALL_TGTS :=
60 DIR_STACK :=
61 TGT_STACK :=
62
63 ########################################
64 #
65 # The single entry point to create all the targets and rules and everything.
66 #
67 # $(eval $(call BOILERMAKE))
68 #
69 ########################################
70
71 define BOILERMAKE
72
73 # Add a new target rule for each user-defined target.
74 $(foreach TGT,${ALL_TGTS},\
75 $(eval $(call ADD_TARGET_RULE,${TGT})))
76
77 # Add pattern rule(s) for creating compiled object code from C source.
78 $(foreach TGT,${ALL_TGTS},\
79 $(foreach EXT,${C_SRC_EXTS},\
80 $(eval $(call ADD_OBJECT_RULE,${BUILD_DIR}/$(call CANONICAL_PATH,${TGT}),\
81 ${EXT},$${COMPILE_C_CMDS}))))
82
83 # Add pattern rule(s) for creating compiled object code from C++ source.
84 $(foreach TGT,${ALL_TGTS},\
85 $(foreach EXT,${CXX_SRC_EXTS},\
86 $(eval $(call ADD_OBJECT_RULE,${BUILD_DIR}/$(call CANONICAL_PATH,${TGT}),\
87 ${EXT},$${COMPILE_CXX_CMDS}))))
88
89 # Add "clean" rules to remove all build-generated files.
90 $(foreach TGT,${ALL_TGTS},\
91 $(eval $(call ADD_CLEAN_RULE,${TGT})))
92
93 # Include generated rules that define additional (header) dependencies
94 # (but don't complain if that file doesn't exist).
95 $(foreach TGT,${ALL_TGTS},\
96 $(eval -include ${${TGT}_DEPS}))
97
98 # Define more targets to copy files to the target directory.
99 $(call ADD_FILE_COPY_RULES,${EXECUTABLES},executable)
100 $(call ADD_FILE_COPY_RULES,${FILES},)
101 endef
102
103
104 ############################################################
105 #
106 # boilermake internal functions below.
107 #
108 ############################################################
109
110 #
111 # Adds a new rule and phony target for cleaning the specified target
112 # (removing its build-generated files). Use with EVAL.
113 #
114 define ADD_CLEAN_RULE
115 doclean: doclean-${1}
116 .PHONY: doclean-${1}
117 doclean-${1}:
118 $$(strip rm -f ${TARGET_DIR}/${1} $${${1}_OBJS:%.o=%.[doP]})
119 $${${1}_POSTCLEAN}
120 endef
121
122 # ADD_FILE_COPY_RULES adds rules to copy source files directly to the
123 # TARGET_DIR and optionally make them executable. A rule to remove the
124 # copied file (on 'make clean') is also added. It expects a list of files
125 # to copy and their destination:
126 #
127 # EXECUTABLES += scripts/a -> bin/b # These go in main.mk
128 #
129 # FILES += scripts/module/c -> lib/site_perl/module/d \
130 # data/e -> share/data/f
131 #
132 # $(call ADD_FILE_COPY_RULES,${EXECS},) # These go in Makefile!
133 # $(call ADD_FILE_COPY_RULES,${FILES},)
134 #
135 # Source locations are relative to the submakefile location, and destination
136 # locations are relative to TARGET_DIR (e.g., 'build/'. Destination
137 # directories are created if needed.
138 #
139 # If the second parameter is the "executable", then the copied file is made
140 # executable.
141 #
142 # ADD_FILE_COPY_RULE does the work of adding the rules, copying the first
143 # parameter to the second parameter and setting +x if the third parameter is
144 # "executable".
145 #
146 # MAKE_FILE_COPY_LIST strips whitespace from around the 'file copy' operator
147 # '->' in the user-supplied file-copy-list. It works by first squashing
148 # adjacent white space to a single space, then replacing adjacent whitespace
149 # with nothing.
150 #
151 # (The $\ at the end of some of these lines serve to eat up whitespace
152 # before the continued line.)
153 #
154 define MAKE_FILE_COPY_LIST
155 $(subst $ ->$ ,->,$\
156 $(subst $ -> $ ,->,$\
157 $(strip ${1})))
158 endef
159
160 define ADD_FILE_COPY_RULE
161 doall: $${TARGET_DIR}/$2
162 ifeq ($3,executable)
163 $${TARGET_DIR}/$2: $1
164 @mkdir -p $$(dir $${TARGET_DIR}/$2)
165 cp -pf $1 $${TARGET_DIR}/$2
166 chmod +x $${TARGET_DIR}/$2
167 else
168 $${TARGET_DIR}/$2: $1
169 @mkdir -p $$(dir $${TARGET_DIR}/$2)
170 cp -pf $1 $${TARGET_DIR}/$2
171 endif
172 doclean: doclean-$1
173 .PHONY: doclean-$1
174 doclean-$1:
175 rm -f $${TARGET_DIR}/$2
176 endef
177
178 define ADD_FILE_COPY_RULES
179 $(foreach R,$(call MAKE_FILE_COPY_LIST,$1),\
180 $(eval $(call ADD_FILE_COPY_RULE,$(firstword $(subst ->, ,${R})),$\
181 $(lastword $(subst ->, ,${R})),$2)))
182 endef
183
184 # Adds a pattern rule for building object files from source files with the
185 # filename extension specified in the second argument. The first argument
186 # must be the name of the base directory where the object files should
187 # reside (such that the portion of the path after the base directory will
188 # match the path to corresponding source files). The third argument must
189 # contain the rules used to compile the source files into object code form.
190 # Use with EVAL.
191 #
192 define ADD_OBJECT_RULE
193 ${1}/%.o: ${2} ${VERSION_H}
194 ${3}
195 endef
196
197 # Adds a new target to the Makefile. Targets are executable files unless
198 # they end with '.a'. Use with EVAL.
199 #
200 define ADD_TARGET_RULE
201 ifeq "$$(suffix ${1})" ".a"
202 # Add a target for creating a static library.
203 $${TARGET_DIR}/${1}: $${${1}_OBJS}
204 @mkdir -p $$(dir $$@)
205 $$(strip $${AR} $${ARFLAGS} $$@ $${${1}_OBJS})
206 $${${1}_POSTMAKE}
207 else
208 # Add a target for linking an executable. First, attempt to select the
209 # appropriate front-end to use for linking. This might not choose the
210 # right one (e.g. if linking with a C++ static library, but all other
211 # sources are C sources), so the user makefile is allowed to specify a
212 # linker to be used for each target.
213 ifeq "$$(strip $${${1}_LINKER})" ""
214 # No linker was explicitly specified to be used for this target. If
215 # there are any C++ sources for this target, use the C++ compiler.
216 # For all other targets, default to using the C compiler.
217 ifneq "$$(strip $$(filter $${CXX_SRC_EXTS},$${${1}_SOURCES}))" ""
218 ${1}_LINKER = $${CXX}
219 else
220 ${1}_LINKER = $${CC}
221 endif
222 endif
223
224 $${TARGET_DIR}/${1}: $${${1}_OBJS} $${${1}_PREREQS}
225 @mkdir -p $$(dir $$@)
226 $$(strip $${${1}_LINKER} -o $$@ $${LDFLAGS} $${${1}_LDFLAGS} $${${1}_OBJS} $${${1}_LDLIBS} $${LDLIBS})
227 $${${1}_POSTMAKE}
228 endif
229 endef
230
231 # COMPILE_C_CMDS - Commands for compiling C source code.
232 define COMPILE_C_CMDS
233 @mkdir -p $(dir $@)
234 $(strip ${CC} -o $@ -c -MD ${CFLAGS} ${SRC_CFLAGS} ${SRC_INCDIRS} ${SYS_INCDIRS} ${SRC_DEFS} $<)
235 @cp ${@:%$(suffix $@)=%.d} ${@:%$(suffix $@)=%.P}; \
236 sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
237 -e '/^$$/ d' -e 's/$$/ :/' < ${@:%$(suffix $@)=%.d} \
238 >> ${@:%$(suffix $@)=%.P}; \
239 rm -f ${@:%$(suffix $@)=%.d}
240 endef
241
242 # COMPILE_CXX_CMDS - Commands for compiling C++ source code.
243 define COMPILE_CXX_CMDS
244 @mkdir -p $(dir $@)
245 $(strip ${CXX} -o $@ -c -MD ${CXXFLAGS} ${SRC_CXXFLAGS} ${SRC_INCDIRS} ${SYS_INCDIRS} ${SRC_DEFS} $<)
246 @cp ${@:%$(suffix $@)=%.d} ${@:%$(suffix $@)=%.P}; \
247 sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
248 -e '/^$$/ d' -e 's/$$/ :/' < ${@:%$(suffix $@)=%.d} \
249 >> ${@:%$(suffix $@)=%.P}; \
250 rm -f ${@:%$(suffix $@)=%.d}
251 endef
252
253 # INCLUDE_SUBMAKEFILE - Parameterized "function" that includes a new
254 # "submakefile" fragment into the overall Makefile. It also recursively
255 # includes all submakefiles of the specified submakefile fragment.
256 #
257 # USE WITH EVAL
258 #
259 define INCLUDE_SUBMAKEFILE
260 # Initialize all variables that can be defined by a makefile fragment, then
261 # include the specified makefile fragment.
262 TARGET :=
263 TGT_LDFLAGS :=
264 TGT_LDLIBS :=
265 TGT_LINKER :=
266 TGT_PREREQS :=
267
268 SOURCES :=
269 SRC_CFLAGS :=
270 SRC_CXXFLAGS :=
271 SRC_DEFS :=
272 SRC_INCDIRS :=
273
274 SYS_INCDIRS :=
275
276 SUBMAKEFILES :=
277
278 # A directory stack is maintained so that the correct paths are used as we
279 # recursively include all submakefiles. Get the makefile's directory and
280 # push it onto the stack.
281 DIR := $(call CANONICAL_PATH,$(dir ${1}))
282 DIR_STACK := $$(call PUSH,$${DIR_STACK},$${DIR})
283
284 include ${1}
285
286 # Initialize internal local variables.
287 OBJS :=
288
289 # Determine which target this makefile's variables apply to. A stack is
290 # used to keep track of which target is the "current" target as we
291 # recursively include other submakefiles.
292 ifneq "$$(strip $${TARGET})" ""
293 # This makefile defined a new target. Target variables defined by this
294 # makefile apply to this new target. Initialize the target's variables.
295
296 ifeq "$$(suffix $${TARGET})" ".a"
297 TGT := $$(addprefix lib/, $$(strip $${TARGET}))
298 else
299 TGT := $$(addprefix bin/, $$(strip $${TARGET}))
300 endif
301 ALL_TGTS += $${TGT}
302 $${TGT}_DEPS :=
303 $${TGT}_LDFLAGS := $${TGT_LDFLAGS}
304 $${TGT}_LDLIBS := $${TGT_LDLIBS}
305 $${TGT}_LINKER := $${TGT_LINKER}
306 $${TGT}_OBJS :=
307 $${TGT}_PREREQS := $$(addprefix $${TARGET_DIR}/lib/,$${TGT_PREREQS})
308 else
309 # The values defined by this makefile apply to the the "current" target
310 # as determined by which target is at the top of the stack.
311 TGT := $$(strip $$(call PEEK,$${TGT_STACK}))
312 $${TGT}_LDFLAGS += $${TGT_LDFLAGS}
313 $${TGT}_LDLIBS += $${TGT_LDLIBS}
314 $${TGT}_PREREQS += $${TGT_PREREQS}
315 endif
316
317 # Push the current target onto the target stack.
318 TGT_STACK := $$(call PUSH,$${TGT_STACK},$${TGT})
319
320 ifneq "$$(strip $${SOURCES})" ""
321 # This makefile builds one or more objects from source. Validate the
322 # specified sources against the supported source file types.
323 BAD_SRCS := $$(strip $$(filter-out $${ALL_SRC_EXTS},$${SOURCES}))
324 ifneq "$${BAD_SRCS}" ""
325 $$(error Unsupported source file(s) found in ${1} [$${BAD_SRCS}])
326 endif
327
328 # Qualify and canonicalize paths.
329 SOURCES := $$(call QUALIFY_PATH,$${DIR},$${SOURCES})
330 SOURCES := $$(call CANONICAL_PATH,$${SOURCES})
331 SRC_INCDIRS := $$(call QUALIFY_PATH,$${DIR},$${SRC_INCDIRS})
332 SRC_INCDIRS := $$(call CANONICAL_PATH,$${SRC_INCDIRS})
333 SYS_INCDIRS := $$(call QUALIFY_PATH,$${DIR},$${SYS_INCDIRS})
334 SYS_INCDIRS := $$(call CANONICAL_PATH,$${SYS_INCDIRS})
335
336 # Save the list of source files for this target.
337 $${TGT}_SOURCES += $${SOURCES}
338
339 # Convert the source file names to their corresponding object file
340 # names.
341 OBJS := $$(addprefix $${BUILD_DIR}/$$(call CANONICAL_PATH,$${TGT})/,\
342 $$(addsuffix .o,$$(basename $${SOURCES})))
343
344 # Add the objects to the current target's list of objects, and create
345 # target-specific variables for the objects based on any source
346 # variables that were defined.
347 $${TGT}_OBJS += $${OBJS}
348 $${TGT}_DEPS += $${OBJS:%.o=%.P}
349 $${OBJS}: SRC_CFLAGS := $${SRC_CFLAGS}
350 $${OBJS}: SRC_CXXFLAGS := $${SRC_CXXFLAGS}
351 $${OBJS}: SRC_DEFS := $$(addprefix -D,$${SRC_DEFS})
352 $${OBJS}: SRC_INCDIRS := $$(addprefix -iquote,$${SRC_INCDIRS})
353 $${OBJS}: SYS_INCDIRS := $$(addprefix -isystem,$${SYS_INCDIRS})
354 endif
355
356 ifneq "$$(strip $${SUBMAKEFILES})" ""
357 # This makefile has submakefiles. Recursively include them.
358 $$(foreach MK,$${SUBMAKEFILES},\
359 $$(eval $$(call INCLUDE_SUBMAKEFILE,\
360 $$(call CANONICAL_PATH,\
361 $$(call QUALIFY_PATH,$${DIR},$${MK})))))
362 endif
363
364 # Reset the "current" target to it's previous value.
365 TGT_STACK := $$(call POP,$${TGT_STACK})
366 TGT := $$(call PEEK,$${TGT_STACK})
367
368 # Reset the "current" directory to it's previous value.
369 DIR_STACK := $$(call POP,$${DIR_STACK})
370 DIR := $$(call PEEK,$${DIR_STACK})
371 endef
372
373
374 # MIN - Parameterized "function" that results in the minimum lexical value of
375 # the two values given.
376 #define MIN
377 #$(firstword $(sort ${1} ${2}))
378 #endef
379
380 # PEEK - Parameterized "function" that results in the value at the top of the
381 # specified colon-delimited stack.
382 define PEEK
383 $(lastword $(subst :, ,${1}))
384 endef
385
386 # POP - Parameterized "function" that pops the top value off of the specified
387 # colon-delimited stack, and results in the new value of the stack. Note that
388 # the popped value cannot be obtained using this function; use peek for that.
389 define POP
390 ${1:%:$(lastword $(subst :, ,${1}))=%}
391 endef
392
393 # PUSH - Parameterized "function" that pushes a value onto the specified colon-
394 # delimited stack, and results in the new value of the stack.
395 define PUSH
396 ${2:%=${1}:%}
397 endef
398
399 # CANONICAL_PATH - Given one or more paths, converts the paths to the canonical
400 # form. The canonical form is the path, relative to the project's top-level
401 # directory (the directory from which "make" is run), and without
402 # any "./" or "../" sequences. For paths that are not located below the
403 # top-level directory, the canonical form is the absolute path (i.e. from
404 # the root of the filesystem) also without "./" or "../" sequences.
405 define CANONICAL_PATH
406 $(patsubst ${CURDIR}/%,%,$(abspath ${1}))
407 endef
408
409 # QUALIFY_PATH - Given a "root" directory and one or more paths, qualifies the
410 # paths using the "root" directory (i.e. appends the root directory name to
411 # the paths) except for paths that are absolute.
412 define QUALIFY_PATH
413 $(addprefix ${1}/,$(filter-out /%,${2})) $(filter /%,${2})
414 endef