diff --git a/README-CMake.md b/README-CMake.md index 8401b39..ab7ee07 100644 --- a/README-CMake.md +++ b/README-CMake.md @@ -49,6 +49,11 @@ You may want to add `-jN` (where N is amount of threads you want to run) option to build commands, because default for `make` is to run single-threaded and `ninja` tends to use too much threads which eat up your RAM (may vary). +Note for packagers: +On Unix systems, the Synfig Studio looks out for its symbols, sounds and plugins at CMAKE_INSTALL_PREFIX/share. +If you want to change the prefix you need to overwrite the `DATA_PREFIX` variable. +Pass `-DDATA_PREFIX=/usr` for example to made Synfig Studio look at /usr/share for its data. + ### Building ``` diff --git a/autobuild/build-cmake-common.sh b/autobuild/build-cmake-common.sh index b0e8ef1..8359a01 100755 --- a/autobuild/build-cmake-common.sh +++ b/autobuild/build-cmake-common.sh @@ -5,6 +5,7 @@ build_mode="Debug" make_jobs=1 make_build_command="make -j $make_jobs" print_build_settings_and_exit="false" +write_portable_run_code="true" # Define build dirs cmake_debug_build_dir="_debug" @@ -29,8 +30,11 @@ cmake_dataprefix_option="" build_etl() { echo "Building ETL" + # Navigate to target build dir cd ${absolute_base_dir} cd "./${cmake_build_dir}/${etl_build_dir}" + + # Configure, make and install cmake "$cmake_build_type_option" "$cmake_install_prefix_option" ../../ETL/ && $make_build_command && make install if [ $? -ne 0 ] @@ -48,8 +52,11 @@ build_etl() { build_synfig_core() { echo "Building synfig-core" + # Navigate to target build dir cd ${absolute_base_dir} cd "./${cmake_build_dir}/${synfig_build_dir}" + + # Configure, make and install cmake "$cmake_build_type_option" "$cmake_install_prefix_option" "$cmake_cxxflags_option" ../../synfig-core/ && $make_build_command && make install if [ $? -ne 0 ] @@ -67,9 +74,12 @@ build_synfig_core() { build_synfig_studio() { echo "Building synfig-studio" + # Navigate to target build dir cd ${absolute_base_dir} cd "./${cmake_build_dir}/${synfigstudio_build_dir}" - cmake "$cmake_build_type_option" "$cmake_prefix_option" "$cmake_install_prefix_option" "$cmake_cxxflags_option" "$cmake_dataprefix_option" ../../synfig-studio/ && $make_build_command && "$(get_run_cmd_prefix)" make build_images && make install + + # Configure, make and install + cmake "$cmake_build_type_option" "$cmake_prefix_option" "$cmake_install_prefix_option" "$cmake_cxxflags_option" "$cmake_dataprefix_option" ../../synfig-studio/ && $make_build_command && run_command_in_outenv "make build_images" && make install if [ $? -ne 0 ] then @@ -109,12 +119,13 @@ get_run_cmd_prefix() { parse_build_arguments() { make_jobs_parameter=$make_jobs - ## Parse arguments + ## Parse arguments and set variables (if an option was found) while [ "$1" != '' ] do [ $1 == "-d" ] && build_mode="Debug" [ $1 == "-r" ] && build_mode="Release" [ $1 == "-p" ] && print_build_settings_and_exit="true" + [ $1 == "-n" ] && write_portable_run_code="false" [ $1 == "-j" ] && make_jobs_parameter=$2 && shift [ $1 == "--data-prefix" ] && synfigstudio_data_prefix=$2 && shift shift @@ -146,6 +157,7 @@ parse_build_arguments() { make_jobs=$make_jobs_parameter fi + # Set custom make command make_build_command="make -j $make_jobs" } @@ -155,6 +167,7 @@ print_build_settings() { echo "Build jobs: $make_jobs" [ ! $cmake_dataprefix_option == "" ] && echo "Custom data prefix: $cmake_dataprefix_option" + # If script was startet with '-p' stop the script here if [ $print_build_settings_and_exit == "true" ] then exit @@ -162,10 +175,82 @@ print_build_settings() { } run_command_in_outenv() { + # Check parameters count if [ "$#" -eq 1 ] then env_run_command="$1" fi - "$(get_run_cmd_prefix) $env_run_command" + # Set env and run command + bash -c "export $(get_run_cmd_prefix) && $env_run_command" +} + +write_portable_run_code() { + # Only write, if it is enabled + if [ $write_portable_run_code == "true" ] + then + # Navigate to out dir + cd ${absolute_base_dir} + cd "./${cmake_build_dir}/${out_dir}" + + file_name="run-portable.sh" + filepath_write_target="./${file_name}" + + echo "Writing runcode to: ${absolute_base_dir}/${cmake_build_dir}/${out_dir}/${file_name}" + + # Define the bash script code, which runs Synfig Studio + portable_run_code_line_01="#!/usr/bin/env bash" + portable_run_code_line_02="# Usage:" + portable_run_code_line_03="# $filepath_write_target [command]" + portable_run_code_line_04="# or $filepath_write_target \"[command] [args]\"" + portable_run_code_line_05="#" + portable_run_code_line_06="# Where:" + portable_run_code_line_07="# command = Command to exec in the out env (Default: \"synfigstudio\")" + portable_run_code_line_08="# args = Parameters passed to the command (Default: empty)" + portable_run_code_line_09="# " + portable_run_code_line_10="# Examples:" + portable_run_code_line_11="# Run Synfig Studio:" + portable_run_code_line_12="# $filepath_write_target" + portable_run_code_line_13="# Get help of the Synfig CLI program:" + portable_run_code_line_14="# $filepath_write_target \"synfig --help\"" + portable_run_code_line_15="# Get bash env to use the Synfig tools directly" + portable_run_code_line_16="# $filepath_write_target bash" + portable_run_code_line_17="# Now you can type synfig or synfigstudio directly to run them" + portable_run_code_line_18="# You can type \"exit\" to end this session" + portable_run_code_line_19="" + portable_run_code_line_20="run_command_string=\"\$1\"" + portable_run_code_line_21="[ \"\$1\" == '' ] && run_command_string=synfigstudio" + portable_run_code_line_22="" + portable_run_code_line_23="$(get_run_cmd_prefix) \$run_command_string" + portable_run_code_line_24="" + + # Write out the code (line by line). + echo -e "$portable_run_code_line_01" > "$filepath_write_target" + echo -e "$portable_run_code_line_02" >> "$filepath_write_target" + echo -e "$portable_run_code_line_03" >> "$filepath_write_target" + echo -e "$portable_run_code_line_04" >> "$filepath_write_target" + echo -e "$portable_run_code_line_05" >> "$filepath_write_target" + echo -e "$portable_run_code_line_06" >> "$filepath_write_target" + echo -e "$portable_run_code_line_07" >> "$filepath_write_target" + echo -e "$portable_run_code_line_08" >> "$filepath_write_target" + echo -e "$portable_run_code_line_09" >> "$filepath_write_target" + echo -e "$portable_run_code_line_10" >> "$filepath_write_target" + echo -e "$portable_run_code_line_11" >> "$filepath_write_target" + echo -e "$portable_run_code_line_12" >> "$filepath_write_target" + echo -e "$portable_run_code_line_13" >> "$filepath_write_target" + echo -e "$portable_run_code_line_14" >> "$filepath_write_target" + echo -e "$portable_run_code_line_15" >> "$filepath_write_target" + echo -e "$portable_run_code_line_16" >> "$filepath_write_target" + echo -e "$portable_run_code_line_17" >> "$filepath_write_target" + echo -e "$portable_run_code_line_18" >> "$filepath_write_target" + echo -e "$portable_run_code_line_19" >> "$filepath_write_target" + echo -e "$portable_run_code_line_20" >> "$filepath_write_target" + echo -e "$portable_run_code_line_21" >> "$filepath_write_target" + echo -e "$portable_run_code_line_22" >> "$filepath_write_target" + echo -e "$portable_run_code_line_23" >> "$filepath_write_target" + echo -e "$portable_run_code_line_24" >> "$filepath_write_target" + + # Make the runscript executable + chmod 755 "$filepath_write_target" + fi } diff --git a/build-cmake.sh b/build-cmake.sh index f1414d2..a5cbfa0 100755 --- a/build-cmake.sh +++ b/build-cmake.sh @@ -6,6 +6,7 @@ # OPTIONS # -d = Debug build (standard) # -r = Release build +# -n = Don't write the run-portable.sh to the out dir # -j NUMBER = Set parallel make jobs (1 <= NUMBER <= 999) (standard is 1) # -p = Only print out the current active build settings and exit # --data-prefix = The installed Synfig Studio looks for it's data (icons, sounds, etc) in [DATA_PREFIX]/share/. This option sets a custom DATA_PREFIX. (Standard is the out directory) @@ -54,5 +55,7 @@ build_synfig_core build_synfig_studio +write_portable_run_code + echo "Build successfull" cd "$pwd_dir" diff --git a/run-cmake.sh b/run-cmake.sh deleted file mode 100755 index ab5e4be..0000000 --- a/run-cmake.sh +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/env bash -# -# = Usage: = -# ./run-cmake.sh [-r] [command] -# -# Options -# -r = Use the release build (standard is debug build) -# -# = Examples: = -# Run Synfig Studio debug build -# ./run-cmake.sh -# Run Synfig Studio release build -# ./run-cmake.sh -r -# Run Synfig CLI (debug build) with parameters -# ./run-cmake.sh "synfig --help-all" -# Create a bash session for running the portable build (debug build) -# ./run-cmake.sh bash - -#Define dir paths -pwd_dir="$PWD" -absolute_script_path="$(readlink -f "$0")" -absolute_base_dir="$(dirname "$absolute_script_path")" - -cd ${absolute_base_dir} - -# Include build folder names and run function -source ./autobuild/build-cmake-common.sh - -if [ "$1" == "-r" ] - then - cmake_build_dir="$cmake_release_build_dir" - shift - else - cmake_build_dir="$cmake_debug_build_dir" -fi - -if [ ! -d "./${cmake_build_dir}/${out_dir}" ] - then - echo "Output directory not found!" - echo "You have to run build-cmake.sh first!" - exit -fi - -if [ "$#" -eq 1 ] - then - current_run_cmd="$1" - run_command_in_outenv "$current_run_cmd" - else - run_command_in_outenv -fi