Skip to content

Commit

Permalink
[tools] add source_desp_cp.sh: add a script to extract cpp and hpp fr…
Browse files Browse the repository at this point in the history
…om a target
  • Loading branch information
jonathanpoelen committed Jan 17, 2024
1 parent 5cb922f commit 677fa96
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions tools/source_deps_cp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env bash
set -eu
set -o pipefail

if [[ "${DEBUG:-0}" = '1' ]]; then
set -x
fi

dest=redemption_source

if (( $# == 0 )) || [[ "$1" = '-h' || "$1" = '--help' ]]; then
echo "Copy .cpp and .hpp in '$dest' from a bjam target
$0 targets...
Ex: $0 libscytale" 2>&1
exit
fi

# extract hpp/cpp
typeset -A dirset sources
while read l ; do
if [[ $l =~ ^[a-zA-Z0-9_/]+'.o: '(.*) ]]; then
for f in ${BASH_REMATCH[1]}; do
# check duplicate
if [[ ! -v sources[$f] ]]; then
sources[$f]=1
dirset[${f%/*}]+="$f "
fi
done
fi
done < <(bjam "$@" cxxflags='-MM -MF -' -a ||:)

rm -r $dest

# create new arbo
dirs=("${!dirset[@]}")
for i in "${!dirs[@]}"; do
dirs[$i]=$dest/${dirs[$i]}
done
mkdir -p ${dirs[@]}

# copy files
for dir in "${!dirset[@]}"; do
cp ${dirset[$dir]} $dest/$dir
done

0 comments on commit 677fa96

Please sign in to comment.