Wed, 19 Feb 2025 18:12:10 +0100
add configure option for static linking
configure | file | annotate | diff | comparison | revisions | |
make/project.xml | file | annotate | diff | comparison | revisions | |
src/main.cpp | file | annotate | diff | comparison | revisions |
--- a/configure Tue Feb 18 19:09:02 2025 +0100 +++ b/configure Wed Feb 19 18:12:10 2025 +0100 @@ -110,6 +110,9 @@ --debug add extra compile flags for debug builds --release add extra compile flags for release builds +Optional Features: + --enable-static statically link libstdc++ + __EOF__ } @@ -174,6 +177,8 @@ "--help"*) printhelp; abort_configure ;; "--debug") BUILD_TYPE="debug" ;; "--release") BUILD_TYPE="release" ;; + "--enable-static") FEATURE_STATIC=on ;; + "--disable-static") unset FEATURE_STATIC ;; "-"*) echo "unknown option: $ARG"; abort_configure ;; esac done @@ -274,6 +279,37 @@ fi } +dependency_error_static() +{ + print_check_msg "$dep_checked_static" "checking for static... " + # dependency static toolchain="gcc" + while true + do + if notistoolchain "gcc"; then + break + fi + TEMP_LDFLAGS="$TEMP_LDFLAGS -static" + print_check_msg "$dep_checked_static" "yes\n" + dep_checked_static=1 + return 1 + done + + # dependency static toolchain="clang" + while true + do + if notistoolchain "clang"; then + break + fi + TEMP_LDFLAGS="$TEMP_LDFLAGS -static" + print_check_msg "$dep_checked_static" "yes\n" + dep_checked_static=1 + return 1 + done + + print_check_msg "$dep_checked_static" "no\n" + dep_checked_static=1 + return 0 +} # start collecting dependency information echo > "$TEMP_DIR/flags.mk" @@ -320,14 +356,34 @@ # echo >> "$TEMP_DIR/flags.mk" -echo "configuring target: default" -echo "# flags for target default" >> "$TEMP_DIR/flags.mk" +echo "configuring global target" +echo "# flags for unnamed target" >> "$TEMP_DIR/flags.mk" TEMP_CFLAGS= TEMP_CXXFLAGS= TEMP_LDFLAGS= # Features +if [ -n "$FEATURE_STATIC" ]; then + # check dependency + if dependency_error_static ; then + # "auto" features can fail and are just disabled in this case + if [ "$FEATURE_STATIC" = "auto" ]; then + DISABLE_FEATURE_STATIC=1 + else + DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED static " + ERROR=1 + fi + fi + if [ -n "$DISABLE_FEATURE_STATIC" ]; then + unset FEATURE_STATIC + fi +fi +if [ -n "$FEATURE_STATIC" ]; then + : +else + : +fi if [ -n "${TEMP_CFLAGS}" ] && [ -n "$lang_c" ]; then @@ -370,6 +426,12 @@ echo "Build Config:" echo " PREFIX: $prefix" echo " TOOLCHAIN: $TOOLCHAIN_NAME" +echo "Features:" +if [ -n "$FEATURE_STATIC" ]; then +echo " static: on" +else +echo " static: off" +fi echo # generate the config.mk file
--- a/make/project.xml Tue Feb 18 19:09:02 2025 +0100 +++ b/make/project.xml Wed Feb 19 18:12:10 2025 +0100 @@ -4,5 +4,17 @@ <lang>cpp</lang> <cxxflags>-std=c++23</cxxflags> </dependency> + <dependency name="static" toolchain="gcc"> + <ldflags>-static</ldflags> + </dependency> + <dependency name="static" toolchain="clang"> + <ldflags>-static</ldflags> + </dependency> + <target> + <feature name="static"> + <desc>statically link libstdc++</desc> + <dependencies>static</dependencies> + </feature> + </target> </project>