i'm compiling library called libcmsdataformat.so.
when libcmsdataformat.so gets compiled, potentially makes 1 (or more) .pcm files (this platform-dependent). if these files made, should copied location (called $obj). if don't exist, program supposed end normally, i.e. without error.
the following works if .pcm file gets made, fails platform .pcm file not generated (i.e. copy gives error since no file found)
src=../src obj=../lib all: $(obj) $(obj)/libcmsdataformat.so movefile .phony : movefile movefile: $(obj)/libcmsdataformat.so ifeq ($(*.pcm $(src)),) @echo "copying.." cp $(src)/*_rdict.pcm $(obj) else @echo "no .pcm found!" endif (rule `libcmsdataformat.so` follows might (or might not!) create 1 or more `*.pcm` files in `$(src)`. any suggestions work both cases welcome, preferably case more 1 .pcm generated.
the problem you're encountering conditional being evaluated early. if use $(if) function, evaluation deferred until rule executed. means it'll see .pcm files created side-effect of build stages.
src=../src obj=../lib all: $(obj) $(obj)/libcmsdataformat.so movefile .phony : movefile movefile: $(obj)/libcmsdataformat.so $(if $(wildcard $(src)/*.pcm), \ @echo "copying.."; \ cp $(src)/*_rdict.pcm $(obj) \ , \ @echo "no .pcm found!") of course, 1 option run cp, ignore return code (you can prefixing first line of recipe -). it's not recommended, however, can hide errors occur when .pcm files exist fail copy.