File: makefile-common-actions.mk

package info (click to toggle)
libsbml 5.10.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 141,800 kB
  • ctags: 98,793
  • sloc: cpp: 804,405; xml: 206,907; ansic: 66,144; cs: 52,916; java: 25,093; python: 23,449; sh: 9,847; perl: 8,414; makefile: 7,580; ruby: 4,760; csh: 3
file content (891 lines) | stat: -rw-r--r-- 30,590 bytes parent folder | download
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
## Filename    : makefile-common-actions.mk
## Description : Makefile include file containing common actions
## Author(s)   : SBML Team <sbml-team@caltech.edu>
## Organization: California Institute of Technology
## Created     : 2004-06-17
##
##<!---------------------------------------------------------------------------
## This file is part of libSBML.  Please visit http://sbml.org for more
## information about SBML, and the latest version of libSBML.
##
## Copyright (C) 2013-2014 jointly by the following organizations:
##     1. California Institute of Technology, Pasadena, CA, USA
##     2. EMBL European Bioinformatics Institute (EMBL-EBI), Hinxton, UK
##     3. University of Heidelberg, Heidelberg, Germany
##
## Copyright (C) 2009-2013 jointly by the following organizations: 
##     1. California Institute of Technology, Pasadena, CA, USA
##     2. EMBL European Bioinformatics Institute (EMBL-EBI), Hinxton, UK
##  
## Copyright (C) 2006-2008 by the California Institute of Technology,
##     Pasadena, CA, USA 
##  
## Copyright (C) 2002-2005 jointly by the following organizations: 
##     1. California Institute of Technology, Pasadena, CA, USA
##     2. Japan Science and Technology Agency, Japan
## 
## This library is free software; you can redistribute it and/or modify it
## under the terms of the GNU Lesser General Public License as published by
## the Free Software Foundation.  A copy of the license agreement is provided
## in the file named "LICENSE.txt" included with this software distribution
## and also available online as http://sbml.org/software/libsbml/license.html
##----------------------------------------------------------------------- -->*/

# General explanations: 
#
# The rules in this file are meant to be generic and included in other
# makefiles.  This file is meant to be included last by other makefiles.
#
# As a general rule, variables with names in all lower-case letters (such
# as `cxxcompile') are assumed to be defined by the enclosing makefile,
# while those in all upper-case letters (such as `TOP_SRCDIR') are assumed
# to be defined in `makefile-common-vars.mk' which in turn must be included
# by the enclosing makefile.


# -----------------------------------------------------------------------------
# Common compilation rules for object files and libraries.
# -----------------------------------------------------------------------------

.SUFFIXES:
.SUFFIXES: .a .so .dylib .jnilib .c .h .cpp .hpp .cs .o .lo .la .obj .Po .py .pyc .pyo .i .bundle .rb .t

# The following define default values of variables like `cxxcompile'.  An
# enclosing makefile can define other values, in which case those
# definitions will override what's given here.

top_include := $(TOP_SRCDIR)/src
top_src     := $(TOP_SRCDIR)/src

default_includes ?= -I. -I$(top_include)

# Compiling under cygwin and Sun cc doesn't need -fPIC.

ifneq "$(HOST_TYPE)" "cygwin"
  ifndef USE_SUN_CC
    FPIC = -fPIC
  endif
endif

# Compiling under Sun cc must not use -Wall.

ifndef USE_SUN_CC
  WALL = -Wall
endif

# Here follow the generic compilation commands.  (Note: the use of 'sort'
# here is only to remove duplicates, which the 'sort' function does as a
# documented side-effect.)

# hardening
CFLAGS = $(shell dpkg-buildflags --get CFLAGS)
CFLAGS += -Wall
CXXFLAGS = $(shell dpkg-buildflags --get CXXFLAGS)
CXXFLAGS += -Wall
LDFLAGS = $(shell dpkg-buildflags --get LDFLAGS)
CPPFLAGS = $(shell dpkg-buildflags --get CPPFLAGS)
CCFLAGS = $(shell dpkg-buildflags --get CFLAGS)

compile ?= $(LIBTOOL) --mode=compile --tag=CC $(CC) $(sort $(default_includes) $(INCLUDES)) $(CPPFLAGS) \
        $(extra_CPPFLAGS) $(CFLAGS) $(extra_CFLAGS) 

cxxcompile ?= $(LIBTOOL) --mode=compile --tag=CXX $(CXX) $(sort $(default_includes) $(INCLUDES)) \
        $(CPPFLAGS) $(extra_CPPFLAGS) $(CXXFLAGS) $(extra_CXXFLAGS) 

# The following two commands are used for dependency tracking only when 
# building universal binaries on MacOSX.

compile_nocflags ?= $(CC) $(sort $(default_includes) $(INCLUDES)) \
        $(CPPFLAGS) $(extra_CPPFLAGS) 

cxxcompile_nocxxflags ?= $(CXX) $(sort $(default_includes) $(INCLUDES)) \
        $(CPPFLAGS) $(extra_CPPFLAGS) \

# For linking libraries, we try to follow the result of the libtool
# numbering scheme, but at the final end, not in the input format.  (The
# libtool input format is peculiar to us.)  Curious, this makes the
# numbering very easy: it's a direct mapping of the libsbml version number.

library_version = $(shell echo $(PACKAGE_VERSION) | sed -e 's/\-.*//g' -e 's/[a-zA-Z]//g' )
library_major_version = $(word 1, $(subst ., ,$(library_version)))
library_minor_version = $(word 2, $(subst ., ,$(library_version)))
library_patch_version = $(word 3, $(subst ., ,$(library_version)))

# `platform_link_flags' is used below in the definition of link_shared_lib.
# Generally, gcc and ld need -shared, but some systems think different.

ifeq "$(HOST_TYPE)" "darwin"
  # MacOS X's normal libraries have the extension .dylib, and "bundles"
  # have .so.  The default shared library definition here builds .dylib.
  platform_link_flags ?= -dynamiclib -flat_namespace \
	-current_version $(library_version)

  #
  # -M options are not allowed with multiple -arch flags.
  # 
  match = $(shell echo $(compile) | grep '\-arch.*\-arch.*')
  ifneq "$(match)" ""
    USE_UNIVBINARY = 1
  endif

  match = $(shell echo $(cxxcompile) | grep '\-arch.*\-arch.*')
  ifneq "$(match)" ""
    USE_UNIVBINARY = 1
  endif 
else
  #
  # -no-undefined option is required to generate a *.dll file
  # by using libtool on Cygwin  
  #
  ifeq "$(HOST_TYPE)" "cygwin" 
    platform_link_flags ?= -no-undefined
  else
    ifeq "$(HOST_TYPE)" "aix5.3.0.0" 
      platform_link_flags ?= -G
    else
      ifdef USE_SUN_CC
        platform_link_flags ?= -G
      else
        platform_link_flags ?= -shared
      endif
    endif
  endif
endif


# The following defines the default function for linking objects into a
# shared library. It gets used thus: $(call link_shared_lib,ARGS...).  The
# forms $(1), $(2) in the expressions below, etc. are the arguments passed
# to the call.  An enclosing makefile can provide another definition, in
# which case, the definition below will not be used.

#    -version-info $(subst .,:,$(library_version)) \

ifndef link_shared_lib
  define link_shared_lib 
    $(LIBTOOL) --mode=link $(CXX) $(extra_LDFLAGS) $(LDFLAGS) \
    -version-info \
    `expr $(library_major_version) \+ $(library_minor_version)`:$(library_patch_version):$(library_minor_version) \
    -inst-prefix-dir "$(DESTDIR)" \
    $(platform_link_flags) -rpath $(LIBDIR) -o $(1) $(objfiles:.o=.lo) \
    $(extra_LIBS) $(LIBS)
  endef
endif

ifndef link_dl_lib
  define link_dl_lib
    $(TOP_SRCDIR)/config/lt_link_helper.sh $(CXX) --libdir $(LIBDIR) \
    $(LDFLAGS) $(extra_LDFLAGS) $(platform_link_flags) \
    -o $(1) $(objfiles:.o=.lo) $(extra_LIBS) $(LIBS)
  endef
endif

# The following defines the default function for linking objects into a
# static library. It gets used thus: $(call link_static_lib,ARGS...).  The
# forms $(1), $(2) in the expressions below, etc. are the arguments passed
# to the call.  An enclosing makefile can provide another definition, in
# which case the definition below will not be used.

ifdef USE_SUN_CC
  define link_static_lib
    -rm -f $(1)
   $(CXX) -xar -o $(1) $(objfiles)
  endef
else
  define link_static_lib
    -rm -f $(1)
    $(AR) -cru $(1) $(objfiles)
    $(RANLIB) $(1)
  endef
endif

# Most of the sources are a mix of C and C++ files.  They have separate
# extensions, and simply using something like $(sources:.cpp=.o) doesn't
# work for converting the source file names into object file names because
# you have to do it twice (once each for .cpp and .c) and then you have to
# filter the results.  This abstracts out this common operation.

make_objects_list = \
  $(filter %.lo,\
    $(patsubst %.cpp,%.lo,$(1)) $(patsubst %.c,%.lo,$(1)))

# The following generate the list of object file names and dependency file
# names from the list of source files.  They're used for the generic
# compilation rules further below.

tmplist  ?= $(sources:.cpp=.lo) $(sources:.c=.lo)
objfiles ?= $(filter %.lo,$(tmplist))

# This next line includes the dependency files.  This uses a wildcard on
# the actual files, so that if they don't exist yet, `make' won't generate
# errors about being unable to include such-and-such file.  If the files
# are missing, the wildcard will expand to nothing.  The /dev/null at the
# end makes sure that we don't have an empty `include' line.

include $(wildcard $(DEPDIR)/*.$(DEPEXT)) /dev/null

# The next set of rules are generic for creating .a, .so, and other styles
# of static and shared library files.

ifneq "$(HOST_TYPE)" "aix"
# Both shared and static libraries in AIX have the same extension (.a).
# We have to choose what's built.  Shared is more likely to be preferred,
# so we leave out this rule for static libraries when building under AIX.

%.a ../%.a: $(objfiles)
	$(call link_static_lib,$@)

endif

%.la ../%.la: $(objfiles)
	$(call link_shared_lib,$@)

%.$(SHAREDLIBEXT) ../%.$(SHAREDLIBEXT): $(objfiles)
	$(call link_dl_lib,$@)

%.$(JNIEXT) ../%.$(JNIEXT): $(objfiles)
	$(call link_dl_lib,$@)

#
# -install_name option should be used when building an universal binary on MacOSX.
#
#%.$(SHAREDLIBEXT) ../%.$(SHAREDLIBEXT): $(objfiles)
#ifeq "$(HOST_TYPE)" "darwin"
#	$(call link_shared_lib,$@ -install_name $@)
#else
#	$(call link_shared_lib,$@)
#endif

# The following define generic rules for creating object files.

ifeq "$(HOST_TYPE)" "aix"

.c.lo:
	$(compile) -c -o $@ $<

.c.obj:
	if $(compile) -c -o $@ \
	  `if test -f '$<'; then $(CYGPATH_W) '$<'; else $(CYGPATH_W) '$(srcdir)/$<'; fi`; \
	then mv "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.$(DEPEXT)"; \
	else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; \
	fi

.cpp.lo .cxx.lo:
	$(cxxcompile) -c -o $@ $<

.cpp.obj:
	if $(cxxcompile) -c -o $@ \
	  `if test -f '$<'; then $(CYGPATH_W) '$<'; else $(CYGPATH_W) '$(srcdir)/$<'; fi`; \
	then mv "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.$(DEPEXT)"; \
	else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; \
	fi

else
# All hosts types that are not aix.

.c.lo:
ifndef USE_UNIVBINARY
  ifdef USE_SUN_CC
	$(compile) -c -o $@ $<
  else
	$(compile) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.$(DEPEXT)" -c -o $@ $<
  endif
else
	$(compile_nocflags) -MT $@ -MM -MP -MF "$(DEPDIR)/$*.$(DEPEXT)" $<
	$(compile) -c -o $@ $<
endif

.c.obj:
	if $(compile) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" \
	  -c -o $@ `if test -f '$<'; then $(CYGPATH_W) '$<'; else $(CYGPATH_W) '$(srcdir)/$<'; fi`; \
	then mv "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.$(DEPEXT)"; \
	else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; \
	fi

.cpp.lo .cxx.lo:
ifndef USE_UNIVBINARY
  ifdef USE_SUN_CC
	$(cxxcompile) -c -o $@ $<
  else
	$(cxxcompile) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.$(DEPEXT)" -c -o $@ $<
  endif
else
	$(cxxcompile_nocxxflags) -MT $@ -MM -MP -MF "$(DEPDIR)/$*.$(DEPEXT)" $<
	$(cxxcompile) -c -o $@ $<
endif

.cpp.obj:
	if $(cxxcompile) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" \
	  -c -o $@ `if test -f '$<'; then $(CYGPATH_W) '$<'; else $(CYGPATH_W) '$(srcdir)/$<'; fi`; \
	then mv "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.$(DEPEXT)"; \
	else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; \
	fi

endif

ifeq "$(HOST_TYPE)" "darwin"

%.bundle ../%.bundle: $(objfiles)
	$(call link_dl_lib,$@)

endif

# This next line ensures that the object output directory is created first.
# Got this from a posting by Paul D. Smith to gnu.utils.help, 2001-12-03.

__dummy := $(shell [ -d $(DEPDIR) ] || mkdir $(DEPDIR))


# -----------------------------------------------------------------------------
# Generic default.
# -----------------------------------------------------------------------------

default: $(objfiles) $(test_objfiles) $(libraries)


# -----------------------------------------------------------------------------
# Generic recursive targets.
# -----------------------------------------------------------------------------

recursive_targets = all-recursive include-recursive install-data-recursive \
	install-exec-recursive installdirs-recursive install-recursive \
	uninstall-recursive uninstall-info-recursive install-info-recursive \
	ps-recursive info-recursive dvi-recursive pdf-recursive \
	check-recursive installcheck-recursive mostlyclean-recursive \
	clean-recursive distclean-recursive maintainer-clean-recursive \
	install-man-recursive tags-recursive etags-recursive ctags-recursive \
	docs-recursive install-docs-recursive \
	dist-recursive distcheck-recursive

# Always want -w in the flags passed to recursive makes, so that it prints
# the current directory at each step.

ifeq "$(findstring $(MAKEFLAGS),-w)" ""
  MAKEFLAGS := $(MAKEFLAGS) -w
endif

# Notes about the following:
#
# include-recursive is split out as a separate target, so that
# it is not made to depend on $(subdirs) targets.  Instead, if
# include-recursive is a command, a separate set of logic below
# causes a 'make include' to be performed in $(subdirs)

$(filter-out include-recursive,$(recursive_targets)): subdirs

subdirs_recurse = $(addsuffix -recurse,$(subdirs))

subdirs: $(subdirs_recurse)

$(subdirs_recurse): 
ifneq "$(MAKEFLAGS)" ""
	$(MAKE) -C $(subst -recurse,,$@) -$(MAKEFLAGS) $(MAKECMDGOALS)
else
	$(MAKE) -C $(subst -recurse,,$@) $(MAKECMDGOALS)
endif

# Now here's the separate logic for include-recursive:

subdirs_recurse_inc = $(addsuffix -recurse-inc,$(subdirs))

include-recursive: $(subdirs_recurse_inc)

$(subdirs_recurse_inc): 
ifneq "$(MAKEFLAGS)" ""
	$(MAKE) -C $(subst -recurse-inc,,$@) -$(MAKEFLAGS) include
else
	$(MAKE) -C $(subst -recurse-inc,,$@) include
endif


# -----------------------------------------------------------------------------
# Running checks.
# -----------------------------------------------------------------------------

# This depends on $(check_driver) and $(test_objfiles) to have been defined
# in the including Makefile.

# 2010-04-26: if you build libSBML as a universal binary with x86_64 support
# on MacOS 10.5, "make check" may fail because not all the libraries needed
# by an executable are available in 64-bit form on the system.  We have to
# drop down to 32-bit in that case.  Conversely, on 10.6, MacOS ships with
# 64-bit binaries for (it seems) everything, and builds 64-bit executables
# by default.  

filtered_cflags   = $(shell echo '$(CFLAGS)'   | sed -e "s/-arch x86_64//g")
filtered_cppflags = $(shell echo '$(CPPFLAGS)' | sed -e "s/-arch x86_64//g")
filtered_ldflags  = $(shell echo '$(LDFLAGS)'  | sed -e "s/-arch x86_64//g")

$(check_driver): $(test_objfiles)
ifndef USE_UNIVBINARY
	$(LIBTOOL) --mode=link $(CXX) $(extra_CPPFLAGS) $(extra_CXXFLAGS) \
	  $(default_includes) $(CPPFLAGS) $(CFLAGS) $(INCLUDES) \
	  $(test_objfiles) $(objfiles) $(extra_LDFLAGS) $(LDFLAGS) \
	  $(LIBS) $(extra_LIBS) -o $@
else
	@version=`uname -r | awk -F. '{print $$1}'`;\
	if test $$version -ge 10; then \
	  cflags="$(CFLAGS)"; \
	  cppflags="$(CPPFLAGS)"; \
	  ldflags="$(LDFLAGS)"; \
        else \
	  cflags="$(filtered_cflags)";\
	  cppflags="$(filtered_cppflags)";\
	  ldflags="$(filtered_ldflags)";\
	fi; \
	$(LIBTOOL) --mode=link $(CXX) $(extra_CPPFLAGS) $(extra_CXXFLAGS) \
	  $(default_includes) $$cppflags $$cflags $(INCLUDES) \
	  $(test_objfiles) $(objfiles) $(extra_LDFLAGS) $$ldflags \
	  $(LIBS) $(extra_LIBS) -o $@
endif

run-checks: $(check_driver) $(libraries)
	@echo
	@echo
	@echo Running Tests in $(thisdir)
	@echo -----------------------------------------------------------------
	@$(call libsbmlrun,./$(check_driver))
	@echo -----------------------------------------------------------------
	@echo

# Utility function for reconstructing test files using translateTests.pl
# This is called by some sub-makefiles in src/bindings.  The arguments are:
#   (1) a letter, 'p' for Python, 'j' for Java, 'r' for Ruby, 'c' for C#
#   (2) a list of directories in src/* (e.g., "xml sbml math annotation")
#   (3) the root of the output directory where to write the translated tests

translateTests = $(TOP_SRCDIR)/dev/utilities/translateTests/translateTests.pl

define test_translator
  for d in $(2); do \
    list="$(top_src)/$$d/test/*.c $(top_src)/$$d/test/*.cpp"; \
    for file in $$list; do \
      $(translateTests) -$(1) -o $(3)/$$d $$file; \
    done; \
  done; 
endef


# -----------------------------------------------------------------------------
# Installation
# -----------------------------------------------------------------------------

# It doesn't look like you can usefully strip binary libraries at installation
# time on Darwin.  The man page for 'strip' says you'd have to do it as 'ld -s'
# to really make it work, but you don't want to strip the library that's built
# in the source tree -- you only want to strip the copy that gets installed
# in the destination directory.  So, we do the following conditional, until
# we can figure out something better.

ifneq "$(HOST_TYPE)" "darwin"
  install_strip = strip -S
else
  install_strip = echo
endif

# The following defines a macro that is invoked like this:
# $(call install_library,$(libname),$(dest))

define install_library
  $(MKINSTALLDIRS) $(DESTDIR)$(LIBDIR)
  $(LIBTOOL) --mode=install $(INSTALL_SH) $(1) $(DESTDIR)$(LIBDIR)
endef

to_install_libraries = $(addprefix install-,$(libraries))

$(to_install_libraries): $(libraries) installdirs
	$(call install_library,$(subst install-,,$@),$(DESTDIR)$(LIBDIR))

install-libraries: $(libraries) $(to_install_libraries)

# 'install_includes takes one argument, the root of the destination directory.

define install_includes
  @file="$(1)"; \
  targetdir="$(2)"; \
  if test -n '$(INCLUDEPREFIX)'; then \
    targetdir="$$targetdir/$(INCLUDEPREFIX)"; \
  fi; \
  if test -n '$(header_inst_prefix)'; then \
    targetdir="$$targetdir/$(header_inst_prefix)"; \
  fi; \
  $(MKINSTALLDIRS) $$targetdir; \
  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
  dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
  if test "$$dir" != "$$file" && test "$$dir" != "."; then \
    dir="/$$dir"; \
    $(MKINSTALLDIRS) $$targetdir/$$dir; \
  else \
    dir=''; \
  fi; \
  if test -d $$d/$$file; then \
    if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
      echo Copying $(srcdir)/$$file; \
      $(INSTALL_SH) -m 644 $(srcdir)/$$file $$targetdir$$dir || exit 1; \
    fi; \
    $(INSTALL_SH) -m 644 $$d/$$file $$targetdir$$dir || exit 1; \
  else \
    echo Copying $$targetdir/$$file; \
    $(INSTALL_SH) -m 644 $$d/$$file $$targetdir/$$file || exit 1; \
  fi;
endef

to_install_headers = $(addprefix install-,$(headers))

$(to_install_headers): $(headers) installdirs
	$(call install_includes,$(subst install-,,$@),$(DESTDIR)$(INCLUDEDIR))

install-headers: $(headers) $(to_install_headers)

# The following is for the copy of the include directory created in the root
# of the libsbml source tree.

include_root = $(subst //,/,$(TOP_SRCDIR)/include/$(INCLUDEPREFIX)/$(header_inst_prefix)/)

include: $(addprefix $(include_root),$(headers))

$(addprefix $(include_root),$(headers)): $(headers)
	$(call install_includes,$(@F),$(TOP_SRCDIR)/include)

#
# And now, code for uninstalling.
#

# The following defines a macro that is invoked like this:
# $(call install_library,$(libname),$(dest))

# The goofiness involving find ... -empty is because rmdir will fail if the
# directory's not empty, and we can't count on the host system having a
# version of GNU rmdir with its --ignore-fail-on-non-empty flag.  This
# is just a more portable way of detecting whether a directory is empty.

define uninstall_library
  @if test -f $(1); then \
    finalname="$(notdir $(basename $(1)))$(suffix $(1)).$(library_version)"; \
    target="$(2)/$$finalname"; \
    if test -f $$target ; then \
      echo rm $$target; \
      rm $$target; \
    fi; \
    target="$(2)/$(notdir $(1))"; \
    if test -L $$target ; then \
      echo rm $$target; \
      rm $$target; \
    fi; \
    if test -f $$target ; then \
      echo rm $$target; \
      rm $$target; \
    fi; \
  else \
    if test -d $(2) && test -n "`find $(2) -maxdepth 0 -empty`"; then \
      echo rmdir $(2); \
      rmdir $(2); \
    fi; \
  fi; \
  if test -n "`find $(DESTDIR)$(LIBDIR) -maxdepth 0 -empty`"; then \
    echo rmdir "$(DESTDIR)$(LIBDIR)"; \
    rmdir "$(DESTDIR)$(LIBDIR)"; \
  else \
    echo "Directory $(DESTDIR)$(LIBDIR) not empty; leaving it alone"; \
  fi;
endef

to_uninstall_libraries = $(addprefix uninstall-,$(libraries))

$(to_uninstall_libraries): 
	$(call uninstall_library,$(subst uninstall-,,$@),$(DESTDIR)$(LIBDIR))

uninstall-libraries: $(to_uninstall_libraries)

# 'install_includes takes one argument, the root of the destination directory.

define uninstall_includes
  @file="$(1)"; \
  targetdir="$(2)"; \
  if test -n '$(INCLUDEPREFIX)'; then \
    targetdir="$$targetdir/$(INCLUDEPREFIX)"; \
  fi; \
  if test -n '$(header_inst_prefix)'; then \
    targetdir="$$targetdir/$(header_inst_prefix)"; \
  fi; \
  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
  dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
  if test "$$dir" != "$$file" && test "$$dir" != "."; then \
    dir="/$$dir"; \
  else \
    dir=''; \
  fi; \
  if test -f $$targetdir/$$file; then \
    echo rm $$targetdir/$$file; \
    rm $$targetdir/$$file; \
  elif test -d $$targetdir/$$file; then \
    if test -n "`find $$targetdir/$$file -empty`"; then \
      echo rmdir $$targetdir/$$file; \
      rmdir $$targetdir/$$file; \
    else \
      echo "Directory $$targetdir/$$file not empty; leaving it alone"; \
    fi; \
  fi; \
  if test -d $$targetdir; then \
    if test -n "`find $$targetdir -maxdepth 0 -empty`"; then \
      echo rmdir $$targetdir; \
      rmdir $$targetdir; \
    fi; \
  fi;
endef

to_uninstall_headers = $(addprefix uninstall-,$(headers))

$(to_uninstall_headers): $(headers) 
	$(call uninstall_includes,$(subst uninstall-,,$@),$(DESTDIR)$(INCLUDEDIR))

uninstall-headers: $(headers) $(to_uninstall_headers)


# -----------------------------------------------------------------------------
# Creating distribution (for libSBML maintainers only)
# -----------------------------------------------------------------------------

# The `dist-normal' case uses the list of files and diretories in
# $(distfiles) and mirrors their structure in $(DISTDIR)/$(thisdir)/,
# except that files and directories that are also listed in
# $(distfile_exclude) are not copied.

# The $(sort ...) removes duplicates.

sortedfiles = $(sort $(distfiles))

dist-normal: DESTINATION := $(DISTDIR)/$(thisdir)
dist-normal: $(distfiles)
	$(shell [ -d $(DESTINATION) ] || mkdir -p $(DESTINATION))
	@list='$(sortedfiles)'; for file in $$list; do \
	  exlist='$(distfiles_exclude)'; for ex in $$exlist; do \
	    if test $$file = $$ex; then continue 2; fi; \
          done; \
	  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
	  dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
	  if test "$$dir" != "$$file" && test "$$dir" != "."; then \
	    dir="/$$dir"; \
	    $(MKINSTALLDIRS) "$(DESTINATION)/$$dir"; \
	  elif test -d "$$dir"; then \
	    $(MKINSTALLDIRS) "$(DESTINATION)/$$dir"; \
	  else \
	    dir=''; \
	  fi; \
	  if test -d $$d/$$file; then \
	    if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
	      echo Copying $(srcdir)/$$file; \
	      cp -r $(srcdir)/$$file $(DESTINATION)/$$dir || exit 1; \
	    fi; \
	    cp -r $$d/$$file $(DESTINATION)/$$dir || exit 1; \
	  else \
	    echo Copying $(DESTINATION)/$$file; \
	    test -f $(DESTINATION)/$$file \
	    || cp -r $$d/$$file $(DESTINATION)/$$file \
	    || exit 1; \
	  fi; \
	done

#	      $(INSTALL_SH) --mode="u+X,g+X,o+X" $(srcdir)/$$file $(DESTINATION)/$$dir || exit 1; \
#	    $(INSTALL_SH) -d $$d/$$file $(DESTINATION)/$$dir || exit 1; \
#	    || $(INSTALL_SH) --mode="u+X,g+X,o+X" $$d/$$file $(DESTINATION)/$$file \


# -----------------------------------------------------------------------------
# Cleaning
# -----------------------------------------------------------------------------

# This tries to follow the recommended GNU make guidelines.

# Although we don't explicitly use libtool in the hand-written libSBML
# makefiles, the cleaning targets for libtool are included below in case
# someone ever decides to use libtool as part of some make actions.

mostlyclean:        clean-generic mostlyclean-libtool
mostlyclean-normal: clean-generic mostlyclean-libtool

clean:        mostlyclean clean-libraries clean-libtool clean-extras clean-deps
clean-normal: mostlyclean clean-libraries clean-libtool clean-extras clean-deps

clean-generic:
	-rm -f *.$(OBJEXT) *.lo core *.core

clean-libtool:
	-rm -rf .libs _libs

clean-deps:
	-test -z "./$(DEPDIR)" || rm -rf ./$(DEPDIR)

ifdef libraries
  clean-libraries:
	-test -z "$(libraries)" || rm -f $(libraries)
else
  clean-libraries:
endif

ifdef extra_clean
  clean-extras:
	-test -z "$(extra_clean)" || rm -rf $(extra_clean)
else
  clean-extras:
endif

mostlyclean-libtool:
	-rm -f *.lo *.la *.loT

distclean: clean distclean-compile distclean-generic \
	distclean-tags distclean-libtool
distclean-normal: clean distclean-compile distclean-generic \
	distclean-tags distclean-libtool

distclean-compile:
	-rm -f *.tab.c

distclean-generic:
	-rm -f Makefile
ifdef extra_distclean
	-rm -rf $(extra_distclean)
endif

distclean-tags:
	-rm -f TAGS CTAGS ID GTAGS GRTAGS GSYMS GPATH tags

distclean-libtool:
	-rm -f libtool

maintainer-clean:        distclean maintainer-clean-generic
maintainer-clean-normal: distclean maintainer-clean-generic

maintainer-clean-generic:
	-rm -rf $(extra_maintainer_clean)


# -----------------------------------------------------------------------------
# Miscellaneous definitions.
# -----------------------------------------------------------------------------

# The following is for running shell commands with the right XX_LIBRARY_PATH
# variable set for different platforms.

ifeq "$(HOST_TYPE)" "darwin"

  define libsbmlrun
	env DYLD_LIBRARY_PATH=".:$(RUN_LDPATH):$(DYLD_LIBRARY_PATH)" srcdir=$(realpath .) $(LIBTOOL) -dlopen $(TOP_BUILDDIR)/src/libsbml.la --mode=execute $(1)
  endef

else

  define libsbmlrun
	env LD_LIBRARY_PATH=".:$(RUN_LDPATH):$(LD_LIBRARY_PATH)" srcdir=$(realpath .) $(LIBTOOL) -dlopen $(TOP_BUILDDIR)/src/libsbml.la --mode=execute $(1)
  endef

endif


# -----------------------------------------------------------------------------
# Common dependency rules.
# -----------------------------------------------------------------------------
# These rules ensure that files like makefiles are recreated when
# dependencies change.  The rules are generic enough that they apply to the
# top-level source directory as well as the source subdirectories.

Makefile: Makefile.in $(TOP_SRCDIR)/configure \
	     $(TOP_SRCDIR)/config/makefile-common-vars.mk
	cd $(TOP_BUILDDIR) && $(SHELL) ./config.status $(thisdir)/$@

$(TOP_SRCDIR)/config/makefile-common-vars.mk: \
	     $(TOP_SRCDIR)/config/makefile-common-vars.mk.in \
	     $(TOP_SRCDIR)/configure
	cd $(TOP_BUILDDIR) && $(SHELL) ./config.status config/makefile-common-vars.mk

$(TOP_SRCDIR)/config.status: $(TOP_SRCDIR)/configure $(TOP_SRCDIR)/VERSION.txt
	$(SHELL) ./config.status --recheck

$(TOP_SRCDIR)/configure: \
	     $(TOP_SRCDIR)/configure.ac \
	     $(TOP_SRCDIR)/VERSION.txt \
	     $(TOP_SRCDIR)/VERSION_PACKAGES.ac \
	     $(ACLOCAL_M4) \
	     $(wildcard $(TOP_SRCDIR)/config/*.m4)
	cd $(TOP_SRCDIR) && $(AUTOCONF) -Wall --force
	cd $(TOP_SRCDIR) && $(SHELL) ./config.status --recheck

$(ACLOCAL_M4): $(ACINCLUDE_M4) 
	cd $(TOP_SRCDIR) && $(ACLOCAL) -I config

$(TOP_SRCDIR)/config/chk_swig_version.sh: $(TOP_SRCDIR)/configure \
	    $(TOP_BUILDDIR)/config.status \
	    $(TOP_BUILDDIR)/config/chk_swig_version.sh.in
	cd $(TOP_BUILDDIR) && $(SHELL) ./config.status config/chk_swig_version.sh


# -----------------------------------------------------------------------------
# Tags files.
# -----------------------------------------------------------------------------

# 2006-08-09 <mhucka@caltech.edu> Previously I had it create tags in each
# source directory separately, but that turns out to be very inconvenient
# when using tags.  The new formulation is designed to create only one tags
# file, recursively looking in subdirectories for source files to use as
# input.  This is therefore really only meant to be used in the libsbml
# 'src' directory.

etags-version-check: 
	@if test -z "`$(ETAGS) --version 2>&1 | grep 'Free Software'`"; then \
	  echo "Your 'etags' command is not the GNU [X]Emacs version,"; \
	  echo "and I'm afraid I don't know how to work with it. Quitting."; \
	  exit 2; \
	fi

ctags-version-check: 
	@if test -z "`$(CTAGS) --version 2>&1 | grep 'Free Software'`"; then \
	  echo "Your 'ctags' command is not the GNU version, and"; \
	  echo "I'm afraid I don't know how to work with it. Quitting."; \
	  exit 2; \
	fi

etags: etags-version-check TAGS
ctags: ctags-version-check CTAGS

etags-command ?= $(ETAGS) $(ETAGSFLAGS)
ctags-command ?= $(CTAGS) $(CTAGSFLAGS)

files-to-tag := $(shell find . -name '*.c' -o -name '*.cpp' -o -name '*.h')

TAGS: $(files-to-tag)
	$(etags-command) $(files-to-tag)

CTAGS: $(files-to-tag)
	$(ctags-command) $(files-to-tag)


# -----------------------------------------------------------------------------
# Common special targets.
# -----------------------------------------------------------------------------

.PHONY: $(recursive_targets) CTAGS GTAGS docs all all-am check check-am \
	include clean clean-generic clean-libtool ctags \
	dist dist-all dist-gzip distcheck distclean \
	distclean-generic distclean-libtool distclean-tags distcleancheck \
	distdir distuninstallcheck dvi dvi-am info info-am \
	install install-am install-data install-data-am \
	install-exec install-exec-am install-info install-info-am \
	install-man install-strip installcheck installcheck-am installdirs \
	installdirs-am maintainer-clean maintainer-clean-generic mostlyclean \
	mostlyclean-generic mostlyclean-libtool \
	pdf pdf-am ps ps-am tags uninstall uninstall-am uninstall-info-am \
	clean-extras subdirs $(subdirs_recurse) subdist subdistcheck

# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:


# -----------------------------------------------------------------------------
# End.
# -----------------------------------------------------------------------------

## The following is for [X]Emacs users.  Please leave in place.
## Local Variables:
## mode: Makefile
## End: