summaryrefslogtreecommitdiffhomepage
path: root/subr.ex/ex_rtl_make.subr
blob: 6867dfad44023063e821a8a3a4be7c345f98fa94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#
# Copyright (c) 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 Lucía Andrea Illanes Albornoz <lucia@luciaillanes.de>
# set +o errexit -o noglob -o nounset is assumed.
#
# Package make command execution
#

#
# ex_rtl_make() - run make(1)
# @_ar:				ar(1) command name or pathname
# @_cc:				C compiler command name or pathname
# @_cxx:			C++ compiler command name or pathname
# @_ld:				ld(1) command name or pathname
# @_libtool:			libtool(1) command name or pathname or "none"
# @_make:			make(1) command name or pathname
# @_pkg_config:			pkg-config(1) command name or pathname
# @_ranlib:			ranlib(1) command name or pathname
# @--:				(ignored)
# @_set_ccfl:			1 if CC=... is to be passed to make(1), 0 if CC=... is not to be passed to make(1)
# @_subdir:			make(1) -C argument
# @--:				(ignored)
# @_makeflags:			make(1) flags as a whitespace-separated list
# @_makeflags_extra:		extra make(1) flags as a whitespace-separated likst
# @_makeflags_list:		make(1) flags as a :-separated list
# @_makeflags_extra_list:	extra make(1) flags as a :-separated list
# @_makeflags_loadavg:		make(1) -l load argument
# @_makeflags_parallelise:	make(1) -j jobs argument
# @_makeflags_verbosity:	make(1) Makefile verbosity arguments or "none"
# @--:				(ignored)
# @_cflags:			$CFLAGS
# @_cflags_extra:		extra $CFLAGS
# @_cppflags:			$CPPFLAGS
# @_cppflags_extra:		extra $CPPFLAGS
# @_cxxflags:			$CXXFLAGS
# @_cxxflags_extra:		extra $CXXFLAGS
# @_ldflags:			$LDFLAGS
# @_ldflags_extra:		extra $LDFLAGS
# @_pkg_config_libdir:		pkg-config(1) search directory
# @--:				(ignored)
# @_destdir_spec:		DESTDIR=... specification
# @_target:			make(1) target
#
# Returns:			zero (0) on success, non-zero (>0) on failure
#
ex_rtl_make() {
	local	_erm_ar="${1}" _erm_cc="${2}" _erm_cxx="${3}" _erm_ld="${4}"			\
		_erm_libtool="${5}" _erm_make="${6}" _erm_pkg_config="${7}" _erm_ranlib="${8}"	\
		_erm_ignored="${9}"								\
		_erm_set_ccfl="${10}" _erm_subdir="${11}"					\
		_erm_ignored="${12}"								\
		_erm_makeflags="${13}" _erm_makeflags_extra="${14}" _erm_makeflags_list="${15}"	\
		_erm_makeflags_extra_list="${16}" _erm_makeflags_loadavg="${17}"		\
		_erm_makeflags_parallelise="${18}" _erm_makeflags_verbosity="${19}"		\
		_erm_ignored="${20}"								\
		_erm_cflags="${21}" _erm_cflags_extra="${22}" _erm_cppflags="${23}"		\
		_erm_cppflags_extra="${24}" _erm_cxxflags="${25}" _erm_cxxflags_extra="${26}"	\
		_erm_ldflags="${27}" _erm_ldflags_extra="${28}" _erm_pkg_config_libdir="${29}"	\
		_erm_ignored="${30}"								\
		_erm_destdir_spec="${31}" _erm_target="${32}"					\
		_erm_rc=0;

	case "${_erm_makeflags_loadavg:-}" in
	none) _erm_makeflags_loadavg=""; ;;
	esac;

	case "${_erm_libtool:-}" in
	none) _erm_libtool=""; ;;
	esac;

	case "${_erm_makeflags_verbosity}" in
	none) _erm_makeflags_verbosity=""; ;;
	esac;

	case "${_erm_set_ccfl}" in
	1) _erm_set_ccfl="1"; ;;
	*) _erm_set_ccfl=""; ;;
	esac;

(
	if [ "${_erm_libtool:+1}" = 1 ]; then
		export MAKE="make LIBTOOL=${_erm_libtool}";
	fi;

	if [ "${_erm_makeflags_list:+1}" = 1 ]; then
		rtl_run_cmdlineV ":" "${_erm_make}"							\
			AR="${_erm_ar}"									\
			${_erm_set_ccfl:+CC="${_erm_cc}"}						\
			${_erm_set_ccfl:+CXX="${_erm_cxx}"}						\
			LD="${_erm_ld}"									\
			${_erm_libtool:+LIBTOOL="${_erm_libtool}"}					\
			${_erm_pkg_config:+PKG_CONFIG="${_erm_pkg_config}"}				\
			RANLIB="${_erm_ranlib}"								\
													\
			"${_erm_makeflags_list}"							\
			"${_erm_makeflags_extra_list:-}"						\
			${_erm_makeflags_loadavg:-}							\
			${_erm_makeflags_parallelise:-}							\
			${_erm_makeflags_verbosity}							\
													\
			${_erm_cflags:+CFLAGS="${_erm_cflags}"}						\
			${_erm_cflags_extra:+CFLAGS+="${_erm_cflags_extra}"}				\
			${_erm_cppflags:+CPPFLAGS="${_erm_cppflags}"}					\
			${_erm_cppflags_extra:+CPPFLAGS+="${_erm_cppflags_extra}"}			\
			${_erm_cxxflags:+CXXFLAGS="${_erm_cxxflags}"}					\
			${_erm_cxxflags_extra:+CXXFLAGS+="${_erm_cxxflags_extra}"}			\
			${_erm_ldflags:+LDFLAGS="${_erm_ldflags}"}					\
			${_erm_ldflags_extra:+LDFLAGS+="${_erm_ldflags_extra}"}				\
			${_erm_pkg_config_libdir:+PKG_CONFIG_LIBDIR="${_erm_pkg_config_libdir}"}	\
													\
			${_erm_subdir:+-C "${_erm_subdir}"}						\
			${_erm_destdir_spec:+"${_erm_destdir_spec}"}					\
			${_erm_target:+"${_erm_target}"}						\
			;
		exit "${?}";
	elif [ "${_erm_makeflags_extra_list:+1}" = 1 ]; then
		rtl_run_cmdlineV ":" "${_erm_make}"							\
			AR="${_erm_ar}"									\
			${_erm_set_ccfl:+CC="${_erm_cc}"}						\
			${_erm_set_ccfl:+CXX="${_erm_cxx}"}						\
			LD="${_erm_ld}"									\
			${_erm_libtool:+LIBTOOL="${_erm_libtool}"}					\
			${_erm_pkg_config:+PKG_CONFIG="${_erm_pkg_config}"}				\
			RANLIB="${_erm_ranlib}"								\
													\
			${_erm_makeflags:-}								\
			"${_erm_makeflags_extra_list}"							\
			${_erm_makeflags_loadavg:-}							\
			${_erm_makeflags_parallelise:-}							\
			${_erm_makeflags_verbosity}							\
													\
			${_erm_cflags:+CFLAGS="${_erm_cflags}"}						\
			${_erm_cflags_extra:+CFLAGS+="${_erm_cflags_extra}"}				\
			${_erm_cppflags:+CPPFLAGS="${_erm_cppflags}"}					\
			${_erm_cppflags_extra:+CPPFLAGS+="${_erm_cppflags_extra}"}			\
			${_erm_cxxflags:+CXXFLAGS="${_erm_cxxflags}"}					\
			${_erm_cxxflags_extra:+CXXFLAGS+="${_erm_cxxflags_extra}"}			\
			${_erm_ldflags:+LDFLAGS="${_erm_ldflags}"}					\
			${_erm_ldflags_extra:+LDFLAGS+="${_erm_ldflags_extra}"}				\
			${_erm_pkg_config_libdir:+PKG_CONFIG_LIBDIR="${_erm_pkg_config_libdir}"}	\
													\
			${_erm_subdir:+-C "${_erm_subdir}"}						\
			${_erm_destdir_spec:+"${_erm_destdir_spec}"}					\
			${_erm_target:+"${_erm_target}"}						\
			;
		exit "${?}";
	else
		rtl_run_cmdlineV ":" "${_erm_make}"							\
			AR="${_erm_ar}"									\
			${_erm_set_ccfl:+CC="${_erm_cc}"}						\
			${_erm_set_ccfl:+CXX="${_erm_cxx}"}						\
			LD="${_erm_ld}"									\
			${_erm_libtool:+LIBTOOL="${_erm_libtool}"}					\
			${_erm_pkg_config:+PKG_CONFIG="${_erm_pkg_config}"}				\
			RANLIB="${_erm_ranlib}"								\
													\
			${_erm_makeflags:-}								\
			${_erm_makeflags_extra:-}							\
			${_erm_makeflags_loadavg:-}							\
			${_erm_makeflags_parallelise:-}							\
			${_erm_makeflags_verbosity}							\
													\
			${_erm_cflags:+CFLAGS="${_erm_cflags}"}						\
			${_erm_cflags_extra:+CFLAGS+="${_erm_cflags_extra}"}				\
			${_erm_cppflags:+CPPFLAGS="${_erm_cppflags}"}					\
			${_erm_cppflags_extra:+CPPFLAGS+="${_erm_cppflags_extra}"}			\
			${_erm_cxxflags:+CXXFLAGS="${_erm_cxxflags}"}					\
			${_erm_cxxflags_extra:+CXXFLAGS+="${_erm_cxxflags_extra}"}			\
			${_erm_ldflags:+LDFLAGS="${_erm_ldflags}"}					\
			${_erm_ldflags_extra:+LDFLAGS+="${_erm_ldflags_extra}"}				\
			${_erm_pkg_config_libdir:+PKG_CONFIG_LIBDIR="${_erm_pkg_config_libdir}"}	\
													\
			${_erm_subdir:+-C "${_erm_subdir}"}						\
			${_erm_destdir_spec:+"${_erm_destdir_spec}"}					\
			${_erm_target:+"${_erm_target}"}						\
			;
		exit "${?}";
	fi;
);
	_erm_rc="${?}";

	return "${_erm_rc}";
};

# vim:filetype=sh textwidth=0