Skip to content

Commit

Permalink
improve configure
Browse files Browse the repository at this point in the history
  • Loading branch information
waruqi committed Jan 17, 2023
1 parent 52742ef commit c21b083
Show file tree
Hide file tree
Showing 2 changed files with 137 additions and 20 deletions.
155 changes: 136 additions & 19 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)"'
Expand Down Expand Up @@ -2603,6 +2612,7 @@ _show_version() {
# --foo=yes => foo
_parse_argument_name() {
_ret=$(echo "${1#*--}" | sed "s/${2-=[^=]*}$//")
string_replace "${_ret}" "-" "_"
}

# --foo=yes => yes
Expand Down Expand Up @@ -2662,20 +2672,108 @@ _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
fi
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
#
Expand Down Expand Up @@ -3290,12 +3388,28 @@ _check_cxxsnippets() {
# check option
_check_option() {
local name="${1}"
_get_option_item "${name}" "before_check"; local before_check="${_ret}"
if test_nz "${before_check}"; then
eval ${before_check}
fi
if _check_csnippets "${name}" && _check_cxxsnippets "${name}"; then
return 0
_get_option_value "${name}"; local value="${_ret}"
_get_option_item "${name}" "default"; local default="${_ret}"
if test_nz "${value}"; then
if _is_enabled "${value}"; then
return 0
else
return 1
fi
elif test_nz "${default}"; then
if _is_enabled "${default}"; then
return 0
else
return 1
fi
else
_get_option_item "${name}" "before_check"; local before_check="${_ret}"
if test_nz "${before_check}"; then
eval ${before_check}
fi
if _check_csnippets "${name}" && _check_cxxsnippets "${name}"; then
return 0
fi
fi
return 1
}
Expand Down Expand Up @@ -3824,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}"
Expand Down
2 changes: 1 addition & 1 deletion src/xmake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ if is_plat "linux" && is_mode "debug"; then
fi

# options
option "demo" "Enable or disable the demo module." true
option "demo" "Enable or disable the demo module." false
option "small" "Enable the small compile mode and disable all modules." true
option "micro" "Compile micro core library for the embed system." false
option "float" "Enable or disable the float type" true
Expand Down

0 comments on commit c21b083

Please sign in to comment.