2021-08-09 12:19:27 +02:00
|
|
|
#!/bin/bash
|
2021-08-29 10:15:55 +02:00
|
|
|
set -e
|
2021-08-09 12:19:27 +02:00
|
|
|
|
|
|
|
if [ ! -e "src/api/api.h" ]; then
|
2021-08-29 10:15:55 +02:00
|
|
|
echo "Please run this script from the root directory of Lite XL."; exit 1
|
2021-08-09 12:19:27 +02:00
|
|
|
fi
|
|
|
|
|
2021-08-29 10:15:55 +02:00
|
|
|
source scripts/common.sh
|
|
|
|
|
|
|
|
show_help() {
|
2021-08-09 12:19:27 +02:00
|
|
|
echo
|
|
|
|
echo "Usage: $0 <OPTIONS>"
|
|
|
|
echo
|
|
|
|
echo "Available options:"
|
|
|
|
echo
|
2023-04-11 17:33:34 +02:00
|
|
|
echo "-b --builddir DIRNAME Sets the name of the build directory (not path)."
|
|
|
|
echo " Default: '$(get_default_build_dir)'."
|
|
|
|
echo " --debug Debug this script."
|
|
|
|
echo "-f --forcefallback Force to build dependencies statically."
|
|
|
|
echo "-h --help Show this help and exit."
|
2024-10-22 17:53:17 +02:00
|
|
|
echo "-d --debug-build Builds a debug build."
|
2023-04-11 17:33:34 +02:00
|
|
|
echo "-p --prefix PREFIX Install directory prefix. Default: '/'."
|
|
|
|
echo "-B --bundle Create an App bundle (macOS only)"
|
2024-10-22 17:53:17 +02:00
|
|
|
echo "-A --addons Add in addons"
|
2023-04-11 17:33:34 +02:00
|
|
|
echo "-P --portable Create a portable binary package."
|
2024-11-16 07:10:24 +01:00
|
|
|
echo "-r --reconfigure Tries to reuse the meson build directory, if possible."
|
|
|
|
echo " Default: Deletes the build directory and recreates it."
|
2023-04-11 17:33:34 +02:00
|
|
|
echo "-O --pgo Use profile guided optimizations (pgo)."
|
|
|
|
echo " macOS: disabled when used with --bundle,"
|
|
|
|
echo " Windows: Implicit being the only option."
|
|
|
|
echo " --cross-platform PLATFORM Cross compile for this platform."
|
|
|
|
echo " The script will find the appropriate"
|
|
|
|
echo " cross file in 'resources/cross'."
|
|
|
|
echo " --cross-arch ARCH Cross compile for this architecture."
|
|
|
|
echo " The script will find the appropriate"
|
|
|
|
echo " cross file in 'resources/cross'."
|
|
|
|
echo " --cross-file CROSS_FILE Cross compile with the given cross file."
|
2021-08-09 12:19:27 +02:00
|
|
|
echo
|
|
|
|
}
|
|
|
|
|
2021-08-29 10:15:55 +02:00
|
|
|
main() {
|
|
|
|
local platform="$(get_platform_name)"
|
2022-10-30 16:48:20 +01:00
|
|
|
local arch="$(get_platform_arch)"
|
2024-10-22 17:53:17 +02:00
|
|
|
local build_dir
|
|
|
|
local plugins="welcome"
|
2021-08-29 10:15:55 +02:00
|
|
|
local prefix=/
|
2024-10-22 17:53:17 +02:00
|
|
|
local addons
|
|
|
|
local build_type="release"
|
2021-08-29 10:15:55 +02:00
|
|
|
local force_fallback
|
|
|
|
local bundle
|
|
|
|
local portable
|
2021-09-05 15:43:22 +02:00
|
|
|
local pgo
|
2023-04-11 17:33:34 +02:00
|
|
|
local cross
|
|
|
|
local cross_platform
|
|
|
|
local cross_arch
|
|
|
|
local cross_file
|
2024-11-16 07:10:24 +01:00
|
|
|
local reconfigure
|
|
|
|
local should_reconfigure
|
2021-08-09 12:19:27 +02:00
|
|
|
|
2021-08-29 10:15:55 +02:00
|
|
|
for i in "$@"; do
|
|
|
|
case $i in
|
|
|
|
-h|--help)
|
|
|
|
show_help
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
-b|--builddir)
|
|
|
|
build_dir="$2"
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
2024-10-22 17:53:17 +02:00
|
|
|
-d|--debug-build)
|
|
|
|
build_type="debug"
|
|
|
|
shift
|
|
|
|
;;
|
2024-11-16 07:10:24 +01:00
|
|
|
-r|--reconfigure)
|
|
|
|
should_reconfigure=true
|
|
|
|
shift
|
|
|
|
;;
|
2021-08-29 10:15:55 +02:00
|
|
|
--debug)
|
|
|
|
set -x
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-f|--forcefallback)
|
|
|
|
force_fallback="--wrap-mode=forcefallback"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-p|--prefix)
|
|
|
|
prefix="$2"
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
2024-10-22 17:53:17 +02:00
|
|
|
-A|--addons)
|
|
|
|
addons="1"
|
|
|
|
shift
|
|
|
|
;;
|
2021-08-29 10:15:55 +02:00
|
|
|
-B|--bundle)
|
2024-10-22 17:53:17 +02:00
|
|
|
if [[ "$platform" != "darwin" ]]; then
|
2021-08-29 10:15:55 +02:00
|
|
|
echo "Warning: ignoring --bundle option, works only under macOS."
|
|
|
|
else
|
|
|
|
bundle="-Dbundle=true"
|
|
|
|
fi
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-P|--portable)
|
|
|
|
portable="-Dportable=true"
|
|
|
|
shift
|
|
|
|
;;
|
2021-09-05 15:43:22 +02:00
|
|
|
-O|--pgo)
|
|
|
|
pgo="-Db_pgo=generate"
|
|
|
|
shift
|
|
|
|
;;
|
2023-04-11 17:33:34 +02:00
|
|
|
--cross-arch)
|
|
|
|
cross="true"
|
|
|
|
cross_arch="$2"
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--cross-platform)
|
|
|
|
cross="true"
|
|
|
|
cross_platform="$2"
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--cross-file)
|
|
|
|
cross="true"
|
|
|
|
cross_file="$2"
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
2021-08-29 10:15:55 +02:00
|
|
|
*)
|
|
|
|
# unknown option
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
2021-08-09 12:19:27 +02:00
|
|
|
|
2021-08-29 10:15:55 +02:00
|
|
|
if [[ -n $1 ]]; then
|
|
|
|
show_help
|
|
|
|
exit 1
|
|
|
|
fi
|
2021-08-09 12:19:27 +02:00
|
|
|
|
2021-08-29 10:15:55 +02:00
|
|
|
if [[ $platform == "macos" && -n $bundle && -n $portable ]]; then
|
|
|
|
echo "Warning: \"bundle\" and \"portable\" specified; excluding portable package."
|
|
|
|
portable=""
|
2021-08-09 12:19:27 +02:00
|
|
|
fi
|
|
|
|
|
2023-04-11 17:33:34 +02:00
|
|
|
# if CROSS_ARCH is used, it will be picked up
|
|
|
|
cross="${cross:-$CROSS_ARCH}"
|
|
|
|
if [[ -n "$cross" ]]; then
|
|
|
|
if [[ -n "$cross_file" ]] && ([[ -z "$cross_arch" ]] || [[ -z "$cross_platform" ]]); then
|
|
|
|
echo "Warning: --cross-platform or --cross-platform not set; guessing it from the filename."
|
|
|
|
# remove file extensions and directories from the path
|
|
|
|
cross_file_name="${cross_file##*/}"
|
|
|
|
cross_file_name="${cross_file_name%%.*}"
|
|
|
|
# cross_platform is the string before encountering the first hyphen
|
|
|
|
if [[ -z "$cross_platform" ]]; then
|
|
|
|
cross_platform="${cross_file_name%%-*}"
|
|
|
|
echo "Warning: Guessing --cross-platform $cross_platform"
|
|
|
|
fi
|
|
|
|
# cross_arch is the string after encountering the first hyphen
|
|
|
|
if [[ -z "$cross_arch" ]]; then
|
|
|
|
cross_arch="${cross_file_name#*-}"
|
|
|
|
echo "Warning: Guessing --cross-arch $cross_arch"
|
2022-11-10 07:16:28 +01:00
|
|
|
fi
|
2022-10-31 00:05:17 +01:00
|
|
|
fi
|
2023-04-11 17:33:34 +02:00
|
|
|
platform="${cross_platform:-$platform}"
|
|
|
|
arch="${cross_arch:-$arch}"
|
2024-10-22 17:53:17 +02:00
|
|
|
cross_file="--cross-file ${cross_file:-resources/cross/$platform-$arch.txt}"
|
2023-04-11 17:33:34 +02:00
|
|
|
# reload build_dir because platform and arch might change
|
2024-10-22 17:53:17 +02:00
|
|
|
if [[ "$build_dir" == "" ]]; then
|
|
|
|
build_dir="$(get_default_build_dir "$platform" "$arch")"
|
|
|
|
fi
|
|
|
|
elif [[ "$build_dir" == "" ]]; then
|
|
|
|
build_dir="$(get_default_build_dir)"
|
2023-04-11 17:33:34 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# arch and platform specific stuff
|
|
|
|
if [[ "$platform" == "macos" ]]; then
|
|
|
|
macos_version_min="10.11"
|
|
|
|
if [[ "$arch" == "arm64" ]]; then
|
|
|
|
macos_version_min="11.0"
|
|
|
|
fi
|
|
|
|
export MACOSX_DEPLOYMENT_TARGET="$macos_version_min"
|
|
|
|
export MIN_SUPPORTED_MACOSX_DEPLOYMENT_TARGET="$macos_version_min"
|
|
|
|
export CFLAGS="-mmacosx-version-min=$macos_version_min"
|
|
|
|
export CXXFLAGS="-mmacosx-version-min=$macos_version_min"
|
|
|
|
export LDFLAGS="-mmacosx-version-min=$macos_version_min"
|
2022-10-30 16:48:20 +01:00
|
|
|
fi
|
|
|
|
|
2024-11-16 07:10:24 +01:00
|
|
|
if [[ $should_reconfigure == true ]] && [[ -d "${build_dir}" ]]; then
|
|
|
|
reconfigure="--reconfigure"
|
|
|
|
elif [[ -d "${build_dir}" ]]; then
|
|
|
|
rm -rf "${build_dir}"
|
2023-04-07 19:25:31 +02:00
|
|
|
fi
|
|
|
|
|
2021-08-09 12:19:27 +02:00
|
|
|
CFLAGS=$CFLAGS LDFLAGS=$LDFLAGS meson setup \
|
2024-10-22 17:53:17 +02:00
|
|
|
"${build_dir}" \
|
|
|
|
--buildtype "$build_type" \
|
2021-08-29 10:15:55 +02:00
|
|
|
--prefix "$prefix" \
|
2024-10-22 17:53:17 +02:00
|
|
|
$cross_file \
|
2021-08-29 10:15:55 +02:00
|
|
|
$force_fallback \
|
|
|
|
$bundle \
|
|
|
|
$portable \
|
2021-09-05 15:43:22 +02:00
|
|
|
$pgo \
|
2024-11-16 07:10:24 +01:00
|
|
|
$reconfigure
|
2021-08-09 12:19:27 +02:00
|
|
|
|
2021-08-29 10:15:55 +02:00
|
|
|
meson compile -C "${build_dir}"
|
2021-09-05 15:43:22 +02:00
|
|
|
|
2024-10-22 17:53:17 +02:00
|
|
|
cp -r data "${build_dir}/src"
|
|
|
|
|
2022-10-30 16:48:20 +01:00
|
|
|
if [[ $pgo != "" ]]; then
|
2021-09-05 15:43:22 +02:00
|
|
|
"${build_dir}/src/lite-xl"
|
|
|
|
meson configure -Db_pgo=use "${build_dir}"
|
|
|
|
meson compile -C "${build_dir}"
|
|
|
|
rm -fr "${build_dir}/data"
|
|
|
|
fi
|
2024-10-22 17:53:17 +02:00
|
|
|
|
|
|
|
rm -fr $build_dir/src/lite-xl.*p $build_dir/src/*.o
|
|
|
|
|
|
|
|
if [[ $addons != "" ]]; then
|
2024-10-22 19:03:56 +02:00
|
|
|
[[ ! -e "$build_dir/lpm" ]] && curl --insecure -L "https://github.com/lite-xl/lite-xl-plugin-manager/releases/download/v1.2.9/lpm.$(get_platform_tuple)$(get_executable_extension)" -o "$build_dir/lpm$(get_executable_extension)" && chmod +x "$build_dir/lpm$(get_executable_extension)"
|
2024-10-22 17:53:17 +02:00
|
|
|
"$build_dir/lpm$(get_executable_extension)" install --datadir ${build_dir}/src/data --userdir ${build_dir}/src/data --arch $(get_platform_tuple) $plugins --assume-yes; "$build_dir/lpm$(get_executable_extension)" purge --datadir ${build_dir}/src/data --userdir ${build_dir}/src/data && chmod -R a+r ${build_dir}
|
|
|
|
fi
|
|
|
|
|
|
|
|
mv "${build_dir}/src" "${build_dir}/lite-xl"
|
2021-08-09 12:19:27 +02:00
|
|
|
}
|
|
|
|
|
2021-08-29 10:15:55 +02:00
|
|
|
main "$@"
|