ntdll: Align string data in RtlCreateProcessParametersEx().
[wine.git] / tools / makedep.c
blob66b21dbacd7e93eec7aeb197bcc767bfa55d14dc
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_filename( source->filename );
2652 output( "\n" );
2653 output_filenames_obj_dir( make, targets );
2654 output( ": %s", source->filename );
2655 output_filenames( source->dependencies );
2656 output( "\n" );
2660 /*******************************************************************
2661 * output_source_tlb
2663 static void output_source_tlb( struct makefile *make, struct incl_file *source, const char *obj )
2665 strarray_add( &make->all_targets, source->name );
2669 /*******************************************************************
2670 * output_source_x
2672 static void output_source_x( struct makefile *make, struct incl_file *source, const char *obj )
2674 output( "%s.h: %s%s %s\n", obj_dir_path( make, obj ),
2675 tools_dir_path( make, "make_xftmpl" ), tools_ext, source->filename );
2676 output( "\t%s%s -H -o $@ %s\n",
2677 tools_dir_path( make, "make_xftmpl" ), tools_ext, source->filename );
2678 if (source->file->flags & FLAG_INSTALL)
2680 strarray_add( &make->install_rules[INSTALL_DEV], source->name );
2681 strarray_add( &make->install_rules[INSTALL_DEV],
2682 strmake( "D$(includedir)/wine/%s", get_include_install_path( source->name ) ));
2683 strarray_add( &make->install_rules[INSTALL_DEV], strmake( "%s.h", obj ));
2684 strarray_add( &make->install_rules[INSTALL_DEV],
2685 strmake( "d$(includedir)/wine/%s.h", get_include_install_path( obj ) ));
2690 /*******************************************************************
2691 * output_source_sfd
2693 static void output_source_sfd( struct makefile *make, struct incl_file *source, const char *obj )
2695 unsigned int i;
2696 char *ttf_file = src_dir_path( make, strmake( "%s.ttf", obj ));
2698 if (fontforge && !make->src_dir)
2700 output( "%s: %s\n", ttf_file, source->filename );
2701 output( "\t%s -script %s %s $@\n",
2702 fontforge, top_src_dir_path( make, "fonts/genttf.ff" ), source->filename );
2703 if (!(source->file->flags & FLAG_SFD_FONTS)) output( "all: %s\n", ttf_file );
2705 if (source->file->flags & FLAG_INSTALL)
2707 strarray_add( &make->install_rules[INSTALL_LIB], strmake( "%s.ttf", obj ));
2708 strarray_add( &make->install_rules[INSTALL_LIB], strmake( "D$(fontdir)/%s.ttf", obj ));
2710 if (source->file->flags & FLAG_SFD_FONTS)
2712 struct strarray *array = source->file->args;
2714 for (i = 0; i < array->count; i++)
2716 char *font = strtok( xstrdup(array->str[i]), " \t" );
2717 char *args = strtok( NULL, "" );
2719 strarray_add( &make->all_targets, xstrdup( font ));
2720 output( "%s: %s %s\n", obj_dir_path( make, font ),
2721 tools_path( make, "sfnt2fon" ), ttf_file );
2722 output( "\t%s -o $@ %s %s\n", tools_path( make, "sfnt2fon" ), ttf_file, args );
2723 strarray_add( &make->install_rules[INSTALL_LIB], xstrdup(font) );
2724 strarray_add( &make->install_rules[INSTALL_LIB], strmake( "d$(fontdir)/%s", font ));
2730 /*******************************************************************
2731 * output_source_svg
2733 static void output_source_svg( struct makefile *make, struct incl_file *source, const char *obj )
2735 static const char * const images[] = { "bmp", "cur", "ico", NULL };
2736 unsigned int i;
2738 if (convert && rsvg && icotool && !make->src_dir)
2740 for (i = 0; images[i]; i++)
2741 if (find_include_file( make, strmake( "%s.%s", obj, images[i] ))) break;
2743 if (images[i])
2745 output( "%s.%s: %s\n", src_dir_path( make, obj ), images[i], source->filename );
2746 output( "\tCONVERT=\"%s\" ICOTOOL=\"%s\" RSVG=\"%s\" %s %s $@\n", convert, icotool, rsvg,
2747 top_src_dir_path( make, "tools/buildimage" ), source->filename );
2753 /*******************************************************************
2754 * output_source_nls
2756 static void output_source_nls( struct makefile *make, struct incl_file *source, const char *obj )
2758 add_install_rule( make, source->name, source->name,
2759 strmake( "D$(datadir)/wine/%s", source->name ));
2763 /*******************************************************************
2764 * output_source_desktop
2766 static void output_source_desktop( struct makefile *make, struct incl_file *source, const char *obj )
2768 add_install_rule( make, source->name, source->name,
2769 strmake( "D$(datadir)/applications/%s", source->name ));
2773 /*******************************************************************
2774 * output_source_po
2776 static void output_source_po( struct makefile *make, struct incl_file *source, const char *obj )
2778 output( "%s.mo: %s\n", obj_dir_path( make, obj ), source->filename );
2779 output( "\t%s -o $@ %s\n", msgfmt, source->filename );
2780 strarray_add( &make->all_targets, strmake( "%s.mo", obj ));
2784 /*******************************************************************
2785 * output_source_in
2787 static void output_source_in( struct makefile *make, struct incl_file *source, const char *obj )
2789 unsigned int i;
2791 if (strendswith( obj, ".man" ) && source->file->args)
2793 struct strarray symlinks;
2794 char *dir, *dest = replace_extension( obj, ".man", "" );
2795 char *lang = strchr( dest, '.' );
2796 char *section = source->file->args;
2797 if (lang)
2799 *lang++ = 0;
2800 dir = strmake( "$(mandir)/%s/man%s", lang, section );
2802 else dir = strmake( "$(mandir)/man%s", section );
2803 add_install_rule( make, dest, xstrdup(obj), strmake( "d%s/%s.%s", dir, dest, section ));
2804 symlinks = get_expanded_file_local_var( make, dest, "SYMLINKS" );
2805 for (i = 0; i < symlinks.count; i++)
2806 add_install_rule( make, symlinks.str[i], strmake( "%s.%s", dest, section ),
2807 strmake( "y%s/%s.%s", dir, symlinks.str[i], section ));
2808 free( dest );
2809 free( dir );
2811 strarray_add( &make->in_files, xstrdup(obj) );
2812 strarray_add( &make->all_targets, xstrdup(obj) );
2813 output( "%s: %s\n", obj_dir_path( make, obj ), source->filename );
2814 output( "\t$(SED_CMD) %s >$@ || (rm -f $@ && false)\n", source->filename );
2815 output( "%s:", obj_dir_path( make, obj ));
2816 output_filenames( source->dependencies );
2817 output( "\n" );
2818 add_install_rule( make, obj, xstrdup( obj ), strmake( "d$(datadir)/wine/%s", obj ));
2822 /*******************************************************************
2823 * output_source_spec
2825 static void output_source_spec( struct makefile *make, struct incl_file *source, const char *obj )
2827 struct strarray imports = get_expanded_file_local_var( make, obj, "IMPORTS" );
2828 struct strarray dll_flags = get_expanded_file_local_var( make, obj, "EXTRADLLFLAGS" );
2829 struct strarray all_libs, dep_libs = empty_strarray;
2831 if (!imports.count) imports = make->imports;
2832 if (!dll_flags.count) dll_flags = make->extradllflags;
2833 all_libs = add_import_libs( make, &dep_libs, imports, 0 );
2834 add_import_libs( make, &dep_libs, get_default_imports( make ), 0 ); /* dependencies only */
2835 strarray_addall( &all_libs, libs );
2837 strarray_add( &make->clean_files, strmake( "%s.dll%s", obj, dll_ext ));
2838 strarray_add( &make->object_files, strmake( "%s.res", obj ));
2839 output( "%s.res: %s.dll%s\n", obj_dir_path( make, obj ), obj_dir_path( make, obj ), dll_ext );
2840 output( "\techo \"%s.dll TESTDLL \\\"%s.dll%s\\\"\" | %s -o $@\n", obj,
2841 obj_dir_path( make, obj ), dll_ext, tools_path( make, "wrc" ));
2843 output( "%s.dll%s:", obj_dir_path( make, obj ), dll_ext );
2844 output_filename( source->filename );
2845 output_filename( strmake( "%s.o", obj_dir_path( make, obj )));
2846 output_filenames( dep_libs );
2847 output_filename( tools_path( make, "winebuild" ));
2848 output_filename( tools_path( make, "winegcc" ));
2849 output( "\n" );
2850 output( "\t%s -s -o $@", tools_path( make, "winegcc" ));
2851 output_filename( strmake( "-B%s", tools_dir_path( make, "winebuild" )));
2852 if (tools_dir) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make, "" )));
2853 output_filenames( target_flags );
2854 output_filenames( unwind_flags );
2855 output_filenames( dll_flags );
2856 output_filename( "-shared" );
2857 output_filename( source->filename );
2858 output_filename( strmake( "%s.o", obj_dir_path( make, obj )));
2859 output_filenames( all_libs );
2860 output_filename( "$(LDFLAGS)" );
2861 output( "\n" );
2863 if (crosstarget)
2865 dep_libs = empty_strarray;
2866 all_libs = add_import_libs( make, &dep_libs, imports, 1 );
2867 add_import_libs( make, &dep_libs, get_default_imports( make ), 1 ); /* dependencies only */
2868 strarray_addall( &all_libs, libs );
2870 strarray_add( &make->clean_files, strmake( "%s.dll", obj ));
2871 strarray_add( &make->crossobj_files, strmake( "%s.cross.res", obj ));
2872 output( "%s.cross.res: %s.dll\n", obj_dir_path( make, obj ), obj_dir_path( make, obj ) );
2873 output( "\techo \"%s.dll TESTDLL \\\"%s.dll\\\"\" | %s -o $@\n", obj,
2874 obj_dir_path( make, obj ), tools_path( make, "wrc" ));
2876 output( "%s.dll:", obj_dir_path( make, obj ));
2877 output_filename( source->filename );
2878 output_filename( strmake( "%s.cross.o", obj_dir_path( make, obj )));
2879 output_filenames( dep_libs );
2880 output_filename( tools_path( make, "winebuild" ));
2881 output_filename( tools_path( make, "winegcc" ));
2882 output( "\n" );
2883 output( "\t%s -s -o $@ -b %s", tools_path( make, "winegcc" ), crosstarget );
2884 output_filename( strmake( "-B%s", tools_dir_path( make, "winebuild" )));
2885 if (tools_dir) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make, "" )));
2886 output_filename( "--lib-suffix=.cross.a" );
2887 output_filenames( dll_flags );
2888 output_filename( "-shared" );
2889 output_filename( source->filename );
2890 output_filename( strmake( "%s.cross.o", obj_dir_path( make, obj )));
2891 output_filenames( all_libs );
2892 output_filename( "$(LDFLAGS)" );
2893 output( "\n" );
2898 /*******************************************************************
2899 * output_source_default
2901 static void output_source_default( struct makefile *make, struct incl_file *source, const char *obj )
2903 struct strarray extradefs = get_expanded_file_local_var( make, obj, "EXTRADEFS" );
2904 int is_dll_src = (make->testdll &&
2905 strendswith( source->name, ".c" ) &&
2906 find_src_file( make, replace_extension( source->name, ".c", ".spec" )));
2907 int need_cross = (make->testdll ||
2908 (source->file->flags & FLAG_C_IMPLIB) ||
2909 (make->module && make->staticlib));
2911 if ((source->file->flags & FLAG_GENERATED) &&
2912 (!make->testdll || !strendswith( source->filename, "testlist.c" )))
2913 strarray_add( &make->clean_files, source->filename );
2914 if (source->file->flags & FLAG_C_IMPLIB) strarray_add( &make->implib_objs, strmake( "%s.o", obj ));
2915 strarray_add( is_dll_src ? &make->clean_files : &make->object_files, strmake( "%s.o", obj ));
2916 output( "%s.o: %s\n", obj_dir_path( make, obj ), source->filename );
2917 output( "\t$(CC) -c -o $@ %s", source->filename );
2918 output_filenames( make->include_args );
2919 output_filenames( make->define_args );
2920 output_filenames( extradefs );
2921 if (make->module || make->staticlib || make->sharedlib || make->testdll)
2923 output_filenames( dll_flags );
2924 if (make->use_msvcrt) output_filenames( msvcrt_flags );
2926 output_filenames( extra_cflags );
2927 output_filenames( cpp_flags );
2928 output_filename( "$(CFLAGS)" );
2929 output( "\n" );
2930 if (crosstarget && need_cross)
2932 strarray_add( is_dll_src ? &make->clean_files : &make->crossobj_files, strmake( "%s.cross.o", obj ));
2933 output( "%s.cross.o: %s\n", obj_dir_path( make, obj ), source->filename );
2934 output( "\t$(CROSSCC) -c -o $@ %s", source->filename );
2935 output_filenames( make->include_args );
2936 output_filenames( make->define_args );
2937 output_filenames( extradefs );
2938 if (make->use_msvcrt) output_filenames( msvcrt_flags );
2939 output_filename( "-DWINE_CROSSTEST" );
2940 output_filenames( cpp_flags );
2941 output_filename( "$(CROSSCFLAGS)" );
2942 output( "\n" );
2944 if (strendswith( source->name, ".c" ) && !(source->file->flags & FLAG_GENERATED))
2946 strarray_add( &make->c2man_files, source->filename );
2947 if (make->testdll && !is_dll_src)
2949 strarray_add( &make->ok_files, strmake( "%s.ok", obj ));
2950 output( "%s.ok:\n", obj_dir_path( make, obj ));
2951 output( "\t%s $(RUNTESTFLAGS) -T %s -M %s -p %s%s %s && touch $@\n",
2952 top_src_dir_path( make, "tools/runtest" ), top_obj_dir_path( make, "" ),
2953 make->testdll, replace_extension( make->testdll, ".dll", "_test.exe" ),
2954 dll_ext, obj );
2957 output( "%s.o", obj_dir_path( make, obj ));
2958 if (crosstarget && need_cross) output( " %s.cross.o", obj_dir_path( make, obj ));
2959 output( ":" );
2960 output_filenames( source->dependencies );
2961 output( "\n" );
2965 /* dispatch table to output rules for a single source file */
2966 static const struct
2968 const char *ext;
2969 void (*fn)( struct makefile *make, struct incl_file *source, const char *obj );
2970 } output_source_funcs[] =
2972 { "y", output_source_y },
2973 { "l", output_source_l },
2974 { "h", output_source_h },
2975 { "rh", output_source_h },
2976 { "inl", output_source_h },
2977 { "rc", output_source_rc },
2978 { "mc", output_source_mc },
2979 { "res", output_source_res },
2980 { "idl", output_source_idl },
2981 { "tlb", output_source_tlb },
2982 { "sfd", output_source_sfd },
2983 { "svg", output_source_svg },
2984 { "nls", output_source_nls },
2985 { "desktop", output_source_desktop },
2986 { "po", output_source_po },
2987 { "in", output_source_in },
2988 { "x", output_source_x },
2989 { "spec", output_source_spec },
2990 { NULL, output_source_default }
2994 /*******************************************************************
2995 * output_man_pages
2997 static void output_man_pages( struct makefile *make )
2999 if (make->c2man_files.count)
3001 char *spec_file = src_dir_path( make, replace_extension( make->module, ".dll", ".spec" ));
3003 output( "manpages::\n" );
3004 output( "\t%s -w %s", top_src_dir_path( make, "tools/c2man.pl" ), spec_file );
3005 output_filename( strmake( "-R%s", top_src_dir_path( make, "" )));
3006 output_filename( strmake( "-I%s", top_src_dir_path( make, "include" )));
3007 output_filename( strmake( "-o %s/man%s",
3008 top_obj_dir_path( make, "documentation" ), man_ext ));
3009 output_filenames( make->c2man_files );
3010 output( "\n" );
3011 output( "htmlpages::\n" );
3012 output( "\t%s -Th -w %s", top_src_dir_path( make, "tools/c2man.pl" ), spec_file );
3013 output_filename( strmake( "-R%s", top_src_dir_path( make, "" )));
3014 output_filename( strmake( "-I%s", top_src_dir_path( make, "include" )));
3015 output_filename( strmake( "-o %s",
3016 top_obj_dir_path( make, "documentation/html" )));
3017 output_filenames( make->c2man_files );
3018 output( "\n" );
3019 output( "sgmlpages::\n" );
3020 output( "\t%s -Ts -w %s", top_src_dir_path( make, "tools/c2man.pl" ), spec_file );
3021 output_filename( strmake( "-R%s", top_src_dir_path( make, "" )));
3022 output_filename( strmake( "-I%s", top_src_dir_path( make, "include" )));
3023 output_filename( strmake( "-o %s",
3024 top_obj_dir_path( make, "documentation/api-guide" )));
3025 output_filenames( make->c2man_files );
3026 output( "\n" );
3027 output( "xmlpages::\n" );
3028 output( "\t%s -Tx -w %s", top_src_dir_path( make, "tools/c2man.pl" ), spec_file );
3029 output_filename( strmake( "-R%s", top_src_dir_path( make, "" )));
3030 output_filename( strmake( "-I%s", top_src_dir_path( make, "include" )));
3031 output_filename( strmake( "-o %s",
3032 top_obj_dir_path( make, "documentation/api-guide-xml" )));
3033 output_filenames( make->c2man_files );
3034 output( "\n" );
3035 strarray_add( &make->phony_targets, "manpages" );
3036 strarray_add( &make->phony_targets, "htmlpages" );
3037 strarray_add( &make->phony_targets, "sgmlpages" );
3038 strarray_add( &make->phony_targets, "xmlpages" );
3040 else output( "manpages htmlpages sgmlpages xmlpages::\n" );
3044 /*******************************************************************
3045 * output_module
3047 static void output_module( struct makefile *make )
3049 struct strarray all_libs = empty_strarray;
3050 struct strarray dep_libs = empty_strarray;
3051 char *module_path = obj_dir_path( make, make->module );
3052 char *spec_file = NULL;
3053 unsigned int i;
3055 if (!make->appmode.count)
3056 spec_file = src_dir_path( make, replace_extension( make->module, ".dll", ".spec" ));
3057 strarray_addall( &all_libs, add_import_libs( make, &dep_libs, make->delayimports, 0 ));
3058 strarray_addall( &all_libs, add_import_libs( make, &dep_libs, make->imports, 0 ));
3059 add_import_libs( make, &dep_libs, get_default_imports( make ), 0 ); /* dependencies only */
3060 strarray_addall( &all_libs, add_default_libraries( make, &dep_libs ));
3062 if (*dll_ext)
3064 for (i = 0; i < make->delayimports.count; i++)
3065 strarray_add( &all_libs, strmake( "-Wb,-d%s", make->delayimports.str[i] ));
3066 strarray_add( &make->all_targets, strmake( "%s%s", make->module, dll_ext ));
3067 strarray_add( &make->all_targets, strmake( "%s.fake", make->module ));
3068 add_install_rule( make, make->module, strmake( "%s%s", make->module, dll_ext ),
3069 strmake( "p$(dlldir)/%s%s", make->module, dll_ext ));
3070 add_install_rule( make, make->module, strmake( "%s.fake", make->module ),
3071 strmake( "d$(dlldir)/fakedlls/%s", make->module ));
3072 output( "%s%s %s.fake:", module_path, dll_ext, module_path );
3074 else
3076 strarray_add( &all_libs, "-lwine" );
3077 strarray_add( &make->all_targets, make->module );
3078 add_install_rule( make, make->module, make->module,
3079 strmake( "p$(%s)/%s", spec_file ? "dlldir" : "bindir", make->module ));
3080 output( "%s:", module_path );
3082 if (spec_file) output_filename( spec_file );
3083 output_filenames_obj_dir( make, make->object_files );
3084 output_filenames( dep_libs );
3085 output_filename( tools_path( make, "winebuild" ));
3086 output_filename( tools_path( make, "winegcc" ));
3087 output( "\n" );
3088 output( "\t%s -o $@", tools_path( make, "winegcc" ));
3089 output_filename( strmake( "-B%s", tools_dir_path( make, "winebuild" )));
3090 if (tools_dir) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make, "" )));
3091 output_filenames( target_flags );
3092 output_filenames( unwind_flags );
3093 if (spec_file)
3095 output( " -shared %s", spec_file );
3096 output_filenames( make->extradllflags );
3098 else output_filenames( make->appmode );
3099 output_filenames_obj_dir( make, make->object_files );
3100 output_filenames( all_libs );
3101 output_filename( "$(LDFLAGS)" );
3102 output( "\n" );
3104 if (spec_file && make->importlib)
3106 char *importlib_path = obj_dir_path( make, strmake( "lib%s", make->importlib ));
3107 if (*dll_ext && !make->implib_objs.count)
3109 strarray_add( &make->clean_files, strmake( "lib%s.def", make->importlib ));
3110 output( "%s.def: %s %s\n", importlib_path, tools_path( make, "winebuild" ), spec_file );
3111 output( "\t%s -w --def -o $@ --export %s", tools_path( make, "winebuild" ), spec_file );
3112 output_filenames( target_flags );
3113 if (make->is_win16) output_filename( "-m16" );
3114 output( "\n" );
3115 add_install_rule( make, make->importlib,
3116 strmake( "lib%s.def", make->importlib ),
3117 strmake( "d$(dlldir)/lib%s.def", make->importlib ));
3119 else
3121 strarray_add( &make->clean_files, strmake( "lib%s.a", make->importlib ));
3122 output( "%s.a: %s %s", importlib_path, tools_path( make, "winebuild" ), spec_file );
3123 output_filenames_obj_dir( make, make->implib_objs );
3124 output( "\n" );
3125 output( "\t%s -w --implib -o $@ --export %s", tools_path( make, "winebuild" ), spec_file );
3126 output_filenames( target_flags );
3127 output_filenames_obj_dir( make, make->implib_objs );
3128 output( "\n" );
3129 add_install_rule( make, make->importlib,
3130 strmake( "lib%s.a", make->importlib ),
3131 strmake( "d$(dlldir)/lib%s.a", make->importlib ));
3133 if (crosstarget && !make->is_win16)
3135 struct strarray cross_files = strarray_replace_extension( &make->implib_objs, ".o", ".cross.o" );
3136 strarray_add( &make->clean_files, strmake( "lib%s.cross.a", make->importlib ));
3137 output( "%s.cross.a: %s %s", importlib_path, tools_path( make, "winebuild" ), spec_file );
3138 output_filenames_obj_dir( make, cross_files );
3139 output( "\n" );
3140 output( "\t%s -b %s -w --implib -o $@ --export %s",
3141 tools_path( make, "winebuild" ), crosstarget, spec_file );
3142 output_filenames_obj_dir( make, cross_files );
3143 output( "\n" );
3147 if (spec_file)
3148 output_man_pages( make );
3149 else if (*dll_ext && !make->is_win16)
3151 char *binary = replace_extension( make->module, ".exe", "" );
3152 add_install_rule( make, binary, "wineapploader", strmake( "t$(bindir)/%s", binary ));
3157 /*******************************************************************
3158 * output_static_lib
3160 static void output_static_lib( struct makefile *make )
3162 strarray_add( &make->all_targets, make->staticlib );
3163 output( "%s:", obj_dir_path( make, make->staticlib ));
3164 output_filenames_obj_dir( make, make->object_files );
3165 output( "\n\trm -f $@\n" );
3166 output( "\t$(AR) $(ARFLAGS) $@" );
3167 output_filenames_obj_dir( make, make->object_files );
3168 output( "\n\t$(RANLIB) $@\n" );
3169 add_install_rule( make, make->staticlib, make->staticlib,
3170 strmake( "d$(dlldir)/%s", make->staticlib ));
3171 if (crosstarget && make->module)
3173 char *name = replace_extension( make->staticlib, ".a", ".cross.a" );
3175 strarray_add( &make->all_targets, name );
3176 output( "%s:", obj_dir_path( make, name ));
3177 output_filenames_obj_dir( make, make->crossobj_files );
3178 output( "\n\trm -f $@\n" );
3179 output( "\t%s-ar $(ARFLAGS) $@", crosstarget );
3180 output_filenames_obj_dir( make, make->crossobj_files );
3181 output( "\n\t%s-ranlib $@\n", crosstarget );
3186 /*******************************************************************
3187 * output_shared_lib
3189 static void output_shared_lib( struct makefile *make )
3191 unsigned int i;
3192 char *basename, *p;
3193 struct strarray names = get_shared_lib_names( make->sharedlib );
3194 struct strarray all_libs = empty_strarray;
3195 struct strarray dep_libs = empty_strarray;
3197 basename = xstrdup( make->sharedlib );
3198 if ((p = strchr( basename, '.' ))) *p = 0;
3200 strarray_addall( &dep_libs, get_local_dependencies( make, basename, make->in_files ));
3201 strarray_addall( &all_libs, get_expanded_file_local_var( make, basename, "LDFLAGS" ));
3202 strarray_addall( &all_libs, add_default_libraries( make, &dep_libs ));
3204 output( "%s:", obj_dir_path( make, make->sharedlib ));
3205 output_filenames_obj_dir( make, make->object_files );
3206 output_filenames( dep_libs );
3207 output( "\n" );
3208 output( "\t$(CC) -o $@" );
3209 output_filenames_obj_dir( make, make->object_files );
3210 output_filenames( all_libs );
3211 output_filename( "$(LDFLAGS)" );
3212 output( "\n" );
3213 add_install_rule( make, make->sharedlib, make->sharedlib,
3214 strmake( "p$(libdir)/%s", make->sharedlib ));
3215 for (i = 1; i < names.count; i++)
3217 output( "%s: %s\n", obj_dir_path( make, names.str[i] ), obj_dir_path( make, names.str[i-1] ));
3218 output_symlink_rule( obj_dir_path( make, names.str[i-1] ), obj_dir_path( make, names.str[i] ));
3219 add_install_rule( make, names.str[i], names.str[i-1],
3220 strmake( "y$(libdir)/%s", names.str[i] ));
3222 strarray_addall( &make->all_targets, names );
3226 /*******************************************************************
3227 * output_import_lib
3229 static void output_import_lib( struct makefile *make )
3231 char *def_file = replace_extension( make->importlib, ".a", ".def" );
3233 /* stand-alone import lib (for libwine) */
3234 if (!strncmp( def_file, "lib", 3 )) def_file += 3;
3235 output( "%s: %s\n", obj_dir_path( make, make->importlib ), src_dir_path( make, def_file ));
3236 output( "\t%s -l $@ -d %s\n", dlltool, src_dir_path( make, def_file ));
3237 add_install_rule( make, make->importlib, make->importlib, strmake( "d$(libdir)/%s", make->importlib ));
3238 strarray_add( &make->all_targets, make->importlib );
3242 /*******************************************************************
3243 * output_test_module
3245 static void output_test_module( struct makefile *make )
3247 char *testmodule = replace_extension( make->testdll, ".dll", "_test.exe" );
3248 char *stripped = replace_extension( make->testdll, ".dll", "_test-stripped.exe" );
3249 char *testres = replace_extension( make->testdll, ".dll", "_test.res" );
3250 struct strarray dep_libs = empty_strarray;
3251 struct strarray all_libs = add_import_libs( make, &dep_libs, make->imports, 0 );
3252 int parent_disabled = 0;
3254 add_import_libs( make, &dep_libs, get_default_imports( make ), 0 ); /* dependencies only */
3255 strarray_addall( &all_libs, libs );
3256 strarray_add( &make->all_targets, strmake( "%s%s", testmodule, dll_ext ));
3257 strarray_add( &make->clean_files, strmake( "%s%s", stripped, dll_ext ));
3258 output( "%s%s:\n", obj_dir_path( make, testmodule ), dll_ext );
3259 output( "\t%s -o $@", tools_path( make, "winegcc" ));
3260 output_filename( strmake( "-B%s", tools_dir_path( make, "winebuild" )));
3261 if (tools_dir) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make, "" )));
3262 output_filenames( target_flags );
3263 output_filenames( unwind_flags );
3264 output_filenames( make->appmode );
3265 output_filenames_obj_dir( make, make->object_files );
3266 output_filenames( all_libs );
3267 output_filename( "$(LDFLAGS)" );
3268 output( "\n" );
3269 output( "%s%s:\n", obj_dir_path( make, stripped ), dll_ext );
3270 output( "\t%s -s -o $@", tools_path( make, "winegcc" ));
3271 output_filename( strmake( "-B%s", tools_dir_path( make, "winebuild" )));
3272 if (tools_dir) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make, "" )));
3273 output_filenames( target_flags );
3274 output_filenames( unwind_flags );
3275 output_filename( strmake( "-Wb,-F,%s", testmodule ));
3276 output_filenames( make->appmode );
3277 output_filenames_obj_dir( make, make->object_files );
3278 output_filenames( all_libs );
3279 output_filename( "$(LDFLAGS)" );
3280 output( "\n" );
3281 output( "%s%s %s%s:", obj_dir_path( make, testmodule ), dll_ext,
3282 obj_dir_path( make, stripped ), dll_ext );
3283 output_filenames_obj_dir( make, make->object_files );
3284 output_filenames( dep_libs );
3285 output_filename( tools_path( make, "winebuild" ));
3286 output_filename( tools_path( make, "winegcc" ));
3287 output( "\n" );
3289 if (!make->disabled && !strarray_exists( &disabled_dirs, "programs/winetest" ))
3290 output( "all: %s/%s\n", top_obj_dir_path( make, "programs/winetest" ), testres );
3291 output( "%s/%s: %s%s\n", top_obj_dir_path( make, "programs/winetest" ), testres,
3292 obj_dir_path( make, stripped ), dll_ext );
3293 output( "\techo \"%s TESTRES \\\"%s%s\\\"\" | %s -o $@\n",
3294 testmodule, obj_dir_path( make, stripped ), dll_ext, tools_path( make, "wrc" ));
3296 if (crosstarget)
3298 char *crosstest = replace_extension( make->testdll, ".dll", "_crosstest.exe" );
3300 dep_libs = empty_strarray;
3301 all_libs = add_import_libs( make, &dep_libs, make->imports, 1 );
3302 add_import_libs( make, &dep_libs, get_default_imports( make ), 1 ); /* dependencies only */
3303 strarray_addall( &all_libs, libs );
3304 strarray_add( &make->clean_files, crosstest );
3305 output( "%s:", obj_dir_path( make, crosstest ));
3306 output_filenames_obj_dir( make, make->crossobj_files );
3307 output_filenames( dep_libs );
3308 output_filename( tools_path( make, "winebuild" ));
3309 output_filename( tools_path( make, "winegcc" ));
3310 output( "\n" );
3311 output( "\t%s -o $@ -b %s", tools_path( make, "winegcc" ), crosstarget );
3312 output_filename( strmake( "-B%s", tools_dir_path( make, "winebuild" )));
3313 if (tools_dir) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make, "" )));
3314 output_filename( "--lib-suffix=.cross.a" );
3315 output_filenames_obj_dir( make, make->crossobj_files );
3316 output_filenames( all_libs );
3317 output_filename( "$(LDFLAGS)" );
3318 output( "\n" );
3319 if (!make->disabled)
3321 output( "%s: %s\n", obj_dir_path( make, "crosstest" ), obj_dir_path( make, crosstest ));
3322 strarray_add( &make->phony_targets, obj_dir_path( make, "crosstest" ));
3323 if (make->obj_dir) output( "crosstest: %s\n", obj_dir_path( make, "crosstest" ));
3327 if (strendswith( make->base_dir, "/tests" ))
3329 char *dir = xstrdup( make->base_dir );
3330 dir[strlen( dir ) - 6] = 0;
3331 parent_disabled = strarray_exists( &disabled_dirs, dir );
3333 output_filenames_obj_dir( make, make->ok_files );
3334 output( ": %s%s ../%s%s\n", testmodule, dll_ext, make->testdll, dll_ext );
3335 output( "check test:" );
3336 if (!make->disabled && !parent_disabled) output_filenames_obj_dir( make, make->ok_files );
3337 output( "\n" );
3338 strarray_add( &make->phony_targets, "check" );
3339 strarray_add( &make->phony_targets, "test" );
3340 output( "testclean::\n" );
3341 output( "\trm -f" );
3342 output_filenames_obj_dir( make, make->ok_files );
3343 output( "\n" );
3344 strarray_addall( &make->clean_files, make->ok_files );
3345 strarray_add( &make->phony_targets, "testclean" );
3349 /*******************************************************************
3350 * output_programs
3352 static void output_programs( struct makefile *make )
3354 unsigned int i, j;
3355 char *ldrpath_local = get_expanded_make_variable( make, "LDRPATH_LOCAL" );
3356 char *ldrpath_install = get_expanded_make_variable( make, "LDRPATH_INSTALL" );
3358 for (i = 0; i < make->programs.count; i++)
3360 char *program_installed = NULL;
3361 char *program = strmake( "%s%s", make->programs.str[i], exe_ext );
3362 struct strarray deps = get_local_dependencies( make, make->programs.str[i], make->in_files );
3363 struct strarray all_libs = get_expanded_file_local_var( make, make->programs.str[i], "LDFLAGS" );
3364 struct strarray objs = get_expanded_file_local_var( make, make->programs.str[i], "OBJS" );
3365 struct strarray symlinks = get_expanded_file_local_var( make, make->programs.str[i], "SYMLINKS" );
3367 if (!objs.count) objs = make->object_files;
3368 strarray_addall( &all_libs, add_default_libraries( make, &deps ));
3370 output( "%s:", obj_dir_path( make, program ) );
3371 output_filenames_obj_dir( make, objs );
3372 output_filenames( deps );
3373 output( "\n" );
3374 output( "\t$(CC) -o $@" );
3375 output_filenames_obj_dir( make, objs );
3377 if (strarray_exists( &all_libs, "-lwine" ))
3379 strarray_add( &all_libs, strmake( "-L%s", top_obj_dir_path( make, "libs/wine" )));
3380 if (ldrpath_local && ldrpath_install)
3382 program_installed = strmake( "%s-installed%s", make->programs.str[i], exe_ext );
3383 output_filename( ldrpath_local );
3384 output_filenames( all_libs );
3385 output_filename( "$(LDFLAGS)" );
3386 output( "\n" );
3387 output( "%s:", obj_dir_path( make, program_installed ) );
3388 output_filenames_obj_dir( make, objs );
3389 output_filenames( deps );
3390 output( "\n" );
3391 output( "\t$(CC) -o $@" );
3392 output_filenames_obj_dir( make, objs );
3393 output_filename( ldrpath_install );
3394 strarray_add( &make->all_targets, program_installed );
3398 output_filenames( all_libs );
3399 output_filename( "$(LDFLAGS)" );
3400 output( "\n" );
3401 strarray_add( &make->all_targets, program );
3403 for (j = 0; j < symlinks.count; j++)
3405 output( "%s: %s\n", obj_dir_path( make, symlinks.str[j] ), obj_dir_path( make, program ));
3406 output_symlink_rule( obj_dir_path( make, program ), obj_dir_path( make, symlinks.str[j] ));
3408 strarray_addall( &make->all_targets, symlinks );
3410 add_install_rule( make, program, program_installed ? program_installed : program,
3411 strmake( "p$(bindir)/%s", program ));
3412 for (j = 0; j < symlinks.count; j++)
3413 add_install_rule( make, symlinks.str[j], program,
3414 strmake( "y$(bindir)/%s%s", symlinks.str[j], exe_ext ));
3419 /*******************************************************************
3420 * output_subdirs
3422 static void output_subdirs( struct makefile *make )
3424 struct strarray symlinks = empty_strarray;
3425 struct strarray all_deps = empty_strarray;
3426 struct strarray build_deps = empty_strarray;
3427 struct strarray builddeps_deps = empty_strarray;
3428 struct strarray makefile_deps = empty_strarray;
3429 struct strarray clean_files = empty_strarray;
3430 struct strarray testclean_files = empty_strarray;
3431 struct strarray distclean_files = empty_strarray;
3432 struct strarray tools_deps = empty_strarray;
3433 struct strarray tooldeps_deps = empty_strarray;
3434 struct strarray winetest_deps = empty_strarray;
3435 struct strarray crosstest_deps = empty_strarray;
3436 unsigned int i, j;
3438 strarray_addall( &distclean_files, make->distclean_files );
3439 for (i = 0; i < make->subdirs.count; i++)
3441 const struct makefile *submake = make->submakes[i];
3442 char *subdir = base_dir_path( submake, "" );
3444 strarray_add( &makefile_deps, top_src_dir_path( make, base_dir_path( submake,
3445 strmake ( "%s.in", output_makefile_name ))));
3446 for (j = 0; j < submake->clean_files.count; j++)
3447 strarray_add( &clean_files, base_dir_path( submake, submake->clean_files.str[j] ));
3448 for (j = 0; j < submake->distclean_files.count; j++)
3449 strarray_add( &distclean_files, base_dir_path( submake, submake->distclean_files.str[j] ));
3450 for (j = 0; j < submake->ok_files.count; j++)
3451 strarray_add( &testclean_files, base_dir_path( submake, submake->ok_files.str[j] ));
3453 /* import libs are still created for disabled dirs, except for win16 ones */
3454 if (submake->module && submake->importlib && !(submake->disabled && submake->is_win16))
3456 char *importlib_path = base_dir_path( submake, strmake( "lib%s", submake->importlib ));
3457 if (submake->implib_objs.count)
3459 output( "%s.a: dummy\n", importlib_path );
3460 output( "\t@cd %s && $(MAKE) lib%s.a\n", subdir, submake->importlib );
3461 strarray_add( &tools_deps, strmake( "%s.a", importlib_path ));
3462 if (crosstarget)
3464 output( "%s.cross.a: dummy\n", importlib_path );
3465 output( "\t@cd %s && $(MAKE) lib%s.cross.a\n", subdir, submake->importlib );
3466 strarray_add( &tools_deps, strmake( "%s.cross.a", importlib_path ));
3469 else
3471 const char *libext = *dll_ext ? ".def" : ".a";
3472 char *spec_file = top_src_dir_path( make, base_dir_path( submake,
3473 replace_extension( submake->module, ".dll", ".spec" )));
3474 output( "%s%s: %s", importlib_path, libext, spec_file );
3475 output_filename( tools_path( make, "winebuild" ));
3476 output( "\n" );
3477 output( "\t%s -w -o $@", tools_path( make, "winebuild" ));
3478 output_filename( *dll_ext ? "--def" : "--implib" );
3479 output_filenames( target_flags );
3480 if (submake->is_win16) output_filename( "-m16" );
3481 output_filename( "--export" );
3482 output_filename( spec_file );
3483 output( "\n" );
3484 strarray_add( &build_deps, strmake( "%s%s", importlib_path, libext ));
3485 if (crosstarget && !submake->is_win16)
3487 output( "%s.cross.a: %s", importlib_path, spec_file );
3488 output_filename( tools_path( make, "winebuild" ));
3489 output( "\n" );
3490 output( "\t%s -b %s -w -o $@", tools_path( make, "winebuild" ), crosstarget );
3491 output_filename( "--implib" );
3492 output_filename( "--export" );
3493 output_filename( spec_file );
3494 output( "\n" );
3495 strarray_add( &build_deps, strmake( "%s.cross.a", importlib_path ));
3498 strarray_addall( &symlinks, output_importlib_symlinks( make, submake ));
3501 if (submake->disabled) continue;
3502 strarray_add( &all_deps, subdir );
3504 if (submake->module)
3506 if (!submake->staticlib)
3508 strarray_add( &builddeps_deps, subdir );
3509 if (!submake->appmode.count)
3511 output( "manpages htmlpages sgmlpages xmlpages::\n" );
3512 output( "\t@cd %s && $(MAKE) $@\n", subdir );
3515 else strarray_add( &tools_deps, subdir );
3517 else if (submake->testdll)
3519 output( "%s/test: dummy\n", subdir );
3520 output( "\t@cd %s && $(MAKE) test\n", subdir );
3521 strarray_add( &winetest_deps, subdir );
3522 strarray_add( &builddeps_deps, subdir );
3523 if (crosstarget)
3525 char *target = base_dir_path( submake, "crosstest" );
3526 output( "crosstest: %s\n", target );
3527 output( "%s: dummy\n", target );
3528 output( "\t@cd %s && $(MAKE) crosstest\n", subdir );
3529 strarray_add( &crosstest_deps, target );
3530 strarray_add( &builddeps_deps, target );
3533 else
3535 if (!strcmp( submake->base_dir, "tools" ) || !strncmp( submake->base_dir, "tools/", 6 ))
3537 strarray_add( &tooldeps_deps, submake->base_dir );
3538 for (j = 0; j < submake->programs.count; j++)
3539 output( "%s/%s%s: %s\n", submake->base_dir,
3540 submake->programs.str[j], tools_ext, submake->base_dir );
3542 if (submake->programs.count || submake->sharedlib)
3544 struct strarray libs = get_expanded_make_var_array( submake, "EXTRALIBS" );
3545 for (j = 0; j < submake->programs.count; j++)
3546 strarray_addall( &libs, get_expanded_file_local_var( submake,
3547 submake->programs.str[j], "LDFLAGS" ));
3548 output( "%s: libs/port", submake->base_dir );
3549 for (j = 0; j < libs.count; j++)
3551 if (!strcmp( libs.str[j], "-lwpp" )) output_filename( "libs/wpp" );
3552 if (!strcmp( libs.str[j], "-lwine" )) output_filename( "libs/wine" );
3554 output( "\n" );
3558 if (submake->install_rules[INSTALL_LIB].count)
3560 output( "install install-lib:: %s\n", submake->base_dir );
3561 output_install_commands( make, submake, submake->install_rules[INSTALL_LIB] );
3563 if (submake->install_rules[INSTALL_DEV].count)
3565 output( "install install-dev:: %s\n", submake->base_dir );
3566 output_install_commands( make, submake, submake->install_rules[INSTALL_DEV] );
3569 output( "all:" );
3570 output_filenames( all_deps );
3571 output( "\n" );
3572 output_filenames( all_deps );
3573 output( ": dummy\n" );
3574 output( "\t@cd $@ && $(MAKE)\n" );
3575 output( "Makefile:" );
3576 output_filenames( makefile_deps );
3577 output( "\n" );
3578 output_filenames( makefile_deps );
3579 output( ":\n" );
3580 if (tooldeps_deps.count)
3582 output( "__tooldeps__:" );
3583 output_filenames( tooldeps_deps );
3584 output( "\n" );
3585 strarray_add( &make->phony_targets, "__tooldeps__" );
3587 if (winetest_deps.count)
3589 output( "buildtests programs/winetest:" );
3590 output_filenames( winetest_deps );
3591 output( "\n" );
3592 output( "check test:" );
3593 for (i = 0; i < winetest_deps.count; i++)
3595 char *target = strmake( "%s/test", winetest_deps.str[i] );
3596 output_filename( target );
3597 strarray_add( &make->phony_targets, target );
3599 output( "\n" );
3600 strarray_add( &make->phony_targets, "buildtests" );
3601 strarray_add( &make->phony_targets, "check" );
3602 strarray_add( &make->phony_targets, "test" );
3604 output( "crosstest:" );
3605 output_filenames( crosstest_deps );
3606 output( "\n" );
3607 if (!crosstest_deps.count)
3608 output( "\t@echo \"crosstest is not supported (mingw not installed?)\" && false\n" );
3609 strarray_add( &make->phony_targets, "crosstest" );
3611 output( "clean::\n");
3612 output_rm_filenames( clean_files );
3613 output( "testclean::\n");
3614 output_rm_filenames( testclean_files );
3615 output( "distclean::\n");
3616 output_rm_filenames( distclean_files );
3617 output_filenames( tools_deps );
3618 output( ":" );
3619 output_filename( tools_dir_path( make, "widl" ));
3620 output_filename( tools_dir_path( make, "winebuild" ));
3621 output_filename( tools_dir_path( make, "winegcc" ));
3622 output_filename( obj_dir_path( make, "include" ));
3623 output( "\n" );
3624 output_filenames( builddeps_deps );
3625 output( ": __builddeps__\n" );
3626 strarray_add( &make->phony_targets, "distclean" );
3627 strarray_add( &make->phony_targets, "testclean" );
3628 strarray_addall( &make->phony_targets, all_deps );
3629 strarray_addall( &make->phony_targets, crosstest_deps );
3631 strarray_addall( &make->clean_files, symlinks );
3632 strarray_addall( &build_deps, tools_deps );
3633 strarray_addall( &build_deps, symlinks );
3634 if (build_deps.count)
3636 output( "__builddeps__:" );
3637 output_filenames( build_deps );
3638 output( "\n" );
3639 strarray_add( &make->phony_targets, "__builddeps__" );
3641 if (get_expanded_make_variable( make, "GETTEXTPO_LIBS" )) output_po_files( make );
3645 /*******************************************************************
3646 * output_sources
3648 static void output_sources( struct makefile *make )
3650 struct incl_file *source;
3651 unsigned int i, j;
3653 strarray_add( &make->phony_targets, "all" );
3655 LIST_FOR_EACH_ENTRY( source, &make->sources, struct incl_file, entry )
3657 char *obj = xstrdup( source->name );
3658 char *ext = get_extension( obj );
3660 if (!ext) fatal_error( "unsupported file type %s\n", source->name );
3661 *ext++ = 0;
3663 for (j = 0; output_source_funcs[j].ext; j++)
3664 if (!strcmp( ext, output_source_funcs[j].ext )) break;
3666 output_source_funcs[j].fn( make, source, obj );
3667 strarray_addall_uniq( &make->dependencies, source->dependencies );
3670 /* special case for winetest: add resource files from other test dirs */
3671 if (make->base_dir && !strcmp( make->base_dir, "programs/winetest" ))
3673 struct strarray tests = enable_tests;
3674 if (!tests.count)
3675 for (i = 0; i < top_makefile->subdirs.count; i++)
3676 if (top_makefile->submakes[i]->testdll && !top_makefile->submakes[i]->disabled)
3677 strarray_add( &tests, top_makefile->submakes[i]->testdll );
3678 for (i = 0; i < tests.count; i++)
3679 strarray_add( &make->object_files, replace_extension( tests.str[i], ".dll", "_test.res" ));
3682 if (make->dlldata_files.count)
3684 output( "%s: %s %s\n", obj_dir_path( make, "dlldata.c" ),
3685 tools_path( make, "widl" ), src_dir_path( make, "Makefile.in" ));
3686 output( "\t%s --dlldata-only -o $@", tools_path( make, "widl" ));
3687 output_filenames( make->dlldata_files );
3688 output( "\n" );
3691 if (make->staticlib) output_static_lib( make );
3692 else if (make->module) output_module( make );
3693 else if (make->testdll) output_test_module( make );
3694 else
3696 if (make->importlib) output_import_lib( make );
3697 if (make->sharedlib) output_shared_lib( make );
3698 if (make->programs.count) output_programs( make );
3701 for (i = 0; i < make->scripts.count; i++)
3702 add_install_rule( make, make->scripts.str[i], make->scripts.str[i],
3703 strmake( "S$(bindir)/%s", make->scripts.str[i] ));
3705 if (!make->src_dir) strarray_add( &make->distclean_files, ".gitignore" );
3706 strarray_add( &make->distclean_files, "Makefile" );
3707 if (make->testdll) strarray_add( &make->distclean_files, "testlist.c" );
3709 if (!make->base_dir)
3710 strarray_addall( &make->distclean_files, get_expanded_make_var_array( make, "CONFIGURE_TARGETS" ));
3711 else if (!strcmp( make->base_dir, "po" ))
3712 strarray_add( &make->distclean_files, "LINGUAS" );
3714 if (make->subdirs.count) output_subdirs( make );
3716 if (!make->disabled)
3718 if (make->all_targets.count)
3720 output( "all:" );
3721 output_filenames_obj_dir( make, make->all_targets );
3722 output( "\n" );
3724 output_install_rules( make, INSTALL_LIB, "install-lib" );
3725 output_install_rules( make, INSTALL_DEV, "install-dev" );
3726 output_uninstall_rules( make );
3729 if (make->dependencies.count)
3731 output_filenames( make->dependencies );
3732 output( ":\n" );
3735 strarray_addall( &make->clean_files, make->object_files );
3736 strarray_addall_uniq( &make->clean_files, make->crossobj_files );
3737 strarray_addall( &make->clean_files, make->all_targets );
3738 strarray_addall( &make->clean_files, get_expanded_make_var_array( make, "EXTRA_TARGETS" ));
3740 if (make->clean_files.count)
3742 output( "%s::\n", obj_dir_path( make, "clean" ));
3743 output( "\trm -f" );
3744 output_filenames_obj_dir( make, make->clean_files );
3745 output( "\n" );
3746 if (make->obj_dir) output( "__clean__: %s\n", obj_dir_path( make, "clean" ));
3747 strarray_add( &make->phony_targets, obj_dir_path( make, "clean" ));
3750 if (make->phony_targets.count)
3752 output( ".PHONY:" );
3753 output_filenames( make->phony_targets );
3754 output( "\n" );
3759 /*******************************************************************
3760 * create_temp_file
3762 static FILE *create_temp_file( const char *orig )
3764 char *name = xmalloc( strlen(orig) + 13 );
3765 unsigned int i, id = getpid();
3766 int fd;
3767 FILE *ret = NULL;
3769 for (i = 0; i < 100; i++)
3771 sprintf( name, "%s.tmp%08x", orig, id );
3772 if ((fd = open( name, O_RDWR | O_CREAT | O_EXCL, 0666 )) != -1)
3774 ret = fdopen( fd, "w" );
3775 break;
3777 if (errno != EEXIST) break;
3778 id += 7777;
3780 if (!ret) fatal_error( "failed to create output file for '%s'\n", orig );
3781 temp_file_name = name;
3782 return ret;
3786 /*******************************************************************
3787 * rename_temp_file
3789 static void rename_temp_file( const char *dest )
3791 int ret = rename( temp_file_name, dest );
3792 if (ret == -1 && errno == EEXIST)
3794 /* rename doesn't overwrite on windows */
3795 unlink( dest );
3796 ret = rename( temp_file_name, dest );
3798 if (ret == -1) fatal_error( "failed to rename output file to '%s'\n", dest );
3799 temp_file_name = NULL;
3803 /*******************************************************************
3804 * are_files_identical
3806 static int are_files_identical( FILE *file1, FILE *file2 )
3808 for (;;)
3810 char buffer1[8192], buffer2[8192];
3811 int size1 = fread( buffer1, 1, sizeof(buffer1), file1 );
3812 int size2 = fread( buffer2, 1, sizeof(buffer2), file2 );
3813 if (size1 != size2) return 0;
3814 if (!size1) return feof( file1 ) && feof( file2 );
3815 if (memcmp( buffer1, buffer2, size1 )) return 0;
3820 /*******************************************************************
3821 * rename_temp_file_if_changed
3823 static void rename_temp_file_if_changed( const char *dest )
3825 FILE *file1, *file2;
3826 int do_rename = 1;
3828 if ((file1 = fopen( dest, "r" )))
3830 if ((file2 = fopen( temp_file_name, "r" )))
3832 do_rename = !are_files_identical( file1, file2 );
3833 fclose( file2 );
3835 fclose( file1 );
3837 if (!do_rename)
3839 unlink( temp_file_name );
3840 temp_file_name = NULL;
3842 else rename_temp_file( dest );
3846 /*******************************************************************
3847 * output_linguas
3849 static void output_linguas( const struct makefile *make )
3851 const char *dest = base_dir_path( make, "LINGUAS" );
3852 struct incl_file *source;
3854 output_file = create_temp_file( dest );
3856 output( "# Automatically generated by make depend; DO NOT EDIT!!\n" );
3857 LIST_FOR_EACH_ENTRY( source, &make->sources, struct incl_file, entry )
3858 if (strendswith( source->name, ".po" ))
3859 output( "%s\n", replace_extension( source->name, ".po", "" ));
3861 if (fclose( output_file )) fatal_perror( "write" );
3862 output_file = NULL;
3863 rename_temp_file_if_changed( dest );
3867 /*******************************************************************
3868 * output_testlist
3870 static void output_testlist( const struct makefile *make )
3872 const char *dest = base_dir_path( make, "testlist.c" );
3873 struct strarray files = empty_strarray;
3874 unsigned int i;
3876 for (i = 0; i < make->ok_files.count; i++)
3877 strarray_add( &files, replace_extension( make->ok_files.str[i], ".ok", "" ));
3879 output_file = create_temp_file( dest );
3881 output( "/* Automatically generated by make depend; DO NOT EDIT!! */\n\n" );
3882 output( "#define WIN32_LEAN_AND_MEAN\n" );
3883 output( "#include <windows.h>\n\n" );
3884 output( "#define STANDALONE\n" );
3885 output( "#include \"wine/test.h\"\n\n" );
3887 for (i = 0; i < files.count; i++) output( "extern void func_%s(void);\n", files.str[i] );
3888 output( "\n" );
3889 output( "const struct test winetest_testlist[] =\n" );
3890 output( "{\n" );
3891 for (i = 0; i < files.count; i++) output( " { \"%s\", func_%s },\n", files.str[i], files.str[i] );
3892 output( " { 0, 0 }\n" );
3893 output( "};\n" );
3895 if (fclose( output_file )) fatal_perror( "write" );
3896 output_file = NULL;
3897 rename_temp_file_if_changed( dest );
3901 /*******************************************************************
3902 * output_gitignore
3904 static void output_gitignore( const char *dest, struct strarray files )
3906 int i;
3908 output_file = create_temp_file( dest );
3910 output( "# Automatically generated by make depend; DO NOT EDIT!!\n" );
3911 for (i = 0; i < files.count; i++)
3913 if (!strchr( files.str[i], '/' )) output( "/" );
3914 output( "%s\n", files.str[i] );
3917 if (fclose( output_file )) fatal_perror( "write" );
3918 output_file = NULL;
3919 rename_temp_file( dest );
3923 /*******************************************************************
3924 * output_top_variables
3926 static void output_top_variables( const struct makefile *make )
3928 unsigned int i;
3929 struct strarray *vars = &top_makefile->vars;
3931 if (!make->base_dir) return; /* don't output variables in the top makefile */
3933 output( "# Automatically generated by make depend; DO NOT EDIT!!\n\n" );
3934 output( "all:\n\n" );
3935 for (i = 0; i < vars->count; i += 2)
3937 if (!strcmp( vars->str[i], "SUBDIRS" )) continue; /* not inherited */
3938 output( "%s = %s\n", vars->str[i], get_make_variable( make, vars->str[i] ));
3940 output( "\n" );
3944 /*******************************************************************
3945 * output_dependencies
3947 static void output_dependencies( struct makefile *make )
3949 struct strarray ignore_files = empty_strarray;
3950 char buffer[1024];
3951 FILE *src_file;
3952 int found = 0;
3954 if (make->base_dir) create_dir( make->base_dir );
3956 output_file_name = base_dir_path( make, output_makefile_name );
3957 output_file = create_temp_file( output_file_name );
3958 output_top_variables( make );
3960 /* copy the contents of the source makefile */
3961 src_file = open_input_makefile( make );
3962 while (fgets( buffer, sizeof(buffer), src_file ) && !found)
3964 if (fwrite( buffer, 1, strlen(buffer), output_file ) != strlen(buffer)) fatal_perror( "write" );
3965 found = !strncmp( buffer, separator, strlen(separator) );
3967 if (fclose( src_file )) fatal_perror( "close" );
3968 input_file_name = NULL;
3970 if (!found) output( "\n%s (everything below this line is auto-generated; DO NOT EDIT!!)\n", separator );
3971 output_sources( make );
3973 fclose( output_file );
3974 output_file = NULL;
3975 rename_temp_file( output_file_name );
3977 strarray_addall( &ignore_files, make->distclean_files );
3978 strarray_addall( &ignore_files, make->clean_files );
3979 if (make->testdll) output_testlist( make );
3980 if (make->base_dir && !strcmp( make->base_dir, "po" )) output_linguas( make );
3981 if (!make->src_dir) output_gitignore( base_dir_path( make, ".gitignore" ), ignore_files );
3983 create_file_directories( make, ignore_files );
3985 output_file_name = NULL;
3989 /*******************************************************************
3990 * load_sources
3992 static void load_sources( struct makefile *make )
3994 static const char *source_vars[] =
3996 "SOURCES",
3997 "C_SRCS",
3998 "OBJC_SRCS",
3999 "RC_SRCS",
4000 "MC_SRCS",
4001 "IDL_SRCS",
4002 "BISON_SRCS",
4003 "LEX_SRCS",
4004 "HEADER_SRCS",
4005 "XTEMPLATE_SRCS",
4006 "SVG_SRCS",
4007 "FONT_SRCS",
4008 "IN_SRCS",
4009 "PO_SRCS",
4010 "MANPAGES",
4011 NULL
4013 const char **var;
4014 unsigned int i;
4015 struct strarray value;
4016 struct incl_file *file;
4018 if (root_src_dir)
4020 make->top_src_dir = concat_paths( make->top_obj_dir, root_src_dir );
4021 make->src_dir = concat_paths( make->top_src_dir, make->base_dir );
4023 strarray_set_value( &make->vars, "top_builddir", top_obj_dir_path( make, "" ));
4024 strarray_set_value( &make->vars, "top_srcdir", top_src_dir_path( make, "" ));
4025 strarray_set_value( &make->vars, "srcdir", src_dir_path( make, "" ));
4027 make->parent_dir = get_expanded_make_variable( make, "PARENTSRC" );
4028 make->module = get_expanded_make_variable( make, "MODULE" );
4029 make->testdll = get_expanded_make_variable( make, "TESTDLL" );
4030 make->sharedlib = get_expanded_make_variable( make, "SHAREDLIB" );
4031 make->staticlib = get_expanded_make_variable( make, "STATICLIB" );
4032 make->importlib = get_expanded_make_variable( make, "IMPORTLIB" );
4034 make->programs = get_expanded_make_var_array( make, "PROGRAMS" );
4035 make->scripts = get_expanded_make_var_array( make, "SCRIPTS" );
4036 make->appmode = get_expanded_make_var_array( make, "APPMODE" );
4037 make->imports = get_expanded_make_var_array( make, "IMPORTS" );
4038 make->delayimports = get_expanded_make_var_array( make, "DELAYIMPORTS" );
4039 make->extradllflags = get_expanded_make_var_array( make, "EXTRADLLFLAGS" );
4040 make->install_lib = get_expanded_make_var_array( make, "INSTALL_LIB" );
4041 make->install_dev = get_expanded_make_var_array( make, "INSTALL_DEV" );
4043 if (make->module && strendswith( make->module, ".a" )) make->staticlib = make->module;
4045 make->disabled = make->base_dir && strarray_exists( &disabled_dirs, make->base_dir );
4046 make->is_win16 = strarray_exists( &make->extradllflags, "-m16" ) || strarray_exists( &make->appmode, "-m16" );
4047 make->use_msvcrt = strarray_exists( &make->appmode, "-mno-cygwin" );
4049 for (i = 0; i < make->imports.count && !make->use_msvcrt; i++)
4050 make->use_msvcrt = !strncmp( make->imports.str[i], "msvcr", 5 ) ||
4051 !strcmp( make->imports.str[i], "ucrtbase" );
4053 if (make->module && !make->install_lib.count && !make->install_dev.count)
4055 if (make->importlib) strarray_add( &make->install_dev, make->importlib );
4056 if (make->staticlib) strarray_add( &make->install_dev, make->staticlib );
4057 else strarray_add( &make->install_lib, make->module );
4060 make->include_paths = empty_strarray;
4061 make->include_args = empty_strarray;
4062 make->define_args = empty_strarray;
4063 strarray_add( &make->define_args, "-D__WINESRC__" );
4065 value = get_expanded_make_var_array( make, "EXTRAINCL" );
4066 for (i = 0; i < value.count; i++)
4067 if (!strncmp( value.str[i], "-I", 2 ))
4068 strarray_add_uniq( &make->include_paths, value.str[i] + 2 );
4069 else
4070 strarray_add_uniq( &make->define_args, value.str[i] );
4071 strarray_addall( &make->define_args, get_expanded_make_var_array( make, "EXTRADEFS" ));
4073 strarray_add( &make->include_args, strmake( "-I%s", obj_dir_path( make, "" )));
4074 if (make->src_dir)
4075 strarray_add( &make->include_args, strmake( "-I%s", make->src_dir ));
4076 if (make->parent_dir)
4077 strarray_add( &make->include_args, strmake( "-I%s", src_dir_path( make, make->parent_dir )));
4078 strarray_add( &make->include_args, strmake( "-I%s", top_obj_dir_path( make, "include" )));
4079 if (make->top_src_dir)
4080 strarray_add( &make->include_args, strmake( "-I%s", top_src_dir_path( make, "include" )));
4081 if (make->use_msvcrt)
4082 strarray_add( &make->include_args, strmake( "-I%s", top_src_dir_path( make, "include/msvcrt" )));
4083 for (i = 0; i < make->include_paths.count; i++)
4084 strarray_add( &make->include_args, strmake( "-I%s", obj_dir_path( make, make->include_paths.str[i] )));
4086 list_init( &make->sources );
4087 list_init( &make->includes );
4089 for (var = source_vars; *var; var++)
4091 value = get_expanded_make_var_array( make, *var );
4092 for (i = 0; i < value.count; i++) add_src_file( make, value.str[i] );
4095 add_generated_sources( make );
4097 value = get_expanded_make_var_array( make, "EXTRA_OBJS" );
4098 for (i = 0; i < value.count; i++)
4100 /* default to .c for unknown extra object files */
4101 if (strendswith( value.str[i], ".o" ))
4102 add_generated_source( make, value.str[i], replace_extension( value.str[i], ".o", ".c" ) );
4103 else
4104 add_generated_source( make, value.str[i], NULL );
4107 LIST_FOR_EACH_ENTRY( file, &make->includes, struct incl_file, entry ) parse_file( make, file, 0 );
4108 LIST_FOR_EACH_ENTRY( file, &make->sources, struct incl_file, entry ) get_dependencies( file, file );
4112 /*******************************************************************
4113 * parse_makeflags
4115 static void parse_makeflags( const char *flags )
4117 const char *p = flags;
4118 char *var, *buffer = xmalloc( strlen(flags) + 1 );
4120 while (*p)
4122 while (isspace(*p)) p++;
4123 var = buffer;
4124 while (*p && !isspace(*p))
4126 if (*p == '\\' && p[1]) p++;
4127 *var++ = *p++;
4129 *var = 0;
4130 if (var > buffer) set_make_variable( &cmdline_vars, buffer );
4135 /*******************************************************************
4136 * parse_option
4138 static int parse_option( const char *opt )
4140 if (opt[0] != '-')
4142 if (strchr( opt, '=' )) return set_make_variable( &cmdline_vars, opt );
4143 return 0;
4145 switch(opt[1])
4147 case 'f':
4148 if (opt[2]) output_makefile_name = opt + 2;
4149 break;
4150 case 'R':
4151 relative_dir_mode = 1;
4152 break;
4153 default:
4154 fprintf( stderr, "Unknown option '%s'\n%s", opt, Usage );
4155 exit(1);
4157 return 1;
4161 /*******************************************************************
4162 * main
4164 int main( int argc, char *argv[] )
4166 const char *makeflags = getenv( "MAKEFLAGS" );
4167 int i, j;
4169 if (makeflags) parse_makeflags( makeflags );
4171 i = 1;
4172 while (i < argc)
4174 if (parse_option( argv[i] ))
4176 for (j = i; j < argc; j++) argv[j] = argv[j+1];
4177 argc--;
4179 else i++;
4182 if (relative_dir_mode)
4184 char *relpath;
4186 if (argc != 3)
4188 fprintf( stderr, "Option -R needs two directories\n%s", Usage );
4189 exit( 1 );
4191 relpath = get_relative_path( argv[1], argv[2] );
4192 printf( "%s\n", relpath ? relpath : "." );
4193 exit( 0 );
4196 atexit( cleanup_files );
4197 signal( SIGTERM, exit_on_signal );
4198 signal( SIGINT, exit_on_signal );
4199 #ifdef SIGHUP
4200 signal( SIGHUP, exit_on_signal );
4201 #endif
4203 for (i = 0; i < HASH_SIZE; i++) list_init( &files[i] );
4205 top_makefile = parse_makefile( NULL );
4207 target_flags = get_expanded_make_var_array( top_makefile, "TARGETFLAGS" );
4208 msvcrt_flags = get_expanded_make_var_array( top_makefile, "MSVCRTFLAGS" );
4209 dll_flags = get_expanded_make_var_array( top_makefile, "DLLFLAGS" );
4210 extra_cflags = get_expanded_make_var_array( top_makefile, "EXTRACFLAGS" );
4211 cpp_flags = get_expanded_make_var_array( top_makefile, "CPPFLAGS" );
4212 unwind_flags = get_expanded_make_var_array( top_makefile, "UNWINDFLAGS" );
4213 widl_flags = get_expanded_make_var_array( top_makefile, "WIDLFLAGS" );
4214 libs = get_expanded_make_var_array( top_makefile, "LIBS" );
4215 enable_tests = get_expanded_make_var_array( top_makefile, "ENABLE_TESTS" );
4217 root_src_dir = get_expanded_make_variable( top_makefile, "srcdir" );
4218 tools_dir = get_expanded_make_variable( top_makefile, "TOOLSDIR" );
4219 tools_ext = get_expanded_make_variable( top_makefile, "TOOLSEXT" );
4220 exe_ext = get_expanded_make_variable( top_makefile, "EXEEXT" );
4221 man_ext = get_expanded_make_variable( top_makefile, "api_manext" );
4222 dll_ext = (exe_ext && !strcmp( exe_ext, ".exe" )) ? "" : ".so";
4223 crosstarget = get_expanded_make_variable( top_makefile, "CROSSTARGET" );
4224 fontforge = get_expanded_make_variable( top_makefile, "FONTFORGE" );
4225 convert = get_expanded_make_variable( top_makefile, "CONVERT" );
4226 rsvg = get_expanded_make_variable( top_makefile, "RSVG" );
4227 icotool = get_expanded_make_variable( top_makefile, "ICOTOOL" );
4228 dlltool = get_expanded_make_variable( top_makefile, "DLLTOOL" );
4229 msgfmt = get_expanded_make_variable( top_makefile, "MSGFMT" );
4230 ln_s = get_expanded_make_variable( top_makefile, "LN_S" );
4232 if (root_src_dir && !strcmp( root_src_dir, "." )) root_src_dir = NULL;
4233 if (tools_dir && !strcmp( tools_dir, "." )) tools_dir = NULL;
4234 if (!exe_ext) exe_ext = "";
4235 if (!tools_ext) tools_ext = "";
4236 if (!man_ext) man_ext = "3w";
4238 if (argc == 1)
4240 disabled_dirs = get_expanded_make_var_array( top_makefile, "DISABLED_SUBDIRS" );
4241 top_makefile->subdirs = get_expanded_make_var_array( top_makefile, "SUBDIRS" );
4242 top_makefile->submakes = xmalloc( top_makefile->subdirs.count * sizeof(*top_makefile->submakes) );
4244 for (i = 0; i < top_makefile->subdirs.count; i++)
4245 top_makefile->submakes[i] = parse_makefile( top_makefile->subdirs.str[i] );
4247 load_sources( top_makefile );
4248 for (i = 0; i < top_makefile->subdirs.count; i++)
4249 load_sources( top_makefile->submakes[i] );
4251 for (i = 0; i < top_makefile->subdirs.count; i++)
4252 output_dependencies( top_makefile->submakes[i] );
4254 output_dependencies( top_makefile );
4255 return 0;
4258 for (i = 1; i < argc; i++)
4260 struct makefile *make = parse_makefile( argv[i] );
4261 load_sources( make );
4262 output_dependencies( make );
4264 return 0;