iRomul
iRomul

Reputation: 351

How to check if a file exists in Makefile

I am using makefile to build my program in multiple system. Some system have installed colorgcc script. In my Makefile i want to check, if script exists and depending on it i setting up CC variable. But my Makefile don't work correctly - in system, that haven't colorgcc, make always set $(CC) as colorgcc. Here's part of Makefile:

ifneq ("$(wildchar /usr/bin/colorgcc)","") 
CC=colorgcc
else
CC=gcc
endif

I also tried to use this variant:

ifeq ( $(shell test -e /usr/bin/colorgcc), ) 
CC=colorgcc
else
CC=gcc
endif

In both case $(CC) doesn't depend of existence file /usr/bin/colorgcc

How can i solve my problem?

Upvotes: 2

Views: 11715

Answers (1)

tripleee
tripleee

Reputation: 189926

In the first case, you mistyped the function $(wildcard ...) so you get nothing, always.

In the second case, the output of test is always the empty string. It will set its exit code depending on whether the condition is true or not, but you are not examining its exit code, just the output it prints, which will always be nothing at all.

Upvotes: 3

Related Questions