makefiles: Always expand the library name for cross-compiled import libraries.
[wine.git] / tools / makedep.c
blob98645db1ab5631e2a3b3977ebcaae79b77b845ec
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.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 * get_static_lib
1931 * Check if makefile builds the named static library and return the full lib path.
1933 static const char *get_static_lib( const struct makefile *make, const char *name )
1935 if (!make->staticlib) return NULL;
1936 if (strncmp( make->staticlib, "lib", 3 )) return NULL;
1937 if (strncmp( make->staticlib + 3, name, strlen(name) )) return NULL;
1938 if (strcmp( make->staticlib + 3 + strlen(name), ".a" )) return NULL;
1939 return base_dir_path( make, make->staticlib );
1943 /*******************************************************************
1944 * add_default_libraries
1946 static struct strarray add_default_libraries( const struct makefile *make, struct strarray *deps )
1948 struct strarray ret = empty_strarray;
1949 struct strarray all_libs = empty_strarray;
1950 unsigned int i, j;
1952 strarray_add( &all_libs, "-lwine_port" );
1953 strarray_addall( &all_libs, get_expanded_make_var_array( make, "EXTRALIBS" ));
1954 strarray_addall( &all_libs, libs );
1956 for (i = 0; i < all_libs.count; i++)
1958 const char *lib = NULL;
1960 if (!strncmp( all_libs.str[i], "-l", 2 ))
1962 const char *name = all_libs.str[i] + 2;
1964 for (j = 0; j < top_makefile->subdirs.count; j++)
1966 const struct makefile *submake = top_makefile->submakes[j];
1968 if ((lib = get_static_lib( submake, name ))) break;
1972 if (lib)
1974 lib = top_obj_dir_path( make, lib );
1975 strarray_add( deps, lib );
1976 strarray_add( &ret, lib );
1978 else strarray_add( &ret, all_libs.str[i] );
1980 return ret;
1984 /*******************************************************************
1985 * add_import_libs
1987 static struct strarray add_import_libs( const struct makefile *make, struct strarray *deps,
1988 struct strarray imports, int cross )
1990 struct strarray ret = empty_strarray;
1991 unsigned int i, j;
1993 for (i = 0; i < imports.count; i++)
1995 const char *name = imports.str[i];
1996 const char *lib = NULL;
1998 for (j = 0; j < top_makefile->subdirs.count; j++)
2000 const struct makefile *submake = top_makefile->submakes[j];
2002 if (submake->importlib && !strcmp( submake->importlib, name ))
2004 if (cross || !*dll_ext || submake->staticimplib)
2005 lib = base_dir_path( submake, strmake( "lib%s.a", name ));
2006 else
2007 strarray_add( deps, top_obj_dir_path( make,
2008 strmake( "%s/lib%s.def", submake->base_dir, name )));
2009 break;
2012 if ((lib = get_static_lib( submake, name ))) break;
2015 if (lib)
2017 if (cross) lib = replace_extension( lib, ".a", ".cross.a" );
2018 lib = top_obj_dir_path( make, lib );
2019 strarray_add( deps, lib );
2020 strarray_add( &ret, lib );
2022 else strarray_add( &ret, strmake( "-l%s", name ));
2024 return ret;
2028 /*******************************************************************
2029 * get_default_imports
2031 static struct strarray get_default_imports( const struct makefile *make )
2033 struct strarray ret = empty_strarray;
2035 if (strarray_exists( &make->extradllflags, "-nodefaultlibs" )) return ret;
2036 if (strarray_exists( &make->appmode, "-mno-cygwin" )) strarray_add( &ret, "msvcrt" );
2037 if (make->is_win16) strarray_add( &ret, "kernel" );
2038 strarray_add( &ret, "kernel32" );
2039 strarray_add( &ret, "ntdll" );
2040 strarray_add( &ret, "winecrt0" );
2041 return ret;
2045 /*******************************************************************
2046 * add_install_rule
2048 static void add_install_rule( const struct makefile *make, struct strarray *install_rules,
2049 const char *target, const char *file, const char *dest )
2051 if (strarray_exists( &make->install_lib, target ))
2053 strarray_add( &install_rules[INSTALL_LIB], file );
2054 strarray_add( &install_rules[INSTALL_LIB], dest );
2056 else if (strarray_exists( &make->install_dev, target ))
2058 strarray_add( &install_rules[INSTALL_DEV], file );
2059 strarray_add( &install_rules[INSTALL_DEV], dest );
2064 /*******************************************************************
2065 * get_include_install_path
2067 * Determine the installation path for a given include file.
2069 static const char *get_include_install_path( const char *name )
2071 if (!strncmp( name, "wine/", 5 )) return name + 5;
2072 if (!strncmp( name, "msvcrt/", 7 )) return name;
2073 return strmake( "windows/%s", name );
2077 /*******************************************************************
2078 * get_shared_library_name
2080 * Determine possible names for a shared library with a version number.
2082 static struct strarray get_shared_lib_names( const char *libname )
2084 struct strarray ret = empty_strarray;
2085 const char *ext, *p;
2086 char *name, *first, *second;
2087 size_t len = 0;
2089 strarray_add( &ret, libname );
2091 for (p = libname; (p = strchr( p, '.' )); p++)
2092 if ((len = strspn( p + 1, "0123456789." ))) break;
2094 if (!len) return ret;
2095 ext = p + 1 + len;
2096 if (*ext && ext[-1] == '.') ext--;
2098 /* keep only the first group of digits */
2099 name = xstrdup( libname );
2100 first = name + (p - libname);
2101 if ((second = strchr( first + 1, '.' )))
2103 strcpy( second, ext );
2104 strarray_add( &ret, xstrdup( name ));
2106 /* now remove all digits */
2107 strcpy( first, ext );
2108 strarray_add( &ret, name );
2109 return ret;
2113 /*******************************************************************
2114 * output_install_rules
2116 * Rules are stored as a (file,dest) pair of values.
2117 * The first char of dest indicates the type of install.
2119 static struct strarray output_install_rules( const struct makefile *make, struct strarray files,
2120 const char *target, struct strarray *phony_targets )
2122 unsigned int i;
2123 char *install_sh;
2124 struct strarray uninstall = empty_strarray;
2125 struct strarray targets = empty_strarray;
2127 if (!files.count) return uninstall;
2129 for (i = 0; i < files.count; i += 2)
2130 if (strchr( "dps", files.str[i + 1][0] )) /* only for files copied from object dir */
2131 strarray_add_uniq( &targets, files.str[i] );
2133 output( "install %s::", target );
2134 output_filenames_obj_dir( make, targets );
2135 output( "\n" );
2137 install_sh = top_dir_path( make, "tools/install-sh" );
2138 for (i = 0; i < files.count; i += 2)
2140 const char *file = files.str[i];
2141 const char *dest = files.str[i + 1];
2143 switch (*dest)
2145 case 'd': /* data file */
2146 output( "\t%s -m 644 $(INSTALL_DATA_FLAGS) %s $(DESTDIR)%s\n",
2147 install_sh, obj_dir_path( make, file ), dest + 1 );
2148 break;
2149 case 'D': /* data file in source dir */
2150 output( "\t%s -m 644 $(INSTALL_DATA_FLAGS) %s $(DESTDIR)%s\n",
2151 install_sh, src_dir_path( make, file ), dest + 1 );
2152 break;
2153 case 'p': /* program file */
2154 output( "\tSTRIPPROG=\"$(STRIP)\" %s $(INSTALL_PROGRAM_FLAGS) %s $(DESTDIR)%s\n",
2155 install_sh, obj_dir_path( make, file ), dest + 1 );
2156 break;
2157 case 's': /* script */
2158 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s $(DESTDIR)%s\n",
2159 install_sh, obj_dir_path( make, file ), dest + 1 );
2160 break;
2161 case 'S': /* script in source dir */
2162 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s $(DESTDIR)%s\n",
2163 install_sh, src_dir_path( make, file ), dest + 1 );
2164 break;
2165 case 'y': /* symlink */
2166 output( "\trm -f $(DESTDIR)%s && %s %s $(DESTDIR)%s\n", dest + 1, ln_s, file, dest + 1 );
2167 break;
2168 default:
2169 assert(0);
2173 for (i = 0; i < files.count; i += 2)
2174 strarray_add( &uninstall, strmake( "$(DESTDIR)%s", files.str[i + 1] + 1 ));
2176 strarray_add_uniq( phony_targets, "install" );
2177 strarray_add_uniq( phony_targets, target );
2178 return uninstall;
2182 /*******************************************************************
2183 * output_importlib_symlinks
2185 static struct strarray output_importlib_symlinks( const struct makefile *parent,
2186 const struct makefile *make )
2188 struct strarray ret = empty_strarray;
2189 const char *dir, *lib;
2191 if (!make->module) return ret;
2192 if (!make->importlib) return ret;
2193 if (make->is_win16 && make->disabled) return ret;
2194 if (strncmp( make->base_dir, "dlls/", 5 )) return ret;
2195 if (!strcmp( make->module, make->importlib )) return ret;
2196 if (!strchr( make->importlib, '.' ) &&
2197 !strncmp( make->module, make->importlib, strlen( make->importlib )) &&
2198 !strcmp( make->module + strlen( make->importlib ), ".dll" ))
2199 return ret;
2201 dir = obj_dir_path( parent, "dlls" );
2202 lib = strmake( "lib%s.%s", make->importlib, *dll_ext ? "def" : "a" );
2203 output( "%s/%s: %s\n", dir, lib, base_dir_path( make, lib ));
2204 output( "\trm -f $@ && %s %s/%s $@\n", ln_s, make->base_dir + strlen("dlls/"), lib );
2205 strarray_add( &ret, strmake( "%s/%s", dir, lib ));
2207 if (crosstarget && !make->is_win16)
2209 lib = strmake( "lib%s.cross.a", make->importlib );
2210 output( "%s/%s: %s\n", dir, lib, base_dir_path( make, lib ));
2211 output( "\trm -f $@ && %s %s/%s $@\n", ln_s, make->base_dir + strlen("dlls/"), lib );
2212 strarray_add( &ret, strmake( "%s/%s", dir, lib ));
2214 return ret;
2218 /*******************************************************************
2219 * output_po_files
2221 static void output_po_files( const struct makefile *make )
2223 const char *po_dir = src_dir_path( make, "po" );
2224 struct strarray pot_files = empty_strarray;
2225 struct incl_file *source;
2226 unsigned int i;
2228 for (i = 0; i < make->subdirs.count; i++)
2230 struct makefile *submake = make->submakes[i];
2232 LIST_FOR_EACH_ENTRY( source, &submake->sources, struct incl_file, entry )
2234 if (strendswith( source->name, ".rc" ) && (source->file->flags & FLAG_RC_PO))
2236 char *pot_file = replace_extension( source->name, ".rc", ".pot" );
2237 char *pot_path = base_dir_path( submake, pot_file );
2238 output( "%s: tools/wrc include dummy\n", pot_path );
2239 output( "\t@cd %s && $(MAKE) %s\n", base_dir_path( submake, "" ), pot_file );
2240 strarray_add( &pot_files, pot_path );
2242 else if (strendswith( source->name, ".mc" ))
2244 char *pot_file = replace_extension( source->name, ".mc", ".pot" );
2245 char *pot_path = base_dir_path( submake, pot_file );
2246 output( "%s: tools/wmc include dummy\n", pot_path );
2247 output( "\t@cd %s && $(MAKE) %s\n", base_dir_path( submake, "" ), pot_file );
2248 strarray_add( &pot_files, pot_path );
2252 if (linguas.count)
2254 for (i = 0; i < linguas.count; i++)
2255 output_filename( strmake( "%s/%s.po", po_dir, linguas.str[i] ));
2256 output( ": %s/wine.pot\n", po_dir );
2257 output( "\tmsgmerge --previous -q $@ %s/wine.pot | msgattrib --no-obsolete -o $@.new && mv $@.new $@\n",
2258 po_dir );
2259 output( "po:" );
2260 for (i = 0; i < linguas.count; i++)
2261 output_filename( strmake( "%s/%s.po", po_dir, linguas.str[i] ));
2262 output( "\n" );
2264 output( "%s/wine.pot:", po_dir );
2265 output_filenames( pot_files );
2266 output( "\n" );
2267 output( "\tmsgcat -o $@" );
2268 output_filenames( pot_files );
2269 output( "\n" );
2273 /*******************************************************************
2274 * output_sources
2276 static struct strarray output_sources( const struct makefile *make )
2278 struct incl_file *source;
2279 unsigned int i, j;
2280 struct strarray object_files = empty_strarray;
2281 struct strarray crossobj_files = empty_strarray;
2282 struct strarray res_files = empty_strarray;
2283 struct strarray clean_files = empty_strarray;
2284 struct strarray uninstall_files = empty_strarray;
2285 struct strarray mo_files = empty_strarray;
2286 struct strarray ok_files = empty_strarray;
2287 struct strarray in_files = empty_strarray;
2288 struct strarray dlldata_files = empty_strarray;
2289 struct strarray c2man_files = empty_strarray;
2290 struct strarray implib_objs = empty_strarray;
2291 struct strarray includes = empty_strarray;
2292 struct strarray phony_targets = empty_strarray;
2293 struct strarray all_targets = empty_strarray;
2294 struct strarray install_rules[NB_INSTALL_RULES];
2295 char *ldrpath_local = get_expanded_make_variable( make, "LDRPATH_LOCAL" );
2296 char *ldrpath_install = get_expanded_make_variable( make, "LDRPATH_INSTALL" );
2298 for (i = 0; i < NB_INSTALL_RULES; i++) install_rules[i] = empty_strarray;
2300 for (i = 0; i < linguas.count; i++)
2301 strarray_add( &mo_files, strmake( "%s/%s.mo", top_obj_dir_path( make, "po" ), linguas.str[i] ));
2303 strarray_add( &phony_targets, "all" );
2304 strarray_add( &includes, strmake( "-I%s", obj_dir_path( make, "" )));
2305 if (make->src_dir) strarray_add( &includes, strmake( "-I%s", make->src_dir ));
2306 if (make->parent_dir) strarray_add( &includes, strmake( "-I%s", src_dir_path( make, make->parent_dir )));
2307 strarray_add( &includes, strmake( "-I%s", top_obj_dir_path( make, "include" )));
2308 if (make->top_src_dir) strarray_add( &includes, strmake( "-I%s", top_dir_path( make, "include" )));
2309 if (make->use_msvcrt) strarray_add( &includes, strmake( "-I%s", top_dir_path( make, "include/msvcrt" )));
2310 for (i = 0; i < make->include_paths.count; i++)
2311 strarray_add( &includes, strmake( "-I%s", obj_dir_path( make, make->include_paths.str[i] )));
2313 LIST_FOR_EACH_ENTRY( source, &make->sources, struct incl_file, entry )
2315 struct strarray dependencies = empty_strarray;
2316 struct strarray extradefs;
2317 char *obj = xstrdup( source->name );
2318 char *ext = get_extension( obj );
2320 if (!ext) fatal_error( "unsupported file type %s\n", source->name );
2321 *ext++ = 0;
2323 extradefs = get_expanded_file_local_var( make, obj, "EXTRADEFS" );
2324 get_dependencies( &dependencies, source, source );
2326 if (!strcmp( ext, "y" )) /* yacc file */
2328 /* add source file dependency for parallel makes */
2329 char *header = strmake( "%s.tab.h", obj );
2331 if (find_include_file( make, header ))
2333 output( "%s: %s\n", obj_dir_path( make, header ), source->filename );
2334 output( "\t$(BISON) -p %s_ -o %s.tab.c -d %s\n",
2335 obj, obj_dir_path( make, obj ), source->filename );
2336 output( "%s.tab.c: %s %s\n", obj_dir_path( make, obj ),
2337 source->filename, obj_dir_path( make, header ));
2338 strarray_add( &clean_files, header );
2340 else output( "%s.tab.c: %s\n", obj, source->filename );
2342 output( "\t$(BISON) -p %s_ -o $@ %s\n", obj, source->filename );
2344 else if (!strcmp( ext, "x" )) /* template file */
2346 output( "%s.h: %s%s %s\n", obj_dir_path( make, obj ),
2347 tools_dir_path( make, "make_xftmpl" ), tools_ext, source->filename );
2348 output( "\t%s%s -H -o $@ %s\n",
2349 tools_dir_path( make, "make_xftmpl" ), tools_ext, source->filename );
2350 if (source->file->flags & FLAG_INSTALL)
2352 strarray_add( &install_rules[INSTALL_DEV], source->name );
2353 strarray_add( &install_rules[INSTALL_DEV],
2354 strmake( "D$(includedir)/%s", get_include_install_path( source->name ) ));
2355 strarray_add( &install_rules[INSTALL_DEV], strmake( "%s.h", obj ));
2356 strarray_add( &install_rules[INSTALL_DEV],
2357 strmake( "d$(includedir)/%s.h", get_include_install_path( obj ) ));
2360 else if (!strcmp( ext, "l" )) /* lex file */
2362 output( "%s.yy.c: %s\n", obj_dir_path( make, obj ), source->filename );
2363 output( "\t$(FLEX) -o$@ %s\n", source->filename );
2365 else if (!strcmp( ext, "rc" )) /* resource file */
2367 strarray_add( &res_files, strmake( "%s.res", obj ));
2368 output( "%s.res: %s\n", obj_dir_path( make, obj ), source->filename );
2369 output( "\t%s -o $@", tools_path( make, "wrc" ) );
2370 if (make->is_win16) output_filename( "-m16" );
2371 else output_filenames( target_flags );
2372 output_filename( "--nostdinc" );
2373 output_filenames( includes );
2374 output_filenames( make->define_args );
2375 output_filenames( extradefs );
2376 if (mo_files.count && (source->file->flags & FLAG_RC_PO))
2378 output_filename( strmake( "--po-dir=%s", top_obj_dir_path( make, "po" )));
2379 output_filename( source->filename );
2380 output( "\n" );
2381 output( "%s.res:", obj_dir_path( make, obj ));
2382 output_filenames( mo_files );
2383 output( "\n" );
2385 else
2387 output_filename( source->filename );
2388 output( "\n" );
2390 if (source->file->flags & FLAG_RC_PO)
2392 strarray_add( &clean_files, strmake( "%s.pot", obj ));
2393 output( "%s.pot: %s\n", obj_dir_path( make, obj ), source->filename );
2394 output( "\t%s -O pot -o $@", tools_path( make, "wrc" ) );
2395 if (make->is_win16) output_filename( "-m16" );
2396 else output_filenames( target_flags );
2397 output_filename( "--nostdinc" );
2398 output_filenames( includes );
2399 output_filenames( make->define_args );
2400 output_filenames( extradefs );
2401 output_filename( source->filename );
2402 output( "\n" );
2403 output( "%s.pot ", obj_dir_path( make, obj ));
2405 output( "%s.res:", obj_dir_path( make, obj ));
2406 output_filename( tools_path( make, "wrc" ));
2407 output_filenames( dependencies );
2408 output( "\n" );
2410 else if (!strcmp( ext, "mc" )) /* message file */
2412 strarray_add( &res_files, strmake( "%s.res", obj ));
2413 strarray_add( &clean_files, strmake( "%s.pot", obj ));
2414 output( "%s.res: %s\n", obj_dir_path( make, obj ), source->filename );
2415 output( "\t%s -U -O res -o $@ %s", tools_path( make, "wmc" ), source->filename );
2416 if (mo_files.count)
2418 output_filename( strmake( "--po-dir=%s", top_obj_dir_path( make, "po" )));
2419 output( "\n" );
2420 output( "%s.res:", obj_dir_path( make, obj ));
2421 output_filenames( mo_files );
2423 output( "\n" );
2424 output( "%s.pot: %s\n", obj_dir_path( make, obj ), source->filename );
2425 output( "\t%s -O pot -o $@ %s", tools_path( make, "wmc" ), source->filename );
2426 output( "\n" );
2427 output( "%s.pot %s.res:", obj_dir_path( make, obj ), obj_dir_path( make, obj ));
2428 output_filename( tools_path( make, "wmc" ));
2429 output_filenames( dependencies );
2430 output( "\n" );
2432 else if (!strcmp( ext, "idl" )) /* IDL file */
2434 struct strarray targets = empty_strarray;
2435 char *dest;
2437 if (!source->file->flags) source->file->flags |= FLAG_IDL_HEADER | FLAG_INSTALL;
2438 if (find_include_file( make, strmake( "%s.h", obj ))) source->file->flags |= FLAG_IDL_HEADER;
2440 for (i = 0; i < sizeof(idl_outputs) / sizeof(idl_outputs[0]); i++)
2442 if (!(source->file->flags & idl_outputs[i].flag)) continue;
2443 dest = strmake( "%s%s", obj, idl_outputs[i].ext );
2444 if (!find_src_file( make, dest )) strarray_add( &clean_files, dest );
2445 strarray_add( &targets, dest );
2447 if (source->file->flags & FLAG_IDL_PROXY) strarray_add( &dlldata_files, source->name );
2448 if (source->file->flags & FLAG_INSTALL)
2450 strarray_add( &install_rules[INSTALL_DEV], xstrdup( source->name ));
2451 strarray_add( &install_rules[INSTALL_DEV],
2452 strmake( "D$(includedir)/%s.idl", get_include_install_path( obj ) ));
2453 if (source->file->flags & FLAG_IDL_HEADER)
2455 strarray_add( &install_rules[INSTALL_DEV], strmake( "%s.h", obj ));
2456 strarray_add( &install_rules[INSTALL_DEV],
2457 strmake( "d$(includedir)/%s.h", get_include_install_path( obj ) ));
2460 if (!targets.count) continue;
2461 output_filenames_obj_dir( make, targets );
2462 output( ": %s\n", tools_path( make, "widl" ));
2463 output( "\t%s -o $@", tools_path( make, "widl" ) );
2464 output_filenames( target_flags );
2465 output_filenames( includes );
2466 output_filenames( make->define_args );
2467 output_filenames( extradefs );
2468 output_filenames( get_expanded_make_var_array( make, "EXTRAIDLFLAGS" ));
2469 output_filename( source->filename );
2470 output( "\n" );
2471 output_filenames_obj_dir( make, targets );
2472 output( ": %s", source->filename );
2473 output_filenames( dependencies );
2474 output( "\n" );
2476 else if (!strcmp( ext, "in" )) /* .in file or man page */
2478 if (strendswith( obj, ".man" ) && source->file->args)
2480 struct strarray symlinks;
2481 char *dir, *dest = replace_extension( obj, ".man", "" );
2482 char *lang = strchr( dest, '.' );
2483 char *section = source->file->args;
2484 if (lang)
2486 *lang++ = 0;
2487 dir = strmake( "$(mandir)/%s/man%s", lang, section );
2489 else dir = strmake( "$(mandir)/man%s", section );
2490 add_install_rule( make, install_rules, dest, xstrdup(obj),
2491 strmake( "d%s/%s.%s", dir, dest, section ));
2492 symlinks = get_expanded_file_local_var( make, dest, "SYMLINKS" );
2493 for (i = 0; i < symlinks.count; i++)
2494 add_install_rule( make, install_rules, symlinks.str[i],
2495 strmake( "%s.%s", dest, section ),
2496 strmake( "y%s/%s.%s", dir, symlinks.str[i], section ));
2497 free( dest );
2498 free( dir );
2500 strarray_add( &in_files, xstrdup(obj) );
2501 strarray_add( &all_targets, xstrdup(obj) );
2502 output( "%s: %s\n", obj_dir_path( make, obj ), source->filename );
2503 output( "\t$(SED_CMD) %s >$@ || (rm -f $@ && false)\n", source->filename );
2504 output( "%s:", obj_dir_path( make, obj ));
2505 output_filenames( dependencies );
2506 output( "\n" );
2507 add_install_rule( make, install_rules, obj, xstrdup( obj ),
2508 strmake( "d$(datadir)/wine/%s", obj ));
2510 else if (!strcmp( ext, "sfd" )) /* font file */
2512 char *ttf_file = src_dir_path( make, strmake( "%s.ttf", obj ));
2513 if (fontforge && !make->src_dir)
2515 output( "%s: %s\n", ttf_file, source->filename );
2516 output( "\t%s -script %s %s $@\n",
2517 fontforge, top_dir_path( make, "fonts/genttf.ff" ), source->filename );
2518 if (!(source->file->flags & FLAG_SFD_FONTS)) output( "all: %s\n", ttf_file );
2520 if (source->file->flags & FLAG_INSTALL)
2522 strarray_add( &install_rules[INSTALL_LIB], strmake( "%s.ttf", obj ));
2523 strarray_add( &install_rules[INSTALL_LIB], strmake( "D$(fontdir)/%s.ttf", obj ));
2525 if (source->file->flags & FLAG_SFD_FONTS)
2527 struct strarray *array = source->file->args;
2529 for (i = 0; i < array->count; i++)
2531 char *font = strtok( xstrdup(array->str[i]), " \t" );
2532 char *args = strtok( NULL, "" );
2534 strarray_add( &all_targets, xstrdup( font ));
2535 output( "%s: %s %s\n", obj_dir_path( make, font ),
2536 tools_path( make, "sfnt2fon" ), ttf_file );
2537 output( "\t%s -o $@ %s %s\n", tools_path( make, "sfnt2fon" ), ttf_file, args );
2538 strarray_add( &install_rules[INSTALL_LIB], xstrdup(font) );
2539 strarray_add( &install_rules[INSTALL_LIB], strmake( "d$(fontdir)/%s", font ));
2543 else if (!strcmp( ext, "svg" )) /* svg file */
2545 if (convert && rsvg && icotool && !make->src_dir)
2547 output( "%s.ico %s.bmp: %s\n",
2548 src_dir_path( make, obj ), src_dir_path( make, obj ), source->filename );
2549 output( "\tCONVERT=\"%s\" ICOTOOL=\"%s\" RSVG=\"%s\" %s %s $@\n", convert, icotool, rsvg,
2550 top_dir_path( make, "tools/buildimage" ), source->filename );
2553 else if (!strcmp( ext, "po" )) /* po file */
2555 output( "%s.mo: %s\n", obj_dir_path( make, obj ), source->filename );
2556 output( "\t%s -o $@ %s\n", msgfmt, source->filename );
2557 strarray_add( &all_targets, strmake( "%s.mo", obj ));
2559 else if (!strcmp( ext, "res" ))
2561 strarray_add( &res_files, source->name );
2563 else if (!strcmp( ext, "tlb" ))
2565 strarray_add( &all_targets, source->name );
2567 else if (!strcmp( ext, "h" ) || !strcmp( ext, "rh" ) || !strcmp( ext, "inl" )) /* header file */
2569 if (source->file->flags & FLAG_GENERATED)
2571 strarray_add( &all_targets, source->name );
2573 else
2575 strarray_add( &install_rules[INSTALL_DEV], source->name );
2576 strarray_add( &install_rules[INSTALL_DEV],
2577 strmake( "D$(includedir)/%s", get_include_install_path( source->name ) ));
2580 else
2582 int need_cross = make->testdll ||
2583 (source->file->flags & FLAG_C_IMPLIB) ||
2584 (make->module && make->staticlib);
2586 if ((source->file->flags & FLAG_GENERATED) &&
2587 (!make->testdll || !strendswith( source->filename, "testlist.c" )))
2588 strarray_add( &clean_files, source->filename );
2589 if (source->file->flags & FLAG_C_IMPLIB) strarray_add( &implib_objs, strmake( "%s.o", obj ));
2590 strarray_add( &object_files, strmake( "%s.o", obj ));
2591 output( "%s.o: %s\n", obj_dir_path( make, obj ), source->filename );
2592 output( "\t$(CC) -c -o $@ %s", source->filename );
2593 output_filenames( includes );
2594 output_filenames( make->define_args );
2595 output_filenames( extradefs );
2596 if (make->module || make->staticlib || make->sharedlib || make->testdll)
2598 output_filenames( dll_flags );
2599 if (make->use_msvcrt) output_filenames( msvcrt_flags );
2601 output_filenames( extra_cflags );
2602 output_filenames( cpp_flags );
2603 output_filename( "$(CFLAGS)" );
2604 output( "\n" );
2605 if (crosstarget && need_cross)
2607 strarray_add( &crossobj_files, strmake( "%s.cross.o", obj ));
2608 output( "%s.cross.o: %s\n", obj_dir_path( make, obj ), source->filename );
2609 output( "\t$(CROSSCC) -c -o $@ %s", source->filename );
2610 output_filenames( includes );
2611 output_filenames( make->define_args );
2612 output_filenames( extradefs );
2613 output_filename( "-DWINE_CROSSTEST" );
2614 output_filenames( cpp_flags );
2615 output_filename( "$(CFLAGS)" );
2616 output( "\n" );
2618 if (make->testdll && !strcmp( ext, "c" ) && !(source->file->flags & FLAG_GENERATED))
2620 strarray_add( &ok_files, strmake( "%s.ok", obj ));
2621 output( "%s.ok:\n", obj_dir_path( make, obj ));
2622 output( "\t%s $(RUNTESTFLAGS) -T %s -M %s -p %s%s %s && touch $@\n",
2623 top_dir_path( make, "tools/runtest" ), top_obj_dir_path( make, "" ), make->testdll,
2624 replace_extension( make->testdll, ".dll", "_test.exe" ), dll_ext, obj );
2626 if (!strcmp( ext, "c" ) && !(source->file->flags & FLAG_GENERATED))
2627 strarray_add( &c2man_files, source->filename );
2628 output( "%s.o", obj_dir_path( make, obj ));
2629 if (crosstarget && need_cross) output( " %s.cross.o", obj_dir_path( make, obj ));
2630 output( ":" );
2631 output_filenames( dependencies );
2632 output( "\n" );
2634 free( obj );
2637 /* rules for files that depend on multiple sources */
2639 if (dlldata_files.count)
2641 output( "%s: %s %s\n", obj_dir_path( make, "dlldata.c" ),
2642 tools_path( make, "widl" ), src_dir_path( make, "Makefile.in" ));
2643 output( "\t%s --dlldata-only -o $@", tools_path( make, "widl" ));
2644 output_filenames( dlldata_files );
2645 output( "\n" );
2648 if (make->module && !make->staticlib)
2650 struct strarray all_libs = empty_strarray;
2651 struct strarray dep_libs = empty_strarray;
2652 char *module_path = obj_dir_path( make, make->module );
2653 char *spec_file = NULL;
2655 if (!make->appmode.count)
2656 spec_file = src_dir_path( make, replace_extension( make->module, ".dll", ".spec" ));
2657 strarray_addall( &all_libs, add_import_libs( make, &dep_libs, make->delayimports, 0 ));
2658 strarray_addall( &all_libs, add_import_libs( make, &dep_libs, make->imports, 0 ));
2659 add_import_libs( make, &dep_libs, get_default_imports( make ), 0 ); /* dependencies only */
2660 strarray_addall( &all_libs, add_default_libraries( make, &dep_libs ));
2662 if (*dll_ext)
2664 for (i = 0; i < make->delayimports.count; i++)
2665 strarray_add( &all_libs, strmake( "-Wb,-d%s", make->delayimports.str[i] ));
2666 strarray_add( &all_targets, strmake( "%s%s", make->module, dll_ext ));
2667 strarray_add( &all_targets, strmake( "%s.fake", make->module ));
2668 add_install_rule( make, install_rules, make->module, strmake( "%s%s", make->module, dll_ext ),
2669 strmake( "p$(dlldir)/%s%s", make->module, dll_ext ));
2670 add_install_rule( make, install_rules, make->module, strmake( "%s.fake", make->module ),
2671 strmake( "d$(fakedlldir)/%s", make->module ));
2672 output( "%s%s %s.fake:", module_path, dll_ext, module_path );
2674 else
2676 strarray_add( &all_libs, "-lwine" );
2677 strarray_add( &all_targets, make->module );
2678 add_install_rule( make, install_rules, make->module, make->module,
2679 strmake( "p$(%s)/%s", spec_file ? "dlldir" : "bindir", make->module ));
2680 output( "%s:", module_path );
2682 if (spec_file) output_filename( spec_file );
2683 output_filenames_obj_dir( make, object_files );
2684 output_filenames_obj_dir( make, res_files );
2685 output_filenames( dep_libs );
2686 output( "\n" );
2687 output( "\t%s -o $@", tools_path( make, "winegcc" ));
2688 output_filename( strmake( "-B%s", tools_dir_path( make, "winebuild" )));
2689 if (tools_dir) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make, "" )));
2690 output_filenames( target_flags );
2691 output_filenames( unwind_flags );
2692 if (spec_file)
2694 output( " -shared %s", spec_file );
2695 output_filenames( make->extradllflags );
2697 else output_filenames( make->appmode );
2698 output_filenames_obj_dir( make, object_files );
2699 output_filenames_obj_dir( make, res_files );
2700 output_filenames( all_libs );
2701 output_filename( "$(LDFLAGS)" );
2702 output( "\n" );
2704 if (spec_file && make->importlib)
2706 char *importlib_path = obj_dir_path( make, strmake( "lib%s", make->importlib ));
2707 if (*dll_ext && !implib_objs.count)
2709 strarray_add( &clean_files, strmake( "lib%s.def", make->importlib ));
2710 output( "%s.def: %s %s\n", importlib_path, tools_path( make, "winebuild" ), spec_file );
2711 output( "\t%s -w --def -o $@ --export %s", tools_path( make, "winebuild" ), spec_file );
2712 output_filenames( target_flags );
2713 if (make->is_win16) output_filename( "-m16" );
2714 output( "\n" );
2715 add_install_rule( make, install_rules, make->importlib,
2716 strmake( "lib%s.def", make->importlib ),
2717 strmake( "d$(dlldir)/lib%s.def", make->importlib ));
2719 else
2721 strarray_add( &clean_files, strmake( "lib%s.a", make->importlib ));
2722 output( "%s.a: %s %s", importlib_path, tools_path( make, "winebuild" ), spec_file );
2723 output_filenames_obj_dir( make, implib_objs );
2724 output( "\n" );
2725 output( "\t%s -w --implib -o $@ --export %s", tools_path( make, "winebuild" ), spec_file );
2726 output_filenames( target_flags );
2727 output_filenames_obj_dir( make, implib_objs );
2728 output( "\n" );
2729 add_install_rule( make, install_rules, make->importlib,
2730 strmake( "lib%s.a", make->importlib ),
2731 strmake( "d$(dlldir)/lib%s.a", make->importlib ));
2733 if (crosstarget && !make->is_win16)
2735 struct strarray cross_files = strarray_replace_extension( &implib_objs, ".o", ".cross.o" );
2736 strarray_add( &clean_files, strmake( "lib%s.cross.a", make->importlib ));
2737 output( "%s.cross.a: %s %s", importlib_path, tools_path( make, "winebuild" ), spec_file );
2738 output_filenames_obj_dir( make, cross_files );
2739 output( "\n" );
2740 output( "\t%s -b %s -w --implib -o $@ --export %s",
2741 tools_path( make, "winebuild" ), crosstarget, spec_file );
2742 output_filenames_obj_dir( make, cross_files );
2743 output( "\n" );
2747 if (spec_file)
2749 if (c2man_files.count)
2751 output( "manpages::\n" );
2752 output( "\t%s -w %s", top_dir_path( make, "tools/c2man.pl" ), spec_file );
2753 output_filename( strmake( "-R%s", top_dir_path( make, "" )));
2754 output_filename( strmake( "-I%s", top_dir_path( make, "include" )));
2755 output_filename( strmake( "-o %s/man%s",
2756 top_obj_dir_path( make, "documentation" ), man_ext ));
2757 output_filenames( c2man_files );
2758 output( "\n" );
2759 output( "htmlpages::\n" );
2760 output( "\t%s -Th -w %s", top_dir_path( make, "tools/c2man.pl" ), spec_file );
2761 output_filename( strmake( "-R%s", top_dir_path( make, "" )));
2762 output_filename( strmake( "-I%s", top_dir_path( make, "include" )));
2763 output_filename( strmake( "-o %s",
2764 top_obj_dir_path( make, "documentation/html" )));
2765 output_filenames( c2man_files );
2766 output( "\n" );
2767 output( "sgmlpages::\n" );
2768 output( "\t%s -Ts -w %s", top_dir_path( make, "tools/c2man.pl" ), spec_file );
2769 output_filename( strmake( "-R%s", top_dir_path( make, "" )));
2770 output_filename( strmake( "-I%s", top_dir_path( make, "include" )));
2771 output_filename( strmake( "-o %s",
2772 top_obj_dir_path( make, "documentation/api-guide" )));
2773 output_filenames( c2man_files );
2774 output( "\n" );
2775 output( "xmlpages::\n" );
2776 output( "\t%s -Tx -w %s", top_dir_path( make, "tools/c2man.pl" ), spec_file );
2777 output_filename( strmake( "-R%s", top_dir_path( make, "" )));
2778 output_filename( strmake( "-I%s", top_dir_path( make, "include" )));
2779 output_filename( strmake( "-o %s",
2780 top_obj_dir_path( make, "documentation/api-guide-xml" )));
2781 output_filenames( c2man_files );
2782 output( "\n" );
2783 strarray_add( &phony_targets, "manpages" );
2784 strarray_add( &phony_targets, "htmlpages" );
2785 strarray_add( &phony_targets, "sgmlpages" );
2786 strarray_add( &phony_targets, "xmlpages" );
2788 else output( "manpages htmlpages sgmlpages xmlpages::\n" );
2790 else if (*dll_ext)
2792 char *binary = replace_extension( make->module, ".exe", "" );
2793 add_install_rule( make, install_rules, binary, tools_dir_path( make, "wineapploader" ),
2794 strmake( "s$(bindir)/%s", binary ));
2798 if (make->staticlib)
2800 strarray_add( &all_targets, make->staticlib );
2801 output( "%s:", obj_dir_path( make, make->staticlib ));
2802 output_filenames_obj_dir( make, object_files );
2803 output( "\n\trm -f $@\n" );
2804 output( "\t$(AR) $(ARFLAGS) $@" );
2805 output_filenames_obj_dir( make, object_files );
2806 output( "\n\t$(RANLIB) $@\n" );
2807 if (crosstarget && make->module)
2809 char *name = replace_extension( make->staticlib, ".a", ".cross.a" );
2811 strarray_add( &all_targets, name );
2812 output( "%s:", obj_dir_path( make, name ));
2813 output_filenames_obj_dir( make, crossobj_files );
2814 output( "\n\trm -f $@\n" );
2815 output( "\t%s-ar $(ARFLAGS) $@", crosstarget );
2816 output_filenames_obj_dir( make, crossobj_files );
2817 output( "\n\t%s-ranlib $@\n", crosstarget );
2821 if (make->sharedlib)
2823 char *basename, *p;
2824 struct strarray names = get_shared_lib_names( make->sharedlib );
2825 struct strarray all_libs = empty_strarray;
2826 struct strarray dep_libs = empty_strarray;
2828 basename = xstrdup( make->sharedlib );
2829 if ((p = strchr( basename, '.' ))) *p = 0;
2831 strarray_addall( &dep_libs, get_local_dependencies( make, basename, in_files ));
2832 strarray_addall( &all_libs, get_expanded_file_local_var( make, basename, "LDFLAGS" ));
2833 strarray_addall( &all_libs, add_default_libraries( make, &dep_libs ));
2835 output( "%s:", obj_dir_path( make, make->sharedlib ));
2836 output_filenames_obj_dir( make, object_files );
2837 output_filenames( dep_libs );
2838 output( "\n" );
2839 output( "\t$(CC) -o $@" );
2840 output_filenames_obj_dir( make, object_files );
2841 output_filenames( all_libs );
2842 output_filename( "$(LDFLAGS)" );
2843 output( "\n" );
2844 add_install_rule( make, install_rules, make->sharedlib, make->sharedlib,
2845 strmake( "p$(libdir)/%s", make->sharedlib ));
2846 for (i = 1; i < names.count; i++)
2848 output( "%s: %s\n", obj_dir_path( make, names.str[i] ), obj_dir_path( make, names.str[i-1] ));
2849 output( "\trm -f $@ && %s %s $@\n", ln_s, names.str[i-1] );
2850 add_install_rule( make, install_rules, names.str[i], names.str[i-1],
2851 strmake( "y$(libdir)/%s", names.str[i] ));
2853 strarray_addall( &all_targets, names );
2856 if (make->importlib && !make->module) /* stand-alone import lib (for libwine) */
2858 char *def_file = replace_extension( make->importlib, ".a", ".def" );
2860 if (!strncmp( def_file, "lib", 3 )) def_file += 3;
2861 output( "%s: %s\n", obj_dir_path( make, make->importlib ), src_dir_path( make, def_file ));
2862 output( "\t%s -l $@ -d %s\n", dlltool, src_dir_path( make, def_file ));
2863 add_install_rule( make, install_rules, make->importlib, make->importlib,
2864 strmake( "d$(libdir)/%s", make->importlib ));
2865 strarray_add( &all_targets, make->importlib );
2868 if (make->testdll)
2870 char *testmodule = replace_extension( make->testdll, ".dll", "_test.exe" );
2871 char *stripped = replace_extension( make->testdll, ".dll", "_test-stripped.exe" );
2872 char *testres = replace_extension( make->testdll, ".dll", "_test.res" );
2873 struct strarray dep_libs = empty_strarray;
2874 struct strarray all_libs = add_import_libs( make, &dep_libs, make->imports, 0 );
2876 add_import_libs( make, &dep_libs, get_default_imports( make ), 0 ); /* dependencies only */
2877 strarray_addall( &all_libs, libs );
2878 strarray_add( &all_targets, strmake( "%s%s", testmodule, dll_ext ));
2879 strarray_add( &clean_files, strmake( "%s%s", stripped, dll_ext ));
2880 output( "%s%s:\n", obj_dir_path( make, testmodule ), dll_ext );
2881 output( "\t%s -o $@", tools_path( make, "winegcc" ));
2882 output_filename( strmake( "-B%s", tools_dir_path( make, "winebuild" )));
2883 if (tools_dir) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make, "" )));
2884 output_filenames( target_flags );
2885 output_filenames( unwind_flags );
2886 output_filenames( make->appmode );
2887 output_filenames_obj_dir( make, object_files );
2888 output_filenames_obj_dir( make, res_files );
2889 output_filenames( all_libs );
2890 output_filename( "$(LDFLAGS)" );
2891 output( "\n" );
2892 output( "%s%s:\n", obj_dir_path( make, stripped ), dll_ext );
2893 output( "\t%s -o $@", tools_path( make, "winegcc" ));
2894 output_filename( strmake( "-B%s", tools_dir_path( make, "winebuild" )));
2895 if (tools_dir) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make, "" )));
2896 output_filenames( target_flags );
2897 output_filenames( unwind_flags );
2898 output_filename( strmake( "-Wb,-F,%s", testmodule ));
2899 output_filenames( make->appmode );
2900 output_filenames_obj_dir( make, object_files );
2901 output_filenames_obj_dir( make, res_files );
2902 output_filenames( all_libs );
2903 output_filename( "$(LDFLAGS)" );
2904 output( "\n" );
2905 output( "%s%s %s%s:", obj_dir_path( make, testmodule ), dll_ext,
2906 obj_dir_path( make, stripped ), dll_ext );
2907 output_filenames_obj_dir( make, object_files );
2908 output_filenames_obj_dir( make, res_files );
2909 output_filenames( dep_libs );
2910 output( "\n" );
2912 if (!make->disabled)
2913 output( "all: %s/%s\n", top_obj_dir_path( make, "programs/winetest" ), testres );
2914 output( "%s/%s: %s%s\n", top_obj_dir_path( make, "programs/winetest" ), testres,
2915 obj_dir_path( make, stripped ), dll_ext );
2916 output( "\techo \"%s TESTRES \\\"%s%s\\\"\" | %s -o $@\n",
2917 testmodule, obj_dir_path( make, stripped ), dll_ext, tools_path( make, "wrc" ));
2919 if (crosstarget)
2921 char *crosstest = replace_extension( make->testdll, ".dll", "_crosstest.exe" );
2923 dep_libs = empty_strarray;
2924 all_libs = add_import_libs( make, &dep_libs, make->imports, 1 );
2925 add_import_libs( make, &dep_libs, get_default_imports( make ), 1 ); /* dependencies only */
2926 strarray_addall( &all_libs, libs );
2927 strarray_add( &clean_files, crosstest );
2928 output( "%s:", obj_dir_path( make, crosstest ));
2929 output_filenames_obj_dir( make, crossobj_files );
2930 output_filenames_obj_dir( make, res_files );
2931 output_filenames( dep_libs );
2932 output( "\n" );
2933 output( "\t%s -o $@ -b %s", tools_path( make, "winegcc" ), crosstarget );
2934 output_filename( strmake( "-B%s", tools_dir_path( make, "winebuild" )));
2935 if (tools_dir) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make, "" )));
2936 output_filename( "--lib-suffix=.cross.a" );
2937 output_filenames_obj_dir( make, crossobj_files );
2938 output_filenames_obj_dir( make, res_files );
2939 output_filenames( all_libs );
2940 output_filename( "$(LDFLAGS)" );
2941 output( "\n" );
2942 if (!make->disabled)
2944 output( "%s: %s\n", obj_dir_path( make, "crosstest" ), obj_dir_path( make, crosstest ));
2945 strarray_add( &phony_targets, obj_dir_path( make, "crosstest" ));
2946 if (make->obj_dir) output( "crosstest: %s\n", obj_dir_path( make, "crosstest" ));
2950 output_filenames_obj_dir( make, ok_files );
2951 output( ": %s%s ../%s%s\n", testmodule, dll_ext, make->testdll, dll_ext );
2952 if (!make->disabled)
2954 output( "check test:" );
2955 output_filenames_obj_dir( make, ok_files );
2956 output( "\n" );
2957 strarray_add( &phony_targets, "check" );
2958 strarray_add( &phony_targets, "test" );
2960 output( "testclean::\n" );
2961 output( "\trm -f" );
2962 output_filenames_obj_dir( make, ok_files );
2963 output( "\n" );
2964 strarray_addall( &clean_files, ok_files );
2965 strarray_add( &phony_targets, "testclean" );
2968 for (i = 0; i < make->programs.count; i++)
2970 char *program_installed = NULL;
2971 char *program = strmake( "%s%s", make->programs.str[i], exe_ext );
2972 struct strarray deps = get_local_dependencies( make, make->programs.str[i], in_files );
2973 struct strarray all_libs = get_expanded_file_local_var( make, make->programs.str[i], "LDFLAGS" );
2974 struct strarray objs = get_expanded_file_local_var( make, make->programs.str[i], "OBJS" );
2975 struct strarray symlinks = get_expanded_file_local_var( make, make->programs.str[i], "SYMLINKS" );
2977 if (!objs.count) objs = object_files;
2978 strarray_addall( &all_libs, add_default_libraries( make, &deps ));
2980 output( "%s:", obj_dir_path( make, program ) );
2981 output_filenames_obj_dir( make, objs );
2982 output_filenames( deps );
2983 output( "\n" );
2984 output( "\t$(CC) -o $@" );
2985 output_filenames_obj_dir( make, objs );
2987 if (strarray_exists( &all_libs, "-lwine" ))
2989 strarray_add( &all_libs, strmake( "-L%s", top_obj_dir_path( make, "libs/wine" )));
2990 if (ldrpath_local && ldrpath_install)
2992 program_installed = strmake( "%s-installed%s", make->programs.str[i], exe_ext );
2993 output_filename( ldrpath_local );
2994 output_filenames( all_libs );
2995 output_filename( "$(LDFLAGS)" );
2996 output( "\n" );
2997 output( "%s:", obj_dir_path( make, program_installed ) );
2998 output_filenames_obj_dir( make, objs );
2999 output_filenames( deps );
3000 output( "\n" );
3001 output( "\t$(CC) -o $@" );
3002 output_filenames_obj_dir( make, objs );
3003 output_filename( ldrpath_install );
3004 strarray_add( &all_targets, program_installed );
3008 output_filenames( all_libs );
3009 output_filename( "$(LDFLAGS)" );
3010 output( "\n" );
3011 strarray_add( &all_targets, program );
3013 if (symlinks.count)
3015 output_filenames_obj_dir( make, symlinks );
3016 output( ": %s\n", obj_dir_path( make, program ));
3017 output( "\trm -f $@ && %s %s $@\n", ln_s, obj_dir_path( make, program ));
3018 strarray_addall( &all_targets, symlinks );
3021 add_install_rule( make, install_rules, program, program_installed ? program_installed : program,
3022 strmake( "p$(bindir)/%s", program ));
3023 for (j = 0; j < symlinks.count; j++)
3024 add_install_rule( make, install_rules, symlinks.str[j], program,
3025 strmake( "y$(bindir)/%s%s", symlinks.str[j], exe_ext ));
3028 for (i = 0; i < make->scripts.count; i++)
3029 add_install_rule( make, install_rules, make->scripts.str[i], make->scripts.str[i],
3030 strmake( "S$(bindir)/%s", make->scripts.str[i] ));
3032 if (!make->disabled)
3034 if (all_targets.count)
3036 output( "all:" );
3037 output_filenames_obj_dir( make, all_targets );
3038 output( "\n" );
3040 strarray_addall( &uninstall_files, output_install_rules( make, install_rules[INSTALL_LIB],
3041 "install-lib", &phony_targets ));
3042 strarray_addall( &uninstall_files, output_install_rules( make, install_rules[INSTALL_DEV],
3043 "install-dev", &phony_targets ));
3044 if (uninstall_files.count)
3046 output( "uninstall::\n" );
3047 output( "\trm -f" );
3048 output_filenames( uninstall_files );
3049 output( "\n" );
3050 strarray_add_uniq( &phony_targets, "uninstall" );
3054 strarray_addall( &clean_files, object_files );
3055 strarray_addall( &clean_files, crossobj_files );
3056 strarray_addall( &clean_files, res_files );
3057 strarray_addall( &clean_files, all_targets );
3058 strarray_addall( &clean_files, get_expanded_make_var_array( make, "EXTRA_TARGETS" ));
3060 if (make->subdirs.count)
3062 struct strarray build_deps = empty_strarray;
3063 struct strarray makefile_deps = empty_strarray;
3064 struct strarray distclean_files = get_expanded_make_var_array( make, "CONFIGURE_TARGETS" );
3066 strarray_add( &distclean_files, obj_dir_path( make, output_makefile_name ));
3067 if (!make->src_dir) strarray_add( &distclean_files, obj_dir_path( make, ".gitignore" ));
3068 for (i = 0; i < make->subdirs.count; i++)
3070 const struct makefile *submake = make->submakes[i];
3072 strarray_add( &makefile_deps, top_dir_path( make, base_dir_path( submake,
3073 strmake ( "%s.in", output_makefile_name ))));
3074 strarray_add( &distclean_files, base_dir_path( submake, output_makefile_name ));
3075 if (!make->src_dir) strarray_add( &distclean_files, base_dir_path( submake, ".gitignore" ));
3076 if (submake->testdll) strarray_add( &distclean_files, base_dir_path( submake, "testlist.c" ));
3077 strarray_addall( &build_deps, output_importlib_symlinks( make, submake ));
3079 output( "Makefile:" );
3080 output_filenames( makefile_deps );
3081 output( "\n" );
3082 output( "distclean::\n");
3083 output( "\trm -f" );
3084 output_filenames( distclean_files );
3085 output( "\n" );
3086 strarray_add( &phony_targets, "distclean" );
3088 if (build_deps.count)
3090 output( "__builddeps__:" );
3091 output_filenames( build_deps );
3092 output( "\n" );
3093 strarray_addall( &clean_files, build_deps );
3095 if (get_expanded_make_variable( make, "GETTEXTPO_LIBS" )) output_po_files( make );
3098 if (clean_files.count)
3100 output( "%s::\n", obj_dir_path( make, "clean" ));
3101 output( "\trm -f" );
3102 output_filenames_obj_dir( make, clean_files );
3103 output( "\n" );
3104 if (make->obj_dir) output( "__clean__: %s\n", obj_dir_path( make, "clean" ));
3105 strarray_add( &phony_targets, obj_dir_path( make, "clean" ));
3108 if (phony_targets.count)
3110 output( ".PHONY:" );
3111 output_filenames( phony_targets );
3112 output( "\n" );
3115 if (!make->base_dir)
3116 strarray_addall( &clean_files, get_expanded_make_var_array( make, "CONFIGURE_TARGETS" ));
3117 return clean_files;
3121 /*******************************************************************
3122 * create_temp_file
3124 static FILE *create_temp_file( const char *orig )
3126 char *name = xmalloc( strlen(orig) + 13 );
3127 unsigned int i, id = getpid();
3128 int fd;
3129 FILE *ret = NULL;
3131 for (i = 0; i < 100; i++)
3133 sprintf( name, "%s.tmp%08x", orig, id );
3134 if ((fd = open( name, O_RDWR | O_CREAT | O_EXCL, 0666 )) != -1)
3136 ret = fdopen( fd, "w" );
3137 break;
3139 if (errno != EEXIST) break;
3140 id += 7777;
3142 if (!ret) fatal_error( "failed to create output file for '%s'\n", orig );
3143 temp_file_name = name;
3144 return ret;
3148 /*******************************************************************
3149 * rename_temp_file
3151 static void rename_temp_file( const char *dest )
3153 int ret = rename( temp_file_name, dest );
3154 if (ret == -1 && errno == EEXIST)
3156 /* rename doesn't overwrite on windows */
3157 unlink( dest );
3158 ret = rename( temp_file_name, dest );
3160 if (ret == -1) fatal_error( "failed to rename output file to '%s'\n", dest );
3161 temp_file_name = NULL;
3165 /*******************************************************************
3166 * are_files_identical
3168 static int are_files_identical( FILE *file1, FILE *file2 )
3170 for (;;)
3172 char buffer1[8192], buffer2[8192];
3173 int size1 = fread( buffer1, 1, sizeof(buffer1), file1 );
3174 int size2 = fread( buffer2, 1, sizeof(buffer2), file2 );
3175 if (size1 != size2) return 0;
3176 if (!size1) return feof( file1 ) && feof( file2 );
3177 if (memcmp( buffer1, buffer2, size1 )) return 0;
3182 /*******************************************************************
3183 * rename_temp_file_if_changed
3185 static void rename_temp_file_if_changed( const char *dest )
3187 FILE *file1, *file2;
3188 int do_rename = 1;
3190 if ((file1 = fopen( dest, "r" )))
3192 if ((file2 = fopen( temp_file_name, "r" )))
3194 do_rename = !are_files_identical( file1, file2 );
3195 fclose( file2 );
3197 fclose( file1 );
3199 if (!do_rename)
3201 unlink( temp_file_name );
3202 temp_file_name = NULL;
3204 else rename_temp_file( dest );
3208 /*******************************************************************
3209 * output_linguas
3211 static void output_linguas( const struct makefile *make )
3213 const char *dest = base_dir_path( make, "LINGUAS" );
3214 struct incl_file *source;
3216 output_file = create_temp_file( dest );
3218 output( "# Automatically generated by make depend; DO NOT EDIT!!\n" );
3219 LIST_FOR_EACH_ENTRY( source, &make->sources, struct incl_file, entry )
3220 if (strendswith( source->name, ".po" ))
3221 output( "%s\n", replace_extension( source->name, ".po", "" ));
3223 if (fclose( output_file )) fatal_perror( "write" );
3224 output_file = NULL;
3225 rename_temp_file_if_changed( dest );
3229 /*******************************************************************
3230 * output_testlist
3232 static void output_testlist( const struct makefile *make )
3234 const char *dest = base_dir_path( make, "testlist.c" );
3235 struct strarray files = empty_strarray;
3236 struct incl_file *source;
3237 unsigned int i;
3239 LIST_FOR_EACH_ENTRY( source, &make->sources, struct incl_file, entry )
3241 if (source->file->flags & FLAG_GENERATED) continue;
3242 if (!strendswith( source->name, ".c" )) continue;
3243 strarray_add( &files, replace_extension( source->name, ".c", "" ));
3246 output_file = create_temp_file( dest );
3248 output( "/* Automatically generated by make depend; DO NOT EDIT!! */\n\n" );
3249 output( "#define WIN32_LEAN_AND_MEAN\n" );
3250 output( "#include <windows.h>\n\n" );
3251 output( "#define STANDALONE\n" );
3252 output( "#include \"wine/test.h\"\n\n" );
3254 for (i = 0; i < files.count; i++) output( "extern void func_%s(void);\n", files.str[i] );
3255 output( "\n" );
3256 output( "const struct test winetest_testlist[] =\n" );
3257 output( "{\n" );
3258 for (i = 0; i < files.count; i++) output( " { \"%s\", func_%s },\n", files.str[i], files.str[i] );
3259 output( " { 0, 0 }\n" );
3260 output( "};\n" );
3262 if (fclose( output_file )) fatal_perror( "write" );
3263 output_file = NULL;
3264 rename_temp_file_if_changed( dest );
3268 /*******************************************************************
3269 * output_gitignore
3271 static void output_gitignore( const char *dest, struct strarray files )
3273 int i;
3275 output_file = create_temp_file( dest );
3277 output( "# Automatically generated by make depend; DO NOT EDIT!!\n" );
3278 for (i = 0; i < files.count; i++)
3280 if (!strchr( files.str[i], '/' )) output( "/" );
3281 output( "%s\n", files.str[i] );
3284 if (fclose( output_file )) fatal_perror( "write" );
3285 output_file = NULL;
3286 rename_temp_file( dest );
3290 /*******************************************************************
3291 * output_top_variables
3293 static void output_top_variables( const struct makefile *make )
3295 unsigned int i;
3296 struct strarray *vars = &top_makefile->vars;
3298 if (!make->base_dir) return; /* don't output variables in the top makefile */
3300 output( "# Automatically generated by make depend; DO NOT EDIT!!\n\n" );
3301 output( "all:\n\n" );
3302 for (i = 0; i < vars->count; i += 2)
3304 if (!strcmp( vars->str[i], "SUBDIRS" )) continue; /* not inherited */
3305 output( "%s = %s\n", vars->str[i], get_make_variable( make, vars->str[i] ));
3307 output( "\n" );
3311 /*******************************************************************
3312 * output_dependencies
3314 static void output_dependencies( const struct makefile *make )
3316 struct strarray targets, ignore_files = empty_strarray;
3317 char buffer[1024];
3318 FILE *src_file;
3319 int found = 0;
3321 if (make->base_dir) create_dir( make->base_dir );
3323 output_file_name = base_dir_path( make, output_makefile_name );
3324 output_file = create_temp_file( output_file_name );
3325 output_top_variables( make );
3327 /* copy the contents of the source makefile */
3328 src_file = open_input_makefile( make );
3329 while (fgets( buffer, sizeof(buffer), src_file ) && !found)
3331 if (fwrite( buffer, 1, strlen(buffer), output_file ) != strlen(buffer)) fatal_perror( "write" );
3332 found = !strncmp( buffer, separator, strlen(separator) );
3334 if (fclose( src_file )) fatal_perror( "close" );
3335 input_file_name = NULL;
3337 if (!found) output( "\n%s (everything below this line is auto-generated; DO NOT EDIT!!)\n", separator );
3338 targets = output_sources( make );
3340 fclose( output_file );
3341 output_file = NULL;
3342 rename_temp_file( output_file_name );
3344 strarray_add( &ignore_files, ".gitignore" );
3345 strarray_add( &ignore_files, "Makefile" );
3346 if (make->testdll)
3348 output_testlist( make );
3349 strarray_add( &ignore_files, "testlist.c" );
3351 if (make->base_dir && !strcmp( make->base_dir, "po" ))
3353 output_linguas( make );
3354 strarray_add( &ignore_files, "LINGUAS" );
3356 strarray_addall( &ignore_files, targets );
3357 if (!make->src_dir) output_gitignore( base_dir_path( make, ".gitignore" ), ignore_files );
3359 create_file_directories( make, targets );
3361 output_file_name = NULL;
3365 /*******************************************************************
3366 * load_sources
3368 static void load_sources( struct makefile *make )
3370 static const char *source_vars[] =
3372 "C_SRCS",
3373 "OBJC_SRCS",
3374 "RC_SRCS",
3375 "MC_SRCS",
3376 "IDL_SRCS",
3377 "BISON_SRCS",
3378 "LEX_SRCS",
3379 "HEADER_SRCS",
3380 "XTEMPLATE_SRCS",
3381 "SVG_SRCS",
3382 "FONT_SRCS",
3383 "IN_SRCS",
3384 "PO_SRCS",
3385 "MANPAGES",
3386 NULL
3388 const char **var;
3389 unsigned int i;
3390 struct strarray value;
3391 struct incl_file *file;
3393 if (root_src_dir)
3395 make->top_src_dir = concat_paths( make->top_obj_dir, root_src_dir );
3396 make->src_dir = concat_paths( make->top_src_dir, make->base_dir );
3398 strarray_set_value( &make->vars, "top_builddir", top_obj_dir_path( make, "" ));
3399 strarray_set_value( &make->vars, "top_srcdir", top_dir_path( make, "" ));
3400 strarray_set_value( &make->vars, "srcdir", src_dir_path( make, "" ));
3402 make->parent_dir = get_expanded_make_variable( make, "PARENTSRC" );
3403 make->module = get_expanded_make_variable( make, "MODULE" );
3404 make->testdll = get_expanded_make_variable( make, "TESTDLL" );
3405 make->sharedlib = get_expanded_make_variable( make, "SHAREDLIB" );
3406 make->staticlib = get_expanded_make_variable( make, "STATICLIB" );
3407 make->importlib = get_expanded_make_variable( make, "IMPORTLIB" );
3409 make->programs = get_expanded_make_var_array( make, "PROGRAMS" );
3410 make->scripts = get_expanded_make_var_array( make, "SCRIPTS" );
3411 make->appmode = get_expanded_make_var_array( make, "APPMODE" );
3412 make->imports = get_expanded_make_var_array( make, "IMPORTS" );
3413 make->delayimports = get_expanded_make_var_array( make, "DELAYIMPORTS" );
3414 make->extradllflags = get_expanded_make_var_array( make, "EXTRADLLFLAGS" );
3415 make->install_lib = get_expanded_make_var_array( make, "INSTALL_LIB" );
3416 make->install_dev = get_expanded_make_var_array( make, "INSTALL_DEV" );
3418 if (make->module && strendswith( make->module, ".a" )) make->staticlib = make->module;
3420 make->disabled = make->base_dir && strarray_exists( &disabled_dirs, make->base_dir );
3421 make->is_win16 = strarray_exists( &make->extradllflags, "-m16" );
3422 make->use_msvcrt = strarray_exists( &make->appmode, "-mno-cygwin" );
3424 for (i = 0; i < make->imports.count && !make->use_msvcrt; i++)
3425 make->use_msvcrt = !strncmp( make->imports.str[i], "msvcr", 5 ) ||
3426 !strcmp( make->imports.str[i], "ucrtbase" );
3428 if (make->module && !make->install_lib.count) strarray_add( &make->install_lib, make->module );
3430 make->include_paths = empty_strarray;
3431 make->define_args = empty_strarray;
3432 strarray_add( &make->define_args, "-D__WINESRC__" );
3434 value = get_expanded_make_var_array( make, "EXTRAINCL" );
3435 for (i = 0; i < value.count; i++)
3436 if (!strncmp( value.str[i], "-I", 2 ))
3437 strarray_add_uniq( &make->include_paths, value.str[i] + 2 );
3438 else
3439 strarray_add_uniq( &make->define_args, value.str[i] );
3440 strarray_addall( &make->define_args, get_expanded_make_var_array( make, "EXTRADEFS" ));
3442 list_init( &make->sources );
3443 list_init( &make->includes );
3445 for (var = source_vars; *var; var++)
3447 value = get_expanded_make_var_array( make, *var );
3448 for (i = 0; i < value.count; i++) add_src_file( make, value.str[i] );
3451 add_generated_sources( make );
3453 value = get_expanded_make_var_array( make, "EXTRA_OBJS" );
3454 for (i = 0; i < value.count; i++)
3456 /* default to .c for unknown extra object files */
3457 if (strendswith( value.str[i], ".o" ))
3458 add_generated_source( make, value.str[i], replace_extension( value.str[i], ".o", ".c" ) );
3459 else
3460 add_generated_source( make, value.str[i], NULL );
3463 LIST_FOR_EACH_ENTRY( file, &make->includes, struct incl_file, entry ) parse_file( make, file, 0 );
3467 /*******************************************************************
3468 * parse_makeflags
3470 static void parse_makeflags( const char *flags )
3472 const char *p = flags;
3473 char *var, *buffer = xmalloc( strlen(flags) + 1 );
3475 while (*p)
3477 while (isspace(*p)) p++;
3478 var = buffer;
3479 while (*p && !isspace(*p))
3481 if (*p == '\\' && p[1]) p++;
3482 *var++ = *p++;
3484 *var = 0;
3485 if (var > buffer) set_make_variable( &cmdline_vars, buffer );
3490 /*******************************************************************
3491 * parse_option
3493 static int parse_option( const char *opt )
3495 if (opt[0] != '-')
3497 if (strchr( opt, '=' )) return set_make_variable( &cmdline_vars, opt );
3498 return 0;
3500 switch(opt[1])
3502 case 'f':
3503 if (opt[2]) output_makefile_name = opt + 2;
3504 break;
3505 case 'R':
3506 relative_dir_mode = 1;
3507 break;
3508 default:
3509 fprintf( stderr, "Unknown option '%s'\n%s", opt, Usage );
3510 exit(1);
3512 return 1;
3516 /*******************************************************************
3517 * main
3519 int main( int argc, char *argv[] )
3521 const char *makeflags = getenv( "MAKEFLAGS" );
3522 int i, j;
3524 if (makeflags) parse_makeflags( makeflags );
3526 i = 1;
3527 while (i < argc)
3529 if (parse_option( argv[i] ))
3531 for (j = i; j < argc; j++) argv[j] = argv[j+1];
3532 argc--;
3534 else i++;
3537 if (relative_dir_mode)
3539 char *relpath;
3541 if (argc != 3)
3543 fprintf( stderr, "Option -R needs two directories\n%s", Usage );
3544 exit( 1 );
3546 relpath = get_relative_path( argv[1], argv[2] );
3547 printf( "%s\n", relpath ? relpath : "." );
3548 exit( 0 );
3551 atexit( cleanup_files );
3552 signal( SIGTERM, exit_on_signal );
3553 signal( SIGINT, exit_on_signal );
3554 #ifdef SIGHUP
3555 signal( SIGHUP, exit_on_signal );
3556 #endif
3558 for (i = 0; i < HASH_SIZE; i++) list_init( &files[i] );
3560 top_makefile = parse_makefile( NULL );
3562 target_flags = get_expanded_make_var_array( top_makefile, "TARGETFLAGS" );
3563 msvcrt_flags = get_expanded_make_var_array( top_makefile, "MSVCRTFLAGS" );
3564 dll_flags = get_expanded_make_var_array( top_makefile, "DLLFLAGS" );
3565 extra_cflags = get_expanded_make_var_array( top_makefile, "EXTRACFLAGS" );
3566 cpp_flags = get_expanded_make_var_array( top_makefile, "CPPFLAGS" );
3567 unwind_flags = get_expanded_make_var_array( top_makefile, "UNWINDFLAGS" );
3568 libs = get_expanded_make_var_array( top_makefile, "LIBS" );
3570 root_src_dir = get_expanded_make_variable( top_makefile, "srcdir" );
3571 tools_dir = get_expanded_make_variable( top_makefile, "TOOLSDIR" );
3572 tools_ext = get_expanded_make_variable( top_makefile, "TOOLSEXT" );
3573 exe_ext = get_expanded_make_variable( top_makefile, "EXEEXT" );
3574 man_ext = get_expanded_make_variable( top_makefile, "api_manext" );
3575 dll_ext = (exe_ext && !strcmp( exe_ext, ".exe" )) ? "" : ".so";
3576 crosstarget = get_expanded_make_variable( top_makefile, "CROSSTARGET" );
3577 fontforge = get_expanded_make_variable( top_makefile, "FONTFORGE" );
3578 convert = get_expanded_make_variable( top_makefile, "CONVERT" );
3579 rsvg = get_expanded_make_variable( top_makefile, "RSVG" );
3580 icotool = get_expanded_make_variable( top_makefile, "ICOTOOL" );
3581 dlltool = get_expanded_make_variable( top_makefile, "DLLTOOL" );
3582 msgfmt = get_expanded_make_variable( top_makefile, "MSGFMT" );
3583 ln_s = get_expanded_make_variable( top_makefile, "LN_S" );
3585 if (root_src_dir && !strcmp( root_src_dir, "." )) root_src_dir = NULL;
3586 if (tools_dir && !strcmp( tools_dir, "." )) tools_dir = NULL;
3587 if (!exe_ext) exe_ext = "";
3588 if (!tools_ext) tools_ext = "";
3589 if (!man_ext) man_ext = "3w";
3591 if (argc == 1)
3593 disabled_dirs = get_expanded_make_var_array( top_makefile, "DISABLED_SUBDIRS" );
3594 top_makefile->subdirs = get_expanded_make_var_array( top_makefile, "SUBDIRS" );
3595 top_makefile->submakes = xmalloc( top_makefile->subdirs.count * sizeof(*top_makefile->submakes) );
3597 for (i = 0; i < top_makefile->subdirs.count; i++)
3598 top_makefile->submakes[i] = parse_makefile( top_makefile->subdirs.str[i] );
3600 load_sources( top_makefile );
3601 for (i = 0; i < top_makefile->subdirs.count; i++)
3602 load_sources( top_makefile->submakes[i] );
3604 for (i = 0; i < top_makefile->subdirs.count; i++)
3605 output_dependencies( top_makefile->submakes[i] );
3607 output_dependencies( top_makefile );
3608 return 0;
3611 for (i = 1; i < argc; i++)
3613 struct makefile *make = parse_makefile( argv[i] );
3614 load_sources( make );
3615 output_dependencies( make );
3617 return 0;