summaryrefslogtreecommitdiffhomepage
path: root/subr/build.subr
blob: 2a9f80fafcf728a66bbef5199cf0a8e7e02681ac (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
#
# . ./build.vars and set -o errexit -o noglob are assumed.
# See warning at the top of build.vars.
#

check_cpuinfo() {
	if [ -z "${BUILD_CPUS}" ]	\
	&& [ -e /proc/cpuinfo ]; then
		BUILD_CPUS=$(awk '/^processor/{cpus++} END{print cpus}' /proc/cpuinfo);
	fi;
};

clear_env() {
	for __ in $(export | sed -e 's/^export //' -e 's/=.*$//'); do
		if ! match_list "${CLEAR_ENV_VARS_EXCEPT}" " " "${__}"; then
			unset "${__}";
		fi;
	done;
};

check_paths() {
	for __ in ${CHECK_PATH_VARS}; do
		if [ -z "${___:=$(get_var_unsafe "${__}")}" ]; then
			log_msg failexit "Error: variable \`${__}' is empty or unset.";
		elif [ "${___#* *}" != "${___}" ]; then
			log_msg failexit "Error: variable \`${__}' contains one or more whitespace characters.";
		fi;
	done;
	for __ in ${CHECK_PREREQ_CMDS} $(eval echo ${CHECK_PREREQ_FILES_DYNAMIC}) ${CHECK_PREREQ_FILES}; do
		if [ "${__#/}" != "${__}" ]; then
			if [ ! -e "${__}" ]; then
				log_msg fail "Error: missing prerequisite file \`${__}'.";
				__exit=1;
			fi;
		else
			if ! test_cmd "${__}"; then
				log_msg fail "Error: missing prerequisite command \`${__}'.";
				__exit=1;
			fi;
		fi;
	done;
	for __ in ${CHECK_PREREQ_PERL_MODULES}; do
		if ! perl -M"${__}" -e "" 2>/dev/null; then
			log_msg fail "Error: missing prerequisite Perl module \`${__}'.";
			__exit=1;
		fi;
	done;
	if [ ${__exit:-0} = 1 ]; then
		exit 1;
	elif [ -n "${__exit}" ]; then
		unset __exit;
	fi;
};

clean_prefix() {
	if [ ${ARG_CLEAN:-0} -eq 1 ]; then
		log_msg info "-c specified, cleaning prefix...";
		for __ in ${CLEAR_PREFIX_DIRS}; do
			if [ -e ${PREFIX}/${__} ]; then
				secure_rm ${PREFIX}/${__};
			fi;
		done;
	fi;
};

copy_etc() {
	tar -C etc -cpf - midipix_check.sh midipix.sh README midipix_shortcut.vbs	|\
	tar -C ${PREFIX} -xpf -;
	chmod +x ${PREFIX}/midipix.sh;
};

create_dirs() {
	insecure_mkdir ${PREFIX} ${PREFIX_NATIVE} ${PREFIX_CROSS} ${PREFIX_TARGET}/lib ${DLCACHEDIR} ${WORKDIR};
	for __ in ${PREFIX}/usr ${PREFIX_NATIVE}/usr; do
		if [ ! -L "${__}" ]; then
			secure_rm "${__}"; ln -sf -- . "${__}";
		fi;
	done;
	insecure_mkdir ${PREFIX_MINIPIX}/bin;
	for __ in lib libexec share; do
		if [ ! -e ${PREFIX_MINIPIX}/${__} ]; then
			ln -sf bin ${PREFIX_MINIPIX}/${__};
		fi;
	done;
};

fini_build_progress_file() {
	if [ -f "${BUILD_STATUS_IN_PROGRESS_FNAME}" ]; then
		secure_rm ${BUILD_STATUS_IN_PROGRESS_FNAME};
	fi;
};

fini_build_vars() {
	: $((BUILD_TIMES_SECS=$(command date +%s)-${BUILD_TIMES_SECS}));
	: $((BUILD_TIMES_HOURS=${BUILD_TIMES_SECS}/3600));
	: $((BUILD_TIMES_MINUTES=(${BUILD_TIMES_SECS}%3600)/60));
	: $((BUILD_TIMES_SECS=(${BUILD_TIMES_SECS}%3600)%60));
};

init_build_log() {
	if [ -e ${BUILD_LOG_FNAME} ]; then
		mv -- ${BUILD_LOG_FNAME} ${BUILD_LOG_LAST_FNAME};
	fi;
};

init_build_progress_file() {
	touch ${BUILD_STATUS_IN_PROGRESS_FNAME};
};

init_build_vars() {
	BUILD_DATE_START="$(date %Y-%m-%d-%H-%M-%S)";
	BUILD_NFINI=${BUILD_NSKIP:=${BUILD_NFAIL:=${BUILD_NBUILT:=0}}};
	BUILD_TIMES_SECS=$(command date +%s);
};

source_scripts() {
	set -- ${BUILD_PACKAGE_LC%.*} ${BUILD_PACKAGE_LC#*.};
	for SCRIPT_SOURCE in vars/${BUILD_PACKAGE_LC}.vars ${BUILD_SCRIPT_FNAME}; do
		if [ -f ${MIDIPIX_BUILD_PWD}/${SCRIPT_SOURCE} ]; then
			if [ ${ARG_DRYRUN:-0} -eq 1 ]; then
				echo . ${MIDIPIX_BUILD_PWD}/${SCRIPT_SOURCE};
			else
				. ${MIDIPIX_BUILD_PWD}/${SCRIPT_SOURCE};
			fi;
		fi;
	done;
};

source_vars() {
	for __ in ${HOME}/midipix_build.vars ../midipix_build.vars ./vars/build.vars; do
		[ -e ${__} ] && . ${__};
	done;
};

subst_tgts() {
	while [ ${#} -ge 1 ]; do
	case "${1}" in
	devroot)
		echo ${DEVROOT_PACKAGES}; ;;
	world)	echo ${WORLD_PACKAGES}; ;;
	*)	echo ${1}; ;;
	esac; shift;
	done;
};

# vim:filetype=sh