Browse code

makefile: per module extra utils and cfgs install

Support for easy adding per module extra scripts, utils (require
compile) or configs.
The following new module makefile variables are supported:

MOD_INSTALL_UTILS - list of utils directories that should be
compiled and installed along the module. The utils must know how
to install themselves (make install).
E.g.: MOD_INSTALL_UTILS=../../utils/sercmd

MOD_INSTALL_SCRIPTS - list of scripts (complete path including
the file name) that should be installed along the module.
E.g.: MOD_INSTALL_SCRIPTS=../../scripts/foo/foo.sh

MOD_INSTALL_CFGS - list of extra config files that should be
installed in the main config directory.

They should be set before including Makefile.modules.

Andrei Pelinescu-Onciul authored on 01/10/2009 13:51:47
Showing 1 changed files
... ...
@@ -14,8 +14,41 @@
14 14
 #  2009-03-10  replaced DEFS with C_DEFS and INCLUDES with C_INCLUDES (DEFS
15 15
 #              and INCLUDES are now used only for "temporary" defines/includes
16 16
 #              inside modules or libs) (andrei)
17
+#  2009-10-01  added support for automatically installing extra utils,
18
+#               scripts and cfg files (andrei)
17 19
 #
18 20
 
21
+#
22
+# Variables that should be defined in the modules, prior to including
23
+# this makefile:
24
+#
25
+# NAME - module binary name, complete with .so and no path (MUST).
26
+#
27
+# COREPATH - path to the main/core directory (OPTIONAL, default ../..)
28
+#
29
+# DEFS - per module extra defines (OPTIONAL)
30
+#
31
+# LIBS - per module extra libs (OPTIONAL)
32
+#
33
+# SER_LIBS - ser/sr libs that should be compiled, linked against and installed
34
+#           along the module. The format is: <path>/<shortname>, e.g.
35
+#           SER_LIBS=../../lib/srdb2/srdb2 for libsrdb2 with the sources
36
+#            in ../../lib/srdb2. (OPTIONAL)
37
+#
38
+# MOD_INSTALL_UTILS - list of utils directories that should be compiled and
39
+#                     installed along the module. The utils must know how to
40
+#                     install themselves (make install).
41
+#                     E.g.: MOD_INSTALL_UTILS=../../utils/sercmd
42
+#                     (OPTIONAL)
43
+#
44
+# MOD_INSTALL_SCRIPTS - list of scripts (complete path including the file name)
45
+#                       that should be installed along the module.
46
+#                       E.g.: MOD_INSTALL_SCRIPTS=../../scripts/foo/foo.sh
47
+#                       (OPTIONAL)
48
+#
49
+# MOD_INSTALL_CFGS - list of extra config files that should be installed in
50
+#                    the main config directory, along the module (OPTIONAL).
51
+
19 52
 MOD_NAME=$(NAME:.so=)
20 53
 
21 54
 # allow placing modules in separate directory apart from ser core
... ...
@@ -82,14 +115,88 @@ LIBS:=$(filter-out -ldl -lresolv, $(LIBS))
82 82
 
83 83
 .PHONY: install
84 84
 .PHONY: install-libs
85
-install: $(NAME) $(mods_dst) install-libs
85
+.PHONY: install-utils
86
+.PHONY: install-scripts
87
+.PHONY: install-cfgs
88
+install: $(NAME) $(mods_dst) install-libs install-utils install-scripts \
89
+		install-cfg
86 90
 	$(INSTALL_TOUCH) $(mods_dst)/$(NAME)
87 91
 	$(INSTALL_MODULES)  $(NAME)  $(mods_dst)
88 92
 
93
+ifneq (,$(SER_LIBS))
89 94
 install-libs:
90
-	@for lib in $(dir $(SER_LIBS)); do \
95
+	@for lib in $(dir $(SER_LIBS)) ; do \
91 96
 		$(call try_err, $(MAKE) -C "$${lib}" install-if-newer ) ;\
92
-	done
97
+	done; true
98
+
99
+else
100
+install-libs:
101
+
102
+endif # $(SER_LIBS)
103
+
104
+ifneq (,$(MOD_INSTALL_UTILS))
105
+install-utils:
106
+	@for ut in $(MOD_INSTALL_UTILS) ; do \
107
+		$(call try_err, $(MAKE) -C "$${ut}" install-if-newer ) ;\
108
+	done; true
109
+
110
+else
111
+install-utils:
112
+
113
+endif # $(MOD_INSTALL_UTILS)
114
+
115
+ifneq (,$(MOD_INSTALL_SCRIPTS))
116
+install-scripts: $(bin_prefix)/$(bin_dir)
117
+	@for r in $(MOD_INSTALL_SCRIPTS) ; do \
118
+		if [ -n "$$r" ]; then \
119
+			if [ -f "$$r" ]; then \
120
+				$(call try_err, $(INSTALL_TOUCH) \
121
+					$(bin_prefix)/$(bin_dir)/`basename "$$r"` ); \
122
+				$(call try_err,\
123
+					$(INSTALL_SCRIPT)  "$$r"  $(bin_prefix)/$(bin_dir) ); \
124
+			else \
125
+				echo "ERROR: $$r not found" ; \
126
+				if [ ${err_fail} = 1 ] ; then \
127
+					exit 1; \
128
+				fi ; \
129
+			fi ; \
130
+		fi ; \
131
+	done; true
132
+
133
+else
134
+install-scripts:
135
+
136
+endif # $(MOD_INSTALL_SCRIPTS)
137
+
138
+ifneq (,$(MOD_INSTALL_CFGS))
139
+install-cfg: $(cfg_prefix)/$(cfg_dir)
140
+	@for r in $(MOD_INSTALL_CFGS) ; do \
141
+		if [ -n "$$r" ]; then \
142
+			if [ -f "$$r" ]; then \
143
+				$(call try_err, $(INSTALL_TOUCH) \
144
+					$(cfg_prefix)/$(cfg_dir)/`basename "$$r"` ); \
145
+				$(call try_err,\
146
+					$(INSTALL_CFG)  "$$r"  $(cfg_prefix)/$(cfg_dir) ); \
147
+			else \
148
+				echo "ERROR: $$r not found" ; \
149
+				if [ ${err_fail} = 1 ] ; then \
150
+					exit 1; \
151
+				fi ; \
152
+			fi ; \
153
+		fi ; \
154
+	done; true
155
+
156
+else
157
+install-cfg:
158
+
159
+endif # $(MOD_INSTALL_CFGS)
160
+
161
+
162
+$(bin_prefix)/$(bin_dir):
163
+	mkdir -p $@
164
+
165
+$(cfg_prefix)/$(cfg_dir):
166
+	mkdir -p $@
93 167
 
94 168
 # README build rules
95 169
 ifneq (,$(wildcard doc/Makefile))