2 * Generate include file dependencies
4 * Copyright 1996, 2013, 2020 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
32 #include <sys/types.h>
36 #include "wine/list.h"
40 INCL_NORMAL
, /* #include "foo.h" */
41 INCL_SYSTEM
, /* #include <foo.h> */
42 INCL_IMPORT
, /* idl import "foo.idl" */
43 INCL_IMPORTLIB
, /* idl importlib "foo.tlb" */
44 INCL_CPP_QUOTE
, /* idl cpp_quote("#include \"foo.h\"") */
45 INCL_CPP_QUOTE_SYSTEM
/* idl cpp_quote("#include <foo.h>") */
50 int line
; /* source line where this header is included */
51 enum incl_type type
; /* type of include */
52 char *name
; /* header name */
58 char *name
; /* full file name relative to cwd */
59 void *args
; /* custom arguments for makefile rule */
60 unsigned int flags
; /* flags (see below) */
61 unsigned int deps_count
; /* files in use */
62 unsigned int deps_size
; /* total allocated size */
63 struct dependency
*deps
; /* all header dependencies */
69 struct list hash_entry
;
73 char *basename
; /* base target name for generated files */
74 char *sourcename
; /* source file name for generated headers */
75 struct incl_file
*included_by
; /* file that included this one */
76 int included_line
; /* line where this file was included */
77 enum incl_type type
; /* type of include */
78 int use_msvcrt
:1; /* put msvcrt headers in the search path? */
79 int is_external
:1; /* file from external library? */
80 struct incl_file
*owner
;
81 unsigned int files_count
; /* files in use */
82 unsigned int files_size
; /* total allocated size */
83 struct incl_file
**files
;
84 struct strarray dependencies
; /* file dependencies */
85 struct strarray importlibdeps
; /* importlib dependencies */
88 #define FLAG_GENERATED 0x000001 /* generated file */
89 #define FLAG_INSTALL 0x000002 /* file to install */
90 #define FLAG_IDL_PROXY 0x000100 /* generates a proxy (_p.c) file */
91 #define FLAG_IDL_CLIENT 0x000200 /* generates a client (_c.c) file */
92 #define FLAG_IDL_SERVER 0x000400 /* generates a server (_s.c) file */
93 #define FLAG_IDL_IDENT 0x000800 /* generates an ident (_i.c) file */
94 #define FLAG_IDL_REGISTER 0x001000 /* generates a registration (_r.res) file */
95 #define FLAG_IDL_TYPELIB 0x002000 /* generates a typelib (_l.res) file */
96 #define FLAG_IDL_REGTYPELIB 0x004000 /* generates a registered typelib (_t.res) file */
97 #define FLAG_IDL_HEADER 0x008000 /* generates a header (.h) file */
98 #define FLAG_RC_PO 0x010000 /* rc file contains translations */
99 #define FLAG_RC_HEADER 0x020000 /* rc file is a header */
100 #define FLAG_C_IMPLIB 0x040000 /* file is part of an import library */
101 #define FLAG_C_UNIX 0x080000 /* file is part of a Unix library */
102 #define FLAG_SFD_FONTS 0x100000 /* sfd file generated bitmap fonts */
110 { FLAG_IDL_TYPELIB
, "_l.res" },
111 { FLAG_IDL_REGTYPELIB
, "_t.res" },
112 { FLAG_IDL_CLIENT
, "_c.c" },
113 { FLAG_IDL_IDENT
, "_i.c" },
114 { FLAG_IDL_PROXY
, "_p.c" },
115 { FLAG_IDL_SERVER
, "_s.c" },
116 { FLAG_IDL_REGISTER
, "_r.res" },
117 { FLAG_IDL_HEADER
, ".h" }
120 #define HASH_SIZE 197
122 static struct list files
[HASH_SIZE
];
123 static struct list global_includes
[HASH_SIZE
];
125 enum install_rules
{ INSTALL_LIB
, INSTALL_DEV
, INSTALL_TEST
, NB_INSTALL_RULES
};
126 static const char *install_targets
[NB_INSTALL_RULES
] = { "install-lib", "install-dev", "install-test" };
127 static const char *install_variables
[NB_INSTALL_RULES
] = { "INSTALL_LIB", "INSTALL_DEV", "INSTALL_TEST" };
129 /* variables common to all makefiles */
130 static struct strarray linguas
;
131 static struct strarray dll_flags
;
132 static struct strarray unix_dllflags
;
133 static struct strarray target_flags
;
134 static struct strarray msvcrt_flags
;
135 static struct strarray extra_cflags
;
136 static struct strarray extra_cross_cflags
;
137 static struct strarray extra_cflags_extlib
;
138 static struct strarray extra_cross_cflags_extlib
;
139 static struct strarray cpp_flags
;
140 static struct strarray lddll_flags
;
141 static struct strarray libs
;
142 static struct strarray enable_tests
;
143 static struct strarray cmdline_vars
;
144 static struct strarray subdirs
;
145 static struct strarray disabled_dirs
;
146 static struct strarray delay_import_libs
;
147 static struct strarray top_install
[NB_INSTALL_RULES
];
148 static const char *root_src_dir
;
149 static const char *tools_dir
;
150 static const char *tools_ext
;
151 static const char *exe_ext
;
152 static const char *dll_ext
;
153 static const char *host_cpu
;
154 static const char *pe_dir
;
155 static const char *so_dir
;
156 static const char *crosstarget
;
157 static const char *crossdebug
;
158 static const char *fontforge
;
159 static const char *convert
;
160 static const char *flex
;
161 static const char *bison
;
162 static const char *ar
;
163 static const char *ranlib
;
164 static const char *rsvg
;
165 static const char *icotool
;
166 static const char *dlltool
;
167 static const char *msgfmt
;
168 static const char *ln_s
;
169 static const char *sed_cmd
;
170 static const char *delay_load_flag
;
174 /* values determined from input makefile */
175 struct strarray vars
;
176 struct strarray include_paths
;
177 struct strarray include_args
;
178 struct strarray define_args
;
179 struct strarray unix_cflags
;
180 struct strarray programs
;
181 struct strarray scripts
;
182 struct strarray imports
;
183 struct strarray delayimports
;
184 struct strarray extradllflags
;
185 struct strarray install
[NB_INSTALL_RULES
];
186 struct strarray extra_targets
;
187 struct strarray extra_imports
;
189 struct list includes
;
192 const char *parent_dir
;
196 const char *sharedlib
;
197 const char *staticlib
;
198 const char *staticimplib
;
199 const char *importlib
;
209 /* values generated at output time */
210 struct strarray in_files
;
211 struct strarray ok_files
;
212 struct strarray pot_files
;
213 struct strarray test_files
;
214 struct strarray clean_files
;
215 struct strarray distclean_files
;
216 struct strarray maintainerclean_files
;
217 struct strarray uninstall_files
;
218 struct strarray object_files
;
219 struct strarray crossobj_files
;
220 struct strarray unixobj_files
;
221 struct strarray res_files
;
222 struct strarray font_files
;
223 struct strarray debug_files
;
224 struct strarray dlldata_files
;
225 struct strarray implib_files
;
226 struct strarray crossimplib_files
;
227 struct strarray all_targets
;
228 struct strarray phony_targets
;
229 struct strarray dependencies
;
230 struct strarray install_rules
[NB_INSTALL_RULES
];
233 static struct makefile
*top_makefile
;
234 static struct makefile
*include_makefile
;
235 static struct makefile
**submakes
;
237 static const char separator
[] = "### Dependencies";
238 static const char *output_makefile_name
= "Makefile";
239 static const char *input_file_name
;
240 static const char *output_file_name
;
241 static const char *temp_file_name
;
242 static int relative_dir_mode
;
243 static int silent_rules
;
244 static int input_line
;
245 static int output_column
;
246 static FILE *output_file
;
248 static const char Usage
[] =
249 "Usage: makedep [options] [directories]\n"
251 " -R from to Compute the relative path between two directories\n"
252 " -S Generate Automake-style silent rules\n"
253 " -fxxx Store output in file 'xxx' (default: Makefile)\n";
256 static void fatal_error( const char *msg
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
257 static void fatal_perror( const char *msg
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
258 static void output( const char *format
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
259 static char *strmake( const char* fmt
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
261 /*******************************************************************
264 static void fatal_error( const char *msg
, ... )
267 va_start( valist
, msg
);
270 fprintf( stderr
, "%s:", input_file_name
);
271 if (input_line
) fprintf( stderr
, "%d:", input_line
);
272 fprintf( stderr
, " error: " );
274 else fprintf( stderr
, "makedep: error: " );
275 vfprintf( stderr
, msg
, valist
);
281 /*******************************************************************
284 static void fatal_perror( const char *msg
, ... )
287 va_start( valist
, msg
);
290 fprintf( stderr
, "%s:", input_file_name
);
291 if (input_line
) fprintf( stderr
, "%d:", input_line
);
292 fprintf( stderr
, " error: " );
294 else fprintf( stderr
, "makedep: error: " );
295 vfprintf( stderr
, msg
, valist
);
302 /*******************************************************************
305 static void cleanup_files(void)
307 if (temp_file_name
) unlink( temp_file_name
);
308 if (output_file_name
) unlink( output_file_name
);
312 /*******************************************************************
315 static void exit_on_signal( int sig
)
317 exit( 1 ); /* this will call the atexit functions */
321 /*******************************************************************
324 static void output( const char *format
, ... )
329 va_start( valist
, format
);
330 ret
= vfprintf( output_file
, format
, valist
);
332 if (ret
< 0) fatal_perror( "output" );
333 if (format
[0] && format
[strlen(format
) - 1] == '\n') output_column
= 0;
334 else output_column
+= ret
;
338 /*******************************************************************
341 * Find a value in a name/value pair string array.
343 static const char *strarray_get_value( const struct strarray
*array
, const char *name
)
345 int pos
, res
, min
= 0, max
= array
->count
/ 2 - 1;
349 pos
= (min
+ max
) / 2;
350 if (!(res
= strcmp( array
->str
[pos
* 2], name
))) return array
->str
[pos
* 2 + 1];
351 if (res
< 0) min
= pos
+ 1;
358 /*******************************************************************
361 * Define a value in a name/value pair string array.
363 static void strarray_set_value( struct strarray
*array
, const char *name
, const char *value
)
365 int i
, pos
, res
, min
= 0, max
= array
->count
/ 2 - 1;
369 pos
= (min
+ max
) / 2;
370 if (!(res
= strcmp( array
->str
[pos
* 2], name
)))
372 /* redefining a variable replaces the previous value */
373 array
->str
[pos
* 2 + 1] = value
;
376 if (res
< 0) min
= pos
+ 1;
379 strarray_add( array
, NULL
);
380 strarray_add( array
, NULL
);
381 for (i
= array
->count
- 1; i
> min
* 2 + 1; i
--) array
->str
[i
] = array
->str
[i
- 2];
382 array
->str
[min
* 2] = name
;
383 array
->str
[min
* 2 + 1] = value
;
387 /*******************************************************************
390 static const char *normalize_arch( const char *arch
)
394 static const char *map
[][8] =
396 /* normalized aliases */
397 { "i386", "i486", "i586", "i686", "ia32" },
398 { "x86_64", "amd64", "x86-64", "x86_amd64", "x64" },
399 { "aarch64", "arm64" },
403 for (i
= 0; i
< sizeof(map
) / sizeof(map
[0]); i
++)
404 for (j
= 0; map
[i
][j
]; j
++)
405 if (!strncmp( arch
, map
[i
][j
], strlen(map
[i
][j
]) ))
411 /*******************************************************************
414 static void output_filename( const char *name
)
416 if (output_column
+ strlen(name
) + 1 > 100)
421 else if (output_column
) output( " " );
422 output( "%s", name
);
426 /*******************************************************************
429 static void output_filenames( struct strarray array
)
433 for (i
= 0; i
< array
.count
; i
++) output_filename( array
.str
[i
] );
437 /*******************************************************************
438 * output_rm_filenames
440 static void output_rm_filenames( struct strarray array
)
442 static const unsigned int max_cmdline
= 30000; /* to be on the safe side */
445 if (!array
.count
) return;
447 for (i
= len
= 0; i
< array
.count
; i
++)
449 if (len
> max_cmdline
)
455 output_filename( array
.str
[i
] );
456 len
+= strlen( array
.str
[i
] ) + 1;
462 /*******************************************************************
465 static char *get_extension( char *filename
)
467 char *ext
= strrchr( filename
, '.' );
468 if (ext
&& strchr( ext
, '/' )) ext
= NULL
;
473 /*******************************************************************
476 static const char *get_base_name( const char *name
)
479 if (!strchr( name
, '.' )) return name
;
480 base
= xstrdup( name
);
481 *strrchr( base
, '.' ) = 0;
486 /*******************************************************************
489 static char *replace_filename( const char *path
, const char *name
)
495 if (!path
) return xstrdup( name
);
496 if (!(p
= strrchr( path
, '/' ))) return xstrdup( name
);
498 ret
= xmalloc( len
+ strlen( name
) + 1 );
499 memcpy( ret
, path
, len
);
500 strcpy( ret
+ len
, name
);
505 /*******************************************************************
508 static char *replace_substr( const char *str
, const char *start
, size_t len
, const char *replace
)
510 size_t pos
= start
- str
;
511 char *ret
= xmalloc( pos
+ strlen(replace
) + strlen(start
+ len
) + 1 );
512 memcpy( ret
, str
, pos
);
513 strcpy( ret
+ pos
, replace
);
514 strcat( ret
+ pos
, start
+ len
);
519 /*******************************************************************
522 * Determine where the destination path is located relative to the 'from' path.
524 static char *get_relative_path( const char *from
, const char *dest
)
528 unsigned int dotdots
= 0;
530 /* a path of "." is equivalent to an empty path */
531 if (!strcmp( from
, "." )) from
= "";
535 while (*from
== '/') from
++;
536 while (*dest
== '/') dest
++;
537 start
= dest
; /* save start of next path element */
540 while (*from
&& *from
!= '/' && *from
== *dest
) { from
++; dest
++; }
541 if ((!*from
|| *from
== '/') && (!*dest
|| *dest
== '/')) continue;
543 /* count remaining elements in 'from' */
547 while (*from
&& *from
!= '/') from
++;
548 while (*from
== '/') from
++;
554 if (!start
[0] && !dotdots
) return NULL
; /* empty path */
556 ret
= xmalloc( 3 * dotdots
+ strlen( start
) + 1 );
557 for (p
= ret
; dotdots
; dotdots
--, p
+= 3) memcpy( p
, "../", 3 );
559 if (start
[0]) strcpy( p
, start
);
560 else p
[-1] = 0; /* remove trailing slash */
565 /*******************************************************************
568 static char *concat_paths( const char *base
, const char *path
)
573 if (!base
|| !base
[0]) return xstrdup( path
&& path
[0] ? path
: "." );
574 if (!path
|| !path
[0]) return xstrdup( base
);
575 if (path
[0] == '/') return xstrdup( path
);
577 len
= strlen( base
);
578 while (len
&& base
[len
- 1] == '/') len
--;
579 while (len
&& !strncmp( path
, "..", 2 ) && (!path
[2] || path
[2] == '/'))
581 for (i
= len
; i
> 0; i
--) if (base
[i
- 1] == '/') break;
582 if (i
== len
- 2 && !memcmp( base
+ i
, "..", 2 )) break; /* we can't go up if we already have ".." */
583 if (i
!= len
- 1 || base
[i
] != '.')
586 while (*path
== '/') path
++;
588 /* else ignore "." element */
589 while (i
> 0 && base
[i
- 1] == '/') i
--;
592 if (!len
&& base
[0] != '/') return xstrdup( path
[0] ? path
: "." );
593 ret
= xmalloc( len
+ strlen( path
) + 2 );
594 memcpy( ret
, base
, len
);
596 strcpy( ret
+ len
, path
);
601 /*******************************************************************
604 static char *obj_dir_path( const struct makefile
*make
, const char *path
)
606 return concat_paths( make
->obj_dir
, path
);
610 /*******************************************************************
613 static char *src_dir_path( const struct makefile
*make
, const char *path
)
615 if (make
->src_dir
) return concat_paths( make
->src_dir
, path
);
616 return obj_dir_path( make
, path
);
620 /*******************************************************************
623 static char *root_src_dir_path( const char *path
)
625 return concat_paths( root_src_dir
, path
);
629 /*******************************************************************
632 static char *tools_dir_path( const struct makefile
*make
, const char *path
)
634 if (tools_dir
) return strmake( "%s/tools/%s", tools_dir
, path
);
635 return strmake( "tools/%s", path
);
639 /*******************************************************************
642 static char *tools_path( const struct makefile
*make
, const char *name
)
644 return strmake( "%s/%s%s", tools_dir_path( make
, name
), name
, tools_ext
);
648 /*******************************************************************
649 * strarray_addall_path
651 static void strarray_addall_path( struct strarray
*array
, const char *dir
, struct strarray added
)
655 for (i
= 0; i
< added
.count
; i
++) strarray_add( array
, concat_paths( dir
, added
.str
[i
] ));
659 /*******************************************************************
662 static char *get_line( FILE *file
)
670 buffer
= xmalloc( size
);
672 if (!fgets( buffer
, size
, file
)) return NULL
;
677 char *p
= buffer
+ strlen(buffer
);
678 /* if line is larger than buffer, resize buffer */
679 while (p
== buffer
+ size
- 1 && p
[-1] != '\n')
681 buffer
= xrealloc( buffer
, size
* 2 );
682 if (!fgets( buffer
+ size
- 1, size
+ 1, file
)) break;
683 p
= buffer
+ strlen(buffer
);
686 if (p
> buffer
&& p
[-1] == '\n')
689 if (p
> buffer
&& p
[-1] == '\r') *(--p
) = 0;
690 if (p
> buffer
&& p
[-1] == '\\')
693 /* line ends in backslash, read continuation line */
694 if (!fgets( p
, size
- (p
- buffer
), file
)) return buffer
;
704 /*******************************************************************
707 static unsigned int hash_filename( const char *name
)
710 unsigned int ret
= 2166136261u;
711 while (*name
) ret
= (ret
* 16777619) ^ *name
++;
712 return ret
% HASH_SIZE
;
716 /*******************************************************************
719 static struct file
*add_file( const char *name
)
721 struct file
*file
= xmalloc( sizeof(*file
) );
722 memset( file
, 0, sizeof(*file
) );
723 file
->name
= xstrdup( name
);
728 /*******************************************************************
731 static void add_dependency( struct file
*file
, const char *name
, enum incl_type type
)
733 if (file
->deps_count
>= file
->deps_size
)
735 file
->deps_size
*= 2;
736 if (file
->deps_size
< 16) file
->deps_size
= 16;
737 file
->deps
= xrealloc( file
->deps
, file
->deps_size
* sizeof(*file
->deps
) );
739 file
->deps
[file
->deps_count
].line
= input_line
;
740 file
->deps
[file
->deps_count
].type
= type
;
741 file
->deps
[file
->deps_count
].name
= xstrdup( name
);
746 /*******************************************************************
749 static struct incl_file
*find_src_file( const struct makefile
*make
, const char *name
)
751 struct incl_file
*file
;
753 if (make
== include_makefile
)
755 unsigned int hash
= hash_filename( name
);
757 LIST_FOR_EACH_ENTRY( file
, &global_includes
[hash
], struct incl_file
, hash_entry
)
758 if (!strcmp( name
, file
->name
)) return file
;
762 LIST_FOR_EACH_ENTRY( file
, &make
->sources
, struct incl_file
, entry
)
763 if (!strcmp( name
, file
->name
)) return file
;
767 /*******************************************************************
770 static struct incl_file
*find_include_file( const struct makefile
*make
, const char *name
)
772 struct incl_file
*file
;
774 LIST_FOR_EACH_ENTRY( file
, &make
->includes
, struct incl_file
, entry
)
776 const char *filename
= file
->filename
;
777 if (!filename
) continue;
778 if (make
->obj_dir
&& strlen(make
->obj_dir
) < strlen(filename
))
780 filename
+= strlen(make
->obj_dir
);
781 while (*filename
== '/') filename
++;
783 if (!strcmp( name
, filename
)) return file
;
788 /*******************************************************************
791 * Add an include file if it doesn't already exists.
793 static struct incl_file
*add_include( struct makefile
*make
, struct incl_file
*parent
,
794 const char *name
, int line
, enum incl_type type
)
796 struct incl_file
*include
;
798 if (parent
->files_count
>= parent
->files_size
)
800 parent
->files_size
*= 2;
801 if (parent
->files_size
< 16) parent
->files_size
= 16;
802 parent
->files
= xrealloc( parent
->files
, parent
->files_size
* sizeof(*parent
->files
) );
805 LIST_FOR_EACH_ENTRY( include
, &make
->includes
, struct incl_file
, entry
)
806 if (!parent
->use_msvcrt
== !include
->use_msvcrt
&& !strcmp( name
, include
->name
))
809 include
= xmalloc( sizeof(*include
) );
810 memset( include
, 0, sizeof(*include
) );
811 include
->name
= xstrdup(name
);
812 include
->included_by
= parent
;
813 include
->included_line
= line
;
814 include
->type
= type
;
815 include
->use_msvcrt
= parent
->use_msvcrt
;
816 list_add_tail( &make
->includes
, &include
->entry
);
818 parent
->files
[parent
->files_count
++] = include
;
823 /*******************************************************************
824 * add_generated_source
826 * Add a generated source file to the list.
828 static struct incl_file
*add_generated_source( struct makefile
*make
,
829 const char *name
, const char *filename
)
831 struct incl_file
*file
= xmalloc( sizeof(*file
) );
833 memset( file
, 0, sizeof(*file
) );
834 file
->file
= add_file( name
);
835 file
->name
= xstrdup( name
);
836 file
->basename
= xstrdup( filename
? filename
: name
);
837 file
->filename
= obj_dir_path( make
, file
->basename
);
838 file
->file
->flags
= FLAG_GENERATED
;
839 file
->use_msvcrt
= make
->use_msvcrt
;
840 list_add_tail( &make
->sources
, &file
->entry
);
841 if (make
== include_makefile
)
843 unsigned int hash
= hash_filename( name
);
844 list_add_tail( &global_includes
[hash
], &file
->hash_entry
);
850 /*******************************************************************
851 * parse_include_directive
853 static void parse_include_directive( struct file
*source
, char *str
)
855 char quote
, *include
, *p
= str
;
857 while (*p
&& isspace(*p
)) p
++;
858 if (*p
!= '\"' && *p
!= '<' ) return;
860 if (quote
== '<') quote
= '>';
862 while (*p
&& (*p
!= quote
)) p
++;
863 if (!*p
) fatal_error( "malformed include directive '%s'\n", str
);
865 add_dependency( source
, include
, (quote
== '>') ? INCL_SYSTEM
: INCL_NORMAL
);
869 /*******************************************************************
870 * parse_pragma_directive
872 static void parse_pragma_directive( struct file
*source
, char *str
)
874 char *flag
, *p
= str
;
876 if (!isspace( *p
)) return;
877 while (*p
&& isspace(*p
)) p
++;
878 p
= strtok( p
, " \t" );
879 if (strcmp( p
, "makedep" )) return;
881 while ((flag
= strtok( NULL
, " \t" )))
883 if (!strcmp( flag
, "depend" ))
885 while ((p
= strtok( NULL
, " \t" ))) add_dependency( source
, p
, INCL_NORMAL
);
888 else if (!strcmp( flag
, "install" )) source
->flags
|= FLAG_INSTALL
;
890 if (strendswith( source
->name
, ".idl" ))
892 if (!strcmp( flag
, "header" )) source
->flags
|= FLAG_IDL_HEADER
;
893 else if (!strcmp( flag
, "proxy" )) source
->flags
|= FLAG_IDL_PROXY
;
894 else if (!strcmp( flag
, "client" )) source
->flags
|= FLAG_IDL_CLIENT
;
895 else if (!strcmp( flag
, "server" )) source
->flags
|= FLAG_IDL_SERVER
;
896 else if (!strcmp( flag
, "ident" )) source
->flags
|= FLAG_IDL_IDENT
;
897 else if (!strcmp( flag
, "typelib" )) source
->flags
|= FLAG_IDL_TYPELIB
;
898 else if (!strcmp( flag
, "register" )) source
->flags
|= FLAG_IDL_REGISTER
;
899 else if (!strcmp( flag
, "regtypelib" )) source
->flags
|= FLAG_IDL_REGTYPELIB
;
901 else if (strendswith( source
->name
, ".rc" ))
903 if (!strcmp( flag
, "header" )) source
->flags
|= FLAG_RC_HEADER
;
904 else if (!strcmp( flag
, "po" )) source
->flags
|= FLAG_RC_PO
;
906 else if (strendswith( source
->name
, ".sfd" ))
908 if (!strcmp( flag
, "font" ))
910 struct strarray
*array
= source
->args
;
914 source
->args
= array
= xmalloc( sizeof(*array
) );
915 *array
= empty_strarray
;
916 source
->flags
|= FLAG_SFD_FONTS
;
918 strarray_add( array
, xstrdup( strtok( NULL
, "" )));
924 if (!strcmp( flag
, "implib" )) source
->flags
|= FLAG_C_IMPLIB
;
925 if (!strcmp( flag
, "unix" )) source
->flags
|= FLAG_C_UNIX
;
931 /*******************************************************************
932 * parse_cpp_directive
934 static void parse_cpp_directive( struct file
*source
, char *str
)
936 while (*str
&& isspace(*str
)) str
++;
937 if (*str
++ != '#') return;
938 while (*str
&& isspace(*str
)) str
++;
940 if (!strncmp( str
, "include", 7 ))
941 parse_include_directive( source
, str
+ 7 );
942 else if (!strncmp( str
, "import", 6 ) && strendswith( source
->name
, ".m" ))
943 parse_include_directive( source
, str
+ 6 );
944 else if (!strncmp( str
, "pragma", 6 ))
945 parse_pragma_directive( source
, str
+ 6 );
949 /*******************************************************************
952 static void parse_idl_file( struct file
*source
, FILE *file
)
954 char *buffer
, *include
;
958 while ((buffer
= get_line( file
)))
962 while (*p
&& isspace(*p
)) p
++;
964 if (!strncmp( p
, "importlib", 9 ))
967 while (*p
&& isspace(*p
)) p
++;
968 if (*p
++ != '(') continue;
969 while (*p
&& isspace(*p
)) p
++;
970 if (*p
++ != '"') continue;
972 while (*p
&& (*p
!= '"')) p
++;
973 if (!*p
) fatal_error( "malformed importlib directive\n" );
975 add_dependency( source
, include
, INCL_IMPORTLIB
);
979 if (!strncmp( p
, "import", 6 ))
982 while (*p
&& isspace(*p
)) p
++;
983 if (*p
!= '"') continue;
985 while (*p
&& (*p
!= '"')) p
++;
986 if (!*p
) fatal_error( "malformed import directive\n" );
988 add_dependency( source
, include
, INCL_IMPORT
);
992 /* check for #include inside cpp_quote */
993 if (!strncmp( p
, "cpp_quote", 9 ))
996 while (*p
&& isspace(*p
)) p
++;
997 if (*p
++ != '(') continue;
998 while (*p
&& isspace(*p
)) p
++;
999 if (*p
++ != '"') continue;
1000 if (*p
++ != '#') continue;
1001 while (*p
&& isspace(*p
)) p
++;
1002 if (strncmp( p
, "include", 7 )) continue;
1004 while (*p
&& isspace(*p
)) p
++;
1005 if (*p
== '\\' && p
[1] == '"')
1012 if (*p
++ != '<' ) continue;
1016 while (*p
&& (*p
!= quote
)) p
++;
1017 if (!*p
|| (quote
== '"' && p
[-1] != '\\'))
1018 fatal_error( "malformed #include directive inside cpp_quote\n" );
1019 if (quote
== '"') p
--; /* remove backslash */
1021 add_dependency( source
, include
, (quote
== '>') ? INCL_CPP_QUOTE_SYSTEM
: INCL_CPP_QUOTE
);
1025 parse_cpp_directive( source
, p
);
1029 /*******************************************************************
1032 static void parse_c_file( struct file
*source
, FILE *file
)
1037 while ((buffer
= get_line( file
)))
1039 parse_cpp_directive( source
, buffer
);
1044 /*******************************************************************
1047 static void parse_rc_file( struct file
*source
, FILE *file
)
1049 char *buffer
, *include
;
1052 while ((buffer
= get_line( file
)))
1056 while (*p
&& isspace(*p
)) p
++;
1058 if (p
[0] == '/' && p
[1] == '*') /* check for magic makedep comment */
1061 while (*p
&& isspace(*p
)) p
++;
1062 if (strncmp( p
, "@makedep:", 9 )) continue;
1064 while (*p
&& isspace(*p
)) p
++;
1069 while (*p
&& *p
!= quote
) p
++;
1074 while (*p
&& !isspace(*p
) && *p
!= '*') p
++;
1077 fatal_error( "malformed makedep comment\n" );
1079 add_dependency( source
, include
, (quote
== '>') ? INCL_SYSTEM
: INCL_NORMAL
);
1083 parse_cpp_directive( source
, buffer
);
1088 /*******************************************************************
1091 static void parse_in_file( struct file
*source
, FILE *file
)
1095 /* make sure it gets rebuilt when the version changes */
1096 add_dependency( source
, "config.h", INCL_SYSTEM
);
1098 if (!strendswith( source
->name
, ".man.in" )) return; /* not a man page */
1101 while ((buffer
= get_line( file
)))
1103 if (strncmp( buffer
, ".TH", 3 )) continue;
1104 if (!(p
= strtok( buffer
, " \t" ))) continue; /* .TH */
1105 if (!(p
= strtok( NULL
, " \t" ))) continue; /* program name */
1106 if (!(p
= strtok( NULL
, " \t" ))) continue; /* man section */
1107 source
->args
= xstrdup( p
);
1113 /*******************************************************************
1116 static void parse_sfd_file( struct file
*source
, FILE *file
)
1118 char *p
, *eol
, *buffer
;
1121 while ((buffer
= get_line( file
)))
1123 if (strncmp( buffer
, "UComments:", 10 )) continue;
1125 while (*p
== ' ') p
++;
1126 if (p
[0] == '"' && p
[1] && buffer
[strlen(buffer
) - 1] == '"')
1129 buffer
[strlen(buffer
) - 1] = 0;
1131 while ((eol
= strstr( p
, "+AAoA" )))
1134 while (*p
&& isspace(*p
)) p
++;
1137 while (*p
&& isspace(*p
)) p
++;
1138 if (!strncmp( p
, "pragma", 6 )) parse_pragma_directive( source
, p
+ 6 );
1142 while (*p
&& isspace(*p
)) p
++;
1143 if (*p
++ != '#') return;
1144 while (*p
&& isspace(*p
)) p
++;
1145 if (!strncmp( p
, "pragma", 6 )) parse_pragma_directive( source
, p
+ 6 );
1154 void (*parse
)( struct file
*file
, FILE *f
);
1155 } parse_functions
[] =
1157 { ".c", parse_c_file
},
1158 { ".h", parse_c_file
},
1159 { ".inl", parse_c_file
},
1160 { ".l", parse_c_file
},
1161 { ".m", parse_c_file
},
1162 { ".rh", parse_c_file
},
1163 { ".x", parse_c_file
},
1164 { ".y", parse_c_file
},
1165 { ".idl", parse_idl_file
},
1166 { ".rc", parse_rc_file
},
1167 { ".in", parse_in_file
},
1168 { ".sfd", parse_sfd_file
}
1171 /*******************************************************************
1174 static struct file
*load_file( const char *name
)
1178 unsigned int i
, hash
= hash_filename( name
);
1180 LIST_FOR_EACH_ENTRY( file
, &files
[hash
], struct file
, entry
)
1181 if (!strcmp( name
, file
->name
)) return file
;
1183 if (!(f
= fopen( name
, "r" ))) return NULL
;
1185 file
= add_file( name
);
1186 list_add_tail( &files
[hash
], &file
->entry
);
1187 input_file_name
= file
->name
;
1190 for (i
= 0; i
< sizeof(parse_functions
) / sizeof(parse_functions
[0]); i
++)
1192 if (!strendswith( name
, parse_functions
[i
].ext
)) continue;
1193 parse_functions
[i
].parse( file
, f
);
1198 input_file_name
= NULL
;
1204 /*******************************************************************
1205 * open_include_path_file
1207 * Open a file from a directory on the include path.
1209 static struct file
*open_include_path_file( const struct makefile
*make
, const char *dir
,
1210 const char *name
, char **filename
)
1212 char *src_path
= concat_paths( dir
, name
);
1213 struct file
*ret
= load_file( src_path
);
1215 if (ret
) *filename
= src_path
;
1220 /*******************************************************************
1221 * open_file_same_dir
1223 * Open a file in the same directory as the parent.
1225 static struct file
*open_file_same_dir( const struct incl_file
*parent
, const char *name
, char **filename
)
1227 char *src_path
= replace_filename( parent
->file
->name
, name
);
1228 struct file
*ret
= load_file( src_path
);
1230 if (ret
) *filename
= replace_filename( parent
->filename
, name
);
1235 /*******************************************************************
1236 * open_same_dir_generated_file
1238 * Open a generated_file in the same directory as the parent.
1240 static struct file
*open_same_dir_generated_file( const struct makefile
*make
,
1241 const struct incl_file
*parent
, struct incl_file
*file
,
1242 const char *ext
, const char *src_ext
)
1245 struct file
*ret
= NULL
;
1247 if (strendswith( file
->name
, ext
) &&
1248 (ret
= open_file_same_dir( parent
, replace_extension( file
->name
, ext
, src_ext
), &filename
)))
1250 file
->sourcename
= filename
;
1251 file
->filename
= obj_dir_path( make
, replace_filename( parent
->name
, file
->name
));
1257 /*******************************************************************
1260 * Open a file in the source directory of the makefile.
1262 static struct file
*open_local_file( const struct makefile
*make
, const char *path
, char **filename
)
1264 char *src_path
= src_dir_path( make
, path
);
1265 struct file
*ret
= load_file( src_path
);
1267 /* if not found, try parent dir */
1268 if (!ret
&& make
->parent_dir
)
1271 path
= strmake( "%s/%s", make
->parent_dir
, path
);
1272 src_path
= src_dir_path( make
, path
);
1273 ret
= load_file( src_path
);
1276 if (ret
) *filename
= src_path
;
1281 /*******************************************************************
1282 * open_local_generated_file
1284 * Open a generated file in the directory of the makefile.
1286 static struct file
*open_local_generated_file( const struct makefile
*make
, struct incl_file
*file
,
1287 const char *ext
, const char *src_ext
)
1289 struct incl_file
*include
;
1291 if (strendswith( file
->name
, ext
) &&
1292 (include
= find_src_file( make
, replace_extension( file
->name
, ext
, src_ext
) )))
1294 file
->sourcename
= include
->filename
;
1295 file
->filename
= obj_dir_path( make
, file
->name
);
1296 return include
->file
;
1302 /*******************************************************************
1305 * Open a file in the top-level source directory.
1307 static struct file
*open_global_file( const char *path
, char **filename
)
1309 char *src_path
= root_src_dir_path( path
);
1310 struct file
*ret
= load_file( src_path
);
1312 if (ret
) *filename
= src_path
;
1317 /*******************************************************************
1318 * open_global_header
1320 * Open a file in the global include source directory.
1322 static struct file
*open_global_header( const char *path
, char **filename
)
1324 struct incl_file
*include
= find_src_file( include_makefile
, path
);
1326 if (!include
) return NULL
;
1327 *filename
= include
->filename
;
1328 return include
->file
;
1332 /*******************************************************************
1333 * open_global_generated_file
1335 * Open a generated file in the top-level source directory.
1337 static struct file
*open_global_generated_file( const struct makefile
*make
, struct incl_file
*file
,
1338 const char *ext
, const char *src_ext
)
1340 struct incl_file
*include
;
1342 if (strendswith( file
->name
, ext
) &&
1343 (include
= find_src_file( include_makefile
, replace_extension( file
->name
, ext
, src_ext
) )))
1345 file
->sourcename
= include
->filename
;
1346 file
->filename
= strmake( "include/%s", file
->name
);
1347 return include
->file
;
1353 /*******************************************************************
1356 static struct file
*open_src_file( const struct makefile
*make
, struct incl_file
*pFile
)
1358 struct file
*file
= open_local_file( make
, pFile
->name
, &pFile
->filename
);
1360 if (!file
) fatal_perror( "open %s", pFile
->name
);
1365 /*******************************************************************
1366 * find_importlib_module
1368 static struct makefile
*find_importlib_module( const char *name
)
1370 unsigned int i
, len
;
1372 for (i
= 0; i
< subdirs
.count
; i
++)
1374 if (strncmp( submakes
[i
]->obj_dir
, "dlls/", 5 )) continue;
1375 len
= strlen(submakes
[i
]->obj_dir
);
1376 if (strncmp( submakes
[i
]->obj_dir
+ 5, name
, len
- 5 )) continue;
1377 if (!name
[len
- 5] || !strcmp( name
+ len
- 5, ".dll" )) return submakes
[i
];
1383 /*******************************************************************
1386 static struct file
*open_include_file( const struct makefile
*make
, struct incl_file
*pFile
)
1388 struct file
*file
= NULL
;
1389 unsigned int i
, len
;
1393 /* check for generated files */
1394 if ((file
= open_local_generated_file( make
, pFile
, ".tab.h", ".y" ))) return file
;
1395 if ((file
= open_local_generated_file( make
, pFile
, ".h", ".idl" ))) return file
;
1396 if (fontforge
&& (file
= open_local_generated_file( make
, pFile
, ".ttf", ".sfd" ))) return file
;
1397 if (convert
&& rsvg
&& icotool
)
1399 if ((file
= open_local_generated_file( make
, pFile
, ".bmp", ".svg" ))) return file
;
1400 if ((file
= open_local_generated_file( make
, pFile
, ".cur", ".svg" ))) return file
;
1401 if ((file
= open_local_generated_file( make
, pFile
, ".ico", ".svg" ))) return file
;
1404 /* check for extra targets */
1405 if (strarray_exists( &make
->extra_targets
, pFile
->name
))
1407 pFile
->sourcename
= src_dir_path( make
, pFile
->name
);
1408 pFile
->filename
= obj_dir_path( make
, pFile
->name
);
1412 /* now try in source dir */
1413 if ((file
= open_local_file( make
, pFile
->name
, &pFile
->filename
))) return file
;
1415 /* check for global importlib (module dependency) */
1416 if (pFile
->type
== INCL_IMPORTLIB
&& find_importlib_module( pFile
->name
))
1418 pFile
->filename
= pFile
->name
;
1422 /* check for generated files in global includes */
1423 if ((file
= open_global_generated_file( make
, pFile
, ".h", ".idl" ))) return file
;
1424 if ((file
= open_global_generated_file( make
, pFile
, ".h", ".h.in" ))) return file
;
1425 if (strendswith( pFile
->name
, "tmpl.h" ) &&
1426 (file
= open_global_generated_file( make
, pFile
, ".h", ".x" ))) return file
;
1428 /* check in global includes source dir */
1429 if ((file
= open_global_header( pFile
->name
, &pFile
->filename
))) return file
;
1431 /* check in global msvcrt includes */
1432 if (pFile
->use_msvcrt
&&
1433 (file
= open_global_header( strmake( "msvcrt/%s", pFile
->name
), &pFile
->filename
)))
1436 /* now search in include paths */
1437 for (i
= 0; i
< make
->include_paths
.count
; i
++)
1439 const char *dir
= make
->include_paths
.str
[i
];
1443 len
= strlen( root_src_dir
);
1444 if (!strncmp( dir
, root_src_dir
, len
) && (!dir
[len
] || dir
[len
] == '/'))
1446 while (dir
[len
] == '/') len
++;
1447 file
= open_global_file( concat_paths( dir
+ len
, pFile
->name
), &pFile
->filename
);
1452 if (*dir
== '/') continue;
1453 file
= open_include_path_file( make
, dir
, pFile
->name
, &pFile
->filename
);
1455 if (!file
) continue;
1456 pFile
->is_external
= 1;
1460 if (pFile
->type
== INCL_SYSTEM
) return NULL
; /* ignore system files we cannot find */
1462 /* try in src file directory */
1463 if ((file
= open_same_dir_generated_file( make
, pFile
->included_by
, pFile
, ".tab.h", ".y" )) ||
1464 (file
= open_same_dir_generated_file( make
, pFile
->included_by
, pFile
, ".h", ".idl" )) ||
1465 (file
= open_file_same_dir( pFile
->included_by
, pFile
->name
, &pFile
->filename
)))
1467 pFile
->is_external
= pFile
->included_by
->is_external
;
1471 if (make
->extlib
) return NULL
; /* ignore missing files in external libs */
1473 fprintf( stderr
, "%s:%d: error: ", pFile
->included_by
->file
->name
, pFile
->included_line
);
1474 perror( pFile
->name
);
1475 pFile
= pFile
->included_by
;
1476 while (pFile
&& pFile
->included_by
)
1478 const char *parent
= pFile
->included_by
->sourcename
;
1479 if (!parent
) parent
= pFile
->included_by
->file
->name
;
1480 fprintf( stderr
, "%s:%d: note: %s was first included here\n",
1481 parent
, pFile
->included_line
, pFile
->name
);
1482 pFile
= pFile
->included_by
;
1488 /*******************************************************************
1491 static void add_all_includes( struct makefile
*make
, struct incl_file
*parent
, struct file
*file
)
1495 for (i
= 0; i
< file
->deps_count
; i
++)
1497 switch (file
->deps
[i
].type
)
1501 add_include( make
, parent
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_NORMAL
);
1503 case INCL_IMPORTLIB
:
1504 add_include( make
, parent
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_IMPORTLIB
);
1507 add_include( make
, parent
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_SYSTEM
);
1509 case INCL_CPP_QUOTE
:
1510 case INCL_CPP_QUOTE_SYSTEM
:
1517 /*******************************************************************
1520 static void parse_file( struct makefile
*make
, struct incl_file
*source
, int src
)
1522 struct file
*file
= src
? open_src_file( make
, source
) : open_include_file( make
, source
);
1526 source
->file
= file
;
1527 source
->files_count
= 0;
1528 source
->files_size
= file
->deps_count
;
1529 source
->files
= xmalloc( source
->files_size
* sizeof(*source
->files
) );
1531 if (strendswith( file
->name
, ".m" )) file
->flags
|= FLAG_C_UNIX
;
1532 if (file
->flags
& FLAG_C_UNIX
) source
->use_msvcrt
= 0;
1533 else if (file
->flags
& FLAG_C_IMPLIB
) source
->use_msvcrt
= 1;
1535 if (source
->sourcename
)
1537 if (strendswith( source
->sourcename
, ".idl" ))
1541 /* generated .h file always includes these */
1542 add_include( make
, source
, "rpc.h", 0, INCL_NORMAL
);
1543 add_include( make
, source
, "rpcndr.h", 0, INCL_NORMAL
);
1544 for (i
= 0; i
< file
->deps_count
; i
++)
1546 switch (file
->deps
[i
].type
)
1549 if (strendswith( file
->deps
[i
].name
, ".idl" ))
1550 add_include( make
, source
, replace_extension( file
->deps
[i
].name
, ".idl", ".h" ),
1551 file
->deps
[i
].line
, INCL_NORMAL
);
1553 add_include( make
, source
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_NORMAL
);
1555 case INCL_CPP_QUOTE
:
1556 add_include( make
, source
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_NORMAL
);
1558 case INCL_CPP_QUOTE_SYSTEM
:
1559 add_include( make
, source
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_SYSTEM
);
1563 case INCL_IMPORTLIB
:
1569 if (strendswith( source
->sourcename
, ".y" ))
1570 return; /* generated .tab.h doesn't include anything */
1573 add_all_includes( make
, source
, file
);
1577 /*******************************************************************
1580 * Add a source file to the list.
1582 static struct incl_file
*add_src_file( struct makefile
*make
, const char *name
)
1584 struct incl_file
*file
= xmalloc( sizeof(*file
) );
1586 memset( file
, 0, sizeof(*file
) );
1587 file
->name
= xstrdup(name
);
1588 file
->use_msvcrt
= make
->use_msvcrt
;
1589 file
->is_external
= !!make
->extlib
;
1590 list_add_tail( &make
->sources
, &file
->entry
);
1591 if (make
== include_makefile
)
1593 unsigned int hash
= hash_filename( name
);
1594 list_add_tail( &global_includes
[hash
], &file
->hash_entry
);
1596 parse_file( make
, file
, 1 );
1601 /*******************************************************************
1602 * open_input_makefile
1604 static FILE *open_input_makefile( const struct makefile
*make
)
1609 input_file_name
= root_src_dir_path( obj_dir_path( make
, "Makefile.in" ));
1611 input_file_name
= output_makefile_name
; /* always use output name for main Makefile */
1614 if (!(ret
= fopen( input_file_name
, "r" ))) fatal_perror( "open" );
1619 /*******************************************************************
1622 static const char *get_make_variable( const struct makefile
*make
, const char *name
)
1626 if ((ret
= strarray_get_value( &cmdline_vars
, name
))) return ret
;
1627 if ((ret
= strarray_get_value( &make
->vars
, name
))) return ret
;
1628 if (top_makefile
&& (ret
= strarray_get_value( &top_makefile
->vars
, name
))) return ret
;
1633 /*******************************************************************
1634 * get_expanded_make_variable
1636 static char *get_expanded_make_variable( const struct makefile
*make
, const char *name
)
1639 char *p
, *end
, *expand
, *tmp
;
1641 var
= get_make_variable( make
, name
);
1642 if (!var
) return NULL
;
1644 p
= expand
= xstrdup( var
);
1645 while ((p
= strchr( p
, '$' )))
1649 if (!(end
= strchr( p
+ 2, ')' ))) fatal_error( "syntax error in '%s'\n", expand
);
1651 if (strchr( p
+ 2, ':' )) fatal_error( "pattern replacement not supported for '%s'\n", p
+ 2 );
1652 var
= get_make_variable( make
, p
+ 2 );
1653 tmp
= replace_substr( expand
, p
, end
- p
, var
? var
: "" );
1654 /* switch to the new string */
1655 p
= tmp
+ (p
- expand
);
1659 else if (p
[1] == '{') /* don't expand ${} variables */
1661 if (!(end
= strchr( p
+ 2, '}' ))) fatal_error( "syntax error in '%s'\n", expand
);
1664 else if (p
[1] == '$')
1668 else fatal_error( "syntax error in '%s'\n", expand
);
1671 /* consider empty variables undefined */
1673 while (*p
&& isspace(*p
)) p
++;
1674 if (*p
) return expand
;
1680 /*******************************************************************
1681 * get_expanded_make_var_array
1683 static struct strarray
get_expanded_make_var_array( const struct makefile
*make
, const char *name
)
1685 struct strarray ret
= empty_strarray
;
1686 char *value
, *token
;
1688 if ((value
= get_expanded_make_variable( make
, name
)))
1689 for (token
= strtok( value
, " \t" ); token
; token
= strtok( NULL
, " \t" ))
1690 strarray_add( &ret
, token
);
1695 /*******************************************************************
1696 * get_expanded_file_local_var
1698 static struct strarray
get_expanded_file_local_var( const struct makefile
*make
, const char *file
,
1701 char *p
, *var
= strmake( "%s_%s", file
, name
);
1703 for (p
= var
; *p
; p
++) if (!isalnum( *p
)) *p
= '_';
1704 return get_expanded_make_var_array( make
, var
);
1708 /*******************************************************************
1711 static int set_make_variable( struct strarray
*array
, const char *assignment
)
1715 p
= name
= xstrdup( assignment
);
1716 while (isalnum(*p
) || *p
== '_') p
++;
1717 if (name
== p
) return 0; /* not a variable */
1721 while (isspace(*p
)) p
++;
1723 if (*p
!= '=') return 0; /* not an assignment */
1725 while (isspace(*p
)) p
++;
1727 strarray_set_value( array
, name
, p
);
1732 /*******************************************************************
1735 static struct makefile
*parse_makefile( const char *path
)
1739 struct makefile
*make
= xmalloc( sizeof(*make
) );
1741 memset( make
, 0, sizeof(*make
) );
1742 make
->obj_dir
= path
;
1743 if (root_src_dir
) make
->src_dir
= root_src_dir_path( make
->obj_dir
);
1744 if (path
&& !strcmp( path
, "include" )) include_makefile
= make
;
1746 file
= open_input_makefile( make
);
1747 while ((buffer
= get_line( file
)))
1749 if (!strncmp( buffer
, separator
, strlen(separator
) )) break;
1750 if (*buffer
== '\t') continue; /* command */
1751 while (isspace( *buffer
)) buffer
++;
1752 if (*buffer
== '#') continue; /* comment */
1753 set_make_variable( &make
->vars
, buffer
);
1756 input_file_name
= NULL
;
1761 /*******************************************************************
1762 * add_generated_sources
1764 static void add_generated_sources( struct makefile
*make
)
1767 struct incl_file
*source
, *next
, *file
, *dlldata
= NULL
;
1768 struct strarray objs
= get_expanded_make_var_array( make
, "EXTRA_OBJS" );
1770 LIST_FOR_EACH_ENTRY_SAFE( source
, next
, &make
->sources
, struct incl_file
, entry
)
1772 if (source
->file
->flags
& FLAG_IDL_CLIENT
)
1774 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_c.c" ), NULL
);
1775 add_dependency( file
->file
, replace_extension( source
->name
, ".idl", ".h" ), INCL_NORMAL
);
1776 add_all_includes( make
, file
, file
->file
);
1778 if (source
->file
->flags
& FLAG_IDL_SERVER
)
1780 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_s.c" ), NULL
);
1781 add_dependency( file
->file
, "wine/exception.h", INCL_NORMAL
);
1782 add_dependency( file
->file
, replace_extension( source
->name
, ".idl", ".h" ), INCL_NORMAL
);
1783 add_all_includes( make
, file
, file
->file
);
1785 if (source
->file
->flags
& FLAG_IDL_IDENT
)
1787 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_i.c" ), NULL
);
1788 add_dependency( file
->file
, "rpc.h", INCL_NORMAL
);
1789 add_dependency( file
->file
, "rpcndr.h", INCL_NORMAL
);
1790 add_dependency( file
->file
, "guiddef.h", INCL_NORMAL
);
1791 add_all_includes( make
, file
, file
->file
);
1793 if (source
->file
->flags
& FLAG_IDL_PROXY
)
1797 dlldata
= add_generated_source( make
, "dlldata.o", "dlldata.c" );
1798 add_dependency( dlldata
->file
, "objbase.h", INCL_NORMAL
);
1799 add_dependency( dlldata
->file
, "rpcproxy.h", INCL_NORMAL
);
1800 add_all_includes( make
, dlldata
, dlldata
->file
);
1802 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_p.c" ), NULL
);
1803 add_dependency( file
->file
, "objbase.h", INCL_NORMAL
);
1804 add_dependency( file
->file
, "rpcproxy.h", INCL_NORMAL
);
1805 add_dependency( file
->file
, "wine/exception.h", INCL_NORMAL
);
1806 add_dependency( file
->file
, replace_extension( source
->name
, ".idl", ".h" ), INCL_NORMAL
);
1807 add_all_includes( make
, file
, file
->file
);
1809 if (source
->file
->flags
& FLAG_IDL_TYPELIB
)
1811 add_generated_source( make
, replace_extension( source
->name
, ".idl", "_l.res" ), NULL
);
1813 if (source
->file
->flags
& FLAG_IDL_REGTYPELIB
)
1815 add_generated_source( make
, replace_extension( source
->name
, ".idl", "_t.res" ), NULL
);
1817 if (source
->file
->flags
& FLAG_IDL_REGISTER
)
1819 add_generated_source( make
, replace_extension( source
->name
, ".idl", "_r.res" ), NULL
);
1821 if (source
->file
->flags
& FLAG_IDL_HEADER
)
1823 add_generated_source( make
, replace_extension( source
->name
, ".idl", ".h" ), NULL
);
1825 if (!source
->file
->flags
&& strendswith( source
->name
, ".idl" ))
1827 if (!strncmp( source
->name
, "wine/", 5 )) continue;
1828 source
->file
->flags
= FLAG_IDL_HEADER
| FLAG_INSTALL
;
1829 add_generated_source( make
, replace_extension( source
->name
, ".idl", ".h" ), NULL
);
1831 if (strendswith( source
->name
, ".x" ))
1833 add_generated_source( make
, replace_extension( source
->name
, ".x", ".h" ), NULL
);
1835 if (strendswith( source
->name
, ".y" ))
1837 file
= add_generated_source( make
, replace_extension( source
->name
, ".y", ".tab.c" ), NULL
);
1838 /* steal the includes list from the source file */
1839 file
->files_count
= source
->files_count
;
1840 file
->files_size
= source
->files_size
;
1841 file
->files
= source
->files
;
1842 source
->files_count
= source
->files_size
= 0;
1843 source
->files
= NULL
;
1845 if (strendswith( source
->name
, ".l" ))
1847 file
= add_generated_source( make
, replace_extension( source
->name
, ".l", ".yy.c" ), NULL
);
1848 /* steal the includes list from the source file */
1849 file
->files_count
= source
->files_count
;
1850 file
->files_size
= source
->files_size
;
1851 file
->files
= source
->files
;
1852 source
->files_count
= source
->files_size
= 0;
1853 source
->files
= NULL
;
1855 if (source
->file
->flags
& FLAG_C_IMPLIB
)
1857 if (!make
->staticimplib
&& make
->importlib
&& *dll_ext
)
1858 make
->staticimplib
= strmake( "lib%s.a", make
->importlib
);
1860 if (strendswith( source
->name
, ".po" ))
1862 if (!make
->disabled
)
1863 strarray_add_uniq( &linguas
, replace_extension( source
->name
, ".po", "" ));
1865 if (strendswith( source
->name
, ".spec" ))
1867 char *obj
= replace_extension( source
->name
, ".spec", "" );
1868 strarray_addall_uniq( &make
->extra_imports
,
1869 get_expanded_file_local_var( make
, obj
, "IMPORTS" ));
1874 file
= add_generated_source( make
, "testlist.o", "testlist.c" );
1875 add_dependency( file
->file
, "wine/test.h", INCL_NORMAL
);
1876 add_all_includes( make
, file
, file
->file
);
1878 for (i
= 0; i
< objs
.count
; i
++)
1880 /* default to .c for unknown extra object files */
1881 if (strendswith( objs
.str
[i
], ".o" ))
1883 file
= add_generated_source( make
, objs
.str
[i
], replace_extension( objs
.str
[i
], ".o", ".c" ));
1884 file
->file
->flags
|= FLAG_C_UNIX
;
1885 file
->use_msvcrt
= 0;
1887 else if (strendswith( objs
.str
[i
], ".res" ))
1888 add_generated_source( make
, replace_extension( objs
.str
[i
], ".res", ".rc" ), NULL
);
1890 add_generated_source( make
, objs
.str
[i
], NULL
);
1895 /*******************************************************************
1898 static void create_dir( const char *dir
)
1902 p
= path
= xstrdup( dir
);
1903 while ((p
= strchr( p
, '/' )))
1906 if (mkdir( path
, 0755 ) == -1 && errno
!= EEXIST
) fatal_perror( "mkdir %s", path
);
1908 while (*p
== '/') p
++;
1910 if (mkdir( path
, 0755 ) == -1 && errno
!= EEXIST
) fatal_perror( "mkdir %s", path
);
1915 /*******************************************************************
1916 * create_file_directories
1918 * Create the base directories of all the files.
1920 static void create_file_directories( const struct makefile
*make
, struct strarray files
)
1922 struct strarray subdirs
= empty_strarray
;
1926 for (i
= 0; i
< files
.count
; i
++)
1928 if (!strchr( files
.str
[i
], '/' )) continue;
1929 dir
= obj_dir_path( make
, files
.str
[i
] );
1930 *strrchr( dir
, '/' ) = 0;
1931 strarray_add_uniq( &subdirs
, dir
);
1934 for (i
= 0; i
< subdirs
.count
; i
++) create_dir( subdirs
.str
[i
] );
1938 /*******************************************************************
1939 * output_filenames_obj_dir
1941 static void output_filenames_obj_dir( const struct makefile
*make
, struct strarray array
)
1945 for (i
= 0; i
< array
.count
; i
++) output_filename( obj_dir_path( make
, array
.str
[i
] ));
1949 /*******************************************************************
1952 static void get_dependencies( struct incl_file
*file
, struct incl_file
*source
)
1956 if (!file
->filename
) return;
1960 if (file
->owner
== source
) return; /* already processed */
1961 if (file
->type
== INCL_IMPORTLIB
)
1963 if (!(source
->file
->flags
& (FLAG_IDL_TYPELIB
| FLAG_IDL_REGTYPELIB
)))
1964 return; /* library is imported only when building a typelib */
1965 strarray_add( &source
->importlibdeps
, file
->filename
);
1967 else strarray_add( &source
->dependencies
, file
->filename
);
1968 file
->owner
= source
;
1971 if (!strcmp( file
->filename
, "include/config.h" ) &&
1972 file
!= source
->files
[0] && !source
->is_external
)
1974 input_file_name
= source
->filename
;
1976 for (i
= 0; i
< source
->file
->deps_count
; i
++)
1978 if (!strcmp( source
->file
->deps
[i
].name
, file
->name
))
1979 input_line
= source
->file
->deps
[i
].line
;
1981 fatal_error( "%s must be included before other headers\n", file
->name
);
1985 for (i
= 0; i
< file
->files_count
; i
++) get_dependencies( file
->files
[i
], source
);
1989 /*******************************************************************
1990 * get_local_dependencies
1992 * Get the local dependencies of a given target.
1994 static struct strarray
get_local_dependencies( const struct makefile
*make
, const char *name
,
1995 struct strarray targets
)
1998 struct strarray deps
= get_expanded_file_local_var( make
, name
, "DEPS" );
2000 for (i
= 0; i
< deps
.count
; i
++)
2002 if (strarray_exists( &targets
, deps
.str
[i
] ))
2003 deps
.str
[i
] = obj_dir_path( make
, deps
.str
[i
] );
2005 deps
.str
[i
] = src_dir_path( make
, deps
.str
[i
] );
2011 /*******************************************************************
2014 * Check if makefile builds the named static library and return the full lib path.
2016 static const char *get_static_lib( const struct makefile
*make
, const char *name
)
2018 if (!make
->staticlib
) return NULL
;
2019 if (make
->disabled
) return NULL
;
2020 if (strncmp( make
->staticlib
, "lib", 3 )) return NULL
;
2021 if (strncmp( make
->staticlib
+ 3, name
, strlen(name
) )) return NULL
;
2022 if (strcmp( make
->staticlib
+ 3 + strlen(name
), ".a" )) return NULL
;
2023 return obj_dir_path( make
, make
->staticlib
);
2027 /*******************************************************************
2028 * get_native_unix_lib
2030 static const char *get_native_unix_lib( const struct makefile
*make
, const char *name
)
2032 if (!make
->native_unix_lib
) return NULL
;
2033 if (strncmp( make
->unixlib
, name
, strlen(name
) )) return NULL
;
2034 if (make
->unixlib
[strlen(name
)] != '.') return NULL
;
2035 return obj_dir_path( make
, make
->unixlib
);
2039 /*******************************************************************
2040 * get_parent_makefile
2042 static struct makefile
*get_parent_makefile( struct makefile
*make
)
2047 if (!make
->obj_dir
) return NULL
;
2048 dir
= xstrdup( make
->obj_dir
);
2049 if (!(p
= strrchr( dir
, '/' ))) return NULL
;
2051 for (i
= 0; i
< subdirs
.count
; i
++)
2052 if (!strcmp( submakes
[i
]->obj_dir
, dir
)) return submakes
[i
];
2057 /*******************************************************************
2060 static int needs_delay_lib( const struct makefile
*make
)
2062 if (delay_load_flag
) return 0;
2063 if (*dll_ext
&& !crosstarget
) return 0;
2064 if (!make
->importlib
) return 0;
2065 return strarray_exists( &delay_import_libs
, make
->importlib
);
2069 /*******************************************************************
2070 * add_unix_libraries
2072 static struct strarray
add_unix_libraries( const struct makefile
*make
, struct strarray
*deps
)
2074 struct strarray ret
= empty_strarray
;
2075 struct strarray all_libs
= empty_strarray
;
2078 if (strcmp( make
->unixlib
, "ntdll.so" )) strarray_add( &all_libs
, "-lntdll" );
2079 strarray_addall( &all_libs
, get_expanded_make_var_array( make
, "UNIX_LIBS" ));
2081 for (i
= 0; i
< all_libs
.count
; i
++)
2083 const char *lib
= NULL
;
2085 if (!strncmp( all_libs
.str
[i
], "-l", 2 ))
2087 for (j
= 0; j
< subdirs
.count
; j
++)
2089 if (make
== submakes
[j
]) continue;
2090 if ((lib
= get_native_unix_lib( submakes
[j
], all_libs
.str
[i
] + 2 ))) break;
2095 strarray_add( deps
, lib
);
2096 strarray_add( &ret
, lib
);
2098 else strarray_add( &ret
, all_libs
.str
[i
] );
2101 strarray_addall( &ret
, libs
);
2106 /*******************************************************************
2109 static int is_crt_module( const char *file
)
2111 return !strncmp( file
, "msvcr", 5 ) || !strncmp( file
, "ucrt", 4 ) || !strcmp( file
, "crtdll.dll" );
2115 /*******************************************************************
2118 static const char *get_default_crt( const struct makefile
*make
)
2120 if (!make
->use_msvcrt
) return NULL
;
2121 if (make
->module
&& is_crt_module( make
->module
)) return NULL
; /* don't add crt import to crt dlls */
2122 return !make
->testdll
&& (!make
->staticlib
|| make
->extlib
) ? "ucrtbase" : "msvcrt";
2126 /*******************************************************************
2129 static const char *get_crt_define( const struct makefile
*make
)
2131 const char *crt_dll
= NULL
;
2132 unsigned int i
, version
= 0;
2134 for (i
= 0; i
< make
->imports
.count
; i
++)
2136 if (!is_crt_module( make
->imports
.str
[i
] )) continue;
2137 if (crt_dll
) fatal_error( "More than one C runtime DLL imported: %s and %s\n",
2138 crt_dll
, make
->imports
.str
[i
] );
2139 crt_dll
= make
->imports
.str
[i
];
2144 if (strarray_exists( &make
->extradllflags
, "-nodefaultlibs" )) return "-D_MSVCR_VER=0";
2145 if (!(crt_dll
= get_default_crt( make
))) crt_dll
= make
->module
;
2147 if (!strncmp( crt_dll
, "ucrt", 4 )) return "-D_UCRT";
2148 sscanf( crt_dll
, "msvcr%u", &version
);
2149 return strmake( "-D_MSVCR_VER=%u", version
);
2153 /*******************************************************************
2154 * add_default_imports
2156 static struct strarray
add_default_imports( const struct makefile
*make
, struct strarray imports
)
2158 struct strarray ret
= empty_strarray
;
2159 const char *crt_dll
= get_default_crt( make
);
2162 for (i
= 0; i
< imports
.count
; i
++)
2164 if (is_crt_module( imports
.str
[i
] )) crt_dll
= imports
.str
[i
];
2165 else strarray_add( &ret
, imports
.str
[i
] );
2168 strarray_add( &ret
, "winecrt0" );
2169 if (crt_dll
) strarray_add( &ret
, crt_dll
);
2171 if (make
->is_win16
&& (!make
->importlib
|| strcmp( make
->importlib
, "kernel" )))
2172 strarray_add( &ret
, "kernel" );
2174 strarray_add( &ret
, "kernel32" );
2175 strarray_add( &ret
, "ntdll" );
2180 /*******************************************************************
2183 static struct strarray
add_import_libs( const struct makefile
*make
, struct strarray
*deps
,
2184 struct strarray imports
, int delay
, int is_cross
)
2186 struct strarray ret
= empty_strarray
;
2189 for (i
= 0; i
< imports
.count
; i
++)
2191 const char *name
= imports
.str
[i
];
2192 const char *lib
= NULL
;
2198 case 'L': strarray_add( &ret
, name
); continue;
2199 case 'l': name
+= 2; break;
2203 else name
= get_base_name( name
);
2205 for (j
= 0; j
< subdirs
.count
; j
++)
2207 if (submakes
[j
]->importlib
&& !strcmp( submakes
[j
]->importlib
, name
))
2208 lib
= obj_dir_path( submakes
[j
], strmake( "lib%s.a", name
));
2210 lib
= get_static_lib( submakes
[j
], name
);
2216 const char *ext
= NULL
;
2218 if (delay
&& !delay_load_flag
&& (is_cross
|| !*dll_ext
)) ext
= ".delay.a";
2219 else if (is_cross
) ext
= ".cross.a";
2220 if (ext
) lib
= replace_extension( lib
, ".a", ext
);
2221 strarray_add_uniq( deps
, lib
);
2222 strarray_add( &ret
, lib
);
2224 else strarray_add( &ret
, strmake( "-l%s", name
));
2230 /*******************************************************************
2233 static void add_install_rule( struct makefile
*make
, const char *target
,
2234 const char *file
, const char *dest
)
2238 for (i
= 0; i
< NB_INSTALL_RULES
; i
++)
2240 if (strarray_exists( &make
->install
[i
], target
) ||
2241 strarray_exists( &top_install
[i
], make
->obj_dir
) ||
2242 strarray_exists( &top_install
[i
], obj_dir_path( make
, target
)))
2244 strarray_add( &make
->install_rules
[i
], file
);
2245 strarray_add( &make
->install_rules
[i
], dest
);
2252 /*******************************************************************
2253 * get_include_install_path
2255 * Determine the installation path for a given include file.
2257 static const char *get_include_install_path( const char *name
)
2259 if (!strncmp( name
, "wine/", 5 )) return name
+ 5;
2260 if (!strncmp( name
, "msvcrt/", 7 )) return name
;
2261 return strmake( "windows/%s", name
);
2265 /*******************************************************************
2266 * get_shared_library_name
2268 * Determine possible names for a shared library with a version number.
2270 static struct strarray
get_shared_lib_names( const char *libname
)
2272 struct strarray ret
= empty_strarray
;
2273 const char *ext
, *p
;
2274 char *name
, *first
, *second
;
2277 strarray_add( &ret
, libname
);
2279 for (p
= libname
; (p
= strchr( p
, '.' )); p
++)
2280 if ((len
= strspn( p
+ 1, "0123456789." ))) break;
2282 if (!len
) return ret
;
2284 if (*ext
&& ext
[-1] == '.') ext
--;
2286 /* keep only the first group of digits */
2287 name
= xstrdup( libname
);
2288 first
= name
+ (p
- libname
);
2289 if ((second
= strchr( first
+ 1, '.' )))
2291 strcpy( second
, ext
);
2292 strarray_add( &ret
, xstrdup( name
));
2298 /*******************************************************************
2299 * get_source_defines
2301 static struct strarray
get_source_defines( struct makefile
*make
, struct incl_file
*source
,
2305 struct strarray ret
= empty_strarray
;
2307 strarray_addall( &ret
, make
->include_args
);
2308 if (source
->use_msvcrt
)
2310 strarray_add( &ret
, strmake( "-I%s", root_src_dir_path( "include/msvcrt" )));
2311 for (i
= 0; i
< make
->include_paths
.count
; i
++)
2312 strarray_add( &ret
, strmake( "-I%s", make
->include_paths
.str
[i
] ));
2314 strarray_addall( &ret
, make
->define_args
);
2315 strarray_addall( &ret
, get_expanded_file_local_var( make
, obj
, "EXTRADEFS" ));
2316 if ((source
->file
->flags
& FLAG_C_UNIX
) && *dll_ext
) strarray_add( &ret
, "-DWINE_UNIX_LIB" );
2321 /*******************************************************************
2322 * remove_warning_flags
2324 static struct strarray
remove_warning_flags( struct strarray flags
)
2327 struct strarray ret
= empty_strarray
;
2329 for (i
= 0; i
< flags
.count
; i
++)
2330 if (strncmp( flags
.str
[i
], "-W", 2 ) || !strncmp( flags
.str
[i
], "-Wno-", 5 ))
2331 strarray_add( &ret
, flags
.str
[i
] );
2336 /*******************************************************************
2339 static const char *get_debug_file( struct makefile
*make
, const char *name
)
2341 const char *debug_file
= NULL
;
2342 if (!make
->is_cross
|| !crossdebug
) return NULL
;
2343 if (!strcmp( crossdebug
, "pdb" )) debug_file
= strmake( "%s.pdb", get_base_name( name
));
2344 else if(!strncmp( crossdebug
, "split", 5 )) debug_file
= strmake( "%s.debug", name
);
2345 if (debug_file
) strarray_add( &make
->debug_files
, debug_file
);
2350 /*******************************************************************
2353 static const char *cmd_prefix( const char *cmd
)
2355 if (!silent_rules
) return "";
2356 return strmake( "$(quiet_%s)", cmd
);
2360 /*******************************************************************
2361 * output_winegcc_command
2363 static void output_winegcc_command( struct makefile
*make
, int is_cross
)
2365 output( "\t%s%s -o $@", cmd_prefix( "CCLD" ), tools_path( make
, "winegcc" ));
2366 output_filename( "--wine-objdir ." );
2369 output_filename( "--winebuild" );
2370 output_filename( tools_path( make
, "winebuild" ));
2374 output_filename( "-b" );
2375 output_filename( crosstarget
);
2376 output_filename( "--lib-suffix=.cross.a" );
2380 output_filenames( target_flags
);
2381 output_filenames( lddll_flags
);
2386 /*******************************************************************
2387 * output_symlink_rule
2389 * Output a rule to create a symlink.
2391 static void output_symlink_rule( const char *src_name
, const char *link_name
, int create_dir
)
2393 const char *name
= strrchr( link_name
, '/' );
2398 dir
= xstrdup( link_name
);
2399 dir
[name
- link_name
] = 0;
2402 output( "\t%s", cmd_prefix( "LN" ));
2403 if (create_dir
&& dir
&& *dir
) output( "%s -d %s && ", root_src_dir_path( "tools/install-sh" ), dir
);
2404 output( "rm -f %s && ", link_name
);
2406 /* dest path with a directory needs special handling if ln -s isn't supported */
2407 if (dir
&& strcmp( ln_s
, "ln -s" ))
2408 output( "cd %s && %s %s %s\n", *dir
? dir
: "/", ln_s
, src_name
, name
+ 1 );
2410 output( "%s %s %s\n", ln_s
, src_name
, link_name
);
2416 /*******************************************************************
2417 * output_srcdir_symlink
2419 * Output rule to create a symlink back to the source directory, for source files
2420 * that are needed at run-time.
2422 static void output_srcdir_symlink( struct makefile
*make
, const char *obj
)
2424 char *src_file
, *dst_file
, *src_name
;
2426 if (!make
->src_dir
) return;
2427 src_file
= src_dir_path( make
, obj
);
2428 dst_file
= obj_dir_path( make
, obj
);
2429 output( "%s: %s\n", dst_file
, src_file
);
2431 src_name
= src_file
;
2432 if (src_name
[0] != '/' && make
->obj_dir
)
2433 src_name
= concat_paths( get_relative_path( make
->obj_dir
, "" ), src_name
);
2435 output_symlink_rule( src_name
, dst_file
, 0 );
2436 strarray_add( &make
->all_targets
, obj
);
2440 /*******************************************************************
2441 * output_install_commands
2443 static void output_install_commands( struct makefile
*make
, struct strarray files
)
2446 char *install_sh
= root_src_dir_path( "tools/install-sh" );
2448 for (i
= 0; i
< files
.count
; i
+= 2)
2450 const char *file
= files
.str
[i
];
2451 const char *dest
= strmake( "$(DESTDIR)%s", files
.str
[i
+ 1] + 1 );
2453 switch (*files
.str
[i
+ 1])
2455 case 'c': /* cross-compiled program */
2456 output( "\tSTRIPPROG=%s-strip %s -m 644 $(INSTALL_PROGRAM_FLAGS) %s %s\n",
2457 crosstarget
, install_sh
, obj_dir_path( make
, file
), dest
);
2458 output( "\t%s --builtin %s\n", tools_path( make
, "winebuild" ), dest
);
2460 case 'd': /* data file */
2461 output( "\t%s -m 644 $(INSTALL_DATA_FLAGS) %s %s\n",
2462 install_sh
, obj_dir_path( make
, file
), dest
);
2464 case 'D': /* data file in source dir */
2465 output( "\t%s -m 644 $(INSTALL_DATA_FLAGS) %s %s\n",
2466 install_sh
, src_dir_path( make
, file
), dest
);
2468 case 'p': /* program file */
2469 output( "\tSTRIPPROG=\"$(STRIP)\" %s $(INSTALL_PROGRAM_FLAGS) %s %s\n",
2470 install_sh
, obj_dir_path( make
, file
), dest
);
2472 case 's': /* script */
2473 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s %s\n",
2474 install_sh
, obj_dir_path( make
, file
), dest
);
2476 case 'S': /* script in source dir */
2477 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s %s\n",
2478 install_sh
, src_dir_path( make
, file
), dest
);
2480 case 't': /* script in tools dir */
2481 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s %s\n",
2482 install_sh
, tools_dir_path( make
, files
.str
[i
] ), dest
);
2484 case 'y': /* symlink */
2485 output_symlink_rule( files
.str
[i
], dest
, 1 );
2490 strarray_add( &make
->uninstall_files
, dest
);
2495 /*******************************************************************
2496 * output_install_rules
2498 * Rules are stored as a (file,dest) pair of values.
2499 * The first char of dest indicates the type of install.
2501 static void output_install_rules( struct makefile
*make
, enum install_rules rules
)
2504 struct strarray files
= make
->install_rules
[rules
];
2505 struct strarray targets
= empty_strarray
;
2507 if (!files
.count
) return;
2509 for (i
= 0; i
< files
.count
; i
+= 2)
2511 const char *file
= files
.str
[i
];
2512 switch (*files
.str
[i
+ 1])
2514 case 'c': /* cross-compiled program */
2515 case 'd': /* data file */
2516 case 'p': /* program file */
2517 case 's': /* script */
2518 strarray_add_uniq( &targets
, obj_dir_path( make
, file
));
2520 case 't': /* script in tools dir */
2521 strarray_add_uniq( &targets
, tools_dir_path( make
, file
));
2526 output( "%s %s::", obj_dir_path( make
, "install" ), obj_dir_path( make
, install_targets
[rules
] ));
2527 output_filenames( targets
);
2529 output_install_commands( make
, files
);
2530 strarray_add_uniq( &make
->phony_targets
, obj_dir_path( make
, "install" ));
2531 strarray_add_uniq( &make
->phony_targets
, obj_dir_path( make
, install_targets
[rules
] ));
2535 static int cmp_string_length( const char **a
, const char **b
)
2537 int paths_a
= 0, paths_b
= 0;
2540 for (p
= *a
; *p
; p
++) if (*p
== '/') paths_a
++;
2541 for (p
= *b
; *p
; p
++) if (*p
== '/') paths_b
++;
2542 if (paths_b
!= paths_a
) return paths_b
- paths_a
;
2543 return strcmp( *a
, *b
);
2546 /*******************************************************************
2547 * output_uninstall_rules
2549 static void output_uninstall_rules( struct makefile
*make
)
2551 static const char *dirs_order
[] =
2552 { "$(includedir)", "$(mandir)", "$(fontdir)", "$(nlsdir)", "$(datadir)", "$(dlldir)" };
2554 struct strarray uninstall_dirs
= empty_strarray
;
2557 if (!make
->uninstall_files
.count
) return;
2558 output( "uninstall::\n" );
2559 output_rm_filenames( make
->uninstall_files
);
2560 strarray_add_uniq( &make
->phony_targets
, "uninstall" );
2562 if (!subdirs
.count
) return;
2563 for (i
= 0; i
< make
->uninstall_files
.count
; i
++)
2565 char *dir
= xstrdup( make
->uninstall_files
.str
[i
] );
2566 while (strchr( dir
, '/' ))
2568 *strrchr( dir
, '/' ) = 0;
2569 strarray_add_uniq( &uninstall_dirs
, xstrdup(dir
) );
2572 strarray_qsort( &uninstall_dirs
, cmp_string_length
);
2573 output( "\t-rmdir" );
2574 for (i
= 0; i
< sizeof(dirs_order
)/sizeof(dirs_order
[0]); i
++)
2576 for (j
= 0; j
< uninstall_dirs
.count
; j
++)
2578 if (!uninstall_dirs
.str
[j
]) continue;
2579 if (strncmp( uninstall_dirs
.str
[j
] + strlen("$(DESTDIR)"), dirs_order
[i
], strlen(dirs_order
[i
]) ))
2581 output_filename( uninstall_dirs
.str
[j
] );
2582 uninstall_dirs
.str
[j
] = NULL
;
2585 for (j
= 0; j
< uninstall_dirs
.count
; j
++)
2586 if (uninstall_dirs
.str
[j
]) output_filename( uninstall_dirs
.str
[j
] );
2591 /*******************************************************************
2594 static void output_po_files( struct makefile
*make
)
2596 const char *po_dir
= src_dir_path( make
, "po" );
2601 for (i
= 0; i
< linguas
.count
; i
++)
2602 output_filename( strmake( "%s/%s.po", po_dir
, linguas
.str
[i
] ));
2603 output( ": %s/wine.pot\n", po_dir
);
2604 output( "\t%smsgmerge --previous -q $@ %s/wine.pot | msgattrib --no-obsolete -o $@.new && mv $@.new $@\n",
2605 cmd_prefix( "MSG" ), po_dir
);
2606 output( "po/all:" );
2607 for (i
= 0; i
< linguas
.count
; i
++)
2608 output_filename( strmake( "%s/%s.po", po_dir
, linguas
.str
[i
] ));
2611 output( "%s/wine.pot:", po_dir
);
2612 output_filenames( make
->pot_files
);
2614 output( "\t%smsgcat -o $@", cmd_prefix( "MSG" ));
2615 output_filenames( make
->pot_files
);
2617 strarray_add( &make
->maintainerclean_files
, strmake( "%s/wine.pot", po_dir
));
2621 /*******************************************************************
2624 static void output_source_y( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2626 /* add source file dependency for parallel makes */
2627 char *header
= strmake( "%s.tab.h", obj
);
2629 if (find_include_file( make
, header
))
2631 output( "%s: %s\n", obj_dir_path( make
, header
), source
->filename
);
2632 output( "\t%s%s -o %s.tab.c -d %s\n",
2633 cmd_prefix( "BISON" ), bison
, obj_dir_path( make
, obj
), source
->filename
);
2634 output( "%s.tab.c: %s %s\n", obj_dir_path( make
, obj
),
2635 source
->filename
, obj_dir_path( make
, header
));
2636 strarray_add( &make
->clean_files
, header
);
2638 else output( "%s.tab.c: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2640 output( "\t%s%s -o $@ %s\n", cmd_prefix( "BISON" ), bison
, source
->filename
);
2644 /*******************************************************************
2647 static void output_source_l( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2649 output( "%s.yy.c: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2650 output( "\t%s%s -o$@ %s\n", cmd_prefix( "FLEX" ), flex
, source
->filename
);
2654 /*******************************************************************
2657 static void output_source_h( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2659 if (source
->file
->flags
& FLAG_GENERATED
)
2660 strarray_add( &make
->all_targets
, source
->name
);
2661 else if ((source
->file
->flags
& FLAG_INSTALL
) || strncmp( source
->name
, "wine/", 5 ))
2662 add_install_rule( make
, source
->name
, source
->name
,
2663 strmake( "D$(includedir)/wine/%s", get_include_install_path( source
->name
) ));
2667 /*******************************************************************
2670 static void output_source_rc( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2672 struct strarray defines
= get_source_defines( make
, source
, obj
);
2673 const char *po_dir
= NULL
;
2676 if (source
->file
->flags
& FLAG_RC_HEADER
) return;
2677 if (source
->file
->flags
& FLAG_GENERATED
) strarray_add( &make
->clean_files
, source
->name
);
2678 if (linguas
.count
&& (source
->file
->flags
& FLAG_RC_PO
)) po_dir
= "po";
2679 strarray_add( &make
->res_files
, strmake( "%s.res", obj
));
2680 if (source
->file
->flags
& FLAG_RC_PO
)
2682 strarray_add( &make
->pot_files
, strmake( "%s.pot", obj
));
2683 output( "%s.pot ", obj_dir_path( make
, obj
) );
2685 output( "%s.res: %s", obj_dir_path( make
, obj
), source
->filename
);
2686 output_filename( tools_path( make
, "wrc" ));
2687 if (make
->src_dir
) output_filename( "nls/locale.nls" );
2688 output_filenames( source
->dependencies
);
2690 output( "\t%s%s -u -o $@", cmd_prefix( "WRC" ), tools_path( make
, "wrc" ) );
2691 if (make
->is_win16
) output_filename( "-m16" );
2692 output_filename( "--nostdinc" );
2693 if (po_dir
) output_filename( strmake( "--po-dir=%s", po_dir
));
2694 output_filenames( defines
);
2695 output_filename( source
->filename
);
2699 output( "%s.res:", obj_dir_path( make
, obj
));
2700 for (i
= 0; i
< linguas
.count
; i
++)
2701 output_filename( strmake( "%s/%s.mo", po_dir
, linguas
.str
[i
] ));
2707 /*******************************************************************
2710 static void output_source_mc( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2713 char *obj_path
= obj_dir_path( make
, obj
);
2715 strarray_add( &make
->res_files
, strmake( "%s.res", obj
));
2716 strarray_add( &make
->pot_files
, strmake( "%s.pot", obj
));
2717 output( "%s.pot %s.res: %s", obj_path
, obj_path
, source
->filename
);
2718 output_filename( tools_path( make
, "wmc" ));
2719 output_filenames( source
->dependencies
);
2721 output( "\t%s%s -u -o $@ %s", cmd_prefix( "WMC" ), tools_path( make
, "wmc" ), source
->filename
);
2724 output_filename( "--po-dir=po" );
2726 output( "%s.res:", obj_dir_path( make
, obj
));
2727 for (i
= 0; i
< linguas
.count
; i
++)
2728 output_filename( strmake( "po/%s.mo", linguas
.str
[i
] ));
2734 /*******************************************************************
2737 static void output_source_res( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2739 strarray_add( &make
->res_files
, source
->name
);
2743 /*******************************************************************
2746 static void output_source_idl( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2748 struct strarray defines
= get_source_defines( make
, source
, obj
);
2749 struct strarray targets
= empty_strarray
;
2753 if (find_include_file( make
, strmake( "%s.h", obj
))) source
->file
->flags
|= FLAG_IDL_HEADER
;
2754 if (!source
->file
->flags
) return;
2756 for (i
= 0; i
< sizeof(idl_outputs
) / sizeof(idl_outputs
[0]); i
++)
2758 if (!(source
->file
->flags
& idl_outputs
[i
].flag
)) continue;
2759 dest
= strmake( "%s%s", obj
, idl_outputs
[i
].ext
);
2760 if (!find_src_file( make
, dest
)) strarray_add( &make
->clean_files
, dest
);
2761 strarray_add( &targets
, dest
);
2763 if (source
->file
->flags
& FLAG_IDL_PROXY
) strarray_add( &make
->dlldata_files
, source
->name
);
2764 if (source
->file
->flags
& FLAG_INSTALL
)
2766 add_install_rule( make
, source
->name
, xstrdup( source
->name
),
2767 strmake( "D$(includedir)/wine/%s.idl", get_include_install_path( obj
) ));
2768 if (source
->file
->flags
& FLAG_IDL_HEADER
)
2769 add_install_rule( make
, source
->name
, strmake( "%s.h", obj
),
2770 strmake( "d$(includedir)/wine/%s.h", get_include_install_path( obj
) ));
2772 if (!targets
.count
) return;
2774 output_filenames_obj_dir( make
, targets
);
2775 output( ": %s\n", tools_path( make
, "widl" ));
2776 output( "\t%s%s -o $@", cmd_prefix( "WIDL" ), tools_path( make
, "widl" ) );
2777 output_filenames( target_flags
);
2778 output_filename( "--nostdinc" );
2779 output_filename( "-Ldlls/\\*" );
2780 output_filenames( defines
);
2781 output_filenames( get_expanded_make_var_array( make
, "EXTRAIDLFLAGS" ));
2782 output_filenames( get_expanded_file_local_var( make
, obj
, "EXTRAIDLFLAGS" ));
2783 output_filename( source
->filename
);
2785 output_filenames_obj_dir( make
, targets
);
2786 output( ": %s", source
->filename
);
2787 output_filenames( source
->dependencies
);
2788 for (i
= 0; i
< source
->importlibdeps
.count
; i
++)
2790 struct makefile
*submake
= find_importlib_module( source
->importlibdeps
.str
[i
] );
2791 output_filename( obj_dir_path( submake
, submake
->module
));
2797 /*******************************************************************
2800 static void output_source_x( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2802 output( "%s.h: %s%s %s\n", obj_dir_path( make
, obj
),
2803 tools_dir_path( make
, "make_xftmpl" ), tools_ext
, source
->filename
);
2804 output( "\t%s%s%s -H -o $@ %s\n", cmd_prefix( "GEN" ),
2805 tools_dir_path( make
, "make_xftmpl" ), tools_ext
, source
->filename
);
2806 if (source
->file
->flags
& FLAG_INSTALL
)
2808 add_install_rule( make
, source
->name
, source
->name
,
2809 strmake( "D$(includedir)/wine/%s", get_include_install_path( source
->name
) ));
2810 add_install_rule( make
, source
->name
, strmake( "%s.h", obj
),
2811 strmake( "d$(includedir)/wine/%s.h", get_include_install_path( obj
) ));
2816 /*******************************************************************
2819 static void output_source_sfd( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2822 char *ttf_obj
= strmake( "%s.ttf", obj
);
2823 char *ttf_file
= src_dir_path( make
, ttf_obj
);
2825 if (fontforge
&& !make
->src_dir
)
2827 output( "%s: %s\n", ttf_file
, source
->filename
);
2828 output( "\t%s%s -script %s %s $@\n", cmd_prefix( "GEN" ),
2829 fontforge
, root_src_dir_path( "fonts/genttf.ff" ), source
->filename
);
2830 if (!(source
->file
->flags
& FLAG_SFD_FONTS
)) strarray_add( &make
->font_files
, ttf_obj
);
2831 strarray_add( &make
->maintainerclean_files
, ttf_obj
);
2833 if (source
->file
->flags
& FLAG_INSTALL
)
2835 add_install_rule( make
, source
->name
, ttf_obj
, strmake( "D$(fontdir)/%s", ttf_obj
));
2836 output_srcdir_symlink( make
, ttf_obj
);
2839 if (source
->file
->flags
& FLAG_SFD_FONTS
)
2841 struct strarray
*array
= source
->file
->args
;
2843 for (i
= 0; i
< array
->count
; i
++)
2845 char *font
= strtok( xstrdup(array
->str
[i
]), " \t" );
2846 char *args
= strtok( NULL
, "" );
2848 strarray_add( &make
->all_targets
, xstrdup( font
));
2849 output( "%s: %s %s\n", obj_dir_path( make
, font
),
2850 tools_path( make
, "sfnt2fon" ), ttf_file
);
2851 output( "\t%s%s -q -o $@ %s %s\n", cmd_prefix( "GEN" ),
2852 tools_path( make
, "sfnt2fon" ), ttf_file
, args
);
2853 add_install_rule( make
, source
->name
, xstrdup(font
), strmake( "d$(fontdir)/%s", font
));
2859 /*******************************************************************
2862 static void output_source_svg( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2864 static const char * const images
[] = { "bmp", "cur", "ico", NULL
};
2867 if (convert
&& rsvg
&& icotool
)
2869 for (i
= 0; images
[i
]; i
++)
2870 if (find_include_file( make
, strmake( "%s.%s", obj
, images
[i
] ))) break;
2874 output( "%s.%s: %s\n", src_dir_path( make
, obj
), images
[i
], source
->filename
);
2875 output( "\t%sCONVERT=\"%s\" ICOTOOL=\"%s\" RSVG=\"%s\" %s %s $@\n",
2876 cmd_prefix( "GEN" ), convert
, icotool
, rsvg
,
2877 root_src_dir_path( "tools/buildimage" ), source
->filename
);
2878 strarray_add( &make
->maintainerclean_files
, strmake( "%s.%s", obj
, images
[i
] ));
2884 /*******************************************************************
2887 static void output_source_nls( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2889 add_install_rule( make
, source
->name
, source
->name
,
2890 strmake( "D$(nlsdir)/%s", source
->name
));
2891 output_srcdir_symlink( make
, strmake( "%s.nls", obj
));
2895 /*******************************************************************
2896 * output_source_desktop
2898 static void output_source_desktop( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2900 add_install_rule( make
, source
->name
, source
->name
,
2901 strmake( "D$(datadir)/applications/%s", source
->name
));
2905 /*******************************************************************
2908 static void output_source_po( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2910 output( "%s.mo: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2911 output( "\t%s%s -o $@ %s\n", cmd_prefix( "MSG" ), msgfmt
, source
->filename
);
2912 strarray_add( &make
->all_targets
, strmake( "%s.mo", obj
));
2916 /*******************************************************************
2919 static void output_source_in( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2923 if (make
== include_makefile
) return; /* ignore generated includes */
2924 if (strendswith( obj
, ".man" ) && source
->file
->args
)
2926 struct strarray symlinks
;
2927 char *dir
, *dest
= replace_extension( obj
, ".man", "" );
2928 char *lang
= strchr( dest
, '.' );
2929 char *section
= source
->file
->args
;
2933 dir
= strmake( "$(mandir)/%s/man%s", lang
, section
);
2935 else dir
= strmake( "$(mandir)/man%s", section
);
2936 add_install_rule( make
, dest
, xstrdup(obj
), strmake( "d%s/%s.%s", dir
, dest
, section
));
2937 symlinks
= get_expanded_file_local_var( make
, dest
, "SYMLINKS" );
2938 for (i
= 0; i
< symlinks
.count
; i
++)
2939 add_install_rule( make
, symlinks
.str
[i
], strmake( "%s.%s", dest
, section
),
2940 strmake( "y%s/%s.%s", dir
, symlinks
.str
[i
], section
));
2944 strarray_add( &make
->in_files
, xstrdup(obj
) );
2945 strarray_add( &make
->all_targets
, xstrdup(obj
) );
2946 output( "%s: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2947 output( "\t%s%s %s >$@ || (rm -f $@ && false)\n", cmd_prefix( "SED" ), sed_cmd
, source
->filename
);
2948 output( "%s:", obj_dir_path( make
, obj
));
2949 output_filenames( source
->dependencies
);
2951 add_install_rule( make
, obj
, xstrdup( obj
), strmake( "d$(datadir)/wine/%s", obj
));
2955 /*******************************************************************
2956 * output_source_spec
2958 static void output_source_spec( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2960 struct strarray imports
= get_expanded_file_local_var( make
, obj
, "IMPORTS" );
2961 struct strarray dll_flags
= get_expanded_file_local_var( make
, obj
, "EXTRADLLFLAGS" );
2962 struct strarray all_libs
, dep_libs
= empty_strarray
;
2963 char *dll_name
, *obj_name
, *output_file
;
2964 const char *debug_file
;
2966 if (!imports
.count
) imports
= make
->imports
;
2967 if (!dll_flags
.count
) dll_flags
= make
->extradllflags
;
2968 if (!strarray_exists( &dll_flags
, "-nodefaultlibs" )) imports
= add_default_imports( make
, imports
);
2970 all_libs
= add_import_libs( make
, &dep_libs
, imports
, 0, make
->is_cross
);
2971 dll_name
= strmake( "%s.dll%s", obj
, make
->is_cross
? "" : dll_ext
);
2972 obj_name
= strmake( "%s%s", obj_dir_path( make
, obj
), make
->is_cross
? ".cross.o" : ".o" );
2973 output_file
= obj_dir_path( make
, dll_name
);
2975 strarray_add( &make
->clean_files
, dll_name
);
2976 strarray_add( &make
->res_files
, strmake( "%s.res", obj
));
2977 output( "%s.res:", obj_dir_path( make
, obj
));
2978 output_filename( obj_dir_path( make
, dll_name
));
2979 output_filename( tools_path( make
, "wrc" ));
2981 output( "\t%secho \"%s.dll TESTDLL \\\"%s\\\"\" | %s -u -o $@\n", cmd_prefix( "WRC" ), obj
, output_file
,
2982 tools_path( make
, "wrc" ));
2984 output( "%s:", output_file
);
2985 output_filename( source
->filename
);
2986 output_filename( obj_name
);
2987 output_filenames( dep_libs
);
2988 output_filename( tools_path( make
, "winebuild" ));
2989 output_filename( tools_path( make
, "winegcc" ));
2991 output_winegcc_command( make
, make
->is_cross
);
2992 output_filename( "-s" );
2993 output_filenames( dll_flags
);
2994 output_filename( "-shared" );
2995 output_filename( source
->filename
);
2996 output_filename( obj_name
);
2997 if ((debug_file
= get_debug_file( make
, dll_name
)))
2998 output_filename( strmake( "-Wl,--debug-file,%s", obj_dir_path( make
, debug_file
)));
2999 output_filenames( all_libs
);
3000 output_filename( make
->is_cross
? "$(CROSSLDFLAGS)" : "$(LDFLAGS)" );
3005 /*******************************************************************
3006 * output_source_default
3008 static void output_source_default( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
3010 struct strarray defines
= get_source_defines( make
, source
, obj
);
3011 int is_dll_src
= (make
->testdll
&&
3012 strendswith( source
->name
, ".c" ) &&
3013 find_src_file( make
, replace_extension( source
->name
, ".c", ".spec" )));
3014 int need_cross
= (crosstarget
&&
3015 !(source
->file
->flags
& FLAG_C_UNIX
) &&
3016 (make
->is_cross
|| make
->staticlib
||
3017 (source
->file
->flags
& FLAG_C_IMPLIB
)));
3018 int need_obj
= ((*dll_ext
|| !(source
->file
->flags
& FLAG_C_UNIX
)) &&
3020 (source
->file
->flags
& FLAG_C_IMPLIB
) ||
3021 (make
->staticlib
&& !make
->extlib
)));
3023 if ((source
->file
->flags
& FLAG_GENERATED
) &&
3024 (!make
->testdll
|| !strendswith( source
->filename
, "testlist.c" )))
3025 strarray_add( &make
->clean_files
, source
->basename
);
3029 if ((source
->file
->flags
& FLAG_C_UNIX
) && *dll_ext
)
3030 strarray_add( &make
->unixobj_files
, strmake( "%s.o", obj
));
3031 else if (source
->file
->flags
& FLAG_C_IMPLIB
)
3032 strarray_add( &make
->implib_files
, strmake( "%s.o", obj
));
3033 else if (!is_dll_src
)
3034 strarray_add( &make
->object_files
, strmake( "%s.o", obj
));
3036 strarray_add( &make
->clean_files
, strmake( "%s.o", obj
));
3037 output( "%s.o: %s\n", obj_dir_path( make
, obj
), source
->filename
);
3038 output( "\t%s$(CC) -c -o $@ %s", cmd_prefix( "CC" ), source
->filename
);
3039 output_filenames( defines
);
3040 if (!source
->use_msvcrt
) output_filenames( make
->unix_cflags
);
3041 output_filenames( make
->extlib
? extra_cflags_extlib
: extra_cflags
);
3042 if (make
->sharedlib
|| (source
->file
->flags
& FLAG_C_UNIX
))
3044 output_filenames( unix_dllflags
);
3046 else if (make
->module
|| make
->testdll
)
3048 output_filenames( dll_flags
);
3049 if (source
->use_msvcrt
) output_filenames( msvcrt_flags
);
3050 if (!*dll_ext
&& make
->module
&& is_crt_module( make
->module
))
3051 output_filename( "-fno-builtin" );
3053 output_filenames( cpp_flags
);
3054 output_filename( "$(CFLAGS)" );
3059 if (source
->file
->flags
& FLAG_C_IMPLIB
)
3060 strarray_add( &make
->crossimplib_files
, strmake( "%s.cross.o", obj
));
3061 else if (!is_dll_src
)
3062 strarray_add( &make
->crossobj_files
, strmake( "%s.cross.o", obj
));
3064 strarray_add( &make
->clean_files
, strmake( "%s.cross.o", obj
));
3065 output( "%s.cross.o: %s\n", obj_dir_path( make
, obj
), source
->filename
);
3066 output( "\t%s$(CROSSCC) -c -o $@ %s", cmd_prefix( "CC" ), source
->filename
);
3067 output_filenames( defines
);
3068 output_filenames( make
->extlib
? extra_cross_cflags_extlib
: extra_cross_cflags
);
3069 if (make
->module
&& is_crt_module( make
->module
))
3070 output_filename( "-fno-builtin" );
3071 /* force -Wformat when using 'long' types, until all modules have been converted
3072 * and we can remove -Wno-format */
3073 if (!make
->extlib
&& strarray_exists( &extra_cross_cflags
, "-Wno-format" ) &&
3074 !strarray_exists( &defines
, "-DWINE_NO_LONG_TYPES" ))
3075 output_filename( "-Wformat" );
3076 output_filenames( cpp_flags
);
3077 output_filename( "$(CROSSCFLAGS)" );
3080 if (make
->testdll
&& !is_dll_src
&& strendswith( source
->name
, ".c" ) &&
3081 !(source
->file
->flags
& FLAG_GENERATED
))
3083 strarray_add( &make
->test_files
, obj
);
3084 strarray_add( &make
->ok_files
, strmake( "%s.ok", obj
));
3085 output( "%s.ok:\n", obj_dir_path( make
, obj
));
3086 output( "\t%s%s $(RUNTESTFLAGS) -T . -M %s -p %s%s %s && touch $@\n",
3087 cmd_prefix( "TEST" ),
3088 root_src_dir_path( "tools/runtest" ), make
->testdll
,
3089 obj_dir_path( make
, replace_extension( make
->testdll
, ".dll", "_test.exe" )),
3090 make
->is_cross
? "" : dll_ext
, obj
);
3092 if (need_obj
) output_filename( strmake( "%s.o", obj_dir_path( make
, obj
)));
3093 if (need_cross
) output_filename( strmake( "%s.cross.o", obj_dir_path( make
, obj
)));
3095 output_filenames( source
->dependencies
);
3100 /* dispatch table to output rules for a single source file */
3104 void (*fn
)( struct makefile
*make
, struct incl_file
*source
, const char *obj
);
3105 } output_source_funcs
[] =
3107 { "y", output_source_y
},
3108 { "l", output_source_l
},
3109 { "h", output_source_h
},
3110 { "rh", output_source_h
},
3111 { "inl", output_source_h
},
3112 { "rc", output_source_rc
},
3113 { "mc", output_source_mc
},
3114 { "res", output_source_res
},
3115 { "idl", output_source_idl
},
3116 { "sfd", output_source_sfd
},
3117 { "svg", output_source_svg
},
3118 { "nls", output_source_nls
},
3119 { "desktop", output_source_desktop
},
3120 { "po", output_source_po
},
3121 { "in", output_source_in
},
3122 { "x", output_source_x
},
3123 { "spec", output_source_spec
},
3124 { NULL
, output_source_default
}
3128 /*******************************************************************
3131 static char *get_unix_lib_name( struct makefile
*make
)
3133 struct incl_file
*source
;
3135 if (!*dll_ext
) return NULL
;
3136 LIST_FOR_EACH_ENTRY( source
, &make
->sources
, struct incl_file
, entry
)
3138 if (!(source
->file
->flags
& FLAG_C_UNIX
)) continue;
3139 return strmake( "%s%s", get_base_name( make
->module
), dll_ext
);
3145 /*******************************************************************
3148 static void output_module( struct makefile
*make
)
3150 struct strarray all_libs
= empty_strarray
;
3151 struct strarray dep_libs
= empty_strarray
;
3152 struct strarray imports
= make
->imports
;
3153 const char *module_name
= make
->module
;
3154 const char *debug_file
;
3155 const char *delay_load
= delay_load_flag
;
3156 char *spec_file
= NULL
;
3159 if (!make
->is_exe
) spec_file
= src_dir_path( make
, replace_extension( make
->module
, ".dll", ".spec" ));
3161 if (!make
->data_only
)
3163 if (*dll_ext
&& !make
->is_cross
&& !make
->data_only
)
3164 module_name
= strmake( "%s%s", make
->module
, dll_ext
);
3166 if (!strarray_exists( &make
->extradllflags
, "-nodefaultlibs" ))
3167 imports
= add_default_imports( make
, imports
);
3169 strarray_addall( &all_libs
, add_import_libs( make
, &dep_libs
, make
->delayimports
, 1, make
->is_cross
));
3170 strarray_addall( &all_libs
, add_import_libs( make
, &dep_libs
, imports
, 0, make
->is_cross
));
3172 if (!make
->use_msvcrt
)
3174 strarray_addall( &all_libs
, get_expanded_make_var_array( make
, "UNIX_LIBS" ));
3175 strarray_addall( &all_libs
, libs
);
3178 if (!make
->is_cross
&& *dll_ext
) delay_load
= "-Wl,-delayload,";
3181 for (i
= 0; i
< make
->delayimports
.count
; i
++)
3182 strarray_add( &all_libs
, strmake( "%s%s%s", delay_load
, make
->delayimports
.str
[i
],
3183 strchr( make
->delayimports
.str
[i
], '.' ) ? "" : ".dll" ));
3186 strarray_add( &make
->all_targets
, module_name
);
3188 if (make
->data_only
)
3189 add_install_rule( make
, make
->module
, module_name
,
3190 strmake( "d%s/%s", *dll_ext
? pe_dir
: "$(dlldir)", module_name
));
3191 else if (make
->is_cross
)
3192 add_install_rule( make
, make
->module
, module_name
, strmake( "c%s/%s", pe_dir
, module_name
));
3194 add_install_rule( make
, make
->module
, module_name
, strmake( "p%s/%s", so_dir
, module_name
));
3196 add_install_rule( make
, make
->module
, module_name
,
3197 strmake( "p$(%s)/%s", spec_file
? "dlldir" : "bindir", module_name
));
3199 output( "%s:", obj_dir_path( make
, module_name
));
3200 if (spec_file
) output_filename( spec_file
);
3201 output_filenames_obj_dir( make
, make
->is_cross
? make
->crossobj_files
: make
->object_files
);
3202 output_filenames_obj_dir( make
, make
->res_files
);
3203 output_filenames( dep_libs
);
3204 output_filename( tools_path( make
, "winebuild" ));
3205 output_filename( tools_path( make
, "winegcc" ));
3207 output_winegcc_command( make
, make
->is_cross
);
3208 if (make
->is_cross
) output_filename( "-Wl,--wine-builtin" );
3211 output_filename( "-shared" );
3212 output_filename( spec_file
);
3214 output_filenames( make
->extradllflags
);
3215 output_filenames_obj_dir( make
, make
->is_cross
? make
->crossobj_files
: make
->object_files
);
3216 output_filenames_obj_dir( make
, make
->res_files
);
3217 debug_file
= get_debug_file( make
, make
->module
);
3218 if (debug_file
) output_filename( strmake( "-Wl,--debug-file,%s", obj_dir_path( make
, debug_file
)));
3219 output_filenames( all_libs
);
3220 output_filename( make
->is_cross
? "$(CROSSLDFLAGS)" : "$(LDFLAGS)" );
3223 if (*dll_ext
&& make
->is_exe
&& !make
->is_win16
&& strendswith( make
->module
, ".exe" ))
3225 char *binary
= replace_extension( make
->module
, ".exe", "" );
3226 add_install_rule( make
, binary
, "wineapploader", strmake( "t$(bindir)/%s", binary
));
3231 /*******************************************************************
3232 * output_fake_module
3234 static void output_fake_module( struct makefile
*make
)
3236 char *spec_file
= NULL
;
3238 if (!make
->is_exe
) spec_file
= src_dir_path( make
, replace_extension( make
->module
, ".dll", ".spec" ));
3240 strarray_add( &make
->all_targets
, make
->module
);
3241 add_install_rule( make
, make
->module
, make
->module
, strmake( "d%s/%s", pe_dir
, make
->module
));
3243 output( "%s:", obj_dir_path( make
, make
->module
));
3244 if (spec_file
) output_filename( spec_file
);
3245 output_filenames_obj_dir( make
, make
->res_files
);
3246 output_filename( tools_path( make
, "winebuild" ));
3247 output_filename( tools_path( make
, "winegcc" ));
3249 output_winegcc_command( make
, make
->is_cross
);
3250 output_filename( "-Wb,--fake-module" );
3253 output_filename( "-shared" );
3254 output_filename( spec_file
);
3256 output_filenames( make
->extradllflags
);
3257 output_filenames_obj_dir( make
, make
->res_files
);
3262 /*******************************************************************
3265 static void output_import_lib( struct makefile
*make
)
3267 char *spec_file
= src_dir_path( make
, replace_extension( make
->module
, ".dll", ".spec" ));
3268 char *importlib_path
= obj_dir_path( make
, strmake( "lib%s", make
->importlib
));
3270 strarray_add( &make
->clean_files
, strmake( "lib%s.a", make
->importlib
));
3271 if (!*dll_ext
&& needs_delay_lib( make
))
3273 strarray_add( &make
->clean_files
, strmake( "lib%s.delay.a", make
->importlib
));
3274 output( "%s.delay.a ", importlib_path
);
3276 output( "%s.a: %s %s", importlib_path
, tools_path( make
, "winebuild" ), spec_file
);
3277 output_filenames_obj_dir( make
, make
->implib_files
);
3279 output( "\t%s%s -w --implib -o $@", cmd_prefix( "BUILD" ), tools_path( make
, "winebuild" ) );
3280 output_filenames( target_flags
);
3281 if (make
->is_win16
) output_filename( "-m16" );
3282 output_filename( "--export" );
3283 output_filename( spec_file
);
3284 output_filenames_obj_dir( make
, make
->implib_files
);
3286 add_install_rule( make
, make
->importlib
,
3287 strmake( "lib%s.a", make
->importlib
),
3288 strmake( "d%s/lib%s.a", so_dir
, make
->importlib
));
3292 strarray_add( &make
->clean_files
, strmake( "lib%s.cross.a", make
->importlib
));
3293 output_filename( strmake( "%s.cross.a", importlib_path
));
3294 if (needs_delay_lib( make
))
3296 strarray_add( &make
->clean_files
, strmake( "lib%s.delay.a", make
->importlib
));
3297 output_filename( strmake( "%s.delay.a", importlib_path
));
3299 output( ": %s %s", tools_path( make
, "winebuild" ), spec_file
);
3300 output_filenames_obj_dir( make
, make
->crossimplib_files
);
3302 output( "\t%s%s -b %s -w --implib -o $@", cmd_prefix( "BUILD" ),
3303 tools_path( make
, "winebuild" ), crosstarget
);
3304 if (make
->is_win16
) output_filename( "-m16" );
3305 output_filename( "--export" );
3306 output_filename( spec_file
);
3307 output_filenames_obj_dir( make
, make
->crossimplib_files
);
3309 add_install_rule( make
, make
->importlib
,
3310 strmake( "lib%s.cross.a", make
->importlib
),
3311 strmake( "d%s/lib%s.a", pe_dir
, make
->importlib
));
3316 /*******************************************************************
3319 static void output_unix_lib( struct makefile
*make
)
3321 struct strarray unix_libs
= empty_strarray
;
3322 struct strarray unix_deps
= empty_strarray
;
3323 char *spec_file
= src_dir_path( make
, replace_extension( make
->module
, ".dll", ".spec" ));
3325 if (!make
->native_unix_lib
)
3327 struct strarray unix_imports
= empty_strarray
;
3329 strarray_add( &unix_imports
, "ntdll" );
3330 strarray_add( &unix_deps
, obj_dir_path( top_makefile
, "dlls/ntdll/ntdll.so" ));
3331 strarray_add( &unix_imports
, "winecrt0" );
3332 if (spec_file
) strarray_add( &unix_deps
, spec_file
);
3334 strarray_addall( &unix_libs
, add_import_libs( make
, &unix_deps
, unix_imports
, 0, 0 ));
3335 strarray_addall( &unix_libs
, get_expanded_make_var_array( make
, "UNIX_LIBS" ));
3336 strarray_addall( &unix_libs
, libs
);
3338 else unix_libs
= add_unix_libraries( make
, &unix_deps
);
3340 strarray_add( &make
->all_targets
, make
->unixlib
);
3341 add_install_rule( make
, make
->module
, make
->unixlib
, strmake( "p%s/%s", so_dir
, make
->unixlib
));
3342 output( "%s:", obj_dir_path( make
, make
->unixlib
));
3343 output_filenames_obj_dir( make
, make
->unixobj_files
);
3344 output_filenames( unix_deps
);
3346 if (make
->native_unix_lib
)
3349 output( "\t%s$(CC) -o $@", cmd_prefix( "CCLD" ));
3350 output_filenames( get_expanded_make_var_array( make
, "UNIXLDFLAGS" ));
3354 output_filename( tools_path( make
, "winebuild" ));
3355 output_filename( tools_path( make
, "winegcc" ));
3357 output_winegcc_command( make
, 0 );
3358 output_filename( "-munix" );
3359 output_filename( "-shared" );
3360 if (spec_file
) output_filename( spec_file
);
3362 output_filenames_obj_dir( make
, make
->unixobj_files
);
3363 output_filenames( unix_libs
);
3364 output_filename( "$(LDFLAGS)" );
3369 /*******************************************************************
3372 static void output_static_lib( struct makefile
*make
)
3374 if (!crosstarget
|| !make
->extlib
)
3376 strarray_add( &make
->clean_files
, make
->staticlib
);
3377 output( "%s: %s", obj_dir_path( make
, make
->staticlib
), tools_path( make
, "winebuild" ));
3378 output_filenames_obj_dir( make
, make
->object_files
);
3379 output_filenames_obj_dir( make
, make
->unixobj_files
);
3381 output( "\t%s%s -w --staticlib -o $@", cmd_prefix( "BUILD" ), tools_path( make
, "winebuild" ));
3382 output_filenames( target_flags
);
3383 output_filenames_obj_dir( make
, make
->object_files
);
3384 output_filenames_obj_dir( make
, make
->unixobj_files
);
3387 add_install_rule( make
, make
->staticlib
, make
->staticlib
,
3388 strmake( "d%s/%s", so_dir
, make
->staticlib
));
3392 char *name
= replace_extension( make
->staticlib
, ".a", ".cross.a" );
3394 strarray_add( &make
->clean_files
, name
);
3395 output( "%s: %s", obj_dir_path( make
, name
), tools_path( make
, "winebuild" ));
3396 output_filenames_obj_dir( make
, make
->crossobj_files
);
3398 output( "\t%s%s -b %s -w --staticlib -o $@", cmd_prefix( "BUILD" ),
3399 tools_path( make
, "winebuild" ), crosstarget
);
3400 output_filenames_obj_dir( make
, make
->crossobj_files
);
3403 add_install_rule( make
, make
->staticlib
, name
,
3404 strmake( "d%s/%s", pe_dir
, make
->staticlib
));
3409 /*******************************************************************
3412 static void output_shared_lib( struct makefile
*make
)
3416 struct strarray names
= get_shared_lib_names( make
->sharedlib
);
3417 struct strarray all_libs
= empty_strarray
;
3418 struct strarray dep_libs
= empty_strarray
;
3420 basename
= xstrdup( make
->sharedlib
);
3421 if ((p
= strchr( basename
, '.' ))) *p
= 0;
3423 strarray_addall( &dep_libs
, get_local_dependencies( make
, basename
, make
->in_files
));
3424 strarray_addall( &all_libs
, get_expanded_file_local_var( make
, basename
, "LDFLAGS" ));
3425 strarray_addall( &all_libs
, get_expanded_make_var_array( make
, "UNIX_LIBS" ));
3426 strarray_addall( &all_libs
, libs
);
3428 output( "%s:", obj_dir_path( make
, make
->sharedlib
));
3429 output_filenames_obj_dir( make
, make
->object_files
);
3430 output_filenames( dep_libs
);
3432 output( "\t%s$(CC) -o $@", cmd_prefix( "CCLD" ));
3433 output_filenames_obj_dir( make
, make
->object_files
);
3434 output_filenames( all_libs
);
3435 output_filename( "$(LDFLAGS)" );
3437 add_install_rule( make
, make
->sharedlib
, make
->sharedlib
, strmake( "p%s/%s", so_dir
, make
->sharedlib
));
3438 for (i
= 1; i
< names
.count
; i
++)
3440 output( "%s: %s\n", obj_dir_path( make
, names
.str
[i
] ), obj_dir_path( make
, names
.str
[i
-1] ));
3441 output_symlink_rule( names
.str
[i
-1], obj_dir_path( make
, names
.str
[i
] ), 0 );
3442 add_install_rule( make
, names
.str
[i
], names
.str
[i
-1], strmake( "y%s/%s", so_dir
, names
.str
[i
] ));
3444 strarray_addall( &make
->all_targets
, names
);
3448 /*******************************************************************
3449 * output_test_module
3451 static void output_test_module( struct makefile
*make
)
3453 char *testmodule
= replace_extension( make
->testdll
, ".dll", "_test.exe" );
3454 char *stripped
= replace_extension( make
->testdll
, ".dll", "_test-stripped.exe" );
3455 char *testres
= replace_extension( make
->testdll
, ".dll", "_test.res" );
3456 struct strarray dep_libs
= empty_strarray
;
3457 struct strarray all_libs
= add_import_libs( make
, &dep_libs
, add_default_imports( make
, make
->imports
),
3458 0, make
->is_cross
);
3459 struct makefile
*parent
= get_parent_makefile( make
);
3460 const char *ext
= make
->is_cross
? "" : dll_ext
;
3461 const char *debug_file
;
3464 strarray_add( &make
->all_targets
, strmake( "%s%s", testmodule
, ext
));
3465 strarray_add( &make
->clean_files
, strmake( "%s%s", stripped
, ext
));
3466 output_file
= strmake( "%s%s", obj_dir_path( make
, testmodule
), ext
);
3467 output( "%s:\n", output_file
);
3468 output_winegcc_command( make
, make
->is_cross
);
3469 output_filenames( make
->extradllflags
);
3470 output_filenames_obj_dir( make
, make
->is_cross
? make
->crossobj_files
: make
->object_files
);
3471 output_filenames_obj_dir( make
, make
->res_files
);
3472 if ((debug_file
= get_debug_file( make
, testmodule
)))
3473 output_filename( strmake( "-Wl,--debug-file,%s", obj_dir_path( make
, debug_file
)));
3474 output_filenames( all_libs
);
3475 output_filename( make
->is_cross
? "$(CROSSLDFLAGS)" : "$(LDFLAGS)" );
3477 output( "%s%s:\n", obj_dir_path( make
, stripped
), ext
);
3478 output_winegcc_command( make
, make
->is_cross
);
3479 output_filename( "-s" );
3480 output_filename( strmake( "-Wb,-F,%s", testmodule
));
3481 output_filenames( make
->extradllflags
);
3482 output_filenames_obj_dir( make
, make
->is_cross
? make
->crossobj_files
: make
->object_files
);
3483 output_filenames_obj_dir( make
, make
->res_files
);
3484 output_filenames( all_libs
);
3485 output_filename( make
->is_cross
? "$(CROSSLDFLAGS)" : "$(LDFLAGS)" );
3487 output( "%s%s %s%s:", obj_dir_path( make
, testmodule
), ext
, obj_dir_path( make
, stripped
), ext
);
3488 output_filenames_obj_dir( make
, make
->is_cross
? make
->crossobj_files
: make
->object_files
);
3489 output_filenames_obj_dir( make
, make
->res_files
);
3490 output_filenames( dep_libs
);
3491 output_filename( tools_path( make
, "winebuild" ));
3492 output_filename( tools_path( make
, "winegcc" ));
3495 output( "programs/winetest/%s: %s%s\n", testres
, obj_dir_path( make
, stripped
), ext
);
3496 output( "\t%secho \"%s TESTRES \\\"%s%s\\\"\" | %s -u -o $@\n", cmd_prefix( "WRC" ),
3497 testmodule
, obj_dir_path( make
, stripped
), ext
, tools_path( make
, "wrc" ));
3499 output_filenames_obj_dir( make
, make
->ok_files
);
3500 output( ": %s%s", obj_dir_path( make
, testmodule
), ext
);
3503 output_filename( parent
->is_cross
? obj_dir_path( parent
, make
->testdll
)
3504 : strmake( "%s%s", obj_dir_path( parent
, make
->testdll
), dll_ext
));
3505 if (parent
->unixlib
) output_filename( obj_dir_path( parent
, parent
->unixlib
));
3508 output( "%s %s:", obj_dir_path( make
, "check" ), obj_dir_path( make
, "test" ));
3509 if (!make
->disabled
&& parent
&& !parent
->disabled
) output_filenames_obj_dir( make
, make
->ok_files
);
3511 strarray_add_uniq( &make
->phony_targets
, obj_dir_path( make
, "check" ));
3512 strarray_add_uniq( &make
->phony_targets
, obj_dir_path( make
, "test" ));
3513 output( "%s::\n", obj_dir_path( make
, "testclean" ));
3514 output( "\trm -f" );
3515 output_filenames_obj_dir( make
, make
->ok_files
);
3517 strarray_addall( &make
->clean_files
, make
->ok_files
);
3518 strarray_add_uniq( &make
->phony_targets
, obj_dir_path( make
, "testclean" ));
3522 /*******************************************************************
3525 static void output_programs( struct makefile
*make
)
3529 for (i
= 0; i
< make
->programs
.count
; i
++)
3531 char *program_installed
= NULL
;
3532 char *program
= strmake( "%s%s", make
->programs
.str
[i
], exe_ext
);
3533 struct strarray deps
= get_local_dependencies( make
, make
->programs
.str
[i
], make
->in_files
);
3534 struct strarray all_libs
= get_expanded_file_local_var( make
, make
->programs
.str
[i
], "LDFLAGS" );
3535 struct strarray objs
= get_expanded_file_local_var( make
, make
->programs
.str
[i
], "OBJS" );
3536 struct strarray symlinks
= get_expanded_file_local_var( make
, make
->programs
.str
[i
], "SYMLINKS" );
3538 if (!objs
.count
) objs
= make
->object_files
;
3539 if (!strarray_exists( &all_libs
, "-nodefaultlibs" ))
3541 strarray_addall( &all_libs
, get_expanded_make_var_array( make
, "UNIX_LIBS" ));
3542 strarray_addall( &all_libs
, libs
);
3545 output( "%s:", obj_dir_path( make
, program
) );
3546 output_filenames_obj_dir( make
, objs
);
3547 output_filenames( deps
);
3549 output( "\t%s$(CC) -o $@", cmd_prefix( "CCLD" ));
3550 output_filenames_obj_dir( make
, objs
);
3551 output_filenames( all_libs
);
3552 output_filename( "$(LDFLAGS)" );
3554 strarray_add( &make
->all_targets
, program
);
3556 for (j
= 0; j
< symlinks
.count
; j
++)
3558 output( "%s: %s\n", obj_dir_path( make
, symlinks
.str
[j
] ), obj_dir_path( make
, program
));
3559 output_symlink_rule( program
, obj_dir_path( make
, symlinks
.str
[j
] ), 0 );
3561 strarray_addall( &make
->all_targets
, symlinks
);
3563 add_install_rule( make
, program
, program_installed
? program_installed
: program
,
3564 strmake( "p$(bindir)/%s", program
));
3565 for (j
= 0; j
< symlinks
.count
; j
++)
3566 add_install_rule( make
, symlinks
.str
[j
], program
,
3567 strmake( "y$(bindir)/%s%s", symlinks
.str
[j
], exe_ext
));
3572 /*******************************************************************
3575 static void output_subdirs( struct makefile
*make
)
3577 struct strarray all_targets
= empty_strarray
;
3578 struct strarray makefile_deps
= empty_strarray
;
3579 struct strarray clean_files
= empty_strarray
;
3580 struct strarray testclean_files
= empty_strarray
;
3581 struct strarray distclean_files
= empty_strarray
;
3582 struct strarray dependencies
= empty_strarray
;
3583 struct strarray install_deps
[NB_INSTALL_RULES
] = { empty_strarray
};
3584 struct strarray tooldeps_deps
= empty_strarray
;
3585 struct strarray buildtest_deps
= empty_strarray
;
3588 strarray_addall( &clean_files
, make
->clean_files
);
3589 strarray_addall( &distclean_files
, make
->distclean_files
);
3590 strarray_addall( &all_targets
, make
->all_targets
);
3591 for (i
= 0; i
< subdirs
.count
; i
++)
3593 strarray_add( &makefile_deps
, src_dir_path( submakes
[i
], "Makefile.in" ));
3594 strarray_addall_uniq( &make
->phony_targets
, submakes
[i
]->phony_targets
);
3595 strarray_addall_uniq( &make
->uninstall_files
, submakes
[i
]->uninstall_files
);
3596 strarray_addall_uniq( &dependencies
, submakes
[i
]->dependencies
);
3597 strarray_addall_path( &clean_files
, submakes
[i
]->obj_dir
, submakes
[i
]->clean_files
);
3598 strarray_addall_path( &distclean_files
, submakes
[i
]->obj_dir
, submakes
[i
]->distclean_files
);
3599 strarray_addall_path( &make
->maintainerclean_files
, submakes
[i
]->obj_dir
, submakes
[i
]->maintainerclean_files
);
3600 strarray_addall_path( &testclean_files
, submakes
[i
]->obj_dir
, submakes
[i
]->ok_files
);
3601 strarray_addall_path( &make
->pot_files
, submakes
[i
]->obj_dir
, submakes
[i
]->pot_files
);
3603 if (submakes
[i
]->disabled
) continue;
3605 strarray_addall_path( &all_targets
, submakes
[i
]->obj_dir
, submakes
[i
]->all_targets
);
3606 strarray_addall_path( &all_targets
, submakes
[i
]->obj_dir
, submakes
[i
]->font_files
);
3607 if (!strcmp( submakes
[i
]->obj_dir
, "tools" ) || !strncmp( submakes
[i
]->obj_dir
, "tools/", 6 ))
3608 strarray_add( &tooldeps_deps
, obj_dir_path( submakes
[i
], "all" ));
3609 if (submakes
[i
]->testdll
)
3610 strarray_add( &buildtest_deps
, obj_dir_path( submakes
[i
], "all" ));
3611 for (j
= 0; j
< NB_INSTALL_RULES
; j
++)
3612 if (submakes
[i
]->install_rules
[j
].count
)
3613 strarray_add( &install_deps
[j
], obj_dir_path( submakes
[i
], install_targets
[j
] ));
3615 strarray_addall( &dependencies
, makefile_deps
);
3617 output_filenames( all_targets
);
3619 output( "Makefile:" );
3620 output_filenames( makefile_deps
);
3622 output_filenames( dependencies
);
3624 for (j
= 0; j
< NB_INSTALL_RULES
; j
++)
3626 if (!install_deps
[j
].count
) continue;
3627 if (strcmp( install_targets
[j
], "install-test" ))
3629 output( "install " );
3630 strarray_add_uniq( &make
->phony_targets
, "install" );
3632 output( "%s::", install_targets
[j
] );
3633 output_filenames( install_deps
[j
] );
3635 strarray_add_uniq( &make
->phony_targets
, install_targets
[j
] );
3637 output_uninstall_rules( make
);
3638 if (buildtest_deps
.count
)
3640 output( "buildtests:" );
3641 output_filenames( buildtest_deps
);
3643 strarray_add_uniq( &make
->phony_targets
, "buildtests" );
3645 output( "check test:" );
3646 output_filenames( testclean_files
);
3648 strarray_add_uniq( &make
->phony_targets
, "check" );
3649 strarray_add_uniq( &make
->phony_targets
, "test" );
3651 if (get_expanded_make_variable( make
, "GETTEXTPO_LIBS" )) output_po_files( make
);
3653 output( "clean::\n");
3654 output_rm_filenames( clean_files
);
3655 output( "testclean::\n");
3656 output_rm_filenames( testclean_files
);
3657 output( "distclean::\n");
3658 output_rm_filenames( distclean_files
);
3659 output( "maintainer-clean::\n");
3660 output_rm_filenames( make
->maintainerclean_files
);
3661 strarray_add_uniq( &make
->phony_targets
, "distclean" );
3662 strarray_add_uniq( &make
->phony_targets
, "testclean" );
3663 strarray_add_uniq( &make
->phony_targets
, "maintainer-clean" );
3665 if (tooldeps_deps
.count
)
3667 output( "__tooldeps__:" );
3668 output_filenames( tooldeps_deps
);
3670 strarray_add_uniq( &make
->phony_targets
, "__tooldeps__" );
3673 if (make
->phony_targets
.count
)
3675 output( ".PHONY:" );
3676 output_filenames( make
->phony_targets
);
3682 /*******************************************************************
3685 static void output_sources( struct makefile
*make
)
3687 struct strarray all_targets
= empty_strarray
;
3688 struct incl_file
*source
;
3691 strarray_add_uniq( &make
->phony_targets
, "all" );
3693 LIST_FOR_EACH_ENTRY( source
, &make
->sources
, struct incl_file
, entry
)
3695 char *obj
= xstrdup( source
->name
);
3696 char *ext
= get_extension( obj
);
3698 if (!ext
) fatal_error( "unsupported file type %s\n", source
->name
);
3701 for (j
= 0; output_source_funcs
[j
].ext
; j
++)
3702 if (!strcmp( ext
, output_source_funcs
[j
].ext
)) break;
3704 output_source_funcs
[j
].fn( make
, source
, obj
);
3705 strarray_addall_uniq( &make
->dependencies
, source
->dependencies
);
3708 /* special case for winetest: add resource files from other test dirs */
3709 if (make
->obj_dir
&& !strcmp( make
->obj_dir
, "programs/winetest" ))
3711 struct strarray tests
= enable_tests
;
3713 for (i
= 0; i
< subdirs
.count
; i
++)
3714 if (submakes
[i
]->testdll
&& !submakes
[i
]->disabled
)
3715 strarray_add( &tests
, submakes
[i
]->testdll
);
3716 for (i
= 0; i
< tests
.count
; i
++)
3717 strarray_add( &make
->res_files
, replace_extension( tests
.str
[i
], ".dll", "_test.res" ));
3720 if (make
->dlldata_files
.count
)
3722 output( "%s: %s %s\n", obj_dir_path( make
, "dlldata.c" ),
3723 tools_path( make
, "widl" ), src_dir_path( make
, "Makefile.in" ));
3724 output( "\t%s%s --dlldata-only -o $@", cmd_prefix( "WIDL" ), tools_path( make
, "widl" ));
3725 output_filenames( make
->dlldata_files
);
3729 if (make
->staticlib
) output_static_lib( make
);
3730 else if (make
->module
)
3732 output_module( make
);
3733 if (*dll_ext
&& !make
->is_cross
&& !make
->data_only
) output_fake_module( make
);
3734 if (make
->unixlib
) output_unix_lib( make
);
3735 if (make
->importlib
) output_import_lib( make
);
3737 else if (make
->testdll
) output_test_module( make
);
3738 else if (make
->sharedlib
) output_shared_lib( make
);
3739 else if (make
->programs
.count
) output_programs( make
);
3741 for (i
= 0; i
< make
->scripts
.count
; i
++)
3742 add_install_rule( make
, make
->scripts
.str
[i
], make
->scripts
.str
[i
],
3743 strmake( "S$(bindir)/%s", make
->scripts
.str
[i
] ));
3745 for (i
= 0; i
< make
->extra_targets
.count
; i
++)
3746 if (strarray_exists( &make
->dependencies
, obj_dir_path( make
, make
->extra_targets
.str
[i
] )))
3747 strarray_add( &make
->clean_files
, make
->extra_targets
.str
[i
] );
3749 strarray_add( &make
->all_targets
, make
->extra_targets
.str
[i
] );
3751 if (!make
->src_dir
) strarray_add( &make
->distclean_files
, ".gitignore" );
3752 strarray_add( &make
->distclean_files
, "Makefile" );
3753 if (make
->testdll
) strarray_add( &make
->distclean_files
, "testlist.c" );
3756 strarray_addall( &make
->distclean_files
, get_expanded_make_var_array( make
, "CONFIGURE_TARGETS" ));
3757 else if (!strcmp( make
->obj_dir
, "po" ))
3758 strarray_add( &make
->distclean_files
, "LINGUAS" );
3760 strarray_addall( &make
->clean_files
, make
->object_files
);
3761 strarray_addall( &make
->clean_files
, make
->crossobj_files
);
3762 strarray_addall( &make
->clean_files
, make
->implib_files
);
3763 strarray_addall( &make
->clean_files
, make
->crossimplib_files
);
3764 strarray_addall( &make
->clean_files
, make
->unixobj_files
);
3765 strarray_addall( &make
->clean_files
, make
->res_files
);
3766 strarray_addall( &make
->clean_files
, make
->pot_files
);
3767 strarray_addall( &make
->clean_files
, make
->debug_files
);
3768 strarray_addall( &make
->clean_files
, make
->all_targets
);
3770 if (make
== top_makefile
)
3772 output_subdirs( make
);
3776 strarray_addall( &all_targets
, make
->all_targets
);
3777 strarray_addall( &all_targets
, make
->font_files
);
3778 if (all_targets
.count
)
3780 output( "%s:", obj_dir_path( make
, "all" ));
3781 output_filenames_obj_dir( make
, all_targets
);
3783 strarray_add_uniq( &make
->phony_targets
, obj_dir_path( make
, "all" ));
3785 for (i
= 0; i
< NB_INSTALL_RULES
; i
++) output_install_rules( make
, i
);
3787 if (make
->clean_files
.count
)
3789 output( "%s::\n", obj_dir_path( make
, "clean" ));
3790 output( "\trm -f" );
3791 output_filenames_obj_dir( make
, make
->clean_files
);
3793 strarray_add( &make
->phony_targets
, obj_dir_path( make
, "clean" ));
3798 /*******************************************************************
3801 static FILE *create_temp_file( const char *orig
)
3803 char *name
= xmalloc( strlen(orig
) + 13 );
3804 unsigned int i
, id
= getpid();
3808 for (i
= 0; i
< 100; i
++)
3810 sprintf( name
, "%s.tmp%08x", orig
, id
);
3811 if ((fd
= open( name
, O_RDWR
| O_CREAT
| O_EXCL
, 0666 )) != -1)
3813 ret
= fdopen( fd
, "w" );
3816 if (errno
!= EEXIST
) break;
3819 if (!ret
) fatal_error( "failed to create output file for '%s'\n", orig
);
3820 temp_file_name
= name
;
3825 /*******************************************************************
3828 static void rename_temp_file( const char *dest
)
3830 int ret
= rename( temp_file_name
, dest
);
3831 if (ret
== -1 && errno
== EEXIST
)
3833 /* rename doesn't overwrite on windows */
3835 ret
= rename( temp_file_name
, dest
);
3837 if (ret
== -1) fatal_error( "failed to rename output file to '%s'\n", dest
);
3838 temp_file_name
= NULL
;
3842 /*******************************************************************
3843 * are_files_identical
3845 static int are_files_identical( FILE *file1
, FILE *file2
)
3849 char buffer1
[8192], buffer2
[8192];
3850 int size1
= fread( buffer1
, 1, sizeof(buffer1
), file1
);
3851 int size2
= fread( buffer2
, 1, sizeof(buffer2
), file2
);
3852 if (size1
!= size2
) return 0;
3853 if (!size1
) return feof( file1
) && feof( file2
);
3854 if (memcmp( buffer1
, buffer2
, size1
)) return 0;
3859 /*******************************************************************
3860 * rename_temp_file_if_changed
3862 static void rename_temp_file_if_changed( const char *dest
)
3864 FILE *file1
, *file2
;
3867 if ((file1
= fopen( dest
, "r" )))
3869 if ((file2
= fopen( temp_file_name
, "r" )))
3871 do_rename
= !are_files_identical( file1
, file2
);
3878 unlink( temp_file_name
);
3879 temp_file_name
= NULL
;
3881 else rename_temp_file( dest
);
3885 /*******************************************************************
3888 static void output_linguas( const struct makefile
*make
)
3890 const char *dest
= obj_dir_path( make
, "LINGUAS" );
3891 struct incl_file
*source
;
3893 output_file
= create_temp_file( dest
);
3895 output( "# Automatically generated by make depend; DO NOT EDIT!!\n" );
3896 LIST_FOR_EACH_ENTRY( source
, &make
->sources
, struct incl_file
, entry
)
3897 if (strendswith( source
->name
, ".po" ))
3898 output( "%s\n", replace_extension( source
->name
, ".po", "" ));
3900 if (fclose( output_file
)) fatal_perror( "write" );
3902 rename_temp_file_if_changed( dest
);
3906 /*******************************************************************
3909 static void output_testlist( const struct makefile
*make
)
3911 const char *dest
= obj_dir_path( make
, "testlist.c" );
3914 output_file
= create_temp_file( dest
);
3916 output( "/* Automatically generated by make depend; DO NOT EDIT!! */\n\n" );
3917 output( "#define WIN32_LEAN_AND_MEAN\n" );
3918 output( "#include <windows.h>\n\n" );
3919 output( "#define STANDALONE\n" );
3920 output( "#include \"wine/test.h\"\n\n" );
3922 for (i
= 0; i
< make
->test_files
.count
; i
++)
3923 output( "extern void func_%s(void);\n", make
->test_files
.str
[i
] );
3925 output( "const struct test winetest_testlist[] =\n" );
3927 for (i
= 0; i
< make
->test_files
.count
; i
++)
3928 output( " { \"%s\", func_%s },\n", make
->test_files
.str
[i
], make
->test_files
.str
[i
] );
3929 output( " { 0, 0 }\n" );
3932 if (fclose( output_file
)) fatal_perror( "write" );
3934 rename_temp_file_if_changed( dest
);
3938 /*******************************************************************
3941 static void output_gitignore( const char *dest
, struct strarray files
)
3945 output_file
= create_temp_file( dest
);
3947 output( "# Automatically generated by make depend; DO NOT EDIT!!\n" );
3948 for (i
= 0; i
< files
.count
; i
++)
3950 if (!strchr( files
.str
[i
], '/' )) output( "/" );
3951 output( "%s\n", files
.str
[i
] );
3954 if (fclose( output_file
)) fatal_perror( "write" );
3956 rename_temp_file( dest
);
3960 /*******************************************************************
3961 * output_stub_makefile
3963 static void output_stub_makefile( struct makefile
*make
)
3965 struct strarray targets
= empty_strarray
;
3966 const char *make_var
= strarray_get_value( &top_makefile
->vars
, "MAKE" );
3969 if (make
->obj_dir
) create_dir( make
->obj_dir
);
3971 output_file_name
= obj_dir_path( make
, "Makefile" );
3972 output_file
= create_temp_file( output_file_name
);
3974 output( "# Auto-generated stub makefile; all rules forward to the top-level makefile\n\n" );
3976 if (make_var
) output( "MAKE = %s\n\n", make_var
);
3979 if (make
->all_targets
.count
) strarray_add( &targets
, "all" );
3980 for (i
= 0; i
< NB_INSTALL_RULES
; i
++)
3982 if (!make
->install_rules
[i
].count
) continue;
3983 strarray_add_uniq( &targets
, "install" );
3984 strarray_add( &targets
, install_targets
[i
] );
3986 if (make
->clean_files
.count
) strarray_add( &targets
, "clean" );
3987 if (make
->test_files
.count
)
3989 strarray_add( &targets
, "check" );
3990 strarray_add( &targets
, "test" );
3991 strarray_add( &targets
, "testclean" );
3994 output_filenames( targets
);
3995 output_filenames( make
->clean_files
);
3997 output( "\t@cd %s && $(MAKE) %s/$@\n", get_relative_path( make
->obj_dir
, "" ), make
->obj_dir
);
3998 output( ".PHONY:" );
3999 output_filenames( targets
);
4002 fclose( output_file
);
4004 rename_temp_file( output_file_name
);
4008 /*******************************************************************
4009 * output_silent_rules
4011 static void output_silent_rules(void)
4013 static const char *cmds
[] =
4031 output( "V = 0\n" );
4032 for (i
= 0; i
< sizeof(cmds
) / sizeof(cmds
[0]); i
++)
4034 output( "quiet_%s = $(quiet_%s_$(V))\n", cmds
[i
], cmds
[i
] );
4035 output( "quiet_%s_0 = @echo \" %-5s \" $@;\n", cmds
[i
], cmds
[i
] );
4036 output( "quiet_%s_1 =\n", cmds
[i
] );
4041 /*******************************************************************
4042 * output_top_makefile
4044 static void output_top_makefile( struct makefile
*make
)
4051 output_file_name
= obj_dir_path( make
, output_makefile_name
);
4052 output_file
= create_temp_file( output_file_name
);
4054 /* copy the contents of the source makefile */
4055 src_file
= open_input_makefile( make
);
4056 while (fgets( buffer
, sizeof(buffer
), src_file
) && !found
)
4058 if (fwrite( buffer
, 1, strlen(buffer
), output_file
) != strlen(buffer
)) fatal_perror( "write" );
4059 found
= !strncmp( buffer
, separator
, strlen(separator
) );
4061 if (fclose( src_file
)) fatal_perror( "close" );
4062 input_file_name
= NULL
;
4064 if (!found
) output( "\n%s (everything below this line is auto-generated; DO NOT EDIT!!)\n", separator
);
4066 if (silent_rules
) output_silent_rules();
4067 for (i
= 0; i
< subdirs
.count
; i
++) output_sources( submakes
[i
] );
4068 output_sources( make
);
4069 /* disable implicit rules */
4070 output( ".SUFFIXES:\n" );
4072 fclose( output_file
);
4074 rename_temp_file( output_file_name
);
4078 /*******************************************************************
4079 * output_dependencies
4081 static void output_dependencies( struct makefile
*make
)
4083 struct strarray ignore_files
= empty_strarray
;
4085 if (make
->obj_dir
) create_dir( make
->obj_dir
);
4087 if (make
== top_makefile
) output_top_makefile( make
);
4088 else output_stub_makefile( make
);
4090 strarray_addall( &ignore_files
, make
->distclean_files
);
4091 strarray_addall( &ignore_files
, make
->clean_files
);
4092 if (make
->testdll
) output_testlist( make
);
4093 if (make
->obj_dir
&& !strcmp( make
->obj_dir
, "po" )) output_linguas( make
);
4094 if (!make
->src_dir
) output_gitignore( obj_dir_path( make
, ".gitignore" ), ignore_files
);
4096 create_file_directories( make
, ignore_files
);
4098 output_file_name
= NULL
;
4102 /*******************************************************************
4105 static void load_sources( struct makefile
*make
)
4107 static const char *source_vars
[] =
4128 struct strarray value
;
4129 struct incl_file
*file
;
4131 strarray_set_value( &make
->vars
, "top_srcdir", root_src_dir_path( "" ));
4132 strarray_set_value( &make
->vars
, "srcdir", src_dir_path( make
, "" ));
4134 make
->parent_dir
= get_expanded_make_variable( make
, "PARENTSRC" );
4135 make
->module
= get_expanded_make_variable( make
, "MODULE" );
4136 make
->testdll
= get_expanded_make_variable( make
, "TESTDLL" );
4137 make
->sharedlib
= get_expanded_make_variable( make
, "SHAREDLIB" );
4138 make
->staticlib
= get_expanded_make_variable( make
, "STATICLIB" );
4139 make
->importlib
= get_expanded_make_variable( make
, "IMPORTLIB" );
4140 make
->extlib
= get_expanded_make_variable( make
, "EXTLIB" );
4141 if (*dll_ext
) make
->unixlib
= get_expanded_make_variable( make
, "UNIXLIB" );
4143 make
->programs
= get_expanded_make_var_array( make
, "PROGRAMS" );
4144 make
->scripts
= get_expanded_make_var_array( make
, "SCRIPTS" );
4145 make
->imports
= get_expanded_make_var_array( make
, "IMPORTS" );
4146 make
->delayimports
= get_expanded_make_var_array( make
, "DELAYIMPORTS" );
4147 make
->extradllflags
= get_expanded_make_var_array( make
, "EXTRADLLFLAGS" );
4148 make
->extra_targets
= get_expanded_make_var_array( make
, "EXTRA_TARGETS" );
4149 for (i
= 0; i
< NB_INSTALL_RULES
; i
++)
4150 make
->install
[i
] = get_expanded_make_var_array( make
, install_variables
[i
] );
4152 if (make
->extlib
) make
->staticlib
= make
->extlib
;
4153 if (make
->staticlib
) make
->module
= make
->staticlib
;
4157 value
= get_expanded_file_local_var( make
, host_cpu
, "EXTRADLLFLAGS" );
4158 if (value
.count
) make
->extradllflags
= value
;
4161 make
->disabled
= make
->obj_dir
&& strarray_exists( &disabled_dirs
, make
->obj_dir
);
4162 make
->is_win16
= strarray_exists( &make
->extradllflags
, "-m16" );
4163 make
->data_only
= strarray_exists( &make
->extradllflags
, "-Wb,--data-only" );
4164 make
->use_msvcrt
= (make
->module
|| make
->testdll
|| make
->is_win16
) &&
4165 !strarray_exists( &make
->extradllflags
, "-mcygwin" );
4166 make
->is_exe
= strarray_exists( &make
->extradllflags
, "-mconsole" ) ||
4167 strarray_exists( &make
->extradllflags
, "-mwindows" );
4168 make
->native_unix_lib
= !!make
->unixlib
;
4170 if (make
->use_msvcrt
) strarray_add_uniq( &make
->extradllflags
, "-mno-cygwin" );
4174 /* add default install rules if nothing was specified */
4175 for (i
= 0; i
< NB_INSTALL_RULES
; i
++) if (make
->install
[i
].count
) break;
4176 if (i
== NB_INSTALL_RULES
)
4178 if (make
->importlib
) strarray_add( &make
->install
[INSTALL_DEV
], make
->importlib
);
4179 if (make
->staticlib
) strarray_add( &make
->install
[INSTALL_DEV
], make
->staticlib
);
4180 else strarray_add( &make
->install
[INSTALL_LIB
], make
->module
);
4184 make
->include_paths
= empty_strarray
;
4185 make
->include_args
= empty_strarray
;
4186 make
->define_args
= empty_strarray
;
4187 make
->unix_cflags
= empty_strarray
;
4188 if (!make
->extlib
) strarray_add( &make
->define_args
, "-D__WINESRC__" );
4190 value
= get_expanded_make_var_array( make
, "EXTRAINCL" );
4191 for (i
= 0; i
< value
.count
; i
++)
4193 if (!strncmp( value
.str
[i
], "-I", 2 ))
4195 const char *dir
= value
.str
[i
] + 2;
4196 if (!strncmp( dir
, "./", 2 ))
4199 while (*dir
== '/') dir
++;
4201 strarray_add_uniq( &make
->include_paths
, dir
);
4203 else if (!strncmp( value
.str
[i
], "-D", 2 ) || !strncmp( value
.str
[i
], "-U", 2 ))
4204 strarray_add_uniq( &make
->define_args
, value
.str
[i
] );
4206 strarray_addall( &make
->define_args
, get_expanded_make_var_array( make
, "EXTRADEFS" ));
4207 strarray_addall_uniq( &make
->unix_cflags
, get_expanded_make_var_array( make
, "UNIX_CFLAGS" ));
4209 strarray_add( &make
->include_args
, strmake( "-I%s", obj_dir_path( make
, "" )));
4211 strarray_add( &make
->include_args
, strmake( "-I%s", make
->src_dir
));
4212 if (make
->parent_dir
)
4213 strarray_add( &make
->include_args
, strmake( "-I%s", src_dir_path( make
, make
->parent_dir
)));
4214 strarray_add( &make
->include_args
, "-Iinclude" );
4215 if (root_src_dir
) strarray_add( &make
->include_args
, strmake( "-I%s", root_src_dir_path( "include" )));
4217 list_init( &make
->sources
);
4218 list_init( &make
->includes
);
4220 for (var
= source_vars
; *var
; var
++)
4222 value
= get_expanded_make_var_array( make
, *var
);
4223 for (i
= 0; i
< value
.count
; i
++) add_src_file( make
, value
.str
[i
] );
4226 add_generated_sources( make
);
4227 if (!make
->unixlib
) make
->unixlib
= get_unix_lib_name( make
);
4229 if (make
->use_msvcrt
) strarray_add( &make
->define_args
, get_crt_define( make
));
4231 LIST_FOR_EACH_ENTRY( file
, &make
->includes
, struct incl_file
, entry
) parse_file( make
, file
, 0 );
4232 LIST_FOR_EACH_ENTRY( file
, &make
->sources
, struct incl_file
, entry
) get_dependencies( file
, file
);
4234 make
->is_cross
= crosstarget
&& make
->use_msvcrt
;
4236 if (!*dll_ext
|| make
->is_cross
)
4237 for (i
= 0; i
< make
->delayimports
.count
; i
++)
4238 strarray_add_uniq( &delay_import_libs
, get_base_name( make
->delayimports
.str
[i
] ));
4242 /*******************************************************************
4245 static void parse_makeflags( const char *flags
)
4247 const char *p
= flags
;
4248 char *var
, *buffer
= xmalloc( strlen(flags
) + 1 );
4252 while (isspace(*p
)) p
++;
4254 while (*p
&& !isspace(*p
))
4256 if (*p
== '\\' && p
[1]) p
++;
4260 if (var
> buffer
) set_make_variable( &cmdline_vars
, buffer
);
4265 /*******************************************************************
4268 static int parse_option( const char *opt
)
4272 if (strchr( opt
, '=' )) return set_make_variable( &cmdline_vars
, opt
);
4278 if (opt
[2]) output_makefile_name
= opt
+ 2;
4281 relative_dir_mode
= 1;
4287 fprintf( stderr
, "Unknown option '%s'\n%s", opt
, Usage
);
4294 /*******************************************************************
4297 int main( int argc
, char *argv
[] )
4299 const char *makeflags
= getenv( "MAKEFLAGS" );
4302 if (makeflags
) parse_makeflags( makeflags
);
4307 if (parse_option( argv
[i
] ))
4309 for (j
= i
; j
< argc
; j
++) argv
[j
] = argv
[j
+1];
4315 if (relative_dir_mode
)
4321 fprintf( stderr
, "Option -R needs two directories\n%s", Usage
);
4324 relpath
= get_relative_path( argv
[1], argv
[2] );
4325 printf( "%s\n", relpath
? relpath
: "." );
4329 if (argc
> 1) fatal_error( "Directory arguments not supported in this mode\n" );
4331 atexit( cleanup_files
);
4332 signal( SIGTERM
, exit_on_signal
);
4333 signal( SIGINT
, exit_on_signal
);
4335 signal( SIGHUP
, exit_on_signal
);
4338 for (i
= 0; i
< HASH_SIZE
; i
++) list_init( &files
[i
] );
4339 for (i
= 0; i
< HASH_SIZE
; i
++) list_init( &global_includes
[i
] );
4341 top_makefile
= parse_makefile( NULL
);
4343 target_flags
= get_expanded_make_var_array( top_makefile
, "TARGETFLAGS" );
4344 msvcrt_flags
= get_expanded_make_var_array( top_makefile
, "MSVCRTFLAGS" );
4345 dll_flags
= get_expanded_make_var_array( top_makefile
, "DLLFLAGS" );
4346 extra_cflags
= get_expanded_make_var_array( top_makefile
, "EXTRACFLAGS" );
4347 extra_cross_cflags
= get_expanded_make_var_array( top_makefile
, "EXTRACROSSCFLAGS" );
4348 unix_dllflags
= get_expanded_make_var_array( top_makefile
, "UNIXDLLFLAGS" );
4349 cpp_flags
= get_expanded_make_var_array( top_makefile
, "CPPFLAGS" );
4350 lddll_flags
= get_expanded_make_var_array( top_makefile
, "LDDLLFLAGS" );
4351 libs
= get_expanded_make_var_array( top_makefile
, "LIBS" );
4352 enable_tests
= get_expanded_make_var_array( top_makefile
, "ENABLE_TESTS" );
4353 for (i
= 0; i
< NB_INSTALL_RULES
; i
++)
4354 top_install
[i
] = get_expanded_make_var_array( top_makefile
, strmake( "TOP_%s", install_variables
[i
] ));
4356 delay_load_flag
= get_expanded_make_variable( top_makefile
, "DELAYLOADFLAG" );
4357 root_src_dir
= get_expanded_make_variable( top_makefile
, "srcdir" );
4358 tools_dir
= get_expanded_make_variable( top_makefile
, "toolsdir" );
4359 tools_ext
= get_expanded_make_variable( top_makefile
, "toolsext" );
4360 exe_ext
= get_expanded_make_variable( top_makefile
, "EXEEXT" );
4361 dll_ext
= (exe_ext
&& !strcmp( exe_ext
, ".exe" )) ? "" : ".so";
4362 host_cpu
= get_expanded_make_variable( top_makefile
, "host_cpu" );
4363 crosstarget
= get_expanded_make_variable( top_makefile
, "CROSSTARGET" );
4364 crossdebug
= get_expanded_make_variable( top_makefile
, "CROSSDEBUG" );
4365 fontforge
= get_expanded_make_variable( top_makefile
, "FONTFORGE" );
4366 convert
= get_expanded_make_variable( top_makefile
, "CONVERT" );
4367 flex
= get_expanded_make_variable( top_makefile
, "FLEX" );
4368 bison
= get_expanded_make_variable( top_makefile
, "BISON" );
4369 ar
= get_expanded_make_variable( top_makefile
, "AR" );
4370 ranlib
= get_expanded_make_variable( top_makefile
, "RANLIB" );
4371 rsvg
= get_expanded_make_variable( top_makefile
, "RSVG" );
4372 icotool
= get_expanded_make_variable( top_makefile
, "ICOTOOL" );
4373 dlltool
= get_expanded_make_variable( top_makefile
, "DLLTOOL" );
4374 msgfmt
= get_expanded_make_variable( top_makefile
, "MSGFMT" );
4375 sed_cmd
= get_expanded_make_variable( top_makefile
, "SED_CMD" );
4376 ln_s
= get_expanded_make_variable( top_makefile
, "LN_S" );
4378 if (root_src_dir
&& !strcmp( root_src_dir
, "." )) root_src_dir
= NULL
;
4379 if (tools_dir
&& !strcmp( tools_dir
, "." )) tools_dir
= NULL
;
4380 if (!exe_ext
) exe_ext
= "";
4381 if (!tools_ext
) tools_ext
= "";
4382 if (host_cpu
&& (host_cpu
= normalize_arch( host_cpu
)))
4384 so_dir
= strmake( "$(dlldir)/%s-unix", host_cpu
);
4385 pe_dir
= strmake( "$(dlldir)/%s-windows", host_cpu
);
4388 so_dir
= pe_dir
= "$(dlldir)";
4390 extra_cflags_extlib
= remove_warning_flags( extra_cflags
);
4391 extra_cross_cflags_extlib
= remove_warning_flags( extra_cross_cflags
);
4393 top_makefile
->src_dir
= root_src_dir
;
4394 subdirs
= get_expanded_make_var_array( top_makefile
, "SUBDIRS" );
4395 disabled_dirs
= get_expanded_make_var_array( top_makefile
, "DISABLED_SUBDIRS" );
4396 submakes
= xmalloc( subdirs
.count
* sizeof(*submakes
) );
4398 for (i
= 0; i
< subdirs
.count
; i
++) submakes
[i
] = parse_makefile( subdirs
.str
[i
] );
4400 load_sources( top_makefile
);
4401 load_sources( include_makefile
);
4402 for (i
= 0; i
< subdirs
.count
; i
++)
4403 if (submakes
[i
] != include_makefile
) load_sources( submakes
[i
] );
4405 output_dependencies( top_makefile
);
4406 for (i
= 0; i
< subdirs
.count
; i
++) output_dependencies( submakes
[i
] );