makefiles: Generate the tools dependencies from makedep.
[wine.git] / tools / makedep.c
blob57adf0bc264668c29ee3d04e77208f90235b2c46
1 /*
2 * Generate include file dependencies
4 * Copyright 1996, 2013 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
22 #define NO_LIBWINE_PORT
23 #include "wine/port.h"
25 #include <assert.h>
26 #include <ctype.h>
27 #include <errno.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <stdarg.h>
31 #include <signal.h>
32 #include <string.h>
33 #ifdef HAVE_UNISTD_H
34 # include <unistd.h>
35 #endif
36 #include "wine/list.h"
38 struct strarray
40 unsigned int count; /* strings in use */
41 unsigned int size; /* total allocated size */
42 const char **str;
45 enum incl_type
47 INCL_NORMAL, /* #include "foo.h" */
48 INCL_SYSTEM, /* #include <foo.h> */
49 INCL_IMPORT, /* idl import "foo.idl" */
50 INCL_IMPORTLIB, /* idl importlib "foo.tlb" */
51 INCL_CPP_QUOTE, /* idl cpp_quote("#include \"foo.h\"") */
52 INCL_CPP_QUOTE_SYSTEM /* idl cpp_quote("#include <foo.h>") */
55 struct dependency
57 int line; /* source line where this header is included */
58 enum incl_type type; /* type of include */
59 char *name; /* header name */
62 struct file
64 struct list entry;
65 char *name; /* full file name relative to cwd */
66 void *args; /* custom arguments for makefile rule */
67 unsigned int flags; /* flags (see below) */
68 unsigned int deps_count; /* files in use */
69 unsigned int deps_size; /* total allocated size */
70 struct dependency *deps; /* all header dependencies */
73 struct incl_file
75 struct list entry;
76 struct file *file;
77 char *name;
78 char *filename;
79 char *sourcename; /* source file name for generated headers */
80 struct incl_file *included_by; /* file that included this one */
81 int included_line; /* line where this file was included */
82 enum incl_type type; /* type of include */
83 struct incl_file *owner;
84 unsigned int files_count; /* files in use */
85 unsigned int files_size; /* total allocated size */
86 struct incl_file **files;
87 struct strarray dependencies; /* file dependencies */
90 #define FLAG_GENERATED 0x000001 /* generated file */
91 #define FLAG_INSTALL 0x000002 /* file to install */
92 #define FLAG_IDL_PROXY 0x000100 /* generates a proxy (_p.c) file */
93 #define FLAG_IDL_CLIENT 0x000200 /* generates a client (_c.c) file */
94 #define FLAG_IDL_SERVER 0x000400 /* generates a server (_s.c) file */
95 #define FLAG_IDL_IDENT 0x000800 /* generates an ident (_i.c) file */
96 #define FLAG_IDL_REGISTER 0x001000 /* generates a registration (_r.res) file */
97 #define FLAG_IDL_TYPELIB 0x002000 /* generates a typelib (.tlb) file */
98 #define FLAG_IDL_REGTYPELIB 0x004000 /* generates a registered typelib (_t.res) file */
99 #define FLAG_IDL_HEADER 0x008000 /* generates a header (.h) file */
100 #define FLAG_RC_PO 0x010000 /* rc file contains translations */
101 #define FLAG_C_IMPLIB 0x020000 /* file is part of an import library */
102 #define FLAG_SFD_FONTS 0x040000 /* sfd file generated bitmap fonts */
104 static const struct
106 unsigned int flag;
107 const char *ext;
108 } idl_outputs[] =
110 { FLAG_IDL_TYPELIB, ".tlb" },
111 { FLAG_IDL_REGTYPELIB, "_t.res" },
112 { FLAG_IDL_CLIENT, "_c.c" },
113 { FLAG_IDL_IDENT, "_i.c" },
114 { FLAG_IDL_PROXY, "_p.c" },
115 { FLAG_IDL_SERVER, "_s.c" },
116 { FLAG_IDL_REGISTER, "_r.res" },
117 { FLAG_IDL_HEADER, ".h" }
120 #define HASH_SIZE 997
122 static struct list files[HASH_SIZE];
124 static const struct strarray empty_strarray;
126 enum install_rules { INSTALL_LIB, INSTALL_DEV, NB_INSTALL_RULES };
128 /* variables common to all makefiles */
129 static struct strarray linguas;
130 static struct strarray dll_flags;
131 static struct strarray target_flags;
132 static struct strarray msvcrt_flags;
133 static struct strarray extra_cflags;
134 static struct strarray cpp_flags;
135 static struct strarray unwind_flags;
136 static struct strarray libs;
137 static struct strarray enable_tests;
138 static struct strarray cmdline_vars;
139 static struct strarray disabled_dirs;
140 static const char *root_src_dir;
141 static const char *tools_dir;
142 static const char *tools_ext;
143 static const char *exe_ext;
144 static const char *dll_ext;
145 static const char *man_ext;
146 static const char *crosstarget;
147 static const char *fontforge;
148 static const char *convert;
149 static const char *rsvg;
150 static const char *icotool;
151 static const char *dlltool;
152 static const char *msgfmt;
153 static const char *ln_s;
155 struct makefile
157 /* values determined from input makefile */
158 struct strarray vars;
159 struct strarray include_paths;
160 struct strarray include_args;
161 struct strarray define_args;
162 struct strarray programs;
163 struct strarray scripts;
164 struct strarray appmode;
165 struct strarray imports;
166 struct strarray subdirs;
167 struct strarray delayimports;
168 struct strarray extradllflags;
169 struct strarray install_lib;
170 struct strarray install_dev;
171 struct list sources;
172 struct list includes;
173 const char *base_dir;
174 const char *src_dir;
175 const char *obj_dir;
176 const char *top_src_dir;
177 const char *top_obj_dir;
178 const char *parent_dir;
179 const char *module;
180 const char *testdll;
181 const char *sharedlib;
182 const char *staticlib;
183 const char *staticimplib;
184 const char *importlib;
185 int disabled;
186 int use_msvcrt;
187 int is_win16;
188 struct makefile **submakes;
190 /* values generated at output time */
191 struct strarray in_files;
192 struct strarray ok_files;
193 struct strarray clean_files;
194 struct strarray distclean_files;
195 struct strarray uninstall_files;
196 struct strarray object_files;
197 struct strarray crossobj_files;
198 struct strarray c2man_files;
199 struct strarray dlldata_files;
200 struct strarray implib_objs;
201 struct strarray all_targets;
202 struct strarray phony_targets;
203 struct strarray install_rules[NB_INSTALL_RULES];
206 static struct makefile *top_makefile;
208 static const char separator[] = "### Dependencies";
209 static const char *output_makefile_name = "Makefile";
210 static const char *input_file_name;
211 static const char *output_file_name;
212 static const char *temp_file_name;
213 static int relative_dir_mode;
214 static int input_line;
215 static int output_column;
216 static FILE *output_file;
218 static const char Usage[] =
219 "Usage: makedep [options] [directories]\n"
220 "Options:\n"
221 " -R from to Compute the relative path between two directories\n"
222 " -fxxx Store output in file 'xxx' (default: Makefile)\n";
225 #ifndef __GNUC__
226 #define __attribute__(x)
227 #endif
229 static void fatal_error( const char *msg, ... ) __attribute__ ((__format__ (__printf__, 1, 2)));
230 static void fatal_perror( const char *msg, ... ) __attribute__ ((__format__ (__printf__, 1, 2)));
231 static void output( const char *format, ... ) __attribute__ ((__format__ (__printf__, 1, 2)));
232 static char *strmake( const char* fmt, ... ) __attribute__ ((__format__ (__printf__, 1, 2)));
234 /*******************************************************************
235 * fatal_error
237 static void fatal_error( const char *msg, ... )
239 va_list valist;
240 va_start( valist, msg );
241 if (input_file_name)
243 fprintf( stderr, "%s:", input_file_name );
244 if (input_line) fprintf( stderr, "%d:", input_line );
245 fprintf( stderr, " error: " );
247 else fprintf( stderr, "makedep: error: " );
248 vfprintf( stderr, msg, valist );
249 va_end( valist );
250 exit(1);
254 /*******************************************************************
255 * fatal_perror
257 static void fatal_perror( const char *msg, ... )
259 va_list valist;
260 va_start( valist, msg );
261 if (input_file_name)
263 fprintf( stderr, "%s:", input_file_name );
264 if (input_line) fprintf( stderr, "%d:", input_line );
265 fprintf( stderr, " error: " );
267 else fprintf( stderr, "makedep: error: " );
268 vfprintf( stderr, msg, valist );
269 perror( " " );
270 va_end( valist );
271 exit(1);
275 /*******************************************************************
276 * cleanup_files
278 static void cleanup_files(void)
280 if (temp_file_name) unlink( temp_file_name );
281 if (output_file_name) unlink( output_file_name );
285 /*******************************************************************
286 * exit_on_signal
288 static void exit_on_signal( int sig )
290 exit( 1 ); /* this will call the atexit functions */
294 /*******************************************************************
295 * xmalloc
297 static void *xmalloc( size_t size )
299 void *res;
300 if (!(res = malloc (size ? size : 1)))
301 fatal_error( "Virtual memory exhausted.\n" );
302 return res;
306 /*******************************************************************
307 * xrealloc
309 static void *xrealloc (void *ptr, size_t size)
311 void *res;
312 assert( size );
313 if (!(res = realloc( ptr, size )))
314 fatal_error( "Virtual memory exhausted.\n" );
315 return res;
318 /*******************************************************************
319 * xstrdup
321 static char *xstrdup( const char *str )
323 char *res = strdup( str );
324 if (!res) fatal_error( "Virtual memory exhausted.\n" );
325 return res;
329 /*******************************************************************
330 * strmake
332 static char *strmake( const char* fmt, ... )
334 int n;
335 size_t size = 100;
336 va_list ap;
338 for (;;)
340 char *p = xmalloc (size);
341 va_start(ap, fmt);
342 n = vsnprintf (p, size, fmt, ap);
343 va_end(ap);
344 if (n == -1) size *= 2;
345 else if ((size_t)n >= size) size = n + 1;
346 else return xrealloc( p, n + 1 );
347 free(p);
352 /*******************************************************************
353 * strendswith
355 static int strendswith( const char* str, const char* end )
357 size_t l = strlen( str );
358 size_t m = strlen( end );
360 return l >= m && strcmp(str + l - m, end) == 0;
364 /*******************************************************************
365 * output
367 static void output( const char *format, ... )
369 int ret;
370 va_list valist;
372 va_start( valist, format );
373 ret = vfprintf( output_file, format, valist );
374 va_end( valist );
375 if (ret < 0) fatal_perror( "output" );
376 if (format[0] && format[strlen(format) - 1] == '\n') output_column = 0;
377 else output_column += ret;
381 /*******************************************************************
382 * strarray_add
384 static void strarray_add( struct strarray *array, const char *str )
386 if (array->count == array->size)
388 if (array->size) array->size *= 2;
389 else array->size = 16;
390 array->str = xrealloc( array->str, sizeof(array->str[0]) * array->size );
392 array->str[array->count++] = str;
396 /*******************************************************************
397 * strarray_addall
399 static void strarray_addall( struct strarray *array, struct strarray added )
401 unsigned int i;
403 for (i = 0; i < added.count; i++) strarray_add( array, added.str[i] );
407 /*******************************************************************
408 * strarray_exists
410 static int strarray_exists( const struct strarray *array, const char *str )
412 unsigned int i;
414 for (i = 0; i < array->count; i++) if (!strcmp( array->str[i], str )) return 1;
415 return 0;
419 /*******************************************************************
420 * strarray_add_uniq
422 static void strarray_add_uniq( struct strarray *array, const char *str )
424 if (!strarray_exists( array, str )) strarray_add( array, str );
428 /*******************************************************************
429 * strarray_get_value
431 * Find a value in a name/value pair string array.
433 static const char *strarray_get_value( const struct strarray *array, const char *name )
435 int pos, res, min = 0, max = array->count / 2 - 1;
437 while (min <= max)
439 pos = (min + max) / 2;
440 if (!(res = strcmp( array->str[pos * 2], name ))) return array->str[pos * 2 + 1];
441 if (res < 0) min = pos + 1;
442 else max = pos - 1;
444 return NULL;
448 /*******************************************************************
449 * strarray_set_value
451 * Define a value in a name/value pair string array.
453 static void strarray_set_value( struct strarray *array, const char *name, const char *value )
455 int i, pos, res, min = 0, max = array->count / 2 - 1;
457 while (min <= max)
459 pos = (min + max) / 2;
460 if (!(res = strcmp( array->str[pos * 2], name )))
462 /* redefining a variable replaces the previous value */
463 array->str[pos * 2 + 1] = value;
464 return;
466 if (res < 0) min = pos + 1;
467 else max = pos - 1;
469 strarray_add( array, NULL );
470 strarray_add( array, NULL );
471 for (i = array->count - 1; i > min * 2 + 1; i--) array->str[i] = array->str[i - 2];
472 array->str[min * 2] = name;
473 array->str[min * 2 + 1] = value;
477 /*******************************************************************
478 * strarray_set_qsort
480 static void strarray_qsort( struct strarray *array, int (*func)(const char **, const char **) )
482 if (array->count) qsort( array->str, array->count, sizeof(*array->str), (void *)func );
486 /*******************************************************************
487 * output_filename
489 static void output_filename( const char *name )
491 if (output_column + strlen(name) + 1 > 100)
493 output( " \\\n" );
494 output( " " );
496 else if (output_column) output( " " );
497 output( "%s", name );
501 /*******************************************************************
502 * output_filenames
504 static void output_filenames( struct strarray array )
506 unsigned int i;
508 for (i = 0; i < array.count; i++) output_filename( array.str[i] );
512 /*******************************************************************
513 * output_rm_filenames
515 static void output_rm_filenames( struct strarray array )
517 static const unsigned int max_cmdline = 30000; /* to be on the safe side */
518 unsigned int i, len;
520 if (!array.count) return;
521 output( "\trm -f" );
522 for (i = len = 0; i < array.count; i++)
524 if (len > max_cmdline)
526 output( "\n" );
527 output( "\trm -f" );
528 len = 0;
530 output_filename( array.str[i] );
531 len += strlen( array.str[i] ) + 1;
533 output( "\n" );
537 /*******************************************************************
538 * get_extension
540 static char *get_extension( char *filename )
542 char *ext = strrchr( filename, '.' );
543 if (ext && strchr( ext, '/' )) ext = NULL;
544 return ext;
548 /*******************************************************************
549 * replace_extension
551 static char *replace_extension( const char *name, const char *old_ext, const char *new_ext )
553 char *ret;
554 size_t name_len = strlen( name );
555 size_t ext_len = strlen( old_ext );
557 if (name_len >= ext_len && !strcmp( name + name_len - ext_len, old_ext )) name_len -= ext_len;
558 ret = xmalloc( name_len + strlen( new_ext ) + 1 );
559 memcpy( ret, name, name_len );
560 strcpy( ret + name_len, new_ext );
561 return ret;
565 /*******************************************************************
566 * replace_filename
568 static char *replace_filename( const char *path, const char *name )
570 const char *p;
571 char *ret;
572 size_t len;
574 if (!path) return xstrdup( name );
575 if (!(p = strrchr( path, '/' ))) return xstrdup( name );
576 len = p - path + 1;
577 ret = xmalloc( len + strlen( name ) + 1 );
578 memcpy( ret, path, len );
579 strcpy( ret + len, name );
580 return ret;
584 /*******************************************************************
585 * strarray_replace_extension
587 static struct strarray strarray_replace_extension( const struct strarray *array,
588 const char *old_ext, const char *new_ext )
590 unsigned int i;
591 struct strarray ret;
593 ret.count = ret.size = array->count;
594 ret.str = xmalloc( sizeof(ret.str[0]) * ret.size );
595 for (i = 0; i < array->count; i++) ret.str[i] = replace_extension( array->str[i], old_ext, new_ext );
596 return ret;
600 /*******************************************************************
601 * replace_substr
603 static char *replace_substr( const char *str, const char *start, size_t len, const char *replace )
605 size_t pos = start - str;
606 char *ret = xmalloc( pos + strlen(replace) + strlen(start + len) + 1 );
607 memcpy( ret, str, pos );
608 strcpy( ret + pos, replace );
609 strcat( ret + pos, start + len );
610 return ret;
614 /*******************************************************************
615 * get_relative_path
617 * Determine where the destination path is located relative to the 'from' path.
619 static char *get_relative_path( const char *from, const char *dest )
621 const char *start;
622 char *ret, *p;
623 unsigned int dotdots = 0;
625 /* a path of "." is equivalent to an empty path */
626 if (!strcmp( from, "." )) from = "";
628 for (;;)
630 while (*from == '/') from++;
631 while (*dest == '/') dest++;
632 start = dest; /* save start of next path element */
633 if (!*from) break;
635 while (*from && *from != '/' && *from == *dest) { from++; dest++; }
636 if ((!*from || *from == '/') && (!*dest || *dest == '/')) continue;
638 /* count remaining elements in 'from' */
641 dotdots++;
642 while (*from && *from != '/') from++;
643 while (*from == '/') from++;
645 while (*from);
646 break;
649 if (!start[0] && !dotdots) return NULL; /* empty path */
651 ret = xmalloc( 3 * dotdots + strlen( start ) + 1 );
652 for (p = ret; dotdots; dotdots--, p += 3) memcpy( p, "../", 3 );
654 if (start[0]) strcpy( p, start );
655 else p[-1] = 0; /* remove trailing slash */
656 return ret;
660 /*******************************************************************
661 * concat_paths
663 static char *concat_paths( const char *base, const char *path )
665 if (!base || !base[0]) return xstrdup( path && path[0] ? path : "." );
666 if (!path || !path[0]) return xstrdup( base );
667 if (path[0] == '/') return xstrdup( path );
668 return strmake( "%s/%s", base, path );
672 /*******************************************************************
673 * base_dir_path
675 static char *base_dir_path( const struct makefile *make, const char *path )
677 return concat_paths( make->base_dir, path );
681 /*******************************************************************
682 * obj_dir_path
684 static char *obj_dir_path( const struct makefile *make, const char *path )
686 return concat_paths( make->obj_dir, path );
690 /*******************************************************************
691 * src_dir_path
693 static char *src_dir_path( const struct makefile *make, const char *path )
695 if (make->src_dir) return concat_paths( make->src_dir, path );
696 return obj_dir_path( make, path );
700 /*******************************************************************
701 * top_obj_dir_path
703 static char *top_obj_dir_path( const struct makefile *make, const char *path )
705 return concat_paths( make->top_obj_dir, path );
709 /*******************************************************************
710 * top_src_dir_path
712 static char *top_src_dir_path( const struct makefile *make, const char *path )
714 if (make->top_src_dir) return concat_paths( make->top_src_dir, path );
715 return top_obj_dir_path( make, path );
719 /*******************************************************************
720 * root_dir_path
722 static char *root_dir_path( const char *path )
724 return concat_paths( root_src_dir, path );
728 /*******************************************************************
729 * tools_dir_path
731 static char *tools_dir_path( const struct makefile *make, const char *path )
733 if (tools_dir) return top_obj_dir_path( make, strmake( "%s/tools/%s", tools_dir, path ));
734 return top_obj_dir_path( make, strmake( "tools/%s", path ));
738 /*******************************************************************
739 * tools_path
741 static char *tools_path( const struct makefile *make, const char *name )
743 return strmake( "%s/%s%s", tools_dir_path( make, name ), name, tools_ext );
747 /*******************************************************************
748 * get_line
750 static char *get_line( FILE *file )
752 static char *buffer;
753 static size_t size;
755 if (!size)
757 size = 1024;
758 buffer = xmalloc( size );
760 if (!fgets( buffer, size, file )) return NULL;
761 input_line++;
763 for (;;)
765 char *p = buffer + strlen(buffer);
766 /* if line is larger than buffer, resize buffer */
767 while (p == buffer + size - 1 && p[-1] != '\n')
769 buffer = xrealloc( buffer, size * 2 );
770 if (!fgets( buffer + size - 1, size + 1, file )) break;
771 p = buffer + strlen(buffer);
772 size *= 2;
774 if (p > buffer && p[-1] == '\n')
776 *(--p) = 0;
777 if (p > buffer && p[-1] == '\r') *(--p) = 0;
778 if (p > buffer && p[-1] == '\\')
780 *(--p) = 0;
781 /* line ends in backslash, read continuation line */
782 if (!fgets( p, size - (p - buffer), file )) return buffer;
783 input_line++;
784 continue;
787 return buffer;
792 /*******************************************************************
793 * hash_filename
795 static unsigned int hash_filename( const char *name )
797 /* FNV-1 hash */
798 unsigned int ret = 2166136261u;
799 while (*name) ret = (ret * 16777619) ^ *name++;
800 return ret % HASH_SIZE;
804 /*******************************************************************
805 * add_file
807 static struct file *add_file( const char *name )
809 struct file *file = xmalloc( sizeof(*file) );
810 memset( file, 0, sizeof(*file) );
811 file->name = xstrdup( name );
812 return file;
816 /*******************************************************************
817 * add_dependency
819 static void add_dependency( struct file *file, const char *name, enum incl_type type )
821 /* enforce some rules for the Wine tree */
823 if (!memcmp( name, "../", 3 ))
824 fatal_error( "#include directive with relative path not allowed\n" );
826 if (!strcmp( name, "config.h" ))
828 if (strendswith( file->name, ".h" ))
829 fatal_error( "config.h must not be included by a header file\n" );
830 if (file->deps_count)
831 fatal_error( "config.h must be included before anything else\n" );
833 else if (!strcmp( name, "wine/port.h" ))
835 if (strendswith( file->name, ".h" ))
836 fatal_error( "wine/port.h must not be included by a header file\n" );
837 if (!file->deps_count) fatal_error( "config.h must be included before wine/port.h\n" );
838 if (file->deps_count > 1)
839 fatal_error( "wine/port.h must be included before everything except config.h\n" );
840 if (strcmp( file->deps[0].name, "config.h" ))
841 fatal_error( "config.h must be included before wine/port.h\n" );
844 if (file->deps_count >= file->deps_size)
846 file->deps_size *= 2;
847 if (file->deps_size < 16) file->deps_size = 16;
848 file->deps = xrealloc( file->deps, file->deps_size * sizeof(*file->deps) );
850 file->deps[file->deps_count].line = input_line;
851 file->deps[file->deps_count].type = type;
852 file->deps[file->deps_count].name = xstrdup( name );
853 file->deps_count++;
857 /*******************************************************************
858 * find_src_file
860 static struct incl_file *find_src_file( const struct makefile *make, const char *name )
862 struct incl_file *file;
864 LIST_FOR_EACH_ENTRY( file, &make->sources, struct incl_file, entry )
865 if (!strcmp( name, file->name )) return file;
866 return NULL;
869 /*******************************************************************
870 * find_include_file
872 static struct incl_file *find_include_file( const struct makefile *make, const char *name )
874 struct incl_file *file;
876 LIST_FOR_EACH_ENTRY( file, &make->includes, struct incl_file, entry )
877 if (!strcmp( name, file->name )) return file;
878 return NULL;
881 /*******************************************************************
882 * add_include
884 * Add an include file if it doesn't already exists.
886 static struct incl_file *add_include( struct makefile *make, struct incl_file *parent,
887 const char *name, int line, enum incl_type type )
889 struct incl_file *include;
891 if (parent->files_count >= parent->files_size)
893 parent->files_size *= 2;
894 if (parent->files_size < 16) parent->files_size = 16;
895 parent->files = xrealloc( parent->files, parent->files_size * sizeof(*parent->files) );
898 LIST_FOR_EACH_ENTRY( include, &make->includes, struct incl_file, entry )
899 if (!strcmp( name, include->name )) goto found;
901 include = xmalloc( sizeof(*include) );
902 memset( include, 0, sizeof(*include) );
903 include->name = xstrdup(name);
904 include->included_by = parent;
905 include->included_line = line;
906 include->type = type;
907 list_add_tail( &make->includes, &include->entry );
908 found:
909 parent->files[parent->files_count++] = include;
910 return include;
914 /*******************************************************************
915 * add_generated_source
917 * Add a generated source file to the list.
919 static struct incl_file *add_generated_source( struct makefile *make,
920 const char *name, const char *filename )
922 struct incl_file *file;
924 if ((file = find_src_file( make, name ))) return file; /* we already have it */
925 file = xmalloc( sizeof(*file) );
926 memset( file, 0, sizeof(*file) );
927 file->file = add_file( name );
928 file->name = xstrdup( name );
929 file->filename = obj_dir_path( make, filename ? filename : name );
930 file->file->flags = FLAG_GENERATED;
931 list_add_tail( &make->sources, &file->entry );
932 return file;
936 /*******************************************************************
937 * parse_include_directive
939 static void parse_include_directive( struct file *source, char *str )
941 char quote, *include, *p = str;
943 while (*p && isspace(*p)) p++;
944 if (*p != '\"' && *p != '<' ) return;
945 quote = *p++;
946 if (quote == '<') quote = '>';
947 include = p;
948 while (*p && (*p != quote)) p++;
949 if (!*p) fatal_error( "malformed include directive '%s'\n", str );
950 *p = 0;
951 add_dependency( source, include, (quote == '>') ? INCL_SYSTEM : INCL_NORMAL );
955 /*******************************************************************
956 * parse_pragma_directive
958 static void parse_pragma_directive( struct file *source, char *str )
960 char *flag, *p = str;
962 if (!isspace( *p )) return;
963 while (*p && isspace(*p)) p++;
964 p = strtok( p, " \t" );
965 if (strcmp( p, "makedep" )) return;
967 while ((flag = strtok( NULL, " \t" )))
969 if (!strcmp( flag, "depend" ))
971 while ((p = strtok( NULL, " \t" ))) add_dependency( source, p, INCL_NORMAL );
972 return;
974 else if (!strcmp( flag, "install" )) source->flags |= FLAG_INSTALL;
976 if (strendswith( source->name, ".idl" ))
978 if (!strcmp( flag, "header" )) source->flags |= FLAG_IDL_HEADER;
979 else if (!strcmp( flag, "proxy" )) source->flags |= FLAG_IDL_PROXY;
980 else if (!strcmp( flag, "client" )) source->flags |= FLAG_IDL_CLIENT;
981 else if (!strcmp( flag, "server" )) source->flags |= FLAG_IDL_SERVER;
982 else if (!strcmp( flag, "ident" )) source->flags |= FLAG_IDL_IDENT;
983 else if (!strcmp( flag, "typelib" )) source->flags |= FLAG_IDL_TYPELIB;
984 else if (!strcmp( flag, "register" )) source->flags |= FLAG_IDL_REGISTER;
985 else if (!strcmp( flag, "regtypelib" )) source->flags |= FLAG_IDL_REGTYPELIB;
987 else if (strendswith( source->name, ".rc" ))
989 if (!strcmp( flag, "po" )) source->flags |= FLAG_RC_PO;
991 else if (strendswith( source->name, ".sfd" ))
993 if (!strcmp( flag, "font" ))
995 struct strarray *array = source->args;
997 if (!array)
999 source->args = array = xmalloc( sizeof(*array) );
1000 *array = empty_strarray;
1001 source->flags |= FLAG_SFD_FONTS;
1003 strarray_add( array, xstrdup( strtok( NULL, "" )));
1004 return;
1007 else if (!strcmp( flag, "implib" )) source->flags |= FLAG_C_IMPLIB;
1012 /*******************************************************************
1013 * parse_cpp_directive
1015 static void parse_cpp_directive( struct file *source, char *str )
1017 while (*str && isspace(*str)) str++;
1018 if (*str++ != '#') return;
1019 while (*str && isspace(*str)) str++;
1021 if (!strncmp( str, "include", 7 ))
1022 parse_include_directive( source, str + 7 );
1023 else if (!strncmp( str, "import", 6 ) && strendswith( source->name, ".m" ))
1024 parse_include_directive( source, str + 6 );
1025 else if (!strncmp( str, "pragma", 6 ))
1026 parse_pragma_directive( source, str + 6 );
1030 /*******************************************************************
1031 * parse_idl_file
1033 static void parse_idl_file( struct file *source, FILE *file )
1035 char *buffer, *include;
1037 input_line = 0;
1039 while ((buffer = get_line( file )))
1041 char quote;
1042 char *p = buffer;
1043 while (*p && isspace(*p)) p++;
1045 if (!strncmp( p, "importlib", 9 ))
1047 p += 9;
1048 while (*p && isspace(*p)) p++;
1049 if (*p++ != '(') continue;
1050 while (*p && isspace(*p)) p++;
1051 if (*p++ != '"') continue;
1052 include = p;
1053 while (*p && (*p != '"')) p++;
1054 if (!*p) fatal_error( "malformed importlib directive\n" );
1055 *p = 0;
1056 add_dependency( source, include, INCL_IMPORTLIB );
1057 continue;
1060 if (!strncmp( p, "import", 6 ))
1062 p += 6;
1063 while (*p && isspace(*p)) p++;
1064 if (*p != '"') continue;
1065 include = ++p;
1066 while (*p && (*p != '"')) p++;
1067 if (!*p) fatal_error( "malformed import directive\n" );
1068 *p = 0;
1069 add_dependency( source, include, INCL_IMPORT );
1070 continue;
1073 /* check for #include inside cpp_quote */
1074 if (!strncmp( p, "cpp_quote", 9 ))
1076 p += 9;
1077 while (*p && isspace(*p)) p++;
1078 if (*p++ != '(') continue;
1079 while (*p && isspace(*p)) p++;
1080 if (*p++ != '"') continue;
1081 if (*p++ != '#') continue;
1082 while (*p && isspace(*p)) p++;
1083 if (strncmp( p, "include", 7 )) continue;
1084 p += 7;
1085 while (*p && isspace(*p)) p++;
1086 if (*p == '\\' && p[1] == '"')
1088 p += 2;
1089 quote = '"';
1091 else
1093 if (*p++ != '<' ) continue;
1094 quote = '>';
1096 include = p;
1097 while (*p && (*p != quote)) p++;
1098 if (!*p || (quote == '"' && p[-1] != '\\'))
1099 fatal_error( "malformed #include directive inside cpp_quote\n" );
1100 if (quote == '"') p--; /* remove backslash */
1101 *p = 0;
1102 add_dependency( source, include, (quote == '>') ? INCL_CPP_QUOTE_SYSTEM : INCL_CPP_QUOTE );
1103 continue;
1106 parse_cpp_directive( source, p );
1110 /*******************************************************************
1111 * parse_c_file
1113 static void parse_c_file( struct file *source, FILE *file )
1115 char *buffer;
1117 input_line = 0;
1118 while ((buffer = get_line( file )))
1120 parse_cpp_directive( source, buffer );
1125 /*******************************************************************
1126 * parse_rc_file
1128 static void parse_rc_file( struct file *source, FILE *file )
1130 char *buffer, *include;
1132 input_line = 0;
1133 while ((buffer = get_line( file )))
1135 char quote;
1136 char *p = buffer;
1137 while (*p && isspace(*p)) p++;
1139 if (p[0] == '/' && p[1] == '*') /* check for magic makedep comment */
1141 p += 2;
1142 while (*p && isspace(*p)) p++;
1143 if (strncmp( p, "@makedep:", 9 )) continue;
1144 p += 9;
1145 while (*p && isspace(*p)) p++;
1146 quote = '"';
1147 if (*p == quote)
1149 include = ++p;
1150 while (*p && *p != quote) p++;
1152 else
1154 include = p;
1155 while (*p && !isspace(*p) && *p != '*') p++;
1157 if (!*p)
1158 fatal_error( "malformed makedep comment\n" );
1159 *p = 0;
1160 add_dependency( source, include, (quote == '>') ? INCL_SYSTEM : INCL_NORMAL );
1161 continue;
1164 parse_cpp_directive( source, buffer );
1169 /*******************************************************************
1170 * parse_in_file
1172 static void parse_in_file( struct file *source, FILE *file )
1174 char *p, *buffer;
1176 /* make sure it gets rebuilt when the version changes */
1177 add_dependency( source, "config.h", INCL_SYSTEM );
1179 if (!strendswith( source->name, ".man.in" )) return; /* not a man page */
1181 input_line = 0;
1182 while ((buffer = get_line( file )))
1184 if (strncmp( buffer, ".TH", 3 )) continue;
1185 if (!(p = strtok( buffer, " \t" ))) continue; /* .TH */
1186 if (!(p = strtok( NULL, " \t" ))) continue; /* program name */
1187 if (!(p = strtok( NULL, " \t" ))) continue; /* man section */
1188 source->args = xstrdup( p );
1189 return;
1194 /*******************************************************************
1195 * parse_sfd_file
1197 static void parse_sfd_file( struct file *source, FILE *file )
1199 char *p, *eol, *buffer;
1201 input_line = 0;
1202 while ((buffer = get_line( file )))
1204 if (strncmp( buffer, "UComments:", 10 )) continue;
1205 p = buffer + 10;
1206 while (*p == ' ') p++;
1207 if (p[0] == '"' && p[1] && buffer[strlen(buffer) - 1] == '"')
1209 p++;
1210 buffer[strlen(buffer) - 1] = 0;
1212 while ((eol = strstr( p, "+AAoA" )))
1214 *eol = 0;
1215 while (*p && isspace(*p)) p++;
1216 if (*p++ == '#')
1218 while (*p && isspace(*p)) p++;
1219 if (!strncmp( p, "pragma", 6 )) parse_pragma_directive( source, p + 6 );
1221 p = eol + 5;
1223 while (*p && isspace(*p)) p++;
1224 if (*p++ != '#') return;
1225 while (*p && isspace(*p)) p++;
1226 if (!strncmp( p, "pragma", 6 )) parse_pragma_directive( source, p + 6 );
1227 return;
1232 static const struct
1234 const char *ext;
1235 void (*parse)( struct file *file, FILE *f );
1236 } parse_functions[] =
1238 { ".c", parse_c_file },
1239 { ".h", parse_c_file },
1240 { ".inl", parse_c_file },
1241 { ".l", parse_c_file },
1242 { ".m", parse_c_file },
1243 { ".rh", parse_c_file },
1244 { ".x", parse_c_file },
1245 { ".y", parse_c_file },
1246 { ".idl", parse_idl_file },
1247 { ".rc", parse_rc_file },
1248 { ".in", parse_in_file },
1249 { ".sfd", parse_sfd_file }
1252 /*******************************************************************
1253 * load_file
1255 static struct file *load_file( const char *name )
1257 struct file *file;
1258 FILE *f;
1259 unsigned int i, hash = hash_filename( name );
1261 LIST_FOR_EACH_ENTRY( file, &files[hash], struct file, entry )
1262 if (!strcmp( name, file->name )) return file;
1264 if (!(f = fopen( name, "r" ))) return NULL;
1266 file = add_file( name );
1267 list_add_tail( &files[hash], &file->entry );
1268 input_file_name = file->name;
1269 input_line = 0;
1271 for (i = 0; i < sizeof(parse_functions) / sizeof(parse_functions[0]); i++)
1273 if (!strendswith( name, parse_functions[i].ext )) continue;
1274 parse_functions[i].parse( file, f );
1275 break;
1278 fclose( f );
1279 input_file_name = NULL;
1281 return file;
1285 /*******************************************************************
1286 * open_include_path_file
1288 * Open a file from a directory on the include path.
1290 static struct file *open_include_path_file( const struct makefile *make, const char *dir,
1291 const char *name, char **filename )
1293 char *src_path = base_dir_path( make, concat_paths( dir, name ));
1294 struct file *ret = load_file( src_path );
1296 if (ret) *filename = src_dir_path( make, concat_paths( dir, name ));
1297 return ret;
1301 /*******************************************************************
1302 * open_file_same_dir
1304 * Open a file in the same directory as the parent.
1306 static struct file *open_file_same_dir( const struct incl_file *parent, const char *name, char **filename )
1308 char *src_path = replace_filename( parent->file->name, name );
1309 struct file *ret = load_file( src_path );
1311 if (ret) *filename = replace_filename( parent->filename, name );
1312 free( src_path );
1313 return ret;
1317 /*******************************************************************
1318 * open_local_file
1320 * Open a file in the source directory of the makefile.
1322 static struct file *open_local_file( const struct makefile *make, const char *path, char **filename )
1324 char *src_path = root_dir_path( base_dir_path( make, path ));
1325 struct file *ret = load_file( src_path );
1327 /* if not found, try parent dir */
1328 if (!ret && make->parent_dir)
1330 free( src_path );
1331 path = strmake( "%s/%s", make->parent_dir, path );
1332 src_path = root_dir_path( base_dir_path( make, path ));
1333 ret = load_file( src_path );
1336 if (ret) *filename = src_dir_path( make, path );
1337 free( src_path );
1338 return ret;
1342 /*******************************************************************
1343 * open_global_file
1345 * Open a file in the top-level source directory.
1347 static struct file *open_global_file( const struct makefile *make, const char *path, char **filename )
1349 char *src_path = root_dir_path( path );
1350 struct file *ret = load_file( src_path );
1352 if (ret) *filename = top_src_dir_path( make, path );
1353 free( src_path );
1354 return ret;
1358 /*******************************************************************
1359 * open_global_header
1361 * Open a file in the global include source directory.
1363 static struct file *open_global_header( const struct makefile *make, const char *path, char **filename )
1365 return open_global_file( make, strmake( "include/%s", path ), filename );
1369 /*******************************************************************
1370 * open_src_file
1372 static struct file *open_src_file( const struct makefile *make, struct incl_file *pFile )
1374 struct file *file = open_local_file( make, pFile->name, &pFile->filename );
1376 if (!file) fatal_perror( "open %s", pFile->name );
1377 return file;
1381 /*******************************************************************
1382 * open_include_file
1384 static struct file *open_include_file( const struct makefile *make, struct incl_file *pFile )
1386 struct file *file = NULL;
1387 char *filename;
1388 unsigned int i, len;
1390 errno = ENOENT;
1392 /* check for generated bison header */
1394 if (strendswith( pFile->name, ".tab.h" ) &&
1395 (file = open_local_file( make, replace_extension( pFile->name, ".tab.h", ".y" ), &filename )))
1397 pFile->sourcename = filename;
1398 pFile->filename = obj_dir_path( make, pFile->name );
1399 return file;
1402 /* check for corresponding idl file in source dir */
1404 if (strendswith( pFile->name, ".h" ) &&
1405 (file = open_local_file( make, replace_extension( pFile->name, ".h", ".idl" ), &filename )))
1407 pFile->sourcename = filename;
1408 pFile->filename = obj_dir_path( make, pFile->name );
1409 return file;
1412 /* check for corresponding tlb file in source dir */
1414 if (strendswith( pFile->name, ".tlb" ) &&
1415 (file = open_local_file( make, replace_extension( pFile->name, ".tlb", ".idl" ), &filename )))
1417 pFile->sourcename = filename;
1418 pFile->filename = obj_dir_path( make, pFile->name );
1419 return file;
1422 /* now try in source dir */
1423 if ((file = open_local_file( make, pFile->name, &pFile->filename ))) return file;
1425 /* check for corresponding idl file in global includes */
1427 if (strendswith( pFile->name, ".h" ) &&
1428 (file = open_global_header( make, replace_extension( pFile->name, ".h", ".idl" ), &filename )))
1430 pFile->sourcename = filename;
1431 pFile->filename = top_obj_dir_path( make, strmake( "include/%s", pFile->name ));
1432 return file;
1435 /* check for corresponding .in file in global includes (for config.h.in) */
1437 if (strendswith( pFile->name, ".h" ) &&
1438 (file = open_global_header( make, replace_extension( pFile->name, ".h", ".h.in" ), &filename )))
1440 pFile->sourcename = filename;
1441 pFile->filename = top_obj_dir_path( make, strmake( "include/%s", pFile->name ));
1442 return file;
1445 /* check for corresponding .x file in global includes */
1447 if (strendswith( pFile->name, "tmpl.h" ) &&
1448 (file = open_global_header( make, replace_extension( pFile->name, ".h", ".x" ), &filename )))
1450 pFile->sourcename = filename;
1451 pFile->filename = top_obj_dir_path( make, strmake( "include/%s", pFile->name ));
1452 return file;
1455 /* check for corresponding .tlb file in global includes */
1457 if (strendswith( pFile->name, ".tlb" ) &&
1458 (file = open_global_header( make, replace_extension( pFile->name, ".tlb", ".idl" ), &filename )))
1460 pFile->sourcename = filename;
1461 pFile->filename = top_obj_dir_path( make, strmake( "include/%s", pFile->name ));
1462 return file;
1465 /* check in global includes source dir */
1467 if ((file = open_global_header( make, pFile->name, &pFile->filename ))) return file;
1469 /* check in global msvcrt includes */
1470 if (make->use_msvcrt &&
1471 (file = open_global_header( make, strmake( "msvcrt/%s", pFile->name ), &pFile->filename )))
1472 return file;
1474 /* now search in include paths */
1475 for (i = 0; i < make->include_paths.count; i++)
1477 const char *dir = make->include_paths.str[i];
1478 const char *prefix = make->top_src_dir ? make->top_src_dir : make->top_obj_dir;
1480 if (prefix)
1482 len = strlen( prefix );
1483 if (!strncmp( dir, prefix, len ) && (!dir[len] || dir[len] == '/'))
1485 while (dir[len] == '/') len++;
1486 file = open_global_file( make, concat_paths( dir + len, pFile->name ), &pFile->filename );
1487 if (file) return file;
1489 if (make->top_src_dir) continue; /* ignore paths that don't point to the top source dir */
1491 if (*dir != '/')
1493 if ((file = open_include_path_file( make, dir, pFile->name, &pFile->filename )))
1494 return file;
1497 if (pFile->type == INCL_SYSTEM) return NULL; /* ignore system files we cannot find */
1499 /* try in src file directory */
1500 if ((file = open_file_same_dir( pFile->included_by, pFile->name, &pFile->filename ))) return file;
1502 fprintf( stderr, "%s:%d: error: ", pFile->included_by->file->name, pFile->included_line );
1503 perror( pFile->name );
1504 pFile = pFile->included_by;
1505 while (pFile && pFile->included_by)
1507 const char *parent = pFile->included_by->sourcename;
1508 if (!parent) parent = pFile->included_by->file->name;
1509 fprintf( stderr, "%s:%d: note: %s was first included here\n",
1510 parent, pFile->included_line, pFile->name );
1511 pFile = pFile->included_by;
1513 exit(1);
1517 /*******************************************************************
1518 * add_all_includes
1520 static void add_all_includes( struct makefile *make, struct incl_file *parent, struct file *file )
1522 unsigned int i;
1524 parent->files_count = 0;
1525 parent->files_size = file->deps_count;
1526 parent->files = xmalloc( parent->files_size * sizeof(*parent->files) );
1527 for (i = 0; i < file->deps_count; i++)
1529 switch (file->deps[i].type)
1531 case INCL_NORMAL:
1532 case INCL_IMPORT:
1533 add_include( make, parent, file->deps[i].name, file->deps[i].line, INCL_NORMAL );
1534 break;
1535 case INCL_IMPORTLIB:
1536 add_include( make, parent, file->deps[i].name, file->deps[i].line, INCL_IMPORTLIB );
1537 break;
1538 case INCL_SYSTEM:
1539 add_include( make, parent, file->deps[i].name, file->deps[i].line, INCL_SYSTEM );
1540 break;
1541 case INCL_CPP_QUOTE:
1542 case INCL_CPP_QUOTE_SYSTEM:
1543 break;
1549 /*******************************************************************
1550 * parse_file
1552 static void parse_file( struct makefile *make, struct incl_file *source, int src )
1554 struct file *file = src ? open_src_file( make, source ) : open_include_file( make, source );
1556 if (!file) return;
1558 source->file = file;
1559 source->files_count = 0;
1560 source->files_size = file->deps_count;
1561 source->files = xmalloc( source->files_size * sizeof(*source->files) );
1563 if (source->sourcename)
1565 if (strendswith( source->sourcename, ".idl" ))
1567 unsigned int i;
1569 if (strendswith( source->name, ".tlb" )) return; /* typelibs don't include anything */
1571 /* generated .h file always includes these */
1572 add_include( make, source, "rpc.h", 0, INCL_NORMAL );
1573 add_include( make, source, "rpcndr.h", 0, INCL_NORMAL );
1574 for (i = 0; i < file->deps_count; i++)
1576 switch (file->deps[i].type)
1578 case INCL_IMPORT:
1579 if (strendswith( file->deps[i].name, ".idl" ))
1580 add_include( make, source, replace_extension( file->deps[i].name, ".idl", ".h" ),
1581 file->deps[i].line, INCL_NORMAL );
1582 else
1583 add_include( make, source, file->deps[i].name, file->deps[i].line, INCL_NORMAL );
1584 break;
1585 case INCL_CPP_QUOTE:
1586 add_include( make, source, file->deps[i].name, file->deps[i].line, INCL_NORMAL );
1587 break;
1588 case INCL_CPP_QUOTE_SYSTEM:
1589 add_include( make, source, file->deps[i].name, file->deps[i].line, INCL_SYSTEM );
1590 break;
1591 case INCL_NORMAL:
1592 case INCL_SYSTEM:
1593 case INCL_IMPORTLIB:
1594 break;
1597 return;
1599 if (strendswith( source->sourcename, ".y" ))
1600 return; /* generated .tab.h doesn't include anything */
1603 add_all_includes( make, source, file );
1607 /*******************************************************************
1608 * add_src_file
1610 * Add a source file to the list.
1612 static struct incl_file *add_src_file( struct makefile *make, const char *name )
1614 struct incl_file *file;
1616 if ((file = find_src_file( make, name ))) return file; /* we already have it */
1617 file = xmalloc( sizeof(*file) );
1618 memset( file, 0, sizeof(*file) );
1619 file->name = xstrdup(name);
1620 list_add_tail( &make->sources, &file->entry );
1621 parse_file( make, file, 1 );
1622 return file;
1626 /*******************************************************************
1627 * open_input_makefile
1629 static FILE *open_input_makefile( const struct makefile *make )
1631 FILE *ret;
1633 if (make->base_dir)
1634 input_file_name = root_dir_path( base_dir_path( make, strmake( "%s.in", output_makefile_name )));
1635 else
1636 input_file_name = output_makefile_name; /* always use output name for main Makefile */
1638 input_line = 0;
1639 if (!(ret = fopen( input_file_name, "r" ))) fatal_perror( "open" );
1640 return ret;
1644 /*******************************************************************
1645 * get_make_variable
1647 static const char *get_make_variable( const struct makefile *make, const char *name )
1649 const char *ret;
1651 if ((ret = strarray_get_value( &cmdline_vars, name ))) return ret;
1652 if ((ret = strarray_get_value( &make->vars, name ))) return ret;
1653 if (top_makefile && (ret = strarray_get_value( &top_makefile->vars, name ))) return ret;
1654 return NULL;
1658 /*******************************************************************
1659 * get_expanded_make_variable
1661 static char *get_expanded_make_variable( const struct makefile *make, const char *name )
1663 const char *var;
1664 char *p, *end, *expand, *tmp;
1666 var = get_make_variable( make, name );
1667 if (!var) return NULL;
1669 p = expand = xstrdup( var );
1670 while ((p = strchr( p, '$' )))
1672 if (p[1] == '(')
1674 if (!(end = strchr( p + 2, ')' ))) fatal_error( "syntax error in '%s'\n", expand );
1675 *end++ = 0;
1676 if (strchr( p + 2, ':' )) fatal_error( "pattern replacement not supported for '%s'\n", p + 2 );
1677 var = get_make_variable( make, p + 2 );
1678 tmp = replace_substr( expand, p, end - p, var ? var : "" );
1679 /* switch to the new string */
1680 p = tmp + (p - expand);
1681 free( expand );
1682 expand = tmp;
1684 else if (p[1] == '{') /* don't expand ${} variables */
1686 if (!(end = strchr( p + 2, '}' ))) fatal_error( "syntax error in '%s'\n", expand );
1687 p = end + 1;
1689 else if (p[1] == '$')
1691 p += 2;
1693 else fatal_error( "syntax error in '%s'\n", expand );
1696 /* consider empty variables undefined */
1697 p = expand;
1698 while (*p && isspace(*p)) p++;
1699 if (*p) return expand;
1700 free( expand );
1701 return NULL;
1705 /*******************************************************************
1706 * get_expanded_make_var_array
1708 static struct strarray get_expanded_make_var_array( const struct makefile *make, const char *name )
1710 struct strarray ret = empty_strarray;
1711 char *value, *token;
1713 if ((value = get_expanded_make_variable( make, name )))
1714 for (token = strtok( value, " \t" ); token; token = strtok( NULL, " \t" ))
1715 strarray_add( &ret, token );
1716 return ret;
1720 /*******************************************************************
1721 * get_expanded_file_local_var
1723 static struct strarray get_expanded_file_local_var( const struct makefile *make, const char *file,
1724 const char *name )
1726 char *p, *var = strmake( "%s_%s", file, name );
1728 for (p = var; *p; p++) if (!isalnum( *p )) *p = '_';
1729 return get_expanded_make_var_array( make, var );
1733 /*******************************************************************
1734 * set_make_variable
1736 static int set_make_variable( struct strarray *array, const char *assignment )
1738 char *p, *name;
1740 p = name = xstrdup( assignment );
1741 while (isalnum(*p) || *p == '_') p++;
1742 if (name == p) return 0; /* not a variable */
1743 if (isspace(*p))
1745 *p++ = 0;
1746 while (isspace(*p)) p++;
1748 if (*p != '=') return 0; /* not an assignment */
1749 *p++ = 0;
1750 while (isspace(*p)) p++;
1752 strarray_set_value( array, name, p );
1753 return 1;
1757 /*******************************************************************
1758 * parse_makefile
1760 static struct makefile *parse_makefile( const char *path )
1762 char *buffer;
1763 FILE *file;
1764 struct makefile *make = xmalloc( sizeof(*make) );
1766 memset( make, 0, sizeof(*make) );
1767 if (path)
1769 make->top_obj_dir = get_relative_path( path, "" );
1770 make->base_dir = path;
1771 if (!strcmp( make->base_dir, "." )) make->base_dir = NULL;
1774 file = open_input_makefile( make );
1775 while ((buffer = get_line( file )))
1777 if (!strncmp( buffer, separator, strlen(separator) )) break;
1778 if (*buffer == '\t') continue; /* command */
1779 while (isspace( *buffer )) buffer++;
1780 if (*buffer == '#') continue; /* comment */
1781 set_make_variable( &make->vars, buffer );
1783 fclose( file );
1784 input_file_name = NULL;
1785 return make;
1789 /*******************************************************************
1790 * add_generated_sources
1792 static void add_generated_sources( struct makefile *make )
1794 struct incl_file *source, *next, *file;
1796 LIST_FOR_EACH_ENTRY_SAFE( source, next, &make->sources, struct incl_file, entry )
1798 if (source->file->flags & FLAG_IDL_CLIENT)
1800 file = add_generated_source( make, replace_extension( source->name, ".idl", "_c.c" ), NULL );
1801 add_dependency( file->file, replace_extension( source->name, ".idl", ".h" ), INCL_NORMAL );
1802 add_all_includes( make, file, file->file );
1804 if (source->file->flags & FLAG_IDL_SERVER)
1806 file = add_generated_source( make, replace_extension( source->name, ".idl", "_s.c" ), NULL );
1807 add_dependency( file->file, "wine/exception.h", INCL_NORMAL );
1808 add_dependency( file->file, replace_extension( source->name, ".idl", ".h" ), INCL_NORMAL );
1809 add_all_includes( make, file, file->file );
1811 if (source->file->flags & FLAG_IDL_IDENT)
1813 file = add_generated_source( make, replace_extension( source->name, ".idl", "_i.c" ), NULL );
1814 add_dependency( file->file, "rpc.h", INCL_NORMAL );
1815 add_dependency( file->file, "rpcndr.h", INCL_NORMAL );
1816 add_dependency( file->file, "guiddef.h", INCL_NORMAL );
1817 add_all_includes( make, file, file->file );
1819 if (source->file->flags & FLAG_IDL_PROXY)
1821 file = add_generated_source( make, "dlldata.o", "dlldata.c" );
1822 add_dependency( file->file, "objbase.h", INCL_NORMAL );
1823 add_dependency( file->file, "rpcproxy.h", INCL_NORMAL );
1824 add_all_includes( make, file, file->file );
1825 file = add_generated_source( make, replace_extension( source->name, ".idl", "_p.c" ), NULL );
1826 add_dependency( file->file, "objbase.h", INCL_NORMAL );
1827 add_dependency( file->file, "rpcproxy.h", INCL_NORMAL );
1828 add_dependency( file->file, "wine/exception.h", INCL_NORMAL );
1829 add_dependency( file->file, replace_extension( source->name, ".idl", ".h" ), INCL_NORMAL );
1830 add_all_includes( make, file, file->file );
1832 if (source->file->flags & FLAG_IDL_TYPELIB)
1834 add_generated_source( make, replace_extension( source->name, ".idl", ".tlb" ), NULL );
1836 if (source->file->flags & FLAG_IDL_REGTYPELIB)
1838 add_generated_source( make, replace_extension( source->name, ".idl", "_t.res" ), NULL );
1840 if (source->file->flags & FLAG_IDL_REGISTER)
1842 add_generated_source( make, replace_extension( source->name, ".idl", "_r.res" ), NULL );
1844 if (source->file->flags & FLAG_IDL_HEADER)
1846 add_generated_source( make, replace_extension( source->name, ".idl", ".h" ), NULL );
1848 if (!source->file->flags && strendswith( source->name, ".idl" ))
1850 add_generated_source( make, replace_extension( source->name, ".idl", ".h" ), NULL );
1852 if (strendswith( source->name, ".x" ))
1854 add_generated_source( make, replace_extension( source->name, ".x", ".h" ), NULL );
1856 if (strendswith( source->name, ".y" ))
1858 file = add_generated_source( make, replace_extension( source->name, ".y", ".tab.c" ), NULL );
1859 /* steal the includes list from the source file */
1860 file->files_count = source->files_count;
1861 file->files_size = source->files_size;
1862 file->files = source->files;
1863 source->files_count = source->files_size = 0;
1864 source->files = NULL;
1866 if (strendswith( source->name, ".l" ))
1868 file = add_generated_source( make, replace_extension( source->name, ".l", ".yy.c" ), NULL );
1869 /* steal the includes list from the source file */
1870 file->files_count = source->files_count;
1871 file->files_size = source->files_size;
1872 file->files = source->files;
1873 source->files_count = source->files_size = 0;
1874 source->files = NULL;
1876 if (source->file->flags & FLAG_C_IMPLIB)
1878 if (!make->staticimplib && make->importlib && *dll_ext)
1879 make->staticimplib = strmake( "lib%s.a", make->importlib );
1881 if (strendswith( source->name, ".po" ))
1883 if (!make->disabled)
1884 strarray_add_uniq( &linguas, replace_extension( source->name, ".po", "" ));
1887 if (make->testdll)
1889 file = add_generated_source( make, "testlist.o", "testlist.c" );
1890 add_dependency( file->file, "wine/test.h", INCL_NORMAL );
1891 add_all_includes( make, file, file->file );
1896 /*******************************************************************
1897 * create_dir
1899 static void create_dir( const char *dir )
1901 char *p, *path;
1903 p = path = xstrdup( dir );
1904 while ((p = strchr( p, '/' )))
1906 *p = 0;
1907 if (mkdir( path, 0755 ) == -1 && errno != EEXIST) fatal_perror( "mkdir %s", path );
1908 *p++ = '/';
1909 while (*p == '/') p++;
1911 if (mkdir( path, 0755 ) == -1 && errno != EEXIST) fatal_perror( "mkdir %s", path );
1912 free( path );
1916 /*******************************************************************
1917 * create_file_directories
1919 * Create the base directories of all the files.
1921 static void create_file_directories( const struct makefile *make, struct strarray files )
1923 struct strarray subdirs = empty_strarray;
1924 unsigned int i;
1925 char *dir;
1927 for (i = 0; i < files.count; i++)
1929 if (!strchr( files.str[i], '/' )) continue;
1930 dir = base_dir_path( make, files.str[i] );
1931 *strrchr( dir, '/' ) = 0;
1932 strarray_add_uniq( &subdirs, dir );
1935 for (i = 0; i < subdirs.count; i++) create_dir( subdirs.str[i] );
1939 /*******************************************************************
1940 * output_filenames_obj_dir
1942 static void output_filenames_obj_dir( const struct makefile *make, struct strarray array )
1944 unsigned int i;
1946 for (i = 0; i < array.count; i++) output_filename( obj_dir_path( make, array.str[i] ));
1950 /*******************************************************************
1951 * get_dependencies
1953 static void get_dependencies( struct incl_file *file, struct incl_file *source )
1955 unsigned int i;
1957 if (!file->filename) return;
1959 if (file != source)
1961 if (file->owner == source) return; /* already processed */
1962 if (file->type == INCL_IMPORTLIB &&
1963 !(source->file->flags & (FLAG_IDL_TYPELIB | FLAG_IDL_REGTYPELIB)))
1964 return; /* library is imported only when building a typelib */
1965 file->owner = source;
1966 strarray_add( &source->dependencies, file->filename );
1968 for (i = 0; i < file->files_count; i++) get_dependencies( file->files[i], source );
1972 /*******************************************************************
1973 * get_local_dependencies
1975 * Get the local dependencies of a given target.
1977 static struct strarray get_local_dependencies( const struct makefile *make, const char *name,
1978 struct strarray targets )
1980 unsigned int i;
1981 struct strarray deps = get_expanded_file_local_var( make, name, "DEPS" );
1983 for (i = 0; i < deps.count; i++)
1985 if (strarray_exists( &targets, deps.str[i] ))
1986 deps.str[i] = obj_dir_path( make, deps.str[i] );
1987 else
1988 deps.str[i] = src_dir_path( make, deps.str[i] );
1990 return deps;
1994 /*******************************************************************
1995 * get_static_lib
1997 * Check if makefile builds the named static library and return the full lib path.
1999 static const char *get_static_lib( const struct makefile *make, const char *name )
2001 if (!make->staticlib) return NULL;
2002 if (strncmp( make->staticlib, "lib", 3 )) return NULL;
2003 if (strncmp( make->staticlib + 3, name, strlen(name) )) return NULL;
2004 if (strcmp( make->staticlib + 3 + strlen(name), ".a" )) return NULL;
2005 return base_dir_path( make, make->staticlib );
2009 /*******************************************************************
2010 * add_default_libraries
2012 static struct strarray add_default_libraries( const struct makefile *make, struct strarray *deps )
2014 struct strarray ret = empty_strarray;
2015 struct strarray all_libs = empty_strarray;
2016 unsigned int i, j;
2018 strarray_add( &all_libs, "-lwine_port" );
2019 strarray_addall( &all_libs, get_expanded_make_var_array( make, "EXTRALIBS" ));
2020 strarray_addall( &all_libs, libs );
2022 for (i = 0; i < all_libs.count; i++)
2024 const char *lib = NULL;
2026 if (!strncmp( all_libs.str[i], "-l", 2 ))
2028 const char *name = all_libs.str[i] + 2;
2030 for (j = 0; j < top_makefile->subdirs.count; j++)
2032 const struct makefile *submake = top_makefile->submakes[j];
2034 if ((lib = get_static_lib( submake, name ))) break;
2038 if (lib)
2040 lib = top_obj_dir_path( make, lib );
2041 strarray_add( deps, lib );
2042 strarray_add( &ret, lib );
2044 else strarray_add( &ret, all_libs.str[i] );
2046 return ret;
2050 /*******************************************************************
2051 * add_import_libs
2053 static struct strarray add_import_libs( const struct makefile *make, struct strarray *deps,
2054 struct strarray imports, int cross )
2056 struct strarray ret = empty_strarray;
2057 unsigned int i, j;
2059 for (i = 0; i < imports.count; i++)
2061 const char *name = imports.str[i];
2062 const char *lib = NULL;
2064 for (j = 0; j < top_makefile->subdirs.count; j++)
2066 const struct makefile *submake = top_makefile->submakes[j];
2068 if (submake->importlib && !strcmp( submake->importlib, name ))
2070 if (cross || !*dll_ext || submake->staticimplib)
2071 lib = base_dir_path( submake, strmake( "lib%s.a", name ));
2072 else
2073 strarray_add( deps, top_obj_dir_path( make,
2074 strmake( "%s/lib%s.def", submake->base_dir, name )));
2075 break;
2078 if ((lib = get_static_lib( submake, name ))) break;
2081 if (lib)
2083 if (cross) lib = replace_extension( lib, ".a", ".cross.a" );
2084 lib = top_obj_dir_path( make, lib );
2085 strarray_add( deps, lib );
2086 strarray_add( &ret, lib );
2088 else strarray_add( &ret, strmake( "-l%s", name ));
2090 return ret;
2094 /*******************************************************************
2095 * get_default_imports
2097 static struct strarray get_default_imports( const struct makefile *make )
2099 struct strarray ret = empty_strarray;
2101 if (strarray_exists( &make->extradllflags, "-nodefaultlibs" )) return ret;
2102 if (strarray_exists( &make->appmode, "-mno-cygwin" )) strarray_add( &ret, "msvcrt" );
2103 if (make->is_win16) strarray_add( &ret, "kernel" );
2104 strarray_add( &ret, "kernel32" );
2105 strarray_add( &ret, "ntdll" );
2106 strarray_add( &ret, "winecrt0" );
2107 return ret;
2111 /*******************************************************************
2112 * add_install_rule
2114 static void add_install_rule( struct makefile *make, const char *target,
2115 const char *file, const char *dest )
2117 if (strarray_exists( &make->install_lib, target ))
2119 strarray_add( &make->install_rules[INSTALL_LIB], file );
2120 strarray_add( &make->install_rules[INSTALL_LIB], dest );
2122 else if (strarray_exists( &make->install_dev, target ))
2124 strarray_add( &make->install_rules[INSTALL_DEV], file );
2125 strarray_add( &make->install_rules[INSTALL_DEV], dest );
2130 /*******************************************************************
2131 * get_include_install_path
2133 * Determine the installation path for a given include file.
2135 static const char *get_include_install_path( const char *name )
2137 if (!strncmp( name, "wine/", 5 )) return name + 5;
2138 if (!strncmp( name, "msvcrt/", 7 )) return name;
2139 return strmake( "windows/%s", name );
2143 /*******************************************************************
2144 * get_shared_library_name
2146 * Determine possible names for a shared library with a version number.
2148 static struct strarray get_shared_lib_names( const char *libname )
2150 struct strarray ret = empty_strarray;
2151 const char *ext, *p;
2152 char *name, *first, *second;
2153 size_t len = 0;
2155 strarray_add( &ret, libname );
2157 for (p = libname; (p = strchr( p, '.' )); p++)
2158 if ((len = strspn( p + 1, "0123456789." ))) break;
2160 if (!len) return ret;
2161 ext = p + 1 + len;
2162 if (*ext && ext[-1] == '.') ext--;
2164 /* keep only the first group of digits */
2165 name = xstrdup( libname );
2166 first = name + (p - libname);
2167 if ((second = strchr( first + 1, '.' )))
2169 strcpy( second, ext );
2170 strarray_add( &ret, xstrdup( name ));
2172 /* now remove all digits */
2173 strcpy( first, ext );
2174 strarray_add( &ret, name );
2175 return ret;
2179 /*******************************************************************
2180 * output_symlink_rule
2182 * Output a rule to create a symlink.
2184 static void output_symlink_rule( const char *src_name, const char *link_name )
2186 const char *name;
2188 output( "\trm -f %s && ", link_name );
2190 /* dest path with a directory needs special handling if ln -s isn't supported */
2191 if (strcmp( ln_s, "ln -s" ) && ((name = strrchr( link_name, '/' ))))
2193 char *dir = xstrdup( link_name );
2194 dir[name - link_name] = 0;
2195 output( "cd %s && %s %s %s\n", *dir ? dir : "/", ln_s, src_name, name + 1 );
2196 free( dir );
2198 else
2200 output( "%s %s %s\n", ln_s, src_name, link_name );
2205 /*******************************************************************
2206 * output_install_commands
2208 static void output_install_commands( struct makefile *make, const struct makefile *submake,
2209 struct strarray files )
2211 unsigned int i;
2212 char *install_sh = top_src_dir_path( make, "tools/install-sh" );
2214 for (i = 0; i < files.count; i += 2)
2216 const char *file = files.str[i];
2217 const char *dest = strmake( "$(DESTDIR)%s", files.str[i + 1] + 1 );
2219 if (submake) file = base_dir_path( submake, file );
2220 switch (*files.str[i + 1])
2222 case 'd': /* data file */
2223 output( "\t%s -m 644 $(INSTALL_DATA_FLAGS) %s %s\n",
2224 install_sh, obj_dir_path( make, file ), dest );
2225 break;
2226 case 'D': /* data file in source dir */
2227 output( "\t%s -m 644 $(INSTALL_DATA_FLAGS) %s %s\n",
2228 install_sh, src_dir_path( make, file ), dest );
2229 break;
2230 case 'p': /* program file */
2231 output( "\tSTRIPPROG=\"$(STRIP)\" %s $(INSTALL_PROGRAM_FLAGS) %s %s\n",
2232 install_sh, obj_dir_path( make, file ), dest );
2233 break;
2234 case 's': /* script */
2235 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s %s\n",
2236 install_sh, obj_dir_path( make, file ), dest );
2237 break;
2238 case 'S': /* script in source dir */
2239 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s %s\n",
2240 install_sh, src_dir_path( make, file ), dest );
2241 break;
2242 case 't': /* script in tools dir */
2243 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s %s\n",
2244 install_sh, tools_dir_path( make, files.str[i] ), dest );
2245 break;
2246 case 'y': /* symlink */
2247 output_symlink_rule( files.str[i], dest );
2248 break;
2249 default:
2250 assert(0);
2252 strarray_add( &make->uninstall_files, dest );
2257 /*******************************************************************
2258 * output_install_rules
2260 * Rules are stored as a (file,dest) pair of values.
2261 * The first char of dest indicates the type of install.
2263 static void output_install_rules( struct makefile *make, enum install_rules rules, const char *target )
2265 unsigned int i;
2266 struct strarray files = make->install_rules[rules];
2267 struct strarray targets = empty_strarray;
2269 if (!files.count) return;
2271 for (i = 0; i < files.count; i += 2)
2273 const char *file = files.str[i];
2274 switch (*files.str[i + 1])
2276 case 'd': /* data file */
2277 case 'p': /* program file */
2278 case 's': /* script */
2279 strarray_add_uniq( &targets, obj_dir_path( make, file ));
2280 break;
2281 case 't': /* script in tools dir */
2282 strarray_add_uniq( &targets, tools_dir_path( make, file ));
2283 break;
2287 output( "install %s::", target );
2288 output_filenames( targets );
2289 output( "\n" );
2290 output_install_commands( make, NULL, files );
2292 strarray_add_uniq( &make->phony_targets, "install" );
2293 strarray_add_uniq( &make->phony_targets, target );
2297 static int cmp_string_length( const char **a, const char **b )
2299 int paths_a = 0, paths_b = 0;
2300 const char *p;
2302 for (p = *a; *p; p++) if (*p == '/') paths_a++;
2303 for (p = *b; *p; p++) if (*p == '/') paths_b++;
2304 if (paths_b != paths_a) return paths_b - paths_a;
2305 return strcmp( *a, *b );
2308 /*******************************************************************
2309 * output_uninstall_rules
2311 static void output_uninstall_rules( struct makefile *make )
2313 static const char *dirs_order[] =
2314 { "$(includedir)", "$(mandir)", "$(fontdir)", "$(datadir)", "$(dlldir)" };
2316 struct strarray subdirs = empty_strarray;
2317 unsigned int i, j;
2319 if (!make->uninstall_files.count) return;
2320 output( "uninstall::\n" );
2321 output_rm_filenames( make->uninstall_files );
2322 strarray_add_uniq( &make->phony_targets, "uninstall" );
2324 if (!make->subdirs.count) return;
2325 for (i = 0; i < make->uninstall_files.count; i++)
2327 char *dir = xstrdup( make->uninstall_files.str[i] );
2328 while (strchr( dir, '/' ))
2330 *strrchr( dir, '/' ) = 0;
2331 strarray_add_uniq( &subdirs, xstrdup(dir) );
2334 strarray_qsort( &subdirs, cmp_string_length );
2335 output( "\t-rmdir" );
2336 for (i = 0; i < sizeof(dirs_order)/sizeof(dirs_order[0]); i++)
2338 for (j = 0; j < subdirs.count; j++)
2340 if (!subdirs.str[j]) continue;
2341 if (strncmp( subdirs.str[j] + strlen("$(DESTDIR)"), dirs_order[i], strlen(dirs_order[i]) ))
2342 continue;
2343 output_filename( subdirs.str[j] );
2344 subdirs.str[j] = NULL;
2347 for (j = 0; j < subdirs.count; j++)
2348 if (subdirs.str[j]) output_filename( subdirs.str[j] );
2349 output( "\n" );
2353 /*******************************************************************
2354 * output_importlib_symlinks
2356 static struct strarray output_importlib_symlinks( const struct makefile *parent,
2357 const struct makefile *make )
2359 struct strarray ret = empty_strarray;
2360 const char *lib, *dst;
2362 if (!make->module) return ret;
2363 if (!make->importlib) return ret;
2364 if (make->is_win16 && make->disabled) return ret;
2365 if (strncmp( make->base_dir, "dlls/", 5 )) return ret;
2366 if (!strcmp( make->module, make->importlib )) return ret;
2367 if (!strchr( make->importlib, '.' ) &&
2368 !strncmp( make->module, make->importlib, strlen( make->importlib )) &&
2369 !strcmp( make->module + strlen( make->importlib ), ".dll" ))
2370 return ret;
2372 lib = strmake( "lib%s.%s", make->importlib, *dll_ext ? "def" : "a" );
2373 dst = concat_paths( obj_dir_path( parent, "dlls" ), lib );
2374 output( "%s: %s\n", dst, base_dir_path( make, lib ));
2375 output_symlink_rule( concat_paths( make->base_dir + strlen("dlls/"), lib ), dst );
2376 strarray_add( &ret, dst );
2378 if (crosstarget && !make->is_win16)
2380 lib = strmake( "lib%s.cross.a", make->importlib );
2381 dst = concat_paths( obj_dir_path( parent, "dlls" ), lib );
2382 output( "%s: %s\n", dst, base_dir_path( make, lib ));
2383 output_symlink_rule( concat_paths( make->base_dir + strlen("dlls/"), lib ), dst );
2384 strarray_add( &ret, dst );
2386 return ret;
2390 /*******************************************************************
2391 * output_po_files
2393 static void output_po_files( const struct makefile *make )
2395 const char *po_dir = src_dir_path( make, "po" );
2396 struct strarray pot_files = empty_strarray;
2397 struct incl_file *source;
2398 unsigned int i;
2400 for (i = 0; i < make->subdirs.count; i++)
2402 struct makefile *submake = make->submakes[i];
2404 LIST_FOR_EACH_ENTRY( source, &submake->sources, struct incl_file, entry )
2406 if (strendswith( source->name, ".rc" ) && (source->file->flags & FLAG_RC_PO))
2408 char *pot_file = replace_extension( source->name, ".rc", ".pot" );
2409 char *pot_path = base_dir_path( submake, pot_file );
2410 output( "%s: tools/wrc include dummy\n", pot_path );
2411 output( "\t@cd %s && $(MAKE) %s\n", base_dir_path( submake, "" ), pot_file );
2412 strarray_add( &pot_files, pot_path );
2414 else if (strendswith( source->name, ".mc" ))
2416 char *pot_file = replace_extension( source->name, ".mc", ".pot" );
2417 char *pot_path = base_dir_path( submake, pot_file );
2418 output( "%s: tools/wmc include dummy\n", pot_path );
2419 output( "\t@cd %s && $(MAKE) %s\n", base_dir_path( submake, "" ), pot_file );
2420 strarray_add( &pot_files, pot_path );
2424 if (linguas.count)
2426 for (i = 0; i < linguas.count; i++)
2427 output_filename( strmake( "%s/%s.po", po_dir, linguas.str[i] ));
2428 output( ": %s/wine.pot\n", po_dir );
2429 output( "\tmsgmerge --previous -q $@ %s/wine.pot | msgattrib --no-obsolete -o $@.new && mv $@.new $@\n",
2430 po_dir );
2431 output( "po:" );
2432 for (i = 0; i < linguas.count; i++)
2433 output_filename( strmake( "%s/%s.po", po_dir, linguas.str[i] ));
2434 output( "\n" );
2436 output( "%s/wine.pot:", po_dir );
2437 output_filenames( pot_files );
2438 output( "\n" );
2439 output( "\tmsgcat -o $@" );
2440 output_filenames( pot_files );
2441 output( "\n" );
2445 /*******************************************************************
2446 * output_source_y
2448 static void output_source_y( struct makefile *make, struct incl_file *source, const char *obj )
2450 /* add source file dependency for parallel makes */
2451 char *header = strmake( "%s.tab.h", obj );
2453 if (find_include_file( make, header ))
2455 output( "%s: %s\n", obj_dir_path( make, header ), source->filename );
2456 output( "\t$(BISON) -p %s_ -o %s.tab.c -d %s\n",
2457 obj, obj_dir_path( make, obj ), source->filename );
2458 output( "%s.tab.c: %s %s\n", obj_dir_path( make, obj ),
2459 source->filename, obj_dir_path( make, header ));
2460 strarray_add( &make->clean_files, header );
2462 else output( "%s.tab.c: %s\n", obj, source->filename );
2464 output( "\t$(BISON) -p %s_ -o $@ %s\n", obj, source->filename );
2468 /*******************************************************************
2469 * output_source_l
2471 static void output_source_l( struct makefile *make, struct incl_file *source, const char *obj )
2473 output( "%s.yy.c: %s\n", obj_dir_path( make, obj ), source->filename );
2474 output( "\t$(FLEX) -o$@ %s\n", source->filename );
2478 /*******************************************************************
2479 * output_source_h
2481 static void output_source_h( struct makefile *make, struct incl_file *source, const char *obj )
2483 if (source->file->flags & FLAG_GENERATED)
2485 strarray_add( &make->all_targets, source->name );
2487 else
2489 strarray_add( &make->install_rules[INSTALL_DEV], source->name );
2490 strarray_add( &make->install_rules[INSTALL_DEV],
2491 strmake( "D$(includedir)/wine/%s", get_include_install_path( source->name ) ));
2496 /*******************************************************************
2497 * output_source_rc
2499 static void output_source_rc( struct makefile *make, struct incl_file *source, const char *obj )
2501 struct strarray extradefs = get_expanded_file_local_var( make, obj, "EXTRADEFS" );
2502 unsigned int i;
2504 strarray_add( &make->object_files, strmake( "%s.res", obj ));
2505 if (crosstarget) strarray_add( &make->crossobj_files, strmake( "%s.res", obj ));
2506 output( "%s.res: %s\n", obj_dir_path( make, obj ), source->filename );
2507 output( "\t%s -o $@", tools_path( make, "wrc" ) );
2508 if (make->is_win16) output_filename( "-m16" );
2509 else output_filenames( target_flags );
2510 output_filename( "--nostdinc" );
2511 output_filenames( make->include_args );
2512 output_filenames( make->define_args );
2513 output_filenames( extradefs );
2514 if (linguas.count && (source->file->flags & FLAG_RC_PO))
2516 char *po_dir = top_obj_dir_path( make, "po" );
2517 output_filename( strmake( "--po-dir=%s", po_dir ));
2518 output_filename( source->filename );
2519 output( "\n" );
2520 output( "%s.res:", obj_dir_path( make, obj ));
2521 for (i = 0; i < linguas.count; i++)
2522 output_filename( strmake( "%s/%s.mo", po_dir, linguas.str[i] ));
2523 output( "\n" );
2525 else
2527 output_filename( source->filename );
2528 output( "\n" );
2530 if (source->file->flags & FLAG_RC_PO)
2532 strarray_add( &make->clean_files, strmake( "%s.pot", obj ));
2533 output( "%s.pot: %s\n", obj_dir_path( make, obj ), source->filename );
2534 output( "\t%s -O pot -o $@", tools_path( make, "wrc" ) );
2535 if (make->is_win16) output_filename( "-m16" );
2536 else output_filenames( target_flags );
2537 output_filename( "--nostdinc" );
2538 output_filenames( make->include_args );
2539 output_filenames( make->define_args );
2540 output_filenames( extradefs );
2541 output_filename( source->filename );
2542 output( "\n" );
2543 output( "%s.pot ", obj_dir_path( make, obj ));
2545 output( "%s.res:", obj_dir_path( make, obj ));
2546 output_filename( tools_path( make, "wrc" ));
2547 output_filenames( source->dependencies );
2548 output( "\n" );
2552 /*******************************************************************
2553 * output_source_mc
2555 static void output_source_mc( struct makefile *make, struct incl_file *source, const char *obj )
2557 unsigned int i;
2559 strarray_add( &make->object_files, strmake( "%s.res", obj ));
2560 if (crosstarget) strarray_add( &make->crossobj_files, strmake( "%s.res", obj ));
2561 strarray_add( &make->clean_files, strmake( "%s.pot", obj ));
2562 output( "%s.res: %s\n", obj_dir_path( make, obj ), source->filename );
2563 output( "\t%s -U -O res -o $@ %s", tools_path( make, "wmc" ), source->filename );
2564 if (linguas.count)
2566 char *po_dir = top_obj_dir_path( make, "po" );
2567 output_filename( strmake( "--po-dir=%s", po_dir ));
2568 output( "\n" );
2569 output( "%s.res:", obj_dir_path( make, obj ));
2570 for (i = 0; i < linguas.count; i++)
2571 output_filename( strmake( "%s/%s.mo", po_dir, linguas.str[i] ));
2573 output( "\n" );
2574 output( "%s.pot: %s\n", obj_dir_path( make, obj ), source->filename );
2575 output( "\t%s -O pot -o $@ %s", tools_path( make, "wmc" ), source->filename );
2576 output( "\n" );
2577 output( "%s.pot %s.res:", obj_dir_path( make, obj ), obj_dir_path( make, obj ));
2578 output_filename( tools_path( make, "wmc" ));
2579 output_filenames( source->dependencies );
2580 output( "\n" );
2584 /*******************************************************************
2585 * output_source_res
2587 static void output_source_res( struct makefile *make, struct incl_file *source, const char *obj )
2589 strarray_add( &make->object_files, source->name );
2590 if (crosstarget) strarray_add( &make->crossobj_files, source->name );
2594 /*******************************************************************
2595 * output_source_idl
2597 static void output_source_idl( struct makefile *make, struct incl_file *source, const char *obj )
2599 struct strarray extradefs = get_expanded_file_local_var( make, obj, "EXTRADEFS" );
2600 struct strarray targets = empty_strarray;
2601 char *dest;
2602 unsigned int i;
2604 if (!source->file->flags) source->file->flags |= FLAG_IDL_HEADER | FLAG_INSTALL;
2605 if (find_include_file( make, strmake( "%s.h", obj ))) source->file->flags |= FLAG_IDL_HEADER;
2607 for (i = 0; i < sizeof(idl_outputs) / sizeof(idl_outputs[0]); i++)
2609 if (!(source->file->flags & idl_outputs[i].flag)) continue;
2610 dest = strmake( "%s%s", obj, idl_outputs[i].ext );
2611 if (!find_src_file( make, dest )) strarray_add( &make->clean_files, dest );
2612 strarray_add( &targets, dest );
2614 if (source->file->flags & FLAG_IDL_PROXY) strarray_add( &make->dlldata_files, source->name );
2615 if (source->file->flags & FLAG_INSTALL)
2617 strarray_add( &make->install_rules[INSTALL_DEV], xstrdup( source->name ));
2618 strarray_add( &make->install_rules[INSTALL_DEV],
2619 strmake( "D$(includedir)/wine/%s.idl", get_include_install_path( obj ) ));
2620 if (source->file->flags & FLAG_IDL_HEADER)
2622 strarray_add( &make->install_rules[INSTALL_DEV], strmake( "%s.h", obj ));
2623 strarray_add( &make->install_rules[INSTALL_DEV],
2624 strmake( "d$(includedir)/wine/%s.h", get_include_install_path( obj ) ));
2627 if (!targets.count) return;
2629 output_filenames_obj_dir( make, targets );
2630 output( ": %s\n", tools_path( make, "widl" ));
2631 output( "\t%s -o $@", tools_path( make, "widl" ) );
2632 output_filenames( target_flags );
2633 output_filenames( make->include_args );
2634 output_filenames( make->define_args );
2635 output_filenames( extradefs );
2636 output_filenames( get_expanded_make_var_array( make, "EXTRAIDLFLAGS" ));
2637 output_filename( source->filename );
2638 output( "\n" );
2639 output_filenames_obj_dir( make, targets );
2640 output( ": %s", source->filename );
2641 output_filenames( source->dependencies );
2642 output( "\n" );
2646 /*******************************************************************
2647 * output_source_tlb
2649 static void output_source_tlb( struct makefile *make, struct incl_file *source, const char *obj )
2651 strarray_add( &make->all_targets, source->name );
2655 /*******************************************************************
2656 * output_source_x
2658 static void output_source_x( struct makefile *make, struct incl_file *source, const char *obj )
2660 output( "%s.h: %s%s %s\n", obj_dir_path( make, obj ),
2661 tools_dir_path( make, "make_xftmpl" ), tools_ext, source->filename );
2662 output( "\t%s%s -H -o $@ %s\n",
2663 tools_dir_path( make, "make_xftmpl" ), tools_ext, source->filename );
2664 if (source->file->flags & FLAG_INSTALL)
2666 strarray_add( &make->install_rules[INSTALL_DEV], source->name );
2667 strarray_add( &make->install_rules[INSTALL_DEV],
2668 strmake( "D$(includedir)/wine/%s", get_include_install_path( source->name ) ));
2669 strarray_add( &make->install_rules[INSTALL_DEV], strmake( "%s.h", obj ));
2670 strarray_add( &make->install_rules[INSTALL_DEV],
2671 strmake( "d$(includedir)/wine/%s.h", get_include_install_path( obj ) ));
2676 /*******************************************************************
2677 * output_source_sfd
2679 static void output_source_sfd( struct makefile *make, struct incl_file *source, const char *obj )
2681 unsigned int i;
2682 char *ttf_file = src_dir_path( make, strmake( "%s.ttf", obj ));
2684 if (fontforge && !make->src_dir)
2686 output( "%s: %s\n", ttf_file, source->filename );
2687 output( "\t%s -script %s %s $@\n",
2688 fontforge, top_src_dir_path( make, "fonts/genttf.ff" ), source->filename );
2689 if (!(source->file->flags & FLAG_SFD_FONTS)) output( "all: %s\n", ttf_file );
2691 if (source->file->flags & FLAG_INSTALL)
2693 strarray_add( &make->install_rules[INSTALL_LIB], strmake( "%s.ttf", obj ));
2694 strarray_add( &make->install_rules[INSTALL_LIB], strmake( "D$(fontdir)/%s.ttf", obj ));
2696 if (source->file->flags & FLAG_SFD_FONTS)
2698 struct strarray *array = source->file->args;
2700 for (i = 0; i < array->count; i++)
2702 char *font = strtok( xstrdup(array->str[i]), " \t" );
2703 char *args = strtok( NULL, "" );
2705 strarray_add( &make->all_targets, xstrdup( font ));
2706 output( "%s: %s %s\n", obj_dir_path( make, font ),
2707 tools_path( make, "sfnt2fon" ), ttf_file );
2708 output( "\t%s -o $@ %s %s\n", tools_path( make, "sfnt2fon" ), ttf_file, args );
2709 strarray_add( &make->install_rules[INSTALL_LIB], xstrdup(font) );
2710 strarray_add( &make->install_rules[INSTALL_LIB], strmake( "d$(fontdir)/%s", font ));
2716 /*******************************************************************
2717 * output_source_svg
2719 static void output_source_svg( struct makefile *make, struct incl_file *source, const char *obj )
2721 static const char * const images[] = { "bmp", "cur", "ico", NULL };
2722 unsigned int i;
2724 if (convert && rsvg && icotool && !make->src_dir)
2726 for (i = 0; images[i]; i++)
2727 if (find_include_file( make, strmake( "%s.%s", obj, images[i] ))) break;
2729 if (images[i])
2731 output( "%s.%s: %s\n", src_dir_path( make, obj ), images[i], source->filename );
2732 output( "\tCONVERT=\"%s\" ICOTOOL=\"%s\" RSVG=\"%s\" %s %s $@\n", convert, icotool, rsvg,
2733 top_src_dir_path( make, "tools/buildimage" ), source->filename );
2739 /*******************************************************************
2740 * output_source_nls
2742 static void output_source_nls( struct makefile *make, struct incl_file *source, const char *obj )
2744 add_install_rule( make, source->name, source->name,
2745 strmake( "D$(datadir)/wine/%s", source->name ));
2749 /*******************************************************************
2750 * output_source_desktop
2752 static void output_source_desktop( struct makefile *make, struct incl_file *source, const char *obj )
2754 add_install_rule( make, source->name, source->name,
2755 strmake( "D$(datadir)/applications/%s", source->name ));
2759 /*******************************************************************
2760 * output_source_po
2762 static void output_source_po( struct makefile *make, struct incl_file *source, const char *obj )
2764 output( "%s.mo: %s\n", obj_dir_path( make, obj ), source->filename );
2765 output( "\t%s -o $@ %s\n", msgfmt, source->filename );
2766 strarray_add( &make->all_targets, strmake( "%s.mo", obj ));
2770 /*******************************************************************
2771 * output_source_in
2773 static void output_source_in( struct makefile *make, struct incl_file *source, const char *obj )
2775 unsigned int i;
2777 if (strendswith( obj, ".man" ) && source->file->args)
2779 struct strarray symlinks;
2780 char *dir, *dest = replace_extension( obj, ".man", "" );
2781 char *lang = strchr( dest, '.' );
2782 char *section = source->file->args;
2783 if (lang)
2785 *lang++ = 0;
2786 dir = strmake( "$(mandir)/%s/man%s", lang, section );
2788 else dir = strmake( "$(mandir)/man%s", section );
2789 add_install_rule( make, dest, xstrdup(obj), strmake( "d%s/%s.%s", dir, dest, section ));
2790 symlinks = get_expanded_file_local_var( make, dest, "SYMLINKS" );
2791 for (i = 0; i < symlinks.count; i++)
2792 add_install_rule( make, symlinks.str[i], strmake( "%s.%s", dest, section ),
2793 strmake( "y%s/%s.%s", dir, symlinks.str[i], section ));
2794 free( dest );
2795 free( dir );
2797 strarray_add( &make->in_files, xstrdup(obj) );
2798 strarray_add( &make->all_targets, xstrdup(obj) );
2799 output( "%s: %s\n", obj_dir_path( make, obj ), source->filename );
2800 output( "\t$(SED_CMD) %s >$@ || (rm -f $@ && false)\n", source->filename );
2801 output( "%s:", obj_dir_path( make, obj ));
2802 output_filenames( source->dependencies );
2803 output( "\n" );
2804 add_install_rule( make, obj, xstrdup( obj ), strmake( "d$(datadir)/wine/%s", obj ));
2808 /*******************************************************************
2809 * output_source_spec
2811 static void output_source_spec( struct makefile *make, struct incl_file *source, const char *obj )
2813 struct strarray imports = get_expanded_file_local_var( make, obj, "IMPORTS" );
2814 struct strarray all_libs, dep_libs = empty_strarray;
2816 if (!imports.count) imports = make->imports;
2817 all_libs = add_import_libs( make, &dep_libs, imports, 0 );
2818 add_import_libs( make, &dep_libs, get_default_imports( make ), 0 ); /* dependencies only */
2819 strarray_addall( &all_libs, libs );
2821 strarray_add( &make->clean_files, strmake( "%s.dll%s", obj, dll_ext ));
2822 strarray_add( &make->object_files, strmake( "%s.res", obj ));
2823 output( "%s.res: %s.dll%s\n", obj_dir_path( make, obj ), obj_dir_path( make, obj ), dll_ext );
2824 output( "\techo \"%s.dll TESTDLL \\\"%s.dll%s\\\"\" | %s -o $@\n", obj,
2825 obj_dir_path( make, obj ), dll_ext, tools_path( make, "wrc" ));
2827 output( "%s.dll%s:", obj_dir_path( make, obj ), dll_ext );
2828 output_filename( source->filename );
2829 output_filename( strmake( "%s.o", obj_dir_path( make, obj )));
2830 output_filenames( dep_libs );
2831 output_filename( tools_path( make, "winebuild" ));
2832 output_filename( tools_path( make, "winegcc" ));
2833 output( "\n" );
2834 output( "\t%s -s -o $@", tools_path( make, "winegcc" ));
2835 output_filename( strmake( "-B%s", tools_dir_path( make, "winebuild" )));
2836 if (tools_dir) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make, "" )));
2837 output_filenames( target_flags );
2838 output_filenames( unwind_flags );
2839 output_filenames( make->extradllflags );
2840 output_filename( "-shared" );
2841 output_filename( source->filename );
2842 output_filename( strmake( "%s.o", obj_dir_path( make, obj )));
2843 output_filenames( all_libs );
2844 output_filename( "$(LDFLAGS)" );
2845 output( "\n" );
2847 if (crosstarget)
2849 dep_libs = empty_strarray;
2850 all_libs = add_import_libs( make, &dep_libs, imports, 1 );
2851 add_import_libs( make, &dep_libs, get_default_imports( make ), 1 ); /* dependencies only */
2852 strarray_addall( &all_libs, libs );
2854 strarray_add( &make->clean_files, strmake( "%s.dll", obj ));
2855 strarray_add( &make->crossobj_files, strmake( "%s.cross.res", obj ));
2856 output( "%s.cross.res: %s.dll\n", obj_dir_path( make, obj ), obj_dir_path( make, obj ) );
2857 output( "\techo \"%s.dll TESTDLL \\\"%s.dll\\\"\" | %s -o $@\n", obj,
2858 obj_dir_path( make, obj ), tools_path( make, "wrc" ));
2860 output( "%s.dll:", obj_dir_path( make, obj ));
2861 output_filename( source->filename );
2862 output_filename( strmake( "%s.cross.o", obj_dir_path( make, obj )));
2863 output_filenames( dep_libs );
2864 output_filename( tools_path( make, "winebuild" ));
2865 output_filename( tools_path( make, "winegcc" ));
2866 output( "\n" );
2867 output( "\t%s -s -o $@ -b %s", tools_path( make, "winegcc" ), crosstarget );
2868 output_filename( strmake( "-B%s", tools_dir_path( make, "winebuild" )));
2869 if (tools_dir) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make, "" )));
2870 output_filename( "--lib-suffix=.cross.a" );
2871 output_filename( "-shared" );
2872 output_filename( source->filename );
2873 output_filename( strmake( "%s.cross.o", obj_dir_path( make, obj )));
2874 output_filenames( all_libs );
2875 output_filename( "$(LDFLAGS)" );
2876 output( "\n" );
2881 /*******************************************************************
2882 * output_source_default
2884 static void output_source_default( struct makefile *make, struct incl_file *source, const char *obj )
2886 struct strarray extradefs = get_expanded_file_local_var( make, obj, "EXTRADEFS" );
2887 int is_dll_src = (make->testdll &&
2888 strendswith( source->name, ".c" ) &&
2889 find_src_file( make, replace_extension( source->name, ".c", ".spec" )));
2890 int need_cross = (make->testdll ||
2891 (source->file->flags & FLAG_C_IMPLIB) ||
2892 (make->module && make->staticlib));
2894 if ((source->file->flags & FLAG_GENERATED) &&
2895 (!make->testdll || !strendswith( source->filename, "testlist.c" )))
2896 strarray_add( &make->clean_files, source->filename );
2897 if (source->file->flags & FLAG_C_IMPLIB) strarray_add( &make->implib_objs, strmake( "%s.o", obj ));
2898 strarray_add( is_dll_src ? &make->clean_files : &make->object_files, strmake( "%s.o", obj ));
2899 output( "%s.o: %s\n", obj_dir_path( make, obj ), source->filename );
2900 output( "\t$(CC) -c -o $@ %s", source->filename );
2901 output_filenames( make->include_args );
2902 output_filenames( make->define_args );
2903 output_filenames( extradefs );
2904 if (make->module || make->staticlib || make->sharedlib || make->testdll)
2906 output_filenames( dll_flags );
2907 if (make->use_msvcrt) output_filenames( msvcrt_flags );
2909 output_filenames( extra_cflags );
2910 output_filenames( cpp_flags );
2911 output_filename( "$(CFLAGS)" );
2912 output( "\n" );
2913 if (crosstarget && need_cross)
2915 strarray_add( is_dll_src ? &make->clean_files : &make->crossobj_files, strmake( "%s.cross.o", obj ));
2916 output( "%s.cross.o: %s\n", obj_dir_path( make, obj ), source->filename );
2917 output( "\t$(CROSSCC) -c -o $@ %s", source->filename );
2918 output_filenames( make->include_args );
2919 output_filenames( make->define_args );
2920 output_filenames( extradefs );
2921 if (make->use_msvcrt) output_filenames( msvcrt_flags );
2922 output_filename( "-DWINE_CROSSTEST" );
2923 output_filenames( cpp_flags );
2924 output_filename( "$(CROSSCFLAGS)" );
2925 output( "\n" );
2927 if (strendswith( source->name, ".c" ) && !(source->file->flags & FLAG_GENERATED))
2929 strarray_add( &make->c2man_files, source->filename );
2930 if (make->testdll && !is_dll_src)
2932 strarray_add( &make->ok_files, strmake( "%s.ok", obj ));
2933 output( "%s.ok:\n", obj_dir_path( make, obj ));
2934 output( "\t%s $(RUNTESTFLAGS) -T %s -M %s -p %s%s %s && touch $@\n",
2935 top_src_dir_path( make, "tools/runtest" ), top_obj_dir_path( make, "" ),
2936 make->testdll, replace_extension( make->testdll, ".dll", "_test.exe" ),
2937 dll_ext, obj );
2940 output( "%s.o", obj_dir_path( make, obj ));
2941 if (crosstarget && need_cross) output( " %s.cross.o", obj_dir_path( make, obj ));
2942 output( ":" );
2943 output_filenames( source->dependencies );
2944 output( "\n" );
2948 /* dispatch table to output rules for a single source file */
2949 static const struct
2951 const char *ext;
2952 void (*fn)( struct makefile *make, struct incl_file *source, const char *obj );
2953 } output_source_funcs[] =
2955 { "y", output_source_y },
2956 { "l", output_source_l },
2957 { "h", output_source_h },
2958 { "rh", output_source_h },
2959 { "inl", output_source_h },
2960 { "rc", output_source_rc },
2961 { "mc", output_source_mc },
2962 { "res", output_source_res },
2963 { "idl", output_source_idl },
2964 { "tlb", output_source_tlb },
2965 { "sfd", output_source_sfd },
2966 { "svg", output_source_svg },
2967 { "nls", output_source_nls },
2968 { "desktop", output_source_desktop },
2969 { "po", output_source_po },
2970 { "in", output_source_in },
2971 { "x", output_source_x },
2972 { "spec", output_source_spec },
2973 { NULL, output_source_default }
2977 /*******************************************************************
2978 * output_man_pages
2980 static void output_man_pages( struct makefile *make )
2982 if (make->c2man_files.count)
2984 char *spec_file = src_dir_path( make, replace_extension( make->module, ".dll", ".spec" ));
2986 output( "manpages::\n" );
2987 output( "\t%s -w %s", top_src_dir_path( make, "tools/c2man.pl" ), spec_file );
2988 output_filename( strmake( "-R%s", top_src_dir_path( make, "" )));
2989 output_filename( strmake( "-I%s", top_src_dir_path( make, "include" )));
2990 output_filename( strmake( "-o %s/man%s",
2991 top_obj_dir_path( make, "documentation" ), man_ext ));
2992 output_filenames( make->c2man_files );
2993 output( "\n" );
2994 output( "htmlpages::\n" );
2995 output( "\t%s -Th -w %s", top_src_dir_path( make, "tools/c2man.pl" ), spec_file );
2996 output_filename( strmake( "-R%s", top_src_dir_path( make, "" )));
2997 output_filename( strmake( "-I%s", top_src_dir_path( make, "include" )));
2998 output_filename( strmake( "-o %s",
2999 top_obj_dir_path( make, "documentation/html" )));
3000 output_filenames( make->c2man_files );
3001 output( "\n" );
3002 output( "sgmlpages::\n" );
3003 output( "\t%s -Ts -w %s", top_src_dir_path( make, "tools/c2man.pl" ), spec_file );
3004 output_filename( strmake( "-R%s", top_src_dir_path( make, "" )));
3005 output_filename( strmake( "-I%s", top_src_dir_path( make, "include" )));
3006 output_filename( strmake( "-o %s",
3007 top_obj_dir_path( make, "documentation/api-guide" )));
3008 output_filenames( make->c2man_files );
3009 output( "\n" );
3010 output( "xmlpages::\n" );
3011 output( "\t%s -Tx -w %s", top_src_dir_path( make, "tools/c2man.pl" ), spec_file );
3012 output_filename( strmake( "-R%s", top_src_dir_path( make, "" )));
3013 output_filename( strmake( "-I%s", top_src_dir_path( make, "include" )));
3014 output_filename( strmake( "-o %s",
3015 top_obj_dir_path( make, "documentation/api-guide-xml" )));
3016 output_filenames( make->c2man_files );
3017 output( "\n" );
3018 strarray_add( &make->phony_targets, "manpages" );
3019 strarray_add( &make->phony_targets, "htmlpages" );
3020 strarray_add( &make->phony_targets, "sgmlpages" );
3021 strarray_add( &make->phony_targets, "xmlpages" );
3023 else output( "manpages htmlpages sgmlpages xmlpages::\n" );
3027 /*******************************************************************
3028 * output_module
3030 static void output_module( struct makefile *make )
3032 struct strarray all_libs = empty_strarray;
3033 struct strarray dep_libs = empty_strarray;
3034 char *module_path = obj_dir_path( make, make->module );
3035 char *spec_file = NULL;
3036 unsigned int i;
3038 if (!make->appmode.count)
3039 spec_file = src_dir_path( make, replace_extension( make->module, ".dll", ".spec" ));
3040 strarray_addall( &all_libs, add_import_libs( make, &dep_libs, make->delayimports, 0 ));
3041 strarray_addall( &all_libs, add_import_libs( make, &dep_libs, make->imports, 0 ));
3042 add_import_libs( make, &dep_libs, get_default_imports( make ), 0 ); /* dependencies only */
3043 strarray_addall( &all_libs, add_default_libraries( make, &dep_libs ));
3045 if (*dll_ext)
3047 for (i = 0; i < make->delayimports.count; i++)
3048 strarray_add( &all_libs, strmake( "-Wb,-d%s", make->delayimports.str[i] ));
3049 strarray_add( &make->all_targets, strmake( "%s%s", make->module, dll_ext ));
3050 strarray_add( &make->all_targets, strmake( "%s.fake", make->module ));
3051 add_install_rule( make, make->module, strmake( "%s%s", make->module, dll_ext ),
3052 strmake( "p$(dlldir)/%s%s", make->module, dll_ext ));
3053 add_install_rule( make, make->module, strmake( "%s.fake", make->module ),
3054 strmake( "d$(dlldir)/fakedlls/%s", make->module ));
3055 output( "%s%s %s.fake:", module_path, dll_ext, module_path );
3057 else
3059 strarray_add( &all_libs, "-lwine" );
3060 strarray_add( &make->all_targets, make->module );
3061 add_install_rule( make, make->module, make->module,
3062 strmake( "p$(%s)/%s", spec_file ? "dlldir" : "bindir", make->module ));
3063 output( "%s:", module_path );
3065 if (spec_file) output_filename( spec_file );
3066 output_filenames_obj_dir( make, make->object_files );
3067 output_filenames( dep_libs );
3068 output_filename( tools_path( make, "winebuild" ));
3069 output_filename( tools_path( make, "winegcc" ));
3070 output( "\n" );
3071 output( "\t%s -o $@", tools_path( make, "winegcc" ));
3072 output_filename( strmake( "-B%s", tools_dir_path( make, "winebuild" )));
3073 if (tools_dir) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make, "" )));
3074 output_filenames( target_flags );
3075 output_filenames( unwind_flags );
3076 if (spec_file)
3078 output( " -shared %s", spec_file );
3079 output_filenames( make->extradllflags );
3081 else output_filenames( make->appmode );
3082 output_filenames_obj_dir( make, make->object_files );
3083 output_filenames( all_libs );
3084 output_filename( "$(LDFLAGS)" );
3085 output( "\n" );
3087 if (spec_file && make->importlib)
3089 char *importlib_path = obj_dir_path( make, strmake( "lib%s", make->importlib ));
3090 if (*dll_ext && !make->implib_objs.count)
3092 strarray_add( &make->clean_files, strmake( "lib%s.def", make->importlib ));
3093 output( "%s.def: %s %s\n", importlib_path, tools_path( make, "winebuild" ), spec_file );
3094 output( "\t%s -w --def -o $@ --export %s", tools_path( make, "winebuild" ), spec_file );
3095 output_filenames( target_flags );
3096 if (make->is_win16) output_filename( "-m16" );
3097 output( "\n" );
3098 add_install_rule( make, make->importlib,
3099 strmake( "lib%s.def", make->importlib ),
3100 strmake( "d$(dlldir)/lib%s.def", make->importlib ));
3102 else
3104 strarray_add( &make->clean_files, strmake( "lib%s.a", make->importlib ));
3105 output( "%s.a: %s %s", importlib_path, tools_path( make, "winebuild" ), spec_file );
3106 output_filenames_obj_dir( make, make->implib_objs );
3107 output( "\n" );
3108 output( "\t%s -w --implib -o $@ --export %s", tools_path( make, "winebuild" ), spec_file );
3109 output_filenames( target_flags );
3110 output_filenames_obj_dir( make, make->implib_objs );
3111 output( "\n" );
3112 add_install_rule( make, make->importlib,
3113 strmake( "lib%s.a", make->importlib ),
3114 strmake( "d$(dlldir)/lib%s.a", make->importlib ));
3116 if (crosstarget && !make->is_win16)
3118 struct strarray cross_files = strarray_replace_extension( &make->implib_objs, ".o", ".cross.o" );
3119 strarray_add( &make->clean_files, strmake( "lib%s.cross.a", make->importlib ));
3120 output( "%s.cross.a: %s %s", importlib_path, tools_path( make, "winebuild" ), spec_file );
3121 output_filenames_obj_dir( make, cross_files );
3122 output( "\n" );
3123 output( "\t%s -b %s -w --implib -o $@ --export %s",
3124 tools_path( make, "winebuild" ), crosstarget, spec_file );
3125 output_filenames_obj_dir( make, cross_files );
3126 output( "\n" );
3130 if (spec_file)
3131 output_man_pages( make );
3132 else if (*dll_ext && !make->is_win16)
3134 char *binary = replace_extension( make->module, ".exe", "" );
3135 add_install_rule( make, binary, "wineapploader", strmake( "t$(bindir)/%s", binary ));
3140 /*******************************************************************
3141 * output_static_lib
3143 static void output_static_lib( struct makefile *make )
3145 strarray_add( &make->all_targets, make->staticlib );
3146 output( "%s:", obj_dir_path( make, make->staticlib ));
3147 output_filenames_obj_dir( make, make->object_files );
3148 output( "\n\trm -f $@\n" );
3149 output( "\t$(AR) $(ARFLAGS) $@" );
3150 output_filenames_obj_dir( make, make->object_files );
3151 output( "\n\t$(RANLIB) $@\n" );
3152 add_install_rule( make, make->staticlib, make->staticlib,
3153 strmake( "d$(dlldir)/%s", make->staticlib ));
3154 if (crosstarget && make->module)
3156 char *name = replace_extension( make->staticlib, ".a", ".cross.a" );
3158 strarray_add( &make->all_targets, name );
3159 output( "%s:", obj_dir_path( make, name ));
3160 output_filenames_obj_dir( make, make->crossobj_files );
3161 output( "\n\trm -f $@\n" );
3162 output( "\t%s-ar $(ARFLAGS) $@", crosstarget );
3163 output_filenames_obj_dir( make, make->crossobj_files );
3164 output( "\n\t%s-ranlib $@\n", crosstarget );
3169 /*******************************************************************
3170 * output_shared_lib
3172 static void output_shared_lib( struct makefile *make )
3174 unsigned int i;
3175 char *basename, *p;
3176 struct strarray names = get_shared_lib_names( make->sharedlib );
3177 struct strarray all_libs = empty_strarray;
3178 struct strarray dep_libs = empty_strarray;
3180 basename = xstrdup( make->sharedlib );
3181 if ((p = strchr( basename, '.' ))) *p = 0;
3183 strarray_addall( &dep_libs, get_local_dependencies( make, basename, make->in_files ));
3184 strarray_addall( &all_libs, get_expanded_file_local_var( make, basename, "LDFLAGS" ));
3185 strarray_addall( &all_libs, add_default_libraries( make, &dep_libs ));
3187 output( "%s:", obj_dir_path( make, make->sharedlib ));
3188 output_filenames_obj_dir( make, make->object_files );
3189 output_filenames( dep_libs );
3190 output( "\n" );
3191 output( "\t$(CC) -o $@" );
3192 output_filenames_obj_dir( make, make->object_files );
3193 output_filenames( all_libs );
3194 output_filename( "$(LDFLAGS)" );
3195 output( "\n" );
3196 add_install_rule( make, make->sharedlib, make->sharedlib,
3197 strmake( "p$(libdir)/%s", make->sharedlib ));
3198 for (i = 1; i < names.count; i++)
3200 output( "%s: %s\n", obj_dir_path( make, names.str[i] ), obj_dir_path( make, names.str[i-1] ));
3201 output_symlink_rule( obj_dir_path( make, names.str[i-1] ), obj_dir_path( make, names.str[i] ));
3202 add_install_rule( make, names.str[i], names.str[i-1],
3203 strmake( "y$(libdir)/%s", names.str[i] ));
3205 strarray_addall( &make->all_targets, names );
3209 /*******************************************************************
3210 * output_import_lib
3212 static void output_import_lib( struct makefile *make )
3214 char *def_file = replace_extension( make->importlib, ".a", ".def" );
3216 /* stand-alone import lib (for libwine) */
3217 if (!strncmp( def_file, "lib", 3 )) def_file += 3;
3218 output( "%s: %s\n", obj_dir_path( make, make->importlib ), src_dir_path( make, def_file ));
3219 output( "\t%s -l $@ -d %s\n", dlltool, src_dir_path( make, def_file ));
3220 add_install_rule( make, make->importlib, make->importlib, strmake( "d$(libdir)/%s", make->importlib ));
3221 strarray_add( &make->all_targets, make->importlib );
3225 /*******************************************************************
3226 * output_test_module
3228 static void output_test_module( struct makefile *make )
3230 char *testmodule = replace_extension( make->testdll, ".dll", "_test.exe" );
3231 char *stripped = replace_extension( make->testdll, ".dll", "_test-stripped.exe" );
3232 char *testres = replace_extension( make->testdll, ".dll", "_test.res" );
3233 struct strarray dep_libs = empty_strarray;
3234 struct strarray all_libs = add_import_libs( make, &dep_libs, make->imports, 0 );
3236 add_import_libs( make, &dep_libs, get_default_imports( make ), 0 ); /* dependencies only */
3237 strarray_addall( &all_libs, libs );
3238 strarray_add( &make->all_targets, strmake( "%s%s", testmodule, dll_ext ));
3239 strarray_add( &make->clean_files, strmake( "%s%s", stripped, dll_ext ));
3240 output( "%s%s:\n", obj_dir_path( make, testmodule ), dll_ext );
3241 output( "\t%s -o $@", tools_path( make, "winegcc" ));
3242 output_filename( strmake( "-B%s", tools_dir_path( make, "winebuild" )));
3243 if (tools_dir) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make, "" )));
3244 output_filenames( target_flags );
3245 output_filenames( unwind_flags );
3246 output_filenames( make->appmode );
3247 output_filenames_obj_dir( make, make->object_files );
3248 output_filenames( all_libs );
3249 output_filename( "$(LDFLAGS)" );
3250 output( "\n" );
3251 output( "%s%s:\n", obj_dir_path( make, stripped ), dll_ext );
3252 output( "\t%s -s -o $@", tools_path( make, "winegcc" ));
3253 output_filename( strmake( "-B%s", tools_dir_path( make, "winebuild" )));
3254 if (tools_dir) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make, "" )));
3255 output_filenames( target_flags );
3256 output_filenames( unwind_flags );
3257 output_filename( strmake( "-Wb,-F,%s", testmodule ));
3258 output_filenames( make->appmode );
3259 output_filenames_obj_dir( make, make->object_files );
3260 output_filenames( all_libs );
3261 output_filename( "$(LDFLAGS)" );
3262 output( "\n" );
3263 output( "%s%s %s%s:", obj_dir_path( make, testmodule ), dll_ext,
3264 obj_dir_path( make, stripped ), dll_ext );
3265 output_filenames_obj_dir( make, make->object_files );
3266 output_filenames( dep_libs );
3267 output_filename( tools_path( make, "winebuild" ));
3268 output_filename( tools_path( make, "winegcc" ));
3269 output( "\n" );
3271 if (!make->disabled)
3272 output( "all: %s/%s\n", top_obj_dir_path( make, "programs/winetest" ), testres );
3273 output( "%s/%s: %s%s\n", top_obj_dir_path( make, "programs/winetest" ), testres,
3274 obj_dir_path( make, stripped ), dll_ext );
3275 output( "\techo \"%s TESTRES \\\"%s%s\\\"\" | %s -o $@\n",
3276 testmodule, obj_dir_path( make, stripped ), dll_ext, tools_path( make, "wrc" ));
3278 if (crosstarget)
3280 char *crosstest = replace_extension( make->testdll, ".dll", "_crosstest.exe" );
3282 dep_libs = empty_strarray;
3283 all_libs = add_import_libs( make, &dep_libs, make->imports, 1 );
3284 add_import_libs( make, &dep_libs, get_default_imports( make ), 1 ); /* dependencies only */
3285 strarray_addall( &all_libs, libs );
3286 strarray_add( &make->clean_files, crosstest );
3287 output( "%s:", obj_dir_path( make, crosstest ));
3288 output_filenames_obj_dir( make, make->crossobj_files );
3289 output_filenames( dep_libs );
3290 output_filename( tools_path( make, "winebuild" ));
3291 output_filename( tools_path( make, "winegcc" ));
3292 output( "\n" );
3293 output( "\t%s -o $@ -b %s", tools_path( make, "winegcc" ), crosstarget );
3294 output_filename( strmake( "-B%s", tools_dir_path( make, "winebuild" )));
3295 if (tools_dir) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make, "" )));
3296 output_filename( "--lib-suffix=.cross.a" );
3297 output_filenames_obj_dir( make, make->crossobj_files );
3298 output_filenames( all_libs );
3299 output_filename( "$(LDFLAGS)" );
3300 output( "\n" );
3301 if (!make->disabled)
3303 output( "%s: %s\n", obj_dir_path( make, "crosstest" ), obj_dir_path( make, crosstest ));
3304 strarray_add( &make->phony_targets, obj_dir_path( make, "crosstest" ));
3305 if (make->obj_dir) output( "crosstest: %s\n", obj_dir_path( make, "crosstest" ));
3309 output_filenames_obj_dir( make, make->ok_files );
3310 output( ": %s%s ../%s%s\n", testmodule, dll_ext, make->testdll, dll_ext );
3311 if (!make->disabled)
3313 output( "check test:" );
3314 output_filenames_obj_dir( make, make->ok_files );
3315 output( "\n" );
3316 strarray_add( &make->phony_targets, "check" );
3317 strarray_add( &make->phony_targets, "test" );
3319 output( "testclean::\n" );
3320 output( "\trm -f" );
3321 output_filenames_obj_dir( make, make->ok_files );
3322 output( "\n" );
3323 strarray_addall( &make->clean_files, make->ok_files );
3324 strarray_add( &make->phony_targets, "testclean" );
3328 /*******************************************************************
3329 * output_programs
3331 static void output_programs( struct makefile *make )
3333 unsigned int i, j;
3334 char *ldrpath_local = get_expanded_make_variable( make, "LDRPATH_LOCAL" );
3335 char *ldrpath_install = get_expanded_make_variable( make, "LDRPATH_INSTALL" );
3337 for (i = 0; i < make->programs.count; i++)
3339 char *program_installed = NULL;
3340 char *program = strmake( "%s%s", make->programs.str[i], exe_ext );
3341 struct strarray deps = get_local_dependencies( make, make->programs.str[i], make->in_files );
3342 struct strarray all_libs = get_expanded_file_local_var( make, make->programs.str[i], "LDFLAGS" );
3343 struct strarray objs = get_expanded_file_local_var( make, make->programs.str[i], "OBJS" );
3344 struct strarray symlinks = get_expanded_file_local_var( make, make->programs.str[i], "SYMLINKS" );
3346 if (!objs.count) objs = make->object_files;
3347 strarray_addall( &all_libs, add_default_libraries( make, &deps ));
3349 output( "%s:", obj_dir_path( make, program ) );
3350 output_filenames_obj_dir( make, objs );
3351 output_filenames( deps );
3352 output( "\n" );
3353 output( "\t$(CC) -o $@" );
3354 output_filenames_obj_dir( make, objs );
3356 if (strarray_exists( &all_libs, "-lwine" ))
3358 strarray_add( &all_libs, strmake( "-L%s", top_obj_dir_path( make, "libs/wine" )));
3359 if (ldrpath_local && ldrpath_install)
3361 program_installed = strmake( "%s-installed%s", make->programs.str[i], exe_ext );
3362 output_filename( ldrpath_local );
3363 output_filenames( all_libs );
3364 output_filename( "$(LDFLAGS)" );
3365 output( "\n" );
3366 output( "%s:", obj_dir_path( make, program_installed ) );
3367 output_filenames_obj_dir( make, objs );
3368 output_filenames( deps );
3369 output( "\n" );
3370 output( "\t$(CC) -o $@" );
3371 output_filenames_obj_dir( make, objs );
3372 output_filename( ldrpath_install );
3373 strarray_add( &make->all_targets, program_installed );
3377 output_filenames( all_libs );
3378 output_filename( "$(LDFLAGS)" );
3379 output( "\n" );
3380 strarray_add( &make->all_targets, program );
3382 for (j = 0; j < symlinks.count; j++)
3384 output( "%s: %s\n", obj_dir_path( make, symlinks.str[j] ), obj_dir_path( make, program ));
3385 output_symlink_rule( obj_dir_path( make, program ), obj_dir_path( make, symlinks.str[j] ));
3387 strarray_addall( &make->all_targets, symlinks );
3389 add_install_rule( make, program, program_installed ? program_installed : program,
3390 strmake( "p$(bindir)/%s", program ));
3391 for (j = 0; j < symlinks.count; j++)
3392 add_install_rule( make, symlinks.str[j], program,
3393 strmake( "y$(bindir)/%s%s", symlinks.str[j], exe_ext ));
3398 /*******************************************************************
3399 * output_subdirs
3401 static void output_subdirs( struct makefile *make )
3403 struct strarray symlinks = empty_strarray;
3404 struct strarray all_deps = empty_strarray;
3405 struct strarray build_deps = empty_strarray;
3406 struct strarray builddeps_deps = empty_strarray;
3407 struct strarray makefile_deps = empty_strarray;
3408 struct strarray clean_files = empty_strarray;
3409 struct strarray testclean_files = empty_strarray;
3410 struct strarray distclean_files = empty_strarray;
3411 struct strarray tools_deps = empty_strarray;
3412 struct strarray tooldeps_deps = empty_strarray;
3413 struct strarray winetest_deps = empty_strarray;
3414 struct strarray crosstest_deps = empty_strarray;
3415 unsigned int i, j;
3417 strarray_addall( &distclean_files, make->distclean_files );
3418 for (i = 0; i < make->subdirs.count; i++)
3420 const struct makefile *submake = make->submakes[i];
3421 char *subdir = base_dir_path( submake, "" );
3423 strarray_add( &makefile_deps, top_src_dir_path( make, base_dir_path( submake,
3424 strmake ( "%s.in", output_makefile_name ))));
3425 for (j = 0; j < submake->clean_files.count; j++)
3426 strarray_add( &clean_files, base_dir_path( submake, submake->clean_files.str[j] ));
3427 for (j = 0; j < submake->distclean_files.count; j++)
3428 strarray_add( &distclean_files, base_dir_path( submake, submake->distclean_files.str[j] ));
3429 for (j = 0; j < submake->ok_files.count; j++)
3430 strarray_add( &testclean_files, base_dir_path( submake, submake->ok_files.str[j] ));
3432 /* import libs are still created for disabled dirs, except for win16 ones */
3433 if (submake->module && submake->importlib && !(submake->disabled && submake->is_win16))
3435 char *importlib_path = base_dir_path( submake, strmake( "lib%s", submake->importlib ));
3436 if (submake->implib_objs.count)
3438 output( "%s.a: dummy\n", importlib_path );
3439 output( "\t@cd %s && $(MAKE) lib%s.a\n", subdir, submake->importlib );
3440 strarray_add( &tools_deps, strmake( "%s.a", importlib_path ));
3441 if (crosstarget)
3443 output( "%s.cross.a: dummy\n", importlib_path );
3444 output( "\t@cd %s && $(MAKE) lib%s.cross.a\n", subdir, submake->importlib );
3445 strarray_add( &tools_deps, strmake( "%s.cross.a", importlib_path ));
3448 else
3450 const char *libext = *dll_ext ? ".def" : ".a";
3451 char *spec_file = top_src_dir_path( make, base_dir_path( submake,
3452 replace_extension( submake->module, ".dll", ".spec" )));
3453 output( "%s%s: %s", importlib_path, libext, spec_file );
3454 output_filename( tools_path( make, "winebuild" ));
3455 output( "\n" );
3456 output( "\t%s -w -o $@", tools_path( make, "winebuild" ));
3457 output_filename( *dll_ext ? "--def" : "--implib" );
3458 output_filenames( target_flags );
3459 if (submake->is_win16) output_filename( "-m16" );
3460 output_filename( "--export" );
3461 output_filename( spec_file );
3462 output( "\n" );
3463 strarray_add( &build_deps, strmake( "%s%s", importlib_path, libext ));
3464 if (crosstarget && !submake->is_win16)
3466 output( "%s.cross.a: %s", importlib_path, spec_file );
3467 output_filename( tools_path( make, "winebuild" ));
3468 output( "\n" );
3469 output( "\t%s -b %s -w -o $@", tools_path( make, "winebuild" ), crosstarget );
3470 output_filename( "--implib" );
3471 output_filenames( target_flags );
3472 output_filename( "--export" );
3473 output_filename( spec_file );
3474 output( "\n" );
3475 strarray_add( &build_deps, strmake( "%s.cross.a", importlib_path ));
3478 strarray_addall( &symlinks, output_importlib_symlinks( make, submake ));
3481 if (submake->disabled) continue;
3482 strarray_add( &all_deps, subdir );
3484 if (submake->module)
3486 if (!submake->staticlib)
3488 strarray_add( &builddeps_deps, subdir );
3489 if (!submake->appmode.count)
3491 output( "manpages htmlpages sgmlpages xmlpages::\n" );
3492 output( "\t@cd %s && $(MAKE) $@\n", subdir );
3495 else strarray_add( &tools_deps, subdir );
3497 else if (submake->testdll)
3499 output( "%s/test: dummy\n", subdir );
3500 output( "\t@cd %s && $(MAKE) test\n", subdir );
3501 strarray_add( &winetest_deps, subdir );
3502 strarray_add( &builddeps_deps, subdir );
3503 if (crosstarget)
3505 char *target = base_dir_path( submake, "crosstest" );
3506 output( "crosstest: %s\n", target );
3507 output( "%s: dummy\n", target );
3508 output( "\t@cd %s && $(MAKE) crosstest\n", subdir );
3509 strarray_add( &crosstest_deps, target );
3510 strarray_add( &builddeps_deps, target );
3513 else
3515 if (!strcmp( submake->base_dir, "tools" ) || !strncmp( submake->base_dir, "tools/", 6 ))
3517 strarray_add( &tooldeps_deps, submake->base_dir );
3518 for (j = 0; j < submake->programs.count; j++)
3519 output( "%s/%s%s: %s\n", submake->base_dir,
3520 submake->programs.str[j], tools_ext, submake->base_dir );
3522 if (submake->programs.count || submake->sharedlib)
3524 struct strarray libs = get_expanded_make_var_array( submake, "EXTRALIBS" );
3525 for (j = 0; j < submake->programs.count; j++)
3526 strarray_addall( &libs, get_expanded_file_local_var( submake,
3527 submake->programs.str[j], "LDFLAGS" ));
3528 output( "%s: libs/port", submake->base_dir );
3529 for (j = 0; j < libs.count; j++)
3531 if (!strcmp( libs.str[j], "-lwpp" )) output_filename( "libs/wpp" );
3532 if (!strcmp( libs.str[j], "-lwine" )) output_filename( "libs/wine" );
3534 output( "\n" );
3538 if (submake->install_rules[INSTALL_LIB].count)
3540 output( "install install-lib:: %s\n", submake->base_dir );
3541 output_install_commands( make, submake, submake->install_rules[INSTALL_LIB] );
3543 if (submake->install_rules[INSTALL_DEV].count)
3545 output( "install install-dev:: %s\n", submake->base_dir );
3546 output_install_commands( make, submake, submake->install_rules[INSTALL_DEV] );
3549 output( "all:" );
3550 output_filenames( all_deps );
3551 output( "\n" );
3552 output_filenames( all_deps );
3553 output( ": dummy\n" );
3554 output( "\t@cd $@ && $(MAKE)\n" );
3555 output( "Makefile:" );
3556 output_filenames( makefile_deps );
3557 output( "\n" );
3558 output_filenames( makefile_deps );
3559 output( ":\n" );
3560 if (tooldeps_deps.count)
3562 output( "__tooldeps__:" );
3563 output_filenames( tooldeps_deps );
3564 output( "\n" );
3565 strarray_add( &make->phony_targets, "__tooldeps__" );
3567 if (winetest_deps.count)
3569 output( "programs/winetest:" );
3570 output_filenames( winetest_deps );
3571 output( "\n" );
3572 output( "check test:" );
3573 for (i = 0; i < winetest_deps.count; i++)
3575 char *target = strmake( "%s/test", winetest_deps.str[i] );
3576 output_filename( target );
3577 strarray_add( &make->phony_targets, target );
3579 output( "\n" );
3580 strarray_add( &make->phony_targets, "check" );
3581 strarray_add( &make->phony_targets, "test" );
3583 output( "crosstest:" );
3584 output_filenames( crosstest_deps );
3585 output( "\n" );
3586 if (!crosstest_deps.count)
3587 output( "\t@echo \"crosstest is not supported (mingw not installed?)\" && false\n" );
3588 strarray_add( &make->phony_targets, "crosstest" );
3590 output( "clean::\n");
3591 output_rm_filenames( clean_files );
3592 output( "testclean::\n");
3593 output_rm_filenames( testclean_files );
3594 output( "distclean::\n");
3595 output_rm_filenames( distclean_files );
3596 output_filenames( tools_deps );
3597 output( ":" );
3598 output_filename( tools_dir_path( make, "widl" ));
3599 output_filename( tools_dir_path( make, "winebuild" ));
3600 output_filename( tools_dir_path( make, "winegcc" ));
3601 output_filename( obj_dir_path( make, "include" ));
3602 output( "\n" );
3603 output_filenames( builddeps_deps );
3604 output( ": __builddeps__\n" );
3605 strarray_add( &make->phony_targets, "distclean" );
3606 strarray_add( &make->phony_targets, "testclean" );
3607 strarray_addall( &make->phony_targets, all_deps );
3608 strarray_addall( &make->phony_targets, crosstest_deps );
3610 strarray_addall( &make->clean_files, symlinks );
3611 strarray_addall( &build_deps, tools_deps );
3612 strarray_addall( &build_deps, symlinks );
3613 if (build_deps.count)
3615 output( "__builddeps__:" );
3616 output_filenames( build_deps );
3617 output( "\n" );
3618 strarray_add( &make->phony_targets, "__builddeps__" );
3620 if (get_expanded_make_variable( make, "GETTEXTPO_LIBS" )) output_po_files( make );
3624 /*******************************************************************
3625 * output_sources
3627 static void output_sources( struct makefile *make )
3629 struct incl_file *source;
3630 unsigned int i, j;
3632 strarray_add( &make->phony_targets, "all" );
3634 LIST_FOR_EACH_ENTRY( source, &make->sources, struct incl_file, entry )
3636 char *obj = xstrdup( source->name );
3637 char *ext = get_extension( obj );
3639 if (!ext) fatal_error( "unsupported file type %s\n", source->name );
3640 *ext++ = 0;
3642 for (j = 0; output_source_funcs[j].ext; j++)
3643 if (!strcmp( ext, output_source_funcs[j].ext )) break;
3645 output_source_funcs[j].fn( make, source, obj );
3646 free( obj );
3649 /* special case for winetest: add resource files from other test dirs */
3650 if (make->base_dir && !strcmp( make->base_dir, "programs/winetest" ))
3652 struct strarray tests = enable_tests;
3653 if (!tests.count)
3654 for (i = 0; i < top_makefile->subdirs.count; i++)
3655 if (top_makefile->submakes[i]->testdll && !top_makefile->submakes[i]->disabled)
3656 strarray_add( &tests, top_makefile->submakes[i]->testdll );
3657 for (i = 0; i < tests.count; i++)
3658 strarray_add( &make->object_files, replace_extension( tests.str[i], ".dll", "_test.res" ));
3661 if (make->dlldata_files.count)
3663 output( "%s: %s %s\n", obj_dir_path( make, "dlldata.c" ),
3664 tools_path( make, "widl" ), src_dir_path( make, "Makefile.in" ));
3665 output( "\t%s --dlldata-only -o $@", tools_path( make, "widl" ));
3666 output_filenames( make->dlldata_files );
3667 output( "\n" );
3670 if (make->staticlib) output_static_lib( make );
3671 else if (make->module) output_module( make );
3672 else if (make->testdll) output_test_module( make );
3673 else
3675 if (make->importlib) output_import_lib( make );
3676 if (make->sharedlib) output_shared_lib( make );
3677 if (make->programs.count) output_programs( make );
3680 for (i = 0; i < make->scripts.count; i++)
3681 add_install_rule( make, make->scripts.str[i], make->scripts.str[i],
3682 strmake( "S$(bindir)/%s", make->scripts.str[i] ));
3684 if (!make->src_dir) strarray_add( &make->distclean_files, ".gitignore" );
3685 strarray_add( &make->distclean_files, "Makefile" );
3686 if (make->testdll) strarray_add( &make->distclean_files, "testlist.c" );
3688 if (!make->base_dir)
3689 strarray_addall( &make->distclean_files, get_expanded_make_var_array( make, "CONFIGURE_TARGETS" ));
3690 else if (!strcmp( make->base_dir, "po" ))
3691 strarray_add( &make->distclean_files, "LINGUAS" );
3693 if (make->subdirs.count) output_subdirs( make );
3695 if (!make->disabled)
3697 if (make->all_targets.count)
3699 output( "all:" );
3700 output_filenames_obj_dir( make, make->all_targets );
3701 output( "\n" );
3703 output_install_rules( make, INSTALL_LIB, "install-lib" );
3704 output_install_rules( make, INSTALL_DEV, "install-dev" );
3705 output_uninstall_rules( make );
3708 strarray_addall( &make->clean_files, make->object_files );
3709 for (i = 0; i < make->crossobj_files.count; i++)
3710 strarray_add_uniq( &make->clean_files, make->crossobj_files.str[i] );
3711 strarray_addall( &make->clean_files, make->all_targets );
3712 strarray_addall( &make->clean_files, get_expanded_make_var_array( make, "EXTRA_TARGETS" ));
3714 if (make->clean_files.count)
3716 output( "%s::\n", obj_dir_path( make, "clean" ));
3717 output( "\trm -f" );
3718 output_filenames_obj_dir( make, make->clean_files );
3719 output( "\n" );
3720 if (make->obj_dir) output( "__clean__: %s\n", obj_dir_path( make, "clean" ));
3721 strarray_add( &make->phony_targets, obj_dir_path( make, "clean" ));
3724 if (make->phony_targets.count)
3726 output( ".PHONY:" );
3727 output_filenames( make->phony_targets );
3728 output( "\n" );
3733 /*******************************************************************
3734 * create_temp_file
3736 static FILE *create_temp_file( const char *orig )
3738 char *name = xmalloc( strlen(orig) + 13 );
3739 unsigned int i, id = getpid();
3740 int fd;
3741 FILE *ret = NULL;
3743 for (i = 0; i < 100; i++)
3745 sprintf( name, "%s.tmp%08x", orig, id );
3746 if ((fd = open( name, O_RDWR | O_CREAT | O_EXCL, 0666 )) != -1)
3748 ret = fdopen( fd, "w" );
3749 break;
3751 if (errno != EEXIST) break;
3752 id += 7777;
3754 if (!ret) fatal_error( "failed to create output file for '%s'\n", orig );
3755 temp_file_name = name;
3756 return ret;
3760 /*******************************************************************
3761 * rename_temp_file
3763 static void rename_temp_file( const char *dest )
3765 int ret = rename( temp_file_name, dest );
3766 if (ret == -1 && errno == EEXIST)
3768 /* rename doesn't overwrite on windows */
3769 unlink( dest );
3770 ret = rename( temp_file_name, dest );
3772 if (ret == -1) fatal_error( "failed to rename output file to '%s'\n", dest );
3773 temp_file_name = NULL;
3777 /*******************************************************************
3778 * are_files_identical
3780 static int are_files_identical( FILE *file1, FILE *file2 )
3782 for (;;)
3784 char buffer1[8192], buffer2[8192];
3785 int size1 = fread( buffer1, 1, sizeof(buffer1), file1 );
3786 int size2 = fread( buffer2, 1, sizeof(buffer2), file2 );
3787 if (size1 != size2) return 0;
3788 if (!size1) return feof( file1 ) && feof( file2 );
3789 if (memcmp( buffer1, buffer2, size1 )) return 0;
3794 /*******************************************************************
3795 * rename_temp_file_if_changed
3797 static void rename_temp_file_if_changed( const char *dest )
3799 FILE *file1, *file2;
3800 int do_rename = 1;
3802 if ((file1 = fopen( dest, "r" )))
3804 if ((file2 = fopen( temp_file_name, "r" )))
3806 do_rename = !are_files_identical( file1, file2 );
3807 fclose( file2 );
3809 fclose( file1 );
3811 if (!do_rename)
3813 unlink( temp_file_name );
3814 temp_file_name = NULL;
3816 else rename_temp_file( dest );
3820 /*******************************************************************
3821 * output_linguas
3823 static void output_linguas( const struct makefile *make )
3825 const char *dest = base_dir_path( make, "LINGUAS" );
3826 struct incl_file *source;
3828 output_file = create_temp_file( dest );
3830 output( "# Automatically generated by make depend; DO NOT EDIT!!\n" );
3831 LIST_FOR_EACH_ENTRY( source, &make->sources, struct incl_file, entry )
3832 if (strendswith( source->name, ".po" ))
3833 output( "%s\n", replace_extension( source->name, ".po", "" ));
3835 if (fclose( output_file )) fatal_perror( "write" );
3836 output_file = NULL;
3837 rename_temp_file_if_changed( dest );
3841 /*******************************************************************
3842 * output_testlist
3844 static void output_testlist( const struct makefile *make )
3846 const char *dest = base_dir_path( make, "testlist.c" );
3847 struct strarray files = empty_strarray;
3848 unsigned int i;
3850 for (i = 0; i < make->ok_files.count; i++)
3851 strarray_add( &files, replace_extension( make->ok_files.str[i], ".ok", "" ));
3853 output_file = create_temp_file( dest );
3855 output( "/* Automatically generated by make depend; DO NOT EDIT!! */\n\n" );
3856 output( "#define WIN32_LEAN_AND_MEAN\n" );
3857 output( "#include <windows.h>\n\n" );
3858 output( "#define STANDALONE\n" );
3859 output( "#include \"wine/test.h\"\n\n" );
3861 for (i = 0; i < files.count; i++) output( "extern void func_%s(void);\n", files.str[i] );
3862 output( "\n" );
3863 output( "const struct test winetest_testlist[] =\n" );
3864 output( "{\n" );
3865 for (i = 0; i < files.count; i++) output( " { \"%s\", func_%s },\n", files.str[i], files.str[i] );
3866 output( " { 0, 0 }\n" );
3867 output( "};\n" );
3869 if (fclose( output_file )) fatal_perror( "write" );
3870 output_file = NULL;
3871 rename_temp_file_if_changed( dest );
3875 /*******************************************************************
3876 * output_gitignore
3878 static void output_gitignore( const char *dest, struct strarray files )
3880 int i;
3882 output_file = create_temp_file( dest );
3884 output( "# Automatically generated by make depend; DO NOT EDIT!!\n" );
3885 for (i = 0; i < files.count; i++)
3887 if (!strchr( files.str[i], '/' )) output( "/" );
3888 output( "%s\n", files.str[i] );
3891 if (fclose( output_file )) fatal_perror( "write" );
3892 output_file = NULL;
3893 rename_temp_file( dest );
3897 /*******************************************************************
3898 * output_top_variables
3900 static void output_top_variables( const struct makefile *make )
3902 unsigned int i;
3903 struct strarray *vars = &top_makefile->vars;
3905 if (!make->base_dir) return; /* don't output variables in the top makefile */
3907 output( "# Automatically generated by make depend; DO NOT EDIT!!\n\n" );
3908 output( "all:\n\n" );
3909 for (i = 0; i < vars->count; i += 2)
3911 if (!strcmp( vars->str[i], "SUBDIRS" )) continue; /* not inherited */
3912 output( "%s = %s\n", vars->str[i], get_make_variable( make, vars->str[i] ));
3914 output( "\n" );
3918 /*******************************************************************
3919 * output_dependencies
3921 static void output_dependencies( struct makefile *make )
3923 struct strarray ignore_files = empty_strarray;
3924 char buffer[1024];
3925 FILE *src_file;
3926 int found = 0;
3928 if (make->base_dir) create_dir( make->base_dir );
3930 output_file_name = base_dir_path( make, output_makefile_name );
3931 output_file = create_temp_file( output_file_name );
3932 output_top_variables( make );
3934 /* copy the contents of the source makefile */
3935 src_file = open_input_makefile( make );
3936 while (fgets( buffer, sizeof(buffer), src_file ) && !found)
3938 if (fwrite( buffer, 1, strlen(buffer), output_file ) != strlen(buffer)) fatal_perror( "write" );
3939 found = !strncmp( buffer, separator, strlen(separator) );
3941 if (fclose( src_file )) fatal_perror( "close" );
3942 input_file_name = NULL;
3944 if (!found) output( "\n%s (everything below this line is auto-generated; DO NOT EDIT!!)\n", separator );
3945 output_sources( make );
3947 fclose( output_file );
3948 output_file = NULL;
3949 rename_temp_file( output_file_name );
3951 strarray_addall( &ignore_files, make->distclean_files );
3952 strarray_addall( &ignore_files, make->clean_files );
3953 if (make->testdll) output_testlist( make );
3954 if (make->base_dir && !strcmp( make->base_dir, "po" )) output_linguas( make );
3955 if (!make->src_dir) output_gitignore( base_dir_path( make, ".gitignore" ), ignore_files );
3957 create_file_directories( make, ignore_files );
3959 output_file_name = NULL;
3963 /*******************************************************************
3964 * load_sources
3966 static void load_sources( struct makefile *make )
3968 static const char *source_vars[] =
3970 "SOURCES",
3971 "C_SRCS",
3972 "OBJC_SRCS",
3973 "RC_SRCS",
3974 "MC_SRCS",
3975 "IDL_SRCS",
3976 "BISON_SRCS",
3977 "LEX_SRCS",
3978 "HEADER_SRCS",
3979 "XTEMPLATE_SRCS",
3980 "SVG_SRCS",
3981 "FONT_SRCS",
3982 "IN_SRCS",
3983 "PO_SRCS",
3984 "MANPAGES",
3985 NULL
3987 const char **var;
3988 unsigned int i;
3989 struct strarray value;
3990 struct incl_file *file;
3992 if (root_src_dir)
3994 make->top_src_dir = concat_paths( make->top_obj_dir, root_src_dir );
3995 make->src_dir = concat_paths( make->top_src_dir, make->base_dir );
3997 strarray_set_value( &make->vars, "top_builddir", top_obj_dir_path( make, "" ));
3998 strarray_set_value( &make->vars, "top_srcdir", top_src_dir_path( make, "" ));
3999 strarray_set_value( &make->vars, "srcdir", src_dir_path( make, "" ));
4001 make->parent_dir = get_expanded_make_variable( make, "PARENTSRC" );
4002 make->module = get_expanded_make_variable( make, "MODULE" );
4003 make->testdll = get_expanded_make_variable( make, "TESTDLL" );
4004 make->sharedlib = get_expanded_make_variable( make, "SHAREDLIB" );
4005 make->staticlib = get_expanded_make_variable( make, "STATICLIB" );
4006 make->importlib = get_expanded_make_variable( make, "IMPORTLIB" );
4008 make->programs = get_expanded_make_var_array( make, "PROGRAMS" );
4009 make->scripts = get_expanded_make_var_array( make, "SCRIPTS" );
4010 make->appmode = get_expanded_make_var_array( make, "APPMODE" );
4011 make->imports = get_expanded_make_var_array( make, "IMPORTS" );
4012 make->delayimports = get_expanded_make_var_array( make, "DELAYIMPORTS" );
4013 make->extradllflags = get_expanded_make_var_array( make, "EXTRADLLFLAGS" );
4014 make->install_lib = get_expanded_make_var_array( make, "INSTALL_LIB" );
4015 make->install_dev = get_expanded_make_var_array( make, "INSTALL_DEV" );
4017 if (make->module && strendswith( make->module, ".a" )) make->staticlib = make->module;
4019 make->disabled = make->base_dir && strarray_exists( &disabled_dirs, make->base_dir );
4020 make->is_win16 = strarray_exists( &make->extradllflags, "-m16" ) || strarray_exists( &make->appmode, "-m16" );
4021 make->use_msvcrt = strarray_exists( &make->appmode, "-mno-cygwin" );
4023 for (i = 0; i < make->imports.count && !make->use_msvcrt; i++)
4024 make->use_msvcrt = !strncmp( make->imports.str[i], "msvcr", 5 ) ||
4025 !strcmp( make->imports.str[i], "ucrtbase" );
4027 if (make->module && !make->install_lib.count && !make->install_dev.count)
4029 if (make->importlib) strarray_add( &make->install_dev, make->importlib );
4030 if (make->staticlib) strarray_add( &make->install_dev, make->staticlib );
4031 else strarray_add( &make->install_lib, make->module );
4034 make->include_paths = empty_strarray;
4035 make->include_args = empty_strarray;
4036 make->define_args = empty_strarray;
4037 strarray_add( &make->define_args, "-D__WINESRC__" );
4039 value = get_expanded_make_var_array( make, "EXTRAINCL" );
4040 for (i = 0; i < value.count; i++)
4041 if (!strncmp( value.str[i], "-I", 2 ))
4042 strarray_add_uniq( &make->include_paths, value.str[i] + 2 );
4043 else
4044 strarray_add_uniq( &make->define_args, value.str[i] );
4045 strarray_addall( &make->define_args, get_expanded_make_var_array( make, "EXTRADEFS" ));
4047 strarray_add( &make->include_args, strmake( "-I%s", obj_dir_path( make, "" )));
4048 if (make->src_dir)
4049 strarray_add( &make->include_args, strmake( "-I%s", make->src_dir ));
4050 if (make->parent_dir)
4051 strarray_add( &make->include_args, strmake( "-I%s", src_dir_path( make, make->parent_dir )));
4052 strarray_add( &make->include_args, strmake( "-I%s", top_obj_dir_path( make, "include" )));
4053 if (make->top_src_dir)
4054 strarray_add( &make->include_args, strmake( "-I%s", top_src_dir_path( make, "include" )));
4055 if (make->use_msvcrt)
4056 strarray_add( &make->include_args, strmake( "-I%s", top_src_dir_path( make, "include/msvcrt" )));
4057 for (i = 0; i < make->include_paths.count; i++)
4058 strarray_add( &make->include_args, strmake( "-I%s", obj_dir_path( make, make->include_paths.str[i] )));
4060 list_init( &make->sources );
4061 list_init( &make->includes );
4063 for (var = source_vars; *var; var++)
4065 value = get_expanded_make_var_array( make, *var );
4066 for (i = 0; i < value.count; i++) add_src_file( make, value.str[i] );
4069 add_generated_sources( make );
4071 value = get_expanded_make_var_array( make, "EXTRA_OBJS" );
4072 for (i = 0; i < value.count; i++)
4074 /* default to .c for unknown extra object files */
4075 if (strendswith( value.str[i], ".o" ))
4076 add_generated_source( make, value.str[i], replace_extension( value.str[i], ".o", ".c" ) );
4077 else
4078 add_generated_source( make, value.str[i], NULL );
4081 LIST_FOR_EACH_ENTRY( file, &make->includes, struct incl_file, entry ) parse_file( make, file, 0 );
4082 LIST_FOR_EACH_ENTRY( file, &make->sources, struct incl_file, entry ) get_dependencies( file, file );
4086 /*******************************************************************
4087 * parse_makeflags
4089 static void parse_makeflags( const char *flags )
4091 const char *p = flags;
4092 char *var, *buffer = xmalloc( strlen(flags) + 1 );
4094 while (*p)
4096 while (isspace(*p)) p++;
4097 var = buffer;
4098 while (*p && !isspace(*p))
4100 if (*p == '\\' && p[1]) p++;
4101 *var++ = *p++;
4103 *var = 0;
4104 if (var > buffer) set_make_variable( &cmdline_vars, buffer );
4109 /*******************************************************************
4110 * parse_option
4112 static int parse_option( const char *opt )
4114 if (opt[0] != '-')
4116 if (strchr( opt, '=' )) return set_make_variable( &cmdline_vars, opt );
4117 return 0;
4119 switch(opt[1])
4121 case 'f':
4122 if (opt[2]) output_makefile_name = opt + 2;
4123 break;
4124 case 'R':
4125 relative_dir_mode = 1;
4126 break;
4127 default:
4128 fprintf( stderr, "Unknown option '%s'\n%s", opt, Usage );
4129 exit(1);
4131 return 1;
4135 /*******************************************************************
4136 * main
4138 int main( int argc, char *argv[] )
4140 const char *makeflags = getenv( "MAKEFLAGS" );
4141 int i, j;
4143 if (makeflags) parse_makeflags( makeflags );
4145 i = 1;
4146 while (i < argc)
4148 if (parse_option( argv[i] ))
4150 for (j = i; j < argc; j++) argv[j] = argv[j+1];
4151 argc--;
4153 else i++;
4156 if (relative_dir_mode)
4158 char *relpath;
4160 if (argc != 3)
4162 fprintf( stderr, "Option -R needs two directories\n%s", Usage );
4163 exit( 1 );
4165 relpath = get_relative_path( argv[1], argv[2] );
4166 printf( "%s\n", relpath ? relpath : "." );
4167 exit( 0 );
4170 atexit( cleanup_files );
4171 signal( SIGTERM, exit_on_signal );
4172 signal( SIGINT, exit_on_signal );
4173 #ifdef SIGHUP
4174 signal( SIGHUP, exit_on_signal );
4175 #endif
4177 for (i = 0; i < HASH_SIZE; i++) list_init( &files[i] );
4179 top_makefile = parse_makefile( NULL );
4181 target_flags = get_expanded_make_var_array( top_makefile, "TARGETFLAGS" );
4182 msvcrt_flags = get_expanded_make_var_array( top_makefile, "MSVCRTFLAGS" );
4183 dll_flags = get_expanded_make_var_array( top_makefile, "DLLFLAGS" );
4184 extra_cflags = get_expanded_make_var_array( top_makefile, "EXTRACFLAGS" );
4185 cpp_flags = get_expanded_make_var_array( top_makefile, "CPPFLAGS" );
4186 unwind_flags = get_expanded_make_var_array( top_makefile, "UNWINDFLAGS" );
4187 libs = get_expanded_make_var_array( top_makefile, "LIBS" );
4188 enable_tests = get_expanded_make_var_array( top_makefile, "ENABLE_TESTS" );
4190 root_src_dir = get_expanded_make_variable( top_makefile, "srcdir" );
4191 tools_dir = get_expanded_make_variable( top_makefile, "TOOLSDIR" );
4192 tools_ext = get_expanded_make_variable( top_makefile, "TOOLSEXT" );
4193 exe_ext = get_expanded_make_variable( top_makefile, "EXEEXT" );
4194 man_ext = get_expanded_make_variable( top_makefile, "api_manext" );
4195 dll_ext = (exe_ext && !strcmp( exe_ext, ".exe" )) ? "" : ".so";
4196 crosstarget = get_expanded_make_variable( top_makefile, "CROSSTARGET" );
4197 fontforge = get_expanded_make_variable( top_makefile, "FONTFORGE" );
4198 convert = get_expanded_make_variable( top_makefile, "CONVERT" );
4199 rsvg = get_expanded_make_variable( top_makefile, "RSVG" );
4200 icotool = get_expanded_make_variable( top_makefile, "ICOTOOL" );
4201 dlltool = get_expanded_make_variable( top_makefile, "DLLTOOL" );
4202 msgfmt = get_expanded_make_variable( top_makefile, "MSGFMT" );
4203 ln_s = get_expanded_make_variable( top_makefile, "LN_S" );
4205 if (root_src_dir && !strcmp( root_src_dir, "." )) root_src_dir = NULL;
4206 if (tools_dir && !strcmp( tools_dir, "." )) tools_dir = NULL;
4207 if (!exe_ext) exe_ext = "";
4208 if (!tools_ext) tools_ext = "";
4209 if (!man_ext) man_ext = "3w";
4211 if (argc == 1)
4213 disabled_dirs = get_expanded_make_var_array( top_makefile, "DISABLED_SUBDIRS" );
4214 top_makefile->subdirs = get_expanded_make_var_array( top_makefile, "SUBDIRS" );
4215 top_makefile->submakes = xmalloc( top_makefile->subdirs.count * sizeof(*top_makefile->submakes) );
4217 for (i = 0; i < top_makefile->subdirs.count; i++)
4218 top_makefile->submakes[i] = parse_makefile( top_makefile->subdirs.str[i] );
4220 load_sources( top_makefile );
4221 for (i = 0; i < top_makefile->subdirs.count; i++)
4222 load_sources( top_makefile->submakes[i] );
4224 for (i = 0; i < top_makefile->subdirs.count; i++)
4225 output_dependencies( top_makefile->submakes[i] );
4227 output_dependencies( top_makefile );
4228 return 0;
4231 for (i = 1; i < argc; i++)
4233 struct makefile *make = parse_makefile( argv[i] );
4234 load_sources( make );
4235 output_dependencies( make );
4237 return 0;