Makefile.modules 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. #
  2. # $Id$
  3. #
  4. # module Makefile
  5. #(to be included from each module)
  6. #
  7. # History:
  8. # --------
  9. # 2007-03-29 if a module depends on SER_LIBS, it will be rebuilt on install
  10. # with the proper rpath; libraries will be automatically
  11. # installed if needed (andrei)
  12. # 2008-06-23 added the README & man targets (andrei)
  13. # 2008-06-27 make cfg / config.mak support (andrei)
  14. # 2009-03-10 replaced DEFS with C_DEFS and INCLUDES with C_INCLUDES (DEFS
  15. # and INCLUDES are now used only for "temporary" defines/includes
  16. # inside modules or libs) (andrei)
  17. # 2009-10-01 added support for automatically installing extra utils,
  18. # scripts and cfg files (andrei)
  19. # 2010-03-04 don't overwrite already installed .cfgs, save the .cfg as
  20. # .sample in this case (andrei)
  21. #
  22. #
  23. # Variables that should be defined in the modules, prior to including
  24. # this makefile:
  25. #
  26. # NAME - module binary name, complete with .so and no path (MUST).
  27. #
  28. # COREPATH - path to the main/core directory (OPTIONAL, default ../..)
  29. #
  30. # DEFS - per module extra defines (OPTIONAL)
  31. #
  32. # LIBS - per module extra libs (OPTIONAL)
  33. #
  34. # SER_LIBS - ser/sr libs that should be compiled, linked against and installed
  35. # along the module. The format is: <path>/<shortname>, e.g.
  36. # SER_LIBS=../../lib/srdb2/srdb2 for libsrdb2 with the sources
  37. # in ../../lib/srdb2. (OPTIONAL)
  38. #
  39. # MOD_INSTALL_UTILS - list of utils directories that should be compiled and
  40. # installed along the module. The utils must know how to
  41. # install themselves (make install).
  42. # E.g.: MOD_INSTALL_UTILS=../../utils/sercmd
  43. # (OPTIONAL)
  44. #
  45. # MOD_INSTALL_SCRIPTS - list of scripts (complete path including the file name)
  46. # that should be installed along the module.
  47. # E.g.: MOD_INSTALL_SCRIPTS=../../scripts/foo/foo.sh
  48. # (OPTIONAL)
  49. #
  50. # MOD_INSTALL_CFGS - list of extra config files that should be installed in
  51. # the main config directory, along the module (OPTIONAL).
  52. #
  53. # MOD_INSTALL_SHARE - list of files to install into the arch-independent
  54. # shared directory (by default
  55. # /usr/local/share/$(MAIN_NAME))
  56. #
  57. MOD_NAME=$(NAME:.so=)
  58. # allow placing modules in separate directory apart from ser core
  59. COREPATH ?=../..
  60. ALLDEP=Makefile $(COREPATH)/Makefile.sources $(COREPATH)/Makefile.rules \
  61. $(COREPATH)/Makefile.modules $(COREPATH)/Makefile.dirs $(COREPATH)/config.mak
  62. #override modules value, a module cannot have submodules
  63. override modules=
  64. override static_modules=
  65. override static_modules_path=
  66. # should be set in the Makefile of each module
  67. # INCLUDES += -I$(COREPATH)
  68. # temporary def (visible only in the module, not exported)
  69. DEFS += -DMOD_NAME='"$(MOD_NAME)"'
  70. ifeq (,$(findstring -DSER_MOD_INTERFACE, $(DEFS)))
  71. MODIFACE=-DKAMAILIO_MOD_INTERFACE
  72. else
  73. MODIFACE=-DSER_MOD_INTERFACE
  74. endif
  75. ifneq ($(makefile_defs_included),1)
  76. $(error "the local makefile does not include Makefile.defs!")
  77. endif
  78. ifeq ($(MAKELEVEL), 0)
  79. # make called directly in the module dir!
  80. #$(warning "you should run make from the main ser directory")
  81. else
  82. # called by the main Makefile
  83. ALLDEP+=$(COREPATH)/Makefile
  84. endif
  85. include $(COREPATH)/Makefile.sources
  86. # if config was not loaded (makefile_defs!=1) ignore
  87. # the rest of makefile and try only to remake the config
  88. ifeq ($(makefile_defs),1)
  89. ifeq (,$(filter $(MOD_NAME), $(static_modules)))
  90. CFLAGS:=$(MOD_CFLAGS)
  91. LDFLAGS:=$(MOD_LDFLAGS)
  92. endif
  93. err_fail?=1
  94. include $(COREPATH)/Makefile.dirs
  95. include $(COREPATH)/Makefile.targets
  96. include $(COREPATH)/Makefile.rules
  97. include $(COREPATH)/Makefile.shared
  98. # default: if not overwritten by the main Makefile, install in modules
  99. mods_dst=$(modules_prefix)/$(modules_dir)/modules
  100. $(mods_dst):
  101. mkdir -p $(mods_dst)
  102. LIBS:=$(filter-out -ldl -lresolv, $(LIBS))
  103. .PHONY: install
  104. .PHONY: install-libs
  105. .PHONY: install-utils
  106. .PHONY: install-scripts
  107. .PHONY: install-cfgs
  108. install: $(NAME) $(mods_dst) install-libs install-utils install-scripts \
  109. install-cfg install-share
  110. $(INSTALL_TOUCH) $(mods_dst)/$(NAME)
  111. $(INSTALL_MODULES) $(NAME) $(mods_dst)
  112. ifneq (,$(SER_LIBS))
  113. install-libs:
  114. @for lib in $(dir $(SER_LIBS)) ; do \
  115. $(call try_err, $(MAKE) -C "$${lib}" install-if-newer ) ;\
  116. done; true
  117. else
  118. install-libs:
  119. endif # $(SER_LIBS)
  120. .PHONY: utils
  121. .PHONY: clean-utils
  122. .PHONY: proper-utils
  123. .PHONY: distclean-utils
  124. .PHONY: realclean-utils
  125. .PHONY: maintainer-clean-utils
  126. ifneq (,$(MOD_INSTALL_UTILS))
  127. install-utils:
  128. @for ut in $(MOD_INSTALL_UTILS) ; do \
  129. $(call try_err, $(MAKE) -C "$${ut}" install-if-newer ) ;\
  130. done; true
  131. utils:
  132. @for r in $(MOD_INSTALL_UTILS) ; do \
  133. $(call try_err, $(MAKE) -C "$$r" ) ;\
  134. done; true
  135. clean-utils:
  136. @for r in $(MOD_INSTALL_UTILS) ; do \
  137. if [ -d "$$r" ]; then \
  138. $(MAKE) -C "$$r" clean ; \
  139. fi ; \
  140. done
  141. proper-utils realclean-utils distclean-utils maintainer-clean-utils: \
  142. clean_target=$(patsubst %-utils,%,$@)
  143. proper-utils realclean-utils distclean-utils maintainer-clean-utils:
  144. @for r in $(MOD_INSTALL_UTILS) ; do \
  145. if [ -d "$$r" ]; then \
  146. $(MAKE) -C "$$r" $(clean_target); \
  147. fi ; \
  148. done
  149. else
  150. # ! MOD_INSTALL_UTILS
  151. install-utils:
  152. utils:
  153. clean-utils:
  154. proper-utils realclean-utils distclean-utils maintainer-clean-utils:
  155. endif # $(MOD_INSTALL_UTILS)
  156. ifneq (,$(MOD_INSTALL_SCRIPTS))
  157. install-scripts: $(bin_prefix)/$(bin_dir)
  158. @for r in $(MOD_INSTALL_SCRIPTS) ; do \
  159. if [ -n "$$r" ]; then \
  160. if [ -f "$$r" ]; then \
  161. $(call try_err, $(INSTALL_TOUCH) \
  162. $(bin_prefix)/$(bin_dir)/`basename "$$r"` ); \
  163. $(call try_err,\
  164. $(INSTALL_SCRIPT) "$$r" $(bin_prefix)/$(bin_dir) ); \
  165. else \
  166. echo "ERROR: $$r not found" ; \
  167. if [ ${err_fail} = 1 ] ; then \
  168. exit 1; \
  169. fi ; \
  170. fi ; \
  171. fi ; \
  172. done; true
  173. else
  174. install-scripts:
  175. endif # $(MOD_INSTALL_SCRIPTS)
  176. ifneq (,$(MOD_INSTALL_CFGS))
  177. install-cfg: $(cfg_prefix)/$(cfg_dir)
  178. @for r in $(MOD_INSTALL_CFGS) ; do \
  179. if [ -n "$$r" ]; then \
  180. if [ -f "$$r" ]; then \
  181. n=`basename "$$r"` ; \
  182. $(call try_err, $(INSTALL_TOUCH) \
  183. "$(cfg_prefix)/$(cfg_dir)/$$n.sample" ); \
  184. $(call try_err,\
  185. $(INSTALL_CFG) "$$r" \
  186. "$(cfg_prefix)/$(cfg_dir)/$$n.sample"); \
  187. if [ -z "${skip_cfg_install}" -a \
  188. ! -f "$(cfg_prefix)/$(cfg_dir)$$n" ]; then \
  189. mv -f $(cfg_prefix)/$(cfg_dir)$$n.sample \
  190. $(cfg_prefix)/$(cfg_dir)$$n; \
  191. fi ; \
  192. else \
  193. echo "ERROR: $$r not found" ; \
  194. if [ ${err_fail} = 1 ] ; then \
  195. exit 1; \
  196. fi ; \
  197. fi ; \
  198. fi ; \
  199. done; true
  200. else
  201. install-cfg:
  202. endif # $(MOD_INSTALL_CFGS)
  203. ifneq (,$(MOD_INSTALL_SHARE))
  204. install-share: $(share_prefix)/$(share_dir)
  205. @for r in $(MOD_INSTALL_SHARE) ; do \
  206. if [ -n "$$r" ]; then \
  207. if [ -f "$$r" ]; then \
  208. $(call try_err, $(INSTALL_TOUCH) \
  209. $(share_prefix)/$(share_dir)/`basename "$$r"` ); \
  210. $(call try_err,\
  211. $(INSTALL_SHARE) "$$r" $(share_prefix)/$(share_dir) ); \
  212. else \
  213. echo "ERROR: $$r not found" ; \
  214. if [ ${err_fail} = 1 ] ; then \
  215. exit 1; \
  216. fi ; \
  217. fi ; \
  218. fi ; \
  219. done; true
  220. else
  221. install-share:
  222. endif # $(MOD_INSTALL_SHARE)
  223. $(bin_prefix)/$(bin_dir):
  224. mkdir -p $@
  225. $(cfg_prefix)/$(cfg_dir):
  226. mkdir -p $@
  227. $(share_prefix)/$(share_dir):
  228. mkdir -p $@
  229. # README build rules
  230. ifneq (,$(wildcard doc/Makefile))
  231. #doc/Makefile present => we can generate README
  232. README: doc/*.xml ../../docbook/entities.xml
  233. $(MAKE) -C doc $(MOD_NAME).txt
  234. mv doc/$(MOD_NAME).txt $@
  235. else
  236. # do nothing
  237. README:
  238. endif
  239. #man page build rules
  240. ifneq (,$(wildcard $(MOD_NAME).xml))
  241. $(MOD_NAME).7: $(MOD_NAME).xml
  242. $(DOCBOOK) -s ../../doc/stylesheets/serdoc2man.xsl $<
  243. man: $(MOD_NAME).7
  244. else
  245. man:
  246. endif
  247. printmiface:
  248. @echo -n $(MODIFACE)
  249. endif # ifeq($(makefile_defs),1)
  250. include $(COREPATH)/Makefile.cfg