1、MSYS2配置文件
这个 profile
文件是一个用于配置 MSYS2 环境的系统级配置文件。它通常会在 MSYS2 环境启动时被执行,以设置一些环境变量、路径以及其他系统级别的配置。接下来我将逐步解释文件中的各个部分:
1. 版权声明和相关链接
# To the extent possible under law, the author(s) have dedicated all
# copyright and related and neighboring rights to this software to the
# public domain worldwide. This software is distributed without any warranty.
# You should have received a copy of the CC0 Public Domain Dedication along
# with this software.
# If not, see <https://creativecommons.org/publicdomain/zero/1.0/>.
这是一个版权声明,表明该软件是开源的,已将所有版权放弃到公有领域,且不提供任何保证。
2. 默认路径设置
MSYS2_PATH="/usr/local/bin:/usr/bin:/bin"
MANPATH='/usr/local/man:/usr/share/man:/usr/man:/share/man'
INFOPATH='/usr/local/info:/usr/share/info:/usr/info:/share/info'
这些设置为 MSYS2 配置了默认的路径,分别是:
MSYS2_PATH
:MSYS2 环境下可执行文件的路径。MANPATH
:手册页的路径。INFOPATH
:信息页面的路径。
3. MSYS2路径继承逻辑
case "${MSYS2_PATH_TYPE:-inherit}" in
strict)
unset ORIGINAL_PATH
;;
inherit)
ORIGINAL_PATH="${ORIGINAL_PATH:-${PATH}}"
;;
*)
WIN_ROOT="$(PATH=${MSYS2_PATH} exec cygpath -Wu)"
ORIGINAL_PATH="${WIN_ROOT}/System32:${WIN_ROOT}:${WIN_ROOT}/System32/Wbem:${WIN_ROOT}/System32/WindowsPowerShell/v1.0/"
esac
这里根据 MSYS2_PATH_TYPE
的值决定如何设置 ORIGINAL_PATH
,即当前路径是否继承 Windows 的路径配置。如果设置为 strict
,则不继承路径配置;inherit
则继承原有路径。
4. 设置 Windows 路径
case "$TMP" in *\\*) TMP="$(cygpath -m "$TMP")";; esac
case "$TEMP" in *\\*) TEMP="$(cygpath -m "$TEMP")";; esac
这里检查 TMP
和 TEMP
环境变量,如果它们包含 Windows 风格的路径(例如 C:\Users
),则使用 cygpath
转换为 MSYS2 风格的路径(例如 /cygdrive/c/Users
)。
5. 加载 /etc/profile.d
中的脚本
profile_d ()
{
local file=
for file in $(export LC_COLLATE=C; echo /etc/profile.d/*.$1); do
[ -e "${file}" ] && . "${file}"
done
}
这个函数用于加载 /etc/profile.d/
目录下的所有配置脚本,文件扩展名为 .$1
(通常是 .sh
)。这些脚本可能用于设置环境变量、别名等。
6. 根据 shell 类型设置配置
if [ ! "x${BASH_VERSION}" = "x" ]; then
HOSTNAME="$(exec /usr/bin/hostname)"
SHELL=`which bash`
profile_d sh
[ -f "/etc/bash.bashrc" ] && . "/etc/bash.bashrc"
elif [ ! "x${KSH_VERSION}" = "x" ]; then
typeset -l HOSTNAME="$(exec /usr/bin/hostname)"
profile_d sh
PS1=$(print '\033]0;${PWD}\n\033[32m${USER}@${HOSTNAME} \033[33m${PWD/${HOME}/~}\033[0m\n$ ')
elif [ ! "x${ZSH_VERSION}" = "x" ]; then
HOSTNAME="$(exec /usr/bin/hostname)"
profile_d sh
profile_d zsh
PS1='(%n@%m)[%h] %~ %% '
SHELL=`which zsh`
elif [ ! "x${POSH_VERSION}" = "x" ]; then
HOSTNAME="$(exec /usr/bin/hostname)"
PS1="$ "
else
HOSTNAME="$(exec /usr/bin/hostname)"
profile_d sh
PS1="$ "
fi
根据当前使用的 shell 类型(Bash、Ksh、Zsh 等),配置不同的提示符(PS1)以及其他 shell 环境设置。例如,针对 Bash 设置 PS1
为带有路径和主机名的信息格式,而针对 Zsh 则使用不同的提示符格式。
7. 环境变量设置
export PATH MANPATH INFOPATH PKG_CONFIG_PATH PKG_CONFIG_SYSTEM_INCLUDE_PATH PKG_CONFIG_SYSTEM_LIBRARY_PATH USER TMP TEMP HOSTNAME PS1 SHELL ORIGINAL_TMP ORIGINAL_TEMP ORIGINAL_PATH CONFIG_SITE
unset PATH_SEPARATOR
设置一些环境变量:
PATH
:可执行文件的搜索路径。MANPATH
:手册页的搜索路径。INFOPATH
:信息文件的搜索路径。PKG_CONFIG_PATH
:Pkg-config 文件的路径。USER
:当前用户。TMP
和TEMP
:临时文件夹的路径。
8. 初次启动提示
if [ "$MAYBE_FIRST_START" = "true" ]; then
printf "\e[1;32mInitial setup complete. MSYS2 is now ready to use.\e[1;0m\n" 1>&2;
fi
unset MAYBE_FIRST_START
如果这是第一次启动 MSYS2 环境,则会显示一条初始化完成的消息。
总结
这个 profile
文件是 MSYS2 环境的初始化脚本,用于配置系统路径、环境变量、shell 配置等,确保在启动时环境能够正确加载和配置。它还根据用户的 shell 类型自适应设置不同的配置,确保用户的终端体验一致和便捷。
2、export PATH修改
-
export 命令是用来将变量导出为环境变量,确保它们在子进程中也能访问。
-
PATH 变量的值在其他地方(如 MSYS2_PATH)被设置和修改,然后通过 export 导出。
-
如果你想修改 PATH,可以直接在终端中执行 export PATH=“new_value:$PATH” 来临时修改,
或者将修改添加到配置文件中来永久生效。
3、MSYS2 MINGW64
4、ucrt clang llvm
clang简单入门
ucrt universal C run time的缩写, 这样看就明白了
是 Windows 提供的一个运行时库,旨在替代传统的 CRT(C Runtime)库。它提供了一套标准的 C 运行时函数,适用于各种 Windows 应用程序,特别是为 UWP(通用 Windows 平台)应用开发提供支持