From owner-freebsd-ports@FreeBSD.ORG Sat Jan 31 00:26:08 2015 Return-Path: Delivered-To: ports@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 23CDB8CD for ; Sat, 31 Jan 2015 00:26:08 +0000 (UTC) Received: from gw.catspoiler.org (cl-1657.chi-02.us.sixxs.net [IPv6:2001:4978:f:678::2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id AB1DEDBF for ; Sat, 31 Jan 2015 00:26:07 +0000 (UTC) Received: from FreeBSD.org (mousie.catspoiler.org [192.168.101.2]) by gw.catspoiler.org (8.13.3/8.13.3) with ESMTP id t0V0PtRi017513; Fri, 30 Jan 2015 16:25:59 -0800 (PST) (envelope-from truckman@FreeBSD.org) Message-Id: <201501310025.t0V0PtRi017513@gw.catspoiler.org> Date: Fri, 30 Jan 2015 16:25:55 -0800 (PST) From: Don Lewis Subject: Re: testing the value of ${CXX} in ports Makefile To: FreeBSD@shaneware.biz In-Reply-To: <54CBC9FE.8080304@ShaneWare.Biz> MIME-Version: 1.0 Content-Type: TEXT/plain; charset=us-ascii Cc: ports@FreeBSD.org X-BeenThere: freebsd-ports@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Porting software to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 31 Jan 2015 00:26:08 -0000 On 31 Jan, Shane Ambler wrote: > On 30/01/2015 14:13, Don Lewis wrote: >> I need to test the value of ${CXX} in the Makefile for a port and am >> getting unexpected results. Here is a simplified version of the >> Makefile: >> >> PORTNAME= junk >> PORTVERSION= 0.0.0 >> CATEGORIES= devel >> DISTFILES= >> >> MAINTAINER= truckman@FreeBSD.org >> COMMENT= junk >> >> USE_GCC= 4.9+ >> >> .include >> >> post-patch: >> echo CXX=${CXX} >> .if ${CXX} == g++49 >> echo detected g++49 >> .else >> echo did not detect g++49 >> .endif >> >> .include >> >> >> If I run "make patch", this is what I get: >> >> # make patch >> ===> junk-0.0.0 depends on file: /usr/local/sbin/pkg - found >> ===> Fetching all distfiles required by junk-0.0.0 for building >> ===> Extracting for junk-0.0.0 >> ===> Patching for junk-0.0.0 >> echo CXX=g++49 >> CXX=g++49 >> echo did not detect g++49 >> did not detect g++49 > > You want to use @${ECHO} in the port makefile for that to print right > >> >> If I run "make -dA patch" and look at the debug output, I observe >> bsd.gcc.mk getting processed after the .if is evaluated. When the .if >> is processed, the value of ${CXX} is still c++. It sort of looks like >> bsd.gcc.mk isn't getting included until bsd.port.post.mk and we are >> relying on lazy expansion to get the correct value of ${CXX} for the >> actions. > > Maybe more to the point is that CXX used to build might only be defined > as part of MAKE_ENV to be passed as the environment for the make > command when it is run. > >> It sort of looks like I'll have to do something like: >> >> post-patch: >> [ ${CXX} = g++49 ] && echo detected g++49 >> >> but that just seems goofy. >> > > I believe the correct way to what you want is - > > USES= compiler That doesn't seem to help. > .include > > .if ${CHOSEN_COMPILER_TYPE} == gcc and ${COMPILER_VERSION} == 49 > EXTRA_PATCHES= ${FILESDIR}/extra-patch-srcfile.c > .endif USE_GCC= 4.9+ USES= compiler .include post-patch: @echo CXX=${CXX} @echo GCC_DEFAULT=${GCC_DEFAULT} .if ${CHOSEN_COMPILER_TYPE} == gcc and ${COMPILER_VERSION} == 49 @echo g++49 was detected .else @echo g++49 was not detected .endif # make patch make: "/usr/ports/editors/junk/Makefile" line 17: Malformed conditional (${CHOSEN_COMPILER_TYPE} == gcc and ${COMPILER_VERSION} == 49) make: Fatal errors encountered -- cannot continue USE_GCC= 4.9+ USES= compiler .include post-patch: @echo CXX=${CXX} @echo GCC_DEFAULT=${GCC_DEFAULT} @echo CHOSEN_COMPILER_TYPE=${CHOSEN_COMPILER_TYPE} .if !defined(CHOSEN_COMPILER_TYPE) @echo CHOSEN_COMPILER_TYPE not yet defined .elif M${CHOSEN_COMPILER_TYPE} == Mgcc && M${COMPILER_VERSION} == M49 @echo g++49 was detected .else @echo g++49 was not detected .endif .include # make patch ===> Patching for junk-0.0.0 CXX=g++49 GCC_DEFAULT=4.8 CHOSEN_COMPILER_TYPE=clang g++49 was not detected > See > https://www.freebsd.org/doc/en_US.ISO8859-1/books/porters-handbook/uses.html > and/or comments in /usr/ports/Mk/Uses/compiler.mk The port isn't ready to use clang and there doesn't seem to be a way to get USES=compiler to pick gcc from ports if it finds clang in base. > You may also want to consider patching with - > > #if (__GNUC__ == 4) && (__GNUC_MINOR__ == 9) > // 4.9 specific changes > #endif That would work if I was patching C or C++ code, but I'm actually patching a file that is used to set the the -O value for CFLAGS. The build stuff in the port is pretty strange and uses different optimization levels for for different parts of the build and one of choices that it makes triggers a code generation bug in gcc 4.9. > Of note is that clang identifies itself as gcc 4.2 so you may also want > to test for __clang__ if you want to use < with __GNUC_MINOR__ > > > You can also define more control over gcc version - USE_GCC=4.8 will > require gcc 4.8 while USE_GCC=4.8+ says you can use 4.8 or higher. I'm currently using GCC=4.8, but I want to make the port use GCC_DEFAULT by setting USE_GCC=yes, but also avoid breakage when the default is changed to 4.9.