The following is a simple recipe that is not behaving as I want it to:

$(eval PkgName := $(shell pacman -Qq zsh | awk '{print $$1}'))

$(if ifeq ($(strip ${PkgName}),), pacman -Sy --noconfirm zsh)

All I want it to do is, to install a package iff it has not been installed previously. The installation executes successfully if the package doesn't exist in the system. However, it also executes if it is already installed.

I have tried the GNU make conditional ifeq with the same outcome.

How can I avoid it to execute if the package already exists in the system?


2 Answers 2


It could be written as follows:

$(eval PkgName := $(shell pacman -Qq zsh | awk '{print $$1}'))

$(if ${PkgName},,pacman -Sy --noconfirm zsh)

That should do it all without errors.

Thanks again, I hope this could help someone in the future.


You are mixing up the $(if cond,true_path,false_path) with the make's conditionals ifeq.

For your use case you can define a make variable $(STATUS) and check within the if statement the absence of install.

STATUS := $(if $(strip $(shell pacman -Qq zsh | awk '{print $$1}')),,$(strip $(shell pacman -Sy --noconfirm zsh)))
  • Thanks, you point me into the right direction. Yet, I found a simpler solution.
    – Thesevs
    Commented Mar 20, 2021 at 14:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .