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 !
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With