mirror of
https://github.com/radareorg/radare2
synced 2026-08-22 20:23:32 -04:00
Improvements on the SDK compilation for apple targets ##build
This commit is contained in:
parent
60c5662587
commit
3a3f20e06c
9 changed files with 477 additions and 303 deletions
7
dist/sdk/Makefile
vendored
Normal file
7
dist/sdk/Makefile
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
all:
|
||||
ifeq ($(uname),Darwin)
|
||||
cd ../.. ; sys/sdk-macos.sh
|
||||
else
|
||||
cd ../.. ; sys/sdk.sh
|
||||
endif
|
||||
mv ../../*.zip .
|
||||
|
|
@ -15,7 +15,7 @@ It is also possible to build r2 natively on your iDevice by following the standa
|
|||
For incremental compilations or daily development you should:
|
||||
|
||||
```sh
|
||||
$ sys/ios-sdk.sh -s
|
||||
$ sys/sdk-ios.sh -s
|
||||
```
|
||||
|
||||
To get a shell with all the environment variables set to build for iOS instead of Mac.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#!/bin/sh
|
||||
sys/ios-sdk.sh -simulator
|
||||
sys/ios-sdk.sh -a arm64
|
||||
sys/sdk-ios.sh -simulator
|
||||
sys/sdk-ios.sh -a arm64
|
||||
lipo -create -output "ios-libr2.dylib \
|
||||
"$INSTALL_DST/$PREFIX"/lib/libr.dylib \
|
||||
"$INSTALL_DST/$PREFIX"/lib_simulator/libr.dylib
|
||||
|
|
|
|||
269
sys/ios-sdk.sh
269
sys/ios-sdk.sh
|
|
@ -1,269 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
# You can modify these variables
|
||||
PREFIX="/usr"
|
||||
INSTALL_DST="/tmp/r2ios"
|
||||
USE_SIMULATOR=0
|
||||
#SIMULATOR_ARCHS="i386+x86_64"
|
||||
SIMULATOR_ARCHS="x86_64"
|
||||
PACKAGE_RADARE=0
|
||||
# Bitcode is deprecated; default off unless explicitly enabled
|
||||
EMBED_BITCODE=0
|
||||
CFLAGS="-O2 -miphoneos-version-min=10.0"
|
||||
DOSH=0
|
||||
ARCHS="" # Will be set by -archs argument. If you want to set it -> e.g. ARCHS="armv7+arm64".
|
||||
MERGE_LIBS=1 # Will merge libs if you build for arm and simulator
|
||||
|
||||
# Environment variables
|
||||
. sys/ios-env.sh
|
||||
export USE_IOS_STATIC=0
|
||||
|
||||
echo "If xcrun --sdk iphoneos cant find the profile use this line:"
|
||||
echo " sudo xcode-select -switch /Applications/Xcode.app"
|
||||
|
||||
PLUGINS_CFG=plugins.ios-store.cfg
|
||||
#PLUGINS_CFG=plugins.ios.cfg
|
||||
|
||||
if [ "${EMBED_BITCODE}" = 1 ]; then
|
||||
export CFLAGS="$CFLAGS -fembed-bitcode"
|
||||
export LDFLAGS="$LDFLAGS -fembed-bitcode"
|
||||
fi
|
||||
|
||||
iosConfigure() {
|
||||
cp -f dist/plugins-cfg/${PLUGINS_CFG} plugins.cfg
|
||||
./configure --with-libr --prefix=${PREFIX} --with-ostype=darwin \
|
||||
--disable-debugger --without-gpl \
|
||||
--without-fork --with-compiler=ios-sdk \
|
||||
--target=arm64-unknown-darwin
|
||||
return $?
|
||||
}
|
||||
|
||||
iosClean() {
|
||||
make clean
|
||||
rm -rf libr/.libr libr/.libr2 libr/libr.a libr/libr.dylib shlr/libr_shlr.a
|
||||
rm -rf shlr/capstone
|
||||
}
|
||||
|
||||
iosBuild() {
|
||||
time make -j4 AR="xcrun --sdk ${SDK} ar" || exit 1
|
||||
# Build and sign
|
||||
( cd binr/radare2 ; make ios_sdk_sign )
|
||||
make install DESTDIR="$INSTALL_DST"
|
||||
rm -rf "$INSTALL_DST/$PREFIX"/share/radare2/*/www/*/node_modules
|
||||
return $?
|
||||
}
|
||||
|
||||
iosMergeLibs() {
|
||||
mkdir -p $INSTALL_DST/$PREFIX/lib_merged
|
||||
#echo "Merging dynamic libs"
|
||||
#lipo "$INSTALL_DST/$PREFIX"/lib/libr*git.dylib $INSTALL_DST/$PREFIX/lib_simulator/libr*git.dylib -output $INSTALL_DST/$PREFIX/lib_merged/libr2.dylib -create
|
||||
echo "Merging static libs (only libr.a)"
|
||||
lipo "$INSTALL_DST/$PREFIX"/lib/libr.a "$INSTALL_DST/$PREFIX"/lib_simulator/libr.a -output "$INSTALL_DST/$PREFIX"/lib_merged/libr.a -create
|
||||
echo "Merging shared libs (only libr.dylib)"
|
||||
lipo "$INSTALL_DST/$PREFIX/lib/libr.dylib" \
|
||||
"$INSTALL_DST/$PREFIX"/lib_simulator/libr.dylib \
|
||||
-output "$INSTALL_DST/$PREFIX"/lib_merged/libr.dylib -create
|
||||
echo "You can find the merged libs in $INSTALL_DST$PREFIX/lib_merged"
|
||||
}
|
||||
|
||||
iosPackage() {
|
||||
( cd "$INSTALL_DST" && tar czvf $INSTALL_DST-${CPU}.tar.gz * )
|
||||
# Prepare radare2
|
||||
rm -rf sys/cydia/radare2/root
|
||||
rm -rf sys/cydia/radare2/root/usr/lib/*.dSYM
|
||||
rm -rf sys/cydia/radare2/root/usr/lib/*.a
|
||||
mkdir -p sys/cydia/radare2/root
|
||||
sudo tar xpzvf "$INSTALL_DST"-${CPU}.tar.gz -C sys/cydia/radare2/root
|
||||
rm -rf sys/cydia/radare2-dev/root
|
||||
# Prepare radare2-dev
|
||||
mkdir -p sys/cydia/radare2-dev/root
|
||||
mkdir -p sys/cydia/radare2-dev/root/usr/include
|
||||
mv sys/cydia/radare2/root/usr/include/* sys/cydia/radare2-dev/root/usr/include
|
||||
mkdir -p sys/cydia/radare2-dev/root/usr/lib
|
||||
mv sys/cydia/radare2/root/usr/lib/lib* sys/cydia/radare2-dev/root/usr/lib
|
||||
mv sys/cydia/radare2/root/usr/lib/pkgconfig sys/cydia/radare2-dev/root/usr/lib
|
||||
(
|
||||
cd sys/cydia/radare2/root/usr/bin ;
|
||||
for a in * ; do strip $a ; done
|
||||
)
|
||||
( cd sys/cydia/radare2 ; sudo make clean ; sudo make )
|
||||
( cd sys/cydia/radare2-dev ; sudo make clean ; sudo make )
|
||||
return $?
|
||||
}
|
||||
|
||||
showHelp() {
|
||||
echo "The following arguments are available:"
|
||||
|
||||
echo " -a, --archs"
|
||||
echo " Select the archs, you want to build for."
|
||||
echo " Available archs: armv7, armv7s, arm64, all"
|
||||
echo " You can select multiple archs by concatenating"
|
||||
echo " them with a '+' sign."
|
||||
echo " Or specify 'all' to build for armv7+armv7s+arm64."
|
||||
echo " See the examples below."
|
||||
|
||||
echo " -h, --help"
|
||||
echo " Show this text."
|
||||
|
||||
echo " -p, --package"
|
||||
echo " Package radare2."
|
||||
|
||||
echo " -s, --shell"
|
||||
echo " Run shell."
|
||||
|
||||
echo " -f, --full"
|
||||
echo " Same as -archs all -simulator."
|
||||
|
||||
echo " -simulator"
|
||||
echo " Build also for i386 and x86_64 archs."
|
||||
echo " So you can use radare2 in the iOS simulator."
|
||||
|
||||
echo "Examples:"
|
||||
echo " sys/ios-sdk.sh -archs arm64"
|
||||
echo " sys/ios-sdk.sh -archs armv7s+arm64 -simulator"
|
||||
echo " sys/ios-sdk.sh -archs all -simulator"
|
||||
|
||||
echo "You can also modify some variables in sys/ios-sdk.sh."
|
||||
}
|
||||
|
||||
# Show help text, if no archs are selected
|
||||
if [ $# -eq 0 ] && [ "${#ARCHS}" = 0 ] && [ "${USE_SIMULATOR}" = 0 ]; then
|
||||
echo "You need to specify the archs you want to build for."
|
||||
echo "Use the -archs/-simulator argument or modify the ARCHS/USE_SIMULATOR variable in sys/ios-sdk.sh."
|
||||
echo
|
||||
showHelp
|
||||
exit 0
|
||||
fi
|
||||
|
||||
while test $# -gt 0; do
|
||||
case "$1" in
|
||||
-full|--full|-f)
|
||||
shift
|
||||
ARCHS="armv7s+arm64"
|
||||
USE_SIMULATOR=1
|
||||
;;
|
||||
-shell|--shell|-s)
|
||||
DOSH=1
|
||||
shift
|
||||
;;
|
||||
-archs|-a|--archs)
|
||||
shift
|
||||
if test $# -gt 0; then
|
||||
if [ "$1" == "all" ]; then
|
||||
ARCHS="armv7+armv7s+arm64"
|
||||
else
|
||||
ARCHS=$1
|
||||
fi
|
||||
fi
|
||||
shift
|
||||
;;
|
||||
-p|--package)
|
||||
iosPackage
|
||||
exit 0
|
||||
;;
|
||||
-simulator)
|
||||
USE_SIMULATOR=1
|
||||
shift
|
||||
;;
|
||||
*|-h|--help)
|
||||
showHelp
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
|
||||
### BUILD PHASE
|
||||
|
||||
# Print which archs we are building for
|
||||
if [ -n "$ARCHS" ] || [ "${USE_SIMULATOR}" = 1 ]; then
|
||||
printf "Will build for "
|
||||
if [ -n "$ARCHS" ]; then
|
||||
printf "%s " "$ARCHS"
|
||||
[ "${USE_SIMULATOR}" = 1 ] && printf "and "
|
||||
fi
|
||||
if [ "${USE_SIMULATOR}" = 1 ]; then
|
||||
printf "simulator(%s)" "$SIMULATOR_ARCHS"
|
||||
fi
|
||||
printf "\n"
|
||||
else
|
||||
echo "Will build for default settings"
|
||||
fi
|
||||
|
||||
if [ "${DOSH}" = 1 ]; then
|
||||
echo "Inside ios-sdk shell"
|
||||
if [ "${USE_SIMULATOR}" = 1 ]; then
|
||||
export CPU="$SIMULATOR_ARCHS"
|
||||
export SDK=iphonesimulator
|
||||
else
|
||||
[ -z "$ARCHS" ] && ARCHS="armv7s+arm64"
|
||||
export CPU="$ARCHS"
|
||||
export SDK=iphoneos
|
||||
fi
|
||||
CPUS=""
|
||||
CPU=`echo $CPU | sed -e 's,+, ,g'`
|
||||
EXTRA=""
|
||||
for a in `IFS=+ echo ${CPU}` ; do
|
||||
CPUS="-arch $a ${CPUS}"
|
||||
done
|
||||
export CPUS="${CPUS}"
|
||||
export LD="xcrun --sdk ${SDK} ld"
|
||||
export ALFLAGS="${CPUS}"
|
||||
export LDFLAGS="${LDFLAGS} ${CPUS}"
|
||||
export PS1="[ios-sdk-$CPU]> "
|
||||
${SHELL}
|
||||
echo "Outside ios-sdk shell"
|
||||
exit $?
|
||||
fi
|
||||
echo
|
||||
sleep 1
|
||||
|
||||
rm -rf "$INSTALL_DST"
|
||||
|
||||
# Build radare2 for i386 and x86_64
|
||||
if [ "${USE_SIMULATOR}" = 1 ]; then
|
||||
iosClean
|
||||
if [ 1 = 0 ]; then
|
||||
iosConfigure
|
||||
if [ $? = 0 ]; then
|
||||
export CPU="$SIMULATOR_ARCHS"
|
||||
export SDK=iphonesimulator
|
||||
echo "Building for simulator($SIMULATOR_ARCHS)"
|
||||
sleep 1
|
||||
iosBuild
|
||||
fi
|
||||
else
|
||||
sys/ios-simulator.sh
|
||||
fi
|
||||
# backup lib folder of simulator
|
||||
if [ "${#ARCHS}" -gt 0 ]; then
|
||||
rm -rf "$INSTALL_DST/$PREFIX"/lib_simulator
|
||||
mv "$INSTALL_DST/$PREFIX"/lib "$INSTALL_DST/$PREFIX"/lib_simulator
|
||||
else
|
||||
cp -r "$INSTALL_DST/$PREFIX"/lib "$INSTALL_DST/$PREFIX"/lib_simulator
|
||||
fi
|
||||
fi
|
||||
|
||||
# check if arm archs were selected and if so build radare2 for them
|
||||
# XXX this is a bashism
|
||||
if [ "${#ARCHS}" -gt 0 ]; then
|
||||
iosClean
|
||||
iosConfigure
|
||||
if [ "$?" = 0 ]; then
|
||||
export CPU="$ARCHS"
|
||||
export SDK=iphoneos
|
||||
echo "Building for $CPU"
|
||||
sleep 1
|
||||
iosBuild
|
||||
if [ "${PACKAGE_RADARE}" = 1 ]; then
|
||||
iosPackage
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# Merge libs if built for simulator and arm archs
|
||||
if [ "${MERGE_LIBS}" = 1 ]; then
|
||||
if [ "${USE_SIMULATOR}" = 1 ] && [ "${#ARCHS}" -gt 0 ]; then
|
||||
iosMergeLibs
|
||||
fi
|
||||
fi
|
||||
|
|
@ -202,7 +202,7 @@ BuildAndInstall() {
|
|||
KEEP_PLUGINS_CFG=1 sys/user.sh
|
||||
;;
|
||||
"iOS")
|
||||
sys/ios-sdk.sh
|
||||
sys/sdk-ios.sh
|
||||
;;
|
||||
"OSX")
|
||||
sys/osx-pkg.sh
|
||||
|
|
|
|||
118
sys/sdk-common.sh
Executable file
118
sys/sdk-common.sh
Executable file
|
|
@ -0,0 +1,118 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Common functions for SDK building
|
||||
|
||||
# Default variables
|
||||
PREFIX="/usr/local"
|
||||
INSTALL_DST="/tmp/r2sdk"
|
||||
CFLAGS="-O2"
|
||||
DOSH=0
|
||||
ARCHS=""
|
||||
MERGE_LIBS=1
|
||||
|
||||
sdkClean() {
|
||||
make clean
|
||||
rm -rf libr/.libr libr/.libr2 libr/libr.a libr/libr.dylib shlr/libr_shlr.a
|
||||
rm -rf shlr/capstone
|
||||
}
|
||||
|
||||
sdkBuild() {
|
||||
time make -j4 || exit 1
|
||||
make install DESTDIR="$INSTALL_DST"
|
||||
rm -rf "$INSTALL_DST/$PREFIX"/share/radare2/*/www/*/node_modules
|
||||
return $?
|
||||
}
|
||||
|
||||
sdkMergeLibs() {
|
||||
mkdir -p "$INSTALL_DST/$PREFIX/lib_merged"
|
||||
echo "Merging static libs (libr.a)"
|
||||
local libs=""
|
||||
for arch in $(echo $ARCHS | tr '+' ' '); do
|
||||
if [ -f "$INSTALL_DST/$PREFIX/lib_$arch/libr.a" ]; then
|
||||
libs="$libs $INSTALL_DST/$PREFIX/lib_$arch/libr.a"
|
||||
fi
|
||||
done
|
||||
if [ -f "$INSTALL_DST/$PREFIX/lib/libr.a" ]; then
|
||||
libs="$libs $INSTALL_DST/$PREFIX/lib/libr.a"
|
||||
fi
|
||||
if [ -n "$libs" ]; then
|
||||
lipo $libs -output "$INSTALL_DST/$PREFIX/lib_merged/libr.a" -create
|
||||
fi
|
||||
echo "Merging shared libs (libr.dylib)"
|
||||
libs=""
|
||||
for arch in $(echo $ARCHS | tr '+' ' '); do
|
||||
if [ -f "$INSTALL_DST/$PREFIX/lib_$arch/libr.dylib" ]; then
|
||||
libs="$libs $INSTALL_DST/$PREFIX/lib_$arch/libr.dylib"
|
||||
fi
|
||||
done
|
||||
if [ -f "$INSTALL_DST/$PREFIX/lib/libr.dylib" ]; then
|
||||
libs="$libs $INSTALL_DST/$PREFIX/lib/libr.dylib"
|
||||
fi
|
||||
if [ -n "$libs" ]; then
|
||||
lipo $libs -output "$INSTALL_DST/$PREFIX/lib_merged/libr.dylib" -create
|
||||
fi
|
||||
echo "Merged libs in $INSTALL_DST$PREFIX/lib_merged"
|
||||
}
|
||||
|
||||
showHelp() {
|
||||
echo "Usage: $0 [options]"
|
||||
echo
|
||||
echo "Options:"
|
||||
echo " -a, --archs ARCHS Architectures to build (e.g., arm64, x86_64+arm64)"
|
||||
echo " -h, --help Show this help"
|
||||
echo " -s, --shell Run shell with environment set"
|
||||
echo " -p, --prefix PREFIX Installation prefix (default: $PREFIX)"
|
||||
echo " -d, --dest DEST Installation destination (default: $INSTALL_DST)"
|
||||
}
|
||||
|
||||
parseArgs() {
|
||||
while test $# -gt 0; do
|
||||
case "$1" in
|
||||
-shell|--shell|-s)
|
||||
DOSH=1
|
||||
shift
|
||||
;;
|
||||
-archs|-a|--archs)
|
||||
shift
|
||||
if test $# -gt 0; then
|
||||
ARCHS=$1
|
||||
fi
|
||||
shift
|
||||
;;
|
||||
-prefix|-p|--prefix)
|
||||
shift
|
||||
if test $# -gt 0; then
|
||||
PREFIX=$1
|
||||
fi
|
||||
shift
|
||||
;;
|
||||
-dest|-d|--dest)
|
||||
shift
|
||||
if test $# -gt 0; then
|
||||
INSTALL_DST=$1
|
||||
fi
|
||||
shift
|
||||
;;
|
||||
*|-h|--help)
|
||||
showHelp
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
setupShell() {
|
||||
local platform=$1
|
||||
echo "Inside $platform-sdk shell"
|
||||
export CPU="$ARCHS"
|
||||
local CPUS=""
|
||||
for a in $(echo $ARCHS | tr '+' ' '); do
|
||||
CPUS="-arch $a ${CPUS}"
|
||||
done
|
||||
export CPUS="${CPUS}"
|
||||
export LDFLAGS="${LDFLAGS} ${CPUS}"
|
||||
export PS1="[$platform-sdk-$CPU]> "
|
||||
${SHELL}
|
||||
echo "Outside $platform-sdk shell"
|
||||
exit $?
|
||||
}
|
||||
177
sys/sdk-ios.sh
Executable file
177
sys/sdk-ios.sh
Executable file
|
|
@ -0,0 +1,177 @@
|
|||
#!/bin/bash
|
||||
|
||||
# iOS SDK builder
|
||||
|
||||
. sys/sdk-common.sh
|
||||
|
||||
# iOS specific variables
|
||||
USE_SIMULATOR=0
|
||||
SIMULATOR_ARCHS="x86_64"
|
||||
PACKAGE_RADARE=0
|
||||
EMBED_BITCODE=0
|
||||
PLUGINS_CFG=plugins.ios-store.cfg
|
||||
|
||||
# Environment variables
|
||||
. sys/ios-env.sh
|
||||
export USE_IOS_STATIC=0
|
||||
|
||||
echo "If xcrun --sdk iphoneos cant find the profile use this line:"
|
||||
echo " sudo xcode-select -switch /Applications/Xcode.app"
|
||||
|
||||
if [ "${EMBED_BITCODE}" = 1 ]; then
|
||||
export CFLAGS="$CFLAGS -fembed-bitcode"
|
||||
export LDFLAGS="$LDFLAGS -fembed-bitcode"
|
||||
fi
|
||||
|
||||
iosConfigure() {
|
||||
cp -f dist/plugins-cfg/${PLUGINS_CFG} plugins.cfg
|
||||
./configure --with-libr --prefix=${PREFIX} --with-ostype=darwin \
|
||||
--disable-debugger --without-gpl \
|
||||
--without-fork --with-compiler=ios-sdk \
|
||||
--target=arm64-unknown-darwin
|
||||
return $?
|
||||
}
|
||||
|
||||
iosPackage() {
|
||||
( cd "$INSTALL_DST" && tar czvf $INSTALL_DST-${CPU}.tar.gz * )
|
||||
# Prepare radare2
|
||||
rm -rf sys/cydia/radare2/root
|
||||
rm -rf sys/cydia/radare2/root/usr/lib/*.dSYM
|
||||
rm -rf sys/cydia/radare2/root/usr/lib/*.a
|
||||
mkdir -p sys/cydia/radare2/root
|
||||
sudo tar xpzvf "$INSTALL_DST"-${CPU}.tar.gz -C sys/cydia/radare2/root
|
||||
rm -rf sys/cydia/radare2-dev/root
|
||||
# Prepare radare2-dev
|
||||
mkdir -p sys/cydia/radare2-dev/root
|
||||
mkdir -p sys/cydia/radare2-dev/root/usr/include
|
||||
mv sys/cydia/radare2/root/usr/include/* sys/cydia/radare2-dev/root/usr/include
|
||||
mkdir -p sys/cydia/radare2-dev/root/usr/lib
|
||||
mv sys/cydia/radare2/root/usr/lib/lib* sys/cydia/radare2-dev/root/usr/lib
|
||||
mv sys/cydia/radare2/root/usr/lib/pkgconfig sys/cydia/radare2-dev/root/usr/lib
|
||||
(
|
||||
cd sys/cydia/radare2/root/usr/bin ;
|
||||
for a in * ; do strip $a ; done
|
||||
)
|
||||
( cd sys/cydia/radare2 ; sudo make clean ; sudo make )
|
||||
( cd sys/cydia/radare2-dev ; sudo make clean ; sudo make )
|
||||
return $?
|
||||
}
|
||||
|
||||
showHelp() {
|
||||
echo "iOS SDK builder"
|
||||
echo
|
||||
echo "Options:"
|
||||
echo " -a, --archs ARCHS Architectures (armv7, armv7s, arm64, all)"
|
||||
echo " -simulator Build for simulator"
|
||||
echo " -f, --full Build all archs + simulator"
|
||||
echo " -p, --package Package radare2"
|
||||
echo " -s, --shell Run shell"
|
||||
echo " -h, --help Show help"
|
||||
echo
|
||||
echo "Examples:"
|
||||
echo " sys/sdk-ios.sh -archs arm64"
|
||||
echo " sys/sdk-ios.sh -archs armv7s+arm64 -simulator"
|
||||
echo " sys/sdk-ios.sh -archs all -simulator"
|
||||
}
|
||||
|
||||
parseArgs "$@"
|
||||
|
||||
# iOS specific args
|
||||
while test $# -gt 0; do
|
||||
case "$1" in
|
||||
-full|--full|-f)
|
||||
shift
|
||||
ARCHS="armv7s+arm64"
|
||||
USE_SIMULATOR=1
|
||||
;;
|
||||
-p|--package)
|
||||
iosPackage
|
||||
exit 0
|
||||
;;
|
||||
-simulator)
|
||||
USE_SIMULATOR=1
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Show help if no archs
|
||||
if [ $# -eq 0 ] && [ "${#ARCHS}" = 0 ] && [ "${USE_SIMULATOR}" = 0 ]; then
|
||||
echo "You need to specify the archs you want to build for."
|
||||
echo "Use -archs/-simulator or modify ARCHS/USE_SIMULATOR."
|
||||
echo
|
||||
showHelp
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
||||
# Build phase
|
||||
if [ -n "$ARCHS" ] || [ "${USE_SIMULATOR}" = 1 ]; then
|
||||
printf "Will build for "
|
||||
if [ -n "$ARCHS" ]; then
|
||||
printf "%s " "$ARCHS"
|
||||
[ "${USE_SIMULATOR}" = 1 ] && printf "and "
|
||||
fi
|
||||
if [ "${USE_SIMULATOR}" = 1 ]; then
|
||||
printf "simulator(%s)" "$SIMULATOR_ARCHS"
|
||||
fi
|
||||
printf "\n"
|
||||
else
|
||||
echo "Will build for default settings"
|
||||
fi
|
||||
|
||||
if [ "${DOSH}" = 1 ]; then
|
||||
setupShell "ios"
|
||||
fi
|
||||
|
||||
echo
|
||||
sleep 1
|
||||
rm -rf "$INSTALL_DST"
|
||||
|
||||
# Build for simulator
|
||||
if [ "${USE_SIMULATOR}" = 1 ]; then
|
||||
sdkClean
|
||||
if [ 1 = 0 ]; then
|
||||
iosConfigure
|
||||
if [ $? -eq 0 ]; then
|
||||
export CPU="$SIMULATOR_ARCHS"
|
||||
export SDK=iphonesimulator
|
||||
echo "Building for simulator($SIMULATOR_ARCHS)"
|
||||
sleep 1
|
||||
sdkBuild
|
||||
fi
|
||||
else
|
||||
sys/ios-simulator.sh
|
||||
fi
|
||||
# backup lib folder
|
||||
if [ "${#ARCHS}" -gt 0 ]; then
|
||||
rm -rf "$INSTALL_DST/$PREFIX"/lib_simulator
|
||||
mv "$INSTALL_DST/$PREFIX"/lib "$INSTALL_DST/$PREFIX"/lib_simulator
|
||||
else
|
||||
cp -r "$INSTALL_DST/$PREFIX"/lib "$INSTALL_DST/$PREFIX"/lib_simulator
|
||||
fi
|
||||
fi
|
||||
|
||||
# Build for device
|
||||
if [ "${#ARCHS}" -gt 0 ]; then
|
||||
sdkClean
|
||||
iosConfigure
|
||||
if [ $? -eq 0 ]; then
|
||||
export CPU="$ARCHS"
|
||||
export SDK=iphoneos
|
||||
echo "Building for $CPU"
|
||||
sleep 1
|
||||
sdkBuild
|
||||
if [ "${PACKAGE_RADARE}" = 1 ]; then
|
||||
iosPackage
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# Merge libs
|
||||
if [ "${MERGE_LIBS}" = 1 ] && [ "${USE_SIMULATOR}" = 1 ] && [ "${#ARCHS}" -gt 0 ]; then
|
||||
sdkMergeLibs
|
||||
fi
|
||||
68
sys/sdk-macos.sh
Executable file
68
sys/sdk-macos.sh
Executable file
|
|
@ -0,0 +1,68 @@
|
|||
#!/bin/bash
|
||||
|
||||
# macOS SDK builder
|
||||
|
||||
. sys/sdk-common.sh
|
||||
|
||||
# macOS specific
|
||||
PLUGINS_CFG=plugins.ios-store.cfg
|
||||
|
||||
macosConfigure() {
|
||||
cp -f dist/plugins-cfg/${PLUGINS_CFG} plugins.cfg
|
||||
./configure --with-libr --prefix=${PREFIX} --with-ostype=darwin \
|
||||
--disable-debugger --without-gpl \
|
||||
--without-fork --with-compiler=clang \
|
||||
--target=x86_64-apple-darwin
|
||||
return $?
|
||||
}
|
||||
|
||||
showHelp() {
|
||||
echo "macOS SDK builder"
|
||||
echo
|
||||
echo "Options:"
|
||||
echo " -a, --archs ARCHS Architectures (x86_64, arm64, all)"
|
||||
echo " -s, --shell Run shell"
|
||||
echo " -h, --help Show help"
|
||||
echo
|
||||
echo "Examples:"
|
||||
echo " sys/sdk-macos.sh -archs arm64"
|
||||
echo " sys/sdk-macos.sh -archs x86_64+arm64"
|
||||
echo " sys/sdk-macos.sh -archs all"
|
||||
}
|
||||
|
||||
parseArgs "$@"
|
||||
|
||||
# Show help if no archs
|
||||
if [ $# -eq 0 ] && [ "${#ARCHS}" = 0 ]; then
|
||||
echo "You need to specify the archs you want to build for."
|
||||
echo "Use -archs or modify ARCHS."
|
||||
echo
|
||||
showHelp
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Build phase
|
||||
if [ -n "$ARCHS" ]; then
|
||||
printf "Will build for %s\n" "$ARCHS"
|
||||
else
|
||||
echo "Will build for default settings"
|
||||
fi
|
||||
|
||||
if [ "${DOSH}" = 1 ]; then
|
||||
setupShell "macos"
|
||||
fi
|
||||
|
||||
echo
|
||||
sleep 1
|
||||
rm -rf "$INSTALL_DST"
|
||||
|
||||
if [ "${#ARCHS}" -gt 0 ]; then
|
||||
sdkClean
|
||||
macosConfigure
|
||||
if [ $? -eq 0 ]; then
|
||||
export CPU="$ARCHS"
|
||||
echo "Building for $CPU"
|
||||
sleep 1
|
||||
sdkBuild
|
||||
fi
|
||||
fi
|
||||
133
sys/sdk.sh
133
sys/sdk.sh
|
|
@ -1,4 +1,8 @@
|
|||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
|
||||
# Unified SDK script
|
||||
|
||||
. sys/sdk-common.sh
|
||||
|
||||
WRKDIR=/tmp
|
||||
SDKDIR=${WRKDIR}/r2-sdk
|
||||
|
|
@ -10,34 +14,103 @@ if [ -n "$1" ]; then
|
|||
SDKDIR="$1"
|
||||
fi
|
||||
|
||||
# Builds an SDK to build stuff for rbin
|
||||
export CFLAGS="-Os -fPIC"
|
||||
make mrproper
|
||||
if [ -z "${R2_PLUGINS_CFG}" ]; then
|
||||
R2_PLUGINS_CFG=dist/plugins-cfg/plugins.bin.cfg
|
||||
fi
|
||||
cp -f "${R2_PLUGINS_CFG}" plugins.cfg
|
||||
#./configure-plugins
|
||||
./configure --prefix="$PREFIX" --with-libr --without-gpl || exit 1
|
||||
#--disable-loadlibs || exit 1
|
||||
make -j8 || exit 1
|
||||
rm -rf "${SDKDIR}"
|
||||
mkdir -p "${SDKDIR}"/lib
|
||||
rm -f libr/libr.a
|
||||
cp -rf libr/include "${SDKDIR}"
|
||||
mkdir -p "${SDKDIR}/include/sdb"
|
||||
cp -rf subprojects/sdb/include/sdb/* "${SDKDIR}/include/sdb"
|
||||
FILES=`find libr shlr -iname '*.a'`
|
||||
cp -f ${FILES} "${SDKDIR}"/lib
|
||||
OS=`uname`
|
||||
AR=`uname -m`
|
||||
SF=r2sdk-${OS}-${AR}
|
||||
|
||||
(
|
||||
cd "${WRKDIR}"
|
||||
mv r2-sdk "${SF}"
|
||||
zip -r "${SF}".zip "${SF}"
|
||||
)
|
||||
mv "${WRKDIR}/${SF}" .
|
||||
mv "${WRKDIR}/${SF}".zip .
|
||||
ln -fs "${SF}" r2sdk
|
||||
if [ "$OS" = "Darwin" ]; then
|
||||
# On macOS, build xcframework for iOS and macOS
|
||||
echo "Building xcframework for iOS and macOS"
|
||||
|
||||
# Build iOS SDK
|
||||
echo "Building iOS SDK..."
|
||||
INSTALL_DST_IOS="/tmp/r2ios"
|
||||
sys/sdk-ios.sh -archs arm64 -d "$INSTALL_DST_IOS"
|
||||
|
||||
# Build macOS SDK
|
||||
echo "Building macOS SDK..."
|
||||
INSTALL_DST_MACOS="/tmp/r2macos"
|
||||
sys/sdk-macos.sh -archs x86_64+arm64 -d "$INSTALL_DST_MACOS"
|
||||
|
||||
# Create xcframework
|
||||
echo "Creating xcframework..."
|
||||
XCF_DST="/tmp/Radare2.xcframework"
|
||||
rm -rf "$XCF_DST"
|
||||
mkdir -p "$XCF_DST"
|
||||
|
||||
# Prepare headers with module maps
|
||||
XCF_HEADERS_IOS="/tmp/xcframework_headers/ios"
|
||||
XCF_HEADERS_MACOS="/tmp/xcframework_headers/macos"
|
||||
rm -rf "$XCF_HEADERS_IOS" "$XCF_HEADERS_MACOS"
|
||||
mkdir -p "$XCF_HEADERS_IOS" "$XCF_HEADERS_MACOS"
|
||||
|
||||
# Copy headers
|
||||
cp -r "$INSTALL_DST_IOS/usr/local/include/"* "$XCF_HEADERS_IOS/"
|
||||
cp -r "$INSTALL_DST_MACOS/usr/local/include/"* "$XCF_HEADERS_MACOS/"
|
||||
|
||||
# Add module.modulemap
|
||||
cat > "$XCF_HEADERS_IOS/module.modulemap" <<'EOF'
|
||||
module radare2 [extern_c] {
|
||||
umbrella "."
|
||||
export *
|
||||
}
|
||||
EOF
|
||||
cat > "$XCF_HEADERS_MACOS/module.modulemap" <<'EOF'
|
||||
module radare2 [extern_c] {
|
||||
umbrella "."
|
||||
export *
|
||||
}
|
||||
EOF
|
||||
|
||||
# For iOS
|
||||
IOS_LIB="$INSTALL_DST_IOS/usr/local/lib/libr.a"
|
||||
IOS_HEADERS="$XCF_HEADERS_IOS"
|
||||
|
||||
# For macOS
|
||||
MACOS_LIB="$INSTALL_DST_MACOS/usr/local/lib/libr.a"
|
||||
MACOS_HEADERS="$XCF_HEADERS_MACOS"
|
||||
|
||||
xcodebuild -create-xcframework \
|
||||
-library "$IOS_LIB" \
|
||||
-headers "$IOS_HEADERS" \
|
||||
-library "$MACOS_LIB" \
|
||||
-headers "$MACOS_HEADERS" \
|
||||
-output "$XCF_DST"
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "XCFramework created at $XCF_DST"
|
||||
# Zip it
|
||||
zip -r Radare2.xcframework.zip "$XCF_DST"
|
||||
echo "Zipped to Radare2.xcframework.zip"
|
||||
else
|
||||
echo "Failed to create xcframework"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
# Generic Unix build
|
||||
export CFLAGS="-Os -fPIC"
|
||||
make mrproper
|
||||
if [ -z "${R2_PLUGINS_CFG}" ]; then
|
||||
R2_PLUGINS_CFG=dist/plugins-cfg/plugins.bin.cfg
|
||||
fi
|
||||
cp -f "${R2_PLUGINS_CFG}" plugins.cfg
|
||||
./configure --prefix="$PREFIX" --with-libr --without-gpl || exit 1
|
||||
make -j8 || exit 1
|
||||
rm -rf "${SDKDIR}"
|
||||
mkdir -p "${SDKDIR}"/lib
|
||||
rm -f libr/libr.a
|
||||
cp -rf libr/include "${SDKDIR}"
|
||||
mkdir -p "${SDKDIR}/include/sdb"
|
||||
cp -rf subprojects/sdb/include/sdb/* "${SDKDIR}/include/sdb"
|
||||
FILES=`find libr shlr -iname '*.a'`
|
||||
cp -f ${FILES} "${SDKDIR}"/lib
|
||||
AR=`uname -m`
|
||||
SF=r2sdk-${OS}-${AR}
|
||||
|
||||
(
|
||||
cd "${WRKDIR}"
|
||||
mv r2-sdk "${SF}"
|
||||
zip -r "${SF}".zip "${SF}"
|
||||
)
|
||||
mv "${WRKDIR}/${SF}" .
|
||||
mv "${WRKDIR}/${SF}".zip .
|
||||
ln -fs "${SF}" r2sdk
|
||||
fi
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue