Browse code

- generic build libs fixes - untested darwin support for automatically setting the library path / rebuilding the lib on changed install path (on darwin the library install path is stored in the library itself and from there it is copied in the linked object => if the library path is changed we have to re-link the library instead of re-linking the object that links it)

Andrei Pelinescu-Onciul authored on 21/05/2007 13:55:51
Showing 3 changed files
... ...
@@ -7,11 +7,17 @@
7 7
 # History:
8 8
 # --------
9 9
 #  2007-03-16  created by andrei
10
+#  2007-05-19  rebuild on changed install name on darwin  (andrei)
10 11
 
11 12
 # NAME, MAJOR_VER and MINOR_VER should be pre-defined in the library 
12 13
 # makefile
13 14
 #
14 15
 
16
+ifneq	(,$(filter install% %install install, $(MAKECMDGOALS)))
17
+compile_for_install:=yes
18
+$(warning install mode => compile_for_install=$(compile_for_install))
19
+endif
20
+
15 21
 ifeq ($(NAME),)
16 22
 $(error NAME, MAJOR_VER and MINOR_VER must be defined in the library Makefile)
17 23
 endif
... ...
@@ -25,20 +31,33 @@ ifeq ($(BUGFIX_VER),)
25 25
 	BUGFIX_VER:=0
26 26
 endif
27 27
 
28
+ifeq	($(strip $(compile_for_install)),yes)
29
+	LIB_INSTALL_NAME:=$(lib_target)/$(LIB_RUNTIME_NAME)
30
+else
31
+	LIB_INSTALL_NAME:=$(shell pwd)/$(LIB_RUNTIME_NAME)
32
+endif
33
+
28 34
 ifeq ($(OS), darwin)
29 35
 	LIB_NAME:= \
30 36
 	$(LIB_PREFIX)$(NAME).$(MAJOR_VER).$(MINOR_VER).$(BUGFIX_VER)$(LIB_SUFFIX)
31 37
 	LIB_RUNTIME_NAME:=$(LIB_PREFIX)$(NAME).$(MAJOR_VER)$(LIB_SUFFIX)
32 38
 	LIB_LINK_NAME:=$(LIB_PREFIX)$(NAME)$(LIB_SUFFIX)
39
+	# on darwin we add an extra dependency on a file containing the install 
40
+	# name (we want to rebuild the library if the install path changed)
41
+	# this is needed because instead of a rpath link option, on darwin the
42
+	# path to a linked library is taken from the library itself (the path
43
+	# is built-in the library)
44
+	LIBINAME_F:=libiname.lst
33 45
 	NAME_LD_FLAGS:= -compatibility_version $(MAJOR_VER).$(MINOR_VER) \
34 46
 					-current_version $(MAJOR_VER).$(MINOR_VER).$(BUGFIX_VER) \
35
-					-install_name $(lib_target)/$(LIB_RUNTIME_NAME)
47
+					-install_name $(LIB_INSTALL_NAME)
36 48
 
37 49
 else
38 50
 	LIB_NAME:=$(LIB_PREFIX)$(NAME)$(LIB_SUFFIX).$(MAJOR_VER).$(MINOR_VER)
39 51
 	LIB_RUNTIME_NAME:=$(LIB_PREFIX)$(NAME)$(LIB_SUFFIX).$(MAJOR_VER)
40 52
 	LIB_LINK_NAME:=$(LIB_PREFIX)$(NAME)$(LIB_SUFFIX)
41 53
 	NAME_LD_FLAGS:= $(LIB_SONAME)$(LIB_RUNTIME_NAME)
54
+	LIBINAME_F:=
42 55
 endif
43 56
 
44 57
 
... ...
@@ -71,7 +90,16 @@ NAME:=$(LIB_NAME)
71 71
 
72 72
 include $(COREPATH)/Makefile.rules
73 73
 
74
-$(NAME): $(LIB_RUNTIME_NAME) $(LIB_LINK_NAME)
74
+ifeq	(,$(filter clean %clean clean% proper %proper proper%, $(MAKECMDGOALS)))
75
+ifneq ($(strip $(LIBINAME_F)),)
76
+-include $(LIBINAME_F)
77
+ifneq ($(strip $(LIB_INSTALL_NAME)), $(strip $(COMPILED_INAME)))
78
+$(shell rm -f $(LIBINAME_F))
79
+endif
80
+endif
81
+endif
82
+
83
+$(NAME): $(LIB_RUNTIME_NAME) $(LIB_LINK_NAME) $(LIBINAME_F)
75 84
 
76 85
 $(LIB_RUNTIME_NAME):
77 86
 	-@ln -s $(LIB_NAME) $(LIB_RUNTIME_NAME)
... ...
@@ -86,11 +114,20 @@ link_clean:
86 86
 
87 87
 clean: link_clean
88 88
 
89
+ifneq ($(strip $(LIBINAME_F)),)
90
+.PHONY: libiname_clean
91
+
92
+libiname_clean:
93
+	-@rm -f "$(LIBINAME_F)"
94
+
95
+clean: libiname_clean
96
+endif
97
+
89 98
 $(lib_prefix)/$(lib_dir):
90 99
 	mkdir -p $(lib_prefix)/$(lib_dir)
91 100
 
92 101
 .PHONY: install
93
-install: $(LIB_NAME) $(lib_prefix)/$(lib_dir)
102
+install: $(LIB_NAME) $(lib_prefix)/$(lib_dir) $(LIBINAME_F)
94 103
 	$(INSTALL_TOUCH) $(lib_prefix)/$(lib_dir)/$(LIB_NAME)
95 104
 	$(INSTALL_LIB) $(LIB_NAME) $(lib_prefix)/$(lib_dir)
96 105
 	rm -f $(lib_prefix)/$(lib_dir)/$(LIB_RUNTIME_NAME) \
... ...
@@ -104,5 +141,11 @@ install: $(LIB_NAME) $(lib_prefix)/$(lib_dir)
104 104
 .PHONY:install-if-newer
105 105
 install-if-newer: $(lib_prefix)/$(lib_dir)/$(LIB_RUNTIME_NAME) 
106 106
 
107
-$(lib_prefix)/$(lib_dir)/$(LIB_RUNTIME_NAME): $(LIB_NAME)
107
+$(lib_prefix)/$(lib_dir)/$(LIB_RUNTIME_NAME): $(LIB_NAME) $(LIBINAME_F)
108 108
 	@$(MAKE) install
109
+
110
+
111
+ifneq ($(strip $(LIBINAME_F)),)
112
+$(LIBINAME_F): $(ALLDEP)
113
+	@echo "COMPILED_INAME:=$(LIB_INSTALL_NAME)" > $(LIBINAME_F)
114
+endif
... ...
@@ -59,9 +59,12 @@ $(modules_prefix)/$(modules_dir):
59 59
 
60 60
 
61 61
 .PHONY: install
62
-install: $(NAME) $(modules_prefix)/$(modules_dir)
62
+.PHONY: install-libs
63
+install: install-libs $(NAME) $(modules_prefix)/$(modules_dir)
63 64
 	$(INSTALL_TOUCH) $(modules_prefix)/$(modules_dir)/$(NAME)
64 65
 	$(INSTALL_MODULES)  $(NAME)  $(modules_prefix)/$(modules_dir)
66
+
67
+install-libs:
65 68
 	@for lib in $(dir $(SER_LIBS)); do \
66 69
 		$(MAKE) -C "$${lib}" install-if-newer ;\
67 70
 	done
... ...
@@ -35,8 +35,18 @@
35 35
 # on some ser libs)
36 36
 
37 37
 ifneq	($(SER_LIBS),)
38
+# realpath doesn't seem to work on darwin
39
+SER_LIBS_DIRS:=$(abspath $(dir $(SER_LIBS)))
40
+ifneq	(,$(filter install install% %install, $(MAKECMDGOALS)))
41
+lib_compile_for_install=yes
42
+expected_lib_ipath=$(lib_target)
43
+else
44
+lib_compile_for_install=no
45
+# function: expected_lib_ipath ser_lib_dir
46
+expected_lib_ipath=$(1)
47
+endif
38 48
 ifneq	($(LD_RPATH),)
39
-ifneq	(,$(filter install, $(MAKECMDGOALS)))
49
+ifneq	(,$(filter install install% %install, $(MAKECMDGOALS)))
40 50
 SER_RPATH_LST:=$(lib_target)
41 51
 else
42 52
 SER_RPATH_LST:=$(realpath $(dir $(SER_LIBS)))
... ...
@@ -45,15 +55,21 @@ ifneq	($(strip $(SER_RPATH_LST)),)
45 45
 SER_RPATH:=$(addprefix $(LD_RPATH),$(SER_RPATH_LST))
46 46
 endif
47 47
 endif
48
+ifeq ($(OS), darwin)
49
+SER_IPATH_LST:=$(addsuffix /libiname.lst,$(SER_LIBS_DIRS))
50
+#$(warning $(NAME) DARWIN, SER_LIBS=$(SER_LIBS), $(SER_LIBS_DIRS), ipath_lst=$(SER_IPATH_LST))
51
+endif
48 52
 endif
49 53
 
50 54
 ALL_LIBS=$(LIBS)
51 55
 
56
+ifeq	(,$(filter clean %clean clean% proper %proper proper%, $(MAKECMDGOALS)))
52 57
 ifneq ($(SER_LIBS),)
53 58
 -include librpath.lst
54 59
 ifneq ($(SER_RPATH_LST), $(LIB_RPATH_LST))
55 60
 $(shell rm -f librpath.lst)
56 61
 endif
62
+endif
57 63
 
58 64
 SER_LIBS_DEPS:= \
59 65
 	$(foreach l, $(SER_LIBS), $(dir $l)$(LIB_PREFIX)$(notdir $l)$(LIB_SUFFIX))
... ...
@@ -62,7 +78,33 @@ ALL_LIBS+=$(foreach l, $(SER_LIBS), -L$(dir $l) -l$(notdir $l))
62 62
 $(NAME): $(SER_LIBS_DEPS) librpath.lst
63 63
 
64 64
 $(SER_LIBS_DEPS):
65
-	$(MAKE) -C $(dir $@)
65
+	$(MAKE) -C $(dir $@)  compile_for_install=$(lib_compile_for_install)
66
+
67
+
68
+ifneq ($(SER_IPATH_LST),)
69
+
70
+$(NAME): $(SER_IPATH_LST) 
71
+
72
+$(SER_IPATH_LST): FORCE
73
+	@if grep "COMPILED_INAME:=$(call expected_lib_ipath,$(@D))" $(@) \
74
+			1>/dev/null 2>/dev/null ; \
75
+	then :; \
76
+	else \
77
+		echo "re-building $(@D)" ; \
78
+		$(MAKE) -C $(@D) compile_for_install=$(lib_compile_for_install) ; \
79
+	fi
80
+
81
+.PHONY: FORCE
82
+FORCE:
83
+
84
+.PHONY: FORCE-BUILD-LIBS
85
+FORCE-BUILD-LIBS:
86
+	@for r in $(SER_LIBS_DIRS) ; do \
87
+		echo building lib $$r; \
88
+		$(MAKE) -C $$r compile_for_install=$(lib_compile_for_install) ; \
89
+	done
90
+
91
+endif
66 92
 
67 93
 endif
68 94