From: Ryan Anderson <ryan@michonline.com>
To: Linus Torvalds <torvalds@transmeta.com>
Cc: linux-kernel@vger.kernel.org,
kernel-janitor-discuss@lists.sourceforge.net
Subject: [PATCH][SPARSE] Runtime detection of gcc include paths
Date: Sun, 8 Jun 2003 21:11:28 -0400 [thread overview]
Message-ID: <20030609011128.GI20872@michonline.com> (raw)
Update pre-process.c to do runtime detection of gcc's internal include
paths.
This uses the same method as previously was used, it just performs the
lookup at runtime.
I do not believe this will work for cross-compiles, though, I believe
the fix will be fairly trivial. (Given that I don't cross-compile, I'm
not quite sure what the exact mechanisms to do so are.)
This should set things up to be able to provide packaged versions. My
next patch will (probably) be everything necessary to build a Debian
package.
# This is a BitKeeper generated patch for the following project:
# Project Name: TSCT - The Silly C Tokenizer
# This patch format is intended for GNU patch command version 2.5 or higher.
# This patch includes the following deltas:
# ChangeSet 1.355 -> 1.356
# Makefile 1.23 -> 1.24
# pre-process.c 1.65 -> 1.67
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 03/06/08 ryan@mythryan2.(none) 1.356
# Rework the way gcc internal includes are found to be done entirely at run-time.
# --------------------------------------------
#
diff -Nru a/Makefile b/Makefile
--- a/Makefile Sun Jun 8 21:04:32 2003
+++ b/Makefile Sun Jun 8 21:04:32 2003
@@ -32,7 +32,7 @@
expression.o: $(LIB_H)
lib.o: $(LIB_H)
parse.o: $(LIB_H)
-pre-process.o: $(LIB_H) pre-process.h
+pre-process.o: $(LIB_H)
scope.o: $(LIB_H)
show-parse.o: $(LIB_H)
symbol.o: $(LIB_H)
@@ -40,8 +40,6 @@
test-parsing.o: $(LIB_H)
tokenize.o: $(LIB_H)
-pre-process.h:
- echo "#define GCC_INTERNAL_INCLUDE \"`$(CC) -print-file-name=include`\"" > pre-process.h
clean:
- rm -f *.[oasi] core core.[0-9]* $(PROGRAMS) pre-process.h
+ rm -f *.[oasi] core core.[0-9]* $(PROGRAMS)
diff -Nru a/pre-process.c b/pre-process.c
--- a/pre-process.c Sun Jun 8 21:04:32 2003
+++ b/pre-process.c Sun Jun 8 21:04:32 2003
@@ -18,7 +18,6 @@
#include <fcntl.h>
#include <limits.h>
-#include "pre-process.h"
#include "lib.h"
#include "parse.h"
#include "token.h"
@@ -45,8 +44,7 @@
NULL,
};
-const char *gcc_includepath[] = {
- GCC_INTERNAL_INCLUDE,
+const char *gcc_includepath[INCLUDEPATHS+1] = {
NULL
};
@@ -531,6 +529,68 @@
}
return 0;
}
+
+static int init_gcc_include_path()
+{
+ char cc[128];
+ char cmd[256];
+ char *s;
+ char buffer[128];;
+ FILE *p;
+
+ s = getenv("CC");
+ if (s) {
+ strncpy(cc,s,127);
+ cc[127]='\0';
+
+ } else {
+ strcpy(cc,"gcc");
+ }
+
+ snprintf(cmd,256,"%s --print-file-name=include",cc);
+
+ p = popen(cmd,"r");
+ if (!p) {
+ perror("ERROR: failed to find gcc-include-path");
+ return 0;
+ }
+
+ /* The format of each line is simply "pathname\n".
+ * So we simply need to strip the last character off the
+ * line before storing it.
+ */
+
+ int includes = 0;
+ do {
+ s = fgets(buffer,127,p);
+ if (s) {
+ buffer[strlen(buffer)-1] = '\0';
+ gcc_includepath[includes] = strdup(buffer);
+ includes++;
+ }
+
+ } while (includes < INCLUDEPATHS - 1 && !feof(p));
+
+ gcc_includepath[includes] = NULL;
+
+ pclose(p);
+
+ return 1;
+
+
+}
+
+
+static int do_gcc_include_path(struct token *head, struct token *token, const char *filename, int flen)
+{
+ static int initialized = 0;
+ if (!initialized) {
+ if (!init_gcc_include_path())
+ return 0;
+ initialized = 1;
+ }
+ return do_include_path(gcc_includepath,head,token,filename,flen);
+}
static void do_include(int local, struct stream *stream, struct token *head, struct token *token, const char *filename)
@@ -556,7 +616,7 @@
return;
if (do_include_path(sys_includepath, head, token, filename, flen))
return;
- if (do_include_path(gcc_includepath, head, token, filename, flen))
+ if (do_gcc_include_path(head,token,filename,flen))
return;
error(token->pos, "unable to open '%s'", filename);
--
Ryan Anderson
sometimes Pug Majere
next reply other threads:[~2003-06-09 0:52 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-06-09 1:11 Ryan Anderson [this message]
2003-06-09 1:09 ` [PATCH][SPARSE] Runtime detection of gcc include paths Linus Torvalds
2003-06-09 3:51 ` H. Peter Anvin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20030609011128.GI20872@michonline.com \
--to=ryan@michonline.com \
--cc=kernel-janitor-discuss@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@transmeta.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox