【決定版】GNU Makeの「--version」オプション:詳細解説と使い方
GNU Makeの--version
オプションは、コマンドラインでMakeのバージョン情報とライセンス情報を表示するために使用されます。このオプションは、Makeのインストールを確認したり、特定の機能がサポートされているかどうかを確認したりする際に役立ちます。
構文
make --version
オプション解説
このオプションには追加の引数はありません。
GNU Make 4.3
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
For more information about copyright, see COPYING.
... (ライセンス情報省略)
- Makeのバージョン情報は、
Makefile
内のMAKE
変数を使用して取得することもできます。 --version
オプションは、Makeの起動時にのみ使用できます。Makefile内では使用できません。
#!/bin/bash
# Check the version of Make
make --version
# Exit the script with a successful exit code
exit 0
This script will print the version and copyright information of the installed Make program to the console. The script will then exit with a successful exit code.
Here is another example of how to use the --version
option to check for a specific Make version:
#!/bin/bash
# Check if Make version 4.3 or later is installed
make --version | grep -q '4.3'
if [ $? -eq 0 ]; then
echo "Make version 4.3 or later is installed"
else
echo "Make version 4.3 or later is not installed"
exit 1
fi
Using the MAKE variable
The MAKE
variable is a shell variable that contains the path to the Make executable. You can use this variable to get the version information of Make by using the following command:
make -C '' --print-file $MAKE | grep VERSION
This command will print the version information of Make to the console. The -C ''
option tells Make to use the current working directory as the build directory. The --print-file
option tells Make to print the contents of the specified file to the console. The grep
command is used to search the output of Make for the line that contains the version information.
Using the uname command
The uname
command can be used to get information about the operating system. You can use the uname
command to get the version information of Make by using the following command:
uname -r | grep release
This command will print the release number of the operating system to the console. The grep
command is used to search the output of uname
for the line that contains the word "release". The release number of the operating system typically includes the version information of Make.
Using a system information tool
There are many system information tools available that can be used to get the version information of Make. For example, you can use the following command on a Linux system to get the version information of Make using the dpkg-query
command:
dpkg-query -W 'make' | grep Version
This command will print the version information of Make to the console. The dpkg-query
command is used to query the Debian package database. The -W
option tells dpkg-query
to display only the specified fields. The grep
command is used to search the output of dpkg-query
for the line that contains the word "Version".
Checking the Makefile
If you are using Make to build a project, you can check the Makefile for the version information of Make. The Makefile may contain a variable that defines the version of Make that is required to build the project. For example, the Makefile may contain the following variable:
MAKE_VERSION := 4.3
If the Makefile contains a variable that defines the required Make version, you can check the version of Make that is installed by using the following command:
make --version | grep ^MAKE