<rdar://problem/20721931> REGRESSION (r178753): All legacy framework headers are...
[WebKit-https.git] / Source / WebKit / mac / postprocess-headers.sh
1 #!/bin/sh
2
3 postProcessInDirectory()
4 {
5     cd "$1"
6
7     local unifdefOptions sedExpression
8
9     if [[ ${PLATFORM_NAME} == macosx ]]; then
10         unifdefOptions="-DTARGET_OS_EMBEDDED=0 -DTARGET_OS_IPHONE=0 -DTARGET_IPHONE_SIMULATOR=0";
11     elif [[ ${PLATFORM_NAME} == *simulator* ]]; then
12         unifdefOptions="-DTARGET_OS_EMBEDDED=0 -DTARGET_OS_IPHONE=1 -DTARGET_IPHONE_SIMULATOR=1";
13     else
14         unifdefOptions="-DTARGET_OS_EMBEDDED=1 -DTARGET_OS_IPHONE=1 -DTARGET_IPHONE_SIMULATOR=0";
15     fi
16
17     # FIXME: We should consider making this logic general purpose so as to support keeping or removing
18     # code guarded by an arbitrary feature define. For now it's sufficient to process touch- and gesture-
19     # guarded code.
20     for featureDefine in "ENABLE_TOUCH_EVENTS" "ENABLE_IOS_GESTURE_EVENTS"
21     do
22         # We assume a disabled feature is either undefined or has the empty string as its value.
23         eval "isFeatureEnabled=\$$featureDefine"
24         if [[ -z $isFeatureEnabled ]]; then
25             unifdefOptions="$unifdefOptions -D$featureDefine=0"
26         else
27             unifdefOptions="$unifdefOptions -D$featureDefine=1"
28         fi
29     done
30
31     if [[ ${PLATFORM_NAME} == macosx ]]; then
32         sedExpression='s/WEBKIT_((CLASS_|ENUM_)?AVAILABLE|DEPRECATED)/NS_\1/g';
33     else
34         sedExpression='s/ *WEBKIT_((CLASS_|ENUM_)?AVAILABLE|DEPRECATED)_MAC\([^)]+\)//g';
35     fi
36
37     for header in $(find . -name '*.h' -type f); do
38         unifdef -B ${unifdefOptions} -o ${header}.unifdef ${header}
39         case $? in
40         0)
41             rm ${header}.unifdef
42             ;;
43         1)
44             mv ${header}{.unifdef,}
45             ;;
46         *)
47             exit 1
48             ;;
49         esac
50
51         if [[ ${header} == "./WebKitAvailability.h" ]]; then
52             continue
53         fi
54
55         sed -E -e "${sedExpression}" < ${header} > ${header}.sed
56         if cmp -s ${header} ${header}.sed; then
57             rm ${header}.sed
58         else
59             mv ${header}.sed ${header}
60         fi
61     done
62 }
63
64 postProcessInDirectory "${TARGET_BUILD_DIR}/${PUBLIC_HEADERS_FOLDER_PATH}"
65 postProcessInDirectory "${TARGET_BUILD_DIR}/${PRIVATE_HEADERS_FOLDER_PATH}"