From owner-freebsd-hackers@FreeBSD.ORG Fri Jun 25 12:57:31 2010 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A84CE106566B for ; Fri, 25 Jun 2010 12:57:31 +0000 (UTC) (envelope-from mahan@mahan.org) Received: from ns.mahan.org (ns.mahan.org [67.116.10.138]) by mx1.freebsd.org (Postfix) with ESMTP id 5FF498FC16 for ; Fri, 25 Jun 2010 12:57:31 +0000 (UTC) Received: from Gypsy.mahan.org (crowTrobot [67.116.10.140]) by ns.mahan.org (8.13.6/8.13.6) with ESMTP id o5PCwO9I063785; Fri, 25 Jun 2010 05:58:25 -0700 (PDT) (envelope-from mahan@mahan.org) Message-ID: <4C24A7B4.5050301@mahan.org> Date: Fri, 25 Jun 2010 05:57:24 -0700 From: Patrick Mahan User-Agent: Thunderbird 2.0.0.22 (X11/20090605) MIME-Version: 1.0 To: =?UTF-8?B?RGFnLUVybGluZyBTbcO4cmdyYXY=?= References: <4C21A743.6040306@mahan.org> <86hbkujdto.fsf@ds4.des.no> In-Reply-To: <86hbkujdto.fsf@ds4.des.no> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable Cc: freebsd-hackers@freebsd.org Subject: Re: Help with some makefile hackery X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 25 Jun 2010 12:57:31 -0000 Dag-Erling, I am using option 3 below. I have the following in my shell: amd64-kernel.sh #!/bin/sh trap "exit 1" 1 2 3 15 export SRCROOT=3D`pwd -P` export MAKEOBJDIRPREFIX=3D$SRCROOT/../amd64/obj export SRCCONF=3D$SRCROOT/src.conf # Use our private copy export SECKNOB=3D"-DPRIVATE" KERNCONF=3DTCONF make NO_CLEAN=3Dyes NO_PROFILE=3Dyes NO_MODULES=3Dyes KERNCONF=3D$KERNCON= F buildkernel ||=20 exit 1 =2E.. In the top-level makefile I have the following label: src-kernel: src-kernel-tools cd src; ./amd64-kernel.sh 2>&1 | tee build_amd64_kernel.log If there is a build failure with the kernel, it can be seen in the file 'build_amd64_kernel.log'. However, the top-level make file just continues on to the next label as if no error occurs. The reason we are using shell scripts is because of the environment variables that need to be defined and some other house-keeping stuff that I did not include in the above example. Also, I wanted scripts so the developer could just build individual "groups" without resorting to building everything. Thanks, Patrick Dag-Erling Sm=C3=B8rgrav wrote: > Patrick Mahan writes: >> My issue is that if there is a build failure at any point, the >> status does not seem to be propagated upward. For example, if >> the kernel fails to build due to incorrect code, the script >> -kernel64.sh stops (verifable by examining the logfile), >> however, the make will continue to the next target, src-world, >> and continue building. How do I propagate the status up to the >> top-level make? >=20 > Your shell script needs to exit with a non-zero status if it fails. > There are several ways to do this. For instance, if your shell script > looks like this: >=20 > #!/bin/sh > make TARGET=3Damd64 kernel-toolchain >=20 > you can: >=20 > - prefix "make" with "exec": sh will exec make instead of running it i= n > a subshell, and the exit status will be whatever make returns. >=20 > - add the following line at the bottom: >=20 > exit $? >=20 > which causes the shell script to exit with the same exit status as > the last command it ran, in this case make. >=20 > - append "|| exit 1" to the the "make" command line; this will cause > the script to exit immediately with status 1 if make fails, otherwis= e > it will continue (in case you want to do something else if make > succeeds) >=20 > - wrap the make command line in an if statement, which allows you do > additional work depending on the outcome, and end the failure case > with "exit 1" or similar >=20 > - insert the following line at any point between the shebang and the > make command line: >=20 > set -e >=20 > this will cause sh to terminate the script immediately with a > non-zero exit status if any command after the "set" line fails. >=20 > However, I don't see the point of using shell scripts in the first > place... >=20 > DES