winefile: Explicitly mark qsort() callback funtions cdecl.
[wine.git] / tools / makedep.c
blob97017d73fb45aca1cb85e1af7286a5c142f72e40
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_PARENTDIR 0x000004 /* file comes from parent dir */
93 #define FLAG_IDL_PROXY 0x000100 /* generates a proxy (_p.c) file */
94 #define FLAG_IDL_CLIENT 0x000200 /* generates a client (_c.c) file */
95 #define FLAG_IDL_SERVER 0x000400 /* generates a server (_s.c) file */
96 #define FLAG_IDL_IDENT 0x000800 /* generates an ident (_i.c) file */
97 #define FLAG_IDL_REGISTER 0x001000 /* generates a registration (_r.res) file */
98 #define FLAG_IDL_TYPELIB 0x002000 /* generates a typelib (.tlb) file */
99 #define FLAG_IDL_REGTYPELIB 0x004000 /* generates a registered typelib (_t.res) file */
100 #define FLAG_IDL_HEADER 0x008000 /* generates a header (.h) file */
101 #define FLAG_RC_PO 0x010000 /* rc file contains translations */
102 #define FLAG_C_IMPLIB 0x020000 /* file is part of an import library */
103 #define FLAG_SFD_FONTS 0x040000 /* sfd file generated bitmap fonts */
105 static const struct
107 unsigned int flag;
108 const char *ext;
109 } idl_outputs[] =
111 { FLAG_IDL_TYPELIB, ".tlb" },
112 { FLAG_IDL_REGTYPELIB, "_t.res" },
113 { FLAG_IDL_CLIENT, "_c.c" },
114 { FLAG_IDL_IDENT, "_i.c" },
115 { FLAG_IDL_PROXY, "_p.c" },
116 { FLAG_IDL_SERVER, "_s.c" },
117 { FLAG_IDL_REGISTER, "_r.res" },
118 { FLAG_IDL_HEADER, ".h" }
121 #define HASH_SIZE 997
123 static struct list files[HASH_SIZE];
125 static const struct strarray empty_strarray;
127 enum install_rules { INSTALL_LIB, INSTALL_DEV, NB_INSTALL_RULES };
129 /* variables common to all makefiles */
130 static struct strarray linguas;
131 static struct strarray dll_flags;
132 static struct strarray target_flags;
133 static struct strarray msvcrt_flags;
134 static struct strarray extra_cflags;
135 static struct strarray extra_cross_cflags;
136 static struct strarray cpp_flags;
137 static struct strarray lddll_flags;
138 static struct strarray libs;
139 static struct strarray enable_tests;
140 static struct strarray cmdline_vars;
141 static struct strarray disabled_dirs;
142 static struct strarray cross_import_libs;
143 static struct strarray delay_import_libs;
144 static struct strarray top_install_lib;
145 static struct strarray top_install_dev;
146 static const char *root_src_dir;
147 static const char *tools_dir;
148 static const char *tools_ext;
149 static const char *exe_ext;
150 static const char *dll_ext;
151 static const char *man_ext;
152 static const char *crosstarget;
153 static const char *fontforge;
154 static const char *convert;
155 static const char *flex;
156 static const char *bison;
157 static const char *ar;
158 static const char *ranlib;
159 static const char *rsvg;
160 static const char *icotool;
161 static const char *dlltool;
162 static const char *msgfmt;
163 static const char *ln_s;
164 static const char *sed_cmd;
166 struct makefile
168 /* values determined from input makefile */
169 struct strarray vars;
170 struct strarray include_paths;
171 struct strarray include_args;
172 struct strarray define_args;
173 struct strarray programs;
174 struct strarray scripts;
175 struct strarray imports;
176 struct strarray subdirs;
177 struct strarray delayimports;
178 struct strarray extradllflags;
179 struct strarray install_lib;
180 struct strarray install_dev;
181 struct strarray extra_targets;
182 struct list sources;
183 struct list includes;
184 const char *base_dir;
185 const char *src_dir;
186 const char *obj_dir;
187 const char *top_src_dir;
188 const char *top_obj_dir;
189 const char *parent_dir;
190 const char *module;
191 const char *testdll;
192 const char *sharedlib;
193 const char *staticlib;
194 const char *staticimplib;
195 const char *importlib;
196 int disabled;
197 int use_msvcrt;
198 int is_cross;
199 int is_win16;
200 int is_exe;
201 struct makefile **submakes;
203 /* values generated at output time */
204 struct strarray in_files;
205 struct strarray ok_files;
206 struct strarray clean_files;
207 struct strarray distclean_files;
208 struct strarray uninstall_files;
209 struct strarray object_files;
210 struct strarray crossobj_files;
211 struct strarray res_files;
212 struct strarray c2man_files;
213 struct strarray dlldata_files;
214 struct strarray implib_objs;
215 struct strarray all_targets;
216 struct strarray phony_targets;
217 struct strarray dependencies;
218 struct strarray install_rules[NB_INSTALL_RULES];
221 static struct makefile *top_makefile;
223 static const char separator[] = "### Dependencies";
224 static const char *output_makefile_name = "Makefile";
225 static const char *input_file_name;
226 static const char *output_file_name;
227 static const char *temp_file_name;
228 static int relative_dir_mode;
229 static int input_line;
230 static int output_column;
231 static FILE *output_file;
233 static const char Usage[] =
234 "Usage: makedep [options] [directories]\n"
235 "Options:\n"
236 " -R from to Compute the relative path between two directories\n"
237 " -fxxx Store output in file 'xxx' (default: Makefile)\n";
240 #ifndef __GNUC__
241 #define __attribute__(x)
242 #endif
244 static void fatal_error( const char *msg, ... ) __attribute__ ((__format__ (__printf__, 1, 2)));
245 static void fatal_perror( const char *msg, ... ) __attribute__ ((__format__ (__printf__, 1, 2)));
246 static void output( const char *format, ... ) __attribute__ ((__format__ (__printf__, 1, 2)));
247 static char *strmake( const char* fmt, ... ) __attribute__ ((__format__ (__printf__, 1, 2)));
249 /*******************************************************************
250 * fatal_error
252 static void fatal_error( const char *msg, ... )
254 va_list valist;
255 va_start( valist, msg );
256 if (input_file_name)
258 fprintf( stderr, "%s:", input_file_name );
259 if (input_line) fprintf( stderr, "%d:", input_line );
260 fprintf( stderr, " error: " );
262 else fprintf( stderr, "makedep: error: " );
263 vfprintf( stderr, msg, valist );
264 va_end( valist );
265 exit(1);
269 /*******************************************************************
270 * fatal_perror
272 static void fatal_perror( const char *msg, ... )
274 va_list valist;
275 va_start( valist, msg );
276 if (input_file_name)
278 fprintf( stderr, "%s:", input_file_name );
279 if (input_line) fprintf( stderr, "%d:", input_line );
280 fprintf( stderr, " error: " );
282 else fprintf( stderr, "makedep: error: " );
283 vfprintf( stderr, msg, valist );
284 perror( " " );
285 va_end( valist );
286 exit(1);
290 /*******************************************************************
291 * cleanup_files
293 static void cleanup_files(void)
295 if (temp_file_name) unlink( temp_file_name );
296 if (output_file_name) unlink( output_file_name );
300 /*******************************************************************
301 * exit_on_signal
303 static void exit_on_signal( int sig )
305 exit( 1 ); /* this will call the atexit functions */
309 /*******************************************************************
310 * xmalloc
312 static void *xmalloc( size_t size )
314 void *res;
315 if (!(res = malloc (size ? size : 1)))
316 fatal_error( "Virtual memory exhausted.\n" );
317 return res;
321 /*******************************************************************
322 * xrealloc
324 static void *xrealloc (void *ptr, size_t size)
326 void *res;
327 assert( size );
328 if (!(res = realloc( ptr, size )))
329 fatal_error( "Virtual memory exhausted.\n" );
330 return res;
333 /*******************************************************************
334 * xstrdup
336 static char *xstrdup( const char *str )
338 char *res = strdup( str );
339 if (!res) fatal_error( "Virtual memory exhausted.\n" );
340 return res;
344 /*******************************************************************
345 * strmake
347 static char *strmake( const char* fmt, ... )
349 int n;
350 size_t size = 100;
351 va_list ap;
353 for (;;)
355 char *p = xmalloc (size);
356 va_start(ap, fmt);
357 n = vsnprintf (p, size, fmt, ap);
358 va_end(ap);
359 if (n == -1) size *= 2;
360 else if ((size_t)n >= size) size = n + 1;
361 else return xrealloc( p, n + 1 );
362 free(p);
367 /*******************************************************************
368 * strendswith
370 static int strendswith( const char* str, const char* end )
372 size_t l = strlen( str );
373 size_t m = strlen( end );
375 return l >= m && strcmp(str + l - m, end) == 0;
379 /*******************************************************************
380 * output
382 static void output( const char *format, ... )
384 int ret;
385 va_list valist;
387 va_start( valist, format );
388 ret = vfprintf( output_file, format, valist );
389 va_end( valist );
390 if (ret < 0) fatal_perror( "output" );
391 if (format[0] && format[strlen(format) - 1] == '\n') output_column = 0;
392 else output_column += ret;
396 /*******************************************************************
397 * strarray_add
399 static void strarray_add( struct strarray *array, const char *str )
401 if (array->count == array->size)
403 if (array->size) array->size *= 2;
404 else array->size = 16;
405 array->str = xrealloc( array->str, sizeof(array->str[0]) * array->size );
407 array->str[array->count++] = str;
411 /*******************************************************************
412 * strarray_addall
414 static void strarray_addall( struct strarray *array, struct strarray added )
416 unsigned int i;
418 for (i = 0; i < added.count; i++) strarray_add( array, added.str[i] );
422 /*******************************************************************
423 * strarray_exists
425 static int strarray_exists( const struct strarray *array, const char *str )
427 unsigned int i;
429 for (i = 0; i < array->count; i++) if (!strcmp( array->str[i], str )) return 1;
430 return 0;
434 /*******************************************************************
435 * strarray_add_uniq
437 static void strarray_add_uniq( struct strarray *array, const char *str )
439 if (!strarray_exists( array, str )) strarray_add( array, str );
443 /*******************************************************************
444 * strarray_addall_uniq
446 static void strarray_addall_uniq( struct strarray *array, struct strarray added )
448 unsigned int i;
450 for (i = 0; i < added.count; i++) strarray_add_uniq( array, added.str[i] );
454 /*******************************************************************
455 * strarray_get_value
457 * Find a value in a name/value pair string array.
459 static const char *strarray_get_value( const struct strarray *array, const char *name )
461 int pos, res, min = 0, max = array->count / 2 - 1;
463 while (min <= max)
465 pos = (min + max) / 2;
466 if (!(res = strcmp( array->str[pos * 2], name ))) return array->str[pos * 2 + 1];
467 if (res < 0) min = pos + 1;
468 else max = pos - 1;
470 return NULL;
474 /*******************************************************************
475 * strarray_set_value
477 * Define a value in a name/value pair string array.
479 static void strarray_set_value( struct strarray *array, const char *name, const char *value )
481 int i, pos, res, min = 0, max = array->count / 2 - 1;
483 while (min <= max)
485 pos = (min + max) / 2;
486 if (!(res = strcmp( array->str[pos * 2], name )))
488 /* redefining a variable replaces the previous value */
489 array->str[pos * 2 + 1] = value;
490 return;
492 if (res < 0) min = pos + 1;
493 else max = pos - 1;
495 strarray_add( array, NULL );
496 strarray_add( array, NULL );
497 for (i = array->count - 1; i > min * 2 + 1; i--) array->str[i] = array->str[i - 2];
498 array->str[min * 2] = name;
499 array->str[min * 2 + 1] = value;
503 /*******************************************************************
504 * strarray_set_qsort
506 static void strarray_qsort( struct strarray *array, int (*func)(const char **, const char **) )
508 if (array->count) qsort( array->str, array->count, sizeof(*array->str), (void *)func );
512 /*******************************************************************
513 * output_filename
515 static void output_filename( const char *name )
517 if (output_column + strlen(name) + 1 > 100)
519 output( " \\\n" );
520 output( " " );
522 else if (output_column) output( " " );
523 output( "%s", name );
527 /*******************************************************************
528 * output_filenames
530 static void output_filenames( struct strarray array )
532 unsigned int i;
534 for (i = 0; i < array.count; i++) output_filename( array.str[i] );
538 /*******************************************************************
539 * output_rm_filenames
541 static void output_rm_filenames( struct strarray array )
543 static const unsigned int max_cmdline = 30000; /* to be on the safe side */
544 unsigned int i, len;
546 if (!array.count) return;
547 output( "\trm -f" );
548 for (i = len = 0; i < array.count; i++)
550 if (len > max_cmdline)
552 output( "\n" );
553 output( "\trm -f" );
554 len = 0;
556 output_filename( array.str[i] );
557 len += strlen( array.str[i] ) + 1;
559 output( "\n" );
563 /*******************************************************************
564 * get_extension
566 static char *get_extension( char *filename )
568 char *ext = strrchr( filename, '.' );
569 if (ext && strchr( ext, '/' )) ext = NULL;
570 return ext;
574 /*******************************************************************
575 * replace_extension
577 static char *replace_extension( const char *name, const char *old_ext, const char *new_ext )
579 char *ret;
580 size_t name_len = strlen( name );
581 size_t ext_len = strlen( old_ext );
583 if (name_len >= ext_len && !strcmp( name + name_len - ext_len, old_ext )) name_len -= ext_len;
584 ret = xmalloc( name_len + strlen( new_ext ) + 1 );
585 memcpy( ret, name, name_len );
586 strcpy( ret + name_len, new_ext );
587 return ret;
591 /*******************************************************************
592 * replace_filename
594 static char *replace_filename( const char *path, const char *name )
596 const char *p;
597 char *ret;
598 size_t len;
600 if (!path) return xstrdup( name );
601 if (!(p = strrchr( path, '/' ))) return xstrdup( name );
602 len = p - path + 1;
603 ret = xmalloc( len + strlen( name ) + 1 );
604 memcpy( ret, path, len );
605 strcpy( ret + len, name );
606 return ret;
610 /*******************************************************************
611 * strarray_replace_extension
613 static struct strarray strarray_replace_extension( const struct strarray *array,
614 const char *old_ext, const char *new_ext )
616 unsigned int i;
617 struct strarray ret;
619 ret.count = ret.size = array->count;
620 ret.str = xmalloc( sizeof(ret.str[0]) * ret.size );
621 for (i = 0; i < array->count; i++) ret.str[i] = replace_extension( array->str[i], old_ext, new_ext );
622 return ret;
626 /*******************************************************************
627 * replace_substr
629 static char *replace_substr( const char *str, const char *start, size_t len, const char *replace )
631 size_t pos = start - str;
632 char *ret = xmalloc( pos + strlen(replace) + strlen(start + len) + 1 );
633 memcpy( ret, str, pos );
634 strcpy( ret + pos, replace );
635 strcat( ret + pos, start + len );
636 return ret;
640 /*******************************************************************
641 * get_relative_path
643 * Determine where the destination path is located relative to the 'from' path.
645 static char *get_relative_path( const char *from, const char *dest )
647 const char *start;
648 char *ret, *p;
649 unsigned int dotdots = 0;
651 /* a path of "." is equivalent to an empty path */
652 if (!strcmp( from, "." )) from = "";
654 for (;;)
656 while (*from == '/') from++;
657 while (*dest == '/') dest++;
658 start = dest; /* save start of next path element */
659 if (!*from) break;
661 while (*from && *from != '/' && *from == *dest) { from++; dest++; }
662 if ((!*from || *from == '/') && (!*dest || *dest == '/')) continue;
664 /* count remaining elements in 'from' */
667 dotdots++;
668 while (*from && *from != '/') from++;
669 while (*from == '/') from++;
671 while (*from);
672 break;
675 if (!start[0] && !dotdots) return NULL; /* empty path */
677 ret = xmalloc( 3 * dotdots + strlen( start ) + 1 );
678 for (p = ret; dotdots; dotdots--, p += 3) memcpy( p, "../", 3 );
680 if (start[0]) strcpy( p, start );
681 else p[-1] = 0; /* remove trailing slash */
682 return ret;
686 /*******************************************************************
687 * concat_paths
689 static char *concat_paths( const char *base, const char *path )
691 if (!base || !base[0]) return xstrdup( path && path[0] ? path : "." );
692 if (!path || !path[0]) return xstrdup( base );
693 if (path[0] == '/') return xstrdup( path );
694 return strmake( "%s/%s", base, path );
698 /*******************************************************************
699 * base_dir_path
701 static char *base_dir_path( const struct makefile *make, const char *path )
703 return concat_paths( make->base_dir, path );
707 /*******************************************************************
708 * obj_dir_path
710 static char *obj_dir_path( const struct makefile *make, const char *path )
712 return concat_paths( make->obj_dir, path );
716 /*******************************************************************
717 * src_dir_path
719 static char *src_dir_path( const struct makefile *make, const char *path )
721 if (make->src_dir) return concat_paths( make->src_dir, path );
722 return obj_dir_path( make, path );
726 /*******************************************************************
727 * top_obj_dir_path
729 static char *top_obj_dir_path( const struct makefile *make, const char *path )
731 return concat_paths( make->top_obj_dir, path );
735 /*******************************************************************
736 * top_src_dir_path
738 static char *top_src_dir_path( const struct makefile *make, const char *path )
740 if (make->top_src_dir) return concat_paths( make->top_src_dir, path );
741 return top_obj_dir_path( make, path );
745 /*******************************************************************
746 * root_dir_path
748 static char *root_dir_path( const char *path )
750 return concat_paths( root_src_dir, path );
754 /*******************************************************************
755 * tools_dir_path
757 static char *tools_dir_path( const struct makefile *make, const char *path )
759 if (tools_dir) return top_obj_dir_path( make, strmake( "%s/tools/%s", tools_dir, path ));
760 return top_obj_dir_path( make, strmake( "tools/%s", path ));
764 /*******************************************************************
765 * tools_path
767 static char *tools_path( const struct makefile *make, const char *name )
769 return strmake( "%s/%s%s", tools_dir_path( make, name ), name, tools_ext );
773 /*******************************************************************
774 * get_line
776 static char *get_line( FILE *file )
778 static char *buffer;
779 static size_t size;
781 if (!size)
783 size = 1024;
784 buffer = xmalloc( size );
786 if (!fgets( buffer, size, file )) return NULL;
787 input_line++;
789 for (;;)
791 char *p = buffer + strlen(buffer);
792 /* if line is larger than buffer, resize buffer */
793 while (p == buffer + size - 1 && p[-1] != '\n')
795 buffer = xrealloc( buffer, size * 2 );
796 if (!fgets( buffer + size - 1, size + 1, file )) break;
797 p = buffer + strlen(buffer);
798 size *= 2;
800 if (p > buffer && p[-1] == '\n')
802 *(--p) = 0;
803 if (p > buffer && p[-1] == '\r') *(--p) = 0;
804 if (p > buffer && p[-1] == '\\')
806 *(--p) = 0;
807 /* line ends in backslash, read continuation line */
808 if (!fgets( p, size - (p - buffer), file )) return buffer;
809 input_line++;
810 continue;
813 return buffer;
818 /*******************************************************************
819 * hash_filename
821 static unsigned int hash_filename( const char *name )
823 /* FNV-1 hash */
824 unsigned int ret = 2166136261u;
825 while (*name) ret = (ret * 16777619) ^ *name++;
826 return ret % HASH_SIZE;
830 /*******************************************************************
831 * add_file
833 static struct file *add_file( const char *name )
835 struct file *file = xmalloc( sizeof(*file) );
836 memset( file, 0, sizeof(*file) );
837 file->name = xstrdup( name );
838 return file;
842 /*******************************************************************
843 * add_dependency
845 static void add_dependency( struct file *file, const char *name, enum incl_type type )
847 /* enforce some rules for the Wine tree */
849 if (!memcmp( name, "../", 3 ))
850 fatal_error( "#include directive with relative path not allowed\n" );
852 if (!strcmp( name, "config.h" ))
854 if (strendswith( file->name, ".h" ))
855 fatal_error( "config.h must not be included by a header file\n" );
856 if (file->deps_count)
857 fatal_error( "config.h must be included before anything else\n" );
859 else if (!strcmp( name, "wine/port.h" ))
861 if (strendswith( file->name, ".h" ))
862 fatal_error( "wine/port.h must not be included by a header file\n" );
863 if (!file->deps_count) fatal_error( "config.h must be included before wine/port.h\n" );
864 if (file->deps_count > 1)
865 fatal_error( "wine/port.h must be included before everything except config.h\n" );
866 if (strcmp( file->deps[0].name, "config.h" ))
867 fatal_error( "config.h must be included before wine/port.h\n" );
870 if (file->deps_count >= file->deps_size)
872 file->deps_size *= 2;
873 if (file->deps_size < 16) file->deps_size = 16;
874 file->deps = xrealloc( file->deps, file->deps_size * sizeof(*file->deps) );
876 file->deps[file->deps_count].line = input_line;
877 file->deps[file->deps_count].type = type;
878 file->deps[file->deps_count].name = xstrdup( name );
879 file->deps_count++;
883 /*******************************************************************
884 * find_src_file
886 static struct incl_file *find_src_file( const struct makefile *make, const char *name )
888 struct incl_file *file;
890 LIST_FOR_EACH_ENTRY( file, &make->sources, struct incl_file, entry )
891 if (!strcmp( name, file->name )) return file;
892 return NULL;
895 /*******************************************************************
896 * find_include_file
898 static struct incl_file *find_include_file( const struct makefile *make, const char *name )
900 struct incl_file *file;
902 LIST_FOR_EACH_ENTRY( file, &make->includes, struct incl_file, entry )
903 if (!strcmp( name, file->name )) return file;
904 return NULL;
907 /*******************************************************************
908 * add_include
910 * Add an include file if it doesn't already exists.
912 static struct incl_file *add_include( struct makefile *make, struct incl_file *parent,
913 const char *name, int line, enum incl_type type )
915 struct incl_file *include;
917 if (parent->files_count >= parent->files_size)
919 parent->files_size *= 2;
920 if (parent->files_size < 16) parent->files_size = 16;
921 parent->files = xrealloc( parent->files, parent->files_size * sizeof(*parent->files) );
924 LIST_FOR_EACH_ENTRY( include, &make->includes, struct incl_file, entry )
925 if (!strcmp( name, include->name )) goto found;
927 include = xmalloc( sizeof(*include) );
928 memset( include, 0, sizeof(*include) );
929 include->name = xstrdup(name);
930 include->included_by = parent;
931 include->included_line = line;
932 include->type = type;
933 list_add_tail( &make->includes, &include->entry );
934 found:
935 parent->files[parent->files_count++] = include;
936 return include;
940 /*******************************************************************
941 * add_generated_source
943 * Add a generated source file to the list.
945 static struct incl_file *add_generated_source( struct makefile *make,
946 const char *name, const char *filename )
948 struct incl_file *file;
950 if ((file = find_src_file( make, name ))) return file; /* we already have it */
951 file = xmalloc( sizeof(*file) );
952 memset( file, 0, sizeof(*file) );
953 file->file = add_file( name );
954 file->name = xstrdup( name );
955 file->filename = obj_dir_path( make, filename ? filename : name );
956 file->file->flags = FLAG_GENERATED;
957 list_add_tail( &make->sources, &file->entry );
958 return file;
962 /*******************************************************************
963 * parse_include_directive
965 static void parse_include_directive( struct file *source, char *str )
967 char quote, *include, *p = str;
969 while (*p && isspace(*p)) p++;
970 if (*p != '\"' && *p != '<' ) return;
971 quote = *p++;
972 if (quote == '<') quote = '>';
973 include = p;
974 while (*p && (*p != quote)) p++;
975 if (!*p) fatal_error( "malformed include directive '%s'\n", str );
976 *p = 0;
977 add_dependency( source, include, (quote == '>') ? INCL_SYSTEM : INCL_NORMAL );
981 /*******************************************************************
982 * parse_pragma_directive
984 static void parse_pragma_directive( struct file *source, char *str )
986 char *flag, *p = str;
988 if (!isspace( *p )) return;
989 while (*p && isspace(*p)) p++;
990 p = strtok( p, " \t" );
991 if (strcmp( p, "makedep" )) return;
993 while ((flag = strtok( NULL, " \t" )))
995 if (!strcmp( flag, "depend" ))
997 while ((p = strtok( NULL, " \t" ))) add_dependency( source, p, INCL_NORMAL );
998 return;
1000 else if (!strcmp( flag, "install" )) source->flags |= FLAG_INSTALL;
1002 if (strendswith( source->name, ".idl" ))
1004 if (!strcmp( flag, "header" )) source->flags |= FLAG_IDL_HEADER;
1005 else if (!strcmp( flag, "proxy" )) source->flags |= FLAG_IDL_PROXY;
1006 else if (!strcmp( flag, "client" )) source->flags |= FLAG_IDL_CLIENT;
1007 else if (!strcmp( flag, "server" )) source->flags |= FLAG_IDL_SERVER;
1008 else if (!strcmp( flag, "ident" )) source->flags |= FLAG_IDL_IDENT;
1009 else if (!strcmp( flag, "typelib" )) source->flags |= FLAG_IDL_TYPELIB;
1010 else if (!strcmp( flag, "register" )) source->flags |= FLAG_IDL_REGISTER;
1011 else if (!strcmp( flag, "regtypelib" )) source->flags |= FLAG_IDL_REGTYPELIB;
1013 else if (strendswith( source->name, ".rc" ))
1015 if (!strcmp( flag, "po" )) source->flags |= FLAG_RC_PO;
1017 else if (strendswith( source->name, ".sfd" ))
1019 if (!strcmp( flag, "font" ))
1021 struct strarray *array = source->args;
1023 if (!array)
1025 source->args = array = xmalloc( sizeof(*array) );
1026 *array = empty_strarray;
1027 source->flags |= FLAG_SFD_FONTS;
1029 strarray_add( array, xstrdup( strtok( NULL, "" )));
1030 return;
1033 else if (!strcmp( flag, "implib" )) source->flags |= FLAG_C_IMPLIB;
1038 /*******************************************************************
1039 * parse_cpp_directive
1041 static void parse_cpp_directive( struct file *source, char *str )
1043 while (*str && isspace(*str)) str++;
1044 if (*str++ != '#') return;
1045 while (*str && isspace(*str)) str++;
1047 if (!strncmp( str, "include", 7 ))
1048 parse_include_directive( source, str + 7 );
1049 else if (!strncmp( str, "import", 6 ) && strendswith( source->name, ".m" ))
1050 parse_include_directive( source, str + 6 );
1051 else if (!strncmp( str, "pragma", 6 ))
1052 parse_pragma_directive( source, str + 6 );
1056 /*******************************************************************
1057 * parse_idl_file
1059 static void parse_idl_file( struct file *source, FILE *file )
1061 char *buffer, *include;
1063 input_line = 0;
1065 while ((buffer = get_line( file )))
1067 char quote;
1068 char *p = buffer;
1069 while (*p && isspace(*p)) p++;
1071 if (!strncmp( p, "importlib", 9 ))
1073 p += 9;
1074 while (*p && isspace(*p)) p++;
1075 if (*p++ != '(') continue;
1076 while (*p && isspace(*p)) p++;
1077 if (*p++ != '"') continue;
1078 include = p;
1079 while (*p && (*p != '"')) p++;
1080 if (!*p) fatal_error( "malformed importlib directive\n" );
1081 *p = 0;
1082 add_dependency( source, include, INCL_IMPORTLIB );
1083 continue;
1086 if (!strncmp( p, "import", 6 ))
1088 p += 6;
1089 while (*p && isspace(*p)) p++;
1090 if (*p != '"') continue;
1091 include = ++p;
1092 while (*p && (*p != '"')) p++;
1093 if (!*p) fatal_error( "malformed import directive\n" );
1094 *p = 0;
1095 add_dependency( source, include, INCL_IMPORT );
1096 continue;
1099 /* check for #include inside cpp_quote */
1100 if (!strncmp( p, "cpp_quote", 9 ))
1102 p += 9;
1103 while (*p && isspace(*p)) p++;
1104 if (*p++ != '(') continue;
1105 while (*p && isspace(*p)) p++;
1106 if (*p++ != '"') continue;
1107 if (*p++ != '#') continue;
1108 while (*p && isspace(*p)) p++;
1109 if (strncmp( p, "include", 7 )) continue;
1110 p += 7;
1111 while (*p && isspace(*p)) p++;
1112 if (*p == '\\' && p[1] == '"')
1114 p += 2;
1115 quote = '"';
1117 else
1119 if (*p++ != '<' ) continue;
1120 quote = '>';
1122 include = p;
1123 while (*p && (*p != quote)) p++;
1124 if (!*p || (quote == '"' && p[-1] != '\\'))
1125 fatal_error( "malformed #include directive inside cpp_quote\n" );
1126 if (quote == '"') p--; /* remove backslash */
1127 *p = 0;
1128 add_dependency( source, include, (quote == '>') ? INCL_CPP_QUOTE_SYSTEM : INCL_CPP_QUOTE );
1129 continue;
1132 parse_cpp_directive( source, p );
1136 /*******************************************************************
1137 * parse_c_file
1139 static void parse_c_file( struct file *source, FILE *file )
1141 char *buffer;
1143 input_line = 0;
1144 while ((buffer = get_line( file )))
1146 parse_cpp_directive( source, buffer );
1151 /*******************************************************************
1152 * parse_rc_file
1154 static void parse_rc_file( struct file *source, FILE *file )
1156 char *buffer, *include;
1158 input_line = 0;
1159 while ((buffer = get_line( file )))
1161 char quote;
1162 char *p = buffer;
1163 while (*p && isspace(*p)) p++;
1165 if (p[0] == '/' && p[1] == '*') /* check for magic makedep comment */
1167 p += 2;
1168 while (*p && isspace(*p)) p++;
1169 if (strncmp( p, "@makedep:", 9 )) continue;
1170 p += 9;
1171 while (*p && isspace(*p)) p++;
1172 quote = '"';
1173 if (*p == quote)
1175 include = ++p;
1176 while (*p && *p != quote) p++;
1178 else
1180 include = p;
1181 while (*p && !isspace(*p) && *p != '*') p++;
1183 if (!*p)
1184 fatal_error( "malformed makedep comment\n" );
1185 *p = 0;
1186 add_dependency( source, include, (quote == '>') ? INCL_SYSTEM : INCL_NORMAL );
1187 continue;
1190 parse_cpp_directive( source, buffer );
1195 /*******************************************************************
1196 * parse_in_file
1198 static void parse_in_file( struct file *source, FILE *file )
1200 char *p, *buffer;
1202 /* make sure it gets rebuilt when the version changes */
1203 add_dependency( source, "config.h", INCL_SYSTEM );
1205 if (!strendswith( source->name, ".man.in" )) return; /* not a man page */
1207 input_line = 0;
1208 while ((buffer = get_line( file )))
1210 if (strncmp( buffer, ".TH", 3 )) continue;
1211 if (!(p = strtok( buffer, " \t" ))) continue; /* .TH */
1212 if (!(p = strtok( NULL, " \t" ))) continue; /* program name */
1213 if (!(p = strtok( NULL, " \t" ))) continue; /* man section */
1214 source->args = xstrdup( p );
1215 return;
1220 /*******************************************************************
1221 * parse_sfd_file
1223 static void parse_sfd_file( struct file *source, FILE *file )
1225 char *p, *eol, *buffer;
1227 input_line = 0;
1228 while ((buffer = get_line( file )))
1230 if (strncmp( buffer, "UComments:", 10 )) continue;
1231 p = buffer + 10;
1232 while (*p == ' ') p++;
1233 if (p[0] == '"' && p[1] && buffer[strlen(buffer) - 1] == '"')
1235 p++;
1236 buffer[strlen(buffer) - 1] = 0;
1238 while ((eol = strstr( p, "+AAoA" )))
1240 *eol = 0;
1241 while (*p && isspace(*p)) p++;
1242 if (*p++ == '#')
1244 while (*p && isspace(*p)) p++;
1245 if (!strncmp( p, "pragma", 6 )) parse_pragma_directive( source, p + 6 );
1247 p = eol + 5;
1249 while (*p && isspace(*p)) p++;
1250 if (*p++ != '#') return;
1251 while (*p && isspace(*p)) p++;
1252 if (!strncmp( p, "pragma", 6 )) parse_pragma_directive( source, p + 6 );
1253 return;
1258 static const struct
1260 const char *ext;
1261 void (*parse)( struct file *file, FILE *f );
1262 } parse_functions[] =
1264 { ".c", parse_c_file },
1265 { ".h", parse_c_file },
1266 { ".inl", parse_c_file },
1267 { ".l", parse_c_file },
1268 { ".m", parse_c_file },
1269 { ".rh", parse_c_file },
1270 { ".x", parse_c_file },
1271 { ".y", parse_c_file },
1272 { ".idl", parse_idl_file },
1273 { ".rc", parse_rc_file },
1274 { ".in", parse_in_file },
1275 { ".sfd", parse_sfd_file }
1278 /*******************************************************************
1279 * load_file
1281 static struct file *load_file( const char *name )
1283 struct file *file;
1284 FILE *f;
1285 unsigned int i, hash = hash_filename( name );
1287 LIST_FOR_EACH_ENTRY( file, &files[hash], struct file, entry )
1288 if (!strcmp( name, file->name )) return file;
1290 if (!(f = fopen( name, "r" ))) return NULL;
1292 file = add_file( name );
1293 list_add_tail( &files[hash], &file->entry );
1294 input_file_name = file->name;
1295 input_line = 0;
1297 for (i = 0; i < sizeof(parse_functions) / sizeof(parse_functions[0]); i++)
1299 if (!strendswith( name, parse_functions[i].ext )) continue;
1300 parse_functions[i].parse( file, f );
1301 break;
1304 fclose( f );
1305 input_file_name = NULL;
1307 return file;
1311 /*******************************************************************
1312 * open_include_path_file
1314 * Open a file from a directory on the include path.
1316 static struct file *open_include_path_file( const struct makefile *make, const char *dir,
1317 const char *name, char **filename )
1319 char *src_path = base_dir_path( make, concat_paths( dir, name ));
1320 struct file *ret = load_file( src_path );
1322 if (ret) *filename = src_dir_path( make, concat_paths( dir, name ));
1323 return ret;
1327 /*******************************************************************
1328 * open_file_same_dir
1330 * Open a file in the same directory as the parent.
1332 static struct file *open_file_same_dir( const struct incl_file *parent, const char *name, char **filename )
1334 char *src_path = replace_filename( parent->file->name, name );
1335 struct file *ret = load_file( src_path );
1337 if (ret) *filename = replace_filename( parent->filename, name );
1338 free( src_path );
1339 return ret;
1343 /*******************************************************************
1344 * open_local_file
1346 * Open a file in the source directory of the makefile.
1348 static struct file *open_local_file( const struct makefile *make, const char *path, char **filename )
1350 char *src_path = root_dir_path( base_dir_path( make, path ));
1351 struct file *ret = load_file( src_path );
1353 /* if not found, try parent dir */
1354 if (!ret && make->parent_dir)
1356 free( src_path );
1357 path = strmake( "%s/%s", make->parent_dir, path );
1358 src_path = root_dir_path( base_dir_path( make, path ));
1359 ret = load_file( src_path );
1360 if (ret) ret->flags |= FLAG_PARENTDIR;
1363 if (ret) *filename = src_dir_path( make, path );
1364 free( src_path );
1365 return ret;
1369 /*******************************************************************
1370 * open_global_file
1372 * Open a file in the top-level source directory.
1374 static struct file *open_global_file( const struct makefile *make, const char *path, char **filename )
1376 char *src_path = root_dir_path( path );
1377 struct file *ret = load_file( src_path );
1379 if (ret) *filename = top_src_dir_path( make, path );
1380 free( src_path );
1381 return ret;
1385 /*******************************************************************
1386 * open_global_header
1388 * Open a file in the global include source directory.
1390 static struct file *open_global_header( const struct makefile *make, const char *path, char **filename )
1392 return open_global_file( make, strmake( "include/%s", path ), filename );
1396 /*******************************************************************
1397 * open_src_file
1399 static struct file *open_src_file( const struct makefile *make, struct incl_file *pFile )
1401 struct file *file = open_local_file( make, pFile->name, &pFile->filename );
1403 if (!file) fatal_perror( "open %s", pFile->name );
1404 return file;
1408 /*******************************************************************
1409 * open_include_file
1411 static struct file *open_include_file( const struct makefile *make, struct incl_file *pFile )
1413 struct file *file = NULL;
1414 char *filename;
1415 unsigned int i, len;
1417 errno = ENOENT;
1419 /* check for generated bison header */
1421 if (strendswith( pFile->name, ".tab.h" ) &&
1422 (file = open_local_file( make, replace_extension( pFile->name, ".tab.h", ".y" ), &filename )))
1424 pFile->sourcename = filename;
1425 pFile->filename = obj_dir_path( make, pFile->name );
1426 return file;
1429 /* check for corresponding idl file in source dir */
1431 if (strendswith( pFile->name, ".h" ) &&
1432 (file = open_local_file( make, replace_extension( pFile->name, ".h", ".idl" ), &filename )))
1434 pFile->sourcename = filename;
1435 pFile->filename = obj_dir_path( make, pFile->name );
1436 return file;
1439 /* check for corresponding tlb file in source dir */
1441 if (strendswith( pFile->name, ".tlb" ) &&
1442 (file = open_local_file( make, replace_extension( pFile->name, ".tlb", ".idl" ), &filename )))
1444 pFile->sourcename = filename;
1445 pFile->filename = obj_dir_path( make, pFile->name );
1446 return file;
1449 /* check for extra targets */
1450 if (strarray_exists( &make->extra_targets, pFile->name ))
1452 pFile->sourcename = filename;
1453 pFile->filename = obj_dir_path( make, pFile->name );
1454 return NULL;
1457 /* now try in source dir */
1458 if ((file = open_local_file( make, pFile->name, &pFile->filename ))) return file;
1460 /* check for corresponding idl file in global includes */
1462 if (strendswith( pFile->name, ".h" ) &&
1463 (file = open_global_header( make, replace_extension( pFile->name, ".h", ".idl" ), &filename )))
1465 pFile->sourcename = filename;
1466 pFile->filename = top_obj_dir_path( make, strmake( "include/%s", pFile->name ));
1467 return file;
1470 /* check for corresponding .in file in global includes (for config.h.in) */
1472 if (strendswith( pFile->name, ".h" ) &&
1473 (file = open_global_header( make, replace_extension( pFile->name, ".h", ".h.in" ), &filename )))
1475 pFile->sourcename = filename;
1476 pFile->filename = top_obj_dir_path( make, strmake( "include/%s", pFile->name ));
1477 return file;
1480 /* check for corresponding .x file in global includes */
1482 if (strendswith( pFile->name, "tmpl.h" ) &&
1483 (file = open_global_header( make, replace_extension( pFile->name, ".h", ".x" ), &filename )))
1485 pFile->sourcename = filename;
1486 pFile->filename = top_obj_dir_path( make, strmake( "include/%s", pFile->name ));
1487 return file;
1490 /* check for corresponding .tlb file in global includes */
1492 if (strendswith( pFile->name, ".tlb" ) &&
1493 (file = open_global_header( make, replace_extension( pFile->name, ".tlb", ".idl" ), &filename )))
1495 pFile->sourcename = filename;
1496 pFile->filename = top_obj_dir_path( make, strmake( "include/%s", pFile->name ));
1497 return file;
1500 /* check in global includes source dir */
1502 if ((file = open_global_header( make, pFile->name, &pFile->filename ))) return file;
1504 /* check in global msvcrt includes */
1505 if (make->use_msvcrt &&
1506 (file = open_global_header( make, strmake( "msvcrt/%s", pFile->name ), &pFile->filename )))
1507 return file;
1509 /* now search in include paths */
1510 for (i = 0; i < make->include_paths.count; i++)
1512 const char *dir = make->include_paths.str[i];
1513 const char *prefix = make->top_src_dir ? make->top_src_dir : make->top_obj_dir;
1515 if (prefix)
1517 len = strlen( prefix );
1518 if (!strncmp( dir, prefix, len ) && (!dir[len] || dir[len] == '/'))
1520 while (dir[len] == '/') len++;
1521 file = open_global_file( make, concat_paths( dir + len, pFile->name ), &pFile->filename );
1522 if (file) return file;
1524 if (make->top_src_dir) continue; /* ignore paths that don't point to the top source dir */
1526 if (*dir != '/')
1528 if ((file = open_include_path_file( make, dir, pFile->name, &pFile->filename )))
1529 return file;
1533 if (pFile->type == INCL_SYSTEM && make->use_msvcrt)
1535 if (!strcmp( pFile->name, "stdarg.h" )) return NULL;
1536 fprintf( stderr, "%s:%d: error: system header %s cannot be used with msvcrt\n",
1537 pFile->included_by->file->name, pFile->included_line, pFile->name );
1538 exit(1);
1541 if (pFile->type == INCL_SYSTEM) return NULL; /* ignore system files we cannot find */
1543 /* try in src file directory */
1544 if ((file = open_file_same_dir( pFile->included_by, pFile->name, &pFile->filename ))) return file;
1546 fprintf( stderr, "%s:%d: error: ", pFile->included_by->file->name, pFile->included_line );
1547 perror( pFile->name );
1548 pFile = pFile->included_by;
1549 while (pFile && pFile->included_by)
1551 const char *parent = pFile->included_by->sourcename;
1552 if (!parent) parent = pFile->included_by->file->name;
1553 fprintf( stderr, "%s:%d: note: %s was first included here\n",
1554 parent, pFile->included_line, pFile->name );
1555 pFile = pFile->included_by;
1557 exit(1);
1561 /*******************************************************************
1562 * add_all_includes
1564 static void add_all_includes( struct makefile *make, struct incl_file *parent, struct file *file )
1566 unsigned int i;
1568 parent->files_count = 0;
1569 parent->files_size = file->deps_count;
1570 parent->files = xmalloc( parent->files_size * sizeof(*parent->files) );
1571 for (i = 0; i < file->deps_count; i++)
1573 switch (file->deps[i].type)
1575 case INCL_NORMAL:
1576 case INCL_IMPORT:
1577 add_include( make, parent, file->deps[i].name, file->deps[i].line, INCL_NORMAL );
1578 break;
1579 case INCL_IMPORTLIB:
1580 add_include( make, parent, file->deps[i].name, file->deps[i].line, INCL_IMPORTLIB );
1581 break;
1582 case INCL_SYSTEM:
1583 add_include( make, parent, file->deps[i].name, file->deps[i].line, INCL_SYSTEM );
1584 break;
1585 case INCL_CPP_QUOTE:
1586 case INCL_CPP_QUOTE_SYSTEM:
1587 break;
1593 /*******************************************************************
1594 * parse_file
1596 static void parse_file( struct makefile *make, struct incl_file *source, int src )
1598 struct file *file = src ? open_src_file( make, source ) : open_include_file( make, source );
1600 if (!file) return;
1602 source->file = file;
1603 source->files_count = 0;
1604 source->files_size = file->deps_count;
1605 source->files = xmalloc( source->files_size * sizeof(*source->files) );
1607 if (source->sourcename)
1609 if (strendswith( source->sourcename, ".idl" ))
1611 unsigned int i;
1613 if (strendswith( source->name, ".tlb" )) return; /* typelibs don't include anything */
1615 /* generated .h file always includes these */
1616 add_include( make, source, "rpc.h", 0, INCL_NORMAL );
1617 add_include( make, source, "rpcndr.h", 0, INCL_NORMAL );
1618 for (i = 0; i < file->deps_count; i++)
1620 switch (file->deps[i].type)
1622 case INCL_IMPORT:
1623 if (strendswith( file->deps[i].name, ".idl" ))
1624 add_include( make, source, replace_extension( file->deps[i].name, ".idl", ".h" ),
1625 file->deps[i].line, INCL_NORMAL );
1626 else
1627 add_include( make, source, file->deps[i].name, file->deps[i].line, INCL_NORMAL );
1628 break;
1629 case INCL_CPP_QUOTE:
1630 add_include( make, source, file->deps[i].name, file->deps[i].line, INCL_NORMAL );
1631 break;
1632 case INCL_CPP_QUOTE_SYSTEM:
1633 add_include( make, source, file->deps[i].name, file->deps[i].line, INCL_SYSTEM );
1634 break;
1635 case INCL_NORMAL:
1636 case INCL_SYSTEM:
1637 case INCL_IMPORTLIB:
1638 break;
1641 return;
1643 if (strendswith( source->sourcename, ".y" ))
1644 return; /* generated .tab.h doesn't include anything */
1647 add_all_includes( make, source, file );
1651 /*******************************************************************
1652 * add_src_file
1654 * Add a source file to the list.
1656 static struct incl_file *add_src_file( struct makefile *make, const char *name )
1658 struct incl_file *file;
1660 if ((file = find_src_file( make, name ))) return file; /* we already have it */
1661 file = xmalloc( sizeof(*file) );
1662 memset( file, 0, sizeof(*file) );
1663 file->name = xstrdup(name);
1664 list_add_tail( &make->sources, &file->entry );
1665 parse_file( make, file, 1 );
1666 return file;
1670 /*******************************************************************
1671 * open_input_makefile
1673 static FILE *open_input_makefile( const struct makefile *make )
1675 FILE *ret;
1677 if (make->base_dir)
1678 input_file_name = root_dir_path( base_dir_path( make, strmake( "%s.in", output_makefile_name )));
1679 else
1680 input_file_name = output_makefile_name; /* always use output name for main Makefile */
1682 input_line = 0;
1683 if (!(ret = fopen( input_file_name, "r" ))) fatal_perror( "open" );
1684 return ret;
1688 /*******************************************************************
1689 * get_make_variable
1691 static const char *get_make_variable( const struct makefile *make, const char *name )
1693 const char *ret;
1695 if ((ret = strarray_get_value( &cmdline_vars, name ))) return ret;
1696 if ((ret = strarray_get_value( &make->vars, name ))) return ret;
1697 if (top_makefile && (ret = strarray_get_value( &top_makefile->vars, name ))) return ret;
1698 return NULL;
1702 /*******************************************************************
1703 * get_expanded_make_variable
1705 static char *get_expanded_make_variable( const struct makefile *make, const char *name )
1707 const char *var;
1708 char *p, *end, *expand, *tmp;
1710 var = get_make_variable( make, name );
1711 if (!var) return NULL;
1713 p = expand = xstrdup( var );
1714 while ((p = strchr( p, '$' )))
1716 if (p[1] == '(')
1718 if (!(end = strchr( p + 2, ')' ))) fatal_error( "syntax error in '%s'\n", expand );
1719 *end++ = 0;
1720 if (strchr( p + 2, ':' )) fatal_error( "pattern replacement not supported for '%s'\n", p + 2 );
1721 var = get_make_variable( make, p + 2 );
1722 tmp = replace_substr( expand, p, end - p, var ? var : "" );
1723 /* switch to the new string */
1724 p = tmp + (p - expand);
1725 free( expand );
1726 expand = tmp;
1728 else if (p[1] == '{') /* don't expand ${} variables */
1730 if (!(end = strchr( p + 2, '}' ))) fatal_error( "syntax error in '%s'\n", expand );
1731 p = end + 1;
1733 else if (p[1] == '$')
1735 p += 2;
1737 else fatal_error( "syntax error in '%s'\n", expand );
1740 /* consider empty variables undefined */
1741 p = expand;
1742 while (*p && isspace(*p)) p++;
1743 if (*p) return expand;
1744 free( expand );
1745 return NULL;
1749 /*******************************************************************
1750 * get_expanded_make_var_array
1752 static struct strarray get_expanded_make_var_array( const struct makefile *make, const char *name )
1754 struct strarray ret = empty_strarray;
1755 char *value, *token;
1757 if ((value = get_expanded_make_variable( make, name )))
1758 for (token = strtok( value, " \t" ); token; token = strtok( NULL, " \t" ))
1759 strarray_add( &ret, token );
1760 return ret;
1764 /*******************************************************************
1765 * get_expanded_file_local_var
1767 static struct strarray get_expanded_file_local_var( const struct makefile *make, const char *file,
1768 const char *name )
1770 char *p, *var = strmake( "%s_%s", file, name );
1772 for (p = var; *p; p++) if (!isalnum( *p )) *p = '_';
1773 return get_expanded_make_var_array( make, var );
1777 /*******************************************************************
1778 * set_make_variable
1780 static int set_make_variable( struct strarray *array, const char *assignment )
1782 char *p, *name;
1784 p = name = xstrdup( assignment );
1785 while (isalnum(*p) || *p == '_') p++;
1786 if (name == p) return 0; /* not a variable */
1787 if (isspace(*p))
1789 *p++ = 0;
1790 while (isspace(*p)) p++;
1792 if (*p != '=') return 0; /* not an assignment */
1793 *p++ = 0;
1794 while (isspace(*p)) p++;
1796 strarray_set_value( array, name, p );
1797 return 1;
1801 /*******************************************************************
1802 * parse_makefile
1804 static struct makefile *parse_makefile( const char *path )
1806 char *buffer;
1807 FILE *file;
1808 struct makefile *make = xmalloc( sizeof(*make) );
1810 memset( make, 0, sizeof(*make) );
1811 if (path)
1813 make->top_obj_dir = get_relative_path( path, "" );
1814 make->base_dir = path;
1815 if (!strcmp( make->base_dir, "." )) make->base_dir = NULL;
1818 file = open_input_makefile( make );
1819 while ((buffer = get_line( file )))
1821 if (!strncmp( buffer, separator, strlen(separator) )) break;
1822 if (*buffer == '\t') continue; /* command */
1823 while (isspace( *buffer )) buffer++;
1824 if (*buffer == '#') continue; /* comment */
1825 set_make_variable( &make->vars, buffer );
1827 fclose( file );
1828 input_file_name = NULL;
1829 return make;
1833 /*******************************************************************
1834 * add_generated_sources
1836 static void add_generated_sources( struct makefile *make )
1838 unsigned int i;
1839 struct incl_file *source, *next, *file;
1840 struct strarray objs = get_expanded_make_var_array( make, "EXTRA_OBJS" );
1842 LIST_FOR_EACH_ENTRY_SAFE( source, next, &make->sources, struct incl_file, entry )
1844 if (source->file->flags & FLAG_IDL_CLIENT)
1846 file = add_generated_source( make, replace_extension( source->name, ".idl", "_c.c" ), NULL );
1847 add_dependency( file->file, replace_extension( source->name, ".idl", ".h" ), INCL_NORMAL );
1848 add_all_includes( make, file, file->file );
1850 if (source->file->flags & FLAG_IDL_SERVER)
1852 file = add_generated_source( make, replace_extension( source->name, ".idl", "_s.c" ), NULL );
1853 add_dependency( file->file, "wine/exception.h", INCL_NORMAL );
1854 add_dependency( file->file, replace_extension( source->name, ".idl", ".h" ), INCL_NORMAL );
1855 add_all_includes( make, file, file->file );
1857 if (source->file->flags & FLAG_IDL_IDENT)
1859 file = add_generated_source( make, replace_extension( source->name, ".idl", "_i.c" ), NULL );
1860 add_dependency( file->file, "rpc.h", INCL_NORMAL );
1861 add_dependency( file->file, "rpcndr.h", INCL_NORMAL );
1862 add_dependency( file->file, "guiddef.h", INCL_NORMAL );
1863 add_all_includes( make, file, file->file );
1865 if (source->file->flags & FLAG_IDL_PROXY)
1867 file = add_generated_source( make, "dlldata.o", "dlldata.c" );
1868 add_dependency( file->file, "objbase.h", INCL_NORMAL );
1869 add_dependency( file->file, "rpcproxy.h", INCL_NORMAL );
1870 add_all_includes( make, file, file->file );
1871 file = add_generated_source( make, replace_extension( source->name, ".idl", "_p.c" ), NULL );
1872 add_dependency( file->file, "objbase.h", INCL_NORMAL );
1873 add_dependency( file->file, "rpcproxy.h", INCL_NORMAL );
1874 add_dependency( file->file, "wine/exception.h", INCL_NORMAL );
1875 add_dependency( file->file, replace_extension( source->name, ".idl", ".h" ), INCL_NORMAL );
1876 add_all_includes( make, file, file->file );
1878 if (source->file->flags & FLAG_IDL_TYPELIB)
1880 add_generated_source( make, replace_extension( source->name, ".idl", ".tlb" ), NULL );
1882 if (source->file->flags & FLAG_IDL_REGTYPELIB)
1884 add_generated_source( make, replace_extension( source->name, ".idl", "_t.res" ), NULL );
1886 if (source->file->flags & FLAG_IDL_REGISTER)
1888 add_generated_source( make, replace_extension( source->name, ".idl", "_r.res" ), NULL );
1890 if (source->file->flags & FLAG_IDL_HEADER)
1892 add_generated_source( make, replace_extension( source->name, ".idl", ".h" ), NULL );
1894 if (!source->file->flags && strendswith( source->name, ".idl" ))
1896 add_generated_source( make, replace_extension( source->name, ".idl", ".h" ), NULL );
1898 if (strendswith( source->name, ".x" ))
1900 add_generated_source( make, replace_extension( source->name, ".x", ".h" ), NULL );
1902 if (strendswith( source->name, ".y" ))
1904 file = add_generated_source( make, replace_extension( source->name, ".y", ".tab.c" ), NULL );
1905 /* steal the includes list from the source file */
1906 file->files_count = source->files_count;
1907 file->files_size = source->files_size;
1908 file->files = source->files;
1909 source->files_count = source->files_size = 0;
1910 source->files = NULL;
1912 if (strendswith( source->name, ".l" ))
1914 file = add_generated_source( make, replace_extension( source->name, ".l", ".yy.c" ), NULL );
1915 /* steal the includes list from the source file */
1916 file->files_count = source->files_count;
1917 file->files_size = source->files_size;
1918 file->files = source->files;
1919 source->files_count = source->files_size = 0;
1920 source->files = NULL;
1922 if (source->file->flags & FLAG_C_IMPLIB)
1924 if (!make->staticimplib && make->importlib && *dll_ext)
1925 make->staticimplib = strmake( "lib%s.a", make->importlib );
1927 if (strendswith( source->name, ".po" ))
1929 if (!make->disabled)
1930 strarray_add_uniq( &linguas, replace_extension( source->name, ".po", "" ));
1933 if (make->testdll)
1935 file = add_generated_source( make, "testlist.o", "testlist.c" );
1936 add_dependency( file->file, "wine/test.h", INCL_NORMAL );
1937 add_all_includes( make, file, file->file );
1939 for (i = 0; i < objs.count; i++)
1941 /* default to .c for unknown extra object files */
1942 if (strendswith( objs.str[i], ".o" ))
1943 add_generated_source( make, objs.str[i], replace_extension( objs.str[i], ".o", ".c" ));
1944 else if (strendswith( objs.str[i], ".res" ))
1945 add_generated_source( make, replace_extension( objs.str[i], ".res", ".rc" ), NULL );
1946 else
1947 add_generated_source( make, objs.str[i], NULL );
1952 /*******************************************************************
1953 * create_dir
1955 static void create_dir( const char *dir )
1957 char *p, *path;
1959 p = path = xstrdup( dir );
1960 while ((p = strchr( p, '/' )))
1962 *p = 0;
1963 if (mkdir( path, 0755 ) == -1 && errno != EEXIST) fatal_perror( "mkdir %s", path );
1964 *p++ = '/';
1965 while (*p == '/') p++;
1967 if (mkdir( path, 0755 ) == -1 && errno != EEXIST) fatal_perror( "mkdir %s", path );
1968 free( path );
1972 /*******************************************************************
1973 * create_file_directories
1975 * Create the base directories of all the files.
1977 static void create_file_directories( const struct makefile *make, struct strarray files )
1979 struct strarray subdirs = empty_strarray;
1980 unsigned int i;
1981 char *dir;
1983 for (i = 0; i < files.count; i++)
1985 if (!strchr( files.str[i], '/' )) continue;
1986 dir = base_dir_path( make, files.str[i] );
1987 *strrchr( dir, '/' ) = 0;
1988 strarray_add_uniq( &subdirs, dir );
1991 for (i = 0; i < subdirs.count; i++) create_dir( subdirs.str[i] );
1995 /*******************************************************************
1996 * output_filenames_obj_dir
1998 static void output_filenames_obj_dir( const struct makefile *make, struct strarray array )
2000 unsigned int i;
2002 for (i = 0; i < array.count; i++) output_filename( obj_dir_path( make, array.str[i] ));
2006 /*******************************************************************
2007 * get_dependencies
2009 static void get_dependencies( struct incl_file *file, struct incl_file *source )
2011 unsigned int i;
2013 if (!file->filename) return;
2015 if (file != source)
2017 if (file->owner == source) return; /* already processed */
2018 if (file->type == INCL_IMPORTLIB &&
2019 !(source->file->flags & (FLAG_IDL_TYPELIB | FLAG_IDL_REGTYPELIB)))
2020 return; /* library is imported only when building a typelib */
2021 file->owner = source;
2022 strarray_add( &source->dependencies, file->filename );
2024 for (i = 0; i < file->files_count; i++) get_dependencies( file->files[i], source );
2028 /*******************************************************************
2029 * get_local_dependencies
2031 * Get the local dependencies of a given target.
2033 static struct strarray get_local_dependencies( const struct makefile *make, const char *name,
2034 struct strarray targets )
2036 unsigned int i;
2037 struct strarray deps = get_expanded_file_local_var( make, name, "DEPS" );
2039 for (i = 0; i < deps.count; i++)
2041 if (strarray_exists( &targets, deps.str[i] ))
2042 deps.str[i] = obj_dir_path( make, deps.str[i] );
2043 else
2044 deps.str[i] = src_dir_path( make, deps.str[i] );
2046 return deps;
2050 /*******************************************************************
2051 * get_static_lib
2053 * Check if makefile builds the named static library and return the full lib path.
2055 static const char *get_static_lib( const struct makefile *make, const char *name )
2057 if (!make->staticlib) return NULL;
2058 if (strncmp( make->staticlib, "lib", 3 )) return NULL;
2059 if (strncmp( make->staticlib + 3, name, strlen(name) )) return NULL;
2060 if (strcmp( make->staticlib + 3 + strlen(name), ".a" )) return NULL;
2061 return base_dir_path( make, make->staticlib );
2065 /*******************************************************************
2066 * get_parent_makefile
2068 static struct makefile *get_parent_makefile( struct makefile *make )
2070 char *dir, *p;
2071 int i;
2073 if (!make->base_dir) return NULL;
2074 dir = xstrdup( make->base_dir );
2075 if (!(p = strrchr( dir, '/' ))) return NULL;
2076 *p = 0;
2077 for (i = 0; i < top_makefile->subdirs.count; i++)
2078 if (!strcmp( top_makefile->submakes[i]->base_dir, dir )) return top_makefile->submakes[i];
2079 return NULL;
2083 /*******************************************************************
2084 * needs_cross_lib
2086 static int needs_cross_lib( const struct makefile *make )
2088 if (!crosstarget) return 0;
2089 if (make->importlib) return strarray_exists( &cross_import_libs, make->importlib );
2090 if (make->staticlib)
2092 const char *name = replace_extension( make->staticlib, ".a", "" );
2093 if (!strncmp( name, "lib", 3 )) name += 3;
2094 return strarray_exists( &cross_import_libs, name );
2096 return 0;
2100 /*******************************************************************
2101 * needs_delay_lib
2103 static int needs_delay_lib( const struct makefile *make )
2105 if (*dll_ext && !crosstarget) return 0;
2106 if (!make->importlib) return 0;
2107 return strarray_exists( &delay_import_libs, make->importlib );
2111 /*******************************************************************
2112 * add_default_libraries
2114 static struct strarray add_default_libraries( const struct makefile *make, struct strarray *deps )
2116 struct strarray ret = empty_strarray;
2117 struct strarray all_libs = empty_strarray;
2118 unsigned int i, j;
2120 if (!make->use_msvcrt) strarray_add( &all_libs, "-lwine_port" );
2121 strarray_addall( &all_libs, get_expanded_make_var_array( make, "EXTRALIBS" ));
2122 strarray_addall( &all_libs, libs );
2124 for (i = 0; i < all_libs.count; i++)
2126 const char *lib = NULL;
2128 if (!strncmp( all_libs.str[i], "-l", 2 ))
2130 const char *name = all_libs.str[i] + 2;
2132 for (j = 0; j < top_makefile->subdirs.count; j++)
2134 const struct makefile *submake = top_makefile->submakes[j];
2136 if ((lib = get_static_lib( submake, name ))) break;
2140 if (lib)
2142 lib = top_obj_dir_path( make, lib );
2143 strarray_add( deps, lib );
2144 strarray_add( &ret, lib );
2146 else strarray_add( &ret, all_libs.str[i] );
2148 return ret;
2152 /*******************************************************************
2153 * add_import_libs
2155 static struct strarray add_import_libs( const struct makefile *make, struct strarray *deps,
2156 struct strarray imports, int delay )
2158 struct strarray ret = empty_strarray;
2159 unsigned int i, j;
2161 for (i = 0; i < imports.count; i++)
2163 const char *name = imports.str[i];
2164 const char *lib = NULL;
2166 for (j = 0; j < top_makefile->subdirs.count; j++)
2168 const struct makefile *submake = top_makefile->submakes[j];
2170 if (submake->importlib && !strcmp( submake->importlib, name ))
2172 if (make->is_cross || !*dll_ext || submake->staticimplib)
2173 lib = base_dir_path( submake, strmake( "lib%s.a", name ));
2174 else
2175 strarray_add( deps, top_obj_dir_path( make,
2176 strmake( "%s/lib%s.def", submake->base_dir, name )));
2177 break;
2180 if ((lib = get_static_lib( submake, name ))) break;
2183 if (lib)
2185 if (delay) lib = replace_extension( lib, ".a", ".delay.a" );
2186 else if (make->is_cross) lib = replace_extension( lib, ".a", ".cross.a" );
2187 lib = top_obj_dir_path( make, lib );
2188 strarray_add( deps, lib );
2189 strarray_add( &ret, lib );
2191 else strarray_add( &ret, strmake( "-l%s", name ));
2193 return ret;
2197 /*******************************************************************
2198 * get_default_imports
2200 static struct strarray get_default_imports( const struct makefile *make )
2202 struct strarray ret = empty_strarray;
2204 if (strarray_exists( &make->extradllflags, "-nodefaultlibs" )) return ret;
2205 if (strarray_exists( &make->extradllflags, "-mno-cygwin" )) strarray_add( &ret, "msvcrt" );
2206 strarray_add( &ret, "winecrt0" );
2207 if (make->is_win16) strarray_add( &ret, "kernel" );
2208 strarray_add( &ret, "kernel32" );
2209 strarray_add( &ret, "ntdll" );
2210 return ret;
2214 /*******************************************************************
2215 * add_install_rule
2217 static void add_install_rule( struct makefile *make, const char *target,
2218 const char *file, const char *dest )
2220 if (strarray_exists( &make->install_lib, target ) ||
2221 strarray_exists( &top_install_lib, make->base_dir ) ||
2222 strarray_exists( &top_install_lib, base_dir_path( make, target )))
2224 strarray_add( &make->install_rules[INSTALL_LIB], file );
2225 strarray_add( &make->install_rules[INSTALL_LIB], dest );
2227 else if (strarray_exists( &make->install_dev, target ) ||
2228 strarray_exists( &top_install_dev, make->base_dir ) ||
2229 strarray_exists( &top_install_dev, base_dir_path( make, target )))
2231 strarray_add( &make->install_rules[INSTALL_DEV], file );
2232 strarray_add( &make->install_rules[INSTALL_DEV], dest );
2237 /*******************************************************************
2238 * get_include_install_path
2240 * Determine the installation path for a given include file.
2242 static const char *get_include_install_path( const char *name )
2244 if (!strncmp( name, "wine/", 5 )) return name + 5;
2245 if (!strncmp( name, "msvcrt/", 7 )) return name;
2246 return strmake( "windows/%s", name );
2250 /*******************************************************************
2251 * get_shared_library_name
2253 * Determine possible names for a shared library with a version number.
2255 static struct strarray get_shared_lib_names( const char *libname )
2257 struct strarray ret = empty_strarray;
2258 const char *ext, *p;
2259 char *name, *first, *second;
2260 size_t len = 0;
2262 strarray_add( &ret, libname );
2264 for (p = libname; (p = strchr( p, '.' )); p++)
2265 if ((len = strspn( p + 1, "0123456789." ))) break;
2267 if (!len) return ret;
2268 ext = p + 1 + len;
2269 if (*ext && ext[-1] == '.') ext--;
2271 /* keep only the first group of digits */
2272 name = xstrdup( libname );
2273 first = name + (p - libname);
2274 if ((second = strchr( first + 1, '.' )))
2276 strcpy( second, ext );
2277 strarray_add( &ret, xstrdup( name ));
2279 /* now remove all digits */
2280 strcpy( first, ext );
2281 strarray_add( &ret, name );
2282 return ret;
2286 /*******************************************************************
2287 * output_winegcc_command
2289 static void output_winegcc_command( struct makefile *make )
2291 output( "\t%s -o $@", tools_path( make, "winegcc" ));
2292 output_filename( strmake( "-B%s", tools_dir_path( make, "winebuild" )));
2293 if (tools_dir) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make, "" )));
2294 if (make->is_cross)
2296 output_filename( "-b" );
2297 output_filename( crosstarget );
2298 output_filename( "--lib-suffix=.cross.a" );
2300 else
2302 output_filenames( target_flags );
2303 output_filenames( lddll_flags );
2308 /*******************************************************************
2309 * output_symlink_rule
2311 * Output a rule to create a symlink.
2313 static void output_symlink_rule( const char *src_name, const char *link_name )
2315 const char *name;
2317 output( "\trm -f %s && ", link_name );
2319 /* dest path with a directory needs special handling if ln -s isn't supported */
2320 if (strcmp( ln_s, "ln -s" ) && ((name = strrchr( link_name, '/' ))))
2322 char *dir = xstrdup( link_name );
2323 dir[name - link_name] = 0;
2324 output( "cd %s && %s %s %s\n", *dir ? dir : "/", ln_s, src_name, name + 1 );
2325 free( dir );
2327 else
2329 output( "%s %s %s\n", ln_s, src_name, link_name );
2334 /*******************************************************************
2335 * output_install_commands
2337 static void output_install_commands( struct makefile *make, const struct makefile *submake,
2338 struct strarray files )
2340 unsigned int i;
2341 char *install_sh = top_src_dir_path( make, "tools/install-sh" );
2343 for (i = 0; i < files.count; i += 2)
2345 const char *file = files.str[i];
2346 const char *dest = strmake( "$(DESTDIR)%s", files.str[i + 1] + 1 );
2348 if (submake) file = base_dir_path( submake, file );
2349 switch (*files.str[i + 1])
2351 case 'c': /* cross-compiled program */
2352 output( "\tSTRIPPROG=%s-strip %s -m 644 $(INSTALL_PROGRAM_FLAGS) %s %s\n",
2353 crosstarget, install_sh, obj_dir_path( make, file ), dest );
2354 break;
2355 case 'd': /* data file */
2356 output( "\t%s -m 644 $(INSTALL_DATA_FLAGS) %s %s\n",
2357 install_sh, obj_dir_path( make, file ), dest );
2358 break;
2359 case 'D': /* data file in source dir */
2360 output( "\t%s -m 644 $(INSTALL_DATA_FLAGS) %s %s\n",
2361 install_sh, src_dir_path( make, file ), dest );
2362 break;
2363 case 'p': /* program file */
2364 output( "\tSTRIPPROG=\"$(STRIP)\" %s $(INSTALL_PROGRAM_FLAGS) %s %s\n",
2365 install_sh, obj_dir_path( make, file ), dest );
2366 break;
2367 case 's': /* script */
2368 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s %s\n",
2369 install_sh, obj_dir_path( make, file ), dest );
2370 break;
2371 case 'S': /* script in source dir */
2372 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s %s\n",
2373 install_sh, src_dir_path( make, file ), dest );
2374 break;
2375 case 't': /* script in tools dir */
2376 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s %s\n",
2377 install_sh, tools_dir_path( make, files.str[i] ), dest );
2378 break;
2379 case 'y': /* symlink */
2380 output_symlink_rule( files.str[i], dest );
2381 break;
2382 default:
2383 assert(0);
2385 strarray_add( &make->uninstall_files, dest );
2390 /*******************************************************************
2391 * output_install_rules
2393 * Rules are stored as a (file,dest) pair of values.
2394 * The first char of dest indicates the type of install.
2396 static void output_install_rules( struct makefile *make, enum install_rules rules, const char *target )
2398 unsigned int i;
2399 struct strarray files = make->install_rules[rules];
2400 struct strarray targets = empty_strarray;
2402 if (!files.count) return;
2404 for (i = 0; i < files.count; i += 2)
2406 const char *file = files.str[i];
2407 switch (*files.str[i + 1])
2409 case 'd': /* data file */
2410 case 'p': /* program file */
2411 case 's': /* script */
2412 strarray_add_uniq( &targets, obj_dir_path( make, file ));
2413 break;
2414 case 't': /* script in tools dir */
2415 strarray_add_uniq( &targets, tools_dir_path( make, file ));
2416 break;
2420 output( "install %s::", target );
2421 output_filenames( targets );
2422 output( "\n" );
2423 output_install_commands( make, NULL, files );
2425 strarray_add_uniq( &make->phony_targets, "install" );
2426 strarray_add_uniq( &make->phony_targets, target );
2430 static int cmp_string_length( const char **a, const char **b )
2432 int paths_a = 0, paths_b = 0;
2433 const char *p;
2435 for (p = *a; *p; p++) if (*p == '/') paths_a++;
2436 for (p = *b; *p; p++) if (*p == '/') paths_b++;
2437 if (paths_b != paths_a) return paths_b - paths_a;
2438 return strcmp( *a, *b );
2441 /*******************************************************************
2442 * output_uninstall_rules
2444 static void output_uninstall_rules( struct makefile *make )
2446 static const char *dirs_order[] =
2447 { "$(includedir)", "$(mandir)", "$(fontdir)", "$(datadir)", "$(dlldir)" };
2449 struct strarray subdirs = empty_strarray;
2450 unsigned int i, j;
2452 if (!make->uninstall_files.count) return;
2453 output( "uninstall::\n" );
2454 output_rm_filenames( make->uninstall_files );
2455 strarray_add_uniq( &make->phony_targets, "uninstall" );
2457 if (!make->subdirs.count) return;
2458 for (i = 0; i < make->uninstall_files.count; i++)
2460 char *dir = xstrdup( make->uninstall_files.str[i] );
2461 while (strchr( dir, '/' ))
2463 *strrchr( dir, '/' ) = 0;
2464 strarray_add_uniq( &subdirs, xstrdup(dir) );
2467 strarray_qsort( &subdirs, cmp_string_length );
2468 output( "\t-rmdir" );
2469 for (i = 0; i < sizeof(dirs_order)/sizeof(dirs_order[0]); i++)
2471 for (j = 0; j < subdirs.count; j++)
2473 if (!subdirs.str[j]) continue;
2474 if (strncmp( subdirs.str[j] + strlen("$(DESTDIR)"), dirs_order[i], strlen(dirs_order[i]) ))
2475 continue;
2476 output_filename( subdirs.str[j] );
2477 subdirs.str[j] = NULL;
2480 for (j = 0; j < subdirs.count; j++)
2481 if (subdirs.str[j]) output_filename( subdirs.str[j] );
2482 output( "\n" );
2486 /*******************************************************************
2487 * output_importlib_symlinks
2489 static struct strarray output_importlib_symlinks( const struct makefile *parent,
2490 const struct makefile *make )
2492 struct strarray ret = empty_strarray;
2493 const char *lib, *dst, *ext[4];
2494 int i, count = 0;
2496 if (!make->module) return ret;
2497 if (!make->importlib) return ret;
2498 if (make->is_win16 && make->disabled) return ret;
2499 if (strncmp( make->base_dir, "dlls/", 5 )) return ret;
2500 if (!strcmp( make->module, make->importlib )) return ret;
2501 if (!strchr( make->importlib, '.' ) &&
2502 !strncmp( make->module, make->importlib, strlen( make->importlib )) &&
2503 !strcmp( make->module + strlen( make->importlib ), ".dll" ))
2504 return ret;
2506 ext[count++] = *dll_ext ? "def" : "a";
2507 if (needs_delay_lib( make )) ext[count++] = "delay.a";
2508 if (needs_cross_lib( make )) ext[count++] = "cross.a";
2510 for (i = 0; i < count; i++)
2512 lib = strmake( "lib%s.%s", make->importlib, ext[i] );
2513 dst = concat_paths( obj_dir_path( parent, "dlls" ), lib );
2514 output( "%s: %s\n", dst, base_dir_path( make, lib ));
2515 output_symlink_rule( concat_paths( make->base_dir + strlen("dlls/"), lib ), dst );
2516 strarray_add( &ret, dst );
2518 return ret;
2522 /*******************************************************************
2523 * output_po_files
2525 static void output_po_files( const struct makefile *make )
2527 const char *po_dir = src_dir_path( make, "po" );
2528 struct strarray pot_files = empty_strarray;
2529 struct incl_file *source;
2530 unsigned int i;
2532 for (i = 0; i < make->subdirs.count; i++)
2534 struct makefile *submake = make->submakes[i];
2536 LIST_FOR_EACH_ENTRY( source, &submake->sources, struct incl_file, entry )
2538 if (source->file->flags & FLAG_PARENTDIR) continue;
2539 if (strendswith( source->name, ".rc" ) && (source->file->flags & FLAG_RC_PO))
2541 char *pot_file = replace_extension( source->name, ".rc", ".pot" );
2542 char *pot_path = base_dir_path( submake, pot_file );
2543 output( "%s: tools/wrc include dummy\n", pot_path );
2544 output( "\t@cd %s && $(MAKE) %s\n", base_dir_path( submake, "" ), pot_file );
2545 strarray_add( &pot_files, pot_path );
2547 else if (strendswith( source->name, ".mc" ))
2549 char *pot_file = replace_extension( source->name, ".mc", ".pot" );
2550 char *pot_path = base_dir_path( submake, pot_file );
2551 output( "%s: tools/wmc include dummy\n", pot_path );
2552 output( "\t@cd %s && $(MAKE) %s\n", base_dir_path( submake, "" ), pot_file );
2553 strarray_add( &pot_files, pot_path );
2557 if (linguas.count)
2559 for (i = 0; i < linguas.count; i++)
2560 output_filename( strmake( "%s/%s.po", po_dir, linguas.str[i] ));
2561 output( ": %s/wine.pot\n", po_dir );
2562 output( "\tmsgmerge --previous -q $@ %s/wine.pot | msgattrib --no-obsolete -o $@.new && mv $@.new $@\n",
2563 po_dir );
2564 output( "po:" );
2565 for (i = 0; i < linguas.count; i++)
2566 output_filename( strmake( "%s/%s.po", po_dir, linguas.str[i] ));
2567 output( "\n" );
2569 output( "%s/wine.pot:", po_dir );
2570 output_filenames( pot_files );
2571 output( "\n" );
2572 output( "\tmsgcat -o $@" );
2573 output_filenames( pot_files );
2574 output( "\n" );
2578 /*******************************************************************
2579 * output_source_y
2581 static void output_source_y( struct makefile *make, struct incl_file *source, const char *obj )
2583 /* add source file dependency for parallel makes */
2584 char *header = strmake( "%s.tab.h", obj );
2586 if (find_include_file( make, header ))
2588 output( "%s: %s\n", obj_dir_path( make, header ), source->filename );
2589 output( "\t%s -p %s_ -o %s.tab.c -d %s\n",
2590 bison, obj, obj_dir_path( make, obj ), source->filename );
2591 output( "%s.tab.c: %s %s\n", obj_dir_path( make, obj ),
2592 source->filename, obj_dir_path( make, header ));
2593 strarray_add( &make->clean_files, header );
2595 else output( "%s.tab.c: %s\n", obj, source->filename );
2597 output( "\t%s -p %s_ -o $@ %s\n", bison, obj, source->filename );
2601 /*******************************************************************
2602 * output_source_l
2604 static void output_source_l( struct makefile *make, struct incl_file *source, const char *obj )
2606 output( "%s.yy.c: %s\n", obj_dir_path( make, obj ), source->filename );
2607 output( "\t%s -o$@ %s\n", flex, source->filename );
2611 /*******************************************************************
2612 * output_source_h
2614 static void output_source_h( struct makefile *make, struct incl_file *source, const char *obj )
2616 if (source->file->flags & FLAG_GENERATED)
2617 strarray_add( &make->all_targets, source->name );
2618 else
2619 add_install_rule( make, source->name, source->name,
2620 strmake( "D$(includedir)/wine/%s", get_include_install_path( source->name ) ));
2624 /*******************************************************************
2625 * output_source_rc
2627 static void output_source_rc( struct makefile *make, struct incl_file *source, const char *obj )
2629 struct strarray extradefs = get_expanded_file_local_var( make, obj, "EXTRADEFS" );
2630 unsigned int i;
2632 if (source->file->flags & FLAG_GENERATED) strarray_add( &make->clean_files, source->name );
2633 strarray_add( &make->res_files, strmake( "%s.res", obj ));
2634 output( "%s.res: %s\n", obj_dir_path( make, obj ), source->filename );
2635 output( "\t%s -o $@", tools_path( make, "wrc" ) );
2636 if (make->is_win16) output_filename( "-m16" );
2637 else output_filenames( target_flags );
2638 output_filename( "--nostdinc" );
2639 output_filenames( make->include_args );
2640 output_filenames( make->define_args );
2641 output_filenames( extradefs );
2642 if (linguas.count && (source->file->flags & FLAG_RC_PO))
2644 char *po_dir = top_obj_dir_path( make, "po" );
2645 output_filename( strmake( "--po-dir=%s", po_dir ));
2646 output_filename( source->filename );
2647 output( "\n" );
2648 output( "%s.res:", obj_dir_path( make, obj ));
2649 for (i = 0; i < linguas.count; i++)
2650 output_filename( strmake( "%s/%s.mo", po_dir, linguas.str[i] ));
2651 output( "\n" );
2653 else
2655 output_filename( source->filename );
2656 output( "\n" );
2658 if (source->file->flags & FLAG_RC_PO && !(source->file->flags & FLAG_PARENTDIR))
2660 strarray_add( &make->clean_files, strmake( "%s.pot", obj ));
2661 output( "%s.pot: %s\n", obj_dir_path( make, obj ), source->filename );
2662 output( "\t%s -O pot -o $@", tools_path( make, "wrc" ) );
2663 if (make->is_win16) output_filename( "-m16" );
2664 else output_filenames( target_flags );
2665 output_filename( "--nostdinc" );
2666 output_filenames( make->include_args );
2667 output_filenames( make->define_args );
2668 output_filenames( extradefs );
2669 output_filename( source->filename );
2670 output( "\n" );
2671 output( "%s.pot ", obj_dir_path( make, obj ));
2673 output( "%s.res:", obj_dir_path( make, obj ));
2674 output_filename( tools_path( make, "wrc" ));
2675 output_filenames( source->dependencies );
2676 output( "\n" );
2680 /*******************************************************************
2681 * output_source_mc
2683 static void output_source_mc( struct makefile *make, struct incl_file *source, const char *obj )
2685 unsigned int i;
2687 strarray_add( &make->res_files, strmake( "%s.res", obj ));
2688 strarray_add( &make->clean_files, strmake( "%s.pot", obj ));
2689 output( "%s.res: %s\n", obj_dir_path( make, obj ), source->filename );
2690 output( "\t%s -U -O res -o $@ %s", tools_path( make, "wmc" ), source->filename );
2691 if (linguas.count)
2693 char *po_dir = top_obj_dir_path( make, "po" );
2694 output_filename( strmake( "--po-dir=%s", po_dir ));
2695 output( "\n" );
2696 output( "%s.res:", obj_dir_path( make, obj ));
2697 for (i = 0; i < linguas.count; i++)
2698 output_filename( strmake( "%s/%s.mo", po_dir, linguas.str[i] ));
2700 output( "\n" );
2701 output( "%s.pot: %s\n", obj_dir_path( make, obj ), source->filename );
2702 output( "\t%s -O pot -o $@ %s", tools_path( make, "wmc" ), source->filename );
2703 output( "\n" );
2704 output( "%s.pot %s.res:", obj_dir_path( make, obj ), obj_dir_path( make, obj ));
2705 output_filename( tools_path( make, "wmc" ));
2706 output_filenames( source->dependencies );
2707 output( "\n" );
2711 /*******************************************************************
2712 * output_source_res
2714 static void output_source_res( struct makefile *make, struct incl_file *source, const char *obj )
2716 strarray_add( &make->res_files, source->name );
2720 /*******************************************************************
2721 * output_source_idl
2723 static void output_source_idl( struct makefile *make, struct incl_file *source, const char *obj )
2725 struct strarray extradefs = get_expanded_file_local_var( make, obj, "EXTRADEFS" );
2726 struct strarray targets = empty_strarray;
2727 char *dest;
2728 unsigned int i;
2730 if (!source->file->flags) source->file->flags |= FLAG_IDL_HEADER | FLAG_INSTALL;
2731 if (find_include_file( make, strmake( "%s.h", obj ))) source->file->flags |= FLAG_IDL_HEADER;
2733 for (i = 0; i < sizeof(idl_outputs) / sizeof(idl_outputs[0]); i++)
2735 if (!(source->file->flags & idl_outputs[i].flag)) continue;
2736 dest = strmake( "%s%s", obj, idl_outputs[i].ext );
2737 if (!find_src_file( make, dest )) strarray_add( &make->clean_files, dest );
2738 strarray_add( &targets, dest );
2740 if (source->file->flags & FLAG_IDL_PROXY) strarray_add( &make->dlldata_files, source->name );
2741 if (source->file->flags & FLAG_INSTALL)
2743 add_install_rule( make, source->name, xstrdup( source->name ),
2744 strmake( "D$(includedir)/wine/%s.idl", get_include_install_path( obj ) ));
2745 if (source->file->flags & FLAG_IDL_HEADER)
2746 add_install_rule( make, source->name, strmake( "%s.h", obj ),
2747 strmake( "d$(includedir)/wine/%s.h", get_include_install_path( obj ) ));
2749 if (!targets.count) return;
2751 output_filenames_obj_dir( make, targets );
2752 output( ": %s\n", tools_path( make, "widl" ));
2753 output( "\t%s -o $@", tools_path( make, "widl" ) );
2754 output_filenames( target_flags );
2755 output_filenames( make->include_args );
2756 output_filenames( make->define_args );
2757 output_filenames( extradefs );
2758 output_filenames( get_expanded_make_var_array( make, "EXTRAIDLFLAGS" ));
2759 output_filenames( get_expanded_file_local_var( make, obj, "EXTRAIDLFLAGS" ));
2760 output_filename( source->filename );
2761 output( "\n" );
2762 output_filenames_obj_dir( make, targets );
2763 output( ": %s", source->filename );
2764 output_filenames( source->dependencies );
2765 output( "\n" );
2769 /*******************************************************************
2770 * output_source_tlb
2772 static void output_source_tlb( struct makefile *make, struct incl_file *source, const char *obj )
2774 strarray_add( &make->all_targets, source->name );
2778 /*******************************************************************
2779 * output_source_x
2781 static void output_source_x( struct makefile *make, struct incl_file *source, const char *obj )
2783 output( "%s.h: %s%s %s\n", obj_dir_path( make, obj ),
2784 tools_dir_path( make, "make_xftmpl" ), tools_ext, source->filename );
2785 output( "\t%s%s -H -o $@ %s\n",
2786 tools_dir_path( make, "make_xftmpl" ), tools_ext, source->filename );
2787 if (source->file->flags & FLAG_INSTALL)
2789 add_install_rule( make, source->name, source->name,
2790 strmake( "D$(includedir)/wine/%s", get_include_install_path( source->name ) ));
2791 add_install_rule( make, source->name, strmake( "%s.h", obj ),
2792 strmake( "d$(includedir)/wine/%s.h", get_include_install_path( obj ) ));
2797 /*******************************************************************
2798 * output_source_sfd
2800 static void output_source_sfd( struct makefile *make, struct incl_file *source, const char *obj )
2802 unsigned int i;
2803 char *ttf_obj = strmake( "%s.ttf", obj );
2804 char *ttf_file = src_dir_path( make, ttf_obj );
2806 if (fontforge && !make->src_dir)
2808 output( "%s: %s\n", ttf_file, source->filename );
2809 output( "\t%s -script %s %s $@\n",
2810 fontforge, top_src_dir_path( make, "fonts/genttf.ff" ), source->filename );
2811 if (!(source->file->flags & FLAG_SFD_FONTS)) output( "all: %s\n", ttf_file );
2813 if (source->file->flags & FLAG_INSTALL)
2814 add_install_rule( make, source->name, ttf_obj, strmake( "D$(fontdir)/%s", ttf_obj ));
2816 if (source->file->flags & FLAG_SFD_FONTS)
2818 struct strarray *array = source->file->args;
2820 for (i = 0; i < array->count; i++)
2822 char *font = strtok( xstrdup(array->str[i]), " \t" );
2823 char *args = strtok( NULL, "" );
2825 strarray_add( &make->all_targets, xstrdup( font ));
2826 output( "%s: %s %s\n", obj_dir_path( make, font ),
2827 tools_path( make, "sfnt2fon" ), ttf_file );
2828 output( "\t%s -o $@ %s %s\n", tools_path( make, "sfnt2fon" ), ttf_file, args );
2829 add_install_rule( make, source->name, xstrdup(font), strmake( "d$(fontdir)/%s", font ));
2835 /*******************************************************************
2836 * output_source_svg
2838 static void output_source_svg( struct makefile *make, struct incl_file *source, const char *obj )
2840 static const char * const images[] = { "bmp", "cur", "ico", NULL };
2841 unsigned int i;
2843 if (convert && rsvg && icotool && !make->src_dir)
2845 for (i = 0; images[i]; i++)
2846 if (find_include_file( make, strmake( "%s.%s", obj, images[i] ))) break;
2848 if (images[i])
2850 output( "%s.%s: %s\n", src_dir_path( make, obj ), images[i], source->filename );
2851 output( "\tCONVERT=\"%s\" ICOTOOL=\"%s\" RSVG=\"%s\" %s %s $@\n", convert, icotool, rsvg,
2852 top_src_dir_path( make, "tools/buildimage" ), source->filename );
2858 /*******************************************************************
2859 * output_source_nls
2861 static void output_source_nls( struct makefile *make, struct incl_file *source, const char *obj )
2863 add_install_rule( make, source->name, source->name,
2864 strmake( "D$(datadir)/wine/%s", source->name ));
2868 /*******************************************************************
2869 * output_source_desktop
2871 static void output_source_desktop( struct makefile *make, struct incl_file *source, const char *obj )
2873 add_install_rule( make, source->name, source->name,
2874 strmake( "D$(datadir)/applications/%s", source->name ));
2878 /*******************************************************************
2879 * output_source_po
2881 static void output_source_po( struct makefile *make, struct incl_file *source, const char *obj )
2883 output( "%s.mo: %s\n", obj_dir_path( make, obj ), source->filename );
2884 output( "\t%s -o $@ %s\n", msgfmt, source->filename );
2885 strarray_add( &make->all_targets, strmake( "%s.mo", obj ));
2889 /*******************************************************************
2890 * output_source_in
2892 static void output_source_in( struct makefile *make, struct incl_file *source, const char *obj )
2894 unsigned int i;
2896 if (strendswith( obj, ".man" ) && source->file->args)
2898 struct strarray symlinks;
2899 char *dir, *dest = replace_extension( obj, ".man", "" );
2900 char *lang = strchr( dest, '.' );
2901 char *section = source->file->args;
2902 if (lang)
2904 *lang++ = 0;
2905 dir = strmake( "$(mandir)/%s/man%s", lang, section );
2907 else dir = strmake( "$(mandir)/man%s", section );
2908 add_install_rule( make, dest, xstrdup(obj), strmake( "d%s/%s.%s", dir, dest, section ));
2909 symlinks = get_expanded_file_local_var( make, dest, "SYMLINKS" );
2910 for (i = 0; i < symlinks.count; i++)
2911 add_install_rule( make, symlinks.str[i], strmake( "%s.%s", dest, section ),
2912 strmake( "y%s/%s.%s", dir, symlinks.str[i], section ));
2913 free( dest );
2914 free( dir );
2916 strarray_add( &make->in_files, xstrdup(obj) );
2917 strarray_add( &make->all_targets, xstrdup(obj) );
2918 output( "%s: %s\n", obj_dir_path( make, obj ), source->filename );
2919 output( "\t%s %s >$@ || (rm -f $@ && false)\n", sed_cmd, source->filename );
2920 output( "%s:", obj_dir_path( make, obj ));
2921 output_filenames( source->dependencies );
2922 output( "\n" );
2923 add_install_rule( make, obj, xstrdup( obj ), strmake( "d$(datadir)/wine/%s", obj ));
2927 /*******************************************************************
2928 * output_source_spec
2930 static void output_source_spec( struct makefile *make, struct incl_file *source, const char *obj )
2932 struct strarray imports = get_expanded_file_local_var( make, obj, "IMPORTS" );
2933 struct strarray dll_flags = get_expanded_file_local_var( make, obj, "EXTRADLLFLAGS" );
2934 struct strarray all_libs, dep_libs = empty_strarray;
2935 char *dll_name, *obj_name;
2937 if (!imports.count) imports = make->imports;
2938 if (!dll_flags.count) dll_flags = make->extradllflags;
2939 all_libs = add_import_libs( make, &dep_libs, imports, 0 );
2940 add_import_libs( make, &dep_libs, get_default_imports( make ), 0 ); /* dependencies only */
2941 strarray_addall( &all_libs, libs );
2942 dll_name = strmake( "%s.dll%s", obj, make->is_cross ? "" : dll_ext );
2943 obj_name = strmake( "%s%s", obj_dir_path( make, obj ), make->is_cross ? ".cross.o" : ".o" );
2945 strarray_add( &make->clean_files, dll_name );
2946 strarray_add( &make->res_files, strmake( "%s.res", obj ));
2947 output( "%s.res: %s\n", obj_dir_path( make, obj ), obj_dir_path( make, dll_name ));
2948 output( "\techo \"%s.dll TESTDLL \\\"%s\\\"\" | %s -o $@\n", obj,
2949 obj_dir_path( make, dll_name ), tools_path( make, "wrc" ));
2951 output( "%s:", obj_dir_path( make, dll_name ));
2952 output_filename( source->filename );
2953 output_filename( obj_name );
2954 output_filenames( dep_libs );
2955 output_filename( tools_path( make, "winebuild" ));
2956 output_filename( tools_path( make, "winegcc" ));
2957 output( "\n" );
2958 output_winegcc_command( make );
2959 output_filename( "-s" );
2960 output_filenames( dll_flags );
2961 output_filename( "-shared" );
2962 output_filename( source->filename );
2963 output_filename( obj_name );
2964 output_filenames( all_libs );
2965 output_filename( make->is_cross ? "$(CROSSLDFLAGS)" : "$(LDFLAGS)" );
2966 output( "\n" );
2970 /*******************************************************************
2971 * output_source_default
2973 static void output_source_default( struct makefile *make, struct incl_file *source, const char *obj )
2975 struct strarray extradefs = get_expanded_file_local_var( make, obj, "EXTRADEFS" );
2976 int is_dll_src = (make->testdll &&
2977 strendswith( source->name, ".c" ) &&
2978 find_src_file( make, replace_extension( source->name, ".c", ".spec" )));
2979 int need_cross = (crosstarget &&
2980 (make->is_cross ||
2981 ((source->file->flags & FLAG_C_IMPLIB) &&
2982 (needs_cross_lib( make ) || needs_delay_lib( make ))) ||
2983 (make->staticlib && needs_cross_lib( make ))));
2984 int need_obj = (!need_cross ||
2985 (source->file->flags & FLAG_C_IMPLIB) ||
2986 (make->module && make->staticlib));
2988 if ((source->file->flags & FLAG_GENERATED) &&
2989 (!make->testdll || !strendswith( source->filename, "testlist.c" )))
2990 strarray_add( &make->clean_files, source->filename );
2991 if (source->file->flags & FLAG_C_IMPLIB) strarray_add( &make->implib_objs, strmake( "%s.o", obj ));
2993 if (need_obj)
2995 strarray_add( is_dll_src ? &make->clean_files : &make->object_files, strmake( "%s.o", obj ));
2996 output( "%s.o: %s\n", obj_dir_path( make, obj ), source->filename );
2997 output( "\t$(CC) -c -o $@ %s", source->filename );
2998 output_filenames( make->include_args );
2999 output_filenames( make->define_args );
3000 output_filenames( extradefs );
3001 if (make->module || make->staticlib || make->sharedlib || make->testdll)
3003 output_filenames( dll_flags );
3004 if (make->use_msvcrt) output_filenames( msvcrt_flags );
3006 output_filenames( extra_cflags );
3007 output_filenames( cpp_flags );
3008 output_filename( "$(CFLAGS)" );
3009 output( "\n" );
3011 if (need_cross)
3013 strarray_add( is_dll_src ? &make->clean_files : &make->crossobj_files, strmake( "%s.cross.o", obj ));
3014 output( "%s.cross.o: %s\n", obj_dir_path( make, obj ), source->filename );
3015 output( "\t$(CROSSCC) -c -o $@ %s", source->filename );
3016 output_filenames( make->include_args );
3017 output_filenames( make->define_args );
3018 output_filenames( extradefs );
3019 output_filenames( extra_cross_cflags );
3020 output_filenames( cpp_flags );
3021 output_filename( "$(CROSSCFLAGS)" );
3022 output( "\n" );
3024 if (strendswith( source->name, ".c" ) && !(source->file->flags & FLAG_GENERATED))
3026 strarray_add( &make->c2man_files, source->filename );
3027 if (make->testdll && !is_dll_src)
3029 strarray_add( &make->ok_files, strmake( "%s.ok", obj ));
3030 output( "%s.ok:\n", obj_dir_path( make, obj ));
3031 output( "\t%s $(RUNTESTFLAGS) -T %s -M %s -p %s%s %s && touch $@\n",
3032 top_src_dir_path( make, "tools/runtest" ), top_obj_dir_path( make, "" ),
3033 make->testdll, replace_extension( make->testdll, ".dll", "_test.exe" ),
3034 make->is_cross ? "" : dll_ext, obj );
3037 if (need_obj) output_filename( strmake( "%s.o", obj_dir_path( make, obj )));
3038 if (need_cross) output_filename( strmake( "%s.cross.o", obj_dir_path( make, obj )));
3039 output( ":" );
3040 output_filenames( source->dependencies );
3041 output( "\n" );
3045 /* dispatch table to output rules for a single source file */
3046 static const struct
3048 const char *ext;
3049 void (*fn)( struct makefile *make, struct incl_file *source, const char *obj );
3050 } output_source_funcs[] =
3052 { "y", output_source_y },
3053 { "l", output_source_l },
3054 { "h", output_source_h },
3055 { "rh", output_source_h },
3056 { "inl", output_source_h },
3057 { "rc", output_source_rc },
3058 { "mc", output_source_mc },
3059 { "res", output_source_res },
3060 { "idl", output_source_idl },
3061 { "tlb", output_source_tlb },
3062 { "sfd", output_source_sfd },
3063 { "svg", output_source_svg },
3064 { "nls", output_source_nls },
3065 { "desktop", output_source_desktop },
3066 { "po", output_source_po },
3067 { "in", output_source_in },
3068 { "x", output_source_x },
3069 { "spec", output_source_spec },
3070 { NULL, output_source_default }
3074 /*******************************************************************
3075 * has_object_file
3077 static int has_object_file( struct makefile *make )
3079 struct incl_file *source;
3080 int i;
3082 LIST_FOR_EACH_ENTRY( source, &make->sources, struct incl_file, entry )
3084 char *ext = get_extension( source->name );
3086 if (!ext) fatal_error( "unsupported file type %s\n", source->name );
3087 ext++;
3089 for (i = 0; output_source_funcs[i].ext; i++)
3090 if (!strcmp( ext, output_source_funcs[i].ext )) break;
3092 if (!output_source_funcs[i].ext) return 1; /* default extension builds to an object file */
3094 return 0;
3098 /*******************************************************************
3099 * output_man_pages
3101 static void output_man_pages( struct makefile *make )
3103 if (make->c2man_files.count)
3105 char *spec_file = src_dir_path( make, replace_extension( make->module, ".dll", ".spec" ));
3107 output( "manpages::\n" );
3108 output( "\t%s -w %s", top_src_dir_path( make, "tools/c2man.pl" ), spec_file );
3109 output_filename( strmake( "-R%s", top_src_dir_path( make, "" )));
3110 output_filename( strmake( "-I%s", top_src_dir_path( make, "include" )));
3111 output_filename( strmake( "-o %s/man%s",
3112 top_obj_dir_path( make, "documentation" ), man_ext ));
3113 output_filenames( make->c2man_files );
3114 output( "\n" );
3115 output( "htmlpages::\n" );
3116 output( "\t%s -Th -w %s", top_src_dir_path( make, "tools/c2man.pl" ), spec_file );
3117 output_filename( strmake( "-R%s", top_src_dir_path( make, "" )));
3118 output_filename( strmake( "-I%s", top_src_dir_path( make, "include" )));
3119 output_filename( strmake( "-o %s",
3120 top_obj_dir_path( make, "documentation/html" )));
3121 output_filenames( make->c2man_files );
3122 output( "\n" );
3123 output( "sgmlpages::\n" );
3124 output( "\t%s -Ts -w %s", top_src_dir_path( make, "tools/c2man.pl" ), spec_file );
3125 output_filename( strmake( "-R%s", top_src_dir_path( make, "" )));
3126 output_filename( strmake( "-I%s", top_src_dir_path( make, "include" )));
3127 output_filename( strmake( "-o %s",
3128 top_obj_dir_path( make, "documentation/api-guide" )));
3129 output_filenames( make->c2man_files );
3130 output( "\n" );
3131 output( "xmlpages::\n" );
3132 output( "\t%s -Tx -w %s", top_src_dir_path( make, "tools/c2man.pl" ), spec_file );
3133 output_filename( strmake( "-R%s", top_src_dir_path( make, "" )));
3134 output_filename( strmake( "-I%s", top_src_dir_path( make, "include" )));
3135 output_filename( strmake( "-o %s",
3136 top_obj_dir_path( make, "documentation/api-guide-xml" )));
3137 output_filenames( make->c2man_files );
3138 output( "\n" );
3139 strarray_add( &make->phony_targets, "manpages" );
3140 strarray_add( &make->phony_targets, "htmlpages" );
3141 strarray_add( &make->phony_targets, "sgmlpages" );
3142 strarray_add( &make->phony_targets, "xmlpages" );
3144 else output( "manpages htmlpages sgmlpages xmlpages::\n" );
3148 /*******************************************************************
3149 * output_module
3151 static void output_module( struct makefile *make )
3153 struct strarray all_libs = empty_strarray;
3154 struct strarray dep_libs = empty_strarray;
3155 char *module_path = obj_dir_path( make, make->module );
3156 char *spec_file = NULL;
3157 unsigned int i;
3159 if (!make->is_exe) spec_file = src_dir_path( make, replace_extension( make->module, ".dll", ".spec" ));
3160 strarray_addall( &all_libs, add_import_libs( make, &dep_libs, make->delayimports, 1 ));
3161 strarray_addall( &all_libs, add_import_libs( make, &dep_libs, make->imports, 0 ));
3162 add_import_libs( make, &dep_libs, get_default_imports( make ), 0 ); /* dependencies only */
3164 if (make->is_cross)
3166 strarray_add( &make->all_targets, strmake( "%s", make->module ));
3167 add_install_rule( make, make->module, strmake( "%s", make->module ),
3168 strmake( "c$(dlldir)/%s", make->module ));
3169 output( "%s:", module_path );
3171 else
3173 strarray_addall( &all_libs, add_default_libraries( make, &dep_libs ));
3175 if (*dll_ext)
3177 for (i = 0; i < make->delayimports.count; i++)
3178 strarray_add( &all_libs, strmake( "-Wb,-d%s", make->delayimports.str[i] ));
3179 strarray_add( &make->all_targets, strmake( "%s%s", make->module, dll_ext ));
3180 strarray_add( &make->all_targets, strmake( "%s.fake", make->module ));
3181 add_install_rule( make, make->module, strmake( "%s%s", make->module, dll_ext ),
3182 strmake( "p$(dlldir)/%s%s", make->module, dll_ext ));
3183 add_install_rule( make, make->module, strmake( "%s.fake", make->module ),
3184 strmake( "d$(dlldir)/fakedlls/%s", make->module ));
3185 output( "%s%s %s.fake:", module_path, dll_ext, module_path );
3187 else
3189 strarray_add( &make->all_targets, make->module );
3190 add_install_rule( make, make->module, make->module,
3191 strmake( "p$(%s)/%s", spec_file ? "dlldir" : "bindir", make->module ));
3192 output( "%s:", module_path );
3196 if (spec_file) output_filename( spec_file );
3197 output_filenames_obj_dir( make, make->is_cross ? make->crossobj_files : make->object_files );
3198 output_filenames_obj_dir( make, make->res_files );
3199 output_filenames( dep_libs );
3200 output_filename( tools_path( make, "winebuild" ));
3201 output_filename( tools_path( make, "winegcc" ));
3202 output( "\n" );
3203 output_winegcc_command( make );
3204 if (make->is_cross) output_filename( "-Wl,--wine-builtin" );
3205 if (spec_file)
3207 output_filename( "-shared" );
3208 output_filename( spec_file );
3210 output_filenames( make->extradllflags );
3211 output_filenames_obj_dir( make, make->is_cross ? make->crossobj_files : make->object_files );
3212 output_filenames_obj_dir( make, make->res_files );
3213 output_filenames( all_libs );
3214 output_filename( make->is_cross ? "$(CROSSLDFLAGS)" : "$(LDFLAGS)" );
3215 output( "\n" );
3217 if (spec_file && make->importlib)
3219 char *importlib_path = obj_dir_path( make, strmake( "lib%s", make->importlib ));
3220 if (*dll_ext && !make->implib_objs.count)
3222 strarray_add( &make->clean_files, strmake( "lib%s.def", make->importlib ));
3223 output( "%s.def: %s %s\n", importlib_path, tools_path( make, "winebuild" ), spec_file );
3224 output( "\t%s -w --def -o $@ --export %s", tools_path( make, "winebuild" ), spec_file );
3225 output_filenames( target_flags );
3226 if (make->is_win16) output_filename( "-m16" );
3227 output( "\n" );
3228 add_install_rule( make, make->importlib,
3229 strmake( "lib%s.def", make->importlib ),
3230 strmake( "d$(dlldir)/lib%s.def", make->importlib ));
3232 else
3234 strarray_add( &make->clean_files, strmake( "lib%s.a", make->importlib ));
3235 if (!*dll_ext && needs_delay_lib( make ))
3237 strarray_add( &make->clean_files, strmake( "lib%s.delay.a", make->importlib ));
3238 output( "%s.delay.a ", importlib_path );
3240 output( "%s.a: %s %s", importlib_path, tools_path( make, "winebuild" ), spec_file );
3241 output_filenames_obj_dir( make, make->implib_objs );
3242 output( "\n" );
3243 output( "\t%s -w --implib -o $@ --export %s", tools_path( make, "winebuild" ), spec_file );
3244 output_filenames( target_flags );
3245 output_filenames_obj_dir( make, make->implib_objs );
3246 output( "\n" );
3247 add_install_rule( make, make->importlib,
3248 strmake( "lib%s.a", make->importlib ),
3249 strmake( "d$(dlldir)/lib%s.a", make->importlib ));
3251 if (crosstarget && (needs_cross_lib( make ) || needs_delay_lib( make )))
3253 struct strarray cross_files = strarray_replace_extension( &make->implib_objs, ".o", ".cross.o" );
3254 if (needs_cross_lib( make ))
3256 strarray_add( &make->clean_files, strmake( "lib%s.cross.a", make->importlib ));
3257 output_filename( strmake( "%s.cross.a", importlib_path ));
3259 if (needs_delay_lib( make ))
3261 strarray_add( &make->clean_files, strmake( "lib%s.delay.a", make->importlib ));
3262 output_filename( strmake( "%s.delay.a", importlib_path ));
3264 output( ": %s %s", tools_path( make, "winebuild" ), spec_file );
3265 output_filenames_obj_dir( make, cross_files );
3266 output( "\n" );
3267 output( "\t%s -b %s -w --implib -o $@ --export %s",
3268 tools_path( make, "winebuild" ), crosstarget, spec_file );
3269 output_filenames_obj_dir( make, cross_files );
3270 output( "\n" );
3274 if (spec_file)
3275 output_man_pages( make );
3276 else if (*dll_ext && !make->is_win16)
3278 char *binary = replace_extension( make->module, ".exe", "" );
3279 add_install_rule( make, binary, "wineapploader", strmake( "t$(bindir)/%s", binary ));
3284 /*******************************************************************
3285 * output_static_lib
3287 static void output_static_lib( struct makefile *make )
3289 strarray_add( &make->all_targets, make->staticlib );
3290 output( "%s:", obj_dir_path( make, make->staticlib ));
3291 output_filenames_obj_dir( make, make->object_files );
3292 output( "\n\trm -f $@\n" );
3293 output( "\t%s rc $@", ar );
3294 output_filenames_obj_dir( make, make->object_files );
3295 output( "\n\t%s $@\n", ranlib );
3296 add_install_rule( make, make->staticlib, make->staticlib,
3297 strmake( "d$(dlldir)/%s", make->staticlib ));
3298 if (needs_cross_lib( make ))
3300 char *name = replace_extension( make->staticlib, ".a", ".cross.a" );
3302 strarray_add( &make->all_targets, name );
3303 output( "%s:", obj_dir_path( make, name ));
3304 output_filenames_obj_dir( make, make->crossobj_files );
3305 output( "\n\trm -f $@\n" );
3306 output( "\t%s-ar rc $@", crosstarget );
3307 output_filenames_obj_dir( make, make->crossobj_files );
3308 output( "\n\t%s-ranlib $@\n", crosstarget );
3313 /*******************************************************************
3314 * output_shared_lib
3316 static void output_shared_lib( struct makefile *make )
3318 unsigned int i;
3319 char *basename, *p;
3320 struct strarray names = get_shared_lib_names( make->sharedlib );
3321 struct strarray all_libs = empty_strarray;
3322 struct strarray dep_libs = empty_strarray;
3324 basename = xstrdup( make->sharedlib );
3325 if ((p = strchr( basename, '.' ))) *p = 0;
3327 strarray_addall( &dep_libs, get_local_dependencies( make, basename, make->in_files ));
3328 strarray_addall( &all_libs, get_expanded_file_local_var( make, basename, "LDFLAGS" ));
3329 strarray_addall( &all_libs, add_default_libraries( make, &dep_libs ));
3331 output( "%s:", obj_dir_path( make, make->sharedlib ));
3332 output_filenames_obj_dir( make, make->object_files );
3333 output_filenames( dep_libs );
3334 output( "\n" );
3335 output( "\t$(CC) -o $@" );
3336 output_filenames_obj_dir( make, make->object_files );
3337 output_filenames( all_libs );
3338 output_filename( "$(LDFLAGS)" );
3339 output( "\n" );
3340 add_install_rule( make, make->sharedlib, make->sharedlib,
3341 strmake( "p$(libdir)/%s", make->sharedlib ));
3342 for (i = 1; i < names.count; i++)
3344 output( "%s: %s\n", obj_dir_path( make, names.str[i] ), obj_dir_path( make, names.str[i-1] ));
3345 output_symlink_rule( obj_dir_path( make, names.str[i-1] ), obj_dir_path( make, names.str[i] ));
3346 add_install_rule( make, names.str[i], names.str[i-1],
3347 strmake( "y$(libdir)/%s", names.str[i] ));
3349 strarray_addall( &make->all_targets, names );
3353 /*******************************************************************
3354 * output_test_module
3356 static void output_test_module( struct makefile *make )
3358 char *testmodule = replace_extension( make->testdll, ".dll", "_test.exe" );
3359 char *stripped = replace_extension( make->testdll, ".dll", "_test-stripped.exe" );
3360 char *testres = replace_extension( make->testdll, ".dll", "_test.res" );
3361 struct strarray dep_libs = empty_strarray;
3362 struct strarray all_libs = add_import_libs( make, &dep_libs, make->imports, 0 );
3363 struct makefile *parent = get_parent_makefile( make );
3364 const char *ext = make->is_cross ? "" : dll_ext;
3365 const char *parent_ext = parent && parent->is_cross ? "" : dll_ext;
3367 add_import_libs( make, &dep_libs, get_default_imports( make ), 0 ); /* dependencies only */
3368 strarray_addall( &all_libs, libs );
3369 strarray_add( &make->all_targets, strmake( "%s%s", testmodule, ext ));
3370 strarray_add( &make->clean_files, strmake( "%s%s", stripped, ext ));
3371 output( "%s%s:\n", obj_dir_path( make, testmodule ), ext );
3372 output_winegcc_command( make );
3373 output_filenames( make->extradllflags );
3374 output_filenames_obj_dir( make, make->is_cross ? make->crossobj_files : make->object_files );
3375 output_filenames_obj_dir( make, make->res_files );
3376 output_filenames( all_libs );
3377 output_filename( make->is_cross ? "$(CROSSLDFLAGS)" : "$(LDFLAGS)" );
3378 output( "\n" );
3379 output( "%s%s:\n", obj_dir_path( make, stripped ), ext );
3380 output_winegcc_command( make );
3381 output_filename( "-s" );
3382 output_filename( strmake( "-Wb,-F,%s", testmodule ));
3383 output_filenames( make->extradllflags );
3384 output_filenames_obj_dir( make, make->is_cross ? make->crossobj_files : make->object_files );
3385 output_filenames_obj_dir( make, make->res_files );
3386 output_filenames( all_libs );
3387 output_filename( make->is_cross ? "$(CROSSLDFLAGS)" : "$(LDFLAGS)" );
3388 output( "\n" );
3389 output( "%s%s %s%s:", obj_dir_path( make, testmodule ), ext, obj_dir_path( make, stripped ), ext );
3390 output_filenames_obj_dir( make, make->is_cross ? make->crossobj_files : make->object_files );
3391 output_filenames_obj_dir( make, make->res_files );
3392 output_filenames( dep_libs );
3393 output_filename( tools_path( make, "winebuild" ));
3394 output_filename( tools_path( make, "winegcc" ));
3395 output( "\n" );
3397 if (!make->disabled && !strarray_exists( &disabled_dirs, "programs/winetest" ))
3398 output( "all: %s/%s\n", top_obj_dir_path( make, "programs/winetest" ), testres );
3399 output( "%s/%s: %s%s\n", top_obj_dir_path( make, "programs/winetest" ), testres,
3400 obj_dir_path( make, stripped ), ext );
3401 output( "\techo \"%s TESTRES \\\"%s%s\\\"\" | %s -o $@\n",
3402 testmodule, obj_dir_path( make, stripped ), ext, tools_path( make, "wrc" ));
3404 output_filenames_obj_dir( make, make->ok_files );
3405 output( ": %s%s ../%s%s\n", testmodule, ext, make->testdll, parent_ext );
3406 output( "check test:" );
3407 if (!make->disabled && parent && !parent->disabled) output_filenames_obj_dir( make, make->ok_files );
3408 output( "\n" );
3409 strarray_add( &make->phony_targets, "check" );
3410 strarray_add( &make->phony_targets, "test" );
3411 output( "testclean::\n" );
3412 output( "\trm -f" );
3413 output_filenames_obj_dir( make, make->ok_files );
3414 output( "\n" );
3415 strarray_addall( &make->clean_files, make->ok_files );
3416 strarray_add( &make->phony_targets, "testclean" );
3420 /*******************************************************************
3421 * output_programs
3423 static void output_programs( struct makefile *make )
3425 unsigned int i, j;
3426 char *ldrpath_local = get_expanded_make_variable( make, "LDRPATH_LOCAL" );
3427 char *ldrpath_install = get_expanded_make_variable( make, "LDRPATH_INSTALL" );
3429 for (i = 0; i < make->programs.count; i++)
3431 char *program_installed = NULL;
3432 char *program = strmake( "%s%s", make->programs.str[i], exe_ext );
3433 struct strarray deps = get_local_dependencies( make, make->programs.str[i], make->in_files );
3434 struct strarray all_libs = get_expanded_file_local_var( make, make->programs.str[i], "LDFLAGS" );
3435 struct strarray objs = get_expanded_file_local_var( make, make->programs.str[i], "OBJS" );
3436 struct strarray symlinks = get_expanded_file_local_var( make, make->programs.str[i], "SYMLINKS" );
3438 if (!objs.count) objs = make->object_files;
3439 strarray_addall( &all_libs, add_default_libraries( make, &deps ));
3441 output( "%s:", obj_dir_path( make, program ) );
3442 output_filenames_obj_dir( make, objs );
3443 output_filenames( deps );
3444 output( "\n" );
3445 output( "\t$(CC) -o $@" );
3446 output_filenames_obj_dir( make, objs );
3448 if (strarray_exists( &all_libs, "-lwine" ))
3450 strarray_add( &all_libs, strmake( "-L%s", top_obj_dir_path( make, "libs/wine" )));
3451 if (ldrpath_local && ldrpath_install)
3453 program_installed = strmake( "%s-installed%s", make->programs.str[i], exe_ext );
3454 output_filename( ldrpath_local );
3455 output_filenames( all_libs );
3456 output_filename( "$(LDFLAGS)" );
3457 output( "\n" );
3458 output( "%s:", obj_dir_path( make, program_installed ) );
3459 output_filenames_obj_dir( make, objs );
3460 output_filenames( deps );
3461 output( "\n" );
3462 output( "\t$(CC) -o $@" );
3463 output_filenames_obj_dir( make, objs );
3464 output_filename( ldrpath_install );
3465 strarray_add( &make->all_targets, program_installed );
3469 output_filenames( all_libs );
3470 output_filename( "$(LDFLAGS)" );
3471 output( "\n" );
3472 strarray_add( &make->all_targets, program );
3474 for (j = 0; j < symlinks.count; j++)
3476 output( "%s: %s\n", obj_dir_path( make, symlinks.str[j] ), obj_dir_path( make, program ));
3477 output_symlink_rule( obj_dir_path( make, program ), obj_dir_path( make, symlinks.str[j] ));
3479 strarray_addall( &make->all_targets, symlinks );
3481 add_install_rule( make, program, program_installed ? program_installed : program,
3482 strmake( "p$(bindir)/%s", program ));
3483 for (j = 0; j < symlinks.count; j++)
3484 add_install_rule( make, symlinks.str[j], program,
3485 strmake( "y$(bindir)/%s%s", symlinks.str[j], exe_ext ));
3490 /*******************************************************************
3491 * output_subdirs
3493 static void output_subdirs( struct makefile *make )
3495 struct strarray symlinks = empty_strarray;
3496 struct strarray all_deps = empty_strarray;
3497 struct strarray build_deps = empty_strarray;
3498 struct strarray builddeps_deps = empty_strarray;
3499 struct strarray makefile_deps = empty_strarray;
3500 struct strarray clean_files = empty_strarray;
3501 struct strarray testclean_files = empty_strarray;
3502 struct strarray distclean_files = empty_strarray;
3503 struct strarray tools_deps = empty_strarray;
3504 struct strarray tooldeps_deps = empty_strarray;
3505 struct strarray winetest_deps = empty_strarray;
3506 unsigned int i, j;
3508 strarray_addall( &distclean_files, make->distclean_files );
3509 for (i = 0; i < make->subdirs.count; i++)
3511 const struct makefile *submake = make->submakes[i];
3512 char *subdir = base_dir_path( submake, "" );
3514 strarray_add( &makefile_deps, top_src_dir_path( make, base_dir_path( submake,
3515 strmake ( "%s.in", output_makefile_name ))));
3516 for (j = 0; j < submake->clean_files.count; j++)
3517 strarray_add( &clean_files, base_dir_path( submake, submake->clean_files.str[j] ));
3518 for (j = 0; j < submake->distclean_files.count; j++)
3519 strarray_add( &distclean_files, base_dir_path( submake, submake->distclean_files.str[j] ));
3520 for (j = 0; j < submake->ok_files.count; j++)
3521 strarray_add( &testclean_files, base_dir_path( submake, submake->ok_files.str[j] ));
3523 /* import libs are still created for disabled dirs, except for win16 ones */
3524 if (submake->module && submake->importlib && !(submake->disabled && submake->is_win16))
3526 char *importlib_path = base_dir_path( submake, strmake( "lib%s", submake->importlib ));
3527 if (submake->implib_objs.count)
3529 output( "%s.a: dummy\n", importlib_path );
3530 output( "\t@cd %s && $(MAKE) lib%s.a\n", subdir, submake->importlib );
3531 strarray_add( &tools_deps, strmake( "%s.a", importlib_path ));
3532 if (needs_cross_lib( submake ))
3534 output( "%s.cross.a: dummy\n", importlib_path );
3535 output( "\t@cd %s && $(MAKE) lib%s.cross.a\n", subdir, submake->importlib );
3536 strarray_add( &tools_deps, strmake( "%s.cross.a", importlib_path ));
3538 if (needs_delay_lib( submake ))
3540 output( "%s.delay.a: dummy\n", importlib_path );
3541 output( "\t@cd %s && $(MAKE) lib%s.delay.a\n", subdir, submake->importlib );
3542 strarray_add( &tools_deps, strmake( "%s.delay.a", importlib_path ));
3545 else
3547 char *spec_file = top_src_dir_path( make, base_dir_path( submake,
3548 replace_extension( submake->module, ".dll", ".spec" )));
3549 if (*dll_ext)
3551 output( "%s.def: %s", importlib_path, spec_file );
3552 strarray_add( &build_deps, strmake( "%s.def", importlib_path ));
3554 else
3556 strarray_add( &build_deps, strmake( "%s.a", importlib_path ));
3557 if (needs_delay_lib( submake )) output( "%s.delay.a ", importlib_path );
3558 output( "%s.a: %s", importlib_path, spec_file );
3560 output_filename( tools_path( make, "winebuild" ));
3561 output( "\n" );
3562 output( "\t%s -w -o $@", tools_path( make, "winebuild" ));
3563 output_filename( *dll_ext ? "--def" : "--implib" );
3564 output_filenames( target_flags );
3565 if (submake->is_win16) output_filename( "-m16" );
3566 output_filename( "--export" );
3567 output_filename( spec_file );
3568 output( "\n" );
3569 if (crosstarget && (needs_cross_lib( submake ) || needs_delay_lib( submake )))
3571 if (needs_cross_lib( submake )) output_filename( strmake( "%s.cross.a", importlib_path ));
3572 if (needs_delay_lib( submake )) output_filename( strmake( "%s.delay.a", importlib_path ));
3573 output( ": %s", spec_file );
3574 output_filename( tools_path( make, "winebuild" ));
3575 output( "\n" );
3576 output( "\t%s -b %s -w -o $@", tools_path( make, "winebuild" ), crosstarget );
3577 output_filename( "--implib" );
3578 output_filename( "--export" );
3579 output_filename( spec_file );
3580 output( "\n" );
3581 strarray_add( &build_deps, strmake( "%s.cross.a", importlib_path ));
3583 if (needs_delay_lib( submake ))
3584 strarray_add( &build_deps, strmake( "%s.delay.a", importlib_path ));
3586 strarray_addall( &symlinks, output_importlib_symlinks( make, submake ));
3589 if (submake->disabled) continue;
3590 strarray_add( &all_deps, subdir );
3592 if (submake->module)
3594 if (!submake->staticlib)
3596 strarray_add( &builddeps_deps, subdir );
3597 if (!submake->is_exe)
3599 output( "manpages htmlpages sgmlpages xmlpages::\n" );
3600 output( "\t@cd %s && $(MAKE) $@\n", subdir );
3603 else strarray_add( &tools_deps, subdir );
3605 else if (submake->testdll)
3607 output( "%s/test: dummy\n", subdir );
3608 output( "\t@cd %s && $(MAKE) test\n", subdir );
3609 strarray_add( &winetest_deps, subdir );
3610 strarray_add( &builddeps_deps, subdir );
3612 else
3614 if (!strcmp( submake->base_dir, "tools" ) || !strncmp( submake->base_dir, "tools/", 6 ))
3616 strarray_add( &tooldeps_deps, submake->base_dir );
3617 for (j = 0; j < submake->programs.count; j++)
3618 output( "%s/%s%s: %s\n", submake->base_dir,
3619 submake->programs.str[j], tools_ext, submake->base_dir );
3621 if (submake->programs.count || submake->sharedlib)
3623 struct strarray libs = get_expanded_make_var_array( submake, "EXTRALIBS" );
3624 for (j = 0; j < submake->programs.count; j++)
3625 strarray_addall( &libs, get_expanded_file_local_var( submake,
3626 submake->programs.str[j], "LDFLAGS" ));
3627 output( "%s: libs/port", submake->base_dir );
3628 for (j = 0; j < libs.count; j++)
3630 if (!strcmp( libs.str[j], "-lwpp" )) output_filename( "libs/wpp" );
3631 if (!strcmp( libs.str[j], "-lwine" )) output_filename( "libs/wine" );
3633 output( "\n" );
3637 if (submake->install_rules[INSTALL_LIB].count)
3639 output( "install install-lib:: %s\n", submake->base_dir );
3640 output_install_commands( make, submake, submake->install_rules[INSTALL_LIB] );
3642 if (submake->install_rules[INSTALL_DEV].count)
3644 output( "install install-dev:: %s\n", submake->base_dir );
3645 output_install_commands( make, submake, submake->install_rules[INSTALL_DEV] );
3648 output( "all:" );
3649 output_filenames( all_deps );
3650 output( "\n" );
3651 output_filenames( all_deps );
3652 output( ": dummy\n" );
3653 output( "\t@cd $@ && $(MAKE)\n" );
3654 output( "Makefile:" );
3655 output_filenames( makefile_deps );
3656 output( "\n" );
3657 output_filenames( makefile_deps );
3658 output( ":\n" );
3659 if (tooldeps_deps.count)
3661 output( "__tooldeps__:" );
3662 output_filenames( tooldeps_deps );
3663 output( "\n" );
3664 strarray_add( &make->phony_targets, "__tooldeps__" );
3666 if (winetest_deps.count)
3668 output( "buildtests programs/winetest:" );
3669 output_filenames( winetest_deps );
3670 output( "\n" );
3671 output( "check test:" );
3672 for (i = 0; i < winetest_deps.count; i++)
3674 char *target = strmake( "%s/test", winetest_deps.str[i] );
3675 output_filename( target );
3676 strarray_add( &make->phony_targets, target );
3678 output( "\n" );
3679 strarray_add( &make->phony_targets, "buildtests" );
3680 strarray_add( &make->phony_targets, "check" );
3681 strarray_add( &make->phony_targets, "test" );
3684 output( "clean::\n");
3685 output_rm_filenames( clean_files );
3686 output( "testclean::\n");
3687 output_rm_filenames( testclean_files );
3688 output( "distclean::\n");
3689 output_rm_filenames( distclean_files );
3690 output_filenames( tools_deps );
3691 output( ":" );
3692 output_filename( tools_dir_path( make, "widl" ));
3693 output_filename( tools_dir_path( make, "winebuild" ));
3694 output_filename( tools_dir_path( make, "winegcc" ));
3695 output_filename( obj_dir_path( make, "include" ));
3696 output( "\n" );
3697 output_filenames( builddeps_deps );
3698 output( ": __builddeps__\n" );
3699 strarray_add( &make->phony_targets, "distclean" );
3700 strarray_add( &make->phony_targets, "testclean" );
3701 strarray_addall( &make->phony_targets, all_deps );
3703 strarray_addall( &make->clean_files, symlinks );
3704 strarray_addall( &build_deps, tools_deps );
3705 strarray_addall( &build_deps, symlinks );
3706 if (build_deps.count)
3708 output( "__builddeps__:" );
3709 output_filenames( build_deps );
3710 output( "\n" );
3711 strarray_add( &make->phony_targets, "__builddeps__" );
3713 if (get_expanded_make_variable( make, "GETTEXTPO_LIBS" )) output_po_files( make );
3717 /*******************************************************************
3718 * output_sources
3720 static void output_sources( struct makefile *make )
3722 struct incl_file *source;
3723 unsigned int i, j;
3725 strarray_add( &make->phony_targets, "all" );
3727 LIST_FOR_EACH_ENTRY( source, &make->sources, struct incl_file, entry )
3729 char *obj = xstrdup( source->name );
3730 char *ext = get_extension( obj );
3732 if (!ext) fatal_error( "unsupported file type %s\n", source->name );
3733 *ext++ = 0;
3735 for (j = 0; output_source_funcs[j].ext; j++)
3736 if (!strcmp( ext, output_source_funcs[j].ext )) break;
3738 output_source_funcs[j].fn( make, source, obj );
3739 strarray_addall_uniq( &make->dependencies, source->dependencies );
3742 /* special case for winetest: add resource files from other test dirs */
3743 if (make->base_dir && !strcmp( make->base_dir, "programs/winetest" ))
3745 struct strarray tests = enable_tests;
3746 if (!tests.count)
3747 for (i = 0; i < top_makefile->subdirs.count; i++)
3748 if (top_makefile->submakes[i]->testdll && !top_makefile->submakes[i]->disabled)
3749 strarray_add( &tests, top_makefile->submakes[i]->testdll );
3750 for (i = 0; i < tests.count; i++)
3751 strarray_add( &make->res_files, replace_extension( tests.str[i], ".dll", "_test.res" ));
3754 if (make->dlldata_files.count)
3756 output( "%s: %s %s\n", obj_dir_path( make, "dlldata.c" ),
3757 tools_path( make, "widl" ), src_dir_path( make, "Makefile.in" ));
3758 output( "\t%s --dlldata-only -o $@", tools_path( make, "widl" ));
3759 output_filenames( make->dlldata_files );
3760 output( "\n" );
3763 if (make->staticlib) output_static_lib( make );
3764 else if (make->module) output_module( make );
3765 else if (make->testdll) output_test_module( make );
3766 else if (make->sharedlib) output_shared_lib( make );
3767 else if (make->programs.count) output_programs( make );
3769 for (i = 0; i < make->scripts.count; i++)
3770 add_install_rule( make, make->scripts.str[i], make->scripts.str[i],
3771 strmake( "S$(bindir)/%s", make->scripts.str[i] ));
3773 if (!make->src_dir) strarray_add( &make->distclean_files, ".gitignore" );
3774 strarray_add( &make->distclean_files, "Makefile" );
3775 if (make->testdll) strarray_add( &make->distclean_files, "testlist.c" );
3777 if (!make->base_dir)
3778 strarray_addall( &make->distclean_files, get_expanded_make_var_array( make, "CONFIGURE_TARGETS" ));
3779 else if (!strcmp( make->base_dir, "po" ))
3780 strarray_add( &make->distclean_files, "LINGUAS" );
3782 if (make->subdirs.count) output_subdirs( make );
3784 if (!make->disabled)
3786 if (make->all_targets.count)
3788 output( "all:" );
3789 output_filenames_obj_dir( make, make->all_targets );
3790 output( "\n" );
3792 output_install_rules( make, INSTALL_LIB, "install-lib" );
3793 output_install_rules( make, INSTALL_DEV, "install-dev" );
3794 output_uninstall_rules( make );
3797 if (make->dependencies.count)
3799 output_filenames( make->dependencies );
3800 output( ":\n" );
3803 strarray_addall( &make->clean_files, make->object_files );
3804 strarray_addall( &make->clean_files, make->crossobj_files );
3805 strarray_addall( &make->clean_files, make->res_files );
3806 strarray_addall( &make->clean_files, make->all_targets );
3807 strarray_addall( &make->clean_files, make->extra_targets );
3809 if (make->clean_files.count)
3811 output( "%s::\n", obj_dir_path( make, "clean" ));
3812 output( "\trm -f" );
3813 output_filenames_obj_dir( make, make->clean_files );
3814 output( "\n" );
3815 if (make->obj_dir) output( "__clean__: %s\n", obj_dir_path( make, "clean" ));
3816 strarray_add( &make->phony_targets, obj_dir_path( make, "clean" ));
3819 if (make->phony_targets.count)
3821 output( ".PHONY:" );
3822 output_filenames( make->phony_targets );
3823 output( "\n" );
3828 /*******************************************************************
3829 * create_temp_file
3831 static FILE *create_temp_file( const char *orig )
3833 char *name = xmalloc( strlen(orig) + 13 );
3834 unsigned int i, id = getpid();
3835 int fd;
3836 FILE *ret = NULL;
3838 for (i = 0; i < 100; i++)
3840 sprintf( name, "%s.tmp%08x", orig, id );
3841 if ((fd = open( name, O_RDWR | O_CREAT | O_EXCL, 0666 )) != -1)
3843 ret = fdopen( fd, "w" );
3844 break;
3846 if (errno != EEXIST) break;
3847 id += 7777;
3849 if (!ret) fatal_error( "failed to create output file for '%s'\n", orig );
3850 temp_file_name = name;
3851 return ret;
3855 /*******************************************************************
3856 * rename_temp_file
3858 static void rename_temp_file( const char *dest )
3860 int ret = rename( temp_file_name, dest );
3861 if (ret == -1 && errno == EEXIST)
3863 /* rename doesn't overwrite on windows */
3864 unlink( dest );
3865 ret = rename( temp_file_name, dest );
3867 if (ret == -1) fatal_error( "failed to rename output file to '%s'\n", dest );
3868 temp_file_name = NULL;
3872 /*******************************************************************
3873 * are_files_identical
3875 static int are_files_identical( FILE *file1, FILE *file2 )
3877 for (;;)
3879 char buffer1[8192], buffer2[8192];
3880 int size1 = fread( buffer1, 1, sizeof(buffer1), file1 );
3881 int size2 = fread( buffer2, 1, sizeof(buffer2), file2 );
3882 if (size1 != size2) return 0;
3883 if (!size1) return feof( file1 ) && feof( file2 );
3884 if (memcmp( buffer1, buffer2, size1 )) return 0;
3889 /*******************************************************************
3890 * rename_temp_file_if_changed
3892 static void rename_temp_file_if_changed( const char *dest )
3894 FILE *file1, *file2;
3895 int do_rename = 1;
3897 if ((file1 = fopen( dest, "r" )))
3899 if ((file2 = fopen( temp_file_name, "r" )))
3901 do_rename = !are_files_identical( file1, file2 );
3902 fclose( file2 );
3904 fclose( file1 );
3906 if (!do_rename)
3908 unlink( temp_file_name );
3909 temp_file_name = NULL;
3911 else rename_temp_file( dest );
3915 /*******************************************************************
3916 * output_linguas
3918 static void output_linguas( const struct makefile *make )
3920 const char *dest = base_dir_path( make, "LINGUAS" );
3921 struct incl_file *source;
3923 output_file = create_temp_file( dest );
3925 output( "# Automatically generated by make depend; DO NOT EDIT!!\n" );
3926 LIST_FOR_EACH_ENTRY( source, &make->sources, struct incl_file, entry )
3927 if (strendswith( source->name, ".po" ))
3928 output( "%s\n", replace_extension( source->name, ".po", "" ));
3930 if (fclose( output_file )) fatal_perror( "write" );
3931 output_file = NULL;
3932 rename_temp_file_if_changed( dest );
3936 /*******************************************************************
3937 * output_testlist
3939 static void output_testlist( const struct makefile *make )
3941 const char *dest = base_dir_path( make, "testlist.c" );
3942 struct strarray files = empty_strarray;
3943 unsigned int i;
3945 for (i = 0; i < make->ok_files.count; i++)
3946 strarray_add( &files, replace_extension( make->ok_files.str[i], ".ok", "" ));
3948 output_file = create_temp_file( dest );
3950 output( "/* Automatically generated by make depend; DO NOT EDIT!! */\n\n" );
3951 output( "#define WIN32_LEAN_AND_MEAN\n" );
3952 output( "#include <windows.h>\n\n" );
3953 output( "#define STANDALONE\n" );
3954 output( "#include \"wine/test.h\"\n\n" );
3956 for (i = 0; i < files.count; i++) output( "extern void func_%s(void);\n", files.str[i] );
3957 output( "\n" );
3958 output( "const struct test winetest_testlist[] =\n" );
3959 output( "{\n" );
3960 for (i = 0; i < files.count; i++) output( " { \"%s\", func_%s },\n", files.str[i], files.str[i] );
3961 output( " { 0, 0 }\n" );
3962 output( "};\n" );
3964 if (fclose( output_file )) fatal_perror( "write" );
3965 output_file = NULL;
3966 rename_temp_file_if_changed( dest );
3970 /*******************************************************************
3971 * output_gitignore
3973 static void output_gitignore( const char *dest, struct strarray files )
3975 int i;
3977 output_file = create_temp_file( dest );
3979 output( "# Automatically generated by make depend; DO NOT EDIT!!\n" );
3980 for (i = 0; i < files.count; i++)
3982 if (!strchr( files.str[i], '/' )) output( "/" );
3983 output( "%s\n", files.str[i] );
3986 if (fclose( output_file )) fatal_perror( "write" );
3987 output_file = NULL;
3988 rename_temp_file( dest );
3992 /*******************************************************************
3993 * output_top_variables
3995 static void output_top_variables( const struct makefile *make )
3997 unsigned int i;
3998 struct strarray *vars = &top_makefile->vars;
4000 if (!make->base_dir) return; /* don't output variables in the top makefile */
4002 output( "# Automatically generated by make depend; DO NOT EDIT!!\n\n" );
4003 output( "all:\n\n" );
4004 for (i = 0; i < vars->count; i += 2)
4006 if (!strcmp( vars->str[i], "SUBDIRS" )) continue; /* not inherited */
4007 output( "%s = %s\n", vars->str[i], get_make_variable( make, vars->str[i] ));
4009 output( "\n" );
4013 /*******************************************************************
4014 * output_dependencies
4016 static void output_dependencies( struct makefile *make )
4018 struct strarray ignore_files = empty_strarray;
4019 char buffer[1024];
4020 FILE *src_file;
4021 int found = 0;
4023 if (make->base_dir) create_dir( make->base_dir );
4025 output_file_name = base_dir_path( make, output_makefile_name );
4026 output_file = create_temp_file( output_file_name );
4027 output_top_variables( make );
4029 /* copy the contents of the source makefile */
4030 src_file = open_input_makefile( make );
4031 while (fgets( buffer, sizeof(buffer), src_file ) && !found)
4033 if (fwrite( buffer, 1, strlen(buffer), output_file ) != strlen(buffer)) fatal_perror( "write" );
4034 found = !strncmp( buffer, separator, strlen(separator) );
4036 if (fclose( src_file )) fatal_perror( "close" );
4037 input_file_name = NULL;
4039 if (!found) output( "\n%s (everything below this line is auto-generated; DO NOT EDIT!!)\n", separator );
4040 output_sources( make );
4042 fclose( output_file );
4043 output_file = NULL;
4044 rename_temp_file( output_file_name );
4046 strarray_addall( &ignore_files, make->distclean_files );
4047 strarray_addall( &ignore_files, make->clean_files );
4048 if (make->testdll) output_testlist( make );
4049 if (make->base_dir && !strcmp( make->base_dir, "po" )) output_linguas( make );
4050 if (!make->src_dir) output_gitignore( base_dir_path( make, ".gitignore" ), ignore_files );
4052 create_file_directories( make, ignore_files );
4054 output_file_name = NULL;
4058 /*******************************************************************
4059 * load_sources
4061 static void load_sources( struct makefile *make )
4063 static const char *source_vars[] =
4065 "SOURCES",
4066 "C_SRCS",
4067 "OBJC_SRCS",
4068 "RC_SRCS",
4069 "MC_SRCS",
4070 "IDL_SRCS",
4071 "BISON_SRCS",
4072 "LEX_SRCS",
4073 "HEADER_SRCS",
4074 "XTEMPLATE_SRCS",
4075 "SVG_SRCS",
4076 "FONT_SRCS",
4077 "IN_SRCS",
4078 "PO_SRCS",
4079 "MANPAGES",
4080 NULL
4082 const char **var;
4083 unsigned int i;
4084 struct strarray value;
4085 struct incl_file *file;
4087 if (root_src_dir)
4089 make->top_src_dir = concat_paths( make->top_obj_dir, root_src_dir );
4090 make->src_dir = concat_paths( make->top_src_dir, make->base_dir );
4092 strarray_set_value( &make->vars, "top_builddir", top_obj_dir_path( make, "" ));
4093 strarray_set_value( &make->vars, "top_srcdir", top_src_dir_path( make, "" ));
4094 strarray_set_value( &make->vars, "srcdir", src_dir_path( make, "" ));
4096 make->parent_dir = get_expanded_make_variable( make, "PARENTSRC" );
4097 make->module = get_expanded_make_variable( make, "MODULE" );
4098 make->testdll = get_expanded_make_variable( make, "TESTDLL" );
4099 make->sharedlib = get_expanded_make_variable( make, "SHAREDLIB" );
4100 make->staticlib = get_expanded_make_variable( make, "STATICLIB" );
4101 make->importlib = get_expanded_make_variable( make, "IMPORTLIB" );
4103 make->programs = get_expanded_make_var_array( make, "PROGRAMS" );
4104 make->scripts = get_expanded_make_var_array( make, "SCRIPTS" );
4105 make->imports = get_expanded_make_var_array( make, "IMPORTS" );
4106 make->delayimports = get_expanded_make_var_array( make, "DELAYIMPORTS" );
4107 make->extradllflags = get_expanded_make_var_array( make, "EXTRADLLFLAGS" );
4108 make->install_lib = get_expanded_make_var_array( make, "INSTALL_LIB" );
4109 make->install_dev = get_expanded_make_var_array( make, "INSTALL_DEV" );
4110 make->extra_targets = get_expanded_make_var_array( make, "EXTRA_TARGETS" );
4112 if (make->module && strendswith( make->module, ".a" )) make->staticlib = make->module;
4113 if (make->testdll) strarray_add( &make->extradllflags, "-mno-cygwin" );
4115 strarray_addall( &make->extradllflags, get_expanded_make_var_array( make, "APPMODE" ));
4116 make->disabled = make->base_dir && strarray_exists( &disabled_dirs, make->base_dir );
4117 make->is_win16 = strarray_exists( &make->extradllflags, "-m16" );
4118 make->use_msvcrt = strarray_exists( &make->extradllflags, "-mno-cygwin" );
4119 make->is_exe = strarray_exists( &make->extradllflags, "-mconsole" ) ||
4120 strarray_exists( &make->extradllflags, "-mwindows" );
4122 for (i = 0; i < make->imports.count && !make->use_msvcrt; i++)
4123 make->use_msvcrt = !strncmp( make->imports.str[i], "msvcr", 5 ) ||
4124 !strcmp( make->imports.str[i], "ucrtbase" );
4126 if (make->module && !make->install_lib.count && !make->install_dev.count)
4128 if (make->importlib) strarray_add( &make->install_dev, make->importlib );
4129 if (make->staticlib) strarray_add( &make->install_dev, make->staticlib );
4130 else strarray_add( &make->install_lib, make->module );
4133 make->include_paths = empty_strarray;
4134 make->include_args = empty_strarray;
4135 make->define_args = empty_strarray;
4136 strarray_add( &make->define_args, "-D__WINESRC__" );
4138 value = get_expanded_make_var_array( make, "EXTRAINCL" );
4139 for (i = 0; i < value.count; i++)
4140 if (!strncmp( value.str[i], "-I", 2 ))
4141 strarray_add_uniq( &make->include_paths, value.str[i] + 2 );
4142 else
4143 strarray_add_uniq( &make->define_args, value.str[i] );
4144 strarray_addall( &make->define_args, get_expanded_make_var_array( make, "EXTRADEFS" ));
4146 strarray_add( &make->include_args, strmake( "-I%s", obj_dir_path( make, "" )));
4147 if (make->src_dir)
4148 strarray_add( &make->include_args, strmake( "-I%s", make->src_dir ));
4149 if (make->parent_dir)
4150 strarray_add( &make->include_args, strmake( "-I%s", src_dir_path( make, make->parent_dir )));
4151 strarray_add( &make->include_args, strmake( "-I%s", top_obj_dir_path( make, "include" )));
4152 if (make->top_src_dir)
4153 strarray_add( &make->include_args, strmake( "-I%s", top_src_dir_path( make, "include" )));
4154 if (make->use_msvcrt)
4155 strarray_add( &make->include_args, strmake( "-I%s", top_src_dir_path( make, "include/msvcrt" )));
4156 for (i = 0; i < make->include_paths.count; i++)
4157 strarray_add( &make->include_args, strmake( "-I%s", obj_dir_path( make, make->include_paths.str[i] )));
4159 list_init( &make->sources );
4160 list_init( &make->includes );
4162 for (var = source_vars; *var; var++)
4164 value = get_expanded_make_var_array( make, *var );
4165 for (i = 0; i < value.count; i++) add_src_file( make, value.str[i] );
4168 add_generated_sources( make );
4170 LIST_FOR_EACH_ENTRY( file, &make->includes, struct incl_file, entry ) parse_file( make, file, 0 );
4171 LIST_FOR_EACH_ENTRY( file, &make->sources, struct incl_file, entry ) get_dependencies( file, file );
4173 if (crosstarget && !make->is_win16 && !strarray_exists( &make->imports, "kernel" ))
4175 make->is_cross = (make->testdll ||
4176 strarray_exists( &make->extradllflags, "-mno-cygwin" ) ||
4177 !has_object_file( make ));
4180 if (make->is_cross)
4182 for (i = 0; i < make->imports.count; i++)
4183 strarray_add_uniq( &cross_import_libs, make->imports.str[i] );
4184 if (strarray_exists( &make->extradllflags, "-mno-cygwin" ))
4185 strarray_add_uniq( &cross_import_libs, "msvcrt" );
4186 strarray_add_uniq( &cross_import_libs, "winecrt0" );
4187 strarray_add_uniq( &cross_import_libs, "kernel32" );
4188 strarray_add_uniq( &cross_import_libs, "ntdll" );
4191 if (!*dll_ext || make->is_cross)
4192 for (i = 0; i < make->delayimports.count; i++)
4193 strarray_add_uniq( &delay_import_libs, make->delayimports.str[i] );
4197 /*******************************************************************
4198 * parse_makeflags
4200 static void parse_makeflags( const char *flags )
4202 const char *p = flags;
4203 char *var, *buffer = xmalloc( strlen(flags) + 1 );
4205 while (*p)
4207 while (isspace(*p)) p++;
4208 var = buffer;
4209 while (*p && !isspace(*p))
4211 if (*p == '\\' && p[1]) p++;
4212 *var++ = *p++;
4214 *var = 0;
4215 if (var > buffer) set_make_variable( &cmdline_vars, buffer );
4220 /*******************************************************************
4221 * parse_option
4223 static int parse_option( const char *opt )
4225 if (opt[0] != '-')
4227 if (strchr( opt, '=' )) return set_make_variable( &cmdline_vars, opt );
4228 return 0;
4230 switch(opt[1])
4232 case 'f':
4233 if (opt[2]) output_makefile_name = opt + 2;
4234 break;
4235 case 'R':
4236 relative_dir_mode = 1;
4237 break;
4238 default:
4239 fprintf( stderr, "Unknown option '%s'\n%s", opt, Usage );
4240 exit(1);
4242 return 1;
4246 /*******************************************************************
4247 * main
4249 int main( int argc, char *argv[] )
4251 const char *makeflags = getenv( "MAKEFLAGS" );
4252 int i, j;
4254 if (makeflags) parse_makeflags( makeflags );
4256 i = 1;
4257 while (i < argc)
4259 if (parse_option( argv[i] ))
4261 for (j = i; j < argc; j++) argv[j] = argv[j+1];
4262 argc--;
4264 else i++;
4267 if (relative_dir_mode)
4269 char *relpath;
4271 if (argc != 3)
4273 fprintf( stderr, "Option -R needs two directories\n%s", Usage );
4274 exit( 1 );
4276 relpath = get_relative_path( argv[1], argv[2] );
4277 printf( "%s\n", relpath ? relpath : "." );
4278 exit( 0 );
4281 atexit( cleanup_files );
4282 signal( SIGTERM, exit_on_signal );
4283 signal( SIGINT, exit_on_signal );
4284 #ifdef SIGHUP
4285 signal( SIGHUP, exit_on_signal );
4286 #endif
4288 for (i = 0; i < HASH_SIZE; i++) list_init( &files[i] );
4290 top_makefile = parse_makefile( NULL );
4292 target_flags = get_expanded_make_var_array( top_makefile, "TARGETFLAGS" );
4293 msvcrt_flags = get_expanded_make_var_array( top_makefile, "MSVCRTFLAGS" );
4294 dll_flags = get_expanded_make_var_array( top_makefile, "DLLFLAGS" );
4295 extra_cflags = get_expanded_make_var_array( top_makefile, "EXTRACFLAGS" );
4296 extra_cross_cflags = get_expanded_make_var_array( top_makefile, "EXTRACROSSCFLAGS" );
4297 cpp_flags = get_expanded_make_var_array( top_makefile, "CPPFLAGS" );
4298 lddll_flags = get_expanded_make_var_array( top_makefile, "LDDLLFLAGS" );
4299 libs = get_expanded_make_var_array( top_makefile, "LIBS" );
4300 enable_tests = get_expanded_make_var_array( top_makefile, "ENABLE_TESTS" );
4301 top_install_lib = get_expanded_make_var_array( top_makefile, "TOP_INSTALL_LIB" );
4302 top_install_dev = get_expanded_make_var_array( top_makefile, "TOP_INSTALL_DEV" );
4304 root_src_dir = get_expanded_make_variable( top_makefile, "srcdir" );
4305 tools_dir = get_expanded_make_variable( top_makefile, "TOOLSDIR" );
4306 tools_ext = get_expanded_make_variable( top_makefile, "TOOLSEXT" );
4307 exe_ext = get_expanded_make_variable( top_makefile, "EXEEXT" );
4308 man_ext = get_expanded_make_variable( top_makefile, "api_manext" );
4309 dll_ext = (exe_ext && !strcmp( exe_ext, ".exe" )) ? "" : ".so";
4310 crosstarget = get_expanded_make_variable( top_makefile, "CROSSTARGET" );
4311 fontforge = get_expanded_make_variable( top_makefile, "FONTFORGE" );
4312 convert = get_expanded_make_variable( top_makefile, "CONVERT" );
4313 flex = get_expanded_make_variable( top_makefile, "FLEX" );
4314 bison = get_expanded_make_variable( top_makefile, "BISON" );
4315 ar = get_expanded_make_variable( top_makefile, "AR" );
4316 ranlib = get_expanded_make_variable( top_makefile, "RANLIB" );
4317 rsvg = get_expanded_make_variable( top_makefile, "RSVG" );
4318 icotool = get_expanded_make_variable( top_makefile, "ICOTOOL" );
4319 dlltool = get_expanded_make_variable( top_makefile, "DLLTOOL" );
4320 msgfmt = get_expanded_make_variable( top_makefile, "MSGFMT" );
4321 sed_cmd = get_expanded_make_variable( top_makefile, "SED_CMD" );
4322 ln_s = get_expanded_make_variable( top_makefile, "LN_S" );
4324 if (root_src_dir && !strcmp( root_src_dir, "." )) root_src_dir = NULL;
4325 if (tools_dir && !strcmp( tools_dir, "." )) tools_dir = NULL;
4326 if (!exe_ext) exe_ext = "";
4327 if (!tools_ext) tools_ext = "";
4328 if (!man_ext) man_ext = "3w";
4330 if (argc == 1)
4332 disabled_dirs = get_expanded_make_var_array( top_makefile, "DISABLED_SUBDIRS" );
4333 top_makefile->subdirs = get_expanded_make_var_array( top_makefile, "SUBDIRS" );
4334 top_makefile->submakes = xmalloc( top_makefile->subdirs.count * sizeof(*top_makefile->submakes) );
4336 for (i = 0; i < top_makefile->subdirs.count; i++)
4337 top_makefile->submakes[i] = parse_makefile( top_makefile->subdirs.str[i] );
4339 load_sources( top_makefile );
4340 for (i = 0; i < top_makefile->subdirs.count; i++)
4341 load_sources( top_makefile->submakes[i] );
4343 for (i = 0; i < top_makefile->subdirs.count; i++)
4344 output_dependencies( top_makefile->submakes[i] );
4346 output_dependencies( top_makefile );
4347 return 0;
4350 for (i = 1; i < argc; i++)
4352 struct makefile *make = parse_makefile( argv[i] );
4353 load_sources( make );
4354 output_dependencies( make );
4356 return 0;