d3dcompiler_43: Turn variable 'c' into a static constant.
[wine.git] / tools / makedep.c
blobe3bb04ae824cfcf28dfa644eb8ddc4d77ef83ca1
1 /*
2 * Generate include file dependencies
4 * Copyright 1996, 2013 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
22 #define NO_LIBWINE_PORT
23 #include "wine/port.h"
25 #include <assert.h>
26 #include <ctype.h>
27 #include <errno.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <stdarg.h>
31 #include <signal.h>
32 #include <string.h>
33 #ifdef HAVE_UNISTD_H
34 # include <unistd.h>
35 #endif
36 #include "wine/list.h"
38 struct strarray
40 unsigned int count; /* strings in use */
41 unsigned int size; /* total allocated size */
42 const char **str;
45 enum incl_type
47 INCL_NORMAL, /* #include "foo.h" */
48 INCL_SYSTEM, /* #include <foo.h> */
49 INCL_IMPORT, /* idl import "foo.idl" */
50 INCL_IMPORTLIB, /* idl importlib "foo.tlb" */
51 INCL_CPP_QUOTE, /* idl cpp_quote("#include \"foo.h\"") */
52 INCL_CPP_QUOTE_SYSTEM /* idl cpp_quote("#include <foo.h>") */
55 struct dependency
57 int line; /* source line where this header is included */
58 enum incl_type type; /* type of include */
59 char *name; /* header name */
62 struct file
64 struct list entry;
65 char *name; /* full file name relative to cwd */
66 void *args; /* custom arguments for makefile rule */
67 unsigned int flags; /* flags (see below) */
68 unsigned int deps_count; /* files in use */
69 unsigned int deps_size; /* total allocated size */
70 struct dependency *deps; /* all header dependencies */
73 struct incl_file
75 struct list entry;
76 struct file *file;
77 char *name;
78 char *filename;
79 char *sourcename; /* source file name for generated headers */
80 struct incl_file *included_by; /* file that included this one */
81 int included_line; /* line where this file was included */
82 enum incl_type type; /* type of include */
83 struct incl_file *owner;
84 unsigned int files_count; /* files in use */
85 unsigned int files_size; /* total allocated size */
86 struct incl_file **files;
87 struct strarray dependencies; /* file dependencies */
90 #define FLAG_GENERATED 0x000001 /* generated file */
91 #define FLAG_INSTALL 0x000002 /* file to install */
92 #define FLAG_IDL_PROXY 0x000100 /* generates a proxy (_p.c) file */
93 #define FLAG_IDL_CLIENT 0x000200 /* generates a client (_c.c) file */
94 #define FLAG_IDL_SERVER 0x000400 /* generates a server (_s.c) file */
95 #define FLAG_IDL_IDENT 0x000800 /* generates an ident (_i.c) file */
96 #define FLAG_IDL_REGISTER 0x001000 /* generates a registration (_r.res) file */
97 #define FLAG_IDL_TYPELIB 0x002000 /* generates a typelib (.tlb) file */
98 #define FLAG_IDL_REGTYPELIB 0x004000 /* generates a registered typelib (_t.res) file */
99 #define FLAG_IDL_HEADER 0x008000 /* generates a header (.h) file */
100 #define FLAG_RC_PO 0x010000 /* rc file contains translations */
101 #define FLAG_C_IMPLIB 0x020000 /* file is part of an import library */
102 #define FLAG_SFD_FONTS 0x040000 /* sfd file generated bitmap fonts */
104 static const struct
106 unsigned int flag;
107 const char *ext;
108 } idl_outputs[] =
110 { FLAG_IDL_TYPELIB, ".tlb" },
111 { FLAG_IDL_REGTYPELIB, "_t.res" },
112 { FLAG_IDL_CLIENT, "_c.c" },
113 { FLAG_IDL_IDENT, "_i.c" },
114 { FLAG_IDL_PROXY, "_p.c" },
115 { FLAG_IDL_SERVER, "_s.c" },
116 { FLAG_IDL_REGISTER, "_r.res" },
117 { FLAG_IDL_HEADER, ".h" }
120 #define HASH_SIZE 997
122 static struct list files[HASH_SIZE];
124 static const struct strarray empty_strarray;
126 enum install_rules { INSTALL_LIB, INSTALL_DEV, NB_INSTALL_RULES };
128 /* variables common to all makefiles */
129 static struct strarray linguas;
130 static struct strarray dll_flags;
131 static struct strarray target_flags;
132 static struct strarray msvcrt_flags;
133 static struct strarray extra_cflags;
134 static struct strarray cpp_flags;
135 static struct strarray unwind_flags;
136 static struct strarray widl_flags;
137 static struct strarray libs;
138 static struct strarray enable_tests;
139 static struct strarray cmdline_vars;
140 static struct strarray disabled_dirs;
141 static const char *root_src_dir;
142 static const char *tools_dir;
143 static const char *tools_ext;
144 static const char *exe_ext;
145 static const char *dll_ext;
146 static const char *man_ext;
147 static const char *crosstarget;
148 static const char *fontforge;
149 static const char *convert;
150 static const char *rsvg;
151 static const char *icotool;
152 static const char *dlltool;
153 static const char *msgfmt;
154 static const char *ln_s;
156 struct makefile
158 /* values determined from input makefile */
159 struct strarray vars;
160 struct strarray include_paths;
161 struct strarray include_args;
162 struct strarray define_args;
163 struct strarray programs;
164 struct strarray scripts;
165 struct strarray appmode;
166 struct strarray imports;
167 struct strarray subdirs;
168 struct strarray delayimports;
169 struct strarray extradllflags;
170 struct strarray install_lib;
171 struct strarray install_dev;
172 struct list sources;
173 struct list includes;
174 const char *base_dir;
175 const char *src_dir;
176 const char *obj_dir;
177 const char *top_src_dir;
178 const char *top_obj_dir;
179 const char *parent_dir;
180 const char *module;
181 const char *testdll;
182 const char *sharedlib;
183 const char *staticlib;
184 const char *staticimplib;
185 const char *importlib;
186 int disabled;
187 int use_msvcrt;
188 int is_win16;
189 struct makefile **submakes;
191 /* values generated at output time */
192 struct strarray in_files;
193 struct strarray ok_files;
194 struct strarray clean_files;
195 struct strarray distclean_files;
196 struct strarray uninstall_files;
197 struct strarray object_files;
198 struct strarray crossobj_files;
199 struct strarray c2man_files;
200 struct strarray dlldata_files;
201 struct strarray implib_objs;
202 struct strarray all_targets;
203 struct strarray phony_targets;
204 struct strarray dependencies;
205 struct strarray install_rules[NB_INSTALL_RULES];
208 static struct makefile *top_makefile;
210 static const char separator[] = "### Dependencies";
211 static const char *output_makefile_name = "Makefile";
212 static const char *input_file_name;
213 static const char *output_file_name;
214 static const char *temp_file_name;
215 static int relative_dir_mode;
216 static int input_line;
217 static int output_column;
218 static FILE *output_file;
220 static const char Usage[] =
221 "Usage: makedep [options] [directories]\n"
222 "Options:\n"
223 " -R from to Compute the relative path between two directories\n"
224 " -fxxx Store output in file 'xxx' (default: Makefile)\n";
227 #ifndef __GNUC__
228 #define __attribute__(x)
229 #endif
231 static void fatal_error( const char *msg, ... ) __attribute__ ((__format__ (__printf__, 1, 2)));
232 static void fatal_perror( const char *msg, ... ) __attribute__ ((__format__ (__printf__, 1, 2)));
233 static void output( const char *format, ... ) __attribute__ ((__format__ (__printf__, 1, 2)));
234 static char *strmake( const char* fmt, ... ) __attribute__ ((__format__ (__printf__, 1, 2)));
236 /*******************************************************************
237 * fatal_error
239 static void fatal_error( const char *msg, ... )
241 va_list valist;
242 va_start( valist, msg );
243 if (input_file_name)
245 fprintf( stderr, "%s:", input_file_name );
246 if (input_line) fprintf( stderr, "%d:", input_line );
247 fprintf( stderr, " error: " );
249 else fprintf( stderr, "makedep: error: " );
250 vfprintf( stderr, msg, valist );
251 va_end( valist );
252 exit(1);
256 /*******************************************************************
257 * fatal_perror
259 static void fatal_perror( const char *msg, ... )
261 va_list valist;
262 va_start( valist, msg );
263 if (input_file_name)
265 fprintf( stderr, "%s:", input_file_name );
266 if (input_line) fprintf( stderr, "%d:", input_line );
267 fprintf( stderr, " error: " );
269 else fprintf( stderr, "makedep: error: " );
270 vfprintf( stderr, msg, valist );
271 perror( " " );
272 va_end( valist );
273 exit(1);
277 /*******************************************************************
278 * cleanup_files
280 static void cleanup_files(void)
282 if (temp_file_name) unlink( temp_file_name );
283 if (output_file_name) unlink( output_file_name );
287 /*******************************************************************
288 * exit_on_signal
290 static void exit_on_signal( int sig )
292 exit( 1 ); /* this will call the atexit functions */
296 /*******************************************************************
297 * xmalloc
299 static void *xmalloc( size_t size )
301 void *res;
302 if (!(res = malloc (size ? size : 1)))
303 fatal_error( "Virtual memory exhausted.\n" );
304 return res;
308 /*******************************************************************
309 * xrealloc
311 static void *xrealloc (void *ptr, size_t size)
313 void *res;
314 assert( size );
315 if (!(res = realloc( ptr, size )))
316 fatal_error( "Virtual memory exhausted.\n" );
317 return res;
320 /*******************************************************************
321 * xstrdup
323 static char *xstrdup( const char *str )
325 char *res = strdup( str );
326 if (!res) fatal_error( "Virtual memory exhausted.\n" );
327 return res;
331 /*******************************************************************
332 * strmake
334 static char *strmake( const char* fmt, ... )
336 int n;
337 size_t size = 100;
338 va_list ap;
340 for (;;)
342 char *p = xmalloc (size);
343 va_start(ap, fmt);
344 n = vsnprintf (p, size, fmt, ap);
345 va_end(ap);
346 if (n == -1) size *= 2;
347 else if ((size_t)n >= size) size = n + 1;
348 else return xrealloc( p, n + 1 );
349 free(p);
354 /*******************************************************************
355 * strendswith
357 static int strendswith( const char* str, const char* end )
359 size_t l = strlen( str );
360 size_t m = strlen( end );
362 return l >= m && strcmp(str + l - m, end) == 0;
366 /*******************************************************************
367 * output
369 static void output( const char *format, ... )
371 int ret;
372 va_list valist;
374 va_start( valist, format );
375 ret = vfprintf( output_file, format, valist );
376 va_end( valist );
377 if (ret < 0) fatal_perror( "output" );
378 if (format[0] && format[strlen(format) - 1] == '\n') output_column = 0;
379 else output_column += ret;
383 /*******************************************************************
384 * strarray_add
386 static void strarray_add( struct strarray *array, const char *str )
388 if (array->count == array->size)
390 if (array->size) array->size *= 2;
391 else array->size = 16;
392 array->str = xrealloc( array->str, sizeof(array->str[0]) * array->size );
394 array->str[array->count++] = str;
398 /*******************************************************************
399 * strarray_addall
401 static void strarray_addall( struct strarray *array, struct strarray added )
403 unsigned int i;
405 for (i = 0; i < added.count; i++) strarray_add( array, added.str[i] );
409 /*******************************************************************
410 * strarray_exists
412 static int strarray_exists( const struct strarray *array, const char *str )
414 unsigned int i;
416 for (i = 0; i < array->count; i++) if (!strcmp( array->str[i], str )) return 1;
417 return 0;
421 /*******************************************************************
422 * strarray_add_uniq
424 static void strarray_add_uniq( struct strarray *array, const char *str )
426 if (!strarray_exists( array, str )) strarray_add( array, str );
430 /*******************************************************************
431 * strarray_addall_uniq
433 static void strarray_addall_uniq( struct strarray *array, struct strarray added )
435 unsigned int i;
437 for (i = 0; i < added.count; i++) strarray_add_uniq( array, added.str[i] );
441 /*******************************************************************
442 * strarray_get_value
444 * Find a value in a name/value pair string array.
446 static const char *strarray_get_value( const struct strarray *array, const char *name )
448 int pos, res, min = 0, max = array->count / 2 - 1;
450 while (min <= max)
452 pos = (min + max) / 2;
453 if (!(res = strcmp( array->str[pos * 2], name ))) return array->str[pos * 2 + 1];
454 if (res < 0) min = pos + 1;
455 else max = pos - 1;
457 return NULL;
461 /*******************************************************************
462 * strarray_set_value
464 * Define a value in a name/value pair string array.
466 static void strarray_set_value( struct strarray *array, const char *name, const char *value )
468 int i, pos, res, min = 0, max = array->count / 2 - 1;
470 while (min <= max)
472 pos = (min + max) / 2;
473 if (!(res = strcmp( array->str[pos * 2], name )))
475 /* redefining a variable replaces the previous value */
476 array->str[pos * 2 + 1] = value;
477 return;
479 if (res < 0) min = pos + 1;
480 else max = pos - 1;
482 strarray_add( array, NULL );
483 strarray_add( array, NULL );
484 for (i = array->count - 1; i > min * 2 + 1; i--) array->str[i] = array->str[i - 2];
485 array->str[min * 2] = name;
486 array->str[min * 2 + 1] = value;
490 /*******************************************************************
491 * strarray_set_qsort
493 static void strarray_qsort( struct strarray *array, int (*func)(const char **, const char **) )
495 if (array->count) qsort( array->str, array->count, sizeof(*array->str), (void *)func );
499 /*******************************************************************
500 * output_filename
502 static void output_filename( const char *name )
504 if (output_column + strlen(name) + 1 > 100)
506 output( " \\\n" );
507 output( " " );
509 else if (output_column) output( " " );
510 output( "%s", name );
514 /*******************************************************************
515 * output_filenames
517 static void output_filenames( struct strarray array )
519 unsigned int i;
521 for (i = 0; i < array.count; i++) output_filename( array.str[i] );
525 /*******************************************************************
526 * output_rm_filenames
528 static void output_rm_filenames( struct strarray array )
530 static const unsigned int max_cmdline = 30000; /* to be on the safe side */
531 unsigned int i, len;
533 if (!array.count) return;
534 output( "\trm -f" );
535 for (i = len = 0; i < array.count; i++)
537 if (len > max_cmdline)
539 output( "\n" );
540 output( "\trm -f" );
541 len = 0;
543 output_filename( array.str[i] );
544 len += strlen( array.str[i] ) + 1;
546 output( "\n" );
550 /*******************************************************************
551 * get_extension
553 static char *get_extension( char *filename )
555 char *ext = strrchr( filename, '.' );
556 if (ext && strchr( ext, '/' )) ext = NULL;
557 return ext;
561 /*******************************************************************
562 * replace_extension
564 static char *replace_extension( const char *name, const char *old_ext, const char *new_ext )
566 char *ret;
567 size_t name_len = strlen( name );
568 size_t ext_len = strlen( old_ext );
570 if (name_len >= ext_len && !strcmp( name + name_len - ext_len, old_ext )) name_len -= ext_len;
571 ret = xmalloc( name_len + strlen( new_ext ) + 1 );
572 memcpy( ret, name, name_len );
573 strcpy( ret + name_len, new_ext );
574 return ret;
578 /*******************************************************************
579 * replace_filename
581 static char *replace_filename( const char *path, const char *name )
583 const char *p;
584 char *ret;
585 size_t len;
587 if (!path) return xstrdup( name );
588 if (!(p = strrchr( path, '/' ))) return xstrdup( name );
589 len = p - path + 1;
590 ret = xmalloc( len + strlen( name ) + 1 );
591 memcpy( ret, path, len );
592 strcpy( ret + len, name );
593 return ret;
597 /*******************************************************************
598 * strarray_replace_extension
600 static struct strarray strarray_replace_extension( const struct strarray *array,
601 const char *old_ext, const char *new_ext )
603 unsigned int i;
604 struct strarray ret;
606 ret.count = ret.size = array->count;
607 ret.str = xmalloc( sizeof(ret.str[0]) * ret.size );
608 for (i = 0; i < array->count; i++) ret.str[i] = replace_extension( array->str[i], old_ext, new_ext );
609 return ret;
613 /*******************************************************************
614 * replace_substr
616 static char *replace_substr( const char *str, const char *start, size_t len, const char *replace )
618 size_t pos = start - str;
619 char *ret = xmalloc( pos + strlen(replace) + strlen(start + len) + 1 );
620 memcpy( ret, str, pos );
621 strcpy( ret + pos, replace );
622 strcat( ret + pos, start + len );
623 return ret;
627 /*******************************************************************
628 * get_relative_path
630 * Determine where the destination path is located relative to the 'from' path.
632 static char *get_relative_path( const char *from, const char *dest )
634 const char *start;
635 char *ret, *p;
636 unsigned int dotdots = 0;
638 /* a path of "." is equivalent to an empty path */
639 if (!strcmp( from, "." )) from = "";
641 for (;;)
643 while (*from == '/') from++;
644 while (*dest == '/') dest++;
645 start = dest; /* save start of next path element */
646 if (!*from) break;
648 while (*from && *from != '/' && *from == *dest) { from++; dest++; }
649 if ((!*from || *from == '/') && (!*dest || *dest == '/')) continue;
651 /* count remaining elements in 'from' */
654 dotdots++;
655 while (*from && *from != '/') from++;
656 while (*from == '/') from++;
658 while (*from);
659 break;
662 if (!start[0] && !dotdots) return NULL; /* empty path */
664 ret = xmalloc( 3 * dotdots + strlen( start ) + 1 );
665 for (p = ret; dotdots; dotdots--, p += 3) memcpy( p, "../", 3 );
667 if (start[0]) strcpy( p, start );
668 else p[-1] = 0; /* remove trailing slash */
669 return ret;
673 /*******************************************************************
674 * concat_paths
676 static char *concat_paths( const char *base, const char *path )
678 if (!base || !base[0]) return xstrdup( path && path[0] ? path : "." );
679 if (!path || !path[0]) return xstrdup( base );
680 if (path[0] == '/') return xstrdup( path );
681 return strmake( "%s/%s", base, path );
685 /*******************************************************************
686 * base_dir_path
688 static char *base_dir_path( const struct makefile *make, const char *path )
690 return concat_paths( make->base_dir, path );
694 /*******************************************************************
695 * obj_dir_path
697 static char *obj_dir_path( const struct makefile *make, const char *path )
699 return concat_paths( make->obj_dir, path );
703 /*******************************************************************
704 * src_dir_path
706 static char *src_dir_path( const struct makefile *make, const char *path )
708 if (make->src_dir) return concat_paths( make->src_dir, path );
709 return obj_dir_path( make, path );
713 /*******************************************************************
714 * top_obj_dir_path
716 static char *top_obj_dir_path( const struct makefile *make, const char *path )
718 return concat_paths( make->top_obj_dir, path );
722 /*******************************************************************
723 * top_src_dir_path
725 static char *top_src_dir_path( const struct makefile *make, const char *path )
727 if (make->top_src_dir) return concat_paths( make->top_src_dir, path );
728 return top_obj_dir_path( make, path );
732 /*******************************************************************
733 * root_dir_path
735 static char *root_dir_path( const char *path )
737 return concat_paths( root_src_dir, path );
741 /*******************************************************************
742 * tools_dir_path
744 static char *tools_dir_path( const struct makefile *make, const char *path )
746 if (tools_dir) return top_obj_dir_path( make, strmake( "%s/tools/%s", tools_dir, path ));
747 return top_obj_dir_path( make, strmake( "tools/%s", path ));
751 /*******************************************************************
752 * tools_path
754 static char *tools_path( const struct makefile *make, const char *name )
756 return strmake( "%s/%s%s", tools_dir_path( make, name ), name, tools_ext );
760 /*******************************************************************
761 * get_line
763 static char *get_line( FILE *file )
765 static char *buffer;
766 static size_t size;
768 if (!size)
770 size = 1024;
771 buffer = xmalloc( size );
773 if (!fgets( buffer, size, file )) return NULL;
774 input_line++;
776 for (;;)
778 char *p = buffer + strlen(buffer);
779 /* if line is larger than buffer, resize buffer */
780 while (p == buffer + size - 1 && p[-1] != '\n')
782 buffer = xrealloc( buffer, size * 2 );
783 if (!fgets( buffer + size - 1, size + 1, file )) break;
784 p = buffer + strlen(buffer);
785 size *= 2;
787 if (p > buffer && p[-1] == '\n')
789 *(--p) = 0;
790 if (p > buffer && p[-1] == '\r') *(--p) = 0;
791 if (p > buffer && p[-1] == '\\')
793 *(--p) = 0;
794 /* line ends in backslash, read continuation line */
795 if (!fgets( p, size - (p - buffer), file )) return buffer;
796 input_line++;
797 continue;
800 return buffer;
805 /*******************************************************************
806 * hash_filename
808 static unsigned int hash_filename( const char *name )
810 /* FNV-1 hash */
811 unsigned int ret = 2166136261u;
812 while (*name) ret = (ret * 16777619) ^ *name++;
813 return ret % HASH_SIZE;
817 /*******************************************************************
818 * add_file
820 static struct file *add_file( const char *name )
822 struct file *file = xmalloc( sizeof(*file) );
823 memset( file, 0, sizeof(*file) );
824 file->name = xstrdup( name );
825 return file;
829 /*******************************************************************
830 * add_dependency
832 static void add_dependency( struct file *file, const char *name, enum incl_type type )
834 /* enforce some rules for the Wine tree */
836 if (!memcmp( name, "../", 3 ))
837 fatal_error( "#include directive with relative path not allowed\n" );
839 if (!strcmp( name, "config.h" ))
841 if (strendswith( file->name, ".h" ))
842 fatal_error( "config.h must not be included by a header file\n" );
843 if (file->deps_count)
844 fatal_error( "config.h must be included before anything else\n" );
846 else if (!strcmp( name, "wine/port.h" ))
848 if (strendswith( file->name, ".h" ))
849 fatal_error( "wine/port.h must not be included by a header file\n" );
850 if (!file->deps_count) fatal_error( "config.h must be included before wine/port.h\n" );
851 if (file->deps_count > 1)
852 fatal_error( "wine/port.h must be included before everything except config.h\n" );
853 if (strcmp( file->deps[0].name, "config.h" ))
854 fatal_error( "config.h must be included before wine/port.h\n" );
857 if (file->deps_count >= file->deps_size)
859 file->deps_size *= 2;
860 if (file->deps_size < 16) file->deps_size = 16;
861 file->deps = xrealloc( file->deps, file->deps_size * sizeof(*file->deps) );
863 file->deps[file->deps_count].line = input_line;
864 file->deps[file->deps_count].type = type;
865 file->deps[file->deps_count].name = xstrdup( name );
866 file->deps_count++;
870 /*******************************************************************
871 * find_src_file
873 static struct incl_file *find_src_file( const struct makefile *make, const char *name )
875 struct incl_file *file;
877 LIST_FOR_EACH_ENTRY( file, &make->sources, struct incl_file, entry )
878 if (!strcmp( name, file->name )) return file;
879 return NULL;
882 /*******************************************************************
883 * find_include_file
885 static struct incl_file *find_include_file( const struct makefile *make, const char *name )
887 struct incl_file *file;
889 LIST_FOR_EACH_ENTRY( file, &make->includes, struct incl_file, entry )
890 if (!strcmp( name, file->name )) return file;
891 return NULL;
894 /*******************************************************************
895 * add_include
897 * Add an include file if it doesn't already exists.
899 static struct incl_file *add_include( struct makefile *make, struct incl_file *parent,
900 const char *name, int line, enum incl_type type )
902 struct incl_file *include;
904 if (parent->files_count >= parent->files_size)
906 parent->files_size *= 2;
907 if (parent->files_size < 16) parent->files_size = 16;
908 parent->files = xrealloc( parent->files, parent->files_size * sizeof(*parent->files) );
911 LIST_FOR_EACH_ENTRY( include, &make->includes, struct incl_file, entry )
912 if (!strcmp( name, include->name )) goto found;
914 include = xmalloc( sizeof(*include) );
915 memset( include, 0, sizeof(*include) );
916 include->name = xstrdup(name);
917 include->included_by = parent;
918 include->included_line = line;
919 include->type = type;
920 list_add_tail( &make->includes, &include->entry );
921 found:
922 parent->files[parent->files_count++] = include;
923 return include;
927 /*******************************************************************
928 * add_generated_source
930 * Add a generated source file to the list.
932 static struct incl_file *add_generated_source( struct makefile *make,
933 const char *name, const char *filename )
935 struct incl_file *file;
937 if ((file = find_src_file( make, name ))) return file; /* we already have it */
938 file = xmalloc( sizeof(*file) );
939 memset( file, 0, sizeof(*file) );
940 file->file = add_file( name );
941 file->name = xstrdup( name );
942 file->filename = obj_dir_path( make, filename ? filename : name );
943 file->file->flags = FLAG_GENERATED;
944 list_add_tail( &make->sources, &file->entry );
945 return file;
949 /*******************************************************************
950 * parse_include_directive
952 static void parse_include_directive( struct file *source, char *str )
954 char quote, *include, *p = str;
956 while (*p && isspace(*p)) p++;
957 if (*p != '\"' && *p != '<' ) return;
958 quote = *p++;
959 if (quote == '<') quote = '>';
960 include = p;
961 while (*p && (*p != quote)) p++;
962 if (!*p) fatal_error( "malformed include directive '%s'\n", str );
963 *p = 0;
964 add_dependency( source, include, (quote == '>') ? INCL_SYSTEM : INCL_NORMAL );
968 /*******************************************************************
969 * parse_pragma_directive
971 static void parse_pragma_directive( struct file *source, char *str )
973 char *flag, *p = str;
975 if (!isspace( *p )) return;
976 while (*p && isspace(*p)) p++;
977 p = strtok( p, " \t" );
978 if (strcmp( p, "makedep" )) return;
980 while ((flag = strtok( NULL, " \t" )))
982 if (!strcmp( flag, "depend" ))
984 while ((p = strtok( NULL, " \t" ))) add_dependency( source, p, INCL_NORMAL );
985 return;
987 else if (!strcmp( flag, "install" )) source->flags |= FLAG_INSTALL;
989 if (strendswith( source->name, ".idl" ))
991 if (!strcmp( flag, "header" )) source->flags |= FLAG_IDL_HEADER;
992 else if (!strcmp( flag, "proxy" )) source->flags |= FLAG_IDL_PROXY;
993 else if (!strcmp( flag, "client" )) source->flags |= FLAG_IDL_CLIENT;
994 else if (!strcmp( flag, "server" )) source->flags |= FLAG_IDL_SERVER;
995 else if (!strcmp( flag, "ident" )) source->flags |= FLAG_IDL_IDENT;
996 else if (!strcmp( flag, "typelib" )) source->flags |= FLAG_IDL_TYPELIB;
997 else if (!strcmp( flag, "register" )) source->flags |= FLAG_IDL_REGISTER;
998 else if (!strcmp( flag, "regtypelib" )) source->flags |= FLAG_IDL_REGTYPELIB;
1000 else if (strendswith( source->name, ".rc" ))
1002 if (!strcmp( flag, "po" )) source->flags |= FLAG_RC_PO;
1004 else if (strendswith( source->name, ".sfd" ))
1006 if (!strcmp( flag, "font" ))
1008 struct strarray *array = source->args;
1010 if (!array)
1012 source->args = array = xmalloc( sizeof(*array) );
1013 *array = empty_strarray;
1014 source->flags |= FLAG_SFD_FONTS;
1016 strarray_add( array, xstrdup( strtok( NULL, "" )));
1017 return;
1020 else if (!strcmp( flag, "implib" )) source->flags |= FLAG_C_IMPLIB;
1025 /*******************************************************************
1026 * parse_cpp_directive
1028 static void parse_cpp_directive( struct file *source, char *str )
1030 while (*str && isspace(*str)) str++;
1031 if (*str++ != '#') return;
1032 while (*str && isspace(*str)) str++;
1034 if (!strncmp( str, "include", 7 ))
1035 parse_include_directive( source, str + 7 );
1036 else if (!strncmp( str, "import", 6 ) && strendswith( source->name, ".m" ))
1037 parse_include_directive( source, str + 6 );
1038 else if (!strncmp( str, "pragma", 6 ))
1039 parse_pragma_directive( source, str + 6 );
1043 /*******************************************************************
1044 * parse_idl_file
1046 static void parse_idl_file( struct file *source, FILE *file )
1048 char *buffer, *include;
1050 input_line = 0;
1052 while ((buffer = get_line( file )))
1054 char quote;
1055 char *p = buffer;
1056 while (*p && isspace(*p)) p++;
1058 if (!strncmp( p, "importlib", 9 ))
1060 p += 9;
1061 while (*p && isspace(*p)) p++;
1062 if (*p++ != '(') continue;
1063 while (*p && isspace(*p)) p++;
1064 if (*p++ != '"') continue;
1065 include = p;
1066 while (*p && (*p != '"')) p++;
1067 if (!*p) fatal_error( "malformed importlib directive\n" );
1068 *p = 0;
1069 add_dependency( source, include, INCL_IMPORTLIB );
1070 continue;
1073 if (!strncmp( p, "import", 6 ))
1075 p += 6;
1076 while (*p && isspace(*p)) p++;
1077 if (*p != '"') continue;
1078 include = ++p;
1079 while (*p && (*p != '"')) p++;
1080 if (!*p) fatal_error( "malformed import directive\n" );
1081 *p = 0;
1082 add_dependency( source, include, INCL_IMPORT );
1083 continue;
1086 /* check for #include inside cpp_quote */
1087 if (!strncmp( p, "cpp_quote", 9 ))
1089 p += 9;
1090 while (*p && isspace(*p)) p++;
1091 if (*p++ != '(') continue;
1092 while (*p && isspace(*p)) p++;
1093 if (*p++ != '"') continue;
1094 if (*p++ != '#') continue;
1095 while (*p && isspace(*p)) p++;
1096 if (strncmp( p, "include", 7 )) continue;
1097 p += 7;
1098 while (*p && isspace(*p)) p++;
1099 if (*p == '\\' && p[1] == '"')
1101 p += 2;
1102 quote = '"';
1104 else
1106 if (*p++ != '<' ) continue;
1107 quote = '>';
1109 include = p;
1110 while (*p && (*p != quote)) p++;
1111 if (!*p || (quote == '"' && p[-1] != '\\'))
1112 fatal_error( "malformed #include directive inside cpp_quote\n" );
1113 if (quote == '"') p--; /* remove backslash */
1114 *p = 0;
1115 add_dependency( source, include, (quote == '>') ? INCL_CPP_QUOTE_SYSTEM : INCL_CPP_QUOTE );
1116 continue;
1119 parse_cpp_directive( source, p );
1123 /*******************************************************************
1124 * parse_c_file
1126 static void parse_c_file( struct file *source, FILE *file )
1128 char *buffer;
1130 input_line = 0;
1131 while ((buffer = get_line( file )))
1133 parse_cpp_directive( source, buffer );
1138 /*******************************************************************
1139 * parse_rc_file
1141 static void parse_rc_file( struct file *source, FILE *file )
1143 char *buffer, *include;
1145 input_line = 0;
1146 while ((buffer = get_line( file )))
1148 char quote;
1149 char *p = buffer;
1150 while (*p && isspace(*p)) p++;
1152 if (p[0] == '/' && p[1] == '*') /* check for magic makedep comment */
1154 p += 2;
1155 while (*p && isspace(*p)) p++;
1156 if (strncmp( p, "@makedep:", 9 )) continue;
1157 p += 9;
1158 while (*p && isspace(*p)) p++;
1159 quote = '"';
1160 if (*p == quote)
1162 include = ++p;
1163 while (*p && *p != quote) p++;
1165 else
1167 include = p;
1168 while (*p && !isspace(*p) && *p != '*') p++;
1170 if (!*p)
1171 fatal_error( "malformed makedep comment\n" );
1172 *p = 0;
1173 add_dependency( source, include, (quote == '>') ? INCL_SYSTEM : INCL_NORMAL );
1174 continue;
1177 parse_cpp_directive( source, buffer );
1182 /*******************************************************************
1183 * parse_in_file
1185 static void parse_in_file( struct file *source, FILE *file )
1187 char *p, *buffer;
1189 /* make sure it gets rebuilt when the version changes */
1190 add_dependency( source, "config.h", INCL_SYSTEM );
1192 if (!strendswith( source->name, ".man.in" )) return; /* not a man page */
1194 input_line = 0;
1195 while ((buffer = get_line( file )))
1197 if (strncmp( buffer, ".TH", 3 )) continue;
1198 if (!(p = strtok( buffer, " \t" ))) continue; /* .TH */
1199 if (!(p = strtok( NULL, " \t" ))) continue; /* program name */
1200 if (!(p = strtok( NULL, " \t" ))) continue; /* man section */
1201 source->args = xstrdup( p );
1202 return;
1207 /*******************************************************************
1208 * parse_sfd_file
1210 static void parse_sfd_file( struct file *source, FILE *file )
1212 char *p, *eol, *buffer;
1214 input_line = 0;
1215 while ((buffer = get_line( file )))
1217 if (strncmp( buffer, "UComments:", 10 )) continue;
1218 p = buffer + 10;
1219 while (*p == ' ') p++;
1220 if (p[0] == '"' && p[1] && buffer[strlen(buffer) - 1] == '"')
1222 p++;
1223 buffer[strlen(buffer) - 1] = 0;
1225 while ((eol = strstr( p, "+AAoA" )))
1227 *eol = 0;
1228 while (*p && isspace(*p)) p++;
1229 if (*p++ == '#')
1231 while (*p && isspace(*p)) p++;
1232 if (!strncmp( p, "pragma", 6 )) parse_pragma_directive( source, p + 6 );
1234 p = eol + 5;
1236 while (*p && isspace(*p)) p++;
1237 if (*p++ != '#') return;
1238 while (*p && isspace(*p)) p++;
1239 if (!strncmp( p, "pragma", 6 )) parse_pragma_directive( source, p + 6 );
1240 return;
1245 static const struct
1247 const char *ext;
1248 void (*parse)( struct file *file, FILE *f );
1249 } parse_functions[] =
1251 { ".c", parse_c_file },
1252 { ".h", parse_c_file },
1253 { ".inl", parse_c_file },
1254 { ".l", parse_c_file },
1255 { ".m", parse_c_file },
1256 { ".rh", parse_c_file },
1257 { ".x", parse_c_file },
1258 { ".y", parse_c_file },
1259 { ".idl", parse_idl_file },
1260 { ".rc", parse_rc_file },
1261 { ".in", parse_in_file },
1262 { ".sfd", parse_sfd_file }
1265 /*******************************************************************
1266 * load_file
1268 static struct file *load_file( const char *name )
1270 struct file *file;
1271 FILE *f;
1272 unsigned int i, hash = hash_filename( name );
1274 LIST_FOR_EACH_ENTRY( file, &files[hash], struct file, entry )
1275 if (!strcmp( name, file->name )) return file;
1277 if (!(f = fopen( name, "r" ))) return NULL;
1279 file = add_file( name );
1280 list_add_tail( &files[hash], &file->entry );
1281 input_file_name = file->name;
1282 input_line = 0;
1284 for (i = 0; i < sizeof(parse_functions) / sizeof(parse_functions[0]); i++)
1286 if (!strendswith( name, parse_functions[i].ext )) continue;
1287 parse_functions[i].parse( file, f );
1288 break;
1291 fclose( f );
1292 input_file_name = NULL;
1294 return file;
1298 /*******************************************************************
1299 * open_include_path_file
1301 * Open a file from a directory on the include path.
1303 static struct file *open_include_path_file( const struct makefile *make, const char *dir,
1304 const char *name, char **filename )
1306 char *src_path = base_dir_path( make, concat_paths( dir, name ));
1307 struct file *ret = load_file( src_path );
1309 if (ret) *filename = src_dir_path( make, concat_paths( dir, name ));
1310 return ret;
1314 /*******************************************************************
1315 * open_file_same_dir
1317 * Open a file in the same directory as the parent.
1319 static struct file *open_file_same_dir( const struct incl_file *parent, const char *name, char **filename )
1321 char *src_path = replace_filename( parent->file->name, name );
1322 struct file *ret = load_file( src_path );
1324 if (ret) *filename = replace_filename( parent->filename, name );
1325 free( src_path );
1326 return ret;
1330 /*******************************************************************
1331 * open_local_file
1333 * Open a file in the source directory of the makefile.
1335 static struct file *open_local_file( const struct makefile *make, const char *path, char **filename )
1337 char *src_path = root_dir_path( base_dir_path( make, path ));
1338 struct file *ret = load_file( src_path );
1340 /* if not found, try parent dir */
1341 if (!ret && make->parent_dir)
1343 free( src_path );
1344 path = strmake( "%s/%s", make->parent_dir, path );
1345 src_path = root_dir_path( base_dir_path( make, path ));
1346 ret = load_file( src_path );
1349 if (ret) *filename = src_dir_path( make, path );
1350 free( src_path );
1351 return ret;
1355 /*******************************************************************
1356 * open_global_file
1358 * Open a file in the top-level source directory.
1360 static struct file *open_global_file( const struct makefile *make, const char *path, char **filename )
1362 char *src_path = root_dir_path( path );
1363 struct file *ret = load_file( src_path );
1365 if (ret) *filename = top_src_dir_path( make, path );
1366 free( src_path );
1367 return ret;
1371 /*******************************************************************
1372 * open_global_header
1374 * Open a file in the global include source directory.
1376 static struct file *open_global_header( const struct makefile *make, const char *path, char **filename )
1378 return open_global_file( make, strmake( "include/%s", path ), filename );
1382 /*******************************************************************
1383 * open_src_file
1385 static struct file *open_src_file( const struct makefile *make, struct incl_file *pFile )
1387 struct file *file = open_local_file( make, pFile->name, &pFile->filename );
1389 if (!file) fatal_perror( "open %s", pFile->name );
1390 return file;
1394 /*******************************************************************
1395 * open_include_file
1397 static struct file *open_include_file( const struct makefile *make, struct incl_file *pFile )
1399 struct file *file = NULL;
1400 char *filename;
1401 unsigned int i, len;
1403 errno = ENOENT;
1405 /* check for generated bison header */
1407 if (strendswith( pFile->name, ".tab.h" ) &&
1408 (file = open_local_file( make, replace_extension( pFile->name, ".tab.h", ".y" ), &filename )))
1410 pFile->sourcename = filename;
1411 pFile->filename = obj_dir_path( make, pFile->name );
1412 return file;
1415 /* check for corresponding idl file in source dir */
1417 if (strendswith( pFile->name, ".h" ) &&
1418 (file = open_local_file( make, replace_extension( pFile->name, ".h", ".idl" ), &filename )))
1420 pFile->sourcename = filename;
1421 pFile->filename = obj_dir_path( make, pFile->name );
1422 return file;
1425 /* check for corresponding tlb file in source dir */
1427 if (strendswith( pFile->name, ".tlb" ) &&
1428 (file = open_local_file( make, replace_extension( pFile->name, ".tlb", ".idl" ), &filename )))
1430 pFile->sourcename = filename;
1431 pFile->filename = obj_dir_path( make, pFile->name );
1432 return file;
1435 /* now try in source dir */
1436 if ((file = open_local_file( make, pFile->name, &pFile->filename ))) return file;
1438 /* check for corresponding idl file in global includes */
1440 if (strendswith( pFile->name, ".h" ) &&
1441 (file = open_global_header( make, replace_extension( pFile->name, ".h", ".idl" ), &filename )))
1443 pFile->sourcename = filename;
1444 pFile->filename = top_obj_dir_path( make, strmake( "include/%s", pFile->name ));
1445 return file;
1448 /* check for corresponding .in file in global includes (for config.h.in) */
1450 if (strendswith( pFile->name, ".h" ) &&
1451 (file = open_global_header( make, replace_extension( pFile->name, ".h", ".h.in" ), &filename )))
1453 pFile->sourcename = filename;
1454 pFile->filename = top_obj_dir_path( make, strmake( "include/%s", pFile->name ));
1455 return file;
1458 /* check for corresponding .x file in global includes */
1460 if (strendswith( pFile->name, "tmpl.h" ) &&
1461 (file = open_global_header( make, replace_extension( pFile->name, ".h", ".x" ), &filename )))
1463 pFile->sourcename = filename;
1464 pFile->filename = top_obj_dir_path( make, strmake( "include/%s", pFile->name ));
1465 return file;
1468 /* check for corresponding .tlb file in global includes */
1470 if (strendswith( pFile->name, ".tlb" ) &&
1471 (file = open_global_header( make, replace_extension( pFile->name, ".tlb", ".idl" ), &filename )))
1473 pFile->sourcename = filename;
1474 pFile->filename = top_obj_dir_path( make, strmake( "include/%s", pFile->name ));
1475 return file;
1478 /* check in global includes source dir */
1480 if ((file = open_global_header( make, pFile->name, &pFile->filename ))) return file;
1482 /* check in global msvcrt includes */
1483 if (make->use_msvcrt &&
1484 (file = open_global_header( make, strmake( "msvcrt/%s", pFile->name ), &pFile->filename )))
1485 return file;
1487 /* now search in include paths */
1488 for (i = 0; i < make->include_paths.count; i++)
1490 const char *dir = make->include_paths.str[i];
1491 const char *prefix = make->top_src_dir ? make->top_src_dir : make->top_obj_dir;
1493 if (prefix)
1495 len = strlen( prefix );
1496 if (!strncmp( dir, prefix, len ) && (!dir[len] || dir[len] == '/'))
1498 while (dir[len] == '/') len++;
1499 file = open_global_file( make, concat_paths( dir + len, pFile->name ), &pFile->filename );
1500 if (file) return file;
1502 if (make->top_src_dir) continue; /* ignore paths that don't point to the top source dir */
1504 if (*dir != '/')
1506 if ((file = open_include_path_file( make, dir, pFile->name, &pFile->filename )))
1507 return file;
1510 if (pFile->type == INCL_SYSTEM) return NULL; /* ignore system files we cannot find */
1512 /* try in src file directory */
1513 if ((file = open_file_same_dir( pFile->included_by, pFile->name, &pFile->filename ))) return file;
1515 fprintf( stderr, "%s:%d: error: ", pFile->included_by->file->name, pFile->included_line );
1516 perror( pFile->name );
1517 pFile = pFile->included_by;
1518 while (pFile && pFile->included_by)
1520 const char *parent = pFile->included_by->sourcename;
1521 if (!parent) parent = pFile->included_by->file->name;
1522 fprintf( stderr, "%s:%d: note: %s was first included here\n",
1523 parent, pFile->included_line, pFile->name );
1524 pFile = pFile->included_by;
1526 exit(1);
1530 /*******************************************************************
1531 * add_all_includes
1533 static void add_all_includes( struct makefile *make, struct incl_file *parent, struct file *file )
1535 unsigned int i;
1537 parent->files_count = 0;
1538 parent->files_size = file->deps_count;
1539 parent->files = xmalloc( parent->files_size * sizeof(*parent->files) );
1540 for (i = 0; i < file->deps_count; i++)
1542 switch (file->deps[i].type)
1544 case INCL_NORMAL:
1545 case INCL_IMPORT:
1546 add_include( make, parent, file->deps[i].name, file->deps[i].line, INCL_NORMAL );
1547 break;
1548 case INCL_IMPORTLIB:
1549 add_include( make, parent, file->deps[i].name, file->deps[i].line, INCL_IMPORTLIB );
1550 break;
1551 case INCL_SYSTEM:
1552 add_include( make, parent, file->deps[i].name, file->deps[i].line, INCL_SYSTEM );
1553 break;
1554 case INCL_CPP_QUOTE:
1555 case INCL_CPP_QUOTE_SYSTEM:
1556 break;
1562 /*******************************************************************
1563 * parse_file
1565 static void parse_file( struct makefile *make, struct incl_file *source, int src )
1567 struct file *file = src ? open_src_file( make, source ) : open_include_file( make, source );
1569 if (!file) return;
1571 source->file = file;
1572 source->files_count = 0;
1573 source->files_size = file->deps_count;
1574 source->files = xmalloc( source->files_size * sizeof(*source->files) );
1576 if (source->sourcename)
1578 if (strendswith( source->sourcename, ".idl" ))
1580 unsigned int i;
1582 if (strendswith( source->name, ".tlb" )) return; /* typelibs don't include anything */
1584 /* generated .h file always includes these */
1585 add_include( make, source, "rpc.h", 0, INCL_NORMAL );
1586 add_include( make, source, "rpcndr.h", 0, INCL_NORMAL );
1587 for (i = 0; i < file->deps_count; i++)
1589 switch (file->deps[i].type)
1591 case INCL_IMPORT:
1592 if (strendswith( file->deps[i].name, ".idl" ))
1593 add_include( make, source, replace_extension( file->deps[i].name, ".idl", ".h" ),
1594 file->deps[i].line, INCL_NORMAL );
1595 else
1596 add_include( make, source, file->deps[i].name, file->deps[i].line, INCL_NORMAL );
1597 break;
1598 case INCL_CPP_QUOTE:
1599 add_include( make, source, file->deps[i].name, file->deps[i].line, INCL_NORMAL );
1600 break;
1601 case INCL_CPP_QUOTE_SYSTEM:
1602 add_include( make, source, file->deps[i].name, file->deps[i].line, INCL_SYSTEM );
1603 break;
1604 case INCL_NORMAL:
1605 case INCL_SYSTEM:
1606 case INCL_IMPORTLIB:
1607 break;
1610 return;
1612 if (strendswith( source->sourcename, ".y" ))
1613 return; /* generated .tab.h doesn't include anything */
1616 add_all_includes( make, source, file );
1620 /*******************************************************************
1621 * add_src_file
1623 * Add a source file to the list.
1625 static struct incl_file *add_src_file( struct makefile *make, const char *name )
1627 struct incl_file *file;
1629 if ((file = find_src_file( make, name ))) return file; /* we already have it */
1630 file = xmalloc( sizeof(*file) );
1631 memset( file, 0, sizeof(*file) );
1632 file->name = xstrdup(name);
1633 list_add_tail( &make->sources, &file->entry );
1634 parse_file( make, file, 1 );
1635 return file;
1639 /*******************************************************************
1640 * open_input_makefile
1642 static FILE *open_input_makefile( const struct makefile *make )
1644 FILE *ret;
1646 if (make->base_dir)
1647 input_file_name = root_dir_path( base_dir_path( make, strmake( "%s.in", output_makefile_name )));
1648 else
1649 input_file_name = output_makefile_name; /* always use output name for main Makefile */
1651 input_line = 0;
1652 if (!(ret = fopen( input_file_name, "r" ))) fatal_perror( "open" );
1653 return ret;
1657 /*******************************************************************
1658 * get_make_variable
1660 static const char *get_make_variable( const struct makefile *make, const char *name )
1662 const char *ret;
1664 if ((ret = strarray_get_value( &cmdline_vars, name ))) return ret;
1665 if ((ret = strarray_get_value( &make->vars, name ))) return ret;
1666 if (top_makefile && (ret = strarray_get_value( &top_makefile->vars, name ))) return ret;
1667 return NULL;
1671 /*******************************************************************
1672 * get_expanded_make_variable
1674 static char *get_expanded_make_variable( const struct makefile *make, const char *name )
1676 const char *var;
1677 char *p, *end, *expand, *tmp;
1679 var = get_make_variable( make, name );
1680 if (!var) return NULL;
1682 p = expand = xstrdup( var );
1683 while ((p = strchr( p, '$' )))
1685 if (p[1] == '(')
1687 if (!(end = strchr( p + 2, ')' ))) fatal_error( "syntax error in '%s'\n", expand );
1688 *end++ = 0;
1689 if (strchr( p + 2, ':' )) fatal_error( "pattern replacement not supported for '%s'\n", p + 2 );
1690 var = get_make_variable( make, p + 2 );
1691 tmp = replace_substr( expand, p, end - p, var ? var : "" );
1692 /* switch to the new string */
1693 p = tmp + (p - expand);
1694 free( expand );
1695 expand = tmp;
1697 else if (p[1] == '{') /* don't expand ${} variables */
1699 if (!(end = strchr( p + 2, '}' ))) fatal_error( "syntax error in '%s'\n", expand );
1700 p = end + 1;
1702 else if (p[1] == '$')
1704 p += 2;
1706 else fatal_error( "syntax error in '%s'\n", expand );
1709 /* consider empty variables undefined */
1710 p = expand;
1711 while (*p && isspace(*p)) p++;
1712 if (*p) return expand;
1713 free( expand );
1714 return NULL;
1718 /*******************************************************************
1719 * get_expanded_make_var_array
1721 static struct strarray get_expanded_make_var_array( const struct makefile *make, const char *name )
1723 struct strarray ret = empty_strarray;
1724 char *value, *token;
1726 if ((value = get_expanded_make_variable( make, name )))
1727 for (token = strtok( value, " \t" ); token; token = strtok( NULL, " \t" ))
1728 strarray_add( &ret, token );
1729 return ret;
1733 /*******************************************************************
1734 * get_expanded_file_local_var
1736 static struct strarray get_expanded_file_local_var( const struct makefile *make, const char *file,
1737 const char *name )
1739 char *p, *var = strmake( "%s_%s", file, name );
1741 for (p = var; *p; p++) if (!isalnum( *p )) *p = '_';
1742 return get_expanded_make_var_array( make, var );
1746 /*******************************************************************
1747 * set_make_variable
1749 static int set_make_variable( struct strarray *array, const char *assignment )
1751 char *p, *name;
1753 p = name = xstrdup( assignment );
1754 while (isalnum(*p) || *p == '_') p++;
1755 if (name == p) return 0; /* not a variable */
1756 if (isspace(*p))
1758 *p++ = 0;
1759 while (isspace(*p)) p++;
1761 if (*p != '=') return 0; /* not an assignment */
1762 *p++ = 0;
1763 while (isspace(*p)) p++;
1765 strarray_set_value( array, name, p );
1766 return 1;
1770 /*******************************************************************
1771 * parse_makefile
1773 static struct makefile *parse_makefile( const char *path )
1775 char *buffer;
1776 FILE *file;
1777 struct makefile *make = xmalloc( sizeof(*make) );
1779 memset( make, 0, sizeof(*make) );
1780 if (path)
1782 make->top_obj_dir = get_relative_path( path, "" );
1783 make->base_dir = path;
1784 if (!strcmp( make->base_dir, "." )) make->base_dir = NULL;
1787 file = open_input_makefile( make );
1788 while ((buffer = get_line( file )))
1790 if (!strncmp( buffer, separator, strlen(separator) )) break;
1791 if (*buffer == '\t') continue; /* command */
1792 while (isspace( *buffer )) buffer++;
1793 if (*buffer == '#') continue; /* comment */
1794 set_make_variable( &make->vars, buffer );
1796 fclose( file );
1797 input_file_name = NULL;
1798 return make;
1802 /*******************************************************************
1803 * add_generated_sources
1805 static void add_generated_sources( struct makefile *make )
1807 struct incl_file *source, *next, *file;
1809 LIST_FOR_EACH_ENTRY_SAFE( source, next, &make->sources, struct incl_file, entry )
1811 if (source->file->flags & FLAG_IDL_CLIENT)
1813 file = add_generated_source( make, replace_extension( source->name, ".idl", "_c.c" ), NULL );
1814 add_dependency( file->file, replace_extension( source->name, ".idl", ".h" ), INCL_NORMAL );
1815 add_all_includes( make, file, file->file );
1817 if (source->file->flags & FLAG_IDL_SERVER)
1819 file = add_generated_source( make, replace_extension( source->name, ".idl", "_s.c" ), NULL );
1820 add_dependency( file->file, "wine/exception.h", INCL_NORMAL );
1821 add_dependency( file->file, replace_extension( source->name, ".idl", ".h" ), INCL_NORMAL );
1822 add_all_includes( make, file, file->file );
1824 if (source->file->flags & FLAG_IDL_IDENT)
1826 file = add_generated_source( make, replace_extension( source->name, ".idl", "_i.c" ), NULL );
1827 add_dependency( file->file, "rpc.h", INCL_NORMAL );
1828 add_dependency( file->file, "rpcndr.h", INCL_NORMAL );
1829 add_dependency( file->file, "guiddef.h", INCL_NORMAL );
1830 add_all_includes( make, file, file->file );
1832 if (source->file->flags & FLAG_IDL_PROXY)
1834 file = add_generated_source( make, "dlldata.o", "dlldata.c" );
1835 add_dependency( file->file, "objbase.h", INCL_NORMAL );
1836 add_dependency( file->file, "rpcproxy.h", INCL_NORMAL );
1837 add_all_includes( make, file, file->file );
1838 file = add_generated_source( make, replace_extension( source->name, ".idl", "_p.c" ), NULL );
1839 add_dependency( file->file, "objbase.h", INCL_NORMAL );
1840 add_dependency( file->file, "rpcproxy.h", INCL_NORMAL );
1841 add_dependency( file->file, "wine/exception.h", INCL_NORMAL );
1842 add_dependency( file->file, replace_extension( source->name, ".idl", ".h" ), INCL_NORMAL );
1843 add_all_includes( make, file, file->file );
1845 if (source->file->flags & FLAG_IDL_TYPELIB)
1847 add_generated_source( make, replace_extension( source->name, ".idl", ".tlb" ), NULL );
1849 if (source->file->flags & FLAG_IDL_REGTYPELIB)
1851 add_generated_source( make, replace_extension( source->name, ".idl", "_t.res" ), NULL );
1853 if (source->file->flags & FLAG_IDL_REGISTER)
1855 add_generated_source( make, replace_extension( source->name, ".idl", "_r.res" ), NULL );
1857 if (source->file->flags & FLAG_IDL_HEADER)
1859 add_generated_source( make, replace_extension( source->name, ".idl", ".h" ), NULL );
1861 if (!source->file->flags && strendswith( source->name, ".idl" ))
1863 add_generated_source( make, replace_extension( source->name, ".idl", ".h" ), NULL );
1865 if (strendswith( source->name, ".x" ))
1867 add_generated_source( make, replace_extension( source->name, ".x", ".h" ), NULL );
1869 if (strendswith( source->name, ".y" ))
1871 file = add_generated_source( make, replace_extension( source->name, ".y", ".tab.c" ), NULL );
1872 /* steal the includes list from the source file */
1873 file->files_count = source->files_count;
1874 file->files_size = source->files_size;
1875 file->files = source->files;
1876 source->files_count = source->files_size = 0;
1877 source->files = NULL;
1879 if (strendswith( source->name, ".l" ))
1881 file = add_generated_source( make, replace_extension( source->name, ".l", ".yy.c" ), NULL );
1882 /* steal the includes list from the source file */
1883 file->files_count = source->files_count;
1884 file->files_size = source->files_size;
1885 file->files = source->files;
1886 source->files_count = source->files_size = 0;
1887 source->files = NULL;
1889 if (source->file->flags & FLAG_C_IMPLIB)
1891 if (!make->staticimplib && make->importlib && *dll_ext)
1892 make->staticimplib = strmake( "lib%s.a", make->importlib );
1894 if (strendswith( source->name, ".po" ))
1896 if (!make->disabled)
1897 strarray_add_uniq( &linguas, replace_extension( source->name, ".po", "" ));
1900 if (make->testdll)
1902 file = add_generated_source( make, "testlist.o", "testlist.c" );
1903 add_dependency( file->file, "wine/test.h", INCL_NORMAL );
1904 add_all_includes( make, file, file->file );
1909 /*******************************************************************
1910 * create_dir
1912 static void create_dir( const char *dir )
1914 char *p, *path;
1916 p = path = xstrdup( dir );
1917 while ((p = strchr( p, '/' )))
1919 *p = 0;
1920 if (mkdir( path, 0755 ) == -1 && errno != EEXIST) fatal_perror( "mkdir %s", path );
1921 *p++ = '/';
1922 while (*p == '/') p++;
1924 if (mkdir( path, 0755 ) == -1 && errno != EEXIST) fatal_perror( "mkdir %s", path );
1925 free( path );
1929 /*******************************************************************
1930 * create_file_directories
1932 * Create the base directories of all the files.
1934 static void create_file_directories( const struct makefile *make, struct strarray files )
1936 struct strarray subdirs = empty_strarray;
1937 unsigned int i;
1938 char *dir;
1940 for (i = 0; i < files.count; i++)
1942 if (!strchr( files.str[i], '/' )) continue;
1943 dir = base_dir_path( make, files.str[i] );
1944 *strrchr( dir, '/' ) = 0;
1945 strarray_add_uniq( &subdirs, dir );
1948 for (i = 0; i < subdirs.count; i++) create_dir( subdirs.str[i] );
1952 /*******************************************************************
1953 * output_filenames_obj_dir
1955 static void output_filenames_obj_dir( const struct makefile *make, struct strarray array )
1957 unsigned int i;
1959 for (i = 0; i < array.count; i++) output_filename( obj_dir_path( make, array.str[i] ));
1963 /*******************************************************************
1964 * get_dependencies
1966 static void get_dependencies( struct incl_file *file, struct incl_file *source )
1968 unsigned int i;
1970 if (!file->filename) return;
1972 if (file != source)
1974 if (file->owner == source) return; /* already processed */
1975 if (file->type == INCL_IMPORTLIB &&
1976 !(source->file->flags & (FLAG_IDL_TYPELIB | FLAG_IDL_REGTYPELIB)))
1977 return; /* library is imported only when building a typelib */
1978 file->owner = source;
1979 strarray_add( &source->dependencies, file->filename );
1981 for (i = 0; i < file->files_count; i++) get_dependencies( file->files[i], source );
1985 /*******************************************************************
1986 * get_local_dependencies
1988 * Get the local dependencies of a given target.
1990 static struct strarray get_local_dependencies( const struct makefile *make, const char *name,
1991 struct strarray targets )
1993 unsigned int i;
1994 struct strarray deps = get_expanded_file_local_var( make, name, "DEPS" );
1996 for (i = 0; i < deps.count; i++)
1998 if (strarray_exists( &targets, deps.str[i] ))
1999 deps.str[i] = obj_dir_path( make, deps.str[i] );
2000 else
2001 deps.str[i] = src_dir_path( make, deps.str[i] );
2003 return deps;
2007 /*******************************************************************
2008 * get_static_lib
2010 * Check if makefile builds the named static library and return the full lib path.
2012 static const char *get_static_lib( const struct makefile *make, const char *name )
2014 if (!make->staticlib) return NULL;
2015 if (strncmp( make->staticlib, "lib", 3 )) return NULL;
2016 if (strncmp( make->staticlib + 3, name, strlen(name) )) return NULL;
2017 if (strcmp( make->staticlib + 3 + strlen(name), ".a" )) return NULL;
2018 return base_dir_path( make, make->staticlib );
2022 /*******************************************************************
2023 * add_default_libraries
2025 static struct strarray add_default_libraries( const struct makefile *make, struct strarray *deps )
2027 struct strarray ret = empty_strarray;
2028 struct strarray all_libs = empty_strarray;
2029 unsigned int i, j;
2031 strarray_add( &all_libs, "-lwine_port" );
2032 strarray_addall( &all_libs, get_expanded_make_var_array( make, "EXTRALIBS" ));
2033 strarray_addall( &all_libs, libs );
2035 for (i = 0; i < all_libs.count; i++)
2037 const char *lib = NULL;
2039 if (!strncmp( all_libs.str[i], "-l", 2 ))
2041 const char *name = all_libs.str[i] + 2;
2043 for (j = 0; j < top_makefile->subdirs.count; j++)
2045 const struct makefile *submake = top_makefile->submakes[j];
2047 if ((lib = get_static_lib( submake, name ))) break;
2051 if (lib)
2053 lib = top_obj_dir_path( make, lib );
2054 strarray_add( deps, lib );
2055 strarray_add( &ret, lib );
2057 else strarray_add( &ret, all_libs.str[i] );
2059 return ret;
2063 /*******************************************************************
2064 * add_import_libs
2066 static struct strarray add_import_libs( const struct makefile *make, struct strarray *deps,
2067 struct strarray imports, int cross )
2069 struct strarray ret = empty_strarray;
2070 unsigned int i, j;
2072 for (i = 0; i < imports.count; i++)
2074 const char *name = imports.str[i];
2075 const char *lib = NULL;
2077 for (j = 0; j < top_makefile->subdirs.count; j++)
2079 const struct makefile *submake = top_makefile->submakes[j];
2081 if (submake->importlib && !strcmp( submake->importlib, name ))
2083 if (cross || !*dll_ext || submake->staticimplib)
2084 lib = base_dir_path( submake, strmake( "lib%s.a", name ));
2085 else
2086 strarray_add( deps, top_obj_dir_path( make,
2087 strmake( "%s/lib%s.def", submake->base_dir, name )));
2088 break;
2091 if ((lib = get_static_lib( submake, name ))) break;
2094 if (lib)
2096 if (cross) lib = replace_extension( lib, ".a", ".cross.a" );
2097 lib = top_obj_dir_path( make, lib );
2098 strarray_add( deps, lib );
2099 strarray_add( &ret, lib );
2101 else strarray_add( &ret, strmake( "-l%s", name ));
2103 return ret;
2107 /*******************************************************************
2108 * get_default_imports
2110 static struct strarray get_default_imports( const struct makefile *make )
2112 struct strarray ret = empty_strarray;
2114 if (strarray_exists( &make->extradllflags, "-nodefaultlibs" )) return ret;
2115 if (strarray_exists( &make->appmode, "-mno-cygwin" )) strarray_add( &ret, "msvcrt" );
2116 if (make->is_win16) strarray_add( &ret, "kernel" );
2117 strarray_add( &ret, "kernel32" );
2118 strarray_add( &ret, "ntdll" );
2119 strarray_add( &ret, "winecrt0" );
2120 return ret;
2124 /*******************************************************************
2125 * add_install_rule
2127 static void add_install_rule( struct makefile *make, const char *target,
2128 const char *file, const char *dest )
2130 if (strarray_exists( &make->install_lib, target ))
2132 strarray_add( &make->install_rules[INSTALL_LIB], file );
2133 strarray_add( &make->install_rules[INSTALL_LIB], dest );
2135 else if (strarray_exists( &make->install_dev, target ))
2137 strarray_add( &make->install_rules[INSTALL_DEV], file );
2138 strarray_add( &make->install_rules[INSTALL_DEV], dest );
2143 /*******************************************************************
2144 * get_include_install_path
2146 * Determine the installation path for a given include file.
2148 static const char *get_include_install_path( const char *name )
2150 if (!strncmp( name, "wine/", 5 )) return name + 5;
2151 if (!strncmp( name, "msvcrt/", 7 )) return name;
2152 return strmake( "windows/%s", name );
2156 /*******************************************************************
2157 * get_shared_library_name
2159 * Determine possible names for a shared library with a version number.
2161 static struct strarray get_shared_lib_names( const char *libname )
2163 struct strarray ret = empty_strarray;
2164 const char *ext, *p;
2165 char *name, *first, *second;
2166 size_t len = 0;
2168 strarray_add( &ret, libname );
2170 for (p = libname; (p = strchr( p, '.' )); p++)
2171 if ((len = strspn( p + 1, "0123456789." ))) break;
2173 if (!len) return ret;
2174 ext = p + 1 + len;
2175 if (*ext && ext[-1] == '.') ext--;
2177 /* keep only the first group of digits */
2178 name = xstrdup( libname );
2179 first = name + (p - libname);
2180 if ((second = strchr( first + 1, '.' )))
2182 strcpy( second, ext );
2183 strarray_add( &ret, xstrdup( name ));
2185 /* now remove all digits */
2186 strcpy( first, ext );
2187 strarray_add( &ret, name );
2188 return ret;
2192 /*******************************************************************
2193 * output_symlink_rule
2195 * Output a rule to create a symlink.
2197 static void output_symlink_rule( const char *src_name, const char *link_name )
2199 const char *name;
2201 output( "\trm -f %s && ", link_name );
2203 /* dest path with a directory needs special handling if ln -s isn't supported */
2204 if (strcmp( ln_s, "ln -s" ) && ((name = strrchr( link_name, '/' ))))
2206 char *dir = xstrdup( link_name );
2207 dir[name - link_name] = 0;
2208 output( "cd %s && %s %s %s\n", *dir ? dir : "/", ln_s, src_name, name + 1 );
2209 free( dir );
2211 else
2213 output( "%s %s %s\n", ln_s, src_name, link_name );
2218 /*******************************************************************
2219 * output_install_commands
2221 static void output_install_commands( struct makefile *make, const struct makefile *submake,
2222 struct strarray files )
2224 unsigned int i;
2225 char *install_sh = top_src_dir_path( make, "tools/install-sh" );
2227 for (i = 0; i < files.count; i += 2)
2229 const char *file = files.str[i];
2230 const char *dest = strmake( "$(DESTDIR)%s", files.str[i + 1] + 1 );
2232 if (submake) file = base_dir_path( submake, file );
2233 switch (*files.str[i + 1])
2235 case 'd': /* data file */
2236 output( "\t%s -m 644 $(INSTALL_DATA_FLAGS) %s %s\n",
2237 install_sh, obj_dir_path( make, file ), dest );
2238 break;
2239 case 'D': /* data file in source dir */
2240 output( "\t%s -m 644 $(INSTALL_DATA_FLAGS) %s %s\n",
2241 install_sh, src_dir_path( make, file ), dest );
2242 break;
2243 case 'p': /* program file */
2244 output( "\tSTRIPPROG=\"$(STRIP)\" %s $(INSTALL_PROGRAM_FLAGS) %s %s\n",
2245 install_sh, obj_dir_path( make, file ), dest );
2246 break;
2247 case 's': /* script */
2248 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s %s\n",
2249 install_sh, obj_dir_path( make, file ), dest );
2250 break;
2251 case 'S': /* script in source dir */
2252 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s %s\n",
2253 install_sh, src_dir_path( make, file ), dest );
2254 break;
2255 case 't': /* script in tools dir */
2256 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s %s\n",
2257 install_sh, tools_dir_path( make, files.str[i] ), dest );
2258 break;
2259 case 'y': /* symlink */
2260 output_symlink_rule( files.str[i], dest );
2261 break;
2262 default:
2263 assert(0);
2265 strarray_add( &make->uninstall_files, dest );
2270 /*******************************************************************
2271 * output_install_rules
2273 * Rules are stored as a (file,dest) pair of values.
2274 * The first char of dest indicates the type of install.
2276 static void output_install_rules( struct makefile *make, enum install_rules rules, const char *target )
2278 unsigned int i;
2279 struct strarray files = make->install_rules[rules];
2280 struct strarray targets = empty_strarray;
2282 if (!files.count) return;
2284 for (i = 0; i < files.count; i += 2)
2286 const char *file = files.str[i];
2287 switch (*files.str[i + 1])
2289 case 'd': /* data file */
2290 case 'p': /* program file */
2291 case 's': /* script */
2292 strarray_add_uniq( &targets, obj_dir_path( make, file ));
2293 break;
2294 case 't': /* script in tools dir */
2295 strarray_add_uniq( &targets, tools_dir_path( make, file ));
2296 break;
2300 output( "install %s::", target );
2301 output_filenames( targets );
2302 output( "\n" );
2303 output_install_commands( make, NULL, files );
2305 strarray_add_uniq( &make->phony_targets, "install" );
2306 strarray_add_uniq( &make->phony_targets, target );
2310 static int cmp_string_length( const char **a, const char **b )
2312 int paths_a = 0, paths_b = 0;
2313 const char *p;
2315 for (p = *a; *p; p++) if (*p == '/') paths_a++;
2316 for (p = *b; *p; p++) if (*p == '/') paths_b++;
2317 if (paths_b != paths_a) return paths_b - paths_a;
2318 return strcmp( *a, *b );
2321 /*******************************************************************
2322 * output_uninstall_rules
2324 static void output_uninstall_rules( struct makefile *make )
2326 static const char *dirs_order[] =
2327 { "$(includedir)", "$(mandir)", "$(fontdir)", "$(datadir)", "$(dlldir)" };
2329 struct strarray subdirs = empty_strarray;
2330 unsigned int i, j;
2332 if (!make->uninstall_files.count) return;
2333 output( "uninstall::\n" );
2334 output_rm_filenames( make->uninstall_files );
2335 strarray_add_uniq( &make->phony_targets, "uninstall" );
2337 if (!make->subdirs.count) return;
2338 for (i = 0; i < make->uninstall_files.count; i++)
2340 char *dir = xstrdup( make->uninstall_files.str[i] );
2341 while (strchr( dir, '/' ))
2343 *strrchr( dir, '/' ) = 0;
2344 strarray_add_uniq( &subdirs, xstrdup(dir) );
2347 strarray_qsort( &subdirs, cmp_string_length );
2348 output( "\t-rmdir" );
2349 for (i = 0; i < sizeof(dirs_order)/sizeof(dirs_order[0]); i++)
2351 for (j = 0; j < subdirs.count; j++)
2353 if (!subdirs.str[j]) continue;
2354 if (strncmp( subdirs.str[j] + strlen("$(DESTDIR)"), dirs_order[i], strlen(dirs_order[i]) ))
2355 continue;
2356 output_filename( subdirs.str[j] );
2357 subdirs.str[j] = NULL;
2360 for (j = 0; j < subdirs.count; j++)
2361 if (subdirs.str[j]) output_filename( subdirs.str[j] );
2362 output( "\n" );
2366 /*******************************************************************
2367 * output_importlib_symlinks
2369 static struct strarray output_importlib_symlinks( const struct makefile *parent,
2370 const struct makefile *make )
2372 struct strarray ret = empty_strarray;
2373 const char *lib, *dst;
2375 if (!make->module) return ret;
2376 if (!make->importlib) return ret;
2377 if (make->is_win16 && make->disabled) return ret;
2378 if (strncmp( make->base_dir, "dlls/", 5 )) return ret;
2379 if (!strcmp( make->module, make->importlib )) return ret;
2380 if (!strchr( make->importlib, '.' ) &&
2381 !strncmp( make->module, make->importlib, strlen( make->importlib )) &&
2382 !strcmp( make->module + strlen( make->importlib ), ".dll" ))
2383 return ret;
2385 lib = strmake( "lib%s.%s", make->importlib, *dll_ext ? "def" : "a" );
2386 dst = concat_paths( obj_dir_path( parent, "dlls" ), lib );
2387 output( "%s: %s\n", dst, base_dir_path( make, lib ));
2388 output_symlink_rule( concat_paths( make->base_dir + strlen("dlls/"), lib ), dst );
2389 strarray_add( &ret, dst );
2391 if (crosstarget && !make->is_win16)
2393 lib = strmake( "lib%s.cross.a", make->importlib );
2394 dst = concat_paths( obj_dir_path( parent, "dlls" ), lib );
2395 output( "%s: %s\n", dst, base_dir_path( make, lib ));
2396 output_symlink_rule( concat_paths( make->base_dir + strlen("dlls/"), lib ), dst );
2397 strarray_add( &ret, dst );
2399 return ret;
2403 /*******************************************************************
2404 * output_po_files
2406 static void output_po_files( const struct makefile *make )
2408 const char *po_dir = src_dir_path( make, "po" );
2409 struct strarray pot_files = empty_strarray;
2410 struct incl_file *source;
2411 unsigned int i;
2413 for (i = 0; i < make->subdirs.count; i++)
2415 struct makefile *submake = make->submakes[i];
2417 LIST_FOR_EACH_ENTRY( source, &submake->sources, struct incl_file, entry )
2419 if (strendswith( source->name, ".rc" ) && (source->file->flags & FLAG_RC_PO))
2421 char *pot_file = replace_extension( source->name, ".rc", ".pot" );
2422 char *pot_path = base_dir_path( submake, pot_file );
2423 output( "%s: tools/wrc include dummy\n", pot_path );
2424 output( "\t@cd %s && $(MAKE) %s\n", base_dir_path( submake, "" ), pot_file );
2425 strarray_add( &pot_files, pot_path );
2427 else if (strendswith( source->name, ".mc" ))
2429 char *pot_file = replace_extension( source->name, ".mc", ".pot" );
2430 char *pot_path = base_dir_path( submake, pot_file );
2431 output( "%s: tools/wmc include dummy\n", pot_path );
2432 output( "\t@cd %s && $(MAKE) %s\n", base_dir_path( submake, "" ), pot_file );
2433 strarray_add( &pot_files, pot_path );
2437 if (linguas.count)
2439 for (i = 0; i < linguas.count; i++)
2440 output_filename( strmake( "%s/%s.po", po_dir, linguas.str[i] ));
2441 output( ": %s/wine.pot\n", po_dir );
2442 output( "\tmsgmerge --previous -q $@ %s/wine.pot | msgattrib --no-obsolete -o $@.new && mv $@.new $@\n",
2443 po_dir );
2444 output( "po:" );
2445 for (i = 0; i < linguas.count; i++)
2446 output_filename( strmake( "%s/%s.po", po_dir, linguas.str[i] ));
2447 output( "\n" );
2449 output( "%s/wine.pot:", po_dir );
2450 output_filenames( pot_files );
2451 output( "\n" );
2452 output( "\tmsgcat -o $@" );
2453 output_filenames( pot_files );
2454 output( "\n" );
2458 /*******************************************************************
2459 * output_source_y
2461 static void output_source_y( struct makefile *make, struct incl_file *source, const char *obj )
2463 /* add source file dependency for parallel makes */
2464 char *header = strmake( "%s.tab.h", obj );
2466 if (find_include_file( make, header ))
2468 output( "%s: %s\n", obj_dir_path( make, header ), source->filename );
2469 output( "\t$(BISON) -p %s_ -o %s.tab.c -d %s\n",
2470 obj, obj_dir_path( make, obj ), source->filename );
2471 output( "%s.tab.c: %s %s\n", obj_dir_path( make, obj ),
2472 source->filename, obj_dir_path( make, header ));
2473 strarray_add( &make->clean_files, header );
2475 else output( "%s.tab.c: %s\n", obj, source->filename );
2477 output( "\t$(BISON) -p %s_ -o $@ %s\n", obj, source->filename );
2481 /*******************************************************************
2482 * output_source_l
2484 static void output_source_l( struct makefile *make, struct incl_file *source, const char *obj )
2486 output( "%s.yy.c: %s\n", obj_dir_path( make, obj ), source->filename );
2487 output( "\t$(FLEX) -o$@ %s\n", source->filename );
2491 /*******************************************************************
2492 * output_source_h
2494 static void output_source_h( struct makefile *make, struct incl_file *source, const char *obj )
2496 if (source->file->flags & FLAG_GENERATED)
2498 strarray_add( &make->all_targets, source->name );
2500 else
2502 strarray_add( &make->install_rules[INSTALL_DEV], source->name );
2503 strarray_add( &make->install_rules[INSTALL_DEV],
2504 strmake( "D$(includedir)/wine/%s", get_include_install_path( source->name ) ));
2509 /*******************************************************************
2510 * output_source_rc
2512 static void output_source_rc( struct makefile *make, struct incl_file *source, const char *obj )
2514 struct strarray extradefs = get_expanded_file_local_var( make, obj, "EXTRADEFS" );
2515 unsigned int i;
2517 strarray_add( &make->object_files, strmake( "%s.res", obj ));
2518 if (crosstarget) strarray_add( &make->crossobj_files, strmake( "%s.res", obj ));
2519 output( "%s.res: %s\n", obj_dir_path( make, obj ), source->filename );
2520 output( "\t%s -o $@", tools_path( make, "wrc" ) );
2521 if (make->is_win16) output_filename( "-m16" );
2522 else output_filenames( target_flags );
2523 output_filename( "--nostdinc" );
2524 output_filenames( make->include_args );
2525 output_filenames( make->define_args );
2526 output_filenames( extradefs );
2527 if (linguas.count && (source->file->flags & FLAG_RC_PO))
2529 char *po_dir = top_obj_dir_path( make, "po" );
2530 output_filename( strmake( "--po-dir=%s", po_dir ));
2531 output_filename( source->filename );
2532 output( "\n" );
2533 output( "%s.res:", obj_dir_path( make, obj ));
2534 for (i = 0; i < linguas.count; i++)
2535 output_filename( strmake( "%s/%s.mo", po_dir, linguas.str[i] ));
2536 output( "\n" );
2538 else
2540 output_filename( source->filename );
2541 output( "\n" );
2543 if (source->file->flags & FLAG_RC_PO)
2545 strarray_add( &make->clean_files, strmake( "%s.pot", obj ));
2546 output( "%s.pot: %s\n", obj_dir_path( make, obj ), source->filename );
2547 output( "\t%s -O pot -o $@", tools_path( make, "wrc" ) );
2548 if (make->is_win16) output_filename( "-m16" );
2549 else output_filenames( target_flags );
2550 output_filename( "--nostdinc" );
2551 output_filenames( make->include_args );
2552 output_filenames( make->define_args );
2553 output_filenames( extradefs );
2554 output_filename( source->filename );
2555 output( "\n" );
2556 output( "%s.pot ", obj_dir_path( make, obj ));
2558 output( "%s.res:", obj_dir_path( make, obj ));
2559 output_filename( tools_path( make, "wrc" ));
2560 output_filenames( source->dependencies );
2561 output( "\n" );
2565 /*******************************************************************
2566 * output_source_mc
2568 static void output_source_mc( struct makefile *make, struct incl_file *source, const char *obj )
2570 unsigned int i;
2572 strarray_add( &make->object_files, strmake( "%s.res", obj ));
2573 if (crosstarget) strarray_add( &make->crossobj_files, strmake( "%s.res", obj ));
2574 strarray_add( &make->clean_files, strmake( "%s.pot", obj ));
2575 output( "%s.res: %s\n", obj_dir_path( make, obj ), source->filename );
2576 output( "\t%s -U -O res -o $@ %s", tools_path( make, "wmc" ), source->filename );
2577 if (linguas.count)
2579 char *po_dir = top_obj_dir_path( make, "po" );
2580 output_filename( strmake( "--po-dir=%s", po_dir ));
2581 output( "\n" );
2582 output( "%s.res:", obj_dir_path( make, obj ));
2583 for (i = 0; i < linguas.count; i++)
2584 output_filename( strmake( "%s/%s.mo", po_dir, linguas.str[i] ));
2586 output( "\n" );
2587 output( "%s.pot: %s\n", obj_dir_path( make, obj ), source->filename );
2588 output( "\t%s -O pot -o $@ %s", tools_path( make, "wmc" ), source->filename );
2589 output( "\n" );
2590 output( "%s.pot %s.res:", obj_dir_path( make, obj ), obj_dir_path( make, obj ));
2591 output_filename( tools_path( make, "wmc" ));
2592 output_filenames( source->dependencies );
2593 output( "\n" );
2597 /*******************************************************************
2598 * output_source_res
2600 static void output_source_res( struct makefile *make, struct incl_file *source, const char *obj )
2602 strarray_add( &make->object_files, source->name );
2603 if (crosstarget) strarray_add( &make->crossobj_files, source->name );
2607 /*******************************************************************
2608 * output_source_idl
2610 static void output_source_idl( struct makefile *make, struct incl_file *source, const char *obj )
2612 struct strarray extradefs = get_expanded_file_local_var( make, obj, "EXTRADEFS" );
2613 struct strarray targets = empty_strarray;
2614 char *dest;
2615 unsigned int i;
2617 if (!source->file->flags) source->file->flags |= FLAG_IDL_HEADER | FLAG_INSTALL;
2618 if (find_include_file( make, strmake( "%s.h", obj ))) source->file->flags |= FLAG_IDL_HEADER;
2620 for (i = 0; i < sizeof(idl_outputs) / sizeof(idl_outputs[0]); i++)
2622 if (!(source->file->flags & idl_outputs[i].flag)) continue;
2623 dest = strmake( "%s%s", obj, idl_outputs[i].ext );
2624 if (!find_src_file( make, dest )) strarray_add( &make->clean_files, dest );
2625 strarray_add( &targets, dest );
2627 if (source->file->flags & FLAG_IDL_PROXY) strarray_add( &make->dlldata_files, source->name );
2628 if (source->file->flags & FLAG_INSTALL)
2630 strarray_add( &make->install_rules[INSTALL_DEV], xstrdup( source->name ));
2631 strarray_add( &make->install_rules[INSTALL_DEV],
2632 strmake( "D$(includedir)/wine/%s.idl", get_include_install_path( obj ) ));
2633 if (source->file->flags & FLAG_IDL_HEADER)
2635 strarray_add( &make->install_rules[INSTALL_DEV], strmake( "%s.h", obj ));
2636 strarray_add( &make->install_rules[INSTALL_DEV],
2637 strmake( "d$(includedir)/wine/%s.h", get_include_install_path( obj ) ));
2640 if (!targets.count) return;
2642 output_filenames_obj_dir( make, targets );
2643 output( ": %s\n", tools_path( make, "widl" ));
2644 output( "\t%s -o $@", tools_path( make, "widl" ) );
2645 output_filenames( widl_flags );
2646 output_filenames( target_flags );
2647 output_filenames( make->include_args );
2648 output_filenames( make->define_args );
2649 output_filenames( extradefs );
2650 output_filenames( get_expanded_make_var_array( make, "EXTRAIDLFLAGS" ));
2651 output_filenames( get_expanded_file_local_var( make, obj, "EXTRAIDLFLAGS" ));
2652 output_filename( source->filename );
2653 output( "\n" );
2654 output_filenames_obj_dir( make, targets );
2655 output( ": %s", source->filename );
2656 output_filenames( source->dependencies );
2657 output( "\n" );
2661 /*******************************************************************
2662 * output_source_tlb
2664 static void output_source_tlb( struct makefile *make, struct incl_file *source, const char *obj )
2666 strarray_add( &make->all_targets, source->name );
2670 /*******************************************************************
2671 * output_source_x
2673 static void output_source_x( struct makefile *make, struct incl_file *source, const char *obj )
2675 output( "%s.h: %s%s %s\n", obj_dir_path( make, obj ),
2676 tools_dir_path( make, "make_xftmpl" ), tools_ext, source->filename );
2677 output( "\t%s%s -H -o $@ %s\n",
2678 tools_dir_path( make, "make_xftmpl" ), tools_ext, source->filename );
2679 if (source->file->flags & FLAG_INSTALL)
2681 strarray_add( &make->install_rules[INSTALL_DEV], source->name );
2682 strarray_add( &make->install_rules[INSTALL_DEV],
2683 strmake( "D$(includedir)/wine/%s", get_include_install_path( source->name ) ));
2684 strarray_add( &make->install_rules[INSTALL_DEV], strmake( "%s.h", obj ));
2685 strarray_add( &make->install_rules[INSTALL_DEV],
2686 strmake( "d$(includedir)/wine/%s.h", get_include_install_path( obj ) ));
2691 /*******************************************************************
2692 * output_source_sfd
2694 static void output_source_sfd( struct makefile *make, struct incl_file *source, const char *obj )
2696 unsigned int i;
2697 char *ttf_file = src_dir_path( make, strmake( "%s.ttf", obj ));
2699 if (fontforge && !make->src_dir)
2701 output( "%s: %s\n", ttf_file, source->filename );
2702 output( "\t%s -script %s %s $@\n",
2703 fontforge, top_src_dir_path( make, "fonts/genttf.ff" ), source->filename );
2704 if (!(source->file->flags & FLAG_SFD_FONTS)) output( "all: %s\n", ttf_file );
2706 if (source->file->flags & FLAG_INSTALL)
2708 strarray_add( &make->install_rules[INSTALL_LIB], strmake( "%s.ttf", obj ));
2709 strarray_add( &make->install_rules[INSTALL_LIB], strmake( "D$(fontdir)/%s.ttf", obj ));
2711 if (source->file->flags & FLAG_SFD_FONTS)
2713 struct strarray *array = source->file->args;
2715 for (i = 0; i < array->count; i++)
2717 char *font = strtok( xstrdup(array->str[i]), " \t" );
2718 char *args = strtok( NULL, "" );
2720 strarray_add( &make->all_targets, xstrdup( font ));
2721 output( "%s: %s %s\n", obj_dir_path( make, font ),
2722 tools_path( make, "sfnt2fon" ), ttf_file );
2723 output( "\t%s -o $@ %s %s\n", tools_path( make, "sfnt2fon" ), ttf_file, args );
2724 strarray_add( &make->install_rules[INSTALL_LIB], xstrdup(font) );
2725 strarray_add( &make->install_rules[INSTALL_LIB], strmake( "d$(fontdir)/%s", font ));
2731 /*******************************************************************
2732 * output_source_svg
2734 static void output_source_svg( struct makefile *make, struct incl_file *source, const char *obj )
2736 static const char * const images[] = { "bmp", "cur", "ico", NULL };
2737 unsigned int i;
2739 if (convert && rsvg && icotool && !make->src_dir)
2741 for (i = 0; images[i]; i++)
2742 if (find_include_file( make, strmake( "%s.%s", obj, images[i] ))) break;
2744 if (images[i])
2746 output( "%s.%s: %s\n", src_dir_path( make, obj ), images[i], source->filename );
2747 output( "\tCONVERT=\"%s\" ICOTOOL=\"%s\" RSVG=\"%s\" %s %s $@\n", convert, icotool, rsvg,
2748 top_src_dir_path( make, "tools/buildimage" ), source->filename );
2754 /*******************************************************************
2755 * output_source_nls
2757 static void output_source_nls( struct makefile *make, struct incl_file *source, const char *obj )
2759 add_install_rule( make, source->name, source->name,
2760 strmake( "D$(datadir)/wine/%s", source->name ));
2764 /*******************************************************************
2765 * output_source_desktop
2767 static void output_source_desktop( struct makefile *make, struct incl_file *source, const char *obj )
2769 add_install_rule( make, source->name, source->name,
2770 strmake( "D$(datadir)/applications/%s", source->name ));
2774 /*******************************************************************
2775 * output_source_po
2777 static void output_source_po( struct makefile *make, struct incl_file *source, const char *obj )
2779 output( "%s.mo: %s\n", obj_dir_path( make, obj ), source->filename );
2780 output( "\t%s -o $@ %s\n", msgfmt, source->filename );
2781 strarray_add( &make->all_targets, strmake( "%s.mo", obj ));
2785 /*******************************************************************
2786 * output_source_in
2788 static void output_source_in( struct makefile *make, struct incl_file *source, const char *obj )
2790 unsigned int i;
2792 if (strendswith( obj, ".man" ) && source->file->args)
2794 struct strarray symlinks;
2795 char *dir, *dest = replace_extension( obj, ".man", "" );
2796 char *lang = strchr( dest, '.' );
2797 char *section = source->file->args;
2798 if (lang)
2800 *lang++ = 0;
2801 dir = strmake( "$(mandir)/%s/man%s", lang, section );
2803 else dir = strmake( "$(mandir)/man%s", section );
2804 add_install_rule( make, dest, xstrdup(obj), strmake( "d%s/%s.%s", dir, dest, section ));
2805 symlinks = get_expanded_file_local_var( make, dest, "SYMLINKS" );
2806 for (i = 0; i < symlinks.count; i++)
2807 add_install_rule( make, symlinks.str[i], strmake( "%s.%s", dest, section ),
2808 strmake( "y%s/%s.%s", dir, symlinks.str[i], section ));
2809 free( dest );
2810 free( dir );
2812 strarray_add( &make->in_files, xstrdup(obj) );
2813 strarray_add( &make->all_targets, xstrdup(obj) );
2814 output( "%s: %s\n", obj_dir_path( make, obj ), source->filename );
2815 output( "\t$(SED_CMD) %s >$@ || (rm -f $@ && false)\n", source->filename );
2816 output( "%s:", obj_dir_path( make, obj ));
2817 output_filenames( source->dependencies );
2818 output( "\n" );
2819 add_install_rule( make, obj, xstrdup( obj ), strmake( "d$(datadir)/wine/%s", obj ));
2823 /*******************************************************************
2824 * output_source_spec
2826 static void output_source_spec( struct makefile *make, struct incl_file *source, const char *obj )
2828 struct strarray imports = get_expanded_file_local_var( make, obj, "IMPORTS" );
2829 struct strarray dll_flags = get_expanded_file_local_var( make, obj, "EXTRADLLFLAGS" );
2830 struct strarray all_libs, dep_libs = empty_strarray;
2832 if (!imports.count) imports = make->imports;
2833 if (!dll_flags.count) dll_flags = make->extradllflags;
2834 all_libs = add_import_libs( make, &dep_libs, imports, 0 );
2835 add_import_libs( make, &dep_libs, get_default_imports( make ), 0 ); /* dependencies only */
2836 strarray_addall( &all_libs, libs );
2838 strarray_add( &make->clean_files, strmake( "%s.dll%s", obj, dll_ext ));
2839 strarray_add( &make->object_files, strmake( "%s.res", obj ));
2840 output( "%s.res: %s.dll%s\n", obj_dir_path( make, obj ), obj_dir_path( make, obj ), dll_ext );
2841 output( "\techo \"%s.dll TESTDLL \\\"%s.dll%s\\\"\" | %s -o $@\n", obj,
2842 obj_dir_path( make, obj ), dll_ext, tools_path( make, "wrc" ));
2844 output( "%s.dll%s:", obj_dir_path( make, obj ), dll_ext );
2845 output_filename( source->filename );
2846 output_filename( strmake( "%s.o", obj_dir_path( make, obj )));
2847 output_filenames( dep_libs );
2848 output_filename( tools_path( make, "winebuild" ));
2849 output_filename( tools_path( make, "winegcc" ));
2850 output( "\n" );
2851 output( "\t%s -s -o $@", tools_path( make, "winegcc" ));
2852 output_filename( strmake( "-B%s", tools_dir_path( make, "winebuild" )));
2853 if (tools_dir) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make, "" )));
2854 output_filenames( target_flags );
2855 output_filenames( unwind_flags );
2856 output_filenames( dll_flags );
2857 output_filename( "-shared" );
2858 output_filename( source->filename );
2859 output_filename( strmake( "%s.o", obj_dir_path( make, obj )));
2860 output_filenames( all_libs );
2861 output_filename( "$(LDFLAGS)" );
2862 output( "\n" );
2864 if (crosstarget)
2866 dep_libs = empty_strarray;
2867 all_libs = add_import_libs( make, &dep_libs, imports, 1 );
2868 add_import_libs( make, &dep_libs, get_default_imports( make ), 1 ); /* dependencies only */
2869 strarray_addall( &all_libs, libs );
2871 strarray_add( &make->clean_files, strmake( "%s.dll", obj ));
2872 strarray_add( &make->crossobj_files, strmake( "%s.cross.res", obj ));
2873 output( "%s.cross.res: %s.dll\n", obj_dir_path( make, obj ), obj_dir_path( make, obj ) );
2874 output( "\techo \"%s.dll TESTDLL \\\"%s.dll\\\"\" | %s -o $@\n", obj,
2875 obj_dir_path( make, obj ), tools_path( make, "wrc" ));
2877 output( "%s.dll:", obj_dir_path( make, obj ));
2878 output_filename( source->filename );
2879 output_filename( strmake( "%s.cross.o", obj_dir_path( make, obj )));
2880 output_filenames( dep_libs );
2881 output_filename( tools_path( make, "winebuild" ));
2882 output_filename( tools_path( make, "winegcc" ));
2883 output( "\n" );
2884 output( "\t%s -s -o $@ -b %s", tools_path( make, "winegcc" ), crosstarget );
2885 output_filename( strmake( "-B%s", tools_dir_path( make, "winebuild" )));
2886 if (tools_dir) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make, "" )));
2887 output_filename( "--lib-suffix=.cross.a" );
2888 output_filenames( dll_flags );
2889 output_filename( "-shared" );
2890 output_filename( source->filename );
2891 output_filename( strmake( "%s.cross.o", obj_dir_path( make, obj )));
2892 output_filenames( all_libs );
2893 output_filename( "$(LDFLAGS)" );
2894 output( "\n" );
2899 /*******************************************************************
2900 * output_source_default
2902 static void output_source_default( struct makefile *make, struct incl_file *source, const char *obj )
2904 struct strarray extradefs = get_expanded_file_local_var( make, obj, "EXTRADEFS" );
2905 int is_dll_src = (make->testdll &&
2906 strendswith( source->name, ".c" ) &&
2907 find_src_file( make, replace_extension( source->name, ".c", ".spec" )));
2908 int need_cross = (make->testdll ||
2909 (source->file->flags & FLAG_C_IMPLIB) ||
2910 (make->module && make->staticlib));
2912 if ((source->file->flags & FLAG_GENERATED) &&
2913 (!make->testdll || !strendswith( source->filename, "testlist.c" )))
2914 strarray_add( &make->clean_files, source->filename );
2915 if (source->file->flags & FLAG_C_IMPLIB) strarray_add( &make->implib_objs, strmake( "%s.o", obj ));
2916 strarray_add( is_dll_src ? &make->clean_files : &make->object_files, strmake( "%s.o", obj ));
2917 output( "%s.o: %s\n", obj_dir_path( make, obj ), source->filename );
2918 output( "\t$(CC) -c -o $@ %s", source->filename );
2919 output_filenames( make->include_args );
2920 output_filenames( make->define_args );
2921 output_filenames( extradefs );
2922 if (make->module || make->staticlib || make->sharedlib || make->testdll)
2924 output_filenames( dll_flags );
2925 if (make->use_msvcrt) output_filenames( msvcrt_flags );
2927 output_filenames( extra_cflags );
2928 output_filenames( cpp_flags );
2929 output_filename( "$(CFLAGS)" );
2930 output( "\n" );
2931 if (crosstarget && need_cross)
2933 strarray_add( is_dll_src ? &make->clean_files : &make->crossobj_files, strmake( "%s.cross.o", obj ));
2934 output( "%s.cross.o: %s\n", obj_dir_path( make, obj ), source->filename );
2935 output( "\t$(CROSSCC) -c -o $@ %s", source->filename );
2936 output_filenames( make->include_args );
2937 output_filenames( make->define_args );
2938 output_filenames( extradefs );
2939 if (make->use_msvcrt) output_filenames( msvcrt_flags );
2940 output_filename( "-DWINE_CROSSTEST" );
2941 output_filenames( cpp_flags );
2942 output_filename( "$(CROSSCFLAGS)" );
2943 output( "\n" );
2945 if (strendswith( source->name, ".c" ) && !(source->file->flags & FLAG_GENERATED))
2947 strarray_add( &make->c2man_files, source->filename );
2948 if (make->testdll && !is_dll_src)
2950 strarray_add( &make->ok_files, strmake( "%s.ok", obj ));
2951 output( "%s.ok:\n", obj_dir_path( make, obj ));
2952 output( "\t%s $(RUNTESTFLAGS) -T %s -M %s -p %s%s %s && touch $@\n",
2953 top_src_dir_path( make, "tools/runtest" ), top_obj_dir_path( make, "" ),
2954 make->testdll, replace_extension( make->testdll, ".dll", "_test.exe" ),
2955 dll_ext, obj );
2958 output( "%s.o", obj_dir_path( make, obj ));
2959 if (crosstarget && need_cross) output( " %s.cross.o", obj_dir_path( make, obj ));
2960 output( ":" );
2961 output_filenames( source->dependencies );
2962 output( "\n" );
2966 /* dispatch table to output rules for a single source file */
2967 static const struct
2969 const char *ext;
2970 void (*fn)( struct makefile *make, struct incl_file *source, const char *obj );
2971 } output_source_funcs[] =
2973 { "y", output_source_y },
2974 { "l", output_source_l },
2975 { "h", output_source_h },
2976 { "rh", output_source_h },
2977 { "inl", output_source_h },
2978 { "rc", output_source_rc },
2979 { "mc", output_source_mc },
2980 { "res", output_source_res },
2981 { "idl", output_source_idl },
2982 { "tlb", output_source_tlb },
2983 { "sfd", output_source_sfd },
2984 { "svg", output_source_svg },
2985 { "nls", output_source_nls },
2986 { "desktop", output_source_desktop },
2987 { "po", output_source_po },
2988 { "in", output_source_in },
2989 { "x", output_source_x },
2990 { "spec", output_source_spec },
2991 { NULL, output_source_default }
2995 /*******************************************************************
2996 * output_man_pages
2998 static void output_man_pages( struct makefile *make )
3000 if (make->c2man_files.count)
3002 char *spec_file = src_dir_path( make, replace_extension( make->module, ".dll", ".spec" ));
3004 output( "manpages::\n" );
3005 output( "\t%s -w %s", top_src_dir_path( make, "tools/c2man.pl" ), spec_file );
3006 output_filename( strmake( "-R%s", top_src_dir_path( make, "" )));
3007 output_filename( strmake( "-I%s", top_src_dir_path( make, "include" )));
3008 output_filename( strmake( "-o %s/man%s",
3009 top_obj_dir_path( make, "documentation" ), man_ext ));
3010 output_filenames( make->c2man_files );
3011 output( "\n" );
3012 output( "htmlpages::\n" );
3013 output( "\t%s -Th -w %s", top_src_dir_path( make, "tools/c2man.pl" ), spec_file );
3014 output_filename( strmake( "-R%s", top_src_dir_path( make, "" )));
3015 output_filename( strmake( "-I%s", top_src_dir_path( make, "include" )));
3016 output_filename( strmake( "-o %s",
3017 top_obj_dir_path( make, "documentation/html" )));
3018 output_filenames( make->c2man_files );
3019 output( "\n" );
3020 output( "sgmlpages::\n" );
3021 output( "\t%s -Ts -w %s", top_src_dir_path( make, "tools/c2man.pl" ), spec_file );
3022 output_filename( strmake( "-R%s", top_src_dir_path( make, "" )));
3023 output_filename( strmake( "-I%s", top_src_dir_path( make, "include" )));
3024 output_filename( strmake( "-o %s",
3025 top_obj_dir_path( make, "documentation/api-guide" )));
3026 output_filenames( make->c2man_files );
3027 output( "\n" );
3028 output( "xmlpages::\n" );
3029 output( "\t%s -Tx -w %s", top_src_dir_path( make, "tools/c2man.pl" ), spec_file );
3030 output_filename( strmake( "-R%s", top_src_dir_path( make, "" )));
3031 output_filename( strmake( "-I%s", top_src_dir_path( make, "include" )));
3032 output_filename( strmake( "-o %s",
3033 top_obj_dir_path( make, "documentation/api-guide-xml" )));
3034 output_filenames( make->c2man_files );
3035 output( "\n" );
3036 strarray_add( &make->phony_targets, "manpages" );
3037 strarray_add( &make->phony_targets, "htmlpages" );
3038 strarray_add( &make->phony_targets, "sgmlpages" );
3039 strarray_add( &make->phony_targets, "xmlpages" );
3041 else output( "manpages htmlpages sgmlpages xmlpages::\n" );
3045 /*******************************************************************
3046 * output_module
3048 static void output_module( struct makefile *make )
3050 struct strarray all_libs = empty_strarray;
3051 struct strarray dep_libs = empty_strarray;
3052 char *module_path = obj_dir_path( make, make->module );
3053 char *spec_file = NULL;
3054 unsigned int i;
3056 if (!make->appmode.count)
3057 spec_file = src_dir_path( make, replace_extension( make->module, ".dll", ".spec" ));
3058 strarray_addall( &all_libs, add_import_libs( make, &dep_libs, make->delayimports, 0 ));
3059 strarray_addall( &all_libs, add_import_libs( make, &dep_libs, make->imports, 0 ));
3060 add_import_libs( make, &dep_libs, get_default_imports( make ), 0 ); /* dependencies only */
3061 strarray_addall( &all_libs, add_default_libraries( make, &dep_libs ));
3063 if (*dll_ext)
3065 for (i = 0; i < make->delayimports.count; i++)
3066 strarray_add( &all_libs, strmake( "-Wb,-d%s", make->delayimports.str[i] ));
3067 strarray_add( &make->all_targets, strmake( "%s%s", make->module, dll_ext ));
3068 strarray_add( &make->all_targets, strmake( "%s.fake", make->module ));
3069 add_install_rule( make, make->module, strmake( "%s%s", make->module, dll_ext ),
3070 strmake( "p$(dlldir)/%s%s", make->module, dll_ext ));
3071 add_install_rule( make, make->module, strmake( "%s.fake", make->module ),
3072 strmake( "d$(dlldir)/fakedlls/%s", make->module ));
3073 output( "%s%s %s.fake:", module_path, dll_ext, module_path );
3075 else
3077 strarray_add( &all_libs, "-lwine" );
3078 strarray_add( &make->all_targets, make->module );
3079 add_install_rule( make, make->module, make->module,
3080 strmake( "p$(%s)/%s", spec_file ? "dlldir" : "bindir", make->module ));
3081 output( "%s:", module_path );
3083 if (spec_file) output_filename( spec_file );
3084 output_filenames_obj_dir( make, make->object_files );
3085 output_filenames( dep_libs );
3086 output_filename( tools_path( make, "winebuild" ));
3087 output_filename( tools_path( make, "winegcc" ));
3088 output( "\n" );
3089 output( "\t%s -o $@", tools_path( make, "winegcc" ));
3090 output_filename( strmake( "-B%s", tools_dir_path( make, "winebuild" )));
3091 if (tools_dir) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make, "" )));
3092 output_filenames( target_flags );
3093 output_filenames( unwind_flags );
3094 if (spec_file)
3096 output( " -shared %s", spec_file );
3097 output_filenames( make->extradllflags );
3099 else output_filenames( make->appmode );
3100 output_filenames_obj_dir( make, make->object_files );
3101 output_filenames( all_libs );
3102 output_filename( "$(LDFLAGS)" );
3103 output( "\n" );
3105 if (spec_file && make->importlib)
3107 char *importlib_path = obj_dir_path( make, strmake( "lib%s", make->importlib ));
3108 if (*dll_ext && !make->implib_objs.count)
3110 strarray_add( &make->clean_files, strmake( "lib%s.def", make->importlib ));
3111 output( "%s.def: %s %s\n", importlib_path, tools_path( make, "winebuild" ), spec_file );
3112 output( "\t%s -w --def -o $@ --export %s", tools_path( make, "winebuild" ), spec_file );
3113 output_filenames( target_flags );
3114 if (make->is_win16) output_filename( "-m16" );
3115 output( "\n" );
3116 add_install_rule( make, make->importlib,
3117 strmake( "lib%s.def", make->importlib ),
3118 strmake( "d$(dlldir)/lib%s.def", make->importlib ));
3120 else
3122 strarray_add( &make->clean_files, strmake( "lib%s.a", make->importlib ));
3123 output( "%s.a: %s %s", importlib_path, tools_path( make, "winebuild" ), spec_file );
3124 output_filenames_obj_dir( make, make->implib_objs );
3125 output( "\n" );
3126 output( "\t%s -w --implib -o $@ --export %s", tools_path( make, "winebuild" ), spec_file );
3127 output_filenames( target_flags );
3128 output_filenames_obj_dir( make, make->implib_objs );
3129 output( "\n" );
3130 add_install_rule( make, make->importlib,
3131 strmake( "lib%s.a", make->importlib ),
3132 strmake( "d$(dlldir)/lib%s.a", make->importlib ));
3134 if (crosstarget && !make->is_win16)
3136 struct strarray cross_files = strarray_replace_extension( &make->implib_objs, ".o", ".cross.o" );
3137 strarray_add( &make->clean_files, strmake( "lib%s.cross.a", make->importlib ));
3138 output( "%s.cross.a: %s %s", importlib_path, tools_path( make, "winebuild" ), spec_file );
3139 output_filenames_obj_dir( make, cross_files );
3140 output( "\n" );
3141 output( "\t%s -b %s -w --implib -o $@ --export %s",
3142 tools_path( make, "winebuild" ), crosstarget, spec_file );
3143 output_filenames_obj_dir( make, cross_files );
3144 output( "\n" );
3148 if (spec_file)
3149 output_man_pages( make );
3150 else if (*dll_ext && !make->is_win16)
3152 char *binary = replace_extension( make->module, ".exe", "" );
3153 add_install_rule( make, binary, "wineapploader", strmake( "t$(bindir)/%s", binary ));
3158 /*******************************************************************
3159 * output_static_lib
3161 static void output_static_lib( struct makefile *make )
3163 strarray_add( &make->all_targets, make->staticlib );
3164 output( "%s:", obj_dir_path( make, make->staticlib ));
3165 output_filenames_obj_dir( make, make->object_files );
3166 output( "\n\trm -f $@\n" );
3167 output( "\t$(AR) $(ARFLAGS) $@" );
3168 output_filenames_obj_dir( make, make->object_files );
3169 output( "\n\t$(RANLIB) $@\n" );
3170 add_install_rule( make, make->staticlib, make->staticlib,
3171 strmake( "d$(dlldir)/%s", make->staticlib ));
3172 if (crosstarget && make->module)
3174 char *name = replace_extension( make->staticlib, ".a", ".cross.a" );
3176 strarray_add( &make->all_targets, name );
3177 output( "%s:", obj_dir_path( make, name ));
3178 output_filenames_obj_dir( make, make->crossobj_files );
3179 output( "\n\trm -f $@\n" );
3180 output( "\t%s-ar $(ARFLAGS) $@", crosstarget );
3181 output_filenames_obj_dir( make, make->crossobj_files );
3182 output( "\n\t%s-ranlib $@\n", crosstarget );
3187 /*******************************************************************
3188 * output_shared_lib
3190 static void output_shared_lib( struct makefile *make )
3192 unsigned int i;
3193 char *basename, *p;
3194 struct strarray names = get_shared_lib_names( make->sharedlib );
3195 struct strarray all_libs = empty_strarray;
3196 struct strarray dep_libs = empty_strarray;
3198 basename = xstrdup( make->sharedlib );
3199 if ((p = strchr( basename, '.' ))) *p = 0;
3201 strarray_addall( &dep_libs, get_local_dependencies( make, basename, make->in_files ));
3202 strarray_addall( &all_libs, get_expanded_file_local_var( make, basename, "LDFLAGS" ));
3203 strarray_addall( &all_libs, add_default_libraries( make, &dep_libs ));
3205 output( "%s:", obj_dir_path( make, make->sharedlib ));
3206 output_filenames_obj_dir( make, make->object_files );
3207 output_filenames( dep_libs );
3208 output( "\n" );
3209 output( "\t$(CC) -o $@" );
3210 output_filenames_obj_dir( make, make->object_files );
3211 output_filenames( all_libs );
3212 output_filename( "$(LDFLAGS)" );
3213 output( "\n" );
3214 add_install_rule( make, make->sharedlib, make->sharedlib,
3215 strmake( "p$(libdir)/%s", make->sharedlib ));
3216 for (i = 1; i < names.count; i++)
3218 output( "%s: %s\n", obj_dir_path( make, names.str[i] ), obj_dir_path( make, names.str[i-1] ));
3219 output_symlink_rule( obj_dir_path( make, names.str[i-1] ), obj_dir_path( make, names.str[i] ));
3220 add_install_rule( make, names.str[i], names.str[i-1],
3221 strmake( "y$(libdir)/%s", names.str[i] ));
3223 strarray_addall( &make->all_targets, names );
3227 /*******************************************************************
3228 * output_import_lib
3230 static void output_import_lib( struct makefile *make )
3232 char *def_file = replace_extension( make->importlib, ".a", ".def" );
3234 /* stand-alone import lib (for libwine) */
3235 if (!strncmp( def_file, "lib", 3 )) def_file += 3;
3236 output( "%s: %s\n", obj_dir_path( make, make->importlib ), src_dir_path( make, def_file ));
3237 output( "\t%s -l $@ -d %s\n", dlltool, src_dir_path( make, def_file ));
3238 add_install_rule( make, make->importlib, make->importlib, strmake( "d$(libdir)/%s", make->importlib ));
3239 strarray_add( &make->all_targets, make->importlib );
3243 /*******************************************************************
3244 * output_test_module
3246 static void output_test_module( struct makefile *make )
3248 char *testmodule = replace_extension( make->testdll, ".dll", "_test.exe" );
3249 char *stripped = replace_extension( make->testdll, ".dll", "_test-stripped.exe" );
3250 char *testres = replace_extension( make->testdll, ".dll", "_test.res" );
3251 struct strarray dep_libs = empty_strarray;
3252 struct strarray all_libs = add_import_libs( make, &dep_libs, make->imports, 0 );
3253 int parent_disabled = 0;
3255 add_import_libs( make, &dep_libs, get_default_imports( make ), 0 ); /* dependencies only */
3256 strarray_addall( &all_libs, libs );
3257 strarray_add( &make->all_targets, strmake( "%s%s", testmodule, dll_ext ));
3258 strarray_add( &make->clean_files, strmake( "%s%s", stripped, dll_ext ));
3259 output( "%s%s:\n", obj_dir_path( make, testmodule ), dll_ext );
3260 output( "\t%s -o $@", tools_path( make, "winegcc" ));
3261 output_filename( strmake( "-B%s", tools_dir_path( make, "winebuild" )));
3262 if (tools_dir) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make, "" )));
3263 output_filenames( target_flags );
3264 output_filenames( unwind_flags );
3265 output_filenames( make->appmode );
3266 output_filenames_obj_dir( make, make->object_files );
3267 output_filenames( all_libs );
3268 output_filename( "$(LDFLAGS)" );
3269 output( "\n" );
3270 output( "%s%s:\n", obj_dir_path( make, stripped ), dll_ext );
3271 output( "\t%s -s -o $@", tools_path( make, "winegcc" ));
3272 output_filename( strmake( "-B%s", tools_dir_path( make, "winebuild" )));
3273 if (tools_dir) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make, "" )));
3274 output_filenames( target_flags );
3275 output_filenames( unwind_flags );
3276 output_filename( strmake( "-Wb,-F,%s", testmodule ));
3277 output_filenames( make->appmode );
3278 output_filenames_obj_dir( make, make->object_files );
3279 output_filenames( all_libs );
3280 output_filename( "$(LDFLAGS)" );
3281 output( "\n" );
3282 output( "%s%s %s%s:", obj_dir_path( make, testmodule ), dll_ext,
3283 obj_dir_path( make, stripped ), dll_ext );
3284 output_filenames_obj_dir( make, make->object_files );
3285 output_filenames( dep_libs );
3286 output_filename( tools_path( make, "winebuild" ));
3287 output_filename( tools_path( make, "winegcc" ));
3288 output( "\n" );
3290 if (!make->disabled && !strarray_exists( &disabled_dirs, "programs/winetest" ))
3291 output( "all: %s/%s\n", top_obj_dir_path( make, "programs/winetest" ), testres );
3292 output( "%s/%s: %s%s\n", top_obj_dir_path( make, "programs/winetest" ), testres,
3293 obj_dir_path( make, stripped ), dll_ext );
3294 output( "\techo \"%s TESTRES \\\"%s%s\\\"\" | %s -o $@\n",
3295 testmodule, obj_dir_path( make, stripped ), dll_ext, tools_path( make, "wrc" ));
3297 if (crosstarget)
3299 char *crosstest = replace_extension( make->testdll, ".dll", "_crosstest.exe" );
3301 dep_libs = empty_strarray;
3302 all_libs = add_import_libs( make, &dep_libs, make->imports, 1 );
3303 add_import_libs( make, &dep_libs, get_default_imports( make ), 1 ); /* dependencies only */
3304 strarray_addall( &all_libs, libs );
3305 strarray_add( &make->clean_files, crosstest );
3306 output( "%s:", obj_dir_path( make, crosstest ));
3307 output_filenames_obj_dir( make, make->crossobj_files );
3308 output_filenames( dep_libs );
3309 output_filename( tools_path( make, "winebuild" ));
3310 output_filename( tools_path( make, "winegcc" ));
3311 output( "\n" );
3312 output( "\t%s -o $@ -b %s", tools_path( make, "winegcc" ), crosstarget );
3313 output_filename( strmake( "-B%s", tools_dir_path( make, "winebuild" )));
3314 if (tools_dir) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make, "" )));
3315 output_filename( "--lib-suffix=.cross.a" );
3316 output_filenames_obj_dir( make, make->crossobj_files );
3317 output_filenames( all_libs );
3318 output_filename( "$(LDFLAGS)" );
3319 output( "\n" );
3320 if (!make->disabled)
3322 output( "%s: %s\n", obj_dir_path( make, "crosstest" ), obj_dir_path( make, crosstest ));
3323 strarray_add( &make->phony_targets, obj_dir_path( make, "crosstest" ));
3324 if (make->obj_dir) output( "crosstest: %s\n", obj_dir_path( make, "crosstest" ));
3328 if (strendswith( make->base_dir, "/tests" ))
3330 char *dir = xstrdup( make->base_dir );
3331 dir[strlen( dir ) - 6] = 0;
3332 parent_disabled = strarray_exists( &disabled_dirs, dir );
3334 output_filenames_obj_dir( make, make->ok_files );
3335 output( ": %s%s ../%s%s\n", testmodule, dll_ext, make->testdll, dll_ext );
3336 output( "check test:" );
3337 if (!make->disabled && !parent_disabled) output_filenames_obj_dir( make, make->ok_files );
3338 output( "\n" );
3339 strarray_add( &make->phony_targets, "check" );
3340 strarray_add( &make->phony_targets, "test" );
3341 output( "testclean::\n" );
3342 output( "\trm -f" );
3343 output_filenames_obj_dir( make, make->ok_files );
3344 output( "\n" );
3345 strarray_addall( &make->clean_files, make->ok_files );
3346 strarray_add( &make->phony_targets, "testclean" );
3350 /*******************************************************************
3351 * output_programs
3353 static void output_programs( struct makefile *make )
3355 unsigned int i, j;
3356 char *ldrpath_local = get_expanded_make_variable( make, "LDRPATH_LOCAL" );
3357 char *ldrpath_install = get_expanded_make_variable( make, "LDRPATH_INSTALL" );
3359 for (i = 0; i < make->programs.count; i++)
3361 char *program_installed = NULL;
3362 char *program = strmake( "%s%s", make->programs.str[i], exe_ext );
3363 struct strarray deps = get_local_dependencies( make, make->programs.str[i], make->in_files );
3364 struct strarray all_libs = get_expanded_file_local_var( make, make->programs.str[i], "LDFLAGS" );
3365 struct strarray objs = get_expanded_file_local_var( make, make->programs.str[i], "OBJS" );
3366 struct strarray symlinks = get_expanded_file_local_var( make, make->programs.str[i], "SYMLINKS" );
3368 if (!objs.count) objs = make->object_files;
3369 strarray_addall( &all_libs, add_default_libraries( make, &deps ));
3371 output( "%s:", obj_dir_path( make, program ) );
3372 output_filenames_obj_dir( make, objs );
3373 output_filenames( deps );
3374 output( "\n" );
3375 output( "\t$(CC) -o $@" );
3376 output_filenames_obj_dir( make, objs );
3378 if (strarray_exists( &all_libs, "-lwine" ))
3380 strarray_add( &all_libs, strmake( "-L%s", top_obj_dir_path( make, "libs/wine" )));
3381 if (ldrpath_local && ldrpath_install)
3383 program_installed = strmake( "%s-installed%s", make->programs.str[i], exe_ext );
3384 output_filename( ldrpath_local );
3385 output_filenames( all_libs );
3386 output_filename( "$(LDFLAGS)" );
3387 output( "\n" );
3388 output( "%s:", obj_dir_path( make, program_installed ) );
3389 output_filenames_obj_dir( make, objs );
3390 output_filenames( deps );
3391 output( "\n" );
3392 output( "\t$(CC) -o $@" );
3393 output_filenames_obj_dir( make, objs );
3394 output_filename( ldrpath_install );
3395 strarray_add( &make->all_targets, program_installed );
3399 output_filenames( all_libs );
3400 output_filename( "$(LDFLAGS)" );
3401 output( "\n" );
3402 strarray_add( &make->all_targets, program );
3404 for (j = 0; j < symlinks.count; j++)
3406 output( "%s: %s\n", obj_dir_path( make, symlinks.str[j] ), obj_dir_path( make, program ));
3407 output_symlink_rule( obj_dir_path( make, program ), obj_dir_path( make, symlinks.str[j] ));
3409 strarray_addall( &make->all_targets, symlinks );
3411 add_install_rule( make, program, program_installed ? program_installed : program,
3412 strmake( "p$(bindir)/%s", program ));
3413 for (j = 0; j < symlinks.count; j++)
3414 add_install_rule( make, symlinks.str[j], program,
3415 strmake( "y$(bindir)/%s%s", symlinks.str[j], exe_ext ));
3420 /*******************************************************************
3421 * output_subdirs
3423 static void output_subdirs( struct makefile *make )
3425 struct strarray symlinks = empty_strarray;
3426 struct strarray all_deps = empty_strarray;
3427 struct strarray build_deps = empty_strarray;
3428 struct strarray builddeps_deps = empty_strarray;
3429 struct strarray makefile_deps = empty_strarray;
3430 struct strarray clean_files = empty_strarray;
3431 struct strarray testclean_files = empty_strarray;
3432 struct strarray distclean_files = empty_strarray;
3433 struct strarray tools_deps = empty_strarray;
3434 struct strarray tooldeps_deps = empty_strarray;
3435 struct strarray winetest_deps = empty_strarray;
3436 struct strarray crosstest_deps = empty_strarray;
3437 unsigned int i, j;
3439 strarray_addall( &distclean_files, make->distclean_files );
3440 for (i = 0; i < make->subdirs.count; i++)
3442 const struct makefile *submake = make->submakes[i];
3443 char *subdir = base_dir_path( submake, "" );
3445 strarray_add( &makefile_deps, top_src_dir_path( make, base_dir_path( submake,
3446 strmake ( "%s.in", output_makefile_name ))));
3447 for (j = 0; j < submake->clean_files.count; j++)
3448 strarray_add( &clean_files, base_dir_path( submake, submake->clean_files.str[j] ));
3449 for (j = 0; j < submake->distclean_files.count; j++)
3450 strarray_add( &distclean_files, base_dir_path( submake, submake->distclean_files.str[j] ));
3451 for (j = 0; j < submake->ok_files.count; j++)
3452 strarray_add( &testclean_files, base_dir_path( submake, submake->ok_files.str[j] ));
3454 /* import libs are still created for disabled dirs, except for win16 ones */
3455 if (submake->module && submake->importlib && !(submake->disabled && submake->is_win16))
3457 char *importlib_path = base_dir_path( submake, strmake( "lib%s", submake->importlib ));
3458 if (submake->implib_objs.count)
3460 output( "%s.a: dummy\n", importlib_path );
3461 output( "\t@cd %s && $(MAKE) lib%s.a\n", subdir, submake->importlib );
3462 strarray_add( &tools_deps, strmake( "%s.a", importlib_path ));
3463 if (crosstarget)
3465 output( "%s.cross.a: dummy\n", importlib_path );
3466 output( "\t@cd %s && $(MAKE) lib%s.cross.a\n", subdir, submake->importlib );
3467 strarray_add( &tools_deps, strmake( "%s.cross.a", importlib_path ));
3470 else
3472 const char *libext = *dll_ext ? ".def" : ".a";
3473 char *spec_file = top_src_dir_path( make, base_dir_path( submake,
3474 replace_extension( submake->module, ".dll", ".spec" )));
3475 output( "%s%s: %s", importlib_path, libext, spec_file );
3476 output_filename( tools_path( make, "winebuild" ));
3477 output( "\n" );
3478 output( "\t%s -w -o $@", tools_path( make, "winebuild" ));
3479 output_filename( *dll_ext ? "--def" : "--implib" );
3480 output_filenames( target_flags );
3481 if (submake->is_win16) output_filename( "-m16" );
3482 output_filename( "--export" );
3483 output_filename( spec_file );
3484 output( "\n" );
3485 strarray_add( &build_deps, strmake( "%s%s", importlib_path, libext ));
3486 if (crosstarget && !submake->is_win16)
3488 output( "%s.cross.a: %s", importlib_path, spec_file );
3489 output_filename( tools_path( make, "winebuild" ));
3490 output( "\n" );
3491 output( "\t%s -b %s -w -o $@", tools_path( make, "winebuild" ), crosstarget );
3492 output_filename( "--implib" );
3493 output_filename( "--export" );
3494 output_filename( spec_file );
3495 output( "\n" );
3496 strarray_add( &build_deps, strmake( "%s.cross.a", importlib_path ));
3499 strarray_addall( &symlinks, output_importlib_symlinks( make, submake ));
3502 if (submake->disabled) continue;
3503 strarray_add( &all_deps, subdir );
3505 if (submake->module)
3507 if (!submake->staticlib)
3509 strarray_add( &builddeps_deps, subdir );
3510 if (!submake->appmode.count)
3512 output( "manpages htmlpages sgmlpages xmlpages::\n" );
3513 output( "\t@cd %s && $(MAKE) $@\n", subdir );
3516 else strarray_add( &tools_deps, subdir );
3518 else if (submake->testdll)
3520 output( "%s/test: dummy\n", subdir );
3521 output( "\t@cd %s && $(MAKE) test\n", subdir );
3522 strarray_add( &winetest_deps, subdir );
3523 strarray_add( &builddeps_deps, subdir );
3524 if (crosstarget)
3526 char *target = base_dir_path( submake, "crosstest" );
3527 output( "crosstest: %s\n", target );
3528 output( "%s: dummy\n", target );
3529 output( "\t@cd %s && $(MAKE) crosstest\n", subdir );
3530 strarray_add( &crosstest_deps, target );
3531 strarray_add( &builddeps_deps, target );
3534 else
3536 if (!strcmp( submake->base_dir, "tools" ) || !strncmp( submake->base_dir, "tools/", 6 ))
3538 strarray_add( &tooldeps_deps, submake->base_dir );
3539 for (j = 0; j < submake->programs.count; j++)
3540 output( "%s/%s%s: %s\n", submake->base_dir,
3541 submake->programs.str[j], tools_ext, submake->base_dir );
3543 if (submake->programs.count || submake->sharedlib)
3545 struct strarray libs = get_expanded_make_var_array( submake, "EXTRALIBS" );
3546 for (j = 0; j < submake->programs.count; j++)
3547 strarray_addall( &libs, get_expanded_file_local_var( submake,
3548 submake->programs.str[j], "LDFLAGS" ));
3549 output( "%s: libs/port", submake->base_dir );
3550 for (j = 0; j < libs.count; j++)
3552 if (!strcmp( libs.str[j], "-lwpp" )) output_filename( "libs/wpp" );
3553 if (!strcmp( libs.str[j], "-lwine" )) output_filename( "libs/wine" );
3555 output( "\n" );
3559 if (submake->install_rules[INSTALL_LIB].count)
3561 output( "install install-lib:: %s\n", submake->base_dir );
3562 output_install_commands( make, submake, submake->install_rules[INSTALL_LIB] );
3564 if (submake->install_rules[INSTALL_DEV].count)
3566 output( "install install-dev:: %s\n", submake->base_dir );
3567 output_install_commands( make, submake, submake->install_rules[INSTALL_DEV] );
3570 output( "all:" );
3571 output_filenames( all_deps );
3572 output( "\n" );
3573 output_filenames( all_deps );
3574 output( ": dummy\n" );
3575 output( "\t@cd $@ && $(MAKE)\n" );
3576 output( "Makefile:" );
3577 output_filenames( makefile_deps );
3578 output( "\n" );
3579 output_filenames( makefile_deps );
3580 output( ":\n" );
3581 if (tooldeps_deps.count)
3583 output( "__tooldeps__:" );
3584 output_filenames( tooldeps_deps );
3585 output( "\n" );
3586 strarray_add( &make->phony_targets, "__tooldeps__" );
3588 if (winetest_deps.count)
3590 output( "buildtests programs/winetest:" );
3591 output_filenames( winetest_deps );
3592 output( "\n" );
3593 output( "check test:" );
3594 for (i = 0; i < winetest_deps.count; i++)
3596 char *target = strmake( "%s/test", winetest_deps.str[i] );
3597 output_filename( target );
3598 strarray_add( &make->phony_targets, target );
3600 output( "\n" );
3601 strarray_add( &make->phony_targets, "buildtests" );
3602 strarray_add( &make->phony_targets, "check" );
3603 strarray_add( &make->phony_targets, "test" );
3605 output( "crosstest:" );
3606 output_filenames( crosstest_deps );
3607 output( "\n" );
3608 if (!crosstest_deps.count)
3609 output( "\t@echo \"crosstest is not supported (mingw not installed?)\" && false\n" );
3610 strarray_add( &make->phony_targets, "crosstest" );
3612 output( "clean::\n");
3613 output_rm_filenames( clean_files );
3614 output( "testclean::\n");
3615 output_rm_filenames( testclean_files );
3616 output( "distclean::\n");
3617 output_rm_filenames( distclean_files );
3618 output_filenames( tools_deps );
3619 output( ":" );
3620 output_filename( tools_dir_path( make, "widl" ));
3621 output_filename( tools_dir_path( make, "winebuild" ));
3622 output_filename( tools_dir_path( make, "winegcc" ));
3623 output_filename( obj_dir_path( make, "include" ));
3624 output( "\n" );
3625 output_filenames( builddeps_deps );
3626 output( ": __builddeps__\n" );
3627 strarray_add( &make->phony_targets, "distclean" );
3628 strarray_add( &make->phony_targets, "testclean" );
3629 strarray_addall( &make->phony_targets, all_deps );
3630 strarray_addall( &make->phony_targets, crosstest_deps );
3632 strarray_addall( &make->clean_files, symlinks );
3633 strarray_addall( &build_deps, tools_deps );
3634 strarray_addall( &build_deps, symlinks );
3635 if (build_deps.count)
3637 output( "__builddeps__:" );
3638 output_filenames( build_deps );
3639 output( "\n" );
3640 strarray_add( &make->phony_targets, "__builddeps__" );
3642 if (get_expanded_make_variable( make, "GETTEXTPO_LIBS" )) output_po_files( make );
3646 /*******************************************************************
3647 * output_sources
3649 static void output_sources( struct makefile *make )
3651 struct incl_file *source;
3652 unsigned int i, j;
3654 strarray_add( &make->phony_targets, "all" );
3656 LIST_FOR_EACH_ENTRY( source, &make->sources, struct incl_file, entry )
3658 char *obj = xstrdup( source->name );
3659 char *ext = get_extension( obj );
3661 if (!ext) fatal_error( "unsupported file type %s\n", source->name );
3662 *ext++ = 0;
3664 for (j = 0; output_source_funcs[j].ext; j++)
3665 if (!strcmp( ext, output_source_funcs[j].ext )) break;
3667 output_source_funcs[j].fn( make, source, obj );
3668 strarray_addall_uniq( &make->dependencies, source->dependencies );
3671 /* special case for winetest: add resource files from other test dirs */
3672 if (make->base_dir && !strcmp( make->base_dir, "programs/winetest" ))
3674 struct strarray tests = enable_tests;
3675 if (!tests.count)
3676 for (i = 0; i < top_makefile->subdirs.count; i++)
3677 if (top_makefile->submakes[i]->testdll && !top_makefile->submakes[i]->disabled)
3678 strarray_add( &tests, top_makefile->submakes[i]->testdll );
3679 for (i = 0; i < tests.count; i++)
3680 strarray_add( &make->object_files, replace_extension( tests.str[i], ".dll", "_test.res" ));
3683 if (make->dlldata_files.count)
3685 output( "%s: %s %s\n", obj_dir_path( make, "dlldata.c" ),
3686 tools_path( make, "widl" ), src_dir_path( make, "Makefile.in" ));
3687 output( "\t%s --dlldata-only -o $@", tools_path( make, "widl" ));
3688 output_filenames( make->dlldata_files );
3689 output( "\n" );
3692 if (make->staticlib) output_static_lib( make );
3693 else if (make->module) output_module( make );
3694 else if (make->testdll) output_test_module( make );
3695 else
3697 if (make->importlib) output_import_lib( make );
3698 if (make->sharedlib) output_shared_lib( make );
3699 if (make->programs.count) output_programs( make );
3702 for (i = 0; i < make->scripts.count; i++)
3703 add_install_rule( make, make->scripts.str[i], make->scripts.str[i],
3704 strmake( "S$(bindir)/%s", make->scripts.str[i] ));
3706 if (!make->src_dir) strarray_add( &make->distclean_files, ".gitignore" );
3707 strarray_add( &make->distclean_files, "Makefile" );
3708 if (make->testdll) strarray_add( &make->distclean_files, "testlist.c" );
3710 if (!make->base_dir)
3711 strarray_addall( &make->distclean_files, get_expanded_make_var_array( make, "CONFIGURE_TARGETS" ));
3712 else if (!strcmp( make->base_dir, "po" ))
3713 strarray_add( &make->distclean_files, "LINGUAS" );
3715 if (make->subdirs.count) output_subdirs( make );
3717 if (!make->disabled)
3719 if (make->all_targets.count)
3721 output( "all:" );
3722 output_filenames_obj_dir( make, make->all_targets );
3723 output( "\n" );
3725 output_install_rules( make, INSTALL_LIB, "install-lib" );
3726 output_install_rules( make, INSTALL_DEV, "install-dev" );
3727 output_uninstall_rules( make );
3730 if (make->dependencies.count)
3732 output_filenames( make->dependencies );
3733 output( ":\n" );
3736 strarray_addall( &make->clean_files, make->object_files );
3737 strarray_addall_uniq( &make->clean_files, make->crossobj_files );
3738 strarray_addall( &make->clean_files, make->all_targets );
3739 strarray_addall( &make->clean_files, get_expanded_make_var_array( make, "EXTRA_TARGETS" ));
3741 if (make->clean_files.count)
3743 output( "%s::\n", obj_dir_path( make, "clean" ));
3744 output( "\trm -f" );
3745 output_filenames_obj_dir( make, make->clean_files );
3746 output( "\n" );
3747 if (make->obj_dir) output( "__clean__: %s\n", obj_dir_path( make, "clean" ));
3748 strarray_add( &make->phony_targets, obj_dir_path( make, "clean" ));
3751 if (make->phony_targets.count)
3753 output( ".PHONY:" );
3754 output_filenames( make->phony_targets );
3755 output( "\n" );
3760 /*******************************************************************
3761 * create_temp_file
3763 static FILE *create_temp_file( const char *orig )
3765 char *name = xmalloc( strlen(orig) + 13 );
3766 unsigned int i, id = getpid();
3767 int fd;
3768 FILE *ret = NULL;
3770 for (i = 0; i < 100; i++)
3772 sprintf( name, "%s.tmp%08x", orig, id );
3773 if ((fd = open( name, O_RDWR | O_CREAT | O_EXCL, 0666 )) != -1)
3775 ret = fdopen( fd, "w" );
3776 break;
3778 if (errno != EEXIST) break;
3779 id += 7777;
3781 if (!ret) fatal_error( "failed to create output file for '%s'\n", orig );
3782 temp_file_name = name;
3783 return ret;
3787 /*******************************************************************
3788 * rename_temp_file
3790 static void rename_temp_file( const char *dest )
3792 int ret = rename( temp_file_name, dest );
3793 if (ret == -1 && errno == EEXIST)
3795 /* rename doesn't overwrite on windows */
3796 unlink( dest );
3797 ret = rename( temp_file_name, dest );
3799 if (ret == -1) fatal_error( "failed to rename output file to '%s'\n", dest );
3800 temp_file_name = NULL;
3804 /*******************************************************************
3805 * are_files_identical
3807 static int are_files_identical( FILE *file1, FILE *file2 )
3809 for (;;)
3811 char buffer1[8192], buffer2[8192];
3812 int size1 = fread( buffer1, 1, sizeof(buffer1), file1 );
3813 int size2 = fread( buffer2, 1, sizeof(buffer2), file2 );
3814 if (size1 != size2) return 0;
3815 if (!size1) return feof( file1 ) && feof( file2 );
3816 if (memcmp( buffer1, buffer2, size1 )) return 0;
3821 /*******************************************************************
3822 * rename_temp_file_if_changed
3824 static void rename_temp_file_if_changed( const char *dest )
3826 FILE *file1, *file2;
3827 int do_rename = 1;
3829 if ((file1 = fopen( dest, "r" )))
3831 if ((file2 = fopen( temp_file_name, "r" )))
3833 do_rename = !are_files_identical( file1, file2 );
3834 fclose( file2 );
3836 fclose( file1 );
3838 if (!do_rename)
3840 unlink( temp_file_name );
3841 temp_file_name = NULL;
3843 else rename_temp_file( dest );
3847 /*******************************************************************
3848 * output_linguas
3850 static void output_linguas( const struct makefile *make )
3852 const char *dest = base_dir_path( make, "LINGUAS" );
3853 struct incl_file *source;
3855 output_file = create_temp_file( dest );
3857 output( "# Automatically generated by make depend; DO NOT EDIT!!\n" );
3858 LIST_FOR_EACH_ENTRY( source, &make->sources, struct incl_file, entry )
3859 if (strendswith( source->name, ".po" ))
3860 output( "%s\n", replace_extension( source->name, ".po", "" ));
3862 if (fclose( output_file )) fatal_perror( "write" );
3863 output_file = NULL;
3864 rename_temp_file_if_changed( dest );
3868 /*******************************************************************
3869 * output_testlist
3871 static void output_testlist( const struct makefile *make )
3873 const char *dest = base_dir_path( make, "testlist.c" );
3874 struct strarray files = empty_strarray;
3875 unsigned int i;
3877 for (i = 0; i < make->ok_files.count; i++)
3878 strarray_add( &files, replace_extension( make->ok_files.str[i], ".ok", "" ));
3880 output_file = create_temp_file( dest );
3882 output( "/* Automatically generated by make depend; DO NOT EDIT!! */\n\n" );
3883 output( "#define WIN32_LEAN_AND_MEAN\n" );
3884 output( "#include <windows.h>\n\n" );
3885 output( "#define STANDALONE\n" );
3886 output( "#include \"wine/test.h\"\n\n" );
3888 for (i = 0; i < files.count; i++) output( "extern void func_%s(void);\n", files.str[i] );
3889 output( "\n" );
3890 output( "const struct test winetest_testlist[] =\n" );
3891 output( "{\n" );
3892 for (i = 0; i < files.count; i++) output( " { \"%s\", func_%s },\n", files.str[i], files.str[i] );
3893 output( " { 0, 0 }\n" );
3894 output( "};\n" );
3896 if (fclose( output_file )) fatal_perror( "write" );
3897 output_file = NULL;
3898 rename_temp_file_if_changed( dest );
3902 /*******************************************************************
3903 * output_gitignore
3905 static void output_gitignore( const char *dest, struct strarray files )
3907 int i;
3909 output_file = create_temp_file( dest );
3911 output( "# Automatically generated by make depend; DO NOT EDIT!!\n" );
3912 for (i = 0; i < files.count; i++)
3914 if (!strchr( files.str[i], '/' )) output( "/" );
3915 output( "%s\n", files.str[i] );
3918 if (fclose( output_file )) fatal_perror( "write" );
3919 output_file = NULL;
3920 rename_temp_file( dest );
3924 /*******************************************************************
3925 * output_top_variables
3927 static void output_top_variables( const struct makefile *make )
3929 unsigned int i;
3930 struct strarray *vars = &top_makefile->vars;
3932 if (!make->base_dir) return; /* don't output variables in the top makefile */
3934 output( "# Automatically generated by make depend; DO NOT EDIT!!\n\n" );
3935 output( "all:\n\n" );
3936 for (i = 0; i < vars->count; i += 2)
3938 if (!strcmp( vars->str[i], "SUBDIRS" )) continue; /* not inherited */
3939 output( "%s = %s\n", vars->str[i], get_make_variable( make, vars->str[i] ));
3941 output( "\n" );
3945 /*******************************************************************
3946 * output_dependencies
3948 static void output_dependencies( struct makefile *make )
3950 struct strarray ignore_files = empty_strarray;
3951 char buffer[1024];
3952 FILE *src_file;
3953 int found = 0;
3955 if (make->base_dir) create_dir( make->base_dir );
3957 output_file_name = base_dir_path( make, output_makefile_name );
3958 output_file = create_temp_file( output_file_name );
3959 output_top_variables( make );
3961 /* copy the contents of the source makefile */
3962 src_file = open_input_makefile( make );
3963 while (fgets( buffer, sizeof(buffer), src_file ) && !found)
3965 if (fwrite( buffer, 1, strlen(buffer), output_file ) != strlen(buffer)) fatal_perror( "write" );
3966 found = !strncmp( buffer, separator, strlen(separator) );
3968 if (fclose( src_file )) fatal_perror( "close" );
3969 input_file_name = NULL;
3971 if (!found) output( "\n%s (everything below this line is auto-generated; DO NOT EDIT!!)\n", separator );
3972 output_sources( make );
3974 fclose( output_file );
3975 output_file = NULL;
3976 rename_temp_file( output_file_name );
3978 strarray_addall( &ignore_files, make->distclean_files );
3979 strarray_addall( &ignore_files, make->clean_files );
3980 if (make->testdll) output_testlist( make );
3981 if (make->base_dir && !strcmp( make->base_dir, "po" )) output_linguas( make );
3982 if (!make->src_dir) output_gitignore( base_dir_path( make, ".gitignore" ), ignore_files );
3984 create_file_directories( make, ignore_files );
3986 output_file_name = NULL;
3990 /*******************************************************************
3991 * load_sources
3993 static void load_sources( struct makefile *make )
3995 static const char *source_vars[] =
3997 "SOURCES",
3998 "C_SRCS",
3999 "OBJC_SRCS",
4000 "RC_SRCS",
4001 "MC_SRCS",
4002 "IDL_SRCS",
4003 "BISON_SRCS",
4004 "LEX_SRCS",
4005 "HEADER_SRCS",
4006 "XTEMPLATE_SRCS",
4007 "SVG_SRCS",
4008 "FONT_SRCS",
4009 "IN_SRCS",
4010 "PO_SRCS",
4011 "MANPAGES",
4012 NULL
4014 const char **var;
4015 unsigned int i;
4016 struct strarray value;
4017 struct incl_file *file;
4019 if (root_src_dir)
4021 make->top_src_dir = concat_paths( make->top_obj_dir, root_src_dir );
4022 make->src_dir = concat_paths( make->top_src_dir, make->base_dir );
4024 strarray_set_value( &make->vars, "top_builddir", top_obj_dir_path( make, "" ));
4025 strarray_set_value( &make->vars, "top_srcdir", top_src_dir_path( make, "" ));
4026 strarray_set_value( &make->vars, "srcdir", src_dir_path( make, "" ));
4028 make->parent_dir = get_expanded_make_variable( make, "PARENTSRC" );
4029 make->module = get_expanded_make_variable( make, "MODULE" );
4030 make->testdll = get_expanded_make_variable( make, "TESTDLL" );
4031 make->sharedlib = get_expanded_make_variable( make, "SHAREDLIB" );
4032 make->staticlib = get_expanded_make_variable( make, "STATICLIB" );
4033 make->importlib = get_expanded_make_variable( make, "IMPORTLIB" );
4035 make->programs = get_expanded_make_var_array( make, "PROGRAMS" );
4036 make->scripts = get_expanded_make_var_array( make, "SCRIPTS" );
4037 make->appmode = get_expanded_make_var_array( make, "APPMODE" );
4038 make->imports = get_expanded_make_var_array( make, "IMPORTS" );
4039 make->delayimports = get_expanded_make_var_array( make, "DELAYIMPORTS" );
4040 make->extradllflags = get_expanded_make_var_array( make, "EXTRADLLFLAGS" );
4041 make->install_lib = get_expanded_make_var_array( make, "INSTALL_LIB" );
4042 make->install_dev = get_expanded_make_var_array( make, "INSTALL_DEV" );
4044 if (make->module && strendswith( make->module, ".a" )) make->staticlib = make->module;
4046 make->disabled = make->base_dir && strarray_exists( &disabled_dirs, make->base_dir );
4047 make->is_win16 = strarray_exists( &make->extradllflags, "-m16" ) || strarray_exists( &make->appmode, "-m16" );
4048 make->use_msvcrt = strarray_exists( &make->appmode, "-mno-cygwin" );
4050 for (i = 0; i < make->imports.count && !make->use_msvcrt; i++)
4051 make->use_msvcrt = !strncmp( make->imports.str[i], "msvcr", 5 ) ||
4052 !strcmp( make->imports.str[i], "ucrtbase" );
4054 if (make->module && !make->install_lib.count && !make->install_dev.count)
4056 if (make->importlib) strarray_add( &make->install_dev, make->importlib );
4057 if (make->staticlib) strarray_add( &make->install_dev, make->staticlib );
4058 else strarray_add( &make->install_lib, make->module );
4061 make->include_paths = empty_strarray;
4062 make->include_args = empty_strarray;
4063 make->define_args = empty_strarray;
4064 strarray_add( &make->define_args, "-D__WINESRC__" );
4066 value = get_expanded_make_var_array( make, "EXTRAINCL" );
4067 for (i = 0; i < value.count; i++)
4068 if (!strncmp( value.str[i], "-I", 2 ))
4069 strarray_add_uniq( &make->include_paths, value.str[i] + 2 );
4070 else
4071 strarray_add_uniq( &make->define_args, value.str[i] );
4072 strarray_addall( &make->define_args, get_expanded_make_var_array( make, "EXTRADEFS" ));
4074 strarray_add( &make->include_args, strmake( "-I%s", obj_dir_path( make, "" )));
4075 if (make->src_dir)
4076 strarray_add( &make->include_args, strmake( "-I%s", make->src_dir ));
4077 if (make->parent_dir)
4078 strarray_add( &make->include_args, strmake( "-I%s", src_dir_path( make, make->parent_dir )));
4079 strarray_add( &make->include_args, strmake( "-I%s", top_obj_dir_path( make, "include" )));
4080 if (make->top_src_dir)
4081 strarray_add( &make->include_args, strmake( "-I%s", top_src_dir_path( make, "include" )));
4082 if (make->use_msvcrt)
4083 strarray_add( &make->include_args, strmake( "-I%s", top_src_dir_path( make, "include/msvcrt" )));
4084 for (i = 0; i < make->include_paths.count; i++)
4085 strarray_add( &make->include_args, strmake( "-I%s", obj_dir_path( make, make->include_paths.str[i] )));
4087 list_init( &make->sources );
4088 list_init( &make->includes );
4090 for (var = source_vars; *var; var++)
4092 value = get_expanded_make_var_array( make, *var );
4093 for (i = 0; i < value.count; i++) add_src_file( make, value.str[i] );
4096 add_generated_sources( make );
4098 value = get_expanded_make_var_array( make, "EXTRA_OBJS" );
4099 for (i = 0; i < value.count; i++)
4101 /* default to .c for unknown extra object files */
4102 if (strendswith( value.str[i], ".o" ))
4103 add_generated_source( make, value.str[i], replace_extension( value.str[i], ".o", ".c" ) );
4104 else
4105 add_generated_source( make, value.str[i], NULL );
4108 LIST_FOR_EACH_ENTRY( file, &make->includes, struct incl_file, entry ) parse_file( make, file, 0 );
4109 LIST_FOR_EACH_ENTRY( file, &make->sources, struct incl_file, entry ) get_dependencies( file, file );
4113 /*******************************************************************
4114 * parse_makeflags
4116 static void parse_makeflags( const char *flags )
4118 const char *p = flags;
4119 char *var, *buffer = xmalloc( strlen(flags) + 1 );
4121 while (*p)
4123 while (isspace(*p)) p++;
4124 var = buffer;
4125 while (*p && !isspace(*p))
4127 if (*p == '\\' && p[1]) p++;
4128 *var++ = *p++;
4130 *var = 0;
4131 if (var > buffer) set_make_variable( &cmdline_vars, buffer );
4136 /*******************************************************************
4137 * parse_option
4139 static int parse_option( const char *opt )
4141 if (opt[0] != '-')
4143 if (strchr( opt, '=' )) return set_make_variable( &cmdline_vars, opt );
4144 return 0;
4146 switch(opt[1])
4148 case 'f':
4149 if (opt[2]) output_makefile_name = opt + 2;
4150 break;
4151 case 'R':
4152 relative_dir_mode = 1;
4153 break;
4154 default:
4155 fprintf( stderr, "Unknown option '%s'\n%s", opt, Usage );
4156 exit(1);
4158 return 1;
4162 /*******************************************************************
4163 * main
4165 int main( int argc, char *argv[] )
4167 const char *makeflags = getenv( "MAKEFLAGS" );
4168 int i, j;
4170 if (makeflags) parse_makeflags( makeflags );
4172 i = 1;
4173 while (i < argc)
4175 if (parse_option( argv[i] ))
4177 for (j = i; j < argc; j++) argv[j] = argv[j+1];
4178 argc--;
4180 else i++;
4183 if (relative_dir_mode)
4185 char *relpath;
4187 if (argc != 3)
4189 fprintf( stderr, "Option -R needs two directories\n%s", Usage );
4190 exit( 1 );
4192 relpath = get_relative_path( argv[1], argv[2] );
4193 printf( "%s\n", relpath ? relpath : "." );
4194 exit( 0 );
4197 atexit( cleanup_files );
4198 signal( SIGTERM, exit_on_signal );
4199 signal( SIGINT, exit_on_signal );
4200 #ifdef SIGHUP
4201 signal( SIGHUP, exit_on_signal );
4202 #endif
4204 for (i = 0; i < HASH_SIZE; i++) list_init( &files[i] );
4206 top_makefile = parse_makefile( NULL );
4208 target_flags = get_expanded_make_var_array( top_makefile, "TARGETFLAGS" );
4209 msvcrt_flags = get_expanded_make_var_array( top_makefile, "MSVCRTFLAGS" );
4210 dll_flags = get_expanded_make_var_array( top_makefile, "DLLFLAGS" );
4211 extra_cflags = get_expanded_make_var_array( top_makefile, "EXTRACFLAGS" );
4212 cpp_flags = get_expanded_make_var_array( top_makefile, "CPPFLAGS" );
4213 unwind_flags = get_expanded_make_var_array( top_makefile, "UNWINDFLAGS" );
4214 widl_flags = get_expanded_make_var_array( top_makefile, "WIDLFLAGS" );
4215 libs = get_expanded_make_var_array( top_makefile, "LIBS" );
4216 enable_tests = get_expanded_make_var_array( top_makefile, "ENABLE_TESTS" );
4218 root_src_dir = get_expanded_make_variable( top_makefile, "srcdir" );
4219 tools_dir = get_expanded_make_variable( top_makefile, "TOOLSDIR" );
4220 tools_ext = get_expanded_make_variable( top_makefile, "TOOLSEXT" );
4221 exe_ext = get_expanded_make_variable( top_makefile, "EXEEXT" );
4222 man_ext = get_expanded_make_variable( top_makefile, "api_manext" );
4223 dll_ext = (exe_ext && !strcmp( exe_ext, ".exe" )) ? "" : ".so";
4224 crosstarget = get_expanded_make_variable( top_makefile, "CROSSTARGET" );
4225 fontforge = get_expanded_make_variable( top_makefile, "FONTFORGE" );
4226 convert = get_expanded_make_variable( top_makefile, "CONVERT" );
4227 rsvg = get_expanded_make_variable( top_makefile, "RSVG" );
4228 icotool = get_expanded_make_variable( top_makefile, "ICOTOOL" );
4229 dlltool = get_expanded_make_variable( top_makefile, "DLLTOOL" );
4230 msgfmt = get_expanded_make_variable( top_makefile, "MSGFMT" );
4231 ln_s = get_expanded_make_variable( top_makefile, "LN_S" );
4233 if (root_src_dir && !strcmp( root_src_dir, "." )) root_src_dir = NULL;
4234 if (tools_dir && !strcmp( tools_dir, "." )) tools_dir = NULL;
4235 if (!exe_ext) exe_ext = "";
4236 if (!tools_ext) tools_ext = "";
4237 if (!man_ext) man_ext = "3w";
4239 if (argc == 1)
4241 disabled_dirs = get_expanded_make_var_array( top_makefile, "DISABLED_SUBDIRS" );
4242 top_makefile->subdirs = get_expanded_make_var_array( top_makefile, "SUBDIRS" );
4243 top_makefile->submakes = xmalloc( top_makefile->subdirs.count * sizeof(*top_makefile->submakes) );
4245 for (i = 0; i < top_makefile->subdirs.count; i++)
4246 top_makefile->submakes[i] = parse_makefile( top_makefile->subdirs.str[i] );
4248 load_sources( top_makefile );
4249 for (i = 0; i < top_makefile->subdirs.count; i++)
4250 load_sources( top_makefile->submakes[i] );
4252 for (i = 0; i < top_makefile->subdirs.count; i++)
4253 output_dependencies( top_makefile->submakes[i] );
4255 output_dependencies( top_makefile );
4256 return 0;
4259 for (i = 1; i < argc; i++)
4261 struct makefile *make = parse_makefile( argv[i] );
4262 load_sources( make );
4263 output_dependencies( make );
4265 return 0;