Reinstate original build scripts with updated directory structure

This commit is contained in:
Rene Hexel 2021-01-10 11:54:48 +10:00
parent 26013d5279
commit 7a23b06d8f
10 changed files with 180 additions and 0 deletions

8
build.sh Executable file
View File

@ -0,0 +1,8 @@
#!/bin/sh
#
# Wrapper around `swift build' that uses pkg-config in config.sh
# to determine compiler and linker flags
#
. ./config.sh
[ -e Sources/${Mod}/${Module}.swift ] || ./generate-wrapper.sh
exec swift build --build-path "$BUILD_DIR" $CCFLAGS $LINKFLAGS "$@"

5
clean.sh Executable file
View File

@ -0,0 +1,5 @@
#!/bin/sh
#
# Remove the .build folder
#
exec rm -rf .build

31
config.sh Executable file
View File

@ -0,0 +1,31 @@
#!/bin/sh
#
# Configuration for the module to compile, the Swift toolchain, and
# the compiler and linker flags to use.
#
VER=3.0
GLIB_VER=2.0
JAZZY_VER=3.24.22
Mod=Gdk
Module=${Mod}-$VER
module=`echo "${Module}" | tr '[:upper:]' '[:lower:]'`
mod=`echo "${Mod}" | tr '[:upper:]' '[:lower:]'`
if [ -z "$BUILD_DIR" ]; then
if `pwd -P | grep -q Dropbox` ; then
export BUILD_DIR="/tmp/.build-$Module"
else
export BUILD_DIR="$PWD/.build"
fi
fi
export PATH="${GIR2SWIFT_PATH}:${BUILD_DIR}/gir2swift/.build/release:${BUILD_DIR}/gir2swift/.build/debug:${PATH}:$PWD/.build/gir2swift/.build/release:$PWD/.build/gir2swift/.build/debug:${PATH}:/usr/local/opt/ruby/bin:`echo /usr/local/lib/ruby/gems/*/bin | tr ' ' '\n' | tail -n1`:${PATH}:`echo /var/lib/gems/*/gems/jazzy-*/bin/ | tr ' ' '\n' | tail -n1`:/usr/local/bin"
export PKG_CONFIG_PATH=/usr/local/opt/libffi/lib/pkgconfig:${PKG_CONFIG_PATH}
LINKFLAGS=`pkg-config --libs $module pangocairo pangoft2 pango gobject-$GLIB_VER gio-unix-$GLIB_VER glib-$GLIB_VER | tr ' ' '\n' | sed -e 's/^/-Xlinker /' -e 's/-Wl,//' | tr '\n' ' ' | sed -e 's/^/-Xlinker /' -e 's/-Wl,//g' -e 's/,/ -Xlinker /g' -e 's/ -pthread/ -lpthread/g' -e 's/-Xcc[ ]*-Xlinker/-Xlinker/g' -e 's/-Xlinker[ ]*-Xcc/-Xcc/g' -e 's/-Xlinker[ ]*--export-dynamic//g' -e 's/-Xlinker[ ]*-Xlinker/-Xlinker/g' -e 's/-Xcc *$//' -e 's/-Xlinker *$//'`
CCFLAGS=`pkg-config --cflags $module pangocairo pangoft2 pango gobject-$GLIB_VER gio-unix-$GLIB_VER glib-$GLIB_VER | tr ' ' '\n' | sed 's/^/-Xcc /' | tr '\n' ' ' | sed -e 's/^/-Xlinker /' -e 's/-Wl,//g' -e 's/,/ -Xlinker /g' -e 's/ -pthread/ -lpthread/g' -e 's/-Xcc[ ]*-Xlinker/-Xlinker/g' -e 's/-Xlinker[ ]*-Xcc/-Xcc/g' -e 's/-Xlinker[ ]*--export-dynamic//g' -e 's/-Xlinker[ ]*-Xlinker/-Xlinker/g' -e 's/-Xcc *$//' -e 's/-Xlinker *$//'`
TAC="tail -r"
if which tac >/dev/null 2>&1 ; then
TAC=tac
else if which gtac >/dev/null 2>&1 ; then
TAC=gtac
fi
fi
JAZZY_B=`echo $CCFLAGS $LINKFLAGS | sed 's/ */,/g'`

7
distclean.sh Executable file
View File

@ -0,0 +1,7 @@
#!/bin/sh
#
# Remove Packages directory and generated files
#
. ./config.sh
./clean.sh
exec rm -rf Package.pins Packages Package.resolved Sources/${Mod}/*-*.swift Sources/${Mod}/${Module}.swift Sources/${Mod}/Swift${Mod}.swift ${Mod}.xcodeproj

19
generate-documentation.sh Executable file
View File

@ -0,0 +1,19 @@
#!/bin/sh
#
# Wrapper around `swift build' that uses pkg-config in config.sh
# to determine compiler and linker flags
#
. ./config.sh
[ -e Sources/${Mod}/${Module}.swift ] || ./generate-wrapper.sh
if [ -z "$@" ]; then
JAZZY_ARGS="--theme fullwidth --author René Hexel --author_url https://experts.griffith.edu.au/9237-rene-hexel --github_url https://github.com/rhx/Swift$Mod --github-file-prefix https://github.com/rhx/Swift$Mod/tree/generated --root-url http://rhx.github.io/Swift$Mod/ --output docs"
fi
[ -e "$BUILD_DIR/build.db" ] || ./build.sh
rm -rf .docs.old
mv docs .docs.old 2>/dev/null
[ -e .build ] || ln -s "$BUILD_DIR" .build
sourcekitten doc --spm --module-name $Mod -- --build-path "$BUILD_DIR" \
$CCFLAGS $LINKFLAGS > "$BUILD_DIR/$Mod-doc.json"
jazzy --sourcekitten-sourcefile "$BUILD_DIR/$Mod-doc.json" --clean \
--module-version $JAZZY_VER --module $Mod $JAZZY_ARGS "$@"
rm -f .build 2>/dev/null

35
generate-wrapper.sh Executable file
View File

@ -0,0 +1,35 @@
#!/bin/bash
#
# Recursive swift code wrapper generator for gobject-introspection (.gir) files.
# This calls the non-recursive gir-to-swift.sh to do the heavy lifting.
#
. ./config.sh
./package.sh update
if [ ! -x "${GIR2SWIFT_PATH}/gir2swift" -a \
! -e "$BUILD_DIR/checkouts/gir2swift" ] ; then
mkdir -p "$BUILD_DIR/checkouts" 2>/dev/null
pushd "$BUILD_DIR/checkouts" >/dev/null
git clone https://github.com/rhx/gir2swift.git
popd >/dev/null 2>&1
fi
if [ ! -x "${GIR2SWIFT_PATH}/gir2swift" ] &&
! -e "$BUILD_DIR/checkouts/gir2swift/.build/release/gir2swift" >/dev/null 2>&1 ; then
pushd "$BUILD_DIR/checkouts/gir2swift" >/dev/null
./build.sh
fi
export PATH="$PWD/.build/release:${PATH}"
popd >/dev/null 2>&1
export PACKAGES="${BUILD_DIR}/checkouts"
[ -e $PACKAGES ] || export PACKAGES=Packages
if which parallel >/dev/null ; then
for gen in $PACKAGES/*/gir-to-swift.sh ; do \
echo echo \"Generate Swift Wrapper for `basename $(dirname $gen) | cut -d- -f1`\" \; \
"( cd `dirname $gen` && ./`basename $gen` $@ )" ; \
done | $TAC | parallel
else
for gen in $PACKAGES/*/gir-to-swift.sh ; do
echo "Generate Swift Wrapper for `basename $(dirname $gen) | cut -d- -f1`"
( cd `dirname $gen` && ./`basename $gen` "$@" )
done
fi
. ./gir-to-swift.sh "$@"

37
gir-to-swift.sh Executable file
View File

@ -0,0 +1,37 @@
#!/bin/sh
#
# Swift code wrapper generator for gobject-introspection (.gir) files.
# This needs an installed `gir2swift' executable (github.com/rhx/gir2swift)
#
. ./config.sh
mkdir -p Sources/${Mod}
GOBJECT_LIBDIR=`pkg-config --libs-only-L gobject-introspection-1.0 2>/dev/null | tr ' ' '\n' | grep gobject-introspection | tail -n1 | cut -c3-`
GOBJECT_DIR=`dirname "${GOBJECT_LIBDIR}"`
for prefix in $PREFIX GOBJECT_DIR /usr/local /usr ; do
gir_dir=${prefix}/share/gir-1.0
gir=${gir_dir}/${Module}.gir
if [ -e "${gir}" ] ; then
export GIR=${gir}
export GIR_DIR=${gir_dir}
fi
done
if [ ! -e "${GIR}" ] ; then
echo "*** ${GIR} does not exist!"
echo "Make sure libgirepository1.0-dev is installed"
echo "and can be found in /usr /usr/local or by pkg-config!"
exit 1
fi
gir2swift -p ${GIR_DIR}/GLib-2.0.gir -p ${GIR_DIR}/GObject-2.0.gir -p ${GIR_DIR}/Pango-1.0.gir -p ${GIR_DIR}/cairo-1.0.gir -p ${GIR_DIR}/PangoCairo-1.0.gir -p ${GIR_DIR}/GdkPixbuf-2.0.gir "${GIR}" | sed -f ${Module}.sed | awk -f ${Module}.awk > Sources/${Mod}/${Module}.swift
gir2swift -o Sources/${Mod} -m ${Module}.module -p ${GIR_DIR}/GLib-2.0.gir -p ${GIR_DIR}/GObject-2.0.gir -p ${GIR_DIR}/Pango-1.0.gir -p ${GIR_DIR}/cairo-1.0.gir -p ${GIR_DIR}/PangoCairo-1.0.gir -p ${GIR_DIR}/GdkPixbuf-2.0.gir "${GIR}"
if which parallel >/dev/null ; then
for src in Sources/${Mod}/*-*.swift ; do \
echo "sed -f ${Module}.sed < ${src} |" \
"awk -f ${Module}.awk > ${src}.out" \; \
"mv ${src}.out ${src}" ; \
done | parallel
else
for src in Sources/${Mod}/*-*.swift ; do
sed -f ${Module}.sed < ${src} | awk -f ${Module}.awk > ${src}.out
mv ${src}.out ${src}
done
fi

7
package.sh Executable file
View File

@ -0,0 +1,7 @@
#!/bin/sh
#
# Wrapper around the Swift package manager that includes config.sh
# to pass compiler and linker flags.
#
. ./config.sh
exec swift package --build-path "$BUILD_DIR" $CCFLAGS $LINKFLAGS "$@"

8
test.sh Executable file
View File

@ -0,0 +1,8 @@
#!/bin/sh
#
# Wrapper around `swift test' using config.sh and checking
# that the swift wrapper code exists
#
. ./config.sh
[ -e Sources/${Mod}/${Module}.swift ] || ./generate-wrapper.sh
exec swift test --build-path "$BUILD_DIR" $CCFLAGS $LINKFLAGS "$@"

23
xcodegen.sh Executable file
View File

@ -0,0 +1,23 @@
#!/bin/sh
#
# Script to generate an Xcode project using the Swift package manager.
# The generated project gets patched to configure the header search paths
# and pass them to subprojects, based on the configured -I flags.
#
. ./config.sh
[ -e Sources/${Mod}/${Module}.swift ] || ./generate-wrapper.sh
./package.sh generate-xcodeproj "$@"
[ ! -e ${Mod}.xcodeproj/Configs ] || \
( cd ${Mod}.xcodeproj/Configs && \
mv Project.xcconfig Project.xcconfig.in && \
echo 'SWIFT_VERSION = 3.0' >> Project.xcconfig.in && \
sed -e 's/ -I ?[^ ]*//g' < Project.xcconfig.in > Project.xcconfig && \
grep 'OTHER_CFLAGS' < Project.xcconfig.in | sed 's/-I */-I/g' | \
tr ' ' '\n' | grep -- -I | tr '\n' ' ' | \
sed -e 's/^/HEADER_SEARCH_PATHS = /' -e 's/ -I/ /g' >> Project.xcconfig
)
( cd ${Mod}.xcodeproj && \
mv project.pbxproj project.pbxproj.in && \
sed < project.pbxproj.in > project.pbxproj \
-e "s|\(HEADER_SEARCH_PATHS = .\)$|\\1 \"`echo $CCFLAGS | sed -e 's/-Xcc *-I */ /g' -e 's/^ *//' -e 's/ *$//'`\",|"
)