2 * Generate include file dependencies
4 * Copyright 1996, 2013, 2020 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
31 #include <sys/types.h>
35 #include "wine/list.h"
39 INCL_NORMAL
, /* #include "foo.h" */
40 INCL_SYSTEM
, /* #include <foo.h> */
41 INCL_IMPORT
, /* idl import "foo.idl" */
42 INCL_IMPORTLIB
, /* idl importlib "foo.tlb" */
43 INCL_CPP_QUOTE
, /* idl cpp_quote("#include \"foo.h\"") */
44 INCL_CPP_QUOTE_SYSTEM
/* idl cpp_quote("#include <foo.h>") */
49 int line
; /* source line where this header is included */
50 enum incl_type type
; /* type of include */
51 char *name
; /* header name */
57 char *name
; /* full file name relative to cwd */
58 void *args
; /* custom arguments for makefile rule */
59 unsigned int flags
; /* flags (see below) */
60 unsigned int deps_count
; /* files in use */
61 unsigned int deps_size
; /* total allocated size */
62 struct dependency
*deps
; /* all header dependencies */
68 struct list hash_entry
;
72 char *basename
; /* base target name for generated files */
73 char *sourcename
; /* source file name for generated headers */
74 struct incl_file
*included_by
; /* file that included this one */
75 int included_line
; /* line where this file was included */
76 enum incl_type type
; /* type of include */
77 unsigned int arch
; /* architecture for multi-arch files, otherwise 0 */
78 unsigned int use_msvcrt
:1; /* put msvcrt headers in the search path? */
79 unsigned int is_external
:1; /* file from external library? */
80 struct incl_file
*owner
;
81 unsigned int files_count
; /* files in use */
82 unsigned int files_size
; /* total allocated size */
83 struct incl_file
**files
;
84 struct strarray dependencies
; /* file dependencies */
85 struct strarray importlibdeps
; /* importlib dependencies */
88 #define FLAG_GENERATED 0x000001 /* generated file */
89 #define FLAG_INSTALL 0x000002 /* file to install */
90 #define FLAG_TESTDLL 0x000004 /* file is part of a TESTDLL resource */
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 */
104 #define FLAG_ARM64EC_X64 0x200000 /* use x86_64 object on ARM64EC */
112 { FLAG_IDL_TYPELIB
, "_l.res" },
113 { FLAG_IDL_REGTYPELIB
, "_t.res" },
114 { FLAG_IDL_CLIENT
, "_c.c" },
115 { FLAG_IDL_IDENT
, "_i.c" },
116 { FLAG_IDL_PROXY
, "_p.c" },
117 { FLAG_IDL_SERVER
, "_s.c" },
118 { FLAG_IDL_REGISTER
, "_r.res" },
121 #define HASH_SIZE 197
123 static struct list files
[HASH_SIZE
];
124 static struct list global_includes
[HASH_SIZE
];
126 enum install_rules
{ INSTALL_LIB
, INSTALL_DEV
, INSTALL_TEST
, NB_INSTALL_RULES
};
127 static const char *install_targets
[NB_INSTALL_RULES
] = { "install-lib", "install-dev", "install-test" };
128 static const char *install_variables
[NB_INSTALL_RULES
] = { "INSTALL_LIB", "INSTALL_DEV", "INSTALL_TEST" };
132 /* variables common to all makefiles */
133 static struct strarray archs
;
134 static struct strarray linguas
;
135 static struct strarray dll_flags
;
136 static struct strarray unix_dllflags
;
137 static struct strarray msvcrt_flags
;
138 static struct strarray cpp_flags
;
139 static struct strarray lddll_flags
;
140 static struct strarray libs
;
141 static struct strarray enable_tests
;
142 static struct strarray cmdline_vars
;
143 static struct strarray subdirs
;
144 static struct strarray delay_import_libs
;
145 static struct strarray top_install
[NB_INSTALL_RULES
];
146 static const char *root_src_dir
;
147 static const char *tools_dir
;
148 static const char *tools_ext
;
149 static const char *exe_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 static const char *wayland_scanner
;
162 static int so_dll_supported
;
163 static int unix_lib_supported
;
164 /* per-architecture global variables */
165 static const char *dll_ext
[MAX_ARCHS
];
166 static const char *arch_dirs
[MAX_ARCHS
];
167 static const char *arch_pe_dirs
[MAX_ARCHS
];
168 static const char *arch_install_dirs
[MAX_ARCHS
];
169 static const char *strip_progs
[MAX_ARCHS
];
170 static const char *debug_flags
[MAX_ARCHS
];
171 static const char *delay_load_flags
[MAX_ARCHS
];
172 static struct strarray target_flags
[MAX_ARCHS
];
173 static struct strarray extra_cflags
[MAX_ARCHS
];
174 static struct strarray extra_cflags_extlib
[MAX_ARCHS
];
175 static struct strarray disabled_dirs
[MAX_ARCHS
];
176 static unsigned int native_archs
[MAX_ARCHS
];
177 static unsigned int hybrid_archs
[MAX_ARCHS
];
178 static struct strarray hybrid_target_flags
[MAX_ARCHS
];
182 /* values determined from input makefile */
183 struct strarray vars
;
184 struct strarray include_paths
;
185 struct strarray include_args
;
186 struct strarray define_args
;
187 struct strarray unix_cflags
;
188 struct strarray programs
;
189 struct strarray scripts
;
190 struct strarray imports
;
191 struct strarray delayimports
;
192 struct strarray extradllflags
;
193 struct strarray install
[NB_INSTALL_RULES
];
194 struct strarray extra_targets
;
195 struct strarray extra_imports
;
197 struct list includes
;
200 const char *parent_dir
;
204 const char *staticlib
;
205 const char *importlib
;
210 int disabled
[MAX_ARCHS
];
212 /* values generated at output time */
213 struct strarray in_files
;
214 struct strarray pot_files
;
215 struct strarray test_files
;
216 struct strarray clean_files
;
217 struct strarray distclean_files
;
218 struct strarray maintainerclean_files
;
219 struct strarray uninstall_files
;
220 struct strarray unixobj_files
;
221 struct strarray font_files
;
222 struct strarray debug_files
;
223 struct strarray dlldata_files
;
224 struct strarray phony_targets
;
225 struct strarray dependencies
;
226 struct strarray object_files
[MAX_ARCHS
];
227 struct strarray implib_files
[MAX_ARCHS
];
228 struct strarray ok_files
[MAX_ARCHS
];
229 struct strarray res_files
[MAX_ARCHS
];
230 struct strarray all_targets
[MAX_ARCHS
];
231 struct strarray install_rules
[NB_INSTALL_RULES
];
234 static struct makefile
*top_makefile
;
235 static struct makefile
*include_makefile
;
236 static struct makefile
**submakes
;
238 static const char separator
[] = "### Dependencies";
239 static const char *output_makefile_name
= "Makefile";
240 static const char *input_file_name
;
241 static const char *output_file_name
;
242 static const char *temp_file_name
;
243 static int relative_dir_mode
;
244 static int silent_rules
;
245 static int input_line
;
246 static int output_column
;
247 static FILE *output_file
;
249 static const char Usage
[] =
250 "Usage: makedep [options] [directories]\n"
252 " -R from to Compute the relative path between two directories\n"
253 " -S Generate Automake-style silent rules\n"
254 " -fxxx Store output in file 'xxx' (default: Makefile)\n";
257 static void fatal_error( const char *msg
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
258 static void fatal_perror( const char *msg
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
259 static void output( const char *format
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
260 static char *strmake( const char* fmt
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
262 /*******************************************************************
265 static void fatal_error( const char *msg
, ... )
268 va_start( valist
, msg
);
271 fprintf( stderr
, "%s:", input_file_name
);
272 if (input_line
) fprintf( stderr
, "%d:", input_line
);
273 fprintf( stderr
, " error: " );
275 else fprintf( stderr
, "makedep: error: " );
276 vfprintf( stderr
, msg
, valist
);
282 /*******************************************************************
285 static void fatal_perror( const char *msg
, ... )
288 va_start( valist
, msg
);
291 fprintf( stderr
, "%s:", input_file_name
);
292 if (input_line
) fprintf( stderr
, "%d:", input_line
);
293 fprintf( stderr
, " error: " );
295 else fprintf( stderr
, "makedep: error: " );
296 vfprintf( stderr
, msg
, valist
);
303 /*******************************************************************
306 static void cleanup_files(void)
308 if (temp_file_name
) unlink( temp_file_name
);
309 if (output_file_name
) unlink( output_file_name
);
313 /*******************************************************************
316 static void exit_on_signal( int sig
)
318 exit( 1 ); /* this will call the atexit functions */
322 /*******************************************************************
325 static void output( const char *format
, ... )
330 va_start( valist
, format
);
331 ret
= vfprintf( output_file
, format
, valist
);
333 if (ret
< 0) fatal_perror( "output" );
334 if (format
[0] && format
[strlen(format
) - 1] == '\n') output_column
= 0;
335 else output_column
+= ret
;
339 /*******************************************************************
342 * Find a value in a name/value pair string array.
344 static const char *strarray_get_value( const struct strarray
*array
, const char *name
)
346 int pos
, res
, min
= 0, max
= array
->count
/ 2 - 1;
350 pos
= (min
+ max
) / 2;
351 if (!(res
= strcmp( array
->str
[pos
* 2], name
))) return array
->str
[pos
* 2 + 1];
352 if (res
< 0) min
= pos
+ 1;
359 /*******************************************************************
362 * Define a value in a name/value pair string array.
364 static void strarray_set_value( struct strarray
*array
, const char *name
, const char *value
)
366 int i
, pos
, res
, min
= 0, max
= array
->count
/ 2 - 1;
370 pos
= (min
+ max
) / 2;
371 if (!(res
= strcmp( array
->str
[pos
* 2], name
)))
373 /* redefining a variable replaces the previous value */
374 array
->str
[pos
* 2 + 1] = value
;
377 if (res
< 0) min
= pos
+ 1;
380 strarray_add( array
, NULL
);
381 strarray_add( array
, NULL
);
382 for (i
= array
->count
- 1; i
> min
* 2 + 1; i
--) array
->str
[i
] = array
->str
[i
- 2];
383 array
->str
[min
* 2] = name
;
384 array
->str
[min
* 2 + 1] = value
;
388 /*******************************************************************
391 static void output_filename( const char *name
)
393 if (output_column
+ strlen(name
) + 1 > 100)
398 else if (output_column
) output( " " );
399 output( "%s", name
);
403 /*******************************************************************
406 static void output_filenames( struct strarray array
)
410 for (i
= 0; i
< array
.count
; i
++) output_filename( array
.str
[i
] );
414 /*******************************************************************
415 * output_rm_filenames
417 static void output_rm_filenames( struct strarray array
, const char *command
)
419 static const unsigned int max_cmdline
= 30000; /* to be on the safe side */
422 if (!array
.count
) return;
423 output( "\t%s", command
);
424 for (i
= len
= 0; i
< array
.count
; i
++)
426 if (len
> max_cmdline
)
429 output( "\t%s", command
);
432 output_filename( array
.str
[i
] );
433 len
+= strlen( array
.str
[i
] ) + 1;
439 /*******************************************************************
442 static char *get_extension( char *filename
)
444 char *ext
= strrchr( filename
, '.' );
445 if (ext
&& strchr( ext
, '/' )) ext
= NULL
;
450 /*******************************************************************
453 static const char *get_base_name( const char *name
)
456 if (!strchr( name
, '.' )) return name
;
457 base
= xstrdup( name
);
458 *strrchr( base
, '.' ) = 0;
463 /*******************************************************************
466 static char *replace_filename( const char *path
, const char *name
)
472 if (!path
) return xstrdup( name
);
473 if (!(p
= strrchr( path
, '/' ))) return xstrdup( name
);
475 ret
= xmalloc( len
+ strlen( name
) + 1 );
476 memcpy( ret
, path
, len
);
477 strcpy( ret
+ len
, name
);
482 /*******************************************************************
485 static char *replace_substr( const char *str
, const char *start
, size_t len
, const char *replace
)
487 size_t pos
= start
- str
;
488 char *ret
= xmalloc( pos
+ strlen(replace
) + strlen(start
+ len
) + 1 );
489 memcpy( ret
, str
, pos
);
490 strcpy( ret
+ pos
, replace
);
491 strcat( ret
+ pos
, start
+ len
);
496 /*******************************************************************
499 * Determine where the destination path is located relative to the 'from' path.
501 static char *get_relative_path( const char *from
, const char *dest
)
505 unsigned int dotdots
= 0;
507 /* a path of "." is equivalent to an empty path */
508 if (!strcmp( from
, "." )) from
= "";
512 while (*from
== '/') from
++;
513 while (*dest
== '/') dest
++;
514 start
= dest
; /* save start of next path element */
517 while (*from
&& *from
!= '/' && *from
== *dest
) { from
++; dest
++; }
518 if ((!*from
|| *from
== '/') && (!*dest
|| *dest
== '/')) continue;
520 /* count remaining elements in 'from' */
524 while (*from
&& *from
!= '/') from
++;
525 while (*from
== '/') from
++;
531 if (!start
[0] && !dotdots
) return NULL
; /* empty path */
533 ret
= xmalloc( 3 * dotdots
+ strlen( start
) + 1 );
534 for (p
= ret
; dotdots
; dotdots
--, p
+= 3) memcpy( p
, "../", 3 );
536 if (start
[0]) strcpy( p
, start
);
537 else p
[-1] = 0; /* remove trailing slash */
542 /*******************************************************************
545 static char *concat_paths( const char *base
, const char *path
)
550 if (!base
|| !base
[0]) return xstrdup( path
&& path
[0] ? path
: "." );
551 if (!path
|| !path
[0]) return xstrdup( base
);
552 if (path
[0] == '/') return xstrdup( path
);
554 len
= strlen( base
);
555 while (len
&& base
[len
- 1] == '/') len
--;
556 while (len
&& !strncmp( path
, "..", 2 ) && (!path
[2] || path
[2] == '/'))
558 for (i
= len
; i
> 0; i
--) if (base
[i
- 1] == '/') break;
559 if (i
== len
- 2 && !memcmp( base
+ i
, "..", 2 )) break; /* we can't go up if we already have ".." */
560 if (i
!= len
- 1 || base
[i
] != '.')
563 while (*path
== '/') path
++;
565 /* else ignore "." element */
566 while (i
> 0 && base
[i
- 1] == '/') i
--;
569 if (!len
&& base
[0] != '/') return xstrdup( path
[0] ? path
: "." );
570 ret
= xmalloc( len
+ strlen( path
) + 2 );
571 memcpy( ret
, base
, len
);
573 strcpy( ret
+ len
, path
);
578 /*******************************************************************
579 * is_native_arch_disabled
581 * Check if the makefile was disabled for a PE arch that matches the native arch.
583 static int is_native_arch_disabled( struct makefile
*make
)
587 if (archs
.count
== 1) return 0;
588 if (!so_dll_supported
) return 1;
590 for (arch
= 1; arch
< archs
.count
; arch
++)
591 if (make
->disabled
[arch
] && !strcmp( archs
.str
[0], archs
.str
[arch
] ))
597 /*******************************************************************
600 static int get_link_arch( struct makefile
*make
, unsigned int arch
, unsigned int *link_arch
)
602 unsigned int hybrid_arch
= hybrid_archs
[arch
];
603 if (native_archs
[arch
]) return 0;
604 if (hybrid_arch
&& make
->disabled
[hybrid_arch
]) hybrid_arch
= 0;
605 if (make
->disabled
[arch
] && !hybrid_arch
) return 0;
606 *link_arch
= hybrid_arch
? hybrid_arch
: arch
;
611 /*******************************************************************
614 * Check if arch is one of the PE architectures in multiarch.
615 * Also return TRUE for native arch iff there's no PE support.
617 static int is_multiarch( unsigned int arch
)
619 return archs
.count
== 1 || arch
;
623 /*******************************************************************
626 * Check if the files of a makefile use msvcrt by default.
628 static int is_using_msvcrt( struct makefile
*make
)
630 return make
->module
|| make
->testdll
;
634 /*******************************************************************
637 static char *arch_module_name( const char *module
, unsigned int arch
)
639 return strmake( "%s%s%s", arch_dirs
[arch
], module
, dll_ext
[arch
] );
643 /*******************************************************************
646 static char *arch_make_variable( const char *name
, unsigned int arch
)
648 return arch
? strmake( "$(%s_%s)", archs
.str
[arch
], name
) : strmake( "$(%s)", name
);
652 /*******************************************************************
655 static char *obj_dir_path( const struct makefile
*make
, const char *path
)
657 return concat_paths( make
->obj_dir
, path
);
661 /*******************************************************************
664 static char *src_dir_path( const struct makefile
*make
, const char *path
)
666 if (make
->src_dir
) return concat_paths( make
->src_dir
, path
);
667 return obj_dir_path( make
, path
);
671 /*******************************************************************
674 static char *root_src_dir_path( const char *path
)
676 return concat_paths( root_src_dir
, path
);
680 /*******************************************************************
683 static char *tools_dir_path( const struct makefile
*make
, const char *path
)
685 if (tools_dir
) return strmake( "%s/tools/%s", tools_dir
, path
);
686 return strmake( "tools/%s", path
);
690 /*******************************************************************
693 static char *tools_path( const struct makefile
*make
, const char *name
)
695 return strmake( "%s/%s%s", tools_dir_path( make
, name
), name
, tools_ext
);
699 /*******************************************************************
700 * strarray_addall_path
702 static void strarray_addall_path( struct strarray
*array
, const char *dir
, struct strarray added
)
706 for (i
= 0; i
< added
.count
; i
++) strarray_add( array
, concat_paths( dir
, added
.str
[i
] ));
710 /*******************************************************************
713 static char *get_line( FILE *file
)
721 buffer
= xmalloc( size
);
723 if (!fgets( buffer
, size
, file
)) return NULL
;
728 char *p
= buffer
+ strlen(buffer
);
729 /* if line is larger than buffer, resize buffer */
730 while (p
== buffer
+ size
- 1 && p
[-1] != '\n')
732 buffer
= xrealloc( buffer
, size
* 2 );
733 if (!fgets( buffer
+ size
- 1, size
+ 1, file
)) break;
734 p
= buffer
+ strlen(buffer
);
737 if (p
> buffer
&& p
[-1] == '\n')
740 if (p
> buffer
&& p
[-1] == '\r') *(--p
) = 0;
741 if (p
> buffer
&& p
[-1] == '\\')
744 /* line ends in backslash, read continuation line */
745 if (!fgets( p
, size
- (p
- buffer
), file
)) return buffer
;
755 /*******************************************************************
758 static unsigned int hash_filename( const char *name
)
761 unsigned int ret
= 2166136261u;
762 while (*name
) ret
= (ret
* 16777619) ^ *name
++;
763 return ret
% HASH_SIZE
;
767 /*******************************************************************
770 static struct file
*add_file( const char *name
)
772 struct file
*file
= xmalloc( sizeof(*file
) );
773 memset( file
, 0, sizeof(*file
) );
774 file
->name
= xstrdup( name
);
779 /*******************************************************************
782 static void add_dependency( struct file
*file
, const char *name
, enum incl_type type
)
784 if (file
->deps_count
>= file
->deps_size
)
786 file
->deps_size
*= 2;
787 if (file
->deps_size
< 16) file
->deps_size
= 16;
788 file
->deps
= xrealloc( file
->deps
, file
->deps_size
* sizeof(*file
->deps
) );
790 file
->deps
[file
->deps_count
].line
= input_line
;
791 file
->deps
[file
->deps_count
].type
= type
;
792 file
->deps
[file
->deps_count
].name
= xstrdup( name
);
797 /*******************************************************************
800 static struct incl_file
*find_src_file( const struct makefile
*make
, const char *name
)
802 struct incl_file
*file
;
804 if (make
== include_makefile
)
806 unsigned int hash
= hash_filename( name
);
808 LIST_FOR_EACH_ENTRY( file
, &global_includes
[hash
], struct incl_file
, hash_entry
)
809 if (!strcmp( name
, file
->name
)) return file
;
813 LIST_FOR_EACH_ENTRY( file
, &make
->sources
, struct incl_file
, entry
)
814 if (!strcmp( name
, file
->name
)) return file
;
818 /*******************************************************************
821 static struct incl_file
*find_include_file( const struct makefile
*make
, const char *name
)
823 struct incl_file
*file
;
825 LIST_FOR_EACH_ENTRY( file
, &make
->includes
, struct incl_file
, entry
)
827 const char *filename
= file
->filename
;
828 if (!filename
) continue;
829 if (make
->obj_dir
&& strlen(make
->obj_dir
) < strlen(filename
))
831 filename
+= strlen(make
->obj_dir
);
832 while (*filename
== '/') filename
++;
834 if (!strcmp( name
, filename
)) return file
;
839 /*******************************************************************
842 * Add an include file if it doesn't already exists.
844 static struct incl_file
*add_include( struct makefile
*make
, struct incl_file
*parent
,
845 const char *name
, int line
, enum incl_type type
)
847 struct incl_file
*include
;
849 if (parent
->files_count
>= parent
->files_size
)
851 parent
->files_size
*= 2;
852 if (parent
->files_size
< 16) parent
->files_size
= 16;
853 parent
->files
= xrealloc( parent
->files
, parent
->files_size
* sizeof(*parent
->files
) );
856 LIST_FOR_EACH_ENTRY( include
, &make
->includes
, struct incl_file
, entry
)
857 if (!parent
->use_msvcrt
== !include
->use_msvcrt
&& !strcmp( name
, include
->name
))
860 include
= xmalloc( sizeof(*include
) );
861 memset( include
, 0, sizeof(*include
) );
862 include
->name
= xstrdup(name
);
863 include
->included_by
= parent
;
864 include
->included_line
= line
;
865 include
->type
= type
;
866 include
->use_msvcrt
= parent
->use_msvcrt
;
867 list_add_tail( &make
->includes
, &include
->entry
);
869 parent
->files
[parent
->files_count
++] = include
;
874 /*******************************************************************
875 * add_generated_source
877 * Add a generated source file to the list.
879 static struct incl_file
*add_generated_source( struct makefile
*make
, const char *name
,
880 const char *filename
, unsigned int arch
)
882 struct incl_file
*file
= xmalloc( sizeof(*file
) );
884 name
= strmake( "%s%s", arch_dirs
[arch
], name
);
885 memset( file
, 0, sizeof(*file
) );
886 file
->file
= add_file( name
);
888 file
->name
= xstrdup( name
);
889 file
->basename
= xstrdup( filename
? filename
: name
);
890 file
->filename
= obj_dir_path( make
, file
->basename
);
891 file
->file
->flags
= FLAG_GENERATED
;
892 file
->use_msvcrt
= is_using_msvcrt( make
);
893 list_add_tail( &make
->sources
, &file
->entry
);
894 if (make
== include_makefile
)
896 unsigned int hash
= hash_filename( name
);
897 list_add_tail( &global_includes
[hash
], &file
->hash_entry
);
903 /*******************************************************************
906 static char *skip_spaces( const char *p
)
908 while (*p
== ' ' || *p
== '\t') p
++;
913 /*******************************************************************
914 * parse_include_directive
916 static void parse_include_directive( struct file
*source
, char *str
)
918 char quote
, *include
, *p
= skip_spaces( str
);
920 if (*p
!= '\"' && *p
!= '<' ) return;
922 if (quote
== '<') quote
= '>';
924 while (*p
&& (*p
!= quote
)) p
++;
925 if (!*p
) fatal_error( "malformed include directive '%s'\n", str
);
927 add_dependency( source
, include
, (quote
== '>') ? INCL_SYSTEM
: INCL_NORMAL
);
931 /*******************************************************************
932 * parse_pragma_directive
934 static void parse_pragma_directive( struct file
*source
, char *str
)
936 char *flag
, *p
= str
;
938 if (*p
!= ' ' && *p
!= '\t') return;
939 p
= strtok( skip_spaces( p
), " \t" );
940 if (strcmp( p
, "makedep" )) return;
942 while ((flag
= strtok( NULL
, " \t" )))
944 if (!strcmp( flag
, "depend" ))
946 while ((p
= strtok( NULL
, " \t" ))) add_dependency( source
, p
, INCL_NORMAL
);
949 else if (!strcmp( flag
, "install" )) source
->flags
|= FLAG_INSTALL
;
950 else if (!strcmp( flag
, "testdll" )) source
->flags
|= FLAG_TESTDLL
;
952 if (strendswith( source
->name
, ".idl" ))
954 if (!strcmp( flag
, "header" )) source
->flags
|= FLAG_IDL_HEADER
;
955 else if (!strcmp( flag
, "proxy" )) source
->flags
|= FLAG_IDL_PROXY
;
956 else if (!strcmp( flag
, "client" )) source
->flags
|= FLAG_IDL_CLIENT
;
957 else if (!strcmp( flag
, "server" )) source
->flags
|= FLAG_IDL_SERVER
;
958 else if (!strcmp( flag
, "ident" )) source
->flags
|= FLAG_IDL_IDENT
;
959 else if (!strcmp( flag
, "typelib" )) source
->flags
|= FLAG_IDL_TYPELIB
;
960 else if (!strcmp( flag
, "register" )) source
->flags
|= FLAG_IDL_REGISTER
;
961 else if (!strcmp( flag
, "regtypelib" )) source
->flags
|= FLAG_IDL_REGTYPELIB
;
963 else if (strendswith( source
->name
, ".rc" ))
965 if (!strcmp( flag
, "header" )) source
->flags
|= FLAG_RC_HEADER
;
966 else if (!strcmp( flag
, "po" )) source
->flags
|= FLAG_RC_PO
;
968 else if (strendswith( source
->name
, ".sfd" ))
970 if (!strcmp( flag
, "font" ))
972 struct strarray
*array
= source
->args
;
976 source
->args
= array
= xmalloc( sizeof(*array
) );
977 *array
= empty_strarray
;
978 source
->flags
|= FLAG_SFD_FONTS
;
980 strarray_add( array
, xstrdup( strtok( NULL
, "" )));
986 if (!strcmp( flag
, "implib" )) source
->flags
|= FLAG_C_IMPLIB
;
987 if (!strcmp( flag
, "unix" )) source
->flags
|= FLAG_C_UNIX
;
988 if (!strcmp( flag
, "arm64ec_x64" )) source
->flags
|= FLAG_ARM64EC_X64
;
994 /*******************************************************************
995 * parse_cpp_directive
997 static void parse_cpp_directive( struct file
*source
, char *str
)
999 str
= skip_spaces( str
);
1000 if (*str
++ != '#') return;
1001 str
= skip_spaces( str
);
1003 if (!strncmp( str
, "include", 7 ))
1004 parse_include_directive( source
, str
+ 7 );
1005 else if (!strncmp( str
, "import", 6 ) && strendswith( source
->name
, ".m" ))
1006 parse_include_directive( source
, str
+ 6 );
1007 else if (!strncmp( str
, "pragma", 6 ))
1008 parse_pragma_directive( source
, str
+ 6 );
1012 /*******************************************************************
1015 static void parse_idl_file( struct file
*source
, FILE *file
)
1017 char *buffer
, *include
;
1021 while ((buffer
= get_line( file
)))
1024 char *p
= skip_spaces( buffer
);
1026 if (!strncmp( p
, "importlib", 9 ))
1028 p
= skip_spaces( p
+ 9 );
1029 if (*p
++ != '(') continue;
1030 p
= skip_spaces( p
);
1031 if (*p
++ != '"') continue;
1033 while (*p
&& (*p
!= '"')) p
++;
1034 if (!*p
) fatal_error( "malformed importlib directive\n" );
1036 add_dependency( source
, include
, INCL_IMPORTLIB
);
1040 if (!strncmp( p
, "import", 6 ))
1042 p
= skip_spaces( p
+ 6 );
1043 if (*p
!= '"') continue;
1045 while (*p
&& (*p
!= '"')) p
++;
1046 if (!*p
) fatal_error( "malformed import directive\n" );
1048 add_dependency( source
, include
, INCL_IMPORT
);
1052 /* check for #include inside cpp_quote */
1053 if (!strncmp( p
, "cpp_quote", 9 ))
1055 p
= skip_spaces( p
+ 9 );
1056 if (*p
++ != '(') continue;
1057 p
= skip_spaces( p
);
1058 if (*p
++ != '"') continue;
1059 if (*p
++ != '#') continue;
1060 p
= skip_spaces( p
);
1061 if (strncmp( p
, "include", 7 )) continue;
1062 p
= skip_spaces( p
+ 7 );
1063 if (*p
== '\\' && p
[1] == '"')
1070 if (*p
++ != '<' ) continue;
1074 while (*p
&& (*p
!= quote
)) p
++;
1075 if (!*p
|| (quote
== '"' && p
[-1] != '\\'))
1076 fatal_error( "malformed #include directive inside cpp_quote\n" );
1077 if (quote
== '"') p
--; /* remove backslash */
1079 add_dependency( source
, include
, (quote
== '>') ? INCL_CPP_QUOTE_SYSTEM
: INCL_CPP_QUOTE
);
1083 parse_cpp_directive( source
, p
);
1087 /*******************************************************************
1090 static void parse_c_file( struct file
*source
, FILE *file
)
1095 while ((buffer
= get_line( file
)))
1097 parse_cpp_directive( source
, buffer
);
1102 /*******************************************************************
1105 static void parse_rc_file( struct file
*source
, FILE *file
)
1107 char *buffer
, *include
;
1110 while ((buffer
= get_line( file
)))
1113 char *p
= skip_spaces( buffer
);
1115 if (p
[0] == '/' && p
[1] == '*') /* check for magic makedep comment */
1117 p
= skip_spaces( p
+ 2 );
1118 if (strncmp( p
, "@makedep:", 9 )) continue;
1119 p
= skip_spaces( p
+ 9 );
1124 while (*p
&& *p
!= quote
) p
++;
1129 while (*p
&& *p
!= ' ' && *p
!= '\t' && *p
!= '*') p
++;
1132 fatal_error( "malformed makedep comment\n" );
1134 add_dependency( source
, include
, (quote
== '>') ? INCL_SYSTEM
: INCL_NORMAL
);
1138 parse_cpp_directive( source
, buffer
);
1143 /*******************************************************************
1146 static void parse_in_file( struct file
*source
, FILE *file
)
1150 /* make sure it gets rebuilt when the version changes */
1151 add_dependency( source
, "config.h", INCL_SYSTEM
);
1153 if (!strendswith( source
->name
, ".man.in" )) return; /* not a man page */
1156 while ((buffer
= get_line( file
)))
1158 if (strncmp( buffer
, ".TH", 3 )) continue;
1159 p
= skip_spaces( buffer
+ 3 );
1160 if (!(p
= strtok( p
, " \t" ))) continue; /* program name */
1161 if (!(p
= strtok( NULL
, " \t" ))) continue; /* man section */
1162 source
->args
= xstrdup( p
);
1168 /*******************************************************************
1171 static void parse_sfd_file( struct file
*source
, FILE *file
)
1173 char *p
, *eol
, *buffer
;
1176 while ((buffer
= get_line( file
)))
1178 if (strncmp( buffer
, "UComments:", 10 )) continue;
1180 while (*p
== ' ') p
++;
1181 if (p
[0] == '"' && p
[1] && buffer
[strlen(buffer
) - 1] == '"')
1184 buffer
[strlen(buffer
) - 1] = 0;
1186 while ((eol
= strstr( p
, "+AAoA" )))
1189 p
= skip_spaces( p
);
1192 p
= skip_spaces( p
);
1193 if (!strncmp( p
, "pragma", 6 )) parse_pragma_directive( source
, p
+ 6 );
1197 p
= skip_spaces( p
);
1198 if (*p
++ != '#') return;
1199 p
= skip_spaces( p
);
1200 if (!strncmp( p
, "pragma", 6 )) parse_pragma_directive( source
, p
+ 6 );
1209 void (*parse
)( struct file
*file
, FILE *f
);
1210 } parse_functions
[] =
1212 { ".c", parse_c_file
},
1213 { ".h", parse_c_file
},
1214 { ".inl", parse_c_file
},
1215 { ".l", parse_c_file
},
1216 { ".m", parse_c_file
},
1217 { ".rh", parse_c_file
},
1218 { ".x", parse_c_file
},
1219 { ".y", parse_c_file
},
1220 { ".idl", parse_idl_file
},
1221 { ".rc", parse_rc_file
},
1222 { ".in", parse_in_file
},
1223 { ".sfd", parse_sfd_file
}
1226 /*******************************************************************
1229 static struct file
*load_file( const char *name
)
1233 unsigned int i
, hash
= hash_filename( name
);
1235 LIST_FOR_EACH_ENTRY( file
, &files
[hash
], struct file
, entry
)
1236 if (!strcmp( name
, file
->name
)) return file
;
1238 if (!(f
= fopen( name
, "r" ))) return NULL
;
1240 file
= add_file( name
);
1241 list_add_tail( &files
[hash
], &file
->entry
);
1242 input_file_name
= file
->name
;
1245 for (i
= 0; i
< ARRAY_SIZE(parse_functions
); i
++)
1247 if (!strendswith( name
, parse_functions
[i
].ext
)) continue;
1248 parse_functions
[i
].parse( file
, f
);
1253 input_file_name
= NULL
;
1259 /*******************************************************************
1260 * open_include_path_file
1262 * Open a file from a directory on the include path.
1264 static struct file
*open_include_path_file( const struct makefile
*make
, const char *dir
,
1265 const char *name
, char **filename
)
1267 char *src_path
= concat_paths( dir
, name
);
1268 struct file
*ret
= load_file( src_path
);
1270 if (ret
) *filename
= src_path
;
1275 /*******************************************************************
1276 * open_file_same_dir
1278 * Open a file in the same directory as the parent.
1280 static struct file
*open_file_same_dir( const struct incl_file
*parent
, const char *name
, char **filename
)
1282 char *src_path
= replace_filename( parent
->file
->name
, name
);
1283 struct file
*ret
= load_file( src_path
);
1285 if (ret
) *filename
= replace_filename( parent
->filename
, name
);
1290 /*******************************************************************
1291 * open_same_dir_generated_file
1293 * Open a generated_file in the same directory as the parent.
1295 static struct file
*open_same_dir_generated_file( const struct makefile
*make
,
1296 const struct incl_file
*parent
, struct incl_file
*file
,
1297 const char *ext
, const char *src_ext
)
1300 struct file
*ret
= NULL
;
1302 if (strendswith( file
->name
, ext
) &&
1303 (ret
= open_file_same_dir( parent
, replace_extension( file
->name
, ext
, src_ext
), &filename
)))
1305 file
->sourcename
= filename
;
1306 file
->filename
= obj_dir_path( make
, replace_filename( parent
->name
, file
->name
));
1312 /*******************************************************************
1315 * Open a file in the source directory of the makefile.
1317 static struct file
*open_local_file( const struct makefile
*make
, const char *path
, char **filename
)
1319 char *src_path
= src_dir_path( make
, path
);
1320 struct file
*ret
= load_file( src_path
);
1322 /* if not found, try parent dir */
1323 if (!ret
&& make
->parent_dir
)
1326 path
= strmake( "%s/%s", make
->parent_dir
, path
);
1327 src_path
= src_dir_path( make
, path
);
1328 ret
= load_file( src_path
);
1331 if (ret
) *filename
= src_path
;
1336 /*******************************************************************
1337 * open_local_generated_file
1339 * Open a generated file in the directory of the makefile.
1341 static struct file
*open_local_generated_file( const struct makefile
*make
, struct incl_file
*file
,
1342 const char *ext
, const char *src_ext
)
1344 struct incl_file
*include
;
1346 if (strendswith( file
->name
, ext
) &&
1347 (include
= find_src_file( make
, replace_extension( file
->name
, ext
, src_ext
) )))
1349 file
->sourcename
= include
->filename
;
1350 file
->filename
= obj_dir_path( make
, file
->name
);
1351 return include
->file
;
1357 /*******************************************************************
1360 * Open a file in the top-level source directory.
1362 static struct file
*open_global_file( const char *path
, char **filename
)
1364 char *src_path
= root_src_dir_path( path
);
1365 struct file
*ret
= load_file( src_path
);
1367 if (ret
) *filename
= src_path
;
1372 /*******************************************************************
1373 * open_global_header
1375 * Open a file in the global include source directory.
1377 static struct file
*open_global_header( const char *path
, char **filename
)
1379 struct incl_file
*include
= find_src_file( include_makefile
, path
);
1381 if (!include
) return NULL
;
1382 *filename
= include
->filename
;
1383 return include
->file
;
1387 /*******************************************************************
1388 * open_global_generated_file
1390 * Open a generated file in the top-level source directory.
1392 static struct file
*open_global_generated_file( const struct makefile
*make
, struct incl_file
*file
,
1393 const char *ext
, const char *src_ext
)
1395 struct incl_file
*include
;
1397 if (strendswith( file
->name
, ext
) &&
1398 (include
= find_src_file( include_makefile
, replace_extension( file
->name
, ext
, src_ext
) )))
1400 file
->sourcename
= include
->filename
;
1401 file
->filename
= strmake( "include/%s", file
->name
);
1402 return include
->file
;
1408 /*******************************************************************
1411 static struct file
*open_src_file( const struct makefile
*make
, struct incl_file
*pFile
)
1413 struct file
*file
= open_local_file( make
, pFile
->name
, &pFile
->filename
);
1415 if (!file
) fatal_perror( "open %s", pFile
->name
);
1420 /*******************************************************************
1421 * find_importlib_module
1423 static struct makefile
*find_importlib_module( const char *name
)
1425 unsigned int i
, len
;
1427 for (i
= 0; i
< subdirs
.count
; i
++)
1429 if (strncmp( submakes
[i
]->obj_dir
, "dlls/", 5 )) continue;
1430 len
= strlen(submakes
[i
]->obj_dir
);
1431 if (strncmp( submakes
[i
]->obj_dir
+ 5, name
, len
- 5 )) continue;
1432 if (!name
[len
- 5] || !strcmp( name
+ len
- 5, ".dll" )) return submakes
[i
];
1438 /*******************************************************************
1441 static struct file
*open_include_file( const struct makefile
*make
, struct incl_file
*pFile
)
1443 struct file
*file
= NULL
;
1444 unsigned int i
, len
;
1448 /* check for generated files */
1449 if ((file
= open_local_generated_file( make
, pFile
, ".tab.h", ".y" ))) return file
;
1450 if ((file
= open_local_generated_file( make
, pFile
, ".h", ".idl" ))) return file
;
1451 if (fontforge
&& (file
= open_local_generated_file( make
, pFile
, ".ttf", ".sfd" ))) return file
;
1452 if (convert
&& rsvg
&& icotool
)
1454 if ((file
= open_local_generated_file( make
, pFile
, ".bmp", ".svg" ))) return file
;
1455 if ((file
= open_local_generated_file( make
, pFile
, ".cur", ".svg" ))) return file
;
1456 if ((file
= open_local_generated_file( make
, pFile
, ".ico", ".svg" ))) return file
;
1458 if ((file
= open_local_generated_file( make
, pFile
, "-client-protocol.h", ".xml" ))) return file
;
1460 /* check for extra targets */
1461 if (strarray_exists( &make
->extra_targets
, pFile
->name
))
1463 pFile
->sourcename
= src_dir_path( make
, pFile
->name
);
1464 pFile
->filename
= obj_dir_path( make
, pFile
->name
);
1468 /* now try in source dir */
1469 if ((file
= open_local_file( make
, pFile
->name
, &pFile
->filename
))) return file
;
1471 /* check for global importlib (module dependency) */
1472 if (pFile
->type
== INCL_IMPORTLIB
&& find_importlib_module( pFile
->name
))
1474 pFile
->filename
= pFile
->name
;
1478 /* check for generated files in global includes */
1479 if ((file
= open_global_generated_file( make
, pFile
, ".h", ".idl" ))) return file
;
1480 if ((file
= open_global_generated_file( make
, pFile
, ".h", ".h.in" ))) return file
;
1481 if (strendswith( pFile
->name
, "tmpl.h" ) &&
1482 (file
= open_global_generated_file( make
, pFile
, ".h", ".x" ))) return file
;
1484 /* check in global includes source dir */
1485 if ((file
= open_global_header( pFile
->name
, &pFile
->filename
))) return file
;
1487 /* check in global msvcrt includes */
1488 if (pFile
->use_msvcrt
&&
1489 (file
= open_global_header( strmake( "msvcrt/%s", pFile
->name
), &pFile
->filename
)))
1492 /* now search in include paths */
1493 for (i
= 0; i
< make
->include_paths
.count
; i
++)
1495 const char *dir
= make
->include_paths
.str
[i
];
1499 len
= strlen( root_src_dir
);
1500 if (!strncmp( dir
, root_src_dir
, len
) && (!dir
[len
] || dir
[len
] == '/'))
1502 while (dir
[len
] == '/') len
++;
1503 file
= open_global_file( concat_paths( dir
+ len
, pFile
->name
), &pFile
->filename
);
1508 if (*dir
== '/') continue;
1509 file
= open_include_path_file( make
, dir
, pFile
->name
, &pFile
->filename
);
1511 if (!file
) continue;
1512 pFile
->is_external
= 1;
1516 if (pFile
->type
== INCL_SYSTEM
) return NULL
; /* ignore system files we cannot find */
1518 /* try in src file directory */
1519 if ((file
= open_same_dir_generated_file( make
, pFile
->included_by
, pFile
, ".tab.h", ".y" )) ||
1520 (file
= open_same_dir_generated_file( make
, pFile
->included_by
, pFile
, ".h", ".idl" )) ||
1521 (file
= open_file_same_dir( pFile
->included_by
, pFile
->name
, &pFile
->filename
)))
1523 pFile
->is_external
= pFile
->included_by
->is_external
;
1527 if (make
->extlib
) return NULL
; /* ignore missing files in external libs */
1529 fprintf( stderr
, "%s:%d: error: ", pFile
->included_by
->file
->name
, pFile
->included_line
);
1530 perror( pFile
->name
);
1531 pFile
= pFile
->included_by
;
1532 while (pFile
&& pFile
->included_by
)
1534 const char *parent
= pFile
->included_by
->sourcename
;
1535 if (!parent
) parent
= pFile
->included_by
->file
->name
;
1536 fprintf( stderr
, "%s:%d: note: %s was first included here\n",
1537 parent
, pFile
->included_line
, pFile
->name
);
1538 pFile
= pFile
->included_by
;
1544 /*******************************************************************
1547 static void add_all_includes( struct makefile
*make
, struct incl_file
*parent
, struct file
*file
)
1551 for (i
= 0; i
< file
->deps_count
; i
++)
1553 switch (file
->deps
[i
].type
)
1557 add_include( make
, parent
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_NORMAL
);
1559 case INCL_IMPORTLIB
:
1560 add_include( make
, parent
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_IMPORTLIB
);
1563 add_include( make
, parent
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_SYSTEM
);
1565 case INCL_CPP_QUOTE
:
1566 case INCL_CPP_QUOTE_SYSTEM
:
1573 /*******************************************************************
1576 static void parse_file( struct makefile
*make
, struct incl_file
*source
, int src
)
1578 struct file
*file
= src
? open_src_file( make
, source
) : open_include_file( make
, source
);
1582 source
->file
= file
;
1583 source
->files_count
= 0;
1584 source
->files_size
= file
->deps_count
;
1585 source
->files
= xmalloc( source
->files_size
* sizeof(*source
->files
) );
1587 if (strendswith( file
->name
, ".m" )) file
->flags
|= FLAG_C_UNIX
;
1588 if (file
->flags
& FLAG_C_UNIX
) source
->use_msvcrt
= 0;
1589 else if (file
->flags
& FLAG_C_IMPLIB
) source
->use_msvcrt
= 1;
1591 if (source
->sourcename
)
1593 if (strendswith( source
->sourcename
, ".idl" ))
1597 /* generated .h file always includes these */
1598 add_include( make
, source
, "rpc.h", 0, INCL_NORMAL
);
1599 add_include( make
, source
, "rpcndr.h", 0, INCL_NORMAL
);
1600 for (i
= 0; i
< file
->deps_count
; i
++)
1602 switch (file
->deps
[i
].type
)
1605 if (strendswith( file
->deps
[i
].name
, ".idl" ))
1606 add_include( make
, source
, replace_extension( file
->deps
[i
].name
, ".idl", ".h" ),
1607 file
->deps
[i
].line
, INCL_NORMAL
);
1609 add_include( make
, source
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_NORMAL
);
1611 case INCL_CPP_QUOTE
:
1612 add_include( make
, source
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_NORMAL
);
1614 case INCL_CPP_QUOTE_SYSTEM
:
1615 add_include( make
, source
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_SYSTEM
);
1619 case INCL_IMPORTLIB
:
1625 if (strendswith( source
->sourcename
, ".y" ))
1626 return; /* generated .tab.h doesn't include anything */
1629 add_all_includes( make
, source
, file
);
1633 /*******************************************************************
1636 * Add a source file to the list.
1638 static struct incl_file
*add_src_file( struct makefile
*make
, const char *name
)
1640 struct incl_file
*file
= xmalloc( sizeof(*file
) );
1642 memset( file
, 0, sizeof(*file
) );
1643 file
->name
= xstrdup(name
);
1644 file
->use_msvcrt
= is_using_msvcrt( make
);
1645 file
->is_external
= !!make
->extlib
;
1646 list_add_tail( &make
->sources
, &file
->entry
);
1647 if (make
== include_makefile
)
1649 unsigned int hash
= hash_filename( name
);
1650 list_add_tail( &global_includes
[hash
], &file
->hash_entry
);
1652 parse_file( make
, file
, 1 );
1657 /*******************************************************************
1658 * open_input_makefile
1660 static FILE *open_input_makefile( const struct makefile
*make
)
1665 input_file_name
= root_src_dir_path( obj_dir_path( make
, "Makefile.in" ));
1667 input_file_name
= output_makefile_name
; /* always use output name for main Makefile */
1670 if (!(ret
= fopen( input_file_name
, "r" ))) fatal_perror( "open" );
1675 /*******************************************************************
1678 static const char *get_make_variable( const struct makefile
*make
, const char *name
)
1682 if ((ret
= strarray_get_value( &cmdline_vars
, name
))) return ret
;
1683 if ((ret
= strarray_get_value( &make
->vars
, name
))) return ret
;
1684 if (top_makefile
&& (ret
= strarray_get_value( &top_makefile
->vars
, name
))) return ret
;
1689 /*******************************************************************
1690 * get_expanded_make_variable
1692 static char *get_expanded_make_variable( const struct makefile
*make
, const char *name
)
1695 char *p
, *end
, *expand
, *tmp
;
1697 var
= get_make_variable( make
, name
);
1698 if (!var
) return NULL
;
1700 p
= expand
= xstrdup( var
);
1701 while ((p
= strchr( p
, '$' )))
1705 if (!(end
= strchr( p
+ 2, ')' ))) fatal_error( "syntax error in '%s'\n", expand
);
1707 if (strchr( p
+ 2, ':' )) fatal_error( "pattern replacement not supported for '%s'\n", p
+ 2 );
1708 var
= get_make_variable( make
, p
+ 2 );
1709 tmp
= replace_substr( expand
, p
, end
- p
, var
? var
: "" );
1710 /* switch to the new string */
1711 p
= tmp
+ (p
- expand
);
1715 else if (p
[1] == '{') /* don't expand ${} variables */
1717 if (!(end
= strchr( p
+ 2, '}' ))) fatal_error( "syntax error in '%s'\n", expand
);
1720 else if (p
[1] == '$')
1724 else fatal_error( "syntax error in '%s'\n", expand
);
1727 /* consider empty variables undefined */
1728 p
= skip_spaces( expand
);
1729 if (*p
) return expand
;
1735 /*******************************************************************
1736 * get_expanded_make_var_array
1738 static struct strarray
get_expanded_make_var_array( const struct makefile
*make
, const char *name
)
1740 struct strarray ret
= empty_strarray
;
1741 char *value
, *token
;
1743 if ((value
= get_expanded_make_variable( make
, name
)))
1744 for (token
= strtok( value
, " \t" ); token
; token
= strtok( NULL
, " \t" ))
1745 strarray_add( &ret
, token
);
1750 /*******************************************************************
1751 * get_expanded_file_local_var
1753 static struct strarray
get_expanded_file_local_var( const struct makefile
*make
, const char *file
,
1756 char *p
, *var
= strmake( "%s_%s", file
, name
);
1758 for (p
= var
; *p
; p
++) if (!isalnum( *p
)) *p
= '_';
1759 return get_expanded_make_var_array( make
, var
);
1763 /*******************************************************************
1764 * get_expanded_arch_var
1766 static char *get_expanded_arch_var( const struct makefile
*make
, const char *name
, int arch
)
1768 return get_expanded_make_variable( make
, arch
? strmake( "%s_%s", archs
.str
[arch
], name
) : name
);
1772 /*******************************************************************
1773 * get_expanded_arch_var_array
1775 static struct strarray
get_expanded_arch_var_array( const struct makefile
*make
, const char *name
, int arch
)
1777 return get_expanded_make_var_array( make
, arch
? strmake( "%s_%s", archs
.str
[arch
], name
) : name
);
1781 /*******************************************************************
1784 static int set_make_variable( struct strarray
*array
, const char *assignment
)
1788 p
= name
= xstrdup( assignment
);
1789 while (isalnum(*p
) || *p
== '_') p
++;
1790 if (name
== p
) return 0; /* not a variable */
1794 p
= skip_spaces( p
);
1796 if (*p
!= '=') return 0; /* not an assignment */
1798 p
= skip_spaces( p
);
1800 strarray_set_value( array
, name
, p
);
1805 /*******************************************************************
1808 static struct makefile
*parse_makefile( const char *path
)
1812 struct makefile
*make
= xmalloc( sizeof(*make
) );
1814 memset( make
, 0, sizeof(*make
) );
1815 make
->obj_dir
= path
;
1816 if (root_src_dir
) make
->src_dir
= root_src_dir_path( make
->obj_dir
);
1817 if (path
&& !strcmp( path
, "include" )) include_makefile
= make
;
1819 file
= open_input_makefile( make
);
1820 while ((buffer
= get_line( file
)))
1822 if (!strncmp( buffer
, separator
, strlen(separator
) )) break;
1823 if (*buffer
== '\t') continue; /* command */
1824 buffer
= skip_spaces( buffer
);
1825 if (*buffer
== '#') continue; /* comment */
1826 set_make_variable( &make
->vars
, buffer
);
1829 input_file_name
= NULL
;
1834 /*******************************************************************
1835 * add_generated_sources
1837 static void add_generated_sources( struct makefile
*make
)
1839 unsigned int i
, arch
;
1840 struct incl_file
*source
, *next
, *file
, *dlldata
= NULL
;
1841 struct strarray objs
= get_expanded_make_var_array( make
, "EXTRA_OBJS" );
1843 LIST_FOR_EACH_ENTRY_SAFE( source
, next
, &make
->sources
, struct incl_file
, entry
)
1845 for (arch
= 0; arch
< archs
.count
; arch
++)
1847 if (!is_multiarch( arch
)) continue;
1848 if (source
->file
->flags
& FLAG_IDL_CLIENT
)
1850 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_c.c" ), NULL
, arch
);
1851 add_dependency( file
->file
, replace_extension( source
->name
, ".idl", ".h" ), INCL_NORMAL
);
1852 add_all_includes( make
, file
, file
->file
);
1854 if (source
->file
->flags
& FLAG_IDL_SERVER
)
1856 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_s.c" ), NULL
, arch
);
1857 add_dependency( file
->file
, "wine/exception.h", INCL_NORMAL
);
1858 add_dependency( file
->file
, replace_extension( source
->name
, ".idl", ".h" ), INCL_NORMAL
);
1859 add_all_includes( make
, file
, file
->file
);
1861 if (source
->file
->flags
& FLAG_IDL_IDENT
)
1863 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_i.c" ), NULL
, arch
);
1864 add_dependency( file
->file
, "rpc.h", INCL_NORMAL
);
1865 add_dependency( file
->file
, "rpcndr.h", INCL_NORMAL
);
1866 add_dependency( file
->file
, "guiddef.h", INCL_NORMAL
);
1867 add_all_includes( make
, file
, file
->file
);
1869 if (source
->file
->flags
& FLAG_IDL_PROXY
)
1871 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_p.c" ), NULL
, arch
);
1872 add_dependency( file
->file
, "objbase.h", INCL_NORMAL
);
1873 add_dependency( file
->file
, "rpcproxy.h", INCL_NORMAL
);
1874 add_dependency( file
->file
, "wine/exception.h", INCL_NORMAL
);
1875 add_dependency( file
->file
, replace_extension( source
->name
, ".idl", ".h" ), INCL_NORMAL
);
1876 add_all_includes( make
, file
, file
->file
);
1878 if (source
->file
->flags
& FLAG_IDL_TYPELIB
)
1880 add_generated_source( make
, replace_extension( source
->name
, ".idl", "_l.res" ), NULL
, arch
);
1882 if (source
->file
->flags
& FLAG_IDL_REGTYPELIB
)
1884 add_generated_source( make
, replace_extension( source
->name
, ".idl", "_t.res" ), NULL
, arch
);
1886 if (source
->file
->flags
& FLAG_IDL_REGISTER
)
1888 add_generated_source( make
, replace_extension( source
->name
, ".idl", "_r.res" ), NULL
, arch
);
1892 /* now the arch-independent files */
1894 if ((source
->file
->flags
& FLAG_IDL_PROXY
) && !dlldata
)
1896 dlldata
= add_generated_source( make
, "dlldata.o", "dlldata.c", 0 );
1897 add_dependency( dlldata
->file
, "objbase.h", INCL_NORMAL
);
1898 add_dependency( dlldata
->file
, "rpcproxy.h", INCL_NORMAL
);
1899 add_all_includes( make
, dlldata
, dlldata
->file
);
1901 if (source
->file
->flags
& FLAG_IDL_HEADER
)
1903 add_generated_source( make
, replace_extension( source
->name
, ".idl", ".h" ), NULL
, 0 );
1905 if (!source
->file
->flags
&& strendswith( source
->name
, ".idl" ))
1907 if (!strncmp( source
->name
, "wine/", 5 )) continue;
1908 source
->file
->flags
= FLAG_IDL_HEADER
| FLAG_INSTALL
;
1909 add_generated_source( make
, replace_extension( source
->name
, ".idl", ".h" ), NULL
, 0 );
1911 if (strendswith( source
->name
, ".x" ))
1913 add_generated_source( make
, replace_extension( source
->name
, ".x", ".h" ), NULL
, 0 );
1915 if (strendswith( source
->name
, ".y" ))
1917 file
= add_generated_source( make
, replace_extension( source
->name
, ".y", ".tab.c" ), NULL
, 0 );
1918 /* steal the includes list from the source file */
1919 file
->files_count
= source
->files_count
;
1920 file
->files_size
= source
->files_size
;
1921 file
->files
= source
->files
;
1922 source
->files_count
= source
->files_size
= 0;
1923 source
->files
= NULL
;
1925 if (strendswith( source
->name
, ".l" ))
1927 file
= add_generated_source( make
, replace_extension( source
->name
, ".l", ".yy.c" ), NULL
, 0 );
1928 /* steal the includes list from the source file */
1929 file
->files_count
= source
->files_count
;
1930 file
->files_size
= source
->files_size
;
1931 file
->files
= source
->files
;
1932 source
->files_count
= source
->files_size
= 0;
1933 source
->files
= NULL
;
1935 if (strendswith( source
->name
, ".po" ))
1937 if (!make
->disabled
[0])
1938 strarray_add_uniq( &linguas
, replace_extension( source
->name
, ".po", "" ));
1940 if (strendswith( source
->name
, ".spec" ))
1942 char *obj
= replace_extension( source
->name
, ".spec", "" );
1943 strarray_addall_uniq( &make
->extra_imports
,
1944 get_expanded_file_local_var( make
, obj
, "IMPORTS" ));
1946 if (strendswith( source
->name
, ".xml" ))
1948 char *code_name
= replace_extension( source
->name
, ".xml", "-protocol.c" );
1949 char *header_name
= replace_extension( source
->name
, ".xml", "-client-protocol.h" );
1951 file
= add_generated_source( make
, code_name
, NULL
, 0 );
1952 file
->file
->flags
|= FLAG_C_UNIX
;
1953 file
->use_msvcrt
= 0;
1954 file
= add_generated_source( make
, header_name
, NULL
, 0 );
1955 file
->file
->flags
|= FLAG_C_UNIX
;
1956 file
->use_msvcrt
= 0;
1959 free( header_name
);
1964 for (arch
= 0; arch
< archs
.count
; arch
++)
1966 if (!is_multiarch( arch
)) continue;
1967 file
= add_generated_source( make
, "testlist.o", "testlist.c", arch
);
1968 add_dependency( file
->file
, "wine/test.h", INCL_NORMAL
);
1969 add_all_includes( make
, file
, file
->file
);
1972 for (i
= 0; i
< objs
.count
; i
++)
1974 /* default to .c for unknown extra object files */
1975 if (strendswith( objs
.str
[i
], ".o" ))
1977 file
= add_generated_source( make
, objs
.str
[i
], replace_extension( objs
.str
[i
], ".o", ".c" ), 0);
1978 file
->file
->flags
|= FLAG_C_UNIX
;
1979 file
->use_msvcrt
= 0;
1981 else if (strendswith( objs
.str
[i
], ".res" ))
1982 add_generated_source( make
, replace_extension( objs
.str
[i
], ".res", ".rc" ), NULL
, 0 );
1984 add_generated_source( make
, objs
.str
[i
], NULL
, 0 );
1989 /*******************************************************************
1992 static void create_dir( const char *dir
)
1996 p
= path
= xstrdup( dir
);
1997 while ((p
= strchr( p
, '/' )))
2000 if (mkdir( path
, 0755 ) == -1 && errno
!= EEXIST
) fatal_perror( "mkdir %s", path
);
2002 while (*p
== '/') p
++;
2004 if (mkdir( path
, 0755 ) == -1 && errno
!= EEXIST
) fatal_perror( "mkdir %s", path
);
2009 /*******************************************************************
2010 * create_file_directories
2012 * Create the base directories of all the files.
2014 static void create_file_directories( const struct makefile
*make
, struct strarray files
)
2016 struct strarray subdirs
= empty_strarray
;
2020 for (i
= 0; i
< files
.count
; i
++)
2022 if (!strchr( files
.str
[i
], '/' )) continue;
2023 dir
= obj_dir_path( make
, files
.str
[i
] );
2024 *strrchr( dir
, '/' ) = 0;
2025 strarray_add_uniq( &subdirs
, dir
);
2028 for (i
= 0; i
< subdirs
.count
; i
++) create_dir( subdirs
.str
[i
] );
2032 /*******************************************************************
2033 * output_filenames_obj_dir
2035 static void output_filenames_obj_dir( const struct makefile
*make
, struct strarray array
)
2039 for (i
= 0; i
< array
.count
; i
++) output_filename( obj_dir_path( make
, array
.str
[i
] ));
2043 /*******************************************************************
2046 static void get_dependencies( struct incl_file
*file
, struct incl_file
*source
)
2050 if (!file
->filename
) return;
2054 if (file
->owner
== source
) return; /* already processed */
2055 if (file
->type
== INCL_IMPORTLIB
)
2057 if (!(source
->file
->flags
& (FLAG_IDL_TYPELIB
| FLAG_IDL_REGTYPELIB
)))
2058 return; /* library is imported only when building a typelib */
2059 strarray_add( &source
->importlibdeps
, file
->filename
);
2061 else strarray_add( &source
->dependencies
, file
->filename
);
2062 file
->owner
= source
;
2065 if (!strcmp( file
->filename
, "include/config.h" ) &&
2066 file
!= source
->files
[0] && !source
->is_external
)
2068 input_file_name
= source
->filename
;
2070 for (i
= 0; i
< source
->file
->deps_count
; i
++)
2072 if (!strcmp( source
->file
->deps
[i
].name
, file
->name
))
2073 input_line
= source
->file
->deps
[i
].line
;
2075 fatal_error( "%s must be included before other headers\n", file
->name
);
2079 for (i
= 0; i
< file
->files_count
; i
++) get_dependencies( file
->files
[i
], source
);
2083 /*******************************************************************
2084 * get_local_dependencies
2086 * Get the local dependencies of a given target.
2088 static struct strarray
get_local_dependencies( const struct makefile
*make
, const char *name
,
2089 struct strarray targets
)
2092 struct strarray deps
= get_expanded_file_local_var( make
, name
, "DEPS" );
2094 for (i
= 0; i
< deps
.count
; i
++)
2096 if (strarray_exists( &targets
, deps
.str
[i
] ))
2097 deps
.str
[i
] = obj_dir_path( make
, deps
.str
[i
] );
2099 deps
.str
[i
] = src_dir_path( make
, deps
.str
[i
] );
2105 /*******************************************************************
2108 * Find the makefile that builds the named static library (which may be an import lib).
2110 static struct makefile
*get_static_lib( const char *name
, unsigned int arch
)
2114 for (i
= 0; i
< subdirs
.count
; i
++)
2116 if (submakes
[i
]->importlib
&& !strcmp( submakes
[i
]->importlib
, name
)) return submakes
[i
];
2117 if (!submakes
[i
]->staticlib
) continue;
2118 if (submakes
[i
]->disabled
[arch
]) continue;
2119 if (strncmp( submakes
[i
]->staticlib
, "lib", 3 )) continue;
2120 if (strncmp( submakes
[i
]->staticlib
+ 3, name
, strlen(name
) )) continue;
2121 if (strcmp( submakes
[i
]->staticlib
+ 3 + strlen(name
), ".a" )) continue;
2128 /*******************************************************************
2129 * get_native_unix_lib
2131 static const char *get_native_unix_lib( const struct makefile
*make
, const char *name
)
2133 if (!make
->unixlib
) return NULL
;
2134 if (strncmp( make
->unixlib
, name
, strlen(name
) )) return NULL
;
2135 if (make
->unixlib
[strlen(name
)] != '.') return NULL
;
2136 return obj_dir_path( make
, make
->unixlib
);
2140 /*******************************************************************
2141 * get_parent_makefile
2143 static struct makefile
*get_parent_makefile( struct makefile
*make
)
2148 if (!make
->obj_dir
) return NULL
;
2149 dir
= xstrdup( make
->obj_dir
);
2150 if (!(p
= strrchr( dir
, '/' ))) return NULL
;
2152 for (i
= 0; i
< subdirs
.count
; i
++)
2153 if (!strcmp( submakes
[i
]->obj_dir
, dir
)) return submakes
[i
];
2158 /*******************************************************************
2161 static int needs_delay_lib( const struct makefile
*make
, unsigned int arch
)
2163 if (delay_load_flags
[arch
]) return 0;
2164 if (!make
->importlib
) return 0;
2165 return strarray_exists( &delay_import_libs
, make
->importlib
);
2169 /*******************************************************************
2170 * add_unix_libraries
2172 static struct strarray
add_unix_libraries( const struct makefile
*make
, struct strarray
*deps
)
2174 struct strarray ret
= empty_strarray
;
2175 struct strarray all_libs
= empty_strarray
;
2178 if (strcmp( make
->unixlib
, "ntdll.so" )) strarray_add( &all_libs
, "-lntdll" );
2179 strarray_addall( &all_libs
, get_expanded_make_var_array( make
, "UNIX_LIBS" ));
2181 for (i
= 0; i
< all_libs
.count
; i
++)
2183 const char *lib
= NULL
;
2185 if (!strncmp( all_libs
.str
[i
], "-l", 2 ))
2187 for (j
= 0; j
< subdirs
.count
; j
++)
2189 if (make
== submakes
[j
]) continue;
2190 if ((lib
= get_native_unix_lib( submakes
[j
], all_libs
.str
[i
] + 2 ))) break;
2195 strarray_add( deps
, lib
);
2196 strarray_add( &ret
, lib
);
2198 else strarray_add( &ret
, all_libs
.str
[i
] );
2201 strarray_addall( &ret
, libs
);
2206 /*******************************************************************
2209 static int is_crt_module( const char *file
)
2211 return !strncmp( file
, "msvcr", 5 ) || !strncmp( file
, "ucrt", 4 ) || !strcmp( file
, "crtdll.dll" );
2215 /*******************************************************************
2218 static const char *get_default_crt( const struct makefile
*make
)
2220 if (make
->module
&& is_crt_module( make
->module
)) return NULL
; /* don't add crt import to crt dlls */
2221 return !make
->testdll
&& (!make
->staticlib
|| make
->extlib
) ? "ucrtbase" : "msvcrt";
2225 /*******************************************************************
2228 static const char *get_crt_define( const struct makefile
*make
)
2230 const char *crt_dll
= NULL
;
2231 unsigned int i
, version
= 0;
2233 for (i
= 0; i
< make
->imports
.count
; i
++)
2235 if (!is_crt_module( make
->imports
.str
[i
] )) continue;
2236 if (crt_dll
) fatal_error( "More than one C runtime DLL imported: %s and %s\n",
2237 crt_dll
, make
->imports
.str
[i
] );
2238 crt_dll
= make
->imports
.str
[i
];
2243 if (strarray_exists( &make
->extradllflags
, "-nodefaultlibs" )) return "-D_MSVCR_VER=0";
2244 if (!(crt_dll
= get_default_crt( make
))) crt_dll
= make
->module
;
2246 if (!strncmp( crt_dll
, "ucrt", 4 )) return "-D_UCRT";
2247 sscanf( crt_dll
, "msvcr%u", &version
);
2248 return strmake( "-D_MSVCR_VER=%u", version
);
2252 /*******************************************************************
2253 * get_default_imports
2255 static struct strarray
get_default_imports( const struct makefile
*make
, struct strarray imports
)
2257 struct strarray ret
= empty_strarray
;
2258 const char *crt_dll
= get_default_crt( make
);
2261 for (i
= 0; i
< imports
.count
; i
++)
2262 if (is_crt_module( imports
.str
[i
] ))
2263 crt_dll
= imports
.str
[i
];
2265 strarray_add( &ret
, "winecrt0" );
2266 if (crt_dll
) strarray_add( &ret
, crt_dll
);
2268 if (make
->is_win16
&& (!make
->importlib
|| strcmp( make
->importlib
, "kernel" )))
2269 strarray_add( &ret
, "kernel" );
2271 strarray_add( &ret
, "kernel32" );
2272 strarray_add( &ret
, "ntdll" );
2279 IMPORT_TYPE_DELAYED
,
2280 IMPORT_TYPE_DEFAULT
,
2283 /*******************************************************************
2286 static struct strarray
add_import_libs( const struct makefile
*make
, struct strarray
*deps
,
2287 struct strarray imports
, enum import_type type
, unsigned int arch
)
2289 struct strarray ret
= empty_strarray
;
2292 if (native_archs
[arch
]) arch
= native_archs
[arch
];
2294 for (i
= 0; i
< imports
.count
; i
++)
2296 const char *name
= imports
.str
[i
];
2297 struct makefile
*submake
;
2299 /* add crt import lib only when adding the default imports libs */
2300 if (is_crt_module( imports
.str
[i
] ) && type
!= IMPORT_TYPE_DEFAULT
) continue;
2306 case 'L': strarray_add( &ret
, name
); continue;
2307 case 'l': name
+= 2; break;
2311 else name
= get_base_name( name
);
2313 if ((submake
= get_static_lib( name
, arch
)))
2315 const char *ext
= (type
== IMPORT_TYPE_DELAYED
&& !delay_load_flags
[arch
]) ? ".delay.a" : ".a";
2316 const char *lib
= obj_dir_path( submake
, strmake( "%slib%s%s", arch_dirs
[arch
], name
, ext
));
2317 strarray_add_uniq( deps
, lib
);
2318 strarray_add( &ret
, lib
);
2320 else strarray_add( &ret
, strmake( "-l%s", name
));
2326 /*******************************************************************
2329 static void add_install_rule( struct makefile
*make
, const char *target
, unsigned int arch
,
2330 const char *file
, const char *dest
)
2334 if (make
->disabled
[arch
]) return;
2336 for (i
= 0; i
< NB_INSTALL_RULES
; i
++)
2338 if (strarray_exists( &make
->install
[i
], target
) ||
2339 strarray_exists( &top_install
[i
], make
->obj_dir
) ||
2340 strarray_exists( &top_install
[i
], obj_dir_path( make
, target
)))
2342 strarray_add( &make
->install_rules
[i
], file
);
2343 strarray_add( &make
->install_rules
[i
], dest
);
2350 /*******************************************************************
2351 * get_include_install_path
2353 * Determine the installation path for a given include file.
2355 static const char *get_include_install_path( const char *name
)
2357 if (!strncmp( name
, "wine/", 5 )) return name
+ 5;
2358 if (!strncmp( name
, "msvcrt/", 7 )) return name
;
2359 return strmake( "windows/%s", name
);
2363 /*******************************************************************
2364 * get_source_defines
2366 static struct strarray
get_source_defines( struct makefile
*make
, struct incl_file
*source
,
2370 struct strarray ret
= empty_strarray
;
2372 strarray_addall( &ret
, make
->include_args
);
2373 if (source
->use_msvcrt
)
2375 strarray_add( &ret
, strmake( "-I%s", root_src_dir_path( "include/msvcrt" )));
2376 for (i
= 0; i
< make
->include_paths
.count
; i
++)
2377 strarray_add( &ret
, strmake( "-I%s", make
->include_paths
.str
[i
] ));
2378 strarray_add( &ret
, get_crt_define( make
));
2380 strarray_addall( &ret
, make
->define_args
);
2381 strarray_addall( &ret
, get_expanded_file_local_var( make
, obj
, "EXTRADEFS" ));
2386 /*******************************************************************
2387 * remove_warning_flags
2389 static struct strarray
remove_warning_flags( struct strarray flags
)
2392 struct strarray ret
= empty_strarray
;
2394 for (i
= 0; i
< flags
.count
; i
++)
2395 if (strncmp( flags
.str
[i
], "-W", 2 ) || !strncmp( flags
.str
[i
], "-Wno-", 5 ))
2396 strarray_add( &ret
, flags
.str
[i
] );
2401 /*******************************************************************
2404 static const char *get_debug_file( struct makefile
*make
, const char *name
, unsigned int arch
)
2406 const char *debug_file
= NULL
;
2407 if (!debug_flags
[arch
]) return NULL
;
2408 if (!strcmp( debug_flags
[arch
], "pdb" )) debug_file
= strmake( "%s.pdb", get_base_name( name
));
2409 else if (!strncmp( debug_flags
[arch
], "split", 5 )) debug_file
= strmake( "%s.debug", name
);
2410 if (debug_file
) strarray_add( &make
->debug_files
, debug_file
);
2415 /*******************************************************************
2418 static const char *cmd_prefix( const char *cmd
)
2420 if (!silent_rules
) return "";
2421 return strmake( "$(quiet_%s)", cmd
);
2425 /*******************************************************************
2426 * output_winegcc_command
2428 static void output_winegcc_command( struct makefile
*make
, unsigned int arch
)
2430 output( "\t%s%s -o $@", cmd_prefix( "CCLD" ), tools_path( make
, "winegcc" ));
2431 output_filename( "--wine-objdir ." );
2434 output_filename( "--winebuild" );
2435 output_filename( tools_path( make
, "winebuild" ));
2437 output_filenames( target_flags
[arch
] );
2438 if (native_archs
[arch
] && !make
->disabled
[native_archs
[arch
]])
2439 output_filenames( hybrid_target_flags
[arch
] );
2441 output_filename( "-mno-cygwin" );
2442 output_filenames( lddll_flags
);
2446 /*******************************************************************
2447 * output_symlink_rule
2449 * Output a rule to create a symlink.
2451 static void output_symlink_rule( const char *src_name
, const char *link_name
, int create_dir
)
2453 const char *name
= strrchr( link_name
, '/' );
2458 dir
= xstrdup( link_name
);
2459 dir
[name
- link_name
] = 0;
2462 output( "\t%s", cmd_prefix( "LN" ));
2463 if (create_dir
&& dir
&& *dir
) output( "%s -d %s && ", root_src_dir_path( "tools/install-sh" ), dir
);
2464 output( "rm -f %s && ", link_name
);
2466 /* dest path with a directory needs special handling if ln -s isn't supported */
2467 if (dir
&& strcmp( ln_s
, "ln -s" ))
2468 output( "cd %s && %s %s %s\n", *dir
? dir
: "/", ln_s
, src_name
, name
+ 1 );
2470 output( "%s %s %s\n", ln_s
, src_name
, link_name
);
2476 /*******************************************************************
2477 * output_srcdir_symlink
2479 * Output rule to create a symlink back to the source directory, for source files
2480 * that are needed at run-time.
2482 static void output_srcdir_symlink( struct makefile
*make
, const char *obj
)
2484 char *src_file
, *dst_file
, *src_name
;
2486 if (!make
->src_dir
) return;
2487 src_file
= src_dir_path( make
, obj
);
2488 dst_file
= obj_dir_path( make
, obj
);
2489 output( "%s: %s\n", dst_file
, src_file
);
2491 src_name
= src_file
;
2492 if (src_name
[0] != '/' && make
->obj_dir
)
2493 src_name
= concat_paths( get_relative_path( make
->obj_dir
, "" ), src_name
);
2495 output_symlink_rule( src_name
, dst_file
, 0 );
2496 strarray_add( &make
->all_targets
[0], obj
);
2500 /*******************************************************************
2501 * output_install_commands
2503 static void output_install_commands( struct makefile
*make
, struct strarray files
)
2505 unsigned int i
, arch
;
2506 char *install_sh
= root_src_dir_path( "tools/install-sh" );
2508 for (i
= 0; i
< files
.count
; i
+= 2)
2510 const char *file
= files
.str
[i
];
2511 const char *dest
= strmake( "$(DESTDIR)%s", files
.str
[i
+ 1] + 1 );
2512 char type
= *files
.str
[i
+ 1];
2516 case '1': case '2': case '3': case '4': case '5':
2517 case '6': case '7': case '8': case '9': /* arch-dependent program */
2519 output( "\tSTRIPPROG=%s %s -m 644 $(INSTALL_PROGRAM_FLAGS) %s %s\n",
2520 strip_progs
[arch
], install_sh
, obj_dir_path( make
, file
), dest
);
2521 output( "\t%s --builtin %s\n", tools_path( make
, "winebuild" ), dest
);
2523 case 'd': /* data file */
2524 output( "\t%s -m 644 $(INSTALL_DATA_FLAGS) %s %s\n",
2525 install_sh
, obj_dir_path( make
, file
), dest
);
2527 case 'D': /* data file in source dir */
2528 output( "\t%s -m 644 $(INSTALL_DATA_FLAGS) %s %s\n",
2529 install_sh
, src_dir_path( make
, file
), dest
);
2531 case '0': /* native arch program file */
2532 case 'p': /* program file */
2533 output( "\tSTRIPPROG=\"$(STRIP)\" %s $(INSTALL_PROGRAM_FLAGS) %s %s\n",
2534 install_sh
, obj_dir_path( make
, file
), dest
);
2536 case 's': /* script */
2537 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s %s\n",
2538 install_sh
, obj_dir_path( make
, file
), dest
);
2540 case 'S': /* script in source dir */
2541 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s %s\n",
2542 install_sh
, src_dir_path( make
, file
), dest
);
2544 case 't': /* script in tools dir */
2545 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s %s\n",
2546 install_sh
, tools_dir_path( make
, files
.str
[i
] ), dest
);
2548 case 'y': /* symlink */
2549 output_symlink_rule( files
.str
[i
], dest
, 1 );
2554 strarray_add( &make
->uninstall_files
, dest
);
2559 /*******************************************************************
2560 * output_install_rules
2562 * Rules are stored as a (file,dest) pair of values.
2563 * The first char of dest indicates the type of install.
2565 static void output_install_rules( struct makefile
*make
, enum install_rules rules
)
2568 struct strarray files
= make
->install_rules
[rules
];
2569 struct strarray targets
= empty_strarray
;
2571 if (!files
.count
) return;
2573 for (i
= 0; i
< files
.count
; i
+= 2)
2575 const char *file
= files
.str
[i
];
2576 switch (*files
.str
[i
+ 1])
2578 case '0': case '1': case '2': case '3': case '4':
2579 case '5': case '6': case '7': case '8': case '9': /* arch-dependent program */
2580 case 'd': /* data file */
2581 case 'p': /* program file */
2582 case 's': /* script */
2583 strarray_add_uniq( &targets
, obj_dir_path( make
, file
));
2585 case 't': /* script in tools dir */
2586 strarray_add_uniq( &targets
, tools_dir_path( make
, file
));
2591 output( "%s %s::", obj_dir_path( make
, "install" ), obj_dir_path( make
, install_targets
[rules
] ));
2592 output_filenames( targets
);
2594 output_install_commands( make
, files
);
2595 strarray_add_uniq( &make
->phony_targets
, obj_dir_path( make
, "install" ));
2596 strarray_add_uniq( &make
->phony_targets
, obj_dir_path( make
, install_targets
[rules
] ));
2600 static int cmp_string_length( const char **a
, const char **b
)
2602 int paths_a
= 0, paths_b
= 0;
2605 for (p
= *a
; *p
; p
++) if (*p
== '/') paths_a
++;
2606 for (p
= *b
; *p
; p
++) if (*p
== '/') paths_b
++;
2607 if (paths_b
!= paths_a
) return paths_b
- paths_a
;
2608 return strcmp( *a
, *b
);
2611 /*******************************************************************
2612 * get_removable_dirs
2614 * Retrieve a list of directories to try to remove after deleting the files.
2616 static struct strarray
get_removable_dirs( struct strarray files
)
2618 struct strarray dirs
= empty_strarray
;
2621 for (i
= 0; i
< files
.count
; i
++)
2623 char *dir
= xstrdup( files
.str
[i
] );
2624 while (strchr( dir
, '/' ))
2626 *strrchr( dir
, '/' ) = 0;
2627 strarray_add_uniq( &dirs
, xstrdup(dir
) );
2630 strarray_qsort( &dirs
, cmp_string_length
);
2635 /*******************************************************************
2636 * output_uninstall_rules
2638 static void output_uninstall_rules( struct makefile
*make
)
2640 static const char *dirs_order
[] =
2641 { "$(includedir)", "$(mandir)", "$(fontdir)", "$(nlsdir)", "$(datadir)", "$(dlldir)" };
2643 struct strarray uninstall_dirs
;
2646 if (!make
->uninstall_files
.count
) return;
2647 output( "uninstall::\n" );
2648 output_rm_filenames( make
->uninstall_files
, "rm -f" );
2649 strarray_add_uniq( &make
->phony_targets
, "uninstall" );
2651 if (!subdirs
.count
) return;
2652 uninstall_dirs
= get_removable_dirs( make
->uninstall_files
);
2653 output( "\t-rmdir" );
2654 for (i
= 0; i
< ARRAY_SIZE(dirs_order
); i
++)
2656 for (j
= 0; j
< uninstall_dirs
.count
; j
++)
2658 if (!uninstall_dirs
.str
[j
]) continue;
2659 if (strncmp( uninstall_dirs
.str
[j
] + strlen("$(DESTDIR)"), dirs_order
[i
], strlen(dirs_order
[i
]) ))
2661 output_filename( uninstall_dirs
.str
[j
] );
2662 uninstall_dirs
.str
[j
] = NULL
;
2665 for (j
= 0; j
< uninstall_dirs
.count
; j
++)
2666 if (uninstall_dirs
.str
[j
]) output_filename( uninstall_dirs
.str
[j
] );
2671 /*******************************************************************
2674 static void output_po_files( struct makefile
*make
)
2676 const char *po_dir
= src_dir_path( make
, "po" );
2681 for (i
= 0; i
< linguas
.count
; i
++)
2682 output_filename( strmake( "%s/%s.po", po_dir
, linguas
.str
[i
] ));
2683 output( ": %s/wine.pot\n", po_dir
);
2684 output( "\t%smsgmerge --previous -q $@ %s/wine.pot | msgattrib --no-obsolete -o $@.new && mv $@.new $@\n",
2685 cmd_prefix( "MSG" ), po_dir
);
2686 output( "po/all:" );
2687 for (i
= 0; i
< linguas
.count
; i
++)
2688 output_filename( strmake( "%s/%s.po", po_dir
, linguas
.str
[i
] ));
2691 output( "%s/wine.pot:", po_dir
);
2692 output_filenames( make
->pot_files
);
2694 output( "\t%smsgcat -o $@", cmd_prefix( "MSG" ));
2695 output_filenames( make
->pot_files
);
2697 strarray_add( &make
->maintainerclean_files
, strmake( "%s/wine.pot", po_dir
));
2701 /*******************************************************************
2704 static void output_source_y( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2706 char *header
= strmake( "%s.tab.h", obj
);
2708 if (find_include_file( make
, header
))
2710 output( "%s: %s\n", obj_dir_path( make
, header
), source
->filename
);
2711 output( "\t%s%s -o %s.tab.$$$$.c --defines=$@ %s && rm -f %s.tab.$$$$.c\n",
2712 cmd_prefix( "BISON" ), bison
, obj_dir_path( make
, obj
),
2713 source
->filename
, obj_dir_path( make
, obj
));
2714 strarray_add( &make
->clean_files
, header
);
2716 output( "%s.tab.c: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2717 output( "\t%s%s -o $@ %s\n", cmd_prefix( "BISON" ), bison
, source
->filename
);
2721 /*******************************************************************
2724 static void output_source_l( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2726 output( "%s.yy.c: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2727 output( "\t%s%s -o$@ %s\n", cmd_prefix( "FLEX" ), flex
, source
->filename
);
2731 /*******************************************************************
2734 static void output_source_h( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2736 if (source
->file
->flags
& FLAG_GENERATED
)
2737 strarray_add( &make
->all_targets
[0], source
->name
);
2738 else if ((source
->file
->flags
& FLAG_INSTALL
) || strncmp( source
->name
, "wine/", 5 ))
2739 add_install_rule( make
, source
->name
, 0, source
->name
,
2740 strmake( "D$(includedir)/wine/%s", get_include_install_path( source
->name
) ));
2744 /*******************************************************************
2747 static void output_source_rc( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2749 struct strarray defines
= get_source_defines( make
, source
, obj
);
2750 const char *po_dir
= NULL
, *res_file
= strmake( "%s.res", obj
);
2751 unsigned int i
, arch
;
2753 if (source
->file
->flags
& FLAG_RC_HEADER
) return;
2754 if (source
->file
->flags
& FLAG_GENERATED
) strarray_add( &make
->clean_files
, source
->name
);
2755 if (linguas
.count
&& (source
->file
->flags
& FLAG_RC_PO
)) po_dir
= "po";
2756 if (!(source
->file
->flags
& FLAG_TESTDLL
))
2758 for (arch
= 0; arch
< archs
.count
; arch
++)
2759 if (!make
->disabled
[arch
]) strarray_add( &make
->res_files
[arch
], res_file
);
2761 else strarray_add( &make
->clean_files
, res_file
);
2763 if (source
->file
->flags
& FLAG_RC_PO
)
2765 strarray_add( &make
->pot_files
, strmake( "%s.pot", obj
));
2766 output( "%s.pot ", obj_dir_path( make
, obj
) );
2768 output( "%s: %s", obj_dir_path( make
, res_file
), source
->filename
);
2769 output_filename( tools_path( make
, "wrc" ));
2770 if (make
->src_dir
) output_filename( "nls/locale.nls" );
2771 output_filenames( source
->dependencies
);
2773 output( "\t%s%s -u -o $@", cmd_prefix( "WRC" ), tools_path( make
, "wrc" ) );
2774 if (make
->is_win16
) output_filename( "-m16" );
2775 output_filename( "--nostdinc" );
2776 if (po_dir
) output_filename( strmake( "--po-dir=%s", po_dir
));
2777 output_filenames( defines
);
2778 output_filename( source
->filename
);
2782 output( "%s:", obj_dir_path( make
, res_file
));
2783 for (i
= 0; i
< linguas
.count
; i
++)
2784 output_filename( strmake( "%s/%s.mo", po_dir
, linguas
.str
[i
] ));
2790 /*******************************************************************
2793 static void output_source_mc( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2795 unsigned int i
, arch
;
2796 char *obj_path
= obj_dir_path( make
, obj
);
2797 char *res_file
= strmake( "%s.res", obj
);
2799 for (arch
= 0; arch
< archs
.count
; arch
++)
2800 if (!make
->disabled
[arch
]) strarray_add( &make
->res_files
[arch
], res_file
);
2801 strarray_add( &make
->pot_files
, strmake( "%s.pot", obj
));
2802 output( "%s.pot %s.res: %s", obj_path
, obj_path
, source
->filename
);
2803 output_filename( tools_path( make
, "wmc" ));
2804 output_filenames( source
->dependencies
);
2805 if (make
->src_dir
) output_filename( "nls/locale.nls" );
2807 output( "\t%s%s -u -o $@ %s", cmd_prefix( "WMC" ), tools_path( make
, "wmc" ), source
->filename
);
2810 output_filename( "--po-dir=po" );
2812 output( "%s.res:", obj_dir_path( make
, obj
));
2813 for (i
= 0; i
< linguas
.count
; i
++)
2814 output_filename( strmake( "po/%s.mo", linguas
.str
[i
] ));
2820 /*******************************************************************
2823 static void output_source_res( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2825 if (make
->disabled
[source
->arch
]) return;
2826 strarray_add( &make
->res_files
[source
->arch
], source
->name
);
2830 /*******************************************************************
2833 static void output_source_idl( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2835 struct strarray defines
= get_source_defines( make
, source
, obj
);
2836 struct strarray headers
= empty_strarray
;
2837 struct strarray deps
= empty_strarray
;
2838 struct strarray multiarch_targets
[MAX_ARCHS
] = { empty_strarray
};
2840 unsigned int i
, arch
;
2842 if (find_include_file( make
, strmake( "%s.h", obj
))) source
->file
->flags
|= FLAG_IDL_HEADER
;
2843 if (!source
->file
->flags
) return;
2845 if (source
->file
->flags
& FLAG_IDL_PROXY
) strarray_add( &make
->dlldata_files
, source
->name
);
2846 if (source
->file
->flags
& FLAG_INSTALL
)
2848 add_install_rule( make
, source
->name
, 0, xstrdup( source
->name
),
2849 strmake( "D$(includedir)/wine/%s.idl", get_include_install_path( obj
) ));
2850 if (source
->file
->flags
& FLAG_IDL_HEADER
)
2851 add_install_rule( make
, source
->name
, 0, strmake( "%s.h", obj
),
2852 strmake( "d$(includedir)/wine/%s.h", get_include_install_path( obj
) ));
2854 if (source
->file
->flags
& FLAG_IDL_HEADER
)
2856 dest
= strmake( "%s.h", obj
);
2857 strarray_add( &headers
, dest
);
2858 if (!find_src_file( make
, dest
)) strarray_add( &make
->clean_files
, dest
);
2861 for (i
= 0; i
< ARRAY_SIZE(idl_outputs
); i
++)
2863 if (!(source
->file
->flags
& idl_outputs
[i
].flag
)) continue;
2864 for (arch
= 0; arch
< archs
.count
; arch
++)
2866 if (!is_multiarch( arch
)) continue;
2867 if (make
->disabled
[arch
]) continue;
2868 dest
= strmake( "%s%s%s", arch_dirs
[arch
], obj
, idl_outputs
[i
].ext
);
2869 if (!find_src_file( make
, dest
)) strarray_add( &make
->clean_files
, dest
);
2870 strarray_add( &multiarch_targets
[arch
], dest
);
2874 for (arch
= 0; arch
< archs
.count
; arch
++)
2876 struct strarray arch_deps
= empty_strarray
;
2878 if (!arch
) strarray_addall( &arch_deps
, headers
);
2879 strarray_addall( &arch_deps
, multiarch_targets
[arch
] );
2880 if (!arch_deps
.count
) continue;
2881 output_filenames_obj_dir( make
, arch_deps
);
2883 output( "\t%s%s -o $@", cmd_prefix( "WIDL" ), tools_path( make
, "widl" ) );
2884 output_filenames( target_flags
[arch
] );
2885 output_filename( "--nostdinc" );
2886 output_filename( "-Ldlls/\\*" );
2887 output_filenames( defines
);
2888 output_filenames( get_expanded_make_var_array( make
, "EXTRAIDLFLAGS" ));
2889 output_filenames( get_expanded_file_local_var( make
, obj
, "EXTRAIDLFLAGS" ));
2890 if (arch
) output_filenames( get_expanded_arch_var_array( make
, "EXTRAIDLFLAGS", arch
));
2891 output_filename( source
->filename
);
2893 strarray_addall( &deps
, arch_deps
);
2898 output_filenames_obj_dir( make
, deps
);
2900 output_filename( tools_path( make
, "widl" ));
2901 output_filename( source
->filename
);
2902 output_filenames( source
->dependencies
);
2906 if (source
->importlibdeps
.count
)
2908 for (arch
= 0; arch
< archs
.count
; arch
++)
2910 if (!multiarch_targets
[arch
].count
) continue;
2911 output_filenames_obj_dir( make
, multiarch_targets
[arch
] );
2913 for (i
= 0; i
< source
->importlibdeps
.count
; i
++)
2915 int native_arch
= native_archs
[arch
] ? native_archs
[arch
] : arch
;
2916 struct makefile
*submake
= find_importlib_module( source
->importlibdeps
.str
[i
] );
2917 const char *module
= strmake( "%s%s", arch_pe_dirs
[native_arch
], submake
->module
);
2918 output_filename( obj_dir_path( submake
, module
));
2926 /*******************************************************************
2929 static void output_source_x( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2931 output( "%s.h: %s%s %s\n", obj_dir_path( make
, obj
),
2932 tools_dir_path( make
, "make_xftmpl" ), tools_ext
, source
->filename
);
2933 output( "\t%s%s%s -H -o $@ %s\n", cmd_prefix( "GEN" ),
2934 tools_dir_path( make
, "make_xftmpl" ), tools_ext
, source
->filename
);
2935 if (source
->file
->flags
& FLAG_INSTALL
)
2937 add_install_rule( make
, source
->name
, 0, source
->name
,
2938 strmake( "D$(includedir)/wine/%s", get_include_install_path( source
->name
) ));
2939 add_install_rule( make
, source
->name
, 0, strmake( "%s.h", obj
),
2940 strmake( "d$(includedir)/wine/%s.h", get_include_install_path( obj
) ));
2945 /*******************************************************************
2948 static void output_source_sfd( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2951 char *ttf_obj
= strmake( "%s.ttf", obj
);
2952 char *ttf_file
= src_dir_path( make
, ttf_obj
);
2954 if (fontforge
&& !make
->src_dir
)
2956 output( "%s: %s\n", ttf_file
, source
->filename
);
2957 output( "\t%s%s -script %s %s $@\n", cmd_prefix( "GEN" ),
2958 fontforge
, root_src_dir_path( "fonts/genttf.ff" ), source
->filename
);
2959 if (!(source
->file
->flags
& FLAG_SFD_FONTS
)) strarray_add( &make
->font_files
, ttf_obj
);
2960 strarray_add( &make
->maintainerclean_files
, ttf_obj
);
2962 if (source
->file
->flags
& FLAG_INSTALL
)
2964 add_install_rule( make
, source
->name
, 0, ttf_obj
, strmake( "D$(fontdir)/%s", ttf_obj
));
2965 output_srcdir_symlink( make
, ttf_obj
);
2968 if (source
->file
->flags
& FLAG_SFD_FONTS
)
2970 struct strarray
*array
= source
->file
->args
;
2972 for (i
= 0; i
< array
->count
; i
++)
2974 char *font
= strtok( xstrdup(array
->str
[i
]), " \t" );
2975 char *args
= strtok( NULL
, "" );
2977 strarray_add( &make
->all_targets
[0], xstrdup( font
));
2978 output( "%s: %s %s\n", obj_dir_path( make
, font
),
2979 tools_path( make
, "sfnt2fon" ), ttf_file
);
2980 output( "\t%s%s -q -o $@ %s %s\n", cmd_prefix( "GEN" ),
2981 tools_path( make
, "sfnt2fon" ), ttf_file
, args
);
2982 add_install_rule( make
, source
->name
, 0, xstrdup(font
), strmake( "d$(fontdir)/%s", font
));
2988 /*******************************************************************
2991 static void output_source_svg( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2993 static const char * const images
[] = { "bmp", "cur", "ico", NULL
};
2996 if (convert
&& rsvg
&& icotool
)
2998 for (i
= 0; images
[i
]; i
++)
2999 if (find_include_file( make
, strmake( "%s.%s", obj
, images
[i
] ))) break;
3003 output( "%s.%s: %s\n", src_dir_path( make
, obj
), images
[i
], source
->filename
);
3004 output( "\t%sCONVERT=\"%s\" ICOTOOL=\"%s\" RSVG=\"%s\" %s %s $@\n",
3005 cmd_prefix( "GEN" ), convert
, icotool
, rsvg
,
3006 root_src_dir_path( "tools/buildimage" ), source
->filename
);
3007 strarray_add( &make
->maintainerclean_files
, strmake( "%s.%s", obj
, images
[i
] ));
3013 /*******************************************************************
3016 static void output_source_nls( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
3018 add_install_rule( make
, source
->name
, 0, source
->name
,
3019 strmake( "D$(nlsdir)/%s", source
->name
));
3020 output_srcdir_symlink( make
, strmake( "%s.nls", obj
));
3024 /*******************************************************************
3025 * output_source_desktop
3027 static void output_source_desktop( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
3029 add_install_rule( make
, source
->name
, 0, source
->name
,
3030 strmake( "D$(datadir)/applications/%s", source
->name
));
3034 /*******************************************************************
3037 static void output_source_po( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
3039 output( "%s.mo: %s\n", obj_dir_path( make
, obj
), source
->filename
);
3040 output( "\t%s%s -o $@ %s\n", cmd_prefix( "MSG" ), msgfmt
, source
->filename
);
3041 strarray_add( &make
->all_targets
[0], strmake( "%s.mo", obj
));
3045 /*******************************************************************
3048 static void output_source_in( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
3052 if (make
== include_makefile
) return; /* ignore generated includes */
3053 if (strendswith( obj
, ".man" ) && source
->file
->args
)
3055 struct strarray symlinks
;
3056 char *dir
, *dest
= replace_extension( obj
, ".man", "" );
3057 char *lang
= strchr( dest
, '.' );
3058 char *section
= source
->file
->args
;
3062 dir
= strmake( "$(mandir)/%s/man%s", lang
, section
);
3064 else dir
= strmake( "$(mandir)/man%s", section
);
3065 add_install_rule( make
, dest
, 0, obj
, strmake( "d%s/%s.%s", dir
, dest
, section
));
3066 symlinks
= get_expanded_file_local_var( make
, dest
, "SYMLINKS" );
3067 for (i
= 0; i
< symlinks
.count
; i
++)
3068 add_install_rule( make
, symlinks
.str
[i
], 0, strmake( "%s.%s", dest
, section
),
3069 strmake( "y%s/%s.%s", dir
, symlinks
.str
[i
], section
));
3073 strarray_add( &make
->in_files
, obj
);
3074 strarray_add( &make
->all_targets
[0], obj
);
3075 output( "%s: %s\n", obj_dir_path( make
, obj
), source
->filename
);
3076 output( "\t%s%s %s >$@ || (rm -f $@ && false)\n", cmd_prefix( "SED" ), sed_cmd
, source
->filename
);
3077 output( "%s:", obj_dir_path( make
, obj
));
3078 output_filenames( source
->dependencies
);
3080 add_install_rule( make
, obj
, 0, obj
, strmake( "d$(datadir)/wine/%s", obj
));
3084 /*******************************************************************
3085 * output_source_spec
3087 static void output_source_spec( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
3093 /*******************************************************************
3094 * output_source_testdll
3096 static void output_source_testdll( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
3098 struct strarray imports
= get_expanded_file_local_var( make
, obj
, "IMPORTS" );
3099 struct strarray dll_flags
= empty_strarray
;
3100 struct strarray default_imports
= empty_strarray
;
3101 struct strarray all_libs
, dep_libs
;
3102 const char *dll_name
, *obj_name
, *res_name
, *output_rsrc
, *output_file
, *debug_file
, *ext
= ".dll";
3103 struct incl_file
*spec_file
= find_src_file( make
, strmake( "%s.spec", obj
));
3104 unsigned int arch
, link_arch
;
3106 if (!imports
.count
) imports
= make
->imports
;
3107 strarray_addall( &dll_flags
, make
->extradllflags
);
3108 strarray_addall( &dll_flags
, get_expanded_file_local_var( make
, obj
, "EXTRADLLFLAGS" ));
3109 if (!strarray_exists( &dll_flags
, "-nodefaultlibs" )) default_imports
= get_default_imports( make
, imports
);
3110 if (strarray_exists( &dll_flags
, "-mconsole" )) ext
= ".exe";
3112 for (arch
= 0; arch
< archs
.count
; arch
++)
3114 const char *hybrid_obj_name
= NULL
;
3116 if (!is_multiarch( arch
) || !get_link_arch( make
, arch
, &link_arch
)) continue;
3118 all_libs
= dep_libs
= empty_strarray
;
3119 strarray_addall( &all_libs
, add_import_libs( make
, &dep_libs
, imports
, IMPORT_TYPE_DIRECT
, arch
) );
3120 strarray_addall( &all_libs
, add_import_libs( make
, &dep_libs
, default_imports
, IMPORT_TYPE_DEFAULT
, arch
) );
3121 if (!arch
) strarray_addall( &all_libs
, libs
);
3122 dll_name
= arch_module_name( strmake( "%s%s", obj
, ext
), arch
);
3123 obj_name
= obj_dir_path( make
, strmake( "%s%s.o", arch_dirs
[arch
], obj
));
3124 if (link_arch
!= arch
)
3125 hybrid_obj_name
= obj_dir_path( make
, strmake( "%s%s.o", arch_dirs
[link_arch
], obj
));
3126 output_file
= obj_dir_path( make
, dll_name
);
3127 output_rsrc
= strmake( "%s.res", dll_name
);
3129 if (!find_src_file( make
, strmake( "%s.rc", obj
) )) res_name
= NULL
;
3130 else res_name
= obj_dir_path( make
, strmake( "%s.res", obj
) );
3132 strarray_add( &make
->clean_files
, dll_name
);
3133 strarray_add( &make
->res_files
[arch
], output_rsrc
);
3134 output( "%s:", obj_dir_path( make
, output_rsrc
));
3135 output_filename( output_file
);
3136 output_filename( tools_path( make
, "wrc" ));
3138 output( "\t%secho \"%s%s TESTDLL \\\"%s\\\"\" | %s -u -o $@\n", cmd_prefix( "WRC" ), obj
, ext
, output_file
,
3139 tools_path( make
, "wrc" ));
3141 output( "%s:", output_file
);
3142 if (spec_file
) output_filename( spec_file
->filename
);
3143 output_filename( obj_name
);
3144 if (hybrid_obj_name
) output_filename( hybrid_obj_name
);
3145 if (res_name
) output_filename( res_name
);
3146 output_filenames( dep_libs
);
3147 output_filename( tools_path( make
, "winebuild" ));
3148 output_filename( tools_path( make
, "winegcc" ));
3150 output_winegcc_command( make
, link_arch
);
3151 output_filename( "-s" );
3152 output_filenames( dll_flags
);
3153 if (link_arch
) output_filenames( get_expanded_arch_var_array( make
, "EXTRADLLFLAGS", link_arch
));
3154 if (!strcmp( ext
, ".dll" )) output_filename( "-shared" );
3155 if (spec_file
) output_filename( spec_file
->filename
);
3156 output_filename( obj_name
);
3157 if (hybrid_obj_name
) output_filename( hybrid_obj_name
);
3158 if (res_name
) output_filename( res_name
);
3159 if ((debug_file
= get_debug_file( make
, dll_name
, link_arch
)))
3160 output_filename( strmake( "-Wl,--debug-file,%s", obj_dir_path( make
, debug_file
)));
3161 output_filenames( all_libs
);
3162 output_filename( arch_make_variable( "LDFLAGS", link_arch
));
3168 /*******************************************************************
3171 static void output_source_xml( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
3173 if (wayland_scanner
)
3175 output( "%s-protocol.c: %s\n", obj_dir_path( make
, obj
), source
->filename
);
3176 output( "\t%s%s private-code %s $@\n", cmd_prefix( "GEN" ), wayland_scanner
, source
->filename
);
3177 output( "%s-client-protocol.h: %s\n", obj_dir_path( make
, obj
), source
->filename
);
3178 output( "\t%s%s client-header %s $@\n", cmd_prefix( "GEN" ), wayland_scanner
, source
->filename
);
3183 /*******************************************************************
3184 * output_source_one_arch
3186 static void output_source_one_arch( struct makefile
*make
, struct incl_file
*source
, const char *obj
,
3187 struct strarray defines
, struct strarray
*targets
,
3190 const char *obj_name
, *var_cc
, *var_cflags
;
3191 struct strarray arch_cflags
= empty_strarray
;
3193 if (make
->disabled
[arch
] && !(source
->file
->flags
& FLAG_C_IMPLIB
)) return;
3197 if (source
->file
->flags
& FLAG_C_UNIX
) return;
3198 if (!is_using_msvcrt( make
) && !make
->staticlib
&& !(source
->file
->flags
& FLAG_C_IMPLIB
)) return;
3200 else if (source
->file
->flags
& FLAG_C_UNIX
)
3202 if (!unix_lib_supported
) return;
3204 else if (archs
.count
> 1 && is_using_msvcrt( make
))
3206 if (!so_dll_supported
) return;
3207 if (!(source
->file
->flags
& FLAG_C_IMPLIB
) && (!make
->staticlib
|| make
->extlib
)) return;
3210 obj_name
= strmake( "%s%s.o", source
->arch
? "" : arch_dirs
[arch
], obj
);
3211 strarray_add( targets
, obj_name
);
3213 if (source
->file
->flags
& FLAG_C_UNIX
)
3214 strarray_add( &make
->unixobj_files
, obj_name
);
3215 else if (source
->file
->flags
& FLAG_C_IMPLIB
)
3216 strarray_add( &make
->implib_files
[arch
], obj_name
);
3217 else if (!(source
->file
->flags
& FLAG_TESTDLL
))
3218 strarray_add( &make
->object_files
[arch
], obj_name
);
3220 strarray_add( &make
->clean_files
, obj_name
);
3222 if ((source
->file
->flags
& FLAG_ARM64EC_X64
) && !strcmp( archs
.str
[arch
], "arm64ec" ))
3224 var_cc
= "$(x86_64_CC)";
3225 var_cflags
= "$(x86_64_CFLAGS)";
3226 strarray_add( &arch_cflags
, "-D__arm64ec_x64__" );
3227 strarray_addall( &arch_cflags
, get_expanded_make_var_array( top_makefile
, "x86_64_EXTRACFLAGS" ));
3231 var_cc
= arch_make_variable( "CC", arch
);
3232 var_cflags
= arch_make_variable( "CFLAGS", arch
);
3233 strarray_addall( &arch_cflags
, make
->extlib
? extra_cflags_extlib
[arch
] : extra_cflags
[arch
] );
3236 output( "%s: %s\n", obj_dir_path( make
, obj_name
), source
->filename
);
3237 output( "\t%s%s -c -o $@ %s", cmd_prefix( "CC" ), var_cc
, source
->filename
);
3238 output_filenames( defines
);
3239 if (!source
->use_msvcrt
) output_filenames( make
->unix_cflags
);
3240 output_filenames( arch_cflags
);
3244 if (source
->file
->flags
& FLAG_C_UNIX
)
3246 output_filenames( unix_dllflags
);
3248 else if (make
->module
|| make
->testdll
)
3250 output_filenames( dll_flags
);
3251 if (source
->use_msvcrt
) output_filenames( msvcrt_flags
);
3252 if (!unix_lib_supported
&& make
->module
&& is_crt_module( make
->module
))
3253 output_filename( "-fno-builtin" );
3258 if (make
->module
&& is_crt_module( make
->module
)) output_filename( "-fno-builtin" );
3261 output_filenames( cpp_flags
);
3262 output_filename( var_cflags
);
3265 if (make
->testdll
&& strendswith( source
->name
, ".c" ) &&
3266 !(source
->file
->flags
& (FLAG_GENERATED
| FLAG_TESTDLL
)))
3268 const char *ok_file
, *test_exe
;
3270 ok_file
= strmake( "%s%s.ok", arch_dirs
[arch
], obj
);
3271 test_exe
= replace_extension( make
->testdll
, ".dll", "_test.exe" );
3272 strarray_add( &make
->ok_files
[arch
], ok_file
);
3273 output( "%s:\n", obj_dir_path( make
, ok_file
));
3274 output( "\t%s%s $(RUNTESTFLAGS) -T . -M %s -p %s %s && touch $@\n",
3275 cmd_prefix( "TEST" ),
3276 root_src_dir_path( "tools/runtest" ), make
->testdll
,
3277 obj_dir_path( make
, arch_module_name( test_exe
, arch
)), obj
);
3282 /*******************************************************************
3283 * output_source_default
3285 static void output_source_default( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
3287 struct strarray defines
= get_source_defines( make
, source
, obj
);
3288 struct strarray targets
= empty_strarray
;
3291 for (arch
= 0; arch
< archs
.count
; arch
++)
3292 if (!source
->arch
|| source
->arch
== arch
)
3293 output_source_one_arch( make
, source
, obj
, defines
, &targets
, arch
);
3295 if (source
->file
->flags
& FLAG_GENERATED
)
3297 if (!make
->testdll
|| !strendswith( source
->filename
, "testlist.c" ))
3298 strarray_add( &make
->clean_files
, source
->basename
);
3300 else if (source
->file
->flags
& FLAG_TESTDLL
)
3302 output_source_testdll( make
, source
, obj
);
3306 if (make
->testdll
&& strendswith( source
->name
, ".c" ))
3307 strarray_add( &make
->test_files
, obj
);
3310 if (targets
.count
&& source
->dependencies
.count
)
3312 output_filenames_obj_dir( make
, targets
);
3314 output_filenames( source
->dependencies
);
3320 /* dispatch table to output rules for a single source file */
3324 void (*fn
)( struct makefile
*make
, struct incl_file
*source
, const char *obj
);
3325 } output_source_funcs
[] =
3327 { "y", output_source_y
},
3328 { "l", output_source_l
},
3329 { "h", output_source_h
},
3330 { "rh", output_source_h
},
3331 { "inl", output_source_h
},
3332 { "rc", output_source_rc
},
3333 { "mc", output_source_mc
},
3334 { "res", output_source_res
},
3335 { "idl", output_source_idl
},
3336 { "sfd", output_source_sfd
},
3337 { "svg", output_source_svg
},
3338 { "nls", output_source_nls
},
3339 { "desktop", output_source_desktop
},
3340 { "po", output_source_po
},
3341 { "in", output_source_in
},
3342 { "x", output_source_x
},
3343 { "spec", output_source_spec
},
3344 { "xml", output_source_xml
},
3345 { NULL
, output_source_default
}
3349 /*******************************************************************
3350 * output_fake_module
3352 static void output_fake_module( struct makefile
*make
, const char *spec_file
)
3354 unsigned int arch
= 0; /* fake modules are always native */
3355 const char *name
= strmake( "%s%s", arch_pe_dirs
[arch
], make
->module
);
3357 if (make
->disabled
[arch
]) return;
3359 strarray_add( &make
->all_targets
[arch
], name
);
3360 add_install_rule( make
, make
->module
, arch
, name
, strmake( "d$(dlldir)/%s", name
));
3362 output( "%s:", obj_dir_path( make
, name
));
3363 if (spec_file
) output_filename( spec_file
);
3364 output_filenames_obj_dir( make
, make
->res_files
[arch
] );
3365 output_filename( tools_path( make
, "winebuild" ));
3366 output_filename( tools_path( make
, "winegcc" ));
3368 output_winegcc_command( make
, arch
);
3369 output_filename( "-Wb,--fake-module" );
3370 if (!make
->is_exe
) output_filename( "-shared" );
3371 if (spec_file
) output_filename( spec_file
);
3372 output_filenames( make
->extradllflags
);
3373 output_filenames_obj_dir( make
, make
->res_files
[arch
] );
3378 /*******************************************************************
3381 static void output_module( struct makefile
*make
, unsigned int arch
)
3383 struct strarray default_imports
= empty_strarray
;
3384 struct strarray all_libs
= empty_strarray
;
3385 struct strarray dep_libs
= empty_strarray
;
3386 struct strarray imports
= make
->imports
;
3387 const char *module_name
;
3388 const char *debug_file
;
3389 char *spec_file
= NULL
;
3390 unsigned int i
, link_arch
;
3392 if (!get_link_arch( make
, arch
, &link_arch
)) return;
3396 if (make
->data_only
|| strarray_exists( &make
->extradllflags
, "-Wl,--subsystem,native" ))
3398 /* spec file is optional */
3399 struct incl_file
*spec
= find_src_file( make
, replace_extension( make
->module
, ".dll", ".spec" ));
3400 if (spec
) spec_file
= spec
->filename
;
3402 else spec_file
= src_dir_path( make
, replace_extension( make
->module
, ".dll", ".spec" ));
3405 if (!make
->data_only
)
3407 module_name
= arch_module_name( make
->module
, arch
);
3409 if (!strarray_exists( &make
->extradllflags
, "-nodefaultlibs" )) default_imports
= get_default_imports( make
, imports
);
3411 strarray_addall( &all_libs
, add_import_libs( make
, &dep_libs
, imports
, IMPORT_TYPE_DIRECT
, arch
));
3412 strarray_addall( &all_libs
, add_import_libs( make
, &dep_libs
, make
->delayimports
, IMPORT_TYPE_DELAYED
, arch
));
3413 strarray_addall( &all_libs
, add_import_libs( make
, &dep_libs
, default_imports
, IMPORT_TYPE_DEFAULT
, arch
) );
3414 if (!arch
) strarray_addall( &all_libs
, libs
);
3416 if (delay_load_flags
[arch
])
3418 for (i
= 0; i
< make
->delayimports
.count
; i
++)
3420 struct makefile
*import
= get_static_lib( make
->delayimports
.str
[i
], arch
);
3421 if (import
) strarray_add( &all_libs
, strmake( "%s%s", delay_load_flags
[arch
], import
->module
));
3425 else module_name
= strmake( "%s%s", arch_pe_dirs
[arch
], make
->module
);
3427 strarray_add( &make
->all_targets
[arch
], module_name
);
3428 if (make
->data_only
)
3429 add_install_rule( make
, make
->module
, arch
, module_name
,
3430 strmake( "d$(dlldir)/%s%s", arch_pe_dirs
[arch
], make
->module
));
3432 add_install_rule( make
, make
->module
, arch
, module_name
,
3433 strmake( "%c%s%s%s", '0' + arch
, arch_install_dirs
[arch
], make
->module
,
3436 output( "%s:", obj_dir_path( make
, module_name
));
3437 if (spec_file
) output_filename( spec_file
);
3438 output_filenames_obj_dir( make
, make
->object_files
[arch
] );
3439 if (link_arch
!= arch
) output_filenames_obj_dir( make
, make
->object_files
[link_arch
] );
3440 output_filenames_obj_dir( make
, make
->res_files
[arch
] );
3441 output_filenames( dep_libs
);
3442 output_filename( tools_path( make
, "winebuild" ));
3443 output_filename( tools_path( make
, "winegcc" ));
3445 output_winegcc_command( make
, link_arch
);
3446 if (arch
) output_filename( "-Wl,--wine-builtin" );
3447 if (!make
->is_exe
) output_filename( "-shared" );
3448 if (spec_file
) output_filename( spec_file
);
3449 output_filenames( make
->extradllflags
);
3450 if (link_arch
) output_filenames( get_expanded_arch_var_array( make
, "EXTRADLLFLAGS", link_arch
));
3451 output_filenames_obj_dir( make
, make
->object_files
[arch
] );
3452 if (link_arch
!= arch
) output_filenames_obj_dir( make
, make
->object_files
[link_arch
] );
3453 output_filenames_obj_dir( make
, make
->res_files
[arch
] );
3454 debug_file
= get_debug_file( make
, module_name
, link_arch
);
3455 if (debug_file
) output_filename( strmake( "-Wl,--debug-file,%s", obj_dir_path( make
, debug_file
)));
3456 output_filenames( all_libs
);
3457 output_filename( arch_make_variable( "LDFLAGS", link_arch
));
3460 if (!make
->data_only
&& !arch
&& unix_lib_supported
) output_fake_module( make
, spec_file
);
3464 /*******************************************************************
3467 static void output_import_lib( struct makefile
*make
, unsigned int arch
)
3469 char *spec_file
= src_dir_path( make
, replace_extension( make
->module
, ".dll", ".spec" ));
3470 const char *name
= strmake( "%slib%s.a", arch_dirs
[arch
], make
->importlib
);
3471 unsigned int hybrid_arch
= hybrid_archs
[arch
];
3473 if (native_archs
[arch
]) return;
3475 strarray_add( &make
->clean_files
, name
);
3476 if (needs_delay_lib( make
, arch
))
3478 const char *delay_name
= replace_extension( name
, ".a", ".delay.a" );
3479 strarray_add( &make
->clean_files
, delay_name
);
3480 output( "%s ", obj_dir_path( make
, delay_name
));
3482 output( "%s: %s %s", obj_dir_path( make
, name
), tools_path( make
, "winebuild" ), spec_file
);
3483 output_filenames_obj_dir( make
, make
->implib_files
[arch
] );
3484 if (hybrid_arch
) output_filenames_obj_dir( make
, make
->implib_files
[hybrid_arch
] );
3486 output( "\t%s%s -w --implib -o $@", cmd_prefix( "BUILD" ), tools_path( make
, "winebuild" ) );
3487 if (!delay_load_flags
[arch
]) output_filename( "--without-dlltool" );
3488 output_filenames( target_flags
[hybrid_arch
? hybrid_arch
: arch
] );
3489 if (make
->is_win16
) output_filename( "-m16" );
3490 if (hybrid_arch
) output_filenames( hybrid_target_flags
[hybrid_arch
] );
3491 output_filename( "--export" );
3492 output_filename( spec_file
);
3493 output_filenames_obj_dir( make
, make
->implib_files
[arch
] );
3494 if (hybrid_arch
) output_filenames_obj_dir( make
, make
->implib_files
[hybrid_arch
] );
3497 add_install_rule( make
, make
->importlib
, arch
, name
,
3498 strmake( "d%slib%s.a", arch_install_dirs
[arch
], make
->importlib
));
3502 /*******************************************************************
3505 static void output_unix_lib( struct makefile
*make
)
3507 struct strarray unix_deps
= empty_strarray
;
3508 struct strarray unix_libs
= add_unix_libraries( make
, &unix_deps
);
3509 unsigned int arch
= 0; /* unix libs are always native */
3511 if (make
->disabled
[arch
]) return;
3513 strarray_add( &make
->all_targets
[arch
], make
->unixlib
);
3514 add_install_rule( make
, make
->module
, arch
, make
->unixlib
,
3515 strmake( "p%s%s", arch_install_dirs
[arch
], make
->unixlib
));
3516 output( "%s:", obj_dir_path( make
, make
->unixlib
));
3517 output_filenames_obj_dir( make
, make
->unixobj_files
);
3518 output_filenames( unix_deps
);
3520 output( "\t%s$(CC) -o $@", cmd_prefix( "CCLD" ));
3521 output_filenames( get_expanded_make_var_array( make
, "UNIXLDFLAGS" ));
3522 output_filenames_obj_dir( make
, make
->unixobj_files
);
3523 output_filenames( unix_libs
);
3524 output_filename( "$(LDFLAGS)" );
3529 /*******************************************************************
3532 static void output_static_lib( struct makefile
*make
, unsigned int arch
)
3534 const char *name
= strmake( "%s%s", arch_dirs
[arch
], make
->staticlib
);
3535 unsigned int hybrid_arch
= hybrid_archs
[arch
];
3537 if (native_archs
[arch
]) return;
3539 strarray_add( &make
->clean_files
, name
);
3540 output( "%s: %s", obj_dir_path( make
, name
), tools_path( make
, "winebuild" ));
3541 output_filenames_obj_dir( make
, make
->object_files
[arch
] );
3542 if (hybrid_arch
) output_filenames_obj_dir( make
, make
->object_files
[hybrid_arch
] );
3543 if (!arch
) output_filenames_obj_dir( make
, make
->unixobj_files
);
3545 output( "\t%s%s -w --staticlib -o $@", cmd_prefix( "BUILD" ), tools_path( make
, "winebuild" ));
3546 output_filenames( target_flags
[hybrid_arch
? hybrid_arch
: arch
] );
3547 output_filenames_obj_dir( make
, make
->object_files
[arch
] );
3548 if (hybrid_arch
) output_filenames_obj_dir( make
, make
->object_files
[hybrid_arch
] );
3549 if (!arch
) output_filenames_obj_dir( make
, make
->unixobj_files
);
3552 add_install_rule( make
, make
->staticlib
, arch
, name
,
3553 strmake( "d%s%s", arch_install_dirs
[arch
], make
->staticlib
));
3557 /*******************************************************************
3558 * output_test_module
3560 static void output_test_module( struct makefile
*make
, unsigned int arch
)
3562 char *basemodule
= replace_extension( make
->testdll
, ".dll", "" );
3563 char *stripped
= arch_module_name( strmake( "%s_test-stripped.exe", basemodule
), arch
);
3564 char *testmodule
= arch_module_name( strmake( "%s_test.exe", basemodule
), arch
);
3565 struct strarray default_imports
= get_default_imports( make
, make
->imports
);
3566 struct strarray dep_libs
= empty_strarray
;
3567 struct strarray all_libs
= empty_strarray
;
3568 struct makefile
*parent
= get_parent_makefile( make
);
3569 const char *debug_file
;
3570 unsigned int link_arch
;
3572 if (!get_link_arch( make
, arch
, &link_arch
)) return;
3574 strarray_addall( &all_libs
, add_import_libs( make
, &dep_libs
, make
->imports
, IMPORT_TYPE_DIRECT
, arch
) );
3575 strarray_addall( &all_libs
, add_import_libs( make
, &dep_libs
, default_imports
, IMPORT_TYPE_DEFAULT
, arch
) );
3577 strarray_add( &make
->all_targets
[arch
], testmodule
);
3578 strarray_add( &make
->clean_files
, stripped
);
3579 output( "%s:\n", obj_dir_path( make
, testmodule
));
3580 output_winegcc_command( make
, link_arch
);
3581 output_filenames( make
->extradllflags
);
3582 output_filenames_obj_dir( make
, make
->object_files
[arch
] );
3583 if (link_arch
!= arch
) output_filenames_obj_dir( make
, make
->object_files
[link_arch
] );
3584 output_filenames_obj_dir( make
, make
->res_files
[arch
] );
3585 if ((debug_file
= get_debug_file( make
, testmodule
, arch
)))
3586 output_filename( strmake( "-Wl,--debug-file,%s", obj_dir_path( make
, debug_file
)));
3587 output_filenames( all_libs
);
3588 output_filename( arch_make_variable( "LDFLAGS", link_arch
));
3590 output( "%s:\n", obj_dir_path( make
, stripped
));
3591 output_winegcc_command( make
, link_arch
);
3592 output_filename( "-s" );
3593 output_filename( strmake( "-Wb,-F,%s_test.exe", basemodule
));
3594 output_filenames( make
->extradllflags
);
3595 output_filenames_obj_dir( make
, make
->object_files
[arch
] );
3596 if (link_arch
!= arch
) output_filenames_obj_dir( make
, make
->object_files
[link_arch
] );
3597 output_filenames_obj_dir( make
, make
->res_files
[arch
] );
3598 output_filenames( all_libs
);
3599 output_filename( arch_make_variable( "LDFLAGS", link_arch
));
3601 output( "%s %s:", obj_dir_path( make
, testmodule
), obj_dir_path( make
, stripped
));
3602 output_filenames_obj_dir( make
, make
->object_files
[arch
] );
3603 if (link_arch
!= arch
) output_filenames_obj_dir( make
, make
->object_files
[link_arch
] );
3604 output_filenames_obj_dir( make
, make
->res_files
[arch
] );
3605 output_filenames( dep_libs
);
3606 output_filename( tools_path( make
, "winebuild" ));
3607 output_filename( tools_path( make
, "winegcc" ));
3610 output( "programs/winetest/%s%s_test.res: %s\n", arch_dirs
[arch
], basemodule
,
3611 obj_dir_path( make
, stripped
));
3612 output( "\t%secho \"%s_test.exe TESTRES \\\"%s\\\"\" | %s -u -o $@\n", cmd_prefix( "WRC" ),
3613 basemodule
, obj_dir_path( make
, stripped
), tools_path( make
, "wrc" ));
3615 if (make
->disabled
[arch
] || (parent
&& parent
->disabled
[arch
]))
3617 make
->ok_files
[arch
] = empty_strarray
;
3620 output_filenames_obj_dir( make
, make
->ok_files
[arch
] );
3621 output( ": %s", obj_dir_path( make
, testmodule
));
3624 char *parent_module
= arch_module_name( make
->testdll
, arch
);
3625 output_filename( obj_dir_path( parent
, parent_module
));
3626 if (parent
->unixlib
) output_filename( obj_dir_path( parent
, parent
->unixlib
));
3629 output( "%s %s:", obj_dir_path( make
, "check" ), obj_dir_path( make
, "test" ));
3630 output_filenames_obj_dir( make
, make
->ok_files
[arch
] );
3632 strarray_add_uniq( &make
->phony_targets
, obj_dir_path( make
, "check" ));
3633 strarray_add_uniq( &make
->phony_targets
, obj_dir_path( make
, "test" ));
3634 output( "%s::\n", obj_dir_path( make
, "testclean" ));
3635 output( "\trm -f" );
3636 output_filenames_obj_dir( make
, make
->ok_files
[arch
] );
3638 strarray_addall( &make
->clean_files
, make
->ok_files
[arch
] );
3639 strarray_add_uniq( &make
->phony_targets
, obj_dir_path( make
, "testclean" ));
3643 /*******************************************************************
3646 static void output_programs( struct makefile
*make
)
3649 unsigned int arch
= 0; /* programs are always native */
3651 for (i
= 0; i
< make
->programs
.count
; i
++)
3653 char *program_installed
= NULL
;
3654 char *program
= strmake( "%s%s", make
->programs
.str
[i
], exe_ext
);
3655 struct strarray deps
= get_local_dependencies( make
, make
->programs
.str
[i
], make
->in_files
);
3656 struct strarray all_libs
= get_expanded_file_local_var( make
, make
->programs
.str
[i
], "LDFLAGS" );
3657 struct strarray objs
= get_expanded_file_local_var( make
, make
->programs
.str
[i
], "OBJS" );
3658 struct strarray symlinks
= get_expanded_file_local_var( make
, make
->programs
.str
[i
], "SYMLINKS" );
3660 if (!objs
.count
) objs
= make
->object_files
[arch
];
3661 if (!strarray_exists( &all_libs
, "-nodefaultlibs" ))
3663 strarray_addall( &all_libs
, get_expanded_make_var_array( make
, "UNIX_LIBS" ));
3664 strarray_addall( &all_libs
, libs
);
3667 output( "%s:", obj_dir_path( make
, program
) );
3668 output_filenames_obj_dir( make
, objs
);
3669 output_filenames( deps
);
3671 output( "\t%s$(CC) -o $@", cmd_prefix( "CCLD" ));
3672 output_filenames_obj_dir( make
, objs
);
3673 output_filenames( all_libs
);
3674 output_filename( "$(LDFLAGS)" );
3676 strarray_add( &make
->all_targets
[arch
], program
);
3678 for (j
= 0; j
< symlinks
.count
; j
++)
3680 output( "%s: %s\n", obj_dir_path( make
, symlinks
.str
[j
] ), obj_dir_path( make
, program
));
3681 output_symlink_rule( program
, obj_dir_path( make
, symlinks
.str
[j
] ), 0 );
3683 strarray_addall( &make
->all_targets
[arch
], symlinks
);
3685 add_install_rule( make
, program
, arch
, program_installed
? program_installed
: program
,
3686 strmake( "p$(bindir)/%s", program
));
3687 for (j
= 0; j
< symlinks
.count
; j
++)
3688 add_install_rule( make
, symlinks
.str
[j
], arch
, program
,
3689 strmake( "y$(bindir)/%s%s", symlinks
.str
[j
], exe_ext
));
3694 /*******************************************************************
3697 static void output_subdirs( struct makefile
*make
)
3699 struct strarray all_targets
= empty_strarray
;
3700 struct strarray makefile_deps
= empty_strarray
;
3701 struct strarray clean_files
= empty_strarray
;
3702 struct strarray testclean_files
= empty_strarray
;
3703 struct strarray distclean_files
= empty_strarray
;
3704 struct strarray distclean_dirs
= empty_strarray
;
3705 struct strarray dependencies
= empty_strarray
;
3706 struct strarray install_deps
[NB_INSTALL_RULES
] = { empty_strarray
};
3707 struct strarray tooldeps_deps
= empty_strarray
;
3708 struct strarray buildtest_deps
= empty_strarray
;
3709 unsigned int i
, j
, arch
;
3711 strarray_addall( &clean_files
, make
->clean_files
);
3712 strarray_addall( &distclean_files
, make
->distclean_files
);
3713 for (arch
= 0; arch
< archs
.count
; arch
++) strarray_addall( &all_targets
, make
->all_targets
[arch
] );
3714 for (i
= 0; i
< subdirs
.count
; i
++)
3716 struct strarray subclean
= empty_strarray
;
3717 strarray_addall( &subclean
, get_removable_dirs( submakes
[i
]->clean_files
));
3718 strarray_addall( &subclean
, get_removable_dirs( submakes
[i
]->distclean_files
));
3719 strarray_add( &makefile_deps
, src_dir_path( submakes
[i
], "Makefile.in" ));
3720 strarray_addall_uniq( &make
->phony_targets
, submakes
[i
]->phony_targets
);
3721 strarray_addall_uniq( &make
->uninstall_files
, submakes
[i
]->uninstall_files
);
3722 strarray_addall_uniq( &dependencies
, submakes
[i
]->dependencies
);
3723 strarray_addall_path( &clean_files
, submakes
[i
]->obj_dir
, submakes
[i
]->clean_files
);
3724 strarray_addall_path( &distclean_files
, submakes
[i
]->obj_dir
, submakes
[i
]->distclean_files
);
3725 strarray_addall_path( &distclean_dirs
, submakes
[i
]->obj_dir
, subclean
);
3726 strarray_addall_path( &make
->maintainerclean_files
, submakes
[i
]->obj_dir
, submakes
[i
]->maintainerclean_files
);
3727 strarray_addall_path( &make
->pot_files
, submakes
[i
]->obj_dir
, submakes
[i
]->pot_files
);
3729 for (arch
= 0; arch
< archs
.count
; arch
++)
3731 if (submakes
[i
]->disabled
[arch
]) continue;
3732 strarray_addall_path( &all_targets
, submakes
[i
]->obj_dir
, submakes
[i
]->all_targets
[arch
] );
3733 strarray_addall_path( &testclean_files
, submakes
[i
]->obj_dir
, submakes
[i
]->ok_files
[arch
] );
3735 if (submakes
[i
]->disabled
[0]) continue;
3737 strarray_addall_path( &all_targets
, submakes
[i
]->obj_dir
, submakes
[i
]->font_files
);
3738 if (!strcmp( submakes
[i
]->obj_dir
, "tools" ) || !strncmp( submakes
[i
]->obj_dir
, "tools/", 6 ))
3739 strarray_add( &tooldeps_deps
, obj_dir_path( submakes
[i
], "all" ));
3740 if (submakes
[i
]->testdll
)
3741 strarray_add( &buildtest_deps
, obj_dir_path( submakes
[i
], "all" ));
3742 for (j
= 0; j
< NB_INSTALL_RULES
; j
++)
3743 if (submakes
[i
]->install_rules
[j
].count
)
3744 strarray_add( &install_deps
[j
], obj_dir_path( submakes
[i
], install_targets
[j
] ));
3746 strarray_addall( &dependencies
, makefile_deps
);
3748 output_filenames( all_targets
);
3750 output( "Makefile:" );
3751 output_filenames( makefile_deps
);
3753 output_filenames( dependencies
);
3755 for (j
= 0; j
< NB_INSTALL_RULES
; j
++)
3757 if (!install_deps
[j
].count
) continue;
3758 if (strcmp( install_targets
[j
], "install-test" ))
3760 output( "install " );
3761 strarray_add_uniq( &make
->phony_targets
, "install" );
3763 output( "%s::", install_targets
[j
] );
3764 output_filenames( install_deps
[j
] );
3766 strarray_add_uniq( &make
->phony_targets
, install_targets
[j
] );
3768 output_uninstall_rules( make
);
3769 if (buildtest_deps
.count
)
3771 output( "buildtests:" );
3772 output_filenames( buildtest_deps
);
3774 strarray_add_uniq( &make
->phony_targets
, "buildtests" );
3776 output( "check test:" );
3777 output_filenames( testclean_files
);
3779 strarray_add_uniq( &make
->phony_targets
, "check" );
3780 strarray_add_uniq( &make
->phony_targets
, "test" );
3782 if (get_expanded_make_variable( make
, "GETTEXTPO_LIBS" )) output_po_files( make
);
3784 output( "clean::\n");
3785 output_rm_filenames( clean_files
, "rm -f" );
3786 output( "testclean::\n");
3787 output_rm_filenames( testclean_files
, "rm -f" );
3788 output( "distclean::\n");
3789 output_rm_filenames( distclean_files
, "rm -f" );
3790 output_rm_filenames( distclean_dirs
, "-rmdir 2>/dev/null" );
3791 output( "maintainer-clean::\n");
3792 output_rm_filenames( make
->maintainerclean_files
, "rm -f" );
3793 strarray_add_uniq( &make
->phony_targets
, "distclean" );
3794 strarray_add_uniq( &make
->phony_targets
, "testclean" );
3795 strarray_add_uniq( &make
->phony_targets
, "maintainer-clean" );
3797 if (tooldeps_deps
.count
)
3799 output( "__tooldeps__:" );
3800 output_filenames( tooldeps_deps
);
3802 strarray_add_uniq( &make
->phony_targets
, "__tooldeps__" );
3805 if (make
->phony_targets
.count
)
3807 output( ".PHONY:" );
3808 output_filenames( make
->phony_targets
);
3814 /*******************************************************************
3817 static void output_sources( struct makefile
*make
)
3819 struct strarray all_targets
= empty_strarray
;
3820 struct incl_file
*source
;
3821 unsigned int i
, j
, arch
;
3823 strarray_add_uniq( &make
->phony_targets
, "all" );
3825 LIST_FOR_EACH_ENTRY( source
, &make
->sources
, struct incl_file
, entry
)
3827 char *obj
= xstrdup( source
->name
);
3828 char *ext
= get_extension( obj
);
3830 if (!ext
) fatal_error( "unsupported file type %s\n", source
->name
);
3833 for (j
= 0; output_source_funcs
[j
].ext
; j
++)
3834 if (!strcmp( ext
, output_source_funcs
[j
].ext
)) break;
3836 output_source_funcs
[j
].fn( make
, source
, obj
);
3837 strarray_addall_uniq( &make
->dependencies
, source
->dependencies
);
3840 /* special case for winetest: add resource files from other test dirs */
3841 if (make
->obj_dir
&& !strcmp( make
->obj_dir
, "programs/winetest" ))
3843 for (arch
= 0; arch
< archs
.count
; arch
++)
3845 if (!is_multiarch( arch
)) continue;
3846 for (i
= 0; i
< subdirs
.count
; i
++)
3848 if (!submakes
[i
]->testdll
) continue;
3849 if (submakes
[i
]->disabled
[arch
]) continue;
3850 if (enable_tests
.count
&& !strarray_exists( &enable_tests
, submakes
[i
]->testdll
)) continue;
3851 strarray_add( &make
->res_files
[arch
],
3852 strmake( "%s%s", arch_dirs
[arch
],
3853 replace_extension( submakes
[i
]->testdll
, ".dll", "_test.res" )));
3858 if (make
->dlldata_files
.count
)
3860 output( "%s: %s %s\n", obj_dir_path( make
, "dlldata.c" ),
3861 tools_path( make
, "widl" ), src_dir_path( make
, "Makefile.in" ));
3862 output( "\t%s%s --dlldata-only -o $@", cmd_prefix( "WIDL" ), tools_path( make
, "widl" ));
3863 output_filenames( make
->dlldata_files
);
3867 if (make
->staticlib
)
3869 for (arch
= 0; arch
< archs
.count
; arch
++)
3870 if (is_multiarch( arch
) || (so_dll_supported
&& !make
->extlib
))
3871 output_static_lib( make
, arch
);
3873 else if (make
->module
)
3875 for (arch
= 0; arch
< archs
.count
; arch
++)
3877 if (is_multiarch( arch
)) output_module( make
, arch
);
3878 if (make
->importlib
&& (is_multiarch( arch
) || !is_native_arch_disabled( make
)))
3879 output_import_lib( make
, arch
);
3881 if (make
->unixlib
) output_unix_lib( make
);
3882 if (make
->is_exe
&& !make
->is_win16
&& unix_lib_supported
&& strendswith( make
->module
, ".exe" ))
3884 char *binary
= replace_extension( make
->module
, ".exe", "" );
3885 add_install_rule( make
, binary
, 0, "wineapploader", strmake( "t$(bindir)/%s", binary
));
3888 else if (make
->testdll
)
3890 for (arch
= 0; arch
< archs
.count
; arch
++)
3891 if (is_multiarch( arch
)) output_test_module( make
, arch
);
3893 else if (make
->programs
.count
) output_programs( make
);
3895 for (i
= 0; i
< make
->scripts
.count
; i
++)
3896 add_install_rule( make
, make
->scripts
.str
[i
], 0, make
->scripts
.str
[i
],
3897 strmake( "S$(bindir)/%s", make
->scripts
.str
[i
] ));
3899 for (i
= 0; i
< make
->extra_targets
.count
; i
++)
3900 if (strarray_exists( &make
->dependencies
, obj_dir_path( make
, make
->extra_targets
.str
[i
] )))
3901 strarray_add( &make
->clean_files
, make
->extra_targets
.str
[i
] );
3903 strarray_add( &make
->all_targets
[0], make
->extra_targets
.str
[i
] );
3905 if (!make
->src_dir
) strarray_add( &make
->distclean_files
, ".gitignore" );
3906 strarray_add( &make
->distclean_files
, "Makefile" );
3907 if (make
->testdll
) strarray_add( &make
->distclean_files
, "testlist.c" );
3910 strarray_addall( &make
->distclean_files
, get_expanded_make_var_array( make
, "CONFIGURE_TARGETS" ));
3911 else if (!strcmp( make
->obj_dir
, "po" ))
3912 strarray_add( &make
->distclean_files
, "LINGUAS" );
3914 for (arch
= 0; arch
< archs
.count
; arch
++)
3916 strarray_addall_uniq( &make
->clean_files
, make
->object_files
[arch
] );
3917 strarray_addall_uniq( &make
->clean_files
, make
->implib_files
[arch
] );
3918 strarray_addall_uniq( &make
->clean_files
, make
->res_files
[arch
] );
3919 strarray_addall_uniq( &make
->clean_files
, make
->all_targets
[arch
] );
3921 strarray_addall( &make
->clean_files
, make
->unixobj_files
);
3922 strarray_addall( &make
->clean_files
, make
->pot_files
);
3923 strarray_addall( &make
->clean_files
, make
->debug_files
);
3925 if (make
== top_makefile
)
3927 output_subdirs( make
);
3931 for (arch
= 0; arch
< archs
.count
; arch
++) strarray_addall( &all_targets
, make
->all_targets
[arch
] );
3932 strarray_addall( &all_targets
, make
->font_files
);
3933 if (all_targets
.count
)
3935 output( "%s:", obj_dir_path( make
, "all" ));
3936 output_filenames_obj_dir( make
, all_targets
);
3938 strarray_add_uniq( &make
->phony_targets
, obj_dir_path( make
, "all" ));
3940 for (i
= 0; i
< NB_INSTALL_RULES
; i
++) output_install_rules( make
, i
);
3942 if (make
->clean_files
.count
)
3944 output( "%s::\n", obj_dir_path( make
, "clean" ));
3945 output( "\trm -f" );
3946 output_filenames_obj_dir( make
, make
->clean_files
);
3948 strarray_add( &make
->phony_targets
, obj_dir_path( make
, "clean" ));
3953 /*******************************************************************
3956 static FILE *create_temp_file( const char *orig
)
3958 char *name
= xmalloc( strlen(orig
) + 13 );
3959 unsigned int i
, id
= getpid();
3963 for (i
= 0; i
< 100; i
++)
3965 snprintf( name
, strlen(orig
) + 13, "%s.tmp%08x", orig
, id
);
3966 if ((fd
= open( name
, O_RDWR
| O_CREAT
| O_EXCL
, 0666 )) != -1)
3968 ret
= fdopen( fd
, "w" );
3971 if (errno
!= EEXIST
) break;
3974 if (!ret
) fatal_error( "failed to create output file for '%s'\n", orig
);
3975 temp_file_name
= name
;
3980 /*******************************************************************
3983 static void rename_temp_file( const char *dest
)
3985 int ret
= rename( temp_file_name
, dest
);
3986 if (ret
== -1 && errno
== EEXIST
)
3988 /* rename doesn't overwrite on windows */
3990 ret
= rename( temp_file_name
, dest
);
3992 if (ret
== -1) fatal_error( "failed to rename output file to '%s'\n", dest
);
3993 temp_file_name
= NULL
;
3997 /*******************************************************************
3998 * are_files_identical
4000 static int are_files_identical( FILE *file1
, FILE *file2
)
4004 char buffer1
[8192], buffer2
[8192];
4005 int size1
= fread( buffer1
, 1, sizeof(buffer1
), file1
);
4006 int size2
= fread( buffer2
, 1, sizeof(buffer2
), file2
);
4007 if (size1
!= size2
) return 0;
4008 if (!size1
) return feof( file1
) && feof( file2
);
4009 if (memcmp( buffer1
, buffer2
, size1
)) return 0;
4014 /*******************************************************************
4015 * rename_temp_file_if_changed
4017 static void rename_temp_file_if_changed( const char *dest
)
4019 FILE *file1
, *file2
;
4022 if ((file1
= fopen( dest
, "r" )))
4024 if ((file2
= fopen( temp_file_name
, "r" )))
4026 do_rename
= !are_files_identical( file1
, file2
);
4033 unlink( temp_file_name
);
4034 temp_file_name
= NULL
;
4036 else rename_temp_file( dest
);
4040 /*******************************************************************
4043 static void output_linguas( const struct makefile
*make
)
4045 const char *dest
= obj_dir_path( make
, "LINGUAS" );
4046 struct incl_file
*source
;
4048 output_file
= create_temp_file( dest
);
4050 output( "# Automatically generated by make depend; DO NOT EDIT!!\n" );
4051 LIST_FOR_EACH_ENTRY( source
, &make
->sources
, struct incl_file
, entry
)
4052 if (strendswith( source
->name
, ".po" ))
4053 output( "%s\n", replace_extension( source
->name
, ".po", "" ));
4055 if (fclose( output_file
)) fatal_perror( "write" );
4057 rename_temp_file_if_changed( dest
);
4061 /*******************************************************************
4064 static void output_testlist( const struct makefile
*make
)
4066 const char *dest
= obj_dir_path( make
, "testlist.c" );
4069 output_file
= create_temp_file( dest
);
4071 output( "/* Automatically generated by make depend; DO NOT EDIT!! */\n\n" );
4072 output( "#define WIN32_LEAN_AND_MEAN\n" );
4073 output( "#include <windows.h>\n\n" );
4074 output( "#define STANDALONE\n" );
4075 output( "#include \"wine/test.h\"\n\n" );
4077 for (i
= 0; i
< make
->test_files
.count
; i
++)
4078 output( "extern void func_%s(void);\n", make
->test_files
.str
[i
] );
4080 output( "const struct test winetest_testlist[] =\n" );
4082 for (i
= 0; i
< make
->test_files
.count
; i
++)
4083 output( " { \"%s\", func_%s },\n", make
->test_files
.str
[i
], make
->test_files
.str
[i
] );
4084 output( " { 0, 0 }\n" );
4087 if (fclose( output_file
)) fatal_perror( "write" );
4089 rename_temp_file_if_changed( dest
);
4093 /*******************************************************************
4096 static void output_gitignore( const char *dest
, struct strarray files
)
4100 output_file
= create_temp_file( dest
);
4102 output( "# Automatically generated by make depend; DO NOT EDIT!!\n" );
4103 for (i
= 0; i
< files
.count
; i
++)
4105 if (!strchr( files
.str
[i
], '/' )) output( "/" );
4106 output( "%s\n", files
.str
[i
] );
4109 if (fclose( output_file
)) fatal_perror( "write" );
4111 rename_temp_file( dest
);
4115 /*******************************************************************
4116 * output_stub_makefile
4118 static void output_stub_makefile( struct makefile
*make
)
4120 struct strarray targets
= empty_strarray
;
4121 const char *make_var
= strarray_get_value( &top_makefile
->vars
, "MAKE" );
4122 unsigned int i
, arch
;
4124 for (arch
= 0; arch
< archs
.count
; arch
++)
4125 if (make
->all_targets
[arch
].count
) strarray_add_uniq( &targets
, "all" );
4127 for (i
= 0; i
< NB_INSTALL_RULES
; i
++)
4129 if (!make
->install_rules
[i
].count
) continue;
4130 strarray_add_uniq( &targets
, "install" );
4131 strarray_add( &targets
, install_targets
[i
] );
4133 if (make
->clean_files
.count
) strarray_add( &targets
, "clean" );
4134 if (make
->test_files
.count
)
4136 strarray_add( &targets
, "check" );
4137 strarray_add( &targets
, "test" );
4138 strarray_add( &targets
, "testclean" );
4141 if (!targets
.count
&& !make
->clean_files
.count
) return;
4143 output_file_name
= obj_dir_path( make
, "Makefile" );
4144 output_file
= create_temp_file( output_file_name
);
4146 output( "# Auto-generated stub makefile; all rules forward to the top-level makefile\n\n" );
4148 if (make_var
) output( "MAKE = %s\n\n", make_var
);
4151 output_filenames( targets
);
4152 output_filenames( make
->clean_files
);
4154 output( "\t@cd %s && $(MAKE) %s/$@\n", get_relative_path( make
->obj_dir
, "" ), make
->obj_dir
);
4155 output( ".PHONY:" );
4156 output_filenames( targets
);
4159 fclose( output_file
);
4161 rename_temp_file( output_file_name
);
4165 /*******************************************************************
4166 * output_silent_rules
4168 static void output_silent_rules(void)
4170 static const char *cmds
[] =
4188 output( "V = 0\n" );
4189 for (i
= 0; i
< ARRAY_SIZE(cmds
); i
++)
4191 output( "quiet_%s = $(quiet_%s_$(V))\n", cmds
[i
], cmds
[i
] );
4192 output( "quiet_%s_0 = @echo \" %-5s \" $@;\n", cmds
[i
], cmds
[i
] );
4193 output( "quiet_%s_1 =\n", cmds
[i
] );
4198 /*******************************************************************
4199 * output_top_makefile
4201 static void output_top_makefile( struct makefile
*make
)
4208 output_file_name
= obj_dir_path( make
, output_makefile_name
);
4209 output_file
= create_temp_file( output_file_name
);
4211 /* copy the contents of the source makefile */
4212 src_file
= open_input_makefile( make
);
4213 while (fgets( buffer
, sizeof(buffer
), src_file
) && !found
)
4215 if (fwrite( buffer
, 1, strlen(buffer
), output_file
) != strlen(buffer
)) fatal_perror( "write" );
4216 found
= !strncmp( buffer
, separator
, strlen(separator
) );
4218 if (fclose( src_file
)) fatal_perror( "close" );
4219 input_file_name
= NULL
;
4221 if (!found
) output( "\n%s (everything below this line is auto-generated; DO NOT EDIT!!)\n", separator
);
4223 if (silent_rules
) output_silent_rules();
4224 for (i
= 0; i
< subdirs
.count
; i
++) output_sources( submakes
[i
] );
4225 output_sources( make
);
4226 /* disable implicit rules */
4227 output( ".SUFFIXES:\n" );
4229 fclose( output_file
);
4231 rename_temp_file( output_file_name
);
4235 /*******************************************************************
4236 * output_dependencies
4238 static void output_dependencies( struct makefile
*make
)
4240 struct strarray ignore_files
= empty_strarray
;
4242 if (make
->obj_dir
) create_dir( make
->obj_dir
);
4244 if (make
== top_makefile
) output_top_makefile( make
);
4245 else output_stub_makefile( make
);
4247 strarray_addall( &ignore_files
, make
->distclean_files
);
4248 strarray_addall( &ignore_files
, make
->clean_files
);
4249 if (make
->testdll
) output_testlist( make
);
4250 if (make
->obj_dir
&& !strcmp( make
->obj_dir
, "po" )) output_linguas( make
);
4251 if (!make
->src_dir
) output_gitignore( obj_dir_path( make
, ".gitignore" ), ignore_files
);
4253 create_file_directories( make
, ignore_files
);
4255 output_file_name
= NULL
;
4259 /*******************************************************************
4262 static void load_sources( struct makefile
*make
)
4264 unsigned int i
, arch
;
4265 struct strarray value
;
4266 struct incl_file
*file
;
4268 strarray_set_value( &make
->vars
, "top_srcdir", root_src_dir_path( "" ));
4269 strarray_set_value( &make
->vars
, "srcdir", src_dir_path( make
, "" ));
4271 make
->parent_dir
= get_expanded_make_variable( make
, "PARENTSRC" );
4272 make
->module
= get_expanded_make_variable( make
, "MODULE" );
4273 make
->testdll
= get_expanded_make_variable( make
, "TESTDLL" );
4274 make
->staticlib
= get_expanded_make_variable( make
, "STATICLIB" );
4275 make
->importlib
= get_expanded_make_variable( make
, "IMPORTLIB" );
4276 make
->extlib
= get_expanded_make_variable( make
, "EXTLIB" );
4277 if (unix_lib_supported
) make
->unixlib
= get_expanded_make_variable( make
, "UNIXLIB" );
4279 make
->programs
= get_expanded_make_var_array( make
, "PROGRAMS" );
4280 make
->scripts
= get_expanded_make_var_array( make
, "SCRIPTS" );
4281 make
->imports
= get_expanded_make_var_array( make
, "IMPORTS" );
4282 make
->delayimports
= get_expanded_make_var_array( make
, "DELAYIMPORTS" );
4283 make
->extradllflags
= get_expanded_make_var_array( make
, "EXTRADLLFLAGS" );
4284 make
->extra_targets
= get_expanded_make_var_array( make
, "EXTRA_TARGETS" );
4285 for (i
= 0; i
< NB_INSTALL_RULES
; i
++)
4286 make
->install
[i
] = get_expanded_make_var_array( make
, install_variables
[i
] );
4288 if (make
->extlib
) make
->staticlib
= make
->extlib
;
4289 if (make
->staticlib
) make
->module
= make
->staticlib
;
4293 make
->disabled
[0] = strarray_exists( &disabled_dirs
[0], make
->obj_dir
);
4294 for (arch
= 1; arch
< archs
.count
; arch
++)
4295 make
->disabled
[arch
] = make
->disabled
[0] || strarray_exists( &disabled_dirs
[arch
], make
->obj_dir
);
4297 make
->is_win16
= strarray_exists( &make
->extradllflags
, "-m16" );
4298 make
->data_only
= strarray_exists( &make
->extradllflags
, "-Wb,--data-only" );
4299 make
->is_exe
= strarray_exists( &make
->extradllflags
, "-mconsole" ) ||
4300 strarray_exists( &make
->extradllflags
, "-mwindows" );
4304 /* add default install rules if nothing was specified */
4305 for (i
= 0; i
< NB_INSTALL_RULES
; i
++) if (make
->install
[i
].count
) break;
4306 if (i
== NB_INSTALL_RULES
)
4308 if (make
->importlib
) strarray_add( &make
->install
[INSTALL_DEV
], make
->importlib
);
4309 if (make
->staticlib
) strarray_add( &make
->install
[INSTALL_DEV
], make
->staticlib
);
4310 else strarray_add( &make
->install
[INSTALL_LIB
], make
->module
);
4314 make
->include_paths
= empty_strarray
;
4315 make
->include_args
= empty_strarray
;
4316 make
->define_args
= empty_strarray
;
4317 make
->unix_cflags
= empty_strarray
;
4318 if (!make
->extlib
) strarray_add( &make
->define_args
, "-D__WINESRC__" );
4319 strarray_add( &make
->unix_cflags
, "-DWINE_UNIX_LIB" );
4321 value
= get_expanded_make_var_array( make
, "EXTRAINCL" );
4322 for (i
= 0; i
< value
.count
; i
++)
4324 if (!strncmp( value
.str
[i
], "-I", 2 ))
4326 const char *dir
= value
.str
[i
] + 2;
4327 if (!strncmp( dir
, "./", 2 ))
4330 while (*dir
== '/') dir
++;
4332 strarray_add_uniq( &make
->include_paths
, dir
);
4334 else if (!strncmp( value
.str
[i
], "-D", 2 ) || !strncmp( value
.str
[i
], "-U", 2 ))
4335 strarray_add_uniq( &make
->define_args
, value
.str
[i
] );
4337 strarray_addall( &make
->define_args
, get_expanded_make_var_array( make
, "EXTRADEFS" ));
4338 strarray_addall_uniq( &make
->unix_cflags
, get_expanded_make_var_array( make
, "UNIX_CFLAGS" ));
4340 strarray_add( &make
->include_args
, strmake( "-I%s", obj_dir_path( make
, "" )));
4342 strarray_add( &make
->include_args
, strmake( "-I%s", make
->src_dir
));
4343 if (make
->parent_dir
)
4344 strarray_add( &make
->include_args
, strmake( "-I%s", src_dir_path( make
, make
->parent_dir
)));
4345 strarray_add( &make
->include_args
, "-Iinclude" );
4346 if (root_src_dir
) strarray_add( &make
->include_args
, strmake( "-I%s", root_src_dir_path( "include" )));
4348 list_init( &make
->sources
);
4349 list_init( &make
->includes
);
4351 value
= get_expanded_make_var_array( make
, "SOURCES" );
4352 for (i
= 0; i
< value
.count
; i
++) add_src_file( make
, value
.str
[i
] );
4354 add_generated_sources( make
);
4356 LIST_FOR_EACH_ENTRY( file
, &make
->includes
, struct incl_file
, entry
) parse_file( make
, file
, 0 );
4357 LIST_FOR_EACH_ENTRY( file
, &make
->sources
, struct incl_file
, entry
) get_dependencies( file
, file
);
4359 for (i
= 0; i
< make
->delayimports
.count
; i
++)
4360 strarray_add_uniq( &delay_import_libs
, get_base_name( make
->delayimports
.str
[i
] ));
4364 /*******************************************************************
4367 static void parse_makeflags( const char *flags
)
4369 const char *p
= flags
;
4370 char *var
, *buffer
= xmalloc( strlen(flags
) + 1 );
4374 p
= skip_spaces( p
);
4376 while (*p
&& !isspace(*p
))
4378 if (*p
== '\\' && p
[1]) p
++;
4382 if (var
> buffer
) set_make_variable( &cmdline_vars
, buffer
);
4387 /*******************************************************************
4390 static int parse_option( const char *opt
)
4394 if (strchr( opt
, '=' )) return set_make_variable( &cmdline_vars
, opt
);
4400 if (opt
[2]) output_makefile_name
= opt
+ 2;
4403 relative_dir_mode
= 1;
4409 fprintf( stderr
, "Unknown option '%s'\n%s", opt
, Usage
);
4416 /*******************************************************************
4419 static unsigned int find_pe_arch( const char *arch
)
4422 for (i
= 1; i
< archs
.count
; i
++) if (!strcmp( archs
.str
[i
], arch
)) return i
;
4427 /*******************************************************************
4430 int main( int argc
, char *argv
[] )
4432 const char *makeflags
= getenv( "MAKEFLAGS" );
4434 unsigned int i
, j
, arch
, ec_arch
;
4436 if (makeflags
) parse_makeflags( makeflags
);
4441 if (parse_option( argv
[i
] ))
4443 for (j
= i
; j
< argc
; j
++) argv
[j
] = argv
[j
+1];
4449 if (relative_dir_mode
)
4455 fprintf( stderr
, "Option -R needs two directories\n%s", Usage
);
4458 relpath
= get_relative_path( argv
[1], argv
[2] );
4459 printf( "%s\n", relpath
? relpath
: "." );
4463 if (argc
> 1) fatal_error( "Directory arguments not supported in this mode\n" );
4465 atexit( cleanup_files
);
4466 init_signals( exit_on_signal
);
4468 for (i
= 0; i
< HASH_SIZE
; i
++) list_init( &files
[i
] );
4469 for (i
= 0; i
< HASH_SIZE
; i
++) list_init( &global_includes
[i
] );
4471 top_makefile
= parse_makefile( NULL
);
4473 target_flags
[0] = get_expanded_make_var_array( top_makefile
, "TARGETFLAGS" );
4474 msvcrt_flags
= get_expanded_make_var_array( top_makefile
, "MSVCRTFLAGS" );
4475 dll_flags
= get_expanded_make_var_array( top_makefile
, "DLLFLAGS" );
4476 unix_dllflags
= get_expanded_make_var_array( top_makefile
, "UNIXDLLFLAGS" );
4477 cpp_flags
= get_expanded_make_var_array( top_makefile
, "CPPFLAGS" );
4478 lddll_flags
= get_expanded_make_var_array( top_makefile
, "LDDLLFLAGS" );
4479 libs
= get_expanded_make_var_array( top_makefile
, "LIBS" );
4480 enable_tests
= get_expanded_make_var_array( top_makefile
, "ENABLE_TESTS" );
4481 for (i
= 0; i
< NB_INSTALL_RULES
; i
++)
4482 top_install
[i
] = get_expanded_make_var_array( top_makefile
, strmake( "TOP_%s", install_variables
[i
] ));
4484 root_src_dir
= get_expanded_make_variable( top_makefile
, "srcdir" );
4485 tools_dir
= get_expanded_make_variable( top_makefile
, "toolsdir" );
4486 tools_ext
= get_expanded_make_variable( top_makefile
, "toolsext" );
4487 exe_ext
= get_expanded_make_variable( top_makefile
, "EXEEXT" );
4488 dll_ext
[0] = get_expanded_make_variable( top_makefile
, "DLLEXT" );
4489 fontforge
= get_expanded_make_variable( top_makefile
, "FONTFORGE" );
4490 convert
= get_expanded_make_variable( top_makefile
, "CONVERT" );
4491 flex
= get_expanded_make_variable( top_makefile
, "FLEX" );
4492 bison
= get_expanded_make_variable( top_makefile
, "BISON" );
4493 ar
= get_expanded_make_variable( top_makefile
, "AR" );
4494 ranlib
= get_expanded_make_variable( top_makefile
, "RANLIB" );
4495 rsvg
= get_expanded_make_variable( top_makefile
, "RSVG" );
4496 icotool
= get_expanded_make_variable( top_makefile
, "ICOTOOL" );
4497 msgfmt
= get_expanded_make_variable( top_makefile
, "MSGFMT" );
4498 sed_cmd
= get_expanded_make_variable( top_makefile
, "SED_CMD" );
4499 ln_s
= get_expanded_make_variable( top_makefile
, "LN_S" );
4500 wayland_scanner
= get_expanded_make_variable( top_makefile
, "WAYLAND_SCANNER" );
4502 if (root_src_dir
&& !strcmp( root_src_dir
, "." )) root_src_dir
= NULL
;
4503 if (tools_dir
&& !strcmp( tools_dir
, "." )) tools_dir
= NULL
;
4504 if (!exe_ext
) exe_ext
= "";
4505 if (!dll_ext
[0]) dll_ext
[0] = "";
4506 if (!tools_ext
) tools_ext
= "";
4508 unix_lib_supported
= !!strcmp( exe_ext
, ".exe" );
4509 so_dll_supported
= !!dll_ext
[0][0]; /* non-empty dll ext means supported */
4511 strarray_add( &archs
, get_expanded_make_variable( top_makefile
, "HOST_ARCH" ));
4512 strarray_addall( &archs
, get_expanded_make_var_array( top_makefile
, "PE_ARCHS" ));
4514 /* check for ARM64X setup */
4515 if ((ec_arch
= find_pe_arch( "arm64ec" )) && (arch
= find_pe_arch( "aarch64" )))
4517 native_archs
[ec_arch
] = arch
;
4518 hybrid_archs
[arch
] = ec_arch
;
4519 strarray_add( &hybrid_target_flags
[ec_arch
], "-marm64x" );
4523 arch_pe_dirs
[0] = strmake( "%s-windows/", archs
.str
[0] );
4524 arch_install_dirs
[0] = unix_lib_supported
? strmake( "$(dlldir)/%s-unix/", archs
.str
[0] ) : "$(dlldir)/";
4525 strip_progs
[0] = "\"$(STRIP)\"";
4527 for (arch
= 1; arch
< archs
.count
; arch
++)
4529 target
= get_expanded_arch_var( top_makefile
, "TARGET", arch
);
4530 strarray_add( &target_flags
[arch
], "-b" );
4531 strarray_add( &target_flags
[arch
], target
);
4532 arch_dirs
[arch
] = strmake( "%s-windows/", archs
.str
[arch
] );
4533 arch_pe_dirs
[arch
] = arch_dirs
[arch
];
4534 arch_install_dirs
[arch
] = strmake( "$(dlldir)/%s", arch_dirs
[arch
] );
4535 strip_progs
[arch
] = strmake( "%s-strip", target
);
4539 for (arch
= 0; arch
< archs
.count
; arch
++)
4541 extra_cflags
[arch
] = get_expanded_arch_var_array( top_makefile
, "EXTRACFLAGS", arch
);
4542 extra_cflags_extlib
[arch
] = remove_warning_flags( extra_cflags
[arch
] );
4543 disabled_dirs
[arch
] = get_expanded_arch_var_array( top_makefile
, "DISABLED_SUBDIRS", arch
);
4544 if (!is_multiarch( arch
)) continue;
4545 delay_load_flags
[arch
] = get_expanded_arch_var( top_makefile
, "DELAYLOADFLAG", arch
);
4546 debug_flags
[arch
] = get_expanded_arch_var( top_makefile
, "DEBUG", arch
);
4549 if (unix_lib_supported
)
4551 delay_load_flags
[0] = "-Wl,-delayload,";
4552 debug_flags
[0] = NULL
;
4555 top_makefile
->src_dir
= root_src_dir
;
4556 subdirs
= get_expanded_make_var_array( top_makefile
, "SUBDIRS" );
4557 submakes
= xmalloc( subdirs
.count
* sizeof(*submakes
) );
4559 for (i
= 0; i
< subdirs
.count
; i
++) submakes
[i
] = parse_makefile( subdirs
.str
[i
] );
4561 load_sources( top_makefile
);
4562 load_sources( include_makefile
);
4563 for (i
= 0; i
< subdirs
.count
; i
++)
4564 if (submakes
[i
] != include_makefile
) load_sources( submakes
[i
] );
4566 output_dependencies( top_makefile
);
4567 for (i
= 0; i
< subdirs
.count
; i
++) output_dependencies( submakes
[i
] );