Makefile.modules 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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. ifneq ($(makefile_defs_included),1)
  71. $(error "the local makefile does not include Makefile.defs!")
  72. endif
  73. ifeq ($(MAKELEVEL), 0)
  74. # make called directly in the module dir!
  75. #$(warning "you should run make from the main ser directory")
  76. else
  77. # called by the main Makefile
  78. ALLDEP+=$(COREPATH)/Makefile
  79. endif
  80. include $(COREPATH)/Makefile.sources
  81. # if config was not loaded (makefile_defs!=1) ignore
  82. # the rest of makefile and try only to remake the config
  83. ifeq ($(makefile_defs),1)
  84. ifeq (,$(filter $(MOD_NAME), $(static_modules)))
  85. CFLAGS:=$(MOD_CFLAGS)
  86. LDFLAGS:=$(MOD_LDFLAGS)
  87. endif
  88. err_fail?=1
  89. include $(COREPATH)/Makefile.dirs
  90. include $(COREPATH)/Makefile.targets
  91. include $(COREPATH)/Makefile.rules
  92. include $(COREPATH)/Makefile.shared
  93. # default: if not overwritten by the main Makefile, install in modules
  94. mods_dst=$(modules_prefix)/$(modules_dir)/modules
  95. $(mods_dst):
  96. mkdir -p $(mods_dst)
  97. LIBS:=$(filter-out -ldl -lresolv, $(LIBS))
  98. .PHONY: install
  99. .PHONY: install-libs
  100. .PHONY: install-utils
  101. .PHONY: install-scripts
  102. .PHONY: install-cfgs
  103. install: $(NAME) $(mods_dst) install-libs install-utils install-scripts \
  104. install-cfg install-share
  105. $(INSTALL_TOUCH) $(mods_dst)/$(NAME)
  106. $(INSTALL_MODULES) $(NAME) $(mods_dst)
  107. ifneq (,$(SER_LIBS))
  108. install-libs:
  109. @for lib in $(dir $(SER_LIBS)) ; do \
  110. $(call try_err, $(MAKE) -C "$${lib}" install-if-newer ) ;\
  111. done; true
  112. else
  113. install-libs:
  114. endif # $(SER_LIBS)
  115. .PHONY: utils
  116. .PHONY: clean-utils
  117. .PHONY: proper-utils
  118. .PHONY: distclean-utils
  119. .PHONY: realclean-utils
  120. .PHONY: maintainer-clean-utils
  121. ifneq (,$(MOD_INSTALL_UTILS))
  122. install-utils:
  123. @for ut in $(MOD_INSTALL_UTILS) ; do \
  124. $(call try_err, $(MAKE) -C "$${ut}" install-if-newer ) ;\
  125. done; true
  126. utils:
  127. @for r in $(MOD_INSTALL_UTILS) ; do \
  128. $(call try_err, $(MAKE) -C "$$r" ) ;\
  129. done; true
  130. clean-utils:
  131. @for r in $(MOD_INSTALL_UTILS) ; do \
  132. if [ -d "$$r" ]; then \
  133. $(MAKE) -C "$$r" clean ; \
  134. fi ; \
  135. done
  136. proper-utils realclean-utils distclean-utils maintainer-clean-utils: \
  137. clean_target=$(patsubst %-utils,%,$@)
  138. proper-utils realclean-utils distclean-utils maintainer-clean-utils:
  139. @for r in $(MOD_INSTALL_UTILS) ; do \
  140. if [ -d "$$r" ]; then \
  141. $(MAKE) -C "$$r" $(clean_target); \
  142. fi ; \
  143. done
  144. else
  145. # ! MOD_INSTALL_UTILS
  146. install-utils:
  147. utils:
  148. clean-utils:
  149. proper-utils realclean-utils distclean-utils maintainer-clean-utils:
  150. endif # $(MOD_INSTALL_UTILS)
  151. ifneq (,$(MOD_INSTALL_SCRIPTS))
  152. install-scripts: $(bin_prefix)/$(bin_dir)
  153. @for r in $(MOD_INSTALL_SCRIPTS) ; do \
  154. if [ -n "$$r" ]; then \
  155. if [ -f "$$r" ]; then \
  156. $(call try_err, $(INSTALL_TOUCH) \
  157. $(bin_prefix)/$(bin_dir)/`basename "$$r"` ); \
  158. $(call try_err,\
  159. $(INSTALL_SCRIPT) "$$r" $(bin_prefix)/$(bin_dir) ); \
  160. else \
  161. echo "ERROR: $$r not found" ; \
  162. if [ ${err_fail} = 1 ] ; then \
  163. exit 1; \
  164. fi ; \
  165. fi ; \
  166. fi ; \
  167. done; true
  168. else
  169. install-scripts:
  170. endif # $(MOD_INSTALL_SCRIPTS)
  171. ifneq (,$(MOD_INSTALL_CFGS))
  172. install-cfg: $(cfg_prefix)/$(cfg_dir)
  173. @for r in $(MOD_INSTALL_CFGS) ; do \
  174. if [ -n "$$r" ]; then \
  175. if [ -f "$$r" ]; then \
  176. n=`basename "$$r"` ; \
  177. $(call try_err, $(INSTALL_TOUCH) \
  178. "$(cfg_prefix)/$(cfg_dir)/$$n.sample" ); \
  179. $(call try_err,\
  180. $(INSTALL_CFG) "$$r" \
  181. "$(cfg_prefix)/$(cfg_dir)/$$n.sample"); \
  182. if [ -z "${skip_cfg_install}" -a \
  183. ! -f "$(cfg_prefix)/$(cfg_dir)$$n" ]; then \
  184. mv -f $(cfg_prefix)/$(cfg_dir)$$n.sample \
  185. $(cfg_prefix)/$(cfg_dir)$$n; \
  186. fi ; \
  187. else \
  188. echo "ERROR: $$r not found" ; \
  189. if [ ${err_fail} = 1 ] ; then \
  190. exit 1; \
  191. fi ; \
  192. fi ; \
  193. fi ; \
  194. done; true
  195. else
  196. install-cfg:
  197. endif # $(MOD_INSTALL_CFGS)
  198. ifneq (,$(MOD_INSTALL_SHARE))
  199. install-share: $(share_prefix)/$(share_dir)
  200. @for r in $(MOD_INSTALL_SHARE) ; do \
  201. if [ -n "$$r" ]; then \
  202. if [ -f "$$r" ]; then \
  203. $(call try_err, $(INSTALL_TOUCH) \
  204. $(share_prefix)/$(share_dir)/`basename "$$r"` ); \
  205. $(call try_err,\
  206. $(INSTALL_SHARE) "$$r" $(share_prefix)/$(share_dir) ); \
  207. else \
  208. echo "ERROR: $$r not found" ; \
  209. if [ ${err_fail} = 1 ] ; then \
  210. exit 1; \
  211. fi ; \
  212. fi ; \
  213. fi ; \
  214. done; true
  215. else
  216. install-share:
  217. endif # $(MOD_INSTALL_SHARE)
  218. $(bin_prefix)/$(bin_dir):
  219. mkdir -p $@
  220. $(cfg_prefix)/$(cfg_dir):
  221. mkdir -p $@
  222. $(share_prefix)/$(share_dir):
  223. mkdir -p $@
  224. # README build rules
  225. ifneq (,$(wildcard doc/Makefile))
  226. #doc/Makefile present => we can generate README
  227. README: doc/*.xml
  228. $(MAKE) -C doc $(MOD_NAME).txt
  229. mv doc/$(MOD_NAME).txt $@
  230. else
  231. # do nothing
  232. README:
  233. endif
  234. #man page build rules
  235. ifneq (,$(wildcard $(MOD_NAME).xml))
  236. $(MOD_NAME).7: $(MOD_NAME).xml
  237. docbook2x-man -s ../../doc/stylesheets/serdoc2man.xsl $<
  238. man: $(MOD_NAME).7
  239. else
  240. man:
  241. endif
  242. endif # ifeq($(makefile_defs),1)
  243. include $(COREPATH)/Makefile.cfg