Last active
May 9, 2018 05:34
-
-
Save mantognini/6080429 to your computer and use it in GitHub Desktop.
Create SFML and CSFML 2.x packages for macOS.
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
#!/bin/sh | |
### | |
### Build SFML head for OS X, current OS version only | |
### | |
### Author: Marco Antognini <[email protected]> | |
### Date: 24/07/2013 | |
### | |
## | |
## SETTINGS | |
## | |
topdir=$(pwd) | |
src_path="$topdir/../SFML" | |
## | |
## HELPER FUNCTIONS | |
## | |
## Echoes to stderr, and die | |
error () # $* message to display | |
{ | |
echo "$@" 1>&2 | |
exit 2 | |
} | |
## Check that the number of parameters is correct, or die | |
param_check () # $1 should be $# on call site, | |
# $2 the number of required params, | |
# $3 an id for the error message | |
{ | |
if [ $# -ne 3 ] | |
then | |
error "Internal error in param_error: the number of parameters is incorrect" | |
fi | |
if [ $1 -ne $2 ] | |
then | |
error "Internal error in $3: the number of parameters is incorrect" | |
fi | |
} | |
## Check that the number of parameters is enough, or die | |
param_check_ge () # $1 should be $# on call site, | |
# $2 the minimal number of params, | |
# $3 an id for the error message | |
{ | |
param_check $# 3 "param_check_ge" | |
if [ $1 -lt $2 ] | |
then | |
error "Internal error in $3: the number of parameters is not enough" | |
fi | |
} | |
## Assert $1 is true, or die | |
assert () # $1: boolean, $2: an error message | |
{ | |
param_check $# 2 "assert" | |
if [ $1 -ne 0 ] | |
then | |
error "$2" | |
fi | |
} | |
## Create directory, or die | |
# === mkdir -p $1 | |
create_dir () # $1: path | |
{ | |
param_check $# 1 "create_dir" | |
mkdir -p "$1" | |
assert $? "Couldn't create $1" | |
} | |
## Destroy and create directory, or die | |
re_create_dir () # $1: path | |
{ | |
param_check $# 1 "re_create_dir" | |
destroy "$1" | |
create_dir "$1" | |
} | |
## Destroy directory, or die | |
# === rm -fr $1 | |
destroy () # $1: path | |
{ | |
param_check $# 1 "destroy" | |
rm -fr "$1" | |
assert $? "Couldn't destroy $1" | |
} | |
## [with root access] Destroy directory, or die | |
# === rm -fr $1 | |
sudo_destroy () # $1: path | |
{ | |
param_check $# 1 "sudo_destroy" | |
echo "sudo_destroy need root password for deleting $1" | |
sudo rm -fr "$1" | |
assert $? "Couldn't destroy $1" | |
} | |
## Destroy all paths, or die | |
destroy_all () # $1...N: paths | |
{ | |
param_check_ge $# 1 "destroy_all" | |
for path in "$@" | |
do | |
destroy "$path" | |
done | |
} | |
## [with root access] Destroy all paths, or die | |
sudo_destroy_all () # $1...N: paths | |
{ | |
param_check_ge $# 1 "sudo_destroy_all" | |
for path in "$@" | |
do | |
sudo_destroy "$path" | |
done | |
} | |
## Copy files/directories, recursively, or die | |
copy () # $1...N: src, $N+1: dest | |
{ | |
param_check_ge $# 2 "copy" | |
cp -R "$@" | |
assert $? "Couldn't copy $1 to $2" | |
} | |
## Go to dir with pushd, or die | |
push_pwd () # $1: path | |
{ | |
param_check $# 1 "push_pwd" | |
pushd "$1" | |
assert $? "Couldn't go to $1" | |
} | |
## Go back, or die | |
pop_pwd () | |
{ | |
param_check $# 0 "pop_pwd" | |
popd | |
assert $? "Couldn't go back" | |
} | |
## Create a .tar.gz archive, or die | |
archive () # $1: src dir, $2: archive name | |
{ | |
param_check $# 2 "archive" | |
push_pwd "$1/.." | |
src=$(basename "$1") | |
tar -zcvf "$2" "$src" | |
assert $? "Zip failed for $2" | |
pop_pwd | |
} | |
## Build SFML with CMake and Make, or die | |
build_sfml () # $1: 'clang' => clang & libc++, 'gcc' => gcc & libstdc++ | |
# $2: 'frameworks'/'dylibs'/'debug_dylibs' | |
# $3: 'doc'/'no doc' | |
# $4: 'examples'/'no examples' | |
# $5: 'templates'/'no templates' | |
# $6: 'default sdk' | |
# $7: source path | |
# $8: build path | |
# $9: install path | |
{ | |
param_check $# 9 "build_sfml" | |
create_dir "$8" | |
build_type="Release" | |
case "$1" in | |
'clang') | |
cxx="clang++" | |
cc="clang" | |
# "-Wcast-align -Wconversion -Wcovered-switch-default -Wdisabled-macro-expansion -Wdocumentation -Wno-documentation-unknown-command -Wfloat-equal -Wmissing-field-initializers -Wmissing-variable-declarations -Wold-style-cast -Wpedantic -Wself-assign -Wshadow -Wshorten-64-to-32 -Wsign-conversion -Wswitch-enum -Wno-vla-extension -Wno-old-style-cast -Wno-c++11-long-long" | |
cxx_cc_common_flags="-Wcovered-switch-default -Wdocumentation -Wno-documentation-unknown-command -Wno-documentation-deprecated-sync -Wmissing-field-initializers -Wmissing-variable-declarations -Wpedantic -Wswitch -Wno-vla-extension -Wno-old-style-cast -Wno-c++11-long-long -stdlib=libc++" | |
# cxx_flags="-stdlib=libc++" | |
# cc_flags="-stdlib=libc++" | |
;; | |
'gcc') | |
cxx="g++" | |
cc="gcc" | |
cxx_cc_common_flags="-Wall -Wextra" | |
cxx_flags="" | |
cc_flags="" | |
;; | |
*) | |
error "Unknown compiler for $1 in create_makefile" | |
;; | |
esac | |
cxx_flags="$cxx_flags $cxx_cc_common_flags" | |
cc_flags="$cc_flags $cxx_cc_common_flags" | |
install_prefix="$9/usr/local" | |
case "$2" in | |
'frameworks') | |
frameworks="TRUE" | |
install_prefix="$9/Library/Frameworks" | |
# Works around System Integrity Protection https://apple.stackexchange.com/q/208478/123882 | |
list_frameworks=`echo $install_prefix/{SFML,sfml-system,sfml-window,sfml-graphics,sfml-audio,sfml-network}.framework` | |
echo ">>>> Working Around SIP" | |
echo ">>>> sudo rm -rf $list_frameworks && sudo mkdir $list_frameworks && sudo chown `whoami` $list_frameworks" | |
sudo rm -rf $list_frameworks && sudo mkdir $list_frameworks && sudo chown `whoami` $list_frameworks || error "Couldn't work around SIP" | |
;; | |
'dylibs') | |
frameworks="FALSE" | |
;; | |
'debug_dylibs') | |
frameworks="FALSE" | |
build_type="Debug" | |
;; | |
*) | |
error "Unknown option for $2 in create_makefile" | |
;; | |
esac | |
case "$3" in | |
'doc') | |
doc="TRUE" | |
;; | |
'no doc') | |
doc="FALSE" | |
;; | |
*) | |
error "Unknown option for $3 in create_makefile" | |
;; | |
esac | |
case "$4" in | |
'examples') | |
examples="TRUE" | |
makeopts="" | |
# NB: cannot use -j8 here because it bugs with cocoa example... | |
;; | |
'no examples') | |
examples="FALSE" | |
makeopts="-j8" | |
;; | |
*) | |
error "Unknown option for $4 in create_makefile" | |
;; | |
esac | |
case "$5" in | |
'templates') | |
templates="TRUE" | |
;; | |
'no templates') | |
templates="FALSE" | |
;; | |
*) | |
error "Unknown option for $5 in create_makefile" | |
;; | |
esac | |
case "$6" in | |
'default sdk') | |
target="" | |
sdk="" | |
;; | |
*) | |
error "Unknown option for $6 in create_makefile" | |
;; | |
esac | |
re_create_dir "$8" | |
push_pwd "$8" | |
# -D "CMAKE_INSTALL_FRAMEWORK_PREFIX:STRING=$9/Library/Frameworks" \ | |
# -D "SFML_DEPENDENCIES_INSTALL_PREFIX=$9/Library/Frameworks" \ | |
cmake -G "Unix Makefiles" \ | |
-D "BUILD_SHARED_LIBS:BOOL=TRUE" \ | |
-D "CMAKE_BUILD_TYPE:STRING=$build_type" \ | |
-D "CMAKE_CXX_COMPILER:FILEPATH=/usr/bin/$cxx" \ | |
-D "CMAKE_CXX_FLAGS:STRING=$cxx_flags" \ | |
-D "CMAKE_C_COMPILER:FILEPATH=/usr/bin/$cc" \ | |
-D "CMAKE_C_FLAGS:STRING=$cc_flags" \ | |
-D "CMAKE_OSX_ARCHITECTURES:STRING=x86_64" \ | |
-D "SFML_BUILD_DOC:BOOL=$doc" \ | |
-D "SFML_BUILD_EXAMPLES:BOOL=$examples" \ | |
-D "SFML_BUILD_FRAMEWORKS:BOOL=$frameworks" \ | |
-D "CMAKE_INSTALL_PREFIX:PATH=$install_prefix" \ | |
-D "SFML_INSTALL_XCODE_TEMPLATES:BOOL=$templates" \ | |
"$7" | |
assert $? "CMake failed" | |
make clean && make $makeopts && make install | |
assert $? "Make failed" | |
pop_pwd | |
} | |
## Remove anything related to SFML | |
wipe_sfml () | |
{ | |
# Remove SFML from /usr/local | |
destroy_all "/usr/local/include/SFML" \ | |
"/usr/local/lib/"libsfml-* \ | |
"/usr/local/share/SFML" \ | |
"/usr/local/lib/cmake/SFML" | |
# Remove SFML from /Library | |
sudo_destroy_all "/Library/Frameworks/"sfml-* \ | |
"/Library/Frameworks/SFML.framework" | |
destroy_all "/Library/Developer/Xcode/Templates/SFML" | |
} | |
## | |
## INITIALIZE | |
## | |
param_check_ge $# 1 "main" | |
## Clean up before doing anything | |
wipe_sfml | |
## | |
## BUILD SFML FOR 1070, 1080, 1090 | |
## | |
# Now configure CMake for 10.7/8/9, 64bits, clang & libc++, no doc, no example, no templates | |
# and build / install SFML ! | |
build_sfml_clang_frameworks () | |
{ | |
build_sfml 'clang' 'frameworks' 'no doc' 'no examples' 'templates' "$sdk" "$src_path" "$topdir/$sdk/clang/frameworks/" "/" | |
} | |
build_sfml_clang_dylibs () | |
{ | |
build_sfml 'clang' 'dylibs' 'no doc' 'no examples' 'templates' "$sdk" "$src_path" "$topdir/$sdk/clang/dylibs/" "/" | |
} | |
build_sfml_clang_debug_dylibs() | |
{ | |
build_sfml 'clang' 'debug_dylibs' 'no doc' 'no examples' 'templates' "$sdk" "$src_path" "$topdir/$sdk/clang/debug_dylibs/" "/" | |
} | |
case "$2" in | |
'') | |
sdk="default sdk" | |
;; | |
*) | |
error "Unknown sdk $2" | |
;; | |
esac | |
case "$1" in | |
'framework'|'frameworks') | |
build_sfml_clang_frameworks | |
;; | |
'dylib'|'dylibs') | |
build_sfml_clang_dylibs | |
;; | |
'debug'|'debug dylib'|'debug dylibs') | |
build_sfml_clang_debug_dylibs | |
;; | |
'all') | |
build_sfml_clang_frameworks | |
build_sfml_clang_dylibs | |
build_sfml_clang_debug_dylibs | |
;; | |
*) | |
error "Unknown option $1" | |
;; | |
esac | |
### End Of Script | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment