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 115
 
83 116
 .PHONY: install
84 117
 .PHONY: install-libs
85
-install: $(NAME) $(mods_dst) install-libs
118
+.PHONY: install-utils
119
+.PHONY: install-scripts
120
+.PHONY: install-cfgs
121
+install: $(NAME) $(mods_dst) install-libs install-utils install-scripts \
122
+		install-cfg
86 123
 	$(INSTALL_TOUCH) $(mods_dst)/$(NAME)
87 124
 	$(INSTALL_MODULES)  $(NAME)  $(mods_dst)
88 125
 
126
+ifneq (,$(SER_LIBS))
89 127
 install-libs:
90
-	@for lib in $(dir $(SER_LIBS)); do \
128
+	@for lib in $(dir $(SER_LIBS)) ; do \
91 129
 		$(call try_err, $(MAKE) -C "$${lib}" install-if-newer ) ;\
92
-	done
130
+	done; true
131
+
132
+else
133
+install-libs:
134
+
135
+endif # $(SER_LIBS)
136
+
137
+ifneq (,$(MOD_INSTALL_UTILS))
138
+install-utils:
139
+	@for ut in $(MOD_INSTALL_UTILS) ; do \
140
+		$(call try_err, $(MAKE) -C "$${ut}" install-if-newer ) ;\
141
+	done; true
142
+
143
+else
144
+install-utils:
145
+
146
+endif # $(MOD_INSTALL_UTILS)
147
+
148
+ifneq (,$(MOD_INSTALL_SCRIPTS))
149
+install-scripts: $(bin_prefix)/$(bin_dir)
150
+	@for r in $(MOD_INSTALL_SCRIPTS) ; do \
151
+		if [ -n "$$r" ]; then \
152
+			if [ -f "$$r" ]; then \
153
+				$(call try_err, $(INSTALL_TOUCH) \
154
+					$(bin_prefix)/$(bin_dir)/`basename "$$r"` ); \
155
+				$(call try_err,\
156
+					$(INSTALL_SCRIPT)  "$$r"  $(bin_prefix)/$(bin_dir) ); \
157
+			else \
158
+				echo "ERROR: $$r not found" ; \
159
+				if [ ${err_fail} = 1 ] ; then \
160
+					exit 1; \
161
+				fi ; \
162
+			fi ; \
163
+		fi ; \
164
+	done; true
165
+
166
+else
167
+install-scripts:
168
+
169
+endif # $(MOD_INSTALL_SCRIPTS)
170
+
171
+ifneq (,$(MOD_INSTALL_CFGS))
172
+install-cfg: $(cfg_prefix)/$(cfg_dir)
173
+	@for r in $(MOD_INSTALL_CFGS) ; do \
174
+		if [ -n "$$r" ]; then \
175
+			if [ -f "$$r" ]; then \
176
+				$(call try_err, $(INSTALL_TOUCH) \
177
+					$(cfg_prefix)/$(cfg_dir)/`basename "$$r"` ); \
178
+				$(call try_err,\
179
+					$(INSTALL_CFG)  "$$r"  $(cfg_prefix)/$(cfg_dir) ); \
180
+			else \
181
+				echo "ERROR: $$r not found" ; \
182
+				if [ ${err_fail} = 1 ] ; then \
183
+					exit 1; \
184
+				fi ; \
185
+			fi ; \
186
+		fi ; \
187
+	done; true
188
+
189
+else
190
+install-cfg:
191
+
192
+endif # $(MOD_INSTALL_CFGS)
193
+
194
+
195
+$(bin_prefix)/$(bin_dir):
196
+	mkdir -p $@
197
+
198
+$(cfg_prefix)/$(cfg_dir):
199
+	mkdir -p $@
93 200
 
94 201
 # README build rules
95 202
 ifneq (,$(wildcard doc/Makefile))