In linux find
can be really powerful.
You can use
OutDir="${BUILD_DIR}/include/header/cocos/" # Linux is case sensitive, Check if
mkdir -p "${OutDir}" # it is needed Cocos or cocos...
cd ./Frameworks/Cocos # just to have clean path to create
# Here with only one line
find . -name "*.h" -exec bash -c 'cp -p --parents {} "${OutDir}" ' \;
# cd - # Eventually to come back to the previous path
Notes:
cp -p
preserve ownership...
cp --parents
create destination dir but needs that the base directory it exists.
mkdir -p
Create the directory with all the parents' path without error if just exists
man find
for all the options of find.
If you want to remain close to the precedent script
cd "${SRCROOT}"
echo 'Copying Cocos Headers into Framework..'
StartSearchDir="${SRCROOT}../Frameworks/Cocos"
BaseDestDir="${BUILD_DIR}/include/header/cocos/"
cd $StartSearchDir
for H in `find . -name "*.h"`; do
echo "${H}"
PathFileDir=$(dirname $H)
mkdir -p "${BUILD_DIR}/${PathFileDir}" # no error, make parents too
cp -p "$H" "${BUILD_DIR}/${PathFileDir}/" # preserve ownership...
# ditto -V "${H}" "${BUILD_DIR}/include/header/cocos/" # commented line
done
Note with dirname
you can extract from a full path+filename string only the path.
Check the help with man dirname
and man basename
Creative woraround :) – Hastur – 2014-12-08T13:45:17.953