Makefile.libs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. #
  2. # $Id$
  3. #
  4. # module Makefile
  5. #(to be included from each library makefile)
  6. #
  7. # History:
  8. # --------
  9. # 2007-03-16 created by andrei
  10. # 2007-05-19 rebuild on changed install name on darwin (andrei)
  11. # 2008-06-27 make cfg / config.mak support (andrei)
  12. # NAME, MAJOR_VER and MINOR_VER should be pre-defined in the library
  13. # makefile
  14. #
  15. ifneq ($(makefile_defs_included), 1)
  16. $(error "the local makefile does not include Makefile.defs!")
  17. endif
  18. ifneq (,$(filter install% %install install, $(MAKECMDGOALS)))
  19. compile_for_install:=yes
  20. ifeq ($(quiet),verbose)
  21. $(info install mode)
  22. endif # verbose
  23. endif
  24. ifeq ($(NAME),)
  25. $(error NAME, MAJOR_VER and MINOR_VER must be defined in the library Makefile)
  26. endif
  27. ifeq ($(MAJOR_VER),)
  28. $(error NAME, MAJOR_VER and MINOR_VER must be defined in the library Makefile)
  29. endif
  30. ifeq ($(MINOR_VER),)
  31. $(error NAME, MAJOR_VER and MINOR_VER must be defined in the library Makefile)
  32. endif
  33. ifeq ($(BUGFIX_VER),)
  34. BUGFIX_VER:=0
  35. endif
  36. # if config was not loaded (makefile_defs!=1) ignore
  37. # the rest of makefile and try only to remake the config
  38. ifeq ($(makefile_defs),1)
  39. ifeq ($(OS), darwin)
  40. LIB_NAME:= \
  41. $(LIB_PREFIX)$(NAME).$(MAJOR_VER).$(MINOR_VER).$(BUGFIX_VER)$(LIB_SUFFIX)
  42. LIB_RUNTIME_NAME:=$(LIB_PREFIX)$(NAME).$(MAJOR_VER)$(LIB_SUFFIX)
  43. LIB_LINK_NAME:=$(LIB_PREFIX)$(NAME)$(LIB_SUFFIX)
  44. # on darwin we add an extra dependency on a file containing the install
  45. # name (we want to rebuild the library if the install path changed)
  46. # this is needed because instead of a rpath link option, on darwin the
  47. # path to a linked library is taken from the library itself (the path
  48. # is built-in the library)
  49. LIBINAME_F:=libiname.lst
  50. NAME_LD_FLAGS= -compatibility_version $(MAJOR_VER).$(MINOR_VER) \
  51. -current_version $(MAJOR_VER).$(MINOR_VER).$(BUGFIX_VER) \
  52. -install_name $(LIB_INSTALL_NAME)
  53. else
  54. LIB_NAME:=$(LIB_PREFIX)$(NAME)$(LIB_SUFFIX).$(MAJOR_VER).$(MINOR_VER)
  55. LIB_RUNTIME_NAME:=$(LIB_PREFIX)$(NAME)$(LIB_SUFFIX).$(MAJOR_VER)
  56. LIB_LINK_NAME:=$(LIB_PREFIX)$(NAME)$(LIB_SUFFIX)
  57. NAME_LD_FLAGS= $(LIB_SONAME)$(LIB_RUNTIME_NAME)
  58. LIBINAME_F:=
  59. endif
  60. ifeq ($(strip $(compile_for_install)),yes)
  61. LIB_INSTALL_NAME:=$(lib_target)/$(LIB_RUNTIME_NAME)
  62. else
  63. LIB_INSTALL_NAME:=$(shell pwd)/$(LIB_RUNTIME_NAME)
  64. endif
  65. COREPATH ?=../..
  66. ALLDEP=Makefile $(COREPATH)/Makefile.sources $(COREPATH)/Makefile.rules \
  67. $(COREPATH)/Makefile.libs $(COREPATH)/config.mak
  68. ifeq ($(MAKELEVEL), 0)
  69. # make called directly in the library dir!
  70. else
  71. # called by the main Makefile
  72. ALLDEP+=$(COREPATH)/Makefile $(COREPATH)/Makefile.defs
  73. endif
  74. include $(COREPATH)/Makefile.sources
  75. CFLAGS:=$(LIB_CFLAGS)
  76. LDFLAGS:=$(LIB_LDFLAGS) $(NAME_LD_FLAGS)
  77. NAME:=$(LIB_NAME)
  78. include $(COREPATH)/Makefile.targets
  79. include $(COREPATH)/Makefile.rules
  80. ifeq (,$(filter clean %clean clean% proper %proper proper%, $(MAKECMDGOALS)))
  81. ifneq ($(strip $(LIBINAME_F)),)
  82. -include $(LIBINAME_F)
  83. ifneq ($(strip $(LIB_INSTALL_NAME)), $(strip $(COMPILED_INAME)))
  84. $(shell rm -f $(LIBINAME_F))
  85. endif
  86. endif
  87. endif
  88. $(NAME): $(LIB_RUNTIME_NAME) $(LIB_LINK_NAME) $(LIBINAME_F)
  89. $(LIB_RUNTIME_NAME):
  90. -@ln -s $(LIB_NAME) $(LIB_RUNTIME_NAME)
  91. $(LIB_LINK_NAME):
  92. ifeq ($(OS), freebsd)
  93. -@ln -s $(LIB_RUNTIME_NAME) $(LIB_LINK_NAME)
  94. else
  95. -@ln -s $(LIB_NAME) $(LIB_LINK_NAME)
  96. endif
  97. .PHONY: link_clean
  98. link_clean:
  99. -@rm -f $(LIB_RUNTIME_NAME)
  100. -@rm -f $(LIB_LINK_NAME)
  101. local-clean: link_clean
  102. .PHONY: libiname_clean
  103. libiname_clean:
  104. -@rm -f libiname.lst
  105. local-clean: libiname_clean
  106. $(lib_prefix)/$(lib_dir):
  107. mkdir -p $(lib_prefix)/$(lib_dir)
  108. .PHONY: install
  109. install: $(LIB_NAME) $(lib_prefix)/$(lib_dir) $(LIBINAME_F)
  110. ifeq ($(OS), freebsd)
  111. $(INSTALL_TOUCH) $(lib_prefix)/$(lib_dir)/$(LIB_RUNTIME_NAME)
  112. $(INSTALL_LIB) $(LIB_NAME) $(lib_prefix)/$(lib_dir)/$(LIB_RUNTIME_NAME)
  113. rm -f $(lib_prefix)/$(lib_dir)/$(LIB_LINK_NAME)
  114. cd $(lib_prefix)/$(lib_dir) ; ln -s $(LIB_RUNTIME_NAME) $(LIB_LINK_NAME)
  115. else
  116. $(INSTALL_TOUCH) $(lib_prefix)/$(lib_dir)/$(LIB_NAME)
  117. $(INSTALL_LIB) $(LIB_NAME) $(lib_prefix)/$(lib_dir)
  118. rm -f $(lib_prefix)/$(lib_dir)/$(LIB_RUNTIME_NAME) \
  119. $(lib_prefix)/$(lib_dir)/$(LIB_LINK_NAME)
  120. cd $(lib_prefix)/$(lib_dir) ; ln -s $(LIB_NAME) $(LIB_RUNTIME_NAME)
  121. cd $(lib_prefix)/$(lib_dir) ; ln -s $(LIB_NAME) $(LIB_LINK_NAME)
  122. endif
  123. .PHONY:install-if-newer
  124. install-if-newer: $(lib_prefix)/$(lib_dir)/$(LIB_RUNTIME_NAME)
  125. $(lib_prefix)/$(lib_dir)/$(LIB_RUNTIME_NAME): $(LIB_NAME) $(LIBINAME_F)
  126. @$(MAKE) install
  127. ifneq ($(strip $(LIBINAME_F)),)
  128. $(LIBINAME_F): $(ALLDEP)
  129. @echo "COMPILED_INAME:=$(LIB_INSTALL_NAME)" > $(LIBINAME_F)
  130. endif
  131. endif # ifeq ($(makefile_defs),1)
  132. include $(COREPATH)/Makefile.cfg