Hi,
attached is a very small patch for tcc that implements the -M option
(used to generate header dependencies by mkdep).
The patch is trivial -- essentially it reuses the code for -E to create
the list of headers used by a file.

The same patch also includes 4 lines that serve
to ignore the '-std=XXX' option sometimes used to invoke the compilers
(for what matters, my goal is try and build FreeBSD using tcc).
Feel free to put this in an #ifdef if you think is questionable.

Hope people will find it useful.

        cheers
        luigi
diff -ubwr ./libtcc.c ../../work.luigi/tcc-0.9.25/libtcc.c
--- ./libtcc.c  2009-12-01 19:42:09.000000000 +0100
+++ ../../work.luigi/tcc-0.9.25/libtcc.c        2009-12-01 17:53:20.000000000 
+0100
@@ -2119,7 +2119,9 @@
 {
     char buf[1024];
 
-    s->output_type = output_type;
+    s->output_type = output_type & 7;
+    s->mode_m = output_type & 8;
+    output_type = s->output_type;
 
     if (!s->nostdinc) {
         /* default include paths */
diff -ubwr ./tcc.c ../../work.luigi/tcc-0.9.25/tcc.c
--- ./tcc.c     2009-05-18 16:27:06.000000000 +0200
+++ ../../work.luigi/tcc-0.9.25/tcc.c   2009-12-01 17:54:17.000000000 +0100
@@ -66,6 +66,7 @@
 static int multiple_files;
 static int print_search_dirs;
 static int output_type;
+static int mode_m;
 static int reloc_output;
 static const char *outfile;
 static int do_bench = 0;
@@ -111,6 +112,8 @@
     TCC_OPTION_w,
     TCC_OPTION_pipe,
     TCC_OPTION_E,
+    TCC_OPTION_M,      /* mkdep */
+    TCC_OPTION_std,    /* -std= */
 };
 
 static const TCCOption tcc_options[] = {
@@ -148,6 +150,8 @@
     { "w", TCC_OPTION_w, 0 },
     { "pipe", TCC_OPTION_pipe, 0},
     { "E", TCC_OPTION_E, 0},
+    { "M", TCC_OPTION_M, 0},
+    { "std=", TCC_OPTION_std, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },
     { NULL },
 };
 
@@ -399,6 +402,10 @@
                     }
                 }
                 break;
+            case TCC_OPTION_std:
+               break; /* ignore -std= */
+            case TCC_OPTION_M:
+                mode_m = 8;    /* FALLTHROUGH */
             case TCC_OPTION_E:
                 output_type = TCC_OUTPUT_PREPROCESS;
                 break;
@@ -502,7 +507,7 @@
         start_time = getclock_us();
     }
 
-    tcc_set_output_type(s, output_type);
+    tcc_set_output_type(s, output_type | mode_m);
 
     /* compile or add each files or library */
     for(i = 0; i < nb_files && ret == 0; i++) {
diff -ubwr ./tcc.h ../../work.luigi/tcc-0.9.25/tcc.h
--- ./tcc.h     2009-05-18 16:27:06.000000000 +0200
+++ ../../work.luigi/tcc-0.9.25/tcc.h   2009-12-01 17:49:44.000000000 +0100
@@ -367,6 +367,7 @@
 
 struct TCCState {
     int output_type;
+    int mode_m;        /* tcc -M */
  
     BufferedFile **include_stack_ptr;
     int *ifdef_stack_ptr;
diff -ubwr ./tccpp.c ../../work.luigi/tcc-0.9.25/tccpp.c
--- ./tccpp.c   2009-05-18 16:27:06.000000000 +0200
+++ ../../work.luigi/tcc-0.9.25/tccpp.c 2009-12-01 19:39:27.000000000 +0100
@@ -2897,6 +2897,7 @@
     Sym *define_start;
     BufferedFile *file_ref;
     int token_seen, line_ref;
+    const char *base_file;
 
     preprocess_init(s1);
     define_start = define_stack;
@@ -2908,6 +2909,12 @@
     line_ref = 0;
     file_ref = NULL;
 
+    base_file = file->filename;
+    if (s1->mode_m) {
+       int l = strlen(base_file);
+       fprintf(s1->outfile, "%.*s.o: %s", l-2, base_file, base_file);
+    }
+
     for (;;) {
         next();
         if (tok == TOK_EOF) {
@@ -2919,16 +2926,25 @@
             token_seen = 0;
         } else if (!token_seen) {
             int d = file->line_num - line_ref;
+         if (s1->mode_m) {
+           if (file != file_ref && file->filename != base_file &&
+               !search_cached_include(s1, '>', file->filename))
+             fprintf(s1->outfile, " \\\n  %s", file->filename);
+         } else {
             if (file != file_ref || d < 0 || d >= 8)
                 fprintf(s1->outfile, "# %d \"%s\"\n", file->line_num, 
file->filename);
             else
                 while (d)
                     fputs("\n", s1->outfile), --d;
+         }
             line_ref = (file_ref = file)->line_num;
             token_seen = 1;
         }
+      if (!s1->mode_m)
         fputs(get_tok_str(tok, &tokc), s1->outfile);
     }
+    if (s1->mode_m)
+       fprintf(s1->outfile, "\n");
     free_defines(define_start); 
     return 0;
 }
_______________________________________________
Tinycc-devel mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/tinycc-devel

Reply via email to