#!/bin/sh # pc_cleansrc # ----------- # Description: # Removes all symbolic links created by 'pc_setupsrc'. # Removes all compiled executables and other build objects. # Localized source files (see pc_localize) are maintained. # Data and other files in the run directory are maintained. delete_links() { links=$1 # delete symlinks to scripts in $PENCIL_HOME for file in $links do # echo "$file" if [ -L $file ]; then rm -f $file fi done } delete_files() { files=$1 # delete regular files from compilation and running for file in $files do if [ -f $file ]; then rm -f $file fi done } clean_src() { dir=$1 objects=$2 # delete object files from compilation for object in $objects do for file in $dir/$object do if [ -f $file ]; then rm -f $file fi done done # delete symlinks in the source directory for file in $dir/* do if [ -L $file ]; then rm -f $file fi done # enter sub-directories for test in $dir/* do if [ -d $test ]; then clean_src "$test" "$objects" fi done rmdir $dir >/dev/null 2>&1 } prune_dir() { this=$1 clean_objects="*.o *.a *.mod *.x *.inc .build-history .buildinfo .buildtime tmp" clean_links="start.csh start_run.csh run.csh getconf.csh Makefile src/.cvsignore" clean_files="pc_commands.log COMPLETED ERROR LOCK STOP FULLSTOP src/Makefile src/mpicomm_double.f90 src/revision.txt src/.current-precision src/.config-files src/.moduleinfo" src_dir="src" if [ -d $src_dir ] || [ `ls -1 $clean_links $clean_files 2>/dev/null | wc -l` -ge 1 ]; then if [ "$this" = '.' ] || [ -z "$this" ] ; then echo "Cleaning up run directory..." else echo "Cleaning up run directory: '$this'" fi delete_links "$clean_links" delete_files "$clean_files" clean_src "$src_dir" "$clean_objects" fi } enter_subdirs() { local path=$1 local start=$2 if [ "$start" != "." ]; then cd "$start" if [ -z "$path" ]; then path="$start" fi fi if [ ! -z "$path" ]; then path+="/" fi for dir in *; do if [ -d "$dir" ] && [ "$dir" != "src" ]; then enter_subdirs "$path$dir" "$dir" fi done prune_dir "$path" if [ "$start" != "." ]; then cd .. fi } if [ -z "$2" ]; then if [ -z "$1" ] || [ "$1" = "-R" ]; then start_dir="." else start_dir="$1" fi else start_dir="$2" fi if [ -d "$start_dir" ]; then if [ "$1" = "-R" ]; then enter_subdirs "" "$start_dir" else prune_dir "$start_dir" fi else echo "No such directory: '$start_dir'" fi