dmsynth: Drop "synth" from the synth_sink field.
[wine.git] / tools / makedep.c
blobff89bae3ccf09bc2067fe0a1176161329b252eb1
1 /*
2 * Generate include file dependencies
4 * Copyright 1996, 2013, 2020 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"
23 #include <assert.h>
24 #include <ctype.h>
25 #include <errno.h>
26 #include <fcntl.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <stdarg.h>
30 #include <signal.h>
31 #include <string.h>
32 #include <sys/types.h>
33 #include <sys/stat.h>
35 #include "tools.h"
36 #include "wine/list.h"
38 enum incl_type
40 INCL_NORMAL, /* #include "foo.h" */
41 INCL_SYSTEM, /* #include <foo.h> */
42 INCL_IMPORT, /* idl import "foo.idl" */
43 INCL_IMPORTLIB, /* idl importlib "foo.tlb" */
44 INCL_CPP_QUOTE, /* idl cpp_quote("#include \"foo.h\"") */
45 INCL_CPP_QUOTE_SYSTEM /* idl cpp_quote("#include <foo.h>") */
48 struct dependency
50 int line; /* source line where this header is included */
51 enum incl_type type; /* type of include */
52 char *name; /* header name */
55 struct file
57 struct list entry;
58 char *name; /* full file name relative to cwd */
59 void *args; /* custom arguments for makefile rule */
60 unsigned int flags; /* flags (see below) */
61 unsigned int deps_count; /* files in use */
62 unsigned int deps_size; /* total allocated size */
63 struct dependency *deps; /* all header dependencies */
66 struct incl_file
68 struct list entry;
69 struct file *file;
70 char *name;
71 char *filename;
72 char *basename; /* base target name for generated files */
73 char *sourcename; /* source file name for generated headers */
74 struct incl_file *included_by; /* file that included this one */
75 int included_line; /* line where this file was included */
76 enum incl_type type; /* type of include */
77 int use_msvcrt:1; /* put msvcrt headers in the search path? */
78 int is_external:1; /* file from external library? */
79 struct incl_file *owner;
80 unsigned int files_count; /* files in use */
81 unsigned int files_size; /* total allocated size */
82 struct incl_file **files;
83 struct strarray dependencies; /* file dependencies */
84 struct strarray importlibdeps; /* importlib dependencies */
87 #define FLAG_GENERATED 0x000001 /* generated file */
88 #define FLAG_INSTALL 0x000002 /* file to install */
89 #define FLAG_IDL_PROXY 0x000100 /* generates a proxy (_p.c) file */
90 #define FLAG_IDL_CLIENT 0x000200 /* generates a client (_c.c) file */
91 #define FLAG_IDL_SERVER 0x000400 /* generates a server (_s.c) file */
92 #define FLAG_IDL_IDENT 0x000800 /* generates an ident (_i.c) file */
93 #define FLAG_IDL_REGISTER 0x001000 /* generates a registration (_r.res) file */
94 #define FLAG_IDL_TYPELIB 0x002000 /* generates a typelib (_l.res) file */
95 #define FLAG_IDL_REGTYPELIB 0x004000 /* generates a registered typelib (_t.res) file */
96 #define FLAG_IDL_HEADER 0x008000 /* generates a header (.h) file */
97 #define FLAG_RC_PO 0x010000 /* rc file contains translations */
98 #define FLAG_C_IMPLIB 0x020000 /* file is part of an import library */
99 #define FLAG_C_UNIX 0x040000 /* file is part of a Unix library */
100 #define FLAG_SFD_FONTS 0x080000 /* sfd file generated bitmap fonts */
102 static const struct
104 unsigned int flag;
105 const char *ext;
106 } idl_outputs[] =
108 { FLAG_IDL_TYPELIB, "_l.res" },
109 { FLAG_IDL_REGTYPELIB, "_t.res" },
110 { FLAG_IDL_CLIENT, "_c.c" },
111 { FLAG_IDL_IDENT, "_i.c" },
112 { FLAG_IDL_PROXY, "_p.c" },
113 { FLAG_IDL_SERVER, "_s.c" },
114 { FLAG_IDL_REGISTER, "_r.res" },
115 { FLAG_IDL_HEADER, ".h" }
118 #define HASH_SIZE 997
120 static struct list files[HASH_SIZE];
122 enum install_rules { INSTALL_LIB, INSTALL_DEV, NB_INSTALL_RULES };
124 /* variables common to all makefiles */
125 static struct strarray linguas;
126 static struct strarray dll_flags;
127 static struct strarray unix_dllflags;
128 static struct strarray target_flags;
129 static struct strarray msvcrt_flags;
130 static struct strarray extra_cflags;
131 static struct strarray extra_cross_cflags;
132 static struct strarray extra_cflags_extlib;
133 static struct strarray extra_cross_cflags_extlib;
134 static struct strarray cpp_flags;
135 static struct strarray lddll_flags;
136 static struct strarray libs;
137 static struct strarray enable_tests;
138 static struct strarray cmdline_vars;
139 static struct strarray subdirs;
140 static struct strarray disabled_dirs;
141 static struct strarray delay_import_libs;
142 static struct strarray top_install_lib;
143 static struct strarray top_install_dev;
144 static const char *root_src_dir;
145 static const char *tools_dir;
146 static const char *tools_ext;
147 static const char *exe_ext;
148 static const char *dll_ext;
149 static const char *host_cpu;
150 static const char *pe_dir;
151 static const char *so_dir;
152 static const char *crosstarget;
153 static const char *crossdebug;
154 static const char *fontforge;
155 static const char *convert;
156 static const char *flex;
157 static const char *bison;
158 static const char *ar;
159 static const char *ranlib;
160 static const char *rsvg;
161 static const char *icotool;
162 static const char *dlltool;
163 static const char *msgfmt;
164 static const char *ln_s;
165 static const char *sed_cmd;
166 static const char *delay_load_flag;
168 struct makefile
170 /* values determined from input makefile */
171 struct strarray vars;
172 struct strarray include_paths;
173 struct strarray include_args;
174 struct strarray define_args;
175 struct strarray programs;
176 struct strarray scripts;
177 struct strarray imports;
178 struct strarray delayimports;
179 struct strarray extradllflags;
180 struct strarray install_lib;
181 struct strarray install_dev;
182 struct strarray extra_targets;
183 struct strarray extra_imports;
184 struct list sources;
185 struct list includes;
186 const char *src_dir;
187 const char *obj_dir;
188 const char *parent_dir;
189 const char *module;
190 const char *testdll;
191 const char *extlib;
192 const char *sharedlib;
193 const char *staticlib;
194 const char *staticimplib;
195 const char *importlib;
196 const char *unixlib;
197 int native_unix_lib;
198 int disabled;
199 int use_msvcrt;
200 int is_cross;
201 int is_win16;
202 int is_exe;
204 /* values generated at output time */
205 struct strarray in_files;
206 struct strarray ok_files;
207 struct strarray pot_files;
208 struct strarray test_files;
209 struct strarray clean_files;
210 struct strarray distclean_files;
211 struct strarray uninstall_files;
212 struct strarray object_files;
213 struct strarray crossobj_files;
214 struct strarray unixobj_files;
215 struct strarray res_files;
216 struct strarray font_files;
217 struct strarray debug_files;
218 struct strarray dlldata_files;
219 struct strarray implib_files;
220 struct strarray crossimplib_files;
221 struct strarray all_targets;
222 struct strarray phony_targets;
223 struct strarray dependencies;
224 struct strarray install_rules[NB_INSTALL_RULES];
227 static struct makefile *top_makefile;
228 static struct makefile **submakes;
230 static const char separator[] = "### Dependencies";
231 static const char *output_makefile_name = "Makefile";
232 static const char *input_file_name;
233 static const char *output_file_name;
234 static const char *temp_file_name;
235 static int relative_dir_mode;
236 static int silent_rules;
237 static int input_line;
238 static int output_column;
239 static FILE *output_file;
241 static const char Usage[] =
242 "Usage: makedep [options] [directories]\n"
243 "Options:\n"
244 " -R from to Compute the relative path between two directories\n"
245 " -S Generate Automake-style silent rules\n"
246 " -fxxx Store output in file 'xxx' (default: Makefile)\n";
249 static void fatal_error( const char *msg, ... ) __attribute__ ((__format__ (__printf__, 1, 2)));
250 static void fatal_perror( const char *msg, ... ) __attribute__ ((__format__ (__printf__, 1, 2)));
251 static void output( const char *format, ... ) __attribute__ ((__format__ (__printf__, 1, 2)));
252 static char *strmake( const char* fmt, ... ) __attribute__ ((__format__ (__printf__, 1, 2)));
254 /*******************************************************************
255 * fatal_error
257 static void fatal_error( const char *msg, ... )
259 va_list valist;
260 va_start( valist, msg );
261 if (input_file_name)
263 fprintf( stderr, "%s:", input_file_name );
264 if (input_line) fprintf( stderr, "%d:", input_line );
265 fprintf( stderr, " error: " );
267 else fprintf( stderr, "makedep: error: " );
268 vfprintf( stderr, msg, valist );
269 va_end( valist );
270 exit(1);
274 /*******************************************************************
275 * fatal_perror
277 static void fatal_perror( const char *msg, ... )
279 va_list valist;
280 va_start( valist, msg );
281 if (input_file_name)
283 fprintf( stderr, "%s:", input_file_name );
284 if (input_line) fprintf( stderr, "%d:", input_line );
285 fprintf( stderr, " error: " );
287 else fprintf( stderr, "makedep: error: " );
288 vfprintf( stderr, msg, valist );
289 perror( " " );
290 va_end( valist );
291 exit(1);
295 /*******************************************************************
296 * cleanup_files
298 static void cleanup_files(void)
300 if (temp_file_name) unlink( temp_file_name );
301 if (output_file_name) unlink( output_file_name );
305 /*******************************************************************
306 * exit_on_signal
308 static void exit_on_signal( int sig )
310 exit( 1 ); /* this will call the atexit functions */
314 /*******************************************************************
315 * output
317 static void output( const char *format, ... )
319 int ret;
320 va_list valist;
322 va_start( valist, format );
323 ret = vfprintf( output_file, format, valist );
324 va_end( valist );
325 if (ret < 0) fatal_perror( "output" );
326 if (format[0] && format[strlen(format) - 1] == '\n') output_column = 0;
327 else output_column += ret;
331 /*******************************************************************
332 * strarray_get_value
334 * Find a value in a name/value pair string array.
336 static const char *strarray_get_value( const struct strarray *array, const char *name )
338 int pos, res, min = 0, max = array->count / 2 - 1;
340 while (min <= max)
342 pos = (min + max) / 2;
343 if (!(res = strcmp( array->str[pos * 2], name ))) return array->str[pos * 2 + 1];
344 if (res < 0) min = pos + 1;
345 else max = pos - 1;
347 return NULL;
351 /*******************************************************************
352 * strarray_set_value
354 * Define a value in a name/value pair string array.
356 static void strarray_set_value( struct strarray *array, const char *name, const char *value )
358 int i, pos, res, min = 0, max = array->count / 2 - 1;
360 while (min <= max)
362 pos = (min + max) / 2;
363 if (!(res = strcmp( array->str[pos * 2], name )))
365 /* redefining a variable replaces the previous value */
366 array->str[pos * 2 + 1] = value;
367 return;
369 if (res < 0) min = pos + 1;
370 else max = pos - 1;
372 strarray_add( array, NULL );
373 strarray_add( array, NULL );
374 for (i = array->count - 1; i > min * 2 + 1; i--) array->str[i] = array->str[i - 2];
375 array->str[min * 2] = name;
376 array->str[min * 2 + 1] = value;
380 /*******************************************************************
381 * normalize_arch
383 static const char *normalize_arch( const char *arch )
385 unsigned int i, j;
387 static const char *map[][8] =
389 /* normalized aliases */
390 { "i386", "i486", "i586", "i686", "ia32" },
391 { "x86_64", "amd64", "x86-64", "x86_amd64", "x64" },
392 { "aarch64", "arm64" },
393 { "arm" },
396 for (i = 0; i < sizeof(map) / sizeof(map[0]); i++)
397 for (j = 0; map[i][j]; j++)
398 if (!strncmp( arch, map[i][j], strlen(map[i][j]) ))
399 return map[i][0];
400 return NULL;
404 /*******************************************************************
405 * output_filename
407 static void output_filename( const char *name )
409 if (output_column + strlen(name) + 1 > 100)
411 output( " \\\n" );
412 output( " " );
414 else if (output_column) output( " " );
415 output( "%s", name );
419 /*******************************************************************
420 * output_filenames
422 static void output_filenames( struct strarray array )
424 unsigned int i;
426 for (i = 0; i < array.count; i++) output_filename( array.str[i] );
430 /*******************************************************************
431 * output_rm_filenames
433 static void output_rm_filenames( struct strarray array )
435 static const unsigned int max_cmdline = 30000; /* to be on the safe side */
436 unsigned int i, len;
438 if (!array.count) return;
439 output( "\trm -f" );
440 for (i = len = 0; i < array.count; i++)
442 if (len > max_cmdline)
444 output( "\n" );
445 output( "\trm -f" );
446 len = 0;
448 output_filename( array.str[i] );
449 len += strlen( array.str[i] ) + 1;
451 output( "\n" );
455 /*******************************************************************
456 * get_extension
458 static char *get_extension( char *filename )
460 char *ext = strrchr( filename, '.' );
461 if (ext && strchr( ext, '/' )) ext = NULL;
462 return ext;
466 /*******************************************************************
467 * get_base_name
469 static const char *get_base_name( const char *name )
471 char *base;
472 if (!strchr( name, '.' )) return name;
473 base = xstrdup( name );
474 *strrchr( base, '.' ) = 0;
475 return base;
479 /*******************************************************************
480 * replace_filename
482 static char *replace_filename( const char *path, const char *name )
484 const char *p;
485 char *ret;
486 size_t len;
488 if (!path) return xstrdup( name );
489 if (!(p = strrchr( path, '/' ))) return xstrdup( name );
490 len = p - path + 1;
491 ret = xmalloc( len + strlen( name ) + 1 );
492 memcpy( ret, path, len );
493 strcpy( ret + len, name );
494 return ret;
498 /*******************************************************************
499 * replace_substr
501 static char *replace_substr( const char *str, const char *start, size_t len, const char *replace )
503 size_t pos = start - str;
504 char *ret = xmalloc( pos + strlen(replace) + strlen(start + len) + 1 );
505 memcpy( ret, str, pos );
506 strcpy( ret + pos, replace );
507 strcat( ret + pos, start + len );
508 return ret;
512 /*******************************************************************
513 * get_relative_path
515 * Determine where the destination path is located relative to the 'from' path.
517 static char *get_relative_path( const char *from, const char *dest )
519 const char *start;
520 char *ret, *p;
521 unsigned int dotdots = 0;
523 /* a path of "." is equivalent to an empty path */
524 if (!strcmp( from, "." )) from = "";
526 for (;;)
528 while (*from == '/') from++;
529 while (*dest == '/') dest++;
530 start = dest; /* save start of next path element */
531 if (!*from) break;
533 while (*from && *from != '/' && *from == *dest) { from++; dest++; }
534 if ((!*from || *from == '/') && (!*dest || *dest == '/')) continue;
536 /* count remaining elements in 'from' */
539 dotdots++;
540 while (*from && *from != '/') from++;
541 while (*from == '/') from++;
543 while (*from);
544 break;
547 if (!start[0] && !dotdots) return NULL; /* empty path */
549 ret = xmalloc( 3 * dotdots + strlen( start ) + 1 );
550 for (p = ret; dotdots; dotdots--, p += 3) memcpy( p, "../", 3 );
552 if (start[0]) strcpy( p, start );
553 else p[-1] = 0; /* remove trailing slash */
554 return ret;
558 /*******************************************************************
559 * concat_paths
561 static char *concat_paths( const char *base, const char *path )
563 int i, len;
564 char *ret;
566 if (!base || !base[0]) return xstrdup( path && path[0] ? path : "." );
567 if (!path || !path[0]) return xstrdup( base );
568 if (path[0] == '/') return xstrdup( path );
570 len = strlen( base );
571 while (len && base[len - 1] == '/') len--;
572 while (len && !strncmp( path, "..", 2 ) && (!path[2] || path[2] == '/'))
574 for (i = len; i > 0; i--) if (base[i - 1] == '/') break;
575 if (i == len - 2 && !memcmp( base + i, "..", 2 )) break; /* we can't go up if we already have ".." */
576 if (i != len - 1 || base[i] != '.')
578 path += 2;
579 while (*path == '/') path++;
581 /* else ignore "." element */
582 while (i > 0 && base[i - 1] == '/') i--;
583 len = i;
585 if (!len && base[0] != '/') return xstrdup( path[0] ? path : "." );
586 ret = xmalloc( len + strlen( path ) + 2 );
587 memcpy( ret, base, len );
588 ret[len++] = '/';
589 strcpy( ret + len, path );
590 return ret;
594 /*******************************************************************
595 * obj_dir_path
597 static char *obj_dir_path( const struct makefile *make, const char *path )
599 return concat_paths( make->obj_dir, path );
603 /*******************************************************************
604 * src_dir_path
606 static char *src_dir_path( const struct makefile *make, const char *path )
608 if (make->src_dir) return concat_paths( make->src_dir, path );
609 return obj_dir_path( make, path );
613 /*******************************************************************
614 * root_src_dir_path
616 static char *root_src_dir_path( const char *path )
618 return concat_paths( root_src_dir, path );
622 /*******************************************************************
623 * tools_dir_path
625 static char *tools_dir_path( const struct makefile *make, const char *path )
627 if (tools_dir) return strmake( "%s/tools/%s", tools_dir, path );
628 return strmake( "tools/%s", path );
632 /*******************************************************************
633 * tools_path
635 static char *tools_path( const struct makefile *make, const char *name )
637 return strmake( "%s/%s%s", tools_dir_path( make, name ), name, tools_ext );
641 /*******************************************************************
642 * strarray_addall_path
644 static void strarray_addall_path( struct strarray *array, const char *dir, struct strarray added )
646 unsigned int i;
648 for (i = 0; i < added.count; i++) strarray_add( array, concat_paths( dir, added.str[i] ));
652 /*******************************************************************
653 * get_line
655 static char *get_line( FILE *file )
657 static char *buffer;
658 static size_t size;
660 if (!size)
662 size = 1024;
663 buffer = xmalloc( size );
665 if (!fgets( buffer, size, file )) return NULL;
666 input_line++;
668 for (;;)
670 char *p = buffer + strlen(buffer);
671 /* if line is larger than buffer, resize buffer */
672 while (p == buffer + size - 1 && p[-1] != '\n')
674 buffer = xrealloc( buffer, size * 2 );
675 if (!fgets( buffer + size - 1, size + 1, file )) break;
676 p = buffer + strlen(buffer);
677 size *= 2;
679 if (p > buffer && p[-1] == '\n')
681 *(--p) = 0;
682 if (p > buffer && p[-1] == '\r') *(--p) = 0;
683 if (p > buffer && p[-1] == '\\')
685 *(--p) = 0;
686 /* line ends in backslash, read continuation line */
687 if (!fgets( p, size - (p - buffer), file )) return buffer;
688 input_line++;
689 continue;
692 return buffer;
697 /*******************************************************************
698 * hash_filename
700 static unsigned int hash_filename( const char *name )
702 /* FNV-1 hash */
703 unsigned int ret = 2166136261u;
704 while (*name) ret = (ret * 16777619) ^ *name++;
705 return ret % HASH_SIZE;
709 /*******************************************************************
710 * add_file
712 static struct file *add_file( const char *name )
714 struct file *file = xmalloc( sizeof(*file) );
715 memset( file, 0, sizeof(*file) );
716 file->name = xstrdup( name );
717 return file;
721 /*******************************************************************
722 * add_dependency
724 static void add_dependency( struct file *file, const char *name, enum incl_type type )
726 if (file->deps_count >= file->deps_size)
728 file->deps_size *= 2;
729 if (file->deps_size < 16) file->deps_size = 16;
730 file->deps = xrealloc( file->deps, file->deps_size * sizeof(*file->deps) );
732 file->deps[file->deps_count].line = input_line;
733 file->deps[file->deps_count].type = type;
734 file->deps[file->deps_count].name = xstrdup( name );
735 file->deps_count++;
739 /*******************************************************************
740 * find_src_file
742 static struct incl_file *find_src_file( const struct makefile *make, const char *name )
744 struct incl_file *file;
746 LIST_FOR_EACH_ENTRY( file, &make->sources, struct incl_file, entry )
747 if (!strcmp( name, file->name )) return file;
748 return NULL;
751 /*******************************************************************
752 * find_include_file
754 static struct incl_file *find_include_file( const struct makefile *make, const char *name )
756 struct incl_file *file;
758 LIST_FOR_EACH_ENTRY( file, &make->includes, struct incl_file, entry )
759 if (!strcmp( name, file->name )) return file;
760 return NULL;
763 /*******************************************************************
764 * add_include
766 * Add an include file if it doesn't already exists.
768 static struct incl_file *add_include( struct makefile *make, struct incl_file *parent,
769 const char *name, int line, enum incl_type type )
771 struct incl_file *include;
773 if (parent->files_count >= parent->files_size)
775 parent->files_size *= 2;
776 if (parent->files_size < 16) parent->files_size = 16;
777 parent->files = xrealloc( parent->files, parent->files_size * sizeof(*parent->files) );
780 LIST_FOR_EACH_ENTRY( include, &make->includes, struct incl_file, entry )
781 if (!parent->use_msvcrt == !include->use_msvcrt && !strcmp( name, include->name ))
782 goto found;
784 include = xmalloc( sizeof(*include) );
785 memset( include, 0, sizeof(*include) );
786 include->name = xstrdup(name);
787 include->included_by = parent;
788 include->included_line = line;
789 include->type = type;
790 include->use_msvcrt = parent->use_msvcrt;
791 list_add_tail( &make->includes, &include->entry );
792 found:
793 parent->files[parent->files_count++] = include;
794 return include;
798 /*******************************************************************
799 * add_generated_source
801 * Add a generated source file to the list.
803 static struct incl_file *add_generated_source( struct makefile *make,
804 const char *name, const char *filename )
806 struct incl_file *file;
808 if ((file = find_src_file( make, name ))) return file; /* we already have it */
809 file = xmalloc( sizeof(*file) );
810 memset( file, 0, sizeof(*file) );
811 file->file = add_file( name );
812 file->name = xstrdup( name );
813 file->basename = xstrdup( filename ? filename : name );
814 file->filename = obj_dir_path( make, file->basename );
815 file->file->flags = FLAG_GENERATED;
816 file->use_msvcrt = make->use_msvcrt;
817 list_add_tail( &make->sources, &file->entry );
818 return file;
822 /*******************************************************************
823 * parse_include_directive
825 static void parse_include_directive( struct file *source, char *str )
827 char quote, *include, *p = str;
829 while (*p && isspace(*p)) p++;
830 if (*p != '\"' && *p != '<' ) return;
831 quote = *p++;
832 if (quote == '<') quote = '>';
833 include = p;
834 while (*p && (*p != quote)) p++;
835 if (!*p) fatal_error( "malformed include directive '%s'\n", str );
836 *p = 0;
837 add_dependency( source, include, (quote == '>') ? INCL_SYSTEM : INCL_NORMAL );
841 /*******************************************************************
842 * parse_pragma_directive
844 static void parse_pragma_directive( struct file *source, char *str )
846 char *flag, *p = str;
848 if (!isspace( *p )) return;
849 while (*p && isspace(*p)) p++;
850 p = strtok( p, " \t" );
851 if (strcmp( p, "makedep" )) return;
853 while ((flag = strtok( NULL, " \t" )))
855 if (!strcmp( flag, "depend" ))
857 while ((p = strtok( NULL, " \t" ))) add_dependency( source, p, INCL_NORMAL );
858 return;
860 else if (!strcmp( flag, "install" )) source->flags |= FLAG_INSTALL;
862 if (strendswith( source->name, ".idl" ))
864 if (!strcmp( flag, "header" )) source->flags |= FLAG_IDL_HEADER;
865 else if (!strcmp( flag, "proxy" )) source->flags |= FLAG_IDL_PROXY;
866 else if (!strcmp( flag, "client" )) source->flags |= FLAG_IDL_CLIENT;
867 else if (!strcmp( flag, "server" )) source->flags |= FLAG_IDL_SERVER;
868 else if (!strcmp( flag, "ident" )) source->flags |= FLAG_IDL_IDENT;
869 else if (!strcmp( flag, "typelib" )) source->flags |= FLAG_IDL_TYPELIB;
870 else if (!strcmp( flag, "register" )) source->flags |= FLAG_IDL_REGISTER;
871 else if (!strcmp( flag, "regtypelib" )) source->flags |= FLAG_IDL_REGTYPELIB;
873 else if (strendswith( source->name, ".rc" ))
875 if (!strcmp( flag, "po" )) source->flags |= FLAG_RC_PO;
877 else if (strendswith( source->name, ".sfd" ))
879 if (!strcmp( flag, "font" ))
881 struct strarray *array = source->args;
883 if (!array)
885 source->args = array = xmalloc( sizeof(*array) );
886 *array = empty_strarray;
887 source->flags |= FLAG_SFD_FONTS;
889 strarray_add( array, xstrdup( strtok( NULL, "" )));
890 return;
893 else
895 if (!strcmp( flag, "implib" )) source->flags |= FLAG_C_IMPLIB;
896 if (!strcmp( flag, "unix" )) source->flags |= FLAG_C_UNIX;
902 /*******************************************************************
903 * parse_cpp_directive
905 static void parse_cpp_directive( struct file *source, char *str )
907 while (*str && isspace(*str)) str++;
908 if (*str++ != '#') return;
909 while (*str && isspace(*str)) str++;
911 if (!strncmp( str, "include", 7 ))
912 parse_include_directive( source, str + 7 );
913 else if (!strncmp( str, "import", 6 ) && strendswith( source->name, ".m" ))
914 parse_include_directive( source, str + 6 );
915 else if (!strncmp( str, "pragma", 6 ))
916 parse_pragma_directive( source, str + 6 );
920 /*******************************************************************
921 * parse_idl_file
923 static void parse_idl_file( struct file *source, FILE *file )
925 char *buffer, *include;
927 input_line = 0;
929 while ((buffer = get_line( file )))
931 char quote;
932 char *p = buffer;
933 while (*p && isspace(*p)) p++;
935 if (!strncmp( p, "importlib", 9 ))
937 p += 9;
938 while (*p && isspace(*p)) p++;
939 if (*p++ != '(') continue;
940 while (*p && isspace(*p)) p++;
941 if (*p++ != '"') continue;
942 include = p;
943 while (*p && (*p != '"')) p++;
944 if (!*p) fatal_error( "malformed importlib directive\n" );
945 *p = 0;
946 add_dependency( source, include, INCL_IMPORTLIB );
947 continue;
950 if (!strncmp( p, "import", 6 ))
952 p += 6;
953 while (*p && isspace(*p)) p++;
954 if (*p != '"') continue;
955 include = ++p;
956 while (*p && (*p != '"')) p++;
957 if (!*p) fatal_error( "malformed import directive\n" );
958 *p = 0;
959 add_dependency( source, include, INCL_IMPORT );
960 continue;
963 /* check for #include inside cpp_quote */
964 if (!strncmp( p, "cpp_quote", 9 ))
966 p += 9;
967 while (*p && isspace(*p)) p++;
968 if (*p++ != '(') continue;
969 while (*p && isspace(*p)) p++;
970 if (*p++ != '"') continue;
971 if (*p++ != '#') continue;
972 while (*p && isspace(*p)) p++;
973 if (strncmp( p, "include", 7 )) continue;
974 p += 7;
975 while (*p && isspace(*p)) p++;
976 if (*p == '\\' && p[1] == '"')
978 p += 2;
979 quote = '"';
981 else
983 if (*p++ != '<' ) continue;
984 quote = '>';
986 include = p;
987 while (*p && (*p != quote)) p++;
988 if (!*p || (quote == '"' && p[-1] != '\\'))
989 fatal_error( "malformed #include directive inside cpp_quote\n" );
990 if (quote == '"') p--; /* remove backslash */
991 *p = 0;
992 add_dependency( source, include, (quote == '>') ? INCL_CPP_QUOTE_SYSTEM : INCL_CPP_QUOTE );
993 continue;
996 parse_cpp_directive( source, p );
1000 /*******************************************************************
1001 * parse_c_file
1003 static void parse_c_file( struct file *source, FILE *file )
1005 char *buffer;
1007 input_line = 0;
1008 while ((buffer = get_line( file )))
1010 parse_cpp_directive( source, buffer );
1015 /*******************************************************************
1016 * parse_rc_file
1018 static void parse_rc_file( struct file *source, FILE *file )
1020 char *buffer, *include;
1022 input_line = 0;
1023 while ((buffer = get_line( file )))
1025 char quote;
1026 char *p = buffer;
1027 while (*p && isspace(*p)) p++;
1029 if (p[0] == '/' && p[1] == '*') /* check for magic makedep comment */
1031 p += 2;
1032 while (*p && isspace(*p)) p++;
1033 if (strncmp( p, "@makedep:", 9 )) continue;
1034 p += 9;
1035 while (*p && isspace(*p)) p++;
1036 quote = '"';
1037 if (*p == quote)
1039 include = ++p;
1040 while (*p && *p != quote) p++;
1042 else
1044 include = p;
1045 while (*p && !isspace(*p) && *p != '*') p++;
1047 if (!*p)
1048 fatal_error( "malformed makedep comment\n" );
1049 *p = 0;
1050 add_dependency( source, include, (quote == '>') ? INCL_SYSTEM : INCL_NORMAL );
1051 continue;
1054 parse_cpp_directive( source, buffer );
1059 /*******************************************************************
1060 * parse_in_file
1062 static void parse_in_file( struct file *source, FILE *file )
1064 char *p, *buffer;
1066 /* make sure it gets rebuilt when the version changes */
1067 add_dependency( source, "config.h", INCL_SYSTEM );
1069 if (!strendswith( source->name, ".man.in" )) return; /* not a man page */
1071 input_line = 0;
1072 while ((buffer = get_line( file )))
1074 if (strncmp( buffer, ".TH", 3 )) continue;
1075 if (!(p = strtok( buffer, " \t" ))) continue; /* .TH */
1076 if (!(p = strtok( NULL, " \t" ))) continue; /* program name */
1077 if (!(p = strtok( NULL, " \t" ))) continue; /* man section */
1078 source->args = xstrdup( p );
1079 return;
1084 /*******************************************************************
1085 * parse_sfd_file
1087 static void parse_sfd_file( struct file *source, FILE *file )
1089 char *p, *eol, *buffer;
1091 input_line = 0;
1092 while ((buffer = get_line( file )))
1094 if (strncmp( buffer, "UComments:", 10 )) continue;
1095 p = buffer + 10;
1096 while (*p == ' ') p++;
1097 if (p[0] == '"' && p[1] && buffer[strlen(buffer) - 1] == '"')
1099 p++;
1100 buffer[strlen(buffer) - 1] = 0;
1102 while ((eol = strstr( p, "+AAoA" )))
1104 *eol = 0;
1105 while (*p && isspace(*p)) p++;
1106 if (*p++ == '#')
1108 while (*p && isspace(*p)) p++;
1109 if (!strncmp( p, "pragma", 6 )) parse_pragma_directive( source, p + 6 );
1111 p = eol + 5;
1113 while (*p && isspace(*p)) p++;
1114 if (*p++ != '#') return;
1115 while (*p && isspace(*p)) p++;
1116 if (!strncmp( p, "pragma", 6 )) parse_pragma_directive( source, p + 6 );
1117 return;
1122 static const struct
1124 const char *ext;
1125 void (*parse)( struct file *file, FILE *f );
1126 } parse_functions[] =
1128 { ".c", parse_c_file },
1129 { ".h", parse_c_file },
1130 { ".inl", parse_c_file },
1131 { ".l", parse_c_file },
1132 { ".m", parse_c_file },
1133 { ".rh", parse_c_file },
1134 { ".x", parse_c_file },
1135 { ".y", parse_c_file },
1136 { ".idl", parse_idl_file },
1137 { ".rc", parse_rc_file },
1138 { ".in", parse_in_file },
1139 { ".sfd", parse_sfd_file }
1142 /*******************************************************************
1143 * load_file
1145 static struct file *load_file( const char *name )
1147 struct file *file;
1148 FILE *f;
1149 unsigned int i, hash = hash_filename( name );
1151 LIST_FOR_EACH_ENTRY( file, &files[hash], struct file, entry )
1152 if (!strcmp( name, file->name )) return file;
1154 if (!(f = fopen( name, "r" ))) return NULL;
1156 file = add_file( name );
1157 list_add_tail( &files[hash], &file->entry );
1158 input_file_name = file->name;
1159 input_line = 0;
1161 for (i = 0; i < sizeof(parse_functions) / sizeof(parse_functions[0]); i++)
1163 if (!strendswith( name, parse_functions[i].ext )) continue;
1164 parse_functions[i].parse( file, f );
1165 break;
1168 fclose( f );
1169 input_file_name = NULL;
1171 return file;
1175 /*******************************************************************
1176 * open_include_path_file
1178 * Open a file from a directory on the include path.
1180 static struct file *open_include_path_file( const struct makefile *make, const char *dir,
1181 const char *name, char **filename )
1183 char *src_path = concat_paths( dir, name );
1184 struct file *ret = load_file( src_path );
1186 if (ret) *filename = src_path;
1187 return ret;
1191 /*******************************************************************
1192 * open_file_same_dir
1194 * Open a file in the same directory as the parent.
1196 static struct file *open_file_same_dir( const struct incl_file *parent, const char *name, char **filename )
1198 char *src_path = replace_filename( parent->file->name, name );
1199 struct file *ret = load_file( src_path );
1201 if (ret) *filename = replace_filename( parent->filename, name );
1202 return ret;
1206 /*******************************************************************
1207 * open_local_file
1209 * Open a file in the source directory of the makefile.
1211 static struct file *open_local_file( const struct makefile *make, const char *path, char **filename )
1213 char *src_path = src_dir_path( make, path );
1214 struct file *ret = load_file( src_path );
1216 /* if not found, try parent dir */
1217 if (!ret && make->parent_dir)
1219 free( src_path );
1220 path = strmake( "%s/%s", make->parent_dir, path );
1221 src_path = src_dir_path( make, path );
1222 ret = load_file( src_path );
1225 if (ret) *filename = src_path;
1226 return ret;
1230 /*******************************************************************
1231 * open_global_file
1233 * Open a file in the top-level source directory.
1235 static struct file *open_global_file( const struct makefile *make, const char *path, char **filename )
1237 char *src_path = root_src_dir_path( path );
1238 struct file *ret = load_file( src_path );
1240 if (ret) *filename = src_path;
1241 return ret;
1245 /*******************************************************************
1246 * open_global_header
1248 * Open a file in the global include source directory.
1250 static struct file *open_global_header( const struct makefile *make, const char *path, char **filename )
1252 if (!strncmp( path, "../", 3 )) return NULL;
1253 return open_global_file( make, strmake( "include/%s", path ), filename );
1257 /*******************************************************************
1258 * open_src_file
1260 static struct file *open_src_file( const struct makefile *make, struct incl_file *pFile )
1262 struct file *file = open_local_file( make, pFile->name, &pFile->filename );
1264 if (!file) fatal_perror( "open %s", pFile->name );
1265 return file;
1269 /*******************************************************************
1270 * find_importlib_module
1272 static struct makefile *find_importlib_module( const char *name )
1274 unsigned int i, len;
1276 for (i = 0; i < subdirs.count; i++)
1278 if (strncmp( submakes[i]->obj_dir, "dlls/", 5 )) continue;
1279 len = strlen(submakes[i]->obj_dir);
1280 if (strncmp( submakes[i]->obj_dir + 5, name, len - 5 )) continue;
1281 if (!name[len - 5] || !strcmp( name + len - 5, ".dll" )) return submakes[i];
1283 return NULL;
1287 /*******************************************************************
1288 * has_external_import
1290 static int has_external_import( const struct makefile *make )
1292 unsigned int i;
1294 for (i = 0; i < make->imports.count; i++)
1296 if (!strncmp( make->imports.str[i], "-l", 2 ))
1297 return 1;
1299 return 0;
1303 /*******************************************************************
1304 * open_include_file
1306 static struct file *open_include_file( const struct makefile *make, struct incl_file *pFile )
1308 struct file *file = NULL;
1309 char *filename;
1310 unsigned int i, len;
1312 errno = ENOENT;
1314 /* check for generated bison header */
1316 if (strendswith( pFile->name, ".tab.h" ) &&
1317 (file = open_local_file( make, replace_extension( pFile->name, ".tab.h", ".y" ), &filename )))
1319 pFile->sourcename = filename;
1320 pFile->filename = obj_dir_path( make, pFile->name );
1321 return file;
1324 /* check for corresponding idl file in source dir */
1326 if (strendswith( pFile->name, ".h" ) &&
1327 (file = open_local_file( make, replace_extension( pFile->name, ".h", ".idl" ), &filename )))
1329 pFile->sourcename = filename;
1330 pFile->filename = obj_dir_path( make, pFile->name );
1331 return file;
1334 /* check for extra targets */
1335 if (strarray_exists( &make->extra_targets, pFile->name ))
1337 pFile->sourcename = src_dir_path( make, pFile->name );
1338 pFile->filename = obj_dir_path( make, pFile->name );
1339 return NULL;
1342 /* now try in source dir */
1343 if ((file = open_local_file( make, pFile->name, &pFile->filename ))) return file;
1345 /* check for global importlib (module dependency) */
1347 if (pFile->type == INCL_IMPORTLIB && find_importlib_module( pFile->name ))
1349 pFile->filename = pFile->name;
1350 return NULL;
1353 /* check for corresponding idl file in global includes */
1355 if (strendswith( pFile->name, ".h" ) &&
1356 (file = open_global_header( make, replace_extension( pFile->name, ".h", ".idl" ), &filename )))
1358 pFile->sourcename = filename;
1359 pFile->filename = strmake( "include/%s", pFile->name );
1360 return file;
1363 /* check for corresponding .in file in global includes (for config.h.in) */
1365 if (strendswith( pFile->name, ".h" ) &&
1366 (file = open_global_header( make, replace_extension( pFile->name, ".h", ".h.in" ), &filename )))
1368 pFile->sourcename = filename;
1369 pFile->filename = strmake( "include/%s", pFile->name );
1370 return file;
1373 /* check for corresponding .x file in global includes */
1375 if (strendswith( pFile->name, "tmpl.h" ) &&
1376 (file = open_global_header( make, replace_extension( pFile->name, ".h", ".x" ), &filename )))
1378 pFile->sourcename = filename;
1379 pFile->filename = strmake( "include/%s", pFile->name );
1380 return file;
1383 /* check in global includes source dir */
1385 if ((file = open_global_header( make, pFile->name, &pFile->filename ))) return file;
1387 /* check in global msvcrt includes */
1388 if (pFile->use_msvcrt &&
1389 (file = open_global_header( make, strmake( "msvcrt/%s", pFile->name ), &pFile->filename )))
1390 return file;
1392 /* now search in include paths */
1393 for (i = 0; i < make->include_paths.count; i++)
1395 const char *dir = make->include_paths.str[i];
1397 if (root_src_dir)
1399 len = strlen( root_src_dir );
1400 if (!strncmp( dir, root_src_dir, len ) && (!dir[len] || dir[len] == '/'))
1402 while (dir[len] == '/') len++;
1403 file = open_global_file( make, concat_paths( dir + len, pFile->name ), &pFile->filename );
1406 else
1408 if (*dir == '/') continue;
1409 file = open_include_path_file( make, dir, pFile->name, &pFile->filename );
1411 if (!file) continue;
1412 pFile->is_external = 1;
1413 return file;
1416 if (pFile->type == INCL_SYSTEM && pFile->use_msvcrt &&
1417 !make->extlib && !pFile->included_by->is_external)
1419 if (!strcmp( pFile->name, "stdarg.h" )) return NULL;
1420 if (!strcmp( pFile->name, "x86intrin.h" )) return NULL;
1421 if (has_external_import( make )) return NULL;
1422 fprintf( stderr, "%s:%d: error: system header %s cannot be used with msvcrt\n",
1423 pFile->included_by->file->name, pFile->included_line, pFile->name );
1424 exit(1);
1427 if (pFile->type == INCL_SYSTEM) return NULL; /* ignore system files we cannot find */
1429 /* try in src file directory */
1430 if ((file = open_file_same_dir( pFile->included_by, pFile->name, &pFile->filename )))
1432 pFile->is_external = pFile->included_by->is_external;
1433 return file;
1436 if (make->extlib) return NULL; /* ignore missing files in external libs */
1438 fprintf( stderr, "%s:%d: error: ", pFile->included_by->file->name, pFile->included_line );
1439 perror( pFile->name );
1440 pFile = pFile->included_by;
1441 while (pFile && pFile->included_by)
1443 const char *parent = pFile->included_by->sourcename;
1444 if (!parent) parent = pFile->included_by->file->name;
1445 fprintf( stderr, "%s:%d: note: %s was first included here\n",
1446 parent, pFile->included_line, pFile->name );
1447 pFile = pFile->included_by;
1449 exit(1);
1453 /*******************************************************************
1454 * add_all_includes
1456 static void add_all_includes( struct makefile *make, struct incl_file *parent, struct file *file )
1458 unsigned int i;
1460 for (i = 0; i < file->deps_count; i++)
1462 switch (file->deps[i].type)
1464 case INCL_NORMAL:
1465 case INCL_IMPORT:
1466 add_include( make, parent, file->deps[i].name, file->deps[i].line, INCL_NORMAL );
1467 break;
1468 case INCL_IMPORTLIB:
1469 add_include( make, parent, file->deps[i].name, file->deps[i].line, INCL_IMPORTLIB );
1470 break;
1471 case INCL_SYSTEM:
1472 add_include( make, parent, file->deps[i].name, file->deps[i].line, INCL_SYSTEM );
1473 break;
1474 case INCL_CPP_QUOTE:
1475 case INCL_CPP_QUOTE_SYSTEM:
1476 break;
1482 /*******************************************************************
1483 * parse_file
1485 static void parse_file( struct makefile *make, struct incl_file *source, int src )
1487 struct file *file = src ? open_src_file( make, source ) : open_include_file( make, source );
1489 if (!file) return;
1491 source->file = file;
1492 source->files_count = 0;
1493 source->files_size = file->deps_count;
1494 source->files = xmalloc( source->files_size * sizeof(*source->files) );
1495 if (file->flags & FLAG_C_UNIX) source->use_msvcrt = 0;
1496 else if (file->flags & FLAG_C_IMPLIB) source->use_msvcrt = 1;
1498 if (source->sourcename)
1500 if (strendswith( source->sourcename, ".idl" ))
1502 unsigned int i;
1504 /* generated .h file always includes these */
1505 add_include( make, source, "rpc.h", 0, INCL_NORMAL );
1506 add_include( make, source, "rpcndr.h", 0, INCL_NORMAL );
1507 for (i = 0; i < file->deps_count; i++)
1509 switch (file->deps[i].type)
1511 case INCL_IMPORT:
1512 if (strendswith( file->deps[i].name, ".idl" ))
1513 add_include( make, source, replace_extension( file->deps[i].name, ".idl", ".h" ),
1514 file->deps[i].line, INCL_NORMAL );
1515 else
1516 add_include( make, source, file->deps[i].name, file->deps[i].line, INCL_NORMAL );
1517 break;
1518 case INCL_CPP_QUOTE:
1519 add_include( make, source, file->deps[i].name, file->deps[i].line, INCL_NORMAL );
1520 break;
1521 case INCL_CPP_QUOTE_SYSTEM:
1522 add_include( make, source, file->deps[i].name, file->deps[i].line, INCL_SYSTEM );
1523 break;
1524 case INCL_NORMAL:
1525 case INCL_SYSTEM:
1526 case INCL_IMPORTLIB:
1527 break;
1530 return;
1532 if (strendswith( source->sourcename, ".y" ))
1533 return; /* generated .tab.h doesn't include anything */
1536 add_all_includes( make, source, file );
1540 /*******************************************************************
1541 * add_src_file
1543 * Add a source file to the list.
1545 static struct incl_file *add_src_file( struct makefile *make, const char *name )
1547 struct incl_file *file;
1549 if ((file = find_src_file( make, name ))) return file; /* we already have it */
1550 file = xmalloc( sizeof(*file) );
1551 memset( file, 0, sizeof(*file) );
1552 file->name = xstrdup(name);
1553 file->use_msvcrt = make->use_msvcrt;
1554 file->is_external = !!make->extlib;
1555 list_add_tail( &make->sources, &file->entry );
1556 parse_file( make, file, 1 );
1557 return file;
1561 /*******************************************************************
1562 * open_input_makefile
1564 static FILE *open_input_makefile( const struct makefile *make )
1566 FILE *ret;
1568 if (make->obj_dir)
1569 input_file_name = root_src_dir_path( obj_dir_path( make, "Makefile.in" ));
1570 else
1571 input_file_name = output_makefile_name; /* always use output name for main Makefile */
1573 input_line = 0;
1574 if (!(ret = fopen( input_file_name, "r" ))) fatal_perror( "open" );
1575 return ret;
1579 /*******************************************************************
1580 * get_make_variable
1582 static const char *get_make_variable( const struct makefile *make, const char *name )
1584 const char *ret;
1586 if ((ret = strarray_get_value( &cmdline_vars, name ))) return ret;
1587 if ((ret = strarray_get_value( &make->vars, name ))) return ret;
1588 if (top_makefile && (ret = strarray_get_value( &top_makefile->vars, name ))) return ret;
1589 return NULL;
1593 /*******************************************************************
1594 * get_expanded_make_variable
1596 static char *get_expanded_make_variable( const struct makefile *make, const char *name )
1598 const char *var;
1599 char *p, *end, *expand, *tmp;
1601 var = get_make_variable( make, name );
1602 if (!var) return NULL;
1604 p = expand = xstrdup( var );
1605 while ((p = strchr( p, '$' )))
1607 if (p[1] == '(')
1609 if (!(end = strchr( p + 2, ')' ))) fatal_error( "syntax error in '%s'\n", expand );
1610 *end++ = 0;
1611 if (strchr( p + 2, ':' )) fatal_error( "pattern replacement not supported for '%s'\n", p + 2 );
1612 var = get_make_variable( make, p + 2 );
1613 tmp = replace_substr( expand, p, end - p, var ? var : "" );
1614 /* switch to the new string */
1615 p = tmp + (p - expand);
1616 free( expand );
1617 expand = tmp;
1619 else if (p[1] == '{') /* don't expand ${} variables */
1621 if (!(end = strchr( p + 2, '}' ))) fatal_error( "syntax error in '%s'\n", expand );
1622 p = end + 1;
1624 else if (p[1] == '$')
1626 p += 2;
1628 else fatal_error( "syntax error in '%s'\n", expand );
1631 /* consider empty variables undefined */
1632 p = expand;
1633 while (*p && isspace(*p)) p++;
1634 if (*p) return expand;
1635 free( expand );
1636 return NULL;
1640 /*******************************************************************
1641 * get_expanded_make_var_array
1643 static struct strarray get_expanded_make_var_array( const struct makefile *make, const char *name )
1645 struct strarray ret = empty_strarray;
1646 char *value, *token;
1648 if ((value = get_expanded_make_variable( make, name )))
1649 for (token = strtok( value, " \t" ); token; token = strtok( NULL, " \t" ))
1650 strarray_add( &ret, token );
1651 return ret;
1655 /*******************************************************************
1656 * get_expanded_file_local_var
1658 static struct strarray get_expanded_file_local_var( const struct makefile *make, const char *file,
1659 const char *name )
1661 char *p, *var = strmake( "%s_%s", file, name );
1663 for (p = var; *p; p++) if (!isalnum( *p )) *p = '_';
1664 return get_expanded_make_var_array( make, var );
1668 /*******************************************************************
1669 * set_make_variable
1671 static int set_make_variable( struct strarray *array, const char *assignment )
1673 char *p, *name;
1675 p = name = xstrdup( assignment );
1676 while (isalnum(*p) || *p == '_') p++;
1677 if (name == p) return 0; /* not a variable */
1678 if (isspace(*p))
1680 *p++ = 0;
1681 while (isspace(*p)) p++;
1683 if (*p != '=') return 0; /* not an assignment */
1684 *p++ = 0;
1685 while (isspace(*p)) p++;
1687 strarray_set_value( array, name, p );
1688 return 1;
1692 /*******************************************************************
1693 * parse_makefile
1695 static struct makefile *parse_makefile( const char *path )
1697 char *buffer;
1698 FILE *file;
1699 struct makefile *make = xmalloc( sizeof(*make) );
1701 memset( make, 0, sizeof(*make) );
1702 make->obj_dir = path;
1703 if (root_src_dir) make->src_dir = root_src_dir_path( make->obj_dir );
1705 file = open_input_makefile( make );
1706 while ((buffer = get_line( file )))
1708 if (!strncmp( buffer, separator, strlen(separator) )) break;
1709 if (*buffer == '\t') continue; /* command */
1710 while (isspace( *buffer )) buffer++;
1711 if (*buffer == '#') continue; /* comment */
1712 set_make_variable( &make->vars, buffer );
1714 fclose( file );
1715 input_file_name = NULL;
1716 return make;
1720 /*******************************************************************
1721 * add_generated_sources
1723 static void add_generated_sources( struct makefile *make )
1725 unsigned int i;
1726 struct incl_file *source, *next, *file;
1727 struct strarray objs = get_expanded_make_var_array( make, "EXTRA_OBJS" );
1729 LIST_FOR_EACH_ENTRY_SAFE( source, next, &make->sources, struct incl_file, entry )
1731 if (source->file->flags & FLAG_IDL_CLIENT)
1733 file = add_generated_source( make, replace_extension( source->name, ".idl", "_c.c" ), NULL );
1734 add_dependency( file->file, replace_extension( source->name, ".idl", ".h" ), INCL_NORMAL );
1735 add_all_includes( make, file, file->file );
1737 if (source->file->flags & FLAG_IDL_SERVER)
1739 file = add_generated_source( make, replace_extension( source->name, ".idl", "_s.c" ), NULL );
1740 add_dependency( file->file, "wine/exception.h", INCL_NORMAL );
1741 add_dependency( file->file, replace_extension( source->name, ".idl", ".h" ), INCL_NORMAL );
1742 add_all_includes( make, file, file->file );
1744 if (source->file->flags & FLAG_IDL_IDENT)
1746 file = add_generated_source( make, replace_extension( source->name, ".idl", "_i.c" ), NULL );
1747 add_dependency( file->file, "rpc.h", INCL_NORMAL );
1748 add_dependency( file->file, "rpcndr.h", INCL_NORMAL );
1749 add_dependency( file->file, "guiddef.h", INCL_NORMAL );
1750 add_all_includes( make, file, file->file );
1752 if (source->file->flags & FLAG_IDL_PROXY)
1754 file = add_generated_source( make, "dlldata.o", "dlldata.c" );
1755 add_dependency( file->file, "objbase.h", INCL_NORMAL );
1756 add_dependency( file->file, "rpcproxy.h", INCL_NORMAL );
1757 add_all_includes( make, file, file->file );
1758 file = add_generated_source( make, replace_extension( source->name, ".idl", "_p.c" ), NULL );
1759 add_dependency( file->file, "objbase.h", INCL_NORMAL );
1760 add_dependency( file->file, "rpcproxy.h", INCL_NORMAL );
1761 add_dependency( file->file, "wine/exception.h", INCL_NORMAL );
1762 add_dependency( file->file, replace_extension( source->name, ".idl", ".h" ), INCL_NORMAL );
1763 add_all_includes( make, file, file->file );
1765 if (source->file->flags & FLAG_IDL_TYPELIB)
1767 add_generated_source( make, replace_extension( source->name, ".idl", "_l.res" ), NULL );
1769 if (source->file->flags & FLAG_IDL_REGTYPELIB)
1771 add_generated_source( make, replace_extension( source->name, ".idl", "_t.res" ), NULL );
1773 if (source->file->flags & FLAG_IDL_REGISTER)
1775 add_generated_source( make, replace_extension( source->name, ".idl", "_r.res" ), NULL );
1777 if (source->file->flags & FLAG_IDL_HEADER)
1779 add_generated_source( make, replace_extension( source->name, ".idl", ".h" ), NULL );
1781 if (!source->file->flags && strendswith( source->name, ".idl" ))
1783 add_generated_source( make, replace_extension( source->name, ".idl", ".h" ), NULL );
1785 if (strendswith( source->name, ".x" ))
1787 add_generated_source( make, replace_extension( source->name, ".x", ".h" ), NULL );
1789 if (strendswith( source->name, ".y" ))
1791 file = add_generated_source( make, replace_extension( source->name, ".y", ".tab.c" ), NULL );
1792 /* steal the includes list from the source file */
1793 file->files_count = source->files_count;
1794 file->files_size = source->files_size;
1795 file->files = source->files;
1796 source->files_count = source->files_size = 0;
1797 source->files = NULL;
1799 if (strendswith( source->name, ".l" ))
1801 file = add_generated_source( make, replace_extension( source->name, ".l", ".yy.c" ), NULL );
1802 /* steal the includes list from the source file */
1803 file->files_count = source->files_count;
1804 file->files_size = source->files_size;
1805 file->files = source->files;
1806 source->files_count = source->files_size = 0;
1807 source->files = NULL;
1809 if (source->file->flags & FLAG_C_IMPLIB)
1811 if (!make->staticimplib && make->importlib && *dll_ext)
1812 make->staticimplib = strmake( "lib%s.a", make->importlib );
1814 if (strendswith( source->name, ".po" ))
1816 if (!make->disabled)
1817 strarray_add_uniq( &linguas, replace_extension( source->name, ".po", "" ));
1819 if (strendswith( source->name, ".spec" ))
1821 char *obj = replace_extension( source->name, ".spec", "" );
1822 strarray_addall_uniq( &make->extra_imports,
1823 get_expanded_file_local_var( make, obj, "IMPORTS" ));
1826 if (make->testdll)
1828 file = add_generated_source( make, "testlist.o", "testlist.c" );
1829 add_dependency( file->file, "wine/test.h", INCL_NORMAL );
1830 add_all_includes( make, file, file->file );
1832 for (i = 0; i < objs.count; i++)
1834 /* default to .c for unknown extra object files */
1835 if (strendswith( objs.str[i], ".o" ))
1837 file = add_generated_source( make, objs.str[i], replace_extension( objs.str[i], ".o", ".c" ));
1838 file->file->flags |= FLAG_C_UNIX;
1839 file->use_msvcrt = 0;
1841 else if (strendswith( objs.str[i], ".res" ))
1842 add_generated_source( make, replace_extension( objs.str[i], ".res", ".rc" ), NULL );
1843 else
1844 add_generated_source( make, objs.str[i], NULL );
1849 /*******************************************************************
1850 * create_dir
1852 static void create_dir( const char *dir )
1854 char *p, *path;
1856 p = path = xstrdup( dir );
1857 while ((p = strchr( p, '/' )))
1859 *p = 0;
1860 if (mkdir( path, 0755 ) == -1 && errno != EEXIST) fatal_perror( "mkdir %s", path );
1861 *p++ = '/';
1862 while (*p == '/') p++;
1864 if (mkdir( path, 0755 ) == -1 && errno != EEXIST) fatal_perror( "mkdir %s", path );
1865 free( path );
1869 /*******************************************************************
1870 * create_file_directories
1872 * Create the base directories of all the files.
1874 static void create_file_directories( const struct makefile *make, struct strarray files )
1876 struct strarray subdirs = empty_strarray;
1877 unsigned int i;
1878 char *dir;
1880 for (i = 0; i < files.count; i++)
1882 if (!strchr( files.str[i], '/' )) continue;
1883 dir = obj_dir_path( make, files.str[i] );
1884 *strrchr( dir, '/' ) = 0;
1885 strarray_add_uniq( &subdirs, dir );
1888 for (i = 0; i < subdirs.count; i++) create_dir( subdirs.str[i] );
1892 /*******************************************************************
1893 * output_filenames_obj_dir
1895 static void output_filenames_obj_dir( const struct makefile *make, struct strarray array )
1897 unsigned int i;
1899 for (i = 0; i < array.count; i++) output_filename( obj_dir_path( make, array.str[i] ));
1903 /*******************************************************************
1904 * get_dependencies
1906 static void get_dependencies( struct incl_file *file, struct incl_file *source )
1908 unsigned int i;
1910 if (!file->filename) return;
1912 if (file != source)
1914 if (file->owner == source) return; /* already processed */
1915 if (file->type == INCL_IMPORTLIB)
1917 if (!(source->file->flags & (FLAG_IDL_TYPELIB | FLAG_IDL_REGTYPELIB)))
1918 return; /* library is imported only when building a typelib */
1919 strarray_add( &source->importlibdeps, file->filename );
1921 else strarray_add( &source->dependencies, file->filename );
1922 file->owner = source;
1924 /* sanity checks */
1925 if (!strcmp( file->filename, "include/config.h" ) &&
1926 file != source->files[0] && !source->is_external)
1928 input_file_name = source->filename;
1929 input_line = 0;
1930 for (i = 0; i < source->file->deps_count; i++)
1932 if (!strcmp( source->file->deps[i].name, file->name ))
1933 input_line = source->file->deps[i].line;
1935 fatal_error( "%s must be included before other headers\n", file->name );
1939 for (i = 0; i < file->files_count; i++) get_dependencies( file->files[i], source );
1943 /*******************************************************************
1944 * get_local_dependencies
1946 * Get the local dependencies of a given target.
1948 static struct strarray get_local_dependencies( const struct makefile *make, const char *name,
1949 struct strarray targets )
1951 unsigned int i;
1952 struct strarray deps = get_expanded_file_local_var( make, name, "DEPS" );
1954 for (i = 0; i < deps.count; i++)
1956 if (strarray_exists( &targets, deps.str[i] ))
1957 deps.str[i] = obj_dir_path( make, deps.str[i] );
1958 else
1959 deps.str[i] = src_dir_path( make, deps.str[i] );
1961 return deps;
1965 /*******************************************************************
1966 * get_static_lib
1968 * Check if makefile builds the named static library and return the full lib path.
1970 static const char *get_static_lib( const struct makefile *make, const char *name )
1972 if (!make->staticlib) return NULL;
1973 if (make->disabled) return NULL;
1974 if (strncmp( make->staticlib, "lib", 3 )) return NULL;
1975 if (strncmp( make->staticlib + 3, name, strlen(name) )) return NULL;
1976 if (strcmp( make->staticlib + 3 + strlen(name), ".a" )) return NULL;
1977 return obj_dir_path( make, make->staticlib );
1981 /*******************************************************************
1982 * get_native_unix_lib
1984 static const char *get_native_unix_lib( const struct makefile *make, const char *name )
1986 if (!make->native_unix_lib) return NULL;
1987 if (strncmp( make->unixlib, name, strlen(name) )) return NULL;
1988 if (make->unixlib[strlen(name)] != '.') return NULL;
1989 return obj_dir_path( make, make->unixlib );
1993 /*******************************************************************
1994 * get_parent_makefile
1996 static struct makefile *get_parent_makefile( struct makefile *make )
1998 char *dir, *p;
1999 int i;
2001 if (!make->obj_dir) return NULL;
2002 dir = xstrdup( make->obj_dir );
2003 if (!(p = strrchr( dir, '/' ))) return NULL;
2004 *p = 0;
2005 for (i = 0; i < subdirs.count; i++)
2006 if (!strcmp( submakes[i]->obj_dir, dir )) return submakes[i];
2007 return NULL;
2011 /*******************************************************************
2012 * needs_delay_lib
2014 static int needs_delay_lib( const struct makefile *make )
2016 if (delay_load_flag) return 0;
2017 if (*dll_ext && !crosstarget) return 0;
2018 if (!make->importlib) return 0;
2019 return strarray_exists( &delay_import_libs, make->importlib );
2023 /*******************************************************************
2024 * add_unix_libraries
2026 static struct strarray add_unix_libraries( const struct makefile *make, struct strarray *deps )
2028 struct strarray ret = empty_strarray;
2029 struct strarray all_libs = empty_strarray;
2030 unsigned int i, j;
2032 if (strcmp( make->unixlib, "ntdll.so" )) strarray_add( &all_libs, "-lntdll" );
2033 strarray_addall( &all_libs, get_expanded_make_var_array( make, "EXTRALIBS" ));
2035 for (i = 0; i < all_libs.count; i++)
2037 const char *lib = NULL;
2039 if (!strncmp( all_libs.str[i], "-l", 2 ))
2041 for (j = 0; j < subdirs.count; j++)
2043 if (make == submakes[j]) continue;
2044 if ((lib = get_native_unix_lib( submakes[j], all_libs.str[i] + 2 ))) break;
2047 if (lib)
2049 strarray_add( deps, lib );
2050 strarray_add( &ret, lib );
2052 else strarray_add( &ret, all_libs.str[i] );
2055 strarray_addall( &ret, libs );
2056 return ret;
2060 /*******************************************************************
2061 * is_crt_module
2063 static int is_crt_module( const char *file )
2065 return !strncmp( file, "msvcr", 5 ) || !strncmp( file, "ucrt", 4 ) || !strcmp( file, "crtdll.dll" );
2069 /*******************************************************************
2070 * get_default_crt
2072 static const char *get_default_crt( const struct makefile *make )
2074 if (!make->use_msvcrt) return NULL;
2075 if (make->module && is_crt_module( make->module )) return NULL; /* don't add crt import to crt dlls */
2076 return !make->testdll && (!make->staticlib || make->extlib) ? "ucrtbase" : "msvcrt";
2080 /*******************************************************************
2081 * get_crt_define
2083 static const char *get_crt_define( const struct makefile *make )
2085 const char *crt_dll = NULL;
2086 unsigned int i, version = 0;
2088 for (i = 0; i < make->imports.count; i++)
2090 if (!is_crt_module( make->imports.str[i] )) continue;
2091 if (crt_dll) fatal_error( "More than one C runtime DLL imported: %s and %s\n",
2092 crt_dll, make->imports.str[i] );
2093 crt_dll = make->imports.str[i];
2096 if (!crt_dll)
2098 if (strarray_exists( &make->extradllflags, "-nodefaultlibs" )) return "-D_MSVCR_VER=0";
2099 if (!(crt_dll = get_default_crt( make ))) crt_dll = make->module;
2101 if (!strncmp( crt_dll, "ucrt", 4 )) return "-D_UCRT";
2102 sscanf( crt_dll, "msvcr%u", &version );
2103 return strmake( "-D_MSVCR_VER=%u", version );
2107 /*******************************************************************
2108 * add_default_imports
2110 static struct strarray add_default_imports( const struct makefile *make, struct strarray imports )
2112 struct strarray ret = empty_strarray;
2113 const char *crt_dll = get_default_crt( make );
2114 unsigned int i;
2116 for (i = 0; i < imports.count; i++)
2118 if (is_crt_module( imports.str[i] )) crt_dll = imports.str[i];
2119 else strarray_add( &ret, imports.str[i] );
2122 strarray_add( &ret, "winecrt0" );
2123 if (crt_dll) strarray_add( &ret, crt_dll );
2125 if (make->is_win16 && (!make->importlib || strcmp( make->importlib, "kernel" )))
2126 strarray_add( &ret, "kernel" );
2128 strarray_add( &ret, "kernel32" );
2129 strarray_add( &ret, "ntdll" );
2130 return ret;
2134 /*******************************************************************
2135 * add_import_libs
2137 static struct strarray add_import_libs( const struct makefile *make, struct strarray *deps,
2138 struct strarray imports, int delay, int is_cross )
2140 struct strarray ret = empty_strarray;
2141 unsigned int i, j;
2143 for (i = 0; i < imports.count; i++)
2145 const char *name = imports.str[i];
2146 const char *lib = NULL;
2148 if (name[0] == '-')
2150 switch (name[1])
2152 case 'L': strarray_add( &ret, name ); continue;
2153 case 'l': name += 2; break;
2154 default: continue;
2157 else name = get_base_name( name );
2159 for (j = 0; j < subdirs.count; j++)
2161 if (submakes[j]->importlib && !strcmp( submakes[j]->importlib, name ))
2162 lib = obj_dir_path( submakes[j], strmake( "lib%s.a", name ));
2163 else
2164 lib = get_static_lib( submakes[j], name );
2165 if (lib) break;
2168 if (lib)
2170 const char *ext = NULL;
2172 if (delay && !delay_load_flag && (is_cross || !*dll_ext)) ext = ".delay.a";
2173 else if (is_cross) ext = ".cross.a";
2174 if (ext) lib = replace_extension( lib, ".a", ext );
2175 strarray_add_uniq( deps, lib );
2176 strarray_add( &ret, lib );
2178 else strarray_add( &ret, strmake( "-l%s", name ));
2180 return ret;
2184 /*******************************************************************
2185 * add_install_rule
2187 static void add_install_rule( struct makefile *make, const char *target,
2188 const char *file, const char *dest )
2190 if (strarray_exists( &make->install_lib, target ) ||
2191 strarray_exists( &top_install_lib, make->obj_dir ) ||
2192 strarray_exists( &top_install_lib, obj_dir_path( make, target )))
2194 strarray_add( &make->install_rules[INSTALL_LIB], file );
2195 strarray_add( &make->install_rules[INSTALL_LIB], dest );
2197 else if (strarray_exists( &make->install_dev, target ) ||
2198 strarray_exists( &top_install_dev, make->obj_dir ) ||
2199 strarray_exists( &top_install_dev, obj_dir_path( make, target )))
2201 strarray_add( &make->install_rules[INSTALL_DEV], file );
2202 strarray_add( &make->install_rules[INSTALL_DEV], dest );
2207 /*******************************************************************
2208 * get_include_install_path
2210 * Determine the installation path for a given include file.
2212 static const char *get_include_install_path( const char *name )
2214 if (!strncmp( name, "wine/", 5 )) return name + 5;
2215 if (!strncmp( name, "msvcrt/", 7 )) return name;
2216 return strmake( "windows/%s", name );
2220 /*******************************************************************
2221 * get_shared_library_name
2223 * Determine possible names for a shared library with a version number.
2225 static struct strarray get_shared_lib_names( const char *libname )
2227 struct strarray ret = empty_strarray;
2228 const char *ext, *p;
2229 char *name, *first, *second;
2230 size_t len = 0;
2232 strarray_add( &ret, libname );
2234 for (p = libname; (p = strchr( p, '.' )); p++)
2235 if ((len = strspn( p + 1, "0123456789." ))) break;
2237 if (!len) return ret;
2238 ext = p + 1 + len;
2239 if (*ext && ext[-1] == '.') ext--;
2241 /* keep only the first group of digits */
2242 name = xstrdup( libname );
2243 first = name + (p - libname);
2244 if ((second = strchr( first + 1, '.' )))
2246 strcpy( second, ext );
2247 strarray_add( &ret, xstrdup( name ));
2249 return ret;
2253 /*******************************************************************
2254 * get_source_defines
2256 static struct strarray get_source_defines( struct makefile *make, struct incl_file *source,
2257 const char *obj )
2259 unsigned int i;
2260 struct strarray ret = empty_strarray;
2262 strarray_addall( &ret, make->include_args );
2263 if (source->use_msvcrt)
2264 strarray_add( &ret, strmake( "-I%s", root_src_dir_path( "include/msvcrt" )));
2265 for (i = 0; i < make->include_paths.count; i++)
2266 strarray_add( &ret, strmake( "-I%s", make->include_paths.str[i] ));
2267 strarray_addall( &ret, make->define_args );
2268 strarray_addall( &ret, get_expanded_file_local_var( make, obj, "EXTRADEFS" ));
2269 if ((source->file->flags & FLAG_C_UNIX) && *dll_ext) strarray_add( &ret, "-DWINE_UNIX_LIB" );
2270 return ret;
2274 /*******************************************************************
2275 * remove_warning_flags
2277 static struct strarray remove_warning_flags( struct strarray flags )
2279 unsigned int i;
2280 struct strarray ret = empty_strarray;
2282 for (i = 0; i < flags.count; i++)
2283 if (strncmp( flags.str[i], "-W", 2 ) || !strncmp( flags.str[i], "-Wno-", 5 ))
2284 strarray_add( &ret, flags.str[i] );
2285 return ret;
2289 /*******************************************************************
2290 * get_debug_file
2292 static const char *get_debug_file( struct makefile *make, const char *name )
2294 const char *debug_file = NULL;
2295 if (!make->is_cross || !crossdebug) return NULL;
2296 if (!strcmp( crossdebug, "pdb" )) debug_file = strmake( "%s.pdb", get_base_name( name ));
2297 else if(!strncmp( crossdebug, "split", 5 )) debug_file = strmake( "%s.debug", name );
2298 if (debug_file) strarray_add( &make->debug_files, debug_file );
2299 return debug_file;
2303 /*******************************************************************
2304 * cmd_prefix
2306 static const char *cmd_prefix( const char *cmd )
2308 if (!silent_rules) return "";
2309 return strmake( "$(quiet_%s)", cmd );
2313 /*******************************************************************
2314 * output_winegcc_command
2316 static void output_winegcc_command( struct makefile *make, int is_cross )
2318 output( "\t%s%s -o $@", cmd_prefix( "CCLD" ), tools_path( make, "winegcc" ));
2319 output_filename( "--wine-objdir ." );
2320 if (tools_dir)
2322 output_filename( "--winebuild" );
2323 output_filename( tools_path( make, "winebuild" ));
2325 if (is_cross)
2327 output_filename( "-b" );
2328 output_filename( crosstarget );
2329 output_filename( "--lib-suffix=.cross.a" );
2331 else
2333 output_filenames( target_flags );
2334 output_filenames( lddll_flags );
2339 /*******************************************************************
2340 * output_symlink_rule
2342 * Output a rule to create a symlink.
2344 static void output_symlink_rule( const char *src_name, const char *link_name, int create_dir )
2346 const char *name = strrchr( link_name, '/' );
2347 char *dir = NULL;
2349 if (name)
2351 dir = xstrdup( link_name );
2352 dir[name - link_name] = 0;
2355 output( "\t%s", cmd_prefix( "LN" ));
2356 if (create_dir && dir && *dir) output( "%s -d %s && ", root_src_dir_path( "tools/install-sh" ), dir );
2357 output( "rm -f %s && ", link_name );
2359 /* dest path with a directory needs special handling if ln -s isn't supported */
2360 if (dir && strcmp( ln_s, "ln -s" ))
2361 output( "cd %s && %s %s %s\n", *dir ? dir : "/", ln_s, src_name, name + 1 );
2362 else
2363 output( "%s %s %s\n", ln_s, src_name, link_name );
2365 free( dir );
2369 /*******************************************************************
2370 * output_srcdir_symlink
2372 * Output rule to create a symlink back to the source directory, for source files
2373 * that are needed at run-time.
2375 static void output_srcdir_symlink( struct makefile *make, const char *obj )
2377 char *src_file, *dst_file, *src_name;
2379 if (!make->src_dir) return;
2380 src_file = src_dir_path( make, obj );
2381 dst_file = obj_dir_path( make, obj );
2382 output( "%s: %s\n", dst_file, src_file );
2384 src_name = src_file;
2385 if (src_name[0] != '/' && make->obj_dir)
2386 src_name = concat_paths( get_relative_path( make->obj_dir, "" ), src_name );
2388 output_symlink_rule( src_name, dst_file, 0 );
2389 strarray_add( &make->all_targets, obj );
2393 /*******************************************************************
2394 * output_install_commands
2396 static void output_install_commands( struct makefile *make, struct strarray files )
2398 unsigned int i;
2399 char *install_sh = root_src_dir_path( "tools/install-sh" );
2401 for (i = 0; i < files.count; i += 2)
2403 const char *file = files.str[i];
2404 const char *dest = strmake( "$(DESTDIR)%s", files.str[i + 1] + 1 );
2406 switch (*files.str[i + 1])
2408 case 'c': /* cross-compiled program */
2409 output( "\tSTRIPPROG=%s-strip %s -m 644 $(INSTALL_PROGRAM_FLAGS) %s %s\n",
2410 crosstarget, install_sh, obj_dir_path( make, file ), dest );
2411 output( "\t%s --builtin %s\n", tools_path( make, "winebuild" ), dest );
2412 break;
2413 case 'd': /* data file */
2414 output( "\t%s -m 644 $(INSTALL_DATA_FLAGS) %s %s\n",
2415 install_sh, obj_dir_path( make, file ), dest );
2416 break;
2417 case 'D': /* data file in source dir */
2418 output( "\t%s -m 644 $(INSTALL_DATA_FLAGS) %s %s\n",
2419 install_sh, src_dir_path( make, file ), dest );
2420 break;
2421 case 'p': /* program file */
2422 output( "\tSTRIPPROG=\"$(STRIP)\" %s $(INSTALL_PROGRAM_FLAGS) %s %s\n",
2423 install_sh, obj_dir_path( make, file ), dest );
2424 break;
2425 case 's': /* script */
2426 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s %s\n",
2427 install_sh, obj_dir_path( make, file ), dest );
2428 break;
2429 case 'S': /* script in source dir */
2430 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s %s\n",
2431 install_sh, src_dir_path( make, file ), dest );
2432 break;
2433 case 't': /* script in tools dir */
2434 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s %s\n",
2435 install_sh, tools_dir_path( make, files.str[i] ), dest );
2436 break;
2437 case 'y': /* symlink */
2438 output_symlink_rule( files.str[i], dest, 1 );
2439 break;
2440 default:
2441 assert(0);
2443 strarray_add( &make->uninstall_files, dest );
2448 /*******************************************************************
2449 * output_install_rules
2451 * Rules are stored as a (file,dest) pair of values.
2452 * The first char of dest indicates the type of install.
2454 static void output_install_rules( struct makefile *make, enum install_rules rules, const char *target )
2456 unsigned int i;
2457 struct strarray files = make->install_rules[rules];
2458 struct strarray targets = empty_strarray;
2460 if (!files.count) return;
2462 for (i = 0; i < files.count; i += 2)
2464 const char *file = files.str[i];
2465 switch (*files.str[i + 1])
2467 case 'c': /* cross-compiled program */
2468 case 'd': /* data file */
2469 case 'p': /* program file */
2470 case 's': /* script */
2471 strarray_add_uniq( &targets, obj_dir_path( make, file ));
2472 break;
2473 case 't': /* script in tools dir */
2474 strarray_add_uniq( &targets, tools_dir_path( make, file ));
2475 break;
2479 output( "%s %s::", obj_dir_path( make, "install" ), obj_dir_path( make, target ));
2480 output_filenames( targets );
2481 output( "\n" );
2482 output_install_commands( make, files );
2483 strarray_add_uniq( &make->phony_targets, obj_dir_path( make, "install" ));
2484 strarray_add_uniq( &make->phony_targets, obj_dir_path( make, target ));
2488 static int cmp_string_length( const char **a, const char **b )
2490 int paths_a = 0, paths_b = 0;
2491 const char *p;
2493 for (p = *a; *p; p++) if (*p == '/') paths_a++;
2494 for (p = *b; *p; p++) if (*p == '/') paths_b++;
2495 if (paths_b != paths_a) return paths_b - paths_a;
2496 return strcmp( *a, *b );
2499 /*******************************************************************
2500 * output_uninstall_rules
2502 static void output_uninstall_rules( struct makefile *make )
2504 static const char *dirs_order[] =
2505 { "$(includedir)", "$(mandir)", "$(fontdir)", "$(nlsdir)", "$(datadir)", "$(dlldir)" };
2507 struct strarray uninstall_dirs = empty_strarray;
2508 unsigned int i, j;
2510 if (!make->uninstall_files.count) return;
2511 output( "uninstall::\n" );
2512 output_rm_filenames( make->uninstall_files );
2513 strarray_add_uniq( &make->phony_targets, "uninstall" );
2515 if (!subdirs.count) return;
2516 for (i = 0; i < make->uninstall_files.count; i++)
2518 char *dir = xstrdup( make->uninstall_files.str[i] );
2519 while (strchr( dir, '/' ))
2521 *strrchr( dir, '/' ) = 0;
2522 strarray_add_uniq( &uninstall_dirs, xstrdup(dir) );
2525 strarray_qsort( &uninstall_dirs, cmp_string_length );
2526 output( "\t-rmdir" );
2527 for (i = 0; i < sizeof(dirs_order)/sizeof(dirs_order[0]); i++)
2529 for (j = 0; j < uninstall_dirs.count; j++)
2531 if (!uninstall_dirs.str[j]) continue;
2532 if (strncmp( uninstall_dirs.str[j] + strlen("$(DESTDIR)"), dirs_order[i], strlen(dirs_order[i]) ))
2533 continue;
2534 output_filename( uninstall_dirs.str[j] );
2535 uninstall_dirs.str[j] = NULL;
2538 for (j = 0; j < uninstall_dirs.count; j++)
2539 if (uninstall_dirs.str[j]) output_filename( uninstall_dirs.str[j] );
2540 output( "\n" );
2544 /*******************************************************************
2545 * output_po_files
2547 static void output_po_files( const struct makefile *make )
2549 const char *po_dir = src_dir_path( make, "po" );
2550 unsigned int i;
2552 if (linguas.count)
2554 for (i = 0; i < linguas.count; i++)
2555 output_filename( strmake( "%s/%s.po", po_dir, linguas.str[i] ));
2556 output( ": %s/wine.pot\n", po_dir );
2557 output( "\t%smsgmerge --previous -q $@ %s/wine.pot | msgattrib --no-obsolete -o $@.new && mv $@.new $@\n",
2558 cmd_prefix( "MSG" ), po_dir );
2559 output( "po:" );
2560 for (i = 0; i < linguas.count; i++)
2561 output_filename( strmake( "%s/%s.po", po_dir, linguas.str[i] ));
2562 output( "\n" );
2564 output( "%s/wine.pot:", po_dir );
2565 output_filenames( make->pot_files );
2566 output( "\n" );
2567 output( "\t%smsgcat -o $@", cmd_prefix( "MSG" ));
2568 output_filenames( make->pot_files );
2569 output( "\n" );
2573 /*******************************************************************
2574 * output_source_y
2576 static void output_source_y( struct makefile *make, struct incl_file *source, const char *obj )
2578 /* add source file dependency for parallel makes */
2579 char *header = strmake( "%s.tab.h", obj );
2581 if (find_include_file( make, header ))
2583 output( "%s: %s\n", obj_dir_path( make, header ), source->filename );
2584 output( "\t%s%s -p %s_ -o %s.tab.c -d %s\n",
2585 cmd_prefix( "BISON" ), bison, obj, obj_dir_path( make, obj ), source->filename );
2586 output( "%s.tab.c: %s %s\n", obj_dir_path( make, obj ),
2587 source->filename, obj_dir_path( make, header ));
2588 strarray_add( &make->clean_files, header );
2590 else output( "%s.tab.c: %s\n", obj_dir_path( make, obj ), source->filename );
2592 output( "\t%s%s -p %s_ -o $@ %s\n", cmd_prefix( "BISON" ), bison, obj, source->filename );
2596 /*******************************************************************
2597 * output_source_l
2599 static void output_source_l( struct makefile *make, struct incl_file *source, const char *obj )
2601 output( "%s.yy.c: %s\n", obj_dir_path( make, obj ), source->filename );
2602 output( "\t%s%s -o$@ %s\n", cmd_prefix( "FLEX" ), flex, source->filename );
2606 /*******************************************************************
2607 * output_source_h
2609 static void output_source_h( struct makefile *make, struct incl_file *source, const char *obj )
2611 if (source->file->flags & FLAG_GENERATED)
2612 strarray_add( &make->all_targets, source->name );
2613 else
2614 add_install_rule( make, source->name, source->name,
2615 strmake( "D$(includedir)/wine/%s", get_include_install_path( source->name ) ));
2619 /*******************************************************************
2620 * output_source_rc
2622 static void output_source_rc( struct makefile *make, struct incl_file *source, const char *obj )
2624 struct strarray defines = get_source_defines( make, source, obj );
2625 const char *po_dir = NULL;
2626 unsigned int i;
2628 if (source->file->flags & FLAG_GENERATED) strarray_add( &make->clean_files, source->name );
2629 if (linguas.count && (source->file->flags & FLAG_RC_PO)) po_dir = "po";
2630 strarray_add( &make->res_files, strmake( "%s.res", obj ));
2631 if (source->file->flags & FLAG_RC_PO)
2633 strarray_add( &make->pot_files, strmake( "%s.pot", obj ));
2634 output( "%s.pot ", obj_dir_path( make, obj ) );
2636 output( "%s.res: %s", obj_dir_path( make, obj ), source->filename );
2637 output_filename( tools_path( make, "wrc" ));
2638 output_filenames( source->dependencies );
2639 output( "\n" );
2640 output( "\t%s%s -u -o $@", cmd_prefix( "WRC" ), tools_path( make, "wrc" ) );
2641 if (make->is_win16) output_filename( "-m16" );
2642 output_filename( "--nostdinc" );
2643 if (po_dir) output_filename( strmake( "--po-dir=%s", po_dir ));
2644 output_filenames( defines );
2645 output_filename( source->filename );
2646 output( "\n" );
2647 if (po_dir)
2649 output( "%s.res:", obj_dir_path( make, obj ));
2650 for (i = 0; i < linguas.count; i++)
2651 output_filename( strmake( "%s/%s.mo", po_dir, linguas.str[i] ));
2652 output( "\n" );
2657 /*******************************************************************
2658 * output_source_mc
2660 static void output_source_mc( struct makefile *make, struct incl_file *source, const char *obj )
2662 unsigned int i;
2663 char *obj_path = obj_dir_path( make, obj );
2665 strarray_add( &make->res_files, strmake( "%s.res", obj ));
2666 strarray_add( &make->pot_files, strmake( "%s.pot", obj ));
2667 output( "%s.pot %s.res: %s", obj_path, obj_path, source->filename );
2668 output_filename( tools_path( make, "wmc" ));
2669 output_filenames( source->dependencies );
2670 output( "\n" );
2671 output( "\t%s%s -u -o $@ %s", cmd_prefix( "WMC" ), tools_path( make, "wmc" ), source->filename );
2672 if (linguas.count)
2674 output_filename( "--po-dir=po" );
2675 output( "\n" );
2676 output( "%s.res:", obj_dir_path( make, obj ));
2677 for (i = 0; i < linguas.count; i++)
2678 output_filename( strmake( "po/%s.mo", linguas.str[i] ));
2680 output( "\n" );
2684 /*******************************************************************
2685 * output_source_res
2687 static void output_source_res( struct makefile *make, struct incl_file *source, const char *obj )
2689 strarray_add( &make->res_files, source->name );
2693 /*******************************************************************
2694 * output_source_idl
2696 static void output_source_idl( struct makefile *make, struct incl_file *source, const char *obj )
2698 struct strarray defines = get_source_defines( make, source, obj );
2699 struct strarray targets = empty_strarray;
2700 char *dest;
2701 unsigned int i;
2703 if (!source->file->flags) source->file->flags |= FLAG_IDL_HEADER | FLAG_INSTALL;
2704 if (find_include_file( make, strmake( "%s.h", obj ))) source->file->flags |= FLAG_IDL_HEADER;
2706 for (i = 0; i < sizeof(idl_outputs) / sizeof(idl_outputs[0]); i++)
2708 if (!(source->file->flags & idl_outputs[i].flag)) continue;
2709 dest = strmake( "%s%s", obj, idl_outputs[i].ext );
2710 if (!find_src_file( make, dest )) strarray_add( &make->clean_files, dest );
2711 strarray_add( &targets, dest );
2713 if (source->file->flags & FLAG_IDL_PROXY) strarray_add( &make->dlldata_files, source->name );
2714 if (source->file->flags & FLAG_INSTALL)
2716 add_install_rule( make, source->name, xstrdup( source->name ),
2717 strmake( "D$(includedir)/wine/%s.idl", get_include_install_path( obj ) ));
2718 if (source->file->flags & FLAG_IDL_HEADER)
2719 add_install_rule( make, source->name, strmake( "%s.h", obj ),
2720 strmake( "d$(includedir)/wine/%s.h", get_include_install_path( obj ) ));
2722 if (!targets.count) return;
2724 output_filenames_obj_dir( make, targets );
2725 output( ": %s\n", tools_path( make, "widl" ));
2726 output( "\t%s%s -o $@", cmd_prefix( "WIDL" ), tools_path( make, "widl" ) );
2727 output_filenames( target_flags );
2728 output_filename( "--nostdinc" );
2729 output_filename( "-Ldlls/\\*" );
2730 output_filenames( defines );
2731 output_filenames( get_expanded_make_var_array( make, "EXTRAIDLFLAGS" ));
2732 output_filenames( get_expanded_file_local_var( make, obj, "EXTRAIDLFLAGS" ));
2733 output_filename( source->filename );
2734 output( "\n" );
2735 output_filenames_obj_dir( make, targets );
2736 output( ": %s", source->filename );
2737 output_filenames( source->dependencies );
2738 for (i = 0; i < source->importlibdeps.count; i++)
2740 struct makefile *submake = find_importlib_module( source->importlibdeps.str[i] );
2741 output_filename( obj_dir_path( submake, submake->module ));
2743 output( "\n" );
2747 /*******************************************************************
2748 * output_source_x
2750 static void output_source_x( struct makefile *make, struct incl_file *source, const char *obj )
2752 output( "%s.h: %s%s %s\n", obj_dir_path( make, obj ),
2753 tools_dir_path( make, "make_xftmpl" ), tools_ext, source->filename );
2754 output( "\t%s%s%s -H -o $@ %s\n", cmd_prefix( "GEN" ),
2755 tools_dir_path( make, "make_xftmpl" ), tools_ext, source->filename );
2756 if (source->file->flags & FLAG_INSTALL)
2758 add_install_rule( make, source->name, source->name,
2759 strmake( "D$(includedir)/wine/%s", get_include_install_path( source->name ) ));
2760 add_install_rule( make, source->name, strmake( "%s.h", obj ),
2761 strmake( "d$(includedir)/wine/%s.h", get_include_install_path( obj ) ));
2766 /*******************************************************************
2767 * output_source_sfd
2769 static void output_source_sfd( struct makefile *make, struct incl_file *source, const char *obj )
2771 unsigned int i;
2772 char *ttf_obj = strmake( "%s.ttf", obj );
2773 char *ttf_file = src_dir_path( make, ttf_obj );
2775 if (fontforge && !make->src_dir)
2777 output( "%s: %s\n", ttf_file, source->filename );
2778 output( "\t%s%s -script %s %s $@\n", cmd_prefix( "GEN" ),
2779 fontforge, root_src_dir_path( "fonts/genttf.ff" ), source->filename );
2780 if (!(source->file->flags & FLAG_SFD_FONTS)) strarray_add( &make->font_files, ttf_obj );
2782 if (source->file->flags & FLAG_INSTALL)
2784 add_install_rule( make, source->name, ttf_obj, strmake( "D$(fontdir)/%s", ttf_obj ));
2785 output_srcdir_symlink( make, ttf_obj );
2788 if (source->file->flags & FLAG_SFD_FONTS)
2790 struct strarray *array = source->file->args;
2792 for (i = 0; i < array->count; i++)
2794 char *font = strtok( xstrdup(array->str[i]), " \t" );
2795 char *args = strtok( NULL, "" );
2797 strarray_add( &make->all_targets, xstrdup( font ));
2798 output( "%s: %s %s\n", obj_dir_path( make, font ),
2799 tools_path( make, "sfnt2fon" ), ttf_file );
2800 output( "\t%s%s -q -o $@ %s %s\n", cmd_prefix( "GEN" ),
2801 tools_path( make, "sfnt2fon" ), ttf_file, args );
2802 add_install_rule( make, source->name, xstrdup(font), strmake( "d$(fontdir)/%s", font ));
2808 /*******************************************************************
2809 * output_source_svg
2811 static void output_source_svg( struct makefile *make, struct incl_file *source, const char *obj )
2813 static const char * const images[] = { "bmp", "cur", "ico", NULL };
2814 unsigned int i;
2816 if (convert && rsvg && icotool && !make->src_dir)
2818 for (i = 0; images[i]; i++)
2819 if (find_include_file( make, strmake( "%s.%s", obj, images[i] ))) break;
2821 if (images[i])
2823 output( "%s.%s: %s\n", src_dir_path( make, obj ), images[i], source->filename );
2824 output( "\t%sCONVERT=\"%s\" ICOTOOL=\"%s\" RSVG=\"%s\" %s %s $@\n",
2825 cmd_prefix( "GEN" ), convert, icotool, rsvg,
2826 root_src_dir_path( "tools/buildimage" ), source->filename );
2832 /*******************************************************************
2833 * output_source_nls
2835 static void output_source_nls( struct makefile *make, struct incl_file *source, const char *obj )
2837 add_install_rule( make, source->name, source->name,
2838 strmake( "D$(nlsdir)/%s", source->name ));
2839 output_srcdir_symlink( make, strmake( "%s.nls", obj ));
2843 /*******************************************************************
2844 * output_source_desktop
2846 static void output_source_desktop( struct makefile *make, struct incl_file *source, const char *obj )
2848 add_install_rule( make, source->name, source->name,
2849 strmake( "D$(datadir)/applications/%s", source->name ));
2853 /*******************************************************************
2854 * output_source_po
2856 static void output_source_po( struct makefile *make, struct incl_file *source, const char *obj )
2858 output( "%s.mo: %s\n", obj_dir_path( make, obj ), source->filename );
2859 output( "\t%s%s -o $@ %s\n", cmd_prefix( "MSG" ), msgfmt, source->filename );
2860 strarray_add( &make->all_targets, strmake( "%s.mo", obj ));
2864 /*******************************************************************
2865 * output_source_in
2867 static void output_source_in( struct makefile *make, struct incl_file *source, const char *obj )
2869 unsigned int i;
2871 if (strendswith( obj, ".man" ) && source->file->args)
2873 struct strarray symlinks;
2874 char *dir, *dest = replace_extension( obj, ".man", "" );
2875 char *lang = strchr( dest, '.' );
2876 char *section = source->file->args;
2877 if (lang)
2879 *lang++ = 0;
2880 dir = strmake( "$(mandir)/%s/man%s", lang, section );
2882 else dir = strmake( "$(mandir)/man%s", section );
2883 add_install_rule( make, dest, xstrdup(obj), strmake( "d%s/%s.%s", dir, dest, section ));
2884 symlinks = get_expanded_file_local_var( make, dest, "SYMLINKS" );
2885 for (i = 0; i < symlinks.count; i++)
2886 add_install_rule( make, symlinks.str[i], strmake( "%s.%s", dest, section ),
2887 strmake( "y%s/%s.%s", dir, symlinks.str[i], section ));
2888 free( dest );
2889 free( dir );
2891 strarray_add( &make->in_files, xstrdup(obj) );
2892 strarray_add( &make->all_targets, xstrdup(obj) );
2893 output( "%s: %s\n", obj_dir_path( make, obj ), source->filename );
2894 output( "\t%s%s %s >$@ || (rm -f $@ && false)\n", cmd_prefix( "SED" ), sed_cmd, source->filename );
2895 output( "%s:", obj_dir_path( make, obj ));
2896 output_filenames( source->dependencies );
2897 output( "\n" );
2898 add_install_rule( make, obj, xstrdup( obj ), strmake( "d$(datadir)/wine/%s", obj ));
2902 /*******************************************************************
2903 * output_source_spec
2905 static void output_source_spec( struct makefile *make, struct incl_file *source, const char *obj )
2907 struct strarray imports = get_expanded_file_local_var( make, obj, "IMPORTS" );
2908 struct strarray dll_flags = get_expanded_file_local_var( make, obj, "EXTRADLLFLAGS" );
2909 struct strarray all_libs, dep_libs = empty_strarray;
2910 char *dll_name, *obj_name, *output_file;
2911 const char *debug_file;
2913 if (!imports.count) imports = make->imports;
2914 if (!dll_flags.count) dll_flags = make->extradllflags;
2915 if (!strarray_exists( &dll_flags, "-nodefaultlibs" )) imports = add_default_imports( make, imports );
2917 all_libs = add_import_libs( make, &dep_libs, imports, 0, make->is_cross );
2918 dll_name = strmake( "%s.dll%s", obj, make->is_cross ? "" : dll_ext );
2919 obj_name = strmake( "%s%s", obj_dir_path( make, obj ), make->is_cross ? ".cross.o" : ".o" );
2920 output_file = obj_dir_path( make, dll_name );
2922 strarray_add( &make->clean_files, dll_name );
2923 strarray_add( &make->res_files, strmake( "%s.res", obj ));
2924 output( "%s.res:", obj_dir_path( make, obj ));
2925 output_filename( obj_dir_path( make, dll_name ));
2926 output_filename( tools_path( make, "wrc" ));
2927 output( "\n" );
2928 output( "\t%secho \"%s.dll TESTDLL \\\"%s\\\"\" | %s -u -o $@\n", cmd_prefix( "WRC" ), obj, output_file,
2929 tools_path( make, "wrc" ));
2931 output( "%s:", output_file);
2932 output_filename( source->filename );
2933 output_filename( obj_name );
2934 output_filenames( dep_libs );
2935 output_filename( tools_path( make, "winebuild" ));
2936 output_filename( tools_path( make, "winegcc" ));
2937 output( "\n" );
2938 output_winegcc_command( make, make->is_cross );
2939 output_filename( "-s" );
2940 output_filenames( dll_flags );
2941 output_filename( "-shared" );
2942 output_filename( source->filename );
2943 output_filename( obj_name );
2944 if ((debug_file = get_debug_file( make, dll_name )))
2945 output_filename( strmake( "-Wl,--debug-file,%s", obj_dir_path( make, debug_file )));
2946 output_filenames( all_libs );
2947 output_filename( make->is_cross ? "$(CROSSLDFLAGS)" : "$(LDFLAGS)" );
2948 output( "\n" );
2952 /*******************************************************************
2953 * output_source_default
2955 static void output_source_default( struct makefile *make, struct incl_file *source, const char *obj )
2957 struct strarray defines = get_source_defines( make, source, obj );
2958 int is_dll_src = (make->testdll &&
2959 strendswith( source->name, ".c" ) &&
2960 find_src_file( make, replace_extension( source->name, ".c", ".spec" )));
2961 int need_cross = (crosstarget &&
2962 !(source->file->flags & FLAG_C_UNIX) &&
2963 (make->is_cross || make->staticlib ||
2964 (source->file->flags & FLAG_C_IMPLIB)));
2965 int need_obj = ((*dll_ext || !(source->file->flags & FLAG_C_UNIX)) &&
2966 (!need_cross ||
2967 (source->file->flags & FLAG_C_IMPLIB) ||
2968 (make->staticlib && !make->extlib)));
2970 if ((source->file->flags & FLAG_GENERATED) &&
2971 (!make->testdll || !strendswith( source->filename, "testlist.c" )))
2972 strarray_add( &make->clean_files, source->basename );
2974 if (need_obj)
2976 if ((source->file->flags & FLAG_C_UNIX) && *dll_ext)
2977 strarray_add( &make->unixobj_files, strmake( "%s.o", obj ));
2978 else if (source->file->flags & FLAG_C_IMPLIB)
2979 strarray_add( &make->implib_files, strmake( "%s.o", obj ));
2980 else if (!is_dll_src)
2981 strarray_add( &make->object_files, strmake( "%s.o", obj ));
2982 else
2983 strarray_add( &make->clean_files, strmake( "%s.o", obj ));
2984 output( "%s.o: %s\n", obj_dir_path( make, obj ), source->filename );
2985 output( "\t%s$(CC) -c -o $@ %s", cmd_prefix( "CC" ), source->filename );
2986 output_filenames( defines );
2987 if (make->sharedlib || (source->file->flags & FLAG_C_UNIX))
2989 output_filenames( unix_dllflags );
2991 else if (make->module || make->testdll)
2993 output_filenames( dll_flags );
2994 if (source->use_msvcrt) output_filenames( msvcrt_flags );
2995 if (!*dll_ext && make->module && is_crt_module( make->module ))
2996 output_filename( "-fno-builtin" );
2998 output_filenames( make->extlib ? extra_cflags_extlib : extra_cflags );
2999 output_filenames( cpp_flags );
3000 output_filename( "$(CFLAGS)" );
3001 output( "\n" );
3003 if (need_cross)
3005 if (source->file->flags & FLAG_C_IMPLIB)
3006 strarray_add( &make->crossimplib_files, strmake( "%s.cross.o", obj ));
3007 else if (!is_dll_src)
3008 strarray_add( &make->crossobj_files, strmake( "%s.cross.o", obj ));
3009 else
3010 strarray_add( &make->clean_files, strmake( "%s.cross.o", obj ));
3011 output( "%s.cross.o: %s\n", obj_dir_path( make, obj ), source->filename );
3012 output( "\t%s$(CROSSCC) -c -o $@ %s", cmd_prefix( "CC" ), source->filename );
3013 output_filenames( defines );
3014 output_filenames( make->extlib ? extra_cross_cflags_extlib : extra_cross_cflags );
3015 if (make->module && is_crt_module( make->module ))
3016 output_filename( "-fno-builtin" );
3017 output_filenames( cpp_flags );
3018 output_filename( "$(CROSSCFLAGS)" );
3019 output( "\n" );
3021 if (make->testdll && !is_dll_src && strendswith( source->name, ".c" ) &&
3022 !(source->file->flags & FLAG_GENERATED))
3024 strarray_add( &make->test_files, obj );
3025 strarray_add( &make->ok_files, strmake( "%s.ok", obj ));
3026 output( "%s.ok:\n", obj_dir_path( make, obj ));
3027 output( "\t%s%s $(RUNTESTFLAGS) -T . -M %s -p %s%s %s && touch $@\n",
3028 cmd_prefix( "TEST" ),
3029 root_src_dir_path( "tools/runtest" ), make->testdll,
3030 obj_dir_path( make, replace_extension( make->testdll, ".dll", "_test.exe" )),
3031 make->is_cross ? "" : dll_ext, obj );
3033 if (need_obj) output_filename( strmake( "%s.o", obj_dir_path( make, obj )));
3034 if (need_cross) output_filename( strmake( "%s.cross.o", obj_dir_path( make, obj )));
3035 output( ":" );
3036 output_filenames( source->dependencies );
3037 output( "\n" );
3041 /* dispatch table to output rules for a single source file */
3042 static const struct
3044 const char *ext;
3045 void (*fn)( struct makefile *make, struct incl_file *source, const char *obj );
3046 } output_source_funcs[] =
3048 { "y", output_source_y },
3049 { "l", output_source_l },
3050 { "h", output_source_h },
3051 { "rh", output_source_h },
3052 { "inl", output_source_h },
3053 { "rc", output_source_rc },
3054 { "mc", output_source_mc },
3055 { "res", output_source_res },
3056 { "idl", output_source_idl },
3057 { "sfd", output_source_sfd },
3058 { "svg", output_source_svg },
3059 { "nls", output_source_nls },
3060 { "desktop", output_source_desktop },
3061 { "po", output_source_po },
3062 { "in", output_source_in },
3063 { "x", output_source_x },
3064 { "spec", output_source_spec },
3065 { NULL, output_source_default }
3069 /*******************************************************************
3070 * get_unix_lib_name
3072 static char *get_unix_lib_name( struct makefile *make )
3074 struct incl_file *source;
3076 if (!*dll_ext) return NULL;
3077 LIST_FOR_EACH_ENTRY( source, &make->sources, struct incl_file, entry )
3079 if (!(source->file->flags & FLAG_C_UNIX)) continue;
3080 return strmake( "%s%s", get_base_name( make->module ), dll_ext );
3082 return NULL;
3086 /*******************************************************************
3087 * output_module
3089 static void output_module( struct makefile *make )
3091 struct strarray all_libs = empty_strarray;
3092 struct strarray dep_libs = empty_strarray;
3093 struct strarray imports = make->imports;
3094 char *module_name = strmake( "%s%s", make->module, make->is_cross ? "" : dll_ext );
3095 const char *debug_file;
3096 const char *delay_load = delay_load_flag;
3097 char *spec_file = NULL;
3098 unsigned int i;
3100 if (!make->is_exe) spec_file = src_dir_path( make, replace_extension( make->module, ".dll", ".spec" ));
3101 if (!strarray_exists( &make->extradllflags, "-nodefaultlibs" ))
3102 imports = add_default_imports( make, imports );
3104 strarray_addall( &all_libs, add_import_libs( make, &dep_libs, make->delayimports, 1, make->is_cross ));
3105 strarray_addall( &all_libs, add_import_libs( make, &dep_libs, imports, 0, make->is_cross ));
3107 if (!make->use_msvcrt)
3109 strarray_addall( &all_libs, get_expanded_make_var_array( make, "EXTRALIBS" ));
3110 strarray_addall( &all_libs, libs );
3113 if (!make->is_cross && *dll_ext) delay_load = "-Wl,-delayload,";
3114 if (delay_load)
3116 for (i = 0; i < make->delayimports.count; i++)
3117 strarray_add( &all_libs, strmake( "%s%s%s", delay_load, make->delayimports.str[i],
3118 strchr( make->delayimports.str[i], '.' ) ? "" : ".dll" ));
3120 strarray_add( &make->all_targets, module_name );
3122 if (make->is_cross)
3123 add_install_rule( make, make->module, module_name, strmake( "c%s/%s", pe_dir, module_name ));
3124 else if (*dll_ext)
3125 add_install_rule( make, make->module, module_name, strmake( "p%s/%s", so_dir, module_name ));
3126 else
3127 add_install_rule( make, make->module, module_name,
3128 strmake( "p$(%s)/%s", spec_file ? "dlldir" : "bindir", module_name ));
3130 output( "%s:", obj_dir_path( make, module_name ));
3131 if (spec_file) output_filename( spec_file );
3132 output_filenames_obj_dir( make, make->is_cross ? make->crossobj_files : make->object_files );
3133 output_filenames_obj_dir( make, make->res_files );
3134 output_filenames( dep_libs );
3135 output_filename( tools_path( make, "winebuild" ));
3136 output_filename( tools_path( make, "winegcc" ));
3137 output( "\n" );
3138 output_winegcc_command( make, make->is_cross );
3139 if (make->is_cross) output_filename( "-Wl,--wine-builtin" );
3140 if (spec_file)
3142 output_filename( "-shared" );
3143 output_filename( spec_file );
3145 output_filenames( make->extradllflags );
3146 output_filenames_obj_dir( make, make->is_cross ? make->crossobj_files : make->object_files );
3147 output_filenames_obj_dir( make, make->res_files );
3148 debug_file = get_debug_file( make, make->module );
3149 if (debug_file) output_filename( strmake( "-Wl,--debug-file,%s", obj_dir_path( make, debug_file )));
3150 output_filenames( all_libs );
3151 output_filename( make->is_cross ? "$(CROSSLDFLAGS)" : "$(LDFLAGS)" );
3152 output( "\n" );
3154 if (*dll_ext && make->is_exe && !make->is_win16 && strendswith( make->module, ".exe" ))
3156 char *binary = replace_extension( make->module, ".exe", "" );
3157 add_install_rule( make, binary, "wineapploader", strmake( "t$(bindir)/%s", binary ));
3162 /*******************************************************************
3163 * output_fake_module
3165 static void output_fake_module( struct makefile *make )
3167 char *spec_file = NULL;
3169 if (!make->is_exe) spec_file = src_dir_path( make, replace_extension( make->module, ".dll", ".spec" ));
3171 strarray_add( &make->all_targets, make->module );
3172 add_install_rule( make, make->module, make->module, strmake( "d%s/%s", pe_dir, make->module ));
3174 output( "%s:", obj_dir_path( make, make->module ));
3175 if (spec_file) output_filename( spec_file );
3176 output_filenames_obj_dir( make, make->res_files );
3177 output_filename( tools_path( make, "winebuild" ));
3178 output_filename( tools_path( make, "winegcc" ));
3179 output( "\n" );
3180 output_winegcc_command( make, make->is_cross );
3181 output_filename( "-Wb,--fake-module" );
3182 if (spec_file)
3184 output_filename( "-shared" );
3185 output_filename( spec_file );
3187 output_filenames( make->extradllflags );
3188 output_filenames_obj_dir( make, make->res_files );
3189 output( "\n" );
3193 /*******************************************************************
3194 * output_import_lib
3196 static void output_import_lib( struct makefile *make )
3198 char *spec_file = src_dir_path( make, replace_extension( make->module, ".dll", ".spec" ));
3199 char *importlib_path = obj_dir_path( make, strmake( "lib%s", make->importlib ));
3201 strarray_add( &make->clean_files, strmake( "lib%s.a", make->importlib ));
3202 if (!*dll_ext && needs_delay_lib( make ))
3204 strarray_add( &make->clean_files, strmake( "lib%s.delay.a", make->importlib ));
3205 output( "%s.delay.a ", importlib_path );
3207 output( "%s.a: %s %s", importlib_path, tools_path( make, "winebuild" ), spec_file );
3208 output_filenames_obj_dir( make, make->implib_files );
3209 output( "\n" );
3210 output( "\t%s%s -w --implib -o $@", cmd_prefix( "BUILD" ), tools_path( make, "winebuild" ) );
3211 output_filenames( target_flags );
3212 if (make->is_win16) output_filename( "-m16" );
3213 output_filename( "--export" );
3214 output_filename( spec_file );
3215 output_filenames_obj_dir( make, make->implib_files );
3216 output( "\n" );
3217 add_install_rule( make, make->importlib,
3218 strmake( "lib%s.a", make->importlib ),
3219 strmake( "d%s/lib%s.a", so_dir, make->importlib ));
3221 if (crosstarget)
3223 strarray_add( &make->clean_files, strmake( "lib%s.cross.a", make->importlib ));
3224 output_filename( strmake( "%s.cross.a", importlib_path ));
3225 if (needs_delay_lib( make ))
3227 strarray_add( &make->clean_files, strmake( "lib%s.delay.a", make->importlib ));
3228 output_filename( strmake( "%s.delay.a", importlib_path ));
3230 output( ": %s %s", tools_path( make, "winebuild" ), spec_file );
3231 output_filenames_obj_dir( make, make->crossimplib_files );
3232 output( "\n" );
3233 output( "\t%s%s -b %s -w --implib -o $@", cmd_prefix( "BUILD" ),
3234 tools_path( make, "winebuild" ), crosstarget );
3235 if (make->is_win16) output_filename( "-m16" );
3236 output_filename( "--export" );
3237 output_filename( spec_file );
3238 output_filenames_obj_dir( make, make->crossimplib_files );
3239 output( "\n" );
3240 add_install_rule( make, make->importlib,
3241 strmake( "lib%s.cross.a", make->importlib ),
3242 strmake( "d%s/lib%s.a", pe_dir, make->importlib ));
3247 /*******************************************************************
3248 * output_unix_lib
3250 static void output_unix_lib( struct makefile *make )
3252 struct strarray unix_libs = empty_strarray;
3253 struct strarray unix_deps = empty_strarray;
3254 char *spec_file = src_dir_path( make, replace_extension( make->module, ".dll", ".spec" ));
3256 if (!make->native_unix_lib)
3258 struct strarray unix_imports = empty_strarray;
3260 strarray_add( &unix_imports, "ntdll" );
3261 strarray_add( &unix_deps, obj_dir_path( top_makefile, "dlls/ntdll/ntdll.so" ));
3262 strarray_add( &unix_imports, "winecrt0" );
3263 if (spec_file) strarray_add( &unix_deps, spec_file );
3265 strarray_addall( &unix_libs, add_import_libs( make, &unix_deps, unix_imports, 0, 0 ));
3266 strarray_addall( &unix_libs, get_expanded_make_var_array( make, "EXTRALIBS" ));
3267 strarray_addall( &unix_libs, libs );
3269 else unix_libs = add_unix_libraries( make, &unix_deps );
3271 strarray_add( &make->all_targets, make->unixlib );
3272 add_install_rule( make, make->module, make->unixlib, strmake( "p%s/%s", so_dir, make->unixlib ));
3273 output( "%s:", obj_dir_path( make, make->unixlib ));
3274 output_filenames_obj_dir( make, make->unixobj_files );
3275 output_filenames( unix_deps );
3277 if (make->native_unix_lib)
3279 output( "\n" );
3280 output( "\t%s$(CC) -o $@", cmd_prefix( "CCLD" ));
3281 output_filenames( get_expanded_make_var_array( make, "UNIXLDFLAGS" ));
3283 else
3285 output_filename( tools_path( make, "winebuild" ));
3286 output_filename( tools_path( make, "winegcc" ));
3287 output( "\n" );
3288 output_winegcc_command( make, 0 );
3289 output_filename( "-munix" );
3290 output_filename( "-shared" );
3291 if (spec_file) output_filename( spec_file );
3293 output_filenames_obj_dir( make, make->unixobj_files );
3294 output_filenames( unix_libs );
3295 output_filename( "$(LDFLAGS)" );
3296 output( "\n" );
3300 /*******************************************************************
3301 * output_static_lib
3303 static void output_static_lib( struct makefile *make )
3305 if (!crosstarget || !make->extlib)
3307 strarray_add( &make->clean_files, make->staticlib );
3308 output( "%s: %s", obj_dir_path( make, make->staticlib ), tools_path( make, "winebuild" ));
3309 output_filenames_obj_dir( make, make->object_files );
3310 output_filenames_obj_dir( make, make->unixobj_files );
3311 output( "\n" );
3312 output( "\t%s%s -w --staticlib -o $@", cmd_prefix( "BUILD" ), tools_path( make, "winebuild" ));
3313 output_filenames( target_flags );
3314 output_filenames_obj_dir( make, make->object_files );
3315 output_filenames_obj_dir( make, make->unixobj_files );
3316 output( "\n" );
3317 add_install_rule( make, make->staticlib, make->staticlib,
3318 strmake( "d%s/%s", so_dir, make->staticlib ));
3320 if (crosstarget)
3322 char *name = replace_extension( make->staticlib, ".a", ".cross.a" );
3324 strarray_add( &make->clean_files, name );
3325 output( "%s: %s", obj_dir_path( make, name ), tools_path( make, "winebuild" ));
3326 output_filenames_obj_dir( make, make->crossobj_files );
3327 output( "\n" );
3328 output( "\t%s%s -b %s -w --staticlib -o $@", cmd_prefix( "BUILD" ),
3329 tools_path( make, "winebuild" ), crosstarget );
3330 output_filenames_obj_dir( make, make->crossobj_files );
3331 output( "\n" );
3332 if (!make->extlib)
3333 add_install_rule( make, make->staticlib, name,
3334 strmake( "d%s/%s", pe_dir, make->staticlib ));
3339 /*******************************************************************
3340 * output_shared_lib
3342 static void output_shared_lib( struct makefile *make )
3344 unsigned int i;
3345 char *basename, *p;
3346 struct strarray names = get_shared_lib_names( make->sharedlib );
3347 struct strarray all_libs = empty_strarray;
3348 struct strarray dep_libs = empty_strarray;
3350 basename = xstrdup( make->sharedlib );
3351 if ((p = strchr( basename, '.' ))) *p = 0;
3353 strarray_addall( &dep_libs, get_local_dependencies( make, basename, make->in_files ));
3354 strarray_addall( &all_libs, get_expanded_file_local_var( make, basename, "LDFLAGS" ));
3355 strarray_addall( &all_libs, get_expanded_make_var_array( make, "EXTRALIBS" ));
3356 strarray_addall( &all_libs, libs );
3358 output( "%s:", obj_dir_path( make, make->sharedlib ));
3359 output_filenames_obj_dir( make, make->object_files );
3360 output_filenames( dep_libs );
3361 output( "\n" );
3362 output( "\t%s$(CC) -o $@", cmd_prefix( "CCLD" ));
3363 output_filenames_obj_dir( make, make->object_files );
3364 output_filenames( all_libs );
3365 output_filename( "$(LDFLAGS)" );
3366 output( "\n" );
3367 add_install_rule( make, make->sharedlib, make->sharedlib, strmake( "p%s/%s", so_dir, make->sharedlib ));
3368 for (i = 1; i < names.count; i++)
3370 output( "%s: %s\n", obj_dir_path( make, names.str[i] ), obj_dir_path( make, names.str[i-1] ));
3371 output_symlink_rule( names.str[i-1], obj_dir_path( make, names.str[i] ), 0 );
3372 add_install_rule( make, names.str[i], names.str[i-1], strmake( "y%s/%s", so_dir, names.str[i] ));
3374 strarray_addall( &make->all_targets, names );
3378 /*******************************************************************
3379 * output_test_module
3381 static void output_test_module( struct makefile *make )
3383 char *testmodule = replace_extension( make->testdll, ".dll", "_test.exe" );
3384 char *stripped = replace_extension( make->testdll, ".dll", "_test-stripped.exe" );
3385 char *testres = replace_extension( make->testdll, ".dll", "_test.res" );
3386 struct strarray dep_libs = empty_strarray;
3387 struct strarray all_libs = add_import_libs( make, &dep_libs, add_default_imports( make, make->imports ),
3388 0, make->is_cross );
3389 struct makefile *parent = get_parent_makefile( make );
3390 const char *ext = make->is_cross ? "" : dll_ext;
3391 const char *debug_file;
3392 char *output_file;
3394 strarray_add( &make->all_targets, strmake( "%s%s", testmodule, ext ));
3395 strarray_add( &make->clean_files, strmake( "%s%s", stripped, ext ));
3396 output_file = strmake( "%s%s", obj_dir_path( make, testmodule ), ext );
3397 output( "%s:\n", output_file );
3398 output_winegcc_command( make, make->is_cross );
3399 output_filenames( make->extradllflags );
3400 output_filenames_obj_dir( make, make->is_cross ? make->crossobj_files : make->object_files );
3401 output_filenames_obj_dir( make, make->res_files );
3402 if ((debug_file = get_debug_file( make, testmodule )))
3403 output_filename( strmake( "-Wl,--debug-file,%s", obj_dir_path( make, debug_file )));
3404 output_filenames( all_libs );
3405 output_filename( make->is_cross ? "$(CROSSLDFLAGS)" : "$(LDFLAGS)" );
3406 output( "\n" );
3407 output( "%s%s:\n", obj_dir_path( make, stripped ), ext );
3408 output_winegcc_command( make, make->is_cross );
3409 output_filename( "-s" );
3410 output_filename( strmake( "-Wb,-F,%s", testmodule ));
3411 output_filenames( make->extradllflags );
3412 output_filenames_obj_dir( make, make->is_cross ? make->crossobj_files : make->object_files );
3413 output_filenames_obj_dir( make, make->res_files );
3414 output_filenames( all_libs );
3415 output_filename( make->is_cross ? "$(CROSSLDFLAGS)" : "$(LDFLAGS)" );
3416 output( "\n" );
3417 output( "%s%s %s%s:", obj_dir_path( make, testmodule ), ext, obj_dir_path( make, stripped ), ext );
3418 output_filenames_obj_dir( make, make->is_cross ? make->crossobj_files : make->object_files );
3419 output_filenames_obj_dir( make, make->res_files );
3420 output_filenames( dep_libs );
3421 output_filename( tools_path( make, "winebuild" ));
3422 output_filename( tools_path( make, "winegcc" ));
3423 output( "\n" );
3425 output( "programs/winetest/%s: %s%s\n", testres, obj_dir_path( make, stripped ), ext );
3426 output( "\t%secho \"%s TESTRES \\\"%s%s\\\"\" | %s -u -o $@\n", cmd_prefix( "WRC" ),
3427 testmodule, obj_dir_path( make, stripped ), ext, tools_path( make, "wrc" ));
3429 output_filenames_obj_dir( make, make->ok_files );
3430 output( ": %s%s", obj_dir_path( make, testmodule ), ext );
3431 if (parent)
3433 output_filename( parent->is_cross ? obj_dir_path( parent, make->testdll )
3434 : strmake( "%s%s", obj_dir_path( parent, make->testdll ), dll_ext ));
3435 if (parent->unixlib) output_filename( obj_dir_path( parent, parent->unixlib ));
3437 output( "\n" );
3438 output( "%s %s:", obj_dir_path( make, "check" ), obj_dir_path( make, "test" ));
3439 if (!make->disabled && parent && !parent->disabled) output_filenames_obj_dir( make, make->ok_files );
3440 output( "\n" );
3441 strarray_add_uniq( &make->phony_targets, obj_dir_path( make, "check" ));
3442 strarray_add_uniq( &make->phony_targets, obj_dir_path( make, "test" ));
3443 output( "%s::\n", obj_dir_path( make, "testclean" ));
3444 output( "\trm -f" );
3445 output_filenames_obj_dir( make, make->ok_files );
3446 output( "\n" );
3447 strarray_addall( &make->clean_files, make->ok_files );
3448 strarray_add_uniq( &make->phony_targets, obj_dir_path( make, "testclean" ));
3452 /*******************************************************************
3453 * output_programs
3455 static void output_programs( struct makefile *make )
3457 unsigned int i, j;
3459 for (i = 0; i < make->programs.count; i++)
3461 char *program_installed = NULL;
3462 char *program = strmake( "%s%s", make->programs.str[i], exe_ext );
3463 struct strarray deps = get_local_dependencies( make, make->programs.str[i], make->in_files );
3464 struct strarray all_libs = get_expanded_file_local_var( make, make->programs.str[i], "LDFLAGS" );
3465 struct strarray objs = get_expanded_file_local_var( make, make->programs.str[i], "OBJS" );
3466 struct strarray symlinks = get_expanded_file_local_var( make, make->programs.str[i], "SYMLINKS" );
3468 if (!objs.count) objs = make->object_files;
3469 if (!strarray_exists( &all_libs, "-nodefaultlibs" ))
3471 strarray_addall( &all_libs, get_expanded_make_var_array( make, "EXTRALIBS" ));
3472 strarray_addall( &all_libs, libs );
3475 output( "%s:", obj_dir_path( make, program ) );
3476 output_filenames_obj_dir( make, objs );
3477 output_filenames( deps );
3478 output( "\n" );
3479 output( "\t%s$(CC) -o $@", cmd_prefix( "CC" ));
3480 output_filenames_obj_dir( make, objs );
3481 output_filenames( all_libs );
3482 output_filename( "$(LDFLAGS)" );
3483 output( "\n" );
3484 strarray_add( &make->all_targets, program );
3486 for (j = 0; j < symlinks.count; j++)
3488 output( "%s: %s\n", obj_dir_path( make, symlinks.str[j] ), obj_dir_path( make, program ));
3489 output_symlink_rule( program, obj_dir_path( make, symlinks.str[j] ), 0 );
3491 strarray_addall( &make->all_targets, symlinks );
3493 add_install_rule( make, program, program_installed ? program_installed : program,
3494 strmake( "p$(bindir)/%s", program ));
3495 for (j = 0; j < symlinks.count; j++)
3496 add_install_rule( make, symlinks.str[j], program,
3497 strmake( "y$(bindir)/%s%s", symlinks.str[j], exe_ext ));
3502 /*******************************************************************
3503 * output_subdirs
3505 static void output_subdirs( struct makefile *make )
3507 struct strarray all_targets = empty_strarray;
3508 struct strarray makefile_deps = empty_strarray;
3509 struct strarray clean_files = empty_strarray;
3510 struct strarray testclean_files = empty_strarray;
3511 struct strarray distclean_files = empty_strarray;
3512 struct strarray dependencies = empty_strarray;
3513 struct strarray install_lib_deps = empty_strarray;
3514 struct strarray install_dev_deps = empty_strarray;
3515 struct strarray tooldeps_deps = empty_strarray;
3516 struct strarray buildtest_deps = empty_strarray;
3517 unsigned int i;
3519 strarray_addall( &clean_files, make->clean_files );
3520 strarray_addall( &distclean_files, make->distclean_files );
3521 strarray_addall( &all_targets, make->all_targets );
3522 for (i = 0; i < subdirs.count; i++)
3524 strarray_add( &makefile_deps, src_dir_path( submakes[i], "Makefile.in" ));
3525 strarray_addall_uniq( &make->phony_targets, submakes[i]->phony_targets );
3526 strarray_addall_uniq( &make->uninstall_files, submakes[i]->uninstall_files );
3527 strarray_addall_uniq( &dependencies, submakes[i]->dependencies );
3528 strarray_addall_path( &clean_files, submakes[i]->obj_dir, submakes[i]->clean_files );
3529 strarray_addall_path( &distclean_files, submakes[i]->obj_dir, submakes[i]->distclean_files );
3530 strarray_addall_path( &testclean_files, submakes[i]->obj_dir, submakes[i]->ok_files );
3531 strarray_addall_path( &make->pot_files, submakes[i]->obj_dir, submakes[i]->pot_files );
3533 if (submakes[i]->disabled) continue;
3535 strarray_addall_path( &all_targets, submakes[i]->obj_dir, submakes[i]->all_targets );
3536 if (!strcmp( submakes[i]->obj_dir, "tools" ) || !strncmp( submakes[i]->obj_dir, "tools/", 6 ))
3537 strarray_add( &tooldeps_deps, obj_dir_path( submakes[i], "all" ));
3538 if (submakes[i]->testdll)
3539 strarray_add( &buildtest_deps, obj_dir_path( submakes[i], "all" ));
3540 if (submakes[i]->install_rules[INSTALL_LIB].count)
3541 strarray_add( &install_lib_deps, obj_dir_path( submakes[i], "install-lib" ));
3542 if (submakes[i]->install_rules[INSTALL_DEV].count)
3543 strarray_add( &install_dev_deps, obj_dir_path( submakes[i], "install-dev" ));
3545 strarray_addall( &dependencies, makefile_deps );
3546 output( "all:" );
3547 output_filenames( all_targets );
3548 output( "\n" );
3549 output( "Makefile:" );
3550 output_filenames( makefile_deps );
3551 output( "\n" );
3552 output_filenames( dependencies );
3553 output( ":\n" );
3554 if (install_lib_deps.count)
3556 output( "install install-lib::" );
3557 output_filenames( install_lib_deps );
3558 output( "\n" );
3559 strarray_add_uniq( &make->phony_targets, "install" );
3560 strarray_add_uniq( &make->phony_targets, "install-lib" );
3562 if (install_dev_deps.count)
3564 output( "install install-dev::" );
3565 output_filenames( install_dev_deps );
3566 output( "\n" );
3567 strarray_add_uniq( &make->phony_targets, "install" );
3568 strarray_add_uniq( &make->phony_targets, "install-dev" );
3570 output_uninstall_rules( make );
3571 if (buildtest_deps.count)
3573 output( "buildtests:" );
3574 output_filenames( buildtest_deps );
3575 output( "\n" );
3576 strarray_add_uniq( &make->phony_targets, "buildtests" );
3578 output( "check test:" );
3579 output_filenames( testclean_files );
3580 output( "\n" );
3581 strarray_add_uniq( &make->phony_targets, "check" );
3582 strarray_add_uniq( &make->phony_targets, "test" );
3584 output( "clean::\n");
3585 output_rm_filenames( clean_files );
3586 output( "testclean::\n");
3587 output_rm_filenames( testclean_files );
3588 output( "distclean::\n");
3589 output_rm_filenames( distclean_files );
3590 strarray_add_uniq( &make->phony_targets, "distclean" );
3591 strarray_add_uniq( &make->phony_targets, "testclean" );
3593 if (tooldeps_deps.count)
3595 output( "__tooldeps__:" );
3596 output_filenames( tooldeps_deps );
3597 output( "\n" );
3598 strarray_add_uniq( &make->phony_targets, "__tooldeps__" );
3601 if (get_expanded_make_variable( make, "GETTEXTPO_LIBS" )) output_po_files( make );
3603 if (make->phony_targets.count)
3605 output( ".PHONY:" );
3606 output_filenames( make->phony_targets );
3607 output( "\n" );
3612 /*******************************************************************
3613 * output_sources
3615 static void output_sources( struct makefile *make )
3617 struct strarray all_targets = empty_strarray;
3618 struct incl_file *source;
3619 unsigned int i, j;
3621 strarray_add_uniq( &make->phony_targets, "all" );
3623 LIST_FOR_EACH_ENTRY( source, &make->sources, struct incl_file, entry )
3625 char *obj = xstrdup( source->name );
3626 char *ext = get_extension( obj );
3628 if (!ext) fatal_error( "unsupported file type %s\n", source->name );
3629 *ext++ = 0;
3631 for (j = 0; output_source_funcs[j].ext; j++)
3632 if (!strcmp( ext, output_source_funcs[j].ext )) break;
3634 output_source_funcs[j].fn( make, source, obj );
3635 strarray_addall_uniq( &make->dependencies, source->dependencies );
3638 /* special case for winetest: add resource files from other test dirs */
3639 if (make->obj_dir && !strcmp( make->obj_dir, "programs/winetest" ))
3641 struct strarray tests = enable_tests;
3642 if (!tests.count)
3643 for (i = 0; i < subdirs.count; i++)
3644 if (submakes[i]->testdll && !submakes[i]->disabled)
3645 strarray_add( &tests, submakes[i]->testdll );
3646 for (i = 0; i < tests.count; i++)
3647 strarray_add( &make->res_files, replace_extension( tests.str[i], ".dll", "_test.res" ));
3650 if (make->dlldata_files.count)
3652 output( "%s: %s %s\n", obj_dir_path( make, "dlldata.c" ),
3653 tools_path( make, "widl" ), src_dir_path( make, "Makefile.in" ));
3654 output( "\t%s%s --dlldata-only -o $@", cmd_prefix( "WIDL" ), tools_path( make, "widl" ));
3655 output_filenames( make->dlldata_files );
3656 output( "\n" );
3659 if (make->staticlib) output_static_lib( make );
3660 else if (make->module)
3662 output_module( make );
3663 if (*dll_ext && !make->is_cross) output_fake_module( make );
3664 if (make->unixlib) output_unix_lib( make );
3665 if (make->importlib) output_import_lib( make );
3667 else if (make->testdll) output_test_module( make );
3668 else if (make->sharedlib) output_shared_lib( make );
3669 else if (make->programs.count) output_programs( make );
3671 for (i = 0; i < make->scripts.count; i++)
3672 add_install_rule( make, make->scripts.str[i], make->scripts.str[i],
3673 strmake( "S$(bindir)/%s", make->scripts.str[i] ));
3675 for (i = 0; i < make->extra_targets.count; i++)
3676 if (strarray_exists( &make->dependencies, obj_dir_path( make, make->extra_targets.str[i] )))
3677 strarray_add( &make->clean_files, make->extra_targets.str[i] );
3678 else
3679 strarray_add( &make->all_targets, make->extra_targets.str[i] );
3681 if (!make->src_dir) strarray_add( &make->distclean_files, ".gitignore" );
3682 strarray_add( &make->distclean_files, "Makefile" );
3683 if (make->testdll) strarray_add( &make->distclean_files, "testlist.c" );
3685 if (!make->obj_dir)
3686 strarray_addall( &make->distclean_files, get_expanded_make_var_array( make, "CONFIGURE_TARGETS" ));
3687 else if (!strcmp( make->obj_dir, "po" ))
3688 strarray_add( &make->distclean_files, "LINGUAS" );
3690 strarray_addall( &make->clean_files, make->object_files );
3691 strarray_addall( &make->clean_files, make->crossobj_files );
3692 strarray_addall( &make->clean_files, make->implib_files );
3693 strarray_addall( &make->clean_files, make->crossimplib_files );
3694 strarray_addall( &make->clean_files, make->unixobj_files );
3695 strarray_addall( &make->clean_files, make->res_files );
3696 strarray_addall( &make->clean_files, make->pot_files );
3697 strarray_addall( &make->clean_files, make->debug_files );
3698 strarray_addall( &make->clean_files, make->all_targets );
3700 if (make == top_makefile)
3702 output_subdirs( make );
3703 return;
3706 strarray_addall( &all_targets, make->all_targets );
3707 strarray_addall( &all_targets, make->font_files );
3708 if (all_targets.count)
3710 output( "%s:", obj_dir_path( make, "all" ));
3711 output_filenames_obj_dir( make, all_targets );
3712 output( "\n" );
3713 strarray_add_uniq( &make->phony_targets, obj_dir_path( make, "all" ));
3715 output_install_rules( make, INSTALL_LIB, "install-lib" );
3716 output_install_rules( make, INSTALL_DEV, "install-dev" );
3718 if (make->clean_files.count)
3720 output( "%s::\n", obj_dir_path( make, "clean" ));
3721 output( "\trm -f" );
3722 output_filenames_obj_dir( make, make->clean_files );
3723 output( "\n" );
3724 strarray_add( &make->phony_targets, obj_dir_path( make, "clean" ));
3729 /*******************************************************************
3730 * create_temp_file
3732 static FILE *create_temp_file( const char *orig )
3734 char *name = xmalloc( strlen(orig) + 13 );
3735 unsigned int i, id = getpid();
3736 int fd;
3737 FILE *ret = NULL;
3739 for (i = 0; i < 100; i++)
3741 sprintf( name, "%s.tmp%08x", orig, id );
3742 if ((fd = open( name, O_RDWR | O_CREAT | O_EXCL, 0666 )) != -1)
3744 ret = fdopen( fd, "w" );
3745 break;
3747 if (errno != EEXIST) break;
3748 id += 7777;
3750 if (!ret) fatal_error( "failed to create output file for '%s'\n", orig );
3751 temp_file_name = name;
3752 return ret;
3756 /*******************************************************************
3757 * rename_temp_file
3759 static void rename_temp_file( const char *dest )
3761 int ret = rename( temp_file_name, dest );
3762 if (ret == -1 && errno == EEXIST)
3764 /* rename doesn't overwrite on windows */
3765 unlink( dest );
3766 ret = rename( temp_file_name, dest );
3768 if (ret == -1) fatal_error( "failed to rename output file to '%s'\n", dest );
3769 temp_file_name = NULL;
3773 /*******************************************************************
3774 * are_files_identical
3776 static int are_files_identical( FILE *file1, FILE *file2 )
3778 for (;;)
3780 char buffer1[8192], buffer2[8192];
3781 int size1 = fread( buffer1, 1, sizeof(buffer1), file1 );
3782 int size2 = fread( buffer2, 1, sizeof(buffer2), file2 );
3783 if (size1 != size2) return 0;
3784 if (!size1) return feof( file1 ) && feof( file2 );
3785 if (memcmp( buffer1, buffer2, size1 )) return 0;
3790 /*******************************************************************
3791 * rename_temp_file_if_changed
3793 static void rename_temp_file_if_changed( const char *dest )
3795 FILE *file1, *file2;
3796 int do_rename = 1;
3798 if ((file1 = fopen( dest, "r" )))
3800 if ((file2 = fopen( temp_file_name, "r" )))
3802 do_rename = !are_files_identical( file1, file2 );
3803 fclose( file2 );
3805 fclose( file1 );
3807 if (!do_rename)
3809 unlink( temp_file_name );
3810 temp_file_name = NULL;
3812 else rename_temp_file( dest );
3816 /*******************************************************************
3817 * output_linguas
3819 static void output_linguas( const struct makefile *make )
3821 const char *dest = obj_dir_path( make, "LINGUAS" );
3822 struct incl_file *source;
3824 output_file = create_temp_file( dest );
3826 output( "# Automatically generated by make depend; DO NOT EDIT!!\n" );
3827 LIST_FOR_EACH_ENTRY( source, &make->sources, struct incl_file, entry )
3828 if (strendswith( source->name, ".po" ))
3829 output( "%s\n", replace_extension( source->name, ".po", "" ));
3831 if (fclose( output_file )) fatal_perror( "write" );
3832 output_file = NULL;
3833 rename_temp_file_if_changed( dest );
3837 /*******************************************************************
3838 * output_testlist
3840 static void output_testlist( const struct makefile *make )
3842 const char *dest = obj_dir_path( make, "testlist.c" );
3843 unsigned int i;
3845 output_file = create_temp_file( dest );
3847 output( "/* Automatically generated by make depend; DO NOT EDIT!! */\n\n" );
3848 output( "#define WIN32_LEAN_AND_MEAN\n" );
3849 output( "#include <windows.h>\n\n" );
3850 output( "#define STANDALONE\n" );
3851 output( "#include \"wine/test.h\"\n\n" );
3853 for (i = 0; i < make->test_files.count; i++)
3854 output( "extern void func_%s(void);\n", make->test_files.str[i] );
3855 output( "\n" );
3856 output( "const struct test winetest_testlist[] =\n" );
3857 output( "{\n" );
3858 for (i = 0; i < make->test_files.count; i++)
3859 output( " { \"%s\", func_%s },\n", make->test_files.str[i], make->test_files.str[i] );
3860 output( " { 0, 0 }\n" );
3861 output( "};\n" );
3863 if (fclose( output_file )) fatal_perror( "write" );
3864 output_file = NULL;
3865 rename_temp_file_if_changed( dest );
3869 /*******************************************************************
3870 * output_gitignore
3872 static void output_gitignore( const char *dest, struct strarray files )
3874 int i;
3876 output_file = create_temp_file( dest );
3878 output( "# Automatically generated by make depend; DO NOT EDIT!!\n" );
3879 for (i = 0; i < files.count; i++)
3881 if (!strchr( files.str[i], '/' )) output( "/" );
3882 output( "%s\n", files.str[i] );
3885 if (fclose( output_file )) fatal_perror( "write" );
3886 output_file = NULL;
3887 rename_temp_file( dest );
3891 /*******************************************************************
3892 * output_stub_makefile
3894 static void output_stub_makefile( struct makefile *make )
3896 struct strarray targets = empty_strarray;
3897 const char *make_var = strarray_get_value( &top_makefile->vars, "MAKE" );
3899 if (make->obj_dir) create_dir( make->obj_dir );
3901 output_file_name = obj_dir_path( make, "Makefile" );
3902 output_file = create_temp_file( output_file_name );
3904 output( "# Auto-generated stub makefile; all rules forward to the top-level makefile\n\n" );
3906 if (make_var) output( "MAKE = %s\n\n", make_var );
3907 output( "all:\n" );
3909 if (make->all_targets.count) strarray_add( &targets, "all" );
3910 if (make->install_rules[INSTALL_LIB].count || make->install_rules[INSTALL_DEV].count)
3911 strarray_add( &targets, "install" );
3912 if (make->install_rules[INSTALL_LIB].count) strarray_add( &targets, "install-lib" );
3913 if (make->install_rules[INSTALL_DEV].count) strarray_add( &targets, "install-dev" );
3914 if (make->clean_files.count) strarray_add( &targets, "clean" );
3915 if (make->test_files.count)
3917 strarray_add( &targets, "check" );
3918 strarray_add( &targets, "test" );
3919 strarray_add( &targets, "testclean" );
3922 output_filenames( targets );
3923 output_filenames( make->clean_files );
3924 output( ":\n" );
3925 output( "\t@cd %s && $(MAKE) %s/$@\n", get_relative_path( make->obj_dir, "" ), make->obj_dir );
3926 output( ".PHONY:" );
3927 output_filenames( targets );
3928 output( "\n" );
3930 fclose( output_file );
3931 output_file = NULL;
3932 rename_temp_file( output_file_name );
3936 /*******************************************************************
3937 * output_silent_rules
3939 static void output_silent_rules(void)
3941 static const char *cmds[] =
3943 "BISON",
3944 "BUILD",
3945 "CC",
3946 "CCLD",
3947 "FLEX",
3948 "GEN",
3949 "LN",
3950 "MSG",
3951 "SED",
3952 "TEST",
3953 "WIDL",
3954 "WMC",
3955 "WRC"
3957 unsigned int i;
3959 output( "V = 0\n" );
3960 for (i = 0; i < sizeof(cmds) / sizeof(cmds[0]); i++)
3962 output( "quiet_%s = $(quiet_%s_$(V))\n", cmds[i], cmds[i] );
3963 output( "quiet_%s_0 = @echo \" %-5s \" $@;\n", cmds[i], cmds[i] );
3964 output( "quiet_%s_1 =\n", cmds[i] );
3969 /*******************************************************************
3970 * output_top_makefile
3972 static void output_top_makefile( struct makefile *make )
3974 char buffer[1024];
3975 FILE *src_file;
3976 int i, found = 0;
3978 output_file_name = obj_dir_path( make, output_makefile_name );
3979 output_file = create_temp_file( output_file_name );
3981 /* copy the contents of the source makefile */
3982 src_file = open_input_makefile( make );
3983 while (fgets( buffer, sizeof(buffer), src_file ) && !found)
3985 if (fwrite( buffer, 1, strlen(buffer), output_file ) != strlen(buffer)) fatal_perror( "write" );
3986 found = !strncmp( buffer, separator, strlen(separator) );
3988 if (fclose( src_file )) fatal_perror( "close" );
3989 input_file_name = NULL;
3991 if (!found) output( "\n%s (everything below this line is auto-generated; DO NOT EDIT!!)\n", separator );
3993 if (silent_rules) output_silent_rules();
3994 for (i = 0; i < subdirs.count; i++) output_sources( submakes[i] );
3995 output_sources( make );
3996 /* disable implicit rules */
3997 output( ".SUFFIXES:\n" );
3999 fclose( output_file );
4000 output_file = NULL;
4001 rename_temp_file( output_file_name );
4005 /*******************************************************************
4006 * output_dependencies
4008 static void output_dependencies( struct makefile *make )
4010 struct strarray ignore_files = empty_strarray;
4012 if (make->obj_dir) create_dir( make->obj_dir );
4014 if (make == top_makefile) output_top_makefile( make );
4015 else output_stub_makefile( make );
4017 strarray_addall( &ignore_files, make->distclean_files );
4018 strarray_addall( &ignore_files, make->clean_files );
4019 if (make->testdll) output_testlist( make );
4020 if (make->obj_dir && !strcmp( make->obj_dir, "po" )) output_linguas( make );
4021 if (!make->src_dir) output_gitignore( obj_dir_path( make, ".gitignore" ), ignore_files );
4023 create_file_directories( make, ignore_files );
4025 output_file_name = NULL;
4029 /*******************************************************************
4030 * load_sources
4032 static void load_sources( struct makefile *make )
4034 static const char *source_vars[] =
4036 "SOURCES",
4037 "C_SRCS",
4038 "OBJC_SRCS",
4039 "RC_SRCS",
4040 "MC_SRCS",
4041 "IDL_SRCS",
4042 "BISON_SRCS",
4043 "LEX_SRCS",
4044 "HEADER_SRCS",
4045 "XTEMPLATE_SRCS",
4046 "SVG_SRCS",
4047 "FONT_SRCS",
4048 "IN_SRCS",
4049 "PO_SRCS",
4050 "MANPAGES",
4051 NULL
4053 const char **var;
4054 unsigned int i;
4055 struct strarray value;
4056 struct incl_file *file;
4058 strarray_set_value( &make->vars, "top_srcdir", root_src_dir_path( "" ));
4059 strarray_set_value( &make->vars, "srcdir", src_dir_path( make, "" ));
4061 make->parent_dir = get_expanded_make_variable( make, "PARENTSRC" );
4062 make->module = get_expanded_make_variable( make, "MODULE" );
4063 make->testdll = get_expanded_make_variable( make, "TESTDLL" );
4064 make->sharedlib = get_expanded_make_variable( make, "SHAREDLIB" );
4065 make->staticlib = get_expanded_make_variable( make, "STATICLIB" );
4066 make->importlib = get_expanded_make_variable( make, "IMPORTLIB" );
4067 make->extlib = get_expanded_make_variable( make, "EXTLIB" );
4068 if (*dll_ext) make->unixlib = get_expanded_make_variable( make, "UNIXLIB" );
4070 make->programs = get_expanded_make_var_array( make, "PROGRAMS" );
4071 make->scripts = get_expanded_make_var_array( make, "SCRIPTS" );
4072 make->imports = get_expanded_make_var_array( make, "IMPORTS" );
4073 make->delayimports = get_expanded_make_var_array( make, "DELAYIMPORTS" );
4074 make->extradllflags = get_expanded_make_var_array( make, "EXTRADLLFLAGS" );
4075 make->install_lib = get_expanded_make_var_array( make, "INSTALL_LIB" );
4076 make->install_dev = get_expanded_make_var_array( make, "INSTALL_DEV" );
4077 make->extra_targets = get_expanded_make_var_array( make, "EXTRA_TARGETS" );
4079 if (make->extlib) make->staticlib = make->extlib;
4080 if (make->staticlib) make->module = make->staticlib;
4082 if (host_cpu)
4084 value = get_expanded_file_local_var( make, host_cpu, "EXTRADLLFLAGS" );
4085 if (value.count) make->extradllflags = value;
4088 make->disabled = make->obj_dir && strarray_exists( &disabled_dirs, make->obj_dir );
4089 make->is_win16 = strarray_exists( &make->extradllflags, "-m16" );
4090 make->use_msvcrt = (make->module || make->testdll || make->is_win16) &&
4091 !strarray_exists( &make->extradllflags, "-mcygwin" );
4092 make->is_exe = strarray_exists( &make->extradllflags, "-mconsole" ) ||
4093 strarray_exists( &make->extradllflags, "-mwindows" );
4094 make->native_unix_lib = !!make->unixlib;
4096 if (make->use_msvcrt) strarray_add_uniq( &make->extradllflags, "-mno-cygwin" );
4098 if (make->module && !make->install_lib.count && !make->install_dev.count)
4100 if (make->importlib) strarray_add( &make->install_dev, make->importlib );
4101 if (make->staticlib) strarray_add( &make->install_dev, make->staticlib );
4102 else strarray_add( &make->install_lib, make->module );
4105 make->include_paths = empty_strarray;
4106 make->include_args = empty_strarray;
4107 make->define_args = empty_strarray;
4108 if (!make->extlib) strarray_add( &make->define_args, "-D__WINESRC__" );
4110 value = get_expanded_make_var_array( make, "EXTRAINCL" );
4111 for (i = 0; i < value.count; i++)
4112 if (!strncmp( value.str[i], "-I", 2 ))
4113 strarray_add_uniq( &make->include_paths, value.str[i] + 2 );
4114 else if (!strncmp( value.str[i], "-D", 2 ) || !strncmp( value.str[i], "-U", 2 ))
4115 strarray_add_uniq( &make->define_args, value.str[i] );
4116 strarray_addall( &make->define_args, get_expanded_make_var_array( make, "EXTRADEFS" ));
4118 strarray_add( &make->include_args, strmake( "-I%s", obj_dir_path( make, "" )));
4119 if (make->src_dir)
4120 strarray_add( &make->include_args, strmake( "-I%s", make->src_dir ));
4121 if (make->parent_dir)
4122 strarray_add( &make->include_args, strmake( "-I%s", src_dir_path( make, make->parent_dir )));
4123 strarray_add( &make->include_args, "-Iinclude" );
4124 if (root_src_dir) strarray_add( &make->include_args, strmake( "-I%s", root_src_dir_path( "include" )));
4126 list_init( &make->sources );
4127 list_init( &make->includes );
4129 for (var = source_vars; *var; var++)
4131 value = get_expanded_make_var_array( make, *var );
4132 for (i = 0; i < value.count; i++) add_src_file( make, value.str[i] );
4135 add_generated_sources( make );
4136 if (!make->unixlib) make->unixlib = get_unix_lib_name( make );
4138 if (make->use_msvcrt) strarray_add( &make->define_args, get_crt_define( make ));
4140 LIST_FOR_EACH_ENTRY( file, &make->includes, struct incl_file, entry ) parse_file( make, file, 0 );
4141 LIST_FOR_EACH_ENTRY( file, &make->sources, struct incl_file, entry ) get_dependencies( file, file );
4143 make->is_cross = crosstarget && make->use_msvcrt;
4145 if (!*dll_ext || make->is_cross)
4146 for (i = 0; i < make->delayimports.count; i++)
4147 strarray_add_uniq( &delay_import_libs, get_base_name( make->delayimports.str[i] ));
4151 /*******************************************************************
4152 * parse_makeflags
4154 static void parse_makeflags( const char *flags )
4156 const char *p = flags;
4157 char *var, *buffer = xmalloc( strlen(flags) + 1 );
4159 while (*p)
4161 while (isspace(*p)) p++;
4162 var = buffer;
4163 while (*p && !isspace(*p))
4165 if (*p == '\\' && p[1]) p++;
4166 *var++ = *p++;
4168 *var = 0;
4169 if (var > buffer) set_make_variable( &cmdline_vars, buffer );
4174 /*******************************************************************
4175 * parse_option
4177 static int parse_option( const char *opt )
4179 if (opt[0] != '-')
4181 if (strchr( opt, '=' )) return set_make_variable( &cmdline_vars, opt );
4182 return 0;
4184 switch(opt[1])
4186 case 'f':
4187 if (opt[2]) output_makefile_name = opt + 2;
4188 break;
4189 case 'R':
4190 relative_dir_mode = 1;
4191 break;
4192 case 'S':
4193 silent_rules = 1;
4194 break;
4195 default:
4196 fprintf( stderr, "Unknown option '%s'\n%s", opt, Usage );
4197 exit(1);
4199 return 1;
4203 /*******************************************************************
4204 * main
4206 int main( int argc, char *argv[] )
4208 const char *makeflags = getenv( "MAKEFLAGS" );
4209 int i, j;
4211 if (makeflags) parse_makeflags( makeflags );
4213 i = 1;
4214 while (i < argc)
4216 if (parse_option( argv[i] ))
4218 for (j = i; j < argc; j++) argv[j] = argv[j+1];
4219 argc--;
4221 else i++;
4224 if (relative_dir_mode)
4226 char *relpath;
4228 if (argc != 3)
4230 fprintf( stderr, "Option -R needs two directories\n%s", Usage );
4231 exit( 1 );
4233 relpath = get_relative_path( argv[1], argv[2] );
4234 printf( "%s\n", relpath ? relpath : "." );
4235 exit( 0 );
4238 if (argc > 1) fatal_error( "Directory arguments not supported in this mode\n" );
4240 atexit( cleanup_files );
4241 signal( SIGTERM, exit_on_signal );
4242 signal( SIGINT, exit_on_signal );
4243 #ifdef SIGHUP
4244 signal( SIGHUP, exit_on_signal );
4245 #endif
4247 for (i = 0; i < HASH_SIZE; i++) list_init( &files[i] );
4249 top_makefile = parse_makefile( NULL );
4251 target_flags = get_expanded_make_var_array( top_makefile, "TARGETFLAGS" );
4252 msvcrt_flags = get_expanded_make_var_array( top_makefile, "MSVCRTFLAGS" );
4253 dll_flags = get_expanded_make_var_array( top_makefile, "DLLFLAGS" );
4254 extra_cflags = get_expanded_make_var_array( top_makefile, "EXTRACFLAGS" );
4255 extra_cross_cflags = get_expanded_make_var_array( top_makefile, "EXTRACROSSCFLAGS" );
4256 unix_dllflags = get_expanded_make_var_array( top_makefile, "UNIXDLLFLAGS" );
4257 cpp_flags = get_expanded_make_var_array( top_makefile, "CPPFLAGS" );
4258 lddll_flags = get_expanded_make_var_array( top_makefile, "LDDLLFLAGS" );
4259 libs = get_expanded_make_var_array( top_makefile, "LIBS" );
4260 enable_tests = get_expanded_make_var_array( top_makefile, "ENABLE_TESTS" );
4261 top_install_lib = get_expanded_make_var_array( top_makefile, "TOP_INSTALL_LIB" );
4262 top_install_dev = get_expanded_make_var_array( top_makefile, "TOP_INSTALL_DEV" );
4264 delay_load_flag = get_expanded_make_variable( top_makefile, "DELAYLOADFLAG" );
4265 root_src_dir = get_expanded_make_variable( top_makefile, "srcdir" );
4266 tools_dir = get_expanded_make_variable( top_makefile, "toolsdir" );
4267 tools_ext = get_expanded_make_variable( top_makefile, "toolsext" );
4268 exe_ext = get_expanded_make_variable( top_makefile, "EXEEXT" );
4269 dll_ext = (exe_ext && !strcmp( exe_ext, ".exe" )) ? "" : ".so";
4270 host_cpu = get_expanded_make_variable( top_makefile, "host_cpu" );
4271 crosstarget = get_expanded_make_variable( top_makefile, "CROSSTARGET" );
4272 crossdebug = get_expanded_make_variable( top_makefile, "CROSSDEBUG" );
4273 fontforge = get_expanded_make_variable( top_makefile, "FONTFORGE" );
4274 convert = get_expanded_make_variable( top_makefile, "CONVERT" );
4275 flex = get_expanded_make_variable( top_makefile, "FLEX" );
4276 bison = get_expanded_make_variable( top_makefile, "BISON" );
4277 ar = get_expanded_make_variable( top_makefile, "AR" );
4278 ranlib = get_expanded_make_variable( top_makefile, "RANLIB" );
4279 rsvg = get_expanded_make_variable( top_makefile, "RSVG" );
4280 icotool = get_expanded_make_variable( top_makefile, "ICOTOOL" );
4281 dlltool = get_expanded_make_variable( top_makefile, "DLLTOOL" );
4282 msgfmt = get_expanded_make_variable( top_makefile, "MSGFMT" );
4283 sed_cmd = get_expanded_make_variable( top_makefile, "SED_CMD" );
4284 ln_s = get_expanded_make_variable( top_makefile, "LN_S" );
4286 if (root_src_dir && !strcmp( root_src_dir, "." )) root_src_dir = NULL;
4287 if (tools_dir && !strcmp( tools_dir, "." )) tools_dir = NULL;
4288 if (!exe_ext) exe_ext = "";
4289 if (!tools_ext) tools_ext = "";
4290 if (host_cpu && (host_cpu = normalize_arch( host_cpu )))
4292 so_dir = strmake( "$(dlldir)/%s-unix", host_cpu );
4293 pe_dir = strmake( "$(dlldir)/%s-windows", host_cpu );
4295 else
4296 so_dir = pe_dir = "$(dlldir)";
4298 extra_cflags_extlib = remove_warning_flags( extra_cflags );
4299 extra_cross_cflags_extlib = remove_warning_flags( extra_cross_cflags );
4301 top_makefile->src_dir = root_src_dir;
4302 subdirs = get_expanded_make_var_array( top_makefile, "SUBDIRS" );
4303 disabled_dirs = get_expanded_make_var_array( top_makefile, "DISABLED_SUBDIRS" );
4304 submakes = xmalloc( subdirs.count * sizeof(*submakes) );
4306 for (i = 0; i < subdirs.count; i++) submakes[i] = parse_makefile( subdirs.str[i] );
4308 load_sources( top_makefile );
4309 for (i = 0; i < subdirs.count; i++) load_sources( submakes[i] );
4311 output_dependencies( top_makefile );
4312 for (i = 0; i < subdirs.count; i++) output_dependencies( submakes[i] );
4314 return 0;