[Makefile] Check Installed Package Version on Ubuntu Linux


Given an installed package name on Ubuntu Linux, find its version in Makefile.

Source code:

Makefile | repository | view raw
1
2
3
4
5
6
PACKAGE_NAME=python
PACKAGE_VERSION=$(strip $(shell apt-cache policy $(PACKAGE_NAME) | grep Installed: | cut -d: -f2))

default:
	@echo "package name: \033[92m$(PACKAGE_NAME)\033[0m"
	@echo "package version: \033[92m$(PACKAGE_VERSION)\033[0m"

Note that strip text function is used to remove spaces of the string.

Output:

package name: python
package version: 2.7.11-2

Tested on Ubuntu Linux 16.10, GNU make 4.1-9.


References:

[1]
[2]
[3]
[4]