1## Filename    : makefile-common-actions.mk
2## Description : Makefile include file containing common actions
3## Author(s)   : SBML Team <sbml-team@googlegroups.com>
4## Organization: California Institute of Technology
5## Created     : 2004-06-17
6##
7##<!---------------------------------------------------------------------------
8## This file is part of libSBML.  Please visit http://sbml.org for more
9## information about SBML, and the latest version of libSBML.
10##
11## Copyright (C) 2013-2018 jointly by the following organizations:
12##     1. California Institute of Technology, Pasadena, CA, USA
13##     2. EMBL European Bioinformatics Institute (EMBL-EBI), Hinxton, UK
14##     3. University of Heidelberg, Heidelberg, Germany
15##
16## Copyright (C) 2009-2013 jointly by the following organizations:
17##     1. California Institute of Technology, Pasadena, CA, USA
18##     2. EMBL European Bioinformatics Institute (EMBL-EBI), Hinxton, UK
19##
20## Copyright (C) 2006-2008 by the California Institute of Technology,
21##     Pasadena, CA, USA
22##
23## Copyright (C) 2002-2005 jointly by the following organizations:
24##     1. California Institute of Technology, Pasadena, CA, USA
25##     2. Japan Science and Technology Agency, Japan
26##
27## This library is free software; you can redistribute it and/or modify it
28## under the terms of the GNU Lesser General Public License as published by
29## the Free Software Foundation.  A copy of the license agreement is provided
30## in the file named "LICENSE.txt" included with this software distribution
31## and also available online as http://sbml.org/software/libsbml/license.html
32##----------------------------------------------------------------------- -->*/
33
34# General explanations:
35#
36# The rules in this file are meant to be generic and included in other
37# makefiles.  This file is meant to be included last by other makefiles.
38#
39# As a general rule, variables with names in all lower-case letters (such
40# as `cxxcompile') are assumed to be defined by the enclosing makefile,
41# while those in all upper-case letters (such as `TOP_SRCDIR') are assumed
42# to be defined in `makefile-common-vars.mk' which in turn must be included
43# by the enclosing makefile.
44
45
46# -----------------------------------------------------------------------------
47# Common compilation rules for object files and libraries.
48# -----------------------------------------------------------------------------
49
50.SUFFIXES:
51.SUFFIXES: .a .so .dylib .jnilib .c .h .cpp .hpp .cs .o .lo .la .obj .Po .py .pyc .pyo .i .bundle .rb .t
52
53# The following define default values of variables like `cxxcompile'.  An
54# enclosing makefile can define other values, in which case those
55# definitions will override what's given here.
56
57top_include := $(TOP_SRCDIR)/src
58top_src     := $(TOP_SRCDIR)/src
59
60default_includes ?= -I. -I$(top_include)
61
62# Compiling under cygwin and Sun cc doesn't need -fPIC.
63
64ifneq "$(HOST_TYPE)" "cygwin"
65  ifndef USE_SUN_CC
66    FPIC = -fPIC
67  endif
68endif
69
70# Compiling under Sun cc must not use -Wall.
71
72ifndef USE_SUN_CC
73  WALL = -Wall
74endif
75
76# Here follow the generic compilation commands.  (Note: the use of 'sort'
77# here is only to remove duplicates, which the 'sort' function does as a
78# documented side-effect.)
79
80compile ?= $(LIBTOOL) --mode=compile --tag=CC $(CC) $(sort $(default_includes) $(INCLUDES)) $(CPPFLAGS) \
81        $(extra_CPPFLAGS) $(CFLAGS) $(extra_CFLAGS)
82
83cxxcompile ?= $(LIBTOOL) --mode=compile --tag=CXX $(CXX) $(sort $(default_includes) $(INCLUDES)) \
84        $(CPPFLAGS) $(extra_CPPFLAGS) $(CXXFLAGS) $(extra_CXXFLAGS)
85
86# The following two commands are used for dependency tracking only when
87# building universal binaries on MacOSX.
88
89compile_nocflags ?= $(CC) $(sort $(default_includes) $(INCLUDES)) \
90        $(CPPFLAGS) $(extra_CPPFLAGS)
91
92cxxcompile_nocxxflags ?= $(CXX) $(sort $(default_includes) $(INCLUDES)) \
93        $(CPPFLAGS) $(extra_CPPFLAGS) \
94
95# For linking libraries, we try to follow the result of the libtool
96# numbering scheme, but at the final end, not in the input format.  (The
97# libtool input format is peculiar to us.)  Curious, this makes the
98# numbering very easy: it's a direct mapping of the libsbml version number.
99
100library_version = $(shell echo $(PACKAGE_VERSION) | sed -e 's/\-.*//g' -e 's/[a-zA-Z]//g' )
101library_major_version = $(word 1, $(subst ., ,$(library_version)))
102library_minor_version = $(word 2, $(subst ., ,$(library_version)))
103library_patch_version = $(word 3, $(subst ., ,$(library_version)))
104
105# `platform_link_flags' is used below in the definition of link_shared_lib.
106# Generally, gcc and ld need -shared, but some systems think different.
107
108ifeq "$(HOST_TYPE)" "darwin"
109  # MacOS X's normal libraries have the extension .dylib, and "bundles"
110  # have .so.  The default shared library definition here builds .dylib.
111  platform_link_flags ?= -dynamiclib -flat_namespace \
112	-current_version $(library_version)
113
114  #
115  # -M options are not allowed with multiple -arch flags.
116  #
117  match = $(shell echo $(compile) | grep '\-arch.*\-arch.*')
118  ifneq "$(match)" ""
119    USE_UNIVBINARY = 1
120  endif
121
122  match = $(shell echo $(cxxcompile) | grep '\-arch.*\-arch.*')
123  ifneq "$(match)" ""
124    USE_UNIVBINARY = 1
125  endif
126else
127  #
128  # -no-undefined option is required to generate a *.dll file
129  # by using libtool on Cygwin
130  #
131  ifeq "$(HOST_TYPE)" "cygwin"
132    platform_link_flags ?= -no-undefined
133  else
134    ifeq "$(HOST_TYPE)" "aix5.3.0.0"
135      platform_link_flags ?= -G
136    else
137      ifdef USE_SUN_CC
138        platform_link_flags ?= -G
139      else
140        platform_link_flags ?= -shared
141      endif
142    endif
143  endif
144endif
145
146
147# The following defines the default function for linking objects into a
148# shared library. It gets used thus: $(call link_shared_lib,ARGS...).  The
149# forms $(1), $(2) in the expressions below, etc. are the arguments passed
150# to the call.  An enclosing makefile can provide another definition, in
151# which case, the definition below will not be used.
152
153#    -version-info $(subst .,:,$(library_version)) \
154
155ifndef link_shared_lib
156  define link_shared_lib
157    $(LIBTOOL) --mode=link $(CXX) $(extra_LDFLAGS) $(LDFLAGS) \
158    -version-info \
159    `expr $(library_major_version) \+ $(library_minor_version)`:$(library_patch_version):$(library_minor_version) \
160    -inst-prefix-dir "$(DESTDIR)" \
161    $(platform_link_flags) -rpath $(LIBDIR) -o $(1) $(objfiles:.o=.lo) \
162    $(extra_LIBS) $(LIBS)
163  endef
164endif
165
166ifndef link_dl_lib
167  define link_dl_lib
168    $(TOP_SRCDIR)/config/lt_link_helper.sh $(CXX) --libdir $(LIBDIR) \
169    $(LDFLAGS) $(extra_LDFLAGS) $(platform_link_flags) \
170    -o $(1) $(objfiles:.o=.lo) $(extra_LIBS) $(LIBS)
171  endef
172endif
173
174# The following defines the default function for linking objects into a
175# static library. It gets used thus: $(call link_static_lib,ARGS...).  The
176# forms $(1), $(2) in the expressions below, etc. are the arguments passed
177# to the call.  An enclosing makefile can provide another definition, in
178# which case the definition below will not be used.
179
180ifdef USE_SUN_CC
181  define link_static_lib
182    -rm -f $(1)
183   $(CXX) -xar -o $(1) $(objfiles)
184  endef
185else
186  define link_static_lib
187    -rm -f $(1)
188    $(AR) -cru $(1) $(objfiles)
189    $(RANLIB) $(1)
190  endef
191endif
192
193# Most of the sources are a mix of C and C++ files.  They have separate
194# extensions, and simply using something like $(sources:.cpp=.o) doesn't
195# work for converting the source file names into object file names because
196# you have to do it twice (once each for .cpp and .c) and then you have to
197# filter the results.  This abstracts out this common operation.
198
199make_objects_list = \
200  $(filter %.lo,\
201    $(patsubst %.cpp,%.lo,$(1)) $(patsubst %.c,%.lo,$(1)))
202
203# The following generate the list of object file names and dependency file
204# names from the list of source files.  They're used for the generic
205# compilation rules further below.
206
207tmplist  ?= $(sources:.cpp=.lo) $(sources:.c=.lo)
208objfiles ?= $(filter %.lo,$(tmplist))
209
210# This next line includes the dependency files.  This uses a wildcard on
211# the actual files, so that if they don't exist yet, `make' won't generate
212# errors about being unable to include such-and-such file.  If the files
213# are missing, the wildcard will expand to nothing.  The /dev/null at the
214# end makes sure that we don't have an empty `include' line.
215
216include $(wildcard $(DEPDIR)/*.$(DEPEXT)) /dev/null
217
218# The next set of rules are generic for creating .a, .so, and other styles
219# of static and shared library files.
220
221ifneq "$(HOST_TYPE)" "aix"
222# Both shared and static libraries in AIX have the same extension (.a).
223# We have to choose what's built.  Shared is more likely to be preferred,
224# so we leave out this rule for static libraries when building under AIX.
225
226%.a ../%.a: $(objfiles)
227	$(call link_static_lib,$@)
228
229endif
230
231%.la ../%.la: $(objfiles)
232	$(call link_shared_lib,$@)
233
234%.$(SHAREDLIBEXT) ../%.$(SHAREDLIBEXT): $(objfiles)
235	$(call link_dl_lib,$@)
236
237%.$(JNIEXT) ../%.$(JNIEXT): $(objfiles)
238	$(call link_dl_lib,$@)
239
240#
241# -install_name option should be used when building an universal binary on MacOSX.
242#
243#%.$(SHAREDLIBEXT) ../%.$(SHAREDLIBEXT): $(objfiles)
244#ifeq "$(HOST_TYPE)" "darwin"
245#	$(call link_shared_lib,$@ -install_name $@)
246#else
247#	$(call link_shared_lib,$@)
248#endif
249
250# The following define generic rules for creating object files.
251
252ifeq "$(HOST_TYPE)" "aix"
253
254.c.lo:
255	$(compile) -c -o $@ $<
256
257.c.obj:
258	if $(compile) -c -o $@ \
259	  `if test -f '$<'; then $(CYGPATH_W) '$<'; else $(CYGPATH_W) '$(srcdir)/$<'; fi`; \
260	then mv "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.$(DEPEXT)"; \
261	else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; \
262	fi
263
264.cpp.lo .cxx.lo:
265	$(cxxcompile) -c -o $@ $<
266
267.cpp.obj:
268	if $(cxxcompile) -c -o $@ \
269	  `if test -f '$<'; then $(CYGPATH_W) '$<'; else $(CYGPATH_W) '$(srcdir)/$<'; fi`; \
270	then mv "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.$(DEPEXT)"; \
271	else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; \
272	fi
273
274else
275# All hosts types that are not aix.
276
277.c.lo:
278ifndef USE_UNIVBINARY
279  ifdef USE_SUN_CC
280	$(compile) -c -o $@ $<
281  else
282	$(compile) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.$(DEPEXT)" -c -o $@ $<
283  endif
284else
285	$(compile_nocflags) -MT $@ -MM -MP -MF "$(DEPDIR)/$*.$(DEPEXT)" $<
286	$(compile) -c -o $@ $<
287endif
288
289.c.obj:
290	if $(compile) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" \
291	  -c -o $@ `if test -f '$<'; then $(CYGPATH_W) '$<'; else $(CYGPATH_W) '$(srcdir)/$<'; fi`; \
292	then mv "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.$(DEPEXT)"; \
293	else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; \
294	fi
295
296.cpp.lo .cxx.lo:
297ifndef USE_UNIVBINARY
298  ifdef USE_SUN_CC
299	$(cxxcompile) -c -o $@ $<
300  else
301	$(cxxcompile) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.$(DEPEXT)" -c -o $@ $<
302  endif
303else
304	$(cxxcompile_nocxxflags) -MT $@ -MM -MP -MF "$(DEPDIR)/$*.$(DEPEXT)" $<
305	$(cxxcompile) -c -o $@ $<
306endif
307
308.cpp.obj:
309	if $(cxxcompile) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" \
310	  -c -o $@ `if test -f '$<'; then $(CYGPATH_W) '$<'; else $(CYGPATH_W) '$(srcdir)/$<'; fi`; \
311	then mv "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.$(DEPEXT)"; \
312	else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; \
313	fi
314
315endif
316
317ifeq "$(HOST_TYPE)" "darwin"
318
319%.bundle ../%.bundle: $(objfiles)
320	$(call link_dl_lib,$@)
321
322endif
323
324# This next line ensures that the object output directory is created first.
325# Got this from a posting by Paul D. Smith to gnu.utils.help, 2001-12-03.
326
327__dummy := $(shell [ -d $(DEPDIR) ] || mkdir $(DEPDIR))
328
329
330# -----------------------------------------------------------------------------
331# Generic default.
332# -----------------------------------------------------------------------------
333
334default: $(objfiles) $(test_objfiles) $(libraries)
335
336
337# -----------------------------------------------------------------------------
338# Generic recursive targets.
339# -----------------------------------------------------------------------------
340
341recursive_targets = all-recursive include-recursive install-data-recursive \
342	install-exec-recursive installdirs-recursive install-recursive \
343	uninstall-recursive uninstall-info-recursive install-info-recursive \
344	ps-recursive info-recursive dvi-recursive pdf-recursive \
345	check-recursive installcheck-recursive mostlyclean-recursive \
346	clean-recursive distclean-recursive maintainer-clean-recursive \
347	install-man-recursive tags-recursive etags-recursive ctags-recursive \
348	docs-recursive install-docs-recursive \
349	dist-recursive distcheck-recursive
350
351# Always want -w in the flags passed to recursive makes, so that it prints
352# the current directory at each step.
353
354ifeq "$(findstring $(MAKEFLAGS),-w)" ""
355  MAKEFLAGS := $(MAKEFLAGS) -w
356endif
357
358# Notes about the following:
359#
360# include-recursive is split out as a separate target, so that
361# it is not made to depend on $(subdirs) targets.  Instead, if
362# include-recursive is a command, a separate set of logic below
363# causes a 'make include' to be performed in $(subdirs)
364
365$(filter-out include-recursive,$(recursive_targets)): subdirs
366
367subdirs_recurse = $(addsuffix -recurse,$(subdirs))
368
369subdirs: $(subdirs_recurse)
370
371$(subdirs_recurse):
372ifneq "$(MAKEFLAGS)" ""
373	$(MAKE) -C $(subst -recurse,,$@) -$(MAKEFLAGS) $(MAKECMDGOALS)
374else
375	$(MAKE) -C $(subst -recurse,,$@) $(MAKECMDGOALS)
376endif
377
378# Now here's the separate logic for include-recursive:
379
380subdirs_recurse_inc = $(addsuffix -recurse-inc,$(subdirs))
381
382include-recursive: $(subdirs_recurse_inc)
383
384$(subdirs_recurse_inc):
385ifneq "$(MAKEFLAGS)" ""
386	$(MAKE) -C $(subst -recurse-inc,,$@) -$(MAKEFLAGS) include
387else
388	$(MAKE) -C $(subst -recurse-inc,,$@) include
389endif
390
391
392# -----------------------------------------------------------------------------
393# Running checks.
394# -----------------------------------------------------------------------------
395
396# This depends on $(check_driver) and $(test_objfiles) to have been defined
397# in the including Makefile.
398
399# 2010-04-26: if you build libSBML as a universal binary with x86_64 support
400# on MacOS 10.5, "make check" may fail because not all the libraries needed
401# by an executable are available in 64-bit form on the system.  We have to
402# drop down to 32-bit in that case.  Conversely, on 10.6, MacOS ships with
403# 64-bit binaries for (it seems) everything, and builds 64-bit executables
404# by default.
405
406filtered_cflags   = $(shell echo '$(CFLAGS)'   | sed -e "s/-arch x86_64//g")
407filtered_cppflags = $(shell echo '$(CPPFLAGS)' | sed -e "s/-arch x86_64//g")
408filtered_ldflags  = $(shell echo '$(LDFLAGS)'  | sed -e "s/-arch x86_64//g")
409
410$(check_driver): $(test_objfiles)
411ifndef USE_UNIVBINARY
412	$(LIBTOOL) --mode=link $(CXX) $(extra_CPPFLAGS) $(extra_CXXFLAGS) \
413	  $(default_includes) $(CPPFLAGS) $(CFLAGS) $(INCLUDES) \
414	  $(test_objfiles) $(objfiles) $(extra_LDFLAGS) $(LDFLAGS) \
415	  $(LIBS) $(extra_LIBS) -o $@
416else
417	@version=`uname -r | awk -F. '{print $$1}'`;\
418	if test $$version -ge 10; then \
419	  cflags="$(CFLAGS)"; \
420	  cppflags="$(CPPFLAGS)"; \
421	  ldflags="$(LDFLAGS)"; \
422        else \
423	  cflags="$(filtered_cflags)";\
424	  cppflags="$(filtered_cppflags)";\
425	  ldflags="$(filtered_ldflags)";\
426	fi; \
427	$(LIBTOOL) --mode=link $(CXX) $(extra_CPPFLAGS) $(extra_CXXFLAGS) \
428	  $(default_includes) $$cppflags $$cflags $(INCLUDES) \
429	  $(test_objfiles) $(objfiles) $(extra_LDFLAGS) $$ldflags \
430	  $(LIBS) $(extra_LIBS) -o $@
431endif
432
433run-checks: $(check_driver) $(libraries)
434	@echo
435	@echo
436	@echo Running Tests in $(thisdir)
437	@echo -----------------------------------------------------------------
438	@$(call libsbmlrun,./$(check_driver))
439	@echo -----------------------------------------------------------------
440	@echo
441
442# Utility function for reconstructing test files using translateTests.pl
443# This is called by some sub-makefiles in src/bindings.  The arguments are:
444#   (1) a letter, 'p' for Python, 'j' for Java, 'r' for Ruby, 'c' for C#
445#   (2) a list of directories in src/* (e.g., "xml sbml math annotation")
446#   (3) the root of the output directory where to write the translated tests
447
448translateTests = $(TOP_SRCDIR)/dev/utilities/translateTests/translateTests.pl
449
450define test_translator
451  for d in $(2); do \
452    list="$(top_src)/$$d/test/*.c $(top_src)/$$d/test/*.cpp"; \
453    for file in $$list; do \
454      $(translateTests) -$(1) -o $(3)/$$d $$file; \
455    done; \
456  done;
457endef
458
459
460# -----------------------------------------------------------------------------
461# Installation
462# -----------------------------------------------------------------------------
463
464# It doesn't look like you can usefully strip binary libraries at installation
465# time on Darwin.  The man page for 'strip' says you'd have to do it as 'ld -s'
466# to really make it work, but you don't want to strip the library that's built
467# in the source tree -- you only want to strip the copy that gets installed
468# in the destination directory.  So, we do the following conditional, until
469# we can figure out something better.
470
471ifneq "$(HOST_TYPE)" "darwin"
472  install_strip = strip -S
473else
474  install_strip = echo
475endif
476
477# The following defines a macro that is invoked like this:
478# $(call install_library,$(libname),$(dest))
479
480define install_library
481  $(MKINSTALLDIRS) $(DESTDIR)$(LIBDIR)
482  $(LIBTOOL) --mode=install $(INSTALL_SH) $(1) $(DESTDIR)$(LIBDIR)
483endef
484
485to_install_libraries = $(addprefix install-,$(libraries))
486
487$(to_install_libraries): $(libraries) installdirs
488	$(call install_library,$(subst install-,,$@),$(DESTDIR)$(LIBDIR))
489
490install-libraries: $(libraries) $(to_install_libraries)
491
492# 'install_includes takes one argument, the root of the destination directory.
493
494define install_includes
495  @file="$(1)"; \
496  targetdir="$(2)"; \
497  if test -n '$(INCLUDEPREFIX)'; then \
498    targetdir="$$targetdir/$(INCLUDEPREFIX)"; \
499  fi; \
500  if test -n '$(header_inst_prefix)'; then \
501    targetdir="$$targetdir/$(header_inst_prefix)"; \
502  fi; \
503  $(MKINSTALLDIRS) $$targetdir; \
504  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
505  dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
506  if test "$$dir" != "$$file" && test "$$dir" != "."; then \
507    dir="/$$dir"; \
508    $(MKINSTALLDIRS) $$targetdir/$$dir; \
509  else \
510    dir=''; \
511  fi; \
512  if test -d $$d/$$file; then \
513    if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
514      echo Copying $(srcdir)/$$file; \
515      $(INSTALL_SH) -m 644 $(srcdir)/$$file $$targetdir$$dir || exit 1; \
516    fi; \
517    $(INSTALL_SH) -m 644 $$d/$$file $$targetdir$$dir || exit 1; \
518  else \
519    echo Copying $$targetdir/$$file; \
520    $(INSTALL_SH) -m 644 $$d/$$file $$targetdir/$$file || exit 1; \
521  fi;
522endef
523
524to_install_headers = $(addprefix install-,$(headers))
525
526$(to_install_headers): $(headers) installdirs
527	$(call install_includes,$(subst install-,,$@),$(DESTDIR)$(INCLUDEDIR))
528
529install-headers: $(headers) $(to_install_headers)
530
531# The following is for the copy of the include directory created in the root
532# of the libsbml source tree.
533
534include_root = $(subst //,/,$(TOP_SRCDIR)/include/$(INCLUDEPREFIX)/$(header_inst_prefix)/)
535
536include: $(addprefix $(include_root),$(headers))
537
538$(addprefix $(include_root),$(headers)): $(headers)
539	$(call install_includes,$(@F),$(TOP_SRCDIR)/include)
540
541#
542# And now, code for uninstalling.
543#
544
545# The following defines a macro that is invoked like this:
546# $(call install_library,$(libname),$(dest))
547
548# The goofiness involving find ... -empty is because rmdir will fail if the
549# directory's not empty, and we can't count on the host system having a
550# version of GNU rmdir with its --ignore-fail-on-non-empty flag.  This
551# is just a more portable way of detecting whether a directory is empty.
552
553define uninstall_library
554  @if test -f $(1); then \
555    finalname="$(notdir $(basename $(1)))$(suffix $(1)).$(library_version)"; \
556    target="$(2)/$$finalname"; \
557    if test -f $$target ; then \
558      echo rm $$target; \
559      rm $$target; \
560    fi; \
561    target="$(2)/$(notdir $(1))"; \
562    if test -L $$target ; then \
563      echo rm $$target; \
564      rm $$target; \
565    fi; \
566    if test -f $$target ; then \
567      echo rm $$target; \
568      rm $$target; \
569    fi; \
570  else \
571    if test -d $(2) && test -n "`find $(2) -maxdepth 0 -empty`"; then \
572      echo rmdir $(2); \
573      rmdir $(2); \
574    fi; \
575  fi; \
576  if test -n "`find $(DESTDIR)$(LIBDIR) -maxdepth 0 -empty`"; then \
577    echo rmdir "$(DESTDIR)$(LIBDIR)"; \
578    rmdir "$(DESTDIR)$(LIBDIR)"; \
579  else \
580    echo "Directory $(DESTDIR)$(LIBDIR) not empty; leaving it alone"; \
581  fi;
582endef
583
584to_uninstall_libraries = $(addprefix uninstall-,$(libraries))
585
586$(to_uninstall_libraries):
587	$(call uninstall_library,$(subst uninstall-,,$@),$(DESTDIR)$(LIBDIR))
588
589uninstall-libraries: $(to_uninstall_libraries)
590
591# 'install_includes takes one argument, the root of the destination directory.
592
593define uninstall_includes
594  @file="$(1)"; \
595  targetdir="$(2)"; \
596  if test -n '$(INCLUDEPREFIX)'; then \
597    targetdir="$$targetdir/$(INCLUDEPREFIX)"; \
598  fi; \
599  if test -n '$(header_inst_prefix)'; then \
600    targetdir="$$targetdir/$(header_inst_prefix)"; \
601  fi; \
602  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
603  dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
604  if test "$$dir" != "$$file" && test "$$dir" != "."; then \
605    dir="/$$dir"; \
606  else \
607    dir=''; \
608  fi; \
609  if test -f $$targetdir/$$file; then \
610    echo rm $$targetdir/$$file; \
611    rm $$targetdir/$$file; \
612  elif test -d $$targetdir/$$file; then \
613    if test -n "`find $$targetdir/$$file -empty`"; then \
614      echo rmdir $$targetdir/$$file; \
615      rmdir $$targetdir/$$file; \
616    else \
617      echo "Directory $$targetdir/$$file not empty; leaving it alone"; \
618    fi; \
619  fi; \
620  if test -d $$targetdir; then \
621    if test -n "`find $$targetdir -maxdepth 0 -empty`"; then \
622      echo rmdir $$targetdir; \
623      rmdir $$targetdir; \
624    fi; \
625  fi;
626endef
627
628to_uninstall_headers = $(addprefix uninstall-,$(headers))
629
630$(to_uninstall_headers): $(headers)
631	$(call uninstall_includes,$(subst uninstall-,,$@),$(DESTDIR)$(INCLUDEDIR))
632
633uninstall-headers: $(headers) $(to_uninstall_headers)
634
635
636# -----------------------------------------------------------------------------
637# Creating distribution (for libSBML maintainers only)
638# -----------------------------------------------------------------------------
639
640# The `dist-normal' case uses the list of files and diretories in
641# $(distfiles) and mirrors their structure in $(DISTDIR)/$(thisdir)/,
642# except that files and directories that are also listed in
643# $(distfile_exclude) are not copied.
644
645# The $(sort ...) removes duplicates.
646
647sortedfiles = $(sort $(distfiles))
648
649dist-normal: DESTINATION := $(DISTDIR)/$(thisdir)
650dist-normal: $(distfiles)
651	$(shell [ -d $(DESTINATION) ] || mkdir -p $(DESTINATION))
652	@list='$(sortedfiles)'; for file in $$list; do \
653	  exlist='$(distfiles_exclude)'; for ex in $$exlist; do \
654	    if test $$file = $$ex; then continue 2; fi; \
655          done; \
656	  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
657	  dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
658	  if test "$$dir" != "$$file" && test "$$dir" != "."; then \
659	    dir="/$$dir"; \
660	    $(MKINSTALLDIRS) "$(DESTINATION)/$$dir"; \
661	  elif test -d "$$dir"; then \
662	    $(MKINSTALLDIRS) "$(DESTINATION)/$$dir"; \
663	  else \
664	    dir=''; \
665	  fi; \
666	  if test -d $$d/$$file; then \
667	    if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
668	      echo Copying $(srcdir)/$$file; \
669	      cp -r $(srcdir)/$$file $(DESTINATION)/$$dir || exit 1; \
670	    fi; \
671	    cp -r $$d/$$file $(DESTINATION)/$$dir || exit 1; \
672	  else \
673	    echo Copying $(DESTINATION)/$$file; \
674	    test -f $(DESTINATION)/$$file \
675	    || cp -r $$d/$$file $(DESTINATION)/$$file \
676	    || exit 1; \
677	  fi; \
678	done
679
680#	      $(INSTALL_SH) --mode="u+X,g+X,o+X" $(srcdir)/$$file $(DESTINATION)/$$dir || exit 1; \
681#	    $(INSTALL_SH) -d $$d/$$file $(DESTINATION)/$$dir || exit 1; \
682#	    || $(INSTALL_SH) --mode="u+X,g+X,o+X" $$d/$$file $(DESTINATION)/$$file \
683
684
685# -----------------------------------------------------------------------------
686# Cleaning
687# -----------------------------------------------------------------------------
688
689# This tries to follow the recommended GNU make guidelines.
690
691# Although we don't explicitly use libtool in the hand-written libSBML
692# makefiles, the cleaning targets for libtool are included below in case
693# someone ever decides to use libtool as part of some make actions.
694
695mostlyclean:        clean-generic mostlyclean-libtool
696mostlyclean-normal: clean-generic mostlyclean-libtool
697
698clean:        mostlyclean clean-libraries clean-libtool clean-extras clean-deps
699clean-normal: mostlyclean clean-libraries clean-libtool clean-extras clean-deps
700
701clean-generic:
702	-rm -f *.$(OBJEXT) *.lo core *.core
703
704clean-libtool:
705	-rm -rf .libs _libs
706
707clean-deps:
708	-test -z "./$(DEPDIR)" || rm -rf ./$(DEPDIR)
709
710ifdef libraries
711  clean-libraries:
712	-test -z "$(libraries)" || rm -f $(libraries)
713else
714  clean-libraries:
715endif
716
717ifdef extra_clean
718  clean-extras:
719	-test -z "$(extra_clean)" || rm -rf $(extra_clean)
720else
721  clean-extras:
722endif
723
724mostlyclean-libtool:
725	-rm -f *.lo *.la *.loT
726
727distclean: clean distclean-compile distclean-generic \
728	distclean-tags distclean-libtool
729distclean-normal: clean distclean-compile distclean-generic \
730	distclean-tags distclean-libtool
731
732distclean-compile:
733	-rm -f *.tab.c
734
735distclean-generic:
736	-rm -f Makefile
737ifdef extra_distclean
738	-rm -rf $(extra_distclean)
739endif
740
741distclean-tags:
742	-rm -f TAGS CTAGS ID GTAGS GRTAGS GSYMS GPATH tags
743
744distclean-libtool:
745	-rm -f libtool
746
747maintainer-clean:        distclean maintainer-clean-generic
748maintainer-clean-normal: distclean maintainer-clean-generic
749
750maintainer-clean-generic:
751	-rm -rf $(extra_maintainer_clean)
752
753
754# -----------------------------------------------------------------------------
755# Miscellaneous definitions.
756# -----------------------------------------------------------------------------
757
758# The following is for running shell commands with the right XX_LIBRARY_PATH
759# variable set for different platforms.
760
761ifeq "$(HOST_TYPE)" "darwin"
762
763  define libsbmlrun
764	env DYLD_LIBRARY_PATH=".:$(RUN_LDPATH):$(DYLD_LIBRARY_PATH)" srcdir=$(realpath .) $(LIBTOOL) -dlopen $(TOP_BUILDDIR)/src/libsbml.la --mode=execute $(1)
765  endef
766
767else
768
769  define libsbmlrun
770	env LD_LIBRARY_PATH=".:$(RUN_LDPATH):$(LD_LIBRARY_PATH)" srcdir=$(realpath .) $(LIBTOOL) -dlopen $(TOP_BUILDDIR)/src/libsbml.la --mode=execute $(1)
771  endef
772
773endif
774
775
776# -----------------------------------------------------------------------------
777# Common dependency rules.
778# -----------------------------------------------------------------------------
779# These rules ensure that files like makefiles are recreated when
780# dependencies change.  The rules are generic enough that they apply to the
781# top-level source directory as well as the source subdirectories.
782
783Makefile: Makefile.in $(TOP_SRCDIR)/configure \
784	     $(TOP_SRCDIR)/config/makefile-common-vars.mk
785	cd $(TOP_BUILDDIR) && $(SHELL) ./config.status $(thisdir)/$@
786
787$(TOP_SRCDIR)/config/makefile-common-vars.mk: \
788	     $(TOP_SRCDIR)/config/makefile-common-vars.mk.in \
789	     $(TOP_SRCDIR)/configure
790	cd $(TOP_BUILDDIR) && $(SHELL) ./config.status config/makefile-common-vars.mk
791
792$(TOP_SRCDIR)/config.status: $(TOP_SRCDIR)/configure $(TOP_SRCDIR)/VERSION.txt
793	$(SHELL) ./config.status --recheck
794
795$(TOP_SRCDIR)/configure: \
796	     $(TOP_SRCDIR)/configure.ac \
797	     $(TOP_SRCDIR)/VERSION.txt \
798	     $(TOP_SRCDIR)/VERSION_PACKAGES.ac \
799	     $(ACLOCAL_M4) \
800	     $(wildcard $(TOP_SRCDIR)/config/*.m4)
801	cd $(TOP_SRCDIR) && $(AUTOCONF) -Wall --force
802	cd $(TOP_SRCDIR) && $(SHELL) ./config.status --recheck
803
804$(ACLOCAL_M4): $(ACINCLUDE_M4)
805	cd $(TOP_SRCDIR) && $(ACLOCAL) -I config
806
807$(TOP_SRCDIR)/config/chk_swig_version.sh: $(TOP_SRCDIR)/configure \
808	    $(TOP_BUILDDIR)/config.status \
809	    $(TOP_BUILDDIR)/config/chk_swig_version.sh.in
810	cd $(TOP_BUILDDIR) && $(SHELL) ./config.status config/chk_swig_version.sh
811
812
813# -----------------------------------------------------------------------------
814# Tags files.
815# -----------------------------------------------------------------------------
816
817# 2006-08-09 <mhucka@caltech.edu> Previously I had it create tags in each
818# source directory separately, but that turns out to be very inconvenient
819# when using tags.  The new formulation is designed to create only one tags
820# file, recursively looking in subdirectories for source files to use as
821# input.  This is therefore really only meant to be used in the libsbml
822# 'src' directory.
823
824etags-version-check:
825	@if test -z "`$(ETAGS) --version 2>&1 | grep 'Free Software'`"; then \
826	  echo "Your 'etags' command is not the GNU [X]Emacs version,"; \
827	  echo "and I'm afraid I don't know how to work with it. Quitting."; \
828	  exit 2; \
829	fi
830
831ctags-version-check:
832	@if test -z "`$(CTAGS) --version 2>&1 | grep 'Free Software'`"; then \
833	  echo "Your 'ctags' command is not the GNU version, and"; \
834	  echo "I'm afraid I don't know how to work with it. Quitting."; \
835	  exit 2; \
836	fi
837
838etags: etags-version-check TAGS
839ctags: ctags-version-check CTAGS
840
841etags-command ?= $(ETAGS) $(ETAGSFLAGS)
842ctags-command ?= $(CTAGS) $(CTAGSFLAGS)
843
844files-to-tag := $(shell find . -name '*.c' -o -name '*.cpp' -o -name '*.h')
845
846TAGS: $(files-to-tag)
847	$(etags-command) $(files-to-tag)
848
849CTAGS: $(files-to-tag)
850	$(ctags-command) $(files-to-tag)
851
852
853# -----------------------------------------------------------------------------
854# Common special targets.
855# -----------------------------------------------------------------------------
856
857.PHONY: $(recursive_targets) CTAGS GTAGS docs all all-am check check-am \
858	include clean clean-generic clean-libtool ctags \
859	dist dist-all dist-gzip distcheck distclean \
860	distclean-generic distclean-libtool distclean-tags distcleancheck \
861	distdir distuninstallcheck dvi dvi-am info info-am \
862	install install-am install-data install-data-am \
863	install-exec install-exec-am install-info install-info-am \
864	install-man install-strip installcheck installcheck-am installdirs \
865	installdirs-am maintainer-clean maintainer-clean-generic mostlyclean \
866	mostlyclean-generic mostlyclean-libtool \
867	pdf pdf-am ps ps-am tags uninstall uninstall-am uninstall-info-am \
868	clean-extras subdirs $(subdirs_recurse) subdist subdistcheck
869
870# Tell versions [3.59,3.63) of GNU make to not export all variables.
871# Otherwise a system limit (for SysV at least) may be exceeded.
872.NOEXPORT:
873
874
875# -----------------------------------------------------------------------------
876# End.
877# -----------------------------------------------------------------------------
878
879## The following is for [X]Emacs users.  Please leave in place.
880## Local Variables:
881## mode: Makefile
882## End:
883