duplicate_apps.sh 1.36 KB
Newer Older
Sylvain Thery's avatar
Sylvain Thery committed
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
#!/bin/bash

if test $# -lt 2; then
	echo $0 application_directory_source application_directory_destination
	exit 2
fi

if test -d $2; then
	echo Directory $2 already exist
	exit 3
fi

if test ! -d $1; then
	echo Directory $1 does not exist
	exit 4
fi


echo "copying ..."
cp -r $1 $2
echo "cleanin ..."

cd $2
find . -name "CMakeFiles" -exec rm -rf {} \;  2> /dev/null
find . -name "cmake_install.cmake" -exec rm -f {} \; 2> /dev/null
find . -name "CMakeCache.txt" -exec rm -f {} \; 2> /dev/null
find . -name "Makefile" -exec rm -f {} \; 2> /dev/null
cd bin
rm -rf *
cd ..


app1=`basename $1`
app2=`basename $2`
echo remplace $app1 by $app2 in CMakeLists.txt ...
find . -name "CMakeLists.txt" -exec sed -i s/$app1/$app2/g {} \;

echo "renaming files:"
list_of_files=`find . -name $app1\*`

for f in $list_of_files; do
	nf=`echo $f | sed s/$app1/$app2/`
	echo  "   "$f -\> $nf
	mv $f $nf
	# search into files for inclusion
	bf=`basename $f`
	bnf=`basename $nf`
	list2=`fgrep -wl $bf *`
#	if test -n """$list2"""; then
#		echo "    files to modify (includes)" $list2
		for xx in $list2; do
			sed -i s/$bf/$bnf/g $xx
		done
#	fi
done

echo Modify contents ...
find . -name "*.cpp" -o -name "*.hpp" -o -name "*.h" -exec sed -i s/${app1^}/${app2^}/g {} \;
find . -name "*.cpp" -exec sed -i s/${app1^}/${app2^}/g {} \;
find . -name "*.h" -exec sed -i s/${app1^}/${app2^}/g {} \;

	
echo finished