CHDK Wiki
Advertisement
#!/bin/sh

### add_to_all_subs.sh

if [ -z "$2" ]; then
  echo
  echo "This script adds lines in source file to target file in all CHDK "
  echo "platform sub directories which have a non-zero target file:"
  echo "        cat source >> platform/*/sub/*/target"
  echo "Use it when you have found a new function or RAM address for a single platform"
  echo "to prevent building problems with other platforms, and to ease porting"
  echo "your feature to other models. Run in CHDK source tree root."
  echo
  echo "usage: add_to_all_subs.sh target source"
  echo
  echo "example:"
  echo "        place a dummy stub in stubfile and a dummy function in libfile, then"
  echo "        add_to_all_subs.sh stubs_entry_2.S stubfile"
  echo "        add_to_all_subs.sh lib.c libfile"
  echo
  echo "stubfile contains the code to add to the end of all stubs_entry_2.S" 
  echo "files in the chdk platform tree. It could be a commented out line"
  echo "(or lines if you are adding more than one function)."
  echo 
  echo "libfile contains the code to add to the end of all platform lib.c files"
  echo "in the chdk platform tree."
  echo
  echo "See the example stubfile and libfile."
  exit 0
fi

targetfile=$1
sourcefile=$2

if [ ! -r $sourcefile ]; then
  echo "error: Cannot read source: $sourcefile, exiting"
  exit 0
fi

for p in platform/*/sub/*; do
  # only try directories
  if [ -d $p ]; then
    # check that target file exits and that it is writable and non-zero
    if [ -s $p/$targetfile ] && [ -w $p/$targetfile ]; then
      echo $p
      echo "     adding lines from $sourcefile to $p/$targetfile"
      echo >> $p/$targetfile
      cat $sourcefile >> $p/$targetfile
    else
      echo $p/$targetfile not found, not non-zero or not writable. Skipping.
    fi
  fi
done
Advertisement