On 25 Mar, Don Lewis wrote:
> On 25 Mar, Gary Aitken wrote:
>> Bewildered and frustrated, looking for some guidance on a seemingly
>> simple task: check the existence of a file and rename it.
>>
>> Looking at a number of examples in the Porter's guide, I should be
>> able to do something like this:
>>
>> post-build:
>> echo "* post-build *"
>> #Avoid executable name conflict with dcraw port
>> .if exists ${WRKSRC}/dcraw
>> echo = dcraw exists =
>> mv ${WRKSRC}/dcraw ${WRKSRC}/${PORTNAME}-dcraw
>> .else
>> echo = dcraw does not exist =
>> .endif
>>
>> That causes:
>> echo "* post-build *"
>> * post-build *
>> .if exists /usr/ports/graphics/ufraw-devel/work/ufraw-6d3259a/dcraw
>> make[1]: exec(.if) failed (No such file or directory)
>> *** Error code 1
>
> Since the .if is indented, it is being treated as a shell command,
> and .if isn't being found in $PATH.
>
>> I then tried adding parens:
>>
>> post-build:
>> echo "* post-build *"
>> #Avoid executable name conflict with dcraw port
>> .if exists(${WRKSRC}/dcraw)
>> echo "= dcraw exists ="
>> mv ${WRKSRC}/dcraw ${WRKSRC}/${PORTNAME}-dcraw
>> .else
>> echo "= dcraw does not exist ="
>> .endif
>>
>> echo "* post-build *"
>> * post-build *
>> .if exists(/usr/ports/graphics/ufraw-devel/work/ufraw-6d3259a/dcraw)
>> Syntax error: "(" unexpected
>> *** Error code 2
>
> Ditto, but the shell command has a shell syntax error.
>
>> I finally got this to do *something*:
>>
>> post-build:
>> echo "* post-build *"
>> # Avoid executable name conflict with dcraw port
>> .if exists ${WRKSRC}/dcraw
>> echo = dcraw exists =
>> mv ${WRKSRC}/dcraw ${WRKSRC}/${PORTNAME}-dcraw
>> .else
>> echo = dcraw does not exist =
>> .endif
>>
>> echo "* post-build *"
>> * post-build *
>> echo "= dcraw does not exist ="
>> = dcraw does not exist =
>>
>> Unfortunately, the file *does* exist.
>
> The .if is treated as a make directive in this case, but it is
> evaluated at the time that make is first invoked, probably when
> when "make build" is first executed, or earlier.
>
>> Can someone enlighten me as to what is going on in the above three
>> situations, to further my education?
>> Any hints / pointers would be much appreciated:
>>
>> 1. Why does the .if, .else, and .endif have to have no leading whitespace?
>
> If there is leading whitespace, then make assumes they are shell
> commands.
>
>> 2. Why does it require the on the stmt after the else but not
>> after the .if? (Same behavior with tabs on the ones after .if)
>
> Probably because the .if evaluates false, so anything between the .if
> and the .else isn't even parsed.
>
>> 3. Why doesn't it find the file?
>
> Because the file doesn't exist when the make first parses the Makefile.
>
>> 4. What's a right way to do this?
>
> Use a shell runtime test:
>
> post-build:
> echo "* post-build *"
> # Avoid executable name conflict with dcraw port
> if [ -e ${WRKSRC}/dcraw ]; then
> echo = dcraw exists =
> mv ${WRKSRC}/dcraw ${WRKSRC}/${PORTNAME}-dcraw
> else
> echo = dcraw does not exist =
> fi
I forgot that all of the lines from the "if" up to but not including
"fi" need to end with a \ so that make treats them all as one multi-line
shell command:
post-build:
echo "* post-build *"
# Avoid executable name conflict with dcraw port
if [ -e ${WRKSRC}/dcraw ]; then \
echo = dcraw exists = \
mv ${WRKSRC}/dcraw ${WRKSRC}/${PORTNAME}-dcraw \
else \
echo = dcraw does not exist = \
fi
___
freebsd-ports@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-ports
To unsubscribe, send any mail to "freebsd-ports-unsubscr...@freebsd.org"