2 * Generate include file dependencies
4 * Copyright 1996, 2013, 2020 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
32 #include <sys/types.h>
36 #include "wine/list.h"
40 INCL_NORMAL
, /* #include "foo.h" */
41 INCL_SYSTEM
, /* #include <foo.h> */
42 INCL_IMPORT
, /* idl import "foo.idl" */
43 INCL_IMPORTLIB
, /* idl importlib "foo.tlb" */
44 INCL_CPP_QUOTE
, /* idl cpp_quote("#include \"foo.h\"") */
45 INCL_CPP_QUOTE_SYSTEM
/* idl cpp_quote("#include <foo.h>") */
50 int line
; /* source line where this header is included */
51 enum incl_type type
; /* type of include */
52 char *name
; /* header name */
58 char *name
; /* full file name relative to cwd */
59 void *args
; /* custom arguments for makefile rule */
60 unsigned int flags
; /* flags (see below) */
61 unsigned int deps_count
; /* files in use */
62 unsigned int deps_size
; /* total allocated size */
63 struct dependency
*deps
; /* all header dependencies */
69 struct list hash_entry
;
73 char *basename
; /* base target name for generated files */
74 char *sourcename
; /* source file name for generated headers */
75 struct incl_file
*included_by
; /* file that included this one */
76 int included_line
; /* line where this file was included */
77 enum incl_type type
; /* type of include */
78 unsigned int arch
; /* architecture for multi-arch files, otherwise 0 */
79 int use_msvcrt
:1; /* put msvcrt headers in the search path? */
80 int is_external
:1; /* file from external library? */
81 struct incl_file
*owner
;
82 unsigned int files_count
; /* files in use */
83 unsigned int files_size
; /* total allocated size */
84 struct incl_file
**files
;
85 struct strarray dependencies
; /* file dependencies */
86 struct strarray importlibdeps
; /* importlib dependencies */
89 #define FLAG_GENERATED 0x000001 /* generated file */
90 #define FLAG_INSTALL 0x000002 /* file to install */
91 #define FLAG_IDL_PROXY 0x000100 /* generates a proxy (_p.c) file */
92 #define FLAG_IDL_CLIENT 0x000200 /* generates a client (_c.c) file */
93 #define FLAG_IDL_SERVER 0x000400 /* generates a server (_s.c) file */
94 #define FLAG_IDL_IDENT 0x000800 /* generates an ident (_i.c) file */
95 #define FLAG_IDL_REGISTER 0x001000 /* generates a registration (_r.res) file */
96 #define FLAG_IDL_TYPELIB 0x002000 /* generates a typelib (_l.res) file */
97 #define FLAG_IDL_REGTYPELIB 0x004000 /* generates a registered typelib (_t.res) file */
98 #define FLAG_IDL_HEADER 0x008000 /* generates a header (.h) file */
99 #define FLAG_RC_PO 0x010000 /* rc file contains translations */
100 #define FLAG_RC_HEADER 0x020000 /* rc file is a header */
101 #define FLAG_C_IMPLIB 0x040000 /* file is part of an import library */
102 #define FLAG_C_UNIX 0x080000 /* file is part of a Unix library */
103 #define FLAG_SFD_FONTS 0x100000 /* sfd file generated bitmap fonts */
111 { FLAG_IDL_TYPELIB
, "_l.res" },
112 { FLAG_IDL_REGTYPELIB
, "_t.res" },
113 { FLAG_IDL_CLIENT
, "_c.c" },
114 { FLAG_IDL_IDENT
, "_i.c" },
115 { FLAG_IDL_PROXY
, "_p.c" },
116 { FLAG_IDL_SERVER
, "_s.c" },
117 { FLAG_IDL_REGISTER
, "_r.res" },
120 #define HASH_SIZE 197
122 static struct list files
[HASH_SIZE
];
123 static struct list global_includes
[HASH_SIZE
];
125 enum install_rules
{ INSTALL_LIB
, INSTALL_DEV
, INSTALL_TEST
, NB_INSTALL_RULES
};
126 static const char *install_targets
[NB_INSTALL_RULES
] = { "install-lib", "install-dev", "install-test" };
127 static const char *install_variables
[NB_INSTALL_RULES
] = { "INSTALL_LIB", "INSTALL_DEV", "INSTALL_TEST" };
131 /* variables common to all makefiles */
132 static struct strarray archs
;
133 static struct strarray linguas
;
134 static struct strarray dll_flags
;
135 static struct strarray unix_dllflags
;
136 static struct strarray msvcrt_flags
;
137 static struct strarray cpp_flags
;
138 static struct strarray lddll_flags
;
139 static struct strarray libs
;
140 static struct strarray enable_tests
;
141 static struct strarray cmdline_vars
;
142 static struct strarray subdirs
;
143 static struct strarray delay_import_libs
;
144 static struct strarray top_install
[NB_INSTALL_RULES
];
145 static const char *root_src_dir
;
146 static const char *tools_dir
;
147 static const char *tools_ext
;
148 static const char *exe_ext
;
149 static const char *dll_ext
;
150 static const char *fontforge
;
151 static const char *convert
;
152 static const char *flex
;
153 static const char *bison
;
154 static const char *ar
;
155 static const char *ranlib
;
156 static const char *rsvg
;
157 static const char *icotool
;
158 static const char *msgfmt
;
159 static const char *ln_s
;
160 static const char *sed_cmd
;
161 /* per-architecture global variables */
162 static const char *arch_dirs
[MAX_ARCHS
];
163 static const char *arch_pe_dirs
[MAX_ARCHS
];
164 static const char *arch_install_dirs
[MAX_ARCHS
];
165 static const char *strip_progs
[MAX_ARCHS
];
166 static const char *debug_flags
[MAX_ARCHS
];
167 static const char *delay_load_flags
[MAX_ARCHS
];
168 static struct strarray target_flags
[MAX_ARCHS
];
169 static struct strarray extra_cflags
[MAX_ARCHS
];
170 static struct strarray extra_cflags_extlib
[MAX_ARCHS
];
171 static struct strarray disabled_dirs
[MAX_ARCHS
];
175 /* values determined from input makefile */
176 struct strarray vars
;
177 struct strarray include_paths
;
178 struct strarray include_args
;
179 struct strarray define_args
;
180 struct strarray unix_cflags
;
181 struct strarray programs
;
182 struct strarray scripts
;
183 struct strarray imports
;
184 struct strarray delayimports
;
185 struct strarray extradllflags
;
186 struct strarray install
[NB_INSTALL_RULES
];
187 struct strarray extra_targets
;
188 struct strarray extra_imports
;
190 struct list includes
;
193 const char *parent_dir
;
197 const char *sharedlib
;
198 const char *staticlib
;
199 const char *importlib
;
204 int disabled
[MAX_ARCHS
];
206 /* values generated at output time */
207 struct strarray in_files
;
208 struct strarray ok_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 res_files
[MAX_ARCHS
];
224 struct strarray all_targets
[MAX_ARCHS
];
225 struct strarray install_rules
[NB_INSTALL_RULES
];
228 static struct makefile
*top_makefile
;
229 static struct makefile
*include_makefile
;
230 static struct makefile
**submakes
;
232 static const char separator
[] = "### Dependencies";
233 static const char *output_makefile_name
= "Makefile";
234 static const char *input_file_name
;
235 static const char *output_file_name
;
236 static const char *temp_file_name
;
237 static int relative_dir_mode
;
238 static int silent_rules
;
239 static int input_line
;
240 static int output_column
;
241 static FILE *output_file
;
243 static const char Usage
[] =
244 "Usage: makedep [options] [directories]\n"
246 " -R from to Compute the relative path between two directories\n"
247 " -S Generate Automake-style silent rules\n"
248 " -fxxx Store output in file 'xxx' (default: Makefile)\n";
251 static void fatal_error( const char *msg
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
252 static void fatal_perror( const char *msg
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
253 static void output( const char *format
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
254 static char *strmake( const char* fmt
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
256 /*******************************************************************
259 static void fatal_error( const char *msg
, ... )
262 va_start( valist
, msg
);
265 fprintf( stderr
, "%s:", input_file_name
);
266 if (input_line
) fprintf( stderr
, "%d:", input_line
);
267 fprintf( stderr
, " error: " );
269 else fprintf( stderr
, "makedep: error: " );
270 vfprintf( stderr
, msg
, valist
);
276 /*******************************************************************
279 static void fatal_perror( const char *msg
, ... )
282 va_start( valist
, msg
);
285 fprintf( stderr
, "%s:", input_file_name
);
286 if (input_line
) fprintf( stderr
, "%d:", input_line
);
287 fprintf( stderr
, " error: " );
289 else fprintf( stderr
, "makedep: error: " );
290 vfprintf( stderr
, msg
, valist
);
297 /*******************************************************************
300 static void cleanup_files(void)
302 if (temp_file_name
) unlink( temp_file_name
);
303 if (output_file_name
) unlink( output_file_name
);
307 /*******************************************************************
310 static void exit_on_signal( int sig
)
312 exit( 1 ); /* this will call the atexit functions */
316 /*******************************************************************
319 static void output( const char *format
, ... )
324 va_start( valist
, format
);
325 ret
= vfprintf( output_file
, format
, valist
);
327 if (ret
< 0) fatal_perror( "output" );
328 if (format
[0] && format
[strlen(format
) - 1] == '\n') output_column
= 0;
329 else output_column
+= ret
;
333 /*******************************************************************
336 * Find a value in a name/value pair string array.
338 static const char *strarray_get_value( const struct strarray
*array
, const char *name
)
340 int pos
, res
, min
= 0, max
= array
->count
/ 2 - 1;
344 pos
= (min
+ max
) / 2;
345 if (!(res
= strcmp( array
->str
[pos
* 2], name
))) return array
->str
[pos
* 2 + 1];
346 if (res
< 0) min
= pos
+ 1;
353 /*******************************************************************
356 * Define a value in a name/value pair string array.
358 static void strarray_set_value( struct strarray
*array
, const char *name
, const char *value
)
360 int i
, pos
, res
, min
= 0, max
= array
->count
/ 2 - 1;
364 pos
= (min
+ max
) / 2;
365 if (!(res
= strcmp( array
->str
[pos
* 2], name
)))
367 /* redefining a variable replaces the previous value */
368 array
->str
[pos
* 2 + 1] = value
;
371 if (res
< 0) min
= pos
+ 1;
374 strarray_add( array
, NULL
);
375 strarray_add( array
, NULL
);
376 for (i
= array
->count
- 1; i
> min
* 2 + 1; i
--) array
->str
[i
] = array
->str
[i
- 2];
377 array
->str
[min
* 2] = name
;
378 array
->str
[min
* 2 + 1] = value
;
382 /*******************************************************************
385 static void output_filename( const char *name
)
387 if (output_column
+ strlen(name
) + 1 > 100)
392 else if (output_column
) output( " " );
393 output( "%s", name
);
397 /*******************************************************************
400 static void output_filenames( struct strarray array
)
404 for (i
= 0; i
< array
.count
; i
++) output_filename( array
.str
[i
] );
408 /*******************************************************************
409 * output_rm_filenames
411 static void output_rm_filenames( struct strarray array
, const char *command
)
413 static const unsigned int max_cmdline
= 30000; /* to be on the safe side */
416 if (!array
.count
) return;
417 output( "\t%s", command
);
418 for (i
= len
= 0; i
< array
.count
; i
++)
420 if (len
> max_cmdline
)
423 output( "\t%s", command
);
426 output_filename( array
.str
[i
] );
427 len
+= strlen( array
.str
[i
] ) + 1;
433 /*******************************************************************
436 static char *get_extension( char *filename
)
438 char *ext
= strrchr( filename
, '.' );
439 if (ext
&& strchr( ext
, '/' )) ext
= NULL
;
444 /*******************************************************************
447 static const char *get_base_name( const char *name
)
450 if (!strchr( name
, '.' )) return name
;
451 base
= xstrdup( name
);
452 *strrchr( base
, '.' ) = 0;
457 /*******************************************************************
460 static char *replace_filename( const char *path
, const char *name
)
466 if (!path
) return xstrdup( name
);
467 if (!(p
= strrchr( path
, '/' ))) return xstrdup( name
);
469 ret
= xmalloc( len
+ strlen( name
) + 1 );
470 memcpy( ret
, path
, len
);
471 strcpy( ret
+ len
, name
);
476 /*******************************************************************
479 static char *replace_substr( const char *str
, const char *start
, size_t len
, const char *replace
)
481 size_t pos
= start
- str
;
482 char *ret
= xmalloc( pos
+ strlen(replace
) + strlen(start
+ len
) + 1 );
483 memcpy( ret
, str
, pos
);
484 strcpy( ret
+ pos
, replace
);
485 strcat( ret
+ pos
, start
+ len
);
490 /*******************************************************************
493 * Determine where the destination path is located relative to the 'from' path.
495 static char *get_relative_path( const char *from
, const char *dest
)
499 unsigned int dotdots
= 0;
501 /* a path of "." is equivalent to an empty path */
502 if (!strcmp( from
, "." )) from
= "";
506 while (*from
== '/') from
++;
507 while (*dest
== '/') dest
++;
508 start
= dest
; /* save start of next path element */
511 while (*from
&& *from
!= '/' && *from
== *dest
) { from
++; dest
++; }
512 if ((!*from
|| *from
== '/') && (!*dest
|| *dest
== '/')) continue;
514 /* count remaining elements in 'from' */
518 while (*from
&& *from
!= '/') from
++;
519 while (*from
== '/') from
++;
525 if (!start
[0] && !dotdots
) return NULL
; /* empty path */
527 ret
= xmalloc( 3 * dotdots
+ strlen( start
) + 1 );
528 for (p
= ret
; dotdots
; dotdots
--, p
+= 3) memcpy( p
, "../", 3 );
530 if (start
[0]) strcpy( p
, start
);
531 else p
[-1] = 0; /* remove trailing slash */
536 /*******************************************************************
539 static char *concat_paths( const char *base
, const char *path
)
544 if (!base
|| !base
[0]) return xstrdup( path
&& path
[0] ? path
: "." );
545 if (!path
|| !path
[0]) return xstrdup( base
);
546 if (path
[0] == '/') return xstrdup( path
);
548 len
= strlen( base
);
549 while (len
&& base
[len
- 1] == '/') len
--;
550 while (len
&& !strncmp( path
, "..", 2 ) && (!path
[2] || path
[2] == '/'))
552 for (i
= len
; i
> 0; i
--) if (base
[i
- 1] == '/') break;
553 if (i
== len
- 2 && !memcmp( base
+ i
, "..", 2 )) break; /* we can't go up if we already have ".." */
554 if (i
!= len
- 1 || base
[i
] != '.')
557 while (*path
== '/') path
++;
559 /* else ignore "." element */
560 while (i
> 0 && base
[i
- 1] == '/') i
--;
563 if (!len
&& base
[0] != '/') return xstrdup( path
[0] ? path
: "." );
564 ret
= xmalloc( len
+ strlen( path
) + 2 );
565 memcpy( ret
, base
, len
);
567 strcpy( ret
+ len
, path
);
572 /*******************************************************************
573 * is_native_arch_disabled
575 * Check if the makefile was disabled for a PE arch that matches the native arch.
577 static int is_native_arch_disabled( struct makefile
*make
)
581 for (arch
= 1; arch
< archs
.count
; arch
++)
582 if (make
->disabled
[arch
] && !strcmp( archs
.str
[0], archs
.str
[arch
] ))
588 /*******************************************************************
591 * Check if arch is one of the PE architectures in multiarch.
592 * Also return TRUE for native arch iff there's no PE support.
594 static int is_multiarch( unsigned int arch
)
596 return archs
.count
== 1 || arch
;
600 /*******************************************************************
603 * Check if the files of a makefile use msvcrt by default.
605 static int is_using_msvcrt( struct makefile
*make
)
607 return make
->module
|| make
->testdll
;
611 /*******************************************************************
614 static char *arch_module_name( const char *module
, unsigned int arch
)
616 return strmake( "%s%s%s", arch_dirs
[arch
], module
, arch
? "" : dll_ext
);
620 /*******************************************************************
623 static char *arch_make_variable( const char *name
, unsigned int arch
)
625 return arch
? strmake( "$(%s_%s)", archs
.str
[arch
], name
) : strmake( "$(%s)", name
);
629 /*******************************************************************
632 static char *obj_dir_path( const struct makefile
*make
, const char *path
)
634 return concat_paths( make
->obj_dir
, path
);
638 /*******************************************************************
641 static char *src_dir_path( const struct makefile
*make
, const char *path
)
643 if (make
->src_dir
) return concat_paths( make
->src_dir
, path
);
644 return obj_dir_path( make
, path
);
648 /*******************************************************************
651 static char *root_src_dir_path( const char *path
)
653 return concat_paths( root_src_dir
, path
);
657 /*******************************************************************
660 static char *tools_dir_path( const struct makefile
*make
, const char *path
)
662 if (tools_dir
) return strmake( "%s/tools/%s", tools_dir
, path
);
663 return strmake( "tools/%s", path
);
667 /*******************************************************************
670 static char *tools_path( const struct makefile
*make
, const char *name
)
672 return strmake( "%s/%s%s", tools_dir_path( make
, name
), name
, tools_ext
);
676 /*******************************************************************
677 * strarray_addall_path
679 static void strarray_addall_path( struct strarray
*array
, const char *dir
, struct strarray added
)
683 for (i
= 0; i
< added
.count
; i
++) strarray_add( array
, concat_paths( dir
, added
.str
[i
] ));
687 /*******************************************************************
690 static char *get_line( FILE *file
)
698 buffer
= xmalloc( size
);
700 if (!fgets( buffer
, size
, file
)) return NULL
;
705 char *p
= buffer
+ strlen(buffer
);
706 /* if line is larger than buffer, resize buffer */
707 while (p
== buffer
+ size
- 1 && p
[-1] != '\n')
709 buffer
= xrealloc( buffer
, size
* 2 );
710 if (!fgets( buffer
+ size
- 1, size
+ 1, file
)) break;
711 p
= buffer
+ strlen(buffer
);
714 if (p
> buffer
&& p
[-1] == '\n')
717 if (p
> buffer
&& p
[-1] == '\r') *(--p
) = 0;
718 if (p
> buffer
&& p
[-1] == '\\')
721 /* line ends in backslash, read continuation line */
722 if (!fgets( p
, size
- (p
- buffer
), file
)) return buffer
;
732 /*******************************************************************
735 static unsigned int hash_filename( const char *name
)
738 unsigned int ret
= 2166136261u;
739 while (*name
) ret
= (ret
* 16777619) ^ *name
++;
740 return ret
% HASH_SIZE
;
744 /*******************************************************************
747 static struct file
*add_file( const char *name
)
749 struct file
*file
= xmalloc( sizeof(*file
) );
750 memset( file
, 0, sizeof(*file
) );
751 file
->name
= xstrdup( name
);
756 /*******************************************************************
759 static void add_dependency( struct file
*file
, const char *name
, enum incl_type type
)
761 if (file
->deps_count
>= file
->deps_size
)
763 file
->deps_size
*= 2;
764 if (file
->deps_size
< 16) file
->deps_size
= 16;
765 file
->deps
= xrealloc( file
->deps
, file
->deps_size
* sizeof(*file
->deps
) );
767 file
->deps
[file
->deps_count
].line
= input_line
;
768 file
->deps
[file
->deps_count
].type
= type
;
769 file
->deps
[file
->deps_count
].name
= xstrdup( name
);
774 /*******************************************************************
777 static struct incl_file
*find_src_file( const struct makefile
*make
, const char *name
)
779 struct incl_file
*file
;
781 if (make
== include_makefile
)
783 unsigned int hash
= hash_filename( name
);
785 LIST_FOR_EACH_ENTRY( file
, &global_includes
[hash
], struct incl_file
, hash_entry
)
786 if (!strcmp( name
, file
->name
)) return file
;
790 LIST_FOR_EACH_ENTRY( file
, &make
->sources
, struct incl_file
, entry
)
791 if (!strcmp( name
, file
->name
)) return file
;
795 /*******************************************************************
798 static struct incl_file
*find_include_file( const struct makefile
*make
, const char *name
)
800 struct incl_file
*file
;
802 LIST_FOR_EACH_ENTRY( file
, &make
->includes
, struct incl_file
, entry
)
804 const char *filename
= file
->filename
;
805 if (!filename
) continue;
806 if (make
->obj_dir
&& strlen(make
->obj_dir
) < strlen(filename
))
808 filename
+= strlen(make
->obj_dir
);
809 while (*filename
== '/') filename
++;
811 if (!strcmp( name
, filename
)) return file
;
816 /*******************************************************************
819 * Add an include file if it doesn't already exists.
821 static struct incl_file
*add_include( struct makefile
*make
, struct incl_file
*parent
,
822 const char *name
, int line
, enum incl_type type
)
824 struct incl_file
*include
;
826 if (parent
->files_count
>= parent
->files_size
)
828 parent
->files_size
*= 2;
829 if (parent
->files_size
< 16) parent
->files_size
= 16;
830 parent
->files
= xrealloc( parent
->files
, parent
->files_size
* sizeof(*parent
->files
) );
833 LIST_FOR_EACH_ENTRY( include
, &make
->includes
, struct incl_file
, entry
)
834 if (!parent
->use_msvcrt
== !include
->use_msvcrt
&& !strcmp( name
, include
->name
))
837 include
= xmalloc( sizeof(*include
) );
838 memset( include
, 0, sizeof(*include
) );
839 include
->name
= xstrdup(name
);
840 include
->included_by
= parent
;
841 include
->included_line
= line
;
842 include
->type
= type
;
843 include
->use_msvcrt
= parent
->use_msvcrt
;
844 list_add_tail( &make
->includes
, &include
->entry
);
846 parent
->files
[parent
->files_count
++] = include
;
851 /*******************************************************************
852 * add_generated_source
854 * Add a generated source file to the list.
856 static struct incl_file
*add_generated_source( struct makefile
*make
, const char *name
,
857 const char *filename
, unsigned int arch
)
859 struct incl_file
*file
= xmalloc( sizeof(*file
) );
861 name
= strmake( "%s%s", arch_dirs
[arch
], name
);
862 memset( file
, 0, sizeof(*file
) );
863 file
->file
= add_file( name
);
865 file
->name
= xstrdup( name
);
866 file
->basename
= xstrdup( filename
? filename
: name
);
867 file
->filename
= obj_dir_path( make
, file
->basename
);
868 file
->file
->flags
= FLAG_GENERATED
;
869 file
->use_msvcrt
= is_using_msvcrt( make
);
870 list_add_tail( &make
->sources
, &file
->entry
);
871 if (make
== include_makefile
)
873 unsigned int hash
= hash_filename( name
);
874 list_add_tail( &global_includes
[hash
], &file
->hash_entry
);
880 /*******************************************************************
883 static char *skip_spaces( const char *p
)
885 while (*p
== ' ' || *p
== '\t') p
++;
890 /*******************************************************************
891 * parse_include_directive
893 static void parse_include_directive( struct file
*source
, char *str
)
895 char quote
, *include
, *p
= skip_spaces( str
);
897 if (*p
!= '\"' && *p
!= '<' ) return;
899 if (quote
== '<') quote
= '>';
901 while (*p
&& (*p
!= quote
)) p
++;
902 if (!*p
) fatal_error( "malformed include directive '%s'\n", str
);
904 add_dependency( source
, include
, (quote
== '>') ? INCL_SYSTEM
: INCL_NORMAL
);
908 /*******************************************************************
909 * parse_pragma_directive
911 static void parse_pragma_directive( struct file
*source
, char *str
)
913 char *flag
, *p
= str
;
915 if (*p
!= ' ' && *p
!= '\t') return;
916 p
= strtok( skip_spaces( p
), " \t" );
917 if (strcmp( p
, "makedep" )) return;
919 while ((flag
= strtok( NULL
, " \t" )))
921 if (!strcmp( flag
, "depend" ))
923 while ((p
= strtok( NULL
, " \t" ))) add_dependency( source
, p
, INCL_NORMAL
);
926 else if (!strcmp( flag
, "install" )) source
->flags
|= FLAG_INSTALL
;
928 if (strendswith( source
->name
, ".idl" ))
930 if (!strcmp( flag
, "header" )) source
->flags
|= FLAG_IDL_HEADER
;
931 else if (!strcmp( flag
, "proxy" )) source
->flags
|= FLAG_IDL_PROXY
;
932 else if (!strcmp( flag
, "client" )) source
->flags
|= FLAG_IDL_CLIENT
;
933 else if (!strcmp( flag
, "server" )) source
->flags
|= FLAG_IDL_SERVER
;
934 else if (!strcmp( flag
, "ident" )) source
->flags
|= FLAG_IDL_IDENT
;
935 else if (!strcmp( flag
, "typelib" )) source
->flags
|= FLAG_IDL_TYPELIB
;
936 else if (!strcmp( flag
, "register" )) source
->flags
|= FLAG_IDL_REGISTER
;
937 else if (!strcmp( flag
, "regtypelib" )) source
->flags
|= FLAG_IDL_REGTYPELIB
;
939 else if (strendswith( source
->name
, ".rc" ))
941 if (!strcmp( flag
, "header" )) source
->flags
|= FLAG_RC_HEADER
;
942 else if (!strcmp( flag
, "po" )) source
->flags
|= FLAG_RC_PO
;
944 else if (strendswith( source
->name
, ".sfd" ))
946 if (!strcmp( flag
, "font" ))
948 struct strarray
*array
= source
->args
;
952 source
->args
= array
= xmalloc( sizeof(*array
) );
953 *array
= empty_strarray
;
954 source
->flags
|= FLAG_SFD_FONTS
;
956 strarray_add( array
, xstrdup( strtok( NULL
, "" )));
962 if (!strcmp( flag
, "implib" )) source
->flags
|= FLAG_C_IMPLIB
;
963 if (!strcmp( flag
, "unix" )) source
->flags
|= FLAG_C_UNIX
;
969 /*******************************************************************
970 * parse_cpp_directive
972 static void parse_cpp_directive( struct file
*source
, char *str
)
974 str
= skip_spaces( str
);
975 if (*str
++ != '#') return;
976 str
= skip_spaces( str
);
978 if (!strncmp( str
, "include", 7 ))
979 parse_include_directive( source
, str
+ 7 );
980 else if (!strncmp( str
, "import", 6 ) && strendswith( source
->name
, ".m" ))
981 parse_include_directive( source
, str
+ 6 );
982 else if (!strncmp( str
, "pragma", 6 ))
983 parse_pragma_directive( source
, str
+ 6 );
987 /*******************************************************************
990 static void parse_idl_file( struct file
*source
, FILE *file
)
992 char *buffer
, *include
;
996 while ((buffer
= get_line( file
)))
999 char *p
= skip_spaces( buffer
);
1001 if (!strncmp( p
, "importlib", 9 ))
1003 p
= skip_spaces( p
+ 9 );
1004 if (*p
++ != '(') continue;
1005 p
= skip_spaces( p
);
1006 if (*p
++ != '"') continue;
1008 while (*p
&& (*p
!= '"')) p
++;
1009 if (!*p
) fatal_error( "malformed importlib directive\n" );
1011 add_dependency( source
, include
, INCL_IMPORTLIB
);
1015 if (!strncmp( p
, "import", 6 ))
1017 p
= skip_spaces( p
+ 6 );
1018 if (*p
!= '"') continue;
1020 while (*p
&& (*p
!= '"')) p
++;
1021 if (!*p
) fatal_error( "malformed import directive\n" );
1023 add_dependency( source
, include
, INCL_IMPORT
);
1027 /* check for #include inside cpp_quote */
1028 if (!strncmp( p
, "cpp_quote", 9 ))
1030 p
= skip_spaces( p
+ 9 );
1031 if (*p
++ != '(') continue;
1032 p
= skip_spaces( p
);
1033 if (*p
++ != '"') continue;
1034 if (*p
++ != '#') continue;
1035 p
= skip_spaces( p
);
1036 if (strncmp( p
, "include", 7 )) continue;
1037 p
= skip_spaces( p
+ 7 );
1038 if (*p
== '\\' && p
[1] == '"')
1045 if (*p
++ != '<' ) continue;
1049 while (*p
&& (*p
!= quote
)) p
++;
1050 if (!*p
|| (quote
== '"' && p
[-1] != '\\'))
1051 fatal_error( "malformed #include directive inside cpp_quote\n" );
1052 if (quote
== '"') p
--; /* remove backslash */
1054 add_dependency( source
, include
, (quote
== '>') ? INCL_CPP_QUOTE_SYSTEM
: INCL_CPP_QUOTE
);
1058 parse_cpp_directive( source
, p
);
1062 /*******************************************************************
1065 static void parse_c_file( struct file
*source
, FILE *file
)
1070 while ((buffer
= get_line( file
)))
1072 parse_cpp_directive( source
, buffer
);
1077 /*******************************************************************
1080 static void parse_rc_file( struct file
*source
, FILE *file
)
1082 char *buffer
, *include
;
1085 while ((buffer
= get_line( file
)))
1088 char *p
= skip_spaces( buffer
);
1090 if (p
[0] == '/' && p
[1] == '*') /* check for magic makedep comment */
1092 p
= skip_spaces( p
+ 2 );
1093 if (strncmp( p
, "@makedep:", 9 )) continue;
1094 p
= skip_spaces( p
+ 9 );
1099 while (*p
&& *p
!= quote
) p
++;
1104 while (*p
&& *p
!= ' ' && *p
!= '\t' && *p
!= '*') p
++;
1107 fatal_error( "malformed makedep comment\n" );
1109 add_dependency( source
, include
, (quote
== '>') ? INCL_SYSTEM
: INCL_NORMAL
);
1113 parse_cpp_directive( source
, buffer
);
1118 /*******************************************************************
1121 static void parse_in_file( struct file
*source
, FILE *file
)
1125 /* make sure it gets rebuilt when the version changes */
1126 add_dependency( source
, "config.h", INCL_SYSTEM
);
1128 if (!strendswith( source
->name
, ".man.in" )) return; /* not a man page */
1131 while ((buffer
= get_line( file
)))
1133 if (strncmp( buffer
, ".TH", 3 )) continue;
1134 p
= skip_spaces( buffer
+ 3 );
1135 if (!(p
= strtok( p
, " \t" ))) continue; /* program name */
1136 if (!(p
= strtok( NULL
, " \t" ))) continue; /* man section */
1137 source
->args
= xstrdup( p
);
1143 /*******************************************************************
1146 static void parse_sfd_file( struct file
*source
, FILE *file
)
1148 char *p
, *eol
, *buffer
;
1151 while ((buffer
= get_line( file
)))
1153 if (strncmp( buffer
, "UComments:", 10 )) continue;
1155 while (*p
== ' ') p
++;
1156 if (p
[0] == '"' && p
[1] && buffer
[strlen(buffer
) - 1] == '"')
1159 buffer
[strlen(buffer
) - 1] = 0;
1161 while ((eol
= strstr( p
, "+AAoA" )))
1164 p
= skip_spaces( p
);
1167 p
= skip_spaces( p
);
1168 if (!strncmp( p
, "pragma", 6 )) parse_pragma_directive( source
, p
+ 6 );
1172 p
= skip_spaces( p
);
1173 if (*p
++ != '#') return;
1174 p
= skip_spaces( p
);
1175 if (!strncmp( p
, "pragma", 6 )) parse_pragma_directive( source
, p
+ 6 );
1184 void (*parse
)( struct file
*file
, FILE *f
);
1185 } parse_functions
[] =
1187 { ".c", parse_c_file
},
1188 { ".h", parse_c_file
},
1189 { ".inl", parse_c_file
},
1190 { ".l", parse_c_file
},
1191 { ".m", parse_c_file
},
1192 { ".rh", parse_c_file
},
1193 { ".x", parse_c_file
},
1194 { ".y", parse_c_file
},
1195 { ".idl", parse_idl_file
},
1196 { ".rc", parse_rc_file
},
1197 { ".in", parse_in_file
},
1198 { ".sfd", parse_sfd_file
}
1201 /*******************************************************************
1204 static struct file
*load_file( const char *name
)
1208 unsigned int i
, hash
= hash_filename( name
);
1210 LIST_FOR_EACH_ENTRY( file
, &files
[hash
], struct file
, entry
)
1211 if (!strcmp( name
, file
->name
)) return file
;
1213 if (!(f
= fopen( name
, "r" ))) return NULL
;
1215 file
= add_file( name
);
1216 list_add_tail( &files
[hash
], &file
->entry
);
1217 input_file_name
= file
->name
;
1220 for (i
= 0; i
< ARRAY_SIZE(parse_functions
); i
++)
1222 if (!strendswith( name
, parse_functions
[i
].ext
)) continue;
1223 parse_functions
[i
].parse( file
, f
);
1228 input_file_name
= NULL
;
1234 /*******************************************************************
1235 * open_include_path_file
1237 * Open a file from a directory on the include path.
1239 static struct file
*open_include_path_file( const struct makefile
*make
, const char *dir
,
1240 const char *name
, char **filename
)
1242 char *src_path
= concat_paths( dir
, name
);
1243 struct file
*ret
= load_file( src_path
);
1245 if (ret
) *filename
= src_path
;
1250 /*******************************************************************
1251 * open_file_same_dir
1253 * Open a file in the same directory as the parent.
1255 static struct file
*open_file_same_dir( const struct incl_file
*parent
, const char *name
, char **filename
)
1257 char *src_path
= replace_filename( parent
->file
->name
, name
);
1258 struct file
*ret
= load_file( src_path
);
1260 if (ret
) *filename
= replace_filename( parent
->filename
, name
);
1265 /*******************************************************************
1266 * open_same_dir_generated_file
1268 * Open a generated_file in the same directory as the parent.
1270 static struct file
*open_same_dir_generated_file( const struct makefile
*make
,
1271 const struct incl_file
*parent
, struct incl_file
*file
,
1272 const char *ext
, const char *src_ext
)
1275 struct file
*ret
= NULL
;
1277 if (strendswith( file
->name
, ext
) &&
1278 (ret
= open_file_same_dir( parent
, replace_extension( file
->name
, ext
, src_ext
), &filename
)))
1280 file
->sourcename
= filename
;
1281 file
->filename
= obj_dir_path( make
, replace_filename( parent
->name
, file
->name
));
1287 /*******************************************************************
1290 * Open a file in the source directory of the makefile.
1292 static struct file
*open_local_file( const struct makefile
*make
, const char *path
, char **filename
)
1294 char *src_path
= src_dir_path( make
, path
);
1295 struct file
*ret
= load_file( src_path
);
1297 /* if not found, try parent dir */
1298 if (!ret
&& make
->parent_dir
)
1301 path
= strmake( "%s/%s", make
->parent_dir
, path
);
1302 src_path
= src_dir_path( make
, path
);
1303 ret
= load_file( src_path
);
1306 if (ret
) *filename
= src_path
;
1311 /*******************************************************************
1312 * open_local_generated_file
1314 * Open a generated file in the directory of the makefile.
1316 static struct file
*open_local_generated_file( const struct makefile
*make
, struct incl_file
*file
,
1317 const char *ext
, const char *src_ext
)
1319 struct incl_file
*include
;
1321 if (strendswith( file
->name
, ext
) &&
1322 (include
= find_src_file( make
, replace_extension( file
->name
, ext
, src_ext
) )))
1324 file
->sourcename
= include
->filename
;
1325 file
->filename
= obj_dir_path( make
, file
->name
);
1326 return include
->file
;
1332 /*******************************************************************
1335 * Open a file in the top-level source directory.
1337 static struct file
*open_global_file( const char *path
, char **filename
)
1339 char *src_path
= root_src_dir_path( path
);
1340 struct file
*ret
= load_file( src_path
);
1342 if (ret
) *filename
= src_path
;
1347 /*******************************************************************
1348 * open_global_header
1350 * Open a file in the global include source directory.
1352 static struct file
*open_global_header( const char *path
, char **filename
)
1354 struct incl_file
*include
= find_src_file( include_makefile
, path
);
1356 if (!include
) return NULL
;
1357 *filename
= include
->filename
;
1358 return include
->file
;
1362 /*******************************************************************
1363 * open_global_generated_file
1365 * Open a generated file in the top-level source directory.
1367 static struct file
*open_global_generated_file( const struct makefile
*make
, struct incl_file
*file
,
1368 const char *ext
, const char *src_ext
)
1370 struct incl_file
*include
;
1372 if (strendswith( file
->name
, ext
) &&
1373 (include
= find_src_file( include_makefile
, replace_extension( file
->name
, ext
, src_ext
) )))
1375 file
->sourcename
= include
->filename
;
1376 file
->filename
= strmake( "include/%s", file
->name
);
1377 return include
->file
;
1383 /*******************************************************************
1386 static struct file
*open_src_file( const struct makefile
*make
, struct incl_file
*pFile
)
1388 struct file
*file
= open_local_file( make
, pFile
->name
, &pFile
->filename
);
1390 if (!file
) fatal_perror( "open %s", pFile
->name
);
1395 /*******************************************************************
1396 * find_importlib_module
1398 static struct makefile
*find_importlib_module( const char *name
)
1400 unsigned int i
, len
;
1402 for (i
= 0; i
< subdirs
.count
; i
++)
1404 if (strncmp( submakes
[i
]->obj_dir
, "dlls/", 5 )) continue;
1405 len
= strlen(submakes
[i
]->obj_dir
);
1406 if (strncmp( submakes
[i
]->obj_dir
+ 5, name
, len
- 5 )) continue;
1407 if (!name
[len
- 5] || !strcmp( name
+ len
- 5, ".dll" )) return submakes
[i
];
1413 /*******************************************************************
1416 static struct file
*open_include_file( const struct makefile
*make
, struct incl_file
*pFile
)
1418 struct file
*file
= NULL
;
1419 unsigned int i
, len
;
1423 /* check for generated files */
1424 if ((file
= open_local_generated_file( make
, pFile
, ".tab.h", ".y" ))) return file
;
1425 if ((file
= open_local_generated_file( make
, pFile
, ".h", ".idl" ))) return file
;
1426 if (fontforge
&& (file
= open_local_generated_file( make
, pFile
, ".ttf", ".sfd" ))) return file
;
1427 if (convert
&& rsvg
&& icotool
)
1429 if ((file
= open_local_generated_file( make
, pFile
, ".bmp", ".svg" ))) return file
;
1430 if ((file
= open_local_generated_file( make
, pFile
, ".cur", ".svg" ))) return file
;
1431 if ((file
= open_local_generated_file( make
, pFile
, ".ico", ".svg" ))) return file
;
1434 /* check for extra targets */
1435 if (strarray_exists( &make
->extra_targets
, pFile
->name
))
1437 pFile
->sourcename
= src_dir_path( make
, pFile
->name
);
1438 pFile
->filename
= obj_dir_path( make
, pFile
->name
);
1442 /* now try in source dir */
1443 if ((file
= open_local_file( make
, pFile
->name
, &pFile
->filename
))) return file
;
1445 /* check for global importlib (module dependency) */
1446 if (pFile
->type
== INCL_IMPORTLIB
&& find_importlib_module( pFile
->name
))
1448 pFile
->filename
= pFile
->name
;
1452 /* check for generated files in global includes */
1453 if ((file
= open_global_generated_file( make
, pFile
, ".h", ".idl" ))) return file
;
1454 if ((file
= open_global_generated_file( make
, pFile
, ".h", ".h.in" ))) return file
;
1455 if (strendswith( pFile
->name
, "tmpl.h" ) &&
1456 (file
= open_global_generated_file( make
, pFile
, ".h", ".x" ))) return file
;
1458 /* check in global includes source dir */
1459 if ((file
= open_global_header( pFile
->name
, &pFile
->filename
))) return file
;
1461 /* check in global msvcrt includes */
1462 if (pFile
->use_msvcrt
&&
1463 (file
= open_global_header( strmake( "msvcrt/%s", pFile
->name
), &pFile
->filename
)))
1466 /* now search in include paths */
1467 for (i
= 0; i
< make
->include_paths
.count
; i
++)
1469 const char *dir
= make
->include_paths
.str
[i
];
1473 len
= strlen( root_src_dir
);
1474 if (!strncmp( dir
, root_src_dir
, len
) && (!dir
[len
] || dir
[len
] == '/'))
1476 while (dir
[len
] == '/') len
++;
1477 file
= open_global_file( concat_paths( dir
+ len
, pFile
->name
), &pFile
->filename
);
1482 if (*dir
== '/') continue;
1483 file
= open_include_path_file( make
, dir
, pFile
->name
, &pFile
->filename
);
1485 if (!file
) continue;
1486 pFile
->is_external
= 1;
1490 if (pFile
->type
== INCL_SYSTEM
) return NULL
; /* ignore system files we cannot find */
1492 /* try in src file directory */
1493 if ((file
= open_same_dir_generated_file( make
, pFile
->included_by
, pFile
, ".tab.h", ".y" )) ||
1494 (file
= open_same_dir_generated_file( make
, pFile
->included_by
, pFile
, ".h", ".idl" )) ||
1495 (file
= open_file_same_dir( pFile
->included_by
, pFile
->name
, &pFile
->filename
)))
1497 pFile
->is_external
= pFile
->included_by
->is_external
;
1501 if (make
->extlib
) return NULL
; /* ignore missing files in external libs */
1503 fprintf( stderr
, "%s:%d: error: ", pFile
->included_by
->file
->name
, pFile
->included_line
);
1504 perror( pFile
->name
);
1505 pFile
= pFile
->included_by
;
1506 while (pFile
&& pFile
->included_by
)
1508 const char *parent
= pFile
->included_by
->sourcename
;
1509 if (!parent
) parent
= pFile
->included_by
->file
->name
;
1510 fprintf( stderr
, "%s:%d: note: %s was first included here\n",
1511 parent
, pFile
->included_line
, pFile
->name
);
1512 pFile
= pFile
->included_by
;
1518 /*******************************************************************
1521 static void add_all_includes( struct makefile
*make
, struct incl_file
*parent
, struct file
*file
)
1525 for (i
= 0; i
< file
->deps_count
; i
++)
1527 switch (file
->deps
[i
].type
)
1531 add_include( make
, parent
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_NORMAL
);
1533 case INCL_IMPORTLIB
:
1534 add_include( make
, parent
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_IMPORTLIB
);
1537 add_include( make
, parent
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_SYSTEM
);
1539 case INCL_CPP_QUOTE
:
1540 case INCL_CPP_QUOTE_SYSTEM
:
1547 /*******************************************************************
1550 static void parse_file( struct makefile
*make
, struct incl_file
*source
, int src
)
1552 struct file
*file
= src
? open_src_file( make
, source
) : open_include_file( make
, source
);
1556 source
->file
= file
;
1557 source
->files_count
= 0;
1558 source
->files_size
= file
->deps_count
;
1559 source
->files
= xmalloc( source
->files_size
* sizeof(*source
->files
) );
1561 if (strendswith( file
->name
, ".m" )) file
->flags
|= FLAG_C_UNIX
;
1562 if (file
->flags
& FLAG_C_UNIX
) source
->use_msvcrt
= 0;
1563 else if (file
->flags
& FLAG_C_IMPLIB
) source
->use_msvcrt
= 1;
1565 if (source
->sourcename
)
1567 if (strendswith( source
->sourcename
, ".idl" ))
1571 /* generated .h file always includes these */
1572 add_include( make
, source
, "rpc.h", 0, INCL_NORMAL
);
1573 add_include( make
, source
, "rpcndr.h", 0, INCL_NORMAL
);
1574 for (i
= 0; i
< file
->deps_count
; i
++)
1576 switch (file
->deps
[i
].type
)
1579 if (strendswith( file
->deps
[i
].name
, ".idl" ))
1580 add_include( make
, source
, replace_extension( file
->deps
[i
].name
, ".idl", ".h" ),
1581 file
->deps
[i
].line
, INCL_NORMAL
);
1583 add_include( make
, source
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_NORMAL
);
1585 case INCL_CPP_QUOTE
:
1586 add_include( make
, source
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_NORMAL
);
1588 case INCL_CPP_QUOTE_SYSTEM
:
1589 add_include( make
, source
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_SYSTEM
);
1593 case INCL_IMPORTLIB
:
1599 if (strendswith( source
->sourcename
, ".y" ))
1600 return; /* generated .tab.h doesn't include anything */
1603 add_all_includes( make
, source
, file
);
1607 /*******************************************************************
1610 * Add a source file to the list.
1612 static struct incl_file
*add_src_file( struct makefile
*make
, const char *name
)
1614 struct incl_file
*file
= xmalloc( sizeof(*file
) );
1616 memset( file
, 0, sizeof(*file
) );
1617 file
->name
= xstrdup(name
);
1618 file
->use_msvcrt
= is_using_msvcrt( make
);
1619 file
->is_external
= !!make
->extlib
;
1620 list_add_tail( &make
->sources
, &file
->entry
);
1621 if (make
== include_makefile
)
1623 unsigned int hash
= hash_filename( name
);
1624 list_add_tail( &global_includes
[hash
], &file
->hash_entry
);
1626 parse_file( make
, file
, 1 );
1631 /*******************************************************************
1632 * open_input_makefile
1634 static FILE *open_input_makefile( const struct makefile
*make
)
1639 input_file_name
= root_src_dir_path( obj_dir_path( make
, "Makefile.in" ));
1641 input_file_name
= output_makefile_name
; /* always use output name for main Makefile */
1644 if (!(ret
= fopen( input_file_name
, "r" ))) fatal_perror( "open" );
1649 /*******************************************************************
1652 static const char *get_make_variable( const struct makefile
*make
, const char *name
)
1656 if ((ret
= strarray_get_value( &cmdline_vars
, name
))) return ret
;
1657 if ((ret
= strarray_get_value( &make
->vars
, name
))) return ret
;
1658 if (top_makefile
&& (ret
= strarray_get_value( &top_makefile
->vars
, name
))) return ret
;
1663 /*******************************************************************
1664 * get_expanded_make_variable
1666 static char *get_expanded_make_variable( const struct makefile
*make
, const char *name
)
1669 char *p
, *end
, *expand
, *tmp
;
1671 var
= get_make_variable( make
, name
);
1672 if (!var
) return NULL
;
1674 p
= expand
= xstrdup( var
);
1675 while ((p
= strchr( p
, '$' )))
1679 if (!(end
= strchr( p
+ 2, ')' ))) fatal_error( "syntax error in '%s'\n", expand
);
1681 if (strchr( p
+ 2, ':' )) fatal_error( "pattern replacement not supported for '%s'\n", p
+ 2 );
1682 var
= get_make_variable( make
, p
+ 2 );
1683 tmp
= replace_substr( expand
, p
, end
- p
, var
? var
: "" );
1684 /* switch to the new string */
1685 p
= tmp
+ (p
- expand
);
1689 else if (p
[1] == '{') /* don't expand ${} variables */
1691 if (!(end
= strchr( p
+ 2, '}' ))) fatal_error( "syntax error in '%s'\n", expand
);
1694 else if (p
[1] == '$')
1698 else fatal_error( "syntax error in '%s'\n", expand
);
1701 /* consider empty variables undefined */
1702 p
= skip_spaces( expand
);
1703 if (*p
) return expand
;
1709 /*******************************************************************
1710 * get_expanded_make_var_array
1712 static struct strarray
get_expanded_make_var_array( const struct makefile
*make
, const char *name
)
1714 struct strarray ret
= empty_strarray
;
1715 char *value
, *token
;
1717 if ((value
= get_expanded_make_variable( make
, name
)))
1718 for (token
= strtok( value
, " \t" ); token
; token
= strtok( NULL
, " \t" ))
1719 strarray_add( &ret
, token
);
1724 /*******************************************************************
1725 * get_expanded_file_local_var
1727 static struct strarray
get_expanded_file_local_var( const struct makefile
*make
, const char *file
,
1730 char *p
, *var
= strmake( "%s_%s", file
, name
);
1732 for (p
= var
; *p
; p
++) if (!isalnum( *p
)) *p
= '_';
1733 return get_expanded_make_var_array( make
, var
);
1737 /*******************************************************************
1738 * get_expanded_arch_var
1740 static char *get_expanded_arch_var( const struct makefile
*make
, const char *name
, int arch
)
1742 return get_expanded_make_variable( make
, arch
? strmake( "%s_%s", archs
.str
[arch
], name
) : name
);
1746 /*******************************************************************
1747 * get_expanded_arch_var_array
1749 static struct strarray
get_expanded_arch_var_array( const struct makefile
*make
, const char *name
, int arch
)
1751 return get_expanded_make_var_array( make
, arch
? strmake( "%s_%s", archs
.str
[arch
], name
) : name
);
1755 /*******************************************************************
1758 static int set_make_variable( struct strarray
*array
, const char *assignment
)
1762 p
= name
= xstrdup( assignment
);
1763 while (isalnum(*p
) || *p
== '_') p
++;
1764 if (name
== p
) return 0; /* not a variable */
1768 p
= skip_spaces( p
);
1770 if (*p
!= '=') return 0; /* not an assignment */
1772 p
= skip_spaces( p
);
1774 strarray_set_value( array
, name
, p
);
1779 /*******************************************************************
1782 static struct makefile
*parse_makefile( const char *path
)
1786 struct makefile
*make
= xmalloc( sizeof(*make
) );
1788 memset( make
, 0, sizeof(*make
) );
1789 make
->obj_dir
= path
;
1790 if (root_src_dir
) make
->src_dir
= root_src_dir_path( make
->obj_dir
);
1791 if (path
&& !strcmp( path
, "include" )) include_makefile
= make
;
1793 file
= open_input_makefile( make
);
1794 while ((buffer
= get_line( file
)))
1796 if (!strncmp( buffer
, separator
, strlen(separator
) )) break;
1797 if (*buffer
== '\t') continue; /* command */
1798 buffer
= skip_spaces( buffer
);
1799 if (*buffer
== '#') continue; /* comment */
1800 set_make_variable( &make
->vars
, buffer
);
1803 input_file_name
= NULL
;
1808 /*******************************************************************
1809 * add_generated_sources
1811 static void add_generated_sources( struct makefile
*make
)
1813 unsigned int i
, arch
;
1814 struct incl_file
*source
, *next
, *file
, *dlldata
= NULL
;
1815 struct strarray objs
= get_expanded_make_var_array( make
, "EXTRA_OBJS" );
1817 LIST_FOR_EACH_ENTRY_SAFE( source
, next
, &make
->sources
, struct incl_file
, entry
)
1819 for (arch
= 0; arch
< archs
.count
; arch
++)
1821 if (!is_multiarch( arch
)) continue;
1822 if (source
->file
->flags
& FLAG_IDL_CLIENT
)
1824 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_c.c" ), NULL
, arch
);
1825 add_dependency( file
->file
, replace_extension( source
->name
, ".idl", ".h" ), INCL_NORMAL
);
1826 add_all_includes( make
, file
, file
->file
);
1828 if (source
->file
->flags
& FLAG_IDL_SERVER
)
1830 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_s.c" ), NULL
, arch
);
1831 add_dependency( file
->file
, "wine/exception.h", INCL_NORMAL
);
1832 add_dependency( file
->file
, replace_extension( source
->name
, ".idl", ".h" ), INCL_NORMAL
);
1833 add_all_includes( make
, file
, file
->file
);
1835 if (source
->file
->flags
& FLAG_IDL_IDENT
)
1837 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_i.c" ), NULL
, arch
);
1838 add_dependency( file
->file
, "rpc.h", INCL_NORMAL
);
1839 add_dependency( file
->file
, "rpcndr.h", INCL_NORMAL
);
1840 add_dependency( file
->file
, "guiddef.h", INCL_NORMAL
);
1841 add_all_includes( make
, file
, file
->file
);
1843 if (source
->file
->flags
& FLAG_IDL_PROXY
)
1845 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_p.c" ), NULL
, arch
);
1846 add_dependency( file
->file
, "objbase.h", INCL_NORMAL
);
1847 add_dependency( file
->file
, "rpcproxy.h", INCL_NORMAL
);
1848 add_dependency( file
->file
, "wine/exception.h", INCL_NORMAL
);
1849 add_dependency( file
->file
, replace_extension( source
->name
, ".idl", ".h" ), INCL_NORMAL
);
1850 add_all_includes( make
, file
, file
->file
);
1852 if (source
->file
->flags
& FLAG_IDL_TYPELIB
)
1854 add_generated_source( make
, replace_extension( source
->name
, ".idl", "_l.res" ), NULL
, arch
);
1856 if (source
->file
->flags
& FLAG_IDL_REGTYPELIB
)
1858 add_generated_source( make
, replace_extension( source
->name
, ".idl", "_t.res" ), NULL
, arch
);
1860 if (source
->file
->flags
& FLAG_IDL_REGISTER
)
1862 add_generated_source( make
, replace_extension( source
->name
, ".idl", "_r.res" ), NULL
, arch
);
1866 /* now the arch-independent files */
1868 if ((source
->file
->flags
& FLAG_IDL_PROXY
) && !dlldata
)
1870 dlldata
= add_generated_source( make
, "dlldata.o", "dlldata.c", 0 );
1871 add_dependency( dlldata
->file
, "objbase.h", INCL_NORMAL
);
1872 add_dependency( dlldata
->file
, "rpcproxy.h", INCL_NORMAL
);
1873 add_all_includes( make
, dlldata
, dlldata
->file
);
1875 if (source
->file
->flags
& FLAG_IDL_HEADER
)
1877 add_generated_source( make
, replace_extension( source
->name
, ".idl", ".h" ), NULL
, 0 );
1879 if (!source
->file
->flags
&& strendswith( source
->name
, ".idl" ))
1881 if (!strncmp( source
->name
, "wine/", 5 )) continue;
1882 source
->file
->flags
= FLAG_IDL_HEADER
| FLAG_INSTALL
;
1883 add_generated_source( make
, replace_extension( source
->name
, ".idl", ".h" ), NULL
, 0 );
1885 if (strendswith( source
->name
, ".x" ))
1887 add_generated_source( make
, replace_extension( source
->name
, ".x", ".h" ), NULL
, 0 );
1889 if (strendswith( source
->name
, ".y" ))
1891 file
= add_generated_source( make
, replace_extension( source
->name
, ".y", ".tab.c" ), NULL
, 0 );
1892 /* steal the includes list from the source file */
1893 file
->files_count
= source
->files_count
;
1894 file
->files_size
= source
->files_size
;
1895 file
->files
= source
->files
;
1896 source
->files_count
= source
->files_size
= 0;
1897 source
->files
= NULL
;
1899 if (strendswith( source
->name
, ".l" ))
1901 file
= add_generated_source( make
, replace_extension( source
->name
, ".l", ".yy.c" ), NULL
, 0 );
1902 /* steal the includes list from the source file */
1903 file
->files_count
= source
->files_count
;
1904 file
->files_size
= source
->files_size
;
1905 file
->files
= source
->files
;
1906 source
->files_count
= source
->files_size
= 0;
1907 source
->files
= NULL
;
1909 if (strendswith( source
->name
, ".po" ))
1911 if (!make
->disabled
[0])
1912 strarray_add_uniq( &linguas
, replace_extension( source
->name
, ".po", "" ));
1914 if (strendswith( source
->name
, ".spec" ))
1916 char *obj
= replace_extension( source
->name
, ".spec", "" );
1917 strarray_addall_uniq( &make
->extra_imports
,
1918 get_expanded_file_local_var( make
, obj
, "IMPORTS" ));
1923 for (arch
= 0; arch
< archs
.count
; arch
++)
1925 if (!is_multiarch( arch
)) continue;
1926 file
= add_generated_source( make
, "testlist.o", "testlist.c", arch
);
1927 add_dependency( file
->file
, "wine/test.h", INCL_NORMAL
);
1928 add_all_includes( make
, file
, file
->file
);
1931 for (i
= 0; i
< objs
.count
; i
++)
1933 /* default to .c for unknown extra object files */
1934 if (strendswith( objs
.str
[i
], ".o" ))
1936 file
= add_generated_source( make
, objs
.str
[i
], replace_extension( objs
.str
[i
], ".o", ".c" ), 0);
1937 file
->file
->flags
|= FLAG_C_UNIX
;
1938 file
->use_msvcrt
= 0;
1940 else if (strendswith( objs
.str
[i
], ".res" ))
1941 add_generated_source( make
, replace_extension( objs
.str
[i
], ".res", ".rc" ), NULL
, 0 );
1943 add_generated_source( make
, objs
.str
[i
], NULL
, 0 );
1948 /*******************************************************************
1951 static void create_dir( const char *dir
)
1955 p
= path
= xstrdup( dir
);
1956 while ((p
= strchr( p
, '/' )))
1959 if (mkdir( path
, 0755 ) == -1 && errno
!= EEXIST
) fatal_perror( "mkdir %s", path
);
1961 while (*p
== '/') p
++;
1963 if (mkdir( path
, 0755 ) == -1 && errno
!= EEXIST
) fatal_perror( "mkdir %s", path
);
1968 /*******************************************************************
1969 * create_file_directories
1971 * Create the base directories of all the files.
1973 static void create_file_directories( const struct makefile
*make
, struct strarray files
)
1975 struct strarray subdirs
= empty_strarray
;
1979 for (i
= 0; i
< files
.count
; i
++)
1981 if (!strchr( files
.str
[i
], '/' )) continue;
1982 dir
= obj_dir_path( make
, files
.str
[i
] );
1983 *strrchr( dir
, '/' ) = 0;
1984 strarray_add_uniq( &subdirs
, dir
);
1987 for (i
= 0; i
< subdirs
.count
; i
++) create_dir( subdirs
.str
[i
] );
1991 /*******************************************************************
1992 * output_filenames_obj_dir
1994 static void output_filenames_obj_dir( const struct makefile
*make
, struct strarray array
)
1998 for (i
= 0; i
< array
.count
; i
++) output_filename( obj_dir_path( make
, array
.str
[i
] ));
2002 /*******************************************************************
2005 static void get_dependencies( struct incl_file
*file
, struct incl_file
*source
)
2009 if (!file
->filename
) return;
2013 if (file
->owner
== source
) return; /* already processed */
2014 if (file
->type
== INCL_IMPORTLIB
)
2016 if (!(source
->file
->flags
& (FLAG_IDL_TYPELIB
| FLAG_IDL_REGTYPELIB
)))
2017 return; /* library is imported only when building a typelib */
2018 strarray_add( &source
->importlibdeps
, file
->filename
);
2020 else strarray_add( &source
->dependencies
, file
->filename
);
2021 file
->owner
= source
;
2024 if (!strcmp( file
->filename
, "include/config.h" ) &&
2025 file
!= source
->files
[0] && !source
->is_external
)
2027 input_file_name
= source
->filename
;
2029 for (i
= 0; i
< source
->file
->deps_count
; i
++)
2031 if (!strcmp( source
->file
->deps
[i
].name
, file
->name
))
2032 input_line
= source
->file
->deps
[i
].line
;
2034 fatal_error( "%s must be included before other headers\n", file
->name
);
2038 for (i
= 0; i
< file
->files_count
; i
++) get_dependencies( file
->files
[i
], source
);
2042 /*******************************************************************
2043 * get_local_dependencies
2045 * Get the local dependencies of a given target.
2047 static struct strarray
get_local_dependencies( const struct makefile
*make
, const char *name
,
2048 struct strarray targets
)
2051 struct strarray deps
= get_expanded_file_local_var( make
, name
, "DEPS" );
2053 for (i
= 0; i
< deps
.count
; i
++)
2055 if (strarray_exists( &targets
, deps
.str
[i
] ))
2056 deps
.str
[i
] = obj_dir_path( make
, deps
.str
[i
] );
2058 deps
.str
[i
] = src_dir_path( make
, deps
.str
[i
] );
2064 /*******************************************************************
2067 * Find the makefile that builds the named static library (which may be an import lib).
2069 static struct makefile
*get_static_lib( const char *name
, unsigned int arch
)
2073 for (i
= 0; i
< subdirs
.count
; i
++)
2075 if (submakes
[i
]->importlib
&& !strcmp( submakes
[i
]->importlib
, name
)) return submakes
[i
];
2076 if (!submakes
[i
]->staticlib
) continue;
2077 if (submakes
[i
]->disabled
[arch
]) continue;
2078 if (strncmp( submakes
[i
]->staticlib
, "lib", 3 )) continue;
2079 if (strncmp( submakes
[i
]->staticlib
+ 3, name
, strlen(name
) )) continue;
2080 if (strcmp( submakes
[i
]->staticlib
+ 3 + strlen(name
), ".a" )) continue;
2087 /*******************************************************************
2088 * get_native_unix_lib
2090 static const char *get_native_unix_lib( const struct makefile
*make
, const char *name
)
2092 if (!make
->unixlib
) return NULL
;
2093 if (strncmp( make
->unixlib
, name
, strlen(name
) )) return NULL
;
2094 if (make
->unixlib
[strlen(name
)] != '.') return NULL
;
2095 return obj_dir_path( make
, make
->unixlib
);
2099 /*******************************************************************
2100 * get_parent_makefile
2102 static struct makefile
*get_parent_makefile( struct makefile
*make
)
2107 if (!make
->obj_dir
) return NULL
;
2108 dir
= xstrdup( make
->obj_dir
);
2109 if (!(p
= strrchr( dir
, '/' ))) return NULL
;
2111 for (i
= 0; i
< subdirs
.count
; i
++)
2112 if (!strcmp( submakes
[i
]->obj_dir
, dir
)) return submakes
[i
];
2117 /*******************************************************************
2120 static int needs_delay_lib( const struct makefile
*make
, unsigned int arch
)
2122 if (delay_load_flags
[arch
]) return 0;
2123 if (!make
->importlib
) return 0;
2124 return strarray_exists( &delay_import_libs
, make
->importlib
);
2128 /*******************************************************************
2129 * add_unix_libraries
2131 static struct strarray
add_unix_libraries( const struct makefile
*make
, struct strarray
*deps
)
2133 struct strarray ret
= empty_strarray
;
2134 struct strarray all_libs
= empty_strarray
;
2137 if (strcmp( make
->unixlib
, "ntdll.so" )) strarray_add( &all_libs
, "-lntdll" );
2138 strarray_addall( &all_libs
, get_expanded_make_var_array( make
, "UNIX_LIBS" ));
2140 for (i
= 0; i
< all_libs
.count
; i
++)
2142 const char *lib
= NULL
;
2144 if (!strncmp( all_libs
.str
[i
], "-l", 2 ))
2146 for (j
= 0; j
< subdirs
.count
; j
++)
2148 if (make
== submakes
[j
]) continue;
2149 if ((lib
= get_native_unix_lib( submakes
[j
], all_libs
.str
[i
] + 2 ))) break;
2154 strarray_add( deps
, lib
);
2155 strarray_add( &ret
, lib
);
2157 else strarray_add( &ret
, all_libs
.str
[i
] );
2160 strarray_addall( &ret
, libs
);
2165 /*******************************************************************
2168 static int is_crt_module( const char *file
)
2170 return !strncmp( file
, "msvcr", 5 ) || !strncmp( file
, "ucrt", 4 ) || !strcmp( file
, "crtdll.dll" );
2174 /*******************************************************************
2177 static const char *get_default_crt( const struct makefile
*make
)
2179 if (make
->module
&& is_crt_module( make
->module
)) return NULL
; /* don't add crt import to crt dlls */
2180 return !make
->testdll
&& (!make
->staticlib
|| make
->extlib
) ? "ucrtbase" : "msvcrt";
2184 /*******************************************************************
2187 static const char *get_crt_define( const struct makefile
*make
)
2189 const char *crt_dll
= NULL
;
2190 unsigned int i
, version
= 0;
2192 for (i
= 0; i
< make
->imports
.count
; i
++)
2194 if (!is_crt_module( make
->imports
.str
[i
] )) continue;
2195 if (crt_dll
) fatal_error( "More than one C runtime DLL imported: %s and %s\n",
2196 crt_dll
, make
->imports
.str
[i
] );
2197 crt_dll
= make
->imports
.str
[i
];
2202 if (strarray_exists( &make
->extradllflags
, "-nodefaultlibs" )) return "-D_MSVCR_VER=0";
2203 if (!(crt_dll
= get_default_crt( make
))) crt_dll
= make
->module
;
2205 if (!strncmp( crt_dll
, "ucrt", 4 )) return "-D_UCRT";
2206 sscanf( crt_dll
, "msvcr%u", &version
);
2207 return strmake( "-D_MSVCR_VER=%u", version
);
2211 /*******************************************************************
2212 * get_default_imports
2214 static struct strarray
get_default_imports( const struct makefile
*make
, struct strarray imports
)
2216 struct strarray ret
= empty_strarray
;
2217 const char *crt_dll
= get_default_crt( make
);
2220 for (i
= 0; i
< imports
.count
; i
++)
2221 if (is_crt_module( imports
.str
[i
] ))
2222 crt_dll
= imports
.str
[i
];
2224 strarray_add( &ret
, "winecrt0" );
2225 if (crt_dll
) strarray_add( &ret
, crt_dll
);
2227 if (make
->is_win16
&& (!make
->importlib
|| strcmp( make
->importlib
, "kernel" )))
2228 strarray_add( &ret
, "kernel" );
2230 strarray_add( &ret
, "kernel32" );
2231 strarray_add( &ret
, "ntdll" );
2238 IMPORT_TYPE_DELAYED
,
2239 IMPORT_TYPE_DEFAULT
,
2242 /*******************************************************************
2245 static struct strarray
add_import_libs( const struct makefile
*make
, struct strarray
*deps
,
2246 struct strarray imports
, enum import_type type
, unsigned int arch
)
2248 struct strarray ret
= empty_strarray
;
2251 for (i
= 0; i
< imports
.count
; i
++)
2253 const char *name
= imports
.str
[i
];
2254 struct makefile
*submake
;
2256 /* add crt import lib only when adding the default imports libs */
2257 if (is_crt_module( imports
.str
[i
] ) && type
!= IMPORT_TYPE_DEFAULT
) continue;
2263 case 'L': strarray_add( &ret
, name
); continue;
2264 case 'l': name
+= 2; break;
2268 else name
= get_base_name( name
);
2270 if ((submake
= get_static_lib( name
, arch
)))
2272 const char *ext
= (type
== IMPORT_TYPE_DELAYED
&& !delay_load_flags
[arch
]) ? ".delay.a" : ".a";
2273 const char *lib
= obj_dir_path( submake
, strmake( "%slib%s%s", arch_dirs
[arch
], name
, ext
));
2274 strarray_add_uniq( deps
, lib
);
2275 strarray_add( &ret
, lib
);
2277 else strarray_add( &ret
, strmake( "-l%s", name
));
2283 /*******************************************************************
2286 static void add_install_rule( struct makefile
*make
, const char *target
, unsigned int arch
,
2287 const char *file
, const char *dest
)
2291 if (make
->disabled
[arch
]) return;
2293 for (i
= 0; i
< NB_INSTALL_RULES
; i
++)
2295 if (strarray_exists( &make
->install
[i
], target
) ||
2296 strarray_exists( &top_install
[i
], make
->obj_dir
) ||
2297 strarray_exists( &top_install
[i
], obj_dir_path( make
, target
)))
2299 strarray_add( &make
->install_rules
[i
], file
);
2300 strarray_add( &make
->install_rules
[i
], dest
);
2307 /*******************************************************************
2308 * get_include_install_path
2310 * Determine the installation path for a given include file.
2312 static const char *get_include_install_path( const char *name
)
2314 if (!strncmp( name
, "wine/", 5 )) return name
+ 5;
2315 if (!strncmp( name
, "msvcrt/", 7 )) return name
;
2316 return strmake( "windows/%s", name
);
2320 /*******************************************************************
2321 * get_shared_library_name
2323 * Determine possible names for a shared library with a version number.
2325 static struct strarray
get_shared_lib_names( const char *libname
)
2327 struct strarray ret
= empty_strarray
;
2328 const char *ext
, *p
;
2329 char *name
, *first
, *second
;
2332 strarray_add( &ret
, libname
);
2334 for (p
= libname
; (p
= strchr( p
, '.' )); p
++)
2335 if ((len
= strspn( p
+ 1, "0123456789." ))) break;
2337 if (!len
) return ret
;
2339 if (*ext
&& ext
[-1] == '.') ext
--;
2341 /* keep only the first group of digits */
2342 name
= xstrdup( libname
);
2343 first
= name
+ (p
- libname
);
2344 if ((second
= strchr( first
+ 1, '.' )))
2346 strcpy( second
, ext
);
2347 strarray_add( &ret
, xstrdup( name
));
2353 /*******************************************************************
2354 * get_source_defines
2356 static struct strarray
get_source_defines( struct makefile
*make
, struct incl_file
*source
,
2360 struct strarray ret
= empty_strarray
;
2362 strarray_addall( &ret
, make
->include_args
);
2363 if (source
->use_msvcrt
)
2365 strarray_add( &ret
, strmake( "-I%s", root_src_dir_path( "include/msvcrt" )));
2366 for (i
= 0; i
< make
->include_paths
.count
; i
++)
2367 strarray_add( &ret
, strmake( "-I%s", make
->include_paths
.str
[i
] ));
2368 strarray_add( &ret
, get_crt_define( make
));
2370 strarray_addall( &ret
, make
->define_args
);
2371 strarray_addall( &ret
, get_expanded_file_local_var( make
, obj
, "EXTRADEFS" ));
2372 if (source
->file
->flags
& FLAG_C_UNIX
) strarray_add( &ret
, "-DWINE_UNIX_LIB" );
2377 /*******************************************************************
2378 * remove_warning_flags
2380 static struct strarray
remove_warning_flags( struct strarray flags
)
2383 struct strarray ret
= empty_strarray
;
2385 for (i
= 0; i
< flags
.count
; i
++)
2386 if (strncmp( flags
.str
[i
], "-W", 2 ) || !strncmp( flags
.str
[i
], "-Wno-", 5 ))
2387 strarray_add( &ret
, flags
.str
[i
] );
2392 /*******************************************************************
2395 static const char *get_debug_file( struct makefile
*make
, const char *name
, unsigned int arch
)
2397 const char *debug_file
= NULL
;
2398 if (!debug_flags
[arch
]) return NULL
;
2399 if (!strcmp( debug_flags
[arch
], "pdb" )) debug_file
= strmake( "%s.pdb", get_base_name( name
));
2400 else if (!strncmp( debug_flags
[arch
], "split", 5 )) debug_file
= strmake( "%s.debug", name
);
2401 if (debug_file
) strarray_add( &make
->debug_files
, debug_file
);
2406 /*******************************************************************
2409 static const char *cmd_prefix( const char *cmd
)
2411 if (!silent_rules
) return "";
2412 return strmake( "$(quiet_%s)", cmd
);
2416 /*******************************************************************
2417 * output_winegcc_command
2419 static void output_winegcc_command( struct makefile
*make
, unsigned int arch
)
2421 output( "\t%s%s -o $@", cmd_prefix( "CCLD" ), tools_path( make
, "winegcc" ));
2422 output_filename( "--wine-objdir ." );
2425 output_filename( "--winebuild" );
2426 output_filename( tools_path( make
, "winebuild" ));
2428 output_filenames( target_flags
[arch
] );
2430 output_filename( "-mno-cygwin" );
2431 output_filenames( lddll_flags
);
2435 /*******************************************************************
2436 * output_symlink_rule
2438 * Output a rule to create a symlink.
2440 static void output_symlink_rule( const char *src_name
, const char *link_name
, int create_dir
)
2442 const char *name
= strrchr( link_name
, '/' );
2447 dir
= xstrdup( link_name
);
2448 dir
[name
- link_name
] = 0;
2451 output( "\t%s", cmd_prefix( "LN" ));
2452 if (create_dir
&& dir
&& *dir
) output( "%s -d %s && ", root_src_dir_path( "tools/install-sh" ), dir
);
2453 output( "rm -f %s && ", link_name
);
2455 /* dest path with a directory needs special handling if ln -s isn't supported */
2456 if (dir
&& strcmp( ln_s
, "ln -s" ))
2457 output( "cd %s && %s %s %s\n", *dir
? dir
: "/", ln_s
, src_name
, name
+ 1 );
2459 output( "%s %s %s\n", ln_s
, src_name
, link_name
);
2465 /*******************************************************************
2466 * output_srcdir_symlink
2468 * Output rule to create a symlink back to the source directory, for source files
2469 * that are needed at run-time.
2471 static void output_srcdir_symlink( struct makefile
*make
, const char *obj
)
2473 char *src_file
, *dst_file
, *src_name
;
2475 if (!make
->src_dir
) return;
2476 src_file
= src_dir_path( make
, obj
);
2477 dst_file
= obj_dir_path( make
, obj
);
2478 output( "%s: %s\n", dst_file
, src_file
);
2480 src_name
= src_file
;
2481 if (src_name
[0] != '/' && make
->obj_dir
)
2482 src_name
= concat_paths( get_relative_path( make
->obj_dir
, "" ), src_name
);
2484 output_symlink_rule( src_name
, dst_file
, 0 );
2485 strarray_add( &make
->all_targets
[0], obj
);
2489 /*******************************************************************
2490 * output_install_commands
2492 static void output_install_commands( struct makefile
*make
, struct strarray files
)
2494 unsigned int i
, arch
;
2495 char *install_sh
= root_src_dir_path( "tools/install-sh" );
2497 for (i
= 0; i
< files
.count
; i
+= 2)
2499 const char *file
= files
.str
[i
];
2500 const char *dest
= strmake( "$(DESTDIR)%s", files
.str
[i
+ 1] + 1 );
2501 char type
= *files
.str
[i
+ 1];
2505 case '1': case '2': case '3': case '4': case '5':
2506 case '6': case '7': case '8': case '9': /* arch-dependent program */
2508 output( "\tSTRIPPROG=%s %s -m 644 $(INSTALL_PROGRAM_FLAGS) %s %s\n",
2509 strip_progs
[arch
], install_sh
, obj_dir_path( make
, file
), dest
);
2510 output( "\t%s --builtin %s\n", tools_path( make
, "winebuild" ), dest
);
2512 case 'd': /* data file */
2513 output( "\t%s -m 644 $(INSTALL_DATA_FLAGS) %s %s\n",
2514 install_sh
, obj_dir_path( make
, file
), dest
);
2516 case 'D': /* data file in source dir */
2517 output( "\t%s -m 644 $(INSTALL_DATA_FLAGS) %s %s\n",
2518 install_sh
, src_dir_path( make
, file
), dest
);
2520 case '0': /* native arch program file */
2521 case 'p': /* program file */
2522 output( "\tSTRIPPROG=\"$(STRIP)\" %s $(INSTALL_PROGRAM_FLAGS) %s %s\n",
2523 install_sh
, obj_dir_path( make
, file
), dest
);
2525 case 's': /* script */
2526 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s %s\n",
2527 install_sh
, obj_dir_path( make
, file
), dest
);
2529 case 'S': /* script in source dir */
2530 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s %s\n",
2531 install_sh
, src_dir_path( make
, file
), dest
);
2533 case 't': /* script in tools dir */
2534 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s %s\n",
2535 install_sh
, tools_dir_path( make
, files
.str
[i
] ), dest
);
2537 case 'y': /* symlink */
2538 output_symlink_rule( files
.str
[i
], dest
, 1 );
2543 strarray_add( &make
->uninstall_files
, dest
);
2548 /*******************************************************************
2549 * output_install_rules
2551 * Rules are stored as a (file,dest) pair of values.
2552 * The first char of dest indicates the type of install.
2554 static void output_install_rules( struct makefile
*make
, enum install_rules rules
)
2557 struct strarray files
= make
->install_rules
[rules
];
2558 struct strarray targets
= empty_strarray
;
2560 if (!files
.count
) return;
2562 for (i
= 0; i
< files
.count
; i
+= 2)
2564 const char *file
= files
.str
[i
];
2565 switch (*files
.str
[i
+ 1])
2567 case '0': case '1': case '2': case '3': case '4':
2568 case '5': case '6': case '7': case '8': case '9': /* arch-dependent program */
2569 case 'd': /* data file */
2570 case 'p': /* program file */
2571 case 's': /* script */
2572 strarray_add_uniq( &targets
, obj_dir_path( make
, file
));
2574 case 't': /* script in tools dir */
2575 strarray_add_uniq( &targets
, tools_dir_path( make
, file
));
2580 output( "%s %s::", obj_dir_path( make
, "install" ), obj_dir_path( make
, install_targets
[rules
] ));
2581 output_filenames( targets
);
2583 output_install_commands( make
, files
);
2584 strarray_add_uniq( &make
->phony_targets
, obj_dir_path( make
, "install" ));
2585 strarray_add_uniq( &make
->phony_targets
, obj_dir_path( make
, install_targets
[rules
] ));
2589 static int cmp_string_length( const char **a
, const char **b
)
2591 int paths_a
= 0, paths_b
= 0;
2594 for (p
= *a
; *p
; p
++) if (*p
== '/') paths_a
++;
2595 for (p
= *b
; *p
; p
++) if (*p
== '/') paths_b
++;
2596 if (paths_b
!= paths_a
) return paths_b
- paths_a
;
2597 return strcmp( *a
, *b
);
2600 /*******************************************************************
2601 * get_removable_dirs
2603 * Retrieve a list of directories to try to remove after deleting the files.
2605 static struct strarray
get_removable_dirs( struct strarray files
)
2607 struct strarray dirs
= empty_strarray
;
2610 for (i
= 0; i
< files
.count
; i
++)
2612 char *dir
= xstrdup( files
.str
[i
] );
2613 while (strchr( dir
, '/' ))
2615 *strrchr( dir
, '/' ) = 0;
2616 strarray_add_uniq( &dirs
, xstrdup(dir
) );
2619 strarray_qsort( &dirs
, cmp_string_length
);
2624 /*******************************************************************
2625 * output_uninstall_rules
2627 static void output_uninstall_rules( struct makefile
*make
)
2629 static const char *dirs_order
[] =
2630 { "$(includedir)", "$(mandir)", "$(fontdir)", "$(nlsdir)", "$(datadir)", "$(dlldir)" };
2632 struct strarray uninstall_dirs
;
2635 if (!make
->uninstall_files
.count
) return;
2636 output( "uninstall::\n" );
2637 output_rm_filenames( make
->uninstall_files
, "rm -f" );
2638 strarray_add_uniq( &make
->phony_targets
, "uninstall" );
2640 if (!subdirs
.count
) return;
2641 uninstall_dirs
= get_removable_dirs( make
->uninstall_files
);
2642 output( "\t-rmdir" );
2643 for (i
= 0; i
< ARRAY_SIZE(dirs_order
); i
++)
2645 for (j
= 0; j
< uninstall_dirs
.count
; j
++)
2647 if (!uninstall_dirs
.str
[j
]) continue;
2648 if (strncmp( uninstall_dirs
.str
[j
] + strlen("$(DESTDIR)"), dirs_order
[i
], strlen(dirs_order
[i
]) ))
2650 output_filename( uninstall_dirs
.str
[j
] );
2651 uninstall_dirs
.str
[j
] = NULL
;
2654 for (j
= 0; j
< uninstall_dirs
.count
; j
++)
2655 if (uninstall_dirs
.str
[j
]) output_filename( uninstall_dirs
.str
[j
] );
2660 /*******************************************************************
2663 static void output_po_files( struct makefile
*make
)
2665 const char *po_dir
= src_dir_path( make
, "po" );
2670 for (i
= 0; i
< linguas
.count
; i
++)
2671 output_filename( strmake( "%s/%s.po", po_dir
, linguas
.str
[i
] ));
2672 output( ": %s/wine.pot\n", po_dir
);
2673 output( "\t%smsgmerge --previous -q $@ %s/wine.pot | msgattrib --no-obsolete -o $@.new && mv $@.new $@\n",
2674 cmd_prefix( "MSG" ), po_dir
);
2675 output( "po/all:" );
2676 for (i
= 0; i
< linguas
.count
; i
++)
2677 output_filename( strmake( "%s/%s.po", po_dir
, linguas
.str
[i
] ));
2680 output( "%s/wine.pot:", po_dir
);
2681 output_filenames( make
->pot_files
);
2683 output( "\t%smsgcat -o $@", cmd_prefix( "MSG" ));
2684 output_filenames( make
->pot_files
);
2686 strarray_add( &make
->maintainerclean_files
, strmake( "%s/wine.pot", po_dir
));
2690 /*******************************************************************
2693 static void output_source_y( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2695 /* add source file dependency for parallel makes */
2696 char *header
= strmake( "%s.tab.h", obj
);
2698 if (find_include_file( make
, header
))
2700 output( "%s: %s\n", obj_dir_path( make
, header
), source
->filename
);
2701 output( "\t%s%s -o %s.tab.c -d %s\n",
2702 cmd_prefix( "BISON" ), bison
, obj_dir_path( make
, obj
), source
->filename
);
2703 output( "%s.tab.c: %s %s\n", obj_dir_path( make
, obj
),
2704 source
->filename
, obj_dir_path( make
, header
));
2705 strarray_add( &make
->clean_files
, header
);
2707 else output( "%s.tab.c: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2709 output( "\t%s%s -o $@ %s\n", cmd_prefix( "BISON" ), bison
, source
->filename
);
2713 /*******************************************************************
2716 static void output_source_l( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2718 output( "%s.yy.c: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2719 output( "\t%s%s -o$@ %s\n", cmd_prefix( "FLEX" ), flex
, source
->filename
);
2723 /*******************************************************************
2726 static void output_source_h( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2728 if (source
->file
->flags
& FLAG_GENERATED
)
2729 strarray_add( &make
->all_targets
[0], source
->name
);
2730 else if ((source
->file
->flags
& FLAG_INSTALL
) || strncmp( source
->name
, "wine/", 5 ))
2731 add_install_rule( make
, source
->name
, 0, source
->name
,
2732 strmake( "D$(includedir)/wine/%s", get_include_install_path( source
->name
) ));
2736 /*******************************************************************
2739 static void output_source_rc( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2741 struct strarray defines
= get_source_defines( make
, source
, obj
);
2742 const char *po_dir
= NULL
, *res_file
= strmake( "%s.res", obj
);
2743 unsigned int i
, arch
;
2745 if (source
->file
->flags
& FLAG_RC_HEADER
) return;
2746 if (source
->file
->flags
& FLAG_GENERATED
) strarray_add( &make
->clean_files
, source
->name
);
2747 if (linguas
.count
&& (source
->file
->flags
& FLAG_RC_PO
)) po_dir
= "po";
2748 for (arch
= 0; arch
< archs
.count
; arch
++) strarray_add( &make
->res_files
[arch
], res_file
);
2749 if (source
->file
->flags
& FLAG_RC_PO
)
2751 strarray_add( &make
->pot_files
, strmake( "%s.pot", obj
));
2752 output( "%s.pot ", obj_dir_path( make
, obj
) );
2754 output( "%s: %s", obj_dir_path( make
, res_file
), source
->filename
);
2755 output_filename( tools_path( make
, "wrc" ));
2756 if (make
->src_dir
) output_filename( "nls/locale.nls" );
2757 output_filenames( source
->dependencies
);
2759 output( "\t%s%s -u -o $@", cmd_prefix( "WRC" ), tools_path( make
, "wrc" ) );
2760 if (make
->is_win16
) output_filename( "-m16" );
2761 output_filename( "--nostdinc" );
2762 if (po_dir
) output_filename( strmake( "--po-dir=%s", po_dir
));
2763 output_filenames( defines
);
2764 output_filename( source
->filename
);
2768 output( "%s:", obj_dir_path( make
, res_file
));
2769 for (i
= 0; i
< linguas
.count
; i
++)
2770 output_filename( strmake( "%s/%s.mo", po_dir
, linguas
.str
[i
] ));
2776 /*******************************************************************
2779 static void output_source_mc( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2781 unsigned int i
, arch
;
2782 char *obj_path
= obj_dir_path( make
, obj
);
2783 char *res_file
= strmake( "%s.res", obj
);
2785 for (arch
= 0; arch
< archs
.count
; arch
++) strarray_add( &make
->res_files
[arch
], res_file
);
2786 strarray_add( &make
->pot_files
, strmake( "%s.pot", obj
));
2787 output( "%s.pot %s.res: %s", obj_path
, obj_path
, source
->filename
);
2788 output_filename( tools_path( make
, "wmc" ));
2789 output_filenames( source
->dependencies
);
2790 if (make
->src_dir
) output_filename( "nls/locale.nls" );
2792 output( "\t%s%s -u -o $@ %s", cmd_prefix( "WMC" ), tools_path( make
, "wmc" ), source
->filename
);
2795 output_filename( "--po-dir=po" );
2797 output( "%s.res:", obj_dir_path( make
, obj
));
2798 for (i
= 0; i
< linguas
.count
; i
++)
2799 output_filename( strmake( "po/%s.mo", linguas
.str
[i
] ));
2805 /*******************************************************************
2808 static void output_source_res( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2810 strarray_add( &make
->res_files
[source
->arch
], source
->name
);
2814 /*******************************************************************
2817 static void output_source_idl( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2819 struct strarray defines
= get_source_defines( make
, source
, obj
);
2820 struct strarray headers
= empty_strarray
;
2821 struct strarray multiarch_targets
[MAX_ARCHS
] = { empty_strarray
};
2823 unsigned int i
, arch
;
2825 if (find_include_file( make
, strmake( "%s.h", obj
))) source
->file
->flags
|= FLAG_IDL_HEADER
;
2826 if (!source
->file
->flags
) return;
2828 if (source
->file
->flags
& FLAG_IDL_PROXY
) strarray_add( &make
->dlldata_files
, source
->name
);
2829 if (source
->file
->flags
& FLAG_INSTALL
)
2831 add_install_rule( make
, source
->name
, 0, xstrdup( source
->name
),
2832 strmake( "D$(includedir)/wine/%s.idl", get_include_install_path( obj
) ));
2833 if (source
->file
->flags
& FLAG_IDL_HEADER
)
2834 add_install_rule( make
, source
->name
, 0, strmake( "%s.h", obj
),
2835 strmake( "d$(includedir)/wine/%s.h", get_include_install_path( obj
) ));
2837 if (source
->file
->flags
& FLAG_IDL_HEADER
)
2839 dest
= strmake( "%s.h", obj
);
2840 strarray_add( &headers
, dest
);
2841 if (!find_src_file( make
, dest
)) strarray_add( &make
->clean_files
, dest
);
2844 for (i
= 0; i
< ARRAY_SIZE(idl_outputs
); i
++)
2846 if (!(source
->file
->flags
& idl_outputs
[i
].flag
)) continue;
2847 for (arch
= 0; arch
< archs
.count
; arch
++)
2849 if (!is_multiarch( arch
)) continue;
2850 dest
= strmake( "%s%s%s", arch_dirs
[arch
], obj
, idl_outputs
[i
].ext
);
2851 if (!find_src_file( make
, dest
)) strarray_add( &make
->clean_files
, dest
);
2852 strarray_add( &multiarch_targets
[arch
], dest
);
2856 for (arch
= 0; arch
< archs
.count
; arch
++)
2858 if (multiarch_targets
[arch
].count
+ (arch
? 0 : headers
.count
) == 0) continue;
2859 if (!arch
) output_filenames_obj_dir( make
, headers
);
2860 output_filenames_obj_dir( make
, multiarch_targets
[arch
] );
2862 output( "\t%s%s -o $@", cmd_prefix( "WIDL" ), tools_path( make
, "widl" ) );
2863 output_filenames( target_flags
[arch
] );
2864 output_filename( "--nostdinc" );
2865 output_filename( "-Ldlls/\\*" );
2866 output_filenames( defines
);
2867 output_filenames( get_expanded_make_var_array( make
, "EXTRAIDLFLAGS" ));
2868 output_filenames( get_expanded_file_local_var( make
, obj
, "EXTRAIDLFLAGS" ));
2869 output_filename( source
->filename
);
2873 output_filenames_obj_dir( make
, headers
);
2874 for (arch
= 0; arch
< archs
.count
; arch
++) output_filenames_obj_dir( make
, multiarch_targets
[arch
] );
2876 output_filename( tools_path( make
, "widl" ));
2877 output_filename( source
->filename
);
2878 output_filenames( source
->dependencies
);
2881 if (source
->importlibdeps
.count
)
2883 for (arch
= 0; arch
< archs
.count
; arch
++)
2885 if (!multiarch_targets
[arch
].count
) continue;
2886 output_filenames_obj_dir( make
, multiarch_targets
[arch
] );
2888 for (i
= 0; i
< source
->importlibdeps
.count
; i
++)
2890 struct makefile
*submake
= find_importlib_module( source
->importlibdeps
.str
[i
] );
2891 const char *module
= strmake( "%s%s", arch_pe_dirs
[arch
], submake
->module
);
2892 output_filename( obj_dir_path( submake
, module
));
2900 /*******************************************************************
2903 static void output_source_x( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2905 output( "%s.h: %s%s %s\n", obj_dir_path( make
, obj
),
2906 tools_dir_path( make
, "make_xftmpl" ), tools_ext
, source
->filename
);
2907 output( "\t%s%s%s -H -o $@ %s\n", cmd_prefix( "GEN" ),
2908 tools_dir_path( make
, "make_xftmpl" ), tools_ext
, source
->filename
);
2909 if (source
->file
->flags
& FLAG_INSTALL
)
2911 add_install_rule( make
, source
->name
, 0, source
->name
,
2912 strmake( "D$(includedir)/wine/%s", get_include_install_path( source
->name
) ));
2913 add_install_rule( make
, source
->name
, 0, strmake( "%s.h", obj
),
2914 strmake( "d$(includedir)/wine/%s.h", get_include_install_path( obj
) ));
2919 /*******************************************************************
2922 static void output_source_sfd( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2925 char *ttf_obj
= strmake( "%s.ttf", obj
);
2926 char *ttf_file
= src_dir_path( make
, ttf_obj
);
2928 if (fontforge
&& !make
->src_dir
)
2930 output( "%s: %s\n", ttf_file
, source
->filename
);
2931 output( "\t%s%s -script %s %s $@\n", cmd_prefix( "GEN" ),
2932 fontforge
, root_src_dir_path( "fonts/genttf.ff" ), source
->filename
);
2933 if (!(source
->file
->flags
& FLAG_SFD_FONTS
)) strarray_add( &make
->font_files
, ttf_obj
);
2934 strarray_add( &make
->maintainerclean_files
, ttf_obj
);
2936 if (source
->file
->flags
& FLAG_INSTALL
)
2938 add_install_rule( make
, source
->name
, 0, ttf_obj
, strmake( "D$(fontdir)/%s", ttf_obj
));
2939 output_srcdir_symlink( make
, ttf_obj
);
2942 if (source
->file
->flags
& FLAG_SFD_FONTS
)
2944 struct strarray
*array
= source
->file
->args
;
2946 for (i
= 0; i
< array
->count
; i
++)
2948 char *font
= strtok( xstrdup(array
->str
[i
]), " \t" );
2949 char *args
= strtok( NULL
, "" );
2951 strarray_add( &make
->all_targets
[0], xstrdup( font
));
2952 output( "%s: %s %s\n", obj_dir_path( make
, font
),
2953 tools_path( make
, "sfnt2fon" ), ttf_file
);
2954 output( "\t%s%s -q -o $@ %s %s\n", cmd_prefix( "GEN" ),
2955 tools_path( make
, "sfnt2fon" ), ttf_file
, args
);
2956 add_install_rule( make
, source
->name
, 0, xstrdup(font
), strmake( "d$(fontdir)/%s", font
));
2962 /*******************************************************************
2965 static void output_source_svg( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2967 static const char * const images
[] = { "bmp", "cur", "ico", NULL
};
2970 if (convert
&& rsvg
&& icotool
)
2972 for (i
= 0; images
[i
]; i
++)
2973 if (find_include_file( make
, strmake( "%s.%s", obj
, images
[i
] ))) break;
2977 output( "%s.%s: %s\n", src_dir_path( make
, obj
), images
[i
], source
->filename
);
2978 output( "\t%sCONVERT=\"%s\" ICOTOOL=\"%s\" RSVG=\"%s\" %s %s $@\n",
2979 cmd_prefix( "GEN" ), convert
, icotool
, rsvg
,
2980 root_src_dir_path( "tools/buildimage" ), source
->filename
);
2981 strarray_add( &make
->maintainerclean_files
, strmake( "%s.%s", obj
, images
[i
] ));
2987 /*******************************************************************
2990 static void output_source_nls( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2992 add_install_rule( make
, source
->name
, 0, source
->name
,
2993 strmake( "D$(nlsdir)/%s", source
->name
));
2994 output_srcdir_symlink( make
, strmake( "%s.nls", obj
));
2998 /*******************************************************************
2999 * output_source_desktop
3001 static void output_source_desktop( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
3003 add_install_rule( make
, source
->name
, 0, source
->name
,
3004 strmake( "D$(datadir)/applications/%s", source
->name
));
3008 /*******************************************************************
3011 static void output_source_po( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
3013 output( "%s.mo: %s\n", obj_dir_path( make
, obj
), source
->filename
);
3014 output( "\t%s%s -o $@ %s\n", cmd_prefix( "MSG" ), msgfmt
, source
->filename
);
3015 strarray_add( &make
->all_targets
[0], strmake( "%s.mo", obj
));
3019 /*******************************************************************
3022 static void output_source_in( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
3026 if (make
== include_makefile
) return; /* ignore generated includes */
3027 if (strendswith( obj
, ".man" ) && source
->file
->args
)
3029 struct strarray symlinks
;
3030 char *dir
, *dest
= replace_extension( obj
, ".man", "" );
3031 char *lang
= strchr( dest
, '.' );
3032 char *section
= source
->file
->args
;
3036 dir
= strmake( "$(mandir)/%s/man%s", lang
, section
);
3038 else dir
= strmake( "$(mandir)/man%s", section
);
3039 add_install_rule( make
, dest
, 0, obj
, strmake( "d%s/%s.%s", dir
, dest
, section
));
3040 symlinks
= get_expanded_file_local_var( make
, dest
, "SYMLINKS" );
3041 for (i
= 0; i
< symlinks
.count
; i
++)
3042 add_install_rule( make
, symlinks
.str
[i
], 0, strmake( "%s.%s", dest
, section
),
3043 strmake( "y%s/%s.%s", dir
, symlinks
.str
[i
], section
));
3047 strarray_add( &make
->in_files
, obj
);
3048 strarray_add( &make
->all_targets
[0], obj
);
3049 output( "%s: %s\n", obj_dir_path( make
, obj
), source
->filename
);
3050 output( "\t%s%s %s >$@ || (rm -f $@ && false)\n", cmd_prefix( "SED" ), sed_cmd
, source
->filename
);
3051 output( "%s:", obj_dir_path( make
, obj
));
3052 output_filenames( source
->dependencies
);
3054 add_install_rule( make
, obj
, 0, obj
, strmake( "d$(datadir)/wine/%s", obj
));
3058 /*******************************************************************
3059 * output_source_spec
3061 static void output_source_spec( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
3063 struct strarray imports
= get_expanded_file_local_var( make
, obj
, "IMPORTS" );
3064 struct strarray dll_flags
= empty_strarray
;
3065 struct strarray default_imports
= empty_strarray
;
3066 struct strarray all_libs
, dep_libs
;
3067 const char *dll_name
, *obj_name
, *res_name
, *output_file
, *debug_file
;
3070 if (!imports
.count
) imports
= make
->imports
;
3071 strarray_addall( &dll_flags
, make
->extradllflags
);
3072 strarray_addall( &dll_flags
, get_expanded_file_local_var( make
, obj
, "EXTRADLLFLAGS" ));
3073 if (!strarray_exists( &dll_flags
, "-nodefaultlibs" )) default_imports
= get_default_imports( make
, imports
);
3075 for (arch
= 0; arch
< archs
.count
; arch
++)
3077 if (!is_multiarch( arch
)) continue;
3078 all_libs
= dep_libs
= empty_strarray
;
3079 strarray_addall( &all_libs
, add_import_libs( make
, &dep_libs
, imports
, IMPORT_TYPE_DIRECT
, arch
) );
3080 strarray_addall( &all_libs
, add_import_libs( make
, &dep_libs
, default_imports
, IMPORT_TYPE_DEFAULT
, arch
) );
3081 if (!arch
) strarray_addall( &all_libs
, libs
);
3082 dll_name
= arch_module_name( strmake( "%s.dll", obj
), arch
);
3083 obj_name
= obj_dir_path( make
, strmake( "%s%s.o", arch_dirs
[arch
], obj
));
3084 res_name
= strmake( "%s%s.res", arch_dirs
[arch
], obj
);
3085 output_file
= obj_dir_path( make
, dll_name
);
3087 strarray_add( &make
->clean_files
, dll_name
);
3088 strarray_add( &make
->res_files
[arch
], res_name
);
3089 output( "%s:", obj_dir_path( make
, res_name
));
3090 output_filename( output_file
);
3091 output_filename( tools_path( make
, "wrc" ));
3093 output( "\t%secho \"%s.dll TESTDLL \\\"%s\\\"\" | %s -u -o $@\n", cmd_prefix( "WRC" ), obj
, output_file
,
3094 tools_path( make
, "wrc" ));
3096 output( "%s:", output_file
);
3097 output_filename( source
->filename
);
3098 output_filename( obj_name
);
3099 output_filenames( dep_libs
);
3100 output_filename( tools_path( make
, "winebuild" ));
3101 output_filename( tools_path( make
, "winegcc" ));
3103 output_winegcc_command( make
, arch
);
3104 output_filename( "-s" );
3105 output_filenames( dll_flags
);
3106 if (arch
) output_filenames( get_expanded_arch_var_array( make
, "EXTRADLLFLAGS", arch
));
3107 output_filename( "-shared" );
3108 output_filename( source
->filename
);
3109 output_filename( obj_name
);
3110 if ((debug_file
= get_debug_file( make
, dll_name
, arch
)))
3111 output_filename( strmake( "-Wl,--debug-file,%s", obj_dir_path( make
, debug_file
)));
3112 output_filenames( all_libs
);
3113 output_filename( arch_make_variable( "LDFLAGS", arch
));
3119 /*******************************************************************
3120 * output_source_one_arch
3122 static void output_source_one_arch( struct makefile
*make
, struct incl_file
*source
, const char *obj
,
3123 struct strarray defines
, struct strarray
*targets
,
3124 unsigned int arch
, int is_dll_src
)
3126 const char *obj_name
;
3130 if (source
->file
->flags
& FLAG_C_UNIX
) return;
3131 if (!is_using_msvcrt( make
) && !make
->staticlib
&& !(source
->file
->flags
& FLAG_C_IMPLIB
)) return;
3133 else if (source
->file
->flags
& FLAG_C_UNIX
)
3135 if (!*dll_ext
) return;
3137 else if (archs
.count
> 1 && is_using_msvcrt( make
) &&
3138 !(source
->file
->flags
& FLAG_C_IMPLIB
) &&
3139 (!make
->staticlib
|| make
->extlib
)) return;
3141 obj_name
= strmake( "%s%s.o", source
->arch
? "" : arch_dirs
[arch
], obj
);
3142 strarray_add( targets
, obj_name
);
3144 if (source
->file
->flags
& FLAG_C_UNIX
)
3145 strarray_add( &make
->unixobj_files
, obj_name
);
3146 else if (source
->file
->flags
& FLAG_C_IMPLIB
)
3147 strarray_add( &make
->implib_files
[arch
], obj_name
);
3148 else if (!is_dll_src
)
3149 strarray_add( &make
->object_files
[arch
], obj_name
);
3151 strarray_add( &make
->clean_files
, obj_name
);
3153 output( "%s: %s\n", obj_dir_path( make
, obj_name
), source
->filename
);
3154 output( "\t%s%s -c -o $@ %s", cmd_prefix( "CC" ), arch_make_variable( "CC", arch
), source
->filename
);
3155 output_filenames( defines
);
3156 if (!source
->use_msvcrt
) output_filenames( make
->unix_cflags
);
3157 output_filenames( make
->extlib
? extra_cflags_extlib
[arch
] : extra_cflags
[arch
] );
3160 if (make
->sharedlib
|| (source
->file
->flags
& FLAG_C_UNIX
))
3162 output_filenames( unix_dllflags
);
3164 else if (make
->module
|| make
->testdll
)
3166 output_filenames( dll_flags
);
3167 if (source
->use_msvcrt
) output_filenames( msvcrt_flags
);
3168 if (!*dll_ext
&& make
->module
&& is_crt_module( make
->module
))
3169 output_filename( "-fno-builtin" );
3174 if (make
->module
&& is_crt_module( make
->module
)) output_filename( "-fno-builtin" );
3177 output_filenames( cpp_flags
);
3178 output_filename( arch_make_variable( "CFLAGS", arch
));
3181 if (make
->testdll
&& !is_dll_src
&& strendswith( source
->name
, ".c" ) &&
3182 !(source
->file
->flags
& FLAG_GENERATED
))
3184 const char *ok_file
, *test_exe
;
3186 ok_file
= strmake( "%s%s.ok", arch_dirs
[arch
], obj
);
3187 test_exe
= replace_extension( make
->testdll
, ".dll", "_test.exe" );
3188 strarray_add( &make
->ok_files
, ok_file
);
3189 output( "%s:\n", obj_dir_path( make
, ok_file
));
3190 output( "\t%s%s $(RUNTESTFLAGS) -T . -M %s -p %s %s && touch $@\n",
3191 cmd_prefix( "TEST" ),
3192 root_src_dir_path( "tools/runtest" ), make
->testdll
,
3193 obj_dir_path( make
, arch_module_name( test_exe
, arch
)), obj
);
3198 /*******************************************************************
3199 * output_source_default
3201 static void output_source_default( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
3203 struct strarray defines
= get_source_defines( make
, source
, obj
);
3204 struct strarray targets
= empty_strarray
;
3205 int is_dll_src
= (make
->testdll
&& strendswith( source
->name
, ".c" ) &&
3206 find_src_file( make
, replace_extension( source
->name
, ".c", ".spec" )));
3209 for (arch
= 0; arch
< archs
.count
; arch
++)
3210 if (!source
->arch
|| source
->arch
== arch
)
3211 output_source_one_arch( make
, source
, obj
, defines
, &targets
, arch
, is_dll_src
);
3213 if (source
->file
->flags
& FLAG_GENERATED
)
3215 if (!make
->testdll
|| !strendswith( source
->filename
, "testlist.c" ))
3216 strarray_add( &make
->clean_files
, source
->basename
);
3220 if (make
->testdll
&& !is_dll_src
&& strendswith( source
->name
, ".c" ))
3221 strarray_add( &make
->test_files
, obj
);
3224 output_filenames_obj_dir( make
, targets
);
3226 output_filenames( source
->dependencies
);
3231 /* dispatch table to output rules for a single source file */
3235 void (*fn
)( struct makefile
*make
, struct incl_file
*source
, const char *obj
);
3236 } output_source_funcs
[] =
3238 { "y", output_source_y
},
3239 { "l", output_source_l
},
3240 { "h", output_source_h
},
3241 { "rh", output_source_h
},
3242 { "inl", output_source_h
},
3243 { "rc", output_source_rc
},
3244 { "mc", output_source_mc
},
3245 { "res", output_source_res
},
3246 { "idl", output_source_idl
},
3247 { "sfd", output_source_sfd
},
3248 { "svg", output_source_svg
},
3249 { "nls", output_source_nls
},
3250 { "desktop", output_source_desktop
},
3251 { "po", output_source_po
},
3252 { "in", output_source_in
},
3253 { "x", output_source_x
},
3254 { "spec", output_source_spec
},
3255 { NULL
, output_source_default
}
3259 /*******************************************************************
3260 * output_fake_module
3262 static void output_fake_module( struct makefile
*make
)
3264 unsigned int arch
= 0; /* fake modules are always native */
3265 const char *spec_file
= NULL
, *name
= strmake( "%s%s", arch_pe_dirs
[arch
], make
->module
);
3267 if (!make
->is_exe
) spec_file
= src_dir_path( make
, replace_extension( make
->module
, ".dll", ".spec" ));
3269 strarray_add( &make
->all_targets
[arch
], name
);
3270 add_install_rule( make
, make
->module
, arch
, name
, strmake( "d$(dlldir)/%s", name
));
3272 output( "%s:", obj_dir_path( make
, name
));
3273 if (spec_file
) output_filename( spec_file
);
3274 output_filenames_obj_dir( make
, make
->res_files
[arch
] );
3275 output_filename( tools_path( make
, "winebuild" ));
3276 output_filename( tools_path( make
, "winegcc" ));
3278 output_winegcc_command( make
, arch
);
3279 output_filename( "-Wb,--fake-module" );
3282 output_filename( "-shared" );
3283 output_filename( spec_file
);
3285 output_filenames( make
->extradllflags
);
3286 output_filenames_obj_dir( make
, make
->res_files
[arch
] );
3291 /*******************************************************************
3294 static void output_module( struct makefile
*make
, unsigned int arch
)
3296 struct strarray default_imports
= empty_strarray
;
3297 struct strarray all_libs
= empty_strarray
;
3298 struct strarray dep_libs
= empty_strarray
;
3299 struct strarray imports
= make
->imports
;
3300 const char *module_name
;
3301 const char *debug_file
;
3302 char *spec_file
= NULL
;
3305 if (!make
->is_exe
) spec_file
= src_dir_path( make
, replace_extension( make
->module
, ".dll", ".spec" ));
3307 if (!make
->data_only
)
3309 module_name
= arch_module_name( make
->module
, arch
);
3311 if (!strarray_exists( &make
->extradllflags
, "-nodefaultlibs" )) default_imports
= get_default_imports( make
, imports
);
3313 strarray_addall( &all_libs
, add_import_libs( make
, &dep_libs
, imports
, IMPORT_TYPE_DIRECT
, arch
));
3314 strarray_addall( &all_libs
, add_import_libs( make
, &dep_libs
, make
->delayimports
, IMPORT_TYPE_DELAYED
, arch
));
3315 strarray_addall( &all_libs
, add_import_libs( make
, &dep_libs
, default_imports
, IMPORT_TYPE_DEFAULT
, arch
) );
3316 if (!arch
) strarray_addall( &all_libs
, libs
);
3318 if (delay_load_flags
[arch
])
3320 for (i
= 0; i
< make
->delayimports
.count
; i
++)
3322 struct makefile
*import
= get_static_lib( make
->delayimports
.str
[i
], arch
);
3323 if (import
) strarray_add( &all_libs
, strmake( "%s%s", delay_load_flags
[arch
], import
->module
));
3327 else module_name
= strmake( "%s%s", arch_pe_dirs
[arch
], make
->module
);
3329 strarray_add( &make
->all_targets
[arch
], module_name
);
3330 if (make
->data_only
)
3331 add_install_rule( make
, make
->module
, arch
, module_name
,
3332 strmake( "d$(dlldir)/%s%s", arch_pe_dirs
[arch
], make
->module
));
3334 add_install_rule( make
, make
->module
, arch
, module_name
,
3335 strmake( "%c%s%s%s", '0' + arch
, arch_install_dirs
[arch
], make
->module
,
3336 arch
? "" : dll_ext
));
3338 output( "%s:", obj_dir_path( make
, module_name
));
3339 if (spec_file
) output_filename( spec_file
);
3340 output_filenames_obj_dir( make
, make
->object_files
[arch
] );
3341 output_filenames_obj_dir( make
, make
->res_files
[arch
] );
3342 output_filenames( dep_libs
);
3343 output_filename( tools_path( make
, "winebuild" ));
3344 output_filename( tools_path( make
, "winegcc" ));
3346 output_winegcc_command( make
, arch
);
3347 if (arch
) output_filename( "-Wl,--wine-builtin" );
3350 output_filename( "-shared" );
3351 output_filename( spec_file
);
3353 output_filenames( make
->extradllflags
);
3354 if (arch
) output_filenames( get_expanded_arch_var_array( make
, "EXTRADLLFLAGS", arch
));
3355 output_filenames_obj_dir( make
, make
->object_files
[arch
] );
3356 output_filenames_obj_dir( make
, make
->res_files
[arch
] );
3357 debug_file
= get_debug_file( make
, module_name
, arch
);
3358 if (debug_file
) output_filename( strmake( "-Wl,--debug-file,%s", obj_dir_path( make
, debug_file
)));
3359 output_filenames( all_libs
);
3360 output_filename( arch_make_variable( "LDFLAGS", arch
));
3363 if (!make
->data_only
&& !arch
&& *dll_ext
) output_fake_module( make
);
3367 /*******************************************************************
3370 static void output_import_lib( struct makefile
*make
, unsigned int arch
)
3372 char *spec_file
= src_dir_path( make
, replace_extension( make
->module
, ".dll", ".spec" ));
3373 const char *name
= strmake( "%slib%s.a", arch_dirs
[arch
], make
->importlib
);
3375 strarray_add( &make
->clean_files
, name
);
3376 if (needs_delay_lib( make
, arch
))
3378 const char *delay_name
= replace_extension( name
, ".a", ".delay.a" );
3379 strarray_add( &make
->clean_files
, delay_name
);
3380 output( "%s ", obj_dir_path( make
, delay_name
));
3382 output( "%s: %s %s", obj_dir_path( make
, name
), tools_path( make
, "winebuild" ), spec_file
);
3383 output_filenames_obj_dir( make
, make
->implib_files
[arch
] );
3385 output( "\t%s%s -w --implib -o $@", cmd_prefix( "BUILD" ), tools_path( make
, "winebuild" ) );
3386 if (!delay_load_flags
[arch
]) output_filename( "--without-dlltool" );
3387 output_filenames( target_flags
[arch
] );
3388 if (make
->is_win16
) output_filename( "-m16" );
3389 output_filename( "--export" );
3390 output_filename( spec_file
);
3391 output_filenames_obj_dir( make
, make
->implib_files
[arch
] );
3394 if (!arch
&& is_native_arch_disabled( make
)) return;
3396 add_install_rule( make
, make
->importlib
, arch
, name
,
3397 strmake( "d%slib%s.a", arch_install_dirs
[arch
], make
->importlib
));
3401 /*******************************************************************
3404 static void output_unix_lib( struct makefile
*make
)
3406 struct strarray unix_deps
= empty_strarray
;
3407 struct strarray unix_libs
= add_unix_libraries( make
, &unix_deps
);
3408 unsigned int arch
= 0; /* unix libs are always native */
3410 strarray_add( &make
->all_targets
[arch
], make
->unixlib
);
3411 add_install_rule( make
, make
->module
, arch
, make
->unixlib
,
3412 strmake( "p%s%s", arch_install_dirs
[arch
], make
->unixlib
));
3413 output( "%s:", obj_dir_path( make
, make
->unixlib
));
3414 output_filenames_obj_dir( make
, make
->unixobj_files
);
3415 output_filenames( unix_deps
);
3417 output( "\t%s$(CC) -o $@", cmd_prefix( "CCLD" ));
3418 output_filenames( get_expanded_make_var_array( make
, "UNIXLDFLAGS" ));
3419 output_filenames_obj_dir( make
, make
->unixobj_files
);
3420 output_filenames( unix_libs
);
3421 output_filename( "$(LDFLAGS)" );
3426 /*******************************************************************
3429 static void output_static_lib( struct makefile
*make
, unsigned int arch
)
3431 const char *name
= strmake( "%s%s", arch_dirs
[arch
], make
->staticlib
);
3433 strarray_add( &make
->clean_files
, name
);
3434 output( "%s: %s", obj_dir_path( make
, name
), tools_path( make
, "winebuild" ));
3435 output_filenames_obj_dir( make
, make
->object_files
[arch
] );
3436 if (!arch
) output_filenames_obj_dir( make
, make
->unixobj_files
);
3438 output( "\t%s%s -w --staticlib -o $@", cmd_prefix( "BUILD" ), tools_path( make
, "winebuild" ));
3439 output_filenames( target_flags
[arch
] );
3440 output_filenames_obj_dir( make
, make
->object_files
[arch
] );
3441 if (!arch
) output_filenames_obj_dir( make
, make
->unixobj_files
);
3444 add_install_rule( make
, make
->staticlib
, arch
, name
,
3445 strmake( "d%s%s", arch_install_dirs
[arch
], make
->staticlib
));
3449 /*******************************************************************
3452 static void output_shared_lib( struct makefile
*make
)
3456 struct strarray names
= get_shared_lib_names( make
->sharedlib
);
3457 struct strarray all_libs
= empty_strarray
;
3458 struct strarray dep_libs
= empty_strarray
;
3459 unsigned int arch
= 0; /* shared libs are always native */
3461 basename
= xstrdup( make
->sharedlib
);
3462 if ((p
= strchr( basename
, '.' ))) *p
= 0;
3464 strarray_addall( &dep_libs
, get_local_dependencies( make
, basename
, make
->in_files
));
3465 strarray_addall( &all_libs
, get_expanded_file_local_var( make
, basename
, "LDFLAGS" ));
3466 strarray_addall( &all_libs
, get_expanded_make_var_array( make
, "UNIX_LIBS" ));
3467 strarray_addall( &all_libs
, libs
);
3469 output( "%s:", obj_dir_path( make
, make
->sharedlib
));
3470 output_filenames_obj_dir( make
, make
->object_files
[arch
] );
3471 output_filenames( dep_libs
);
3473 output( "\t%s$(CC) -o $@", cmd_prefix( "CCLD" ));
3474 output_filenames_obj_dir( make
, make
->object_files
[arch
] );
3475 output_filenames( all_libs
);
3476 output_filename( "$(LDFLAGS)" );
3478 add_install_rule( make
, make
->sharedlib
, arch
, make
->sharedlib
,
3479 strmake( "p%s%s", arch_install_dirs
[arch
], make
->sharedlib
));
3480 for (i
= 1; i
< names
.count
; i
++)
3482 output( "%s: %s\n", obj_dir_path( make
, names
.str
[i
] ), obj_dir_path( make
, names
.str
[i
-1] ));
3483 output_symlink_rule( names
.str
[i
-1], obj_dir_path( make
, names
.str
[i
] ), 0 );
3484 add_install_rule( make
, names
.str
[i
], arch
, names
.str
[i
-1],
3485 strmake( "y%s%s", arch_install_dirs
[arch
], names
.str
[i
] ));
3487 strarray_addall( &make
->all_targets
[arch
], names
);
3491 /*******************************************************************
3492 * output_test_module
3494 static void output_test_module( struct makefile
*make
, unsigned int arch
)
3496 char *basemodule
= replace_extension( make
->testdll
, ".dll", "" );
3497 char *stripped
= arch_module_name( strmake( "%s_test-stripped.exe", basemodule
), arch
);
3498 char *testmodule
= arch_module_name( strmake( "%s_test.exe", basemodule
), arch
);
3499 struct strarray default_imports
= get_default_imports( make
, make
->imports
);
3500 struct strarray dep_libs
= empty_strarray
;
3501 struct strarray all_libs
= empty_strarray
;
3502 struct makefile
*parent
= get_parent_makefile( make
);
3503 const char *debug_file
;
3505 strarray_addall( &all_libs
, add_import_libs( make
, &dep_libs
, make
->imports
, IMPORT_TYPE_DIRECT
, arch
) );
3506 strarray_addall( &all_libs
, add_import_libs( make
, &dep_libs
, default_imports
, IMPORT_TYPE_DEFAULT
, arch
) );
3508 strarray_add( &make
->all_targets
[arch
], testmodule
);
3509 strarray_add( &make
->clean_files
, stripped
);
3510 output( "%s:\n", obj_dir_path( make
, testmodule
));
3511 output_winegcc_command( make
, arch
);
3512 output_filenames( make
->extradllflags
);
3513 output_filenames_obj_dir( make
, make
->object_files
[arch
] );
3514 output_filenames_obj_dir( make
, make
->res_files
[arch
] );
3515 if ((debug_file
= get_debug_file( make
, testmodule
, arch
)))
3516 output_filename( strmake( "-Wl,--debug-file,%s", obj_dir_path( make
, debug_file
)));
3517 output_filenames( all_libs
);
3518 output_filename( arch_make_variable( "LDFLAGS", arch
));
3520 output( "%s:\n", obj_dir_path( make
, stripped
));
3521 output_winegcc_command( make
, arch
);
3522 output_filename( "-s" );
3523 output_filename( strmake( "-Wb,-F,%s_test.exe", basemodule
));
3524 output_filenames( make
->extradllflags
);
3525 output_filenames_obj_dir( make
, make
->object_files
[arch
] );
3526 output_filenames_obj_dir( make
, make
->res_files
[arch
] );
3527 output_filenames( all_libs
);
3528 output_filename( arch_make_variable( "LDFLAGS", arch
));
3530 output( "%s %s:", obj_dir_path( make
, testmodule
), obj_dir_path( make
, stripped
));
3531 output_filenames_obj_dir( make
, make
->object_files
[arch
] );
3532 output_filenames_obj_dir( make
, make
->res_files
[arch
] );
3533 output_filenames( dep_libs
);
3534 output_filename( tools_path( make
, "winebuild" ));
3535 output_filename( tools_path( make
, "winegcc" ));
3538 output( "programs/winetest/%s%s_test.res: %s\n", arch_dirs
[arch
], basemodule
,
3539 obj_dir_path( make
, stripped
));
3540 output( "\t%secho \"%s_test.exe TESTRES \\\"%s\\\"\" | %s -u -o $@\n", cmd_prefix( "WRC" ),
3541 basemodule
, obj_dir_path( make
, stripped
), tools_path( make
, "wrc" ));
3543 output_filenames_obj_dir( make
, make
->ok_files
);
3544 output( ": %s", obj_dir_path( make
, testmodule
));
3547 char *parent_module
= arch_module_name( make
->testdll
, arch
);
3548 output_filename( obj_dir_path( parent
, parent_module
));
3549 if (parent
->unixlib
) output_filename( obj_dir_path( parent
, parent
->unixlib
));
3552 output( "%s %s:", obj_dir_path( make
, "check" ), obj_dir_path( make
, "test" ));
3553 if (!make
->disabled
[arch
] && parent
&& !parent
->disabled
[arch
])
3554 output_filenames_obj_dir( make
, make
->ok_files
);
3556 strarray_add_uniq( &make
->phony_targets
, obj_dir_path( make
, "check" ));
3557 strarray_add_uniq( &make
->phony_targets
, obj_dir_path( make
, "test" ));
3558 output( "%s::\n", obj_dir_path( make
, "testclean" ));
3559 output( "\trm -f" );
3560 output_filenames_obj_dir( make
, make
->ok_files
);
3562 strarray_addall( &make
->clean_files
, make
->ok_files
);
3563 strarray_add_uniq( &make
->phony_targets
, obj_dir_path( make
, "testclean" ));
3567 /*******************************************************************
3570 static void output_programs( struct makefile
*make
)
3573 unsigned int arch
= 0; /* programs are always native */
3575 for (i
= 0; i
< make
->programs
.count
; i
++)
3577 char *program_installed
= NULL
;
3578 char *program
= strmake( "%s%s", make
->programs
.str
[i
], exe_ext
);
3579 struct strarray deps
= get_local_dependencies( make
, make
->programs
.str
[i
], make
->in_files
);
3580 struct strarray all_libs
= get_expanded_file_local_var( make
, make
->programs
.str
[i
], "LDFLAGS" );
3581 struct strarray objs
= get_expanded_file_local_var( make
, make
->programs
.str
[i
], "OBJS" );
3582 struct strarray symlinks
= get_expanded_file_local_var( make
, make
->programs
.str
[i
], "SYMLINKS" );
3584 if (!objs
.count
) objs
= make
->object_files
[arch
];
3585 if (!strarray_exists( &all_libs
, "-nodefaultlibs" ))
3587 strarray_addall( &all_libs
, get_expanded_make_var_array( make
, "UNIX_LIBS" ));
3588 strarray_addall( &all_libs
, libs
);
3591 output( "%s:", obj_dir_path( make
, program
) );
3592 output_filenames_obj_dir( make
, objs
);
3593 output_filenames( deps
);
3595 output( "\t%s$(CC) -o $@", cmd_prefix( "CCLD" ));
3596 output_filenames_obj_dir( make
, objs
);
3597 output_filenames( all_libs
);
3598 output_filename( "$(LDFLAGS)" );
3600 strarray_add( &make
->all_targets
[arch
], program
);
3602 for (j
= 0; j
< symlinks
.count
; j
++)
3604 output( "%s: %s\n", obj_dir_path( make
, symlinks
.str
[j
] ), obj_dir_path( make
, program
));
3605 output_symlink_rule( program
, obj_dir_path( make
, symlinks
.str
[j
] ), 0 );
3607 strarray_addall( &make
->all_targets
[arch
], symlinks
);
3609 add_install_rule( make
, program
, arch
, program_installed
? program_installed
: program
,
3610 strmake( "p$(bindir)/%s", program
));
3611 for (j
= 0; j
< symlinks
.count
; j
++)
3612 add_install_rule( make
, symlinks
.str
[j
], arch
, program
,
3613 strmake( "y$(bindir)/%s%s", symlinks
.str
[j
], exe_ext
));
3618 /*******************************************************************
3621 static void output_subdirs( struct makefile
*make
)
3623 struct strarray all_targets
= empty_strarray
;
3624 struct strarray makefile_deps
= empty_strarray
;
3625 struct strarray clean_files
= empty_strarray
;
3626 struct strarray testclean_files
= empty_strarray
;
3627 struct strarray distclean_files
= empty_strarray
;
3628 struct strarray distclean_dirs
= empty_strarray
;
3629 struct strarray dependencies
= empty_strarray
;
3630 struct strarray install_deps
[NB_INSTALL_RULES
] = { empty_strarray
};
3631 struct strarray tooldeps_deps
= empty_strarray
;
3632 struct strarray buildtest_deps
= empty_strarray
;
3633 unsigned int i
, j
, arch
;
3635 strarray_addall( &clean_files
, make
->clean_files
);
3636 strarray_addall( &distclean_files
, make
->distclean_files
);
3637 for (arch
= 0; arch
< archs
.count
; arch
++) strarray_addall( &all_targets
, make
->all_targets
[arch
] );
3638 for (i
= 0; i
< subdirs
.count
; i
++)
3640 struct strarray subclean
= empty_strarray
;
3641 strarray_addall( &subclean
, get_removable_dirs( submakes
[i
]->clean_files
));
3642 strarray_addall( &subclean
, get_removable_dirs( submakes
[i
]->distclean_files
));
3643 strarray_add( &makefile_deps
, src_dir_path( submakes
[i
], "Makefile.in" ));
3644 strarray_addall_uniq( &make
->phony_targets
, submakes
[i
]->phony_targets
);
3645 strarray_addall_uniq( &make
->uninstall_files
, submakes
[i
]->uninstall_files
);
3646 strarray_addall_uniq( &dependencies
, submakes
[i
]->dependencies
);
3647 strarray_addall_path( &clean_files
, submakes
[i
]->obj_dir
, submakes
[i
]->clean_files
);
3648 strarray_addall_path( &distclean_files
, submakes
[i
]->obj_dir
, submakes
[i
]->distclean_files
);
3649 strarray_addall_path( &distclean_dirs
, submakes
[i
]->obj_dir
, subclean
);
3650 strarray_addall_path( &make
->maintainerclean_files
, submakes
[i
]->obj_dir
, submakes
[i
]->maintainerclean_files
);
3651 strarray_addall_path( &testclean_files
, submakes
[i
]->obj_dir
, submakes
[i
]->ok_files
);
3652 strarray_addall_path( &make
->pot_files
, submakes
[i
]->obj_dir
, submakes
[i
]->pot_files
);
3654 for (arch
= 0; arch
< archs
.count
; arch
++)
3656 if (submakes
[i
]->disabled
[arch
]) continue;
3657 strarray_addall_path( &all_targets
, submakes
[i
]->obj_dir
, submakes
[i
]->all_targets
[arch
] );
3659 if (submakes
[i
]->disabled
[0]) continue;
3661 strarray_addall_path( &all_targets
, submakes
[i
]->obj_dir
, submakes
[i
]->font_files
);
3662 if (!strcmp( submakes
[i
]->obj_dir
, "tools" ) || !strncmp( submakes
[i
]->obj_dir
, "tools/", 6 ))
3663 strarray_add( &tooldeps_deps
, obj_dir_path( submakes
[i
], "all" ));
3664 if (submakes
[i
]->testdll
)
3665 strarray_add( &buildtest_deps
, obj_dir_path( submakes
[i
], "all" ));
3666 for (j
= 0; j
< NB_INSTALL_RULES
; j
++)
3667 if (submakes
[i
]->install_rules
[j
].count
)
3668 strarray_add( &install_deps
[j
], obj_dir_path( submakes
[i
], install_targets
[j
] ));
3670 strarray_addall( &dependencies
, makefile_deps
);
3672 output_filenames( all_targets
);
3674 output( "Makefile:" );
3675 output_filenames( makefile_deps
);
3677 output_filenames( dependencies
);
3679 for (j
= 0; j
< NB_INSTALL_RULES
; j
++)
3681 if (!install_deps
[j
].count
) continue;
3682 if (strcmp( install_targets
[j
], "install-test" ))
3684 output( "install " );
3685 strarray_add_uniq( &make
->phony_targets
, "install" );
3687 output( "%s::", install_targets
[j
] );
3688 output_filenames( install_deps
[j
] );
3690 strarray_add_uniq( &make
->phony_targets
, install_targets
[j
] );
3692 output_uninstall_rules( make
);
3693 if (buildtest_deps
.count
)
3695 output( "buildtests:" );
3696 output_filenames( buildtest_deps
);
3698 strarray_add_uniq( &make
->phony_targets
, "buildtests" );
3700 output( "check test:" );
3701 output_filenames( testclean_files
);
3703 strarray_add_uniq( &make
->phony_targets
, "check" );
3704 strarray_add_uniq( &make
->phony_targets
, "test" );
3706 if (get_expanded_make_variable( make
, "GETTEXTPO_LIBS" )) output_po_files( make
);
3708 output( "clean::\n");
3709 output_rm_filenames( clean_files
, "rm -f" );
3710 output( "testclean::\n");
3711 output_rm_filenames( testclean_files
, "rm -f" );
3712 output( "distclean::\n");
3713 output_rm_filenames( distclean_files
, "rm -f" );
3714 output_rm_filenames( distclean_dirs
, "-rmdir 2>/dev/null" );
3715 output( "maintainer-clean::\n");
3716 output_rm_filenames( make
->maintainerclean_files
, "rm -f" );
3717 strarray_add_uniq( &make
->phony_targets
, "distclean" );
3718 strarray_add_uniq( &make
->phony_targets
, "testclean" );
3719 strarray_add_uniq( &make
->phony_targets
, "maintainer-clean" );
3721 if (tooldeps_deps
.count
)
3723 output( "__tooldeps__:" );
3724 output_filenames( tooldeps_deps
);
3726 strarray_add_uniq( &make
->phony_targets
, "__tooldeps__" );
3729 if (make
->phony_targets
.count
)
3731 output( ".PHONY:" );
3732 output_filenames( make
->phony_targets
);
3738 /*******************************************************************
3741 static void output_sources( struct makefile
*make
)
3743 struct strarray all_targets
= empty_strarray
;
3744 struct incl_file
*source
;
3745 unsigned int i
, j
, arch
;
3747 strarray_add_uniq( &make
->phony_targets
, "all" );
3749 LIST_FOR_EACH_ENTRY( source
, &make
->sources
, struct incl_file
, entry
)
3751 char *obj
= xstrdup( source
->name
);
3752 char *ext
= get_extension( obj
);
3754 if (!ext
) fatal_error( "unsupported file type %s\n", source
->name
);
3757 for (j
= 0; output_source_funcs
[j
].ext
; j
++)
3758 if (!strcmp( ext
, output_source_funcs
[j
].ext
)) break;
3760 output_source_funcs
[j
].fn( make
, source
, obj
);
3761 strarray_addall_uniq( &make
->dependencies
, source
->dependencies
);
3764 /* special case for winetest: add resource files from other test dirs */
3765 if (make
->obj_dir
&& !strcmp( make
->obj_dir
, "programs/winetest" ))
3767 for (arch
= 0; arch
< archs
.count
; arch
++)
3769 if (!is_multiarch( arch
)) continue;
3770 for (i
= 0; i
< subdirs
.count
; i
++)
3772 if (!submakes
[i
]->testdll
) continue;
3773 if (submakes
[i
]->disabled
[arch
]) continue;
3774 if (enable_tests
.count
&& !strarray_exists( &enable_tests
, submakes
[i
]->testdll
)) continue;
3775 strarray_add( &make
->res_files
[arch
],
3776 strmake( "%s%s", arch_dirs
[arch
],
3777 replace_extension( submakes
[i
]->testdll
, ".dll", "_test.res" )));
3782 if (make
->dlldata_files
.count
)
3784 output( "%s: %s %s\n", obj_dir_path( make
, "dlldata.c" ),
3785 tools_path( make
, "widl" ), src_dir_path( make
, "Makefile.in" ));
3786 output( "\t%s%s --dlldata-only -o $@", cmd_prefix( "WIDL" ), tools_path( make
, "widl" ));
3787 output_filenames( make
->dlldata_files
);
3791 if (make
->staticlib
)
3793 for (arch
= 0; arch
< archs
.count
; arch
++)
3794 if (is_multiarch( arch
) || !make
->extlib
) output_static_lib( make
, arch
);
3796 else if (make
->module
)
3798 for (arch
= 0; arch
< archs
.count
; arch
++) if (is_multiarch( arch
)) output_module( make
, arch
);
3799 if (make
->unixlib
) output_unix_lib( make
);
3800 if (make
->importlib
) for (arch
= 0; arch
< archs
.count
; arch
++) output_import_lib( make
, arch
);
3801 if (make
->is_exe
&& !make
->is_win16
&& *dll_ext
&& strendswith( make
->module
, ".exe" ))
3803 char *binary
= replace_extension( make
->module
, ".exe", "" );
3804 add_install_rule( make
, binary
, 0, "wineapploader", strmake( "t$(bindir)/%s", binary
));
3807 else if (make
->testdll
)
3809 for (arch
= 0; arch
< archs
.count
; arch
++)
3810 if (is_multiarch( arch
)) output_test_module( make
, arch
);
3812 else if (make
->sharedlib
) output_shared_lib( make
);
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 if (make
->obj_dir
) create_dir( make
->obj_dir
);
4046 output_file_name
= obj_dir_path( make
, "Makefile" );
4047 output_file
= create_temp_file( output_file_name
);
4049 output( "# Auto-generated stub makefile; all rules forward to the top-level makefile\n\n" );
4051 if (make_var
) output( "MAKE = %s\n\n", make_var
);
4054 for (arch
= 0; arch
< archs
.count
; arch
++)
4055 if (make
->all_targets
[arch
].count
) strarray_add_uniq( &targets
, "all" );
4057 for (i
= 0; i
< NB_INSTALL_RULES
; i
++)
4059 if (!make
->install_rules
[i
].count
) continue;
4060 strarray_add_uniq( &targets
, "install" );
4061 strarray_add( &targets
, install_targets
[i
] );
4063 if (make
->clean_files
.count
) strarray_add( &targets
, "clean" );
4064 if (make
->test_files
.count
)
4066 strarray_add( &targets
, "check" );
4067 strarray_add( &targets
, "test" );
4068 strarray_add( &targets
, "testclean" );
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
->sharedlib
= get_expanded_make_variable( make
, "SHAREDLIB" );
4215 make
->staticlib
= get_expanded_make_variable( make
, "STATICLIB" );
4216 make
->importlib
= get_expanded_make_variable( make
, "IMPORTLIB" );
4217 make
->extlib
= get_expanded_make_variable( make
, "EXTLIB" );
4218 if (*dll_ext
) make
->unixlib
= get_expanded_make_variable( make
, "UNIXLIB" );
4220 make
->programs
= get_expanded_make_var_array( make
, "PROGRAMS" );
4221 make
->scripts
= get_expanded_make_var_array( make
, "SCRIPTS" );
4222 make
->imports
= get_expanded_make_var_array( make
, "IMPORTS" );
4223 make
->delayimports
= get_expanded_make_var_array( make
, "DELAYIMPORTS" );
4224 make
->extradllflags
= get_expanded_make_var_array( make
, "EXTRADLLFLAGS" );
4225 make
->extra_targets
= get_expanded_make_var_array( make
, "EXTRA_TARGETS" );
4226 for (i
= 0; i
< NB_INSTALL_RULES
; i
++)
4227 make
->install
[i
] = get_expanded_make_var_array( make
, install_variables
[i
] );
4229 if (make
->extlib
) make
->staticlib
= make
->extlib
;
4230 if (make
->staticlib
) make
->module
= make
->staticlib
;
4234 make
->disabled
[0] = strarray_exists( &disabled_dirs
[0], make
->obj_dir
);
4235 for (arch
= 1; arch
< archs
.count
; arch
++)
4236 make
->disabled
[arch
] = make
->disabled
[0] || strarray_exists( &disabled_dirs
[arch
], make
->obj_dir
);
4238 make
->is_win16
= strarray_exists( &make
->extradllflags
, "-m16" );
4239 make
->data_only
= strarray_exists( &make
->extradllflags
, "-Wb,--data-only" );
4240 make
->is_exe
= strarray_exists( &make
->extradllflags
, "-mconsole" ) ||
4241 strarray_exists( &make
->extradllflags
, "-mwindows" );
4245 /* add default install rules if nothing was specified */
4246 for (i
= 0; i
< NB_INSTALL_RULES
; i
++) if (make
->install
[i
].count
) break;
4247 if (i
== NB_INSTALL_RULES
)
4249 if (make
->importlib
) strarray_add( &make
->install
[INSTALL_DEV
], make
->importlib
);
4250 if (make
->staticlib
) strarray_add( &make
->install
[INSTALL_DEV
], make
->staticlib
);
4251 else strarray_add( &make
->install
[INSTALL_LIB
], make
->module
);
4255 make
->include_paths
= empty_strarray
;
4256 make
->include_args
= empty_strarray
;
4257 make
->define_args
= empty_strarray
;
4258 make
->unix_cflags
= empty_strarray
;
4259 if (!make
->extlib
) strarray_add( &make
->define_args
, "-D__WINESRC__" );
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 signal( SIGTERM
, exit_on_signal
);
4399 signal( SIGINT
, exit_on_signal
);
4401 signal( SIGHUP
, exit_on_signal
);
4404 for (i
= 0; i
< HASH_SIZE
; i
++) list_init( &files
[i
] );
4405 for (i
= 0; i
< HASH_SIZE
; i
++) list_init( &global_includes
[i
] );
4407 top_makefile
= parse_makefile( NULL
);
4409 target_flags
[0] = get_expanded_make_var_array( top_makefile
, "TARGETFLAGS" );
4410 msvcrt_flags
= get_expanded_make_var_array( top_makefile
, "MSVCRTFLAGS" );
4411 dll_flags
= get_expanded_make_var_array( top_makefile
, "DLLFLAGS" );
4412 unix_dllflags
= get_expanded_make_var_array( top_makefile
, "UNIXDLLFLAGS" );
4413 cpp_flags
= get_expanded_make_var_array( top_makefile
, "CPPFLAGS" );
4414 lddll_flags
= get_expanded_make_var_array( top_makefile
, "LDDLLFLAGS" );
4415 libs
= get_expanded_make_var_array( top_makefile
, "LIBS" );
4416 enable_tests
= get_expanded_make_var_array( top_makefile
, "ENABLE_TESTS" );
4417 for (i
= 0; i
< NB_INSTALL_RULES
; i
++)
4418 top_install
[i
] = get_expanded_make_var_array( top_makefile
, strmake( "TOP_%s", install_variables
[i
] ));
4420 root_src_dir
= get_expanded_make_variable( top_makefile
, "srcdir" );
4421 tools_dir
= get_expanded_make_variable( top_makefile
, "toolsdir" );
4422 tools_ext
= get_expanded_make_variable( top_makefile
, "toolsext" );
4423 exe_ext
= get_expanded_make_variable( top_makefile
, "EXEEXT" );
4424 dll_ext
= (exe_ext
&& !strcmp( exe_ext
, ".exe" )) ? "" : ".so";
4425 fontforge
= get_expanded_make_variable( top_makefile
, "FONTFORGE" );
4426 convert
= get_expanded_make_variable( top_makefile
, "CONVERT" );
4427 flex
= get_expanded_make_variable( top_makefile
, "FLEX" );
4428 bison
= get_expanded_make_variable( top_makefile
, "BISON" );
4429 ar
= get_expanded_make_variable( top_makefile
, "AR" );
4430 ranlib
= get_expanded_make_variable( top_makefile
, "RANLIB" );
4431 rsvg
= get_expanded_make_variable( top_makefile
, "RSVG" );
4432 icotool
= get_expanded_make_variable( top_makefile
, "ICOTOOL" );
4433 msgfmt
= get_expanded_make_variable( top_makefile
, "MSGFMT" );
4434 sed_cmd
= get_expanded_make_variable( top_makefile
, "SED_CMD" );
4435 ln_s
= get_expanded_make_variable( top_makefile
, "LN_S" );
4437 if (root_src_dir
&& !strcmp( root_src_dir
, "." )) root_src_dir
= NULL
;
4438 if (tools_dir
&& !strcmp( tools_dir
, "." )) tools_dir
= NULL
;
4439 if (!exe_ext
) exe_ext
= "";
4440 if (!tools_ext
) tools_ext
= "";
4442 strarray_add( &archs
, get_expanded_make_variable( top_makefile
, "HOST_ARCH" ));
4443 strarray_addall( &archs
, get_expanded_make_var_array( top_makefile
, "PE_ARCHS" ));
4446 arch_pe_dirs
[0] = strmake( "%s-windows/", archs
.str
[0] );
4447 arch_install_dirs
[0] = *dll_ext
? strmake( "$(dlldir)/%s-unix/", archs
.str
[0] ) : "$(dlldir)/";
4448 strip_progs
[0] = "\"$(STRIP)\"";
4450 for (arch
= 1; arch
< archs
.count
; arch
++)
4452 target
= get_expanded_arch_var( top_makefile
, "TARGET", arch
);
4453 strarray_add( &target_flags
[arch
], "-b" );
4454 strarray_add( &target_flags
[arch
], target
);
4455 arch_dirs
[arch
] = strmake( "%s-windows/", archs
.str
[arch
] );
4456 arch_pe_dirs
[arch
] = arch_dirs
[arch
];
4457 arch_install_dirs
[arch
] = strmake( "$(dlldir)/%s", arch_dirs
[arch
] );
4458 strip_progs
[arch
] = strmake( "%s-strip", target
);
4461 for (arch
= 0; arch
< archs
.count
; arch
++)
4463 extra_cflags
[arch
] = get_expanded_arch_var_array( top_makefile
, "EXTRACFLAGS", arch
);
4464 extra_cflags_extlib
[arch
] = remove_warning_flags( extra_cflags
[arch
] );
4465 disabled_dirs
[arch
] = get_expanded_arch_var_array( top_makefile
, "DISABLED_SUBDIRS", arch
);
4466 if (!is_multiarch( arch
)) continue;
4467 delay_load_flags
[arch
] = get_expanded_arch_var( top_makefile
, "DELAYLOADFLAG", arch
);
4468 debug_flags
[arch
] = get_expanded_arch_var( top_makefile
, "DEBUG", arch
);
4473 delay_load_flags
[0] = "-Wl,-delayload,";
4474 debug_flags
[0] = NULL
;
4477 top_makefile
->src_dir
= root_src_dir
;
4478 subdirs
= get_expanded_make_var_array( top_makefile
, "SUBDIRS" );
4479 submakes
= xmalloc( subdirs
.count
* sizeof(*submakes
) );
4481 for (i
= 0; i
< subdirs
.count
; i
++) submakes
[i
] = parse_makefile( subdirs
.str
[i
] );
4483 load_sources( top_makefile
);
4484 load_sources( include_makefile
);
4485 for (i
= 0; i
< subdirs
.count
; i
++)
4486 if (submakes
[i
] != include_makefile
) load_sources( submakes
[i
] );
4488 output_dependencies( top_makefile
);
4489 for (i
= 0; i
< subdirs
.count
; i
++) output_dependencies( submakes
[i
] );