diff options
| author | ruki <[email protected]> | 2023-01-17 22:59:03 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2023-01-17 22:59:03 +0800 |
| commit | f6c553dca9fc154956af407c36a05ac7c102850b (patch) | |
| tree | fc33ded7b79baa3c3fbfa6e988977b29a3b3264c | |
| parent | 0d24972843162a183454095fb8078e64b8881c69 (diff) | |
update configure
| -rwxr-xr-x | configure | 127 |
1 files changed, 114 insertions, 13 deletions
@@ -54,6 +54,12 @@ print() { printf "${@}\n" } +wprint() { + if "${xmake_sh_verbose}"; then + printf "warning: ${@}\n" + fi +} + # test empty string test_z() { if test "x${1}" = "x"; then @@ -655,9 +661,9 @@ if test -d "/usr/local"; then elif test -d "/usr"; then _install_prefix_default="/usr" fi -_install_bindir_default="bin" -_install_libdir_default="lib" -_install_includedir_default="include" +_install_bindir_default="\${prefix}/bin" +_install_libdir_default="\${prefix}/lib" +_install_includedir_default="\${prefix}/include" # determining target platform # e.g. @@ -2570,12 +2576,15 @@ Common options: --toolchain=TOOLCHAIN Set toolchain name. - clang - gcc + --buildir=DIR Set build directory. (default: '"${xmake_sh_buildir}"') +Autoconf options: + --build=BUILD Configure for building on BUILD [guessed] + --host=HOST Cross-compile to build programs to run on HOST [BUILD] --prefix=PREFIX Set install files directory in tree rooted at PREFIX. (default: '"${_install_prefix_default}"') --bindir=DIR Set install binaries directory in PREFIX/DIR. (default: '"${_install_bindir_default}"') --libdir=DIR Set install libraries directory in PREFIX/DIR. (default: '"${_install_libdir_default}"') --includedir=DIR Set install includes directory in PREFIX/DIR. (default: '"${_install_includedir_default}"') - --buildir=DIR Set build directory. (default: '"${xmake_sh_buildir}"') Project options: '"$(_show_options_usage)"' @@ -2603,6 +2612,7 @@ _show_version() { # --foo=yes => foo _parse_argument_name() { _ret=$(echo "${1#*--}" | sed "s/${2-=[^=]*}$//") + string_replace "${_ret}" "-" "_" } # --foo=yes => yes @@ -2662,6 +2672,12 @@ _handle_option() { elif test_eq "${name}" "buildir"; then xmake_sh_buildir="${value}" return 0 + elif test_eq "${name}" "build"; then + _autoconf_build_type="${value}" + return 0 + elif test_eq "${name}" "host"; then + _autoconf_host_type="${value}" + return 0 elif _has_option "${name}"; then _set_option_value "${name}" "${value}" return 0 @@ -2669,14 +2685,96 @@ _handle_option() { return 1 } while test $# != 0; do - if _handle_option ${1}; then - shift - else - raise "Unknown option: $1" + if ! _handle_option ${1}; then + wprint "unknown option: $1" fi + shift done #----------------------------------------------------------------------------- +# handle some autoconf configurations +# + +# parse triplet +# e.g. i686-linux-gnu, aarch64-apple-darwin, x86_64-w64-mingw32 +_parse_triplet() { + local triplet="${1}" + string_split "${triplet}" "-" +} + +_get_arch_from_cpu() { + local cpu="${1}" + case "${cpu}" in + i686) _ret="i386";; + i386) _ret="i386";; + x86_64) _ret="x86_64";; + aarch64) _ret="arm64";; + arm64) _ret="arm64";; + arm*) _ret="arm";; + *) _ret="${cpu}";; + esac +} + +_get_plat_from_vendor_os() { + local vendor="${1}" + local os="${2}" + case "${vendor}" in + linux) + if string_contains "${os}" "android"; then + _ret="android" + else + _ret="linux" + fi + ;; + apple) + if test_eq "${os}" "darwin"; then + _ret="macosx" + fi + ;; + w64) _ret="mingw";; + esac +} + +_handle_autoconf_configs() { + if test_z "${_autoconf_host_type}"; then + _autoconf_host_type="${_autoconf_build_type}" + fi + + if test_nz "${_autoconf_build_type}"; then + _parse_triplet "${_autoconf_build_type}"; local cpu="${_ret}"; local vendor="${_ret2}"; local os="${_ret3}" + _get_arch_from_cpu "${cpu}" + if test_nz "${_ret}"; then + os_arch="${_ret}" + else + wprint "unknown cpu: ${cpu} in --build=${value}" + fi + _get_plat_from_vendor_os "${vendor}" "${os}" + if test_nz "${_ret}"; then + os_host="${_ret}" + else + wprint "unknown vendor-os: ${vendor}-${os} in --build=${value}" + fi + fi + + if test_nz "${_autoconf_host_type}"; then + _parse_triplet "${_autoconf_host_type}"; local cpu="${_ret}"; local vendor="${_ret2}"; local os="${_ret3}" + _get_arch_from_cpu "${cpu}" + if test_nz "${_ret}"; then + _target_arch_default="${_ret}" + else + wprint "unknown cpu: ${cpu} in --host=${value}" + fi + _get_plat_from_vendor_os "${vendor}" "${os}" + if test_nz "${_ret}"; then + _target_plat_default="${_ret}" + else + wprint "unknown vendor-os: ${vendor}-${os} in --build=${value}" + fi + fi +} +_handle_autoconf_configs + +#----------------------------------------------------------------------------- # detect platform and toolchains # @@ -3840,18 +3938,21 @@ _gmake_add_install_target() { # install target file _get_target_item "${target}" "kind"; local targetkind="${_ret}" if test_eq "${targetkind}" "binary"; then - print "\t@mkdir -p ${installdir}/${_install_bindir_default}" >> "${xmake_sh_makefile}" - print "\t@cp -p ${targetfile} ${installdir}/${_install_bindir_default}/${filename}" >> "${xmake_sh_makefile}" + string_replace "${_install_bindir_default}" "\${prefix}" "${installdir}"; _install_bindir_default="${_ret}" + print "\t@mkdir -p ${_install_bindir_default}" >> "${xmake_sh_makefile}" + print "\t@cp -p ${targetfile} ${_install_bindir_default}/${filename}" >> "${xmake_sh_makefile}" elif test_eq "${targetkind}" "static" || test_eq "${targetkind}" "shared"; then - print "\t@mkdir -p ${installdir}/${_install_libdir_default}" >> "${xmake_sh_makefile}" - print "\t@cp -p ${targetfile} ${installdir}/${_install_libdir_default}/${filename}" >> "${xmake_sh_makefile}" + string_replace "${_install_libdir_default}" "\${prefix}" "${installdir}"; _install_libdir_default="${_ret}" + print "\t@mkdir -p ${_install_libdir_default}" >> "${xmake_sh_makefile}" + print "\t@cp -p ${targetfile} ${_install_libdir_default}/${filename}" >> "${xmake_sh_makefile}" fi # install header files _get_target_item "${target}" "headerfiles"; local headerfiles="${_ret}" if test_nz "${headerfiles}"; then + string_replace "${_install_includedir_default}" "\${prefix}" "${installdir}"; _install_includedir_default="${_ret}" local srcheaderfile="" - local includedir="${installdir}/${_install_includedir_default}" + local includedir="${_install_includedir_default}" for srcheaderfile in ${headerfiles}; do string_split "${srcheaderfile}" ":" local srcheaderfile="${_ret}" |
