Created
March 12, 2018 03:10
-
-
Save eni9889/deb00270e27e0f45eafbbfd274f30344 to your computer and use it in GitHub Desktop.
Generate Namespace Headers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This script is a modified version of this: https://github.com/jverkoey/nimbus/blob/master/scripts/generate_namespace_header | |
header=$SRCROOT/ext/NamespacedDependencies.h | |
prefix="YOUR_PREFIX_HERE" | |
echo "Generating $header from $CODESIGNING_FOLDER_PATH..." | |
echo "// Namespaced Header | |
#ifndef __NS_SYMBOL | |
// We need to have multiple levels of macros here so that __NAMESPACE_PREFIX_ is | |
// properly replaced by the time we concatenate the namespace prefix. | |
#define __NS_REWRITE(ns, symbol) ns ## _ ## symbol | |
#define __NS_BRIDGE(ns, symbol) __NS_REWRITE(ns, symbol) | |
#define __NS_SYMBOL(symbol) __NS_BRIDGE($prefix, symbol) | |
#endif | |
" > $header | |
# The following one-liner is a bit of a pain in the ass. | |
# Breakdown: | |
# | |
# nm $CODESIGNING_FOLDER_PATH -j | |
# Dump all of the symbols from the compiled library. This will include all UIKit | |
# and Foundation symbols as well. | |
# | |
# | grep "^_OBJC_CLASS_$_" | |
# Filter out the interfaces. | |
# | |
# | grep -v "\$_NS" | |
# Remove all Foundation classes. | |
# | |
# | grep -v "\$_UI" | |
# Remove all UIKit classes. | |
# | |
# | sed -e 's/_OBJC_CLASS_\$_\(.*\)/#ifndef \1\'$'\n''#define \1 __NS_SYMBOL(\1)\'$'\n''#endif/g' | |
# I use the syntax outlined here: | |
# http://stackoverflow.com/questions/6761796/bash-perl-or-sed-insert-on-new-line-after-found-phrase | |
# to create newlines so that we can write the following on separate lines: | |
# | |
# #ifndef ... | |
# #define ... | |
# #endif | |
# | |
echo "// Classes" >> $header | |
nm $CODESIGNING_FOLDER_PATH -j | sort | uniq | grep "^_OBJC_CLASS_\$_" | grep -v "\$_AGSGT" | grep -v "\$_CL" | grep -v "\$_NS" | grep -v "\$_UI" | sed -e 's/_OBJC_CLASS_\$_\(.*\)/#ifndef \1\'$'\n''#define \1 __NS_SYMBOL(\1)\'$'\n''#endif\'$'\n''/g' >> $header | |
echo "// Functions" >> $header | |
nm $CODESIGNING_FOLDER_PATH | sort | uniq | grep " T " | cut -d' ' -f3 | grep -v "\$_NS" | grep -v "\$_UI" | sed -e 's/_\(.*\)/#ifndef \1\'$'\n''#define \1 __NS_SYMBOL(\1)\'$'\n''#endif\'$'\n''/g' >> $header | |
echo "// Externs" >> $header | |
nm $CODESIGNING_FOLDER_PATH | sort | uniq | grep " D " | cut -d' ' -f3 | grep -v "\$_NS" | grep -v "\$_UI" | sed -e 's/_\(.*\)/#ifndef \1\'$'\n''#define \1 __NS_SYMBOL(\1)\'$'\n''#endif\'$'\n''/g' >> $header | |
nm $CODESIGNING_FOLDER_PATH | sort | uniq | grep " S " | cut -d' ' -f3 | grep -v "\$_NS" | grep -v ".eh" | grep -v "\$_UI" | grep -v "OBJC_" | sed -e 's/_\(.*\)/#ifndef \1\'$'\n''#define \1 __NS_SYMBOL(\1)\'$'\n''#endif\'$'\n''/g' >> $header | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment