2 * Generate include file dependencies
4 * Copyright 1996, 2013, 2020 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
32 #include <sys/types.h>
36 #include "wine/list.h"
40 INCL_NORMAL
, /* #include "foo.h" */
41 INCL_SYSTEM
, /* #include <foo.h> */
42 INCL_IMPORT
, /* idl import "foo.idl" */
43 INCL_IMPORTLIB
, /* idl importlib "foo.tlb" */
44 INCL_CPP_QUOTE
, /* idl cpp_quote("#include \"foo.h\"") */
45 INCL_CPP_QUOTE_SYSTEM
/* idl cpp_quote("#include <foo.h>") */
50 int line
; /* source line where this header is included */
51 enum incl_type type
; /* type of include */
52 char *name
; /* header name */
58 char *name
; /* full file name relative to cwd */
59 void *args
; /* custom arguments for makefile rule */
60 unsigned int flags
; /* flags (see below) */
61 unsigned int deps_count
; /* files in use */
62 unsigned int deps_size
; /* total allocated size */
63 struct dependency
*deps
; /* all header dependencies */
72 char *basename
; /* base target name for generated files */
73 char *sourcename
; /* source file name for generated headers */
74 struct incl_file
*included_by
; /* file that included this one */
75 int included_line
; /* line where this file was included */
76 enum incl_type type
; /* type of include */
77 int use_msvcrt
:1; /* put msvcrt headers in the search path? */
78 int is_external
:1; /* file from external library? */
79 struct incl_file
*owner
;
80 unsigned int files_count
; /* files in use */
81 unsigned int files_size
; /* total allocated size */
82 struct incl_file
**files
;
83 struct strarray dependencies
; /* file dependencies */
84 struct strarray importlibdeps
; /* importlib dependencies */
87 #define FLAG_GENERATED 0x000001 /* generated file */
88 #define FLAG_INSTALL 0x000002 /* file to install */
89 #define FLAG_IDL_PROXY 0x000100 /* generates a proxy (_p.c) file */
90 #define FLAG_IDL_CLIENT 0x000200 /* generates a client (_c.c) file */
91 #define FLAG_IDL_SERVER 0x000400 /* generates a server (_s.c) file */
92 #define FLAG_IDL_IDENT 0x000800 /* generates an ident (_i.c) file */
93 #define FLAG_IDL_REGISTER 0x001000 /* generates a registration (_r.res) file */
94 #define FLAG_IDL_TYPELIB 0x002000 /* generates a typelib (_l.res) file */
95 #define FLAG_IDL_REGTYPELIB 0x004000 /* generates a registered typelib (_t.res) file */
96 #define FLAG_IDL_HEADER 0x008000 /* generates a header (.h) file */
97 #define FLAG_RC_PO 0x010000 /* rc file contains translations */
98 #define FLAG_C_IMPLIB 0x020000 /* file is part of an import library */
99 #define FLAG_C_UNIX 0x040000 /* file is part of a Unix library */
100 #define FLAG_SFD_FONTS 0x080000 /* sfd file generated bitmap fonts */
108 { FLAG_IDL_TYPELIB
, "_l.res" },
109 { FLAG_IDL_REGTYPELIB
, "_t.res" },
110 { FLAG_IDL_CLIENT
, "_c.c" },
111 { FLAG_IDL_IDENT
, "_i.c" },
112 { FLAG_IDL_PROXY
, "_p.c" },
113 { FLAG_IDL_SERVER
, "_s.c" },
114 { FLAG_IDL_REGISTER
, "_r.res" },
115 { FLAG_IDL_HEADER
, ".h" }
118 #define HASH_SIZE 997
120 static struct list files
[HASH_SIZE
];
122 enum install_rules
{ INSTALL_LIB
, INSTALL_DEV
, NB_INSTALL_RULES
};
124 /* variables common to all makefiles */
125 static struct strarray linguas
;
126 static struct strarray dll_flags
;
127 static struct strarray unix_dllflags
;
128 static struct strarray target_flags
;
129 static struct strarray msvcrt_flags
;
130 static struct strarray extra_cflags
;
131 static struct strarray extra_cross_cflags
;
132 static struct strarray extra_cflags_extlib
;
133 static struct strarray extra_cross_cflags_extlib
;
134 static struct strarray cpp_flags
;
135 static struct strarray lddll_flags
;
136 static struct strarray libs
;
137 static struct strarray enable_tests
;
138 static struct strarray cmdline_vars
;
139 static struct strarray subdirs
;
140 static struct strarray disabled_dirs
;
141 static struct strarray delay_import_libs
;
142 static struct strarray top_install_lib
;
143 static struct strarray top_install_dev
;
144 static const char *root_src_dir
;
145 static const char *tools_dir
;
146 static const char *tools_ext
;
147 static const char *exe_ext
;
148 static const char *dll_ext
;
149 static const char *host_cpu
;
150 static const char *pe_dir
;
151 static const char *so_dir
;
152 static const char *crosstarget
;
153 static const char *crossdebug
;
154 static const char *fontforge
;
155 static const char *convert
;
156 static const char *flex
;
157 static const char *bison
;
158 static const char *ar
;
159 static const char *ranlib
;
160 static const char *rsvg
;
161 static const char *icotool
;
162 static const char *dlltool
;
163 static const char *msgfmt
;
164 static const char *ln_s
;
165 static const char *sed_cmd
;
166 static const char *delay_load_flag
;
170 /* values determined from input makefile */
171 struct strarray vars
;
172 struct strarray include_paths
;
173 struct strarray include_args
;
174 struct strarray define_args
;
175 struct strarray programs
;
176 struct strarray scripts
;
177 struct strarray imports
;
178 struct strarray delayimports
;
179 struct strarray extradllflags
;
180 struct strarray install_lib
;
181 struct strarray install_dev
;
182 struct strarray extra_targets
;
183 struct strarray extra_imports
;
185 struct list includes
;
188 const char *parent_dir
;
192 const char *sharedlib
;
193 const char *staticlib
;
194 const char *staticimplib
;
195 const char *importlib
;
205 /* values generated at output time */
206 struct strarray in_files
;
207 struct strarray ok_files
;
208 struct strarray pot_files
;
209 struct strarray test_files
;
210 struct strarray clean_files
;
211 struct strarray distclean_files
;
212 struct strarray maintainerclean_files
;
213 struct strarray uninstall_files
;
214 struct strarray object_files
;
215 struct strarray crossobj_files
;
216 struct strarray unixobj_files
;
217 struct strarray res_files
;
218 struct strarray font_files
;
219 struct strarray debug_files
;
220 struct strarray dlldata_files
;
221 struct strarray implib_files
;
222 struct strarray crossimplib_files
;
223 struct strarray all_targets
;
224 struct strarray phony_targets
;
225 struct strarray dependencies
;
226 struct strarray install_rules
[NB_INSTALL_RULES
];
229 static struct makefile
*top_makefile
;
230 static struct makefile
**submakes
;
232 static const char separator
[] = "### Dependencies";
233 static const char *output_makefile_name
= "Makefile";
234 static const char *input_file_name
;
235 static const char *output_file_name
;
236 static const char *temp_file_name
;
237 static int relative_dir_mode
;
238 static int silent_rules
;
239 static int input_line
;
240 static int output_column
;
241 static FILE *output_file
;
243 static const char Usage
[] =
244 "Usage: makedep [options] [directories]\n"
246 " -R from to Compute the relative path between two directories\n"
247 " -S Generate Automake-style silent rules\n"
248 " -fxxx Store output in file 'xxx' (default: Makefile)\n";
251 static void fatal_error( const char *msg
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
252 static void fatal_perror( const char *msg
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
253 static void output( const char *format
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
254 static char *strmake( const char* fmt
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
256 /*******************************************************************
259 static void fatal_error( const char *msg
, ... )
262 va_start( valist
, msg
);
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
);
276 /*******************************************************************
279 static void fatal_perror( const char *msg
, ... )
282 va_start( valist
, msg
);
285 fprintf( stderr
, "%s:", input_file_name
);
286 if (input_line
) fprintf( stderr
, "%d:", input_line
);
287 fprintf( stderr
, " error: " );
289 else fprintf( stderr
, "makedep: error: " );
290 vfprintf( stderr
, msg
, valist
);
297 /*******************************************************************
300 static void cleanup_files(void)
302 if (temp_file_name
) unlink( temp_file_name
);
303 if (output_file_name
) unlink( output_file_name
);
307 /*******************************************************************
310 static void exit_on_signal( int sig
)
312 exit( 1 ); /* this will call the atexit functions */
316 /*******************************************************************
319 static void output( const char *format
, ... )
324 va_start( valist
, format
);
325 ret
= vfprintf( output_file
, format
, valist
);
327 if (ret
< 0) fatal_perror( "output" );
328 if (format
[0] && format
[strlen(format
) - 1] == '\n') output_column
= 0;
329 else output_column
+= ret
;
333 /*******************************************************************
336 * Find a value in a name/value pair string array.
338 static const char *strarray_get_value( const struct strarray
*array
, const char *name
)
340 int pos
, res
, min
= 0, max
= array
->count
/ 2 - 1;
344 pos
= (min
+ max
) / 2;
345 if (!(res
= strcmp( array
->str
[pos
* 2], name
))) return array
->str
[pos
* 2 + 1];
346 if (res
< 0) min
= pos
+ 1;
353 /*******************************************************************
356 * Define a value in a name/value pair string array.
358 static void strarray_set_value( struct strarray
*array
, const char *name
, const char *value
)
360 int i
, pos
, res
, min
= 0, max
= array
->count
/ 2 - 1;
364 pos
= (min
+ max
) / 2;
365 if (!(res
= strcmp( array
->str
[pos
* 2], name
)))
367 /* redefining a variable replaces the previous value */
368 array
->str
[pos
* 2 + 1] = value
;
371 if (res
< 0) min
= pos
+ 1;
374 strarray_add( array
, NULL
);
375 strarray_add( array
, NULL
);
376 for (i
= array
->count
- 1; i
> min
* 2 + 1; i
--) array
->str
[i
] = array
->str
[i
- 2];
377 array
->str
[min
* 2] = name
;
378 array
->str
[min
* 2 + 1] = value
;
382 /*******************************************************************
385 static const char *normalize_arch( const char *arch
)
389 static const char *map
[][8] =
391 /* normalized aliases */
392 { "i386", "i486", "i586", "i686", "ia32" },
393 { "x86_64", "amd64", "x86-64", "x86_amd64", "x64" },
394 { "aarch64", "arm64" },
398 for (i
= 0; i
< sizeof(map
) / sizeof(map
[0]); i
++)
399 for (j
= 0; map
[i
][j
]; j
++)
400 if (!strncmp( arch
, map
[i
][j
], strlen(map
[i
][j
]) ))
406 /*******************************************************************
409 static void output_filename( const char *name
)
411 if (output_column
+ strlen(name
) + 1 > 100)
416 else if (output_column
) output( " " );
417 output( "%s", name
);
421 /*******************************************************************
424 static void output_filenames( struct strarray array
)
428 for (i
= 0; i
< array
.count
; i
++) output_filename( array
.str
[i
] );
432 /*******************************************************************
433 * output_rm_filenames
435 static void output_rm_filenames( struct strarray array
)
437 static const unsigned int max_cmdline
= 30000; /* to be on the safe side */
440 if (!array
.count
) return;
442 for (i
= len
= 0; i
< array
.count
; i
++)
444 if (len
> max_cmdline
)
450 output_filename( array
.str
[i
] );
451 len
+= strlen( array
.str
[i
] ) + 1;
457 /*******************************************************************
460 static char *get_extension( char *filename
)
462 char *ext
= strrchr( filename
, '.' );
463 if (ext
&& strchr( ext
, '/' )) ext
= NULL
;
468 /*******************************************************************
471 static const char *get_base_name( const char *name
)
474 if (!strchr( name
, '.' )) return name
;
475 base
= xstrdup( name
);
476 *strrchr( base
, '.' ) = 0;
481 /*******************************************************************
484 static char *replace_filename( const char *path
, const char *name
)
490 if (!path
) return xstrdup( name
);
491 if (!(p
= strrchr( path
, '/' ))) return xstrdup( name
);
493 ret
= xmalloc( len
+ strlen( name
) + 1 );
494 memcpy( ret
, path
, len
);
495 strcpy( ret
+ len
, name
);
500 /*******************************************************************
503 static char *replace_substr( const char *str
, const char *start
, size_t len
, const char *replace
)
505 size_t pos
= start
- str
;
506 char *ret
= xmalloc( pos
+ strlen(replace
) + strlen(start
+ len
) + 1 );
507 memcpy( ret
, str
, pos
);
508 strcpy( ret
+ pos
, replace
);
509 strcat( ret
+ pos
, start
+ len
);
514 /*******************************************************************
517 * Determine where the destination path is located relative to the 'from' path.
519 static char *get_relative_path( const char *from
, const char *dest
)
523 unsigned int dotdots
= 0;
525 /* a path of "." is equivalent to an empty path */
526 if (!strcmp( from
, "." )) from
= "";
530 while (*from
== '/') from
++;
531 while (*dest
== '/') dest
++;
532 start
= dest
; /* save start of next path element */
535 while (*from
&& *from
!= '/' && *from
== *dest
) { from
++; dest
++; }
536 if ((!*from
|| *from
== '/') && (!*dest
|| *dest
== '/')) continue;
538 /* count remaining elements in 'from' */
542 while (*from
&& *from
!= '/') from
++;
543 while (*from
== '/') from
++;
549 if (!start
[0] && !dotdots
) return NULL
; /* empty path */
551 ret
= xmalloc( 3 * dotdots
+ strlen( start
) + 1 );
552 for (p
= ret
; dotdots
; dotdots
--, p
+= 3) memcpy( p
, "../", 3 );
554 if (start
[0]) strcpy( p
, start
);
555 else p
[-1] = 0; /* remove trailing slash */
560 /*******************************************************************
563 static char *concat_paths( const char *base
, const char *path
)
568 if (!base
|| !base
[0]) return xstrdup( path
&& path
[0] ? path
: "." );
569 if (!path
|| !path
[0]) return xstrdup( base
);
570 if (path
[0] == '/') return xstrdup( path
);
572 len
= strlen( base
);
573 while (len
&& base
[len
- 1] == '/') len
--;
574 while (len
&& !strncmp( path
, "..", 2 ) && (!path
[2] || path
[2] == '/'))
576 for (i
= len
; i
> 0; i
--) if (base
[i
- 1] == '/') break;
577 if (i
== len
- 2 && !memcmp( base
+ i
, "..", 2 )) break; /* we can't go up if we already have ".." */
578 if (i
!= len
- 1 || base
[i
] != '.')
581 while (*path
== '/') path
++;
583 /* else ignore "." element */
584 while (i
> 0 && base
[i
- 1] == '/') i
--;
587 if (!len
&& base
[0] != '/') return xstrdup( path
[0] ? path
: "." );
588 ret
= xmalloc( len
+ strlen( path
) + 2 );
589 memcpy( ret
, base
, len
);
591 strcpy( ret
+ len
, path
);
596 /*******************************************************************
599 static char *obj_dir_path( const struct makefile
*make
, const char *path
)
601 return concat_paths( make
->obj_dir
, path
);
605 /*******************************************************************
608 static char *src_dir_path( const struct makefile
*make
, const char *path
)
610 if (make
->src_dir
) return concat_paths( make
->src_dir
, path
);
611 return obj_dir_path( make
, path
);
615 /*******************************************************************
618 static char *root_src_dir_path( const char *path
)
620 return concat_paths( root_src_dir
, path
);
624 /*******************************************************************
627 static char *tools_dir_path( const struct makefile
*make
, const char *path
)
629 if (tools_dir
) return strmake( "%s/tools/%s", tools_dir
, path
);
630 return strmake( "tools/%s", path
);
634 /*******************************************************************
637 static char *tools_path( const struct makefile
*make
, const char *name
)
639 return strmake( "%s/%s%s", tools_dir_path( make
, name
), name
, tools_ext
);
643 /*******************************************************************
644 * strarray_addall_path
646 static void strarray_addall_path( struct strarray
*array
, const char *dir
, struct strarray added
)
650 for (i
= 0; i
< added
.count
; i
++) strarray_add( array
, concat_paths( dir
, added
.str
[i
] ));
654 /*******************************************************************
657 static char *get_line( FILE *file
)
665 buffer
= xmalloc( size
);
667 if (!fgets( buffer
, size
, file
)) return NULL
;
672 char *p
= buffer
+ strlen(buffer
);
673 /* if line is larger than buffer, resize buffer */
674 while (p
== buffer
+ size
- 1 && p
[-1] != '\n')
676 buffer
= xrealloc( buffer
, size
* 2 );
677 if (!fgets( buffer
+ size
- 1, size
+ 1, file
)) break;
678 p
= buffer
+ strlen(buffer
);
681 if (p
> buffer
&& p
[-1] == '\n')
684 if (p
> buffer
&& p
[-1] == '\r') *(--p
) = 0;
685 if (p
> buffer
&& p
[-1] == '\\')
688 /* line ends in backslash, read continuation line */
689 if (!fgets( p
, size
- (p
- buffer
), file
)) return buffer
;
699 /*******************************************************************
702 static unsigned int hash_filename( const char *name
)
705 unsigned int ret
= 2166136261u;
706 while (*name
) ret
= (ret
* 16777619) ^ *name
++;
707 return ret
% HASH_SIZE
;
711 /*******************************************************************
714 static struct file
*add_file( const char *name
)
716 struct file
*file
= xmalloc( sizeof(*file
) );
717 memset( file
, 0, sizeof(*file
) );
718 file
->name
= xstrdup( name
);
723 /*******************************************************************
726 static void add_dependency( struct file
*file
, const char *name
, enum incl_type type
)
728 if (file
->deps_count
>= file
->deps_size
)
730 file
->deps_size
*= 2;
731 if (file
->deps_size
< 16) file
->deps_size
= 16;
732 file
->deps
= xrealloc( file
->deps
, file
->deps_size
* sizeof(*file
->deps
) );
734 file
->deps
[file
->deps_count
].line
= input_line
;
735 file
->deps
[file
->deps_count
].type
= type
;
736 file
->deps
[file
->deps_count
].name
= xstrdup( name
);
741 /*******************************************************************
744 static struct incl_file
*find_src_file( const struct makefile
*make
, const char *name
)
746 struct incl_file
*file
;
748 LIST_FOR_EACH_ENTRY( file
, &make
->sources
, struct incl_file
, entry
)
749 if (!strcmp( name
, file
->name
)) return file
;
753 /*******************************************************************
756 static struct incl_file
*find_include_file( const struct makefile
*make
, const char *name
)
758 struct incl_file
*file
;
760 LIST_FOR_EACH_ENTRY( file
, &make
->includes
, struct incl_file
, entry
)
762 const char *filename
= file
->filename
;
763 if (!filename
) continue;
764 if (make
->obj_dir
&& strlen(make
->obj_dir
) < strlen(filename
))
766 filename
+= strlen(make
->obj_dir
);
767 while (*filename
== '/') filename
++;
769 if (!strcmp( name
, filename
)) return file
;
774 /*******************************************************************
777 * Add an include file if it doesn't already exists.
779 static struct incl_file
*add_include( struct makefile
*make
, struct incl_file
*parent
,
780 const char *name
, int line
, enum incl_type type
)
782 struct incl_file
*include
;
784 if (parent
->files_count
>= parent
->files_size
)
786 parent
->files_size
*= 2;
787 if (parent
->files_size
< 16) parent
->files_size
= 16;
788 parent
->files
= xrealloc( parent
->files
, parent
->files_size
* sizeof(*parent
->files
) );
791 LIST_FOR_EACH_ENTRY( include
, &make
->includes
, struct incl_file
, entry
)
792 if (!parent
->use_msvcrt
== !include
->use_msvcrt
&& !strcmp( name
, include
->name
))
795 include
= xmalloc( sizeof(*include
) );
796 memset( include
, 0, sizeof(*include
) );
797 include
->name
= xstrdup(name
);
798 include
->included_by
= parent
;
799 include
->included_line
= line
;
800 include
->type
= type
;
801 include
->use_msvcrt
= parent
->use_msvcrt
;
802 list_add_tail( &make
->includes
, &include
->entry
);
804 parent
->files
[parent
->files_count
++] = include
;
809 /*******************************************************************
810 * add_generated_source
812 * Add a generated source file to the list.
814 static struct incl_file
*add_generated_source( struct makefile
*make
,
815 const char *name
, const char *filename
)
817 struct incl_file
*file
;
819 if ((file
= find_src_file( make
, name
))) return file
; /* we already have it */
820 file
= xmalloc( sizeof(*file
) );
821 memset( file
, 0, sizeof(*file
) );
822 file
->file
= add_file( name
);
823 file
->name
= xstrdup( name
);
824 file
->basename
= xstrdup( filename
? filename
: name
);
825 file
->filename
= obj_dir_path( make
, file
->basename
);
826 file
->file
->flags
= FLAG_GENERATED
;
827 file
->use_msvcrt
= make
->use_msvcrt
;
828 list_add_tail( &make
->sources
, &file
->entry
);
833 /*******************************************************************
834 * parse_include_directive
836 static void parse_include_directive( struct file
*source
, char *str
)
838 char quote
, *include
, *p
= str
;
840 while (*p
&& isspace(*p
)) p
++;
841 if (*p
!= '\"' && *p
!= '<' ) return;
843 if (quote
== '<') quote
= '>';
845 while (*p
&& (*p
!= quote
)) p
++;
846 if (!*p
) fatal_error( "malformed include directive '%s'\n", str
);
848 add_dependency( source
, include
, (quote
== '>') ? INCL_SYSTEM
: INCL_NORMAL
);
852 /*******************************************************************
853 * parse_pragma_directive
855 static void parse_pragma_directive( struct file
*source
, char *str
)
857 char *flag
, *p
= str
;
859 if (!isspace( *p
)) return;
860 while (*p
&& isspace(*p
)) p
++;
861 p
= strtok( p
, " \t" );
862 if (strcmp( p
, "makedep" )) return;
864 while ((flag
= strtok( NULL
, " \t" )))
866 if (!strcmp( flag
, "depend" ))
868 while ((p
= strtok( NULL
, " \t" ))) add_dependency( source
, p
, INCL_NORMAL
);
871 else if (!strcmp( flag
, "install" )) source
->flags
|= FLAG_INSTALL
;
873 if (strendswith( source
->name
, ".idl" ))
875 if (!strcmp( flag
, "header" )) source
->flags
|= FLAG_IDL_HEADER
;
876 else if (!strcmp( flag
, "proxy" )) source
->flags
|= FLAG_IDL_PROXY
;
877 else if (!strcmp( flag
, "client" )) source
->flags
|= FLAG_IDL_CLIENT
;
878 else if (!strcmp( flag
, "server" )) source
->flags
|= FLAG_IDL_SERVER
;
879 else if (!strcmp( flag
, "ident" )) source
->flags
|= FLAG_IDL_IDENT
;
880 else if (!strcmp( flag
, "typelib" )) source
->flags
|= FLAG_IDL_TYPELIB
;
881 else if (!strcmp( flag
, "register" )) source
->flags
|= FLAG_IDL_REGISTER
;
882 else if (!strcmp( flag
, "regtypelib" )) source
->flags
|= FLAG_IDL_REGTYPELIB
;
884 else if (strendswith( source
->name
, ".rc" ))
886 if (!strcmp( flag
, "po" )) source
->flags
|= FLAG_RC_PO
;
888 else if (strendswith( source
->name
, ".sfd" ))
890 if (!strcmp( flag
, "font" ))
892 struct strarray
*array
= source
->args
;
896 source
->args
= array
= xmalloc( sizeof(*array
) );
897 *array
= empty_strarray
;
898 source
->flags
|= FLAG_SFD_FONTS
;
900 strarray_add( array
, xstrdup( strtok( NULL
, "" )));
906 if (!strcmp( flag
, "implib" )) source
->flags
|= FLAG_C_IMPLIB
;
907 if (!strcmp( flag
, "unix" )) source
->flags
|= FLAG_C_UNIX
;
913 /*******************************************************************
914 * parse_cpp_directive
916 static void parse_cpp_directive( struct file
*source
, char *str
)
918 while (*str
&& isspace(*str
)) str
++;
919 if (*str
++ != '#') return;
920 while (*str
&& isspace(*str
)) str
++;
922 if (!strncmp( str
, "include", 7 ))
923 parse_include_directive( source
, str
+ 7 );
924 else if (!strncmp( str
, "import", 6 ) && strendswith( source
->name
, ".m" ))
925 parse_include_directive( source
, str
+ 6 );
926 else if (!strncmp( str
, "pragma", 6 ))
927 parse_pragma_directive( source
, str
+ 6 );
931 /*******************************************************************
934 static void parse_idl_file( struct file
*source
, FILE *file
)
936 char *buffer
, *include
;
940 while ((buffer
= get_line( file
)))
944 while (*p
&& isspace(*p
)) p
++;
946 if (!strncmp( p
, "importlib", 9 ))
949 while (*p
&& isspace(*p
)) p
++;
950 if (*p
++ != '(') continue;
951 while (*p
&& isspace(*p
)) p
++;
952 if (*p
++ != '"') continue;
954 while (*p
&& (*p
!= '"')) p
++;
955 if (!*p
) fatal_error( "malformed importlib directive\n" );
957 add_dependency( source
, include
, INCL_IMPORTLIB
);
961 if (!strncmp( p
, "import", 6 ))
964 while (*p
&& isspace(*p
)) p
++;
965 if (*p
!= '"') continue;
967 while (*p
&& (*p
!= '"')) p
++;
968 if (!*p
) fatal_error( "malformed import directive\n" );
970 add_dependency( source
, include
, INCL_IMPORT
);
974 /* check for #include inside cpp_quote */
975 if (!strncmp( p
, "cpp_quote", 9 ))
978 while (*p
&& isspace(*p
)) p
++;
979 if (*p
++ != '(') continue;
980 while (*p
&& isspace(*p
)) p
++;
981 if (*p
++ != '"') continue;
982 if (*p
++ != '#') continue;
983 while (*p
&& isspace(*p
)) p
++;
984 if (strncmp( p
, "include", 7 )) continue;
986 while (*p
&& isspace(*p
)) p
++;
987 if (*p
== '\\' && p
[1] == '"')
994 if (*p
++ != '<' ) continue;
998 while (*p
&& (*p
!= quote
)) p
++;
999 if (!*p
|| (quote
== '"' && p
[-1] != '\\'))
1000 fatal_error( "malformed #include directive inside cpp_quote\n" );
1001 if (quote
== '"') p
--; /* remove backslash */
1003 add_dependency( source
, include
, (quote
== '>') ? INCL_CPP_QUOTE_SYSTEM
: INCL_CPP_QUOTE
);
1007 parse_cpp_directive( source
, p
);
1011 /*******************************************************************
1014 static void parse_c_file( struct file
*source
, FILE *file
)
1019 while ((buffer
= get_line( file
)))
1021 parse_cpp_directive( source
, buffer
);
1026 /*******************************************************************
1029 static void parse_rc_file( struct file
*source
, FILE *file
)
1031 char *buffer
, *include
;
1034 while ((buffer
= get_line( file
)))
1038 while (*p
&& isspace(*p
)) p
++;
1040 if (p
[0] == '/' && p
[1] == '*') /* check for magic makedep comment */
1043 while (*p
&& isspace(*p
)) p
++;
1044 if (strncmp( p
, "@makedep:", 9 )) continue;
1046 while (*p
&& isspace(*p
)) p
++;
1051 while (*p
&& *p
!= quote
) p
++;
1056 while (*p
&& !isspace(*p
) && *p
!= '*') p
++;
1059 fatal_error( "malformed makedep comment\n" );
1061 add_dependency( source
, include
, (quote
== '>') ? INCL_SYSTEM
: INCL_NORMAL
);
1065 parse_cpp_directive( source
, buffer
);
1070 /*******************************************************************
1073 static void parse_in_file( struct file
*source
, FILE *file
)
1077 /* make sure it gets rebuilt when the version changes */
1078 add_dependency( source
, "config.h", INCL_SYSTEM
);
1080 if (!strendswith( source
->name
, ".man.in" )) return; /* not a man page */
1083 while ((buffer
= get_line( file
)))
1085 if (strncmp( buffer
, ".TH", 3 )) continue;
1086 if (!(p
= strtok( buffer
, " \t" ))) continue; /* .TH */
1087 if (!(p
= strtok( NULL
, " \t" ))) continue; /* program name */
1088 if (!(p
= strtok( NULL
, " \t" ))) continue; /* man section */
1089 source
->args
= xstrdup( p
);
1095 /*******************************************************************
1098 static void parse_sfd_file( struct file
*source
, FILE *file
)
1100 char *p
, *eol
, *buffer
;
1103 while ((buffer
= get_line( file
)))
1105 if (strncmp( buffer
, "UComments:", 10 )) continue;
1107 while (*p
== ' ') p
++;
1108 if (p
[0] == '"' && p
[1] && buffer
[strlen(buffer
) - 1] == '"')
1111 buffer
[strlen(buffer
) - 1] = 0;
1113 while ((eol
= strstr( p
, "+AAoA" )))
1116 while (*p
&& isspace(*p
)) p
++;
1119 while (*p
&& isspace(*p
)) p
++;
1120 if (!strncmp( p
, "pragma", 6 )) parse_pragma_directive( source
, p
+ 6 );
1124 while (*p
&& isspace(*p
)) p
++;
1125 if (*p
++ != '#') return;
1126 while (*p
&& isspace(*p
)) p
++;
1127 if (!strncmp( p
, "pragma", 6 )) parse_pragma_directive( source
, p
+ 6 );
1136 void (*parse
)( struct file
*file
, FILE *f
);
1137 } parse_functions
[] =
1139 { ".c", parse_c_file
},
1140 { ".h", parse_c_file
},
1141 { ".inl", parse_c_file
},
1142 { ".l", parse_c_file
},
1143 { ".m", parse_c_file
},
1144 { ".rh", parse_c_file
},
1145 { ".x", parse_c_file
},
1146 { ".y", parse_c_file
},
1147 { ".idl", parse_idl_file
},
1148 { ".rc", parse_rc_file
},
1149 { ".in", parse_in_file
},
1150 { ".sfd", parse_sfd_file
}
1153 /*******************************************************************
1156 static struct file
*load_file( const char *name
)
1160 unsigned int i
, hash
= hash_filename( name
);
1162 LIST_FOR_EACH_ENTRY( file
, &files
[hash
], struct file
, entry
)
1163 if (!strcmp( name
, file
->name
)) return file
;
1165 if (!(f
= fopen( name
, "r" ))) return NULL
;
1167 file
= add_file( name
);
1168 list_add_tail( &files
[hash
], &file
->entry
);
1169 input_file_name
= file
->name
;
1172 for (i
= 0; i
< sizeof(parse_functions
) / sizeof(parse_functions
[0]); i
++)
1174 if (!strendswith( name
, parse_functions
[i
].ext
)) continue;
1175 parse_functions
[i
].parse( file
, f
);
1180 input_file_name
= NULL
;
1186 /*******************************************************************
1187 * open_include_path_file
1189 * Open a file from a directory on the include path.
1191 static struct file
*open_include_path_file( const struct makefile
*make
, const char *dir
,
1192 const char *name
, char **filename
)
1194 char *src_path
= concat_paths( dir
, name
);
1195 struct file
*ret
= load_file( src_path
);
1197 if (ret
) *filename
= src_path
;
1202 /*******************************************************************
1203 * open_file_same_dir
1205 * Open a file in the same directory as the parent.
1207 static struct file
*open_file_same_dir( const struct incl_file
*parent
, const char *name
, char **filename
)
1209 char *src_path
= replace_filename( parent
->file
->name
, name
);
1210 struct file
*ret
= load_file( src_path
);
1212 if (ret
) *filename
= replace_filename( parent
->filename
, name
);
1217 /*******************************************************************
1218 * open_same_dir_generated_file
1220 * Open a generated_file in the same directory as the parent.
1222 static struct file
*open_same_dir_generated_file( const struct makefile
*make
,
1223 const struct incl_file
*parent
, struct incl_file
*file
,
1224 const char *ext
, const char *src_ext
)
1227 struct file
*ret
= NULL
;
1229 if (strendswith( file
->name
, ext
) &&
1230 (ret
= open_file_same_dir( parent
, replace_extension( file
->name
, ext
, src_ext
), &filename
)))
1232 file
->sourcename
= filename
;
1233 file
->filename
= obj_dir_path( make
, replace_filename( parent
->name
, file
->name
));
1239 /*******************************************************************
1242 * Open a file in the source directory of the makefile.
1244 static struct file
*open_local_file( const struct makefile
*make
, const char *path
, char **filename
)
1246 char *src_path
= src_dir_path( make
, path
);
1247 struct file
*ret
= load_file( src_path
);
1249 /* if not found, try parent dir */
1250 if (!ret
&& make
->parent_dir
)
1253 path
= strmake( "%s/%s", make
->parent_dir
, path
);
1254 src_path
= src_dir_path( make
, path
);
1255 ret
= load_file( src_path
);
1258 if (ret
) *filename
= src_path
;
1263 /*******************************************************************
1264 * open_local_generated_file
1266 * Open a generated file in the directory of the makefile.
1268 static struct file
*open_local_generated_file( const struct makefile
*make
, struct incl_file
*file
,
1269 const char *ext
, const char *src_ext
)
1272 struct file
*ret
= NULL
;
1274 if (strendswith( file
->name
, ext
) &&
1275 (ret
= open_local_file( make
, replace_extension( file
->name
, ext
, src_ext
), &filename
)))
1277 file
->sourcename
= filename
;
1278 file
->filename
= obj_dir_path( make
, file
->name
);
1284 /*******************************************************************
1287 * Open a file in the top-level source directory.
1289 static struct file
*open_global_file( const struct makefile
*make
, const char *path
, char **filename
)
1291 char *src_path
= root_src_dir_path( path
);
1292 struct file
*ret
= load_file( src_path
);
1294 if (ret
) *filename
= src_path
;
1299 /*******************************************************************
1300 * open_global_header
1302 * Open a file in the global include source directory.
1304 static struct file
*open_global_header( const struct makefile
*make
, const char *path
, char **filename
)
1306 if (!strncmp( path
, "../", 3 )) return NULL
;
1307 return open_global_file( make
, strmake( "include/%s", path
), filename
);
1311 /*******************************************************************
1312 * open_global_generated_file
1314 * Open a generated file in the top-level source directory.
1316 static struct file
*open_global_generated_file( const struct makefile
*make
, struct incl_file
*file
,
1317 const char *ext
, const char *src_ext
)
1320 struct file
*ret
= NULL
;
1322 if (strendswith( file
->name
, ext
) &&
1323 (ret
= open_global_header( make
, replace_extension( file
->name
, ext
, src_ext
), &filename
)))
1325 file
->sourcename
= filename
;
1326 file
->filename
= strmake( "include/%s", file
->name
);
1332 /*******************************************************************
1335 static struct file
*open_src_file( const struct makefile
*make
, struct incl_file
*pFile
)
1337 struct file
*file
= open_local_file( make
, pFile
->name
, &pFile
->filename
);
1339 if (!file
) fatal_perror( "open %s", pFile
->name
);
1344 /*******************************************************************
1345 * find_importlib_module
1347 static struct makefile
*find_importlib_module( const char *name
)
1349 unsigned int i
, len
;
1351 for (i
= 0; i
< subdirs
.count
; i
++)
1353 if (strncmp( submakes
[i
]->obj_dir
, "dlls/", 5 )) continue;
1354 len
= strlen(submakes
[i
]->obj_dir
);
1355 if (strncmp( submakes
[i
]->obj_dir
+ 5, name
, len
- 5 )) continue;
1356 if (!name
[len
- 5] || !strcmp( name
+ len
- 5, ".dll" )) return submakes
[i
];
1362 /*******************************************************************
1365 static struct file
*open_include_file( const struct makefile
*make
, struct incl_file
*pFile
)
1367 struct file
*file
= NULL
;
1368 unsigned int i
, len
;
1372 /* check for generated files */
1373 if ((file
= open_local_generated_file( make
, pFile
, ".tab.h", ".y" ))) return file
;
1374 if ((file
= open_local_generated_file( make
, pFile
, ".h", ".idl" ))) return file
;
1375 if (fontforge
&& (file
= open_local_generated_file( make
, pFile
, ".ttf", ".sfd" ))) return file
;
1376 if (convert
&& rsvg
&& icotool
)
1378 if ((file
= open_local_generated_file( make
, pFile
, ".bmp", ".svg" ))) return file
;
1379 if ((file
= open_local_generated_file( make
, pFile
, ".cur", ".svg" ))) return file
;
1380 if ((file
= open_local_generated_file( make
, pFile
, ".ico", ".svg" ))) return file
;
1383 /* check for extra targets */
1384 if (strarray_exists( &make
->extra_targets
, pFile
->name
))
1386 pFile
->sourcename
= src_dir_path( make
, pFile
->name
);
1387 pFile
->filename
= obj_dir_path( make
, pFile
->name
);
1391 /* now try in source dir */
1392 if ((file
= open_local_file( make
, pFile
->name
, &pFile
->filename
))) return file
;
1394 /* check for global importlib (module dependency) */
1395 if (pFile
->type
== INCL_IMPORTLIB
&& find_importlib_module( pFile
->name
))
1397 pFile
->filename
= pFile
->name
;
1401 /* check for generated files in global includes */
1402 if ((file
= open_global_generated_file( make
, pFile
, ".h", ".idl" ))) return file
;
1403 if ((file
= open_global_generated_file( make
, pFile
, ".h", ".h.in" ))) return file
;
1404 if (strendswith( pFile
->name
, "tmpl.h" ) &&
1405 (file
= open_global_generated_file( make
, pFile
, ".h", ".x" ))) return file
;
1407 /* check in global includes source dir */
1408 if ((file
= open_global_header( make
, pFile
->name
, &pFile
->filename
))) return file
;
1410 /* check in global msvcrt includes */
1411 if (pFile
->use_msvcrt
&&
1412 (file
= open_global_header( make
, strmake( "msvcrt/%s", pFile
->name
), &pFile
->filename
)))
1415 /* now search in include paths */
1416 for (i
= 0; i
< make
->include_paths
.count
; i
++)
1418 const char *dir
= make
->include_paths
.str
[i
];
1422 len
= strlen( root_src_dir
);
1423 if (!strncmp( dir
, root_src_dir
, len
) && (!dir
[len
] || dir
[len
] == '/'))
1425 while (dir
[len
] == '/') len
++;
1426 file
= open_global_file( make
, concat_paths( dir
+ len
, pFile
->name
), &pFile
->filename
);
1431 if (*dir
== '/') continue;
1432 file
= open_include_path_file( make
, dir
, pFile
->name
, &pFile
->filename
);
1434 if (!file
) continue;
1435 pFile
->is_external
= 1;
1439 if (pFile
->type
== INCL_SYSTEM
) return NULL
; /* ignore system files we cannot find */
1441 /* try in src file directory */
1442 if ((file
= open_same_dir_generated_file( make
, pFile
->included_by
, pFile
, ".tab.h", ".y" )) ||
1443 (file
= open_same_dir_generated_file( make
, pFile
->included_by
, pFile
, ".h", ".idl" )) ||
1444 (file
= open_file_same_dir( pFile
->included_by
, pFile
->name
, &pFile
->filename
)))
1446 pFile
->is_external
= pFile
->included_by
->is_external
;
1450 if (make
->extlib
) return NULL
; /* ignore missing files in external libs */
1452 fprintf( stderr
, "%s:%d: error: ", pFile
->included_by
->file
->name
, pFile
->included_line
);
1453 perror( pFile
->name
);
1454 pFile
= pFile
->included_by
;
1455 while (pFile
&& pFile
->included_by
)
1457 const char *parent
= pFile
->included_by
->sourcename
;
1458 if (!parent
) parent
= pFile
->included_by
->file
->name
;
1459 fprintf( stderr
, "%s:%d: note: %s was first included here\n",
1460 parent
, pFile
->included_line
, pFile
->name
);
1461 pFile
= pFile
->included_by
;
1467 /*******************************************************************
1470 static void add_all_includes( struct makefile
*make
, struct incl_file
*parent
, struct file
*file
)
1474 for (i
= 0; i
< file
->deps_count
; i
++)
1476 switch (file
->deps
[i
].type
)
1480 add_include( make
, parent
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_NORMAL
);
1482 case INCL_IMPORTLIB
:
1483 add_include( make
, parent
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_IMPORTLIB
);
1486 add_include( make
, parent
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_SYSTEM
);
1488 case INCL_CPP_QUOTE
:
1489 case INCL_CPP_QUOTE_SYSTEM
:
1496 /*******************************************************************
1499 static void parse_file( struct makefile
*make
, struct incl_file
*source
, int src
)
1501 struct file
*file
= src
? open_src_file( make
, source
) : open_include_file( make
, source
);
1505 source
->file
= file
;
1506 source
->files_count
= 0;
1507 source
->files_size
= file
->deps_count
;
1508 source
->files
= xmalloc( source
->files_size
* sizeof(*source
->files
) );
1509 if (file
->flags
& FLAG_C_UNIX
) source
->use_msvcrt
= 0;
1510 else if (file
->flags
& FLAG_C_IMPLIB
) source
->use_msvcrt
= 1;
1512 if (source
->sourcename
)
1514 if (strendswith( source
->sourcename
, ".idl" ))
1518 /* generated .h file always includes these */
1519 add_include( make
, source
, "rpc.h", 0, INCL_NORMAL
);
1520 add_include( make
, source
, "rpcndr.h", 0, INCL_NORMAL
);
1521 for (i
= 0; i
< file
->deps_count
; i
++)
1523 switch (file
->deps
[i
].type
)
1526 if (strendswith( file
->deps
[i
].name
, ".idl" ))
1527 add_include( make
, source
, replace_extension( file
->deps
[i
].name
, ".idl", ".h" ),
1528 file
->deps
[i
].line
, INCL_NORMAL
);
1530 add_include( make
, source
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_NORMAL
);
1532 case INCL_CPP_QUOTE
:
1533 add_include( make
, source
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_NORMAL
);
1535 case INCL_CPP_QUOTE_SYSTEM
:
1536 add_include( make
, source
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_SYSTEM
);
1540 case INCL_IMPORTLIB
:
1546 if (strendswith( source
->sourcename
, ".y" ))
1547 return; /* generated .tab.h doesn't include anything */
1550 add_all_includes( make
, source
, file
);
1554 /*******************************************************************
1557 * Add a source file to the list.
1559 static struct incl_file
*add_src_file( struct makefile
*make
, const char *name
)
1561 struct incl_file
*file
;
1563 if ((file
= find_src_file( make
, name
))) return file
; /* we already have it */
1564 file
= xmalloc( sizeof(*file
) );
1565 memset( file
, 0, sizeof(*file
) );
1566 file
->name
= xstrdup(name
);
1567 file
->use_msvcrt
= make
->use_msvcrt
;
1568 file
->is_external
= !!make
->extlib
;
1569 list_add_tail( &make
->sources
, &file
->entry
);
1570 parse_file( make
, file
, 1 );
1575 /*******************************************************************
1576 * open_input_makefile
1578 static FILE *open_input_makefile( const struct makefile
*make
)
1583 input_file_name
= root_src_dir_path( obj_dir_path( make
, "Makefile.in" ));
1585 input_file_name
= output_makefile_name
; /* always use output name for main Makefile */
1588 if (!(ret
= fopen( input_file_name
, "r" ))) fatal_perror( "open" );
1593 /*******************************************************************
1596 static const char *get_make_variable( const struct makefile
*make
, const char *name
)
1600 if ((ret
= strarray_get_value( &cmdline_vars
, name
))) return ret
;
1601 if ((ret
= strarray_get_value( &make
->vars
, name
))) return ret
;
1602 if (top_makefile
&& (ret
= strarray_get_value( &top_makefile
->vars
, name
))) return ret
;
1607 /*******************************************************************
1608 * get_expanded_make_variable
1610 static char *get_expanded_make_variable( const struct makefile
*make
, const char *name
)
1613 char *p
, *end
, *expand
, *tmp
;
1615 var
= get_make_variable( make
, name
);
1616 if (!var
) return NULL
;
1618 p
= expand
= xstrdup( var
);
1619 while ((p
= strchr( p
, '$' )))
1623 if (!(end
= strchr( p
+ 2, ')' ))) fatal_error( "syntax error in '%s'\n", expand
);
1625 if (strchr( p
+ 2, ':' )) fatal_error( "pattern replacement not supported for '%s'\n", p
+ 2 );
1626 var
= get_make_variable( make
, p
+ 2 );
1627 tmp
= replace_substr( expand
, p
, end
- p
, var
? var
: "" );
1628 /* switch to the new string */
1629 p
= tmp
+ (p
- expand
);
1633 else if (p
[1] == '{') /* don't expand ${} variables */
1635 if (!(end
= strchr( p
+ 2, '}' ))) fatal_error( "syntax error in '%s'\n", expand
);
1638 else if (p
[1] == '$')
1642 else fatal_error( "syntax error in '%s'\n", expand
);
1645 /* consider empty variables undefined */
1647 while (*p
&& isspace(*p
)) p
++;
1648 if (*p
) return expand
;
1654 /*******************************************************************
1655 * get_expanded_make_var_array
1657 static struct strarray
get_expanded_make_var_array( const struct makefile
*make
, const char *name
)
1659 struct strarray ret
= empty_strarray
;
1660 char *value
, *token
;
1662 if ((value
= get_expanded_make_variable( make
, name
)))
1663 for (token
= strtok( value
, " \t" ); token
; token
= strtok( NULL
, " \t" ))
1664 strarray_add( &ret
, token
);
1669 /*******************************************************************
1670 * get_expanded_file_local_var
1672 static struct strarray
get_expanded_file_local_var( const struct makefile
*make
, const char *file
,
1675 char *p
, *var
= strmake( "%s_%s", file
, name
);
1677 for (p
= var
; *p
; p
++) if (!isalnum( *p
)) *p
= '_';
1678 return get_expanded_make_var_array( make
, var
);
1682 /*******************************************************************
1685 static int set_make_variable( struct strarray
*array
, const char *assignment
)
1689 p
= name
= xstrdup( assignment
);
1690 while (isalnum(*p
) || *p
== '_') p
++;
1691 if (name
== p
) return 0; /* not a variable */
1695 while (isspace(*p
)) p
++;
1697 if (*p
!= '=') return 0; /* not an assignment */
1699 while (isspace(*p
)) p
++;
1701 strarray_set_value( array
, name
, p
);
1706 /*******************************************************************
1709 static struct makefile
*parse_makefile( const char *path
)
1713 struct makefile
*make
= xmalloc( sizeof(*make
) );
1715 memset( make
, 0, sizeof(*make
) );
1716 make
->obj_dir
= path
;
1717 if (root_src_dir
) make
->src_dir
= root_src_dir_path( make
->obj_dir
);
1719 file
= open_input_makefile( make
);
1720 while ((buffer
= get_line( file
)))
1722 if (!strncmp( buffer
, separator
, strlen(separator
) )) break;
1723 if (*buffer
== '\t') continue; /* command */
1724 while (isspace( *buffer
)) buffer
++;
1725 if (*buffer
== '#') continue; /* comment */
1726 set_make_variable( &make
->vars
, buffer
);
1729 input_file_name
= NULL
;
1734 /*******************************************************************
1735 * add_generated_sources
1737 static void add_generated_sources( struct makefile
*make
)
1740 struct incl_file
*source
, *next
, *file
;
1741 struct strarray objs
= get_expanded_make_var_array( make
, "EXTRA_OBJS" );
1743 LIST_FOR_EACH_ENTRY_SAFE( source
, next
, &make
->sources
, struct incl_file
, entry
)
1745 if (source
->file
->flags
& FLAG_IDL_CLIENT
)
1747 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_c.c" ), NULL
);
1748 add_dependency( file
->file
, replace_extension( source
->name
, ".idl", ".h" ), INCL_NORMAL
);
1749 add_all_includes( make
, file
, file
->file
);
1751 if (source
->file
->flags
& FLAG_IDL_SERVER
)
1753 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_s.c" ), NULL
);
1754 add_dependency( file
->file
, "wine/exception.h", INCL_NORMAL
);
1755 add_dependency( file
->file
, replace_extension( source
->name
, ".idl", ".h" ), INCL_NORMAL
);
1756 add_all_includes( make
, file
, file
->file
);
1758 if (source
->file
->flags
& FLAG_IDL_IDENT
)
1760 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_i.c" ), NULL
);
1761 add_dependency( file
->file
, "rpc.h", INCL_NORMAL
);
1762 add_dependency( file
->file
, "rpcndr.h", INCL_NORMAL
);
1763 add_dependency( file
->file
, "guiddef.h", INCL_NORMAL
);
1764 add_all_includes( make
, file
, file
->file
);
1766 if (source
->file
->flags
& FLAG_IDL_PROXY
)
1768 file
= add_generated_source( make
, "dlldata.o", "dlldata.c" );
1769 add_dependency( file
->file
, "objbase.h", INCL_NORMAL
);
1770 add_dependency( file
->file
, "rpcproxy.h", INCL_NORMAL
);
1771 add_all_includes( make
, file
, file
->file
);
1772 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_p.c" ), NULL
);
1773 add_dependency( file
->file
, "objbase.h", INCL_NORMAL
);
1774 add_dependency( file
->file
, "rpcproxy.h", INCL_NORMAL
);
1775 add_dependency( file
->file
, "wine/exception.h", INCL_NORMAL
);
1776 add_dependency( file
->file
, replace_extension( source
->name
, ".idl", ".h" ), INCL_NORMAL
);
1777 add_all_includes( make
, file
, file
->file
);
1779 if (source
->file
->flags
& FLAG_IDL_TYPELIB
)
1781 add_generated_source( make
, replace_extension( source
->name
, ".idl", "_l.res" ), NULL
);
1783 if (source
->file
->flags
& FLAG_IDL_REGTYPELIB
)
1785 add_generated_source( make
, replace_extension( source
->name
, ".idl", "_t.res" ), NULL
);
1787 if (source
->file
->flags
& FLAG_IDL_REGISTER
)
1789 add_generated_source( make
, replace_extension( source
->name
, ".idl", "_r.res" ), NULL
);
1791 if (source
->file
->flags
& FLAG_IDL_HEADER
)
1793 add_generated_source( make
, replace_extension( source
->name
, ".idl", ".h" ), NULL
);
1795 if (!source
->file
->flags
&& strendswith( source
->name
, ".idl" ))
1797 add_generated_source( make
, replace_extension( source
->name
, ".idl", ".h" ), NULL
);
1799 if (strendswith( source
->name
, ".x" ))
1801 add_generated_source( make
, replace_extension( source
->name
, ".x", ".h" ), NULL
);
1803 if (strendswith( source
->name
, ".y" ))
1805 file
= add_generated_source( make
, replace_extension( source
->name
, ".y", ".tab.c" ), NULL
);
1806 /* steal the includes list from the source file */
1807 file
->files_count
= source
->files_count
;
1808 file
->files_size
= source
->files_size
;
1809 file
->files
= source
->files
;
1810 source
->files_count
= source
->files_size
= 0;
1811 source
->files
= NULL
;
1813 if (strendswith( source
->name
, ".l" ))
1815 file
= add_generated_source( make
, replace_extension( source
->name
, ".l", ".yy.c" ), NULL
);
1816 /* steal the includes list from the source file */
1817 file
->files_count
= source
->files_count
;
1818 file
->files_size
= source
->files_size
;
1819 file
->files
= source
->files
;
1820 source
->files_count
= source
->files_size
= 0;
1821 source
->files
= NULL
;
1823 if (source
->file
->flags
& FLAG_C_IMPLIB
)
1825 if (!make
->staticimplib
&& make
->importlib
&& *dll_ext
)
1826 make
->staticimplib
= strmake( "lib%s.a", make
->importlib
);
1828 if (strendswith( source
->name
, ".po" ))
1830 if (!make
->disabled
)
1831 strarray_add_uniq( &linguas
, replace_extension( source
->name
, ".po", "" ));
1833 if (strendswith( source
->name
, ".spec" ))
1835 char *obj
= replace_extension( source
->name
, ".spec", "" );
1836 strarray_addall_uniq( &make
->extra_imports
,
1837 get_expanded_file_local_var( make
, obj
, "IMPORTS" ));
1842 file
= add_generated_source( make
, "testlist.o", "testlist.c" );
1843 add_dependency( file
->file
, "wine/test.h", INCL_NORMAL
);
1844 add_all_includes( make
, file
, file
->file
);
1846 for (i
= 0; i
< objs
.count
; i
++)
1848 /* default to .c for unknown extra object files */
1849 if (strendswith( objs
.str
[i
], ".o" ))
1851 file
= add_generated_source( make
, objs
.str
[i
], replace_extension( objs
.str
[i
], ".o", ".c" ));
1852 file
->file
->flags
|= FLAG_C_UNIX
;
1853 file
->use_msvcrt
= 0;
1855 else if (strendswith( objs
.str
[i
], ".res" ))
1856 add_generated_source( make
, replace_extension( objs
.str
[i
], ".res", ".rc" ), NULL
);
1858 add_generated_source( make
, objs
.str
[i
], NULL
);
1863 /*******************************************************************
1866 static void create_dir( const char *dir
)
1870 p
= path
= xstrdup( dir
);
1871 while ((p
= strchr( p
, '/' )))
1874 if (mkdir( path
, 0755 ) == -1 && errno
!= EEXIST
) fatal_perror( "mkdir %s", path
);
1876 while (*p
== '/') p
++;
1878 if (mkdir( path
, 0755 ) == -1 && errno
!= EEXIST
) fatal_perror( "mkdir %s", path
);
1883 /*******************************************************************
1884 * create_file_directories
1886 * Create the base directories of all the files.
1888 static void create_file_directories( const struct makefile
*make
, struct strarray files
)
1890 struct strarray subdirs
= empty_strarray
;
1894 for (i
= 0; i
< files
.count
; i
++)
1896 if (!strchr( files
.str
[i
], '/' )) continue;
1897 dir
= obj_dir_path( make
, files
.str
[i
] );
1898 *strrchr( dir
, '/' ) = 0;
1899 strarray_add_uniq( &subdirs
, dir
);
1902 for (i
= 0; i
< subdirs
.count
; i
++) create_dir( subdirs
.str
[i
] );
1906 /*******************************************************************
1907 * output_filenames_obj_dir
1909 static void output_filenames_obj_dir( const struct makefile
*make
, struct strarray array
)
1913 for (i
= 0; i
< array
.count
; i
++) output_filename( obj_dir_path( make
, array
.str
[i
] ));
1917 /*******************************************************************
1920 static void get_dependencies( struct incl_file
*file
, struct incl_file
*source
)
1924 if (!file
->filename
) return;
1928 if (file
->owner
== source
) return; /* already processed */
1929 if (file
->type
== INCL_IMPORTLIB
)
1931 if (!(source
->file
->flags
& (FLAG_IDL_TYPELIB
| FLAG_IDL_REGTYPELIB
)))
1932 return; /* library is imported only when building a typelib */
1933 strarray_add( &source
->importlibdeps
, file
->filename
);
1935 else strarray_add( &source
->dependencies
, file
->filename
);
1936 file
->owner
= source
;
1939 if (!strcmp( file
->filename
, "include/config.h" ) &&
1940 file
!= source
->files
[0] && !source
->is_external
)
1942 input_file_name
= source
->filename
;
1944 for (i
= 0; i
< source
->file
->deps_count
; i
++)
1946 if (!strcmp( source
->file
->deps
[i
].name
, file
->name
))
1947 input_line
= source
->file
->deps
[i
].line
;
1949 fatal_error( "%s must be included before other headers\n", file
->name
);
1953 for (i
= 0; i
< file
->files_count
; i
++) get_dependencies( file
->files
[i
], source
);
1957 /*******************************************************************
1958 * get_local_dependencies
1960 * Get the local dependencies of a given target.
1962 static struct strarray
get_local_dependencies( const struct makefile
*make
, const char *name
,
1963 struct strarray targets
)
1966 struct strarray deps
= get_expanded_file_local_var( make
, name
, "DEPS" );
1968 for (i
= 0; i
< deps
.count
; i
++)
1970 if (strarray_exists( &targets
, deps
.str
[i
] ))
1971 deps
.str
[i
] = obj_dir_path( make
, deps
.str
[i
] );
1973 deps
.str
[i
] = src_dir_path( make
, deps
.str
[i
] );
1979 /*******************************************************************
1982 * Check if makefile builds the named static library and return the full lib path.
1984 static const char *get_static_lib( const struct makefile
*make
, const char *name
)
1986 if (!make
->staticlib
) return NULL
;
1987 if (make
->disabled
) return NULL
;
1988 if (strncmp( make
->staticlib
, "lib", 3 )) return NULL
;
1989 if (strncmp( make
->staticlib
+ 3, name
, strlen(name
) )) return NULL
;
1990 if (strcmp( make
->staticlib
+ 3 + strlen(name
), ".a" )) return NULL
;
1991 return obj_dir_path( make
, make
->staticlib
);
1995 /*******************************************************************
1996 * get_native_unix_lib
1998 static const char *get_native_unix_lib( const struct makefile
*make
, const char *name
)
2000 if (!make
->native_unix_lib
) return NULL
;
2001 if (strncmp( make
->unixlib
, name
, strlen(name
) )) return NULL
;
2002 if (make
->unixlib
[strlen(name
)] != '.') return NULL
;
2003 return obj_dir_path( make
, make
->unixlib
);
2007 /*******************************************************************
2008 * get_parent_makefile
2010 static struct makefile
*get_parent_makefile( struct makefile
*make
)
2015 if (!make
->obj_dir
) return NULL
;
2016 dir
= xstrdup( make
->obj_dir
);
2017 if (!(p
= strrchr( dir
, '/' ))) return NULL
;
2019 for (i
= 0; i
< subdirs
.count
; i
++)
2020 if (!strcmp( submakes
[i
]->obj_dir
, dir
)) return submakes
[i
];
2025 /*******************************************************************
2028 static int needs_delay_lib( const struct makefile
*make
)
2030 if (delay_load_flag
) return 0;
2031 if (*dll_ext
&& !crosstarget
) return 0;
2032 if (!make
->importlib
) return 0;
2033 return strarray_exists( &delay_import_libs
, make
->importlib
);
2037 /*******************************************************************
2038 * add_unix_libraries
2040 static struct strarray
add_unix_libraries( const struct makefile
*make
, struct strarray
*deps
)
2042 struct strarray ret
= empty_strarray
;
2043 struct strarray all_libs
= empty_strarray
;
2046 if (strcmp( make
->unixlib
, "ntdll.so" )) strarray_add( &all_libs
, "-lntdll" );
2047 strarray_addall( &all_libs
, get_expanded_make_var_array( make
, "EXTRALIBS" ));
2049 for (i
= 0; i
< all_libs
.count
; i
++)
2051 const char *lib
= NULL
;
2053 if (!strncmp( all_libs
.str
[i
], "-l", 2 ))
2055 for (j
= 0; j
< subdirs
.count
; j
++)
2057 if (make
== submakes
[j
]) continue;
2058 if ((lib
= get_native_unix_lib( submakes
[j
], all_libs
.str
[i
] + 2 ))) break;
2063 strarray_add( deps
, lib
);
2064 strarray_add( &ret
, lib
);
2066 else strarray_add( &ret
, all_libs
.str
[i
] );
2069 strarray_addall( &ret
, libs
);
2074 /*******************************************************************
2077 static int is_crt_module( const char *file
)
2079 return !strncmp( file
, "msvcr", 5 ) || !strncmp( file
, "ucrt", 4 ) || !strcmp( file
, "crtdll.dll" );
2083 /*******************************************************************
2086 static const char *get_default_crt( const struct makefile
*make
)
2088 if (!make
->use_msvcrt
) return NULL
;
2089 if (make
->module
&& is_crt_module( make
->module
)) return NULL
; /* don't add crt import to crt dlls */
2090 return !make
->testdll
&& (!make
->staticlib
|| make
->extlib
) ? "ucrtbase" : "msvcrt";
2094 /*******************************************************************
2097 static const char *get_crt_define( const struct makefile
*make
)
2099 const char *crt_dll
= NULL
;
2100 unsigned int i
, version
= 0;
2102 for (i
= 0; i
< make
->imports
.count
; i
++)
2104 if (!is_crt_module( make
->imports
.str
[i
] )) continue;
2105 if (crt_dll
) fatal_error( "More than one C runtime DLL imported: %s and %s\n",
2106 crt_dll
, make
->imports
.str
[i
] );
2107 crt_dll
= make
->imports
.str
[i
];
2112 if (strarray_exists( &make
->extradllflags
, "-nodefaultlibs" )) return "-D_MSVCR_VER=0";
2113 if (!(crt_dll
= get_default_crt( make
))) crt_dll
= make
->module
;
2115 if (!strncmp( crt_dll
, "ucrt", 4 )) return "-D_UCRT";
2116 sscanf( crt_dll
, "msvcr%u", &version
);
2117 return strmake( "-D_MSVCR_VER=%u", version
);
2121 /*******************************************************************
2122 * add_default_imports
2124 static struct strarray
add_default_imports( const struct makefile
*make
, struct strarray imports
)
2126 struct strarray ret
= empty_strarray
;
2127 const char *crt_dll
= get_default_crt( make
);
2130 for (i
= 0; i
< imports
.count
; i
++)
2132 if (is_crt_module( imports
.str
[i
] )) crt_dll
= imports
.str
[i
];
2133 else strarray_add( &ret
, imports
.str
[i
] );
2136 strarray_add( &ret
, "winecrt0" );
2137 if (crt_dll
) strarray_add( &ret
, crt_dll
);
2139 if (make
->is_win16
&& (!make
->importlib
|| strcmp( make
->importlib
, "kernel" )))
2140 strarray_add( &ret
, "kernel" );
2142 strarray_add( &ret
, "kernel32" );
2143 strarray_add( &ret
, "ntdll" );
2148 /*******************************************************************
2151 static struct strarray
add_import_libs( const struct makefile
*make
, struct strarray
*deps
,
2152 struct strarray imports
, int delay
, int is_cross
)
2154 struct strarray ret
= empty_strarray
;
2157 for (i
= 0; i
< imports
.count
; i
++)
2159 const char *name
= imports
.str
[i
];
2160 const char *lib
= NULL
;
2166 case 'L': strarray_add( &ret
, name
); continue;
2167 case 'l': name
+= 2; break;
2171 else name
= get_base_name( name
);
2173 for (j
= 0; j
< subdirs
.count
; j
++)
2175 if (submakes
[j
]->importlib
&& !strcmp( submakes
[j
]->importlib
, name
))
2176 lib
= obj_dir_path( submakes
[j
], strmake( "lib%s.a", name
));
2178 lib
= get_static_lib( submakes
[j
], name
);
2184 const char *ext
= NULL
;
2186 if (delay
&& !delay_load_flag
&& (is_cross
|| !*dll_ext
)) ext
= ".delay.a";
2187 else if (is_cross
) ext
= ".cross.a";
2188 if (ext
) lib
= replace_extension( lib
, ".a", ext
);
2189 strarray_add_uniq( deps
, lib
);
2190 strarray_add( &ret
, lib
);
2192 else strarray_add( &ret
, strmake( "-l%s", name
));
2198 /*******************************************************************
2201 static void add_install_rule( struct makefile
*make
, const char *target
,
2202 const char *file
, const char *dest
)
2204 if (strarray_exists( &make
->install_lib
, target
) ||
2205 strarray_exists( &top_install_lib
, make
->obj_dir
) ||
2206 strarray_exists( &top_install_lib
, obj_dir_path( make
, target
)))
2208 strarray_add( &make
->install_rules
[INSTALL_LIB
], file
);
2209 strarray_add( &make
->install_rules
[INSTALL_LIB
], dest
);
2211 else if (strarray_exists( &make
->install_dev
, target
) ||
2212 strarray_exists( &top_install_dev
, make
->obj_dir
) ||
2213 strarray_exists( &top_install_dev
, obj_dir_path( make
, target
)))
2215 strarray_add( &make
->install_rules
[INSTALL_DEV
], file
);
2216 strarray_add( &make
->install_rules
[INSTALL_DEV
], dest
);
2221 /*******************************************************************
2222 * get_include_install_path
2224 * Determine the installation path for a given include file.
2226 static const char *get_include_install_path( const char *name
)
2228 if (!strncmp( name
, "wine/", 5 )) return name
+ 5;
2229 if (!strncmp( name
, "msvcrt/", 7 )) return name
;
2230 return strmake( "windows/%s", name
);
2234 /*******************************************************************
2235 * get_shared_library_name
2237 * Determine possible names for a shared library with a version number.
2239 static struct strarray
get_shared_lib_names( const char *libname
)
2241 struct strarray ret
= empty_strarray
;
2242 const char *ext
, *p
;
2243 char *name
, *first
, *second
;
2246 strarray_add( &ret
, libname
);
2248 for (p
= libname
; (p
= strchr( p
, '.' )); p
++)
2249 if ((len
= strspn( p
+ 1, "0123456789." ))) break;
2251 if (!len
) return ret
;
2253 if (*ext
&& ext
[-1] == '.') ext
--;
2255 /* keep only the first group of digits */
2256 name
= xstrdup( libname
);
2257 first
= name
+ (p
- libname
);
2258 if ((second
= strchr( first
+ 1, '.' )))
2260 strcpy( second
, ext
);
2261 strarray_add( &ret
, xstrdup( name
));
2267 /*******************************************************************
2268 * get_source_defines
2270 static struct strarray
get_source_defines( struct makefile
*make
, struct incl_file
*source
,
2274 struct strarray ret
= empty_strarray
;
2276 strarray_addall( &ret
, make
->include_args
);
2277 if (source
->use_msvcrt
)
2278 strarray_add( &ret
, strmake( "-I%s", root_src_dir_path( "include/msvcrt" )));
2279 for (i
= 0; i
< make
->include_paths
.count
; i
++)
2280 strarray_add( &ret
, strmake( "-I%s", make
->include_paths
.str
[i
] ));
2281 strarray_addall( &ret
, make
->define_args
);
2282 strarray_addall( &ret
, get_expanded_file_local_var( make
, obj
, "EXTRADEFS" ));
2283 if ((source
->file
->flags
& FLAG_C_UNIX
) && *dll_ext
) strarray_add( &ret
, "-DWINE_UNIX_LIB" );
2288 /*******************************************************************
2289 * remove_warning_flags
2291 static struct strarray
remove_warning_flags( struct strarray flags
)
2294 struct strarray ret
= empty_strarray
;
2296 for (i
= 0; i
< flags
.count
; i
++)
2297 if (strncmp( flags
.str
[i
], "-W", 2 ) || !strncmp( flags
.str
[i
], "-Wno-", 5 ))
2298 strarray_add( &ret
, flags
.str
[i
] );
2303 /*******************************************************************
2306 static const char *get_debug_file( struct makefile
*make
, const char *name
)
2308 const char *debug_file
= NULL
;
2309 if (!make
->is_cross
|| !crossdebug
) return NULL
;
2310 if (!strcmp( crossdebug
, "pdb" )) debug_file
= strmake( "%s.pdb", get_base_name( name
));
2311 else if(!strncmp( crossdebug
, "split", 5 )) debug_file
= strmake( "%s.debug", name
);
2312 if (debug_file
) strarray_add( &make
->debug_files
, debug_file
);
2317 /*******************************************************************
2320 static const char *cmd_prefix( const char *cmd
)
2322 if (!silent_rules
) return "";
2323 return strmake( "$(quiet_%s)", cmd
);
2327 /*******************************************************************
2328 * output_winegcc_command
2330 static void output_winegcc_command( struct makefile
*make
, int is_cross
)
2332 output( "\t%s%s -o $@", cmd_prefix( "CCLD" ), tools_path( make
, "winegcc" ));
2333 output_filename( "--wine-objdir ." );
2336 output_filename( "--winebuild" );
2337 output_filename( tools_path( make
, "winebuild" ));
2341 output_filename( "-b" );
2342 output_filename( crosstarget
);
2343 output_filename( "--lib-suffix=.cross.a" );
2347 output_filenames( target_flags
);
2348 output_filenames( lddll_flags
);
2353 /*******************************************************************
2354 * output_symlink_rule
2356 * Output a rule to create a symlink.
2358 static void output_symlink_rule( const char *src_name
, const char *link_name
, int create_dir
)
2360 const char *name
= strrchr( link_name
, '/' );
2365 dir
= xstrdup( link_name
);
2366 dir
[name
- link_name
] = 0;
2369 output( "\t%s", cmd_prefix( "LN" ));
2370 if (create_dir
&& dir
&& *dir
) output( "%s -d %s && ", root_src_dir_path( "tools/install-sh" ), dir
);
2371 output( "rm -f %s && ", link_name
);
2373 /* dest path with a directory needs special handling if ln -s isn't supported */
2374 if (dir
&& strcmp( ln_s
, "ln -s" ))
2375 output( "cd %s && %s %s %s\n", *dir
? dir
: "/", ln_s
, src_name
, name
+ 1 );
2377 output( "%s %s %s\n", ln_s
, src_name
, link_name
);
2383 /*******************************************************************
2384 * output_srcdir_symlink
2386 * Output rule to create a symlink back to the source directory, for source files
2387 * that are needed at run-time.
2389 static void output_srcdir_symlink( struct makefile
*make
, const char *obj
)
2391 char *src_file
, *dst_file
, *src_name
;
2393 if (!make
->src_dir
) return;
2394 src_file
= src_dir_path( make
, obj
);
2395 dst_file
= obj_dir_path( make
, obj
);
2396 output( "%s: %s\n", dst_file
, src_file
);
2398 src_name
= src_file
;
2399 if (src_name
[0] != '/' && make
->obj_dir
)
2400 src_name
= concat_paths( get_relative_path( make
->obj_dir
, "" ), src_name
);
2402 output_symlink_rule( src_name
, dst_file
, 0 );
2403 strarray_add( &make
->all_targets
, obj
);
2407 /*******************************************************************
2408 * output_install_commands
2410 static void output_install_commands( struct makefile
*make
, struct strarray files
)
2413 char *install_sh
= root_src_dir_path( "tools/install-sh" );
2415 for (i
= 0; i
< files
.count
; i
+= 2)
2417 const char *file
= files
.str
[i
];
2418 const char *dest
= strmake( "$(DESTDIR)%s", files
.str
[i
+ 1] + 1 );
2420 switch (*files
.str
[i
+ 1])
2422 case 'c': /* cross-compiled program */
2423 output( "\tSTRIPPROG=%s-strip %s -m 644 $(INSTALL_PROGRAM_FLAGS) %s %s\n",
2424 crosstarget
, install_sh
, obj_dir_path( make
, file
), dest
);
2425 output( "\t%s --builtin %s\n", tools_path( make
, "winebuild" ), dest
);
2427 case 'd': /* data file */
2428 output( "\t%s -m 644 $(INSTALL_DATA_FLAGS) %s %s\n",
2429 install_sh
, obj_dir_path( make
, file
), dest
);
2431 case 'D': /* data file in source dir */
2432 output( "\t%s -m 644 $(INSTALL_DATA_FLAGS) %s %s\n",
2433 install_sh
, src_dir_path( make
, file
), dest
);
2435 case 'p': /* program file */
2436 output( "\tSTRIPPROG=\"$(STRIP)\" %s $(INSTALL_PROGRAM_FLAGS) %s %s\n",
2437 install_sh
, obj_dir_path( make
, file
), dest
);
2439 case 's': /* script */
2440 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s %s\n",
2441 install_sh
, obj_dir_path( make
, file
), dest
);
2443 case 'S': /* script in source dir */
2444 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s %s\n",
2445 install_sh
, src_dir_path( make
, file
), dest
);
2447 case 't': /* script in tools dir */
2448 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s %s\n",
2449 install_sh
, tools_dir_path( make
, files
.str
[i
] ), dest
);
2451 case 'y': /* symlink */
2452 output_symlink_rule( files
.str
[i
], dest
, 1 );
2457 strarray_add( &make
->uninstall_files
, dest
);
2462 /*******************************************************************
2463 * output_install_rules
2465 * Rules are stored as a (file,dest) pair of values.
2466 * The first char of dest indicates the type of install.
2468 static void output_install_rules( struct makefile
*make
, enum install_rules rules
, const char *target
)
2471 struct strarray files
= make
->install_rules
[rules
];
2472 struct strarray targets
= empty_strarray
;
2474 if (!files
.count
) return;
2476 for (i
= 0; i
< files
.count
; i
+= 2)
2478 const char *file
= files
.str
[i
];
2479 switch (*files
.str
[i
+ 1])
2481 case 'c': /* cross-compiled program */
2482 case 'd': /* data file */
2483 case 'p': /* program file */
2484 case 's': /* script */
2485 strarray_add_uniq( &targets
, obj_dir_path( make
, file
));
2487 case 't': /* script in tools dir */
2488 strarray_add_uniq( &targets
, tools_dir_path( make
, file
));
2493 output( "%s %s::", obj_dir_path( make
, "install" ), obj_dir_path( make
, target
));
2494 output_filenames( targets
);
2496 output_install_commands( make
, files
);
2497 strarray_add_uniq( &make
->phony_targets
, obj_dir_path( make
, "install" ));
2498 strarray_add_uniq( &make
->phony_targets
, obj_dir_path( make
, target
));
2502 static int cmp_string_length( const char **a
, const char **b
)
2504 int paths_a
= 0, paths_b
= 0;
2507 for (p
= *a
; *p
; p
++) if (*p
== '/') paths_a
++;
2508 for (p
= *b
; *p
; p
++) if (*p
== '/') paths_b
++;
2509 if (paths_b
!= paths_a
) return paths_b
- paths_a
;
2510 return strcmp( *a
, *b
);
2513 /*******************************************************************
2514 * output_uninstall_rules
2516 static void output_uninstall_rules( struct makefile
*make
)
2518 static const char *dirs_order
[] =
2519 { "$(includedir)", "$(mandir)", "$(fontdir)", "$(nlsdir)", "$(datadir)", "$(dlldir)" };
2521 struct strarray uninstall_dirs
= empty_strarray
;
2524 if (!make
->uninstall_files
.count
) return;
2525 output( "uninstall::\n" );
2526 output_rm_filenames( make
->uninstall_files
);
2527 strarray_add_uniq( &make
->phony_targets
, "uninstall" );
2529 if (!subdirs
.count
) return;
2530 for (i
= 0; i
< make
->uninstall_files
.count
; i
++)
2532 char *dir
= xstrdup( make
->uninstall_files
.str
[i
] );
2533 while (strchr( dir
, '/' ))
2535 *strrchr( dir
, '/' ) = 0;
2536 strarray_add_uniq( &uninstall_dirs
, xstrdup(dir
) );
2539 strarray_qsort( &uninstall_dirs
, cmp_string_length
);
2540 output( "\t-rmdir" );
2541 for (i
= 0; i
< sizeof(dirs_order
)/sizeof(dirs_order
[0]); i
++)
2543 for (j
= 0; j
< uninstall_dirs
.count
; j
++)
2545 if (!uninstall_dirs
.str
[j
]) continue;
2546 if (strncmp( uninstall_dirs
.str
[j
] + strlen("$(DESTDIR)"), dirs_order
[i
], strlen(dirs_order
[i
]) ))
2548 output_filename( uninstall_dirs
.str
[j
] );
2549 uninstall_dirs
.str
[j
] = NULL
;
2552 for (j
= 0; j
< uninstall_dirs
.count
; j
++)
2553 if (uninstall_dirs
.str
[j
]) output_filename( uninstall_dirs
.str
[j
] );
2558 /*******************************************************************
2561 static void output_po_files( struct makefile
*make
)
2563 const char *po_dir
= src_dir_path( make
, "po" );
2568 for (i
= 0; i
< linguas
.count
; i
++)
2569 output_filename( strmake( "%s/%s.po", po_dir
, linguas
.str
[i
] ));
2570 output( ": %s/wine.pot\n", po_dir
);
2571 output( "\t%smsgmerge --previous -q $@ %s/wine.pot | msgattrib --no-obsolete -o $@.new && mv $@.new $@\n",
2572 cmd_prefix( "MSG" ), po_dir
);
2573 output( "po/all:" );
2574 for (i
= 0; i
< linguas
.count
; i
++)
2575 output_filename( strmake( "%s/%s.po", po_dir
, linguas
.str
[i
] ));
2578 output( "%s/wine.pot:", po_dir
);
2579 output_filenames( make
->pot_files
);
2581 output( "\t%smsgcat -o $@", cmd_prefix( "MSG" ));
2582 output_filenames( make
->pot_files
);
2584 strarray_add( &make
->maintainerclean_files
, strmake( "%s/wine.pot", po_dir
));
2588 /*******************************************************************
2591 static void output_source_y( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2593 /* add source file dependency for parallel makes */
2594 char *header
= strmake( "%s.tab.h", obj
);
2596 if (find_include_file( make
, header
))
2598 output( "%s: %s\n", obj_dir_path( make
, header
), source
->filename
);
2599 output( "\t%s%s -o %s.tab.c -d %s\n",
2600 cmd_prefix( "BISON" ), bison
, obj_dir_path( make
, obj
), source
->filename
);
2601 output( "%s.tab.c: %s %s\n", obj_dir_path( make
, obj
),
2602 source
->filename
, obj_dir_path( make
, header
));
2603 strarray_add( &make
->clean_files
, header
);
2605 else output( "%s.tab.c: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2607 output( "\t%s%s -o $@ %s\n", cmd_prefix( "BISON" ), bison
, source
->filename
);
2611 /*******************************************************************
2614 static void output_source_l( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2616 output( "%s.yy.c: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2617 output( "\t%s%s -o$@ %s\n", cmd_prefix( "FLEX" ), flex
, source
->filename
);
2621 /*******************************************************************
2624 static void output_source_h( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2626 if (source
->file
->flags
& FLAG_GENERATED
)
2627 strarray_add( &make
->all_targets
, source
->name
);
2629 add_install_rule( make
, source
->name
, source
->name
,
2630 strmake( "D$(includedir)/wine/%s", get_include_install_path( source
->name
) ));
2634 /*******************************************************************
2637 static void output_source_rc( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2639 struct strarray defines
= get_source_defines( make
, source
, obj
);
2640 const char *po_dir
= NULL
;
2643 if (source
->file
->flags
& FLAG_GENERATED
) strarray_add( &make
->clean_files
, source
->name
);
2644 if (linguas
.count
&& (source
->file
->flags
& FLAG_RC_PO
)) po_dir
= "po";
2645 strarray_add( &make
->res_files
, strmake( "%s.res", obj
));
2646 if (source
->file
->flags
& FLAG_RC_PO
)
2648 strarray_add( &make
->pot_files
, strmake( "%s.pot", obj
));
2649 output( "%s.pot ", obj_dir_path( make
, obj
) );
2651 output( "%s.res: %s", obj_dir_path( make
, obj
), source
->filename
);
2652 output_filename( tools_path( make
, "wrc" ));
2653 if (make
->src_dir
) output_filename( "nls/locale.nls" );
2654 output_filenames( source
->dependencies
);
2656 output( "\t%s%s -u -o $@", cmd_prefix( "WRC" ), tools_path( make
, "wrc" ) );
2657 if (make
->is_win16
) output_filename( "-m16" );
2658 output_filename( "--nostdinc" );
2659 if (po_dir
) output_filename( strmake( "--po-dir=%s", po_dir
));
2660 output_filenames( defines
);
2661 output_filename( source
->filename
);
2665 output( "%s.res:", obj_dir_path( make
, obj
));
2666 for (i
= 0; i
< linguas
.count
; i
++)
2667 output_filename( strmake( "%s/%s.mo", po_dir
, linguas
.str
[i
] ));
2673 /*******************************************************************
2676 static void output_source_mc( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2679 char *obj_path
= obj_dir_path( make
, obj
);
2681 strarray_add( &make
->res_files
, strmake( "%s.res", obj
));
2682 strarray_add( &make
->pot_files
, strmake( "%s.pot", obj
));
2683 output( "%s.pot %s.res: %s", obj_path
, obj_path
, source
->filename
);
2684 output_filename( tools_path( make
, "wmc" ));
2685 output_filenames( source
->dependencies
);
2687 output( "\t%s%s -u -o $@ %s", cmd_prefix( "WMC" ), tools_path( make
, "wmc" ), source
->filename
);
2690 output_filename( "--po-dir=po" );
2692 output( "%s.res:", obj_dir_path( make
, obj
));
2693 for (i
= 0; i
< linguas
.count
; i
++)
2694 output_filename( strmake( "po/%s.mo", linguas
.str
[i
] ));
2700 /*******************************************************************
2703 static void output_source_res( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2705 strarray_add( &make
->res_files
, source
->name
);
2709 /*******************************************************************
2712 static void output_source_idl( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2714 struct strarray defines
= get_source_defines( make
, source
, obj
);
2715 struct strarray targets
= empty_strarray
;
2719 if (!source
->file
->flags
) source
->file
->flags
|= FLAG_IDL_HEADER
| FLAG_INSTALL
;
2720 if (find_include_file( make
, strmake( "%s.h", obj
))) source
->file
->flags
|= FLAG_IDL_HEADER
;
2722 for (i
= 0; i
< sizeof(idl_outputs
) / sizeof(idl_outputs
[0]); i
++)
2724 if (!(source
->file
->flags
& idl_outputs
[i
].flag
)) continue;
2725 dest
= strmake( "%s%s", obj
, idl_outputs
[i
].ext
);
2726 if (!find_src_file( make
, dest
)) strarray_add( &make
->clean_files
, dest
);
2727 strarray_add( &targets
, dest
);
2729 if (source
->file
->flags
& FLAG_IDL_PROXY
) strarray_add( &make
->dlldata_files
, source
->name
);
2730 if (source
->file
->flags
& FLAG_INSTALL
)
2732 add_install_rule( make
, source
->name
, xstrdup( source
->name
),
2733 strmake( "D$(includedir)/wine/%s.idl", get_include_install_path( obj
) ));
2734 if (source
->file
->flags
& FLAG_IDL_HEADER
)
2735 add_install_rule( make
, source
->name
, strmake( "%s.h", obj
),
2736 strmake( "d$(includedir)/wine/%s.h", get_include_install_path( obj
) ));
2738 if (!targets
.count
) return;
2740 output_filenames_obj_dir( make
, targets
);
2741 output( ": %s\n", tools_path( make
, "widl" ));
2742 output( "\t%s%s -o $@", cmd_prefix( "WIDL" ), tools_path( make
, "widl" ) );
2743 output_filenames( target_flags
);
2744 output_filename( "--nostdinc" );
2745 output_filename( "-Ldlls/\\*" );
2746 output_filenames( defines
);
2747 output_filenames( get_expanded_make_var_array( make
, "EXTRAIDLFLAGS" ));
2748 output_filenames( get_expanded_file_local_var( make
, obj
, "EXTRAIDLFLAGS" ));
2749 output_filename( source
->filename
);
2751 output_filenames_obj_dir( make
, targets
);
2752 output( ": %s", source
->filename
);
2753 output_filenames( source
->dependencies
);
2754 for (i
= 0; i
< source
->importlibdeps
.count
; i
++)
2756 struct makefile
*submake
= find_importlib_module( source
->importlibdeps
.str
[i
] );
2757 output_filename( obj_dir_path( submake
, submake
->module
));
2763 /*******************************************************************
2766 static void output_source_x( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2768 output( "%s.h: %s%s %s\n", obj_dir_path( make
, obj
),
2769 tools_dir_path( make
, "make_xftmpl" ), tools_ext
, source
->filename
);
2770 output( "\t%s%s%s -H -o $@ %s\n", cmd_prefix( "GEN" ),
2771 tools_dir_path( make
, "make_xftmpl" ), tools_ext
, source
->filename
);
2772 if (source
->file
->flags
& FLAG_INSTALL
)
2774 add_install_rule( make
, source
->name
, source
->name
,
2775 strmake( "D$(includedir)/wine/%s", get_include_install_path( source
->name
) ));
2776 add_install_rule( make
, source
->name
, strmake( "%s.h", obj
),
2777 strmake( "d$(includedir)/wine/%s.h", get_include_install_path( obj
) ));
2782 /*******************************************************************
2785 static void output_source_sfd( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2788 char *ttf_obj
= strmake( "%s.ttf", obj
);
2789 char *ttf_file
= src_dir_path( make
, ttf_obj
);
2791 if (fontforge
&& !make
->src_dir
)
2793 output( "%s: %s\n", ttf_file
, source
->filename
);
2794 output( "\t%s%s -script %s %s $@\n", cmd_prefix( "GEN" ),
2795 fontforge
, root_src_dir_path( "fonts/genttf.ff" ), source
->filename
);
2796 if (!(source
->file
->flags
& FLAG_SFD_FONTS
)) strarray_add( &make
->font_files
, ttf_obj
);
2797 strarray_add( &make
->maintainerclean_files
, ttf_obj
);
2799 if (source
->file
->flags
& FLAG_INSTALL
)
2801 add_install_rule( make
, source
->name
, ttf_obj
, strmake( "D$(fontdir)/%s", ttf_obj
));
2802 output_srcdir_symlink( make
, ttf_obj
);
2805 if (source
->file
->flags
& FLAG_SFD_FONTS
)
2807 struct strarray
*array
= source
->file
->args
;
2809 for (i
= 0; i
< array
->count
; i
++)
2811 char *font
= strtok( xstrdup(array
->str
[i
]), " \t" );
2812 char *args
= strtok( NULL
, "" );
2814 strarray_add( &make
->all_targets
, xstrdup( font
));
2815 output( "%s: %s %s\n", obj_dir_path( make
, font
),
2816 tools_path( make
, "sfnt2fon" ), ttf_file
);
2817 output( "\t%s%s -q -o $@ %s %s\n", cmd_prefix( "GEN" ),
2818 tools_path( make
, "sfnt2fon" ), ttf_file
, args
);
2819 add_install_rule( make
, source
->name
, xstrdup(font
), strmake( "d$(fontdir)/%s", font
));
2825 /*******************************************************************
2828 static void output_source_svg( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2830 static const char * const images
[] = { "bmp", "cur", "ico", NULL
};
2833 if (convert
&& rsvg
&& icotool
)
2835 for (i
= 0; images
[i
]; i
++)
2836 if (find_include_file( make
, strmake( "%s.%s", obj
, images
[i
] ))) break;
2840 output( "%s.%s: %s\n", src_dir_path( make
, obj
), images
[i
], source
->filename
);
2841 output( "\t%sCONVERT=\"%s\" ICOTOOL=\"%s\" RSVG=\"%s\" %s %s $@\n",
2842 cmd_prefix( "GEN" ), convert
, icotool
, rsvg
,
2843 root_src_dir_path( "tools/buildimage" ), source
->filename
);
2844 strarray_add( &make
->maintainerclean_files
, strmake( "%s.%s", obj
, images
[i
] ));
2850 /*******************************************************************
2853 static void output_source_nls( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2855 add_install_rule( make
, source
->name
, source
->name
,
2856 strmake( "D$(nlsdir)/%s", source
->name
));
2857 output_srcdir_symlink( make
, strmake( "%s.nls", obj
));
2861 /*******************************************************************
2862 * output_source_desktop
2864 static void output_source_desktop( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2866 add_install_rule( make
, source
->name
, source
->name
,
2867 strmake( "D$(datadir)/applications/%s", source
->name
));
2871 /*******************************************************************
2874 static void output_source_po( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2876 output( "%s.mo: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2877 output( "\t%s%s -o $@ %s\n", cmd_prefix( "MSG" ), msgfmt
, source
->filename
);
2878 strarray_add( &make
->all_targets
, strmake( "%s.mo", obj
));
2882 /*******************************************************************
2885 static void output_source_in( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2889 if (strendswith( obj
, ".man" ) && source
->file
->args
)
2891 struct strarray symlinks
;
2892 char *dir
, *dest
= replace_extension( obj
, ".man", "" );
2893 char *lang
= strchr( dest
, '.' );
2894 char *section
= source
->file
->args
;
2898 dir
= strmake( "$(mandir)/%s/man%s", lang
, section
);
2900 else dir
= strmake( "$(mandir)/man%s", section
);
2901 add_install_rule( make
, dest
, xstrdup(obj
), strmake( "d%s/%s.%s", dir
, dest
, section
));
2902 symlinks
= get_expanded_file_local_var( make
, dest
, "SYMLINKS" );
2903 for (i
= 0; i
< symlinks
.count
; i
++)
2904 add_install_rule( make
, symlinks
.str
[i
], strmake( "%s.%s", dest
, section
),
2905 strmake( "y%s/%s.%s", dir
, symlinks
.str
[i
], section
));
2909 strarray_add( &make
->in_files
, xstrdup(obj
) );
2910 strarray_add( &make
->all_targets
, xstrdup(obj
) );
2911 output( "%s: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2912 output( "\t%s%s %s >$@ || (rm -f $@ && false)\n", cmd_prefix( "SED" ), sed_cmd
, source
->filename
);
2913 output( "%s:", obj_dir_path( make
, obj
));
2914 output_filenames( source
->dependencies
);
2916 add_install_rule( make
, obj
, xstrdup( obj
), strmake( "d$(datadir)/wine/%s", obj
));
2920 /*******************************************************************
2921 * output_source_spec
2923 static void output_source_spec( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2925 struct strarray imports
= get_expanded_file_local_var( make
, obj
, "IMPORTS" );
2926 struct strarray dll_flags
= get_expanded_file_local_var( make
, obj
, "EXTRADLLFLAGS" );
2927 struct strarray all_libs
, dep_libs
= empty_strarray
;
2928 char *dll_name
, *obj_name
, *output_file
;
2929 const char *debug_file
;
2931 if (!imports
.count
) imports
= make
->imports
;
2932 if (!dll_flags
.count
) dll_flags
= make
->extradllflags
;
2933 if (!strarray_exists( &dll_flags
, "-nodefaultlibs" )) imports
= add_default_imports( make
, imports
);
2935 all_libs
= add_import_libs( make
, &dep_libs
, imports
, 0, make
->is_cross
);
2936 dll_name
= strmake( "%s.dll%s", obj
, make
->is_cross
? "" : dll_ext
);
2937 obj_name
= strmake( "%s%s", obj_dir_path( make
, obj
), make
->is_cross
? ".cross.o" : ".o" );
2938 output_file
= obj_dir_path( make
, dll_name
);
2940 strarray_add( &make
->clean_files
, dll_name
);
2941 strarray_add( &make
->res_files
, strmake( "%s.res", obj
));
2942 output( "%s.res:", obj_dir_path( make
, obj
));
2943 output_filename( obj_dir_path( make
, dll_name
));
2944 output_filename( tools_path( make
, "wrc" ));
2946 output( "\t%secho \"%s.dll TESTDLL \\\"%s\\\"\" | %s -u -o $@\n", cmd_prefix( "WRC" ), obj
, output_file
,
2947 tools_path( make
, "wrc" ));
2949 output( "%s:", output_file
);
2950 output_filename( source
->filename
);
2951 output_filename( obj_name
);
2952 output_filenames( dep_libs
);
2953 output_filename( tools_path( make
, "winebuild" ));
2954 output_filename( tools_path( make
, "winegcc" ));
2956 output_winegcc_command( make
, make
->is_cross
);
2957 output_filename( "-s" );
2958 output_filenames( dll_flags
);
2959 output_filename( "-shared" );
2960 output_filename( source
->filename
);
2961 output_filename( obj_name
);
2962 if ((debug_file
= get_debug_file( make
, dll_name
)))
2963 output_filename( strmake( "-Wl,--debug-file,%s", obj_dir_path( make
, debug_file
)));
2964 output_filenames( all_libs
);
2965 output_filename( make
->is_cross
? "$(CROSSLDFLAGS)" : "$(LDFLAGS)" );
2970 /*******************************************************************
2971 * output_source_default
2973 static void output_source_default( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2975 struct strarray defines
= get_source_defines( make
, source
, obj
);
2976 int is_dll_src
= (make
->testdll
&&
2977 strendswith( source
->name
, ".c" ) &&
2978 find_src_file( make
, replace_extension( source
->name
, ".c", ".spec" )));
2979 int need_cross
= (crosstarget
&&
2980 !(source
->file
->flags
& FLAG_C_UNIX
) &&
2981 (make
->is_cross
|| make
->staticlib
||
2982 (source
->file
->flags
& FLAG_C_IMPLIB
)));
2983 int need_obj
= ((*dll_ext
|| !(source
->file
->flags
& FLAG_C_UNIX
)) &&
2985 (source
->file
->flags
& FLAG_C_IMPLIB
) ||
2986 (make
->staticlib
&& !make
->extlib
)));
2988 if ((source
->file
->flags
& FLAG_GENERATED
) &&
2989 (!make
->testdll
|| !strendswith( source
->filename
, "testlist.c" )))
2990 strarray_add( &make
->clean_files
, source
->basename
);
2994 if ((source
->file
->flags
& FLAG_C_UNIX
) && *dll_ext
)
2995 strarray_add( &make
->unixobj_files
, strmake( "%s.o", obj
));
2996 else if (source
->file
->flags
& FLAG_C_IMPLIB
)
2997 strarray_add( &make
->implib_files
, strmake( "%s.o", obj
));
2998 else if (!is_dll_src
)
2999 strarray_add( &make
->object_files
, strmake( "%s.o", obj
));
3001 strarray_add( &make
->clean_files
, strmake( "%s.o", obj
));
3002 output( "%s.o: %s\n", obj_dir_path( make
, obj
), source
->filename
);
3003 output( "\t%s$(CC) -c -o $@ %s", cmd_prefix( "CC" ), source
->filename
);
3004 output_filenames( defines
);
3005 output_filenames( make
->extlib
? extra_cflags_extlib
: extra_cflags
);
3006 if (make
->sharedlib
|| (source
->file
->flags
& FLAG_C_UNIX
))
3008 output_filenames( unix_dllflags
);
3010 else if (make
->module
|| make
->testdll
)
3012 output_filenames( dll_flags
);
3013 if (source
->use_msvcrt
) output_filenames( msvcrt_flags
);
3014 if (!*dll_ext
&& make
->module
&& is_crt_module( make
->module
))
3015 output_filename( "-fno-builtin" );
3017 output_filenames( cpp_flags
);
3018 output_filename( "$(CFLAGS)" );
3023 if (source
->file
->flags
& FLAG_C_IMPLIB
)
3024 strarray_add( &make
->crossimplib_files
, strmake( "%s.cross.o", obj
));
3025 else if (!is_dll_src
)
3026 strarray_add( &make
->crossobj_files
, strmake( "%s.cross.o", obj
));
3028 strarray_add( &make
->clean_files
, strmake( "%s.cross.o", obj
));
3029 output( "%s.cross.o: %s\n", obj_dir_path( make
, obj
), source
->filename
);
3030 output( "\t%s$(CROSSCC) -c -o $@ %s", cmd_prefix( "CC" ), source
->filename
);
3031 output_filenames( defines
);
3032 output_filenames( make
->extlib
? extra_cross_cflags_extlib
: extra_cross_cflags
);
3033 if (make
->module
&& is_crt_module( make
->module
))
3034 output_filename( "-fno-builtin" );
3035 /* force -Wformat when using 'long' types, until all modules have been converted
3036 * and we can remove -Wno-format */
3037 if (!make
->extlib
&& strarray_exists( &extra_cross_cflags
, "-Wno-format" ) &&
3038 !strarray_exists( &defines
, "-DWINE_NO_LONG_TYPES" ))
3039 output_filename( "-Wformat" );
3040 output_filenames( cpp_flags
);
3041 output_filename( "$(CROSSCFLAGS)" );
3044 if (make
->testdll
&& !is_dll_src
&& strendswith( source
->name
, ".c" ) &&
3045 !(source
->file
->flags
& FLAG_GENERATED
))
3047 strarray_add( &make
->test_files
, obj
);
3048 strarray_add( &make
->ok_files
, strmake( "%s.ok", obj
));
3049 output( "%s.ok:\n", obj_dir_path( make
, obj
));
3050 output( "\t%s%s $(RUNTESTFLAGS) -T . -M %s -p %s%s %s && touch $@\n",
3051 cmd_prefix( "TEST" ),
3052 root_src_dir_path( "tools/runtest" ), make
->testdll
,
3053 obj_dir_path( make
, replace_extension( make
->testdll
, ".dll", "_test.exe" )),
3054 make
->is_cross
? "" : dll_ext
, obj
);
3056 if (need_obj
) output_filename( strmake( "%s.o", obj_dir_path( make
, obj
)));
3057 if (need_cross
) output_filename( strmake( "%s.cross.o", obj_dir_path( make
, obj
)));
3059 output_filenames( source
->dependencies
);
3064 /* dispatch table to output rules for a single source file */
3068 void (*fn
)( struct makefile
*make
, struct incl_file
*source
, const char *obj
);
3069 } output_source_funcs
[] =
3071 { "y", output_source_y
},
3072 { "l", output_source_l
},
3073 { "h", output_source_h
},
3074 { "rh", output_source_h
},
3075 { "inl", output_source_h
},
3076 { "rc", output_source_rc
},
3077 { "mc", output_source_mc
},
3078 { "res", output_source_res
},
3079 { "idl", output_source_idl
},
3080 { "sfd", output_source_sfd
},
3081 { "svg", output_source_svg
},
3082 { "nls", output_source_nls
},
3083 { "desktop", output_source_desktop
},
3084 { "po", output_source_po
},
3085 { "in", output_source_in
},
3086 { "x", output_source_x
},
3087 { "spec", output_source_spec
},
3088 { NULL
, output_source_default
}
3092 /*******************************************************************
3095 static char *get_unix_lib_name( struct makefile
*make
)
3097 struct incl_file
*source
;
3099 if (!*dll_ext
) return NULL
;
3100 LIST_FOR_EACH_ENTRY( source
, &make
->sources
, struct incl_file
, entry
)
3102 if (!(source
->file
->flags
& FLAG_C_UNIX
)) continue;
3103 return strmake( "%s%s", get_base_name( make
->module
), dll_ext
);
3109 /*******************************************************************
3112 static void output_module( struct makefile
*make
)
3114 struct strarray all_libs
= empty_strarray
;
3115 struct strarray dep_libs
= empty_strarray
;
3116 struct strarray imports
= make
->imports
;
3117 const char *module_name
= make
->module
;
3118 const char *debug_file
;
3119 const char *delay_load
= delay_load_flag
;
3120 char *spec_file
= NULL
;
3123 if (!make
->is_exe
) spec_file
= src_dir_path( make
, replace_extension( make
->module
, ".dll", ".spec" ));
3125 if (!make
->data_only
)
3127 if (*dll_ext
&& !make
->is_cross
&& !make
->data_only
)
3128 module_name
= strmake( "%s%s", make
->module
, dll_ext
);
3130 if (!strarray_exists( &make
->extradllflags
, "-nodefaultlibs" ))
3131 imports
= add_default_imports( make
, imports
);
3133 strarray_addall( &all_libs
, add_import_libs( make
, &dep_libs
, make
->delayimports
, 1, make
->is_cross
));
3134 strarray_addall( &all_libs
, add_import_libs( make
, &dep_libs
, imports
, 0, make
->is_cross
));
3136 if (!make
->use_msvcrt
)
3138 strarray_addall( &all_libs
, get_expanded_make_var_array( make
, "EXTRALIBS" ));
3139 strarray_addall( &all_libs
, libs
);
3142 if (!make
->is_cross
&& *dll_ext
) delay_load
= "-Wl,-delayload,";
3145 for (i
= 0; i
< make
->delayimports
.count
; i
++)
3146 strarray_add( &all_libs
, strmake( "%s%s%s", delay_load
, make
->delayimports
.str
[i
],
3147 strchr( make
->delayimports
.str
[i
], '.' ) ? "" : ".dll" ));
3150 strarray_add( &make
->all_targets
, module_name
);
3152 if (make
->data_only
)
3153 add_install_rule( make
, make
->module
, module_name
,
3154 strmake( "d%s/%s", *dll_ext
? pe_dir
: "$(dlldir)", module_name
));
3155 else if (make
->is_cross
)
3156 add_install_rule( make
, make
->module
, module_name
, strmake( "c%s/%s", pe_dir
, module_name
));
3158 add_install_rule( make
, make
->module
, module_name
, strmake( "p%s/%s", so_dir
, module_name
));
3160 add_install_rule( make
, make
->module
, module_name
,
3161 strmake( "p$(%s)/%s", spec_file
? "dlldir" : "bindir", module_name
));
3163 output( "%s:", obj_dir_path( make
, module_name
));
3164 if (spec_file
) output_filename( spec_file
);
3165 output_filenames_obj_dir( make
, make
->is_cross
? make
->crossobj_files
: make
->object_files
);
3166 output_filenames_obj_dir( make
, make
->res_files
);
3167 output_filenames( dep_libs
);
3168 output_filename( tools_path( make
, "winebuild" ));
3169 output_filename( tools_path( make
, "winegcc" ));
3171 output_winegcc_command( make
, make
->is_cross
);
3172 if (make
->is_cross
) output_filename( "-Wl,--wine-builtin" );
3175 output_filename( "-shared" );
3176 output_filename( spec_file
);
3178 output_filenames( make
->extradllflags
);
3179 output_filenames_obj_dir( make
, make
->is_cross
? make
->crossobj_files
: make
->object_files
);
3180 output_filenames_obj_dir( make
, make
->res_files
);
3181 debug_file
= get_debug_file( make
, make
->module
);
3182 if (debug_file
) output_filename( strmake( "-Wl,--debug-file,%s", obj_dir_path( make
, debug_file
)));
3183 output_filenames( all_libs
);
3184 output_filename( make
->is_cross
? "$(CROSSLDFLAGS)" : "$(LDFLAGS)" );
3187 if (*dll_ext
&& make
->is_exe
&& !make
->is_win16
&& strendswith( make
->module
, ".exe" ))
3189 char *binary
= replace_extension( make
->module
, ".exe", "" );
3190 add_install_rule( make
, binary
, "wineapploader", strmake( "t$(bindir)/%s", binary
));
3195 /*******************************************************************
3196 * output_fake_module
3198 static void output_fake_module( struct makefile
*make
)
3200 char *spec_file
= NULL
;
3202 if (!make
->is_exe
) spec_file
= src_dir_path( make
, replace_extension( make
->module
, ".dll", ".spec" ));
3204 strarray_add( &make
->all_targets
, make
->module
);
3205 add_install_rule( make
, make
->module
, make
->module
, strmake( "d%s/%s", pe_dir
, make
->module
));
3207 output( "%s:", obj_dir_path( make
, make
->module
));
3208 if (spec_file
) output_filename( spec_file
);
3209 output_filenames_obj_dir( make
, make
->res_files
);
3210 output_filename( tools_path( make
, "winebuild" ));
3211 output_filename( tools_path( make
, "winegcc" ));
3213 output_winegcc_command( make
, make
->is_cross
);
3214 output_filename( "-Wb,--fake-module" );
3217 output_filename( "-shared" );
3218 output_filename( spec_file
);
3220 output_filenames( make
->extradllflags
);
3221 output_filenames_obj_dir( make
, make
->res_files
);
3226 /*******************************************************************
3229 static void output_import_lib( struct makefile
*make
)
3231 char *spec_file
= src_dir_path( make
, replace_extension( make
->module
, ".dll", ".spec" ));
3232 char *importlib_path
= obj_dir_path( make
, strmake( "lib%s", make
->importlib
));
3234 strarray_add( &make
->clean_files
, strmake( "lib%s.a", make
->importlib
));
3235 if (!*dll_ext
&& needs_delay_lib( make
))
3237 strarray_add( &make
->clean_files
, strmake( "lib%s.delay.a", make
->importlib
));
3238 output( "%s.delay.a ", importlib_path
);
3240 output( "%s.a: %s %s", importlib_path
, tools_path( make
, "winebuild" ), spec_file
);
3241 output_filenames_obj_dir( make
, make
->implib_files
);
3243 output( "\t%s%s -w --implib -o $@", cmd_prefix( "BUILD" ), tools_path( make
, "winebuild" ) );
3244 output_filenames( target_flags
);
3245 if (make
->is_win16
) output_filename( "-m16" );
3246 output_filename( "--export" );
3247 output_filename( spec_file
);
3248 output_filenames_obj_dir( make
, make
->implib_files
);
3250 add_install_rule( make
, make
->importlib
,
3251 strmake( "lib%s.a", make
->importlib
),
3252 strmake( "d%s/lib%s.a", so_dir
, make
->importlib
));
3256 strarray_add( &make
->clean_files
, strmake( "lib%s.cross.a", make
->importlib
));
3257 output_filename( strmake( "%s.cross.a", importlib_path
));
3258 if (needs_delay_lib( make
))
3260 strarray_add( &make
->clean_files
, strmake( "lib%s.delay.a", make
->importlib
));
3261 output_filename( strmake( "%s.delay.a", importlib_path
));
3263 output( ": %s %s", tools_path( make
, "winebuild" ), spec_file
);
3264 output_filenames_obj_dir( make
, make
->crossimplib_files
);
3266 output( "\t%s%s -b %s -w --implib -o $@", cmd_prefix( "BUILD" ),
3267 tools_path( make
, "winebuild" ), crosstarget
);
3268 if (make
->is_win16
) output_filename( "-m16" );
3269 output_filename( "--export" );
3270 output_filename( spec_file
);
3271 output_filenames_obj_dir( make
, make
->crossimplib_files
);
3273 add_install_rule( make
, make
->importlib
,
3274 strmake( "lib%s.cross.a", make
->importlib
),
3275 strmake( "d%s/lib%s.a", pe_dir
, make
->importlib
));
3280 /*******************************************************************
3283 static void output_unix_lib( struct makefile
*make
)
3285 struct strarray unix_libs
= empty_strarray
;
3286 struct strarray unix_deps
= empty_strarray
;
3287 char *spec_file
= src_dir_path( make
, replace_extension( make
->module
, ".dll", ".spec" ));
3289 if (!make
->native_unix_lib
)
3291 struct strarray unix_imports
= empty_strarray
;
3293 strarray_add( &unix_imports
, "ntdll" );
3294 strarray_add( &unix_deps
, obj_dir_path( top_makefile
, "dlls/ntdll/ntdll.so" ));
3295 strarray_add( &unix_imports
, "winecrt0" );
3296 if (spec_file
) strarray_add( &unix_deps
, spec_file
);
3298 strarray_addall( &unix_libs
, add_import_libs( make
, &unix_deps
, unix_imports
, 0, 0 ));
3299 strarray_addall( &unix_libs
, get_expanded_make_var_array( make
, "EXTRALIBS" ));
3300 strarray_addall( &unix_libs
, libs
);
3302 else unix_libs
= add_unix_libraries( make
, &unix_deps
);
3304 strarray_add( &make
->all_targets
, make
->unixlib
);
3305 add_install_rule( make
, make
->module
, make
->unixlib
, strmake( "p%s/%s", so_dir
, make
->unixlib
));
3306 output( "%s:", obj_dir_path( make
, make
->unixlib
));
3307 output_filenames_obj_dir( make
, make
->unixobj_files
);
3308 output_filenames( unix_deps
);
3310 if (make
->native_unix_lib
)
3313 output( "\t%s$(CC) -o $@", cmd_prefix( "CCLD" ));
3314 output_filenames( get_expanded_make_var_array( make
, "UNIXLDFLAGS" ));
3318 output_filename( tools_path( make
, "winebuild" ));
3319 output_filename( tools_path( make
, "winegcc" ));
3321 output_winegcc_command( make
, 0 );
3322 output_filename( "-munix" );
3323 output_filename( "-shared" );
3324 if (spec_file
) output_filename( spec_file
);
3326 output_filenames_obj_dir( make
, make
->unixobj_files
);
3327 output_filenames( unix_libs
);
3328 output_filename( "$(LDFLAGS)" );
3333 /*******************************************************************
3336 static void output_static_lib( struct makefile
*make
)
3338 if (!crosstarget
|| !make
->extlib
)
3340 strarray_add( &make
->clean_files
, make
->staticlib
);
3341 output( "%s: %s", obj_dir_path( make
, make
->staticlib
), tools_path( make
, "winebuild" ));
3342 output_filenames_obj_dir( make
, make
->object_files
);
3343 output_filenames_obj_dir( make
, make
->unixobj_files
);
3345 output( "\t%s%s -w --staticlib -o $@", cmd_prefix( "BUILD" ), tools_path( make
, "winebuild" ));
3346 output_filenames( target_flags
);
3347 output_filenames_obj_dir( make
, make
->object_files
);
3348 output_filenames_obj_dir( make
, make
->unixobj_files
);
3350 add_install_rule( make
, make
->staticlib
, make
->staticlib
,
3351 strmake( "d%s/%s", so_dir
, make
->staticlib
));
3355 char *name
= replace_extension( make
->staticlib
, ".a", ".cross.a" );
3357 strarray_add( &make
->clean_files
, name
);
3358 output( "%s: %s", obj_dir_path( make
, name
), tools_path( make
, "winebuild" ));
3359 output_filenames_obj_dir( make
, make
->crossobj_files
);
3361 output( "\t%s%s -b %s -w --staticlib -o $@", cmd_prefix( "BUILD" ),
3362 tools_path( make
, "winebuild" ), crosstarget
);
3363 output_filenames_obj_dir( make
, make
->crossobj_files
);
3366 add_install_rule( make
, make
->staticlib
, name
,
3367 strmake( "d%s/%s", pe_dir
, make
->staticlib
));
3372 /*******************************************************************
3375 static void output_shared_lib( struct makefile
*make
)
3379 struct strarray names
= get_shared_lib_names( make
->sharedlib
);
3380 struct strarray all_libs
= empty_strarray
;
3381 struct strarray dep_libs
= empty_strarray
;
3383 basename
= xstrdup( make
->sharedlib
);
3384 if ((p
= strchr( basename
, '.' ))) *p
= 0;
3386 strarray_addall( &dep_libs
, get_local_dependencies( make
, basename
, make
->in_files
));
3387 strarray_addall( &all_libs
, get_expanded_file_local_var( make
, basename
, "LDFLAGS" ));
3388 strarray_addall( &all_libs
, get_expanded_make_var_array( make
, "EXTRALIBS" ));
3389 strarray_addall( &all_libs
, libs
);
3391 output( "%s:", obj_dir_path( make
, make
->sharedlib
));
3392 output_filenames_obj_dir( make
, make
->object_files
);
3393 output_filenames( dep_libs
);
3395 output( "\t%s$(CC) -o $@", cmd_prefix( "CCLD" ));
3396 output_filenames_obj_dir( make
, make
->object_files
);
3397 output_filenames( all_libs
);
3398 output_filename( "$(LDFLAGS)" );
3400 add_install_rule( make
, make
->sharedlib
, make
->sharedlib
, strmake( "p%s/%s", so_dir
, make
->sharedlib
));
3401 for (i
= 1; i
< names
.count
; i
++)
3403 output( "%s: %s\n", obj_dir_path( make
, names
.str
[i
] ), obj_dir_path( make
, names
.str
[i
-1] ));
3404 output_symlink_rule( names
.str
[i
-1], obj_dir_path( make
, names
.str
[i
] ), 0 );
3405 add_install_rule( make
, names
.str
[i
], names
.str
[i
-1], strmake( "y%s/%s", so_dir
, names
.str
[i
] ));
3407 strarray_addall( &make
->all_targets
, names
);
3411 /*******************************************************************
3412 * output_test_module
3414 static void output_test_module( struct makefile
*make
)
3416 char *testmodule
= replace_extension( make
->testdll
, ".dll", "_test.exe" );
3417 char *stripped
= replace_extension( make
->testdll
, ".dll", "_test-stripped.exe" );
3418 char *testres
= replace_extension( make
->testdll
, ".dll", "_test.res" );
3419 struct strarray dep_libs
= empty_strarray
;
3420 struct strarray all_libs
= add_import_libs( make
, &dep_libs
, add_default_imports( make
, make
->imports
),
3421 0, make
->is_cross
);
3422 struct makefile
*parent
= get_parent_makefile( make
);
3423 const char *ext
= make
->is_cross
? "" : dll_ext
;
3424 const char *debug_file
;
3427 strarray_add( &make
->all_targets
, strmake( "%s%s", testmodule
, ext
));
3428 strarray_add( &make
->clean_files
, strmake( "%s%s", stripped
, ext
));
3429 output_file
= strmake( "%s%s", obj_dir_path( make
, testmodule
), ext
);
3430 output( "%s:\n", output_file
);
3431 output_winegcc_command( make
, make
->is_cross
);
3432 output_filenames( make
->extradllflags
);
3433 output_filenames_obj_dir( make
, make
->is_cross
? make
->crossobj_files
: make
->object_files
);
3434 output_filenames_obj_dir( make
, make
->res_files
);
3435 if ((debug_file
= get_debug_file( make
, testmodule
)))
3436 output_filename( strmake( "-Wl,--debug-file,%s", obj_dir_path( make
, debug_file
)));
3437 output_filenames( all_libs
);
3438 output_filename( make
->is_cross
? "$(CROSSLDFLAGS)" : "$(LDFLAGS)" );
3440 output( "%s%s:\n", obj_dir_path( make
, stripped
), ext
);
3441 output_winegcc_command( make
, make
->is_cross
);
3442 output_filename( "-s" );
3443 output_filename( strmake( "-Wb,-F,%s", testmodule
));
3444 output_filenames( make
->extradllflags
);
3445 output_filenames_obj_dir( make
, make
->is_cross
? make
->crossobj_files
: make
->object_files
);
3446 output_filenames_obj_dir( make
, make
->res_files
);
3447 output_filenames( all_libs
);
3448 output_filename( make
->is_cross
? "$(CROSSLDFLAGS)" : "$(LDFLAGS)" );
3450 output( "%s%s %s%s:", obj_dir_path( make
, testmodule
), ext
, obj_dir_path( make
, stripped
), ext
);
3451 output_filenames_obj_dir( make
, make
->is_cross
? make
->crossobj_files
: make
->object_files
);
3452 output_filenames_obj_dir( make
, make
->res_files
);
3453 output_filenames( dep_libs
);
3454 output_filename( tools_path( make
, "winebuild" ));
3455 output_filename( tools_path( make
, "winegcc" ));
3458 output( "programs/winetest/%s: %s%s\n", testres
, obj_dir_path( make
, stripped
), ext
);
3459 output( "\t%secho \"%s TESTRES \\\"%s%s\\\"\" | %s -u -o $@\n", cmd_prefix( "WRC" ),
3460 testmodule
, obj_dir_path( make
, stripped
), ext
, tools_path( make
, "wrc" ));
3462 output_filenames_obj_dir( make
, make
->ok_files
);
3463 output( ": %s%s", obj_dir_path( make
, testmodule
), ext
);
3466 output_filename( parent
->is_cross
? obj_dir_path( parent
, make
->testdll
)
3467 : strmake( "%s%s", obj_dir_path( parent
, make
->testdll
), dll_ext
));
3468 if (parent
->unixlib
) output_filename( obj_dir_path( parent
, parent
->unixlib
));
3471 output( "%s %s:", obj_dir_path( make
, "check" ), obj_dir_path( make
, "test" ));
3472 if (!make
->disabled
&& parent
&& !parent
->disabled
) output_filenames_obj_dir( make
, make
->ok_files
);
3474 strarray_add_uniq( &make
->phony_targets
, obj_dir_path( make
, "check" ));
3475 strarray_add_uniq( &make
->phony_targets
, obj_dir_path( make
, "test" ));
3476 output( "%s::\n", obj_dir_path( make
, "testclean" ));
3477 output( "\trm -f" );
3478 output_filenames_obj_dir( make
, make
->ok_files
);
3480 strarray_addall( &make
->clean_files
, make
->ok_files
);
3481 strarray_add_uniq( &make
->phony_targets
, obj_dir_path( make
, "testclean" ));
3485 /*******************************************************************
3488 static void output_programs( struct makefile
*make
)
3492 for (i
= 0; i
< make
->programs
.count
; i
++)
3494 char *program_installed
= NULL
;
3495 char *program
= strmake( "%s%s", make
->programs
.str
[i
], exe_ext
);
3496 struct strarray deps
= get_local_dependencies( make
, make
->programs
.str
[i
], make
->in_files
);
3497 struct strarray all_libs
= get_expanded_file_local_var( make
, make
->programs
.str
[i
], "LDFLAGS" );
3498 struct strarray objs
= get_expanded_file_local_var( make
, make
->programs
.str
[i
], "OBJS" );
3499 struct strarray symlinks
= get_expanded_file_local_var( make
, make
->programs
.str
[i
], "SYMLINKS" );
3501 if (!objs
.count
) objs
= make
->object_files
;
3502 if (!strarray_exists( &all_libs
, "-nodefaultlibs" ))
3504 strarray_addall( &all_libs
, get_expanded_make_var_array( make
, "EXTRALIBS" ));
3505 strarray_addall( &all_libs
, libs
);
3508 output( "%s:", obj_dir_path( make
, program
) );
3509 output_filenames_obj_dir( make
, objs
);
3510 output_filenames( deps
);
3512 output( "\t%s$(CC) -o $@", cmd_prefix( "CCLD" ));
3513 output_filenames_obj_dir( make
, objs
);
3514 output_filenames( all_libs
);
3515 output_filename( "$(LDFLAGS)" );
3517 strarray_add( &make
->all_targets
, program
);
3519 for (j
= 0; j
< symlinks
.count
; j
++)
3521 output( "%s: %s\n", obj_dir_path( make
, symlinks
.str
[j
] ), obj_dir_path( make
, program
));
3522 output_symlink_rule( program
, obj_dir_path( make
, symlinks
.str
[j
] ), 0 );
3524 strarray_addall( &make
->all_targets
, symlinks
);
3526 add_install_rule( make
, program
, program_installed
? program_installed
: program
,
3527 strmake( "p$(bindir)/%s", program
));
3528 for (j
= 0; j
< symlinks
.count
; j
++)
3529 add_install_rule( make
, symlinks
.str
[j
], program
,
3530 strmake( "y$(bindir)/%s%s", symlinks
.str
[j
], exe_ext
));
3535 /*******************************************************************
3538 static void output_subdirs( struct makefile
*make
)
3540 struct strarray all_targets
= empty_strarray
;
3541 struct strarray makefile_deps
= empty_strarray
;
3542 struct strarray clean_files
= empty_strarray
;
3543 struct strarray testclean_files
= empty_strarray
;
3544 struct strarray distclean_files
= empty_strarray
;
3545 struct strarray dependencies
= empty_strarray
;
3546 struct strarray install_lib_deps
= empty_strarray
;
3547 struct strarray install_dev_deps
= empty_strarray
;
3548 struct strarray tooldeps_deps
= empty_strarray
;
3549 struct strarray buildtest_deps
= empty_strarray
;
3552 strarray_addall( &clean_files
, make
->clean_files
);
3553 strarray_addall( &distclean_files
, make
->distclean_files
);
3554 strarray_addall( &all_targets
, make
->all_targets
);
3555 for (i
= 0; i
< subdirs
.count
; i
++)
3557 strarray_add( &makefile_deps
, src_dir_path( submakes
[i
], "Makefile.in" ));
3558 strarray_addall_uniq( &make
->phony_targets
, submakes
[i
]->phony_targets
);
3559 strarray_addall_uniq( &make
->uninstall_files
, submakes
[i
]->uninstall_files
);
3560 strarray_addall_uniq( &dependencies
, submakes
[i
]->dependencies
);
3561 strarray_addall_path( &clean_files
, submakes
[i
]->obj_dir
, submakes
[i
]->clean_files
);
3562 strarray_addall_path( &distclean_files
, submakes
[i
]->obj_dir
, submakes
[i
]->distclean_files
);
3563 strarray_addall_path( &make
->maintainerclean_files
, submakes
[i
]->obj_dir
, submakes
[i
]->maintainerclean_files
);
3564 strarray_addall_path( &testclean_files
, submakes
[i
]->obj_dir
, submakes
[i
]->ok_files
);
3565 strarray_addall_path( &make
->pot_files
, submakes
[i
]->obj_dir
, submakes
[i
]->pot_files
);
3567 if (submakes
[i
]->disabled
) continue;
3569 strarray_addall_path( &all_targets
, submakes
[i
]->obj_dir
, submakes
[i
]->all_targets
);
3570 strarray_addall_path( &all_targets
, submakes
[i
]->obj_dir
, submakes
[i
]->font_files
);
3571 if (!strcmp( submakes
[i
]->obj_dir
, "tools" ) || !strncmp( submakes
[i
]->obj_dir
, "tools/", 6 ))
3572 strarray_add( &tooldeps_deps
, obj_dir_path( submakes
[i
], "all" ));
3573 if (submakes
[i
]->testdll
)
3574 strarray_add( &buildtest_deps
, obj_dir_path( submakes
[i
], "all" ));
3575 if (submakes
[i
]->install_rules
[INSTALL_LIB
].count
)
3576 strarray_add( &install_lib_deps
, obj_dir_path( submakes
[i
], "install-lib" ));
3577 if (submakes
[i
]->install_rules
[INSTALL_DEV
].count
)
3578 strarray_add( &install_dev_deps
, obj_dir_path( submakes
[i
], "install-dev" ));
3580 strarray_addall( &dependencies
, makefile_deps
);
3582 output_filenames( all_targets
);
3584 output( "Makefile:" );
3585 output_filenames( makefile_deps
);
3587 output_filenames( dependencies
);
3589 if (install_lib_deps
.count
)
3591 output( "install install-lib::" );
3592 output_filenames( install_lib_deps
);
3594 strarray_add_uniq( &make
->phony_targets
, "install" );
3595 strarray_add_uniq( &make
->phony_targets
, "install-lib" );
3597 if (install_dev_deps
.count
)
3599 output( "install install-dev::" );
3600 output_filenames( install_dev_deps
);
3602 strarray_add_uniq( &make
->phony_targets
, "install" );
3603 strarray_add_uniq( &make
->phony_targets
, "install-dev" );
3605 output_uninstall_rules( make
);
3606 if (buildtest_deps
.count
)
3608 output( "buildtests:" );
3609 output_filenames( buildtest_deps
);
3611 strarray_add_uniq( &make
->phony_targets
, "buildtests" );
3613 output( "check test:" );
3614 output_filenames( testclean_files
);
3616 strarray_add_uniq( &make
->phony_targets
, "check" );
3617 strarray_add_uniq( &make
->phony_targets
, "test" );
3619 if (get_expanded_make_variable( make
, "GETTEXTPO_LIBS" )) output_po_files( make
);
3621 output( "clean::\n");
3622 output_rm_filenames( clean_files
);
3623 output( "testclean::\n");
3624 output_rm_filenames( testclean_files
);
3625 output( "distclean::\n");
3626 output_rm_filenames( distclean_files
);
3627 output( "maintainer-clean::\n");
3628 output_rm_filenames( make
->maintainerclean_files
);
3629 strarray_add_uniq( &make
->phony_targets
, "distclean" );
3630 strarray_add_uniq( &make
->phony_targets
, "testclean" );
3631 strarray_add_uniq( &make
->phony_targets
, "maintainer-clean" );
3633 if (tooldeps_deps
.count
)
3635 output( "__tooldeps__:" );
3636 output_filenames( tooldeps_deps
);
3638 strarray_add_uniq( &make
->phony_targets
, "__tooldeps__" );
3641 if (make
->phony_targets
.count
)
3643 output( ".PHONY:" );
3644 output_filenames( make
->phony_targets
);
3650 /*******************************************************************
3653 static void output_sources( struct makefile
*make
)
3655 struct strarray all_targets
= empty_strarray
;
3656 struct incl_file
*source
;
3659 strarray_add_uniq( &make
->phony_targets
, "all" );
3661 LIST_FOR_EACH_ENTRY( source
, &make
->sources
, struct incl_file
, entry
)
3663 char *obj
= xstrdup( source
->name
);
3664 char *ext
= get_extension( obj
);
3666 if (!ext
) fatal_error( "unsupported file type %s\n", source
->name
);
3669 for (j
= 0; output_source_funcs
[j
].ext
; j
++)
3670 if (!strcmp( ext
, output_source_funcs
[j
].ext
)) break;
3672 output_source_funcs
[j
].fn( make
, source
, obj
);
3673 strarray_addall_uniq( &make
->dependencies
, source
->dependencies
);
3676 /* special case for winetest: add resource files from other test dirs */
3677 if (make
->obj_dir
&& !strcmp( make
->obj_dir
, "programs/winetest" ))
3679 struct strarray tests
= enable_tests
;
3681 for (i
= 0; i
< subdirs
.count
; i
++)
3682 if (submakes
[i
]->testdll
&& !submakes
[i
]->disabled
)
3683 strarray_add( &tests
, submakes
[i
]->testdll
);
3684 for (i
= 0; i
< tests
.count
; i
++)
3685 strarray_add( &make
->res_files
, replace_extension( tests
.str
[i
], ".dll", "_test.res" ));
3688 if (make
->dlldata_files
.count
)
3690 output( "%s: %s %s\n", obj_dir_path( make
, "dlldata.c" ),
3691 tools_path( make
, "widl" ), src_dir_path( make
, "Makefile.in" ));
3692 output( "\t%s%s --dlldata-only -o $@", cmd_prefix( "WIDL" ), tools_path( make
, "widl" ));
3693 output_filenames( make
->dlldata_files
);
3697 if (make
->staticlib
) output_static_lib( make
);
3698 else if (make
->module
)
3700 output_module( make
);
3701 if (*dll_ext
&& !make
->is_cross
&& !make
->data_only
) output_fake_module( make
);
3702 if (make
->unixlib
) output_unix_lib( make
);
3703 if (make
->importlib
) output_import_lib( make
);
3705 else if (make
->testdll
) output_test_module( make
);
3706 else if (make
->sharedlib
) output_shared_lib( make
);
3707 else if (make
->programs
.count
) output_programs( make
);
3709 for (i
= 0; i
< make
->scripts
.count
; i
++)
3710 add_install_rule( make
, make
->scripts
.str
[i
], make
->scripts
.str
[i
],
3711 strmake( "S$(bindir)/%s", make
->scripts
.str
[i
] ));
3713 for (i
= 0; i
< make
->extra_targets
.count
; i
++)
3714 if (strarray_exists( &make
->dependencies
, obj_dir_path( make
, make
->extra_targets
.str
[i
] )))
3715 strarray_add( &make
->clean_files
, make
->extra_targets
.str
[i
] );
3717 strarray_add( &make
->all_targets
, make
->extra_targets
.str
[i
] );
3719 if (!make
->src_dir
) strarray_add( &make
->distclean_files
, ".gitignore" );
3720 strarray_add( &make
->distclean_files
, "Makefile" );
3721 if (make
->testdll
) strarray_add( &make
->distclean_files
, "testlist.c" );
3724 strarray_addall( &make
->distclean_files
, get_expanded_make_var_array( make
, "CONFIGURE_TARGETS" ));
3725 else if (!strcmp( make
->obj_dir
, "po" ))
3726 strarray_add( &make
->distclean_files
, "LINGUAS" );
3728 strarray_addall( &make
->clean_files
, make
->object_files
);
3729 strarray_addall( &make
->clean_files
, make
->crossobj_files
);
3730 strarray_addall( &make
->clean_files
, make
->implib_files
);
3731 strarray_addall( &make
->clean_files
, make
->crossimplib_files
);
3732 strarray_addall( &make
->clean_files
, make
->unixobj_files
);
3733 strarray_addall( &make
->clean_files
, make
->res_files
);
3734 strarray_addall( &make
->clean_files
, make
->pot_files
);
3735 strarray_addall( &make
->clean_files
, make
->debug_files
);
3736 strarray_addall( &make
->clean_files
, make
->all_targets
);
3738 if (make
== top_makefile
)
3740 output_subdirs( make
);
3744 strarray_addall( &all_targets
, make
->all_targets
);
3745 strarray_addall( &all_targets
, make
->font_files
);
3746 if (all_targets
.count
)
3748 output( "%s:", obj_dir_path( make
, "all" ));
3749 output_filenames_obj_dir( make
, all_targets
);
3751 strarray_add_uniq( &make
->phony_targets
, obj_dir_path( make
, "all" ));
3753 output_install_rules( make
, INSTALL_LIB
, "install-lib" );
3754 output_install_rules( make
, INSTALL_DEV
, "install-dev" );
3756 if (make
->clean_files
.count
)
3758 output( "%s::\n", obj_dir_path( make
, "clean" ));
3759 output( "\trm -f" );
3760 output_filenames_obj_dir( make
, make
->clean_files
);
3762 strarray_add( &make
->phony_targets
, obj_dir_path( make
, "clean" ));
3767 /*******************************************************************
3770 static FILE *create_temp_file( const char *orig
)
3772 char *name
= xmalloc( strlen(orig
) + 13 );
3773 unsigned int i
, id
= getpid();
3777 for (i
= 0; i
< 100; i
++)
3779 sprintf( name
, "%s.tmp%08x", orig
, id
);
3780 if ((fd
= open( name
, O_RDWR
| O_CREAT
| O_EXCL
, 0666 )) != -1)
3782 ret
= fdopen( fd
, "w" );
3785 if (errno
!= EEXIST
) break;
3788 if (!ret
) fatal_error( "failed to create output file for '%s'\n", orig
);
3789 temp_file_name
= name
;
3794 /*******************************************************************
3797 static void rename_temp_file( const char *dest
)
3799 int ret
= rename( temp_file_name
, dest
);
3800 if (ret
== -1 && errno
== EEXIST
)
3802 /* rename doesn't overwrite on windows */
3804 ret
= rename( temp_file_name
, dest
);
3806 if (ret
== -1) fatal_error( "failed to rename output file to '%s'\n", dest
);
3807 temp_file_name
= NULL
;
3811 /*******************************************************************
3812 * are_files_identical
3814 static int are_files_identical( FILE *file1
, FILE *file2
)
3818 char buffer1
[8192], buffer2
[8192];
3819 int size1
= fread( buffer1
, 1, sizeof(buffer1
), file1
);
3820 int size2
= fread( buffer2
, 1, sizeof(buffer2
), file2
);
3821 if (size1
!= size2
) return 0;
3822 if (!size1
) return feof( file1
) && feof( file2
);
3823 if (memcmp( buffer1
, buffer2
, size1
)) return 0;
3828 /*******************************************************************
3829 * rename_temp_file_if_changed
3831 static void rename_temp_file_if_changed( const char *dest
)
3833 FILE *file1
, *file2
;
3836 if ((file1
= fopen( dest
, "r" )))
3838 if ((file2
= fopen( temp_file_name
, "r" )))
3840 do_rename
= !are_files_identical( file1
, file2
);
3847 unlink( temp_file_name
);
3848 temp_file_name
= NULL
;
3850 else rename_temp_file( dest
);
3854 /*******************************************************************
3857 static void output_linguas( const struct makefile
*make
)
3859 const char *dest
= obj_dir_path( make
, "LINGUAS" );
3860 struct incl_file
*source
;
3862 output_file
= create_temp_file( dest
);
3864 output( "# Automatically generated by make depend; DO NOT EDIT!!\n" );
3865 LIST_FOR_EACH_ENTRY( source
, &make
->sources
, struct incl_file
, entry
)
3866 if (strendswith( source
->name
, ".po" ))
3867 output( "%s\n", replace_extension( source
->name
, ".po", "" ));
3869 if (fclose( output_file
)) fatal_perror( "write" );
3871 rename_temp_file_if_changed( dest
);
3875 /*******************************************************************
3878 static void output_testlist( const struct makefile
*make
)
3880 const char *dest
= obj_dir_path( make
, "testlist.c" );
3883 output_file
= create_temp_file( dest
);
3885 output( "/* Automatically generated by make depend; DO NOT EDIT!! */\n\n" );
3886 output( "#define WIN32_LEAN_AND_MEAN\n" );
3887 output( "#include <windows.h>\n\n" );
3888 output( "#define STANDALONE\n" );
3889 output( "#include \"wine/test.h\"\n\n" );
3891 for (i
= 0; i
< make
->test_files
.count
; i
++)
3892 output( "extern void func_%s(void);\n", make
->test_files
.str
[i
] );
3894 output( "const struct test winetest_testlist[] =\n" );
3896 for (i
= 0; i
< make
->test_files
.count
; i
++)
3897 output( " { \"%s\", func_%s },\n", make
->test_files
.str
[i
], make
->test_files
.str
[i
] );
3898 output( " { 0, 0 }\n" );
3901 if (fclose( output_file
)) fatal_perror( "write" );
3903 rename_temp_file_if_changed( dest
);
3907 /*******************************************************************
3910 static void output_gitignore( const char *dest
, struct strarray files
)
3914 output_file
= create_temp_file( dest
);
3916 output( "# Automatically generated by make depend; DO NOT EDIT!!\n" );
3917 for (i
= 0; i
< files
.count
; i
++)
3919 if (!strchr( files
.str
[i
], '/' )) output( "/" );
3920 output( "%s\n", files
.str
[i
] );
3923 if (fclose( output_file
)) fatal_perror( "write" );
3925 rename_temp_file( dest
);
3929 /*******************************************************************
3930 * output_stub_makefile
3932 static void output_stub_makefile( struct makefile
*make
)
3934 struct strarray targets
= empty_strarray
;
3935 const char *make_var
= strarray_get_value( &top_makefile
->vars
, "MAKE" );
3937 if (make
->obj_dir
) create_dir( make
->obj_dir
);
3939 output_file_name
= obj_dir_path( make
, "Makefile" );
3940 output_file
= create_temp_file( output_file_name
);
3942 output( "# Auto-generated stub makefile; all rules forward to the top-level makefile\n\n" );
3944 if (make_var
) output( "MAKE = %s\n\n", make_var
);
3947 if (make
->all_targets
.count
) strarray_add( &targets
, "all" );
3948 if (make
->install_rules
[INSTALL_LIB
].count
|| make
->install_rules
[INSTALL_DEV
].count
)
3949 strarray_add( &targets
, "install" );
3950 if (make
->install_rules
[INSTALL_LIB
].count
) strarray_add( &targets
, "install-lib" );
3951 if (make
->install_rules
[INSTALL_DEV
].count
) strarray_add( &targets
, "install-dev" );
3952 if (make
->clean_files
.count
) strarray_add( &targets
, "clean" );
3953 if (make
->test_files
.count
)
3955 strarray_add( &targets
, "check" );
3956 strarray_add( &targets
, "test" );
3957 strarray_add( &targets
, "testclean" );
3960 output_filenames( targets
);
3961 output_filenames( make
->clean_files
);
3963 output( "\t@cd %s && $(MAKE) %s/$@\n", get_relative_path( make
->obj_dir
, "" ), make
->obj_dir
);
3964 output( ".PHONY:" );
3965 output_filenames( targets
);
3968 fclose( output_file
);
3970 rename_temp_file( output_file_name
);
3974 /*******************************************************************
3975 * output_silent_rules
3977 static void output_silent_rules(void)
3979 static const char *cmds
[] =
3997 output( "V = 0\n" );
3998 for (i
= 0; i
< sizeof(cmds
) / sizeof(cmds
[0]); i
++)
4000 output( "quiet_%s = $(quiet_%s_$(V))\n", cmds
[i
], cmds
[i
] );
4001 output( "quiet_%s_0 = @echo \" %-5s \" $@;\n", cmds
[i
], cmds
[i
] );
4002 output( "quiet_%s_1 =\n", cmds
[i
] );
4007 /*******************************************************************
4008 * output_top_makefile
4010 static void output_top_makefile( struct makefile
*make
)
4017 output_file_name
= obj_dir_path( make
, output_makefile_name
);
4018 output_file
= create_temp_file( output_file_name
);
4020 /* copy the contents of the source makefile */
4021 src_file
= open_input_makefile( make
);
4022 while (fgets( buffer
, sizeof(buffer
), src_file
) && !found
)
4024 if (fwrite( buffer
, 1, strlen(buffer
), output_file
) != strlen(buffer
)) fatal_perror( "write" );
4025 found
= !strncmp( buffer
, separator
, strlen(separator
) );
4027 if (fclose( src_file
)) fatal_perror( "close" );
4028 input_file_name
= NULL
;
4030 if (!found
) output( "\n%s (everything below this line is auto-generated; DO NOT EDIT!!)\n", separator
);
4032 if (silent_rules
) output_silent_rules();
4033 for (i
= 0; i
< subdirs
.count
; i
++) output_sources( submakes
[i
] );
4034 output_sources( make
);
4035 /* disable implicit rules */
4036 output( ".SUFFIXES:\n" );
4038 fclose( output_file
);
4040 rename_temp_file( output_file_name
);
4044 /*******************************************************************
4045 * output_dependencies
4047 static void output_dependencies( struct makefile
*make
)
4049 struct strarray ignore_files
= empty_strarray
;
4051 if (make
->obj_dir
) create_dir( make
->obj_dir
);
4053 if (make
== top_makefile
) output_top_makefile( make
);
4054 else output_stub_makefile( make
);
4056 strarray_addall( &ignore_files
, make
->distclean_files
);
4057 strarray_addall( &ignore_files
, make
->clean_files
);
4058 if (make
->testdll
) output_testlist( make
);
4059 if (make
->obj_dir
&& !strcmp( make
->obj_dir
, "po" )) output_linguas( make
);
4060 if (!make
->src_dir
) output_gitignore( obj_dir_path( make
, ".gitignore" ), ignore_files
);
4062 create_file_directories( make
, ignore_files
);
4064 output_file_name
= NULL
;
4068 /*******************************************************************
4071 static void load_sources( struct makefile
*make
)
4073 static const char *source_vars
[] =
4094 struct strarray value
;
4095 struct incl_file
*file
;
4097 strarray_set_value( &make
->vars
, "top_srcdir", root_src_dir_path( "" ));
4098 strarray_set_value( &make
->vars
, "srcdir", src_dir_path( make
, "" ));
4100 make
->parent_dir
= get_expanded_make_variable( make
, "PARENTSRC" );
4101 make
->module
= get_expanded_make_variable( make
, "MODULE" );
4102 make
->testdll
= get_expanded_make_variable( make
, "TESTDLL" );
4103 make
->sharedlib
= get_expanded_make_variable( make
, "SHAREDLIB" );
4104 make
->staticlib
= get_expanded_make_variable( make
, "STATICLIB" );
4105 make
->importlib
= get_expanded_make_variable( make
, "IMPORTLIB" );
4106 make
->extlib
= get_expanded_make_variable( make
, "EXTLIB" );
4107 if (*dll_ext
) make
->unixlib
= get_expanded_make_variable( make
, "UNIXLIB" );
4109 make
->programs
= get_expanded_make_var_array( make
, "PROGRAMS" );
4110 make
->scripts
= get_expanded_make_var_array( make
, "SCRIPTS" );
4111 make
->imports
= get_expanded_make_var_array( make
, "IMPORTS" );
4112 make
->delayimports
= get_expanded_make_var_array( make
, "DELAYIMPORTS" );
4113 make
->extradllflags
= get_expanded_make_var_array( make
, "EXTRADLLFLAGS" );
4114 make
->install_lib
= get_expanded_make_var_array( make
, "INSTALL_LIB" );
4115 make
->install_dev
= get_expanded_make_var_array( make
, "INSTALL_DEV" );
4116 make
->extra_targets
= get_expanded_make_var_array( make
, "EXTRA_TARGETS" );
4118 if (make
->extlib
) make
->staticlib
= make
->extlib
;
4119 if (make
->staticlib
) make
->module
= make
->staticlib
;
4123 value
= get_expanded_file_local_var( make
, host_cpu
, "EXTRADLLFLAGS" );
4124 if (value
.count
) make
->extradllflags
= value
;
4127 make
->disabled
= make
->obj_dir
&& strarray_exists( &disabled_dirs
, make
->obj_dir
);
4128 make
->is_win16
= strarray_exists( &make
->extradllflags
, "-m16" );
4129 make
->data_only
= strarray_exists( &make
->extradllflags
, "-Wb,--data-only" );
4130 make
->use_msvcrt
= (make
->module
|| make
->testdll
|| make
->is_win16
) &&
4131 !strarray_exists( &make
->extradllflags
, "-mcygwin" );
4132 make
->is_exe
= strarray_exists( &make
->extradllflags
, "-mconsole" ) ||
4133 strarray_exists( &make
->extradllflags
, "-mwindows" );
4134 make
->native_unix_lib
= !!make
->unixlib
;
4136 if (make
->use_msvcrt
) strarray_add_uniq( &make
->extradllflags
, "-mno-cygwin" );
4138 if (make
->module
&& !make
->install_lib
.count
&& !make
->install_dev
.count
)
4140 if (make
->importlib
) strarray_add( &make
->install_dev
, make
->importlib
);
4141 if (make
->staticlib
) strarray_add( &make
->install_dev
, make
->staticlib
);
4142 else strarray_add( &make
->install_lib
, make
->module
);
4145 make
->include_paths
= empty_strarray
;
4146 make
->include_args
= empty_strarray
;
4147 make
->define_args
= empty_strarray
;
4148 if (!make
->extlib
) strarray_add( &make
->define_args
, "-D__WINESRC__" );
4150 value
= get_expanded_make_var_array( make
, "EXTRAINCL" );
4151 for (i
= 0; i
< value
.count
; i
++)
4152 if (!strncmp( value
.str
[i
], "-I", 2 ))
4153 strarray_add_uniq( &make
->include_paths
, value
.str
[i
] + 2 );
4154 else if (!strncmp( value
.str
[i
], "-D", 2 ) || !strncmp( value
.str
[i
], "-U", 2 ))
4155 strarray_add_uniq( &make
->define_args
, value
.str
[i
] );
4156 strarray_addall( &make
->define_args
, get_expanded_make_var_array( make
, "EXTRADEFS" ));
4158 strarray_add( &make
->include_args
, strmake( "-I%s", obj_dir_path( make
, "" )));
4160 strarray_add( &make
->include_args
, strmake( "-I%s", make
->src_dir
));
4161 if (make
->parent_dir
)
4162 strarray_add( &make
->include_args
, strmake( "-I%s", src_dir_path( make
, make
->parent_dir
)));
4163 strarray_add( &make
->include_args
, "-Iinclude" );
4164 if (root_src_dir
) strarray_add( &make
->include_args
, strmake( "-I%s", root_src_dir_path( "include" )));
4166 list_init( &make
->sources
);
4167 list_init( &make
->includes
);
4169 for (var
= source_vars
; *var
; var
++)
4171 value
= get_expanded_make_var_array( make
, *var
);
4172 for (i
= 0; i
< value
.count
; i
++) add_src_file( make
, value
.str
[i
] );
4175 add_generated_sources( make
);
4176 if (!make
->unixlib
) make
->unixlib
= get_unix_lib_name( make
);
4178 if (make
->use_msvcrt
) strarray_add( &make
->define_args
, get_crt_define( make
));
4180 LIST_FOR_EACH_ENTRY( file
, &make
->includes
, struct incl_file
, entry
) parse_file( make
, file
, 0 );
4181 LIST_FOR_EACH_ENTRY( file
, &make
->sources
, struct incl_file
, entry
) get_dependencies( file
, file
);
4183 make
->is_cross
= crosstarget
&& make
->use_msvcrt
;
4185 if (!*dll_ext
|| make
->is_cross
)
4186 for (i
= 0; i
< make
->delayimports
.count
; i
++)
4187 strarray_add_uniq( &delay_import_libs
, get_base_name( make
->delayimports
.str
[i
] ));
4191 /*******************************************************************
4194 static void parse_makeflags( const char *flags
)
4196 const char *p
= flags
;
4197 char *var
, *buffer
= xmalloc( strlen(flags
) + 1 );
4201 while (isspace(*p
)) p
++;
4203 while (*p
&& !isspace(*p
))
4205 if (*p
== '\\' && p
[1]) p
++;
4209 if (var
> buffer
) set_make_variable( &cmdline_vars
, buffer
);
4214 /*******************************************************************
4217 static int parse_option( const char *opt
)
4221 if (strchr( opt
, '=' )) return set_make_variable( &cmdline_vars
, opt
);
4227 if (opt
[2]) output_makefile_name
= opt
+ 2;
4230 relative_dir_mode
= 1;
4236 fprintf( stderr
, "Unknown option '%s'\n%s", opt
, Usage
);
4243 /*******************************************************************
4246 int main( int argc
, char *argv
[] )
4248 const char *makeflags
= getenv( "MAKEFLAGS" );
4251 if (makeflags
) parse_makeflags( makeflags
);
4256 if (parse_option( argv
[i
] ))
4258 for (j
= i
; j
< argc
; j
++) argv
[j
] = argv
[j
+1];
4264 if (relative_dir_mode
)
4270 fprintf( stderr
, "Option -R needs two directories\n%s", Usage
);
4273 relpath
= get_relative_path( argv
[1], argv
[2] );
4274 printf( "%s\n", relpath
? relpath
: "." );
4278 if (argc
> 1) fatal_error( "Directory arguments not supported in this mode\n" );
4280 atexit( cleanup_files
);
4281 signal( SIGTERM
, exit_on_signal
);
4282 signal( SIGINT
, exit_on_signal
);
4284 signal( SIGHUP
, exit_on_signal
);
4287 for (i
= 0; i
< HASH_SIZE
; i
++) list_init( &files
[i
] );
4289 top_makefile
= parse_makefile( NULL
);
4291 target_flags
= get_expanded_make_var_array( top_makefile
, "TARGETFLAGS" );
4292 msvcrt_flags
= get_expanded_make_var_array( top_makefile
, "MSVCRTFLAGS" );
4293 dll_flags
= get_expanded_make_var_array( top_makefile
, "DLLFLAGS" );
4294 extra_cflags
= get_expanded_make_var_array( top_makefile
, "EXTRACFLAGS" );
4295 extra_cross_cflags
= get_expanded_make_var_array( top_makefile
, "EXTRACROSSCFLAGS" );
4296 unix_dllflags
= get_expanded_make_var_array( top_makefile
, "UNIXDLLFLAGS" );
4297 cpp_flags
= get_expanded_make_var_array( top_makefile
, "CPPFLAGS" );
4298 lddll_flags
= get_expanded_make_var_array( top_makefile
, "LDDLLFLAGS" );
4299 libs
= get_expanded_make_var_array( top_makefile
, "LIBS" );
4300 enable_tests
= get_expanded_make_var_array( top_makefile
, "ENABLE_TESTS" );
4301 top_install_lib
= get_expanded_make_var_array( top_makefile
, "TOP_INSTALL_LIB" );
4302 top_install_dev
= get_expanded_make_var_array( top_makefile
, "TOP_INSTALL_DEV" );
4304 delay_load_flag
= get_expanded_make_variable( top_makefile
, "DELAYLOADFLAG" );
4305 root_src_dir
= get_expanded_make_variable( top_makefile
, "srcdir" );
4306 tools_dir
= get_expanded_make_variable( top_makefile
, "toolsdir" );
4307 tools_ext
= get_expanded_make_variable( top_makefile
, "toolsext" );
4308 exe_ext
= get_expanded_make_variable( top_makefile
, "EXEEXT" );
4309 dll_ext
= (exe_ext
&& !strcmp( exe_ext
, ".exe" )) ? "" : ".so";
4310 host_cpu
= get_expanded_make_variable( top_makefile
, "host_cpu" );
4311 crosstarget
= get_expanded_make_variable( top_makefile
, "CROSSTARGET" );
4312 crossdebug
= get_expanded_make_variable( top_makefile
, "CROSSDEBUG" );
4313 fontforge
= get_expanded_make_variable( top_makefile
, "FONTFORGE" );
4314 convert
= get_expanded_make_variable( top_makefile
, "CONVERT" );
4315 flex
= get_expanded_make_variable( top_makefile
, "FLEX" );
4316 bison
= get_expanded_make_variable( top_makefile
, "BISON" );
4317 ar
= get_expanded_make_variable( top_makefile
, "AR" );
4318 ranlib
= get_expanded_make_variable( top_makefile
, "RANLIB" );
4319 rsvg
= get_expanded_make_variable( top_makefile
, "RSVG" );
4320 icotool
= get_expanded_make_variable( top_makefile
, "ICOTOOL" );
4321 dlltool
= get_expanded_make_variable( top_makefile
, "DLLTOOL" );
4322 msgfmt
= get_expanded_make_variable( top_makefile
, "MSGFMT" );
4323 sed_cmd
= get_expanded_make_variable( top_makefile
, "SED_CMD" );
4324 ln_s
= get_expanded_make_variable( top_makefile
, "LN_S" );
4326 if (root_src_dir
&& !strcmp( root_src_dir
, "." )) root_src_dir
= NULL
;
4327 if (tools_dir
&& !strcmp( tools_dir
, "." )) tools_dir
= NULL
;
4328 if (!exe_ext
) exe_ext
= "";
4329 if (!tools_ext
) tools_ext
= "";
4330 if (host_cpu
&& (host_cpu
= normalize_arch( host_cpu
)))
4332 so_dir
= strmake( "$(dlldir)/%s-unix", host_cpu
);
4333 pe_dir
= strmake( "$(dlldir)/%s-windows", host_cpu
);
4336 so_dir
= pe_dir
= "$(dlldir)";
4338 extra_cflags_extlib
= remove_warning_flags( extra_cflags
);
4339 extra_cross_cflags_extlib
= remove_warning_flags( extra_cross_cflags
);
4341 top_makefile
->src_dir
= root_src_dir
;
4342 subdirs
= get_expanded_make_var_array( top_makefile
, "SUBDIRS" );
4343 disabled_dirs
= get_expanded_make_var_array( top_makefile
, "DISABLED_SUBDIRS" );
4344 submakes
= xmalloc( subdirs
.count
* sizeof(*submakes
) );
4346 for (i
= 0; i
< subdirs
.count
; i
++) submakes
[i
] = parse_makefile( subdirs
.str
[i
] );
4348 load_sources( top_makefile
);
4349 for (i
= 0; i
< subdirs
.count
; i
++) load_sources( submakes
[i
] );
4351 output_dependencies( top_makefile
);
4352 for (i
= 0; i
< subdirs
.count
; i
++) output_dependencies( submakes
[i
] );