From owner-freebsd-ports@freebsd.org Mon Mar 26 05:22:41 2018 Return-Path: Delivered-To: freebsd-ports@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 00BC2F6CA44 for ; Mon, 26 Mar 2018 05:22:41 +0000 (UTC) (envelope-from truckman@FreeBSD.org) Received: from mx2.catspoiler.org (mx2.catspoiler.org [IPv6:2607:f740:16::d18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "amnesiac", Issuer "amnesiac" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 97D446B282 for ; Mon, 26 Mar 2018 05:22:40 +0000 (UTC) (envelope-from truckman@FreeBSD.org) Received: from gw.catspoiler.org ([76.212.85.177]) by mx2.catspoiler.org (8.15.2/8.15.2) with ESMTPS id w2Q5NY8u035835 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 26 Mar 2018 05:23:35 GMT (envelope-from truckman@FreeBSD.org) Received: from mousie.catspoiler.org (mousie.catspoiler.org [192.168.101.2]) by gw.catspoiler.org (8.15.2/8.15.2) with ESMTPS id w2Q5MNdI081145 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sun, 25 Mar 2018 22:22:24 -0700 (PDT) (envelope-from truckman@FreeBSD.org) Date: Sun, 25 Mar 2018 22:22:18 -0700 (PDT) From: Don Lewis Subject: Re: .if and Makefile issues To: freebsd@dreamchaser.org cc: FreeBSD Mailing List In-Reply-To: <85769c6d-a71a-f2c6-8a65-ac9b82f534ab@dreamchaser.org> Message-ID: References: <85769c6d-a71a-f2c6-8a65-ac9b82f534ab@dreamchaser.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; CHARSET=us-ascii Content-Disposition: INLINE X-BeenThere: freebsd-ports@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: Porting software to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 26 Mar 2018 05:22:41 -0000 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