winex11: Print error message when libvulkan cannot be loaded.
[wine.git] / tools / makedep.c
blobc9ab24da79042a575fa7ac8ae3967dd00e02b6de
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 dependencies;
204 struct strarray install_rules[NB_INSTALL_RULES];
207 static struct makefile *top_makefile;
209 static const char separator[] = "### Dependencies";
210 static const char *output_makefile_name = "Makefile";
211 static const char *input_file_name;
212 static const char *output_file_name;
213 static const char *temp_file_name;
214 static int relative_dir_mode;
215 static int input_line;
216 static int output_column;
217 static FILE *output_file;
219 static const char Usage[] =
220 "Usage: makedep [options] [directories]\n"
221 "Options:\n"
222 " -R from to Compute the relative path between two directories\n"
223 " -fxxx Store output in file 'xxx' (default: Makefile)\n";
226 #ifndef __GNUC__
227 #define __attribute__(x)
228 #endif
230 static void fatal_error( const char *msg, ... ) __attribute__ ((__format__ (__printf__, 1, 2)));
231 static void fatal_perror( const char *msg, ... ) __attribute__ ((__format__ (__printf__, 1, 2)));
232 static void output( const char *format, ... ) __attribute__ ((__format__ (__printf__, 1, 2)));
233 static char *strmake( const char* fmt, ... ) __attribute__ ((__format__ (__printf__, 1, 2)));
235 /*******************************************************************
236 * fatal_error
238 static void fatal_error( const char *msg, ... )
240 va_list valist;
241 va_start( valist, msg );
242 if (input_file_name)
244 fprintf( stderr, "%s:", input_file_name );
245 if (input_line) fprintf( stderr, "%d:", input_line );
246 fprintf( stderr, " error: " );
248 else fprintf( stderr, "makedep: error: " );
249 vfprintf( stderr, msg, valist );
250 va_end( valist );
251 exit(1);
255 /*******************************************************************
256 * fatal_perror
258 static void fatal_perror( const char *msg, ... )
260 va_list valist;
261 va_start( valist, msg );
262 if (input_file_name)
264 fprintf( stderr, "%s:", input_file_name );
265 if (input_line) fprintf( stderr, "%d:", input_line );
266 fprintf( stderr, " error: " );
268 else fprintf( stderr, "makedep: error: " );
269 vfprintf( stderr, msg, valist );
270 perror( " " );
271 va_end( valist );
272 exit(1);
276 /*******************************************************************
277 * cleanup_files
279 static void cleanup_files(void)
281 if (temp_file_name) unlink( temp_file_name );
282 if (output_file_name) unlink( output_file_name );
286 /*******************************************************************
287 * exit_on_signal
289 static void exit_on_signal( int sig )
291 exit( 1 ); /* this will call the atexit functions */
295 /*******************************************************************
296 * xmalloc
298 static void *xmalloc( size_t size )
300 void *res;
301 if (!(res = malloc (size ? size : 1)))
302 fatal_error( "Virtual memory exhausted.\n" );
303 return res;
307 /*******************************************************************
308 * xrealloc
310 static void *xrealloc (void *ptr, size_t size)
312 void *res;
313 assert( size );
314 if (!(res = realloc( ptr, size )))
315 fatal_error( "Virtual memory exhausted.\n" );
316 return res;
319 /*******************************************************************
320 * xstrdup
322 static char *xstrdup( const char *str )
324 char *res = strdup( str );
325 if (!res) fatal_error( "Virtual memory exhausted.\n" );
326 return res;
330 /*******************************************************************
331 * strmake
333 static char *strmake( const char* fmt, ... )
335 int n;
336 size_t size = 100;
337 va_list ap;
339 for (;;)
341 char *p = xmalloc (size);
342 va_start(ap, fmt);
343 n = vsnprintf (p, size, fmt, ap);
344 va_end(ap);
345 if (n == -1) size *= 2;
346 else if ((size_t)n >= size) size = n + 1;
347 else return xrealloc( p, n + 1 );
348 free(p);
353 /*******************************************************************
354 * strendswith
356 static int strendswith( const char* str, const char* end )
358 size_t l = strlen( str );
359 size_t m = strlen( end );
361 return l >= m && strcmp(str + l - m, end) == 0;
365 /*******************************************************************
366 * output
368 static void output( const char *format, ... )
370 int ret;
371 va_list valist;
373 va_start( valist, format );
374 ret = vfprintf( output_file, format, valist );
375 va_end( valist );
376 if (ret < 0) fatal_perror( "output" );
377 if (format[0] && format[strlen(format) - 1] == '\n') output_column = 0;
378 else output_column += ret;
382 /*******************************************************************
383 * strarray_add
385 static void strarray_add( struct strarray *array, const char *str )
387 if (array->count == array->size)
389 if (array->size) array->size *= 2;
390 else array->size = 16;
391 array->str = xrealloc( array->str, sizeof(array->str[0]) * array->size );
393 array->str[array->count++] = str;
397 /*******************************************************************
398 * strarray_addall
400 static void strarray_addall( struct strarray *array, struct strarray added )
402 unsigned int i;
404 for (i = 0; i < added.count; i++) strarray_add( array, added.str[i] );
408 /*******************************************************************
409 * strarray_exists
411 static int strarray_exists( const struct strarray *array, const char *str )
413 unsigned int i;
415 for (i = 0; i < array->count; i++) if (!strcmp( array->str[i], str )) return 1;
416 return 0;
420 /*******************************************************************
421 * strarray_add_uniq
423 static void strarray_add_uniq( struct strarray *array, const char *str )
425 if (!strarray_exists( array, str )) strarray_add( array, str );
429 /*******************************************************************
430 * strarray_addall_uniq
432 static void strarray_addall_uniq( struct strarray *array, struct strarray added )
434 unsigned int i;
436 for (i = 0; i < added.count; i++) strarray_add_uniq( array, added.str[i] );
440 /*******************************************************************
441 * strarray_get_value
443 * Find a value in a name/value pair string array.
445 static const char *strarray_get_value( const struct strarray *array, const char *name )
447 int pos, res, min = 0, max = array->count / 2 - 1;
449 while (min <= max)
451 pos = (min + max) / 2;
452 if (!(res = strcmp( array->str[pos * 2], name ))) return array->str[pos * 2 + 1];
453 if (res < 0) min = pos + 1;
454 else max = pos - 1;
456 return NULL;
460 /*******************************************************************
461 * strarray_set_value
463 * Define a value in a name/value pair string array.
465 static void strarray_set_value( struct strarray *array, const char *name, const char *value )
467 int i, pos, res, min = 0, max = array->count / 2 - 1;
469 while (min <= max)
471 pos = (min + max) / 2;
472 if (!(res = strcmp( array->str[pos * 2], name )))
474 /* redefining a variable replaces the previous value */
475 array->str[pos * 2 + 1] = value;
476 return;
478 if (res < 0) min = pos + 1;
479 else max = pos - 1;
481 strarray_add( array, NULL );
482 strarray_add( array, NULL );
483 for (i = array->count - 1; i > min * 2 + 1; i--) array->str[i] = array->str[i - 2];
484 array->str[min * 2] = name;
485 array->str[min * 2 + 1] = value;
489 /*******************************************************************
490 * strarray_set_qsort
492 static void strarray_qsort( struct strarray *array, int (*func)(const char **, const char **) )
494 if (array->count) qsort( array->str, array->count, sizeof(*array->str), (void *)func );
498 /*******************************************************************
499 * output_filename
501 static void output_filename( const char *name )
503 if (output_column + strlen(name) + 1 > 100)
505 output( " \\\n" );
506 output( " " );
508 else if (output_column) output( " " );
509 output( "%s", name );
513 /*******************************************************************
514 * output_filenames
516 static void output_filenames( struct strarray array )
518 unsigned int i;
520 for (i = 0; i < array.count; i++) output_filename( array.str[i] );
524 /*******************************************************************
525 * output_rm_filenames
527 static void output_rm_filenames( struct strarray array )
529 static const unsigned int max_cmdline = 30000; /* to be on the safe side */
530 unsigned int i, len;
532 if (!array.count) return;
533 output( "\trm -f" );
534 for (i = len = 0; i < array.count; i++)
536 if (len > max_cmdline)
538 output( "\n" );
539 output( "\trm -f" );
540 len = 0;
542 output_filename( array.str[i] );
543 len += strlen( array.str[i] ) + 1;
545 output( "\n" );
549 /*******************************************************************
550 * get_extension
552 static char *get_extension( char *filename )
554 char *ext = strrchr( filename, '.' );
555 if (ext && strchr( ext, '/' )) ext = NULL;
556 return ext;
560 /*******************************************************************
561 * replace_extension
563 static char *replace_extension( const char *name, const char *old_ext, const char *new_ext )
565 char *ret;
566 size_t name_len = strlen( name );
567 size_t ext_len = strlen( old_ext );
569 if (name_len >= ext_len && !strcmp( name + name_len - ext_len, old_ext )) name_len -= ext_len;
570 ret = xmalloc( name_len + strlen( new_ext ) + 1 );
571 memcpy( ret, name, name_len );
572 strcpy( ret + name_len, new_ext );
573 return ret;
577 /*******************************************************************
578 * replace_filename
580 static char *replace_filename( const char *path, const char *name )
582 const char *p;
583 char *ret;
584 size_t len;
586 if (!path) return xstrdup( name );
587 if (!(p = strrchr( path, '/' ))) return xstrdup( name );
588 len = p - path + 1;
589 ret = xmalloc( len + strlen( name ) + 1 );
590 memcpy( ret, path, len );
591 strcpy( ret + len, name );
592 return ret;
596 /*******************************************************************
597 * strarray_replace_extension
599 static struct strarray strarray_replace_extension( const struct strarray *array,
600 const char *old_ext, const char *new_ext )
602 unsigned int i;
603 struct strarray ret;
605 ret.count = ret.size = array->count;
606 ret.str = xmalloc( sizeof(ret.str[0]) * ret.size );
607 for (i = 0; i < array->count; i++) ret.str[i] = replace_extension( array->str[i], old_ext, new_ext );
608 return ret;
612 /*******************************************************************
613 * replace_substr
615 static char *replace_substr( const char *str, const char *start, size_t len, const char *replace )
617 size_t pos = start - str;
618 char *ret = xmalloc( pos + strlen(replace) + strlen(start + len) + 1 );
619 memcpy( ret, str, pos );
620 strcpy( ret + pos, replace );
621 strcat( ret + pos, start + len );
622 return ret;
626 /*******************************************************************
627 * get_relative_path
629 * Determine where the destination path is located relative to the 'from' path.
631 static char *get_relative_path( const char *from, const char *dest )
633 const char *start;
634 char *ret, *p;
635 unsigned int dotdots = 0;
637 /* a path of "." is equivalent to an empty path */
638 if (!strcmp( from, "." )) from = "";
640 for (;;)
642 while (*from == '/') from++;
643 while (*dest == '/') dest++;
644 start = dest; /* save start of next path element */
645 if (!*from) break;
647 while (*from && *from != '/' && *from == *dest) { from++; dest++; }
648 if ((!*from || *from == '/') && (!*dest || *dest == '/')) continue;
650 /* count remaining elements in 'from' */
653 dotdots++;
654 while (*from && *from != '/') from++;
655 while (*from == '/') from++;
657 while (*from);
658 break;
661 if (!start[0] && !dotdots) return NULL; /* empty path */
663 ret = xmalloc( 3 * dotdots + strlen( start ) + 1 );
664 for (p = ret; dotdots; dotdots--, p += 3) memcpy( p, "../", 3 );
666 if (start[0]) strcpy( p, start );
667 else p[-1] = 0; /* remove trailing slash */
668 return ret;
672 /*******************************************************************
673 * concat_paths
675 static char *concat_paths( const char *base, const char *path )
677 if (!base || !base[0]) return xstrdup( path && path[0] ? path : "." );
678 if (!path || !path[0]) return xstrdup( base );
679 if (path[0] == '/') return xstrdup( path );
680 return strmake( "%s/%s", base, path );
684 /*******************************************************************
685 * base_dir_path
687 static char *base_dir_path( const struct makefile *make, const char *path )
689 return concat_paths( make->base_dir, path );
693 /*******************************************************************
694 * obj_dir_path
696 static char *obj_dir_path( const struct makefile *make, const char *path )
698 return concat_paths( make->obj_dir, path );
702 /*******************************************************************
703 * src_dir_path
705 static char *src_dir_path( const struct makefile *make, const char *path )
707 if (make->src_dir) return concat_paths( make->src_dir, path );
708 return obj_dir_path( make, path );
712 /*******************************************************************
713 * top_obj_dir_path
715 static char *top_obj_dir_path( const struct makefile *make, const char *path )
717 return concat_paths( make->top_obj_dir, path );
721 /*******************************************************************
722 * top_src_dir_path
724 static char *top_src_dir_path( const struct makefile *make, const char *path )
726 if (make->top_src_dir) return concat_paths( make->top_src_dir, path );
727 return top_obj_dir_path( make, path );
731 /*******************************************************************
732 * root_dir_path
734 static char *root_dir_path( const char *path )
736 return concat_paths( root_src_dir, path );
740 /*******************************************************************
741 * tools_dir_path
743 static char *tools_dir_path( const struct makefile *make, const char *path )
745 if (tools_dir) return top_obj_dir_path( make, strmake( "%s/tools/%s", tools_dir, path ));
746 return top_obj_dir_path( make, strmake( "tools/%s", path ));
750 /*******************************************************************
751 * tools_path
753 static char *tools_path( const struct makefile *make, const char *name )
755 return strmake( "%s/%s%s", tools_dir_path( make, name ), name, tools_ext );
759 /*******************************************************************
760 * get_line
762 static char *get_line( FILE *file )
764 static char *buffer;
765 static size_t size;
767 if (!size)
769 size = 1024;
770 buffer = xmalloc( size );
772 if (!fgets( buffer, size, file )) return NULL;
773 input_line++;
775 for (;;)
777 char *p = buffer + strlen(buffer);
778 /* if line is larger than buffer, resize buffer */
779 while (p == buffer + size - 1 && p[-1] != '\n')
781 buffer = xrealloc( buffer, size * 2 );
782 if (!fgets( buffer + size - 1, size + 1, file )) break;
783 p = buffer + strlen(buffer);
784 size *= 2;
786 if (p > buffer && p[-1] == '\n')
788 *(--p) = 0;
789 if (p > buffer && p[-1] == '\r') *(--p) = 0;
790 if (p > buffer && p[-1] == '\\')
792 *(--p) = 0;
793 /* line ends in backslash, read continuation line */
794 if (!fgets( p, size - (p - buffer), file )) return buffer;
795 input_line++;
796 continue;
799 return buffer;
804 /*******************************************************************
805 * hash_filename
807 static unsigned int hash_filename( const char *name )
809 /* FNV-1 hash */
810 unsigned int ret = 2166136261u;
811 while (*name) ret = (ret * 16777619) ^ *name++;
812 return ret % HASH_SIZE;
816 /*******************************************************************
817 * add_file
819 static struct file *add_file( const char *name )
821 struct file *file = xmalloc( sizeof(*file) );
822 memset( file, 0, sizeof(*file) );
823 file->name = xstrdup( name );
824 return file;
828 /*******************************************************************
829 * add_dependency
831 static void add_dependency( struct file *file, const char *name, enum incl_type type )
833 /* enforce some rules for the Wine tree */
835 if (!memcmp( name, "../", 3 ))
836 fatal_error( "#include directive with relative path not allowed\n" );
838 if (!strcmp( name, "config.h" ))
840 if (strendswith( file->name, ".h" ))
841 fatal_error( "config.h must not be included by a header file\n" );
842 if (file->deps_count)
843 fatal_error( "config.h must be included before anything else\n" );
845 else if (!strcmp( name, "wine/port.h" ))
847 if (strendswith( file->name, ".h" ))
848 fatal_error( "wine/port.h must not be included by a header file\n" );
849 if (!file->deps_count) fatal_error( "config.h must be included before wine/port.h\n" );
850 if (file->deps_count > 1)
851 fatal_error( "wine/port.h must be included before everything except config.h\n" );
852 if (strcmp( file->deps[0].name, "config.h" ))
853 fatal_error( "config.h must be included before wine/port.h\n" );
856 if (file->deps_count >= file->deps_size)
858 file->deps_size *= 2;
859 if (file->deps_size < 16) file->deps_size = 16;
860 file->deps = xrealloc( file->deps, file->deps_size * sizeof(*file->deps) );
862 file->deps[file->deps_count].line = input_line;
863 file->deps[file->deps_count].type = type;
864 file->deps[file->deps_count].name = xstrdup( name );
865 file->deps_count++;
869 /*******************************************************************
870 * find_src_file
872 static struct incl_file *find_src_file( const struct makefile *make, const char *name )
874 struct incl_file *file;
876 LIST_FOR_EACH_ENTRY( file, &make->sources, struct incl_file, entry )
877 if (!strcmp( name, file->name )) return file;
878 return NULL;
881 /*******************************************************************
882 * find_include_file
884 static struct incl_file *find_include_file( const struct makefile *make, const char *name )
886 struct incl_file *file;
888 LIST_FOR_EACH_ENTRY( file, &make->includes, struct incl_file, entry )
889 if (!strcmp( name, file->name )) return file;
890 return NULL;
893 /*******************************************************************
894 * add_include
896 * Add an include file if it doesn't already exists.
898 static struct incl_file *add_include( struct makefile *make, struct incl_file *parent,
899 const char *name, int line, enum incl_type type )
901 struct incl_file *include;
903 if (parent->files_count >= parent->files_size)
905 parent->files_size *= 2;
906 if (parent->files_size < 16) parent->files_size = 16;
907 parent->files = xrealloc( parent->files, parent->files_size * sizeof(*parent->files) );
910 LIST_FOR_EACH_ENTRY( include, &make->includes, struct incl_file, entry )
911 if (!strcmp( name, include->name )) goto found;
913 include = xmalloc( sizeof(*include) );
914 memset( include, 0, sizeof(*include) );
915 include->name = xstrdup(name);
916 include->included_by = parent;
917 include->included_line = line;
918 include->type = type;
919 list_add_tail( &make->includes, &include->entry );
920 found:
921 parent->files[parent->files_count++] = include;
922 return include;
926 /*******************************************************************
927 * add_generated_source
929 * Add a generated source file to the list.
931 static struct incl_file *add_generated_source( struct makefile *make,
932 const char *name, const char *filename )
934 struct incl_file *file;
936 if ((file = find_src_file( make, name ))) return file; /* we already have it */
937 file = xmalloc( sizeof(*file) );
938 memset( file, 0, sizeof(*file) );
939 file->file = add_file( name );
940 file->name = xstrdup( name );
941 file->filename = obj_dir_path( make, filename ? filename : name );
942 file->file->flags = FLAG_GENERATED;
943 list_add_tail( &make->sources, &file->entry );
944 return file;
948 /*******************************************************************
949 * parse_include_directive
951 static void parse_include_directive( struct file *source, char *str )
953 char quote, *include, *p = str;
955 while (*p && isspace(*p)) p++;
956 if (*p != '\"' && *p != '<' ) return;
957 quote = *p++;
958 if (quote == '<') quote = '>';
959 include = p;
960 while (*p && (*p != quote)) p++;
961 if (!*p) fatal_error( "malformed include directive '%s'\n", str );
962 *p = 0;
963 add_dependency( source, include, (quote == '>') ? INCL_SYSTEM : INCL_NORMAL );
967 /*******************************************************************
968 * parse_pragma_directive
970 static void parse_pragma_directive( struct file *source, char *str )
972 char *flag, *p = str;
974 if (!isspace( *p )) return;
975 while (*p && isspace(*p)) p++;
976 p = strtok( p, " \t" );
977 if (strcmp( p, "makedep" )) return;
979 while ((flag = strtok( NULL, " \t" )))
981 if (!strcmp( flag, "depend" ))
983 while ((p = strtok( NULL, " \t" ))) add_dependency( source, p, INCL_NORMAL );
984 return;
986 else if (!strcmp( flag, "install" )) source->flags |= FLAG_INSTALL;
988 if (strendswith( source->name, ".idl" ))
990 if (!strcmp( flag, "header" )) source->flags |= FLAG_IDL_HEADER;
991 else if (!strcmp( flag, "proxy" )) source->flags |= FLAG_IDL_PROXY;
992 else if (!strcmp( flag, "client" )) source->flags |= FLAG_IDL_CLIENT;
993 else if (!strcmp( flag, "server" )) source->flags |= FLAG_IDL_SERVER;
994 else if (!strcmp( flag, "ident" )) source->flags |= FLAG_IDL_IDENT;
995 else if (!strcmp( flag, "typelib" )) source->flags |= FLAG_IDL_TYPELIB;
996 else if (!strcmp( flag, "register" )) source->flags |= FLAG_IDL_REGISTER;
997 else if (!strcmp( flag, "regtypelib" )) source->flags |= FLAG_IDL_REGTYPELIB;
999 else if (strendswith( source->name, ".rc" ))
1001 if (!strcmp( flag, "po" )) source->flags |= FLAG_RC_PO;
1003 else if (strendswith( source->name, ".sfd" ))
1005 if (!strcmp( flag, "font" ))
1007 struct strarray *array = source->args;
1009 if (!array)
1011 source->args = array = xmalloc( sizeof(*array) );
1012 *array = empty_strarray;
1013 source->flags |= FLAG_SFD_FONTS;
1015 strarray_add( array, xstrdup( strtok( NULL, "" )));
1016 return;
1019 else if (!strcmp( flag, "implib" )) source->flags |= FLAG_C_IMPLIB;
1024 /*******************************************************************
1025 * parse_cpp_directive
1027 static void parse_cpp_directive( struct file *source, char *str )
1029 while (*str && isspace(*str)) str++;
1030 if (*str++ != '#') return;
1031 while (*str && isspace(*str)) str++;
1033 if (!strncmp( str, "include", 7 ))
1034 parse_include_directive( source, str + 7 );
1035 else if (!strncmp( str, "import", 6 ) && strendswith( source->name, ".m" ))
1036 parse_include_directive( source, str + 6 );
1037 else if (!strncmp( str, "pragma", 6 ))
1038 parse_pragma_directive( source, str + 6 );
1042 /*******************************************************************
1043 * parse_idl_file
1045 static void parse_idl_file( struct file *source, FILE *file )
1047 char *buffer, *include;
1049 input_line = 0;
1051 while ((buffer = get_line( file )))
1053 char quote;
1054 char *p = buffer;
1055 while (*p && isspace(*p)) p++;
1057 if (!strncmp( p, "importlib", 9 ))
1059 p += 9;
1060 while (*p && isspace(*p)) p++;
1061 if (*p++ != '(') continue;
1062 while (*p && isspace(*p)) p++;
1063 if (*p++ != '"') continue;
1064 include = p;
1065 while (*p && (*p != '"')) p++;
1066 if (!*p) fatal_error( "malformed importlib directive\n" );
1067 *p = 0;
1068 add_dependency( source, include, INCL_IMPORTLIB );
1069 continue;
1072 if (!strncmp( p, "import", 6 ))
1074 p += 6;
1075 while (*p && isspace(*p)) p++;
1076 if (*p != '"') continue;
1077 include = ++p;
1078 while (*p && (*p != '"')) p++;
1079 if (!*p) fatal_error( "malformed import directive\n" );
1080 *p = 0;
1081 add_dependency( source, include, INCL_IMPORT );
1082 continue;
1085 /* check for #include inside cpp_quote */
1086 if (!strncmp( p, "cpp_quote", 9 ))
1088 p += 9;
1089 while (*p && isspace(*p)) p++;
1090 if (*p++ != '(') continue;
1091 while (*p && isspace(*p)) p++;
1092 if (*p++ != '"') continue;
1093 if (*p++ != '#') continue;
1094 while (*p && isspace(*p)) p++;
1095 if (strncmp( p, "include", 7 )) continue;
1096 p += 7;
1097 while (*p && isspace(*p)) p++;
1098 if (*p == '\\' && p[1] == '"')
1100 p += 2;
1101 quote = '"';
1103 else
1105 if (*p++ != '<' ) continue;
1106 quote = '>';
1108 include = p;
1109 while (*p && (*p != quote)) p++;
1110 if (!*p || (quote == '"' && p[-1] != '\\'))
1111 fatal_error( "malformed #include directive inside cpp_quote\n" );
1112 if (quote == '"') p--; /* remove backslash */
1113 *p = 0;
1114 add_dependency( source, include, (quote == '>') ? INCL_CPP_QUOTE_SYSTEM : INCL_CPP_QUOTE );
1115 continue;
1118 parse_cpp_directive( source, p );
1122 /*******************************************************************
1123 * parse_c_file
1125 static void parse_c_file( struct file *source, FILE *file )
1127 char *buffer;
1129 input_line = 0;
1130 while ((buffer = get_line( file )))
1132 parse_cpp_directive( source, buffer );
1137 /*******************************************************************
1138 * parse_rc_file
1140 static void parse_rc_file( struct file *source, FILE *file )
1142 char *buffer, *include;
1144 input_line = 0;
1145 while ((buffer = get_line( file )))
1147 char quote;
1148 char *p = buffer;
1149 while (*p && isspace(*p)) p++;
1151 if (p[0] == '/' && p[1] == '*') /* check for magic makedep comment */
1153 p += 2;
1154 while (*p && isspace(*p)) p++;
1155 if (strncmp( p, "@makedep:", 9 )) continue;
1156 p += 9;
1157 while (*p && isspace(*p)) p++;
1158 quote = '"';
1159 if (*p == quote)
1161 include = ++p;
1162 while (*p && *p != quote) p++;
1164 else
1166 include = p;
1167 while (*p && !isspace(*p) && *p != '*') p++;
1169 if (!*p)
1170 fatal_error( "malformed makedep comment\n" );
1171 *p = 0;
1172 add_dependency( source, include, (quote == '>') ? INCL_SYSTEM : INCL_NORMAL );
1173 continue;
1176 parse_cpp_directive( source, buffer );
1181 /*******************************************************************
1182 * parse_in_file
1184 static void parse_in_file( struct file *source, FILE *file )
1186 char *p, *buffer;
1188 /* make sure it gets rebuilt when the version changes */
1189 add_dependency( source, "config.h", INCL_SYSTEM );
1191 if (!strendswith( source->name, ".man.in" )) return; /* not a man page */
1193 input_line = 0;
1194 while ((buffer = get_line( file )))
1196 if (strncmp( buffer, ".TH", 3 )) continue;
1197 if (!(p = strtok( buffer, " \t" ))) continue; /* .TH */
1198 if (!(p = strtok( NULL, " \t" ))) continue; /* program name */
1199 if (!(p = strtok( NULL, " \t" ))) continue; /* man section */
1200 source->args = xstrdup( p );
1201 return;
1206 /*******************************************************************
1207 * parse_sfd_file
1209 static void parse_sfd_file( struct file *source, FILE *file )
1211 char *p, *eol, *buffer;
1213 input_line = 0;
1214 while ((buffer = get_line( file )))
1216 if (strncmp( buffer, "UComments:", 10 )) continue;
1217 p = buffer + 10;
1218 while (*p == ' ') p++;
1219 if (p[0] == '"' && p[1] && buffer[strlen(buffer) - 1] == '"')
1221 p++;
1222 buffer[strlen(buffer) - 1] = 0;
1224 while ((eol = strstr( p, "+AAoA" )))
1226 *eol = 0;
1227 while (*p && isspace(*p)) p++;
1228 if (*p++ == '#')
1230 while (*p && isspace(*p)) p++;
1231 if (!strncmp( p, "pragma", 6 )) parse_pragma_directive( source, p + 6 );
1233 p = eol + 5;
1235 while (*p && isspace(*p)) p++;
1236 if (*p++ != '#') return;
1237 while (*p && isspace(*p)) p++;
1238 if (!strncmp( p, "pragma", 6 )) parse_pragma_directive( source, p + 6 );
1239 return;
1244 static const struct
1246 const char *ext;
1247 void (*parse)( struct file *file, FILE *f );
1248 } parse_functions[] =
1250 { ".c", parse_c_file },
1251 { ".h", parse_c_file },
1252 { ".inl", parse_c_file },
1253 { ".l", parse_c_file },
1254 { ".m", parse_c_file },
1255 { ".rh", parse_c_file },
1256 { ".x", parse_c_file },
1257 { ".y", parse_c_file },
1258 { ".idl", parse_idl_file },
1259 { ".rc", parse_rc_file },
1260 { ".in", parse_in_file },
1261 { ".sfd", parse_sfd_file }
1264 /*******************************************************************
1265 * load_file
1267 static struct file *load_file( const char *name )
1269 struct file *file;
1270 FILE *f;
1271 unsigned int i, hash = hash_filename( name );
1273 LIST_FOR_EACH_ENTRY( file, &files[hash], struct file, entry )
1274 if (!strcmp( name, file->name )) return file;
1276 if (!(f = fopen( name, "r" ))) return NULL;
1278 file = add_file( name );
1279 list_add_tail( &files[hash], &file->entry );
1280 input_file_name = file->name;
1281 input_line = 0;
1283 for (i = 0; i < sizeof(parse_functions) / sizeof(parse_functions[0]); i++)
1285 if (!strendswith( name, parse_functions[i].ext )) continue;
1286 parse_functions[i].parse( file, f );
1287 break;
1290 fclose( f );
1291 input_file_name = NULL;
1293 return file;
1297 /*******************************************************************
1298 * open_include_path_file
1300 * Open a file from a directory on the include path.
1302 static struct file *open_include_path_file( const struct makefile *make, const char *dir,
1303 const char *name, char **filename )
1305 char *src_path = base_dir_path( make, concat_paths( dir, name ));
1306 struct file *ret = load_file( src_path );
1308 if (ret) *filename = src_dir_path( make, concat_paths( dir, name ));
1309 return ret;
1313 /*******************************************************************
1314 * open_file_same_dir
1316 * Open a file in the same directory as the parent.
1318 static struct file *open_file_same_dir( const struct incl_file *parent, const char *name, char **filename )
1320 char *src_path = replace_filename( parent->file->name, name );
1321 struct file *ret = load_file( src_path );
1323 if (ret) *filename = replace_filename( parent->filename, name );
1324 free( src_path );
1325 return ret;
1329 /*******************************************************************
1330 * open_local_file
1332 * Open a file in the source directory of the makefile.
1334 static struct file *open_local_file( const struct makefile *make, const char *path, char **filename )
1336 char *src_path = root_dir_path( base_dir_path( make, path ));
1337 struct file *ret = load_file( src_path );
1339 /* if not found, try parent dir */
1340 if (!ret && make->parent_dir)
1342 free( src_path );
1343 path = strmake( "%s/%s", make->parent_dir, path );
1344 src_path = root_dir_path( base_dir_path( make, path ));
1345 ret = load_file( src_path );
1348 if (ret) *filename = src_dir_path( make, path );
1349 free( src_path );
1350 return ret;
1354 /*******************************************************************
1355 * open_global_file
1357 * Open a file in the top-level source directory.
1359 static struct file *open_global_file( const struct makefile *make, const char *path, char **filename )
1361 char *src_path = root_dir_path( path );
1362 struct file *ret = load_file( src_path );
1364 if (ret) *filename = top_src_dir_path( make, path );
1365 free( src_path );
1366 return ret;
1370 /*******************************************************************
1371 * open_global_header
1373 * Open a file in the global include source directory.
1375 static struct file *open_global_header( const struct makefile *make, const char *path, char **filename )
1377 return open_global_file( make, strmake( "include/%s", path ), filename );
1381 /*******************************************************************
1382 * open_src_file
1384 static struct file *open_src_file( const struct makefile *make, struct incl_file *pFile )
1386 struct file *file = open_local_file( make, pFile->name, &pFile->filename );
1388 if (!file) fatal_perror( "open %s", pFile->name );
1389 return file;
1393 /*******************************************************************
1394 * open_include_file
1396 static struct file *open_include_file( const struct makefile *make, struct incl_file *pFile )
1398 struct file *file = NULL;
1399 char *filename;
1400 unsigned int i, len;
1402 errno = ENOENT;
1404 /* check for generated bison header */
1406 if (strendswith( pFile->name, ".tab.h" ) &&
1407 (file = open_local_file( make, replace_extension( pFile->name, ".tab.h", ".y" ), &filename )))
1409 pFile->sourcename = filename;
1410 pFile->filename = obj_dir_path( make, pFile->name );
1411 return file;
1414 /* check for corresponding idl file in source dir */
1416 if (strendswith( pFile->name, ".h" ) &&
1417 (file = open_local_file( make, replace_extension( pFile->name, ".h", ".idl" ), &filename )))
1419 pFile->sourcename = filename;
1420 pFile->filename = obj_dir_path( make, pFile->name );
1421 return file;
1424 /* check for corresponding tlb file in source dir */
1426 if (strendswith( pFile->name, ".tlb" ) &&
1427 (file = open_local_file( make, replace_extension( pFile->name, ".tlb", ".idl" ), &filename )))
1429 pFile->sourcename = filename;
1430 pFile->filename = obj_dir_path( make, pFile->name );
1431 return file;
1434 /* now try in source dir */
1435 if ((file = open_local_file( make, pFile->name, &pFile->filename ))) return file;
1437 /* check for corresponding idl file in global includes */
1439 if (strendswith( pFile->name, ".h" ) &&
1440 (file = open_global_header( make, replace_extension( pFile->name, ".h", ".idl" ), &filename )))
1442 pFile->sourcename = filename;
1443 pFile->filename = top_obj_dir_path( make, strmake( "include/%s", pFile->name ));
1444 return file;
1447 /* check for corresponding .in file in global includes (for config.h.in) */
1449 if (strendswith( pFile->name, ".h" ) &&
1450 (file = open_global_header( make, replace_extension( pFile->name, ".h", ".h.in" ), &filename )))
1452 pFile->sourcename = filename;
1453 pFile->filename = top_obj_dir_path( make, strmake( "include/%s", pFile->name ));
1454 return file;
1457 /* check for corresponding .x file in global includes */
1459 if (strendswith( pFile->name, "tmpl.h" ) &&
1460 (file = open_global_header( make, replace_extension( pFile->name, ".h", ".x" ), &filename )))
1462 pFile->sourcename = filename;
1463 pFile->filename = top_obj_dir_path( make, strmake( "include/%s", pFile->name ));
1464 return file;
1467 /* check for corresponding .tlb file in global includes */
1469 if (strendswith( pFile->name, ".tlb" ) &&
1470 (file = open_global_header( make, replace_extension( pFile->name, ".tlb", ".idl" ), &filename )))
1472 pFile->sourcename = filename;
1473 pFile->filename = top_obj_dir_path( make, strmake( "include/%s", pFile->name ));
1474 return file;
1477 /* check in global includes source dir */
1479 if ((file = open_global_header( make, pFile->name, &pFile->filename ))) return file;
1481 /* check in global msvcrt includes */
1482 if (make->use_msvcrt &&
1483 (file = open_global_header( make, strmake( "msvcrt/%s", pFile->name ), &pFile->filename )))
1484 return file;
1486 /* now search in include paths */
1487 for (i = 0; i < make->include_paths.count; i++)
1489 const char *dir = make->include_paths.str[i];
1490 const char *prefix = make->top_src_dir ? make->top_src_dir : make->top_obj_dir;
1492 if (prefix)
1494 len = strlen( prefix );
1495 if (!strncmp( dir, prefix, len ) && (!dir[len] || dir[len] == '/'))
1497 while (dir[len] == '/') len++;
1498 file = open_global_file( make, concat_paths( dir + len, pFile->name ), &pFile->filename );
1499 if (file) return file;
1501 if (make->top_src_dir) continue; /* ignore paths that don't point to the top source dir */
1503 if (*dir != '/')
1505 if ((file = open_include_path_file( make, dir, pFile->name, &pFile->filename )))
1506 return file;
1509 if (pFile->type == INCL_SYSTEM) return NULL; /* ignore system files we cannot find */
1511 /* try in src file directory */
1512 if ((file = open_file_same_dir( pFile->included_by, pFile->name, &pFile->filename ))) return file;
1514 fprintf( stderr, "%s:%d: error: ", pFile->included_by->file->name, pFile->included_line );
1515 perror( pFile->name );
1516 pFile = pFile->included_by;
1517 while (pFile && pFile->included_by)
1519 const char *parent = pFile->included_by->sourcename;
1520 if (!parent) parent = pFile->included_by->file->name;
1521 fprintf( stderr, "%s:%d: note: %s was first included here\n",
1522 parent, pFile->included_line, pFile->name );
1523 pFile = pFile->included_by;
1525 exit(1);
1529 /*******************************************************************
1530 * add_all_includes
1532 static void add_all_includes( struct makefile *make, struct incl_file *parent, struct file *file )
1534 unsigned int i;
1536 parent->files_count = 0;
1537 parent->files_size = file->deps_count;
1538 parent->files = xmalloc( parent->files_size * sizeof(*parent->files) );
1539 for (i = 0; i < file->deps_count; i++)
1541 switch (file->deps[i].type)
1543 case INCL_NORMAL:
1544 case INCL_IMPORT:
1545 add_include( make, parent, file->deps[i].name, file->deps[i].line, INCL_NORMAL );
1546 break;
1547 case INCL_IMPORTLIB:
1548 add_include( make, parent, file->deps[i].name, file->deps[i].line, INCL_IMPORTLIB );
1549 break;
1550 case INCL_SYSTEM:
1551 add_include( make, parent, file->deps[i].name, file->deps[i].line, INCL_SYSTEM );
1552 break;
1553 case INCL_CPP_QUOTE:
1554 case INCL_CPP_QUOTE_SYSTEM:
1555 break;
1561 /*******************************************************************
1562 * parse_file
1564 static void parse_file( struct makefile *make, struct incl_file *source, int src )
1566 struct file *file = src ? open_src_file( make, source ) : open_include_file( make, source );
1568 if (!file) return;
1570 source->file = file;
1571 source->files_count = 0;
1572 source->files_size = file->deps_count;
1573 source->files = xmalloc( source->files_size * sizeof(*source->files) );
1575 if (source->sourcename)
1577 if (strendswith( source->sourcename, ".idl" ))
1579 unsigned int i;
1581 if (strendswith( source->name, ".tlb" )) return; /* typelibs don't include anything */
1583 /* generated .h file always includes these */
1584 add_include( make, source, "rpc.h", 0, INCL_NORMAL );
1585 add_include( make, source, "rpcndr.h", 0, INCL_NORMAL );
1586 for (i = 0; i < file->deps_count; i++)
1588 switch (file->deps[i].type)
1590 case INCL_IMPORT:
1591 if (strendswith( file->deps[i].name, ".idl" ))
1592 add_include( make, source, replace_extension( file->deps[i].name, ".idl", ".h" ),
1593 file->deps[i].line, INCL_NORMAL );
1594 else
1595 add_include( make, source, file->deps[i].name, file->deps[i].line, INCL_NORMAL );
1596 break;
1597 case INCL_CPP_QUOTE:
1598 add_include( make, source, file->deps[i].name, file->deps[i].line, INCL_NORMAL );
1599 break;
1600 case INCL_CPP_QUOTE_SYSTEM:
1601 add_include( make, source, file->deps[i].name, file->deps[i].line, INCL_SYSTEM );
1602 break;
1603 case INCL_NORMAL:
1604 case INCL_SYSTEM:
1605 case INCL_IMPORTLIB:
1606 break;
1609 return;
1611 if (strendswith( source->sourcename, ".y" ))
1612 return; /* generated .tab.h doesn't include anything */
1615 add_all_includes( make, source, file );
1619 /*******************************************************************
1620 * add_src_file
1622 * Add a source file to the list.
1624 static struct incl_file *add_src_file( struct makefile *make, const char *name )
1626 struct incl_file *file;
1628 if ((file = find_src_file( make, name ))) return file; /* we already have it */
1629 file = xmalloc( sizeof(*file) );
1630 memset( file, 0, sizeof(*file) );
1631 file->name = xstrdup(name);
1632 list_add_tail( &make->sources, &file->entry );
1633 parse_file( make, file, 1 );
1634 return file;
1638 /*******************************************************************
1639 * open_input_makefile
1641 static FILE *open_input_makefile( const struct makefile *make )
1643 FILE *ret;
1645 if (make->base_dir)
1646 input_file_name = root_dir_path( base_dir_path( make, strmake( "%s.in", output_makefile_name )));
1647 else
1648 input_file_name = output_makefile_name; /* always use output name for main Makefile */
1650 input_line = 0;
1651 if (!(ret = fopen( input_file_name, "r" ))) fatal_perror( "open" );
1652 return ret;
1656 /*******************************************************************
1657 * get_make_variable
1659 static const char *get_make_variable( const struct makefile *make, const char *name )
1661 const char *ret;
1663 if ((ret = strarray_get_value( &cmdline_vars, name ))) return ret;
1664 if ((ret = strarray_get_value( &make->vars, name ))) return ret;
1665 if (top_makefile && (ret = strarray_get_value( &top_makefile->vars, name ))) return ret;
1666 return NULL;
1670 /*******************************************************************
1671 * get_expanded_make_variable
1673 static char *get_expanded_make_variable( const struct makefile *make, const char *name )
1675 const char *var;
1676 char *p, *end, *expand, *tmp;
1678 var = get_make_variable( make, name );
1679 if (!var) return NULL;
1681 p = expand = xstrdup( var );
1682 while ((p = strchr( p, '$' )))
1684 if (p[1] == '(')
1686 if (!(end = strchr( p + 2, ')' ))) fatal_error( "syntax error in '%s'\n", expand );
1687 *end++ = 0;
1688 if (strchr( p + 2, ':' )) fatal_error( "pattern replacement not supported for '%s'\n", p + 2 );
1689 var = get_make_variable( make, p + 2 );
1690 tmp = replace_substr( expand, p, end - p, var ? var : "" );
1691 /* switch to the new string */
1692 p = tmp + (p - expand);
1693 free( expand );
1694 expand = tmp;
1696 else if (p[1] == '{') /* don't expand ${} variables */
1698 if (!(end = strchr( p + 2, '}' ))) fatal_error( "syntax error in '%s'\n", expand );
1699 p = end + 1;
1701 else if (p[1] == '$')
1703 p += 2;
1705 else fatal_error( "syntax error in '%s'\n", expand );
1708 /* consider empty variables undefined */
1709 p = expand;
1710 while (*p && isspace(*p)) p++;
1711 if (*p) return expand;
1712 free( expand );
1713 return NULL;
1717 /*******************************************************************
1718 * get_expanded_make_var_array
1720 static struct strarray get_expanded_make_var_array( const struct makefile *make, const char *name )
1722 struct strarray ret = empty_strarray;
1723 char *value, *token;
1725 if ((value = get_expanded_make_variable( make, name )))
1726 for (token = strtok( value, " \t" ); token; token = strtok( NULL, " \t" ))
1727 strarray_add( &ret, token );
1728 return ret;
1732 /*******************************************************************
1733 * get_expanded_file_local_var
1735 static struct strarray get_expanded_file_local_var( const struct makefile *make, const char *file,
1736 const char *name )
1738 char *p, *var = strmake( "%s_%s", file, name );
1740 for (p = var; *p; p++) if (!isalnum( *p )) *p = '_';
1741 return get_expanded_make_var_array( make, var );
1745 /*******************************************************************
1746 * set_make_variable
1748 static int set_make_variable( struct strarray *array, const char *assignment )
1750 char *p, *name;
1752 p = name = xstrdup( assignment );
1753 while (isalnum(*p) || *p == '_') p++;
1754 if (name == p) return 0; /* not a variable */
1755 if (isspace(*p))
1757 *p++ = 0;
1758 while (isspace(*p)) p++;
1760 if (*p != '=') return 0; /* not an assignment */
1761 *p++ = 0;
1762 while (isspace(*p)) p++;
1764 strarray_set_value( array, name, p );
1765 return 1;
1769 /*******************************************************************
1770 * parse_makefile
1772 static struct makefile *parse_makefile( const char *path )
1774 char *buffer;
1775 FILE *file;
1776 struct makefile *make = xmalloc( sizeof(*make) );
1778 memset( make, 0, sizeof(*make) );
1779 if (path)
1781 make->top_obj_dir = get_relative_path( path, "" );
1782 make->base_dir = path;
1783 if (!strcmp( make->base_dir, "." )) make->base_dir = NULL;
1786 file = open_input_makefile( make );
1787 while ((buffer = get_line( file )))
1789 if (!strncmp( buffer, separator, strlen(separator) )) break;
1790 if (*buffer == '\t') continue; /* command */
1791 while (isspace( *buffer )) buffer++;
1792 if (*buffer == '#') continue; /* comment */
1793 set_make_variable( &make->vars, buffer );
1795 fclose( file );
1796 input_file_name = NULL;
1797 return make;
1801 /*******************************************************************
1802 * add_generated_sources
1804 static void add_generated_sources( struct makefile *make )
1806 struct incl_file *source, *next, *file;
1808 LIST_FOR_EACH_ENTRY_SAFE( source, next, &make->sources, struct incl_file, entry )
1810 if (source->file->flags & FLAG_IDL_CLIENT)
1812 file = add_generated_source( make, replace_extension( source->name, ".idl", "_c.c" ), NULL );
1813 add_dependency( file->file, replace_extension( source->name, ".idl", ".h" ), INCL_NORMAL );
1814 add_all_includes( make, file, file->file );
1816 if (source->file->flags & FLAG_IDL_SERVER)
1818 file = add_generated_source( make, replace_extension( source->name, ".idl", "_s.c" ), NULL );
1819 add_dependency( file->file, "wine/exception.h", INCL_NORMAL );
1820 add_dependency( file->file, replace_extension( source->name, ".idl", ".h" ), INCL_NORMAL );
1821 add_all_includes( make, file, file->file );
1823 if (source->file->flags & FLAG_IDL_IDENT)
1825 file = add_generated_source( make, replace_extension( source->name, ".idl", "_i.c" ), NULL );
1826 add_dependency( file->file, "rpc.h", INCL_NORMAL );
1827 add_dependency( file->file, "rpcndr.h", INCL_NORMAL );
1828 add_dependency( file->file, "guiddef.h", INCL_NORMAL );
1829 add_all_includes( make, file, file->file );
1831 if (source->file->flags & FLAG_IDL_PROXY)
1833 file = add_generated_source( make, "dlldata.o", "dlldata.c" );
1834 add_dependency( file->file, "objbase.h", INCL_NORMAL );
1835 add_dependency( file->file, "rpcproxy.h", INCL_NORMAL );
1836 add_all_includes( make, file, file->file );
1837 file = add_generated_source( make, replace_extension( source->name, ".idl", "_p.c" ), NULL );
1838 add_dependency( file->file, "objbase.h", INCL_NORMAL );
1839 add_dependency( file->file, "rpcproxy.h", INCL_NORMAL );
1840 add_dependency( file->file, "wine/exception.h", INCL_NORMAL );
1841 add_dependency( file->file, replace_extension( source->name, ".idl", ".h" ), INCL_NORMAL );
1842 add_all_includes( make, file, file->file );
1844 if (source->file->flags & FLAG_IDL_TYPELIB)
1846 add_generated_source( make, replace_extension( source->name, ".idl", ".tlb" ), NULL );
1848 if (source->file->flags & FLAG_IDL_REGTYPELIB)
1850 add_generated_source( make, replace_extension( source->name, ".idl", "_t.res" ), NULL );
1852 if (source->file->flags & FLAG_IDL_REGISTER)
1854 add_generated_source( make, replace_extension( source->name, ".idl", "_r.res" ), NULL );
1856 if (source->file->flags & FLAG_IDL_HEADER)
1858 add_generated_source( make, replace_extension( source->name, ".idl", ".h" ), NULL );
1860 if (!source->file->flags && strendswith( source->name, ".idl" ))
1862 add_generated_source( make, replace_extension( source->name, ".idl", ".h" ), NULL );
1864 if (strendswith( source->name, ".x" ))
1866 add_generated_source( make, replace_extension( source->name, ".x", ".h" ), NULL );
1868 if (strendswith( source->name, ".y" ))
1870 file = add_generated_source( make, replace_extension( source->name, ".y", ".tab.c" ), NULL );
1871 /* steal the includes list from the source file */
1872 file->files_count = source->files_count;
1873 file->files_size = source->files_size;
1874 file->files = source->files;
1875 source->files_count = source->files_size = 0;
1876 source->files = NULL;
1878 if (strendswith( source->name, ".l" ))
1880 file = add_generated_source( make, replace_extension( source->name, ".l", ".yy.c" ), NULL );
1881 /* steal the includes list from the source file */
1882 file->files_count = source->files_count;
1883 file->files_size = source->files_size;
1884 file->files = source->files;
1885 source->files_count = source->files_size = 0;
1886 source->files = NULL;
1888 if (source->file->flags & FLAG_C_IMPLIB)
1890 if (!make->staticimplib && make->importlib && *dll_ext)
1891 make->staticimplib = strmake( "lib%s.a", make->importlib );
1893 if (strendswith( source->name, ".po" ))
1895 if (!make->disabled)
1896 strarray_add_uniq( &linguas, replace_extension( source->name, ".po", "" ));
1899 if (make->testdll)
1901 file = add_generated_source( make, "testlist.o", "testlist.c" );
1902 add_dependency( file->file, "wine/test.h", INCL_NORMAL );
1903 add_all_includes( make, file, file->file );
1908 /*******************************************************************
1909 * create_dir
1911 static void create_dir( const char *dir )
1913 char *p, *path;
1915 p = path = xstrdup( dir );
1916 while ((p = strchr( p, '/' )))
1918 *p = 0;
1919 if (mkdir( path, 0755 ) == -1 && errno != EEXIST) fatal_perror( "mkdir %s", path );
1920 *p++ = '/';
1921 while (*p == '/') p++;
1923 if (mkdir( path, 0755 ) == -1 && errno != EEXIST) fatal_perror( "mkdir %s", path );
1924 free( path );
1928 /*******************************************************************
1929 * create_file_directories
1931 * Create the base directories of all the files.
1933 static void create_file_directories( const struct makefile *make, struct strarray files )
1935 struct strarray subdirs = empty_strarray;
1936 unsigned int i;
1937 char *dir;
1939 for (i = 0; i < files.count; i++)
1941 if (!strchr( files.str[i], '/' )) continue;
1942 dir = base_dir_path( make, files.str[i] );
1943 *strrchr( dir, '/' ) = 0;
1944 strarray_add_uniq( &subdirs, dir );
1947 for (i = 0; i < subdirs.count; i++) create_dir( subdirs.str[i] );
1951 /*******************************************************************
1952 * output_filenames_obj_dir
1954 static void output_filenames_obj_dir( const struct makefile *make, struct strarray array )
1956 unsigned int i;
1958 for (i = 0; i < array.count; i++) output_filename( obj_dir_path( make, array.str[i] ));
1962 /*******************************************************************
1963 * get_dependencies
1965 static void get_dependencies( struct incl_file *file, struct incl_file *source )
1967 unsigned int i;
1969 if (!file->filename) return;
1971 if (file != source)
1973 if (file->owner == source) return; /* already processed */
1974 if (file->type == INCL_IMPORTLIB &&
1975 !(source->file->flags & (FLAG_IDL_TYPELIB | FLAG_IDL_REGTYPELIB)))
1976 return; /* library is imported only when building a typelib */
1977 file->owner = source;
1978 strarray_add( &source->dependencies, file->filename );
1980 for (i = 0; i < file->files_count; i++) get_dependencies( file->files[i], source );
1984 /*******************************************************************
1985 * get_local_dependencies
1987 * Get the local dependencies of a given target.
1989 static struct strarray get_local_dependencies( const struct makefile *make, const char *name,
1990 struct strarray targets )
1992 unsigned int i;
1993 struct strarray deps = get_expanded_file_local_var( make, name, "DEPS" );
1995 for (i = 0; i < deps.count; i++)
1997 if (strarray_exists( &targets, deps.str[i] ))
1998 deps.str[i] = obj_dir_path( make, deps.str[i] );
1999 else
2000 deps.str[i] = src_dir_path( make, deps.str[i] );
2002 return deps;
2006 /*******************************************************************
2007 * get_static_lib
2009 * Check if makefile builds the named static library and return the full lib path.
2011 static const char *get_static_lib( const struct makefile *make, const char *name )
2013 if (!make->staticlib) return NULL;
2014 if (strncmp( make->staticlib, "lib", 3 )) return NULL;
2015 if (strncmp( make->staticlib + 3, name, strlen(name) )) return NULL;
2016 if (strcmp( make->staticlib + 3 + strlen(name), ".a" )) return NULL;
2017 return base_dir_path( make, make->staticlib );
2021 /*******************************************************************
2022 * add_default_libraries
2024 static struct strarray add_default_libraries( const struct makefile *make, struct strarray *deps )
2026 struct strarray ret = empty_strarray;
2027 struct strarray all_libs = empty_strarray;
2028 unsigned int i, j;
2030 strarray_add( &all_libs, "-lwine_port" );
2031 strarray_addall( &all_libs, get_expanded_make_var_array( make, "EXTRALIBS" ));
2032 strarray_addall( &all_libs, libs );
2034 for (i = 0; i < all_libs.count; i++)
2036 const char *lib = NULL;
2038 if (!strncmp( all_libs.str[i], "-l", 2 ))
2040 const char *name = all_libs.str[i] + 2;
2042 for (j = 0; j < top_makefile->subdirs.count; j++)
2044 const struct makefile *submake = top_makefile->submakes[j];
2046 if ((lib = get_static_lib( submake, name ))) break;
2050 if (lib)
2052 lib = top_obj_dir_path( make, lib );
2053 strarray_add( deps, lib );
2054 strarray_add( &ret, lib );
2056 else strarray_add( &ret, all_libs.str[i] );
2058 return ret;
2062 /*******************************************************************
2063 * add_import_libs
2065 static struct strarray add_import_libs( const struct makefile *make, struct strarray *deps,
2066 struct strarray imports, int cross )
2068 struct strarray ret = empty_strarray;
2069 unsigned int i, j;
2071 for (i = 0; i < imports.count; i++)
2073 const char *name = imports.str[i];
2074 const char *lib = NULL;
2076 for (j = 0; j < top_makefile->subdirs.count; j++)
2078 const struct makefile *submake = top_makefile->submakes[j];
2080 if (submake->importlib && !strcmp( submake->importlib, name ))
2082 if (cross || !*dll_ext || submake->staticimplib)
2083 lib = base_dir_path( submake, strmake( "lib%s.a", name ));
2084 else
2085 strarray_add( deps, top_obj_dir_path( make,
2086 strmake( "%s/lib%s.def", submake->base_dir, name )));
2087 break;
2090 if ((lib = get_static_lib( submake, name ))) break;
2093 if (lib)
2095 if (cross) lib = replace_extension( lib, ".a", ".cross.a" );
2096 lib = top_obj_dir_path( make, lib );
2097 strarray_add( deps, lib );
2098 strarray_add( &ret, lib );
2100 else strarray_add( &ret, strmake( "-l%s", name ));
2102 return ret;
2106 /*******************************************************************
2107 * get_default_imports
2109 static struct strarray get_default_imports( const struct makefile *make )
2111 struct strarray ret = empty_strarray;
2113 if (strarray_exists( &make->extradllflags, "-nodefaultlibs" )) return ret;
2114 if (strarray_exists( &make->appmode, "-mno-cygwin" )) strarray_add( &ret, "msvcrt" );
2115 if (make->is_win16) strarray_add( &ret, "kernel" );
2116 strarray_add( &ret, "kernel32" );
2117 strarray_add( &ret, "ntdll" );
2118 strarray_add( &ret, "winecrt0" );
2119 return ret;
2123 /*******************************************************************
2124 * add_install_rule
2126 static void add_install_rule( struct makefile *make, const char *target,
2127 const char *file, const char *dest )
2129 if (strarray_exists( &make->install_lib, target ))
2131 strarray_add( &make->install_rules[INSTALL_LIB], file );
2132 strarray_add( &make->install_rules[INSTALL_LIB], dest );
2134 else if (strarray_exists( &make->install_dev, target ))
2136 strarray_add( &make->install_rules[INSTALL_DEV], file );
2137 strarray_add( &make->install_rules[INSTALL_DEV], dest );
2142 /*******************************************************************
2143 * get_include_install_path
2145 * Determine the installation path for a given include file.
2147 static const char *get_include_install_path( const char *name )
2149 if (!strncmp( name, "wine/", 5 )) return name + 5;
2150 if (!strncmp( name, "msvcrt/", 7 )) return name;
2151 return strmake( "windows/%s", name );
2155 /*******************************************************************
2156 * get_shared_library_name
2158 * Determine possible names for a shared library with a version number.
2160 static struct strarray get_shared_lib_names( const char *libname )
2162 struct strarray ret = empty_strarray;
2163 const char *ext, *p;
2164 char *name, *first, *second;
2165 size_t len = 0;
2167 strarray_add( &ret, libname );
2169 for (p = libname; (p = strchr( p, '.' )); p++)
2170 if ((len = strspn( p + 1, "0123456789." ))) break;
2172 if (!len) return ret;
2173 ext = p + 1 + len;
2174 if (*ext && ext[-1] == '.') ext--;
2176 /* keep only the first group of digits */
2177 name = xstrdup( libname );
2178 first = name + (p - libname);
2179 if ((second = strchr( first + 1, '.' )))
2181 strcpy( second, ext );
2182 strarray_add( &ret, xstrdup( name ));
2184 /* now remove all digits */
2185 strcpy( first, ext );
2186 strarray_add( &ret, name );
2187 return ret;
2191 /*******************************************************************
2192 * output_symlink_rule
2194 * Output a rule to create a symlink.
2196 static void output_symlink_rule( const char *src_name, const char *link_name )
2198 const char *name;
2200 output( "\trm -f %s && ", link_name );
2202 /* dest path with a directory needs special handling if ln -s isn't supported */
2203 if (strcmp( ln_s, "ln -s" ) && ((name = strrchr( link_name, '/' ))))
2205 char *dir = xstrdup( link_name );
2206 dir[name - link_name] = 0;
2207 output( "cd %s && %s %s %s\n", *dir ? dir : "/", ln_s, src_name, name + 1 );
2208 free( dir );
2210 else
2212 output( "%s %s %s\n", ln_s, src_name, link_name );
2217 /*******************************************************************
2218 * output_install_commands
2220 static void output_install_commands( struct makefile *make, const struct makefile *submake,
2221 struct strarray files )
2223 unsigned int i;
2224 char *install_sh = top_src_dir_path( make, "tools/install-sh" );
2226 for (i = 0; i < files.count; i += 2)
2228 const char *file = files.str[i];
2229 const char *dest = strmake( "$(DESTDIR)%s", files.str[i + 1] + 1 );
2231 if (submake) file = base_dir_path( submake, file );
2232 switch (*files.str[i + 1])
2234 case 'd': /* data file */
2235 output( "\t%s -m 644 $(INSTALL_DATA_FLAGS) %s %s\n",
2236 install_sh, obj_dir_path( make, file ), dest );
2237 break;
2238 case 'D': /* data file in source dir */
2239 output( "\t%s -m 644 $(INSTALL_DATA_FLAGS) %s %s\n",
2240 install_sh, src_dir_path( make, file ), dest );
2241 break;
2242 case 'p': /* program file */
2243 output( "\tSTRIPPROG=\"$(STRIP)\" %s $(INSTALL_PROGRAM_FLAGS) %s %s\n",
2244 install_sh, obj_dir_path( make, file ), dest );
2245 break;
2246 case 's': /* script */
2247 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s %s\n",
2248 install_sh, obj_dir_path( make, file ), dest );
2249 break;
2250 case 'S': /* script in source dir */
2251 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s %s\n",
2252 install_sh, src_dir_path( make, file ), dest );
2253 break;
2254 case 't': /* script in tools dir */
2255 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s %s\n",
2256 install_sh, tools_dir_path( make, files.str[i] ), dest );
2257 break;
2258 case 'y': /* symlink */
2259 output_symlink_rule( files.str[i], dest );
2260 break;
2261 default:
2262 assert(0);
2264 strarray_add( &make->uninstall_files, dest );
2269 /*******************************************************************
2270 * output_install_rules
2272 * Rules are stored as a (file,dest) pair of values.
2273 * The first char of dest indicates the type of install.
2275 static void output_install_rules( struct makefile *make, enum install_rules rules, const char *target )
2277 unsigned int i;
2278 struct strarray files = make->install_rules[rules];
2279 struct strarray targets = empty_strarray;
2281 if (!files.count) return;
2283 for (i = 0; i < files.count; i += 2)
2285 const char *file = files.str[i];
2286 switch (*files.str[i + 1])
2288 case 'd': /* data file */
2289 case 'p': /* program file */
2290 case 's': /* script */
2291 strarray_add_uniq( &targets, obj_dir_path( make, file ));
2292 break;
2293 case 't': /* script in tools dir */
2294 strarray_add_uniq( &targets, tools_dir_path( make, file ));
2295 break;
2299 output( "install %s::", target );
2300 output_filenames( targets );
2301 output( "\n" );
2302 output_install_commands( make, NULL, files );
2304 strarray_add_uniq( &make->phony_targets, "install" );
2305 strarray_add_uniq( &make->phony_targets, target );
2309 static int cmp_string_length( const char **a, const char **b )
2311 int paths_a = 0, paths_b = 0;
2312 const char *p;
2314 for (p = *a; *p; p++) if (*p == '/') paths_a++;
2315 for (p = *b; *p; p++) if (*p == '/') paths_b++;
2316 if (paths_b != paths_a) return paths_b - paths_a;
2317 return strcmp( *a, *b );
2320 /*******************************************************************
2321 * output_uninstall_rules
2323 static void output_uninstall_rules( struct makefile *make )
2325 static const char *dirs_order[] =
2326 { "$(includedir)", "$(mandir)", "$(fontdir)", "$(datadir)", "$(dlldir)" };
2328 struct strarray subdirs = empty_strarray;
2329 unsigned int i, j;
2331 if (!make->uninstall_files.count) return;
2332 output( "uninstall::\n" );
2333 output_rm_filenames( make->uninstall_files );
2334 strarray_add_uniq( &make->phony_targets, "uninstall" );
2336 if (!make->subdirs.count) return;
2337 for (i = 0; i < make->uninstall_files.count; i++)
2339 char *dir = xstrdup( make->uninstall_files.str[i] );
2340 while (strchr( dir, '/' ))
2342 *strrchr( dir, '/' ) = 0;
2343 strarray_add_uniq( &subdirs, xstrdup(dir) );
2346 strarray_qsort( &subdirs, cmp_string_length );
2347 output( "\t-rmdir" );
2348 for (i = 0; i < sizeof(dirs_order)/sizeof(dirs_order[0]); i++)
2350 for (j = 0; j < subdirs.count; j++)
2352 if (!subdirs.str[j]) continue;
2353 if (strncmp( subdirs.str[j] + strlen("$(DESTDIR)"), dirs_order[i], strlen(dirs_order[i]) ))
2354 continue;
2355 output_filename( subdirs.str[j] );
2356 subdirs.str[j] = NULL;
2359 for (j = 0; j < subdirs.count; j++)
2360 if (subdirs.str[j]) output_filename( subdirs.str[j] );
2361 output( "\n" );
2365 /*******************************************************************
2366 * output_importlib_symlinks
2368 static struct strarray output_importlib_symlinks( const struct makefile *parent,
2369 const struct makefile *make )
2371 struct strarray ret = empty_strarray;
2372 const char *lib, *dst;
2374 if (!make->module) return ret;
2375 if (!make->importlib) return ret;
2376 if (make->is_win16 && make->disabled) return ret;
2377 if (strncmp( make->base_dir, "dlls/", 5 )) return ret;
2378 if (!strcmp( make->module, make->importlib )) return ret;
2379 if (!strchr( make->importlib, '.' ) &&
2380 !strncmp( make->module, make->importlib, strlen( make->importlib )) &&
2381 !strcmp( make->module + strlen( make->importlib ), ".dll" ))
2382 return ret;
2384 lib = strmake( "lib%s.%s", make->importlib, *dll_ext ? "def" : "a" );
2385 dst = concat_paths( obj_dir_path( parent, "dlls" ), lib );
2386 output( "%s: %s\n", dst, base_dir_path( make, lib ));
2387 output_symlink_rule( concat_paths( make->base_dir + strlen("dlls/"), lib ), dst );
2388 strarray_add( &ret, dst );
2390 if (crosstarget && !make->is_win16)
2392 lib = strmake( "lib%s.cross.a", make->importlib );
2393 dst = concat_paths( obj_dir_path( parent, "dlls" ), lib );
2394 output( "%s: %s\n", dst, base_dir_path( make, lib ));
2395 output_symlink_rule( concat_paths( make->base_dir + strlen("dlls/"), lib ), dst );
2396 strarray_add( &ret, dst );
2398 return ret;
2402 /*******************************************************************
2403 * output_po_files
2405 static void output_po_files( const struct makefile *make )
2407 const char *po_dir = src_dir_path( make, "po" );
2408 struct strarray pot_files = empty_strarray;
2409 struct incl_file *source;
2410 unsigned int i;
2412 for (i = 0; i < make->subdirs.count; i++)
2414 struct makefile *submake = make->submakes[i];
2416 LIST_FOR_EACH_ENTRY( source, &submake->sources, struct incl_file, entry )
2418 if (strendswith( source->name, ".rc" ) && (source->file->flags & FLAG_RC_PO))
2420 char *pot_file = replace_extension( source->name, ".rc", ".pot" );
2421 char *pot_path = base_dir_path( submake, pot_file );
2422 output( "%s: tools/wrc include dummy\n", pot_path );
2423 output( "\t@cd %s && $(MAKE) %s\n", base_dir_path( submake, "" ), pot_file );
2424 strarray_add( &pot_files, pot_path );
2426 else if (strendswith( source->name, ".mc" ))
2428 char *pot_file = replace_extension( source->name, ".mc", ".pot" );
2429 char *pot_path = base_dir_path( submake, pot_file );
2430 output( "%s: tools/wmc include dummy\n", pot_path );
2431 output( "\t@cd %s && $(MAKE) %s\n", base_dir_path( submake, "" ), pot_file );
2432 strarray_add( &pot_files, pot_path );
2436 if (linguas.count)
2438 for (i = 0; i < linguas.count; i++)
2439 output_filename( strmake( "%s/%s.po", po_dir, linguas.str[i] ));
2440 output( ": %s/wine.pot\n", po_dir );
2441 output( "\tmsgmerge --previous -q $@ %s/wine.pot | msgattrib --no-obsolete -o $@.new && mv $@.new $@\n",
2442 po_dir );
2443 output( "po:" );
2444 for (i = 0; i < linguas.count; i++)
2445 output_filename( strmake( "%s/%s.po", po_dir, linguas.str[i] ));
2446 output( "\n" );
2448 output( "%s/wine.pot:", po_dir );
2449 output_filenames( pot_files );
2450 output( "\n" );
2451 output( "\tmsgcat -o $@" );
2452 output_filenames( pot_files );
2453 output( "\n" );
2457 /*******************************************************************
2458 * output_source_y
2460 static void output_source_y( struct makefile *make, struct incl_file *source, const char *obj )
2462 /* add source file dependency for parallel makes */
2463 char *header = strmake( "%s.tab.h", obj );
2465 if (find_include_file( make, header ))
2467 output( "%s: %s\n", obj_dir_path( make, header ), source->filename );
2468 output( "\t$(BISON) -p %s_ -o %s.tab.c -d %s\n",
2469 obj, obj_dir_path( make, obj ), source->filename );
2470 output( "%s.tab.c: %s %s\n", obj_dir_path( make, obj ),
2471 source->filename, obj_dir_path( make, header ));
2472 strarray_add( &make->clean_files, header );
2474 else output( "%s.tab.c: %s\n", obj, source->filename );
2476 output( "\t$(BISON) -p %s_ -o $@ %s\n", obj, source->filename );
2480 /*******************************************************************
2481 * output_source_l
2483 static void output_source_l( struct makefile *make, struct incl_file *source, const char *obj )
2485 output( "%s.yy.c: %s\n", obj_dir_path( make, obj ), source->filename );
2486 output( "\t$(FLEX) -o$@ %s\n", source->filename );
2490 /*******************************************************************
2491 * output_source_h
2493 static void output_source_h( struct makefile *make, struct incl_file *source, const char *obj )
2495 if (source->file->flags & FLAG_GENERATED)
2497 strarray_add( &make->all_targets, source->name );
2499 else
2501 strarray_add( &make->install_rules[INSTALL_DEV], source->name );
2502 strarray_add( &make->install_rules[INSTALL_DEV],
2503 strmake( "D$(includedir)/wine/%s", get_include_install_path( source->name ) ));
2508 /*******************************************************************
2509 * output_source_rc
2511 static void output_source_rc( struct makefile *make, struct incl_file *source, const char *obj )
2513 struct strarray extradefs = get_expanded_file_local_var( make, obj, "EXTRADEFS" );
2514 unsigned int i;
2516 strarray_add( &make->object_files, strmake( "%s.res", obj ));
2517 if (crosstarget) strarray_add( &make->crossobj_files, strmake( "%s.res", obj ));
2518 output( "%s.res: %s\n", obj_dir_path( make, obj ), source->filename );
2519 output( "\t%s -o $@", tools_path( make, "wrc" ) );
2520 if (make->is_win16) output_filename( "-m16" );
2521 else output_filenames( target_flags );
2522 output_filename( "--nostdinc" );
2523 output_filenames( make->include_args );
2524 output_filenames( make->define_args );
2525 output_filenames( extradefs );
2526 if (linguas.count && (source->file->flags & FLAG_RC_PO))
2528 char *po_dir = top_obj_dir_path( make, "po" );
2529 output_filename( strmake( "--po-dir=%s", po_dir ));
2530 output_filename( source->filename );
2531 output( "\n" );
2532 output( "%s.res:", obj_dir_path( make, obj ));
2533 for (i = 0; i < linguas.count; i++)
2534 output_filename( strmake( "%s/%s.mo", po_dir, linguas.str[i] ));
2535 output( "\n" );
2537 else
2539 output_filename( source->filename );
2540 output( "\n" );
2542 if (source->file->flags & FLAG_RC_PO)
2544 strarray_add( &make->clean_files, strmake( "%s.pot", obj ));
2545 output( "%s.pot: %s\n", obj_dir_path( make, obj ), source->filename );
2546 output( "\t%s -O pot -o $@", tools_path( make, "wrc" ) );
2547 if (make->is_win16) output_filename( "-m16" );
2548 else output_filenames( target_flags );
2549 output_filename( "--nostdinc" );
2550 output_filenames( make->include_args );
2551 output_filenames( make->define_args );
2552 output_filenames( extradefs );
2553 output_filename( source->filename );
2554 output( "\n" );
2555 output( "%s.pot ", obj_dir_path( make, obj ));
2557 output( "%s.res:", obj_dir_path( make, obj ));
2558 output_filename( tools_path( make, "wrc" ));
2559 output_filenames( source->dependencies );
2560 output( "\n" );
2564 /*******************************************************************
2565 * output_source_mc
2567 static void output_source_mc( struct makefile *make, struct incl_file *source, const char *obj )
2569 unsigned int i;
2571 strarray_add( &make->object_files, strmake( "%s.res", obj ));
2572 if (crosstarget) strarray_add( &make->crossobj_files, strmake( "%s.res", obj ));
2573 strarray_add( &make->clean_files, strmake( "%s.pot", obj ));
2574 output( "%s.res: %s\n", obj_dir_path( make, obj ), source->filename );
2575 output( "\t%s -U -O res -o $@ %s", tools_path( make, "wmc" ), source->filename );
2576 if (linguas.count)
2578 char *po_dir = top_obj_dir_path( make, "po" );
2579 output_filename( strmake( "--po-dir=%s", po_dir ));
2580 output( "\n" );
2581 output( "%s.res:", obj_dir_path( make, obj ));
2582 for (i = 0; i < linguas.count; i++)
2583 output_filename( strmake( "%s/%s.mo", po_dir, linguas.str[i] ));
2585 output( "\n" );
2586 output( "%s.pot: %s\n", obj_dir_path( make, obj ), source->filename );
2587 output( "\t%s -O pot -o $@ %s", tools_path( make, "wmc" ), source->filename );
2588 output( "\n" );
2589 output( "%s.pot %s.res:", obj_dir_path( make, obj ), obj_dir_path( make, obj ));
2590 output_filename( tools_path( make, "wmc" ));
2591 output_filenames( source->dependencies );
2592 output( "\n" );
2596 /*******************************************************************
2597 * output_source_res
2599 static void output_source_res( struct makefile *make, struct incl_file *source, const char *obj )
2601 strarray_add( &make->object_files, source->name );
2602 if (crosstarget) strarray_add( &make->crossobj_files, source->name );
2606 /*******************************************************************
2607 * output_source_idl
2609 static void output_source_idl( struct makefile *make, struct incl_file *source, const char *obj )
2611 struct strarray extradefs = get_expanded_file_local_var( make, obj, "EXTRADEFS" );
2612 struct strarray targets = empty_strarray;
2613 char *dest;
2614 unsigned int i;
2616 if (!source->file->flags) source->file->flags |= FLAG_IDL_HEADER | FLAG_INSTALL;
2617 if (find_include_file( make, strmake( "%s.h", obj ))) source->file->flags |= FLAG_IDL_HEADER;
2619 for (i = 0; i < sizeof(idl_outputs) / sizeof(idl_outputs[0]); i++)
2621 if (!(source->file->flags & idl_outputs[i].flag)) continue;
2622 dest = strmake( "%s%s", obj, idl_outputs[i].ext );
2623 if (!find_src_file( make, dest )) strarray_add( &make->clean_files, dest );
2624 strarray_add( &targets, dest );
2626 if (source->file->flags & FLAG_IDL_PROXY) strarray_add( &make->dlldata_files, source->name );
2627 if (source->file->flags & FLAG_INSTALL)
2629 strarray_add( &make->install_rules[INSTALL_DEV], xstrdup( source->name ));
2630 strarray_add( &make->install_rules[INSTALL_DEV],
2631 strmake( "D$(includedir)/wine/%s.idl", get_include_install_path( obj ) ));
2632 if (source->file->flags & FLAG_IDL_HEADER)
2634 strarray_add( &make->install_rules[INSTALL_DEV], strmake( "%s.h", obj ));
2635 strarray_add( &make->install_rules[INSTALL_DEV],
2636 strmake( "d$(includedir)/wine/%s.h", get_include_install_path( obj ) ));
2639 if (!targets.count) return;
2641 output_filenames_obj_dir( make, targets );
2642 output( ": %s\n", tools_path( make, "widl" ));
2643 output( "\t%s -o $@", tools_path( make, "widl" ) );
2644 output_filenames( target_flags );
2645 output_filenames( make->include_args );
2646 output_filenames( make->define_args );
2647 output_filenames( extradefs );
2648 output_filenames( get_expanded_make_var_array( make, "EXTRAIDLFLAGS" ));
2649 output_filename( source->filename );
2650 output( "\n" );
2651 output_filenames_obj_dir( make, targets );
2652 output( ": %s", source->filename );
2653 output_filenames( source->dependencies );
2654 output( "\n" );
2658 /*******************************************************************
2659 * output_source_tlb
2661 static void output_source_tlb( struct makefile *make, struct incl_file *source, const char *obj )
2663 strarray_add( &make->all_targets, source->name );
2667 /*******************************************************************
2668 * output_source_x
2670 static void output_source_x( struct makefile *make, struct incl_file *source, const char *obj )
2672 output( "%s.h: %s%s %s\n", obj_dir_path( make, obj ),
2673 tools_dir_path( make, "make_xftmpl" ), tools_ext, source->filename );
2674 output( "\t%s%s -H -o $@ %s\n",
2675 tools_dir_path( make, "make_xftmpl" ), tools_ext, source->filename );
2676 if (source->file->flags & FLAG_INSTALL)
2678 strarray_add( &make->install_rules[INSTALL_DEV], source->name );
2679 strarray_add( &make->install_rules[INSTALL_DEV],
2680 strmake( "D$(includedir)/wine/%s", get_include_install_path( source->name ) ));
2681 strarray_add( &make->install_rules[INSTALL_DEV], strmake( "%s.h", obj ));
2682 strarray_add( &make->install_rules[INSTALL_DEV],
2683 strmake( "d$(includedir)/wine/%s.h", get_include_install_path( obj ) ));
2688 /*******************************************************************
2689 * output_source_sfd
2691 static void output_source_sfd( struct makefile *make, struct incl_file *source, const char *obj )
2693 unsigned int i;
2694 char *ttf_file = src_dir_path( make, strmake( "%s.ttf", obj ));
2696 if (fontforge && !make->src_dir)
2698 output( "%s: %s\n", ttf_file, source->filename );
2699 output( "\t%s -script %s %s $@\n",
2700 fontforge, top_src_dir_path( make, "fonts/genttf.ff" ), source->filename );
2701 if (!(source->file->flags & FLAG_SFD_FONTS)) output( "all: %s\n", ttf_file );
2703 if (source->file->flags & FLAG_INSTALL)
2705 strarray_add( &make->install_rules[INSTALL_LIB], strmake( "%s.ttf", obj ));
2706 strarray_add( &make->install_rules[INSTALL_LIB], strmake( "D$(fontdir)/%s.ttf", obj ));
2708 if (source->file->flags & FLAG_SFD_FONTS)
2710 struct strarray *array = source->file->args;
2712 for (i = 0; i < array->count; i++)
2714 char *font = strtok( xstrdup(array->str[i]), " \t" );
2715 char *args = strtok( NULL, "" );
2717 strarray_add( &make->all_targets, xstrdup( font ));
2718 output( "%s: %s %s\n", obj_dir_path( make, font ),
2719 tools_path( make, "sfnt2fon" ), ttf_file );
2720 output( "\t%s -o $@ %s %s\n", tools_path( make, "sfnt2fon" ), ttf_file, args );
2721 strarray_add( &make->install_rules[INSTALL_LIB], xstrdup(font) );
2722 strarray_add( &make->install_rules[INSTALL_LIB], strmake( "d$(fontdir)/%s", font ));
2728 /*******************************************************************
2729 * output_source_svg
2731 static void output_source_svg( struct makefile *make, struct incl_file *source, const char *obj )
2733 static const char * const images[] = { "bmp", "cur", "ico", NULL };
2734 unsigned int i;
2736 if (convert && rsvg && icotool && !make->src_dir)
2738 for (i = 0; images[i]; i++)
2739 if (find_include_file( make, strmake( "%s.%s", obj, images[i] ))) break;
2741 if (images[i])
2743 output( "%s.%s: %s\n", src_dir_path( make, obj ), images[i], source->filename );
2744 output( "\tCONVERT=\"%s\" ICOTOOL=\"%s\" RSVG=\"%s\" %s %s $@\n", convert, icotool, rsvg,
2745 top_src_dir_path( make, "tools/buildimage" ), source->filename );
2751 /*******************************************************************
2752 * output_source_nls
2754 static void output_source_nls( struct makefile *make, struct incl_file *source, const char *obj )
2756 add_install_rule( make, source->name, source->name,
2757 strmake( "D$(datadir)/wine/%s", source->name ));
2761 /*******************************************************************
2762 * output_source_desktop
2764 static void output_source_desktop( struct makefile *make, struct incl_file *source, const char *obj )
2766 add_install_rule( make, source->name, source->name,
2767 strmake( "D$(datadir)/applications/%s", source->name ));
2771 /*******************************************************************
2772 * output_source_po
2774 static void output_source_po( struct makefile *make, struct incl_file *source, const char *obj )
2776 output( "%s.mo: %s\n", obj_dir_path( make, obj ), source->filename );
2777 output( "\t%s -o $@ %s\n", msgfmt, source->filename );
2778 strarray_add( &make->all_targets, strmake( "%s.mo", obj ));
2782 /*******************************************************************
2783 * output_source_in
2785 static void output_source_in( struct makefile *make, struct incl_file *source, const char *obj )
2787 unsigned int i;
2789 if (strendswith( obj, ".man" ) && source->file->args)
2791 struct strarray symlinks;
2792 char *dir, *dest = replace_extension( obj, ".man", "" );
2793 char *lang = strchr( dest, '.' );
2794 char *section = source->file->args;
2795 if (lang)
2797 *lang++ = 0;
2798 dir = strmake( "$(mandir)/%s/man%s", lang, section );
2800 else dir = strmake( "$(mandir)/man%s", section );
2801 add_install_rule( make, dest, xstrdup(obj), strmake( "d%s/%s.%s", dir, dest, section ));
2802 symlinks = get_expanded_file_local_var( make, dest, "SYMLINKS" );
2803 for (i = 0; i < symlinks.count; i++)
2804 add_install_rule( make, symlinks.str[i], strmake( "%s.%s", dest, section ),
2805 strmake( "y%s/%s.%s", dir, symlinks.str[i], section ));
2806 free( dest );
2807 free( dir );
2809 strarray_add( &make->in_files, xstrdup(obj) );
2810 strarray_add( &make->all_targets, xstrdup(obj) );
2811 output( "%s: %s\n", obj_dir_path( make, obj ), source->filename );
2812 output( "\t$(SED_CMD) %s >$@ || (rm -f $@ && false)\n", source->filename );
2813 output( "%s:", obj_dir_path( make, obj ));
2814 output_filenames( source->dependencies );
2815 output( "\n" );
2816 add_install_rule( make, obj, xstrdup( obj ), strmake( "d$(datadir)/wine/%s", obj ));
2820 /*******************************************************************
2821 * output_source_spec
2823 static void output_source_spec( struct makefile *make, struct incl_file *source, const char *obj )
2825 struct strarray imports = get_expanded_file_local_var( make, obj, "IMPORTS" );
2826 struct strarray all_libs, dep_libs = empty_strarray;
2828 if (!imports.count) imports = make->imports;
2829 all_libs = add_import_libs( make, &dep_libs, imports, 0 );
2830 add_import_libs( make, &dep_libs, get_default_imports( make ), 0 ); /* dependencies only */
2831 strarray_addall( &all_libs, libs );
2833 strarray_add( &make->clean_files, strmake( "%s.dll%s", obj, dll_ext ));
2834 strarray_add( &make->object_files, strmake( "%s.res", obj ));
2835 output( "%s.res: %s.dll%s\n", obj_dir_path( make, obj ), obj_dir_path( make, obj ), dll_ext );
2836 output( "\techo \"%s.dll TESTDLL \\\"%s.dll%s\\\"\" | %s -o $@\n", obj,
2837 obj_dir_path( make, obj ), dll_ext, tools_path( make, "wrc" ));
2839 output( "%s.dll%s:", obj_dir_path( make, obj ), dll_ext );
2840 output_filename( source->filename );
2841 output_filename( strmake( "%s.o", obj_dir_path( make, obj )));
2842 output_filenames( dep_libs );
2843 output_filename( tools_path( make, "winebuild" ));
2844 output_filename( tools_path( make, "winegcc" ));
2845 output( "\n" );
2846 output( "\t%s -s -o $@", tools_path( make, "winegcc" ));
2847 output_filename( strmake( "-B%s", tools_dir_path( make, "winebuild" )));
2848 if (tools_dir) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make, "" )));
2849 output_filenames( target_flags );
2850 output_filenames( unwind_flags );
2851 output_filenames( make->extradllflags );
2852 output_filename( "-shared" );
2853 output_filename( source->filename );
2854 output_filename( strmake( "%s.o", obj_dir_path( make, obj )));
2855 output_filenames( all_libs );
2856 output_filename( "$(LDFLAGS)" );
2857 output( "\n" );
2859 if (crosstarget)
2861 dep_libs = empty_strarray;
2862 all_libs = add_import_libs( make, &dep_libs, imports, 1 );
2863 add_import_libs( make, &dep_libs, get_default_imports( make ), 1 ); /* dependencies only */
2864 strarray_addall( &all_libs, libs );
2866 strarray_add( &make->clean_files, strmake( "%s.dll", obj ));
2867 strarray_add( &make->crossobj_files, strmake( "%s.cross.res", obj ));
2868 output( "%s.cross.res: %s.dll\n", obj_dir_path( make, obj ), obj_dir_path( make, obj ) );
2869 output( "\techo \"%s.dll TESTDLL \\\"%s.dll\\\"\" | %s -o $@\n", obj,
2870 obj_dir_path( make, obj ), tools_path( make, "wrc" ));
2872 output( "%s.dll:", obj_dir_path( make, obj ));
2873 output_filename( source->filename );
2874 output_filename( strmake( "%s.cross.o", obj_dir_path( make, obj )));
2875 output_filenames( dep_libs );
2876 output_filename( tools_path( make, "winebuild" ));
2877 output_filename( tools_path( make, "winegcc" ));
2878 output( "\n" );
2879 output( "\t%s -s -o $@ -b %s", tools_path( make, "winegcc" ), crosstarget );
2880 output_filename( strmake( "-B%s", tools_dir_path( make, "winebuild" )));
2881 if (tools_dir) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make, "" )));
2882 output_filename( "--lib-suffix=.cross.a" );
2883 output_filename( "-shared" );
2884 output_filename( source->filename );
2885 output_filename( strmake( "%s.cross.o", obj_dir_path( make, obj )));
2886 output_filenames( all_libs );
2887 output_filename( "$(LDFLAGS)" );
2888 output( "\n" );
2893 /*******************************************************************
2894 * output_source_default
2896 static void output_source_default( struct makefile *make, struct incl_file *source, const char *obj )
2898 struct strarray extradefs = get_expanded_file_local_var( make, obj, "EXTRADEFS" );
2899 int is_dll_src = (make->testdll &&
2900 strendswith( source->name, ".c" ) &&
2901 find_src_file( make, replace_extension( source->name, ".c", ".spec" )));
2902 int need_cross = (make->testdll ||
2903 (source->file->flags & FLAG_C_IMPLIB) ||
2904 (make->module && make->staticlib));
2906 if ((source->file->flags & FLAG_GENERATED) &&
2907 (!make->testdll || !strendswith( source->filename, "testlist.c" )))
2908 strarray_add( &make->clean_files, source->filename );
2909 if (source->file->flags & FLAG_C_IMPLIB) strarray_add( &make->implib_objs, strmake( "%s.o", obj ));
2910 strarray_add( is_dll_src ? &make->clean_files : &make->object_files, strmake( "%s.o", obj ));
2911 output( "%s.o: %s\n", obj_dir_path( make, obj ), source->filename );
2912 output( "\t$(CC) -c -o $@ %s", source->filename );
2913 output_filenames( make->include_args );
2914 output_filenames( make->define_args );
2915 output_filenames( extradefs );
2916 if (make->module || make->staticlib || make->sharedlib || make->testdll)
2918 output_filenames( dll_flags );
2919 if (make->use_msvcrt) output_filenames( msvcrt_flags );
2921 output_filenames( extra_cflags );
2922 output_filenames( cpp_flags );
2923 output_filename( "$(CFLAGS)" );
2924 output( "\n" );
2925 if (crosstarget && need_cross)
2927 strarray_add( is_dll_src ? &make->clean_files : &make->crossobj_files, strmake( "%s.cross.o", obj ));
2928 output( "%s.cross.o: %s\n", obj_dir_path( make, obj ), source->filename );
2929 output( "\t$(CROSSCC) -c -o $@ %s", source->filename );
2930 output_filenames( make->include_args );
2931 output_filenames( make->define_args );
2932 output_filenames( extradefs );
2933 if (make->use_msvcrt) output_filenames( msvcrt_flags );
2934 output_filename( "-DWINE_CROSSTEST" );
2935 output_filenames( cpp_flags );
2936 output_filename( "$(CROSSCFLAGS)" );
2937 output( "\n" );
2939 if (strendswith( source->name, ".c" ) && !(source->file->flags & FLAG_GENERATED))
2941 strarray_add( &make->c2man_files, source->filename );
2942 if (make->testdll && !is_dll_src)
2944 strarray_add( &make->ok_files, strmake( "%s.ok", obj ));
2945 output( "%s.ok:\n", obj_dir_path( make, obj ));
2946 output( "\t%s $(RUNTESTFLAGS) -T %s -M %s -p %s%s %s && touch $@\n",
2947 top_src_dir_path( make, "tools/runtest" ), top_obj_dir_path( make, "" ),
2948 make->testdll, replace_extension( make->testdll, ".dll", "_test.exe" ),
2949 dll_ext, obj );
2952 output( "%s.o", obj_dir_path( make, obj ));
2953 if (crosstarget && need_cross) output( " %s.cross.o", obj_dir_path( make, obj ));
2954 output( ":" );
2955 output_filenames( source->dependencies );
2956 output( "\n" );
2960 /* dispatch table to output rules for a single source file */
2961 static const struct
2963 const char *ext;
2964 void (*fn)( struct makefile *make, struct incl_file *source, const char *obj );
2965 } output_source_funcs[] =
2967 { "y", output_source_y },
2968 { "l", output_source_l },
2969 { "h", output_source_h },
2970 { "rh", output_source_h },
2971 { "inl", output_source_h },
2972 { "rc", output_source_rc },
2973 { "mc", output_source_mc },
2974 { "res", output_source_res },
2975 { "idl", output_source_idl },
2976 { "tlb", output_source_tlb },
2977 { "sfd", output_source_sfd },
2978 { "svg", output_source_svg },
2979 { "nls", output_source_nls },
2980 { "desktop", output_source_desktop },
2981 { "po", output_source_po },
2982 { "in", output_source_in },
2983 { "x", output_source_x },
2984 { "spec", output_source_spec },
2985 { NULL, output_source_default }
2989 /*******************************************************************
2990 * output_man_pages
2992 static void output_man_pages( struct makefile *make )
2994 if (make->c2man_files.count)
2996 char *spec_file = src_dir_path( make, replace_extension( make->module, ".dll", ".spec" ));
2998 output( "manpages::\n" );
2999 output( "\t%s -w %s", top_src_dir_path( make, "tools/c2man.pl" ), spec_file );
3000 output_filename( strmake( "-R%s", top_src_dir_path( make, "" )));
3001 output_filename( strmake( "-I%s", top_src_dir_path( make, "include" )));
3002 output_filename( strmake( "-o %s/man%s",
3003 top_obj_dir_path( make, "documentation" ), man_ext ));
3004 output_filenames( make->c2man_files );
3005 output( "\n" );
3006 output( "htmlpages::\n" );
3007 output( "\t%s -Th -w %s", top_src_dir_path( make, "tools/c2man.pl" ), spec_file );
3008 output_filename( strmake( "-R%s", top_src_dir_path( make, "" )));
3009 output_filename( strmake( "-I%s", top_src_dir_path( make, "include" )));
3010 output_filename( strmake( "-o %s",
3011 top_obj_dir_path( make, "documentation/html" )));
3012 output_filenames( make->c2man_files );
3013 output( "\n" );
3014 output( "sgmlpages::\n" );
3015 output( "\t%s -Ts -w %s", top_src_dir_path( make, "tools/c2man.pl" ), spec_file );
3016 output_filename( strmake( "-R%s", top_src_dir_path( make, "" )));
3017 output_filename( strmake( "-I%s", top_src_dir_path( make, "include" )));
3018 output_filename( strmake( "-o %s",
3019 top_obj_dir_path( make, "documentation/api-guide" )));
3020 output_filenames( make->c2man_files );
3021 output( "\n" );
3022 output( "xmlpages::\n" );
3023 output( "\t%s -Tx -w %s", top_src_dir_path( make, "tools/c2man.pl" ), spec_file );
3024 output_filename( strmake( "-R%s", top_src_dir_path( make, "" )));
3025 output_filename( strmake( "-I%s", top_src_dir_path( make, "include" )));
3026 output_filename( strmake( "-o %s",
3027 top_obj_dir_path( make, "documentation/api-guide-xml" )));
3028 output_filenames( make->c2man_files );
3029 output( "\n" );
3030 strarray_add( &make->phony_targets, "manpages" );
3031 strarray_add( &make->phony_targets, "htmlpages" );
3032 strarray_add( &make->phony_targets, "sgmlpages" );
3033 strarray_add( &make->phony_targets, "xmlpages" );
3035 else output( "manpages htmlpages sgmlpages xmlpages::\n" );
3039 /*******************************************************************
3040 * output_module
3042 static void output_module( struct makefile *make )
3044 struct strarray all_libs = empty_strarray;
3045 struct strarray dep_libs = empty_strarray;
3046 char *module_path = obj_dir_path( make, make->module );
3047 char *spec_file = NULL;
3048 unsigned int i;
3050 if (!make->appmode.count)
3051 spec_file = src_dir_path( make, replace_extension( make->module, ".dll", ".spec" ));
3052 strarray_addall( &all_libs, add_import_libs( make, &dep_libs, make->delayimports, 0 ));
3053 strarray_addall( &all_libs, add_import_libs( make, &dep_libs, make->imports, 0 ));
3054 add_import_libs( make, &dep_libs, get_default_imports( make ), 0 ); /* dependencies only */
3055 strarray_addall( &all_libs, add_default_libraries( make, &dep_libs ));
3057 if (*dll_ext)
3059 for (i = 0; i < make->delayimports.count; i++)
3060 strarray_add( &all_libs, strmake( "-Wb,-d%s", make->delayimports.str[i] ));
3061 strarray_add( &make->all_targets, strmake( "%s%s", make->module, dll_ext ));
3062 strarray_add( &make->all_targets, strmake( "%s.fake", make->module ));
3063 add_install_rule( make, make->module, strmake( "%s%s", make->module, dll_ext ),
3064 strmake( "p$(dlldir)/%s%s", make->module, dll_ext ));
3065 add_install_rule( make, make->module, strmake( "%s.fake", make->module ),
3066 strmake( "d$(dlldir)/fakedlls/%s", make->module ));
3067 output( "%s%s %s.fake:", module_path, dll_ext, module_path );
3069 else
3071 strarray_add( &all_libs, "-lwine" );
3072 strarray_add( &make->all_targets, make->module );
3073 add_install_rule( make, make->module, make->module,
3074 strmake( "p$(%s)/%s", spec_file ? "dlldir" : "bindir", make->module ));
3075 output( "%s:", module_path );
3077 if (spec_file) output_filename( spec_file );
3078 output_filenames_obj_dir( make, make->object_files );
3079 output_filenames( dep_libs );
3080 output_filename( tools_path( make, "winebuild" ));
3081 output_filename( tools_path( make, "winegcc" ));
3082 output( "\n" );
3083 output( "\t%s -o $@", tools_path( make, "winegcc" ));
3084 output_filename( strmake( "-B%s", tools_dir_path( make, "winebuild" )));
3085 if (tools_dir) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make, "" )));
3086 output_filenames( target_flags );
3087 output_filenames( unwind_flags );
3088 if (spec_file)
3090 output( " -shared %s", spec_file );
3091 output_filenames( make->extradllflags );
3093 else output_filenames( make->appmode );
3094 output_filenames_obj_dir( make, make->object_files );
3095 output_filenames( all_libs );
3096 output_filename( "$(LDFLAGS)" );
3097 output( "\n" );
3099 if (spec_file && make->importlib)
3101 char *importlib_path = obj_dir_path( make, strmake( "lib%s", make->importlib ));
3102 if (*dll_ext && !make->implib_objs.count)
3104 strarray_add( &make->clean_files, strmake( "lib%s.def", make->importlib ));
3105 output( "%s.def: %s %s\n", importlib_path, tools_path( make, "winebuild" ), spec_file );
3106 output( "\t%s -w --def -o $@ --export %s", tools_path( make, "winebuild" ), spec_file );
3107 output_filenames( target_flags );
3108 if (make->is_win16) output_filename( "-m16" );
3109 output( "\n" );
3110 add_install_rule( make, make->importlib,
3111 strmake( "lib%s.def", make->importlib ),
3112 strmake( "d$(dlldir)/lib%s.def", make->importlib ));
3114 else
3116 strarray_add( &make->clean_files, strmake( "lib%s.a", make->importlib ));
3117 output( "%s.a: %s %s", importlib_path, tools_path( make, "winebuild" ), spec_file );
3118 output_filenames_obj_dir( make, make->implib_objs );
3119 output( "\n" );
3120 output( "\t%s -w --implib -o $@ --export %s", tools_path( make, "winebuild" ), spec_file );
3121 output_filenames( target_flags );
3122 output_filenames_obj_dir( make, make->implib_objs );
3123 output( "\n" );
3124 add_install_rule( make, make->importlib,
3125 strmake( "lib%s.a", make->importlib ),
3126 strmake( "d$(dlldir)/lib%s.a", make->importlib ));
3128 if (crosstarget && !make->is_win16)
3130 struct strarray cross_files = strarray_replace_extension( &make->implib_objs, ".o", ".cross.o" );
3131 strarray_add( &make->clean_files, strmake( "lib%s.cross.a", make->importlib ));
3132 output( "%s.cross.a: %s %s", importlib_path, tools_path( make, "winebuild" ), spec_file );
3133 output_filenames_obj_dir( make, cross_files );
3134 output( "\n" );
3135 output( "\t%s -b %s -w --implib -o $@ --export %s",
3136 tools_path( make, "winebuild" ), crosstarget, spec_file );
3137 output_filenames_obj_dir( make, cross_files );
3138 output( "\n" );
3142 if (spec_file)
3143 output_man_pages( make );
3144 else if (*dll_ext && !make->is_win16)
3146 char *binary = replace_extension( make->module, ".exe", "" );
3147 add_install_rule( make, binary, "wineapploader", strmake( "t$(bindir)/%s", binary ));
3152 /*******************************************************************
3153 * output_static_lib
3155 static void output_static_lib( struct makefile *make )
3157 strarray_add( &make->all_targets, make->staticlib );
3158 output( "%s:", obj_dir_path( make, make->staticlib ));
3159 output_filenames_obj_dir( make, make->object_files );
3160 output( "\n\trm -f $@\n" );
3161 output( "\t$(AR) $(ARFLAGS) $@" );
3162 output_filenames_obj_dir( make, make->object_files );
3163 output( "\n\t$(RANLIB) $@\n" );
3164 add_install_rule( make, make->staticlib, make->staticlib,
3165 strmake( "d$(dlldir)/%s", make->staticlib ));
3166 if (crosstarget && make->module)
3168 char *name = replace_extension( make->staticlib, ".a", ".cross.a" );
3170 strarray_add( &make->all_targets, name );
3171 output( "%s:", obj_dir_path( make, name ));
3172 output_filenames_obj_dir( make, make->crossobj_files );
3173 output( "\n\trm -f $@\n" );
3174 output( "\t%s-ar $(ARFLAGS) $@", crosstarget );
3175 output_filenames_obj_dir( make, make->crossobj_files );
3176 output( "\n\t%s-ranlib $@\n", crosstarget );
3181 /*******************************************************************
3182 * output_shared_lib
3184 static void output_shared_lib( struct makefile *make )
3186 unsigned int i;
3187 char *basename, *p;
3188 struct strarray names = get_shared_lib_names( make->sharedlib );
3189 struct strarray all_libs = empty_strarray;
3190 struct strarray dep_libs = empty_strarray;
3192 basename = xstrdup( make->sharedlib );
3193 if ((p = strchr( basename, '.' ))) *p = 0;
3195 strarray_addall( &dep_libs, get_local_dependencies( make, basename, make->in_files ));
3196 strarray_addall( &all_libs, get_expanded_file_local_var( make, basename, "LDFLAGS" ));
3197 strarray_addall( &all_libs, add_default_libraries( make, &dep_libs ));
3199 output( "%s:", obj_dir_path( make, make->sharedlib ));
3200 output_filenames_obj_dir( make, make->object_files );
3201 output_filenames( dep_libs );
3202 output( "\n" );
3203 output( "\t$(CC) -o $@" );
3204 output_filenames_obj_dir( make, make->object_files );
3205 output_filenames( all_libs );
3206 output_filename( "$(LDFLAGS)" );
3207 output( "\n" );
3208 add_install_rule( make, make->sharedlib, make->sharedlib,
3209 strmake( "p$(libdir)/%s", make->sharedlib ));
3210 for (i = 1; i < names.count; i++)
3212 output( "%s: %s\n", obj_dir_path( make, names.str[i] ), obj_dir_path( make, names.str[i-1] ));
3213 output_symlink_rule( obj_dir_path( make, names.str[i-1] ), obj_dir_path( make, names.str[i] ));
3214 add_install_rule( make, names.str[i], names.str[i-1],
3215 strmake( "y$(libdir)/%s", names.str[i] ));
3217 strarray_addall( &make->all_targets, names );
3221 /*******************************************************************
3222 * output_import_lib
3224 static void output_import_lib( struct makefile *make )
3226 char *def_file = replace_extension( make->importlib, ".a", ".def" );
3228 /* stand-alone import lib (for libwine) */
3229 if (!strncmp( def_file, "lib", 3 )) def_file += 3;
3230 output( "%s: %s\n", obj_dir_path( make, make->importlib ), src_dir_path( make, def_file ));
3231 output( "\t%s -l $@ -d %s\n", dlltool, src_dir_path( make, def_file ));
3232 add_install_rule( make, make->importlib, make->importlib, strmake( "d$(libdir)/%s", make->importlib ));
3233 strarray_add( &make->all_targets, make->importlib );
3237 /*******************************************************************
3238 * output_test_module
3240 static void output_test_module( struct makefile *make )
3242 char *testmodule = replace_extension( make->testdll, ".dll", "_test.exe" );
3243 char *stripped = replace_extension( make->testdll, ".dll", "_test-stripped.exe" );
3244 char *testres = replace_extension( make->testdll, ".dll", "_test.res" );
3245 struct strarray dep_libs = empty_strarray;
3246 struct strarray all_libs = add_import_libs( make, &dep_libs, make->imports, 0 );
3248 add_import_libs( make, &dep_libs, get_default_imports( make ), 0 ); /* dependencies only */
3249 strarray_addall( &all_libs, libs );
3250 strarray_add( &make->all_targets, strmake( "%s%s", testmodule, dll_ext ));
3251 strarray_add( &make->clean_files, strmake( "%s%s", stripped, dll_ext ));
3252 output( "%s%s:\n", obj_dir_path( make, testmodule ), dll_ext );
3253 output( "\t%s -o $@", tools_path( make, "winegcc" ));
3254 output_filename( strmake( "-B%s", tools_dir_path( make, "winebuild" )));
3255 if (tools_dir) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make, "" )));
3256 output_filenames( target_flags );
3257 output_filenames( unwind_flags );
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:\n", obj_dir_path( make, stripped ), dll_ext );
3264 output( "\t%s -s -o $@", tools_path( make, "winegcc" ));
3265 output_filename( strmake( "-B%s", tools_dir_path( make, "winebuild" )));
3266 if (tools_dir) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make, "" )));
3267 output_filenames( target_flags );
3268 output_filenames( unwind_flags );
3269 output_filename( strmake( "-Wb,-F,%s", testmodule ));
3270 output_filenames( make->appmode );
3271 output_filenames_obj_dir( make, make->object_files );
3272 output_filenames( all_libs );
3273 output_filename( "$(LDFLAGS)" );
3274 output( "\n" );
3275 output( "%s%s %s%s:", obj_dir_path( make, testmodule ), dll_ext,
3276 obj_dir_path( make, stripped ), dll_ext );
3277 output_filenames_obj_dir( make, make->object_files );
3278 output_filenames( dep_libs );
3279 output_filename( tools_path( make, "winebuild" ));
3280 output_filename( tools_path( make, "winegcc" ));
3281 output( "\n" );
3283 if (!make->disabled)
3284 output( "all: %s/%s\n", top_obj_dir_path( make, "programs/winetest" ), testres );
3285 output( "%s/%s: %s%s\n", top_obj_dir_path( make, "programs/winetest" ), testres,
3286 obj_dir_path( make, stripped ), dll_ext );
3287 output( "\techo \"%s TESTRES \\\"%s%s\\\"\" | %s -o $@\n",
3288 testmodule, obj_dir_path( make, stripped ), dll_ext, tools_path( make, "wrc" ));
3290 if (crosstarget)
3292 char *crosstest = replace_extension( make->testdll, ".dll", "_crosstest.exe" );
3294 dep_libs = empty_strarray;
3295 all_libs = add_import_libs( make, &dep_libs, make->imports, 1 );
3296 add_import_libs( make, &dep_libs, get_default_imports( make ), 1 ); /* dependencies only */
3297 strarray_addall( &all_libs, libs );
3298 strarray_add( &make->clean_files, crosstest );
3299 output( "%s:", obj_dir_path( make, crosstest ));
3300 output_filenames_obj_dir( make, make->crossobj_files );
3301 output_filenames( dep_libs );
3302 output_filename( tools_path( make, "winebuild" ));
3303 output_filename( tools_path( make, "winegcc" ));
3304 output( "\n" );
3305 output( "\t%s -o $@ -b %s", tools_path( make, "winegcc" ), crosstarget );
3306 output_filename( strmake( "-B%s", tools_dir_path( make, "winebuild" )));
3307 if (tools_dir) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make, "" )));
3308 output_filename( "--lib-suffix=.cross.a" );
3309 output_filenames_obj_dir( make, make->crossobj_files );
3310 output_filenames( all_libs );
3311 output_filename( "$(LDFLAGS)" );
3312 output( "\n" );
3313 if (!make->disabled)
3315 output( "%s: %s\n", obj_dir_path( make, "crosstest" ), obj_dir_path( make, crosstest ));
3316 strarray_add( &make->phony_targets, obj_dir_path( make, "crosstest" ));
3317 if (make->obj_dir) output( "crosstest: %s\n", obj_dir_path( make, "crosstest" ));
3321 output_filenames_obj_dir( make, make->ok_files );
3322 output( ": %s%s ../%s%s\n", testmodule, dll_ext, make->testdll, dll_ext );
3323 if (!make->disabled)
3325 output( "check test:" );
3326 output_filenames_obj_dir( make, make->ok_files );
3327 output( "\n" );
3328 strarray_add( &make->phony_targets, "check" );
3329 strarray_add( &make->phony_targets, "test" );
3331 output( "testclean::\n" );
3332 output( "\trm -f" );
3333 output_filenames_obj_dir( make, make->ok_files );
3334 output( "\n" );
3335 strarray_addall( &make->clean_files, make->ok_files );
3336 strarray_add( &make->phony_targets, "testclean" );
3340 /*******************************************************************
3341 * output_programs
3343 static void output_programs( struct makefile *make )
3345 unsigned int i, j;
3346 char *ldrpath_local = get_expanded_make_variable( make, "LDRPATH_LOCAL" );
3347 char *ldrpath_install = get_expanded_make_variable( make, "LDRPATH_INSTALL" );
3349 for (i = 0; i < make->programs.count; i++)
3351 char *program_installed = NULL;
3352 char *program = strmake( "%s%s", make->programs.str[i], exe_ext );
3353 struct strarray deps = get_local_dependencies( make, make->programs.str[i], make->in_files );
3354 struct strarray all_libs = get_expanded_file_local_var( make, make->programs.str[i], "LDFLAGS" );
3355 struct strarray objs = get_expanded_file_local_var( make, make->programs.str[i], "OBJS" );
3356 struct strarray symlinks = get_expanded_file_local_var( make, make->programs.str[i], "SYMLINKS" );
3358 if (!objs.count) objs = make->object_files;
3359 strarray_addall( &all_libs, add_default_libraries( make, &deps ));
3361 output( "%s:", obj_dir_path( make, program ) );
3362 output_filenames_obj_dir( make, objs );
3363 output_filenames( deps );
3364 output( "\n" );
3365 output( "\t$(CC) -o $@" );
3366 output_filenames_obj_dir( make, objs );
3368 if (strarray_exists( &all_libs, "-lwine" ))
3370 strarray_add( &all_libs, strmake( "-L%s", top_obj_dir_path( make, "libs/wine" )));
3371 if (ldrpath_local && ldrpath_install)
3373 program_installed = strmake( "%s-installed%s", make->programs.str[i], exe_ext );
3374 output_filename( ldrpath_local );
3375 output_filenames( all_libs );
3376 output_filename( "$(LDFLAGS)" );
3377 output( "\n" );
3378 output( "%s:", obj_dir_path( make, program_installed ) );
3379 output_filenames_obj_dir( make, objs );
3380 output_filenames( deps );
3381 output( "\n" );
3382 output( "\t$(CC) -o $@" );
3383 output_filenames_obj_dir( make, objs );
3384 output_filename( ldrpath_install );
3385 strarray_add( &make->all_targets, program_installed );
3389 output_filenames( all_libs );
3390 output_filename( "$(LDFLAGS)" );
3391 output( "\n" );
3392 strarray_add( &make->all_targets, program );
3394 for (j = 0; j < symlinks.count; j++)
3396 output( "%s: %s\n", obj_dir_path( make, symlinks.str[j] ), obj_dir_path( make, program ));
3397 output_symlink_rule( obj_dir_path( make, program ), obj_dir_path( make, symlinks.str[j] ));
3399 strarray_addall( &make->all_targets, symlinks );
3401 add_install_rule( make, program, program_installed ? program_installed : program,
3402 strmake( "p$(bindir)/%s", program ));
3403 for (j = 0; j < symlinks.count; j++)
3404 add_install_rule( make, symlinks.str[j], program,
3405 strmake( "y$(bindir)/%s%s", symlinks.str[j], exe_ext ));
3410 /*******************************************************************
3411 * output_subdirs
3413 static void output_subdirs( struct makefile *make )
3415 struct strarray symlinks = empty_strarray;
3416 struct strarray all_deps = empty_strarray;
3417 struct strarray build_deps = empty_strarray;
3418 struct strarray builddeps_deps = empty_strarray;
3419 struct strarray makefile_deps = empty_strarray;
3420 struct strarray clean_files = empty_strarray;
3421 struct strarray testclean_files = empty_strarray;
3422 struct strarray distclean_files = empty_strarray;
3423 struct strarray tools_deps = empty_strarray;
3424 struct strarray tooldeps_deps = empty_strarray;
3425 struct strarray winetest_deps = empty_strarray;
3426 struct strarray crosstest_deps = empty_strarray;
3427 unsigned int i, j;
3429 strarray_addall( &distclean_files, make->distclean_files );
3430 for (i = 0; i < make->subdirs.count; i++)
3432 const struct makefile *submake = make->submakes[i];
3433 char *subdir = base_dir_path( submake, "" );
3435 strarray_add( &makefile_deps, top_src_dir_path( make, base_dir_path( submake,
3436 strmake ( "%s.in", output_makefile_name ))));
3437 for (j = 0; j < submake->clean_files.count; j++)
3438 strarray_add( &clean_files, base_dir_path( submake, submake->clean_files.str[j] ));
3439 for (j = 0; j < submake->distclean_files.count; j++)
3440 strarray_add( &distclean_files, base_dir_path( submake, submake->distclean_files.str[j] ));
3441 for (j = 0; j < submake->ok_files.count; j++)
3442 strarray_add( &testclean_files, base_dir_path( submake, submake->ok_files.str[j] ));
3444 /* import libs are still created for disabled dirs, except for win16 ones */
3445 if (submake->module && submake->importlib && !(submake->disabled && submake->is_win16))
3447 char *importlib_path = base_dir_path( submake, strmake( "lib%s", submake->importlib ));
3448 if (submake->implib_objs.count)
3450 output( "%s.a: dummy\n", importlib_path );
3451 output( "\t@cd %s && $(MAKE) lib%s.a\n", subdir, submake->importlib );
3452 strarray_add( &tools_deps, strmake( "%s.a", importlib_path ));
3453 if (crosstarget)
3455 output( "%s.cross.a: dummy\n", importlib_path );
3456 output( "\t@cd %s && $(MAKE) lib%s.cross.a\n", subdir, submake->importlib );
3457 strarray_add( &tools_deps, strmake( "%s.cross.a", importlib_path ));
3460 else
3462 const char *libext = *dll_ext ? ".def" : ".a";
3463 char *spec_file = top_src_dir_path( make, base_dir_path( submake,
3464 replace_extension( submake->module, ".dll", ".spec" )));
3465 output( "%s%s: %s", importlib_path, libext, spec_file );
3466 output_filename( tools_path( make, "winebuild" ));
3467 output( "\n" );
3468 output( "\t%s -w -o $@", tools_path( make, "winebuild" ));
3469 output_filename( *dll_ext ? "--def" : "--implib" );
3470 output_filenames( target_flags );
3471 if (submake->is_win16) output_filename( "-m16" );
3472 output_filename( "--export" );
3473 output_filename( spec_file );
3474 output( "\n" );
3475 strarray_add( &build_deps, strmake( "%s%s", importlib_path, libext ));
3476 if (crosstarget && !submake->is_win16)
3478 output( "%s.cross.a: %s", importlib_path, spec_file );
3479 output_filename( tools_path( make, "winebuild" ));
3480 output( "\n" );
3481 output( "\t%s -b %s -w -o $@", tools_path( make, "winebuild" ), crosstarget );
3482 output_filename( "--implib" );
3483 output_filenames( target_flags );
3484 output_filename( "--export" );
3485 output_filename( spec_file );
3486 output( "\n" );
3487 strarray_add( &build_deps, strmake( "%s.cross.a", importlib_path ));
3490 strarray_addall( &symlinks, output_importlib_symlinks( make, submake ));
3493 if (submake->disabled) continue;
3494 strarray_add( &all_deps, subdir );
3496 if (submake->module)
3498 if (!submake->staticlib)
3500 strarray_add( &builddeps_deps, subdir );
3501 if (!submake->appmode.count)
3503 output( "manpages htmlpages sgmlpages xmlpages::\n" );
3504 output( "\t@cd %s && $(MAKE) $@\n", subdir );
3507 else strarray_add( &tools_deps, subdir );
3509 else if (submake->testdll)
3511 output( "%s/test: dummy\n", subdir );
3512 output( "\t@cd %s && $(MAKE) test\n", subdir );
3513 strarray_add( &winetest_deps, subdir );
3514 strarray_add( &builddeps_deps, subdir );
3515 if (crosstarget)
3517 char *target = base_dir_path( submake, "crosstest" );
3518 output( "crosstest: %s\n", target );
3519 output( "%s: dummy\n", target );
3520 output( "\t@cd %s && $(MAKE) crosstest\n", subdir );
3521 strarray_add( &crosstest_deps, target );
3522 strarray_add( &builddeps_deps, target );
3525 else
3527 if (!strcmp( submake->base_dir, "tools" ) || !strncmp( submake->base_dir, "tools/", 6 ))
3529 strarray_add( &tooldeps_deps, submake->base_dir );
3530 for (j = 0; j < submake->programs.count; j++)
3531 output( "%s/%s%s: %s\n", submake->base_dir,
3532 submake->programs.str[j], tools_ext, submake->base_dir );
3534 if (submake->programs.count || submake->sharedlib)
3536 struct strarray libs = get_expanded_make_var_array( submake, "EXTRALIBS" );
3537 for (j = 0; j < submake->programs.count; j++)
3538 strarray_addall( &libs, get_expanded_file_local_var( submake,
3539 submake->programs.str[j], "LDFLAGS" ));
3540 output( "%s: libs/port", submake->base_dir );
3541 for (j = 0; j < libs.count; j++)
3543 if (!strcmp( libs.str[j], "-lwpp" )) output_filename( "libs/wpp" );
3544 if (!strcmp( libs.str[j], "-lwine" )) output_filename( "libs/wine" );
3546 output( "\n" );
3550 if (submake->install_rules[INSTALL_LIB].count)
3552 output( "install install-lib:: %s\n", submake->base_dir );
3553 output_install_commands( make, submake, submake->install_rules[INSTALL_LIB] );
3555 if (submake->install_rules[INSTALL_DEV].count)
3557 output( "install install-dev:: %s\n", submake->base_dir );
3558 output_install_commands( make, submake, submake->install_rules[INSTALL_DEV] );
3561 output( "all:" );
3562 output_filenames( all_deps );
3563 output( "\n" );
3564 output_filenames( all_deps );
3565 output( ": dummy\n" );
3566 output( "\t@cd $@ && $(MAKE)\n" );
3567 output( "Makefile:" );
3568 output_filenames( makefile_deps );
3569 output( "\n" );
3570 output_filenames( makefile_deps );
3571 output( ":\n" );
3572 if (tooldeps_deps.count)
3574 output( "__tooldeps__:" );
3575 output_filenames( tooldeps_deps );
3576 output( "\n" );
3577 strarray_add( &make->phony_targets, "__tooldeps__" );
3579 if (winetest_deps.count)
3581 output( "programs/winetest:" );
3582 output_filenames( winetest_deps );
3583 output( "\n" );
3584 output( "check test:" );
3585 for (i = 0; i < winetest_deps.count; i++)
3587 char *target = strmake( "%s/test", winetest_deps.str[i] );
3588 output_filename( target );
3589 strarray_add( &make->phony_targets, target );
3591 output( "\n" );
3592 strarray_add( &make->phony_targets, "check" );
3593 strarray_add( &make->phony_targets, "test" );
3595 output( "crosstest:" );
3596 output_filenames( crosstest_deps );
3597 output( "\n" );
3598 if (!crosstest_deps.count)
3599 output( "\t@echo \"crosstest is not supported (mingw not installed?)\" && false\n" );
3600 strarray_add( &make->phony_targets, "crosstest" );
3602 output( "clean::\n");
3603 output_rm_filenames( clean_files );
3604 output( "testclean::\n");
3605 output_rm_filenames( testclean_files );
3606 output( "distclean::\n");
3607 output_rm_filenames( distclean_files );
3608 output_filenames( tools_deps );
3609 output( ":" );
3610 output_filename( tools_dir_path( make, "widl" ));
3611 output_filename( tools_dir_path( make, "winebuild" ));
3612 output_filename( tools_dir_path( make, "winegcc" ));
3613 output_filename( obj_dir_path( make, "include" ));
3614 output( "\n" );
3615 output_filenames( builddeps_deps );
3616 output( ": __builddeps__\n" );
3617 strarray_add( &make->phony_targets, "distclean" );
3618 strarray_add( &make->phony_targets, "testclean" );
3619 strarray_addall( &make->phony_targets, all_deps );
3620 strarray_addall( &make->phony_targets, crosstest_deps );
3622 strarray_addall( &make->clean_files, symlinks );
3623 strarray_addall( &build_deps, tools_deps );
3624 strarray_addall( &build_deps, symlinks );
3625 if (build_deps.count)
3627 output( "__builddeps__:" );
3628 output_filenames( build_deps );
3629 output( "\n" );
3630 strarray_add( &make->phony_targets, "__builddeps__" );
3632 if (get_expanded_make_variable( make, "GETTEXTPO_LIBS" )) output_po_files( make );
3636 /*******************************************************************
3637 * output_sources
3639 static void output_sources( struct makefile *make )
3641 struct incl_file *source;
3642 unsigned int i, j;
3644 strarray_add( &make->phony_targets, "all" );
3646 LIST_FOR_EACH_ENTRY( source, &make->sources, struct incl_file, entry )
3648 char *obj = xstrdup( source->name );
3649 char *ext = get_extension( obj );
3651 if (!ext) fatal_error( "unsupported file type %s\n", source->name );
3652 *ext++ = 0;
3654 for (j = 0; output_source_funcs[j].ext; j++)
3655 if (!strcmp( ext, output_source_funcs[j].ext )) break;
3657 output_source_funcs[j].fn( make, source, obj );
3658 strarray_addall_uniq( &make->dependencies, source->dependencies );
3661 /* special case for winetest: add resource files from other test dirs */
3662 if (make->base_dir && !strcmp( make->base_dir, "programs/winetest" ))
3664 struct strarray tests = enable_tests;
3665 if (!tests.count)
3666 for (i = 0; i < top_makefile->subdirs.count; i++)
3667 if (top_makefile->submakes[i]->testdll && !top_makefile->submakes[i]->disabled)
3668 strarray_add( &tests, top_makefile->submakes[i]->testdll );
3669 for (i = 0; i < tests.count; i++)
3670 strarray_add( &make->object_files, replace_extension( tests.str[i], ".dll", "_test.res" ));
3673 if (make->dlldata_files.count)
3675 output( "%s: %s %s\n", obj_dir_path( make, "dlldata.c" ),
3676 tools_path( make, "widl" ), src_dir_path( make, "Makefile.in" ));
3677 output( "\t%s --dlldata-only -o $@", tools_path( make, "widl" ));
3678 output_filenames( make->dlldata_files );
3679 output( "\n" );
3682 if (make->staticlib) output_static_lib( make );
3683 else if (make->module) output_module( make );
3684 else if (make->testdll) output_test_module( make );
3685 else
3687 if (make->importlib) output_import_lib( make );
3688 if (make->sharedlib) output_shared_lib( make );
3689 if (make->programs.count) output_programs( make );
3692 for (i = 0; i < make->scripts.count; i++)
3693 add_install_rule( make, make->scripts.str[i], make->scripts.str[i],
3694 strmake( "S$(bindir)/%s", make->scripts.str[i] ));
3696 if (!make->src_dir) strarray_add( &make->distclean_files, ".gitignore" );
3697 strarray_add( &make->distclean_files, "Makefile" );
3698 if (make->testdll) strarray_add( &make->distclean_files, "testlist.c" );
3700 if (!make->base_dir)
3701 strarray_addall( &make->distclean_files, get_expanded_make_var_array( make, "CONFIGURE_TARGETS" ));
3702 else if (!strcmp( make->base_dir, "po" ))
3703 strarray_add( &make->distclean_files, "LINGUAS" );
3705 if (make->subdirs.count) output_subdirs( make );
3707 if (!make->disabled)
3709 if (make->all_targets.count)
3711 output( "all:" );
3712 output_filenames_obj_dir( make, make->all_targets );
3713 output( "\n" );
3715 output_install_rules( make, INSTALL_LIB, "install-lib" );
3716 output_install_rules( make, INSTALL_DEV, "install-dev" );
3717 output_uninstall_rules( make );
3720 if (make->dependencies.count)
3722 output_filenames( make->dependencies );
3723 output( ":\n" );
3726 strarray_addall( &make->clean_files, make->object_files );
3727 strarray_addall_uniq( &make->clean_files, make->crossobj_files );
3728 strarray_addall( &make->clean_files, make->all_targets );
3729 strarray_addall( &make->clean_files, get_expanded_make_var_array( make, "EXTRA_TARGETS" ));
3731 if (make->clean_files.count)
3733 output( "%s::\n", obj_dir_path( make, "clean" ));
3734 output( "\trm -f" );
3735 output_filenames_obj_dir( make, make->clean_files );
3736 output( "\n" );
3737 if (make->obj_dir) output( "__clean__: %s\n", obj_dir_path( make, "clean" ));
3738 strarray_add( &make->phony_targets, obj_dir_path( make, "clean" ));
3741 if (make->phony_targets.count)
3743 output( ".PHONY:" );
3744 output_filenames( make->phony_targets );
3745 output( "\n" );
3750 /*******************************************************************
3751 * create_temp_file
3753 static FILE *create_temp_file( const char *orig )
3755 char *name = xmalloc( strlen(orig) + 13 );
3756 unsigned int i, id = getpid();
3757 int fd;
3758 FILE *ret = NULL;
3760 for (i = 0; i < 100; i++)
3762 sprintf( name, "%s.tmp%08x", orig, id );
3763 if ((fd = open( name, O_RDWR | O_CREAT | O_EXCL, 0666 )) != -1)
3765 ret = fdopen( fd, "w" );
3766 break;
3768 if (errno != EEXIST) break;
3769 id += 7777;
3771 if (!ret) fatal_error( "failed to create output file for '%s'\n", orig );
3772 temp_file_name = name;
3773 return ret;
3777 /*******************************************************************
3778 * rename_temp_file
3780 static void rename_temp_file( const char *dest )
3782 int ret = rename( temp_file_name, dest );
3783 if (ret == -1 && errno == EEXIST)
3785 /* rename doesn't overwrite on windows */
3786 unlink( dest );
3787 ret = rename( temp_file_name, dest );
3789 if (ret == -1) fatal_error( "failed to rename output file to '%s'\n", dest );
3790 temp_file_name = NULL;
3794 /*******************************************************************
3795 * are_files_identical
3797 static int are_files_identical( FILE *file1, FILE *file2 )
3799 for (;;)
3801 char buffer1[8192], buffer2[8192];
3802 int size1 = fread( buffer1, 1, sizeof(buffer1), file1 );
3803 int size2 = fread( buffer2, 1, sizeof(buffer2), file2 );
3804 if (size1 != size2) return 0;
3805 if (!size1) return feof( file1 ) && feof( file2 );
3806 if (memcmp( buffer1, buffer2, size1 )) return 0;
3811 /*******************************************************************
3812 * rename_temp_file_if_changed
3814 static void rename_temp_file_if_changed( const char *dest )
3816 FILE *file1, *file2;
3817 int do_rename = 1;
3819 if ((file1 = fopen( dest, "r" )))
3821 if ((file2 = fopen( temp_file_name, "r" )))
3823 do_rename = !are_files_identical( file1, file2 );
3824 fclose( file2 );
3826 fclose( file1 );
3828 if (!do_rename)
3830 unlink( temp_file_name );
3831 temp_file_name = NULL;
3833 else rename_temp_file( dest );
3837 /*******************************************************************
3838 * output_linguas
3840 static void output_linguas( const struct makefile *make )
3842 const char *dest = base_dir_path( make, "LINGUAS" );
3843 struct incl_file *source;
3845 output_file = create_temp_file( dest );
3847 output( "# Automatically generated by make depend; DO NOT EDIT!!\n" );
3848 LIST_FOR_EACH_ENTRY( source, &make->sources, struct incl_file, entry )
3849 if (strendswith( source->name, ".po" ))
3850 output( "%s\n", replace_extension( source->name, ".po", "" ));
3852 if (fclose( output_file )) fatal_perror( "write" );
3853 output_file = NULL;
3854 rename_temp_file_if_changed( dest );
3858 /*******************************************************************
3859 * output_testlist
3861 static void output_testlist( const struct makefile *make )
3863 const char *dest = base_dir_path( make, "testlist.c" );
3864 struct strarray files = empty_strarray;
3865 unsigned int i;
3867 for (i = 0; i < make->ok_files.count; i++)
3868 strarray_add( &files, replace_extension( make->ok_files.str[i], ".ok", "" ));
3870 output_file = create_temp_file( dest );
3872 output( "/* Automatically generated by make depend; DO NOT EDIT!! */\n\n" );
3873 output( "#define WIN32_LEAN_AND_MEAN\n" );
3874 output( "#include <windows.h>\n\n" );
3875 output( "#define STANDALONE\n" );
3876 output( "#include \"wine/test.h\"\n\n" );
3878 for (i = 0; i < files.count; i++) output( "extern void func_%s(void);\n", files.str[i] );
3879 output( "\n" );
3880 output( "const struct test winetest_testlist[] =\n" );
3881 output( "{\n" );
3882 for (i = 0; i < files.count; i++) output( " { \"%s\", func_%s },\n", files.str[i], files.str[i] );
3883 output( " { 0, 0 }\n" );
3884 output( "};\n" );
3886 if (fclose( output_file )) fatal_perror( "write" );
3887 output_file = NULL;
3888 rename_temp_file_if_changed( dest );
3892 /*******************************************************************
3893 * output_gitignore
3895 static void output_gitignore( const char *dest, struct strarray files )
3897 int i;
3899 output_file = create_temp_file( dest );
3901 output( "# Automatically generated by make depend; DO NOT EDIT!!\n" );
3902 for (i = 0; i < files.count; i++)
3904 if (!strchr( files.str[i], '/' )) output( "/" );
3905 output( "%s\n", files.str[i] );
3908 if (fclose( output_file )) fatal_perror( "write" );
3909 output_file = NULL;
3910 rename_temp_file( dest );
3914 /*******************************************************************
3915 * output_top_variables
3917 static void output_top_variables( const struct makefile *make )
3919 unsigned int i;
3920 struct strarray *vars = &top_makefile->vars;
3922 if (!make->base_dir) return; /* don't output variables in the top makefile */
3924 output( "# Automatically generated by make depend; DO NOT EDIT!!\n\n" );
3925 output( "all:\n\n" );
3926 for (i = 0; i < vars->count; i += 2)
3928 if (!strcmp( vars->str[i], "SUBDIRS" )) continue; /* not inherited */
3929 output( "%s = %s\n", vars->str[i], get_make_variable( make, vars->str[i] ));
3931 output( "\n" );
3935 /*******************************************************************
3936 * output_dependencies
3938 static void output_dependencies( struct makefile *make )
3940 struct strarray ignore_files = empty_strarray;
3941 char buffer[1024];
3942 FILE *src_file;
3943 int found = 0;
3945 if (make->base_dir) create_dir( make->base_dir );
3947 output_file_name = base_dir_path( make, output_makefile_name );
3948 output_file = create_temp_file( output_file_name );
3949 output_top_variables( make );
3951 /* copy the contents of the source makefile */
3952 src_file = open_input_makefile( make );
3953 while (fgets( buffer, sizeof(buffer), src_file ) && !found)
3955 if (fwrite( buffer, 1, strlen(buffer), output_file ) != strlen(buffer)) fatal_perror( "write" );
3956 found = !strncmp( buffer, separator, strlen(separator) );
3958 if (fclose( src_file )) fatal_perror( "close" );
3959 input_file_name = NULL;
3961 if (!found) output( "\n%s (everything below this line is auto-generated; DO NOT EDIT!!)\n", separator );
3962 output_sources( make );
3964 fclose( output_file );
3965 output_file = NULL;
3966 rename_temp_file( output_file_name );
3968 strarray_addall( &ignore_files, make->distclean_files );
3969 strarray_addall( &ignore_files, make->clean_files );
3970 if (make->testdll) output_testlist( make );
3971 if (make->base_dir && !strcmp( make->base_dir, "po" )) output_linguas( make );
3972 if (!make->src_dir) output_gitignore( base_dir_path( make, ".gitignore" ), ignore_files );
3974 create_file_directories( make, ignore_files );
3976 output_file_name = NULL;
3980 /*******************************************************************
3981 * load_sources
3983 static void load_sources( struct makefile *make )
3985 static const char *source_vars[] =
3987 "SOURCES",
3988 "C_SRCS",
3989 "OBJC_SRCS",
3990 "RC_SRCS",
3991 "MC_SRCS",
3992 "IDL_SRCS",
3993 "BISON_SRCS",
3994 "LEX_SRCS",
3995 "HEADER_SRCS",
3996 "XTEMPLATE_SRCS",
3997 "SVG_SRCS",
3998 "FONT_SRCS",
3999 "IN_SRCS",
4000 "PO_SRCS",
4001 "MANPAGES",
4002 NULL
4004 const char **var;
4005 unsigned int i;
4006 struct strarray value;
4007 struct incl_file *file;
4009 if (root_src_dir)
4011 make->top_src_dir = concat_paths( make->top_obj_dir, root_src_dir );
4012 make->src_dir = concat_paths( make->top_src_dir, make->base_dir );
4014 strarray_set_value( &make->vars, "top_builddir", top_obj_dir_path( make, "" ));
4015 strarray_set_value( &make->vars, "top_srcdir", top_src_dir_path( make, "" ));
4016 strarray_set_value( &make->vars, "srcdir", src_dir_path( make, "" ));
4018 make->parent_dir = get_expanded_make_variable( make, "PARENTSRC" );
4019 make->module = get_expanded_make_variable( make, "MODULE" );
4020 make->testdll = get_expanded_make_variable( make, "TESTDLL" );
4021 make->sharedlib = get_expanded_make_variable( make, "SHAREDLIB" );
4022 make->staticlib = get_expanded_make_variable( make, "STATICLIB" );
4023 make->importlib = get_expanded_make_variable( make, "IMPORTLIB" );
4025 make->programs = get_expanded_make_var_array( make, "PROGRAMS" );
4026 make->scripts = get_expanded_make_var_array( make, "SCRIPTS" );
4027 make->appmode = get_expanded_make_var_array( make, "APPMODE" );
4028 make->imports = get_expanded_make_var_array( make, "IMPORTS" );
4029 make->delayimports = get_expanded_make_var_array( make, "DELAYIMPORTS" );
4030 make->extradllflags = get_expanded_make_var_array( make, "EXTRADLLFLAGS" );
4031 make->install_lib = get_expanded_make_var_array( make, "INSTALL_LIB" );
4032 make->install_dev = get_expanded_make_var_array( make, "INSTALL_DEV" );
4034 if (make->module && strendswith( make->module, ".a" )) make->staticlib = make->module;
4036 make->disabled = make->base_dir && strarray_exists( &disabled_dirs, make->base_dir );
4037 make->is_win16 = strarray_exists( &make->extradllflags, "-m16" ) || strarray_exists( &make->appmode, "-m16" );
4038 make->use_msvcrt = strarray_exists( &make->appmode, "-mno-cygwin" );
4040 for (i = 0; i < make->imports.count && !make->use_msvcrt; i++)
4041 make->use_msvcrt = !strncmp( make->imports.str[i], "msvcr", 5 ) ||
4042 !strcmp( make->imports.str[i], "ucrtbase" );
4044 if (make->module && !make->install_lib.count && !make->install_dev.count)
4046 if (make->importlib) strarray_add( &make->install_dev, make->importlib );
4047 if (make->staticlib) strarray_add( &make->install_dev, make->staticlib );
4048 else strarray_add( &make->install_lib, make->module );
4051 make->include_paths = empty_strarray;
4052 make->include_args = empty_strarray;
4053 make->define_args = empty_strarray;
4054 strarray_add( &make->define_args, "-D__WINESRC__" );
4056 value = get_expanded_make_var_array( make, "EXTRAINCL" );
4057 for (i = 0; i < value.count; i++)
4058 if (!strncmp( value.str[i], "-I", 2 ))
4059 strarray_add_uniq( &make->include_paths, value.str[i] + 2 );
4060 else
4061 strarray_add_uniq( &make->define_args, value.str[i] );
4062 strarray_addall( &make->define_args, get_expanded_make_var_array( make, "EXTRADEFS" ));
4064 strarray_add( &make->include_args, strmake( "-I%s", obj_dir_path( make, "" )));
4065 if (make->src_dir)
4066 strarray_add( &make->include_args, strmake( "-I%s", make->src_dir ));
4067 if (make->parent_dir)
4068 strarray_add( &make->include_args, strmake( "-I%s", src_dir_path( make, make->parent_dir )));
4069 strarray_add( &make->include_args, strmake( "-I%s", top_obj_dir_path( make, "include" )));
4070 if (make->top_src_dir)
4071 strarray_add( &make->include_args, strmake( "-I%s", top_src_dir_path( make, "include" )));
4072 if (make->use_msvcrt)
4073 strarray_add( &make->include_args, strmake( "-I%s", top_src_dir_path( make, "include/msvcrt" )));
4074 for (i = 0; i < make->include_paths.count; i++)
4075 strarray_add( &make->include_args, strmake( "-I%s", obj_dir_path( make, make->include_paths.str[i] )));
4077 list_init( &make->sources );
4078 list_init( &make->includes );
4080 for (var = source_vars; *var; var++)
4082 value = get_expanded_make_var_array( make, *var );
4083 for (i = 0; i < value.count; i++) add_src_file( make, value.str[i] );
4086 add_generated_sources( make );
4088 value = get_expanded_make_var_array( make, "EXTRA_OBJS" );
4089 for (i = 0; i < value.count; i++)
4091 /* default to .c for unknown extra object files */
4092 if (strendswith( value.str[i], ".o" ))
4093 add_generated_source( make, value.str[i], replace_extension( value.str[i], ".o", ".c" ) );
4094 else
4095 add_generated_source( make, value.str[i], NULL );
4098 LIST_FOR_EACH_ENTRY( file, &make->includes, struct incl_file, entry ) parse_file( make, file, 0 );
4099 LIST_FOR_EACH_ENTRY( file, &make->sources, struct incl_file, entry ) get_dependencies( file, file );
4103 /*******************************************************************
4104 * parse_makeflags
4106 static void parse_makeflags( const char *flags )
4108 const char *p = flags;
4109 char *var, *buffer = xmalloc( strlen(flags) + 1 );
4111 while (*p)
4113 while (isspace(*p)) p++;
4114 var = buffer;
4115 while (*p && !isspace(*p))
4117 if (*p == '\\' && p[1]) p++;
4118 *var++ = *p++;
4120 *var = 0;
4121 if (var > buffer) set_make_variable( &cmdline_vars, buffer );
4126 /*******************************************************************
4127 * parse_option
4129 static int parse_option( const char *opt )
4131 if (opt[0] != '-')
4133 if (strchr( opt, '=' )) return set_make_variable( &cmdline_vars, opt );
4134 return 0;
4136 switch(opt[1])
4138 case 'f':
4139 if (opt[2]) output_makefile_name = opt + 2;
4140 break;
4141 case 'R':
4142 relative_dir_mode = 1;
4143 break;
4144 default:
4145 fprintf( stderr, "Unknown option '%s'\n%s", opt, Usage );
4146 exit(1);
4148 return 1;
4152 /*******************************************************************
4153 * main
4155 int main( int argc, char *argv[] )
4157 const char *makeflags = getenv( "MAKEFLAGS" );
4158 int i, j;
4160 if (makeflags) parse_makeflags( makeflags );
4162 i = 1;
4163 while (i < argc)
4165 if (parse_option( argv[i] ))
4167 for (j = i; j < argc; j++) argv[j] = argv[j+1];
4168 argc--;
4170 else i++;
4173 if (relative_dir_mode)
4175 char *relpath;
4177 if (argc != 3)
4179 fprintf( stderr, "Option -R needs two directories\n%s", Usage );
4180 exit( 1 );
4182 relpath = get_relative_path( argv[1], argv[2] );
4183 printf( "%s\n", relpath ? relpath : "." );
4184 exit( 0 );
4187 atexit( cleanup_files );
4188 signal( SIGTERM, exit_on_signal );
4189 signal( SIGINT, exit_on_signal );
4190 #ifdef SIGHUP
4191 signal( SIGHUP, exit_on_signal );
4192 #endif
4194 for (i = 0; i < HASH_SIZE; i++) list_init( &files[i] );
4196 top_makefile = parse_makefile( NULL );
4198 target_flags = get_expanded_make_var_array( top_makefile, "TARGETFLAGS" );
4199 msvcrt_flags = get_expanded_make_var_array( top_makefile, "MSVCRTFLAGS" );
4200 dll_flags = get_expanded_make_var_array( top_makefile, "DLLFLAGS" );
4201 extra_cflags = get_expanded_make_var_array( top_makefile, "EXTRACFLAGS" );
4202 cpp_flags = get_expanded_make_var_array( top_makefile, "CPPFLAGS" );
4203 unwind_flags = get_expanded_make_var_array( top_makefile, "UNWINDFLAGS" );
4204 libs = get_expanded_make_var_array( top_makefile, "LIBS" );
4205 enable_tests = get_expanded_make_var_array( top_makefile, "ENABLE_TESTS" );
4207 root_src_dir = get_expanded_make_variable( top_makefile, "srcdir" );
4208 tools_dir = get_expanded_make_variable( top_makefile, "TOOLSDIR" );
4209 tools_ext = get_expanded_make_variable( top_makefile, "TOOLSEXT" );
4210 exe_ext = get_expanded_make_variable( top_makefile, "EXEEXT" );
4211 man_ext = get_expanded_make_variable( top_makefile, "api_manext" );
4212 dll_ext = (exe_ext && !strcmp( exe_ext, ".exe" )) ? "" : ".so";
4213 crosstarget = get_expanded_make_variable( top_makefile, "CROSSTARGET" );
4214 fontforge = get_expanded_make_variable( top_makefile, "FONTFORGE" );
4215 convert = get_expanded_make_variable( top_makefile, "CONVERT" );
4216 rsvg = get_expanded_make_variable( top_makefile, "RSVG" );
4217 icotool = get_expanded_make_variable( top_makefile, "ICOTOOL" );
4218 dlltool = get_expanded_make_variable( top_makefile, "DLLTOOL" );
4219 msgfmt = get_expanded_make_variable( top_makefile, "MSGFMT" );
4220 ln_s = get_expanded_make_variable( top_makefile, "LN_S" );
4222 if (root_src_dir && !strcmp( root_src_dir, "." )) root_src_dir = NULL;
4223 if (tools_dir && !strcmp( tools_dir, "." )) tools_dir = NULL;
4224 if (!exe_ext) exe_ext = "";
4225 if (!tools_ext) tools_ext = "";
4226 if (!man_ext) man_ext = "3w";
4228 if (argc == 1)
4230 disabled_dirs = get_expanded_make_var_array( top_makefile, "DISABLED_SUBDIRS" );
4231 top_makefile->subdirs = get_expanded_make_var_array( top_makefile, "SUBDIRS" );
4232 top_makefile->submakes = xmalloc( top_makefile->subdirs.count * sizeof(*top_makefile->submakes) );
4234 for (i = 0; i < top_makefile->subdirs.count; i++)
4235 top_makefile->submakes[i] = parse_makefile( top_makefile->subdirs.str[i] );
4237 load_sources( top_makefile );
4238 for (i = 0; i < top_makefile->subdirs.count; i++)
4239 load_sources( top_makefile->submakes[i] );
4241 for (i = 0; i < top_makefile->subdirs.count; i++)
4242 output_dependencies( top_makefile->submakes[i] );
4244 output_dependencies( top_makefile );
4245 return 0;
4248 for (i = 1; i < argc; i++)
4250 struct makefile *make = parse_makefile( argv[i] );
4251 load_sources( make );
4252 output_dependencies( make );
4254 return 0;