This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH/RFC] Step 2 in getting GNU libobjc back to be able to use on Darwin, include files



On Jul 26, 2004, at 4:43 PM, James E Wilson wrote:


Andrew Pinski wrote:
after which TARGET_EXTRA_INCLUDES does.  Yes I added the documenation
for TARGET_EXTRA_PRE_INCLUDES but I did not say they both have to be
defined and you have to declare target_c_incpath your self as this
was not done before but I will post a follow up patch which documents
this requirement.

This second step in getting GNU's libobjc working correctly
on Darwin.

Makes we wonder if I missed the first step, as I don't see it. Maybe it was in the PR?

Step 1 was the libobjc part which I had committed a while back.



I didn't see this followup patch, but maybe you were waiting for some approvals? As it stands, the docs don't agree with the sources, so either the docs need to be updated, or else the patches need to be reworked so that you don't have to define both. I'd suggest that it makes more sense to fix the code to handle these like other hooks. So TARGET_*EXTRA_INCLUDES are defined to an empty hook if the target doesn't define them. And then darwin-c.c no longer needs to define target_c_incpath, and we no longer need C_INCPATH_INIT. I think this would be better then fixing the docs.

And this is what I committed after testing on both powerpc-apple- darwin and i686-pc-linux-gnu. This combined both step 2 and step 3 and fixes the need to document the need to define both TARGET_*EXTRA_INCLUDES.

ChangeLog:

	* c-incpath.h (target_c_incpath_s): Add extra_pre_includes.
	Add two parameters to extra_includes.
	(C_INCPATH_INIT): Remove.
	* c-incpath.c (register_include_chains): Call extra_pre_includes
	before adding the standard include directory.
	Update call to extra_includes.
	(!defined TARGET_EXTRA_INCLUDES): Update
	hook_void_charptr_charptr_int and add !define
	TARGET_EXTRA_PRE_INCLUDES.
	(!define TARGET_EXTRA_INCLUDES): Define as
	hook_void_charptr_charptr_int.
	(!define TARGET_EXTRA_PRE_INCLUDES): Likewise.
	(target_c_incpath): Always declare.
	* fixinclude.c (defined TARGET_EXTRA_INCLUDES): Declare a
	empty function.
	(define TARGET_EXTRA_PRE_INCLUDES): Likewise.
	* config/darwin.h: (darwin_register_frameworks): Update for
	the two new parameters.
	(darwin_register_objc_includes): Add prototype.
	(TARGET_EXTRA_PRE_INCLUDES): Define.
	* config/darwin-c.c (darwin_register_objc_includes): New function.
	(darwin_register_frameworks): Update for the two new parameters.
	(target_c_incpath): Remove.
	* config/t-darwin (darwin-c.o): Add $(PREPROCESSOR_DEFINES) to
	the compile line.
	* doc/tm.texi (TARGET_EXTRA_INCLUDES): Document the two new
	parameters.
	(TARGET_EXTRA_PRE_INCLUDES): Document.


* gcc.c (spec_function): Add replace-outfile. (replace_outfile_spec_function): New function. * config/darwin.h (LINK_SPEC): Add replace -lobjc with -lobjc-gnu if -fgnu-runtime is supplied. * invoke.texi (replace-outfile): Document.


Index: c-incpath.c =================================================================== RCS file: /cvs/gcc/gcc/gcc/c-incpath.c,v retrieving revision 1.17 diff -u -p -r1.17 c-incpath.c --- c-incpath.c 10 Sep 2004 15:09:36 -0000 1.17 +++ c-incpath.c 16 Sep 2004 06:09:36 -0000 @@ -372,21 +372,34 @@ register_include_chains (cpp_reader *pfi include chain. */ add_env_var_paths ("CPATH", BRACKET); add_env_var_paths (lang_env_vars[idx], SYSTEM); + + target_c_incpath.extra_pre_includes (sysroot, iprefix, stdinc);

   /* Finally chain on the standard directories.  */
   if (stdinc)
     add_standard_paths (sysroot, iprefix, cxx_stdinc);

-  target_c_incpath.extra_includes (stdinc);
+  target_c_incpath.extra_includes (sysroot, iprefix, stdinc);

merge_include_chains (pfile, verbose);

cpp_set_include_chains (pfile, heads[QUOTE], heads[BRACKET],
quote_ignores_source_dir);
}
+#if !(defined TARGET_EXTRA_INCLUDES) || !(defined TARGET_EXTRA_PRE_INCLUDES)
+static void hook_void_charptr_charptr_int (const char *sysroot ATTRIBUTE_UNUSED,
+ const char *iprefix ATTRIBUTE_UNUSED,
+ int stdinc ATTRIBUTE_UNUSED)
+{
+}
+#endif


#ifndef TARGET_EXTRA_INCLUDES
-static void hook_void_int(int u ATTRIBUTE_UNUSED) { }
-
-struct target_c_incpath_s target_c_incpath = { hook_void_int };
+#define TARGET_EXTRA_INCLUDES hook_void_charptr_charptr_int
#endif
+#ifndef TARGET_EXTRA_PRE_INCLUDES
+#define TARGET_EXTRA_PRE_INCLUDES hook_void_charptr_charptr_int
+#endif
+
+struct target_c_incpath_s target_c_incpath = { TARGET_EXTRA_PRE_INCLUDES, TARGET_EXTRA_INCLUDES };
+
Index: c-incpath.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-incpath.h,v
retrieving revision 1.6
diff -u -p -r1.6 c-incpath.h
--- c-incpath.h 22 May 2004 02:39:31 -0000 1.6
+++ c-incpath.h 16 Sep 2004 06:09:36 -0000
@@ -23,11 +23,10 @@ extern void add_cpp_dir_path (struct cpp


struct target_c_incpath_s {
/* Do extra includes processing. STDINC is false iff -nostdinc was given. */
- void (*extra_includes) (int);
+ void (*extra_pre_includes) (const char *, const char *, int);
+ void (*extra_includes) (const char *, const char *, int);
};


extern struct target_c_incpath_s target_c_incpath;

-#define C_INCPATH_INIT { TARGET_EXTRA_INCLUDES }
-
 enum { QUOTE = 0, BRACKET, SYSTEM, AFTER };
Index: fix-header.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fix-header.c,v
retrieving revision 1.113
diff -u -p -r1.113 fix-header.c
--- fix-header.c	8 Sep 2004 15:44:44 -0000	1.113
+++ fix-header.c	16 Sep 2004 06:09:36 -0000
@@ -82,9 +82,19 @@ Foundation, 59 Temple Place - Suite 330,
 #include "errors.h"

 #ifdef TARGET_EXTRA_INCLUDES
-static void hook_void_int(int u ATTRIBUTE_UNUSED) { }
+void TARGET_EXTRA_INCLUDES (const char *sysroot ATTRIBUTE_UNUSED,
+			    const char *iprefix ATTRIBUTE_UNUSED,
+			    int stdinc ATTRIBUTE_UNUSED)
+{
+}
+#endif

-struct target_c_incpath_s target_c_incpath = { hook_void_int };
+#ifdef TARGET_EXTRA_PRE_INCLUDES
+void TARGET_EXTRA_PRE_INCLUDES (const char *sysroot ATTRIBUTE_UNUSED,
+			    const char *iprefix ATTRIBUTE_UNUSED,
+			    int stdinc ATTRIBUTE_UNUSED)
+{
+}
 #endif

 struct line_maps line_table;
Index: gcc.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gcc.c,v
retrieving revision 1.432
diff -u -p -r1.432 gcc.c
--- gcc.c	9 Sep 2004 11:04:52 -0000	1.432
+++ gcc.c	16 Sep 2004 06:09:38 -0000
@@ -361,6 +361,7 @@ static const char *convert_filename (con

 static const char *if_exists_spec_function (int, const char **);
 static const char *if_exists_else_spec_function (int, const char **);
+static const char *replace_outfile_spec_function (int, const char **);
 
 /* The Specs Language

@@ -1572,6 +1573,7 @@ static const struct spec_function static
 {
   { "if-exists",		if_exists_spec_function },
   { "if-exists-else",		if_exists_else_spec_function },
+  { "replace-outfile",		replace_outfile_spec_function },
   { 0, 0 }
 };

@@ -7582,3 +7584,24 @@ if_exists_else_spec_function (int argc,

return argv[1];
}
+
+/* replace-outfile built-in spec function.
+ This looks for the first argument in the outfiles array's name and replaces it
+ with the second argument. */
+
+static const char *
+replace_outfile_spec_function (int argc, const char **argv)
+{
+ int i;
+ /* Must have exactly two arguments. */
+ if (argc != 2)
+ abort ();
+
+ for (i = 0; i < n_infiles; i++)
+ {
+ if (outfiles[i] && !strcmp (outfiles[i], argv[0]))
+ outfiles[i] = xstrdup (argv[1]);
+ }
+ return NULL;
+}
+
Index: config/darwin-c.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/darwin-c.c,v
retrieving revision 1.13
diff -u -p -r1.13 darwin-c.c
--- config/darwin-c.c 14 Sep 2004 10:45:51 -0000 1.13
+++ config/darwin-c.c 16 Sep 2004 06:09:38 -0000
@@ -30,6 +30,8 @@ Boston, MA 02111-1307, USA. */
#include "c-incpath.h"
#include "toplev.h"
#include "tm_p.h"
+#include "cppdefault.h"
+#include "prefix.h"


/* Pragmas. */

@@ -419,13 +421,55 @@ static const char *framework_defaults []
     "/Library/Frameworks",
   };

+/* Register the GNU objective-C runtime include path if STDINC. */
+
+void
+darwin_register_objc_includes (const char *sysroot, const char *iprefix,
+ int stdinc)
+{
+ const char *fname;
+ size_t len;
+ /* We do not do anything if we do not want the standard includes. */
+ if (!stdinc)
+ return;
+
+ fname = GCC_INCLUDE_DIR "-gnu-runtime";
+
+ /* Register the GNU OBJC runtime include path if we are compiling OBJC
+ with GNU-runtime. */
+
+ if (c_dialect_objc () && !flag_next_runtime)
+ {
+ char *str;
+ /* See if our directory starts with the standard prefix.
+ "Translate" them, ie. replace /usr/local/lib/gcc... with
+ IPREFIX and search them first. */
+ if (iprefix && (len = cpp_GCC_INCLUDE_DIR_len) != 0 && !sysroot
+ && !strncmp (fname, cpp_GCC_INCLUDE_DIR, len))
+ {
+ str = concat (iprefix, fname + len, NULL);
+ /* FIXME: wrap the headers for C++awareness. */
+ add_path (str, SYSTEM, /*c++aware=*/false, false);
+ }
+
+ /* Should this directory start with the sysroot? */
+ if (sysroot)
+ str = concat (sysroot, fname, NULL);
+ else
+ str = update_path (fname, "");
+
+ add_path (str, SYSTEM, /*c++aware=*/false, false);
+ }
+}
+


 /* Register all the system framework paths if STDINC is true and setup
    the missing_header callback for subframework searching if any
    frameworks had been registered.  */

 void
-darwin_register_frameworks (int stdinc)
+darwin_register_frameworks (const char *sysroot ATTRIBUTE_UNUSED,
+			    const char *iprefix ATTRIBUTE_UNUSED, int stdinc)
 {
   if (stdinc)
     {
@@ -476,5 +520,3 @@ find_subframework_header (cpp_reader *pf

   return 0;
 }
-
-struct target_c_incpath_s target_c_incpath = C_INCPATH_INIT;
Index: config/darwin.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/darwin.h,v
retrieving revision 1.95
diff -u -p -r1.95 darwin.h
--- config/darwin.h	8 Sep 2004 18:56:20 -0000	1.95
+++ config/darwin.h	16 Sep 2004 06:09:38 -0000
@@ -238,6 +238,7 @@ extern const char *darwin_fix_and_contin
    their names so all of them get passed.  */
 #define LINK_SPEC  \
   "%{static}%{!static:-dynamic} \
+   %{fgnu-runtime:%:replace-outfile(-lobjc -lobjc-gnu)}\
    %{!Zdynamiclib: \
      %{Zbundle:-bundle} \
      %{Zbundle_loader*:-bundle_loader %*} \
@@ -962,7 +963,9 @@ enum machopic_addr_class {
 #undef ASM_APP_OFF
 #define ASM_APP_OFF ""

-void darwin_register_frameworks (int);
+void darwin_register_frameworks (const char *, const char *, int);
+void darwin_register_objc_includes (const char *, const char *, int);
+#define TARGET_EXTRA_PRE_INCLUDES darwin_register_objc_includes
 #define TARGET_EXTRA_INCLUDES darwin_register_frameworks

void add_framework_path (char *);
Index: config/t-darwin
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/t-darwin,v
retrieving revision 1.7
diff -u -p -r1.7 t-darwin
--- config/t-darwin 10 Sep 2004 18:57:43 -0000 1.7
+++ config/t-darwin 16 Sep 2004 06:09:38 -0000
@@ -7,7 +7,7 @@ darwin.o: $(srcdir)/config/darwin.c $(CO
darwin-c.o: $(srcdir)/config/darwin-c.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
$(TM_H) $(CPPLIB_H) tree.h c-pragma.h $(C_TREE_H) toplev.h $(TM_P_H) \
c-incpath.h
- $(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $(srcdir)/config/darwin-c.c
+ $(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $(srcdir)/config/darwin-c.c $(PREPROCESSOR_DEFINES)


gt-darwin.h : s-gtype ; @true

Index: doc/invoke.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/invoke.texi,v
retrieving revision 1.535
diff -u -p -r1.535 invoke.texi
--- doc/invoke.texi 14 Sep 2004 22:30:38 -0000 1.535
+++ doc/invoke.texi 16 Sep 2004 06:09:40 -0000
@@ -6361,6 +6361,16 @@ based on the existence of the first. He
crt0%O%s %:if-exists(crti%O%s) \
%:if-exists-else(crtbeginT%O%s crtbegin%O%s)
@end smallexample
+
+@item @code{replace-outfile}
+The @code{replace-outfile} spec function takes two arguments. It looks for the
+first argument in the outfiles array and replaces it with the second argument. Here
+is a small example of its usage:
+
+@smallexample
+%@{fgnu-runtime:%:replace-outfile(-lobjc -lobjc-gnu)@}
+@end smallexample
+
@end table


 @item %@{@code{S}@}
Index: doc/tm.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/tm.texi,v
retrieving revision 1.370
diff -u -p -r1.370 tm.texi
--- doc/tm.texi	15 Sep 2004 13:12:33 -0000	1.370
+++ doc/tm.texi	16 Sep 2004 06:09:41 -0000
@@ -9370,10 +9370,19 @@ system library's @code{pow}, @code{powf}
 The default value places no upper bound on the multiplication count.
 @end defmac

-@deftypefn Macro void TARGET_EXTRA_INCLUDES (int @var{stdinc})
+@deftypefn Macro void TARGET_EXTRA_INCLUDES (const char *@var{sysroot}, const char *@var{iprefix}, int @var{stdinc})
This target hook should register any extra include files for the
target. The parameter @var{stdinc} indicates if normal include files
-are present.
+are present. The parameter @var{sysroot} is the system root directory.
+The parameter @var{iprefix} is the prefix for the gcc directory.
+@end deftypefn
+
+@deftypefn Macro void TARGET_EXTRA_PRE_INCLUDES (const char *@var{sysroot}, const char *@var{iprefix}, int @var{stdinc})
+This target hook should register any extra include files for the
+target before any standard headers. The parameter @var{stdinc}
+indicates if normal include files are present. The parameter
+@var{sysroot} is the system root directory. The parameter
+@var{iprefix} is the prefix for the gcc directory.
@end deftypefn


@deftypefn Macro void TARGET_OPTF (char *@var{path})


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]