Makefile.utils 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #
  2. # $Id$
  3. #
  4. # utils Makefile
  5. #(to be included from each util/ subdirectory)
  6. #
  7. # History:
  8. # --------
  9. # 2009-04-23 initial version derived from Makefile.modules (andrei)
  10. #
  11. # Variables that should be defined in the util Makefiles, prior to including
  12. # this makefile:
  13. #
  14. # NAME - util binary name, with no path (MUST).
  15. #
  16. # COREPATH - path to the main/core directory (OPTIONAL, default ../..)
  17. #
  18. # DEFS - local extra defines (OPTIONAL)
  19. #
  20. # LIBS - local extra libs (OPTIONAL)
  21. #
  22. # SER_LIBS - ser/sr libs that should be compiled, linked against and installed
  23. # along the binary. The format is: <path>/<shortname>, e.g.
  24. # SER_LIBS=../../lib/srdb2/srdb2 for libsrdb2 with the sources
  25. # in ../../lib/srdb2. (OPTIONAL)
  26. #
  27. UTIL_NAME=$(NAME)
  28. # default path to the core makefiles
  29. COREPATH ?=../..
  30. ALLDEP=Makefile $(COREPATH)/Makefile.sources $(COREPATH)/Makefile.rules \
  31. $(COREPATH)/Makefile.utils $(COREPATH)/Makefile.dirs $(COREPATH)/config.mak
  32. #override modules value, an util cannot have submodules
  33. override modules=
  34. override static_modules=
  35. override static_modules_path=
  36. # temporary def (visible only in the util makefile, not exported)
  37. DEFS += -DMOD_NAME="utils/$(UTIL_NAME)"
  38. ifneq ($(makefile_defs_included),1)
  39. $(error "the local makefile does not include Makefile.defs!")
  40. endif
  41. ifeq ($(MAKELEVEL), 0)
  42. # make called directly in the module dir!
  43. else
  44. # called by the main Makefile
  45. ALLDEP+=$(COREPATH)/Makefile
  46. endif
  47. include $(COREPATH)/Makefile.sources
  48. # if config was not loaded (makefile_defs!=1) ignore
  49. # the rest of makefile and try only to remake the config
  50. ifeq ($(makefile_defs),1)
  51. # set CFLAGS & LDFLAGS
  52. CFLAGS:=$(UTILS_CFLAGS)
  53. LDFLAGS:=$(UTILS_LDFLAGS)
  54. err_fail?=1
  55. include $(COREPATH)/Makefile.dirs
  56. include $(COREPATH)/Makefile.targets
  57. include $(COREPATH)/Makefile.rules
  58. include $(COREPATH)/Makefile.shared
  59. # default: if not overwritten by the main Makefile, install in bin_dir
  60. util_dst=$(bin_prefix)/$(bin_dir)
  61. $(util_dst):
  62. mkdir -p $(util_dst)
  63. modules:
  64. .PHONY: install
  65. .PHONY: install-libs
  66. install: $(NAME) $(util_dst) install-libs install-util-man
  67. $(INSTALL_TOUCH) $(util_dst)/$(NAME)
  68. $(INSTALL_BIN) $(NAME) $(util_dst)
  69. ifneq (,$(SER_LIBS))
  70. install-libs:
  71. @for lib in $(dir $(SER_LIBS)); do \
  72. $(call try_err, $(MAKE) -C "$${lib}" install-if-newer ) ;\
  73. done; true
  74. else
  75. install-libs:
  76. endif # $(SER_LIBS)
  77. .PHONY: install-if-newer
  78. install-if-newer: $(util_dst)/$(NAME)
  79. $(util_dst)/$(NAME): $(NAME)
  80. @$(MAKE) install
  81. # README build rules
  82. ifneq (,$(wildcard doc/Makefile))
  83. #doc/Makefile present => we can generate README
  84. README: doc/*.xml
  85. $(MAKE) -C doc $(UTIL_NAME).txt
  86. mv doc/$(UTIL_NAME).txt $@
  87. else
  88. # do nothing
  89. README:
  90. endif
  91. #man page build rules
  92. ifneq (,$(wildcard $(UTIL_NAME).xml))
  93. $(UTIL_NAME).7: $(UTIL_NAME).xml
  94. $(DOCBOOK) -s ../../doc/stylesheets/serdoc2man.xsl $<
  95. man: $(UTIL_NAME).7
  96. else
  97. man:
  98. endif
  99. $(man_prefix)/$(man_dir)/man8:
  100. mkdir -p $(man_prefix)/$(man_dir)/man8
  101. .PHONY: install-util-man
  102. #src-name man page install rules
  103. ifneq (,$(wildcard $(UTIL_SRC_NAME).8))
  104. install-util-man: $(man_prefix)/$(man_dir)/man8
  105. sed -e "s#$(UTIL_SRC_NAME)#$(UTIL_NAME)#g" \
  106. -e "s#$(SRC_NAME)#$(MAIN_NAME)#g" \
  107. < $(UTIL_SRC_NAME).8 > $(man_prefix)/$(man_dir)/man8/$(UTIL_NAME).8
  108. chmod 644 $(man_prefix)/$(man_dir)/man8/$(UTIL_NAME).8
  109. else
  110. install-util-man:
  111. endif
  112. endif # ifeq($(makefile_defs),1)
  113. include $(COREPATH)/Makefile.cfg