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
31 #include <sys/types.h>
35 #include "wine/list.h"
39 INCL_NORMAL
, /* #include "foo.h" */
40 INCL_SYSTEM
, /* #include <foo.h> */
41 INCL_IMPORT
, /* idl import "foo.idl" */
42 INCL_IMPORTLIB
, /* idl importlib "foo.tlb" */
43 INCL_CPP_QUOTE
, /* idl cpp_quote("#include \"foo.h\"") */
44 INCL_CPP_QUOTE_SYSTEM
/* idl cpp_quote("#include <foo.h>") */
49 int line
; /* source line where this header is included */
50 enum incl_type type
; /* type of include */
51 char *name
; /* header name */
57 char *name
; /* full file name relative to cwd */
58 void *args
; /* custom arguments for makefile rule */
59 unsigned int flags
; /* flags (see below) */
60 unsigned int deps_count
; /* files in use */
61 unsigned int deps_size
; /* total allocated size */
62 struct dependency
*deps
; /* all header dependencies */
68 struct list hash_entry
;
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 unsigned int arch
; /* architecture for multi-arch files, otherwise 0 */
78 unsigned int use_msvcrt
:1; /* put msvcrt headers in the search path? */
79 unsigned int is_external
:1; /* file from external library? */
80 struct incl_file
*owner
;
81 unsigned int files_count
; /* files in use */
82 unsigned int files_size
; /* total allocated size */
83 struct incl_file
**files
;
84 struct strarray dependencies
; /* file dependencies */
85 struct strarray importlibdeps
; /* importlib dependencies */
88 #define FLAG_GENERATED 0x000001 /* generated file */
89 #define FLAG_INSTALL 0x000002 /* file to install */
90 #define FLAG_IDL_PROXY 0x000100 /* generates a proxy (_p.c) file */
91 #define FLAG_IDL_CLIENT 0x000200 /* generates a client (_c.c) file */
92 #define FLAG_IDL_SERVER 0x000400 /* generates a server (_s.c) file */
93 #define FLAG_IDL_IDENT 0x000800 /* generates an ident (_i.c) file */
94 #define FLAG_IDL_REGISTER 0x001000 /* generates a registration (_r.res) file */
95 #define FLAG_IDL_TYPELIB 0x002000 /* generates a typelib (_l.res) file */
96 #define FLAG_IDL_REGTYPELIB 0x004000 /* generates a registered typelib (_t.res) file */
97 #define FLAG_IDL_HEADER 0x008000 /* generates a header (.h) file */
98 #define FLAG_RC_PO 0x010000 /* rc file contains translations */
99 #define FLAG_RC_HEADER 0x020000 /* rc file is a header */
100 #define FLAG_C_IMPLIB 0x040000 /* file is part of an import library */
101 #define FLAG_C_UNIX 0x080000 /* file is part of a Unix library */
102 #define FLAG_SFD_FONTS 0x100000 /* sfd file generated bitmap fonts */
110 { FLAG_IDL_TYPELIB
, "_l.res" },
111 { FLAG_IDL_REGTYPELIB
, "_t.res" },
112 { FLAG_IDL_CLIENT
, "_c.c" },
113 { FLAG_IDL_IDENT
, "_i.c" },
114 { FLAG_IDL_PROXY
, "_p.c" },
115 { FLAG_IDL_SERVER
, "_s.c" },
116 { FLAG_IDL_REGISTER
, "_r.res" },
119 #define HASH_SIZE 197
121 static struct list files
[HASH_SIZE
];
122 static struct list global_includes
[HASH_SIZE
];
124 enum install_rules
{ INSTALL_LIB
, INSTALL_DEV
, INSTALL_TEST
, NB_INSTALL_RULES
};
125 static const char *install_targets
[NB_INSTALL_RULES
] = { "install-lib", "install-dev", "install-test" };
126 static const char *install_variables
[NB_INSTALL_RULES
] = { "INSTALL_LIB", "INSTALL_DEV", "INSTALL_TEST" };
130 /* variables common to all makefiles */
131 static struct strarray archs
;
132 static struct strarray linguas
;
133 static struct strarray dll_flags
;
134 static struct strarray unix_dllflags
;
135 static struct strarray msvcrt_flags
;
136 static struct strarray cpp_flags
;
137 static struct strarray lddll_flags
;
138 static struct strarray libs
;
139 static struct strarray enable_tests
;
140 static struct strarray cmdline_vars
;
141 static struct strarray subdirs
;
142 static struct strarray delay_import_libs
;
143 static struct strarray top_install
[NB_INSTALL_RULES
];
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 *fontforge
;
149 static const char *convert
;
150 static const char *flex
;
151 static const char *bison
;
152 static const char *ar
;
153 static const char *ranlib
;
154 static const char *rsvg
;
155 static const char *icotool
;
156 static const char *msgfmt
;
157 static const char *ln_s
;
158 static const char *sed_cmd
;
159 static const char *wayland_scanner
;
160 static int so_dll_supported
;
161 static int unix_lib_supported
;
162 /* per-architecture global variables */
163 static const char *dll_ext
[MAX_ARCHS
];
164 static const char *arch_dirs
[MAX_ARCHS
];
165 static const char *arch_pe_dirs
[MAX_ARCHS
];
166 static const char *arch_install_dirs
[MAX_ARCHS
];
167 static const char *strip_progs
[MAX_ARCHS
];
168 static const char *debug_flags
[MAX_ARCHS
];
169 static const char *delay_load_flags
[MAX_ARCHS
];
170 static struct strarray target_flags
[MAX_ARCHS
];
171 static struct strarray extra_cflags
[MAX_ARCHS
];
172 static struct strarray extra_cflags_extlib
[MAX_ARCHS
];
173 static struct strarray disabled_dirs
[MAX_ARCHS
];
177 /* values determined from input makefile */
178 struct strarray vars
;
179 struct strarray include_paths
;
180 struct strarray include_args
;
181 struct strarray define_args
;
182 struct strarray unix_cflags
;
183 struct strarray programs
;
184 struct strarray scripts
;
185 struct strarray imports
;
186 struct strarray delayimports
;
187 struct strarray extradllflags
;
188 struct strarray install
[NB_INSTALL_RULES
];
189 struct strarray extra_targets
;
190 struct strarray extra_imports
;
192 struct list includes
;
195 const char *parent_dir
;
199 const char *staticlib
;
200 const char *importlib
;
205 int disabled
[MAX_ARCHS
];
207 /* values generated at output time */
208 struct strarray in_files
;
209 struct strarray pot_files
;
210 struct strarray test_files
;
211 struct strarray clean_files
;
212 struct strarray distclean_files
;
213 struct strarray maintainerclean_files
;
214 struct strarray uninstall_files
;
215 struct strarray unixobj_files
;
216 struct strarray font_files
;
217 struct strarray debug_files
;
218 struct strarray dlldata_files
;
219 struct strarray phony_targets
;
220 struct strarray dependencies
;
221 struct strarray object_files
[MAX_ARCHS
];
222 struct strarray implib_files
[MAX_ARCHS
];
223 struct strarray ok_files
[MAX_ARCHS
];
224 struct strarray res_files
[MAX_ARCHS
];
225 struct strarray all_targets
[MAX_ARCHS
];
226 struct strarray install_rules
[NB_INSTALL_RULES
];
229 static struct makefile
*top_makefile
;
230 static struct makefile
*include_makefile
;
231 static struct makefile
**submakes
;
233 static const char separator
[] = "### Dependencies";
234 static const char *output_makefile_name
= "Makefile";
235 static const char *input_file_name
;
236 static const char *output_file_name
;
237 static const char *temp_file_name
;
238 static int relative_dir_mode
;
239 static int silent_rules
;
240 static int input_line
;
241 static int output_column
;
242 static FILE *output_file
;
244 static const char Usage
[] =
245 "Usage: makedep [options] [directories]\n"
247 " -R from to Compute the relative path between two directories\n"
248 " -S Generate Automake-style silent rules\n"
249 " -fxxx Store output in file 'xxx' (default: Makefile)\n";
252 static void fatal_error( const char *msg
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
253 static void fatal_perror( const char *msg
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
254 static void output( const char *format
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
255 static char *strmake( const char* fmt
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
257 /*******************************************************************
260 static void fatal_error( const char *msg
, ... )
263 va_start( valist
, msg
);
266 fprintf( stderr
, "%s:", input_file_name
);
267 if (input_line
) fprintf( stderr
, "%d:", input_line
);
268 fprintf( stderr
, " error: " );
270 else fprintf( stderr
, "makedep: error: " );
271 vfprintf( stderr
, msg
, valist
);
277 /*******************************************************************
280 static void fatal_perror( const char *msg
, ... )
283 va_start( valist
, msg
);
286 fprintf( stderr
, "%s:", input_file_name
);
287 if (input_line
) fprintf( stderr
, "%d:", input_line
);
288 fprintf( stderr
, " error: " );
290 else fprintf( stderr
, "makedep: error: " );
291 vfprintf( stderr
, msg
, valist
);
298 /*******************************************************************
301 static void cleanup_files(void)
303 if (temp_file_name
) unlink( temp_file_name
);
304 if (output_file_name
) unlink( output_file_name
);
308 /*******************************************************************
311 static void exit_on_signal( int sig
)
313 exit( 1 ); /* this will call the atexit functions */
317 /*******************************************************************
320 static void output( const char *format
, ... )
325 va_start( valist
, format
);
326 ret
= vfprintf( output_file
, format
, valist
);
328 if (ret
< 0) fatal_perror( "output" );
329 if (format
[0] && format
[strlen(format
) - 1] == '\n') output_column
= 0;
330 else output_column
+= ret
;
334 /*******************************************************************
337 * Find a value in a name/value pair string array.
339 static const char *strarray_get_value( const struct strarray
*array
, const char *name
)
341 int pos
, res
, min
= 0, max
= array
->count
/ 2 - 1;
345 pos
= (min
+ max
) / 2;
346 if (!(res
= strcmp( array
->str
[pos
* 2], name
))) return array
->str
[pos
* 2 + 1];
347 if (res
< 0) min
= pos
+ 1;
354 /*******************************************************************
357 * Define a value in a name/value pair string array.
359 static void strarray_set_value( struct strarray
*array
, const char *name
, const char *value
)
361 int i
, pos
, res
, min
= 0, max
= array
->count
/ 2 - 1;
365 pos
= (min
+ max
) / 2;
366 if (!(res
= strcmp( array
->str
[pos
* 2], name
)))
368 /* redefining a variable replaces the previous value */
369 array
->str
[pos
* 2 + 1] = value
;
372 if (res
< 0) min
= pos
+ 1;
375 strarray_add( array
, NULL
);
376 strarray_add( array
, NULL
);
377 for (i
= array
->count
- 1; i
> min
* 2 + 1; i
--) array
->str
[i
] = array
->str
[i
- 2];
378 array
->str
[min
* 2] = name
;
379 array
->str
[min
* 2 + 1] = value
;
383 /*******************************************************************
386 static void output_filename( const char *name
)
388 if (output_column
+ strlen(name
) + 1 > 100)
393 else if (output_column
) output( " " );
394 output( "%s", name
);
398 /*******************************************************************
401 static void output_filenames( struct strarray array
)
405 for (i
= 0; i
< array
.count
; i
++) output_filename( array
.str
[i
] );
409 /*******************************************************************
410 * output_rm_filenames
412 static void output_rm_filenames( struct strarray array
, const char *command
)
414 static const unsigned int max_cmdline
= 30000; /* to be on the safe side */
417 if (!array
.count
) return;
418 output( "\t%s", command
);
419 for (i
= len
= 0; i
< array
.count
; i
++)
421 if (len
> max_cmdline
)
424 output( "\t%s", command
);
427 output_filename( array
.str
[i
] );
428 len
+= strlen( array
.str
[i
] ) + 1;
434 /*******************************************************************
437 static char *get_extension( char *filename
)
439 char *ext
= strrchr( filename
, '.' );
440 if (ext
&& strchr( ext
, '/' )) ext
= NULL
;
445 /*******************************************************************
448 static const char *get_base_name( const char *name
)
451 if (!strchr( name
, '.' )) return name
;
452 base
= xstrdup( name
);
453 *strrchr( base
, '.' ) = 0;
458 /*******************************************************************
461 static char *replace_filename( const char *path
, const char *name
)
467 if (!path
) return xstrdup( name
);
468 if (!(p
= strrchr( path
, '/' ))) return xstrdup( name
);
470 ret
= xmalloc( len
+ strlen( name
) + 1 );
471 memcpy( ret
, path
, len
);
472 strcpy( ret
+ len
, name
);
477 /*******************************************************************
480 static char *replace_substr( const char *str
, const char *start
, size_t len
, const char *replace
)
482 size_t pos
= start
- str
;
483 char *ret
= xmalloc( pos
+ strlen(replace
) + strlen(start
+ len
) + 1 );
484 memcpy( ret
, str
, pos
);
485 strcpy( ret
+ pos
, replace
);
486 strcat( ret
+ pos
, start
+ len
);
491 /*******************************************************************
494 * Determine where the destination path is located relative to the 'from' path.
496 static char *get_relative_path( const char *from
, const char *dest
)
500 unsigned int dotdots
= 0;
502 /* a path of "." is equivalent to an empty path */
503 if (!strcmp( from
, "." )) from
= "";
507 while (*from
== '/') from
++;
508 while (*dest
== '/') dest
++;
509 start
= dest
; /* save start of next path element */
512 while (*from
&& *from
!= '/' && *from
== *dest
) { from
++; dest
++; }
513 if ((!*from
|| *from
== '/') && (!*dest
|| *dest
== '/')) continue;
515 /* count remaining elements in 'from' */
519 while (*from
&& *from
!= '/') from
++;
520 while (*from
== '/') from
++;
526 if (!start
[0] && !dotdots
) return NULL
; /* empty path */
528 ret
= xmalloc( 3 * dotdots
+ strlen( start
) + 1 );
529 for (p
= ret
; dotdots
; dotdots
--, p
+= 3) memcpy( p
, "../", 3 );
531 if (start
[0]) strcpy( p
, start
);
532 else p
[-1] = 0; /* remove trailing slash */
537 /*******************************************************************
540 static char *concat_paths( const char *base
, const char *path
)
545 if (!base
|| !base
[0]) return xstrdup( path
&& path
[0] ? path
: "." );
546 if (!path
|| !path
[0]) return xstrdup( base
);
547 if (path
[0] == '/') return xstrdup( path
);
549 len
= strlen( base
);
550 while (len
&& base
[len
- 1] == '/') len
--;
551 while (len
&& !strncmp( path
, "..", 2 ) && (!path
[2] || path
[2] == '/'))
553 for (i
= len
; i
> 0; i
--) if (base
[i
- 1] == '/') break;
554 if (i
== len
- 2 && !memcmp( base
+ i
, "..", 2 )) break; /* we can't go up if we already have ".." */
555 if (i
!= len
- 1 || base
[i
] != '.')
558 while (*path
== '/') path
++;
560 /* else ignore "." element */
561 while (i
> 0 && base
[i
- 1] == '/') i
--;
564 if (!len
&& base
[0] != '/') return xstrdup( path
[0] ? path
: "." );
565 ret
= xmalloc( len
+ strlen( path
) + 2 );
566 memcpy( ret
, base
, len
);
568 strcpy( ret
+ len
, path
);
573 /*******************************************************************
574 * is_native_arch_disabled
576 * Check if the makefile was disabled for a PE arch that matches the native arch.
578 static int is_native_arch_disabled( struct makefile
*make
)
582 if (archs
.count
== 1) return 0;
583 if (!so_dll_supported
) return 1;
585 for (arch
= 1; arch
< archs
.count
; arch
++)
586 if (make
->disabled
[arch
] && !strcmp( archs
.str
[0], archs
.str
[arch
] ))
592 /*******************************************************************
595 * Check if arch is one of the PE architectures in multiarch.
596 * Also return TRUE for native arch iff there's no PE support.
598 static int is_multiarch( unsigned int arch
)
600 return archs
.count
== 1 || arch
;
604 /*******************************************************************
607 * Check if the files of a makefile use msvcrt by default.
609 static int is_using_msvcrt( struct makefile
*make
)
611 return make
->module
|| make
->testdll
;
615 /*******************************************************************
618 static char *arch_module_name( const char *module
, unsigned int arch
)
620 return strmake( "%s%s%s", arch_dirs
[arch
], module
, dll_ext
[arch
] );
624 /*******************************************************************
627 static char *arch_make_variable( const char *name
, unsigned int arch
)
629 return arch
? strmake( "$(%s_%s)", archs
.str
[arch
], name
) : strmake( "$(%s)", name
);
633 /*******************************************************************
636 static char *obj_dir_path( const struct makefile
*make
, const char *path
)
638 return concat_paths( make
->obj_dir
, path
);
642 /*******************************************************************
645 static char *src_dir_path( const struct makefile
*make
, const char *path
)
647 if (make
->src_dir
) return concat_paths( make
->src_dir
, path
);
648 return obj_dir_path( make
, path
);
652 /*******************************************************************
655 static char *root_src_dir_path( const char *path
)
657 return concat_paths( root_src_dir
, path
);
661 /*******************************************************************
664 static char *tools_dir_path( const struct makefile
*make
, const char *path
)
666 if (tools_dir
) return strmake( "%s/tools/%s", tools_dir
, path
);
667 return strmake( "tools/%s", path
);
671 /*******************************************************************
674 static char *tools_path( const struct makefile
*make
, const char *name
)
676 return strmake( "%s/%s%s", tools_dir_path( make
, name
), name
, tools_ext
);
680 /*******************************************************************
681 * strarray_addall_path
683 static void strarray_addall_path( struct strarray
*array
, const char *dir
, struct strarray added
)
687 for (i
= 0; i
< added
.count
; i
++) strarray_add( array
, concat_paths( dir
, added
.str
[i
] ));
691 /*******************************************************************
694 static char *get_line( FILE *file
)
702 buffer
= xmalloc( size
);
704 if (!fgets( buffer
, size
, file
)) return NULL
;
709 char *p
= buffer
+ strlen(buffer
);
710 /* if line is larger than buffer, resize buffer */
711 while (p
== buffer
+ size
- 1 && p
[-1] != '\n')
713 buffer
= xrealloc( buffer
, size
* 2 );
714 if (!fgets( buffer
+ size
- 1, size
+ 1, file
)) break;
715 p
= buffer
+ strlen(buffer
);
718 if (p
> buffer
&& p
[-1] == '\n')
721 if (p
> buffer
&& p
[-1] == '\r') *(--p
) = 0;
722 if (p
> buffer
&& p
[-1] == '\\')
725 /* line ends in backslash, read continuation line */
726 if (!fgets( p
, size
- (p
- buffer
), file
)) return buffer
;
736 /*******************************************************************
739 static unsigned int hash_filename( const char *name
)
742 unsigned int ret
= 2166136261u;
743 while (*name
) ret
= (ret
* 16777619) ^ *name
++;
744 return ret
% HASH_SIZE
;
748 /*******************************************************************
751 static struct file
*add_file( const char *name
)
753 struct file
*file
= xmalloc( sizeof(*file
) );
754 memset( file
, 0, sizeof(*file
) );
755 file
->name
= xstrdup( name
);
760 /*******************************************************************
763 static void add_dependency( struct file
*file
, const char *name
, enum incl_type type
)
765 if (file
->deps_count
>= file
->deps_size
)
767 file
->deps_size
*= 2;
768 if (file
->deps_size
< 16) file
->deps_size
= 16;
769 file
->deps
= xrealloc( file
->deps
, file
->deps_size
* sizeof(*file
->deps
) );
771 file
->deps
[file
->deps_count
].line
= input_line
;
772 file
->deps
[file
->deps_count
].type
= type
;
773 file
->deps
[file
->deps_count
].name
= xstrdup( name
);
778 /*******************************************************************
781 static struct incl_file
*find_src_file( const struct makefile
*make
, const char *name
)
783 struct incl_file
*file
;
785 if (make
== include_makefile
)
787 unsigned int hash
= hash_filename( name
);
789 LIST_FOR_EACH_ENTRY( file
, &global_includes
[hash
], struct incl_file
, hash_entry
)
790 if (!strcmp( name
, file
->name
)) return file
;
794 LIST_FOR_EACH_ENTRY( file
, &make
->sources
, struct incl_file
, entry
)
795 if (!strcmp( name
, file
->name
)) return file
;
799 /*******************************************************************
802 static struct incl_file
*find_include_file( const struct makefile
*make
, const char *name
)
804 struct incl_file
*file
;
806 LIST_FOR_EACH_ENTRY( file
, &make
->includes
, struct incl_file
, entry
)
808 const char *filename
= file
->filename
;
809 if (!filename
) continue;
810 if (make
->obj_dir
&& strlen(make
->obj_dir
) < strlen(filename
))
812 filename
+= strlen(make
->obj_dir
);
813 while (*filename
== '/') filename
++;
815 if (!strcmp( name
, filename
)) return file
;
820 /*******************************************************************
823 * Add an include file if it doesn't already exists.
825 static struct incl_file
*add_include( struct makefile
*make
, struct incl_file
*parent
,
826 const char *name
, int line
, enum incl_type type
)
828 struct incl_file
*include
;
830 if (parent
->files_count
>= parent
->files_size
)
832 parent
->files_size
*= 2;
833 if (parent
->files_size
< 16) parent
->files_size
= 16;
834 parent
->files
= xrealloc( parent
->files
, parent
->files_size
* sizeof(*parent
->files
) );
837 LIST_FOR_EACH_ENTRY( include
, &make
->includes
, struct incl_file
, entry
)
838 if (!parent
->use_msvcrt
== !include
->use_msvcrt
&& !strcmp( name
, include
->name
))
841 include
= xmalloc( sizeof(*include
) );
842 memset( include
, 0, sizeof(*include
) );
843 include
->name
= xstrdup(name
);
844 include
->included_by
= parent
;
845 include
->included_line
= line
;
846 include
->type
= type
;
847 include
->use_msvcrt
= parent
->use_msvcrt
;
848 list_add_tail( &make
->includes
, &include
->entry
);
850 parent
->files
[parent
->files_count
++] = include
;
855 /*******************************************************************
856 * add_generated_source
858 * Add a generated source file to the list.
860 static struct incl_file
*add_generated_source( struct makefile
*make
, const char *name
,
861 const char *filename
, unsigned int arch
)
863 struct incl_file
*file
= xmalloc( sizeof(*file
) );
865 name
= strmake( "%s%s", arch_dirs
[arch
], name
);
866 memset( file
, 0, sizeof(*file
) );
867 file
->file
= add_file( name
);
869 file
->name
= xstrdup( name
);
870 file
->basename
= xstrdup( filename
? filename
: name
);
871 file
->filename
= obj_dir_path( make
, file
->basename
);
872 file
->file
->flags
= FLAG_GENERATED
;
873 file
->use_msvcrt
= is_using_msvcrt( make
);
874 list_add_tail( &make
->sources
, &file
->entry
);
875 if (make
== include_makefile
)
877 unsigned int hash
= hash_filename( name
);
878 list_add_tail( &global_includes
[hash
], &file
->hash_entry
);
884 /*******************************************************************
887 static char *skip_spaces( const char *p
)
889 while (*p
== ' ' || *p
== '\t') p
++;
894 /*******************************************************************
895 * parse_include_directive
897 static void parse_include_directive( struct file
*source
, char *str
)
899 char quote
, *include
, *p
= skip_spaces( str
);
901 if (*p
!= '\"' && *p
!= '<' ) return;
903 if (quote
== '<') quote
= '>';
905 while (*p
&& (*p
!= quote
)) p
++;
906 if (!*p
) fatal_error( "malformed include directive '%s'\n", str
);
908 add_dependency( source
, include
, (quote
== '>') ? INCL_SYSTEM
: INCL_NORMAL
);
912 /*******************************************************************
913 * parse_pragma_directive
915 static void parse_pragma_directive( struct file
*source
, char *str
)
917 char *flag
, *p
= str
;
919 if (*p
!= ' ' && *p
!= '\t') return;
920 p
= strtok( skip_spaces( p
), " \t" );
921 if (strcmp( p
, "makedep" )) return;
923 while ((flag
= strtok( NULL
, " \t" )))
925 if (!strcmp( flag
, "depend" ))
927 while ((p
= strtok( NULL
, " \t" ))) add_dependency( source
, p
, INCL_NORMAL
);
930 else if (!strcmp( flag
, "install" )) source
->flags
|= FLAG_INSTALL
;
932 if (strendswith( source
->name
, ".idl" ))
934 if (!strcmp( flag
, "header" )) source
->flags
|= FLAG_IDL_HEADER
;
935 else if (!strcmp( flag
, "proxy" )) source
->flags
|= FLAG_IDL_PROXY
;
936 else if (!strcmp( flag
, "client" )) source
->flags
|= FLAG_IDL_CLIENT
;
937 else if (!strcmp( flag
, "server" )) source
->flags
|= FLAG_IDL_SERVER
;
938 else if (!strcmp( flag
, "ident" )) source
->flags
|= FLAG_IDL_IDENT
;
939 else if (!strcmp( flag
, "typelib" )) source
->flags
|= FLAG_IDL_TYPELIB
;
940 else if (!strcmp( flag
, "register" )) source
->flags
|= FLAG_IDL_REGISTER
;
941 else if (!strcmp( flag
, "regtypelib" )) source
->flags
|= FLAG_IDL_REGTYPELIB
;
943 else if (strendswith( source
->name
, ".rc" ))
945 if (!strcmp( flag
, "header" )) source
->flags
|= FLAG_RC_HEADER
;
946 else if (!strcmp( flag
, "po" )) source
->flags
|= FLAG_RC_PO
;
948 else if (strendswith( source
->name
, ".sfd" ))
950 if (!strcmp( flag
, "font" ))
952 struct strarray
*array
= source
->args
;
956 source
->args
= array
= xmalloc( sizeof(*array
) );
957 *array
= empty_strarray
;
958 source
->flags
|= FLAG_SFD_FONTS
;
960 strarray_add( array
, xstrdup( strtok( NULL
, "" )));
966 if (!strcmp( flag
, "implib" )) source
->flags
|= FLAG_C_IMPLIB
;
967 if (!strcmp( flag
, "unix" )) source
->flags
|= FLAG_C_UNIX
;
973 /*******************************************************************
974 * parse_cpp_directive
976 static void parse_cpp_directive( struct file
*source
, char *str
)
978 str
= skip_spaces( str
);
979 if (*str
++ != '#') return;
980 str
= skip_spaces( str
);
982 if (!strncmp( str
, "include", 7 ))
983 parse_include_directive( source
, str
+ 7 );
984 else if (!strncmp( str
, "import", 6 ) && strendswith( source
->name
, ".m" ))
985 parse_include_directive( source
, str
+ 6 );
986 else if (!strncmp( str
, "pragma", 6 ))
987 parse_pragma_directive( source
, str
+ 6 );
991 /*******************************************************************
994 static void parse_idl_file( struct file
*source
, FILE *file
)
996 char *buffer
, *include
;
1000 while ((buffer
= get_line( file
)))
1003 char *p
= skip_spaces( buffer
);
1005 if (!strncmp( p
, "importlib", 9 ))
1007 p
= skip_spaces( p
+ 9 );
1008 if (*p
++ != '(') continue;
1009 p
= skip_spaces( p
);
1010 if (*p
++ != '"') continue;
1012 while (*p
&& (*p
!= '"')) p
++;
1013 if (!*p
) fatal_error( "malformed importlib directive\n" );
1015 add_dependency( source
, include
, INCL_IMPORTLIB
);
1019 if (!strncmp( p
, "import", 6 ))
1021 p
= skip_spaces( p
+ 6 );
1022 if (*p
!= '"') continue;
1024 while (*p
&& (*p
!= '"')) p
++;
1025 if (!*p
) fatal_error( "malformed import directive\n" );
1027 add_dependency( source
, include
, INCL_IMPORT
);
1031 /* check for #include inside cpp_quote */
1032 if (!strncmp( p
, "cpp_quote", 9 ))
1034 p
= skip_spaces( p
+ 9 );
1035 if (*p
++ != '(') continue;
1036 p
= skip_spaces( p
);
1037 if (*p
++ != '"') continue;
1038 if (*p
++ != '#') continue;
1039 p
= skip_spaces( p
);
1040 if (strncmp( p
, "include", 7 )) continue;
1041 p
= skip_spaces( p
+ 7 );
1042 if (*p
== '\\' && p
[1] == '"')
1049 if (*p
++ != '<' ) continue;
1053 while (*p
&& (*p
!= quote
)) p
++;
1054 if (!*p
|| (quote
== '"' && p
[-1] != '\\'))
1055 fatal_error( "malformed #include directive inside cpp_quote\n" );
1056 if (quote
== '"') p
--; /* remove backslash */
1058 add_dependency( source
, include
, (quote
== '>') ? INCL_CPP_QUOTE_SYSTEM
: INCL_CPP_QUOTE
);
1062 parse_cpp_directive( source
, p
);
1066 /*******************************************************************
1069 static void parse_c_file( struct file
*source
, FILE *file
)
1074 while ((buffer
= get_line( file
)))
1076 parse_cpp_directive( source
, buffer
);
1081 /*******************************************************************
1084 static void parse_rc_file( struct file
*source
, FILE *file
)
1086 char *buffer
, *include
;
1089 while ((buffer
= get_line( file
)))
1092 char *p
= skip_spaces( buffer
);
1094 if (p
[0] == '/' && p
[1] == '*') /* check for magic makedep comment */
1096 p
= skip_spaces( p
+ 2 );
1097 if (strncmp( p
, "@makedep:", 9 )) continue;
1098 p
= skip_spaces( p
+ 9 );
1103 while (*p
&& *p
!= quote
) p
++;
1108 while (*p
&& *p
!= ' ' && *p
!= '\t' && *p
!= '*') p
++;
1111 fatal_error( "malformed makedep comment\n" );
1113 add_dependency( source
, include
, (quote
== '>') ? INCL_SYSTEM
: INCL_NORMAL
);
1117 parse_cpp_directive( source
, buffer
);
1122 /*******************************************************************
1125 static void parse_in_file( struct file
*source
, FILE *file
)
1129 /* make sure it gets rebuilt when the version changes */
1130 add_dependency( source
, "config.h", INCL_SYSTEM
);
1132 if (!strendswith( source
->name
, ".man.in" )) return; /* not a man page */
1135 while ((buffer
= get_line( file
)))
1137 if (strncmp( buffer
, ".TH", 3 )) continue;
1138 p
= skip_spaces( buffer
+ 3 );
1139 if (!(p
= strtok( p
, " \t" ))) continue; /* program name */
1140 if (!(p
= strtok( NULL
, " \t" ))) continue; /* man section */
1141 source
->args
= xstrdup( p
);
1147 /*******************************************************************
1150 static void parse_sfd_file( struct file
*source
, FILE *file
)
1152 char *p
, *eol
, *buffer
;
1155 while ((buffer
= get_line( file
)))
1157 if (strncmp( buffer
, "UComments:", 10 )) continue;
1159 while (*p
== ' ') p
++;
1160 if (p
[0] == '"' && p
[1] && buffer
[strlen(buffer
) - 1] == '"')
1163 buffer
[strlen(buffer
) - 1] = 0;
1165 while ((eol
= strstr( p
, "+AAoA" )))
1168 p
= skip_spaces( p
);
1171 p
= skip_spaces( p
);
1172 if (!strncmp( p
, "pragma", 6 )) parse_pragma_directive( source
, p
+ 6 );
1176 p
= skip_spaces( p
);
1177 if (*p
++ != '#') return;
1178 p
= skip_spaces( p
);
1179 if (!strncmp( p
, "pragma", 6 )) parse_pragma_directive( source
, p
+ 6 );
1188 void (*parse
)( struct file
*file
, FILE *f
);
1189 } parse_functions
[] =
1191 { ".c", parse_c_file
},
1192 { ".h", parse_c_file
},
1193 { ".inl", parse_c_file
},
1194 { ".l", parse_c_file
},
1195 { ".m", parse_c_file
},
1196 { ".rh", parse_c_file
},
1197 { ".x", parse_c_file
},
1198 { ".y", parse_c_file
},
1199 { ".idl", parse_idl_file
},
1200 { ".rc", parse_rc_file
},
1201 { ".in", parse_in_file
},
1202 { ".sfd", parse_sfd_file
}
1205 /*******************************************************************
1208 static struct file
*load_file( const char *name
)
1212 unsigned int i
, hash
= hash_filename( name
);
1214 LIST_FOR_EACH_ENTRY( file
, &files
[hash
], struct file
, entry
)
1215 if (!strcmp( name
, file
->name
)) return file
;
1217 if (!(f
= fopen( name
, "r" ))) return NULL
;
1219 file
= add_file( name
);
1220 list_add_tail( &files
[hash
], &file
->entry
);
1221 input_file_name
= file
->name
;
1224 for (i
= 0; i
< ARRAY_SIZE(parse_functions
); i
++)
1226 if (!strendswith( name
, parse_functions
[i
].ext
)) continue;
1227 parse_functions
[i
].parse( file
, f
);
1232 input_file_name
= NULL
;
1238 /*******************************************************************
1239 * open_include_path_file
1241 * Open a file from a directory on the include path.
1243 static struct file
*open_include_path_file( const struct makefile
*make
, const char *dir
,
1244 const char *name
, char **filename
)
1246 char *src_path
= concat_paths( dir
, name
);
1247 struct file
*ret
= load_file( src_path
);
1249 if (ret
) *filename
= src_path
;
1254 /*******************************************************************
1255 * open_file_same_dir
1257 * Open a file in the same directory as the parent.
1259 static struct file
*open_file_same_dir( const struct incl_file
*parent
, const char *name
, char **filename
)
1261 char *src_path
= replace_filename( parent
->file
->name
, name
);
1262 struct file
*ret
= load_file( src_path
);
1264 if (ret
) *filename
= replace_filename( parent
->filename
, name
);
1269 /*******************************************************************
1270 * open_same_dir_generated_file
1272 * Open a generated_file in the same directory as the parent.
1274 static struct file
*open_same_dir_generated_file( const struct makefile
*make
,
1275 const struct incl_file
*parent
, struct incl_file
*file
,
1276 const char *ext
, const char *src_ext
)
1279 struct file
*ret
= NULL
;
1281 if (strendswith( file
->name
, ext
) &&
1282 (ret
= open_file_same_dir( parent
, replace_extension( file
->name
, ext
, src_ext
), &filename
)))
1284 file
->sourcename
= filename
;
1285 file
->filename
= obj_dir_path( make
, replace_filename( parent
->name
, file
->name
));
1291 /*******************************************************************
1294 * Open a file in the source directory of the makefile.
1296 static struct file
*open_local_file( const struct makefile
*make
, const char *path
, char **filename
)
1298 char *src_path
= src_dir_path( make
, path
);
1299 struct file
*ret
= load_file( src_path
);
1301 /* if not found, try parent dir */
1302 if (!ret
&& make
->parent_dir
)
1305 path
= strmake( "%s/%s", make
->parent_dir
, path
);
1306 src_path
= src_dir_path( make
, path
);
1307 ret
= load_file( src_path
);
1310 if (ret
) *filename
= src_path
;
1315 /*******************************************************************
1316 * open_local_generated_file
1318 * Open a generated file in the directory of the makefile.
1320 static struct file
*open_local_generated_file( const struct makefile
*make
, struct incl_file
*file
,
1321 const char *ext
, const char *src_ext
)
1323 struct incl_file
*include
;
1325 if (strendswith( file
->name
, ext
) &&
1326 (include
= find_src_file( make
, replace_extension( file
->name
, ext
, src_ext
) )))
1328 file
->sourcename
= include
->filename
;
1329 file
->filename
= obj_dir_path( make
, file
->name
);
1330 return include
->file
;
1336 /*******************************************************************
1339 * Open a file in the top-level source directory.
1341 static struct file
*open_global_file( const char *path
, char **filename
)
1343 char *src_path
= root_src_dir_path( path
);
1344 struct file
*ret
= load_file( src_path
);
1346 if (ret
) *filename
= src_path
;
1351 /*******************************************************************
1352 * open_global_header
1354 * Open a file in the global include source directory.
1356 static struct file
*open_global_header( const char *path
, char **filename
)
1358 struct incl_file
*include
= find_src_file( include_makefile
, path
);
1360 if (!include
) return NULL
;
1361 *filename
= include
->filename
;
1362 return include
->file
;
1366 /*******************************************************************
1367 * open_global_generated_file
1369 * Open a generated file in the top-level source directory.
1371 static struct file
*open_global_generated_file( const struct makefile
*make
, struct incl_file
*file
,
1372 const char *ext
, const char *src_ext
)
1374 struct incl_file
*include
;
1376 if (strendswith( file
->name
, ext
) &&
1377 (include
= find_src_file( include_makefile
, replace_extension( file
->name
, ext
, src_ext
) )))
1379 file
->sourcename
= include
->filename
;
1380 file
->filename
= strmake( "include/%s", file
->name
);
1381 return include
->file
;
1387 /*******************************************************************
1390 static struct file
*open_src_file( const struct makefile
*make
, struct incl_file
*pFile
)
1392 struct file
*file
= open_local_file( make
, pFile
->name
, &pFile
->filename
);
1394 if (!file
) fatal_perror( "open %s", pFile
->name
);
1399 /*******************************************************************
1400 * find_importlib_module
1402 static struct makefile
*find_importlib_module( const char *name
)
1404 unsigned int i
, len
;
1406 for (i
= 0; i
< subdirs
.count
; i
++)
1408 if (strncmp( submakes
[i
]->obj_dir
, "dlls/", 5 )) continue;
1409 len
= strlen(submakes
[i
]->obj_dir
);
1410 if (strncmp( submakes
[i
]->obj_dir
+ 5, name
, len
- 5 )) continue;
1411 if (!name
[len
- 5] || !strcmp( name
+ len
- 5, ".dll" )) return submakes
[i
];
1417 /*******************************************************************
1420 static struct file
*open_include_file( const struct makefile
*make
, struct incl_file
*pFile
)
1422 struct file
*file
= NULL
;
1423 unsigned int i
, len
;
1427 /* check for generated files */
1428 if ((file
= open_local_generated_file( make
, pFile
, ".tab.h", ".y" ))) return file
;
1429 if ((file
= open_local_generated_file( make
, pFile
, ".h", ".idl" ))) return file
;
1430 if (fontforge
&& (file
= open_local_generated_file( make
, pFile
, ".ttf", ".sfd" ))) return file
;
1431 if (convert
&& rsvg
&& icotool
)
1433 if ((file
= open_local_generated_file( make
, pFile
, ".bmp", ".svg" ))) return file
;
1434 if ((file
= open_local_generated_file( make
, pFile
, ".cur", ".svg" ))) return file
;
1435 if ((file
= open_local_generated_file( make
, pFile
, ".ico", ".svg" ))) return file
;
1437 if ((file
= open_local_generated_file( make
, pFile
, "-client-protocol.h", ".xml" ))) return file
;
1439 /* check for extra targets */
1440 if (strarray_exists( &make
->extra_targets
, pFile
->name
))
1442 pFile
->sourcename
= src_dir_path( make
, pFile
->name
);
1443 pFile
->filename
= obj_dir_path( make
, pFile
->name
);
1447 /* now try in source dir */
1448 if ((file
= open_local_file( make
, pFile
->name
, &pFile
->filename
))) return file
;
1450 /* check for global importlib (module dependency) */
1451 if (pFile
->type
== INCL_IMPORTLIB
&& find_importlib_module( pFile
->name
))
1453 pFile
->filename
= pFile
->name
;
1457 /* check for generated files in global includes */
1458 if ((file
= open_global_generated_file( make
, pFile
, ".h", ".idl" ))) return file
;
1459 if ((file
= open_global_generated_file( make
, pFile
, ".h", ".h.in" ))) return file
;
1460 if (strendswith( pFile
->name
, "tmpl.h" ) &&
1461 (file
= open_global_generated_file( make
, pFile
, ".h", ".x" ))) return file
;
1463 /* check in global includes source dir */
1464 if ((file
= open_global_header( pFile
->name
, &pFile
->filename
))) return file
;
1466 /* check in global msvcrt includes */
1467 if (pFile
->use_msvcrt
&&
1468 (file
= open_global_header( strmake( "msvcrt/%s", pFile
->name
), &pFile
->filename
)))
1471 /* now search in include paths */
1472 for (i
= 0; i
< make
->include_paths
.count
; i
++)
1474 const char *dir
= make
->include_paths
.str
[i
];
1478 len
= strlen( root_src_dir
);
1479 if (!strncmp( dir
, root_src_dir
, len
) && (!dir
[len
] || dir
[len
] == '/'))
1481 while (dir
[len
] == '/') len
++;
1482 file
= open_global_file( concat_paths( dir
+ len
, pFile
->name
), &pFile
->filename
);
1487 if (*dir
== '/') continue;
1488 file
= open_include_path_file( make
, dir
, pFile
->name
, &pFile
->filename
);
1490 if (!file
) continue;
1491 pFile
->is_external
= 1;
1495 if (pFile
->type
== INCL_SYSTEM
) return NULL
; /* ignore system files we cannot find */
1497 /* try in src file directory */
1498 if ((file
= open_same_dir_generated_file( make
, pFile
->included_by
, pFile
, ".tab.h", ".y" )) ||
1499 (file
= open_same_dir_generated_file( make
, pFile
->included_by
, pFile
, ".h", ".idl" )) ||
1500 (file
= open_file_same_dir( pFile
->included_by
, pFile
->name
, &pFile
->filename
)))
1502 pFile
->is_external
= pFile
->included_by
->is_external
;
1506 if (make
->extlib
) return NULL
; /* ignore missing files in external libs */
1508 fprintf( stderr
, "%s:%d: error: ", pFile
->included_by
->file
->name
, pFile
->included_line
);
1509 perror( pFile
->name
);
1510 pFile
= pFile
->included_by
;
1511 while (pFile
&& pFile
->included_by
)
1513 const char *parent
= pFile
->included_by
->sourcename
;
1514 if (!parent
) parent
= pFile
->included_by
->file
->name
;
1515 fprintf( stderr
, "%s:%d: note: %s was first included here\n",
1516 parent
, pFile
->included_line
, pFile
->name
);
1517 pFile
= pFile
->included_by
;
1523 /*******************************************************************
1526 static void add_all_includes( struct makefile
*make
, struct incl_file
*parent
, struct file
*file
)
1530 for (i
= 0; i
< file
->deps_count
; i
++)
1532 switch (file
->deps
[i
].type
)
1536 add_include( make
, parent
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_NORMAL
);
1538 case INCL_IMPORTLIB
:
1539 add_include( make
, parent
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_IMPORTLIB
);
1542 add_include( make
, parent
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_SYSTEM
);
1544 case INCL_CPP_QUOTE
:
1545 case INCL_CPP_QUOTE_SYSTEM
:
1552 /*******************************************************************
1555 static void parse_file( struct makefile
*make
, struct incl_file
*source
, int src
)
1557 struct file
*file
= src
? open_src_file( make
, source
) : open_include_file( make
, source
);
1561 source
->file
= file
;
1562 source
->files_count
= 0;
1563 source
->files_size
= file
->deps_count
;
1564 source
->files
= xmalloc( source
->files_size
* sizeof(*source
->files
) );
1566 if (strendswith( file
->name
, ".m" )) file
->flags
|= FLAG_C_UNIX
;
1567 if (file
->flags
& FLAG_C_UNIX
) source
->use_msvcrt
= 0;
1568 else if (file
->flags
& FLAG_C_IMPLIB
) source
->use_msvcrt
= 1;
1570 if (source
->sourcename
)
1572 if (strendswith( source
->sourcename
, ".idl" ))
1576 /* generated .h file always includes these */
1577 add_include( make
, source
, "rpc.h", 0, INCL_NORMAL
);
1578 add_include( make
, source
, "rpcndr.h", 0, INCL_NORMAL
);
1579 for (i
= 0; i
< file
->deps_count
; i
++)
1581 switch (file
->deps
[i
].type
)
1584 if (strendswith( file
->deps
[i
].name
, ".idl" ))
1585 add_include( make
, source
, replace_extension( file
->deps
[i
].name
, ".idl", ".h" ),
1586 file
->deps
[i
].line
, INCL_NORMAL
);
1588 add_include( make
, source
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_NORMAL
);
1590 case INCL_CPP_QUOTE
:
1591 add_include( make
, source
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_NORMAL
);
1593 case INCL_CPP_QUOTE_SYSTEM
:
1594 add_include( make
, source
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_SYSTEM
);
1598 case INCL_IMPORTLIB
:
1604 if (strendswith( source
->sourcename
, ".y" ))
1605 return; /* generated .tab.h doesn't include anything */
1608 add_all_includes( make
, source
, file
);
1612 /*******************************************************************
1615 * Add a source file to the list.
1617 static struct incl_file
*add_src_file( struct makefile
*make
, const char *name
)
1619 struct incl_file
*file
= xmalloc( sizeof(*file
) );
1621 memset( file
, 0, sizeof(*file
) );
1622 file
->name
= xstrdup(name
);
1623 file
->use_msvcrt
= is_using_msvcrt( make
);
1624 file
->is_external
= !!make
->extlib
;
1625 list_add_tail( &make
->sources
, &file
->entry
);
1626 if (make
== include_makefile
)
1628 unsigned int hash
= hash_filename( name
);
1629 list_add_tail( &global_includes
[hash
], &file
->hash_entry
);
1631 parse_file( make
, file
, 1 );
1636 /*******************************************************************
1637 * open_input_makefile
1639 static FILE *open_input_makefile( const struct makefile
*make
)
1644 input_file_name
= root_src_dir_path( obj_dir_path( make
, "Makefile.in" ));
1646 input_file_name
= output_makefile_name
; /* always use output name for main Makefile */
1649 if (!(ret
= fopen( input_file_name
, "r" ))) fatal_perror( "open" );
1654 /*******************************************************************
1657 static const char *get_make_variable( const struct makefile
*make
, const char *name
)
1661 if ((ret
= strarray_get_value( &cmdline_vars
, name
))) return ret
;
1662 if ((ret
= strarray_get_value( &make
->vars
, name
))) return ret
;
1663 if (top_makefile
&& (ret
= strarray_get_value( &top_makefile
->vars
, name
))) return ret
;
1668 /*******************************************************************
1669 * get_expanded_make_variable
1671 static char *get_expanded_make_variable( const struct makefile
*make
, const char *name
)
1674 char *p
, *end
, *expand
, *tmp
;
1676 var
= get_make_variable( make
, name
);
1677 if (!var
) return NULL
;
1679 p
= expand
= xstrdup( var
);
1680 while ((p
= strchr( p
, '$' )))
1684 if (!(end
= strchr( p
+ 2, ')' ))) fatal_error( "syntax error in '%s'\n", expand
);
1686 if (strchr( p
+ 2, ':' )) fatal_error( "pattern replacement not supported for '%s'\n", p
+ 2 );
1687 var
= get_make_variable( make
, p
+ 2 );
1688 tmp
= replace_substr( expand
, p
, end
- p
, var
? var
: "" );
1689 /* switch to the new string */
1690 p
= tmp
+ (p
- expand
);
1694 else if (p
[1] == '{') /* don't expand ${} variables */
1696 if (!(end
= strchr( p
+ 2, '}' ))) fatal_error( "syntax error in '%s'\n", expand
);
1699 else if (p
[1] == '$')
1703 else fatal_error( "syntax error in '%s'\n", expand
);
1706 /* consider empty variables undefined */
1707 p
= skip_spaces( expand
);
1708 if (*p
) return expand
;
1714 /*******************************************************************
1715 * get_expanded_make_var_array
1717 static struct strarray
get_expanded_make_var_array( const struct makefile
*make
, const char *name
)
1719 struct strarray ret
= empty_strarray
;
1720 char *value
, *token
;
1722 if ((value
= get_expanded_make_variable( make
, name
)))
1723 for (token
= strtok( value
, " \t" ); token
; token
= strtok( NULL
, " \t" ))
1724 strarray_add( &ret
, token
);
1729 /*******************************************************************
1730 * get_expanded_file_local_var
1732 static struct strarray
get_expanded_file_local_var( const struct makefile
*make
, const char *file
,
1735 char *p
, *var
= strmake( "%s_%s", file
, name
);
1737 for (p
= var
; *p
; p
++) if (!isalnum( *p
)) *p
= '_';
1738 return get_expanded_make_var_array( make
, var
);
1742 /*******************************************************************
1743 * get_expanded_arch_var
1745 static char *get_expanded_arch_var( const struct makefile
*make
, const char *name
, int arch
)
1747 return get_expanded_make_variable( make
, arch
? strmake( "%s_%s", archs
.str
[arch
], name
) : name
);
1751 /*******************************************************************
1752 * get_expanded_arch_var_array
1754 static struct strarray
get_expanded_arch_var_array( const struct makefile
*make
, const char *name
, int arch
)
1756 return get_expanded_make_var_array( make
, arch
? strmake( "%s_%s", archs
.str
[arch
], name
) : name
);
1760 /*******************************************************************
1763 static int set_make_variable( struct strarray
*array
, const char *assignment
)
1767 p
= name
= xstrdup( assignment
);
1768 while (isalnum(*p
) || *p
== '_') p
++;
1769 if (name
== p
) return 0; /* not a variable */
1773 p
= skip_spaces( p
);
1775 if (*p
!= '=') return 0; /* not an assignment */
1777 p
= skip_spaces( p
);
1779 strarray_set_value( array
, name
, p
);
1784 /*******************************************************************
1787 static struct makefile
*parse_makefile( const char *path
)
1791 struct makefile
*make
= xmalloc( sizeof(*make
) );
1793 memset( make
, 0, sizeof(*make
) );
1794 make
->obj_dir
= path
;
1795 if (root_src_dir
) make
->src_dir
= root_src_dir_path( make
->obj_dir
);
1796 if (path
&& !strcmp( path
, "include" )) include_makefile
= make
;
1798 file
= open_input_makefile( make
);
1799 while ((buffer
= get_line( file
)))
1801 if (!strncmp( buffer
, separator
, strlen(separator
) )) break;
1802 if (*buffer
== '\t') continue; /* command */
1803 buffer
= skip_spaces( buffer
);
1804 if (*buffer
== '#') continue; /* comment */
1805 set_make_variable( &make
->vars
, buffer
);
1808 input_file_name
= NULL
;
1813 /*******************************************************************
1814 * add_generated_sources
1816 static void add_generated_sources( struct makefile
*make
)
1818 unsigned int i
, arch
;
1819 struct incl_file
*source
, *next
, *file
, *dlldata
= NULL
;
1820 struct strarray objs
= get_expanded_make_var_array( make
, "EXTRA_OBJS" );
1822 LIST_FOR_EACH_ENTRY_SAFE( source
, next
, &make
->sources
, struct incl_file
, entry
)
1824 for (arch
= 0; arch
< archs
.count
; arch
++)
1826 if (!is_multiarch( arch
)) continue;
1827 if (source
->file
->flags
& FLAG_IDL_CLIENT
)
1829 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_c.c" ), NULL
, arch
);
1830 add_dependency( file
->file
, replace_extension( source
->name
, ".idl", ".h" ), INCL_NORMAL
);
1831 add_all_includes( make
, file
, file
->file
);
1833 if (source
->file
->flags
& FLAG_IDL_SERVER
)
1835 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_s.c" ), NULL
, arch
);
1836 add_dependency( file
->file
, "wine/exception.h", INCL_NORMAL
);
1837 add_dependency( file
->file
, replace_extension( source
->name
, ".idl", ".h" ), INCL_NORMAL
);
1838 add_all_includes( make
, file
, file
->file
);
1840 if (source
->file
->flags
& FLAG_IDL_IDENT
)
1842 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_i.c" ), NULL
, arch
);
1843 add_dependency( file
->file
, "rpc.h", INCL_NORMAL
);
1844 add_dependency( file
->file
, "rpcndr.h", INCL_NORMAL
);
1845 add_dependency( file
->file
, "guiddef.h", INCL_NORMAL
);
1846 add_all_includes( make
, file
, file
->file
);
1848 if (source
->file
->flags
& FLAG_IDL_PROXY
)
1850 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_p.c" ), NULL
, arch
);
1851 add_dependency( file
->file
, "objbase.h", INCL_NORMAL
);
1852 add_dependency( file
->file
, "rpcproxy.h", INCL_NORMAL
);
1853 add_dependency( file
->file
, "wine/exception.h", INCL_NORMAL
);
1854 add_dependency( file
->file
, replace_extension( source
->name
, ".idl", ".h" ), INCL_NORMAL
);
1855 add_all_includes( make
, file
, file
->file
);
1857 if (source
->file
->flags
& FLAG_IDL_TYPELIB
)
1859 add_generated_source( make
, replace_extension( source
->name
, ".idl", "_l.res" ), NULL
, arch
);
1861 if (source
->file
->flags
& FLAG_IDL_REGTYPELIB
)
1863 add_generated_source( make
, replace_extension( source
->name
, ".idl", "_t.res" ), NULL
, arch
);
1865 if (source
->file
->flags
& FLAG_IDL_REGISTER
)
1867 add_generated_source( make
, replace_extension( source
->name
, ".idl", "_r.res" ), NULL
, arch
);
1871 /* now the arch-independent files */
1873 if ((source
->file
->flags
& FLAG_IDL_PROXY
) && !dlldata
)
1875 dlldata
= add_generated_source( make
, "dlldata.o", "dlldata.c", 0 );
1876 add_dependency( dlldata
->file
, "objbase.h", INCL_NORMAL
);
1877 add_dependency( dlldata
->file
, "rpcproxy.h", INCL_NORMAL
);
1878 add_all_includes( make
, dlldata
, dlldata
->file
);
1880 if (source
->file
->flags
& FLAG_IDL_HEADER
)
1882 add_generated_source( make
, replace_extension( source
->name
, ".idl", ".h" ), NULL
, 0 );
1884 if (!source
->file
->flags
&& strendswith( source
->name
, ".idl" ))
1886 if (!strncmp( source
->name
, "wine/", 5 )) continue;
1887 source
->file
->flags
= FLAG_IDL_HEADER
| FLAG_INSTALL
;
1888 add_generated_source( make
, replace_extension( source
->name
, ".idl", ".h" ), NULL
, 0 );
1890 if (strendswith( source
->name
, ".x" ))
1892 add_generated_source( make
, replace_extension( source
->name
, ".x", ".h" ), NULL
, 0 );
1894 if (strendswith( source
->name
, ".y" ))
1896 file
= add_generated_source( make
, replace_extension( source
->name
, ".y", ".tab.c" ), NULL
, 0 );
1897 /* steal the includes list from the source file */
1898 file
->files_count
= source
->files_count
;
1899 file
->files_size
= source
->files_size
;
1900 file
->files
= source
->files
;
1901 source
->files_count
= source
->files_size
= 0;
1902 source
->files
= NULL
;
1904 if (strendswith( source
->name
, ".l" ))
1906 file
= add_generated_source( make
, replace_extension( source
->name
, ".l", ".yy.c" ), NULL
, 0 );
1907 /* steal the includes list from the source file */
1908 file
->files_count
= source
->files_count
;
1909 file
->files_size
= source
->files_size
;
1910 file
->files
= source
->files
;
1911 source
->files_count
= source
->files_size
= 0;
1912 source
->files
= NULL
;
1914 if (strendswith( source
->name
, ".po" ))
1916 if (!make
->disabled
[0])
1917 strarray_add_uniq( &linguas
, replace_extension( source
->name
, ".po", "" ));
1919 if (strendswith( source
->name
, ".spec" ))
1921 char *obj
= replace_extension( source
->name
, ".spec", "" );
1922 strarray_addall_uniq( &make
->extra_imports
,
1923 get_expanded_file_local_var( make
, obj
, "IMPORTS" ));
1925 if (strendswith( source
->name
, ".xml" ))
1927 char *code_name
= replace_extension( source
->name
, ".xml", "-protocol.c" );
1928 char *header_name
= replace_extension( source
->name
, ".xml", "-client-protocol.h" );
1930 file
= add_generated_source( make
, code_name
, NULL
, 0 );
1931 file
->file
->flags
|= FLAG_C_UNIX
;
1932 file
->use_msvcrt
= 0;
1933 file
= add_generated_source( make
, header_name
, NULL
, 0 );
1934 file
->file
->flags
|= FLAG_C_UNIX
;
1935 file
->use_msvcrt
= 0;
1938 free( header_name
);
1943 for (arch
= 0; arch
< archs
.count
; arch
++)
1945 if (!is_multiarch( arch
)) continue;
1946 file
= add_generated_source( make
, "testlist.o", "testlist.c", arch
);
1947 add_dependency( file
->file
, "wine/test.h", INCL_NORMAL
);
1948 add_all_includes( make
, file
, file
->file
);
1951 for (i
= 0; i
< objs
.count
; i
++)
1953 /* default to .c for unknown extra object files */
1954 if (strendswith( objs
.str
[i
], ".o" ))
1956 file
= add_generated_source( make
, objs
.str
[i
], replace_extension( objs
.str
[i
], ".o", ".c" ), 0);
1957 file
->file
->flags
|= FLAG_C_UNIX
;
1958 file
->use_msvcrt
= 0;
1960 else if (strendswith( objs
.str
[i
], ".res" ))
1961 add_generated_source( make
, replace_extension( objs
.str
[i
], ".res", ".rc" ), NULL
, 0 );
1963 add_generated_source( make
, objs
.str
[i
], NULL
, 0 );
1968 /*******************************************************************
1971 static void create_dir( const char *dir
)
1975 p
= path
= xstrdup( dir
);
1976 while ((p
= strchr( p
, '/' )))
1979 if (mkdir( path
, 0755 ) == -1 && errno
!= EEXIST
) fatal_perror( "mkdir %s", path
);
1981 while (*p
== '/') p
++;
1983 if (mkdir( path
, 0755 ) == -1 && errno
!= EEXIST
) fatal_perror( "mkdir %s", path
);
1988 /*******************************************************************
1989 * create_file_directories
1991 * Create the base directories of all the files.
1993 static void create_file_directories( const struct makefile
*make
, struct strarray files
)
1995 struct strarray subdirs
= empty_strarray
;
1999 for (i
= 0; i
< files
.count
; i
++)
2001 if (!strchr( files
.str
[i
], '/' )) continue;
2002 dir
= obj_dir_path( make
, files
.str
[i
] );
2003 *strrchr( dir
, '/' ) = 0;
2004 strarray_add_uniq( &subdirs
, dir
);
2007 for (i
= 0; i
< subdirs
.count
; i
++) create_dir( subdirs
.str
[i
] );
2011 /*******************************************************************
2012 * output_filenames_obj_dir
2014 static void output_filenames_obj_dir( const struct makefile
*make
, struct strarray array
)
2018 for (i
= 0; i
< array
.count
; i
++) output_filename( obj_dir_path( make
, array
.str
[i
] ));
2022 /*******************************************************************
2025 static void get_dependencies( struct incl_file
*file
, struct incl_file
*source
)
2029 if (!file
->filename
) return;
2033 if (file
->owner
== source
) return; /* already processed */
2034 if (file
->type
== INCL_IMPORTLIB
)
2036 if (!(source
->file
->flags
& (FLAG_IDL_TYPELIB
| FLAG_IDL_REGTYPELIB
)))
2037 return; /* library is imported only when building a typelib */
2038 strarray_add( &source
->importlibdeps
, file
->filename
);
2040 else strarray_add( &source
->dependencies
, file
->filename
);
2041 file
->owner
= source
;
2044 if (!strcmp( file
->filename
, "include/config.h" ) &&
2045 file
!= source
->files
[0] && !source
->is_external
)
2047 input_file_name
= source
->filename
;
2049 for (i
= 0; i
< source
->file
->deps_count
; i
++)
2051 if (!strcmp( source
->file
->deps
[i
].name
, file
->name
))
2052 input_line
= source
->file
->deps
[i
].line
;
2054 fatal_error( "%s must be included before other headers\n", file
->name
);
2058 for (i
= 0; i
< file
->files_count
; i
++) get_dependencies( file
->files
[i
], source
);
2062 /*******************************************************************
2063 * get_local_dependencies
2065 * Get the local dependencies of a given target.
2067 static struct strarray
get_local_dependencies( const struct makefile
*make
, const char *name
,
2068 struct strarray targets
)
2071 struct strarray deps
= get_expanded_file_local_var( make
, name
, "DEPS" );
2073 for (i
= 0; i
< deps
.count
; i
++)
2075 if (strarray_exists( &targets
, deps
.str
[i
] ))
2076 deps
.str
[i
] = obj_dir_path( make
, deps
.str
[i
] );
2078 deps
.str
[i
] = src_dir_path( make
, deps
.str
[i
] );
2084 /*******************************************************************
2087 * Find the makefile that builds the named static library (which may be an import lib).
2089 static struct makefile
*get_static_lib( const char *name
, unsigned int arch
)
2093 for (i
= 0; i
< subdirs
.count
; i
++)
2095 if (submakes
[i
]->importlib
&& !strcmp( submakes
[i
]->importlib
, name
)) return submakes
[i
];
2096 if (!submakes
[i
]->staticlib
) continue;
2097 if (submakes
[i
]->disabled
[arch
]) continue;
2098 if (strncmp( submakes
[i
]->staticlib
, "lib", 3 )) continue;
2099 if (strncmp( submakes
[i
]->staticlib
+ 3, name
, strlen(name
) )) continue;
2100 if (strcmp( submakes
[i
]->staticlib
+ 3 + strlen(name
), ".a" )) continue;
2107 /*******************************************************************
2108 * get_native_unix_lib
2110 static const char *get_native_unix_lib( const struct makefile
*make
, const char *name
)
2112 if (!make
->unixlib
) return NULL
;
2113 if (strncmp( make
->unixlib
, name
, strlen(name
) )) return NULL
;
2114 if (make
->unixlib
[strlen(name
)] != '.') return NULL
;
2115 return obj_dir_path( make
, make
->unixlib
);
2119 /*******************************************************************
2120 * get_parent_makefile
2122 static struct makefile
*get_parent_makefile( struct makefile
*make
)
2127 if (!make
->obj_dir
) return NULL
;
2128 dir
= xstrdup( make
->obj_dir
);
2129 if (!(p
= strrchr( dir
, '/' ))) return NULL
;
2131 for (i
= 0; i
< subdirs
.count
; i
++)
2132 if (!strcmp( submakes
[i
]->obj_dir
, dir
)) return submakes
[i
];
2137 /*******************************************************************
2140 static int needs_delay_lib( const struct makefile
*make
, unsigned int arch
)
2142 if (delay_load_flags
[arch
]) return 0;
2143 if (!make
->importlib
) return 0;
2144 return strarray_exists( &delay_import_libs
, make
->importlib
);
2148 /*******************************************************************
2149 * add_unix_libraries
2151 static struct strarray
add_unix_libraries( const struct makefile
*make
, struct strarray
*deps
)
2153 struct strarray ret
= empty_strarray
;
2154 struct strarray all_libs
= empty_strarray
;
2157 if (strcmp( make
->unixlib
, "ntdll.so" )) strarray_add( &all_libs
, "-lntdll" );
2158 strarray_addall( &all_libs
, get_expanded_make_var_array( make
, "UNIX_LIBS" ));
2160 for (i
= 0; i
< all_libs
.count
; i
++)
2162 const char *lib
= NULL
;
2164 if (!strncmp( all_libs
.str
[i
], "-l", 2 ))
2166 for (j
= 0; j
< subdirs
.count
; j
++)
2168 if (make
== submakes
[j
]) continue;
2169 if ((lib
= get_native_unix_lib( submakes
[j
], all_libs
.str
[i
] + 2 ))) break;
2174 strarray_add( deps
, lib
);
2175 strarray_add( &ret
, lib
);
2177 else strarray_add( &ret
, all_libs
.str
[i
] );
2180 strarray_addall( &ret
, libs
);
2185 /*******************************************************************
2188 static int is_crt_module( const char *file
)
2190 return !strncmp( file
, "msvcr", 5 ) || !strncmp( file
, "ucrt", 4 ) || !strcmp( file
, "crtdll.dll" );
2194 /*******************************************************************
2197 static const char *get_default_crt( const struct makefile
*make
)
2199 if (make
->module
&& is_crt_module( make
->module
)) return NULL
; /* don't add crt import to crt dlls */
2200 return !make
->testdll
&& (!make
->staticlib
|| make
->extlib
) ? "ucrtbase" : "msvcrt";
2204 /*******************************************************************
2207 static const char *get_crt_define( const struct makefile
*make
)
2209 const char *crt_dll
= NULL
;
2210 unsigned int i
, version
= 0;
2212 for (i
= 0; i
< make
->imports
.count
; i
++)
2214 if (!is_crt_module( make
->imports
.str
[i
] )) continue;
2215 if (crt_dll
) fatal_error( "More than one C runtime DLL imported: %s and %s\n",
2216 crt_dll
, make
->imports
.str
[i
] );
2217 crt_dll
= make
->imports
.str
[i
];
2222 if (strarray_exists( &make
->extradllflags
, "-nodefaultlibs" )) return "-D_MSVCR_VER=0";
2223 if (!(crt_dll
= get_default_crt( make
))) crt_dll
= make
->module
;
2225 if (!strncmp( crt_dll
, "ucrt", 4 )) return "-D_UCRT";
2226 sscanf( crt_dll
, "msvcr%u", &version
);
2227 return strmake( "-D_MSVCR_VER=%u", version
);
2231 /*******************************************************************
2232 * get_default_imports
2234 static struct strarray
get_default_imports( const struct makefile
*make
, struct strarray imports
)
2236 struct strarray ret
= empty_strarray
;
2237 const char *crt_dll
= get_default_crt( make
);
2240 for (i
= 0; i
< imports
.count
; i
++)
2241 if (is_crt_module( imports
.str
[i
] ))
2242 crt_dll
= imports
.str
[i
];
2244 strarray_add( &ret
, "winecrt0" );
2245 if (crt_dll
) strarray_add( &ret
, crt_dll
);
2247 if (make
->is_win16
&& (!make
->importlib
|| strcmp( make
->importlib
, "kernel" )))
2248 strarray_add( &ret
, "kernel" );
2250 strarray_add( &ret
, "kernel32" );
2251 strarray_add( &ret
, "ntdll" );
2258 IMPORT_TYPE_DELAYED
,
2259 IMPORT_TYPE_DEFAULT
,
2262 /*******************************************************************
2265 static struct strarray
add_import_libs( const struct makefile
*make
, struct strarray
*deps
,
2266 struct strarray imports
, enum import_type type
, unsigned int arch
)
2268 struct strarray ret
= empty_strarray
;
2271 for (i
= 0; i
< imports
.count
; i
++)
2273 const char *name
= imports
.str
[i
];
2274 struct makefile
*submake
;
2276 /* add crt import lib only when adding the default imports libs */
2277 if (is_crt_module( imports
.str
[i
] ) && type
!= IMPORT_TYPE_DEFAULT
) continue;
2283 case 'L': strarray_add( &ret
, name
); continue;
2284 case 'l': name
+= 2; break;
2288 else name
= get_base_name( name
);
2290 if ((submake
= get_static_lib( name
, arch
)))
2292 const char *ext
= (type
== IMPORT_TYPE_DELAYED
&& !delay_load_flags
[arch
]) ? ".delay.a" : ".a";
2293 const char *lib
= obj_dir_path( submake
, strmake( "%slib%s%s", arch_dirs
[arch
], name
, ext
));
2294 strarray_add_uniq( deps
, lib
);
2295 strarray_add( &ret
, lib
);
2297 else strarray_add( &ret
, strmake( "-l%s", name
));
2303 /*******************************************************************
2306 static void add_install_rule( struct makefile
*make
, const char *target
, unsigned int arch
,
2307 const char *file
, const char *dest
)
2311 if (make
->disabled
[arch
]) return;
2313 for (i
= 0; i
< NB_INSTALL_RULES
; i
++)
2315 if (strarray_exists( &make
->install
[i
], target
) ||
2316 strarray_exists( &top_install
[i
], make
->obj_dir
) ||
2317 strarray_exists( &top_install
[i
], obj_dir_path( make
, target
)))
2319 strarray_add( &make
->install_rules
[i
], file
);
2320 strarray_add( &make
->install_rules
[i
], dest
);
2327 /*******************************************************************
2328 * get_include_install_path
2330 * Determine the installation path for a given include file.
2332 static const char *get_include_install_path( const char *name
)
2334 if (!strncmp( name
, "wine/", 5 )) return name
+ 5;
2335 if (!strncmp( name
, "msvcrt/", 7 )) return name
;
2336 return strmake( "windows/%s", name
);
2340 /*******************************************************************
2341 * get_source_defines
2343 static struct strarray
get_source_defines( struct makefile
*make
, struct incl_file
*source
,
2347 struct strarray ret
= empty_strarray
;
2349 strarray_addall( &ret
, make
->include_args
);
2350 if (source
->use_msvcrt
)
2352 strarray_add( &ret
, strmake( "-I%s", root_src_dir_path( "include/msvcrt" )));
2353 for (i
= 0; i
< make
->include_paths
.count
; i
++)
2354 strarray_add( &ret
, strmake( "-I%s", make
->include_paths
.str
[i
] ));
2355 strarray_add( &ret
, get_crt_define( make
));
2357 strarray_addall( &ret
, make
->define_args
);
2358 strarray_addall( &ret
, get_expanded_file_local_var( make
, obj
, "EXTRADEFS" ));
2363 /*******************************************************************
2364 * remove_warning_flags
2366 static struct strarray
remove_warning_flags( struct strarray flags
)
2369 struct strarray ret
= empty_strarray
;
2371 for (i
= 0; i
< flags
.count
; i
++)
2372 if (strncmp( flags
.str
[i
], "-W", 2 ) || !strncmp( flags
.str
[i
], "-Wno-", 5 ))
2373 strarray_add( &ret
, flags
.str
[i
] );
2378 /*******************************************************************
2381 static const char *get_debug_file( struct makefile
*make
, const char *name
, unsigned int arch
)
2383 const char *debug_file
= NULL
;
2384 if (!debug_flags
[arch
]) return NULL
;
2385 if (!strcmp( debug_flags
[arch
], "pdb" )) debug_file
= strmake( "%s.pdb", get_base_name( name
));
2386 else if (!strncmp( debug_flags
[arch
], "split", 5 )) debug_file
= strmake( "%s.debug", name
);
2387 if (debug_file
) strarray_add( &make
->debug_files
, debug_file
);
2392 /*******************************************************************
2395 static const char *cmd_prefix( const char *cmd
)
2397 if (!silent_rules
) return "";
2398 return strmake( "$(quiet_%s)", cmd
);
2402 /*******************************************************************
2403 * output_winegcc_command
2405 static void output_winegcc_command( struct makefile
*make
, unsigned int arch
)
2407 output( "\t%s%s -o $@", cmd_prefix( "CCLD" ), tools_path( make
, "winegcc" ));
2408 output_filename( "--wine-objdir ." );
2411 output_filename( "--winebuild" );
2412 output_filename( tools_path( make
, "winebuild" ));
2414 output_filenames( target_flags
[arch
] );
2416 output_filename( "-mno-cygwin" );
2417 output_filenames( lddll_flags
);
2421 /*******************************************************************
2422 * output_symlink_rule
2424 * Output a rule to create a symlink.
2426 static void output_symlink_rule( const char *src_name
, const char *link_name
, int create_dir
)
2428 const char *name
= strrchr( link_name
, '/' );
2433 dir
= xstrdup( link_name
);
2434 dir
[name
- link_name
] = 0;
2437 output( "\t%s", cmd_prefix( "LN" ));
2438 if (create_dir
&& dir
&& *dir
) output( "%s -d %s && ", root_src_dir_path( "tools/install-sh" ), dir
);
2439 output( "rm -f %s && ", link_name
);
2441 /* dest path with a directory needs special handling if ln -s isn't supported */
2442 if (dir
&& strcmp( ln_s
, "ln -s" ))
2443 output( "cd %s && %s %s %s\n", *dir
? dir
: "/", ln_s
, src_name
, name
+ 1 );
2445 output( "%s %s %s\n", ln_s
, src_name
, link_name
);
2451 /*******************************************************************
2452 * output_srcdir_symlink
2454 * Output rule to create a symlink back to the source directory, for source files
2455 * that are needed at run-time.
2457 static void output_srcdir_symlink( struct makefile
*make
, const char *obj
)
2459 char *src_file
, *dst_file
, *src_name
;
2461 if (!make
->src_dir
) return;
2462 src_file
= src_dir_path( make
, obj
);
2463 dst_file
= obj_dir_path( make
, obj
);
2464 output( "%s: %s\n", dst_file
, src_file
);
2466 src_name
= src_file
;
2467 if (src_name
[0] != '/' && make
->obj_dir
)
2468 src_name
= concat_paths( get_relative_path( make
->obj_dir
, "" ), src_name
);
2470 output_symlink_rule( src_name
, dst_file
, 0 );
2471 strarray_add( &make
->all_targets
[0], obj
);
2475 /*******************************************************************
2476 * output_install_commands
2478 static void output_install_commands( struct makefile
*make
, struct strarray files
)
2480 unsigned int i
, arch
;
2481 char *install_sh
= root_src_dir_path( "tools/install-sh" );
2483 for (i
= 0; i
< files
.count
; i
+= 2)
2485 const char *file
= files
.str
[i
];
2486 const char *dest
= strmake( "$(DESTDIR)%s", files
.str
[i
+ 1] + 1 );
2487 char type
= *files
.str
[i
+ 1];
2491 case '1': case '2': case '3': case '4': case '5':
2492 case '6': case '7': case '8': case '9': /* arch-dependent program */
2494 output( "\tSTRIPPROG=%s %s -m 644 $(INSTALL_PROGRAM_FLAGS) %s %s\n",
2495 strip_progs
[arch
], install_sh
, obj_dir_path( make
, file
), dest
);
2496 output( "\t%s --builtin %s\n", tools_path( make
, "winebuild" ), dest
);
2498 case 'd': /* data file */
2499 output( "\t%s -m 644 $(INSTALL_DATA_FLAGS) %s %s\n",
2500 install_sh
, obj_dir_path( make
, file
), dest
);
2502 case 'D': /* data file in source dir */
2503 output( "\t%s -m 644 $(INSTALL_DATA_FLAGS) %s %s\n",
2504 install_sh
, src_dir_path( make
, file
), dest
);
2506 case '0': /* native arch program file */
2507 case 'p': /* program file */
2508 output( "\tSTRIPPROG=\"$(STRIP)\" %s $(INSTALL_PROGRAM_FLAGS) %s %s\n",
2509 install_sh
, obj_dir_path( make
, file
), dest
);
2511 case 's': /* script */
2512 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s %s\n",
2513 install_sh
, obj_dir_path( make
, file
), dest
);
2515 case 'S': /* script in source dir */
2516 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s %s\n",
2517 install_sh
, src_dir_path( make
, file
), dest
);
2519 case 't': /* script in tools dir */
2520 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s %s\n",
2521 install_sh
, tools_dir_path( make
, files
.str
[i
] ), dest
);
2523 case 'y': /* symlink */
2524 output_symlink_rule( files
.str
[i
], dest
, 1 );
2529 strarray_add( &make
->uninstall_files
, dest
);
2534 /*******************************************************************
2535 * output_install_rules
2537 * Rules are stored as a (file,dest) pair of values.
2538 * The first char of dest indicates the type of install.
2540 static void output_install_rules( struct makefile
*make
, enum install_rules rules
)
2543 struct strarray files
= make
->install_rules
[rules
];
2544 struct strarray targets
= empty_strarray
;
2546 if (!files
.count
) return;
2548 for (i
= 0; i
< files
.count
; i
+= 2)
2550 const char *file
= files
.str
[i
];
2551 switch (*files
.str
[i
+ 1])
2553 case '0': case '1': case '2': case '3': case '4':
2554 case '5': case '6': case '7': case '8': case '9': /* arch-dependent program */
2555 case 'd': /* data file */
2556 case 'p': /* program file */
2557 case 's': /* script */
2558 strarray_add_uniq( &targets
, obj_dir_path( make
, file
));
2560 case 't': /* script in tools dir */
2561 strarray_add_uniq( &targets
, tools_dir_path( make
, file
));
2566 output( "%s %s::", obj_dir_path( make
, "install" ), obj_dir_path( make
, install_targets
[rules
] ));
2567 output_filenames( targets
);
2569 output_install_commands( make
, files
);
2570 strarray_add_uniq( &make
->phony_targets
, obj_dir_path( make
, "install" ));
2571 strarray_add_uniq( &make
->phony_targets
, obj_dir_path( make
, install_targets
[rules
] ));
2575 static int cmp_string_length( const char **a
, const char **b
)
2577 int paths_a
= 0, paths_b
= 0;
2580 for (p
= *a
; *p
; p
++) if (*p
== '/') paths_a
++;
2581 for (p
= *b
; *p
; p
++) if (*p
== '/') paths_b
++;
2582 if (paths_b
!= paths_a
) return paths_b
- paths_a
;
2583 return strcmp( *a
, *b
);
2586 /*******************************************************************
2587 * get_removable_dirs
2589 * Retrieve a list of directories to try to remove after deleting the files.
2591 static struct strarray
get_removable_dirs( struct strarray files
)
2593 struct strarray dirs
= empty_strarray
;
2596 for (i
= 0; i
< files
.count
; i
++)
2598 char *dir
= xstrdup( files
.str
[i
] );
2599 while (strchr( dir
, '/' ))
2601 *strrchr( dir
, '/' ) = 0;
2602 strarray_add_uniq( &dirs
, xstrdup(dir
) );
2605 strarray_qsort( &dirs
, cmp_string_length
);
2610 /*******************************************************************
2611 * output_uninstall_rules
2613 static void output_uninstall_rules( struct makefile
*make
)
2615 static const char *dirs_order
[] =
2616 { "$(includedir)", "$(mandir)", "$(fontdir)", "$(nlsdir)", "$(datadir)", "$(dlldir)" };
2618 struct strarray uninstall_dirs
;
2621 if (!make
->uninstall_files
.count
) return;
2622 output( "uninstall::\n" );
2623 output_rm_filenames( make
->uninstall_files
, "rm -f" );
2624 strarray_add_uniq( &make
->phony_targets
, "uninstall" );
2626 if (!subdirs
.count
) return;
2627 uninstall_dirs
= get_removable_dirs( make
->uninstall_files
);
2628 output( "\t-rmdir" );
2629 for (i
= 0; i
< ARRAY_SIZE(dirs_order
); i
++)
2631 for (j
= 0; j
< uninstall_dirs
.count
; j
++)
2633 if (!uninstall_dirs
.str
[j
]) continue;
2634 if (strncmp( uninstall_dirs
.str
[j
] + strlen("$(DESTDIR)"), dirs_order
[i
], strlen(dirs_order
[i
]) ))
2636 output_filename( uninstall_dirs
.str
[j
] );
2637 uninstall_dirs
.str
[j
] = NULL
;
2640 for (j
= 0; j
< uninstall_dirs
.count
; j
++)
2641 if (uninstall_dirs
.str
[j
]) output_filename( uninstall_dirs
.str
[j
] );
2646 /*******************************************************************
2649 static void output_po_files( struct makefile
*make
)
2651 const char *po_dir
= src_dir_path( make
, "po" );
2656 for (i
= 0; i
< linguas
.count
; i
++)
2657 output_filename( strmake( "%s/%s.po", po_dir
, linguas
.str
[i
] ));
2658 output( ": %s/wine.pot\n", po_dir
);
2659 output( "\t%smsgmerge --previous -q $@ %s/wine.pot | msgattrib --no-obsolete -o $@.new && mv $@.new $@\n",
2660 cmd_prefix( "MSG" ), po_dir
);
2661 output( "po/all:" );
2662 for (i
= 0; i
< linguas
.count
; i
++)
2663 output_filename( strmake( "%s/%s.po", po_dir
, linguas
.str
[i
] ));
2666 output( "%s/wine.pot:", po_dir
);
2667 output_filenames( make
->pot_files
);
2669 output( "\t%smsgcat -o $@", cmd_prefix( "MSG" ));
2670 output_filenames( make
->pot_files
);
2672 strarray_add( &make
->maintainerclean_files
, strmake( "%s/wine.pot", po_dir
));
2676 /*******************************************************************
2679 static void output_source_y( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2681 /* add source file dependency for parallel makes */
2682 char *header
= strmake( "%s.tab.h", obj
);
2684 if (find_include_file( make
, header
))
2686 output( "%s: %s\n", obj_dir_path( make
, header
), source
->filename
);
2687 output( "\t%s%s -o %s.tab.c -d %s\n",
2688 cmd_prefix( "BISON" ), bison
, obj_dir_path( make
, obj
), source
->filename
);
2689 output( "%s.tab.c: %s %s\n", obj_dir_path( make
, obj
),
2690 source
->filename
, obj_dir_path( make
, header
));
2691 strarray_add( &make
->clean_files
, header
);
2693 else output( "%s.tab.c: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2695 output( "\t%s%s -o $@ %s\n", cmd_prefix( "BISON" ), bison
, source
->filename
);
2699 /*******************************************************************
2702 static void output_source_l( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2704 output( "%s.yy.c: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2705 output( "\t%s%s -o$@ %s\n", cmd_prefix( "FLEX" ), flex
, source
->filename
);
2709 /*******************************************************************
2712 static void output_source_h( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2714 if (source
->file
->flags
& FLAG_GENERATED
)
2715 strarray_add( &make
->all_targets
[0], source
->name
);
2716 else if ((source
->file
->flags
& FLAG_INSTALL
) || strncmp( source
->name
, "wine/", 5 ))
2717 add_install_rule( make
, source
->name
, 0, source
->name
,
2718 strmake( "D$(includedir)/wine/%s", get_include_install_path( source
->name
) ));
2722 /*******************************************************************
2725 static void output_source_rc( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2727 struct strarray defines
= get_source_defines( make
, source
, obj
);
2728 const char *po_dir
= NULL
, *res_file
= strmake( "%s.res", obj
);
2729 unsigned int i
, arch
;
2731 if (source
->file
->flags
& FLAG_RC_HEADER
) return;
2732 if (source
->file
->flags
& FLAG_GENERATED
) strarray_add( &make
->clean_files
, source
->name
);
2733 if (linguas
.count
&& (source
->file
->flags
& FLAG_RC_PO
)) po_dir
= "po";
2734 if (!make
->testdll
|| !find_src_file( make
, strmake( "%s.spec", obj
) )) /* RC is for a TESTDLL */
2736 for (arch
= 0; arch
< archs
.count
; arch
++)
2737 if (!make
->disabled
[arch
]) strarray_add( &make
->res_files
[arch
], res_file
);
2739 else strarray_add( &make
->clean_files
, res_file
);
2741 if (source
->file
->flags
& FLAG_RC_PO
)
2743 strarray_add( &make
->pot_files
, strmake( "%s.pot", obj
));
2744 output( "%s.pot ", obj_dir_path( make
, obj
) );
2746 output( "%s: %s", obj_dir_path( make
, res_file
), source
->filename
);
2747 output_filename( tools_path( make
, "wrc" ));
2748 if (make
->src_dir
) output_filename( "nls/locale.nls" );
2749 output_filenames( source
->dependencies
);
2751 output( "\t%s%s -u -o $@", cmd_prefix( "WRC" ), tools_path( make
, "wrc" ) );
2752 if (make
->is_win16
) output_filename( "-m16" );
2753 output_filename( "--nostdinc" );
2754 if (po_dir
) output_filename( strmake( "--po-dir=%s", po_dir
));
2755 output_filenames( defines
);
2756 output_filename( source
->filename
);
2760 output( "%s:", obj_dir_path( make
, res_file
));
2761 for (i
= 0; i
< linguas
.count
; i
++)
2762 output_filename( strmake( "%s/%s.mo", po_dir
, linguas
.str
[i
] ));
2768 /*******************************************************************
2771 static void output_source_mc( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2773 unsigned int i
, arch
;
2774 char *obj_path
= obj_dir_path( make
, obj
);
2775 char *res_file
= strmake( "%s.res", obj
);
2777 for (arch
= 0; arch
< archs
.count
; arch
++)
2778 if (!make
->disabled
[arch
]) strarray_add( &make
->res_files
[arch
], res_file
);
2779 strarray_add( &make
->pot_files
, strmake( "%s.pot", obj
));
2780 output( "%s.pot %s.res: %s", obj_path
, obj_path
, source
->filename
);
2781 output_filename( tools_path( make
, "wmc" ));
2782 output_filenames( source
->dependencies
);
2783 if (make
->src_dir
) output_filename( "nls/locale.nls" );
2785 output( "\t%s%s -u -o $@ %s", cmd_prefix( "WMC" ), tools_path( make
, "wmc" ), source
->filename
);
2788 output_filename( "--po-dir=po" );
2790 output( "%s.res:", obj_dir_path( make
, obj
));
2791 for (i
= 0; i
< linguas
.count
; i
++)
2792 output_filename( strmake( "po/%s.mo", linguas
.str
[i
] ));
2798 /*******************************************************************
2801 static void output_source_res( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2803 if (make
->disabled
[source
->arch
]) return;
2804 strarray_add( &make
->res_files
[source
->arch
], source
->name
);
2808 /*******************************************************************
2811 static void output_source_idl( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2813 struct strarray defines
= get_source_defines( make
, source
, obj
);
2814 struct strarray headers
= empty_strarray
;
2815 struct strarray deps
= empty_strarray
;
2816 struct strarray multiarch_targets
[MAX_ARCHS
] = { empty_strarray
};
2818 unsigned int i
, arch
;
2820 if (find_include_file( make
, strmake( "%s.h", obj
))) source
->file
->flags
|= FLAG_IDL_HEADER
;
2821 if (!source
->file
->flags
) return;
2823 if (source
->file
->flags
& FLAG_IDL_PROXY
) strarray_add( &make
->dlldata_files
, source
->name
);
2824 if (source
->file
->flags
& FLAG_INSTALL
)
2826 add_install_rule( make
, source
->name
, 0, xstrdup( source
->name
),
2827 strmake( "D$(includedir)/wine/%s.idl", get_include_install_path( obj
) ));
2828 if (source
->file
->flags
& FLAG_IDL_HEADER
)
2829 add_install_rule( make
, source
->name
, 0, strmake( "%s.h", obj
),
2830 strmake( "d$(includedir)/wine/%s.h", get_include_install_path( obj
) ));
2832 if (source
->file
->flags
& FLAG_IDL_HEADER
)
2834 dest
= strmake( "%s.h", obj
);
2835 strarray_add( &headers
, dest
);
2836 if (!find_src_file( make
, dest
)) strarray_add( &make
->clean_files
, dest
);
2839 for (i
= 0; i
< ARRAY_SIZE(idl_outputs
); i
++)
2841 if (!(source
->file
->flags
& idl_outputs
[i
].flag
)) continue;
2842 for (arch
= 0; arch
< archs
.count
; arch
++)
2844 if (!is_multiarch( arch
)) continue;
2845 if (make
->disabled
[arch
]) continue;
2846 dest
= strmake( "%s%s%s", arch_dirs
[arch
], obj
, idl_outputs
[i
].ext
);
2847 if (!find_src_file( make
, dest
)) strarray_add( &make
->clean_files
, dest
);
2848 strarray_add( &multiarch_targets
[arch
], dest
);
2852 for (arch
= 0; arch
< archs
.count
; arch
++)
2854 struct strarray arch_deps
= empty_strarray
;
2856 if (!arch
) strarray_addall( &arch_deps
, headers
);
2857 strarray_addall( &arch_deps
, multiarch_targets
[arch
] );
2858 if (!arch_deps
.count
) continue;
2859 output_filenames_obj_dir( make
, arch_deps
);
2861 output( "\t%s%s -o $@", cmd_prefix( "WIDL" ), tools_path( make
, "widl" ) );
2862 output_filenames( target_flags
[arch
] );
2863 output_filename( "--nostdinc" );
2864 output_filename( "-Ldlls/\\*" );
2865 output_filenames( defines
);
2866 output_filenames( get_expanded_make_var_array( make
, "EXTRAIDLFLAGS" ));
2867 output_filenames( get_expanded_file_local_var( make
, obj
, "EXTRAIDLFLAGS" ));
2868 output_filename( source
->filename
);
2870 strarray_addall( &deps
, arch_deps
);
2875 output_filenames_obj_dir( make
, deps
);
2877 output_filename( tools_path( make
, "widl" ));
2878 output_filename( source
->filename
);
2879 output_filenames( source
->dependencies
);
2883 if (source
->importlibdeps
.count
)
2885 for (arch
= 0; arch
< archs
.count
; arch
++)
2887 if (!multiarch_targets
[arch
].count
) continue;
2888 output_filenames_obj_dir( make
, multiarch_targets
[arch
] );
2890 for (i
= 0; i
< source
->importlibdeps
.count
; i
++)
2892 struct makefile
*submake
= find_importlib_module( source
->importlibdeps
.str
[i
] );
2893 const char *module
= strmake( "%s%s", arch_pe_dirs
[arch
], submake
->module
);
2894 output_filename( obj_dir_path( submake
, module
));
2902 /*******************************************************************
2905 static void output_source_x( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2907 output( "%s.h: %s%s %s\n", obj_dir_path( make
, obj
),
2908 tools_dir_path( make
, "make_xftmpl" ), tools_ext
, source
->filename
);
2909 output( "\t%s%s%s -H -o $@ %s\n", cmd_prefix( "GEN" ),
2910 tools_dir_path( make
, "make_xftmpl" ), tools_ext
, source
->filename
);
2911 if (source
->file
->flags
& FLAG_INSTALL
)
2913 add_install_rule( make
, source
->name
, 0, source
->name
,
2914 strmake( "D$(includedir)/wine/%s", get_include_install_path( source
->name
) ));
2915 add_install_rule( make
, source
->name
, 0, strmake( "%s.h", obj
),
2916 strmake( "d$(includedir)/wine/%s.h", get_include_install_path( obj
) ));
2921 /*******************************************************************
2924 static void output_source_sfd( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2927 char *ttf_obj
= strmake( "%s.ttf", obj
);
2928 char *ttf_file
= src_dir_path( make
, ttf_obj
);
2930 if (fontforge
&& !make
->src_dir
)
2932 output( "%s: %s\n", ttf_file
, source
->filename
);
2933 output( "\t%s%s -script %s %s $@\n", cmd_prefix( "GEN" ),
2934 fontforge
, root_src_dir_path( "fonts/genttf.ff" ), source
->filename
);
2935 if (!(source
->file
->flags
& FLAG_SFD_FONTS
)) strarray_add( &make
->font_files
, ttf_obj
);
2936 strarray_add( &make
->maintainerclean_files
, ttf_obj
);
2938 if (source
->file
->flags
& FLAG_INSTALL
)
2940 add_install_rule( make
, source
->name
, 0, ttf_obj
, strmake( "D$(fontdir)/%s", ttf_obj
));
2941 output_srcdir_symlink( make
, ttf_obj
);
2944 if (source
->file
->flags
& FLAG_SFD_FONTS
)
2946 struct strarray
*array
= source
->file
->args
;
2948 for (i
= 0; i
< array
->count
; i
++)
2950 char *font
= strtok( xstrdup(array
->str
[i
]), " \t" );
2951 char *args
= strtok( NULL
, "" );
2953 strarray_add( &make
->all_targets
[0], xstrdup( font
));
2954 output( "%s: %s %s\n", obj_dir_path( make
, font
),
2955 tools_path( make
, "sfnt2fon" ), ttf_file
);
2956 output( "\t%s%s -q -o $@ %s %s\n", cmd_prefix( "GEN" ),
2957 tools_path( make
, "sfnt2fon" ), ttf_file
, args
);
2958 add_install_rule( make
, source
->name
, 0, xstrdup(font
), strmake( "d$(fontdir)/%s", font
));
2964 /*******************************************************************
2967 static void output_source_svg( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2969 static const char * const images
[] = { "bmp", "cur", "ico", NULL
};
2972 if (convert
&& rsvg
&& icotool
)
2974 for (i
= 0; images
[i
]; i
++)
2975 if (find_include_file( make
, strmake( "%s.%s", obj
, images
[i
] ))) break;
2979 output( "%s.%s: %s\n", src_dir_path( make
, obj
), images
[i
], source
->filename
);
2980 output( "\t%sCONVERT=\"%s\" ICOTOOL=\"%s\" RSVG=\"%s\" %s %s $@\n",
2981 cmd_prefix( "GEN" ), convert
, icotool
, rsvg
,
2982 root_src_dir_path( "tools/buildimage" ), source
->filename
);
2983 strarray_add( &make
->maintainerclean_files
, strmake( "%s.%s", obj
, images
[i
] ));
2989 /*******************************************************************
2992 static void output_source_nls( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2994 add_install_rule( make
, source
->name
, 0, source
->name
,
2995 strmake( "D$(nlsdir)/%s", source
->name
));
2996 output_srcdir_symlink( make
, strmake( "%s.nls", obj
));
3000 /*******************************************************************
3001 * output_source_desktop
3003 static void output_source_desktop( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
3005 add_install_rule( make
, source
->name
, 0, source
->name
,
3006 strmake( "D$(datadir)/applications/%s", source
->name
));
3010 /*******************************************************************
3013 static void output_source_po( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
3015 output( "%s.mo: %s\n", obj_dir_path( make
, obj
), source
->filename
);
3016 output( "\t%s%s -o $@ %s\n", cmd_prefix( "MSG" ), msgfmt
, source
->filename
);
3017 strarray_add( &make
->all_targets
[0], strmake( "%s.mo", obj
));
3021 /*******************************************************************
3024 static void output_source_in( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
3028 if (make
== include_makefile
) return; /* ignore generated includes */
3029 if (strendswith( obj
, ".man" ) && source
->file
->args
)
3031 struct strarray symlinks
;
3032 char *dir
, *dest
= replace_extension( obj
, ".man", "" );
3033 char *lang
= strchr( dest
, '.' );
3034 char *section
= source
->file
->args
;
3038 dir
= strmake( "$(mandir)/%s/man%s", lang
, section
);
3040 else dir
= strmake( "$(mandir)/man%s", section
);
3041 add_install_rule( make
, dest
, 0, obj
, strmake( "d%s/%s.%s", dir
, dest
, section
));
3042 symlinks
= get_expanded_file_local_var( make
, dest
, "SYMLINKS" );
3043 for (i
= 0; i
< symlinks
.count
; i
++)
3044 add_install_rule( make
, symlinks
.str
[i
], 0, strmake( "%s.%s", dest
, section
),
3045 strmake( "y%s/%s.%s", dir
, symlinks
.str
[i
], section
));
3049 strarray_add( &make
->in_files
, obj
);
3050 strarray_add( &make
->all_targets
[0], obj
);
3051 output( "%s: %s\n", obj_dir_path( make
, obj
), source
->filename
);
3052 output( "\t%s%s %s >$@ || (rm -f $@ && false)\n", cmd_prefix( "SED" ), sed_cmd
, source
->filename
);
3053 output( "%s:", obj_dir_path( make
, obj
));
3054 output_filenames( source
->dependencies
);
3056 add_install_rule( make
, obj
, 0, obj
, strmake( "d$(datadir)/wine/%s", obj
));
3060 /*******************************************************************
3061 * output_source_spec
3063 static void output_source_spec( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
3065 struct strarray imports
= get_expanded_file_local_var( make
, obj
, "IMPORTS" );
3066 struct strarray dll_flags
= empty_strarray
;
3067 struct strarray default_imports
= empty_strarray
;
3068 struct strarray all_libs
, dep_libs
;
3069 const char *dll_name
, *obj_name
, *res_name
, *output_rsrc
, *output_file
, *debug_file
;
3072 if (!imports
.count
) imports
= make
->imports
;
3073 strarray_addall( &dll_flags
, make
->extradllflags
);
3074 strarray_addall( &dll_flags
, get_expanded_file_local_var( make
, obj
, "EXTRADLLFLAGS" ));
3075 if (!strarray_exists( &dll_flags
, "-nodefaultlibs" )) default_imports
= get_default_imports( make
, imports
);
3077 for (arch
= 0; arch
< archs
.count
; arch
++)
3079 if (!is_multiarch( arch
)) continue;
3080 all_libs
= dep_libs
= empty_strarray
;
3081 strarray_addall( &all_libs
, add_import_libs( make
, &dep_libs
, imports
, IMPORT_TYPE_DIRECT
, arch
) );
3082 strarray_addall( &all_libs
, add_import_libs( make
, &dep_libs
, default_imports
, IMPORT_TYPE_DEFAULT
, arch
) );
3083 if (!arch
) strarray_addall( &all_libs
, libs
);
3084 dll_name
= arch_module_name( strmake( "%s.dll", obj
), arch
);
3085 obj_name
= obj_dir_path( make
, strmake( "%s%s.o", arch_dirs
[arch
], obj
));
3086 output_file
= obj_dir_path( make
, dll_name
);
3087 output_rsrc
= strmake( "%s.res", dll_name
);
3089 if (!find_src_file( make
, strmake( "%s.rc", obj
) )) res_name
= NULL
;
3090 else res_name
= obj_dir_path( make
, strmake( "%s.res", obj
) );
3092 strarray_add( &make
->clean_files
, dll_name
);
3093 strarray_add( &make
->res_files
[arch
], output_rsrc
);
3094 output( "%s:", obj_dir_path( make
, output_rsrc
));
3095 output_filename( output_file
);
3096 output_filename( tools_path( make
, "wrc" ));
3098 output( "\t%secho \"%s.dll TESTDLL \\\"%s\\\"\" | %s -u -o $@\n", cmd_prefix( "WRC" ), obj
, output_file
,
3099 tools_path( make
, "wrc" ));
3101 output( "%s:", output_file
);
3102 output_filename( source
->filename
);
3103 output_filename( obj_name
);
3104 if (res_name
) output_filename( res_name
);
3105 output_filenames( dep_libs
);
3106 output_filename( tools_path( make
, "winebuild" ));
3107 output_filename( tools_path( make
, "winegcc" ));
3109 output_winegcc_command( make
, arch
);
3110 output_filename( "-s" );
3111 output_filenames( dll_flags
);
3112 if (arch
) output_filenames( get_expanded_arch_var_array( make
, "EXTRADLLFLAGS", arch
));
3113 output_filename( "-shared" );
3114 output_filename( source
->filename
);
3115 output_filename( obj_name
);
3116 if (res_name
) output_filename( res_name
);
3117 if ((debug_file
= get_debug_file( make
, dll_name
, arch
)))
3118 output_filename( strmake( "-Wl,--debug-file,%s", obj_dir_path( make
, debug_file
)));
3119 output_filenames( all_libs
);
3120 output_filename( arch_make_variable( "LDFLAGS", arch
));
3126 /*******************************************************************
3129 static void output_source_xml( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
3131 if (wayland_scanner
)
3133 output( "%s-protocol.c: %s\n", obj_dir_path( make
, obj
), source
->filename
);
3134 output( "\t%s%s private-code %s $@\n", cmd_prefix( "GEN" ), wayland_scanner
, source
->filename
);
3135 output( "%s-client-protocol.h: %s\n", obj_dir_path( make
, obj
), source
->filename
);
3136 output( "\t%s%s client-header %s $@\n", cmd_prefix( "GEN" ), wayland_scanner
, source
->filename
);
3141 /*******************************************************************
3142 * output_source_one_arch
3144 static void output_source_one_arch( struct makefile
*make
, struct incl_file
*source
, const char *obj
,
3145 struct strarray defines
, struct strarray
*targets
,
3146 unsigned int arch
, int is_dll_src
)
3148 const char *obj_name
;
3150 if (make
->disabled
[arch
] && !(source
->file
->flags
& FLAG_C_IMPLIB
)) return;
3154 if (source
->file
->flags
& FLAG_C_UNIX
) return;
3155 if (!is_using_msvcrt( make
) && !make
->staticlib
&& !(source
->file
->flags
& FLAG_C_IMPLIB
)) return;
3157 else if (source
->file
->flags
& FLAG_C_UNIX
)
3159 if (!unix_lib_supported
) return;
3161 else if (archs
.count
> 1 && is_using_msvcrt( make
))
3163 if (!so_dll_supported
) return;
3164 if (!(source
->file
->flags
& FLAG_C_IMPLIB
) && (!make
->staticlib
|| make
->extlib
)) return;
3167 obj_name
= strmake( "%s%s.o", source
->arch
? "" : arch_dirs
[arch
], obj
);
3168 strarray_add( targets
, obj_name
);
3170 if (source
->file
->flags
& FLAG_C_UNIX
)
3171 strarray_add( &make
->unixobj_files
, obj_name
);
3172 else if (source
->file
->flags
& FLAG_C_IMPLIB
)
3173 strarray_add( &make
->implib_files
[arch
], obj_name
);
3174 else if (!is_dll_src
)
3175 strarray_add( &make
->object_files
[arch
], obj_name
);
3177 strarray_add( &make
->clean_files
, obj_name
);
3179 output( "%s: %s\n", obj_dir_path( make
, obj_name
), source
->filename
);
3180 output( "\t%s%s -c -o $@ %s", cmd_prefix( "CC" ), arch_make_variable( "CC", arch
), source
->filename
);
3181 output_filenames( defines
);
3182 if (!source
->use_msvcrt
) output_filenames( make
->unix_cflags
);
3183 output_filenames( make
->extlib
? extra_cflags_extlib
[arch
] : extra_cflags
[arch
] );
3186 if (source
->file
->flags
& FLAG_C_UNIX
)
3188 output_filenames( unix_dllflags
);
3190 else if (make
->module
|| make
->testdll
)
3192 output_filenames( dll_flags
);
3193 if (source
->use_msvcrt
) output_filenames( msvcrt_flags
);
3194 if (!unix_lib_supported
&& make
->module
&& is_crt_module( make
->module
))
3195 output_filename( "-fno-builtin" );
3200 if (make
->module
&& is_crt_module( make
->module
)) output_filename( "-fno-builtin" );
3203 output_filenames( cpp_flags
);
3204 output_filename( arch_make_variable( "CFLAGS", arch
));
3207 if (make
->testdll
&& !is_dll_src
&& strendswith( source
->name
, ".c" ) &&
3208 !(source
->file
->flags
& FLAG_GENERATED
))
3210 const char *ok_file
, *test_exe
;
3212 ok_file
= strmake( "%s%s.ok", arch_dirs
[arch
], obj
);
3213 test_exe
= replace_extension( make
->testdll
, ".dll", "_test.exe" );
3214 strarray_add( &make
->ok_files
[arch
], ok_file
);
3215 output( "%s:\n", obj_dir_path( make
, ok_file
));
3216 output( "\t%s%s $(RUNTESTFLAGS) -T . -M %s -p %s %s && touch $@\n",
3217 cmd_prefix( "TEST" ),
3218 root_src_dir_path( "tools/runtest" ), make
->testdll
,
3219 obj_dir_path( make
, arch_module_name( test_exe
, arch
)), obj
);
3224 /*******************************************************************
3225 * output_source_default
3227 static void output_source_default( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
3229 struct strarray defines
= get_source_defines( make
, source
, obj
);
3230 struct strarray targets
= empty_strarray
;
3231 int is_dll_src
= (make
->testdll
&& strendswith( source
->name
, ".c" ) &&
3232 find_src_file( make
, replace_extension( source
->name
, ".c", ".spec" )));
3235 for (arch
= 0; arch
< archs
.count
; arch
++)
3236 if (!source
->arch
|| source
->arch
== arch
)
3237 output_source_one_arch( make
, source
, obj
, defines
, &targets
, arch
, is_dll_src
);
3239 if (source
->file
->flags
& FLAG_GENERATED
)
3241 if (!make
->testdll
|| !strendswith( source
->filename
, "testlist.c" ))
3242 strarray_add( &make
->clean_files
, source
->basename
);
3246 if (make
->testdll
&& !is_dll_src
&& strendswith( source
->name
, ".c" ))
3247 strarray_add( &make
->test_files
, obj
);
3250 if (targets
.count
&& source
->dependencies
.count
)
3252 output_filenames_obj_dir( make
, targets
);
3254 output_filenames( source
->dependencies
);
3260 /* dispatch table to output rules for a single source file */
3264 void (*fn
)( struct makefile
*make
, struct incl_file
*source
, const char *obj
);
3265 } output_source_funcs
[] =
3267 { "y", output_source_y
},
3268 { "l", output_source_l
},
3269 { "h", output_source_h
},
3270 { "rh", output_source_h
},
3271 { "inl", output_source_h
},
3272 { "rc", output_source_rc
},
3273 { "mc", output_source_mc
},
3274 { "res", output_source_res
},
3275 { "idl", output_source_idl
},
3276 { "sfd", output_source_sfd
},
3277 { "svg", output_source_svg
},
3278 { "nls", output_source_nls
},
3279 { "desktop", output_source_desktop
},
3280 { "po", output_source_po
},
3281 { "in", output_source_in
},
3282 { "x", output_source_x
},
3283 { "spec", output_source_spec
},
3284 { "xml", output_source_xml
},
3285 { NULL
, output_source_default
}
3289 /*******************************************************************
3290 * output_fake_module
3292 static void output_fake_module( struct makefile
*make
)
3294 unsigned int arch
= 0; /* fake modules are always native */
3295 const char *spec_file
= NULL
, *name
= strmake( "%s%s", arch_pe_dirs
[arch
], make
->module
);
3297 if (make
->disabled
[arch
]) return;
3299 if (!make
->is_exe
) spec_file
= src_dir_path( make
, replace_extension( make
->module
, ".dll", ".spec" ));
3301 strarray_add( &make
->all_targets
[arch
], name
);
3302 add_install_rule( make
, make
->module
, arch
, name
, strmake( "d$(dlldir)/%s", name
));
3304 output( "%s:", obj_dir_path( make
, name
));
3305 if (spec_file
) output_filename( spec_file
);
3306 output_filenames_obj_dir( make
, make
->res_files
[arch
] );
3307 output_filename( tools_path( make
, "winebuild" ));
3308 output_filename( tools_path( make
, "winegcc" ));
3310 output_winegcc_command( make
, arch
);
3311 output_filename( "-Wb,--fake-module" );
3314 output_filename( "-shared" );
3315 output_filename( spec_file
);
3317 output_filenames( make
->extradllflags
);
3318 output_filenames_obj_dir( make
, make
->res_files
[arch
] );
3323 /*******************************************************************
3326 static void output_module( struct makefile
*make
, unsigned int arch
)
3328 struct strarray default_imports
= empty_strarray
;
3329 struct strarray all_libs
= empty_strarray
;
3330 struct strarray dep_libs
= empty_strarray
;
3331 struct strarray imports
= make
->imports
;
3332 const char *module_name
;
3333 const char *debug_file
;
3334 char *spec_file
= NULL
;
3337 if (make
->disabled
[arch
]) return;
3339 if (!make
->is_exe
) spec_file
= src_dir_path( make
, replace_extension( make
->module
, ".dll", ".spec" ));
3341 if (!make
->data_only
)
3343 module_name
= arch_module_name( make
->module
, arch
);
3345 if (!strarray_exists( &make
->extradllflags
, "-nodefaultlibs" )) default_imports
= get_default_imports( make
, imports
);
3347 strarray_addall( &all_libs
, add_import_libs( make
, &dep_libs
, imports
, IMPORT_TYPE_DIRECT
, arch
));
3348 strarray_addall( &all_libs
, add_import_libs( make
, &dep_libs
, make
->delayimports
, IMPORT_TYPE_DELAYED
, arch
));
3349 strarray_addall( &all_libs
, add_import_libs( make
, &dep_libs
, default_imports
, IMPORT_TYPE_DEFAULT
, arch
) );
3350 if (!arch
) strarray_addall( &all_libs
, libs
);
3352 if (delay_load_flags
[arch
])
3354 for (i
= 0; i
< make
->delayimports
.count
; i
++)
3356 struct makefile
*import
= get_static_lib( make
->delayimports
.str
[i
], arch
);
3357 if (import
) strarray_add( &all_libs
, strmake( "%s%s", delay_load_flags
[arch
], import
->module
));
3361 else module_name
= strmake( "%s%s", arch_pe_dirs
[arch
], make
->module
);
3363 strarray_add( &make
->all_targets
[arch
], module_name
);
3364 if (make
->data_only
)
3365 add_install_rule( make
, make
->module
, arch
, module_name
,
3366 strmake( "d$(dlldir)/%s%s", arch_pe_dirs
[arch
], make
->module
));
3368 add_install_rule( make
, make
->module
, arch
, module_name
,
3369 strmake( "%c%s%s%s", '0' + arch
, arch_install_dirs
[arch
], make
->module
,
3372 output( "%s:", obj_dir_path( make
, module_name
));
3373 if (spec_file
) output_filename( spec_file
);
3374 output_filenames_obj_dir( make
, make
->object_files
[arch
] );
3375 output_filenames_obj_dir( make
, make
->res_files
[arch
] );
3376 output_filenames( dep_libs
);
3377 output_filename( tools_path( make
, "winebuild" ));
3378 output_filename( tools_path( make
, "winegcc" ));
3380 output_winegcc_command( make
, arch
);
3381 if (arch
) output_filename( "-Wl,--wine-builtin" );
3384 output_filename( "-shared" );
3385 output_filename( spec_file
);
3387 output_filenames( make
->extradllflags
);
3388 if (arch
) output_filenames( get_expanded_arch_var_array( make
, "EXTRADLLFLAGS", arch
));
3389 output_filenames_obj_dir( make
, make
->object_files
[arch
] );
3390 output_filenames_obj_dir( make
, make
->res_files
[arch
] );
3391 debug_file
= get_debug_file( make
, module_name
, arch
);
3392 if (debug_file
) output_filename( strmake( "-Wl,--debug-file,%s", obj_dir_path( make
, debug_file
)));
3393 output_filenames( all_libs
);
3394 output_filename( arch_make_variable( "LDFLAGS", arch
));
3397 if (!make
->data_only
&& !arch
&& unix_lib_supported
) output_fake_module( make
);
3401 /*******************************************************************
3404 static void output_import_lib( struct makefile
*make
, unsigned int arch
)
3406 char *spec_file
= src_dir_path( make
, replace_extension( make
->module
, ".dll", ".spec" ));
3407 const char *name
= strmake( "%slib%s.a", arch_dirs
[arch
], make
->importlib
);
3409 strarray_add( &make
->clean_files
, name
);
3410 if (needs_delay_lib( make
, arch
))
3412 const char *delay_name
= replace_extension( name
, ".a", ".delay.a" );
3413 strarray_add( &make
->clean_files
, delay_name
);
3414 output( "%s ", obj_dir_path( make
, delay_name
));
3416 output( "%s: %s %s", obj_dir_path( make
, name
), tools_path( make
, "winebuild" ), spec_file
);
3417 output_filenames_obj_dir( make
, make
->implib_files
[arch
] );
3419 output( "\t%s%s -w --implib -o $@", cmd_prefix( "BUILD" ), tools_path( make
, "winebuild" ) );
3420 if (!delay_load_flags
[arch
]) output_filename( "--without-dlltool" );
3421 output_filenames( target_flags
[arch
] );
3422 if (make
->is_win16
) output_filename( "-m16" );
3423 output_filename( "--export" );
3424 output_filename( spec_file
);
3425 output_filenames_obj_dir( make
, make
->implib_files
[arch
] );
3428 add_install_rule( make
, make
->importlib
, arch
, name
,
3429 strmake( "d%slib%s.a", arch_install_dirs
[arch
], make
->importlib
));
3433 /*******************************************************************
3436 static void output_unix_lib( struct makefile
*make
)
3438 struct strarray unix_deps
= empty_strarray
;
3439 struct strarray unix_libs
= add_unix_libraries( make
, &unix_deps
);
3440 unsigned int arch
= 0; /* unix libs are always native */
3442 if (make
->disabled
[arch
]) return;
3444 strarray_add( &make
->all_targets
[arch
], make
->unixlib
);
3445 add_install_rule( make
, make
->module
, arch
, make
->unixlib
,
3446 strmake( "p%s%s", arch_install_dirs
[arch
], make
->unixlib
));
3447 output( "%s:", obj_dir_path( make
, make
->unixlib
));
3448 output_filenames_obj_dir( make
, make
->unixobj_files
);
3449 output_filenames( unix_deps
);
3451 output( "\t%s$(CC) -o $@", cmd_prefix( "CCLD" ));
3452 output_filenames( get_expanded_make_var_array( make
, "UNIXLDFLAGS" ));
3453 output_filenames_obj_dir( make
, make
->unixobj_files
);
3454 output_filenames( unix_libs
);
3455 output_filename( "$(LDFLAGS)" );
3460 /*******************************************************************
3463 static void output_static_lib( struct makefile
*make
, unsigned int arch
)
3465 const char *name
= strmake( "%s%s", arch_dirs
[arch
], make
->staticlib
);
3467 strarray_add( &make
->clean_files
, name
);
3468 output( "%s: %s", obj_dir_path( make
, name
), tools_path( make
, "winebuild" ));
3469 output_filenames_obj_dir( make
, make
->object_files
[arch
] );
3470 if (!arch
) output_filenames_obj_dir( make
, make
->unixobj_files
);
3472 output( "\t%s%s -w --staticlib -o $@", cmd_prefix( "BUILD" ), tools_path( make
, "winebuild" ));
3473 output_filenames( target_flags
[arch
] );
3474 output_filenames_obj_dir( make
, make
->object_files
[arch
] );
3475 if (!arch
) output_filenames_obj_dir( make
, make
->unixobj_files
);
3478 add_install_rule( make
, make
->staticlib
, arch
, name
,
3479 strmake( "d%s%s", arch_install_dirs
[arch
], make
->staticlib
));
3483 /*******************************************************************
3484 * output_test_module
3486 static void output_test_module( struct makefile
*make
, unsigned int arch
)
3488 char *basemodule
= replace_extension( make
->testdll
, ".dll", "" );
3489 char *stripped
= arch_module_name( strmake( "%s_test-stripped.exe", basemodule
), arch
);
3490 char *testmodule
= arch_module_name( strmake( "%s_test.exe", basemodule
), arch
);
3491 struct strarray default_imports
= get_default_imports( make
, make
->imports
);
3492 struct strarray dep_libs
= empty_strarray
;
3493 struct strarray all_libs
= empty_strarray
;
3494 struct makefile
*parent
= get_parent_makefile( make
);
3495 const char *debug_file
;
3497 strarray_addall( &all_libs
, add_import_libs( make
, &dep_libs
, make
->imports
, IMPORT_TYPE_DIRECT
, arch
) );
3498 strarray_addall( &all_libs
, add_import_libs( make
, &dep_libs
, default_imports
, IMPORT_TYPE_DEFAULT
, arch
) );
3500 strarray_add( &make
->all_targets
[arch
], testmodule
);
3501 strarray_add( &make
->clean_files
, stripped
);
3502 output( "%s:\n", obj_dir_path( make
, testmodule
));
3503 output_winegcc_command( make
, arch
);
3504 output_filenames( make
->extradllflags
);
3505 output_filenames_obj_dir( make
, make
->object_files
[arch
] );
3506 output_filenames_obj_dir( make
, make
->res_files
[arch
] );
3507 if ((debug_file
= get_debug_file( make
, testmodule
, arch
)))
3508 output_filename( strmake( "-Wl,--debug-file,%s", obj_dir_path( make
, debug_file
)));
3509 output_filenames( all_libs
);
3510 output_filename( arch_make_variable( "LDFLAGS", arch
));
3512 output( "%s:\n", obj_dir_path( make
, stripped
));
3513 output_winegcc_command( make
, arch
);
3514 output_filename( "-s" );
3515 output_filename( strmake( "-Wb,-F,%s_test.exe", basemodule
));
3516 output_filenames( make
->extradllflags
);
3517 output_filenames_obj_dir( make
, make
->object_files
[arch
] );
3518 output_filenames_obj_dir( make
, make
->res_files
[arch
] );
3519 output_filenames( all_libs
);
3520 output_filename( arch_make_variable( "LDFLAGS", arch
));
3522 output( "%s %s:", obj_dir_path( make
, testmodule
), obj_dir_path( make
, stripped
));
3523 output_filenames_obj_dir( make
, make
->object_files
[arch
] );
3524 output_filenames_obj_dir( make
, make
->res_files
[arch
] );
3525 output_filenames( dep_libs
);
3526 output_filename( tools_path( make
, "winebuild" ));
3527 output_filename( tools_path( make
, "winegcc" ));
3530 output( "programs/winetest/%s%s_test.res: %s\n", arch_dirs
[arch
], basemodule
,
3531 obj_dir_path( make
, stripped
));
3532 output( "\t%secho \"%s_test.exe TESTRES \\\"%s\\\"\" | %s -u -o $@\n", cmd_prefix( "WRC" ),
3533 basemodule
, obj_dir_path( make
, stripped
), tools_path( make
, "wrc" ));
3535 if (make
->disabled
[arch
] || (parent
&& parent
->disabled
[arch
]))
3537 make
->ok_files
[arch
] = empty_strarray
;
3540 output_filenames_obj_dir( make
, make
->ok_files
[arch
] );
3541 output( ": %s", obj_dir_path( make
, testmodule
));
3544 char *parent_module
= arch_module_name( make
->testdll
, arch
);
3545 output_filename( obj_dir_path( parent
, parent_module
));
3546 if (parent
->unixlib
) output_filename( obj_dir_path( parent
, parent
->unixlib
));
3549 output( "%s %s:", obj_dir_path( make
, "check" ), obj_dir_path( make
, "test" ));
3550 output_filenames_obj_dir( make
, make
->ok_files
[arch
] );
3552 strarray_add_uniq( &make
->phony_targets
, obj_dir_path( make
, "check" ));
3553 strarray_add_uniq( &make
->phony_targets
, obj_dir_path( make
, "test" ));
3554 output( "%s::\n", obj_dir_path( make
, "testclean" ));
3555 output( "\trm -f" );
3556 output_filenames_obj_dir( make
, make
->ok_files
[arch
] );
3558 strarray_addall( &make
->clean_files
, make
->ok_files
[arch
] );
3559 strarray_add_uniq( &make
->phony_targets
, obj_dir_path( make
, "testclean" ));
3563 /*******************************************************************
3566 static void output_programs( struct makefile
*make
)
3569 unsigned int arch
= 0; /* programs are always native */
3571 for (i
= 0; i
< make
->programs
.count
; i
++)
3573 char *program_installed
= NULL
;
3574 char *program
= strmake( "%s%s", make
->programs
.str
[i
], exe_ext
);
3575 struct strarray deps
= get_local_dependencies( make
, make
->programs
.str
[i
], make
->in_files
);
3576 struct strarray all_libs
= get_expanded_file_local_var( make
, make
->programs
.str
[i
], "LDFLAGS" );
3577 struct strarray objs
= get_expanded_file_local_var( make
, make
->programs
.str
[i
], "OBJS" );
3578 struct strarray symlinks
= get_expanded_file_local_var( make
, make
->programs
.str
[i
], "SYMLINKS" );
3580 if (!objs
.count
) objs
= make
->object_files
[arch
];
3581 if (!strarray_exists( &all_libs
, "-nodefaultlibs" ))
3583 strarray_addall( &all_libs
, get_expanded_make_var_array( make
, "UNIX_LIBS" ));
3584 strarray_addall( &all_libs
, libs
);
3587 output( "%s:", obj_dir_path( make
, program
) );
3588 output_filenames_obj_dir( make
, objs
);
3589 output_filenames( deps
);
3591 output( "\t%s$(CC) -o $@", cmd_prefix( "CCLD" ));
3592 output_filenames_obj_dir( make
, objs
);
3593 output_filenames( all_libs
);
3594 output_filename( "$(LDFLAGS)" );
3596 strarray_add( &make
->all_targets
[arch
], program
);
3598 for (j
= 0; j
< symlinks
.count
; j
++)
3600 output( "%s: %s\n", obj_dir_path( make
, symlinks
.str
[j
] ), obj_dir_path( make
, program
));
3601 output_symlink_rule( program
, obj_dir_path( make
, symlinks
.str
[j
] ), 0 );
3603 strarray_addall( &make
->all_targets
[arch
], symlinks
);
3605 add_install_rule( make
, program
, arch
, program_installed
? program_installed
: program
,
3606 strmake( "p$(bindir)/%s", program
));
3607 for (j
= 0; j
< symlinks
.count
; j
++)
3608 add_install_rule( make
, symlinks
.str
[j
], arch
, program
,
3609 strmake( "y$(bindir)/%s%s", symlinks
.str
[j
], exe_ext
));
3614 /*******************************************************************
3617 static void output_subdirs( struct makefile
*make
)
3619 struct strarray all_targets
= empty_strarray
;
3620 struct strarray makefile_deps
= empty_strarray
;
3621 struct strarray clean_files
= empty_strarray
;
3622 struct strarray testclean_files
= empty_strarray
;
3623 struct strarray distclean_files
= empty_strarray
;
3624 struct strarray distclean_dirs
= empty_strarray
;
3625 struct strarray dependencies
= empty_strarray
;
3626 struct strarray install_deps
[NB_INSTALL_RULES
] = { empty_strarray
};
3627 struct strarray tooldeps_deps
= empty_strarray
;
3628 struct strarray buildtest_deps
= empty_strarray
;
3629 unsigned int i
, j
, arch
;
3631 strarray_addall( &clean_files
, make
->clean_files
);
3632 strarray_addall( &distclean_files
, make
->distclean_files
);
3633 for (arch
= 0; arch
< archs
.count
; arch
++) strarray_addall( &all_targets
, make
->all_targets
[arch
] );
3634 for (i
= 0; i
< subdirs
.count
; i
++)
3636 struct strarray subclean
= empty_strarray
;
3637 strarray_addall( &subclean
, get_removable_dirs( submakes
[i
]->clean_files
));
3638 strarray_addall( &subclean
, get_removable_dirs( submakes
[i
]->distclean_files
));
3639 strarray_add( &makefile_deps
, src_dir_path( submakes
[i
], "Makefile.in" ));
3640 strarray_addall_uniq( &make
->phony_targets
, submakes
[i
]->phony_targets
);
3641 strarray_addall_uniq( &make
->uninstall_files
, submakes
[i
]->uninstall_files
);
3642 strarray_addall_uniq( &dependencies
, submakes
[i
]->dependencies
);
3643 strarray_addall_path( &clean_files
, submakes
[i
]->obj_dir
, submakes
[i
]->clean_files
);
3644 strarray_addall_path( &distclean_files
, submakes
[i
]->obj_dir
, submakes
[i
]->distclean_files
);
3645 strarray_addall_path( &distclean_dirs
, submakes
[i
]->obj_dir
, subclean
);
3646 strarray_addall_path( &make
->maintainerclean_files
, submakes
[i
]->obj_dir
, submakes
[i
]->maintainerclean_files
);
3647 strarray_addall_path( &make
->pot_files
, submakes
[i
]->obj_dir
, submakes
[i
]->pot_files
);
3649 for (arch
= 0; arch
< archs
.count
; arch
++)
3651 if (submakes
[i
]->disabled
[arch
]) continue;
3652 strarray_addall_path( &all_targets
, submakes
[i
]->obj_dir
, submakes
[i
]->all_targets
[arch
] );
3653 strarray_addall_path( &testclean_files
, submakes
[i
]->obj_dir
, submakes
[i
]->ok_files
[arch
] );
3655 if (submakes
[i
]->disabled
[0]) continue;
3657 strarray_addall_path( &all_targets
, submakes
[i
]->obj_dir
, submakes
[i
]->font_files
);
3658 if (!strcmp( submakes
[i
]->obj_dir
, "tools" ) || !strncmp( submakes
[i
]->obj_dir
, "tools/", 6 ))
3659 strarray_add( &tooldeps_deps
, obj_dir_path( submakes
[i
], "all" ));
3660 if (submakes
[i
]->testdll
)
3661 strarray_add( &buildtest_deps
, obj_dir_path( submakes
[i
], "all" ));
3662 for (j
= 0; j
< NB_INSTALL_RULES
; j
++)
3663 if (submakes
[i
]->install_rules
[j
].count
)
3664 strarray_add( &install_deps
[j
], obj_dir_path( submakes
[i
], install_targets
[j
] ));
3666 strarray_addall( &dependencies
, makefile_deps
);
3668 output_filenames( all_targets
);
3670 output( "Makefile:" );
3671 output_filenames( makefile_deps
);
3673 output_filenames( dependencies
);
3675 for (j
= 0; j
< NB_INSTALL_RULES
; j
++)
3677 if (!install_deps
[j
].count
) continue;
3678 if (strcmp( install_targets
[j
], "install-test" ))
3680 output( "install " );
3681 strarray_add_uniq( &make
->phony_targets
, "install" );
3683 output( "%s::", install_targets
[j
] );
3684 output_filenames( install_deps
[j
] );
3686 strarray_add_uniq( &make
->phony_targets
, install_targets
[j
] );
3688 output_uninstall_rules( make
);
3689 if (buildtest_deps
.count
)
3691 output( "buildtests:" );
3692 output_filenames( buildtest_deps
);
3694 strarray_add_uniq( &make
->phony_targets
, "buildtests" );
3696 output( "check test:" );
3697 output_filenames( testclean_files
);
3699 strarray_add_uniq( &make
->phony_targets
, "check" );
3700 strarray_add_uniq( &make
->phony_targets
, "test" );
3702 if (get_expanded_make_variable( make
, "GETTEXTPO_LIBS" )) output_po_files( make
);
3704 output( "clean::\n");
3705 output_rm_filenames( clean_files
, "rm -f" );
3706 output( "testclean::\n");
3707 output_rm_filenames( testclean_files
, "rm -f" );
3708 output( "distclean::\n");
3709 output_rm_filenames( distclean_files
, "rm -f" );
3710 output_rm_filenames( distclean_dirs
, "-rmdir 2>/dev/null" );
3711 output( "maintainer-clean::\n");
3712 output_rm_filenames( make
->maintainerclean_files
, "rm -f" );
3713 strarray_add_uniq( &make
->phony_targets
, "distclean" );
3714 strarray_add_uniq( &make
->phony_targets
, "testclean" );
3715 strarray_add_uniq( &make
->phony_targets
, "maintainer-clean" );
3717 if (tooldeps_deps
.count
)
3719 output( "__tooldeps__:" );
3720 output_filenames( tooldeps_deps
);
3722 strarray_add_uniq( &make
->phony_targets
, "__tooldeps__" );
3725 if (make
->phony_targets
.count
)
3727 output( ".PHONY:" );
3728 output_filenames( make
->phony_targets
);
3734 /*******************************************************************
3737 static void output_sources( struct makefile
*make
)
3739 struct strarray all_targets
= empty_strarray
;
3740 struct incl_file
*source
;
3741 unsigned int i
, j
, arch
;
3743 strarray_add_uniq( &make
->phony_targets
, "all" );
3745 LIST_FOR_EACH_ENTRY( source
, &make
->sources
, struct incl_file
, entry
)
3747 char *obj
= xstrdup( source
->name
);
3748 char *ext
= get_extension( obj
);
3750 if (!ext
) fatal_error( "unsupported file type %s\n", source
->name
);
3753 for (j
= 0; output_source_funcs
[j
].ext
; j
++)
3754 if (!strcmp( ext
, output_source_funcs
[j
].ext
)) break;
3756 output_source_funcs
[j
].fn( make
, source
, obj
);
3757 strarray_addall_uniq( &make
->dependencies
, source
->dependencies
);
3760 /* special case for winetest: add resource files from other test dirs */
3761 if (make
->obj_dir
&& !strcmp( make
->obj_dir
, "programs/winetest" ))
3763 for (arch
= 0; arch
< archs
.count
; arch
++)
3765 if (!is_multiarch( arch
)) continue;
3766 for (i
= 0; i
< subdirs
.count
; i
++)
3768 if (!submakes
[i
]->testdll
) continue;
3769 if (submakes
[i
]->disabled
[arch
]) continue;
3770 if (enable_tests
.count
&& !strarray_exists( &enable_tests
, submakes
[i
]->testdll
)) continue;
3771 strarray_add( &make
->res_files
[arch
],
3772 strmake( "%s%s", arch_dirs
[arch
],
3773 replace_extension( submakes
[i
]->testdll
, ".dll", "_test.res" )));
3778 if (make
->dlldata_files
.count
)
3780 output( "%s: %s %s\n", obj_dir_path( make
, "dlldata.c" ),
3781 tools_path( make
, "widl" ), src_dir_path( make
, "Makefile.in" ));
3782 output( "\t%s%s --dlldata-only -o $@", cmd_prefix( "WIDL" ), tools_path( make
, "widl" ));
3783 output_filenames( make
->dlldata_files
);
3787 if (make
->staticlib
)
3789 for (arch
= 0; arch
< archs
.count
; arch
++)
3790 if (is_multiarch( arch
) || (so_dll_supported
&& !make
->extlib
))
3791 output_static_lib( make
, arch
);
3793 else if (make
->module
)
3795 for (arch
= 0; arch
< archs
.count
; arch
++)
3797 if (is_multiarch( arch
)) output_module( make
, arch
);
3798 if (make
->importlib
&& (is_multiarch( arch
) || !is_native_arch_disabled( make
)))
3799 output_import_lib( make
, arch
);
3801 if (make
->unixlib
) output_unix_lib( make
);
3802 if (make
->is_exe
&& !make
->is_win16
&& unix_lib_supported
&& strendswith( make
->module
, ".exe" ))
3804 char *binary
= replace_extension( make
->module
, ".exe", "" );
3805 add_install_rule( make
, binary
, 0, "wineapploader", strmake( "t$(bindir)/%s", binary
));
3808 else if (make
->testdll
)
3810 for (arch
= 0; arch
< archs
.count
; arch
++)
3811 if (is_multiarch( arch
)) output_test_module( make
, arch
);
3813 else if (make
->programs
.count
) output_programs( make
);
3815 for (i
= 0; i
< make
->scripts
.count
; i
++)
3816 add_install_rule( make
, make
->scripts
.str
[i
], 0, make
->scripts
.str
[i
],
3817 strmake( "S$(bindir)/%s", make
->scripts
.str
[i
] ));
3819 for (i
= 0; i
< make
->extra_targets
.count
; i
++)
3820 if (strarray_exists( &make
->dependencies
, obj_dir_path( make
, make
->extra_targets
.str
[i
] )))
3821 strarray_add( &make
->clean_files
, make
->extra_targets
.str
[i
] );
3823 strarray_add( &make
->all_targets
[0], make
->extra_targets
.str
[i
] );
3825 if (!make
->src_dir
) strarray_add( &make
->distclean_files
, ".gitignore" );
3826 strarray_add( &make
->distclean_files
, "Makefile" );
3827 if (make
->testdll
) strarray_add( &make
->distclean_files
, "testlist.c" );
3830 strarray_addall( &make
->distclean_files
, get_expanded_make_var_array( make
, "CONFIGURE_TARGETS" ));
3831 else if (!strcmp( make
->obj_dir
, "po" ))
3832 strarray_add( &make
->distclean_files
, "LINGUAS" );
3834 for (arch
= 0; arch
< archs
.count
; arch
++)
3836 strarray_addall_uniq( &make
->clean_files
, make
->object_files
[arch
] );
3837 strarray_addall_uniq( &make
->clean_files
, make
->implib_files
[arch
] );
3838 strarray_addall_uniq( &make
->clean_files
, make
->res_files
[arch
] );
3839 strarray_addall_uniq( &make
->clean_files
, make
->all_targets
[arch
] );
3841 strarray_addall( &make
->clean_files
, make
->unixobj_files
);
3842 strarray_addall( &make
->clean_files
, make
->pot_files
);
3843 strarray_addall( &make
->clean_files
, make
->debug_files
);
3845 if (make
== top_makefile
)
3847 output_subdirs( make
);
3851 for (arch
= 0; arch
< archs
.count
; arch
++) strarray_addall( &all_targets
, make
->all_targets
[arch
] );
3852 strarray_addall( &all_targets
, make
->font_files
);
3853 if (all_targets
.count
)
3855 output( "%s:", obj_dir_path( make
, "all" ));
3856 output_filenames_obj_dir( make
, all_targets
);
3858 strarray_add_uniq( &make
->phony_targets
, obj_dir_path( make
, "all" ));
3860 for (i
= 0; i
< NB_INSTALL_RULES
; i
++) output_install_rules( make
, i
);
3862 if (make
->clean_files
.count
)
3864 output( "%s::\n", obj_dir_path( make
, "clean" ));
3865 output( "\trm -f" );
3866 output_filenames_obj_dir( make
, make
->clean_files
);
3868 strarray_add( &make
->phony_targets
, obj_dir_path( make
, "clean" ));
3873 /*******************************************************************
3876 static FILE *create_temp_file( const char *orig
)
3878 char *name
= xmalloc( strlen(orig
) + 13 );
3879 unsigned int i
, id
= getpid();
3883 for (i
= 0; i
< 100; i
++)
3885 sprintf( name
, "%s.tmp%08x", orig
, id
);
3886 if ((fd
= open( name
, O_RDWR
| O_CREAT
| O_EXCL
, 0666 )) != -1)
3888 ret
= fdopen( fd
, "w" );
3891 if (errno
!= EEXIST
) break;
3894 if (!ret
) fatal_error( "failed to create output file for '%s'\n", orig
);
3895 temp_file_name
= name
;
3900 /*******************************************************************
3903 static void rename_temp_file( const char *dest
)
3905 int ret
= rename( temp_file_name
, dest
);
3906 if (ret
== -1 && errno
== EEXIST
)
3908 /* rename doesn't overwrite on windows */
3910 ret
= rename( temp_file_name
, dest
);
3912 if (ret
== -1) fatal_error( "failed to rename output file to '%s'\n", dest
);
3913 temp_file_name
= NULL
;
3917 /*******************************************************************
3918 * are_files_identical
3920 static int are_files_identical( FILE *file1
, FILE *file2
)
3924 char buffer1
[8192], buffer2
[8192];
3925 int size1
= fread( buffer1
, 1, sizeof(buffer1
), file1
);
3926 int size2
= fread( buffer2
, 1, sizeof(buffer2
), file2
);
3927 if (size1
!= size2
) return 0;
3928 if (!size1
) return feof( file1
) && feof( file2
);
3929 if (memcmp( buffer1
, buffer2
, size1
)) return 0;
3934 /*******************************************************************
3935 * rename_temp_file_if_changed
3937 static void rename_temp_file_if_changed( const char *dest
)
3939 FILE *file1
, *file2
;
3942 if ((file1
= fopen( dest
, "r" )))
3944 if ((file2
= fopen( temp_file_name
, "r" )))
3946 do_rename
= !are_files_identical( file1
, file2
);
3953 unlink( temp_file_name
);
3954 temp_file_name
= NULL
;
3956 else rename_temp_file( dest
);
3960 /*******************************************************************
3963 static void output_linguas( const struct makefile
*make
)
3965 const char *dest
= obj_dir_path( make
, "LINGUAS" );
3966 struct incl_file
*source
;
3968 output_file
= create_temp_file( dest
);
3970 output( "# Automatically generated by make depend; DO NOT EDIT!!\n" );
3971 LIST_FOR_EACH_ENTRY( source
, &make
->sources
, struct incl_file
, entry
)
3972 if (strendswith( source
->name
, ".po" ))
3973 output( "%s\n", replace_extension( source
->name
, ".po", "" ));
3975 if (fclose( output_file
)) fatal_perror( "write" );
3977 rename_temp_file_if_changed( dest
);
3981 /*******************************************************************
3984 static void output_testlist( const struct makefile
*make
)
3986 const char *dest
= obj_dir_path( make
, "testlist.c" );
3989 output_file
= create_temp_file( dest
);
3991 output( "/* Automatically generated by make depend; DO NOT EDIT!! */\n\n" );
3992 output( "#define WIN32_LEAN_AND_MEAN\n" );
3993 output( "#include <windows.h>\n\n" );
3994 output( "#define STANDALONE\n" );
3995 output( "#include \"wine/test.h\"\n\n" );
3997 for (i
= 0; i
< make
->test_files
.count
; i
++)
3998 output( "extern void func_%s(void);\n", make
->test_files
.str
[i
] );
4000 output( "const struct test winetest_testlist[] =\n" );
4002 for (i
= 0; i
< make
->test_files
.count
; i
++)
4003 output( " { \"%s\", func_%s },\n", make
->test_files
.str
[i
], make
->test_files
.str
[i
] );
4004 output( " { 0, 0 }\n" );
4007 if (fclose( output_file
)) fatal_perror( "write" );
4009 rename_temp_file_if_changed( dest
);
4013 /*******************************************************************
4016 static void output_gitignore( const char *dest
, struct strarray files
)
4020 output_file
= create_temp_file( dest
);
4022 output( "# Automatically generated by make depend; DO NOT EDIT!!\n" );
4023 for (i
= 0; i
< files
.count
; i
++)
4025 if (!strchr( files
.str
[i
], '/' )) output( "/" );
4026 output( "%s\n", files
.str
[i
] );
4029 if (fclose( output_file
)) fatal_perror( "write" );
4031 rename_temp_file( dest
);
4035 /*******************************************************************
4036 * output_stub_makefile
4038 static void output_stub_makefile( struct makefile
*make
)
4040 struct strarray targets
= empty_strarray
;
4041 const char *make_var
= strarray_get_value( &top_makefile
->vars
, "MAKE" );
4042 unsigned int i
, arch
;
4044 for (arch
= 0; arch
< archs
.count
; arch
++)
4045 if (make
->all_targets
[arch
].count
) strarray_add_uniq( &targets
, "all" );
4047 for (i
= 0; i
< NB_INSTALL_RULES
; i
++)
4049 if (!make
->install_rules
[i
].count
) continue;
4050 strarray_add_uniq( &targets
, "install" );
4051 strarray_add( &targets
, install_targets
[i
] );
4053 if (make
->clean_files
.count
) strarray_add( &targets
, "clean" );
4054 if (make
->test_files
.count
)
4056 strarray_add( &targets
, "check" );
4057 strarray_add( &targets
, "test" );
4058 strarray_add( &targets
, "testclean" );
4061 if (!targets
.count
&& !make
->clean_files
.count
) return;
4063 output_file_name
= obj_dir_path( make
, "Makefile" );
4064 output_file
= create_temp_file( output_file_name
);
4066 output( "# Auto-generated stub makefile; all rules forward to the top-level makefile\n\n" );
4068 if (make_var
) output( "MAKE = %s\n\n", make_var
);
4071 output_filenames( targets
);
4072 output_filenames( make
->clean_files
);
4074 output( "\t@cd %s && $(MAKE) %s/$@\n", get_relative_path( make
->obj_dir
, "" ), make
->obj_dir
);
4075 output( ".PHONY:" );
4076 output_filenames( targets
);
4079 fclose( output_file
);
4081 rename_temp_file( output_file_name
);
4085 /*******************************************************************
4086 * output_silent_rules
4088 static void output_silent_rules(void)
4090 static const char *cmds
[] =
4108 output( "V = 0\n" );
4109 for (i
= 0; i
< ARRAY_SIZE(cmds
); i
++)
4111 output( "quiet_%s = $(quiet_%s_$(V))\n", cmds
[i
], cmds
[i
] );
4112 output( "quiet_%s_0 = @echo \" %-5s \" $@;\n", cmds
[i
], cmds
[i
] );
4113 output( "quiet_%s_1 =\n", cmds
[i
] );
4118 /*******************************************************************
4119 * output_top_makefile
4121 static void output_top_makefile( struct makefile
*make
)
4128 output_file_name
= obj_dir_path( make
, output_makefile_name
);
4129 output_file
= create_temp_file( output_file_name
);
4131 /* copy the contents of the source makefile */
4132 src_file
= open_input_makefile( make
);
4133 while (fgets( buffer
, sizeof(buffer
), src_file
) && !found
)
4135 if (fwrite( buffer
, 1, strlen(buffer
), output_file
) != strlen(buffer
)) fatal_perror( "write" );
4136 found
= !strncmp( buffer
, separator
, strlen(separator
) );
4138 if (fclose( src_file
)) fatal_perror( "close" );
4139 input_file_name
= NULL
;
4141 if (!found
) output( "\n%s (everything below this line is auto-generated; DO NOT EDIT!!)\n", separator
);
4143 if (silent_rules
) output_silent_rules();
4144 for (i
= 0; i
< subdirs
.count
; i
++) output_sources( submakes
[i
] );
4145 output_sources( make
);
4146 /* disable implicit rules */
4147 output( ".SUFFIXES:\n" );
4149 fclose( output_file
);
4151 rename_temp_file( output_file_name
);
4155 /*******************************************************************
4156 * output_dependencies
4158 static void output_dependencies( struct makefile
*make
)
4160 struct strarray ignore_files
= empty_strarray
;
4162 if (make
->obj_dir
) create_dir( make
->obj_dir
);
4164 if (make
== top_makefile
) output_top_makefile( make
);
4165 else output_stub_makefile( make
);
4167 strarray_addall( &ignore_files
, make
->distclean_files
);
4168 strarray_addall( &ignore_files
, make
->clean_files
);
4169 if (make
->testdll
) output_testlist( make
);
4170 if (make
->obj_dir
&& !strcmp( make
->obj_dir
, "po" )) output_linguas( make
);
4171 if (!make
->src_dir
) output_gitignore( obj_dir_path( make
, ".gitignore" ), ignore_files
);
4173 create_file_directories( make
, ignore_files
);
4175 output_file_name
= NULL
;
4179 /*******************************************************************
4182 static void load_sources( struct makefile
*make
)
4184 static const char *source_vars
[] =
4204 unsigned int i
, arch
;
4205 struct strarray value
;
4206 struct incl_file
*file
;
4208 strarray_set_value( &make
->vars
, "top_srcdir", root_src_dir_path( "" ));
4209 strarray_set_value( &make
->vars
, "srcdir", src_dir_path( make
, "" ));
4211 make
->parent_dir
= get_expanded_make_variable( make
, "PARENTSRC" );
4212 make
->module
= get_expanded_make_variable( make
, "MODULE" );
4213 make
->testdll
= get_expanded_make_variable( make
, "TESTDLL" );
4214 make
->staticlib
= get_expanded_make_variable( make
, "STATICLIB" );
4215 make
->importlib
= get_expanded_make_variable( make
, "IMPORTLIB" );
4216 make
->extlib
= get_expanded_make_variable( make
, "EXTLIB" );
4217 if (unix_lib_supported
) make
->unixlib
= get_expanded_make_variable( make
, "UNIXLIB" );
4219 make
->programs
= get_expanded_make_var_array( make
, "PROGRAMS" );
4220 make
->scripts
= get_expanded_make_var_array( make
, "SCRIPTS" );
4221 make
->imports
= get_expanded_make_var_array( make
, "IMPORTS" );
4222 make
->delayimports
= get_expanded_make_var_array( make
, "DELAYIMPORTS" );
4223 make
->extradllflags
= get_expanded_make_var_array( make
, "EXTRADLLFLAGS" );
4224 make
->extra_targets
= get_expanded_make_var_array( make
, "EXTRA_TARGETS" );
4225 for (i
= 0; i
< NB_INSTALL_RULES
; i
++)
4226 make
->install
[i
] = get_expanded_make_var_array( make
, install_variables
[i
] );
4228 if (make
->extlib
) make
->staticlib
= make
->extlib
;
4229 if (make
->staticlib
) make
->module
= make
->staticlib
;
4233 make
->disabled
[0] = strarray_exists( &disabled_dirs
[0], make
->obj_dir
);
4234 for (arch
= 1; arch
< archs
.count
; arch
++)
4235 make
->disabled
[arch
] = make
->disabled
[0] || strarray_exists( &disabled_dirs
[arch
], make
->obj_dir
);
4237 make
->is_win16
= strarray_exists( &make
->extradllflags
, "-m16" );
4238 make
->data_only
= strarray_exists( &make
->extradllflags
, "-Wb,--data-only" );
4239 make
->is_exe
= strarray_exists( &make
->extradllflags
, "-mconsole" ) ||
4240 strarray_exists( &make
->extradllflags
, "-mwindows" );
4244 /* add default install rules if nothing was specified */
4245 for (i
= 0; i
< NB_INSTALL_RULES
; i
++) if (make
->install
[i
].count
) break;
4246 if (i
== NB_INSTALL_RULES
)
4248 if (make
->importlib
) strarray_add( &make
->install
[INSTALL_DEV
], make
->importlib
);
4249 if (make
->staticlib
) strarray_add( &make
->install
[INSTALL_DEV
], make
->staticlib
);
4250 else strarray_add( &make
->install
[INSTALL_LIB
], make
->module
);
4254 make
->include_paths
= empty_strarray
;
4255 make
->include_args
= empty_strarray
;
4256 make
->define_args
= empty_strarray
;
4257 make
->unix_cflags
= empty_strarray
;
4258 if (!make
->extlib
) strarray_add( &make
->define_args
, "-D__WINESRC__" );
4259 strarray_add( &make
->unix_cflags
, "-DWINE_UNIX_LIB" );
4261 value
= get_expanded_make_var_array( make
, "EXTRAINCL" );
4262 for (i
= 0; i
< value
.count
; i
++)
4264 if (!strncmp( value
.str
[i
], "-I", 2 ))
4266 const char *dir
= value
.str
[i
] + 2;
4267 if (!strncmp( dir
, "./", 2 ))
4270 while (*dir
== '/') dir
++;
4272 strarray_add_uniq( &make
->include_paths
, dir
);
4274 else if (!strncmp( value
.str
[i
], "-D", 2 ) || !strncmp( value
.str
[i
], "-U", 2 ))
4275 strarray_add_uniq( &make
->define_args
, value
.str
[i
] );
4277 strarray_addall( &make
->define_args
, get_expanded_make_var_array( make
, "EXTRADEFS" ));
4278 strarray_addall_uniq( &make
->unix_cflags
, get_expanded_make_var_array( make
, "UNIX_CFLAGS" ));
4280 strarray_add( &make
->include_args
, strmake( "-I%s", obj_dir_path( make
, "" )));
4282 strarray_add( &make
->include_args
, strmake( "-I%s", make
->src_dir
));
4283 if (make
->parent_dir
)
4284 strarray_add( &make
->include_args
, strmake( "-I%s", src_dir_path( make
, make
->parent_dir
)));
4285 strarray_add( &make
->include_args
, "-Iinclude" );
4286 if (root_src_dir
) strarray_add( &make
->include_args
, strmake( "-I%s", root_src_dir_path( "include" )));
4288 list_init( &make
->sources
);
4289 list_init( &make
->includes
);
4291 for (var
= source_vars
; *var
; var
++)
4293 value
= get_expanded_make_var_array( make
, *var
);
4294 for (i
= 0; i
< value
.count
; i
++) add_src_file( make
, value
.str
[i
] );
4297 add_generated_sources( make
);
4299 LIST_FOR_EACH_ENTRY( file
, &make
->includes
, struct incl_file
, entry
) parse_file( make
, file
, 0 );
4300 LIST_FOR_EACH_ENTRY( file
, &make
->sources
, struct incl_file
, entry
) get_dependencies( file
, file
);
4302 for (i
= 0; i
< make
->delayimports
.count
; i
++)
4303 strarray_add_uniq( &delay_import_libs
, get_base_name( make
->delayimports
.str
[i
] ));
4307 /*******************************************************************
4310 static void parse_makeflags( const char *flags
)
4312 const char *p
= flags
;
4313 char *var
, *buffer
= xmalloc( strlen(flags
) + 1 );
4317 p
= skip_spaces( p
);
4319 while (*p
&& !isspace(*p
))
4321 if (*p
== '\\' && p
[1]) p
++;
4325 if (var
> buffer
) set_make_variable( &cmdline_vars
, buffer
);
4330 /*******************************************************************
4333 static int parse_option( const char *opt
)
4337 if (strchr( opt
, '=' )) return set_make_variable( &cmdline_vars
, opt
);
4343 if (opt
[2]) output_makefile_name
= opt
+ 2;
4346 relative_dir_mode
= 1;
4352 fprintf( stderr
, "Unknown option '%s'\n%s", opt
, Usage
);
4359 /*******************************************************************
4362 int main( int argc
, char *argv
[] )
4364 const char *makeflags
= getenv( "MAKEFLAGS" );
4366 unsigned int i
, j
, arch
;
4368 if (makeflags
) parse_makeflags( makeflags
);
4373 if (parse_option( argv
[i
] ))
4375 for (j
= i
; j
< argc
; j
++) argv
[j
] = argv
[j
+1];
4381 if (relative_dir_mode
)
4387 fprintf( stderr
, "Option -R needs two directories\n%s", Usage
);
4390 relpath
= get_relative_path( argv
[1], argv
[2] );
4391 printf( "%s\n", relpath
? relpath
: "." );
4395 if (argc
> 1) fatal_error( "Directory arguments not supported in this mode\n" );
4397 atexit( cleanup_files
);
4398 init_signals( exit_on_signal
);
4400 for (i
= 0; i
< HASH_SIZE
; i
++) list_init( &files
[i
] );
4401 for (i
= 0; i
< HASH_SIZE
; i
++) list_init( &global_includes
[i
] );
4403 top_makefile
= parse_makefile( NULL
);
4405 target_flags
[0] = get_expanded_make_var_array( top_makefile
, "TARGETFLAGS" );
4406 msvcrt_flags
= get_expanded_make_var_array( top_makefile
, "MSVCRTFLAGS" );
4407 dll_flags
= get_expanded_make_var_array( top_makefile
, "DLLFLAGS" );
4408 unix_dllflags
= get_expanded_make_var_array( top_makefile
, "UNIXDLLFLAGS" );
4409 cpp_flags
= get_expanded_make_var_array( top_makefile
, "CPPFLAGS" );
4410 lddll_flags
= get_expanded_make_var_array( top_makefile
, "LDDLLFLAGS" );
4411 libs
= get_expanded_make_var_array( top_makefile
, "LIBS" );
4412 enable_tests
= get_expanded_make_var_array( top_makefile
, "ENABLE_TESTS" );
4413 for (i
= 0; i
< NB_INSTALL_RULES
; i
++)
4414 top_install
[i
] = get_expanded_make_var_array( top_makefile
, strmake( "TOP_%s", install_variables
[i
] ));
4416 root_src_dir
= get_expanded_make_variable( top_makefile
, "srcdir" );
4417 tools_dir
= get_expanded_make_variable( top_makefile
, "toolsdir" );
4418 tools_ext
= get_expanded_make_variable( top_makefile
, "toolsext" );
4419 exe_ext
= get_expanded_make_variable( top_makefile
, "EXEEXT" );
4420 dll_ext
[0] = get_expanded_make_variable( top_makefile
, "DLLEXT" );
4421 fontforge
= get_expanded_make_variable( top_makefile
, "FONTFORGE" );
4422 convert
= get_expanded_make_variable( top_makefile
, "CONVERT" );
4423 flex
= get_expanded_make_variable( top_makefile
, "FLEX" );
4424 bison
= get_expanded_make_variable( top_makefile
, "BISON" );
4425 ar
= get_expanded_make_variable( top_makefile
, "AR" );
4426 ranlib
= get_expanded_make_variable( top_makefile
, "RANLIB" );
4427 rsvg
= get_expanded_make_variable( top_makefile
, "RSVG" );
4428 icotool
= get_expanded_make_variable( top_makefile
, "ICOTOOL" );
4429 msgfmt
= get_expanded_make_variable( top_makefile
, "MSGFMT" );
4430 sed_cmd
= get_expanded_make_variable( top_makefile
, "SED_CMD" );
4431 ln_s
= get_expanded_make_variable( top_makefile
, "LN_S" );
4432 wayland_scanner
= get_expanded_make_variable( top_makefile
, "WAYLAND_SCANNER" );
4434 if (root_src_dir
&& !strcmp( root_src_dir
, "." )) root_src_dir
= NULL
;
4435 if (tools_dir
&& !strcmp( tools_dir
, "." )) tools_dir
= NULL
;
4436 if (!exe_ext
) exe_ext
= "";
4437 if (!dll_ext
[0]) dll_ext
[0] = "";
4438 if (!tools_ext
) tools_ext
= "";
4440 unix_lib_supported
= !!strcmp( exe_ext
, ".exe" );
4441 so_dll_supported
= !!dll_ext
[0][0]; /* non-empty dll ext means supported */
4443 strarray_add( &archs
, get_expanded_make_variable( top_makefile
, "HOST_ARCH" ));
4444 strarray_addall( &archs
, get_expanded_make_var_array( top_makefile
, "PE_ARCHS" ));
4447 arch_pe_dirs
[0] = strmake( "%s-windows/", archs
.str
[0] );
4448 arch_install_dirs
[0] = unix_lib_supported
? strmake( "$(dlldir)/%s-unix/", archs
.str
[0] ) : "$(dlldir)/";
4449 strip_progs
[0] = "\"$(STRIP)\"";
4451 for (arch
= 1; arch
< archs
.count
; arch
++)
4453 target
= get_expanded_arch_var( top_makefile
, "TARGET", arch
);
4454 strarray_add( &target_flags
[arch
], "-b" );
4455 strarray_add( &target_flags
[arch
], target
);
4456 arch_dirs
[arch
] = strmake( "%s-windows/", archs
.str
[arch
] );
4457 arch_pe_dirs
[arch
] = arch_dirs
[arch
];
4458 arch_install_dirs
[arch
] = strmake( "$(dlldir)/%s", arch_dirs
[arch
] );
4459 strip_progs
[arch
] = strmake( "%s-strip", target
);
4463 for (arch
= 0; arch
< archs
.count
; arch
++)
4465 extra_cflags
[arch
] = get_expanded_arch_var_array( top_makefile
, "EXTRACFLAGS", arch
);
4466 extra_cflags_extlib
[arch
] = remove_warning_flags( extra_cflags
[arch
] );
4467 disabled_dirs
[arch
] = get_expanded_arch_var_array( top_makefile
, "DISABLED_SUBDIRS", arch
);
4468 if (!is_multiarch( arch
)) continue;
4469 delay_load_flags
[arch
] = get_expanded_arch_var( top_makefile
, "DELAYLOADFLAG", arch
);
4470 debug_flags
[arch
] = get_expanded_arch_var( top_makefile
, "DEBUG", arch
);
4473 if (unix_lib_supported
)
4475 delay_load_flags
[0] = "-Wl,-delayload,";
4476 debug_flags
[0] = NULL
;
4479 top_makefile
->src_dir
= root_src_dir
;
4480 subdirs
= get_expanded_make_var_array( top_makefile
, "SUBDIRS" );
4481 submakes
= xmalloc( subdirs
.count
* sizeof(*submakes
) );
4483 for (i
= 0; i
< subdirs
.count
; i
++) submakes
[i
] = parse_makefile( subdirs
.str
[i
] );
4485 load_sources( top_makefile
);
4486 load_sources( include_makefile
);
4487 for (i
= 0; i
< subdirs
.count
; i
++)
4488 if (submakes
[i
] != include_makefile
) load_sources( submakes
[i
] );
4490 output_dependencies( top_makefile
);
4491 for (i
= 0; i
< subdirs
.count
; i
++) output_dependencies( submakes
[i
] );