From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9448 invoked by alias); 18 Feb 2015 08:26:08 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 9435 invoked by uid 89); 18 Feb 2015 08:26:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 18 Feb 2015 08:26:06 +0000 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=SVR-IES-FEM-02.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1YNzxK-0003KL-7T from Thomas_Schwinge@mentor.com ; Wed, 18 Feb 2015 00:26:02 -0800 Received: from feldtkeller.schwinge.homeip.net (137.202.0.76) by SVR-IES-FEM-02.mgc.mentorg.com (137.202.0.106) with Microsoft SMTP Server id 14.3.224.2; Wed, 18 Feb 2015 08:26:01 +0000 From: Thomas Schwinge To: GCC Patches CC: Bernd Schmidt , , Subject: nvptx mkoffload: For non-installed testing, look in all COMPILER_PATHs for GCC_INSTALL_NAME (was: nvptx offloading patches [4/n]) In-Reply-To: <5454CDF1.3070307@codesourcery.com> References: <5454CDF1.3070307@codesourcery.com> User-Agent: Notmuch/0.9-101-g81dad07 (http://notmuchmail.org) Emacs/24.4.1 (i586-pc-linux-gnu) Date: Wed, 18 Feb 2015 08:26:00 -0000 Message-ID: <87fva3fwx6.fsf@kepler.schwinge.homeip.net> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" X-SW-Source: 2015-02/txt/msg01068.txt.bz2 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Content-length: 4963 Hi! On Sat, 1 Nov 2014 13:11:29 +0100, Bernd Schmidt = wrote: > [nvptx mkoffload] To support the --enable-offload-targets=3Dnvptx-none=3D[install directory] configuration option, I committed the following to trunk in r220782 (and filed ): commit a7243b5200794d53b01d59fa69d467a0545db73f Author: tschwinge Date: Wed Feb 18 08:17:32 2015 +0000 nvptx mkoffload: For non-installed testing, look in all COMPILER_PATHs = for GCC_INSTALL_NAME. =20=20=20=20 gcc/ * config/nvptx/mkoffload.c (parse_env_var, free_array_of_ptrs) (access_check): New functions, copied from config/i386/intelmic-mkoffload.c. (main): For non-installed testing, look in all COMPILER_PATHs for GCC_INSTALL_NAME. =20=20=20=20 git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@220782 138bc75d-0d04-04= 10-961f-82ee72b054a4 --- gcc/ChangeLog | 6 +++ gcc/config/nvptx/mkoffload.c | 103 ++++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 109 insertions(+) diff --git gcc/ChangeLog gcc/ChangeLog index 180a605..0f144f5 100644 --- gcc/ChangeLog +++ gcc/ChangeLog @@ -1,5 +1,11 @@ 2015-02-18 Thomas Schwinge =20 + * config/nvptx/mkoffload.c (parse_env_var, free_array_of_ptrs) + (access_check): New functions, copied from + config/i386/intelmic-mkoffload.c. + (main): For non-installed testing, look in all COMPILER_PATHs for + GCC_INSTALL_NAME. + * config/nvptx/nvptx.h (GOMP_SELF_SPECS): Define macro. =20 2015-02-18 Andrew Pinski diff --git gcc/config/nvptx/mkoffload.c gcc/config/nvptx/mkoffload.c index 96341b8..02c44b6 100644 --- gcc/config/nvptx/mkoffload.c +++ gcc/config/nvptx/mkoffload.c @@ -762,6 +762,78 @@ parse_file (Token *tok) return tok; } =20 +/* Parse STR, saving found tokens into PVALUES and return their number. + Tokens are assumed to be delimited by ':'. */ +static unsigned +parse_env_var (const char *str, char ***pvalues) +{ + const char *curval, *nextval; + char **values; + unsigned num =3D 1, i; + + curval =3D strchr (str, ':'); + while (curval) + { + num++; + curval =3D strchr (curval + 1, ':'); + } + + values =3D (char **) xmalloc (num * sizeof (char *)); + curval =3D str; + nextval =3D strchr (curval, ':'); + if (nextval =3D=3D NULL) + nextval =3D strchr (curval, '\0'); + + for (i =3D 0; i < num; i++) + { + int l =3D nextval - curval; + values[i] =3D (char *) xmalloc (l + 1); + memcpy (values[i], curval, l); + values[i][l] =3D 0; + curval =3D nextval + 1; + nextval =3D strchr (curval, ':'); + if (nextval =3D=3D NULL) + nextval =3D strchr (curval, '\0'); + } + *pvalues =3D values; + return num; +} + +/* Auxiliary function that frees elements of PTR and PTR itself. + N is number of elements to be freed. If PTR is NULL, nothing is freed. + If an element is NULL, subsequent elements are not freed. */ +static void +free_array_of_ptrs (void **ptr, unsigned n) +{ + unsigned i; + if (!ptr) + return; + for (i =3D 0; i < n; i++) + { + if (!ptr[i]) + break; + free (ptr[i]); + } + free (ptr); + return; +} + +/* Check whether NAME can be accessed in MODE. This is like access, + except that it never considers directories to be executable. */ +static int +access_check (const char *name, int mode) +{ + if (mode =3D=3D X_OK) + { + struct stat st; + + if (stat (name, &st) < 0 || S_ISDIR (st.st_mode)) + return -1; + } + + return access (name, mode); +} + static void process (FILE *in, FILE *out) { @@ -853,6 +925,37 @@ main (int argc, char **argv) driver_used =3D sprintf (driver, "%s/", gcc_path); sprintf (driver + driver_used, "%s", GCC_INSTALL_NAME); =20 + bool found =3D false; + if (gcc_path =3D=3D NULL) + found =3D true; + else if (access_check (driver, X_OK) =3D=3D 0) + found =3D true; + else + { + /* Don't use alloca pointer with XRESIZEVEC. */ + driver =3D NULL; + /* Look in all COMPILER_PATHs for GCC_INSTALL_NAME. */ + char **paths =3D NULL; + unsigned n_paths; + n_paths =3D parse_env_var (getenv ("COMPILER_PATH"), &paths); + for (unsigned i =3D 0; i < n_paths; i++) + { + len =3D strlen (paths[i]) + 1 + strlen (GCC_INSTALL_NAME) + 1; + driver =3D XRESIZEVEC (char, driver, len); + sprintf (driver, "%s/%s", paths[i], GCC_INSTALL_NAME); + if (access_check (driver, X_OK) =3D=3D 0) + { + found =3D true; + break; + } + } + free_array_of_ptrs ((void **) paths, n_paths); + } + + if (!found) + fatal_error (input_location, + "offload compiler %s not found", GCC_INSTALL_NAME); + /* We may be called with all the arguments stored in some file and passed with @file. Expand them into argv before processing. */ expandargv (&argc, &argv); Gr=C3=BC=C3=9Fe, Thomas --=-=-= Content-Type: application/pgp-signature; name="signature.asc" Content-length: 472 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAEBAgAGBQJU5EyVAAoJEK3/DN1sMFFtJP8IALXgmugnIPMXz8MFSTvL4UW3 vbwq35bNpNreAUfKIfHMVhZtxN+SnQDB+6qLKG81NOOLJ3e3FTUwjw3/irxmbXSk ANgy6kTlDJNQeHhggHmhCP1jsg+XSNxmIWVijHn9iMTEGeAo19oafaC9/rRwMTe3 wdtqwfm8Gzrp1/VS+VrBMN6hu0UH//gNXPi6zTANtom4McCkRTufLfiMC+sBAu+8 CxbXHmEQ2WtpuPT94Y6E/U3sxCB9Djev/MD/LlP1mlWIRf7hKQfQ1fkDmF85MrJ0 hx0XyrKd7XjXY5nkViyGmGZLvuBnXYVRtvkjOmfindTXCfo3lsmyym9CNYYhOMU= =z7yZ -----END PGP SIGNATURE----- --=-=-=--