Makefile.rules 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. #
  2. # $Id$
  3. #
  4. #
  5. # common Makefile rules, included by main Makefile & the modules
  6. #
  7. #
  8. # Uses: NAME, ALLDEP, CC, CFLAGS, DEFS, INCLUDES, LIBS, MKDEP, auto_gen,
  9. # auto_gen_others, depends, objs, extra_objs, static_modules,
  10. # static_modules_path, LD_RPATH
  11. # (all this must be defined previously!, see Makefile.defs & Makefile)
  12. # Optional: SER_LIBS - list of ser libraries that will be automatically
  13. # built if necessary. Format: path/shortname, where shortname is the
  14. # name passed to -l (e.g. for libprint.so the shortname is print)
  15. #
  16. # History:
  17. # --------
  18. # 2007-03-29 set rpath differently for make install
  19. # automatically build listed SER_LIBS if needed (andrei)
  20. # 2008-06-23 automatically rebuild if make time defines or includes
  21. # changed (via makecfg.lst)
  22. #
  23. # check if the saved cfg corresponds with the current one
  24. # (if not rebuild everything)
  25. ifeq (,$(filter $(nodep_targets),$(MAKECMDGOALS)))
  26. -include makecfg.lst
  27. ifneq ($(strip $(DEFS)), $(strip $(CFG_DEFS)))
  28. #$(warning different defs: <$(strip $(DEFS))> != )
  29. #$(warning : <$(strip $(CFG_DEFS))>)
  30. $(shell rm -f makecfg.lst)
  31. endif
  32. ifneq ($(INCLUDES), $(CFG_INCLUDES))
  33. $(shell rm -f makecfg.lst)
  34. endif
  35. endif
  36. ALLDEP+=makecfg.lst
  37. #implicit rules
  38. %.o:%.c $(ALLDEP)
  39. $(CC) $(CFLAGS) $(INCLUDES) $(DEFS) -c $< -o $@
  40. %.d: %.c $(ALLDEP)
  41. @set -e; $(MKDEP) $(CFLAGS) $(INCLUDES) $(DEFS) $< \
  42. | sed 's#\(\($(*D)/\)\{0,1\}$(*F)\)\.o[ :]*#$*.o $@ : #g' > $@; \
  43. test -s $@ || ( rm -f $@; false )
  44. # use RPATH and SER_LIBS if needed (make install and the module depends
  45. # on some ser libs)
  46. ifneq ($(SER_LIBS),)
  47. # abspath & realpath don't seem to work on darwin
  48. SER_LIBS_DIRS:=$(dir $(SER_LIBS))
  49. ifneq (,$(filter install install% %install, $(MAKECMDGOALS)))
  50. lib_compile_for_install=yes
  51. expected_lib_ipath=$(lib_target)
  52. else
  53. lib_compile_for_install=no
  54. # function: expected_lib_ipath ser_lib_dir
  55. expected_lib_ipath=$(1)
  56. endif
  57. ifneq ($(LD_RPATH),)
  58. ifneq (,$(filter install install% %install, $(MAKECMDGOALS)))
  59. SER_RPATH_LST:=$(lib_target)
  60. else
  61. SER_RPATH_LST:=$(realpath $(dir $(SER_LIBS)))
  62. endif
  63. ifneq ($(strip $(SER_RPATH_LST)),)
  64. SER_RPATH:=$(addprefix $(LD_RPATH),$(SER_RPATH_LST))
  65. endif
  66. endif
  67. ifeq ($(OS), darwin)
  68. SER_IPATH_LST:=$(addsuffix /libiname.lst,$(SER_LIBS_DIRS))
  69. #$(warning $(NAME) DARWIN, SER_LIBS=$(SER_LIBS), $(SER_LIBS_DIRS), ipath_lst=$(SER_IPATH_LST))
  70. endif
  71. endif
  72. ALL_LIBS=$(LIBS)
  73. ifeq (,$(filter clean %clean clean% proper %proper proper%, $(MAKECMDGOALS)))
  74. ifneq ($(SER_LIBS),)
  75. -include librpath.lst
  76. ifneq ($(SER_RPATH_LST), $(LIB_RPATH_LST))
  77. $(shell rm -f librpath.lst)
  78. endif
  79. endif
  80. SER_LIBS_DEPS:= \
  81. $(foreach l, $(SER_LIBS), $(dir $l)$(LIB_PREFIX)$(notdir $l)$(LIB_SUFFIX))
  82. ALL_LIBS+=$(foreach l, $(SER_LIBS), -L$(dir $l) -l$(notdir $l))
  83. $(NAME): librpath.lst $(SER_LIBS_DEPS)
  84. $(SER_LIBS_DEPS): FORCE
  85. $(MAKE) -wC $(dir $@) compile_for_install=$(lib_compile_for_install)
  86. .PHONY: FORCE
  87. FORCE:
  88. ifneq ($(SER_IPATH_LST),)
  89. $(NAME): $(SER_IPATH_LST)
  90. $(SER_IPATH_LST): FORCE
  91. @if grep \
  92. "COMPILED_INAME:=$(call expected_lib_ipath,$(shell cd $(@D); pwd))" \
  93. $(@) 1>/dev/null 2>/dev/null ; \
  94. then :; \
  95. else \
  96. echo "re-building $(@D)" ; \
  97. $(MAKE) -wC $(@D) compile_for_install=$(lib_compile_for_install) ; \
  98. fi
  99. .PHONY: FORCE-BUILD-LIBS
  100. FORCE-BUILD-LIBS:
  101. @for r in $(SER_LIBS_DIRS) ; do \
  102. echo building lib $$r; \
  103. $(MAKE) -wC $$r compile_for_install=$(lib_compile_for_install) ; \
  104. done
  105. endif
  106. endif
  107. # normal rules
  108. $(NAME): $(objs) $(ALLDEP)
  109. $(LD) $(LDFLAGS) $(objs) $(extra_objs) $(ALL_LIBS) $(SER_RPATH) -o $(NAME)
  110. librpath.lst: $(ALLDEP)
  111. @echo LIB_RPATH_LST:=$(SER_RPATH_LST) >librpath.lst
  112. makecfg.lst:
  113. @echo CFG_DEFS:=$(subst ',\', $(subst ",\", $(strip $(DEFS)))) >>$@
  114. @echo CFG_INCLUDES:=$(subst ',\', $(subst ",\", $(strip $(INCLUDES)))) >>$@
  115. .PHONY: all
  116. all: $(NAME) modules
  117. .PHONY: dep
  118. dep: $(depends)
  119. .PHONY: static
  120. static: $(objs)
  121. .PHONY: clean
  122. clean:
  123. -@rm -f $(objs) $(NAME) $(objs:.o=.il) librpath.lst 2>/dev/null
  124. -@for r in $(modules) $(static_modules_path) "" ; do \
  125. if [ -d "$$r" ]; then \
  126. echo "module $$r" ; \
  127. $(MAKE) -C $$r clean ; \
  128. $(MAKE) -C $$r/doc clean ; \
  129. fi ; \
  130. done
  131. @if [ -n "$(modules)" ]; then \
  132. for r in $(utils_compile) "" ; do \
  133. if [ -d "$$r" ]; then \
  134. $(MAKE) -C $$r clean ; \
  135. fi ; \
  136. done \
  137. fi
  138. .PHONY: proper
  139. .PHONY: distclean
  140. .PHONY: realclean
  141. proper realclean distclean: mrproper
  142. mrproper: clean
  143. -@rm -f $(depends) $(auto_gen) $(auto_gen_others) \
  144. makecfg.lst 2>/dev/null
  145. -@for r in $(modules) "" ; do \
  146. if [ -d "$$r" ]; then \
  147. $(MAKE) -C $$r proper ; \
  148. $(MAKE) -C $$r/doc proper ; \
  149. fi ; \
  150. done
  151. @if [ -n "$(modules)" ]; then \
  152. for r in $(utils_compile) "" ; do \
  153. if [ -d "$$r" ]; then \
  154. $(MAKE) -C $$r proper ; \
  155. fi ; \
  156. done \
  157. fi
  158. .PHONY: mantainer-cleaan
  159. mantainer-clean: distclean
  160. -rm -f TAGS tags *.dbg .*.swp
  161. -@for r in $(modules) "" ; do \
  162. if [ -d "$$r" ]; then \
  163. $(MAKE) -C $$r mantainer-clean; \
  164. fi ; \
  165. done
  166. .PHONY: doxygen
  167. doxygen:
  168. -@mkdir -p $(doxygen_dir)
  169. doxygen ./$(COREPATH)/doc/doxygen/ser.doxygen
  170. .PHONY: clean_doxygen
  171. clean_doxygen:
  172. -@rm -rf $(doxygen_dir)/{xml,man,rtf,latex,html}
  173. -@rmdir --ignore-fail-on-non-empty -p $(doxygen_dir) || true
  174. .PHONY: TAGS
  175. TAGS:
  176. $(MKTAGS)
  177. ifeq (,$(MAKECMDGOALS))
  178. -include $(depends)
  179. else
  180. ifeq (,$(strip $(nodep_targets)))
  181. include Makefile.targets
  182. endif
  183. ifneq (,$(filter-out $(nodep_targets),$(MAKECMDGOALS)))
  184. -include $(depends)
  185. endif
  186. endif # ifeq (,$(MAKECMDGOALS))