Blame erlang-find-provides.sh

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