Make --with-pjproject-bundled the default for Asterisk 15
[asterisk/asterisk.git] / build_tools / list_valid_installed_externals
1 #!/usr/bin/env bash
2
3 if [[ ( ${BASH_VERSINFO[0]} == 4 && ${BASH_VERSINFO[1]} > 1 ) || ${BASH_VERSINFO[0]} > 4 ]] ; then
4         shopt -s compat41
5 fi
6 set -e
7
8 ASTTOPDIR=${ASTTOPDIR:-.}
9
10 tmpdir=$(mktemp -d)
11 if [[ -z "${tmpdir}" ]] ; then
12         echo "${module_name}: Unable to create temporary directory."
13         exit 1
14 fi
15 trap "rm -rf ${tmpdir}" EXIT
16
17 # We have to pre-process the makeopts file so it will be parsable by bash
18 # Surround values with double quotes
19 # Convert make  $(or) functions to bash ${name:-value}
20 sed -r  -e "s/^([^ =]+)\s*=\s*(.*)$/\1=\"\2\"/g" \
21         -e 's/^([^ =]+)="\$\(or ([^,]*),([^)]+)\)"/_tmp="\2"\n\1="${_tmp:-\3}"/g'  ${ASTTOPDIR}/makeopts >${tmpdir}/makeopts
22 source ${tmpdir}/makeopts
23 if [[ -z "${ASTMODDIR}" ]] ; then
24         echo "${module_name}: Unable to parse ${ASTTOPDIR}/makeopts."
25         exit 1
26 fi
27
28 XMLSTARLET=${XMLSTARLET:-xmlstarlet}
29 if [[ "${XMLSTARLET}" = ":" ]] ; then
30         echo "${module_name}: The externals downloader requires xmlstarlet to be installed."
31         exit 1
32 fi
33
34 version=$(${ASTTOPDIR}/build_tools/make_version ${ASTTOPDIR})
35 if [[ ! ${version} =~ ^(GIT-)?([^.-]+)[.-].* ]] ; then
36         echo "${module_name}: Couldn't parse version ${version}"
37         exit 1
38 fi
39 major_version=${BASH_REMATCH[2]}.0
40
41 if [[ "${HOST_CPU}" = "x86_64" ]] ; then
42         host_bits=64
43 else
44         host_bits=32
45 fi
46
47 names=""
48 for manifest in ${DESTDIR}${ASTMODDIR}/*.manifest.xml ; do
49         if [ ! -f "$manifest" ] ; then
50                 break
51         fi
52         package_version=$(${XMLSTARLET} sel -t -v "/package/@version" ${manifest})
53         package_major_version=${package_version%_*}
54         package_arch=$(${XMLSTARLET} sel -t -v "/package/@arch" ${manifest})
55         if [[ "$package_major_version" = "$major_version" && "${package_arch}" = "x86_${host_bits}" ]] ; then
56                 names+=$(${XMLSTARLET} sel -t -m "//file[@executable = 'yes']" -v "concat(@name, ' ')" ${manifest})
57         fi
58 done
59 echo $names