msys2でPKGBUILDを書くときにcmakeを使う際は引数展開にご注意を。

# 問題

PKGBUILDを書いて`makepkg`してパッケージをインストールしたら、`/msys64/msys64/mingw64`がinstall prefixになってしまった。`/msys64/msys64/`とは一体・・・。

```plain:ビルド出力より抜粋
-- Install configuration: ""
-- Installing: C:/msys64/home/yumetodo/patches/mingw-w64-lpsolve/pkg/mingw-w64-x86_64-lpsolve/msys64/mingw64/lib/liblpsolve55.dll.a
-- Installing: C:/msys64/home/yumetodo/patches/mingw-w64-lpsolve/pkg/mingw-w64-x86_64-lpsolve/msys64/mingw64/bin/liblpsolve55.dll
-- Installing: C:/msys64/home/yumetodo/patches/mingw-w64-lpsolve/pkg/mingw-w64-x86_64-lpsolve/msys64/mingw64/include/lpsolve/lp_bit.h
-- Installing: C:/msys64/home/yumetodo/patches/mingw-w64-lpsolve/pkg/mingw-w64-x86_64-lpsolve/msys64/mingw64/include/lpsolve/lp_crash.h
-- Installing: C:/msys64/home/yumetodo/patches/mingw-w64-lpsolve/pkg/mingw-w64-x86_64-lpsolve/msys64/mingw64/include/lpsolve/lp_explicit.h
-- Installing: C:/msys64/home/yumetodo/patches/mingw-w64-lpsolve/pkg/mingw-w64-x86_64-lpsolve/msys64/mingw64/include/lpsolve/lp_fortify.h
-- Installing: C:/msys64/home/yumetodo/patches/mingw-w64-lpsolve/pkg/mingw-w64-x86_64-lpsolve/msys64/mingw64/include/lpsolve/lp_Hash.h
```

# 原因

PKGBUILDの`build()`でcmakeを呼び出していたが、

```bash:PKGBUILD_build()
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DLIB_TYPE=SHARED \
    ../lp_solve_5.5
```

のように呼び出していた。このとき`MINGW_PREFIX`は`/mingw64`である。

しかし、

- [MSYS2小ネタ集 - Qiita](https://qiita.com/ubnt_intrepid/items/0d9ea1c792dd2049d71c)
- [bash broken : cannnot escape * · Issue #1347 · Alexpux/MINGW-packages](https://github.com/Alexpux/MINGW-packages/issues/1347)

にもあるように、msys2は引数展開を行うため、`CMAKE_INSTALL_PREFIX`は`C:\msys2\mingw64`になってしまう(msys2の場所依存)。

# 解決策

```bash:PKGBUILD_build()
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DLIB_TYPE=SHARED \
    ../lp_solve_5.5
````

展開を阻止しましょう。

```plain:ビルド出力より抜粋
-- Install configuration: ""
-- Installing: C:/msys64/home/yumetodo/patches/mingw-w64-lpsolve/pkg/mingw-w64-x86_64-lpsolve/mingw64/lib/liblpsolve55.dll.a
-- Installing: C:/msys64/home/yumetodo/patches/mingw-w64-lpsolve/pkg/mingw-w64-x86_64-lpsolve/mingw64/bin/liblpsolve55.dll
-- Installing: C:/msys64/home/yumetodo/patches/mingw-w64-lpsolve/pkg/mingw-w64-x86_64-lpsolve/mingw64/include/lpsolve/lp_bit.h
-- Installing: C:/msys64/home/yumetodo/patches/mingw-w64-lpsolve/pkg/mingw-w64-x86_64-lpsolve/mingw64/include/lpsolve/lp_crash.h
-- Installing: C:/msys64/home/yumetodo/patches/mingw-w64-lpsolve/pkg/mingw-w64-x86_64-lpsolve/mingw64/include/lpsolve/lp_explicit.h
-- Installing: C:/msys64/home/yumetodo/patches/mingw-w64-lpsolve/pkg/mingw-w64-x86_64-lpsolve/mingw64/include/lpsolve/lp_fortify.h
-- Installing: C:/msys64/home/yumetodo/patches/mingw-w64-lpsolve/pkg/mingw-w64-x86_64-lpsolve/mingw64/include/lpsolve/lp_Hash.h
```

# License

[CC BY 4.0](https://creativecommons.org/licenses/by/4.0/deed.ja)

<a href="https://commons.wikimedia.org/wiki/File:CC-BY_icon.svg#/media/File:CC-BY_icon.svg"><img src="https://upload.wikimedia.org/wikipedia/commons/thumb/1/16/CC-BY_icon.svg/1200px-CC-BY_icon.svg.png" alt="CC-BY icon.svg" width="88px"></a>