2
0

unix-common.mk 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # -*-makefile-*- <-- an Emacs control
  2. # The including make file must define these make variables:
  3. #
  4. # SHARED_LIBS_TO_BUILD: List of the shared libraries that need to be
  5. # built -- just the basic library names. E.g. "libfoo libbar"
  6. #
  7. # SHARED_LIBS_TO_INSTALL: List of the shared libraries that need to be
  8. # installed -- just the basic library names. E.g. "libfoo libbar"
  9. #
  10. # SHLIB_SUFFIX: Shared library filename suffix, e.g. "so".
  11. #
  12. # MAJ: Library major version number, e.g. "3" in file name "libfoo.3.1"
  13. #
  14. # MIN: Library minor version number, e.g. "1" in file name "libfoo.3.1"
  15. #
  16. # LDFLAGS_SHLIB: linker (Ld) flags needed to link object files together into
  17. # a shared library. May use $(SONAME) for the soname of the library.
  18. # Include -lc if appropriate.
  19. #
  20. # LADD: Additional linker flags (normally set on the make command line).
  21. #
  22. # INSTALL_DATA: beginning of shell command to install a library file.
  23. #
  24. # DESTDIR: main installation directory
  25. #
  26. # LIBINST_DIR: directory in which to install libraries, relative to DESTDIR.
  27. #
  28. # LN_S: beginning of shell command to make symbolic link (e.g. "ln -s").
  29. #
  30. # CXXLD: beginning of shell command to link, e.g. "g++".
  31. # This make file defines these make variables that the including make file
  32. # can use:
  33. #
  34. # SHLIB_CMD: a command to build a shared library for C linkage
  35. # You can use this in a rule to build a shared library
  36. # SHLIBPP_CMD: Same, but for C++ linkage
  37. # Including make file must contain a rule to build each library file
  38. # (e.g. libfoo.3.1)
  39. # This make file provides these rules:
  40. #
  41. # install-shared-libraries: install all shared libraries and the necessary
  42. # symbolic links.
  43. # SONAME is to be referenced by $(LDFLAGS_SHLIB) in the rule to make
  44. # a shared library (in common.mk). I.e. $@ is the name of the shared
  45. # library file.
  46. # SONAME is the name of the library file being built, with the minor
  47. # version number cut off. E.g. if we're building libfoo.so.1.2, SONAME
  48. # is libfoo.so.1 .
  49. SONAME = $(@:%.$(MIN)=%)
  50. SHLIB_CMD = $(CCLD) $(LADD) $(LDFLAGS_SHLIB) -o $@ $^
  51. SHLIB_LE_TARGETS = $(call shliblefn, $(SHARED_LIBS_TO_BUILD))
  52. $(SHLIB_LE_TARGETS):%:%.$(MAJ).$(MIN)
  53. rm -f $@
  54. $(LN_S) $< $@
  55. .PHONY: $(SHLIB_INSTALL_TARGETS)
  56. .PHONY: install-shared-libraries
  57. SHLIB_INSTALL_TARGETS = $(SHARED_LIBS_TO_INSTALL:%=%/install)
  58. #SHLIB_INSTALL_TARGETS is like "libfoo/install libbar/install"
  59. install-shared-libraries: $(SHLIB_INSTALL_TARGETS)
  60. $(SHLIB_INSTALL_TARGETS):%/install:%.$(SHLIB_SUFFIX).$(MAJ).$(MIN)
  61. # $< is a library file name, e.g. libfoo.so.3.1 .
  62. $(INSTALL_SHLIB) $< $(DESTDIR)$(LIBINST_DIR)/$<
  63. cd $(DESTDIR)$(LIBINST_DIR); \
  64. rm -f $(<:%.$(MIN)=%); \
  65. $(LN_S) $< $(<:%.$(MIN)=%)
  66. cd $(DESTDIR)$(LIBINST_DIR); \
  67. rm -f $(<:%.$(MAJ).$(MIN)=%); \
  68. $(LN_S) $(<:%.$(MIN)=%) $(<:%.$(MAJ).$(MIN)=%)