Makefile.rules
247c2b65
 #
 # $Id$
 #
 #
 # common Makefile rules, included by main Makefile & the  modules
 #
 
 #
3922c022
 # Uses: NAME, ALLDEP, CC, CFLAGS, DEFS, INCLUDES, LIBS, MKDEP, auto_gen, 
 # auto_gen_others, depends, objs, extra_objs, static_modules, 
 # static_modules_path, LD_RPATH
247c2b65
 # (all this must  be defined previously!,  see Makefile.defs & Makefile)
3922c022
 # Optional: SER_LIBS - list of ser libraries that will be automatically
 #  built if necessary. Format: path/shortname, where shortname is the 
 #  name passed to -l (e.g. for libprint.so the shortname is print)
 #
 # History:
 # --------
 #  2007-03-29  set rpath differently for make install
 #              automatically build listed SER_LIBS if needed (andrei)
247c2b65
 #
 
 
 
 #implicit rules
04bb7a49
 %.o:%.c  $(ALLDEP)
ad1e3e5c
 	$(CC) $(CFLAGS) $(INCLUDES) $(DEFS) -c $< -o $@
247c2b65
 
 %.d: %.c $(ALLDEP)
2e3486a0
 	@set -e; $(MKDEP) $(CFLAGS) $(INCLUDES) $(DEFS) $< \
debad23c
 	|  sed 's#\(\($*D)\)\?$(*F)\)\.o[ :]*#$*.o $@ : #g' > $@; \
247c2b65
 	[ -s $@ ] || rm -f $@
 
3922c022
 # use RPATH and SER_LIBS if needed (make install and the module depends
 # on some ser libs)
 
c853f68a
 ifneq	($(SER_LIBS),)
08067fd5
 # abspath & realpath don't seem to work on darwin
 SER_LIBS_DIRS:=$(dir $(SER_LIBS))
da33ba73
 ifneq	(,$(filter install install% %install, $(MAKECMDGOALS)))
 lib_compile_for_install=yes
 expected_lib_ipath=$(lib_target)
 else
 lib_compile_for_install=no
 # function: expected_lib_ipath ser_lib_dir
 expected_lib_ipath=$(1)
 endif
c853f68a
 ifneq	($(LD_RPATH),)
da33ba73
 ifneq	(,$(filter install install% %install, $(MAKECMDGOALS)))
28b28d2c
 SER_RPATH_LST:=$(lib_target)
3922c022
 else
 SER_RPATH_LST:=$(realpath $(dir $(SER_LIBS)))
 endif
 ifneq	($(strip $(SER_RPATH_LST)),)
 SER_RPATH:=$(addprefix $(LD_RPATH),$(SER_RPATH_LST))
c853f68a
 endif
 endif
da33ba73
 ifeq ($(OS), darwin)
 SER_IPATH_LST:=$(addsuffix /libiname.lst,$(SER_LIBS_DIRS))
 #$(warning $(NAME) DARWIN, SER_LIBS=$(SER_LIBS), $(SER_LIBS_DIRS), ipath_lst=$(SER_IPATH_LST))
 endif
3922c022
 endif
 
 ALL_LIBS=$(LIBS)
 
da33ba73
 ifeq	(,$(filter clean %clean clean% proper %proper proper%, $(MAKECMDGOALS)))
3922c022
 ifneq ($(SER_LIBS),)
 -include librpath.lst
 ifneq ($(SER_RPATH_LST), $(LIB_RPATH_LST))
 $(shell rm -f librpath.lst)
 endif
da33ba73
 endif
3922c022
 
 SER_LIBS_DEPS:= \
 	$(foreach l, $(SER_LIBS), $(dir $l)$(LIB_PREFIX)$(notdir $l)$(LIB_SUFFIX))
 ALL_LIBS+=$(foreach l, $(SER_LIBS), -L$(dir $l) -l$(notdir $l))
 
 $(NAME): $(SER_LIBS_DEPS) librpath.lst
c853f68a
 
3922c022
 $(SER_LIBS_DEPS):
08067fd5
 	$(MAKE) -wC $(dir $@)  compile_for_install=$(lib_compile_for_install)
da33ba73
 
 
 ifneq ($(SER_IPATH_LST),)
 
 $(NAME): $(SER_IPATH_LST) 
 
 $(SER_IPATH_LST): FORCE
08067fd5
 	@if grep \
 		"COMPILED_INAME:=$(call expected_lib_ipath,$(shell cd $(@D); pwd))" \
 		$(@) 1>/dev/null 2>/dev/null ; \
da33ba73
 	then :; \
 	else \
 		echo "re-building $(@D)" ; \
08067fd5
 		$(MAKE) -wC $(@D) compile_for_install=$(lib_compile_for_install) ; \
da33ba73
 	fi
 
 .PHONY: FORCE
 FORCE:
 
 .PHONY: FORCE-BUILD-LIBS
 FORCE-BUILD-LIBS:
 	@for r in $(SER_LIBS_DIRS) ; do \
 		echo building lib $$r; \
08067fd5
 		$(MAKE) -wC $$r compile_for_install=$(lib_compile_for_install) ; \
da33ba73
 	done
 
 endif
3922c022
 
 endif
247c2b65
 
 # normal rules
dcb5f364
 $(NAME): $(objs) $(ALLDEP)
c853f68a
 	$(LD) $(LDFLAGS) $(objs) $(extra_objs) $(ALL_LIBS) $(SER_RPATH) -o $(NAME)
247c2b65
 
 
3922c022
 librpath.lst: $(ALLDEP)
 	@echo LIB_RPATH_LST:=$(SER_RPATH_LST) >librpath.lst
 
247c2b65
 .PHONY: all
 all: $(NAME) modules
 
 .PHONY: dep
 dep: $(depends)
 
404073d3
 .PHONY: static
 static: $(objs)
 
247c2b65
 .PHONY: clean
054cb6cf
 clean: 
3922c022
 	-@rm -f $(objs) $(NAME) $(objs:.o=.il) librpath.lst 2>/dev/null
e7a9bd30
 	-@for r in $(modules) $(static_modules_path) "" ; do \
a65ed385
 		if [ -d "$$r" ]; then \
e7a9bd30
 			echo "module $$r" ; \
 			$(MAKE) -C $$r clean ; \
08067fd5
 			$(MAKE) -C $$r/doc clean ; \
e7a9bd30
 		fi ; \
eddda8ce
 	done 
 	@if [ -n "$(modules)" ]; then \
 		for r in $(utils_compile) "" ; do \
 			if [ -d "$$r" ]; then \
 				 $(MAKE) -C $$r clean ; \
 			fi ; \
 		done \
a65ed385
 	fi
247c2b65
 
 .PHONY: proper
 .PHONY: distclean
 .PHONY: realclean
 proper realclean distclean: clean 
9de818a2
 	-@rm -f $(depends) $(auto_gen) $(auto_gen_others) 2>/dev/null
e7a9bd30
 	-@for r in $(modules) "" ; do \
a65ed385
 		if [ -d "$$r" ]; then \
e7a9bd30
 			 $(MAKE) -C $$r proper ; \
cbd93cf4
 		        $(MAKE) -C $$r/doc proper ; \
e7a9bd30
 		fi ; \
 	done 
eddda8ce
 	@if [ -n "$(modules)" ]; then \
 		for r in $(utils_compile) "" ; do \
 			if [ -d "$$r" ]; then \
 				 $(MAKE) -C $$r proper ; \
 			fi ; \
 		done \
 	fi
247c2b65
 
 .PHONY: mantainer-cleaan
 mantainer-clean: distclean
74121cdb
 	-rm -f TAGS tags *.dbg .*.swp
e7a9bd30
 	-@for r in $(modules) "" ; do \
a65ed385
 		if [ -d "$$r" ]; then \
e7a9bd30
 			$(MAKE) -C $$r mantainer-clean; \
 		fi ; \
 	 done 
 
247c2b65
 
a51f9e36
 .PHONY: doxygen
 doxygen:
 	-@mkdir -p $(doxygen_dir)
 	doxygen ./$(COREPATH)/doc/doxygen/ser.doxygen
 
 
 .PHONY: clean_doxygen
 clean_doxygen:
 	-@rm -rf $(doxygen_dir)/{xml,man,rtf,latex,html}
 	-@rmdir --ignore-fail-on-non-empty -p $(doxygen_dir) || true
 
 
247c2b65
 .PHONY: TAGS
 TAGS:
 	$(MKTAGS) 
 	
04bb7a49
 ifeq (,$(MAKECMDGOALS))
a2dd69c1
 -include $(depends)
04bb7a49
 endif
247c2b65
 ifneq (,$(filter-out clean proper distclean realclean mantainer-clean TAGS \
d4f2d8b0
 		tar modules, $(MAKECMDGOALS)))
a2dd69c1
 -include $(depends)
247c2b65
 endif