Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ifeq issue: compare 2 strings with a dot included

Tags:

gnu-make

I am trying to implement a simple string comparison to get the type of a file (using its extension) like this:

extract_pkg: $(PKG)
    $(eval EXT := $(suffix $(PKG)))
    @echo $(EXT)
ifeq ($(EXT), .zip)
    @echo "is zip file"
else
    @echo "is not a zip file"
endif

extract_pkg : PKG = mypkg.zip

However, when I run it it goes into the else branch. My guess is, it has to do with the dot, but I dont find a solution. Thanks for your help !

Edit 1: the essential code would be actually somewhat like the following, and it works as expected:

test_cmp:
ifeq (.zip,.zip)
        @echo ".zip==.zip"
endif
ifeq (zip,zip)
        @echo "zip==zip"
endif

thus the problem is somewhere else !

like image 241
user1240076 Avatar asked Nov 30 '22 20:11

user1240076


1 Answers

One thing to be careful about -- spaces in if constructs are significant. So if you have something like:

ifeq ($(EXT), .zip)

it will only match if $(EXT) expands to exactly ".zip" -- including the space before the period. So your first example will always print is not a zip file, since $(EXT) will never contain the space.

like image 97
Chris Dodd Avatar answered Dec 29 '22 06:12

Chris Dodd