7748c21
#!/bin/bash
7748c21
7748c21
# This script reads filenames from STDIN and outputs any relevant provides
7748c21
# information that needs to be included in the package.
7748c21
7748c21
BUILDDIR=
7748c21
7748c21
while true; do
7748c21
	case "$1" in
7748c21
		-b) BUILDDIR="$2"; shift 2;;
7748c21
		--) shift; break;;
7748c21
		*) echo "$0: option error at $1"; exit 1;;
7748c21
	esac
7748c21
done
7748c21
7748c21
filelist=`sed "s/['\"]/\\\&/g"`
7748c21
7748c21
/usr/lib/rpm/rpmdeps --provides $filelist
7748c21
7748c21
# Get the list of *.app files
7748c21
appfiles=$(echo $filelist | tr [:blank:] '\n' | grep -o -E '.*/ebin/.*\.app$')
7748c21
7748c21
for f in $appfiles; do
7748c21
	app=`cat $f | tr -d [:space:] | awk -F '{application,' '{print $2}'|cut -d , -f 1`
7748c21
	ver=`cat $f | tr -d [:space:] | grep -o -E '\{vsn,\".*[0-9]\"\}' | sed -e "s,.vsn\,\",,g;s,\".,,g"`
7748c21
7748c21
	# HiPE module is different from others
7748c21
	if [ "$app" == "hipe" ] ;
7748c21
	then
7748c21
		# Hardcoded minimal set of HiPE exported functions
7748c21
		echo "erlang(hipe_amd64_main:rtl_to_amd64/3)"
7748c21
		echo "erlang(hipe_arm_main:rtl_to_arm/3)"
7748c21
		echo "erlang(hipe:c/1)"
7748c21
		echo "erlang(hipe:compile/4)"
7748c21
		echo "erlang(hipe_data_pp:pp/4)"
7748c21
		echo "erlang(hipe_icode2rtl:translate/2)"
7748c21
		echo "erlang(hipe_icode_heap_test:cfg/1)"
7748c21
		echo "erlang(hipe_ppc_main:rtl_to_ppc/3)"
7748c21
		echo "erlang(hipe_rtl_arch:endianess/0)"
7748c21
		echo "erlang(hipe_rtl_arch:nr_of_return_regs/0)"
7748c21
		echo "erlang(hipe_rtl_arch:word_size/0)"
7748c21
		echo "erlang(hipe_rtl_cfg:init/1)"
7748c21
		echo "erlang(hipe_rtl_cfg:linearize/1)"
7748c21
		echo "erlang(hipe_rtl_cfg:pp/1)"
7748c21
		echo "erlang(hipe_rtl_cfg:remove_trivial_bbs/1)"
7748c21
		echo "erlang(hipe_rtl_cfg:remove_unreachable_code/1)"
7748c21
		echo "erlang(hipe_rtl_cleanup_const:cleanup/1)"
7748c21
		echo "erlang(hipe_rtl_lcm:rtl_lcm/2)"
7748c21
		echo "erlang(hipe_rtl_ssa_avail_expr:cfg/1)"
7748c21
		echo "erlang(hipe_rtl_ssa:check/1)"
7748c21
		echo "erlang(hipe_rtl_ssa_const_prop:propagate/1)"
7748c21
		echo "erlang(hipe_rtl_ssa:convert/1)"
7748c21
		echo "erlang(hipe_rtl_ssapre:rtl_ssapre/2)"
7748c21
		echo "erlang(hipe_rtl_ssa:remove_dead_code/1)"
7748c21
		echo "erlang(hipe_rtl_ssa:unconvert/1)"
7748c21
		echo "erlang(hipe_rtl_symbolic:expand/1)"
7748c21
		echo "erlang(hipe_sparc_main:rtl_to_sparc/3)"
7748c21
		echo "erlang(hipe_tagscheme:fixnum_val/1)"
7748c21
		echo "erlang(hipe_tagscheme:is_fixnum/1)"
7748c21
		echo "erlang(hipe_x86_main:rtl_to_x86/3)"
7748c21
	fi
7748c21
7748c21
	echo "erlang($app) = $ver"
7748c21
done
7748c21
859b2ca
# Check for two special cases by inspecting path to ebin directory
7748c21
basedirs=$(echo $filelist | tr [:blank:] '\n' | grep -o -E 'erlang\/lib\/[a-zA-Z_0-9]*-[0-9.]*\/ebin' | cut -d \/ -f 3 | sort | uniq)
7748c21
for bd in $basedirs; do
7748c21
	basename=`echo $bd | cut -d \- -f 1`
7748c21
	basever=`echo $bd | cut -d \- -f 2`
7748c21
	case $basename in
7748c21
		"erts")
7748c21
			echo "erlang($basename) = $basever"
7748c21
7748c21
			# BIFs from erts - this module is very specific
7748c21
			cat $BUILDDIR/erts/emulator/*/erl_bif_list.h 2>/dev/null |\
7748c21
				grep -v am__AtomAlias |\
7748c21
				grep -o -E 'am_.*\,am_.*\,.\,' |\
7748c21
				sed s,am_,,g |\
7748c21
				sed -e "s,Plus,+,g;s,Minus,-,g;s,Neqeq,=\/=,g;s,Neq,\/=,g;s,Div,\/,g;s,Eqeq,=\:=,g;s,Eq,==,g;s,Ge,>=,g;s,Gt,>,g;s,Le,=<,g;s,Lt,<,g;s,Times,*,g;s,subtract,--,g;s,append\,,++\,,g" |\
7748c21
				awk -F \, '{print "erlang(" $1 ":" $2 "/" $3 ")" }'
7748c21
7748c21
			# Add BIFs for HiPE
7748c21
			grep "bif " $BUILDDIR/erts/emulator/hipe/*.tab | awk -F "bif " '{print "erlang(" $2 ")"}'
7748c21
			;;
7748c21
		"wx")
859b2ca
			# wx module doesn't contain app-file.
7748c21
			echo "erlang($basename) = $basever"
7748c21
			;;
7748c21
		*)
7748c21
			;;
7748c21
	esac
7748c21
done
7748c21
7748c21
# Get the list of *.beam files
7748c21
beamfiles=$(echo $filelist | tr [:blank:] '\n' | grep -o -E '.*/ebin/.*\.beam$')
7748c21
/usr/lib/rpm/erlang-find-provides.escript $beamfiles | sed s,\',,g
7748c21