makefile

Conditional statement in makefile based on querying present working directory


From here, I realize it is possible to query the pwd.

I have the following 2 lines that I currently comment on/off

# LDLIBSOPTIONS=-L "/home/OpenXLSX/linux/lib"
LDLIBSOPTIONS=-L "/office/OpenXLSX/linux/lib"

manually depending on which computer I am working on.

Is it possible to do this via a query/grep combination in the makefile itself? I only work under /home/ or under /office/ so the pwd is guaranteed to produce exactly one of these paths on query.

Something like (in pseudocode, I do not know the exact syntax)

if(pwd | grep "home")
    LDLIBSOPTIONS=-L "/home/OpenXLSX/linux/lib"
else
    LDLIBSOPTIONS=-L "/office/OpenXLSX/linux/lib"

Solution

  • In this particular case, it looks like you want the first component of $PWD to be copied into the variable, rather than some if/else:

    LDLIBSOPTIONS := -L "$(shell echo $PWD | sed -e 's,\b/.*,,')/OpenXLSX/linux/lib"