契機
サクラエディタで diff 表示用の diff.exe がなくなっていると聞いたので作ってみようと思った
方法
Windws の Fedora remix on WSL2 で Windows 向けにコンパイルする
手順
- インストール先、ビルド用のディレクトリを作成
mkdir -p ~/opt/diff
mkdir ~/BUILD
cd ~/BUILD
make install した後に bin ディレクトリから取ってくるので、ダミーのインストールディレクトリも作成しておく。
- コンパイラをダウンロード
sudo dnf install mingw64-gcc-c++
- ソースをダウンロードして展開
curl -O ftp://ftp.jaist.ac.jp/pub/GNU/diffutils/diffutils-3.12.tar.xz
tar Jxf diffutils-3.12.tar.xz
cd diffutils-3.12
- ライブラリの依存を減らすため、スタティックリンクにする
export CFLAGS=-static LDFLAGS=-static
export gl_cv_func_strcasecmp_works=no
下のは gl_cv_func_strcasecmp_works
は gnulib
の変更で入ったらしい。そのままだとエラーになるので no でも yes でも構わないが、取り合えず no にしておく。
https://savannah.gnu.org/bugs/?66978
- configure && make
mingw64-configure --prefix=$HOME/opt/diff --enable-threads=windows
make -j4
- エラー発生!
make[2]: Entering directory '/root/BUILD/diffutils-3.12/src'
CCLD cmp.exe
CCLD diff.exe
CCLD diff3.exe
CC sdiff.o
sdiff.c: In function 'main':
sdiff.c:577:28: error: passing argument 2 of '_execvp' from incompatible pointer type [-Wincompatible-pointer-types]
577 | execvp (diffargv[0], (char **) diffargv);
| ^~~~~~~~~~~~~~~~~~
| |
| char **
In file included from /usr/x86_64-w64-mingw32/sys-root/mingw/include/unistd.h:11,
from ../lib/unistd.h:40,
from ../lib/time.h:51,
from ../lib/sys/stat.h:51,
from system.h:27,
from sdiff.c:21:
/usr/x86_64-w64-mingw32/sys-root/mingw/include/process.h:78:77: note: expected 'const char * const*' but argument is of type 'char **'
78 | _CRTIMP intptr_t __cdecl _execvp(const char *_Filename,const char *const *_ArgList);
| ~~~~~~~~~~~~~~~~~~~^~~~~~~~
でも、よく見ると欲しい diff.exe はもう出来ているのでそこから貰ってくる。
- strip してデスクトップへコピー
❯ file src/*.exe
src/cmp.exe: PE32+ executable (console) x86-64, for MS Windows, 19 sections
src/diff.exe: PE32+ executable (console) x86-64, for MS Windows, 19 sections
src/diff3.exe: PE32+ executable (console) x86-64, for MS Windows, 19 sections
❯ mingw-strip src/*.exe
❯ file src/*.exe
src/cmp.exe: PE32+ executable (console) x86-64 (stripped to external PDB), for MS Windows, 10 sections
src/diff.exe: PE32+ executable (console) x86-64 (stripped to external PDB), for MS Windows, 10 sections
src/diff3.exe: PE32+ executable (console) x86-64 (stripped to external PDB), for MS Windows, 10 sections
❯ cp src/*.exe ~/winhome/Desktop
これでデスクトップ上に cmp.exe, diff.exe, diff3.exe ができました。ドキュメントは Web から漁れば必要ないでしょう。あとは煮るなり焼くなり適当に!