I am writing a Makefile which needs to figure out the directory of an installed program, which can be found in PATH
; or that is to say, is assumed to be in PATH
.
For example: if the binary is /opt/Xilinx/12.1/ISE_DS/ISE/bin/lin64/xst
, then the path I am looking for is /opt/Xilinx/12.1/ISE_DS/ISE
. The program could also be found as /home/markus/Xilinx/10.1/ISE/bin/lin64/xst
for example. Xilinx included the ISE_DS
part of the path only in later versions.
As a matter of fact the /bin/lin64/xst
substring cannot simply be deleted, because it could also be /bin/lin/xst
depending on your installation.
The Makefile could do something like XILINX_PATH = $(shell which xst)
and then process this string according to the above example, but I cannot figure out how to do this in a clean way.
The best I could come up with is this:
XILINX_PATH_1 = $(shell which xst)
XILINX_PATH_2 = $(subst /bin/lin64/xst,,${XILINX_PATH_1})
XILINX_PATH = $(subst /bin/lin/xst,,${XILINX_PATH_2})
Is there a better solution?