4 # This script processes the directory hierarchy
5 # passed to it and eliminates all source code,
6 # makefile fragments, and documentation that is
7 # not suitable for open source posting.
12 DST
=/tmp
/hfs
-open-source
16 xcodebuild installsrc SRCROOT
=$DST
20 if [ ! -d "${SRCROOT}" ]; then
21 echo "Could not access ${SRCROOT}" 1>&2
27 if [ "$OPENSOURCE" -eq 1 ]; then
28 UNIFDEF_FLAGS
="$UNIFDEF_FLAGS -D_OPEN_SOURCE_ -D__OPEN_SOURCE__ -U__arm__ -Uarm -UARM -U__ARM__ -U__arm64__ -Uarm64 -UARM64 -U__ARM64__ -UTARGET_OS_EMBEDDED -UHFS_CONFIG_KEY_ROLL"
31 # From this point forward, all paths are ./-relative
34 find -d .
-name .open_source_exclude
| while read f
; do
37 cat $f | while read g
; do
39 echo "Removing $dir/$g (Listed in $f)"
40 rm -f "$dir/$g" || exit 1
42 echo "Bad entry '$g' in $f"
50 echo "Removing $dir (Contains empty $f)"
57 # Propagate error from sub-shell invocation above
61 function stripfile
() {
65 unifdef
$extraflags $UNIFDEF_FLAGS $path > $path.new
71 echo "Problems parsing $path, removing..."
74 if [ -s $path.new
]; then
78 echo "Removing empty $path"
86 find . \
( -type f
-o -type l \
) -a \
( -name "*.[chy]" -o -name "*.cpp" \
) | while read f
; do
90 # Free-form plain text files
91 find . \
( -type f
-o -type l \
) -a \
( -name "*.[sS]" -o -name "*.sh" -o -name "README" -o -name "*.py" \
) | while read f
; do
100 # Remove project references
101 grep -i -v -E '(hfs_key_roll)' .
/hfs.xcodeproj
/project.pbxproj
> .
/hfs.xcodeproj
/project.pbxproj.new
102 mv -f .
/hfs.xcodeproj
/project.pbxproj.new .
/hfs.xcodeproj
/project.pbxproj
104 # Check for remaining bad file names
105 BADFILES
=`find . \( -name "*.arm*" -o -name "arm*" \) | xargs echo`;
106 if [ -n "$BADFILES" ]; then
107 echo "Bad file names $BADFILES"
111 # Check for remaining bad file contents
112 if grep -iEr '([^UD_]_?_OPEN_SOURCE_|XNU_HIDE_SEED|XNU_HIDE_HARDWARE|CONFIG_EMBEDDED)' .
; then
113 echo "cleanup FAILURE"