Linux運維_Bash腳本_構建安裝Meson-1.0.1和Ninja-1.11.1
Bash (Bourne Again Shell) 是一個解釋器,負責處理 Unix 系統命令行上的命令。它是由 Brian Fox 編寫的免費軟件,并于 1989 年發布的免費軟件,作為 Sh (Bourne Shell) 的替代品。
您可以在 Linux 和 MacOS 機器上使用 Bash,甚至可以通過適用于 Linux 的 Windows 子系統在 Windows 10 機器上使用。
使用方法
- 下載源碼包:
meson-1.0.1.tar.gz
re2c-3.1.tar.gz
ninja-1.11.1.tar.gz
- 放于指定路徑:
這里 Bash Shell 腳本的全局變量 STORAGE 指定的存放源碼包的路徑 /home/goufeng 可進行修改。
- 執行 Bash Shell 腳本:
輸入 /[路徑名]/[腳本名].sh 即可進行自動編譯部署,過程中提示輸入 (y/n) 輸入 y 則進行下一步,這樣分階段確認的原因是為了確保能夠看到上一個源碼編譯結果中可能的錯誤和提示。
完整腳本
#! /bin/bash
# Create By GF 2024-02-20 21:42# Install First: GNU-Tools (Contains: pkg-config, m4, autoconf, automake, libtool, gettext, flex, bison, libiconv, make)# ------------------ Meson - 1.0.1 -----------------
# Need File: meson-1.0.1.tar.gz
# ---------- Ninja - 1.11.1 - configure.py ---------
# Need File: re2c-3.1.tar.gz
# Need File: ninja-1.11.1.tar.gz# ##################################################
STORAGE=/home/goufeng# ########################################### Meson - 1.0.1 ########################################### Function: 構建安裝(Build Install) Meson-1.0.1 (by Python3)
# ##################################################
function Build_Install_Meson_1_0_1_by_Python3() {if [[ ! -f "/usr/local/bin/meson" ]]; then# Meson 工具一般和 Ninja 工具一起使用。# Meson 可以使用 Python 的 Pip 工具安裝: pip install --user meson# Meson 可以從源碼進行構建安裝: python3 setup.py build 以及 python3 setup.py install# Ninja 可以使用 Python 的 Pip 工具安裝: pip install --user ninja# Ninja 可以從源碼進行構建安裝: python3 ./configure.py --bootstrap (需要下載含有 configure.py 的源碼包)local VERIFYlocal STEP_UNZIPPED=0local STEP_BUILDED=0local STEP_INSTALLED=0# ------------------------------------------read -p "[Confirm] Build and Install ( meson-1.0.1 )? (y/n)>" VERIFYif [[ "$VERIFY" != "y" ]]; then exit 1; fi# ------------------------------------------tar -zxvf $STORAGE/meson-1.0.1.tar.gz && STEP_UNZIPPED=1# ------------------------------------------cd $STORAGE/meson-1.0.1 && python3 setup.py build && STEP_BUILDED=1# ------------------------------------------cd $STORAGE/meson-1.0.1 && python3 setup.py install && STEP_INSTALLED=1# ------------------------------------------if [[ $STEP_INSTALLED == 1 ]]; thenln -sf /opt/Python-3.8.0/bin/meson /usr/local/bin/fi# ------------------------------------------cd $STORAGE && rm -rf $STORAGE/meson-1.0.1 && return 0elseecho "[Caution] Bin: ( /usr/local/bin/meson ) Already Exists."# ------------------------------------------return 0fi
}# ################################### Ninja - 1.11.1 - configure.py ################################### Function: 編譯安裝(Compile Install) re2c-3.1
# ##################################################
function Compile_Install_re2c_3_1() {if [[ ! -f "/usr/local/bin/re2c" ]]; thenlocal VERIFYlocal STEP_UNZIPPED=0local STEP_AUTOGEN=0local STEP_CONFIGURED=0local STEP_INSTALLED=0# ------------------------------------------read -p "[Confirm] Compile and Install ( re2c-3.1 )? (y/n)>" VERIFYif [[ "$VERIFY" != "y" ]]; then exit 1; fi# ------------------------------------------tar -zxvf $STORAGE/re2c-3.1.tar.gz && STEP_UNZIPPED=1# ------------------------------------------# * Problem: aclocal: warning: couldn't open directory 'm4': No such file or directory# - Solve: 只是由于文件夾下沒有 m4 文件夾導致, 只需要在當前文件夾下創建一個 m4 文件夾即可 (mkdir m4)。# ..........................................# * Problem: Makefile.am:477: error: Libtool library used but 'LIBTOOL' is undefined# Makefile.am:477: The usual way to define 'LIBTOOL' is to add 'LT_INIT'# Makefile.am:477: to 'configure.ac' and run 'aclocal' and 'autoconf' again.# Makefile.am:477: If 'LT_INIT' is in 'configure.ac', make sure# Makefile.am:477: its definition is in aclocal's search path.# autoreconf: automake failed with exit status: 1# - Solve: 原因是 automake 和 libtool 沒有安裝在同一目錄中, 導致 aclocal 在路徑中找不到 .m4 文件。# 解決方法 (1):# 1. 執行 aclocal --print-ac-dir 查看 aclocal 的路徑, 例如顯示 /opt/automake-1.15/share/aclocal# 2. 將 libtool 的 share/aclocal 目錄中的 .m4 文件復制到 /opt/automake-1.15/share/aclocal (cp /opt/libtool-2.4.6/share/aclocal/*.m4 /opt/automake-1.15/share/aclocal/)# 3. 再次執行 autoreconf, 問題解決。# 解決方法 (2):# 1. 確保二進制 bin 文件: "aclocal" (包含在 automake 中) 和 "libtoolize" (包含在 libtool 中) 在可找到 PATH 中 (最好是同一路徑下)# 2. 先執行 libtoolize, 會在當前目錄自動生成要用到的 .m4 文件, 再執行 autoreconf, 問題解決。cd $STORAGE/re2c-3.1 && ./autogen.sh && STEP_AUTOGEN=1# ------------------------------------------cd $STORAGE/re2c-3.1 && ./configure --prefix=/opt/re2c-3.1 && STEP_CONFIGURED=1# ------------------------------------------make && make install && STEP_INSTALLED=1# ------------------------------------------if [[ $STEP_INSTALLED == 1 ]]; thenln -sf /opt/re2c-3.1/bin/re2c /usr/local/bin/ln -sf /opt/re2c-3.1/bin/re2go /usr/local/bin/ln -sf /opt/re2c-3.1/bin/re2rust /usr/local/bin/fi# ------------------------------------------cd $STORAGE && rm -rf $STORAGE/re2c-3.1 && return 0elseecho "[Caution] Bin: ( /usr/local/bin/re2c ) Already Exists."# ------------------------------------------return 0fi
}# Function: 構建安裝(Build Install) Ninja-1.11.1-by-Py-Configure (by Python3)
# ##################################################
function Build_Install_Ninja_1_11_1_by_Py_Configure_by_Python3() {if [[ ! -f "/usr/local/bin/ninja" ]]; then# Ninja 工具一般配合 Meson 工具使用。# Meson 可以使用 Python 的 Pip 工具安裝: pip install --user meson# Meson 可以從源碼進行構建安裝: python3 setup.py build 以及 python3 setup.py install# Ninja 可以使用 Python 的 Pip 工具安裝: pip install --user ninja# Ninja 可以從源碼進行構建安裝: python3 ./configure.py --bootstrap (需要下載含有 configure.py 的源碼包)local VERIFYlocal STEP_UNZIPPED=0local STEP_BUILDED=0# ------------------------------------------read -p "[Confirm] Build and Install ( ninja-1.11.1 )? (y/n)>" VERIFYif [[ "$VERIFY" != "y" ]]; then exit 1; fi# ------------------------------------------tar zxvf $STORAGE/ninja-1.11.1.tar.gz && STEP_UNZIPPED=1# ------------------------------------------# * Problem: warning: A compatible version of re2c (>= 0.11.3) was not found; changes to src/*.in.cc will not affect your build.# - Solve: Install re2c.# ..........................................# * Caution: 構建完成后, 構建目錄下將生成 ninja 二進制可執行文件。cd $STORAGE/ninja-1.11.1 && python3 ./configure.py --bootstrap && STEP_BUILDED=1# ------------------------------------------# * Caution: 安裝 Ninja, 其實就是讓系統在需要的時候能找到 Ninja 這個二進制文件并運行。if [[ $STEP_BUILDED == 1 ]]; thencp $STORAGE/ninja-1.11.1/ninja /usr/local/bin/fi# ------------------------------------------cd $STORAGE && rm -rf $STORAGE/ninja-1.11.1 && return 0elseecho "[Caution] Bin: ( /usr/local/bin/ninja ) Already Exists."# ------------------------------------------return 0fi
}function main() {# --------------- Meson - 1.0.1 ----------------Build_Install_Meson_1_0_1_by_Python3# -------- Ninja - 1.11.1 - configure.py -------Compile_Install_re2c_3_1Build_Install_Ninja_1_11_1_by_Py_Configure_by_Python3
}main
總結
以上就是關于 Linux運維 Bash腳本 構建安裝Meson-1.0.1和Ninja-1.11.1 的全部內容。
更多內容可以訪問我的代碼倉庫:
https://gitee.com/goufeng928/public
https://github.com/goufeng928/public