]> git.saurik.com Git - apple/hfs.git/blob - make_opensource.sh
hfs-407.1.3.tar.gz
[apple/hfs.git] / make_opensource.sh
1 #!/bin/sh
2
3 #
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.
8 #
9
10 OPENSOURCE=1
11
12 DST=/tmp/hfs-open-source
13
14 rm -rf $DST
15 mkdir $DST
16 xcodebuild installsrc SRCROOT=$DST
17
18 SRCROOT="$DST"
19
20 if [ ! -d "${SRCROOT}" ]; then
21 echo "Could not access ${SRCROOT}" 1>&2
22 exit 1
23 fi
24
25
26 UNIFDEF_FLAGS=""
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"
29 fi
30
31 # From this point forward, all paths are ./-relative
32 cd "${SRCROOT}"
33
34 find -d . -name .open_source_exclude | while read f; do
35 dir=`dirname $f`
36 if [ -s $f ]; then
37 cat $f | while read g; do
38 if [ -n "$g" ]; then
39 echo "Removing $dir/$g (Listed in $f)"
40 rm -f "$dir/$g" || exit 1
41 else
42 echo "Bad entry '$g' in $f"
43 exit 1
44 fi
45 done
46 if [ $? -ne 0 ]; then
47 exit 1
48 fi
49 else
50 echo "Removing $dir (Contains empty $f)"
51 rm -rf "$dir"
52 fi
53 rm -f "$f"
54 done
55
56 if [ $? -ne 0 ]; then
57 # Propagate error from sub-shell invocation above
58 exit 1
59 fi
60
61 function stripfile() {
62 local extraflags="$1"
63 local path="$2"
64
65 unifdef $extraflags $UNIFDEF_FLAGS $path > $path.new
66 if [ $? -eq 0 ]; then
67 # no change
68 rm $path.new
69 else
70 if [ $? -eq 2 ]; then
71 echo "Problems parsing $path, removing..."
72 rm $path.new $path
73 else
74 if [ -s $path.new ]; then
75 echo "Modified $path"
76 mv -f $path.new $path
77 else
78 echo "Removing empty $path"
79 rm -f $path.new $path
80 fi
81 fi
82 fi
83 }
84
85 # C/C++ Source files
86 find . \( -type f -o -type l \) -a \( -name "*.[chy]" -o -name "*.cpp" \) | while read f; do
87 stripfile "" "$f"
88 done
89
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
92 stripfile "-t" "$f"
93 case "$f" in
94 *.sh)
95 chmod +x "$f"
96 ;;
97 esac
98 done
99
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
103
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"
108 exit 1
109 fi
110
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"
114 exit 1
115 else
116 echo "done"
117 exit 0
118 fi