d3d11/tests: Test values of unused fields in D3D11_DEPTH_STENCIL_DESC.
[wine.git] / tools / makedep.c
blob8cbba1bc9a3c85537872a1b5fc3208a2e2b831b6
1 /*
2 * Generate include file dependencies
4 * Copyright 1996, 2013 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
22 #define NO_LIBWINE_PORT
23 #include "wine/port.h"
25 #include <assert.h>
26 #include <ctype.h>
27 #include <errno.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <stdarg.h>
31 #include <signal.h>
32 #include <string.h>
33 #ifdef HAVE_UNISTD_H
34 # include <unistd.h>
35 #endif
36 #include "wine/list.h"
38 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 *sourcename; /* source file name for generated headers */
73 struct incl_file *included_by; /* file that included this one */
74 int included_line; /* line where this file was included */
75 enum incl_type type; /* type of include */
76 struct incl_file *owner;
77 unsigned int files_count; /* files in use */
78 unsigned int files_size; /* total allocated size */
79 struct incl_file **files;
82 #define FLAG_GENERATED 0x000001 /* generated file */
83 #define FLAG_INSTALL 0x000002 /* file to install */
84 #define FLAG_IDL_PROXY 0x000100 /* generates a proxy (_p.c) file */
85 #define FLAG_IDL_CLIENT 0x000200 /* generates a client (_c.c) file */
86 #define FLAG_IDL_SERVER 0x000400 /* generates a server (_s.c) file */
87 #define FLAG_IDL_IDENT 0x000800 /* generates an ident (_i.c) file */
88 #define FLAG_IDL_REGISTER 0x001000 /* generates a registration (_r.res) file */
89 #define FLAG_IDL_TYPELIB 0x002000 /* generates a typelib (.tlb) file */
90 #define FLAG_IDL_REGTYPELIB 0x004000 /* generates a registered typelib (_t.res) file */
91 #define FLAG_IDL_HEADER 0x008000 /* generates a header (.h) file */
92 #define FLAG_RC_PO 0x010000 /* rc file contains translations */
93 #define FLAG_C_IMPLIB 0x020000 /* file is part of an import library */
94 #define FLAG_SFD_FONTS 0x040000 /* sfd file generated bitmap fonts */
96 static const struct
98 unsigned int flag;
99 const char *ext;
100 } idl_outputs[] =
102 { FLAG_IDL_TYPELIB, ".tlb" },
103 { FLAG_IDL_REGTYPELIB, "_t.res" },
104 { FLAG_IDL_CLIENT, "_c.c" },
105 { FLAG_IDL_IDENT, "_i.c" },
106 { FLAG_IDL_PROXY, "_p.c" },
107 { FLAG_IDL_SERVER, "_s.c" },
108 { FLAG_IDL_REGISTER, "_r.res" },
109 { FLAG_IDL_HEADER, ".h" }
112 #define HASH_SIZE 997
114 static struct list files[HASH_SIZE];
116 struct strarray
118 unsigned int count; /* strings in use */
119 unsigned int size; /* total allocated size */
120 const char **str;
123 static const struct strarray empty_strarray;
125 enum install_rules { INSTALL_LIB, INSTALL_DEV, NB_INSTALL_RULES };
127 /* variables common to all makefiles */
128 static struct strarray linguas;
129 static struct strarray dll_flags;
130 static struct strarray target_flags;
131 static struct strarray msvcrt_flags;
132 static struct strarray extra_cflags;
133 static struct strarray cpp_flags;
134 static struct strarray unwind_flags;
135 static struct strarray libs;
136 static struct strarray cmdline_vars;
137 static struct strarray disabled_dirs;
138 static const char *root_src_dir;
139 static const char *tools_dir;
140 static const char *tools_ext;
141 static const char *exe_ext;
142 static const char *dll_ext;
143 static const char *man_ext;
144 static const char *crosstarget;
145 static const char *fontforge;
146 static const char *convert;
147 static const char *rsvg;
148 static const char *icotool;
149 static const char *dlltool;
150 static const char *msgfmt;
151 static const char *ln_s;
153 struct makefile
155 struct strarray vars;
156 struct strarray include_paths;
157 struct strarray define_args;
158 struct strarray programs;
159 struct strarray scripts;
160 struct strarray appmode;
161 struct strarray imports;
162 struct strarray subdirs;
163 struct strarray delayimports;
164 struct strarray extradllflags;
165 struct strarray install_lib;
166 struct strarray install_dev;
167 struct list sources;
168 struct list includes;
169 const char *base_dir;
170 const char *src_dir;
171 const char *obj_dir;
172 const char *top_src_dir;
173 const char *top_obj_dir;
174 const char *parent_dir;
175 const char *module;
176 const char *testdll;
177 const char *sharedlib;
178 const char *staticlib;
179 const char *staticimplib;
180 const char *importlib;
181 int disabled;
182 int use_msvcrt;
183 int is_win16;
184 struct makefile **submakes;
187 static struct makefile *top_makefile;
189 static const char separator[] = "### Dependencies";
190 static const char *output_makefile_name = "Makefile";
191 static const char *input_file_name;
192 static const char *output_file_name;
193 static const char *temp_file_name;
194 static int relative_dir_mode;
195 static int input_line;
196 static int output_column;
197 static FILE *output_file;
199 static const char Usage[] =
200 "Usage: makedep [options] [directories]\n"
201 "Options:\n"
202 " -R from to Compute the relative path between two directories\n"
203 " -fxxx Store output in file 'xxx' (default: Makefile)\n";
206 #ifndef __GNUC__
207 #define __attribute__(x)
208 #endif
210 static void fatal_error( const char *msg, ... ) __attribute__ ((__format__ (__printf__, 1, 2)));
211 static void fatal_perror( const char *msg, ... ) __attribute__ ((__format__ (__printf__, 1, 2)));
212 static void output( const char *format, ... ) __attribute__ ((__format__ (__printf__, 1, 2)));
213 static char *strmake( const char* fmt, ... ) __attribute__ ((__format__ (__printf__, 1, 2)));
215 /*******************************************************************
216 * fatal_error
218 static void fatal_error( const char *msg, ... )
220 va_list valist;
221 va_start( valist, msg );
222 if (input_file_name)
224 fprintf( stderr, "%s:", input_file_name );
225 if (input_line) fprintf( stderr, "%d:", input_line );
226 fprintf( stderr, " error: " );
228 else fprintf( stderr, "makedep: error: " );
229 vfprintf( stderr, msg, valist );
230 va_end( valist );
231 exit(1);
235 /*******************************************************************
236 * fatal_perror
238 static void fatal_perror( const char *msg, ... )
240 va_list valist;
241 va_start( valist, msg );
242 if (input_file_name)
244 fprintf( stderr, "%s:", input_file_name );
245 if (input_line) fprintf( stderr, "%d:", input_line );
246 fprintf( stderr, " error: " );
248 else fprintf( stderr, "makedep: error: " );
249 vfprintf( stderr, msg, valist );
250 perror( " " );
251 va_end( valist );
252 exit(1);
256 /*******************************************************************
257 * cleanup_files
259 static void cleanup_files(void)
261 if (temp_file_name) unlink( temp_file_name );
262 if (output_file_name) unlink( output_file_name );
266 /*******************************************************************
267 * exit_on_signal
269 static void exit_on_signal( int sig )
271 exit( 1 ); /* this will call the atexit functions */
275 /*******************************************************************
276 * xmalloc
278 static void *xmalloc( size_t size )
280 void *res;
281 if (!(res = malloc (size ? size : 1)))
282 fatal_error( "Virtual memory exhausted.\n" );
283 return res;
287 /*******************************************************************
288 * xrealloc
290 static void *xrealloc (void *ptr, size_t size)
292 void *res;
293 assert( size );
294 if (!(res = realloc( ptr, size )))
295 fatal_error( "Virtual memory exhausted.\n" );
296 return res;
299 /*******************************************************************
300 * xstrdup
302 static char *xstrdup( const char *str )
304 char *res = strdup( str );
305 if (!res) fatal_error( "Virtual memory exhausted.\n" );
306 return res;
310 /*******************************************************************
311 * strmake
313 static char *strmake( const char* fmt, ... )
315 int n;
316 size_t size = 100;
317 va_list ap;
319 for (;;)
321 char *p = xmalloc (size);
322 va_start(ap, fmt);
323 n = vsnprintf (p, size, fmt, ap);
324 va_end(ap);
325 if (n == -1) size *= 2;
326 else if ((size_t)n >= size) size = n + 1;
327 else return xrealloc( p, n + 1 );
328 free(p);
333 /*******************************************************************
334 * strendswith
336 static int strendswith( const char* str, const char* end )
338 size_t l = strlen( str );
339 size_t m = strlen( end );
341 return l >= m && strcmp(str + l - m, end) == 0;
345 /*******************************************************************
346 * output
348 static void output( const char *format, ... )
350 int ret;
351 va_list valist;
353 va_start( valist, format );
354 ret = vfprintf( output_file, format, valist );
355 va_end( valist );
356 if (ret < 0) fatal_perror( "output" );
357 if (format[0] && format[strlen(format) - 1] == '\n') output_column = 0;
358 else output_column += ret;
362 /*******************************************************************
363 * strarray_add
365 static void strarray_add( struct strarray *array, const char *str )
367 if (array->count == array->size)
369 if (array->size) array->size *= 2;
370 else array->size = 16;
371 array->str = xrealloc( array->str, sizeof(array->str[0]) * array->size );
373 array->str[array->count++] = str;
377 /*******************************************************************
378 * strarray_addall
380 static void strarray_addall( struct strarray *array, struct strarray added )
382 unsigned int i;
384 for (i = 0; i < added.count; i++) strarray_add( array, added.str[i] );
388 /*******************************************************************
389 * strarray_exists
391 static int strarray_exists( const struct strarray *array, const char *str )
393 unsigned int i;
395 for (i = 0; i < array->count; i++) if (!strcmp( array->str[i], str )) return 1;
396 return 0;
400 /*******************************************************************
401 * strarray_add_uniq
403 static void strarray_add_uniq( struct strarray *array, const char *str )
405 if (!strarray_exists( array, str )) strarray_add( array, str );
409 /*******************************************************************
410 * strarray_get_value
412 * Find a value in a name/value pair string array.
414 static const char *strarray_get_value( const struct strarray *array, const char *name )
416 unsigned int i;
418 for (i = 0; i < array->count; i += 2)
419 if (!strcmp( array->str[i], name )) return array->str[i + 1];
420 return NULL;
424 /*******************************************************************
425 * strarray_set_value
427 * Define a value in a name/value pair string array.
429 static void strarray_set_value( struct strarray *array, const char *name, const char *value )
431 unsigned int i;
433 /* redefining a variable replaces the previous value */
434 for (i = 0; i < array->count; i += 2)
436 if (strcmp( array->str[i], name )) continue;
437 array->str[i + 1] = value;
438 return;
440 strarray_add( array, name );
441 strarray_add( array, value );
445 /*******************************************************************
446 * output_filename
448 static void output_filename( const char *name )
450 if (output_column + strlen(name) + 1 > 100)
452 output( " \\\n" );
453 output( " " );
455 else if (output_column) output( " " );
456 output( "%s", name );
460 /*******************************************************************
461 * output_filenames
463 static void output_filenames( struct strarray array )
465 unsigned int i;
467 for (i = 0; i < array.count; i++) output_filename( array.str[i] );
471 /*******************************************************************
472 * get_extension
474 static char *get_extension( char *filename )
476 char *ext = strrchr( filename, '.' );
477 if (ext && strchr( ext, '/' )) ext = NULL;
478 return ext;
482 /*******************************************************************
483 * replace_extension
485 static char *replace_extension( const char *name, const char *old_ext, const char *new_ext )
487 char *ret;
488 size_t name_len = strlen( name );
489 size_t ext_len = strlen( old_ext );
491 if (name_len >= ext_len && !strcmp( name + name_len - ext_len, old_ext )) name_len -= ext_len;
492 ret = xmalloc( name_len + strlen( new_ext ) + 1 );
493 memcpy( ret, name, name_len );
494 strcpy( ret + name_len, new_ext );
495 return ret;
499 /*******************************************************************
500 * replace_filename
502 static char *replace_filename( const char *path, const char *name )
504 const char *p;
505 char *ret;
506 size_t len;
508 if (!path) return xstrdup( name );
509 if (!(p = strrchr( path, '/' ))) return xstrdup( name );
510 len = p - path + 1;
511 ret = xmalloc( len + strlen( name ) + 1 );
512 memcpy( ret, path, len );
513 strcpy( ret + len, name );
514 return ret;
518 /*******************************************************************
519 * strarray_replace_extension
521 static struct strarray strarray_replace_extension( const struct strarray *array,
522 const char *old_ext, const char *new_ext )
524 unsigned int i;
525 struct strarray ret;
527 ret.count = ret.size = array->count;
528 ret.str = xmalloc( sizeof(ret.str[0]) * ret.size );
529 for (i = 0; i < array->count; i++) ret.str[i] = replace_extension( array->str[i], old_ext, new_ext );
530 return ret;
534 /*******************************************************************
535 * replace_substr
537 static char *replace_substr( const char *str, const char *start, size_t len, const char *replace )
539 size_t pos = start - str;
540 char *ret = xmalloc( pos + strlen(replace) + strlen(start + len) + 1 );
541 memcpy( ret, str, pos );
542 strcpy( ret + pos, replace );
543 strcat( ret + pos, start + len );
544 return ret;
548 /*******************************************************************
549 * get_relative_path
551 * Determine where the destination path is located relative to the 'from' path.
553 static char *get_relative_path( const char *from, const char *dest )
555 const char *start;
556 char *ret, *p;
557 unsigned int dotdots = 0;
559 /* a path of "." is equivalent to an empty path */
560 if (!strcmp( from, "." )) from = "";
562 for (;;)
564 while (*from == '/') from++;
565 while (*dest == '/') dest++;
566 start = dest; /* save start of next path element */
567 if (!*from) break;
569 while (*from && *from != '/' && *from == *dest) { from++; dest++; }
570 if ((!*from || *from == '/') && (!*dest || *dest == '/')) continue;
572 /* count remaining elements in 'from' */
575 dotdots++;
576 while (*from && *from != '/') from++;
577 while (*from == '/') from++;
579 while (*from);
580 break;
583 if (!start[0] && !dotdots) return NULL; /* empty path */
585 ret = xmalloc( 3 * dotdots + strlen( start ) + 1 );
586 for (p = ret; dotdots; dotdots--, p += 3) memcpy( p, "../", 3 );
588 if (start[0]) strcpy( p, start );
589 else p[-1] = 0; /* remove trailing slash */
590 return ret;
594 /*******************************************************************
595 * concat_paths
597 static char *concat_paths( const char *base, const char *path )
599 if (!base || !base[0]) return xstrdup( path && path[0] ? path : "." );
600 if (!path || !path[0]) return xstrdup( base );
601 if (path[0] == '/') return xstrdup( path );
602 return strmake( "%s/%s", base, path );
606 /*******************************************************************
607 * base_dir_path
609 static char *base_dir_path( const struct makefile *make, const char *path )
611 return concat_paths( make->base_dir, path );
615 /*******************************************************************
616 * obj_dir_path
618 static char *obj_dir_path( const struct makefile *make, const char *path )
620 return concat_paths( make->obj_dir, path );
624 /*******************************************************************
625 * src_dir_path
627 static char *src_dir_path( const struct makefile *make, const char *path )
629 if (make->src_dir) return concat_paths( make->src_dir, path );
630 return obj_dir_path( make, path );
634 /*******************************************************************
635 * top_obj_dir_path
637 static char *top_obj_dir_path( const struct makefile *make, const char *path )
639 return concat_paths( make->top_obj_dir, path );
643 /*******************************************************************
644 * top_dir_path
646 static char *top_dir_path( const struct makefile *make, const char *path )
648 if (make->top_src_dir) return concat_paths( make->top_src_dir, path );
649 return top_obj_dir_path( make, path );
653 /*******************************************************************
654 * root_dir_path
656 static char *root_dir_path( const char *path )
658 return concat_paths( root_src_dir, path );
662 /*******************************************************************
663 * tools_dir_path
665 static char *tools_dir_path( const struct makefile *make, const char *path )
667 if (tools_dir) return top_obj_dir_path( make, strmake( "%s/tools/%s", tools_dir, path ));
668 return top_obj_dir_path( make, strmake( "tools/%s", path ));
672 /*******************************************************************
673 * tools_path
675 static char *tools_path( const struct makefile *make, const char *name )
677 return strmake( "%s/%s%s", tools_dir_path( make, name ), name, tools_ext );
681 /*******************************************************************
682 * get_line
684 static char *get_line( FILE *file )
686 static char *buffer;
687 static size_t size;
689 if (!size)
691 size = 1024;
692 buffer = xmalloc( size );
694 if (!fgets( buffer, size, file )) return NULL;
695 input_line++;
697 for (;;)
699 char *p = buffer + strlen(buffer);
700 /* if line is larger than buffer, resize buffer */
701 while (p == buffer + size - 1 && p[-1] != '\n')
703 buffer = xrealloc( buffer, size * 2 );
704 if (!fgets( buffer + size - 1, size + 1, file )) break;
705 p = buffer + strlen(buffer);
706 size *= 2;
708 if (p > buffer && p[-1] == '\n')
710 *(--p) = 0;
711 if (p > buffer && p[-1] == '\r') *(--p) = 0;
712 if (p > buffer && p[-1] == '\\')
714 *(--p) = 0;
715 /* line ends in backslash, read continuation line */
716 if (!fgets( p, size - (p - buffer), file )) return buffer;
717 input_line++;
718 continue;
721 return buffer;
726 /*******************************************************************
727 * hash_filename
729 static unsigned int hash_filename( const char *name )
731 /* FNV-1 hash */
732 unsigned int ret = 2166136261u;
733 while (*name) ret = (ret * 16777619) ^ *name++;
734 return ret % HASH_SIZE;
738 /*******************************************************************
739 * add_file
741 static struct file *add_file( const char *name )
743 struct file *file = xmalloc( sizeof(*file) );
744 memset( file, 0, sizeof(*file) );
745 file->name = xstrdup( name );
746 return file;
750 /*******************************************************************
751 * add_dependency
753 static void add_dependency( struct file *file, const char *name, enum incl_type type )
755 /* enforce some rules for the Wine tree */
757 if (!memcmp( name, "../", 3 ))
758 fatal_error( "#include directive with relative path not allowed\n" );
760 if (!strcmp( name, "config.h" ))
762 if (strendswith( file->name, ".h" ))
763 fatal_error( "config.h must not be included by a header file\n" );
764 if (file->deps_count)
765 fatal_error( "config.h must be included before anything else\n" );
767 else if (!strcmp( name, "wine/port.h" ))
769 if (strendswith( file->name, ".h" ))
770 fatal_error( "wine/port.h must not be included by a header file\n" );
771 if (!file->deps_count) fatal_error( "config.h must be included before wine/port.h\n" );
772 if (file->deps_count > 1)
773 fatal_error( "wine/port.h must be included before everything except config.h\n" );
774 if (strcmp( file->deps[0].name, "config.h" ))
775 fatal_error( "config.h must be included before wine/port.h\n" );
778 if (file->deps_count >= file->deps_size)
780 file->deps_size *= 2;
781 if (file->deps_size < 16) file->deps_size = 16;
782 file->deps = xrealloc( file->deps, file->deps_size * sizeof(*file->deps) );
784 file->deps[file->deps_count].line = input_line;
785 file->deps[file->deps_count].type = type;
786 file->deps[file->deps_count].name = xstrdup( name );
787 file->deps_count++;
791 /*******************************************************************
792 * find_src_file
794 static struct incl_file *find_src_file( const struct makefile *make, const char *name )
796 struct incl_file *file;
798 LIST_FOR_EACH_ENTRY( file, &make->sources, struct incl_file, entry )
799 if (!strcmp( name, file->name )) return file;
800 return NULL;
803 /*******************************************************************
804 * find_include_file
806 static struct incl_file *find_include_file( const struct makefile *make, const char *name )
808 struct incl_file *file;
810 LIST_FOR_EACH_ENTRY( file, &make->includes, struct incl_file, entry )
811 if (!strcmp( name, file->name )) return file;
812 return NULL;
815 /*******************************************************************
816 * add_include
818 * Add an include file if it doesn't already exists.
820 static struct incl_file *add_include( struct makefile *make, struct incl_file *parent,
821 const char *name, int line, enum incl_type type )
823 struct incl_file *include;
825 if (parent->files_count >= parent->files_size)
827 parent->files_size *= 2;
828 if (parent->files_size < 16) parent->files_size = 16;
829 parent->files = xrealloc( parent->files, parent->files_size * sizeof(*parent->files) );
832 LIST_FOR_EACH_ENTRY( include, &make->includes, struct incl_file, entry )
833 if (!strcmp( name, include->name )) goto found;
835 include = xmalloc( sizeof(*include) );
836 memset( include, 0, sizeof(*include) );
837 include->name = xstrdup(name);
838 include->included_by = parent;
839 include->included_line = line;
840 include->type = type;
841 list_add_tail( &make->includes, &include->entry );
842 found:
843 parent->files[parent->files_count++] = include;
844 return include;
848 /*******************************************************************
849 * add_generated_source
851 * Add a generated source file to the list.
853 static struct incl_file *add_generated_source( struct makefile *make,
854 const char *name, const char *filename )
856 struct incl_file *file;
858 if ((file = find_src_file( make, name ))) return file; /* we already have it */
859 file = xmalloc( sizeof(*file) );
860 memset( file, 0, sizeof(*file) );
861 file->file = add_file( name );
862 file->name = xstrdup( name );
863 file->filename = obj_dir_path( make, filename ? filename : name );
864 file->file->flags = FLAG_GENERATED;
865 list_add_tail( &make->sources, &file->entry );
866 return file;
870 /*******************************************************************
871 * parse_include_directive
873 static void parse_include_directive( struct file *source, char *str )
875 char quote, *include, *p = str;
877 while (*p && isspace(*p)) p++;
878 if (*p != '\"' && *p != '<' ) return;
879 quote = *p++;
880 if (quote == '<') quote = '>';
881 include = p;
882 while (*p && (*p != quote)) p++;
883 if (!*p) fatal_error( "malformed include directive '%s'\n", str );
884 *p = 0;
885 add_dependency( source, include, (quote == '>') ? INCL_SYSTEM : INCL_NORMAL );
889 /*******************************************************************
890 * parse_pragma_directive
892 static void parse_pragma_directive( struct file *source, char *str )
894 char *flag, *p = str;
896 if (!isspace( *p )) return;
897 while (*p && isspace(*p)) p++;
898 p = strtok( p, " \t" );
899 if (strcmp( p, "makedep" )) return;
901 while ((flag = strtok( NULL, " \t" )))
903 if (!strcmp( flag, "depend" ))
905 while ((p = strtok( NULL, " \t" ))) add_dependency( source, p, INCL_NORMAL );
906 return;
908 else if (!strcmp( flag, "install" )) source->flags |= FLAG_INSTALL;
910 if (strendswith( source->name, ".idl" ))
912 if (!strcmp( flag, "header" )) source->flags |= FLAG_IDL_HEADER;
913 else if (!strcmp( flag, "proxy" )) source->flags |= FLAG_IDL_PROXY;
914 else if (!strcmp( flag, "client" )) source->flags |= FLAG_IDL_CLIENT;
915 else if (!strcmp( flag, "server" )) source->flags |= FLAG_IDL_SERVER;
916 else if (!strcmp( flag, "ident" )) source->flags |= FLAG_IDL_IDENT;
917 else if (!strcmp( flag, "typelib" )) source->flags |= FLAG_IDL_TYPELIB;
918 else if (!strcmp( flag, "register" )) source->flags |= FLAG_IDL_REGISTER;
919 else if (!strcmp( flag, "regtypelib" )) source->flags |= FLAG_IDL_REGTYPELIB;
921 else if (strendswith( source->name, ".rc" ))
923 if (!strcmp( flag, "po" )) source->flags |= FLAG_RC_PO;
925 else if (strendswith( source->name, ".sfd" ))
927 if (!strcmp( flag, "font" ))
929 struct strarray *array = source->args;
931 if (!array)
933 source->args = array = xmalloc( sizeof(*array) );
934 *array = empty_strarray;
935 source->flags |= FLAG_SFD_FONTS;
937 strarray_add( array, xstrdup( strtok( NULL, "" )));
938 return;
941 else if (!strcmp( flag, "implib" )) source->flags |= FLAG_C_IMPLIB;
946 /*******************************************************************
947 * parse_cpp_directive
949 static void parse_cpp_directive( struct file *source, char *str )
951 while (*str && isspace(*str)) str++;
952 if (*str++ != '#') return;
953 while (*str && isspace(*str)) str++;
955 if (!strncmp( str, "include", 7 ))
956 parse_include_directive( source, str + 7 );
957 else if (!strncmp( str, "import", 6 ) && strendswith( source->name, ".m" ))
958 parse_include_directive( source, str + 6 );
959 else if (!strncmp( str, "pragma", 6 ))
960 parse_pragma_directive( source, str + 6 );
964 /*******************************************************************
965 * parse_idl_file
967 static void parse_idl_file( struct file *source, FILE *file )
969 char *buffer, *include;
971 input_line = 0;
973 while ((buffer = get_line( file )))
975 char quote;
976 char *p = buffer;
977 while (*p && isspace(*p)) p++;
979 if (!strncmp( p, "importlib", 9 ))
981 p += 9;
982 while (*p && isspace(*p)) p++;
983 if (*p++ != '(') continue;
984 while (*p && isspace(*p)) p++;
985 if (*p++ != '"') continue;
986 include = p;
987 while (*p && (*p != '"')) p++;
988 if (!*p) fatal_error( "malformed importlib directive\n" );
989 *p = 0;
990 add_dependency( source, include, INCL_IMPORTLIB );
991 continue;
994 if (!strncmp( p, "import", 6 ))
996 p += 6;
997 while (*p && isspace(*p)) p++;
998 if (*p != '"') continue;
999 include = ++p;
1000 while (*p && (*p != '"')) p++;
1001 if (!*p) fatal_error( "malformed import directive\n" );
1002 *p = 0;
1003 add_dependency( source, include, INCL_IMPORT );
1004 continue;
1007 /* check for #include inside cpp_quote */
1008 if (!strncmp( p, "cpp_quote", 9 ))
1010 p += 9;
1011 while (*p && isspace(*p)) p++;
1012 if (*p++ != '(') continue;
1013 while (*p && isspace(*p)) p++;
1014 if (*p++ != '"') continue;
1015 if (*p++ != '#') continue;
1016 while (*p && isspace(*p)) p++;
1017 if (strncmp( p, "include", 7 )) continue;
1018 p += 7;
1019 while (*p && isspace(*p)) p++;
1020 if (*p == '\\' && p[1] == '"')
1022 p += 2;
1023 quote = '"';
1025 else
1027 if (*p++ != '<' ) continue;
1028 quote = '>';
1030 include = p;
1031 while (*p && (*p != quote)) p++;
1032 if (!*p || (quote == '"' && p[-1] != '\\'))
1033 fatal_error( "malformed #include directive inside cpp_quote\n" );
1034 if (quote == '"') p--; /* remove backslash */
1035 *p = 0;
1036 add_dependency( source, include, (quote == '>') ? INCL_CPP_QUOTE_SYSTEM : INCL_CPP_QUOTE );
1037 continue;
1040 parse_cpp_directive( source, p );
1044 /*******************************************************************
1045 * parse_c_file
1047 static void parse_c_file( struct file *source, FILE *file )
1049 char *buffer;
1051 input_line = 0;
1052 while ((buffer = get_line( file )))
1054 parse_cpp_directive( source, buffer );
1059 /*******************************************************************
1060 * parse_rc_file
1062 static void parse_rc_file( struct file *source, FILE *file )
1064 char *buffer, *include;
1066 input_line = 0;
1067 while ((buffer = get_line( file )))
1069 char quote;
1070 char *p = buffer;
1071 while (*p && isspace(*p)) p++;
1073 if (p[0] == '/' && p[1] == '*') /* check for magic makedep comment */
1075 p += 2;
1076 while (*p && isspace(*p)) p++;
1077 if (strncmp( p, "@makedep:", 9 )) continue;
1078 p += 9;
1079 while (*p && isspace(*p)) p++;
1080 quote = '"';
1081 if (*p == quote)
1083 include = ++p;
1084 while (*p && *p != quote) p++;
1086 else
1088 include = p;
1089 while (*p && !isspace(*p) && *p != '*') p++;
1091 if (!*p)
1092 fatal_error( "malformed makedep comment\n" );
1093 *p = 0;
1094 add_dependency( source, include, (quote == '>') ? INCL_SYSTEM : INCL_NORMAL );
1095 continue;
1098 parse_cpp_directive( source, buffer );
1103 /*******************************************************************
1104 * parse_in_file
1106 static void parse_in_file( struct file *source, FILE *file )
1108 char *p, *buffer;
1110 /* make sure it gets rebuilt when the version changes */
1111 add_dependency( source, "config.h", INCL_SYSTEM );
1113 if (!strendswith( source->name, ".man.in" )) return; /* not a man page */
1115 input_line = 0;
1116 while ((buffer = get_line( file )))
1118 if (strncmp( buffer, ".TH", 3 )) continue;
1119 if (!(p = strtok( buffer, " \t" ))) continue; /* .TH */
1120 if (!(p = strtok( NULL, " \t" ))) continue; /* program name */
1121 if (!(p = strtok( NULL, " \t" ))) continue; /* man section */
1122 source->args = xstrdup( p );
1123 return;
1128 /*******************************************************************
1129 * parse_sfd_file
1131 static void parse_sfd_file( struct file *source, FILE *file )
1133 char *p, *eol, *buffer;
1135 input_line = 0;
1136 while ((buffer = get_line( file )))
1138 if (strncmp( buffer, "UComments:", 10 )) continue;
1139 p = buffer + 10;
1140 while (*p == ' ') p++;
1141 if (p[0] == '"' && p[1] && buffer[strlen(buffer) - 1] == '"')
1143 p++;
1144 buffer[strlen(buffer) - 1] = 0;
1146 while ((eol = strstr( p, "+AAoA" )))
1148 *eol = 0;
1149 while (*p && isspace(*p)) p++;
1150 if (*p++ == '#')
1152 while (*p && isspace(*p)) p++;
1153 if (!strncmp( p, "pragma", 6 )) parse_pragma_directive( source, p + 6 );
1155 p = eol + 5;
1157 while (*p && isspace(*p)) p++;
1158 if (*p++ != '#') return;
1159 while (*p && isspace(*p)) p++;
1160 if (!strncmp( p, "pragma", 6 )) parse_pragma_directive( source, p + 6 );
1161 return;
1166 static const struct
1168 const char *ext;
1169 void (*parse)( struct file *file, FILE *f );
1170 } parse_functions[] =
1172 { ".c", parse_c_file },
1173 { ".h", parse_c_file },
1174 { ".inl", parse_c_file },
1175 { ".l", parse_c_file },
1176 { ".m", parse_c_file },
1177 { ".rh", parse_c_file },
1178 { ".x", parse_c_file },
1179 { ".y", parse_c_file },
1180 { ".idl", parse_idl_file },
1181 { ".rc", parse_rc_file },
1182 { ".in", parse_in_file },
1183 { ".sfd", parse_sfd_file }
1186 /*******************************************************************
1187 * load_file
1189 static struct file *load_file( const char *name )
1191 struct file *file;
1192 FILE *f;
1193 unsigned int i, hash = hash_filename( name );
1195 LIST_FOR_EACH_ENTRY( file, &files[hash], struct file, entry )
1196 if (!strcmp( name, file->name )) return file;
1198 if (!(f = fopen( name, "r" ))) return NULL;
1200 file = add_file( name );
1201 list_add_tail( &files[hash], &file->entry );
1202 input_file_name = file->name;
1203 input_line = 0;
1205 for (i = 0; i < sizeof(parse_functions) / sizeof(parse_functions[0]); i++)
1207 if (!strendswith( name, parse_functions[i].ext )) continue;
1208 parse_functions[i].parse( file, f );
1209 break;
1212 fclose( f );
1213 input_file_name = NULL;
1215 return file;
1219 /*******************************************************************
1220 * open_include_path_file
1222 * Open a file from a directory on the include path.
1224 static struct file *open_include_path_file( const struct makefile *make, const char *dir,
1225 const char *name, char **filename )
1227 char *src_path = base_dir_path( make, concat_paths( dir, name ));
1228 struct file *ret = load_file( src_path );
1230 if (ret) *filename = src_dir_path( make, concat_paths( dir, name ));
1231 return ret;
1235 /*******************************************************************
1236 * open_file_same_dir
1238 * Open a file in the same directory as the parent.
1240 static struct file *open_file_same_dir( const struct incl_file *parent, const char *name, char **filename )
1242 char *src_path = replace_filename( parent->file->name, name );
1243 struct file *ret = load_file( src_path );
1245 if (ret) *filename = replace_filename( parent->filename, name );
1246 free( src_path );
1247 return ret;
1251 /*******************************************************************
1252 * open_local_file
1254 * Open a file in the source directory of the makefile.
1256 static struct file *open_local_file( const struct makefile *make, const char *path, char **filename )
1258 char *src_path = root_dir_path( base_dir_path( make, path ));
1259 struct file *ret = load_file( src_path );
1261 /* if not found, try parent dir */
1262 if (!ret && make->parent_dir)
1264 free( src_path );
1265 path = strmake( "%s/%s", make->parent_dir, path );
1266 src_path = root_dir_path( base_dir_path( make, path ));
1267 ret = load_file( src_path );
1270 if (ret) *filename = src_dir_path( make, path );
1271 free( src_path );
1272 return ret;
1276 /*******************************************************************
1277 * open_global_file
1279 * Open a file in the top-level source directory.
1281 static struct file *open_global_file( const struct makefile *make, const char *path, char **filename )
1283 char *src_path = root_dir_path( path );
1284 struct file *ret = load_file( src_path );
1286 if (ret) *filename = top_dir_path( make, path );
1287 free( src_path );
1288 return ret;
1292 /*******************************************************************
1293 * open_global_header
1295 * Open a file in the global include source directory.
1297 static struct file *open_global_header( const struct makefile *make, const char *path, char **filename )
1299 return open_global_file( make, strmake( "include/%s", path ), filename );
1303 /*******************************************************************
1304 * open_src_file
1306 static struct file *open_src_file( const struct makefile *make, struct incl_file *pFile )
1308 struct file *file = open_local_file( make, pFile->name, &pFile->filename );
1310 if (!file) fatal_perror( "open %s", pFile->name );
1311 return file;
1315 /*******************************************************************
1316 * open_include_file
1318 static struct file *open_include_file( const struct makefile *make, struct incl_file *pFile )
1320 struct file *file = NULL;
1321 char *filename;
1322 unsigned int i, len;
1324 errno = ENOENT;
1326 /* check for generated bison header */
1328 if (strendswith( pFile->name, ".tab.h" ) &&
1329 (file = open_local_file( make, replace_extension( pFile->name, ".tab.h", ".y" ), &filename )))
1331 pFile->sourcename = filename;
1332 pFile->filename = obj_dir_path( make, pFile->name );
1333 return file;
1336 /* check for corresponding idl file in source dir */
1338 if (strendswith( pFile->name, ".h" ) &&
1339 (file = open_local_file( make, replace_extension( pFile->name, ".h", ".idl" ), &filename )))
1341 pFile->sourcename = filename;
1342 pFile->filename = obj_dir_path( make, pFile->name );
1343 return file;
1346 /* check for corresponding tlb file in source dir */
1348 if (strendswith( pFile->name, ".tlb" ) &&
1349 (file = open_local_file( make, replace_extension( pFile->name, ".tlb", ".idl" ), &filename )))
1351 pFile->sourcename = filename;
1352 pFile->filename = obj_dir_path( make, pFile->name );
1353 return file;
1356 /* now try in source dir */
1357 if ((file = open_local_file( make, pFile->name, &pFile->filename ))) return file;
1359 /* check for corresponding idl file in global includes */
1361 if (strendswith( pFile->name, ".h" ) &&
1362 (file = open_global_header( make, replace_extension( pFile->name, ".h", ".idl" ), &filename )))
1364 pFile->sourcename = filename;
1365 pFile->filename = top_obj_dir_path( make, strmake( "include/%s", pFile->name ));
1366 return file;
1369 /* check for corresponding .in file in global includes (for config.h.in) */
1371 if (strendswith( pFile->name, ".h" ) &&
1372 (file = open_global_header( make, replace_extension( pFile->name, ".h", ".h.in" ), &filename )))
1374 pFile->sourcename = filename;
1375 pFile->filename = top_obj_dir_path( make, strmake( "include/%s", pFile->name ));
1376 return file;
1379 /* check for corresponding .x file in global includes */
1381 if (strendswith( pFile->name, "tmpl.h" ) &&
1382 (file = open_global_header( make, replace_extension( pFile->name, ".h", ".x" ), &filename )))
1384 pFile->sourcename = filename;
1385 pFile->filename = top_obj_dir_path( make, strmake( "include/%s", pFile->name ));
1386 return file;
1389 /* check for corresponding .tlb file in global includes */
1391 if (strendswith( pFile->name, ".tlb" ) &&
1392 (file = open_global_header( make, replace_extension( pFile->name, ".tlb", ".idl" ), &filename )))
1394 pFile->sourcename = filename;
1395 pFile->filename = top_obj_dir_path( make, strmake( "include/%s", pFile->name ));
1396 return file;
1399 /* check in global includes source dir */
1401 if ((file = open_global_header( make, pFile->name, &pFile->filename ))) return file;
1403 /* check in global msvcrt includes */
1404 if (make->use_msvcrt &&
1405 (file = open_global_header( make, strmake( "msvcrt/%s", pFile->name ), &pFile->filename )))
1406 return file;
1408 /* now search in include paths */
1409 for (i = 0; i < make->include_paths.count; i++)
1411 const char *dir = make->include_paths.str[i];
1412 const char *prefix = make->top_src_dir ? make->top_src_dir : make->top_obj_dir;
1414 if (prefix)
1416 len = strlen( prefix );
1417 if (!strncmp( dir, prefix, len ) && (!dir[len] || dir[len] == '/'))
1419 while (dir[len] == '/') len++;
1420 file = open_global_file( make, concat_paths( dir + len, pFile->name ), &pFile->filename );
1421 if (file) return file;
1423 if (make->top_src_dir) continue; /* ignore paths that don't point to the top source dir */
1425 if (*dir != '/')
1427 if ((file = open_include_path_file( make, dir, pFile->name, &pFile->filename )))
1428 return file;
1431 if (pFile->type == INCL_SYSTEM) return NULL; /* ignore system files we cannot find */
1433 /* try in src file directory */
1434 if ((file = open_file_same_dir( pFile->included_by, pFile->name, &pFile->filename ))) return file;
1436 fprintf( stderr, "%s:%d: error: ", pFile->included_by->file->name, pFile->included_line );
1437 perror( pFile->name );
1438 pFile = pFile->included_by;
1439 while (pFile && pFile->included_by)
1441 const char *parent = pFile->included_by->sourcename;
1442 if (!parent) parent = pFile->included_by->file->name;
1443 fprintf( stderr, "%s:%d: note: %s was first included here\n",
1444 parent, pFile->included_line, pFile->name );
1445 pFile = pFile->included_by;
1447 exit(1);
1451 /*******************************************************************
1452 * add_all_includes
1454 static void add_all_includes( struct makefile *make, struct incl_file *parent, struct file *file )
1456 unsigned int i;
1458 parent->files_count = 0;
1459 parent->files_size = file->deps_count;
1460 parent->files = xmalloc( parent->files_size * sizeof(*parent->files) );
1461 for (i = 0; i < file->deps_count; i++)
1463 switch (file->deps[i].type)
1465 case INCL_NORMAL:
1466 case INCL_IMPORT:
1467 add_include( make, parent, file->deps[i].name, file->deps[i].line, INCL_NORMAL );
1468 break;
1469 case INCL_IMPORTLIB:
1470 add_include( make, parent, file->deps[i].name, file->deps[i].line, INCL_IMPORTLIB );
1471 break;
1472 case INCL_SYSTEM:
1473 add_include( make, parent, file->deps[i].name, file->deps[i].line, INCL_SYSTEM );
1474 break;
1475 case INCL_CPP_QUOTE:
1476 case INCL_CPP_QUOTE_SYSTEM:
1477 break;
1483 /*******************************************************************
1484 * parse_file
1486 static void parse_file( struct makefile *make, struct incl_file *source, int src )
1488 struct file *file = src ? open_src_file( make, source ) : open_include_file( make, source );
1490 if (!file) return;
1492 source->file = file;
1493 source->files_count = 0;
1494 source->files_size = file->deps_count;
1495 source->files = xmalloc( source->files_size * sizeof(*source->files) );
1497 if (source->sourcename)
1499 if (strendswith( source->sourcename, ".idl" ))
1501 unsigned int i;
1503 if (strendswith( source->name, ".tlb" )) return; /* typelibs don't include anything */
1505 /* generated .h file always includes these */
1506 add_include( make, source, "rpc.h", 0, INCL_NORMAL );
1507 add_include( make, source, "rpcndr.h", 0, INCL_NORMAL );
1508 for (i = 0; i < file->deps_count; i++)
1510 switch (file->deps[i].type)
1512 case INCL_IMPORT:
1513 if (strendswith( file->deps[i].name, ".idl" ))
1514 add_include( make, source, replace_extension( file->deps[i].name, ".idl", ".h" ),
1515 file->deps[i].line, INCL_NORMAL );
1516 else
1517 add_include( make, source, file->deps[i].name, file->deps[i].line, INCL_NORMAL );
1518 break;
1519 case INCL_CPP_QUOTE:
1520 add_include( make, source, file->deps[i].name, file->deps[i].line, INCL_NORMAL );
1521 break;
1522 case INCL_CPP_QUOTE_SYSTEM:
1523 add_include( make, source, file->deps[i].name, file->deps[i].line, INCL_SYSTEM );
1524 break;
1525 case INCL_NORMAL:
1526 case INCL_SYSTEM:
1527 case INCL_IMPORTLIB:
1528 break;
1531 return;
1533 if (strendswith( source->sourcename, ".y" ))
1534 return; /* generated .tab.h doesn't include anything */
1537 add_all_includes( make, source, file );
1541 /*******************************************************************
1542 * add_src_file
1544 * Add a source file to the list.
1546 static struct incl_file *add_src_file( struct makefile *make, const char *name )
1548 struct incl_file *file;
1550 if ((file = find_src_file( make, name ))) return file; /* we already have it */
1551 file = xmalloc( sizeof(*file) );
1552 memset( file, 0, sizeof(*file) );
1553 file->name = xstrdup(name);
1554 list_add_tail( &make->sources, &file->entry );
1555 parse_file( make, file, 1 );
1556 return file;
1560 /*******************************************************************
1561 * open_input_makefile
1563 static FILE *open_input_makefile( const struct makefile *make )
1565 FILE *ret;
1567 if (make->base_dir)
1568 input_file_name = root_dir_path( base_dir_path( make, strmake( "%s.in", output_makefile_name )));
1569 else
1570 input_file_name = output_makefile_name; /* always use output name for main Makefile */
1572 input_line = 0;
1573 if (!(ret = fopen( input_file_name, "r" ))) fatal_perror( "open" );
1574 return ret;
1578 /*******************************************************************
1579 * get_make_variable
1581 static const char *get_make_variable( const struct makefile *make, const char *name )
1583 const char *ret;
1585 if ((ret = strarray_get_value( &cmdline_vars, name ))) return ret;
1586 if ((ret = strarray_get_value( &make->vars, name ))) return ret;
1587 if (top_makefile && (ret = strarray_get_value( &top_makefile->vars, name ))) return ret;
1588 return NULL;
1592 /*******************************************************************
1593 * get_expanded_make_variable
1595 static char *get_expanded_make_variable( const struct makefile *make, const char *name )
1597 const char *var;
1598 char *p, *end, *expand, *tmp;
1600 var = get_make_variable( make, name );
1601 if (!var) return NULL;
1603 p = expand = xstrdup( var );
1604 while ((p = strchr( p, '$' )))
1606 if (p[1] == '(')
1608 if (!(end = strchr( p + 2, ')' ))) fatal_error( "syntax error in '%s'\n", expand );
1609 *end++ = 0;
1610 if (strchr( p + 2, ':' )) fatal_error( "pattern replacement not supported for '%s'\n", p + 2 );
1611 var = get_make_variable( make, p + 2 );
1612 tmp = replace_substr( expand, p, end - p, var ? var : "" );
1613 /* switch to the new string */
1614 p = tmp + (p - expand);
1615 free( expand );
1616 expand = tmp;
1618 else if (p[1] == '{') /* don't expand ${} variables */
1620 if (!(end = strchr( p + 2, '}' ))) fatal_error( "syntax error in '%s'\n", expand );
1621 p = end + 1;
1623 else if (p[1] == '$')
1625 p += 2;
1627 else fatal_error( "syntax error in '%s'\n", expand );
1630 /* consider empty variables undefined */
1631 p = expand;
1632 while (*p && isspace(*p)) p++;
1633 if (*p) return expand;
1634 free( expand );
1635 return NULL;
1639 /*******************************************************************
1640 * get_expanded_make_var_array
1642 static struct strarray get_expanded_make_var_array( const struct makefile *make, const char *name )
1644 struct strarray ret = empty_strarray;
1645 char *value, *token;
1647 if ((value = get_expanded_make_variable( make, name )))
1648 for (token = strtok( value, " \t" ); token; token = strtok( NULL, " \t" ))
1649 strarray_add( &ret, token );
1650 return ret;
1654 /*******************************************************************
1655 * get_expanded_file_local_var
1657 static struct strarray get_expanded_file_local_var( const struct makefile *make, const char *file,
1658 const char *name )
1660 char *p, *var = strmake( "%s_%s", file, name );
1662 for (p = var; *p; p++) if (!isalnum( *p )) *p = '_';
1663 return get_expanded_make_var_array( make, var );
1667 /*******************************************************************
1668 * set_make_variable
1670 static int set_make_variable( struct strarray *array, const char *assignment )
1672 char *p, *name;
1674 p = name = xstrdup( assignment );
1675 while (isalnum(*p) || *p == '_') p++;
1676 if (name == p) return 0; /* not a variable */
1677 if (isspace(*p))
1679 *p++ = 0;
1680 while (isspace(*p)) p++;
1682 if (*p != '=') return 0; /* not an assignment */
1683 *p++ = 0;
1684 while (isspace(*p)) p++;
1686 strarray_set_value( array, name, p );
1687 return 1;
1691 /*******************************************************************
1692 * parse_makefile
1694 static struct makefile *parse_makefile( const char *path )
1696 char *buffer;
1697 FILE *file;
1698 struct makefile *make = xmalloc( sizeof(*make) );
1700 memset( make, 0, sizeof(*make) );
1701 if (path)
1703 make->top_obj_dir = get_relative_path( path, "" );
1704 make->base_dir = path;
1705 if (!strcmp( make->base_dir, "." )) make->base_dir = NULL;
1708 file = open_input_makefile( make );
1709 while ((buffer = get_line( file )))
1711 if (!strncmp( buffer, separator, strlen(separator) )) break;
1712 if (*buffer == '\t') continue; /* command */
1713 while (isspace( *buffer )) buffer++;
1714 if (*buffer == '#') continue; /* comment */
1715 set_make_variable( &make->vars, buffer );
1717 fclose( file );
1718 input_file_name = NULL;
1719 return make;
1723 /*******************************************************************
1724 * add_generated_sources
1726 static void add_generated_sources( struct makefile *make )
1728 struct incl_file *source, *next, *file;
1730 LIST_FOR_EACH_ENTRY_SAFE( source, next, &make->sources, struct incl_file, entry )
1732 if (source->file->flags & FLAG_IDL_CLIENT)
1734 file = add_generated_source( make, replace_extension( source->name, ".idl", "_c.c" ), NULL );
1735 add_dependency( file->file, replace_extension( source->name, ".idl", ".h" ), INCL_NORMAL );
1736 add_all_includes( make, file, file->file );
1738 if (source->file->flags & FLAG_IDL_SERVER)
1740 file = add_generated_source( make, replace_extension( source->name, ".idl", "_s.c" ), NULL );
1741 add_dependency( file->file, "wine/exception.h", INCL_NORMAL );
1742 add_dependency( file->file, replace_extension( source->name, ".idl", ".h" ), INCL_NORMAL );
1743 add_all_includes( make, file, file->file );
1745 if (source->file->flags & FLAG_IDL_IDENT)
1747 file = add_generated_source( make, replace_extension( source->name, ".idl", "_i.c" ), NULL );
1748 add_dependency( file->file, "rpc.h", INCL_NORMAL );
1749 add_dependency( file->file, "rpcndr.h", INCL_NORMAL );
1750 add_dependency( file->file, "guiddef.h", INCL_NORMAL );
1751 add_all_includes( make, file, file->file );
1753 if (source->file->flags & FLAG_IDL_PROXY)
1755 file = add_generated_source( make, "dlldata.o", "dlldata.c" );
1756 add_dependency( file->file, "objbase.h", INCL_NORMAL );
1757 add_dependency( file->file, "rpcproxy.h", INCL_NORMAL );
1758 add_all_includes( make, file, file->file );
1759 file = add_generated_source( make, replace_extension( source->name, ".idl", "_p.c" ), NULL );
1760 add_dependency( file->file, "objbase.h", INCL_NORMAL );
1761 add_dependency( file->file, "rpcproxy.h", INCL_NORMAL );
1762 add_dependency( file->file, "wine/exception.h", INCL_NORMAL );
1763 add_dependency( file->file, replace_extension( source->name, ".idl", ".h" ), INCL_NORMAL );
1764 add_all_includes( make, file, file->file );
1766 if (source->file->flags & FLAG_IDL_TYPELIB)
1768 add_generated_source( make, replace_extension( source->name, ".idl", ".tlb" ), NULL );
1770 if (source->file->flags & FLAG_IDL_REGTYPELIB)
1772 add_generated_source( make, replace_extension( source->name, ".idl", "_t.res" ), NULL );
1774 if (source->file->flags & FLAG_IDL_REGISTER)
1776 add_generated_source( make, replace_extension( source->name, ".idl", "_r.res" ), NULL );
1778 if (source->file->flags & FLAG_IDL_HEADER)
1780 add_generated_source( make, replace_extension( source->name, ".idl", ".h" ), NULL );
1782 if (!source->file->flags && strendswith( source->name, ".idl" ))
1784 add_generated_source( make, replace_extension( source->name, ".idl", ".h" ), NULL );
1786 if (strendswith( source->name, ".x" ))
1788 add_generated_source( make, replace_extension( source->name, ".x", ".h" ), NULL );
1790 if (strendswith( source->name, ".y" ))
1792 file = add_generated_source( make, replace_extension( source->name, ".y", ".tab.c" ), NULL );
1793 /* steal the includes list from the source file */
1794 file->files_count = source->files_count;
1795 file->files_size = source->files_size;
1796 file->files = source->files;
1797 source->files_count = source->files_size = 0;
1798 source->files = NULL;
1800 if (strendswith( source->name, ".l" ))
1802 file = add_generated_source( make, replace_extension( source->name, ".l", ".yy.c" ), NULL );
1803 /* steal the includes list from the source file */
1804 file->files_count = source->files_count;
1805 file->files_size = source->files_size;
1806 file->files = source->files;
1807 source->files_count = source->files_size = 0;
1808 source->files = NULL;
1810 if (source->file->flags & FLAG_C_IMPLIB)
1812 if (!make->staticimplib && make->importlib && *dll_ext)
1813 make->staticimplib = strmake( "lib%s.def.a", make->importlib );
1815 if (strendswith( source->name, ".po" ))
1817 if (!make->disabled)
1818 strarray_add_uniq( &linguas, replace_extension( source->name, ".po", "" ));
1821 if (make->testdll)
1823 file = add_generated_source( make, "testlist.o", "testlist.c" );
1824 add_dependency( file->file, "wine/test.h", INCL_NORMAL );
1825 add_all_includes( make, file, file->file );
1830 /*******************************************************************
1831 * create_dir
1833 static void create_dir( const char *dir )
1835 char *p, *path;
1837 p = path = xstrdup( dir );
1838 while ((p = strchr( p, '/' )))
1840 *p = 0;
1841 if (mkdir( path, 0755 ) == -1 && errno != EEXIST) fatal_perror( "mkdir %s", path );
1842 *p++ = '/';
1843 while (*p == '/') p++;
1845 if (mkdir( path, 0755 ) == -1 && errno != EEXIST) fatal_perror( "mkdir %s", path );
1846 free( path );
1850 /*******************************************************************
1851 * create_file_directories
1853 * Create the base directories of all the files.
1855 static void create_file_directories( const struct makefile *make, struct strarray files )
1857 struct strarray subdirs = empty_strarray;
1858 unsigned int i;
1859 char *dir;
1861 for (i = 0; i < files.count; i++)
1863 if (!strchr( files.str[i], '/' )) continue;
1864 dir = base_dir_path( make, files.str[i] );
1865 *strrchr( dir, '/' ) = 0;
1866 strarray_add_uniq( &subdirs, dir );
1869 for (i = 0; i < subdirs.count; i++) create_dir( subdirs.str[i] );
1873 /*******************************************************************
1874 * output_filenames_obj_dir
1876 static void output_filenames_obj_dir( const struct makefile *make, struct strarray array )
1878 unsigned int i;
1880 for (i = 0; i < array.count; i++) output_filename( obj_dir_path( make, array.str[i] ));
1884 /*******************************************************************
1885 * get_dependencies
1887 static void get_dependencies( struct strarray *deps, struct incl_file *file, struct incl_file *source )
1889 unsigned int i;
1891 if (!file->filename) return;
1893 if (file != source)
1895 if (file->owner == source) return; /* already processed */
1896 if (file->type == INCL_IMPORTLIB &&
1897 !(source->file->flags & (FLAG_IDL_TYPELIB | FLAG_IDL_REGTYPELIB)))
1898 return; /* library is imported only when building a typelib */
1899 file->owner = source;
1900 strarray_add( deps, file->filename );
1902 for (i = 0; i < file->files_count; i++) get_dependencies( deps, file->files[i], source );
1906 /*******************************************************************
1907 * get_local_dependencies
1909 * Get the local dependencies of a given target.
1911 static struct strarray get_local_dependencies( const struct makefile *make, const char *name,
1912 struct strarray targets )
1914 unsigned int i;
1915 struct strarray deps = get_expanded_file_local_var( make, name, "DEPS" );
1917 for (i = 0; i < deps.count; i++)
1919 if (strarray_exists( &targets, deps.str[i] ))
1920 deps.str[i] = obj_dir_path( make, deps.str[i] );
1921 else
1922 deps.str[i] = src_dir_path( make, deps.str[i] );
1924 return deps;
1928 /*******************************************************************
1929 * has_static_lib
1931 * Check if makefile builds the named static library.
1933 static int has_static_lib( const struct makefile *make, const char *name )
1935 if (!make->staticlib) return 0;
1936 if (strncmp( make->staticlib, "lib", 3 )) return 0;
1937 if (strncmp( make->staticlib + 3, name, strlen(name) )) return 0;
1938 return !strcmp( make->staticlib + 3 + strlen(name), ".a" );
1942 /*******************************************************************
1943 * add_default_libraries
1945 static struct strarray add_default_libraries( const struct makefile *make, struct strarray *deps )
1947 struct strarray ret = empty_strarray;
1948 struct strarray all_libs = empty_strarray;
1949 unsigned int i, j;
1951 strarray_add( &all_libs, "-lwine_port" );
1952 strarray_addall( &all_libs, get_expanded_make_var_array( make, "EXTRALIBS" ));
1953 strarray_addall( &all_libs, libs );
1955 for (i = 0; i < all_libs.count; i++)
1957 int found = 0;
1958 if (!strncmp( all_libs.str[i], "-l", 2 ))
1960 const char *name = all_libs.str[i] + 2;
1962 for (j = 0; j < top_makefile->subdirs.count; j++)
1964 const struct makefile *submake = top_makefile->submakes[j];
1966 if ((found = has_static_lib( submake, name )))
1968 const char *lib = strmake( "%s/lib%s.a",
1969 top_obj_dir_path( make, submake->base_dir ), name );
1970 strarray_add( deps, lib );
1971 strarray_add( &ret, lib );
1972 break;
1976 if (!found) strarray_add( &ret, all_libs.str[i] );
1978 return ret;
1982 /*******************************************************************
1983 * add_import_libs
1985 static struct strarray add_import_libs( const struct makefile *make, struct strarray *deps,
1986 struct strarray imports, int cross )
1988 struct strarray ret = empty_strarray;
1989 unsigned int i, j;
1991 for (i = 0; i < imports.count; i++)
1993 const char *name = imports.str[i];
1995 for (j = 0; j < top_makefile->subdirs.count; j++)
1997 const struct makefile *submake = top_makefile->submakes[j];
1999 if (submake->importlib && !strcmp( submake->importlib, name ))
2001 const char *dir = top_obj_dir_path( make, submake->base_dir );
2002 const char *ext = cross ? "cross.a" : *dll_ext ? "def" : "a";
2004 strarray_add( deps, strmake( "%s/lib%s.%s", dir, name, ext ));
2005 if (!cross && submake->staticimplib)
2006 strarray_add( deps, strmake( "%s/%s", dir, submake->staticimplib ));
2007 break;
2010 if (has_static_lib( submake, name ))
2012 const char *dir = top_obj_dir_path( make, submake->base_dir );
2014 strarray_add( deps, strmake( "%s/lib%s.a", dir, name ));
2015 break;
2018 strarray_add( &ret, strmake( "-l%s", name ));
2020 return ret;
2024 /*******************************************************************
2025 * get_default_imports
2027 static struct strarray get_default_imports( const struct makefile *make )
2029 struct strarray ret = empty_strarray;
2031 if (strarray_exists( &make->extradllflags, "-nodefaultlibs" )) return ret;
2032 if (strarray_exists( &make->appmode, "-mno-cygwin" )) strarray_add( &ret, "msvcrt" );
2033 if (make->is_win16) strarray_add( &ret, "kernel" );
2034 strarray_add( &ret, "kernel32" );
2035 strarray_add( &ret, "ntdll" );
2036 strarray_add( &ret, "winecrt0" );
2037 return ret;
2041 /*******************************************************************
2042 * add_install_rule
2044 static void add_install_rule( const struct makefile *make, struct strarray *install_rules,
2045 const char *target, const char *file, const char *dest )
2047 if (strarray_exists( &make->install_lib, target ))
2049 strarray_add( &install_rules[INSTALL_LIB], file );
2050 strarray_add( &install_rules[INSTALL_LIB], dest );
2052 else if (strarray_exists( &make->install_dev, target ))
2054 strarray_add( &install_rules[INSTALL_DEV], file );
2055 strarray_add( &install_rules[INSTALL_DEV], dest );
2060 /*******************************************************************
2061 * get_include_install_path
2063 * Determine the installation path for a given include file.
2065 static const char *get_include_install_path( const char *name )
2067 if (!strncmp( name, "wine/", 5 )) return name + 5;
2068 if (!strncmp( name, "msvcrt/", 7 )) return name;
2069 return strmake( "windows/%s", name );
2073 /*******************************************************************
2074 * get_shared_library_name
2076 * Determine possible names for a shared library with a version number.
2078 static struct strarray get_shared_lib_names( const char *libname )
2080 struct strarray ret = empty_strarray;
2081 const char *ext, *p;
2082 char *name, *first, *second;
2083 size_t len = 0;
2085 strarray_add( &ret, libname );
2087 for (p = libname; (p = strchr( p, '.' )); p++)
2088 if ((len = strspn( p + 1, "0123456789." ))) break;
2090 if (!len) return ret;
2091 ext = p + 1 + len;
2092 if (*ext && ext[-1] == '.') ext--;
2094 /* keep only the first group of digits */
2095 name = xstrdup( libname );
2096 first = name + (p - libname);
2097 if ((second = strchr( first + 1, '.' )))
2099 strcpy( second, ext );
2100 strarray_add( &ret, xstrdup( name ));
2102 /* now remove all digits */
2103 strcpy( first, ext );
2104 strarray_add( &ret, name );
2105 return ret;
2109 /*******************************************************************
2110 * output_install_rules
2112 * Rules are stored as a (file,dest) pair of values.
2113 * The first char of dest indicates the type of install.
2115 static struct strarray output_install_rules( const struct makefile *make, struct strarray files,
2116 const char *target, struct strarray *phony_targets )
2118 unsigned int i;
2119 char *install_sh;
2120 struct strarray uninstall = empty_strarray;
2121 struct strarray targets = empty_strarray;
2123 if (!files.count) return uninstall;
2125 for (i = 0; i < files.count; i += 2)
2126 if (strchr( "dps", files.str[i + 1][0] )) /* only for files copied from object dir */
2127 strarray_add_uniq( &targets, files.str[i] );
2129 output( "install %s::", target );
2130 output_filenames_obj_dir( make, targets );
2131 output( "\n" );
2133 install_sh = top_dir_path( make, "tools/install-sh" );
2134 for (i = 0; i < files.count; i += 2)
2136 const char *file = files.str[i];
2137 const char *dest = files.str[i + 1];
2139 switch (*dest)
2141 case 'd': /* data file */
2142 output( "\t%s -m 644 $(INSTALL_DATA_FLAGS) %s $(DESTDIR)%s\n",
2143 install_sh, obj_dir_path( make, file ), dest + 1 );
2144 break;
2145 case 'D': /* data file in source dir */
2146 output( "\t%s -m 644 $(INSTALL_DATA_FLAGS) %s $(DESTDIR)%s\n",
2147 install_sh, src_dir_path( make, file ), dest + 1 );
2148 break;
2149 case 'p': /* program file */
2150 output( "\tSTRIPPROG=\"$(STRIP)\" %s $(INSTALL_PROGRAM_FLAGS) %s $(DESTDIR)%s\n",
2151 install_sh, obj_dir_path( make, file ), dest + 1 );
2152 break;
2153 case 's': /* script */
2154 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s $(DESTDIR)%s\n",
2155 install_sh, obj_dir_path( make, file ), dest + 1 );
2156 break;
2157 case 'S': /* script in source dir */
2158 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s $(DESTDIR)%s\n",
2159 install_sh, src_dir_path( make, file ), dest + 1 );
2160 break;
2161 case 'y': /* symlink */
2162 output( "\trm -f $(DESTDIR)%s && %s %s $(DESTDIR)%s\n", dest + 1, ln_s, file, dest + 1 );
2163 break;
2164 default:
2165 assert(0);
2169 for (i = 0; i < files.count; i += 2)
2170 strarray_add( &uninstall, strmake( "$(DESTDIR)%s", files.str[i + 1] + 1 ));
2172 strarray_add_uniq( phony_targets, "install" );
2173 strarray_add_uniq( phony_targets, target );
2174 return uninstall;
2178 /*******************************************************************
2179 * output_importlib_symlinks
2181 static struct strarray output_importlib_symlinks( const struct makefile *parent,
2182 const struct makefile *make )
2184 struct strarray ret = empty_strarray;
2185 const char *dir, *lib;
2187 if (!make->module) return ret;
2188 if (!make->importlib) return ret;
2189 if (make->is_win16 && make->disabled) return ret;
2190 if (strncmp( make->base_dir, "dlls/", 5 )) return ret;
2191 if (!strcmp( make->module, make->importlib )) return ret;
2192 if (!strchr( make->importlib, '.' ) &&
2193 !strncmp( make->module, make->importlib, strlen( make->importlib )) &&
2194 !strcmp( make->module + strlen( make->importlib ), ".dll" ))
2195 return ret;
2197 dir = obj_dir_path( parent, "dlls" );
2198 lib = strmake( "lib%s.%s", make->importlib, *dll_ext ? "def" : "a" );
2199 output( "%s/%s: %s\n", dir, lib, base_dir_path( make, lib ));
2200 output( "\trm -f $@ && %s %s/%s $@\n", ln_s, make->base_dir + strlen("dlls/"), lib );
2201 strarray_add( &ret, strmake( "%s/%s", dir, lib ));
2203 if (crosstarget && !make->is_win16)
2205 lib = strmake( "lib%s.cross.a", make->importlib );
2206 output( "%s/%s: %s\n", dir, lib, base_dir_path( make, lib ));
2207 output( "\trm -f $@ && %s %s/%s $@\n", ln_s, make->base_dir + strlen("dlls/"), lib );
2208 strarray_add( &ret, strmake( "%s/%s", dir, lib ));
2210 return ret;
2214 /*******************************************************************
2215 * output_po_files
2217 static void output_po_files( const struct makefile *make )
2219 const char *po_dir = src_dir_path( make, "po" );
2220 struct strarray pot_files = empty_strarray;
2221 struct incl_file *source;
2222 unsigned int i;
2224 for (i = 0; i < make->subdirs.count; i++)
2226 struct makefile *submake = make->submakes[i];
2228 LIST_FOR_EACH_ENTRY( source, &submake->sources, struct incl_file, entry )
2230 if (strendswith( source->name, ".rc" ) && (source->file->flags & FLAG_RC_PO))
2232 char *pot_file = replace_extension( source->name, ".rc", ".pot" );
2233 char *pot_path = base_dir_path( submake, pot_file );
2234 output( "%s: tools/wrc include dummy\n", pot_path );
2235 output( "\t@cd %s && $(MAKE) %s\n", base_dir_path( submake, "" ), pot_file );
2236 strarray_add( &pot_files, pot_path );
2238 else if (strendswith( source->name, ".mc" ))
2240 char *pot_file = replace_extension( source->name, ".mc", ".pot" );
2241 char *pot_path = base_dir_path( submake, pot_file );
2242 output( "%s: tools/wmc include dummy\n", pot_path );
2243 output( "\t@cd %s && $(MAKE) %s\n", base_dir_path( submake, "" ), pot_file );
2244 strarray_add( &pot_files, pot_path );
2248 if (linguas.count)
2250 for (i = 0; i < linguas.count; i++)
2251 output_filename( strmake( "%s/%s.po", po_dir, linguas.str[i] ));
2252 output( ": %s/wine.pot\n", po_dir );
2253 output( "\tmsgmerge --previous -q $@ %s/wine.pot | msgattrib --no-obsolete -o $@.new && mv $@.new $@\n",
2254 po_dir );
2255 output( "po:" );
2256 for (i = 0; i < linguas.count; i++)
2257 output_filename( strmake( "%s/%s.po", po_dir, linguas.str[i] ));
2258 output( "\n" );
2260 output( "%s/wine.pot:", po_dir );
2261 output_filenames( pot_files );
2262 output( "\n" );
2263 output( "\tmsgcat -o $@" );
2264 output_filenames( pot_files );
2265 output( "\n" );
2269 /*******************************************************************
2270 * output_sources
2272 static struct strarray output_sources( const struct makefile *make )
2274 struct incl_file *source;
2275 unsigned int i, j;
2276 struct strarray object_files = empty_strarray;
2277 struct strarray crossobj_files = empty_strarray;
2278 struct strarray res_files = empty_strarray;
2279 struct strarray clean_files = empty_strarray;
2280 struct strarray uninstall_files = empty_strarray;
2281 struct strarray mo_files = empty_strarray;
2282 struct strarray ok_files = empty_strarray;
2283 struct strarray in_files = empty_strarray;
2284 struct strarray dlldata_files = empty_strarray;
2285 struct strarray c2man_files = empty_strarray;
2286 struct strarray implib_objs = empty_strarray;
2287 struct strarray includes = empty_strarray;
2288 struct strarray phony_targets = empty_strarray;
2289 struct strarray all_targets = empty_strarray;
2290 struct strarray install_rules[NB_INSTALL_RULES];
2291 char *ldrpath_local = get_expanded_make_variable( make, "LDRPATH_LOCAL" );
2292 char *ldrpath_install = get_expanded_make_variable( make, "LDRPATH_INSTALL" );
2294 for (i = 0; i < NB_INSTALL_RULES; i++) install_rules[i] = empty_strarray;
2296 for (i = 0; i < linguas.count; i++)
2297 strarray_add( &mo_files, strmake( "%s/%s.mo", top_obj_dir_path( make, "po" ), linguas.str[i] ));
2299 strarray_add( &phony_targets, "all" );
2300 strarray_add( &includes, strmake( "-I%s", obj_dir_path( make, "" )));
2301 if (make->src_dir) strarray_add( &includes, strmake( "-I%s", make->src_dir ));
2302 if (make->parent_dir) strarray_add( &includes, strmake( "-I%s", src_dir_path( make, make->parent_dir )));
2303 strarray_add( &includes, strmake( "-I%s", top_obj_dir_path( make, "include" )));
2304 if (make->top_src_dir) strarray_add( &includes, strmake( "-I%s", top_dir_path( make, "include" )));
2305 if (make->use_msvcrt) strarray_add( &includes, strmake( "-I%s", top_dir_path( make, "include/msvcrt" )));
2306 for (i = 0; i < make->include_paths.count; i++)
2307 strarray_add( &includes, strmake( "-I%s", obj_dir_path( make, make->include_paths.str[i] )));
2309 LIST_FOR_EACH_ENTRY( source, &make->sources, struct incl_file, entry )
2311 struct strarray dependencies = empty_strarray;
2312 struct strarray extradefs;
2313 char *obj = xstrdup( source->name );
2314 char *ext = get_extension( obj );
2316 if (!ext) fatal_error( "unsupported file type %s\n", source->name );
2317 *ext++ = 0;
2319 extradefs = get_expanded_file_local_var( make, obj, "EXTRADEFS" );
2320 get_dependencies( &dependencies, source, source );
2322 if (!strcmp( ext, "y" )) /* yacc file */
2324 /* add source file dependency for parallel makes */
2325 char *header = strmake( "%s.tab.h", obj );
2327 if (find_include_file( make, header ))
2329 output( "%s: %s\n", obj_dir_path( make, header ), source->filename );
2330 output( "\t$(BISON) -p %s_ -o %s.tab.c -d %s\n",
2331 obj, obj_dir_path( make, obj ), source->filename );
2332 output( "%s.tab.c: %s %s\n", obj_dir_path( make, obj ),
2333 source->filename, obj_dir_path( make, header ));
2334 strarray_add( &clean_files, header );
2336 else output( "%s.tab.c: %s\n", obj, source->filename );
2338 output( "\t$(BISON) -p %s_ -o $@ %s\n", obj, source->filename );
2340 else if (!strcmp( ext, "x" )) /* template file */
2342 output( "%s.h: %s%s %s\n", obj_dir_path( make, obj ),
2343 tools_dir_path( make, "make_xftmpl" ), tools_ext, source->filename );
2344 output( "\t%s%s -H -o $@ %s\n",
2345 tools_dir_path( make, "make_xftmpl" ), tools_ext, source->filename );
2346 if (source->file->flags & FLAG_INSTALL)
2348 strarray_add( &install_rules[INSTALL_DEV], source->name );
2349 strarray_add( &install_rules[INSTALL_DEV],
2350 strmake( "D$(includedir)/%s", get_include_install_path( source->name ) ));
2351 strarray_add( &install_rules[INSTALL_DEV], strmake( "%s.h", obj ));
2352 strarray_add( &install_rules[INSTALL_DEV],
2353 strmake( "d$(includedir)/%s.h", get_include_install_path( obj ) ));
2356 else if (!strcmp( ext, "l" )) /* lex file */
2358 output( "%s.yy.c: %s\n", obj_dir_path( make, obj ), source->filename );
2359 output( "\t$(FLEX) -o$@ %s\n", source->filename );
2361 else if (!strcmp( ext, "rc" )) /* resource file */
2363 strarray_add( &res_files, strmake( "%s.res", obj ));
2364 output( "%s.res: %s\n", obj_dir_path( make, obj ), source->filename );
2365 output( "\t%s -o $@", tools_path( make, "wrc" ) );
2366 if (make->is_win16) output_filename( "-m16" );
2367 else output_filenames( target_flags );
2368 output_filename( "--nostdinc" );
2369 output_filenames( includes );
2370 output_filenames( make->define_args );
2371 output_filenames( extradefs );
2372 if (mo_files.count && (source->file->flags & FLAG_RC_PO))
2374 output_filename( strmake( "--po-dir=%s", top_obj_dir_path( make, "po" )));
2375 output_filename( source->filename );
2376 output( "\n" );
2377 output( "%s.res:", obj_dir_path( make, obj ));
2378 output_filenames( mo_files );
2379 output( "\n" );
2381 else
2383 output_filename( source->filename );
2384 output( "\n" );
2386 if (source->file->flags & FLAG_RC_PO)
2388 strarray_add( &clean_files, strmake( "%s.pot", obj ));
2389 output( "%s.pot: %s\n", obj_dir_path( make, obj ), source->filename );
2390 output( "\t%s -O pot -o $@", tools_path( make, "wrc" ) );
2391 if (make->is_win16) output_filename( "-m16" );
2392 else output_filenames( target_flags );
2393 output_filename( "--nostdinc" );
2394 output_filenames( includes );
2395 output_filenames( make->define_args );
2396 output_filenames( extradefs );
2397 output_filename( source->filename );
2398 output( "\n" );
2399 output( "%s.pot ", obj_dir_path( make, obj ));
2401 output( "%s.res:", obj_dir_path( make, obj ));
2402 output_filename( tools_path( make, "wrc" ));
2403 output_filenames( dependencies );
2404 output( "\n" );
2406 else if (!strcmp( ext, "mc" )) /* message file */
2408 strarray_add( &res_files, strmake( "%s.res", obj ));
2409 strarray_add( &clean_files, strmake( "%s.pot", obj ));
2410 output( "%s.res: %s\n", obj_dir_path( make, obj ), source->filename );
2411 output( "\t%s -U -O res -o $@ %s", tools_path( make, "wmc" ), source->filename );
2412 if (mo_files.count)
2414 output_filename( strmake( "--po-dir=%s", top_obj_dir_path( make, "po" )));
2415 output( "\n" );
2416 output( "%s.res:", obj_dir_path( make, obj ));
2417 output_filenames( mo_files );
2419 output( "\n" );
2420 output( "%s.pot: %s\n", obj_dir_path( make, obj ), source->filename );
2421 output( "\t%s -O pot -o $@ %s", tools_path( make, "wmc" ), source->filename );
2422 output( "\n" );
2423 output( "%s.pot %s.res:", obj_dir_path( make, obj ), obj_dir_path( make, obj ));
2424 output_filename( tools_path( make, "wmc" ));
2425 output_filenames( dependencies );
2426 output( "\n" );
2428 else if (!strcmp( ext, "idl" )) /* IDL file */
2430 struct strarray targets = empty_strarray;
2431 char *dest;
2433 if (!source->file->flags) source->file->flags |= FLAG_IDL_HEADER | FLAG_INSTALL;
2434 if (find_include_file( make, strmake( "%s.h", obj ))) source->file->flags |= FLAG_IDL_HEADER;
2436 for (i = 0; i < sizeof(idl_outputs) / sizeof(idl_outputs[0]); i++)
2438 if (!(source->file->flags & idl_outputs[i].flag)) continue;
2439 dest = strmake( "%s%s", obj, idl_outputs[i].ext );
2440 if (!find_src_file( make, dest )) strarray_add( &clean_files, dest );
2441 strarray_add( &targets, dest );
2443 if (source->file->flags & FLAG_IDL_PROXY) strarray_add( &dlldata_files, source->name );
2444 if (source->file->flags & FLAG_INSTALL)
2446 strarray_add( &install_rules[INSTALL_DEV], xstrdup( source->name ));
2447 strarray_add( &install_rules[INSTALL_DEV],
2448 strmake( "D$(includedir)/%s.idl", get_include_install_path( obj ) ));
2449 if (source->file->flags & FLAG_IDL_HEADER)
2451 strarray_add( &install_rules[INSTALL_DEV], strmake( "%s.h", obj ));
2452 strarray_add( &install_rules[INSTALL_DEV],
2453 strmake( "d$(includedir)/%s.h", get_include_install_path( obj ) ));
2456 if (!targets.count) continue;
2457 output_filenames_obj_dir( make, targets );
2458 output( ": %s\n", tools_path( make, "widl" ));
2459 output( "\t%s -o $@", tools_path( make, "widl" ) );
2460 output_filenames( target_flags );
2461 output_filenames( includes );
2462 output_filenames( make->define_args );
2463 output_filenames( extradefs );
2464 output_filenames( get_expanded_make_var_array( make, "EXTRAIDLFLAGS" ));
2465 output_filename( source->filename );
2466 output( "\n" );
2467 output_filenames_obj_dir( make, targets );
2468 output( ": %s", source->filename );
2469 output_filenames( dependencies );
2470 output( "\n" );
2472 else if (!strcmp( ext, "in" )) /* .in file or man page */
2474 if (strendswith( obj, ".man" ) && source->file->args)
2476 struct strarray symlinks;
2477 char *dir, *dest = replace_extension( obj, ".man", "" );
2478 char *lang = strchr( dest, '.' );
2479 char *section = source->file->args;
2480 if (lang)
2482 *lang++ = 0;
2483 dir = strmake( "$(mandir)/%s/man%s", lang, section );
2485 else dir = strmake( "$(mandir)/man%s", section );
2486 add_install_rule( make, install_rules, dest, xstrdup(obj),
2487 strmake( "d%s/%s.%s", dir, dest, section ));
2488 symlinks = get_expanded_file_local_var( make, dest, "SYMLINKS" );
2489 for (i = 0; i < symlinks.count; i++)
2490 add_install_rule( make, install_rules, symlinks.str[i],
2491 strmake( "%s.%s", dest, section ),
2492 strmake( "y%s/%s.%s", dir, symlinks.str[i], section ));
2493 free( dest );
2494 free( dir );
2496 strarray_add( &in_files, xstrdup(obj) );
2497 strarray_add( &all_targets, xstrdup(obj) );
2498 output( "%s: %s\n", obj_dir_path( make, obj ), source->filename );
2499 output( "\t$(SED_CMD) %s >$@ || (rm -f $@ && false)\n", source->filename );
2500 output( "%s:", obj_dir_path( make, obj ));
2501 output_filenames( dependencies );
2502 output( "\n" );
2503 add_install_rule( make, install_rules, obj, xstrdup( obj ),
2504 strmake( "d$(datadir)/wine/%s", obj ));
2506 else if (!strcmp( ext, "sfd" )) /* font file */
2508 char *ttf_file = src_dir_path( make, strmake( "%s.ttf", obj ));
2509 if (fontforge && !make->src_dir)
2511 output( "%s: %s\n", ttf_file, source->filename );
2512 output( "\t%s -script %s %s $@\n",
2513 fontforge, top_dir_path( make, "fonts/genttf.ff" ), source->filename );
2514 if (!(source->file->flags & FLAG_SFD_FONTS)) output( "all: %s\n", ttf_file );
2516 if (source->file->flags & FLAG_INSTALL)
2518 strarray_add( &install_rules[INSTALL_LIB], strmake( "%s.ttf", obj ));
2519 strarray_add( &install_rules[INSTALL_LIB], strmake( "D$(fontdir)/%s.ttf", obj ));
2521 if (source->file->flags & FLAG_SFD_FONTS)
2523 struct strarray *array = source->file->args;
2525 for (i = 0; i < array->count; i++)
2527 char *font = strtok( xstrdup(array->str[i]), " \t" );
2528 char *args = strtok( NULL, "" );
2530 strarray_add( &all_targets, xstrdup( font ));
2531 output( "%s: %s %s\n", obj_dir_path( make, font ),
2532 tools_path( make, "sfnt2fon" ), ttf_file );
2533 output( "\t%s -o $@ %s %s\n", tools_path( make, "sfnt2fon" ), ttf_file, args );
2534 strarray_add( &install_rules[INSTALL_LIB], xstrdup(font) );
2535 strarray_add( &install_rules[INSTALL_LIB], strmake( "d$(fontdir)/%s", font ));
2539 else if (!strcmp( ext, "svg" )) /* svg file */
2541 if (convert && rsvg && icotool && !make->src_dir)
2543 output( "%s.ico %s.bmp: %s\n",
2544 src_dir_path( make, obj ), src_dir_path( make, obj ), source->filename );
2545 output( "\tCONVERT=\"%s\" ICOTOOL=\"%s\" RSVG=\"%s\" %s %s $@\n", convert, icotool, rsvg,
2546 top_dir_path( make, "tools/buildimage" ), source->filename );
2549 else if (!strcmp( ext, "po" )) /* po file */
2551 output( "%s.mo: %s\n", obj_dir_path( make, obj ), source->filename );
2552 output( "\t%s -o $@ %s\n", msgfmt, source->filename );
2553 strarray_add( &all_targets, strmake( "%s.mo", obj ));
2555 else if (!strcmp( ext, "res" ))
2557 strarray_add( &res_files, source->name );
2559 else if (!strcmp( ext, "tlb" ))
2561 strarray_add( &all_targets, source->name );
2563 else if (!strcmp( ext, "h" ) || !strcmp( ext, "rh" ) || !strcmp( ext, "inl" )) /* header file */
2565 if (source->file->flags & FLAG_GENERATED)
2567 strarray_add( &all_targets, source->name );
2569 else
2571 strarray_add( &install_rules[INSTALL_DEV], source->name );
2572 strarray_add( &install_rules[INSTALL_DEV],
2573 strmake( "D$(includedir)/%s", get_include_install_path( source->name ) ));
2576 else
2578 int need_cross = make->testdll ||
2579 (source->file->flags & FLAG_C_IMPLIB) ||
2580 (make->module && make->staticlib);
2582 if ((source->file->flags & FLAG_GENERATED) &&
2583 (!make->testdll || !strendswith( source->filename, "testlist.c" )))
2584 strarray_add( &clean_files, source->filename );
2585 if (source->file->flags & FLAG_C_IMPLIB) strarray_add( &implib_objs, strmake( "%s.o", obj ));
2586 strarray_add( &object_files, strmake( "%s.o", obj ));
2587 output( "%s.o: %s\n", obj_dir_path( make, obj ), source->filename );
2588 output( "\t$(CC) -c -o $@ %s", source->filename );
2589 output_filenames( includes );
2590 output_filenames( make->define_args );
2591 output_filenames( extradefs );
2592 if (make->module || make->staticlib || make->sharedlib || make->testdll)
2594 output_filenames( dll_flags );
2595 if (make->use_msvcrt) output_filenames( msvcrt_flags );
2597 output_filenames( extra_cflags );
2598 output_filenames( cpp_flags );
2599 output_filename( "$(CFLAGS)" );
2600 output( "\n" );
2601 if (crosstarget && need_cross)
2603 strarray_add( &crossobj_files, strmake( "%s.cross.o", obj ));
2604 output( "%s.cross.o: %s\n", obj_dir_path( make, obj ), source->filename );
2605 output( "\t$(CROSSCC) -c -o $@ %s", source->filename );
2606 output_filenames( includes );
2607 output_filenames( make->define_args );
2608 output_filenames( extradefs );
2609 output_filename( "-DWINE_CROSSTEST" );
2610 output_filenames( cpp_flags );
2611 output_filename( "$(CFLAGS)" );
2612 output( "\n" );
2614 if (make->testdll && !strcmp( ext, "c" ) && !(source->file->flags & FLAG_GENERATED))
2616 strarray_add( &ok_files, strmake( "%s.ok", obj ));
2617 output( "%s.ok:\n", obj_dir_path( make, obj ));
2618 output( "\t%s $(RUNTESTFLAGS) -T %s -M %s -p %s%s %s && touch $@\n",
2619 top_dir_path( make, "tools/runtest" ), top_obj_dir_path( make, "" ), make->testdll,
2620 replace_extension( make->testdll, ".dll", "_test.exe" ), dll_ext, obj );
2622 if (!strcmp( ext, "c" ) && !(source->file->flags & FLAG_GENERATED))
2623 strarray_add( &c2man_files, source->filename );
2624 output( "%s.o", obj_dir_path( make, obj ));
2625 if (crosstarget && need_cross) output( " %s.cross.o", obj_dir_path( make, obj ));
2626 output( ":" );
2627 output_filenames( dependencies );
2628 output( "\n" );
2630 free( obj );
2633 /* rules for files that depend on multiple sources */
2635 if (dlldata_files.count)
2637 output( "%s: %s %s\n", obj_dir_path( make, "dlldata.c" ),
2638 tools_path( make, "widl" ), src_dir_path( make, "Makefile.in" ));
2639 output( "\t%s --dlldata-only -o $@", tools_path( make, "widl" ));
2640 output_filenames( dlldata_files );
2641 output( "\n" );
2644 if (make->module && !make->staticlib)
2646 struct strarray all_libs = empty_strarray;
2647 struct strarray dep_libs = empty_strarray;
2648 char *module_path = obj_dir_path( make, make->module );
2649 char *spec_file = NULL;
2651 if (!make->appmode.count)
2652 spec_file = src_dir_path( make, replace_extension( make->module, ".dll", ".spec" ));
2653 strarray_addall( &all_libs, add_import_libs( make, &dep_libs, make->delayimports, 0 ));
2654 strarray_addall( &all_libs, add_import_libs( make, &dep_libs, make->imports, 0 ));
2655 add_import_libs( make, &dep_libs, get_default_imports( make ), 0 ); /* dependencies only */
2656 strarray_addall( &all_libs, add_default_libraries( make, &dep_libs ));
2658 if (*dll_ext)
2660 for (i = 0; i < make->delayimports.count; i++)
2661 strarray_add( &all_libs, strmake( "-Wb,-d%s", make->delayimports.str[i] ));
2662 strarray_add( &all_targets, strmake( "%s%s", make->module, dll_ext ));
2663 strarray_add( &all_targets, strmake( "%s.fake", make->module ));
2664 add_install_rule( make, install_rules, make->module, strmake( "%s%s", make->module, dll_ext ),
2665 strmake( "p$(dlldir)/%s%s", make->module, dll_ext ));
2666 add_install_rule( make, install_rules, make->module, strmake( "%s.fake", make->module ),
2667 strmake( "d$(fakedlldir)/%s", make->module ));
2668 output( "%s%s %s.fake:", module_path, dll_ext, module_path );
2670 else
2672 strarray_add( &all_libs, "-lwine" );
2673 strarray_add( &all_targets, make->module );
2674 add_install_rule( make, install_rules, make->module, make->module,
2675 strmake( "p$(%s)/%s", spec_file ? "dlldir" : "bindir", make->module ));
2676 output( "%s:", module_path );
2678 if (spec_file) output_filename( spec_file );
2679 output_filenames_obj_dir( make, object_files );
2680 output_filenames_obj_dir( make, res_files );
2681 output_filenames( dep_libs );
2682 output( "\n" );
2683 output( "\t%s -o $@", tools_path( make, "winegcc" ));
2684 output_filename( strmake( "-B%s", tools_dir_path( make, "winebuild" )));
2685 if (tools_dir) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make, "" )));
2686 output_filenames( target_flags );
2687 output_filenames( unwind_flags );
2688 if (spec_file)
2690 output( " -shared %s", spec_file );
2691 output_filenames( make->extradllflags );
2693 else output_filenames( make->appmode );
2694 output_filenames_obj_dir( make, object_files );
2695 output_filenames_obj_dir( make, res_files );
2696 output_filenames( all_libs );
2697 output_filename( "$(LDFLAGS)" );
2698 output( "\n" );
2700 if (spec_file && make->importlib)
2702 char *importlib_path = obj_dir_path( make, strmake( "lib%s", make->importlib ));
2703 if (*dll_ext)
2705 strarray_add( &clean_files, strmake( "lib%s.def", make->importlib ));
2706 output( "%s.def: %s %s\n", importlib_path, tools_path( make, "winebuild" ), spec_file );
2707 output( "\t%s -w --def -o $@ --export %s", tools_path( make, "winebuild" ), spec_file );
2708 output_filenames( target_flags );
2709 if (make->is_win16) output_filename( "-m16" );
2710 output( "\n" );
2711 add_install_rule( make, install_rules, make->importlib,
2712 strmake( "lib%s.def", make->importlib ),
2713 strmake( "d$(dlldir)/lib%s.def", make->importlib ));
2714 if (implib_objs.count)
2716 strarray_add( &clean_files, strmake( "lib%s.def.a", make->importlib ));
2717 output( "%s.def.a:", importlib_path );
2718 output_filenames_obj_dir( make, implib_objs );
2719 output( "\n" );
2720 output( "\trm -f $@\n" );
2721 output( "\t$(AR) $(ARFLAGS) $@" );
2722 output_filenames_obj_dir( make, implib_objs );
2723 output( "\n" );
2724 output( "\t$(RANLIB) $@\n" );
2725 add_install_rule( make, install_rules, make->importlib,
2726 strmake( "lib%s.def.a", make->importlib ),
2727 strmake( "d$(dlldir)/lib%s.def.a", make->importlib ));
2730 else
2732 strarray_add( &clean_files, strmake( "lib%s.a", make->importlib ));
2733 output( "%s.a: %s %s", importlib_path, tools_path( make, "winebuild" ), spec_file );
2734 output_filenames_obj_dir( make, implib_objs );
2735 output( "\n" );
2736 output( "\t%s -w --implib -o $@ --export %s", tools_path( make, "winebuild" ), spec_file );
2737 output_filenames( target_flags );
2738 output_filenames_obj_dir( make, implib_objs );
2739 output( "\n" );
2740 add_install_rule( make, install_rules, make->importlib,
2741 strmake( "lib%s.a", make->importlib ),
2742 strmake( "d$(dlldir)/lib%s.a", make->importlib ));
2744 if (crosstarget && !make->is_win16)
2746 struct strarray cross_files = strarray_replace_extension( &implib_objs, ".o", ".cross.o" );
2747 strarray_add( &clean_files, strmake( "lib%s.cross.a", make->importlib ));
2748 output( "%s.cross.a: %s %s", importlib_path, tools_path( make, "winebuild" ), spec_file );
2749 output_filenames_obj_dir( make, cross_files );
2750 output( "\n" );
2751 output( "\t%s -b %s -w --implib -o $@ --export %s",
2752 tools_path( make, "winebuild" ), crosstarget, spec_file );
2753 output_filenames_obj_dir( make, cross_files );
2754 output( "\n" );
2758 if (spec_file)
2760 if (c2man_files.count)
2762 output( "manpages::\n" );
2763 output( "\t%s -w %s", top_dir_path( make, "tools/c2man.pl" ), spec_file );
2764 output_filename( strmake( "-R%s", top_dir_path( make, "" )));
2765 output_filename( strmake( "-I%s", top_dir_path( make, "include" )));
2766 output_filename( strmake( "-o %s/man%s",
2767 top_obj_dir_path( make, "documentation" ), man_ext ));
2768 output_filenames( c2man_files );
2769 output( "\n" );
2770 output( "htmlpages::\n" );
2771 output( "\t%s -Th -w %s", top_dir_path( make, "tools/c2man.pl" ), spec_file );
2772 output_filename( strmake( "-R%s", top_dir_path( make, "" )));
2773 output_filename( strmake( "-I%s", top_dir_path( make, "include" )));
2774 output_filename( strmake( "-o %s",
2775 top_obj_dir_path( make, "documentation/html" )));
2776 output_filenames( c2man_files );
2777 output( "\n" );
2778 output( "sgmlpages::\n" );
2779 output( "\t%s -Ts -w %s", top_dir_path( make, "tools/c2man.pl" ), spec_file );
2780 output_filename( strmake( "-R%s", top_dir_path( make, "" )));
2781 output_filename( strmake( "-I%s", top_dir_path( make, "include" )));
2782 output_filename( strmake( "-o %s",
2783 top_obj_dir_path( make, "documentation/api-guide" )));
2784 output_filenames( c2man_files );
2785 output( "\n" );
2786 output( "xmlpages::\n" );
2787 output( "\t%s -Tx -w %s", top_dir_path( make, "tools/c2man.pl" ), spec_file );
2788 output_filename( strmake( "-R%s", top_dir_path( make, "" )));
2789 output_filename( strmake( "-I%s", top_dir_path( make, "include" )));
2790 output_filename( strmake( "-o %s",
2791 top_obj_dir_path( make, "documentation/api-guide-xml" )));
2792 output_filenames( c2man_files );
2793 output( "\n" );
2794 strarray_add( &phony_targets, "manpages" );
2795 strarray_add( &phony_targets, "htmlpages" );
2796 strarray_add( &phony_targets, "sgmlpages" );
2797 strarray_add( &phony_targets, "xmlpages" );
2799 else output( "manpages htmlpages sgmlpages xmlpages::\n" );
2801 else if (*dll_ext)
2803 char *binary = replace_extension( make->module, ".exe", "" );
2804 add_install_rule( make, install_rules, binary, tools_dir_path( make, "wineapploader" ),
2805 strmake( "s$(bindir)/%s", binary ));
2809 if (make->staticlib)
2811 strarray_add( &all_targets, make->staticlib );
2812 output( "%s:", obj_dir_path( make, make->staticlib ));
2813 output_filenames_obj_dir( make, object_files );
2814 output( "\n\trm -f $@\n" );
2815 output( "\t$(AR) $(ARFLAGS) $@" );
2816 output_filenames_obj_dir( make, object_files );
2817 output( "\n\t$(RANLIB) $@\n" );
2818 if (crosstarget && make->module)
2820 char *name = replace_extension( make->staticlib, ".a", ".cross.a" );
2822 strarray_add( &all_targets, name );
2823 output( "%s:", obj_dir_path( make, name ));
2824 output_filenames_obj_dir( make, crossobj_files );
2825 output( "\n\trm -f $@\n" );
2826 output( "\t%s-ar $(ARFLAGS) $@", crosstarget );
2827 output_filenames_obj_dir( make, crossobj_files );
2828 output( "\n\t%s-ranlib $@\n", crosstarget );
2832 if (make->sharedlib)
2834 char *basename, *p;
2835 struct strarray names = get_shared_lib_names( make->sharedlib );
2836 struct strarray all_libs = empty_strarray;
2837 struct strarray dep_libs = empty_strarray;
2839 basename = xstrdup( make->sharedlib );
2840 if ((p = strchr( basename, '.' ))) *p = 0;
2842 strarray_addall( &dep_libs, get_local_dependencies( make, basename, in_files ));
2843 strarray_addall( &all_libs, get_expanded_file_local_var( make, basename, "LDFLAGS" ));
2844 strarray_addall( &all_libs, add_default_libraries( make, &dep_libs ));
2846 output( "%s:", obj_dir_path( make, make->sharedlib ));
2847 output_filenames_obj_dir( make, object_files );
2848 output_filenames( dep_libs );
2849 output( "\n" );
2850 output( "\t$(CC) -o $@" );
2851 output_filenames_obj_dir( make, object_files );
2852 output_filenames( all_libs );
2853 output_filename( "$(LDFLAGS)" );
2854 output( "\n" );
2855 add_install_rule( make, install_rules, make->sharedlib, make->sharedlib,
2856 strmake( "p$(libdir)/%s", make->sharedlib ));
2857 for (i = 1; i < names.count; i++)
2859 output( "%s: %s\n", obj_dir_path( make, names.str[i] ), obj_dir_path( make, names.str[i-1] ));
2860 output( "\trm -f $@ && %s %s $@\n", ln_s, names.str[i-1] );
2861 add_install_rule( make, install_rules, names.str[i], names.str[i-1],
2862 strmake( "y$(libdir)/%s", names.str[i] ));
2864 strarray_addall( &all_targets, names );
2867 if (make->importlib && !make->module) /* stand-alone import lib (for libwine) */
2869 char *def_file = replace_extension( make->importlib, ".a", ".def" );
2871 if (!strncmp( def_file, "lib", 3 )) def_file += 3;
2872 output( "%s: %s\n", obj_dir_path( make, make->importlib ), src_dir_path( make, def_file ));
2873 output( "\t%s -l $@ -d %s\n", dlltool, src_dir_path( make, def_file ));
2874 add_install_rule( make, install_rules, make->importlib, make->importlib,
2875 strmake( "d$(libdir)/%s", make->importlib ));
2876 strarray_add( &all_targets, make->importlib );
2879 if (make->testdll)
2881 char *testmodule = replace_extension( make->testdll, ".dll", "_test.exe" );
2882 char *stripped = replace_extension( make->testdll, ".dll", "_test-stripped.exe" );
2883 char *testres = replace_extension( make->testdll, ".dll", "_test.res" );
2884 struct strarray dep_libs = empty_strarray;
2885 struct strarray all_libs = add_import_libs( make, &dep_libs, make->imports, 0 );
2887 add_import_libs( make, &dep_libs, get_default_imports( make ), 0 ); /* dependencies only */
2888 strarray_addall( &all_libs, libs );
2889 strarray_add( &all_targets, strmake( "%s%s", testmodule, dll_ext ));
2890 strarray_add( &clean_files, strmake( "%s%s", stripped, dll_ext ));
2891 output( "%s%s:\n", obj_dir_path( make, testmodule ), dll_ext );
2892 output( "\t%s -o $@", tools_path( make, "winegcc" ));
2893 output_filename( strmake( "-B%s", tools_dir_path( make, "winebuild" )));
2894 if (tools_dir) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make, "" )));
2895 output_filenames( target_flags );
2896 output_filenames( unwind_flags );
2897 output_filenames( make->appmode );
2898 output_filenames_obj_dir( make, object_files );
2899 output_filenames_obj_dir( make, res_files );
2900 output_filenames( all_libs );
2901 output_filename( "$(LDFLAGS)" );
2902 output( "\n" );
2903 output( "%s%s:\n", obj_dir_path( make, stripped ), dll_ext );
2904 output( "\t%s -o $@", tools_path( make, "winegcc" ));
2905 output_filename( strmake( "-B%s", tools_dir_path( make, "winebuild" )));
2906 if (tools_dir) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make, "" )));
2907 output_filenames( target_flags );
2908 output_filenames( unwind_flags );
2909 output_filename( strmake( "-Wb,-F,%s", testmodule ));
2910 output_filenames( make->appmode );
2911 output_filenames_obj_dir( make, object_files );
2912 output_filenames_obj_dir( make, res_files );
2913 output_filenames( all_libs );
2914 output_filename( "$(LDFLAGS)" );
2915 output( "\n" );
2916 output( "%s%s %s%s:", obj_dir_path( make, testmodule ), dll_ext,
2917 obj_dir_path( make, stripped ), dll_ext );
2918 output_filenames_obj_dir( make, object_files );
2919 output_filenames_obj_dir( make, res_files );
2920 output_filenames( dep_libs );
2921 output( "\n" );
2923 if (!make->disabled)
2924 output( "all: %s/%s\n", top_obj_dir_path( make, "programs/winetest" ), testres );
2925 output( "%s/%s: %s%s\n", top_obj_dir_path( make, "programs/winetest" ), testres,
2926 obj_dir_path( make, stripped ), dll_ext );
2927 output( "\techo \"%s TESTRES \\\"%s%s\\\"\" | %s -o $@\n",
2928 testmodule, obj_dir_path( make, stripped ), dll_ext, tools_path( make, "wrc" ));
2930 if (crosstarget)
2932 char *crosstest = replace_extension( make->testdll, ".dll", "_crosstest.exe" );
2934 dep_libs = empty_strarray;
2935 all_libs = add_import_libs( make, &dep_libs, make->imports, 1 );
2936 add_import_libs( make, &dep_libs, get_default_imports( make ), 1 ); /* dependencies only */
2937 strarray_addall( &all_libs, libs );
2938 strarray_add( &clean_files, crosstest );
2939 output( "%s:", obj_dir_path( make, crosstest ));
2940 output_filenames_obj_dir( make, crossobj_files );
2941 output_filenames_obj_dir( make, res_files );
2942 output_filenames( dep_libs );
2943 output( "\n" );
2944 output( "\t%s -o $@ -b %s", tools_path( make, "winegcc" ), crosstarget );
2945 output_filename( strmake( "-B%s", tools_dir_path( make, "winebuild" )));
2946 if (tools_dir) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make, "" )));
2947 output_filename( "--lib-suffix=.cross.a" );
2948 output_filenames_obj_dir( make, crossobj_files );
2949 output_filenames_obj_dir( make, res_files );
2950 output_filenames( all_libs );
2951 output_filename( "$(LDFLAGS)" );
2952 output( "\n" );
2953 if (!make->disabled)
2955 output( "%s: %s\n", obj_dir_path( make, "crosstest" ), obj_dir_path( make, crosstest ));
2956 strarray_add( &phony_targets, obj_dir_path( make, "crosstest" ));
2957 if (make->obj_dir) output( "crosstest: %s\n", obj_dir_path( make, "crosstest" ));
2961 output_filenames_obj_dir( make, ok_files );
2962 output( ": %s%s ../%s%s\n", testmodule, dll_ext, make->testdll, dll_ext );
2963 if (!make->disabled)
2965 output( "check test:" );
2966 output_filenames_obj_dir( make, ok_files );
2967 output( "\n" );
2968 strarray_add( &phony_targets, "check" );
2969 strarray_add( &phony_targets, "test" );
2971 output( "testclean::\n" );
2972 output( "\trm -f" );
2973 output_filenames_obj_dir( make, ok_files );
2974 output( "\n" );
2975 strarray_addall( &clean_files, ok_files );
2976 strarray_add( &phony_targets, "testclean" );
2979 for (i = 0; i < make->programs.count; i++)
2981 char *program_installed = NULL;
2982 char *program = strmake( "%s%s", make->programs.str[i], exe_ext );
2983 struct strarray deps = get_local_dependencies( make, make->programs.str[i], in_files );
2984 struct strarray all_libs = get_expanded_file_local_var( make, make->programs.str[i], "LDFLAGS" );
2985 struct strarray objs = get_expanded_file_local_var( make, make->programs.str[i], "OBJS" );
2986 struct strarray symlinks = get_expanded_file_local_var( make, make->programs.str[i], "SYMLINKS" );
2988 if (!objs.count) objs = object_files;
2989 strarray_addall( &all_libs, add_default_libraries( make, &deps ));
2991 output( "%s:", obj_dir_path( make, program ) );
2992 output_filenames_obj_dir( make, objs );
2993 output_filenames( deps );
2994 output( "\n" );
2995 output( "\t$(CC) -o $@" );
2996 output_filenames_obj_dir( make, objs );
2998 if (strarray_exists( &all_libs, "-lwine" ))
3000 strarray_add( &all_libs, strmake( "-L%s", top_obj_dir_path( make, "libs/wine" )));
3001 if (ldrpath_local && ldrpath_install)
3003 program_installed = strmake( "%s-installed%s", make->programs.str[i], exe_ext );
3004 output_filename( ldrpath_local );
3005 output_filenames( all_libs );
3006 output_filename( "$(LDFLAGS)" );
3007 output( "\n" );
3008 output( "%s:", obj_dir_path( make, program_installed ) );
3009 output_filenames_obj_dir( make, objs );
3010 output_filenames( deps );
3011 output( "\n" );
3012 output( "\t$(CC) -o $@" );
3013 output_filenames_obj_dir( make, objs );
3014 output_filename( ldrpath_install );
3015 strarray_add( &all_targets, program_installed );
3019 output_filenames( all_libs );
3020 output_filename( "$(LDFLAGS)" );
3021 output( "\n" );
3022 strarray_add( &all_targets, program );
3024 if (symlinks.count)
3026 output_filenames_obj_dir( make, symlinks );
3027 output( ": %s\n", obj_dir_path( make, program ));
3028 output( "\trm -f $@ && %s %s $@\n", ln_s, obj_dir_path( make, program ));
3029 strarray_addall( &all_targets, symlinks );
3032 add_install_rule( make, install_rules, program, program_installed ? program_installed : program,
3033 strmake( "p$(bindir)/%s", program ));
3034 for (j = 0; j < symlinks.count; j++)
3035 add_install_rule( make, install_rules, symlinks.str[j], program,
3036 strmake( "y$(bindir)/%s%s", symlinks.str[j], exe_ext ));
3039 for (i = 0; i < make->scripts.count; i++)
3040 add_install_rule( make, install_rules, make->scripts.str[i], make->scripts.str[i],
3041 strmake( "S$(bindir)/%s", make->scripts.str[i] ));
3043 if (!make->disabled)
3045 if (all_targets.count)
3047 output( "all:" );
3048 output_filenames_obj_dir( make, all_targets );
3049 output( "\n" );
3051 strarray_addall( &uninstall_files, output_install_rules( make, install_rules[INSTALL_LIB],
3052 "install-lib", &phony_targets ));
3053 strarray_addall( &uninstall_files, output_install_rules( make, install_rules[INSTALL_DEV],
3054 "install-dev", &phony_targets ));
3055 if (uninstall_files.count)
3057 output( "uninstall::\n" );
3058 output( "\trm -f" );
3059 output_filenames( uninstall_files );
3060 output( "\n" );
3061 strarray_add_uniq( &phony_targets, "uninstall" );
3065 strarray_addall( &clean_files, object_files );
3066 strarray_addall( &clean_files, crossobj_files );
3067 strarray_addall( &clean_files, res_files );
3068 strarray_addall( &clean_files, all_targets );
3069 strarray_addall( &clean_files, get_expanded_make_var_array( make, "EXTRA_TARGETS" ));
3071 if (make->subdirs.count)
3073 struct strarray build_deps = empty_strarray;
3074 struct strarray makefile_deps = empty_strarray;
3075 struct strarray distclean_files = get_expanded_make_var_array( make, "CONFIGURE_TARGETS" );
3077 strarray_add( &distclean_files, obj_dir_path( make, output_makefile_name ));
3078 if (!make->src_dir) strarray_add( &distclean_files, obj_dir_path( make, ".gitignore" ));
3079 for (i = 0; i < make->subdirs.count; i++)
3081 const struct makefile *submake = make->submakes[i];
3083 strarray_add( &makefile_deps, top_dir_path( make, base_dir_path( submake,
3084 strmake ( "%s.in", output_makefile_name ))));
3085 strarray_add( &distclean_files, base_dir_path( submake, output_makefile_name ));
3086 if (!make->src_dir) strarray_add( &distclean_files, base_dir_path( submake, ".gitignore" ));
3087 if (submake->testdll) strarray_add( &distclean_files, base_dir_path( submake, "testlist.c" ));
3088 strarray_addall( &build_deps, output_importlib_symlinks( make, submake ));
3090 output( "Makefile:" );
3091 output_filenames( makefile_deps );
3092 output( "\n" );
3093 output( "distclean::\n");
3094 output( "\trm -f" );
3095 output_filenames( distclean_files );
3096 output( "\n" );
3097 strarray_add( &phony_targets, "distclean" );
3099 if (build_deps.count)
3101 output( "__builddeps__:" );
3102 output_filenames( build_deps );
3103 output( "\n" );
3104 strarray_addall( &clean_files, build_deps );
3106 if (get_expanded_make_variable( make, "GETTEXTPO_LIBS" )) output_po_files( make );
3109 if (clean_files.count)
3111 output( "%s::\n", obj_dir_path( make, "clean" ));
3112 output( "\trm -f" );
3113 output_filenames_obj_dir( make, clean_files );
3114 output( "\n" );
3115 if (make->obj_dir) output( "__clean__: %s\n", obj_dir_path( make, "clean" ));
3116 strarray_add( &phony_targets, obj_dir_path( make, "clean" ));
3119 if (phony_targets.count)
3121 output( ".PHONY:" );
3122 output_filenames( phony_targets );
3123 output( "\n" );
3126 if (!make->base_dir)
3127 strarray_addall( &clean_files, get_expanded_make_var_array( make, "CONFIGURE_TARGETS" ));
3128 return clean_files;
3132 /*******************************************************************
3133 * create_temp_file
3135 static FILE *create_temp_file( const char *orig )
3137 char *name = xmalloc( strlen(orig) + 13 );
3138 unsigned int i, id = getpid();
3139 int fd;
3140 FILE *ret = NULL;
3142 for (i = 0; i < 100; i++)
3144 sprintf( name, "%s.tmp%08x", orig, id );
3145 if ((fd = open( name, O_RDWR | O_CREAT | O_EXCL, 0666 )) != -1)
3147 ret = fdopen( fd, "w" );
3148 break;
3150 if (errno != EEXIST) break;
3151 id += 7777;
3153 if (!ret) fatal_error( "failed to create output file for '%s'\n", orig );
3154 temp_file_name = name;
3155 return ret;
3159 /*******************************************************************
3160 * rename_temp_file
3162 static void rename_temp_file( const char *dest )
3164 int ret = rename( temp_file_name, dest );
3165 if (ret == -1 && errno == EEXIST)
3167 /* rename doesn't overwrite on windows */
3168 unlink( dest );
3169 ret = rename( temp_file_name, dest );
3171 if (ret == -1) fatal_error( "failed to rename output file to '%s'\n", dest );
3172 temp_file_name = NULL;
3176 /*******************************************************************
3177 * are_files_identical
3179 static int are_files_identical( FILE *file1, FILE *file2 )
3181 for (;;)
3183 char buffer1[8192], buffer2[8192];
3184 int size1 = fread( buffer1, 1, sizeof(buffer1), file1 );
3185 int size2 = fread( buffer2, 1, sizeof(buffer2), file2 );
3186 if (size1 != size2) return 0;
3187 if (!size1) return feof( file1 ) && feof( file2 );
3188 if (memcmp( buffer1, buffer2, size1 )) return 0;
3193 /*******************************************************************
3194 * rename_temp_file_if_changed
3196 static void rename_temp_file_if_changed( const char *dest )
3198 FILE *file1, *file2;
3199 int do_rename = 1;
3201 if ((file1 = fopen( dest, "r" )))
3203 if ((file2 = fopen( temp_file_name, "r" )))
3205 do_rename = !are_files_identical( file1, file2 );
3206 fclose( file2 );
3208 fclose( file1 );
3210 if (!do_rename)
3212 unlink( temp_file_name );
3213 temp_file_name = NULL;
3215 else rename_temp_file( dest );
3219 /*******************************************************************
3220 * output_linguas
3222 static void output_linguas( const struct makefile *make )
3224 const char *dest = base_dir_path( make, "LINGUAS" );
3225 struct incl_file *source;
3227 output_file = create_temp_file( dest );
3229 output( "# Automatically generated by make depend; DO NOT EDIT!!\n" );
3230 LIST_FOR_EACH_ENTRY( source, &make->sources, struct incl_file, entry )
3231 if (strendswith( source->name, ".po" ))
3232 output( "%s\n", replace_extension( source->name, ".po", "" ));
3234 if (fclose( output_file )) fatal_perror( "write" );
3235 output_file = NULL;
3236 rename_temp_file_if_changed( dest );
3240 /*******************************************************************
3241 * output_testlist
3243 static void output_testlist( const struct makefile *make )
3245 const char *dest = base_dir_path( make, "testlist.c" );
3246 struct strarray files = empty_strarray;
3247 struct incl_file *source;
3248 unsigned int i;
3250 LIST_FOR_EACH_ENTRY( source, &make->sources, struct incl_file, entry )
3252 if (source->file->flags & FLAG_GENERATED) continue;
3253 if (!strendswith( source->name, ".c" )) continue;
3254 strarray_add( &files, replace_extension( source->name, ".c", "" ));
3257 output_file = create_temp_file( dest );
3259 output( "/* Automatically generated by make depend; DO NOT EDIT!! */\n\n" );
3260 output( "#define WIN32_LEAN_AND_MEAN\n" );
3261 output( "#include <windows.h>\n\n" );
3262 output( "#define STANDALONE\n" );
3263 output( "#include \"wine/test.h\"\n\n" );
3265 for (i = 0; i < files.count; i++) output( "extern void func_%s(void);\n", files.str[i] );
3266 output( "\n" );
3267 output( "const struct test winetest_testlist[] =\n" );
3268 output( "{\n" );
3269 for (i = 0; i < files.count; i++) output( " { \"%s\", func_%s },\n", files.str[i], files.str[i] );
3270 output( " { 0, 0 }\n" );
3271 output( "};\n" );
3273 if (fclose( output_file )) fatal_perror( "write" );
3274 output_file = NULL;
3275 rename_temp_file_if_changed( dest );
3279 /*******************************************************************
3280 * output_gitignore
3282 static void output_gitignore( const char *dest, struct strarray files )
3284 int i;
3286 output_file = create_temp_file( dest );
3288 output( "# Automatically generated by make depend; DO NOT EDIT!!\n" );
3289 for (i = 0; i < files.count; i++)
3291 if (!strchr( files.str[i], '/' )) output( "/" );
3292 output( "%s\n", files.str[i] );
3295 if (fclose( output_file )) fatal_perror( "write" );
3296 output_file = NULL;
3297 rename_temp_file( dest );
3301 /*******************************************************************
3302 * output_top_variables
3304 static void output_top_variables( const struct makefile *make )
3306 unsigned int i;
3307 struct strarray *vars = &top_makefile->vars;
3309 if (!make->base_dir) return; /* don't output variables in the top makefile */
3311 output( "# Automatically generated by make depend; DO NOT EDIT!!\n\n" );
3312 output( "all:\n\n" );
3313 for (i = 0; i < vars->count; i += 2)
3315 if (!strcmp( vars->str[i], "SUBDIRS" )) continue; /* not inherited */
3316 output( "%s = %s\n", vars->str[i], get_make_variable( make, vars->str[i] ));
3318 output( "\n" );
3322 /*******************************************************************
3323 * output_dependencies
3325 static void output_dependencies( const struct makefile *make )
3327 struct strarray targets, ignore_files = empty_strarray;
3328 char buffer[1024];
3329 FILE *src_file;
3330 int found = 0;
3332 if (make->base_dir) create_dir( make->base_dir );
3334 output_file_name = base_dir_path( make, output_makefile_name );
3335 output_file = create_temp_file( output_file_name );
3336 output_top_variables( make );
3338 /* copy the contents of the source makefile */
3339 src_file = open_input_makefile( make );
3340 while (fgets( buffer, sizeof(buffer), src_file ) && !found)
3342 if (fwrite( buffer, 1, strlen(buffer), output_file ) != strlen(buffer)) fatal_perror( "write" );
3343 found = !strncmp( buffer, separator, strlen(separator) );
3345 if (fclose( src_file )) fatal_perror( "close" );
3346 input_file_name = NULL;
3348 if (!found) output( "\n%s (everything below this line is auto-generated; DO NOT EDIT!!)\n", separator );
3349 targets = output_sources( make );
3351 fclose( output_file );
3352 output_file = NULL;
3353 rename_temp_file( output_file_name );
3355 strarray_add( &ignore_files, ".gitignore" );
3356 strarray_add( &ignore_files, "Makefile" );
3357 if (make->testdll)
3359 output_testlist( make );
3360 strarray_add( &ignore_files, "testlist.c" );
3362 if (make->base_dir && !strcmp( make->base_dir, "po" ))
3364 output_linguas( make );
3365 strarray_add( &ignore_files, "LINGUAS" );
3367 strarray_addall( &ignore_files, targets );
3368 if (!make->src_dir) output_gitignore( base_dir_path( make, ".gitignore" ), ignore_files );
3370 create_file_directories( make, targets );
3372 output_file_name = NULL;
3376 /*******************************************************************
3377 * load_sources
3379 static void load_sources( struct makefile *make )
3381 static const char *source_vars[] =
3383 "C_SRCS",
3384 "OBJC_SRCS",
3385 "RC_SRCS",
3386 "MC_SRCS",
3387 "IDL_SRCS",
3388 "BISON_SRCS",
3389 "LEX_SRCS",
3390 "HEADER_SRCS",
3391 "XTEMPLATE_SRCS",
3392 "SVG_SRCS",
3393 "FONT_SRCS",
3394 "IN_SRCS",
3395 "PO_SRCS",
3396 "MANPAGES",
3397 NULL
3399 const char **var;
3400 unsigned int i;
3401 struct strarray value;
3402 struct incl_file *file;
3404 if (root_src_dir)
3406 make->top_src_dir = concat_paths( make->top_obj_dir, root_src_dir );
3407 make->src_dir = concat_paths( make->top_src_dir, make->base_dir );
3409 strarray_set_value( &make->vars, "top_builddir", top_obj_dir_path( make, "" ));
3410 strarray_set_value( &make->vars, "top_srcdir", top_dir_path( make, "" ));
3411 strarray_set_value( &make->vars, "srcdir", src_dir_path( make, "" ));
3413 make->parent_dir = get_expanded_make_variable( make, "PARENTSRC" );
3414 make->module = get_expanded_make_variable( make, "MODULE" );
3415 make->testdll = get_expanded_make_variable( make, "TESTDLL" );
3416 make->sharedlib = get_expanded_make_variable( make, "SHAREDLIB" );
3417 make->staticlib = get_expanded_make_variable( make, "STATICLIB" );
3418 make->importlib = get_expanded_make_variable( make, "IMPORTLIB" );
3420 make->programs = get_expanded_make_var_array( make, "PROGRAMS" );
3421 make->scripts = get_expanded_make_var_array( make, "SCRIPTS" );
3422 make->appmode = get_expanded_make_var_array( make, "APPMODE" );
3423 make->imports = get_expanded_make_var_array( make, "IMPORTS" );
3424 make->delayimports = get_expanded_make_var_array( make, "DELAYIMPORTS" );
3425 make->extradllflags = get_expanded_make_var_array( make, "EXTRADLLFLAGS" );
3426 make->install_lib = get_expanded_make_var_array( make, "INSTALL_LIB" );
3427 make->install_dev = get_expanded_make_var_array( make, "INSTALL_DEV" );
3429 if (make->module && strendswith( make->module, ".a" )) make->staticlib = make->module;
3431 make->disabled = make->base_dir && strarray_exists( &disabled_dirs, make->base_dir );
3432 make->is_win16 = strarray_exists( &make->extradllflags, "-m16" );
3433 make->use_msvcrt = strarray_exists( &make->appmode, "-mno-cygwin" );
3435 for (i = 0; i < make->imports.count && !make->use_msvcrt; i++)
3436 make->use_msvcrt = !strncmp( make->imports.str[i], "msvcr", 5 ) ||
3437 !strcmp( make->imports.str[i], "ucrtbase" );
3439 if (make->module && !make->install_lib.count) strarray_add( &make->install_lib, make->module );
3441 make->include_paths = empty_strarray;
3442 make->define_args = empty_strarray;
3443 strarray_add( &make->define_args, "-D__WINESRC__" );
3445 value = get_expanded_make_var_array( make, "EXTRAINCL" );
3446 for (i = 0; i < value.count; i++)
3447 if (!strncmp( value.str[i], "-I", 2 ))
3448 strarray_add_uniq( &make->include_paths, value.str[i] + 2 );
3449 else
3450 strarray_add_uniq( &make->define_args, value.str[i] );
3451 strarray_addall( &make->define_args, get_expanded_make_var_array( make, "EXTRADEFS" ));
3453 list_init( &make->sources );
3454 list_init( &make->includes );
3456 for (var = source_vars; *var; var++)
3458 value = get_expanded_make_var_array( make, *var );
3459 for (i = 0; i < value.count; i++) add_src_file( make, value.str[i] );
3462 add_generated_sources( make );
3464 value = get_expanded_make_var_array( make, "EXTRA_OBJS" );
3465 for (i = 0; i < value.count; i++)
3467 /* default to .c for unknown extra object files */
3468 if (strendswith( value.str[i], ".o" ))
3469 add_generated_source( make, value.str[i], replace_extension( value.str[i], ".o", ".c" ) );
3470 else
3471 add_generated_source( make, value.str[i], NULL );
3474 LIST_FOR_EACH_ENTRY( file, &make->includes, struct incl_file, entry ) parse_file( make, file, 0 );
3478 /*******************************************************************
3479 * parse_makeflags
3481 static void parse_makeflags( const char *flags )
3483 const char *p = flags;
3484 char *var, *buffer = xmalloc( strlen(flags) + 1 );
3486 while (*p)
3488 while (isspace(*p)) p++;
3489 var = buffer;
3490 while (*p && !isspace(*p))
3492 if (*p == '\\' && p[1]) p++;
3493 *var++ = *p++;
3495 *var = 0;
3496 if (var > buffer) set_make_variable( &cmdline_vars, buffer );
3501 /*******************************************************************
3502 * parse_option
3504 static int parse_option( const char *opt )
3506 if (opt[0] != '-')
3508 if (strchr( opt, '=' )) return set_make_variable( &cmdline_vars, opt );
3509 return 0;
3511 switch(opt[1])
3513 case 'f':
3514 if (opt[2]) output_makefile_name = opt + 2;
3515 break;
3516 case 'R':
3517 relative_dir_mode = 1;
3518 break;
3519 default:
3520 fprintf( stderr, "Unknown option '%s'\n%s", opt, Usage );
3521 exit(1);
3523 return 1;
3527 /*******************************************************************
3528 * main
3530 int main( int argc, char *argv[] )
3532 const char *makeflags = getenv( "MAKEFLAGS" );
3533 int i, j;
3535 if (makeflags) parse_makeflags( makeflags );
3537 i = 1;
3538 while (i < argc)
3540 if (parse_option( argv[i] ))
3542 for (j = i; j < argc; j++) argv[j] = argv[j+1];
3543 argc--;
3545 else i++;
3548 if (relative_dir_mode)
3550 char *relpath;
3552 if (argc != 3)
3554 fprintf( stderr, "Option -R needs two directories\n%s", Usage );
3555 exit( 1 );
3557 relpath = get_relative_path( argv[1], argv[2] );
3558 printf( "%s\n", relpath ? relpath : "." );
3559 exit( 0 );
3562 atexit( cleanup_files );
3563 signal( SIGTERM, exit_on_signal );
3564 signal( SIGINT, exit_on_signal );
3565 #ifdef SIGHUP
3566 signal( SIGHUP, exit_on_signal );
3567 #endif
3569 for (i = 0; i < HASH_SIZE; i++) list_init( &files[i] );
3571 top_makefile = parse_makefile( NULL );
3573 target_flags = get_expanded_make_var_array( top_makefile, "TARGETFLAGS" );
3574 msvcrt_flags = get_expanded_make_var_array( top_makefile, "MSVCRTFLAGS" );
3575 dll_flags = get_expanded_make_var_array( top_makefile, "DLLFLAGS" );
3576 extra_cflags = get_expanded_make_var_array( top_makefile, "EXTRACFLAGS" );
3577 cpp_flags = get_expanded_make_var_array( top_makefile, "CPPFLAGS" );
3578 unwind_flags = get_expanded_make_var_array( top_makefile, "UNWINDFLAGS" );
3579 libs = get_expanded_make_var_array( top_makefile, "LIBS" );
3581 root_src_dir = get_expanded_make_variable( top_makefile, "srcdir" );
3582 tools_dir = get_expanded_make_variable( top_makefile, "TOOLSDIR" );
3583 tools_ext = get_expanded_make_variable( top_makefile, "TOOLSEXT" );
3584 exe_ext = get_expanded_make_variable( top_makefile, "EXEEXT" );
3585 man_ext = get_expanded_make_variable( top_makefile, "api_manext" );
3586 dll_ext = (exe_ext && !strcmp( exe_ext, ".exe" )) ? "" : ".so";
3587 crosstarget = get_expanded_make_variable( top_makefile, "CROSSTARGET" );
3588 fontforge = get_expanded_make_variable( top_makefile, "FONTFORGE" );
3589 convert = get_expanded_make_variable( top_makefile, "CONVERT" );
3590 rsvg = get_expanded_make_variable( top_makefile, "RSVG" );
3591 icotool = get_expanded_make_variable( top_makefile, "ICOTOOL" );
3592 dlltool = get_expanded_make_variable( top_makefile, "DLLTOOL" );
3593 msgfmt = get_expanded_make_variable( top_makefile, "MSGFMT" );
3594 ln_s = get_expanded_make_variable( top_makefile, "LN_S" );
3596 if (root_src_dir && !strcmp( root_src_dir, "." )) root_src_dir = NULL;
3597 if (tools_dir && !strcmp( tools_dir, "." )) tools_dir = NULL;
3598 if (!exe_ext) exe_ext = "";
3599 if (!tools_ext) tools_ext = "";
3600 if (!man_ext) man_ext = "3w";
3602 if (argc == 1)
3604 disabled_dirs = get_expanded_make_var_array( top_makefile, "DISABLED_SUBDIRS" );
3605 top_makefile->subdirs = get_expanded_make_var_array( top_makefile, "SUBDIRS" );
3606 top_makefile->submakes = xmalloc( top_makefile->subdirs.count * sizeof(*top_makefile->submakes) );
3608 for (i = 0; i < top_makefile->subdirs.count; i++)
3609 top_makefile->submakes[i] = parse_makefile( top_makefile->subdirs.str[i] );
3611 load_sources( top_makefile );
3612 for (i = 0; i < top_makefile->subdirs.count; i++)
3613 load_sources( top_makefile->submakes[i] );
3615 for (i = 0; i < top_makefile->subdirs.count; i++)
3616 output_dependencies( top_makefile->submakes[i] );
3618 output_dependencies( top_makefile );
3619 return 0;
3622 for (i = 1; i < argc; i++)
3624 struct makefile *make = parse_makefile( argv[i] );
3625 load_sources( make );
3626 output_dependencies( make );
3628 return 0;