copydeps.sh.in 1.97 KB
#!/bin/bash
myDIR=$(dirname $(readlink -f $0))

# Updated by ./configure
BUILDDIR=@BUILDDIR@
prefix=@prefix@

# Crio diretório temporário
TEMPDIR=$(mktemp -d)

# Cleanup em caso de falha
ontrap() 
{
    #
    # Apaga diretorio temporário caso o script seja interrompido
    #
	cd ${myDIR}
	rm -fr ${TEMPDIR}
	exit -1
}

trap ontrap INT 

#
# Lista de DLLs a ignorar
#
libs_to_exclude="
	advapi32
	cfgmgr32
	comctl32
	comdlg32
	crypt32
	d3d8
	d3d9
	ddraw
	dnsapi
	dsound
	dwmapi
	gdi32
	gdiplus
	glu32
	glut32
	imm32
	iphlpapi
	kernel32
	ksuser
	mpr
	mscms
	mscoree
	msimg32
	msvcr71
	msvcr80
	msvcr90
	msvcrt
	mswsock
	netapi32
	odbc32
	ole32
	oleacc
	oleaut32
	opengl32
	psapi
	rpcrt4
	secur32
	setupapi
	shell32
	shlwapi
	user32
	usp10
	version
	wininet
	winmm
	wldap32
	ws2_32
	wsock32
	winspool.drv
"

#
# Fico em loop montando dependências
#
APPLICATION_PATH=${BUILDDIR}/.bin/Release
RUNTIME_PATH=${BUILDDIR}/.bin/runtime

mkdir -p ${RUNTIME_PATH}

AGAIN=1
until [  $AGAIN = 0 ]; do

	AGAIN=0

	find ${APPLICATION_PATH} -iname *.exe > ${TEMPDIR}/binaries.txt
	find ${APPLICATION_PATH} -iname *.dll >> ${TEMPDIR}/binaries.txt
	find ${RUNTIME_PATH} -iname *.dll >> ${TEMPDIR}/binaries.txt

	# Obtenho a lista de DLLs
	rm -f ${TEMPDIR}/requires.txt
	touch ${TEMPDIR}/requires.txt
	while read FILENAME
	do
		objdump -p ${FILENAME} | grep "DLL Name:" | cut -d: -f2 | tr "[:upper:]" "[:lower:]" >> ${TEMPDIR}/requires.txt
	done < ${TEMPDIR}/binaries.txt
	
	# Excluo DLLs do sistema
	for i in $libs_to_exclude; do
		sed -i -e "/${i}/d" ${TEMPDIR}/requires.txt
	done

	while read FILENAME
	do

		if [ -e ${APPLICATION_PATH}/${FILENAME} ]; then
			touch ${APPLICATION_PATH}/${FILENAME}

		elif [ -e ${RUNTIME_PATH}/${FILENAME} ]; then
			touch ${RUNTIME_PATH}/${FILENAME}

		elif [ -e ${prefix}/bin/${FILENAME} ]; then
			AGAIN=1
			echo ${prefix}/bin/${FILENAME}
			cp ${prefix}/bin/${FILENAME} ${RUNTIME_PATH}

		fi

	done < ${TEMPDIR}/requires.txt
	rm -f ${TEMPDIR}/requires.txt


done

cd ${myDIR}
rm -fr ${TEMPDIR}