Browse Source

- modules are installed by Makefile.modules
- rpath is automatically set up for modules using ser libraries on install
or make (rpath is different for installed modules and for modules only
compiled)
- ser libraries are built and installed automatically if a module needs them
(the module must define SER_LIBS in its makefile). See print_lib for an
example.

Andrei Pelinescu-Onciul 18 years ago
parent
commit
3922c0220e
5 changed files with 101 additions and 34 deletions
  1. 15 18
      Makefile
  2. 6 2
      Makefile.defs
  3. 14 7
      Makefile.libs
  4. 22 1
      Makefile.modules
  5. 44 6
      Makefile.rules

+ 15 - 18
Makefile

@@ -41,7 +41,8 @@
 #               logic when using group_include (greger)
 #  2007-03-01  fail if a module or a required utility make fail unless 
 #              err_fail=0; don't try to make modules with no Makefiles (andrei)
-#  2007-03-16  moved the exports to Makefile.defs
+#  2007-03-16  moved the exports to Makefile.defs (andrei)
+#  2007-03-29  install-modules changed to use make -C modpath install (andrei)
 
 auto_gen=lex.yy.c cfg.tab.c #lexx, yacc etc
 auto_gen_others=cfg.tab.h  # auto generated, non-c
@@ -326,6 +327,7 @@ tar:
 		--exclude=CVS* \
 		--exclude=.svn* \
 		--exclude=.cvsignore \
+		--exclude=librpath.lst \
 		--exclude=*.[do] \
 		--exclude=*.so \
 		--exclude=*.il \
@@ -391,7 +393,7 @@ modules-doc:
 	done 
 
 .PHONY: install
-install: all mk-install-dirs install-cfg install-bin install-modules \
+install: install-bin install-modules install-cfg \
 	install-doc install-man install-utils
 		mv -f $(bin-prefix)/$(bin-dir)/sc $(bin-prefix)/$(bin-dir)/serctl #fix
 
@@ -440,23 +442,18 @@ install-cfg: $(cfg-prefix)/$(cfg-dir)
 		$(INSTALL-CFG) etc/dictionary.ser $(cfg-prefix)/$(cfg-dir)
 #		$(INSTALL-CFG) etc/ser.cfg $(cfg-prefix)/$(cfg-dir)
 
-install-bin: $(bin-prefix)/$(bin-dir) 
-		$(INSTALL-TOUCH) $(bin-prefix)/$(bin-dir)/ser 
-		$(INSTALL-BIN) ser $(bin-prefix)/$(bin-dir)
+install-bin: $(bin-prefix)/$(bin-dir) $(NAME)
+		$(INSTALL-TOUCH) $(bin-prefix)/$(bin-dir)/$(NAME)
+		$(INSTALL-BIN) $(NAME) $(bin-prefix)/$(bin-dir)
 
-install-modules: modules $(modules-prefix)/$(modules-dir)
-	@for r in $(modules_full_path) "" ; do \
-		if [ -n "$$r" ]; then \
-			if [ -f "$$r" ]; then \
-				$(INSTALL-TOUCH) \
-					$(modules-prefix)/$(modules-dir)/`basename "$$r"` ; \
-				$(INSTALL-MODULES)  "$$r"  $(modules-prefix)/$(modules-dir) ; \
-			else \
-				echo "ERROR: module $$r not compiled" ; \
-				if [ ${err_fail} = 1 ] ; then \
-					exit 1; \
-				fi ; \
-			fi ;\
+install-modules: $(modules-prefix)/$(modules-dir)
+	@for r in $(modules) "" ; do \
+		if [ -n "$$r" -a -r "$$r/Makefile" ]; then \
+			echo  "" ; \
+			echo  "" ; \
+			if ! $(MAKE) -C $$r install && [ ${err_fail} = 1 ] ; then \
+				exit 1; \
+			fi ; \
 		fi ; \
 	done; true
 

+ 6 - 2
Makefile.defs

@@ -71,7 +71,7 @@ MAIN_NAME=ser
 VERSION = 2
 PATCHLEVEL = 1
 SUBLEVEL =  0
-EXTRAVERSION = -dev1
+EXTRAVERSION = -dev2
 
 SER_VER = $(shell expr $(VERSION) \* 1000000 + $(PATCHLEVEL) \* 1000 + \
 			$(SUBLEVEL) )
@@ -1266,6 +1266,8 @@ endif
 YACC_FLAGS=-d -b cfg
 # on solaris add -lxnet (e.g. LIBS= -lxnet)
 LIBS= -ldl -lresolv
+LIB_PREFIX:=lib
+LIB_SUFFIX:=.so
 
 
 #os specific stuff
@@ -1455,6 +1457,7 @@ ifeq ($(OS), darwin)
 	LDFLAGS=        # darwin doesn't like -O2 or -E
 	MOD_LDFLAGS:= -bundle -bundle_loader ../../$(MAIN_NAME)
 	LIB_LDFLAGS:= -dynamiclib
+	LIB_SUFFIX:=.dylib
 	# on darwin soname should include the full path
 	# (it kind of combines rpath & soname)
 	LIB_SONAME=
@@ -1497,7 +1500,8 @@ endif
 #export relevant variables to the sub-makes
 export RELEASE OS ARCH
 export DEFS PROFILE CC LD MKDEP MKTAGS CFLAGS LDFLAGS INCLUDES MOD_CFLAGS \
-		MOD_LDFLAGS LIB_CFLAGS LIB_LDFLAGS LIB_SONAME LD_RPATH
+		MOD_LDFLAGS LIB_CFLAGS LIB_LDFLAGS LIB_SONAME LD_RPATH \
+		LIB_SUFFIX LIB_PREFIX
 export LIBS
 export LEX YACC YACC_FLAGS
 export PREFIX LOCALBASE

+ 14 - 7
Makefile.libs

@@ -26,17 +26,18 @@ ifeq ($(BUGFIX_VER),)
 endif
 
 ifeq ($(OS), darwin)
-	LIB_NAME:=lib$(NAME).$(MAJOR_VER).$(MINOR_VER).$(BUGFIX_VER).dylib
-	LIB_RUNTIME_NAME:=lib$(NAME).$(MAJOR_VER).dylib
-	LIB_LINK_NAME:=lib$(NAME).dylib
+	LIB_NAME:= \
+	$(LIB_PREFIX)$(NAME).$(MAJOR_VER).$(MINOR_VER).$(BUGFIX_VER)$(LIB_SUFFIX)
+	LIB_RUNTIME_NAME:=$(LIB_PREFIX)$(NAME).$(MAJOR_VER)$(LIB_SUFFIX)
+	LIB_LINK_NAME:=$(LIB_PREFIX)$(NAME)$(LIB_SUFFIX)
 	NAME_LD_FLAGS:= -compatibility_version $(MAJOR_VER).$(MINOR_VER) \
 					-current_version $(MAJOR_VER).$(MINOR_VER).$(BUGFIX_VER) \
 					-install_name $(lib_target)/$(LIB_RUNTIME_NAME)
 
 else
-	LIB_NAME:=lib$(NAME).so.$(MAJOR_VER).$(MINOR_VER)
-	LIB_RUNTIME_NAME:=lib$(NAME).so.$(MAJOR_VER)
-	LIB_LINK_NAME:=lib$(NAME).so
+	LIB_NAME:=$(LIB_PREFIX)$(NAME)$(LIB_SUFFIX).$(MAJOR_VER).$(MINOR_VER)
+	LIB_RUNTIME_NAME:=$(LIB_PREFIX)$(NAME)$(LIB_SUFFIX).$(MAJOR_VER)
+	LIB_LINK_NAME:=$(LIB_PREFIX)$(NAME)$(LIB_SUFFIX)
 	NAME_LD_FLAGS:= $(LIB_SONAME)$(LIB_RUNTIME_NAME)
 endif
 
@@ -72,7 +73,7 @@ include $(COREPATH)/Makefile.rules
 
 $(NAME): $(LIB_RUNTIME_NAME) $(LIB_LINK_NAME)
 
-$(LIB_RUNTIME_NAME): 
+$(LIB_RUNTIME_NAME):
 	-@ln -s $(LIB_NAME) $(LIB_RUNTIME_NAME)
 
 $(LIB_LINK_NAME):
@@ -99,3 +100,9 @@ install: $(LIB_NAME) $(lib-prefix)/$(lib-dir)
 	ln -s $(lib-prefix)/$(lib-dir)/$(LIB_NAME) \
 			$(lib-prefix)/$(lib-dir)/$(LIB_LINK_NAME) 
 
+
+.PHONY:install-if-newer
+install-if-newer: $(lib-prefix)/$(lib-dir)/$(LIB_RUNTIME_NAME) 
+
+$(lib-prefix)/$(lib-dir)/$(LIB_RUNTIME_NAME): $(LIB_NAME)
+	@$(MAKE) install

+ 22 - 1
Makefile.modules

@@ -4,6 +4,13 @@
 # module Makefile
 #(to be included from each module)
 #
+# History:
+# --------
+#  2007-03-29  if a module depends on SER_LIBS, it will be rebuilt on install
+#               with the proper rpath; libraries will be automatically
+#               installed if needed (andrei)
+#
+
 MOD_NAME=$(NAME:.so=)
 
 # allow place modules in separate directory apart from ser core
@@ -23,7 +30,7 @@ override static_modules_path=
 ifeq ($(MAKELEVEL), 0)
 # make called directly in the module dir!
 
-$(warning "you should run make from the main ser directory")
+#$(warning "you should run make from the main ser directory")
 ifneq ($(makefile_defs), 1)
 $(error "the local makefile does not include Makefile.defs!")
 endif
@@ -42,4 +49,18 @@ CFLAGS:=$(MOD_CFLAGS)
 LDFLAGS:=$(MOD_LDFLAGS)
 endif
 
+
 include $(COREPATH)/Makefile.rules
+
+
+$(modules-prefix)/$(modules-dir):
+		mkdir -p $(modules-prefix)/$(modules-dir)
+
+
+.PHONY: install
+install: $(NAME) $(modules-prefix)/$(modules-dir)
+	$(INSTALL-TOUCH) $(modules-prefix)/$(modules-dir)/$(NAME)
+	$(INSTALL-MODULES)  $(NAME)  $(modules-prefix)/$(modules-dir)
+	@for lib in $(dir $(SER_LIBS)); do \
+		$(MAKE) -C "$${lib}" install-if-newer ;\
+	done

+ 44 - 6
Makefile.rules

@@ -6,9 +6,18 @@
 #
 
 #
-# Uses: NAME, ALLDEP, CC, CFLAGS, DEFS, INCLUDES, LIBS, MKDEP, auto_gen, auto_gen_others,
-# depends, objs, extra_objs, static_modules, static_modules_path
+# 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
 # (all this must  be defined previously!,  see Makefile.defs & Makefile)
+# 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)
 #
 
 
@@ -22,20 +31,49 @@
 	|  sed 's#\(\($*D)\)\?$(*F)\)\.o[ :]*#$*.o $@ : #g' > $@; \
 	[ -s $@ ] || rm -f $@
 
-# use RPATH and SER_LIBS if needed
+# use RPATH and SER_LIBS if needed (make install and the module depends
+# on some ser libs)
+
 ifneq	($(SER_LIBS),)
 ifneq	($(LD_RPATH),)
-SER_RPATH:=$(LD_RPATH)$(lib-target)
+ifneq	(,$(filter install, $(MAKECMDGOALS)))
+SER_RPATH_LST:=$(lib-target)
+else
+SER_RPATH_LST:=$(realpath $(dir $(SER_LIBS)))
+endif
+ifneq	($(strip $(SER_RPATH_LST)),)
+SER_RPATH:=$(addprefix $(LD_RPATH),$(SER_RPATH_LST))
 endif
 endif
+endif
+
+ALL_LIBS=$(LIBS)
+
+ifneq ($(SER_LIBS),)
+-include librpath.lst
+ifneq ($(SER_RPATH_LST), $(LIB_RPATH_LST))
+$(shell rm -f librpath.lst)
+endif
+
+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
 
-ALL_LIBS=$(LIBS) $(SER_LIBS)
+$(SER_LIBS_DEPS):
+	$(MAKE) -C $(dir $@)
+
+endif
 
 # normal rules
 $(NAME): $(objs) $(ALLDEP)
 	$(LD) $(LDFLAGS) $(objs) $(extra_objs) $(ALL_LIBS) $(SER_RPATH) -o $(NAME)
 
 
+librpath.lst: $(ALLDEP)
+	@echo LIB_RPATH_LST:=$(SER_RPATH_LST) >librpath.lst
+
 .PHONY: all
 all: $(NAME) modules
 
@@ -47,7 +85,7 @@ static: $(objs)
 
 .PHONY: clean
 clean: 
-	-@rm -f $(objs) $(NAME) $(objs:.o=.il) 2>/dev/null
+	-@rm -f $(objs) $(NAME) $(objs:.o=.il) librpath.lst 2>/dev/null
 	-@for r in $(modules) $(static_modules_path) "" ; do \
 		if [ -d "$$r" ]; then \
 			echo "module $$r" ; \