2 * Generate include file dependencies
4 * Copyright 1996, 2013, 2020 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
32 #include <sys/types.h>
36 #include "wine/list.h"
40 INCL_NORMAL
, /* #include "foo.h" */
41 INCL_SYSTEM
, /* #include <foo.h> */
42 INCL_IMPORT
, /* idl import "foo.idl" */
43 INCL_IMPORTLIB
, /* idl importlib "foo.tlb" */
44 INCL_CPP_QUOTE
, /* idl cpp_quote("#include \"foo.h\"") */
45 INCL_CPP_QUOTE_SYSTEM
/* idl cpp_quote("#include <foo.h>") */
50 int line
; /* source line where this header is included */
51 enum incl_type type
; /* type of include */
52 char *name
; /* header name */
58 char *name
; /* full file name relative to cwd */
59 void *args
; /* custom arguments for makefile rule */
60 unsigned int flags
; /* flags (see below) */
61 unsigned int deps_count
; /* files in use */
62 unsigned int deps_size
; /* total allocated size */
63 struct dependency
*deps
; /* all header dependencies */
72 char *basename
; /* base target name for generated files */
73 char *sourcename
; /* source file name for generated headers */
74 struct incl_file
*included_by
; /* file that included this one */
75 int included_line
; /* line where this file was included */
76 enum incl_type type
; /* type of include */
77 int use_msvcrt
:1; /* put msvcrt headers in the search path? */
78 int is_external
:1; /* file from external library? */
79 struct incl_file
*owner
;
80 unsigned int files_count
; /* files in use */
81 unsigned int files_size
; /* total allocated size */
82 struct incl_file
**files
;
83 struct strarray dependencies
; /* file dependencies */
84 struct strarray importlibdeps
; /* importlib dependencies */
87 #define FLAG_GENERATED 0x000001 /* generated file */
88 #define FLAG_INSTALL 0x000002 /* file to install */
89 #define FLAG_IDL_PROXY 0x000100 /* generates a proxy (_p.c) file */
90 #define FLAG_IDL_CLIENT 0x000200 /* generates a client (_c.c) file */
91 #define FLAG_IDL_SERVER 0x000400 /* generates a server (_s.c) file */
92 #define FLAG_IDL_IDENT 0x000800 /* generates an ident (_i.c) file */
93 #define FLAG_IDL_REGISTER 0x001000 /* generates a registration (_r.res) file */
94 #define FLAG_IDL_TYPELIB 0x002000 /* generates a typelib (_l.res) file */
95 #define FLAG_IDL_REGTYPELIB 0x004000 /* generates a registered typelib (_t.res) file */
96 #define FLAG_IDL_HEADER 0x008000 /* generates a header (.h) file */
97 #define FLAG_RC_PO 0x010000 /* rc file contains translations */
98 #define FLAG_C_IMPLIB 0x020000 /* file is part of an import library */
99 #define FLAG_C_UNIX 0x040000 /* file is part of a Unix library */
100 #define FLAG_SFD_FONTS 0x080000 /* sfd file generated bitmap fonts */
108 { FLAG_IDL_TYPELIB
, "_l.res" },
109 { FLAG_IDL_REGTYPELIB
, "_t.res" },
110 { FLAG_IDL_CLIENT
, "_c.c" },
111 { FLAG_IDL_IDENT
, "_i.c" },
112 { FLAG_IDL_PROXY
, "_p.c" },
113 { FLAG_IDL_SERVER
, "_s.c" },
114 { FLAG_IDL_REGISTER
, "_r.res" },
115 { FLAG_IDL_HEADER
, ".h" }
118 #define HASH_SIZE 997
120 static struct list files
[HASH_SIZE
];
122 enum install_rules
{ INSTALL_LIB
, INSTALL_DEV
, NB_INSTALL_RULES
};
124 /* variables common to all makefiles */
125 static struct strarray linguas
;
126 static struct strarray dll_flags
;
127 static struct strarray unix_dllflags
;
128 static struct strarray target_flags
;
129 static struct strarray msvcrt_flags
;
130 static struct strarray extra_cflags
;
131 static struct strarray extra_cross_cflags
;
132 static struct strarray extra_cflags_extlib
;
133 static struct strarray extra_cross_cflags_extlib
;
134 static struct strarray cpp_flags
;
135 static struct strarray lddll_flags
;
136 static struct strarray libs
;
137 static struct strarray enable_tests
;
138 static struct strarray cmdline_vars
;
139 static struct strarray subdirs
;
140 static struct strarray disabled_dirs
;
141 static struct strarray delay_import_libs
;
142 static struct strarray top_install_lib
;
143 static struct strarray top_install_dev
;
144 static const char *root_src_dir
;
145 static const char *tools_dir
;
146 static const char *tools_ext
;
147 static const char *exe_ext
;
148 static const char *dll_ext
;
149 static const char *host_cpu
;
150 static const char *pe_dir
;
151 static const char *so_dir
;
152 static const char *crosstarget
;
153 static const char *crossdebug
;
154 static const char *fontforge
;
155 static const char *convert
;
156 static const char *flex
;
157 static const char *bison
;
158 static const char *ar
;
159 static const char *ranlib
;
160 static const char *rsvg
;
161 static const char *icotool
;
162 static const char *dlltool
;
163 static const char *msgfmt
;
164 static const char *ln_s
;
165 static const char *sed_cmd
;
166 static const char *delay_load_flag
;
170 /* values determined from input makefile */
171 struct strarray vars
;
172 struct strarray include_paths
;
173 struct strarray include_args
;
174 struct strarray define_args
;
175 struct strarray unix_cflags
;
176 struct strarray programs
;
177 struct strarray scripts
;
178 struct strarray imports
;
179 struct strarray delayimports
;
180 struct strarray extradllflags
;
181 struct strarray install_lib
;
182 struct strarray install_dev
;
183 struct strarray extra_targets
;
184 struct strarray extra_imports
;
186 struct list includes
;
189 const char *parent_dir
;
193 const char *sharedlib
;
194 const char *staticlib
;
195 const char *staticimplib
;
196 const char *importlib
;
206 /* values generated at output time */
207 struct strarray in_files
;
208 struct strarray ok_files
;
209 struct strarray pot_files
;
210 struct strarray test_files
;
211 struct strarray clean_files
;
212 struct strarray distclean_files
;
213 struct strarray maintainerclean_files
;
214 struct strarray uninstall_files
;
215 struct strarray object_files
;
216 struct strarray crossobj_files
;
217 struct strarray unixobj_files
;
218 struct strarray res_files
;
219 struct strarray font_files
;
220 struct strarray debug_files
;
221 struct strarray dlldata_files
;
222 struct strarray implib_files
;
223 struct strarray crossimplib_files
;
224 struct strarray all_targets
;
225 struct strarray phony_targets
;
226 struct strarray dependencies
;
227 struct strarray install_rules
[NB_INSTALL_RULES
];
230 static struct makefile
*top_makefile
;
231 static struct makefile
**submakes
;
233 static const char separator
[] = "### Dependencies";
234 static const char *output_makefile_name
= "Makefile";
235 static const char *input_file_name
;
236 static const char *output_file_name
;
237 static const char *temp_file_name
;
238 static int relative_dir_mode
;
239 static int silent_rules
;
240 static int input_line
;
241 static int output_column
;
242 static FILE *output_file
;
244 static const char Usage
[] =
245 "Usage: makedep [options] [directories]\n"
247 " -R from to Compute the relative path between two directories\n"
248 " -S Generate Automake-style silent rules\n"
249 " -fxxx Store output in file 'xxx' (default: Makefile)\n";
252 static void fatal_error( const char *msg
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
253 static void fatal_perror( const char *msg
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
254 static void output( const char *format
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
255 static char *strmake( const char* fmt
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
257 /*******************************************************************
260 static void fatal_error( const char *msg
, ... )
263 va_start( valist
, msg
);
266 fprintf( stderr
, "%s:", input_file_name
);
267 if (input_line
) fprintf( stderr
, "%d:", input_line
);
268 fprintf( stderr
, " error: " );
270 else fprintf( stderr
, "makedep: error: " );
271 vfprintf( stderr
, msg
, valist
);
277 /*******************************************************************
280 static void fatal_perror( const char *msg
, ... )
283 va_start( valist
, msg
);
286 fprintf( stderr
, "%s:", input_file_name
);
287 if (input_line
) fprintf( stderr
, "%d:", input_line
);
288 fprintf( stderr
, " error: " );
290 else fprintf( stderr
, "makedep: error: " );
291 vfprintf( stderr
, msg
, valist
);
298 /*******************************************************************
301 static void cleanup_files(void)
303 if (temp_file_name
) unlink( temp_file_name
);
304 if (output_file_name
) unlink( output_file_name
);
308 /*******************************************************************
311 static void exit_on_signal( int sig
)
313 exit( 1 ); /* this will call the atexit functions */
317 /*******************************************************************
320 static void output( const char *format
, ... )
325 va_start( valist
, format
);
326 ret
= vfprintf( output_file
, format
, valist
);
328 if (ret
< 0) fatal_perror( "output" );
329 if (format
[0] && format
[strlen(format
) - 1] == '\n') output_column
= 0;
330 else output_column
+= ret
;
334 /*******************************************************************
337 * Find a value in a name/value pair string array.
339 static const char *strarray_get_value( const struct strarray
*array
, const char *name
)
341 int pos
, res
, min
= 0, max
= array
->count
/ 2 - 1;
345 pos
= (min
+ max
) / 2;
346 if (!(res
= strcmp( array
->str
[pos
* 2], name
))) return array
->str
[pos
* 2 + 1];
347 if (res
< 0) min
= pos
+ 1;
354 /*******************************************************************
357 * Define a value in a name/value pair string array.
359 static void strarray_set_value( struct strarray
*array
, const char *name
, const char *value
)
361 int i
, pos
, res
, min
= 0, max
= array
->count
/ 2 - 1;
365 pos
= (min
+ max
) / 2;
366 if (!(res
= strcmp( array
->str
[pos
* 2], name
)))
368 /* redefining a variable replaces the previous value */
369 array
->str
[pos
* 2 + 1] = value
;
372 if (res
< 0) min
= pos
+ 1;
375 strarray_add( array
, NULL
);
376 strarray_add( array
, NULL
);
377 for (i
= array
->count
- 1; i
> min
* 2 + 1; i
--) array
->str
[i
] = array
->str
[i
- 2];
378 array
->str
[min
* 2] = name
;
379 array
->str
[min
* 2 + 1] = value
;
383 /*******************************************************************
386 static const char *normalize_arch( const char *arch
)
390 static const char *map
[][8] =
392 /* normalized aliases */
393 { "i386", "i486", "i586", "i686", "ia32" },
394 { "x86_64", "amd64", "x86-64", "x86_amd64", "x64" },
395 { "aarch64", "arm64" },
399 for (i
= 0; i
< sizeof(map
) / sizeof(map
[0]); i
++)
400 for (j
= 0; map
[i
][j
]; j
++)
401 if (!strncmp( arch
, map
[i
][j
], strlen(map
[i
][j
]) ))
407 /*******************************************************************
410 static void output_filename( const char *name
)
412 if (output_column
+ strlen(name
) + 1 > 100)
417 else if (output_column
) output( " " );
418 output( "%s", name
);
422 /*******************************************************************
425 static void output_filenames( struct strarray array
)
429 for (i
= 0; i
< array
.count
; i
++) output_filename( array
.str
[i
] );
433 /*******************************************************************
434 * output_rm_filenames
436 static void output_rm_filenames( struct strarray array
)
438 static const unsigned int max_cmdline
= 30000; /* to be on the safe side */
441 if (!array
.count
) return;
443 for (i
= len
= 0; i
< array
.count
; i
++)
445 if (len
> max_cmdline
)
451 output_filename( array
.str
[i
] );
452 len
+= strlen( array
.str
[i
] ) + 1;
458 /*******************************************************************
461 static char *get_extension( char *filename
)
463 char *ext
= strrchr( filename
, '.' );
464 if (ext
&& strchr( ext
, '/' )) ext
= NULL
;
469 /*******************************************************************
472 static const char *get_base_name( const char *name
)
475 if (!strchr( name
, '.' )) return name
;
476 base
= xstrdup( name
);
477 *strrchr( base
, '.' ) = 0;
482 /*******************************************************************
485 static char *replace_filename( const char *path
, const char *name
)
491 if (!path
) return xstrdup( name
);
492 if (!(p
= strrchr( path
, '/' ))) return xstrdup( name
);
494 ret
= xmalloc( len
+ strlen( name
) + 1 );
495 memcpy( ret
, path
, len
);
496 strcpy( ret
+ len
, name
);
501 /*******************************************************************
504 static char *replace_substr( const char *str
, const char *start
, size_t len
, const char *replace
)
506 size_t pos
= start
- str
;
507 char *ret
= xmalloc( pos
+ strlen(replace
) + strlen(start
+ len
) + 1 );
508 memcpy( ret
, str
, pos
);
509 strcpy( ret
+ pos
, replace
);
510 strcat( ret
+ pos
, start
+ len
);
515 /*******************************************************************
518 * Determine where the destination path is located relative to the 'from' path.
520 static char *get_relative_path( const char *from
, const char *dest
)
524 unsigned int dotdots
= 0;
526 /* a path of "." is equivalent to an empty path */
527 if (!strcmp( from
, "." )) from
= "";
531 while (*from
== '/') from
++;
532 while (*dest
== '/') dest
++;
533 start
= dest
; /* save start of next path element */
536 while (*from
&& *from
!= '/' && *from
== *dest
) { from
++; dest
++; }
537 if ((!*from
|| *from
== '/') && (!*dest
|| *dest
== '/')) continue;
539 /* count remaining elements in 'from' */
543 while (*from
&& *from
!= '/') from
++;
544 while (*from
== '/') from
++;
550 if (!start
[0] && !dotdots
) return NULL
; /* empty path */
552 ret
= xmalloc( 3 * dotdots
+ strlen( start
) + 1 );
553 for (p
= ret
; dotdots
; dotdots
--, p
+= 3) memcpy( p
, "../", 3 );
555 if (start
[0]) strcpy( p
, start
);
556 else p
[-1] = 0; /* remove trailing slash */
561 /*******************************************************************
564 static char *concat_paths( const char *base
, const char *path
)
569 if (!base
|| !base
[0]) return xstrdup( path
&& path
[0] ? path
: "." );
570 if (!path
|| !path
[0]) return xstrdup( base
);
571 if (path
[0] == '/') return xstrdup( path
);
573 len
= strlen( base
);
574 while (len
&& base
[len
- 1] == '/') len
--;
575 while (len
&& !strncmp( path
, "..", 2 ) && (!path
[2] || path
[2] == '/'))
577 for (i
= len
; i
> 0; i
--) if (base
[i
- 1] == '/') break;
578 if (i
== len
- 2 && !memcmp( base
+ i
, "..", 2 )) break; /* we can't go up if we already have ".." */
579 if (i
!= len
- 1 || base
[i
] != '.')
582 while (*path
== '/') path
++;
584 /* else ignore "." element */
585 while (i
> 0 && base
[i
- 1] == '/') i
--;
588 if (!len
&& base
[0] != '/') return xstrdup( path
[0] ? path
: "." );
589 ret
= xmalloc( len
+ strlen( path
) + 2 );
590 memcpy( ret
, base
, len
);
592 strcpy( ret
+ len
, path
);
597 /*******************************************************************
600 static char *obj_dir_path( const struct makefile
*make
, const char *path
)
602 return concat_paths( make
->obj_dir
, path
);
606 /*******************************************************************
609 static char *src_dir_path( const struct makefile
*make
, const char *path
)
611 if (make
->src_dir
) return concat_paths( make
->src_dir
, path
);
612 return obj_dir_path( make
, path
);
616 /*******************************************************************
619 static char *root_src_dir_path( const char *path
)
621 return concat_paths( root_src_dir
, path
);
625 /*******************************************************************
628 static char *tools_dir_path( const struct makefile
*make
, const char *path
)
630 if (tools_dir
) return strmake( "%s/tools/%s", tools_dir
, path
);
631 return strmake( "tools/%s", path
);
635 /*******************************************************************
638 static char *tools_path( const struct makefile
*make
, const char *name
)
640 return strmake( "%s/%s%s", tools_dir_path( make
, name
), name
, tools_ext
);
644 /*******************************************************************
645 * strarray_addall_path
647 static void strarray_addall_path( struct strarray
*array
, const char *dir
, struct strarray added
)
651 for (i
= 0; i
< added
.count
; i
++) strarray_add( array
, concat_paths( dir
, added
.str
[i
] ));
655 /*******************************************************************
658 static char *get_line( FILE *file
)
666 buffer
= xmalloc( size
);
668 if (!fgets( buffer
, size
, file
)) return NULL
;
673 char *p
= buffer
+ strlen(buffer
);
674 /* if line is larger than buffer, resize buffer */
675 while (p
== buffer
+ size
- 1 && p
[-1] != '\n')
677 buffer
= xrealloc( buffer
, size
* 2 );
678 if (!fgets( buffer
+ size
- 1, size
+ 1, file
)) break;
679 p
= buffer
+ strlen(buffer
);
682 if (p
> buffer
&& p
[-1] == '\n')
685 if (p
> buffer
&& p
[-1] == '\r') *(--p
) = 0;
686 if (p
> buffer
&& p
[-1] == '\\')
689 /* line ends in backslash, read continuation line */
690 if (!fgets( p
, size
- (p
- buffer
), file
)) return buffer
;
700 /*******************************************************************
703 static unsigned int hash_filename( const char *name
)
706 unsigned int ret
= 2166136261u;
707 while (*name
) ret
= (ret
* 16777619) ^ *name
++;
708 return ret
% HASH_SIZE
;
712 /*******************************************************************
715 static struct file
*add_file( const char *name
)
717 struct file
*file
= xmalloc( sizeof(*file
) );
718 memset( file
, 0, sizeof(*file
) );
719 file
->name
= xstrdup( name
);
724 /*******************************************************************
727 static void add_dependency( struct file
*file
, const char *name
, enum incl_type type
)
729 if (file
->deps_count
>= file
->deps_size
)
731 file
->deps_size
*= 2;
732 if (file
->deps_size
< 16) file
->deps_size
= 16;
733 file
->deps
= xrealloc( file
->deps
, file
->deps_size
* sizeof(*file
->deps
) );
735 file
->deps
[file
->deps_count
].line
= input_line
;
736 file
->deps
[file
->deps_count
].type
= type
;
737 file
->deps
[file
->deps_count
].name
= xstrdup( name
);
742 /*******************************************************************
745 static struct incl_file
*find_src_file( const struct makefile
*make
, const char *name
)
747 struct incl_file
*file
;
749 LIST_FOR_EACH_ENTRY( file
, &make
->sources
, struct incl_file
, entry
)
750 if (!strcmp( name
, file
->name
)) return file
;
754 /*******************************************************************
757 static struct incl_file
*find_include_file( const struct makefile
*make
, const char *name
)
759 struct incl_file
*file
;
761 LIST_FOR_EACH_ENTRY( file
, &make
->includes
, struct incl_file
, entry
)
763 const char *filename
= file
->filename
;
764 if (!filename
) continue;
765 if (make
->obj_dir
&& strlen(make
->obj_dir
) < strlen(filename
))
767 filename
+= strlen(make
->obj_dir
);
768 while (*filename
== '/') filename
++;
770 if (!strcmp( name
, filename
)) return file
;
775 /*******************************************************************
778 * Add an include file if it doesn't already exists.
780 static struct incl_file
*add_include( struct makefile
*make
, struct incl_file
*parent
,
781 const char *name
, int line
, enum incl_type type
)
783 struct incl_file
*include
;
785 if (parent
->files_count
>= parent
->files_size
)
787 parent
->files_size
*= 2;
788 if (parent
->files_size
< 16) parent
->files_size
= 16;
789 parent
->files
= xrealloc( parent
->files
, parent
->files_size
* sizeof(*parent
->files
) );
792 LIST_FOR_EACH_ENTRY( include
, &make
->includes
, struct incl_file
, entry
)
793 if (!parent
->use_msvcrt
== !include
->use_msvcrt
&& !strcmp( name
, include
->name
))
796 include
= xmalloc( sizeof(*include
) );
797 memset( include
, 0, sizeof(*include
) );
798 include
->name
= xstrdup(name
);
799 include
->included_by
= parent
;
800 include
->included_line
= line
;
801 include
->type
= type
;
802 include
->use_msvcrt
= parent
->use_msvcrt
;
803 list_add_tail( &make
->includes
, &include
->entry
);
805 parent
->files
[parent
->files_count
++] = include
;
810 /*******************************************************************
811 * add_generated_source
813 * Add a generated source file to the list.
815 static struct incl_file
*add_generated_source( struct makefile
*make
,
816 const char *name
, const char *filename
)
818 struct incl_file
*file
;
820 if ((file
= find_src_file( make
, name
))) return file
; /* we already have it */
821 file
= xmalloc( sizeof(*file
) );
822 memset( file
, 0, sizeof(*file
) );
823 file
->file
= add_file( name
);
824 file
->name
= xstrdup( name
);
825 file
->basename
= xstrdup( filename
? filename
: name
);
826 file
->filename
= obj_dir_path( make
, file
->basename
);
827 file
->file
->flags
= FLAG_GENERATED
;
828 file
->use_msvcrt
= make
->use_msvcrt
;
829 list_add_tail( &make
->sources
, &file
->entry
);
834 /*******************************************************************
835 * parse_include_directive
837 static void parse_include_directive( struct file
*source
, char *str
)
839 char quote
, *include
, *p
= str
;
841 while (*p
&& isspace(*p
)) p
++;
842 if (*p
!= '\"' && *p
!= '<' ) return;
844 if (quote
== '<') quote
= '>';
846 while (*p
&& (*p
!= quote
)) p
++;
847 if (!*p
) fatal_error( "malformed include directive '%s'\n", str
);
849 add_dependency( source
, include
, (quote
== '>') ? INCL_SYSTEM
: INCL_NORMAL
);
853 /*******************************************************************
854 * parse_pragma_directive
856 static void parse_pragma_directive( struct file
*source
, char *str
)
858 char *flag
, *p
= str
;
860 if (!isspace( *p
)) return;
861 while (*p
&& isspace(*p
)) p
++;
862 p
= strtok( p
, " \t" );
863 if (strcmp( p
, "makedep" )) return;
865 while ((flag
= strtok( NULL
, " \t" )))
867 if (!strcmp( flag
, "depend" ))
869 while ((p
= strtok( NULL
, " \t" ))) add_dependency( source
, p
, INCL_NORMAL
);
872 else if (!strcmp( flag
, "install" )) source
->flags
|= FLAG_INSTALL
;
874 if (strendswith( source
->name
, ".idl" ))
876 if (!strcmp( flag
, "header" )) source
->flags
|= FLAG_IDL_HEADER
;
877 else if (!strcmp( flag
, "proxy" )) source
->flags
|= FLAG_IDL_PROXY
;
878 else if (!strcmp( flag
, "client" )) source
->flags
|= FLAG_IDL_CLIENT
;
879 else if (!strcmp( flag
, "server" )) source
->flags
|= FLAG_IDL_SERVER
;
880 else if (!strcmp( flag
, "ident" )) source
->flags
|= FLAG_IDL_IDENT
;
881 else if (!strcmp( flag
, "typelib" )) source
->flags
|= FLAG_IDL_TYPELIB
;
882 else if (!strcmp( flag
, "register" )) source
->flags
|= FLAG_IDL_REGISTER
;
883 else if (!strcmp( flag
, "regtypelib" )) source
->flags
|= FLAG_IDL_REGTYPELIB
;
885 else if (strendswith( source
->name
, ".rc" ))
887 if (!strcmp( flag
, "po" )) source
->flags
|= FLAG_RC_PO
;
889 else if (strendswith( source
->name
, ".sfd" ))
891 if (!strcmp( flag
, "font" ))
893 struct strarray
*array
= source
->args
;
897 source
->args
= array
= xmalloc( sizeof(*array
) );
898 *array
= empty_strarray
;
899 source
->flags
|= FLAG_SFD_FONTS
;
901 strarray_add( array
, xstrdup( strtok( NULL
, "" )));
907 if (!strcmp( flag
, "implib" )) source
->flags
|= FLAG_C_IMPLIB
;
908 if (!strcmp( flag
, "unix" )) source
->flags
|= FLAG_C_UNIX
;
914 /*******************************************************************
915 * parse_cpp_directive
917 static void parse_cpp_directive( struct file
*source
, char *str
)
919 while (*str
&& isspace(*str
)) str
++;
920 if (*str
++ != '#') return;
921 while (*str
&& isspace(*str
)) str
++;
923 if (!strncmp( str
, "include", 7 ))
924 parse_include_directive( source
, str
+ 7 );
925 else if (!strncmp( str
, "import", 6 ) && strendswith( source
->name
, ".m" ))
926 parse_include_directive( source
, str
+ 6 );
927 else if (!strncmp( str
, "pragma", 6 ))
928 parse_pragma_directive( source
, str
+ 6 );
932 /*******************************************************************
935 static void parse_idl_file( struct file
*source
, FILE *file
)
937 char *buffer
, *include
;
941 while ((buffer
= get_line( file
)))
945 while (*p
&& isspace(*p
)) p
++;
947 if (!strncmp( p
, "importlib", 9 ))
950 while (*p
&& isspace(*p
)) p
++;
951 if (*p
++ != '(') continue;
952 while (*p
&& isspace(*p
)) p
++;
953 if (*p
++ != '"') continue;
955 while (*p
&& (*p
!= '"')) p
++;
956 if (!*p
) fatal_error( "malformed importlib directive\n" );
958 add_dependency( source
, include
, INCL_IMPORTLIB
);
962 if (!strncmp( p
, "import", 6 ))
965 while (*p
&& isspace(*p
)) p
++;
966 if (*p
!= '"') continue;
968 while (*p
&& (*p
!= '"')) p
++;
969 if (!*p
) fatal_error( "malformed import directive\n" );
971 add_dependency( source
, include
, INCL_IMPORT
);
975 /* check for #include inside cpp_quote */
976 if (!strncmp( p
, "cpp_quote", 9 ))
979 while (*p
&& isspace(*p
)) p
++;
980 if (*p
++ != '(') continue;
981 while (*p
&& isspace(*p
)) p
++;
982 if (*p
++ != '"') continue;
983 if (*p
++ != '#') continue;
984 while (*p
&& isspace(*p
)) p
++;
985 if (strncmp( p
, "include", 7 )) continue;
987 while (*p
&& isspace(*p
)) p
++;
988 if (*p
== '\\' && p
[1] == '"')
995 if (*p
++ != '<' ) continue;
999 while (*p
&& (*p
!= quote
)) p
++;
1000 if (!*p
|| (quote
== '"' && p
[-1] != '\\'))
1001 fatal_error( "malformed #include directive inside cpp_quote\n" );
1002 if (quote
== '"') p
--; /* remove backslash */
1004 add_dependency( source
, include
, (quote
== '>') ? INCL_CPP_QUOTE_SYSTEM
: INCL_CPP_QUOTE
);
1008 parse_cpp_directive( source
, p
);
1012 /*******************************************************************
1015 static void parse_c_file( struct file
*source
, FILE *file
)
1020 while ((buffer
= get_line( file
)))
1022 parse_cpp_directive( source
, buffer
);
1027 /*******************************************************************
1030 static void parse_rc_file( struct file
*source
, FILE *file
)
1032 char *buffer
, *include
;
1035 while ((buffer
= get_line( file
)))
1039 while (*p
&& isspace(*p
)) p
++;
1041 if (p
[0] == '/' && p
[1] == '*') /* check for magic makedep comment */
1044 while (*p
&& isspace(*p
)) p
++;
1045 if (strncmp( p
, "@makedep:", 9 )) continue;
1047 while (*p
&& isspace(*p
)) p
++;
1052 while (*p
&& *p
!= quote
) p
++;
1057 while (*p
&& !isspace(*p
) && *p
!= '*') p
++;
1060 fatal_error( "malformed makedep comment\n" );
1062 add_dependency( source
, include
, (quote
== '>') ? INCL_SYSTEM
: INCL_NORMAL
);
1066 parse_cpp_directive( source
, buffer
);
1071 /*******************************************************************
1074 static void parse_in_file( struct file
*source
, FILE *file
)
1078 /* make sure it gets rebuilt when the version changes */
1079 add_dependency( source
, "config.h", INCL_SYSTEM
);
1081 if (!strendswith( source
->name
, ".man.in" )) return; /* not a man page */
1084 while ((buffer
= get_line( file
)))
1086 if (strncmp( buffer
, ".TH", 3 )) continue;
1087 if (!(p
= strtok( buffer
, " \t" ))) continue; /* .TH */
1088 if (!(p
= strtok( NULL
, " \t" ))) continue; /* program name */
1089 if (!(p
= strtok( NULL
, " \t" ))) continue; /* man section */
1090 source
->args
= xstrdup( p
);
1096 /*******************************************************************
1099 static void parse_sfd_file( struct file
*source
, FILE *file
)
1101 char *p
, *eol
, *buffer
;
1104 while ((buffer
= get_line( file
)))
1106 if (strncmp( buffer
, "UComments:", 10 )) continue;
1108 while (*p
== ' ') p
++;
1109 if (p
[0] == '"' && p
[1] && buffer
[strlen(buffer
) - 1] == '"')
1112 buffer
[strlen(buffer
) - 1] = 0;
1114 while ((eol
= strstr( p
, "+AAoA" )))
1117 while (*p
&& isspace(*p
)) p
++;
1120 while (*p
&& isspace(*p
)) p
++;
1121 if (!strncmp( p
, "pragma", 6 )) parse_pragma_directive( source
, p
+ 6 );
1125 while (*p
&& isspace(*p
)) p
++;
1126 if (*p
++ != '#') return;
1127 while (*p
&& isspace(*p
)) p
++;
1128 if (!strncmp( p
, "pragma", 6 )) parse_pragma_directive( source
, p
+ 6 );
1137 void (*parse
)( struct file
*file
, FILE *f
);
1138 } parse_functions
[] =
1140 { ".c", parse_c_file
},
1141 { ".h", parse_c_file
},
1142 { ".inl", parse_c_file
},
1143 { ".l", parse_c_file
},
1144 { ".m", parse_c_file
},
1145 { ".rh", parse_c_file
},
1146 { ".x", parse_c_file
},
1147 { ".y", parse_c_file
},
1148 { ".idl", parse_idl_file
},
1149 { ".rc", parse_rc_file
},
1150 { ".in", parse_in_file
},
1151 { ".sfd", parse_sfd_file
}
1154 /*******************************************************************
1157 static struct file
*load_file( const char *name
)
1161 unsigned int i
, hash
= hash_filename( name
);
1163 LIST_FOR_EACH_ENTRY( file
, &files
[hash
], struct file
, entry
)
1164 if (!strcmp( name
, file
->name
)) return file
;
1166 if (!(f
= fopen( name
, "r" ))) return NULL
;
1168 file
= add_file( name
);
1169 list_add_tail( &files
[hash
], &file
->entry
);
1170 input_file_name
= file
->name
;
1173 for (i
= 0; i
< sizeof(parse_functions
) / sizeof(parse_functions
[0]); i
++)
1175 if (!strendswith( name
, parse_functions
[i
].ext
)) continue;
1176 parse_functions
[i
].parse( file
, f
);
1181 input_file_name
= NULL
;
1187 /*******************************************************************
1188 * open_include_path_file
1190 * Open a file from a directory on the include path.
1192 static struct file
*open_include_path_file( const struct makefile
*make
, const char *dir
,
1193 const char *name
, char **filename
)
1195 char *src_path
= concat_paths( dir
, name
);
1196 struct file
*ret
= load_file( src_path
);
1198 if (ret
) *filename
= src_path
;
1203 /*******************************************************************
1204 * open_file_same_dir
1206 * Open a file in the same directory as the parent.
1208 static struct file
*open_file_same_dir( const struct incl_file
*parent
, const char *name
, char **filename
)
1210 char *src_path
= replace_filename( parent
->file
->name
, name
);
1211 struct file
*ret
= load_file( src_path
);
1213 if (ret
) *filename
= replace_filename( parent
->filename
, name
);
1218 /*******************************************************************
1219 * open_same_dir_generated_file
1221 * Open a generated_file in the same directory as the parent.
1223 static struct file
*open_same_dir_generated_file( const struct makefile
*make
,
1224 const struct incl_file
*parent
, struct incl_file
*file
,
1225 const char *ext
, const char *src_ext
)
1228 struct file
*ret
= NULL
;
1230 if (strendswith( file
->name
, ext
) &&
1231 (ret
= open_file_same_dir( parent
, replace_extension( file
->name
, ext
, src_ext
), &filename
)))
1233 file
->sourcename
= filename
;
1234 file
->filename
= obj_dir_path( make
, replace_filename( parent
->name
, file
->name
));
1240 /*******************************************************************
1243 * Open a file in the source directory of the makefile.
1245 static struct file
*open_local_file( const struct makefile
*make
, const char *path
, char **filename
)
1247 char *src_path
= src_dir_path( make
, path
);
1248 struct file
*ret
= load_file( src_path
);
1250 /* if not found, try parent dir */
1251 if (!ret
&& make
->parent_dir
)
1254 path
= strmake( "%s/%s", make
->parent_dir
, path
);
1255 src_path
= src_dir_path( make
, path
);
1256 ret
= load_file( src_path
);
1259 if (ret
) *filename
= src_path
;
1264 /*******************************************************************
1265 * open_local_generated_file
1267 * Open a generated file in the directory of the makefile.
1269 static struct file
*open_local_generated_file( const struct makefile
*make
, struct incl_file
*file
,
1270 const char *ext
, const char *src_ext
)
1273 struct file
*ret
= NULL
;
1275 if (strendswith( file
->name
, ext
) &&
1276 (ret
= open_local_file( make
, replace_extension( file
->name
, ext
, src_ext
), &filename
)))
1278 file
->sourcename
= filename
;
1279 file
->filename
= obj_dir_path( make
, file
->name
);
1285 /*******************************************************************
1288 * Open a file in the top-level source directory.
1290 static struct file
*open_global_file( const struct makefile
*make
, const char *path
, char **filename
)
1292 char *src_path
= root_src_dir_path( path
);
1293 struct file
*ret
= load_file( src_path
);
1295 if (ret
) *filename
= src_path
;
1300 /*******************************************************************
1301 * open_global_header
1303 * Open a file in the global include source directory.
1305 static struct file
*open_global_header( const struct makefile
*make
, const char *path
, char **filename
)
1307 if (!strncmp( path
, "../", 3 )) return NULL
;
1308 return open_global_file( make
, strmake( "include/%s", path
), filename
);
1312 /*******************************************************************
1313 * open_global_generated_file
1315 * Open a generated file in the top-level source directory.
1317 static struct file
*open_global_generated_file( const struct makefile
*make
, struct incl_file
*file
,
1318 const char *ext
, const char *src_ext
)
1321 struct file
*ret
= NULL
;
1323 if (strendswith( file
->name
, ext
) &&
1324 (ret
= open_global_header( make
, replace_extension( file
->name
, ext
, src_ext
), &filename
)))
1326 file
->sourcename
= filename
;
1327 file
->filename
= strmake( "include/%s", file
->name
);
1333 /*******************************************************************
1336 static struct file
*open_src_file( const struct makefile
*make
, struct incl_file
*pFile
)
1338 struct file
*file
= open_local_file( make
, pFile
->name
, &pFile
->filename
);
1340 if (!file
) fatal_perror( "open %s", pFile
->name
);
1345 /*******************************************************************
1346 * find_importlib_module
1348 static struct makefile
*find_importlib_module( const char *name
)
1350 unsigned int i
, len
;
1352 for (i
= 0; i
< subdirs
.count
; i
++)
1354 if (strncmp( submakes
[i
]->obj_dir
, "dlls/", 5 )) continue;
1355 len
= strlen(submakes
[i
]->obj_dir
);
1356 if (strncmp( submakes
[i
]->obj_dir
+ 5, name
, len
- 5 )) continue;
1357 if (!name
[len
- 5] || !strcmp( name
+ len
- 5, ".dll" )) return submakes
[i
];
1363 /*******************************************************************
1366 static struct file
*open_include_file( const struct makefile
*make
, struct incl_file
*pFile
)
1368 struct file
*file
= NULL
;
1369 unsigned int i
, len
;
1373 /* check for generated files */
1374 if ((file
= open_local_generated_file( make
, pFile
, ".tab.h", ".y" ))) return file
;
1375 if ((file
= open_local_generated_file( make
, pFile
, ".h", ".idl" ))) return file
;
1376 if (fontforge
&& (file
= open_local_generated_file( make
, pFile
, ".ttf", ".sfd" ))) return file
;
1377 if (convert
&& rsvg
&& icotool
)
1379 if ((file
= open_local_generated_file( make
, pFile
, ".bmp", ".svg" ))) return file
;
1380 if ((file
= open_local_generated_file( make
, pFile
, ".cur", ".svg" ))) return file
;
1381 if ((file
= open_local_generated_file( make
, pFile
, ".ico", ".svg" ))) return file
;
1384 /* check for extra targets */
1385 if (strarray_exists( &make
->extra_targets
, pFile
->name
))
1387 pFile
->sourcename
= src_dir_path( make
, pFile
->name
);
1388 pFile
->filename
= obj_dir_path( make
, pFile
->name
);
1392 /* now try in source dir */
1393 if ((file
= open_local_file( make
, pFile
->name
, &pFile
->filename
))) return file
;
1395 /* check for global importlib (module dependency) */
1396 if (pFile
->type
== INCL_IMPORTLIB
&& find_importlib_module( pFile
->name
))
1398 pFile
->filename
= pFile
->name
;
1402 /* check for generated files in global includes */
1403 if ((file
= open_global_generated_file( make
, pFile
, ".h", ".idl" ))) return file
;
1404 if ((file
= open_global_generated_file( make
, pFile
, ".h", ".h.in" ))) return file
;
1405 if (strendswith( pFile
->name
, "tmpl.h" ) &&
1406 (file
= open_global_generated_file( make
, pFile
, ".h", ".x" ))) return file
;
1408 /* check in global includes source dir */
1409 if ((file
= open_global_header( make
, pFile
->name
, &pFile
->filename
))) return file
;
1411 /* check in global msvcrt includes */
1412 if (pFile
->use_msvcrt
&&
1413 (file
= open_global_header( make
, strmake( "msvcrt/%s", pFile
->name
), &pFile
->filename
)))
1416 /* now search in include paths */
1417 for (i
= 0; i
< make
->include_paths
.count
; i
++)
1419 const char *dir
= make
->include_paths
.str
[i
];
1423 len
= strlen( root_src_dir
);
1424 if (!strncmp( dir
, root_src_dir
, len
) && (!dir
[len
] || dir
[len
] == '/'))
1426 while (dir
[len
] == '/') len
++;
1427 file
= open_global_file( make
, concat_paths( dir
+ len
, pFile
->name
), &pFile
->filename
);
1432 if (*dir
== '/') continue;
1433 file
= open_include_path_file( make
, dir
, pFile
->name
, &pFile
->filename
);
1435 if (!file
) continue;
1436 pFile
->is_external
= 1;
1440 if (pFile
->type
== INCL_SYSTEM
) return NULL
; /* ignore system files we cannot find */
1442 /* try in src file directory */
1443 if ((file
= open_same_dir_generated_file( make
, pFile
->included_by
, pFile
, ".tab.h", ".y" )) ||
1444 (file
= open_same_dir_generated_file( make
, pFile
->included_by
, pFile
, ".h", ".idl" )) ||
1445 (file
= open_file_same_dir( pFile
->included_by
, pFile
->name
, &pFile
->filename
)))
1447 pFile
->is_external
= pFile
->included_by
->is_external
;
1451 if (make
->extlib
) return NULL
; /* ignore missing files in external libs */
1453 fprintf( stderr
, "%s:%d: error: ", pFile
->included_by
->file
->name
, pFile
->included_line
);
1454 perror( pFile
->name
);
1455 pFile
= pFile
->included_by
;
1456 while (pFile
&& pFile
->included_by
)
1458 const char *parent
= pFile
->included_by
->sourcename
;
1459 if (!parent
) parent
= pFile
->included_by
->file
->name
;
1460 fprintf( stderr
, "%s:%d: note: %s was first included here\n",
1461 parent
, pFile
->included_line
, pFile
->name
);
1462 pFile
= pFile
->included_by
;
1468 /*******************************************************************
1471 static void add_all_includes( struct makefile
*make
, struct incl_file
*parent
, struct file
*file
)
1475 for (i
= 0; i
< file
->deps_count
; i
++)
1477 switch (file
->deps
[i
].type
)
1481 add_include( make
, parent
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_NORMAL
);
1483 case INCL_IMPORTLIB
:
1484 add_include( make
, parent
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_IMPORTLIB
);
1487 add_include( make
, parent
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_SYSTEM
);
1489 case INCL_CPP_QUOTE
:
1490 case INCL_CPP_QUOTE_SYSTEM
:
1497 /*******************************************************************
1500 static void parse_file( struct makefile
*make
, struct incl_file
*source
, int src
)
1502 struct file
*file
= src
? open_src_file( make
, source
) : open_include_file( make
, source
);
1506 source
->file
= file
;
1507 source
->files_count
= 0;
1508 source
->files_size
= file
->deps_count
;
1509 source
->files
= xmalloc( source
->files_size
* sizeof(*source
->files
) );
1511 if (strendswith( file
->name
, ".m" )) file
->flags
|= FLAG_C_UNIX
;
1512 if (file
->flags
& FLAG_C_UNIX
) source
->use_msvcrt
= 0;
1513 else if (file
->flags
& FLAG_C_IMPLIB
) source
->use_msvcrt
= 1;
1515 if (source
->sourcename
)
1517 if (strendswith( source
->sourcename
, ".idl" ))
1521 /* generated .h file always includes these */
1522 add_include( make
, source
, "rpc.h", 0, INCL_NORMAL
);
1523 add_include( make
, source
, "rpcndr.h", 0, INCL_NORMAL
);
1524 for (i
= 0; i
< file
->deps_count
; i
++)
1526 switch (file
->deps
[i
].type
)
1529 if (strendswith( file
->deps
[i
].name
, ".idl" ))
1530 add_include( make
, source
, replace_extension( file
->deps
[i
].name
, ".idl", ".h" ),
1531 file
->deps
[i
].line
, INCL_NORMAL
);
1533 add_include( make
, source
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_NORMAL
);
1535 case INCL_CPP_QUOTE
:
1536 add_include( make
, source
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_NORMAL
);
1538 case INCL_CPP_QUOTE_SYSTEM
:
1539 add_include( make
, source
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_SYSTEM
);
1543 case INCL_IMPORTLIB
:
1549 if (strendswith( source
->sourcename
, ".y" ))
1550 return; /* generated .tab.h doesn't include anything */
1553 add_all_includes( make
, source
, file
);
1557 /*******************************************************************
1560 * Add a source file to the list.
1562 static struct incl_file
*add_src_file( struct makefile
*make
, const char *name
)
1564 struct incl_file
*file
;
1566 if ((file
= find_src_file( make
, name
))) return file
; /* we already have it */
1567 file
= xmalloc( sizeof(*file
) );
1568 memset( file
, 0, sizeof(*file
) );
1569 file
->name
= xstrdup(name
);
1570 file
->use_msvcrt
= make
->use_msvcrt
;
1571 file
->is_external
= !!make
->extlib
;
1572 list_add_tail( &make
->sources
, &file
->entry
);
1573 parse_file( make
, file
, 1 );
1578 /*******************************************************************
1579 * open_input_makefile
1581 static FILE *open_input_makefile( const struct makefile
*make
)
1586 input_file_name
= root_src_dir_path( obj_dir_path( make
, "Makefile.in" ));
1588 input_file_name
= output_makefile_name
; /* always use output name for main Makefile */
1591 if (!(ret
= fopen( input_file_name
, "r" ))) fatal_perror( "open" );
1596 /*******************************************************************
1599 static const char *get_make_variable( const struct makefile
*make
, const char *name
)
1603 if ((ret
= strarray_get_value( &cmdline_vars
, name
))) return ret
;
1604 if ((ret
= strarray_get_value( &make
->vars
, name
))) return ret
;
1605 if (top_makefile
&& (ret
= strarray_get_value( &top_makefile
->vars
, name
))) return ret
;
1610 /*******************************************************************
1611 * get_expanded_make_variable
1613 static char *get_expanded_make_variable( const struct makefile
*make
, const char *name
)
1616 char *p
, *end
, *expand
, *tmp
;
1618 var
= get_make_variable( make
, name
);
1619 if (!var
) return NULL
;
1621 p
= expand
= xstrdup( var
);
1622 while ((p
= strchr( p
, '$' )))
1626 if (!(end
= strchr( p
+ 2, ')' ))) fatal_error( "syntax error in '%s'\n", expand
);
1628 if (strchr( p
+ 2, ':' )) fatal_error( "pattern replacement not supported for '%s'\n", p
+ 2 );
1629 var
= get_make_variable( make
, p
+ 2 );
1630 tmp
= replace_substr( expand
, p
, end
- p
, var
? var
: "" );
1631 /* switch to the new string */
1632 p
= tmp
+ (p
- expand
);
1636 else if (p
[1] == '{') /* don't expand ${} variables */
1638 if (!(end
= strchr( p
+ 2, '}' ))) fatal_error( "syntax error in '%s'\n", expand
);
1641 else if (p
[1] == '$')
1645 else fatal_error( "syntax error in '%s'\n", expand
);
1648 /* consider empty variables undefined */
1650 while (*p
&& isspace(*p
)) p
++;
1651 if (*p
) return expand
;
1657 /*******************************************************************
1658 * get_expanded_make_var_array
1660 static struct strarray
get_expanded_make_var_array( const struct makefile
*make
, const char *name
)
1662 struct strarray ret
= empty_strarray
;
1663 char *value
, *token
;
1665 if ((value
= get_expanded_make_variable( make
, name
)))
1666 for (token
= strtok( value
, " \t" ); token
; token
= strtok( NULL
, " \t" ))
1667 strarray_add( &ret
, token
);
1672 /*******************************************************************
1673 * get_expanded_file_local_var
1675 static struct strarray
get_expanded_file_local_var( const struct makefile
*make
, const char *file
,
1678 char *p
, *var
= strmake( "%s_%s", file
, name
);
1680 for (p
= var
; *p
; p
++) if (!isalnum( *p
)) *p
= '_';
1681 return get_expanded_make_var_array( make
, var
);
1685 /*******************************************************************
1688 static int set_make_variable( struct strarray
*array
, const char *assignment
)
1692 p
= name
= xstrdup( assignment
);
1693 while (isalnum(*p
) || *p
== '_') p
++;
1694 if (name
== p
) return 0; /* not a variable */
1698 while (isspace(*p
)) p
++;
1700 if (*p
!= '=') return 0; /* not an assignment */
1702 while (isspace(*p
)) p
++;
1704 strarray_set_value( array
, name
, p
);
1709 /*******************************************************************
1712 static struct makefile
*parse_makefile( const char *path
)
1716 struct makefile
*make
= xmalloc( sizeof(*make
) );
1718 memset( make
, 0, sizeof(*make
) );
1719 make
->obj_dir
= path
;
1720 if (root_src_dir
) make
->src_dir
= root_src_dir_path( make
->obj_dir
);
1722 file
= open_input_makefile( make
);
1723 while ((buffer
= get_line( file
)))
1725 if (!strncmp( buffer
, separator
, strlen(separator
) )) break;
1726 if (*buffer
== '\t') continue; /* command */
1727 while (isspace( *buffer
)) buffer
++;
1728 if (*buffer
== '#') continue; /* comment */
1729 set_make_variable( &make
->vars
, buffer
);
1732 input_file_name
= NULL
;
1737 /*******************************************************************
1738 * add_generated_sources
1740 static void add_generated_sources( struct makefile
*make
)
1743 struct incl_file
*source
, *next
, *file
;
1744 struct strarray objs
= get_expanded_make_var_array( make
, "EXTRA_OBJS" );
1746 LIST_FOR_EACH_ENTRY_SAFE( source
, next
, &make
->sources
, struct incl_file
, entry
)
1748 if (source
->file
->flags
& FLAG_IDL_CLIENT
)
1750 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_c.c" ), NULL
);
1751 add_dependency( file
->file
, replace_extension( source
->name
, ".idl", ".h" ), INCL_NORMAL
);
1752 add_all_includes( make
, file
, file
->file
);
1754 if (source
->file
->flags
& FLAG_IDL_SERVER
)
1756 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_s.c" ), NULL
);
1757 add_dependency( file
->file
, "wine/exception.h", INCL_NORMAL
);
1758 add_dependency( file
->file
, replace_extension( source
->name
, ".idl", ".h" ), INCL_NORMAL
);
1759 add_all_includes( make
, file
, file
->file
);
1761 if (source
->file
->flags
& FLAG_IDL_IDENT
)
1763 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_i.c" ), NULL
);
1764 add_dependency( file
->file
, "rpc.h", INCL_NORMAL
);
1765 add_dependency( file
->file
, "rpcndr.h", INCL_NORMAL
);
1766 add_dependency( file
->file
, "guiddef.h", INCL_NORMAL
);
1767 add_all_includes( make
, file
, file
->file
);
1769 if (source
->file
->flags
& FLAG_IDL_PROXY
)
1771 file
= add_generated_source( make
, "dlldata.o", "dlldata.c" );
1772 add_dependency( file
->file
, "objbase.h", INCL_NORMAL
);
1773 add_dependency( file
->file
, "rpcproxy.h", INCL_NORMAL
);
1774 add_all_includes( make
, file
, file
->file
);
1775 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_p.c" ), NULL
);
1776 add_dependency( file
->file
, "objbase.h", INCL_NORMAL
);
1777 add_dependency( file
->file
, "rpcproxy.h", INCL_NORMAL
);
1778 add_dependency( file
->file
, "wine/exception.h", INCL_NORMAL
);
1779 add_dependency( file
->file
, replace_extension( source
->name
, ".idl", ".h" ), INCL_NORMAL
);
1780 add_all_includes( make
, file
, file
->file
);
1782 if (source
->file
->flags
& FLAG_IDL_TYPELIB
)
1784 add_generated_source( make
, replace_extension( source
->name
, ".idl", "_l.res" ), NULL
);
1786 if (source
->file
->flags
& FLAG_IDL_REGTYPELIB
)
1788 add_generated_source( make
, replace_extension( source
->name
, ".idl", "_t.res" ), NULL
);
1790 if (source
->file
->flags
& FLAG_IDL_REGISTER
)
1792 add_generated_source( make
, replace_extension( source
->name
, ".idl", "_r.res" ), NULL
);
1794 if (source
->file
->flags
& FLAG_IDL_HEADER
)
1796 add_generated_source( make
, replace_extension( source
->name
, ".idl", ".h" ), NULL
);
1798 if (!source
->file
->flags
&& strendswith( source
->name
, ".idl" ))
1800 add_generated_source( make
, replace_extension( source
->name
, ".idl", ".h" ), NULL
);
1802 if (strendswith( source
->name
, ".x" ))
1804 add_generated_source( make
, replace_extension( source
->name
, ".x", ".h" ), NULL
);
1806 if (strendswith( source
->name
, ".y" ))
1808 file
= add_generated_source( make
, replace_extension( source
->name
, ".y", ".tab.c" ), NULL
);
1809 /* steal the includes list from the source file */
1810 file
->files_count
= source
->files_count
;
1811 file
->files_size
= source
->files_size
;
1812 file
->files
= source
->files
;
1813 source
->files_count
= source
->files_size
= 0;
1814 source
->files
= NULL
;
1816 if (strendswith( source
->name
, ".l" ))
1818 file
= add_generated_source( make
, replace_extension( source
->name
, ".l", ".yy.c" ), NULL
);
1819 /* steal the includes list from the source file */
1820 file
->files_count
= source
->files_count
;
1821 file
->files_size
= source
->files_size
;
1822 file
->files
= source
->files
;
1823 source
->files_count
= source
->files_size
= 0;
1824 source
->files
= NULL
;
1826 if (source
->file
->flags
& FLAG_C_IMPLIB
)
1828 if (!make
->staticimplib
&& make
->importlib
&& *dll_ext
)
1829 make
->staticimplib
= strmake( "lib%s.a", make
->importlib
);
1831 if (strendswith( source
->name
, ".po" ))
1833 if (!make
->disabled
)
1834 strarray_add_uniq( &linguas
, replace_extension( source
->name
, ".po", "" ));
1836 if (strendswith( source
->name
, ".spec" ))
1838 char *obj
= replace_extension( source
->name
, ".spec", "" );
1839 strarray_addall_uniq( &make
->extra_imports
,
1840 get_expanded_file_local_var( make
, obj
, "IMPORTS" ));
1845 file
= add_generated_source( make
, "testlist.o", "testlist.c" );
1846 add_dependency( file
->file
, "wine/test.h", INCL_NORMAL
);
1847 add_all_includes( make
, file
, file
->file
);
1849 for (i
= 0; i
< objs
.count
; i
++)
1851 /* default to .c for unknown extra object files */
1852 if (strendswith( objs
.str
[i
], ".o" ))
1854 file
= add_generated_source( make
, objs
.str
[i
], replace_extension( objs
.str
[i
], ".o", ".c" ));
1855 file
->file
->flags
|= FLAG_C_UNIX
;
1856 file
->use_msvcrt
= 0;
1858 else if (strendswith( objs
.str
[i
], ".res" ))
1859 add_generated_source( make
, replace_extension( objs
.str
[i
], ".res", ".rc" ), NULL
);
1861 add_generated_source( make
, objs
.str
[i
], NULL
);
1866 /*******************************************************************
1869 static void create_dir( const char *dir
)
1873 p
= path
= xstrdup( dir
);
1874 while ((p
= strchr( p
, '/' )))
1877 if (mkdir( path
, 0755 ) == -1 && errno
!= EEXIST
) fatal_perror( "mkdir %s", path
);
1879 while (*p
== '/') p
++;
1881 if (mkdir( path
, 0755 ) == -1 && errno
!= EEXIST
) fatal_perror( "mkdir %s", path
);
1886 /*******************************************************************
1887 * create_file_directories
1889 * Create the base directories of all the files.
1891 static void create_file_directories( const struct makefile
*make
, struct strarray files
)
1893 struct strarray subdirs
= empty_strarray
;
1897 for (i
= 0; i
< files
.count
; i
++)
1899 if (!strchr( files
.str
[i
], '/' )) continue;
1900 dir
= obj_dir_path( make
, files
.str
[i
] );
1901 *strrchr( dir
, '/' ) = 0;
1902 strarray_add_uniq( &subdirs
, dir
);
1905 for (i
= 0; i
< subdirs
.count
; i
++) create_dir( subdirs
.str
[i
] );
1909 /*******************************************************************
1910 * output_filenames_obj_dir
1912 static void output_filenames_obj_dir( const struct makefile
*make
, struct strarray array
)
1916 for (i
= 0; i
< array
.count
; i
++) output_filename( obj_dir_path( make
, array
.str
[i
] ));
1920 /*******************************************************************
1923 static void get_dependencies( struct incl_file
*file
, struct incl_file
*source
)
1927 if (!file
->filename
) return;
1931 if (file
->owner
== source
) return; /* already processed */
1932 if (file
->type
== INCL_IMPORTLIB
)
1934 if (!(source
->file
->flags
& (FLAG_IDL_TYPELIB
| FLAG_IDL_REGTYPELIB
)))
1935 return; /* library is imported only when building a typelib */
1936 strarray_add( &source
->importlibdeps
, file
->filename
);
1938 else strarray_add( &source
->dependencies
, file
->filename
);
1939 file
->owner
= source
;
1942 if (!strcmp( file
->filename
, "include/config.h" ) &&
1943 file
!= source
->files
[0] && !source
->is_external
)
1945 input_file_name
= source
->filename
;
1947 for (i
= 0; i
< source
->file
->deps_count
; i
++)
1949 if (!strcmp( source
->file
->deps
[i
].name
, file
->name
))
1950 input_line
= source
->file
->deps
[i
].line
;
1952 fatal_error( "%s must be included before other headers\n", file
->name
);
1956 for (i
= 0; i
< file
->files_count
; i
++) get_dependencies( file
->files
[i
], source
);
1960 /*******************************************************************
1961 * get_local_dependencies
1963 * Get the local dependencies of a given target.
1965 static struct strarray
get_local_dependencies( const struct makefile
*make
, const char *name
,
1966 struct strarray targets
)
1969 struct strarray deps
= get_expanded_file_local_var( make
, name
, "DEPS" );
1971 for (i
= 0; i
< deps
.count
; i
++)
1973 if (strarray_exists( &targets
, deps
.str
[i
] ))
1974 deps
.str
[i
] = obj_dir_path( make
, deps
.str
[i
] );
1976 deps
.str
[i
] = src_dir_path( make
, deps
.str
[i
] );
1982 /*******************************************************************
1985 * Check if makefile builds the named static library and return the full lib path.
1987 static const char *get_static_lib( const struct makefile
*make
, const char *name
)
1989 if (!make
->staticlib
) return NULL
;
1990 if (make
->disabled
) return NULL
;
1991 if (strncmp( make
->staticlib
, "lib", 3 )) return NULL
;
1992 if (strncmp( make
->staticlib
+ 3, name
, strlen(name
) )) return NULL
;
1993 if (strcmp( make
->staticlib
+ 3 + strlen(name
), ".a" )) return NULL
;
1994 return obj_dir_path( make
, make
->staticlib
);
1998 /*******************************************************************
1999 * get_native_unix_lib
2001 static const char *get_native_unix_lib( const struct makefile
*make
, const char *name
)
2003 if (!make
->native_unix_lib
) return NULL
;
2004 if (strncmp( make
->unixlib
, name
, strlen(name
) )) return NULL
;
2005 if (make
->unixlib
[strlen(name
)] != '.') return NULL
;
2006 return obj_dir_path( make
, make
->unixlib
);
2010 /*******************************************************************
2011 * get_parent_makefile
2013 static struct makefile
*get_parent_makefile( struct makefile
*make
)
2018 if (!make
->obj_dir
) return NULL
;
2019 dir
= xstrdup( make
->obj_dir
);
2020 if (!(p
= strrchr( dir
, '/' ))) return NULL
;
2022 for (i
= 0; i
< subdirs
.count
; i
++)
2023 if (!strcmp( submakes
[i
]->obj_dir
, dir
)) return submakes
[i
];
2028 /*******************************************************************
2031 static int needs_delay_lib( const struct makefile
*make
)
2033 if (delay_load_flag
) return 0;
2034 if (*dll_ext
&& !crosstarget
) return 0;
2035 if (!make
->importlib
) return 0;
2036 return strarray_exists( &delay_import_libs
, make
->importlib
);
2040 /*******************************************************************
2041 * add_unix_libraries
2043 static struct strarray
add_unix_libraries( const struct makefile
*make
, struct strarray
*deps
)
2045 struct strarray ret
= empty_strarray
;
2046 struct strarray all_libs
= empty_strarray
;
2049 if (strcmp( make
->unixlib
, "ntdll.so" )) strarray_add( &all_libs
, "-lntdll" );
2050 strarray_addall( &all_libs
, get_expanded_make_var_array( make
, "UNIX_LIBS" ));
2052 for (i
= 0; i
< all_libs
.count
; i
++)
2054 const char *lib
= NULL
;
2056 if (!strncmp( all_libs
.str
[i
], "-l", 2 ))
2058 for (j
= 0; j
< subdirs
.count
; j
++)
2060 if (make
== submakes
[j
]) continue;
2061 if ((lib
= get_native_unix_lib( submakes
[j
], all_libs
.str
[i
] + 2 ))) break;
2066 strarray_add( deps
, lib
);
2067 strarray_add( &ret
, lib
);
2069 else strarray_add( &ret
, all_libs
.str
[i
] );
2072 strarray_addall( &ret
, libs
);
2077 /*******************************************************************
2080 static int is_crt_module( const char *file
)
2082 return !strncmp( file
, "msvcr", 5 ) || !strncmp( file
, "ucrt", 4 ) || !strcmp( file
, "crtdll.dll" );
2086 /*******************************************************************
2089 static const char *get_default_crt( const struct makefile
*make
)
2091 if (!make
->use_msvcrt
) return NULL
;
2092 if (make
->module
&& is_crt_module( make
->module
)) return NULL
; /* don't add crt import to crt dlls */
2093 return !make
->testdll
&& (!make
->staticlib
|| make
->extlib
) ? "ucrtbase" : "msvcrt";
2097 /*******************************************************************
2100 static const char *get_crt_define( const struct makefile
*make
)
2102 const char *crt_dll
= NULL
;
2103 unsigned int i
, version
= 0;
2105 for (i
= 0; i
< make
->imports
.count
; i
++)
2107 if (!is_crt_module( make
->imports
.str
[i
] )) continue;
2108 if (crt_dll
) fatal_error( "More than one C runtime DLL imported: %s and %s\n",
2109 crt_dll
, make
->imports
.str
[i
] );
2110 crt_dll
= make
->imports
.str
[i
];
2115 if (strarray_exists( &make
->extradllflags
, "-nodefaultlibs" )) return "-D_MSVCR_VER=0";
2116 if (!(crt_dll
= get_default_crt( make
))) crt_dll
= make
->module
;
2118 if (!strncmp( crt_dll
, "ucrt", 4 )) return "-D_UCRT";
2119 sscanf( crt_dll
, "msvcr%u", &version
);
2120 return strmake( "-D_MSVCR_VER=%u", version
);
2124 /*******************************************************************
2125 * add_default_imports
2127 static struct strarray
add_default_imports( const struct makefile
*make
, struct strarray imports
)
2129 struct strarray ret
= empty_strarray
;
2130 const char *crt_dll
= get_default_crt( make
);
2133 for (i
= 0; i
< imports
.count
; i
++)
2135 if (is_crt_module( imports
.str
[i
] )) crt_dll
= imports
.str
[i
];
2136 else strarray_add( &ret
, imports
.str
[i
] );
2139 strarray_add( &ret
, "winecrt0" );
2140 if (crt_dll
) strarray_add( &ret
, crt_dll
);
2142 if (make
->is_win16
&& (!make
->importlib
|| strcmp( make
->importlib
, "kernel" )))
2143 strarray_add( &ret
, "kernel" );
2145 strarray_add( &ret
, "kernel32" );
2146 strarray_add( &ret
, "ntdll" );
2151 /*******************************************************************
2154 static struct strarray
add_import_libs( const struct makefile
*make
, struct strarray
*deps
,
2155 struct strarray imports
, int delay
, int is_cross
)
2157 struct strarray ret
= empty_strarray
;
2160 for (i
= 0; i
< imports
.count
; i
++)
2162 const char *name
= imports
.str
[i
];
2163 const char *lib
= NULL
;
2169 case 'L': strarray_add( &ret
, name
); continue;
2170 case 'l': name
+= 2; break;
2174 else name
= get_base_name( name
);
2176 for (j
= 0; j
< subdirs
.count
; j
++)
2178 if (submakes
[j
]->importlib
&& !strcmp( submakes
[j
]->importlib
, name
))
2179 lib
= obj_dir_path( submakes
[j
], strmake( "lib%s.a", name
));
2181 lib
= get_static_lib( submakes
[j
], name
);
2187 const char *ext
= NULL
;
2189 if (delay
&& !delay_load_flag
&& (is_cross
|| !*dll_ext
)) ext
= ".delay.a";
2190 else if (is_cross
) ext
= ".cross.a";
2191 if (ext
) lib
= replace_extension( lib
, ".a", ext
);
2192 strarray_add_uniq( deps
, lib
);
2193 strarray_add( &ret
, lib
);
2195 else strarray_add( &ret
, strmake( "-l%s", name
));
2201 /*******************************************************************
2204 static void add_install_rule( struct makefile
*make
, const char *target
,
2205 const char *file
, const char *dest
)
2207 if (strarray_exists( &make
->install_lib
, target
) ||
2208 strarray_exists( &top_install_lib
, make
->obj_dir
) ||
2209 strarray_exists( &top_install_lib
, obj_dir_path( make
, target
)))
2211 strarray_add( &make
->install_rules
[INSTALL_LIB
], file
);
2212 strarray_add( &make
->install_rules
[INSTALL_LIB
], dest
);
2214 else if (strarray_exists( &make
->install_dev
, target
) ||
2215 strarray_exists( &top_install_dev
, make
->obj_dir
) ||
2216 strarray_exists( &top_install_dev
, obj_dir_path( make
, target
)))
2218 strarray_add( &make
->install_rules
[INSTALL_DEV
], file
);
2219 strarray_add( &make
->install_rules
[INSTALL_DEV
], dest
);
2224 /*******************************************************************
2225 * get_include_install_path
2227 * Determine the installation path for a given include file.
2229 static const char *get_include_install_path( const char *name
)
2231 if (!strncmp( name
, "wine/", 5 )) return name
+ 5;
2232 if (!strncmp( name
, "msvcrt/", 7 )) return name
;
2233 return strmake( "windows/%s", name
);
2237 /*******************************************************************
2238 * get_shared_library_name
2240 * Determine possible names for a shared library with a version number.
2242 static struct strarray
get_shared_lib_names( const char *libname
)
2244 struct strarray ret
= empty_strarray
;
2245 const char *ext
, *p
;
2246 char *name
, *first
, *second
;
2249 strarray_add( &ret
, libname
);
2251 for (p
= libname
; (p
= strchr( p
, '.' )); p
++)
2252 if ((len
= strspn( p
+ 1, "0123456789." ))) break;
2254 if (!len
) return ret
;
2256 if (*ext
&& ext
[-1] == '.') ext
--;
2258 /* keep only the first group of digits */
2259 name
= xstrdup( libname
);
2260 first
= name
+ (p
- libname
);
2261 if ((second
= strchr( first
+ 1, '.' )))
2263 strcpy( second
, ext
);
2264 strarray_add( &ret
, xstrdup( name
));
2270 /*******************************************************************
2271 * get_source_defines
2273 static struct strarray
get_source_defines( struct makefile
*make
, struct incl_file
*source
,
2277 struct strarray ret
= empty_strarray
;
2279 strarray_addall( &ret
, make
->include_args
);
2280 if (source
->use_msvcrt
)
2282 strarray_add( &ret
, strmake( "-I%s", root_src_dir_path( "include/msvcrt" )));
2283 for (i
= 0; i
< make
->include_paths
.count
; i
++)
2284 strarray_add( &ret
, strmake( "-I%s", make
->include_paths
.str
[i
] ));
2286 strarray_addall( &ret
, make
->define_args
);
2287 strarray_addall( &ret
, get_expanded_file_local_var( make
, obj
, "EXTRADEFS" ));
2288 if ((source
->file
->flags
& FLAG_C_UNIX
) && *dll_ext
) strarray_add( &ret
, "-DWINE_UNIX_LIB" );
2293 /*******************************************************************
2294 * remove_warning_flags
2296 static struct strarray
remove_warning_flags( struct strarray flags
)
2299 struct strarray ret
= empty_strarray
;
2301 for (i
= 0; i
< flags
.count
; i
++)
2302 if (strncmp( flags
.str
[i
], "-W", 2 ) || !strncmp( flags
.str
[i
], "-Wno-", 5 ))
2303 strarray_add( &ret
, flags
.str
[i
] );
2308 /*******************************************************************
2311 static const char *get_debug_file( struct makefile
*make
, const char *name
)
2313 const char *debug_file
= NULL
;
2314 if (!make
->is_cross
|| !crossdebug
) return NULL
;
2315 if (!strcmp( crossdebug
, "pdb" )) debug_file
= strmake( "%s.pdb", get_base_name( name
));
2316 else if(!strncmp( crossdebug
, "split", 5 )) debug_file
= strmake( "%s.debug", name
);
2317 if (debug_file
) strarray_add( &make
->debug_files
, debug_file
);
2322 /*******************************************************************
2325 static const char *cmd_prefix( const char *cmd
)
2327 if (!silent_rules
) return "";
2328 return strmake( "$(quiet_%s)", cmd
);
2332 /*******************************************************************
2333 * output_winegcc_command
2335 static void output_winegcc_command( struct makefile
*make
, int is_cross
)
2337 output( "\t%s%s -o $@", cmd_prefix( "CCLD" ), tools_path( make
, "winegcc" ));
2338 output_filename( "--wine-objdir ." );
2341 output_filename( "--winebuild" );
2342 output_filename( tools_path( make
, "winebuild" ));
2346 output_filename( "-b" );
2347 output_filename( crosstarget
);
2348 output_filename( "--lib-suffix=.cross.a" );
2352 output_filenames( target_flags
);
2353 output_filenames( lddll_flags
);
2358 /*******************************************************************
2359 * output_symlink_rule
2361 * Output a rule to create a symlink.
2363 static void output_symlink_rule( const char *src_name
, const char *link_name
, int create_dir
)
2365 const char *name
= strrchr( link_name
, '/' );
2370 dir
= xstrdup( link_name
);
2371 dir
[name
- link_name
] = 0;
2374 output( "\t%s", cmd_prefix( "LN" ));
2375 if (create_dir
&& dir
&& *dir
) output( "%s -d %s && ", root_src_dir_path( "tools/install-sh" ), dir
);
2376 output( "rm -f %s && ", link_name
);
2378 /* dest path with a directory needs special handling if ln -s isn't supported */
2379 if (dir
&& strcmp( ln_s
, "ln -s" ))
2380 output( "cd %s && %s %s %s\n", *dir
? dir
: "/", ln_s
, src_name
, name
+ 1 );
2382 output( "%s %s %s\n", ln_s
, src_name
, link_name
);
2388 /*******************************************************************
2389 * output_srcdir_symlink
2391 * Output rule to create a symlink back to the source directory, for source files
2392 * that are needed at run-time.
2394 static void output_srcdir_symlink( struct makefile
*make
, const char *obj
)
2396 char *src_file
, *dst_file
, *src_name
;
2398 if (!make
->src_dir
) return;
2399 src_file
= src_dir_path( make
, obj
);
2400 dst_file
= obj_dir_path( make
, obj
);
2401 output( "%s: %s\n", dst_file
, src_file
);
2403 src_name
= src_file
;
2404 if (src_name
[0] != '/' && make
->obj_dir
)
2405 src_name
= concat_paths( get_relative_path( make
->obj_dir
, "" ), src_name
);
2407 output_symlink_rule( src_name
, dst_file
, 0 );
2408 strarray_add( &make
->all_targets
, obj
);
2412 /*******************************************************************
2413 * output_install_commands
2415 static void output_install_commands( struct makefile
*make
, struct strarray files
)
2418 char *install_sh
= root_src_dir_path( "tools/install-sh" );
2420 for (i
= 0; i
< files
.count
; i
+= 2)
2422 const char *file
= files
.str
[i
];
2423 const char *dest
= strmake( "$(DESTDIR)%s", files
.str
[i
+ 1] + 1 );
2425 switch (*files
.str
[i
+ 1])
2427 case 'c': /* cross-compiled program */
2428 output( "\tSTRIPPROG=%s-strip %s -m 644 $(INSTALL_PROGRAM_FLAGS) %s %s\n",
2429 crosstarget
, install_sh
, obj_dir_path( make
, file
), dest
);
2430 output( "\t%s --builtin %s\n", tools_path( make
, "winebuild" ), dest
);
2432 case 'd': /* data file */
2433 output( "\t%s -m 644 $(INSTALL_DATA_FLAGS) %s %s\n",
2434 install_sh
, obj_dir_path( make
, file
), dest
);
2436 case 'D': /* data file in source dir */
2437 output( "\t%s -m 644 $(INSTALL_DATA_FLAGS) %s %s\n",
2438 install_sh
, src_dir_path( make
, file
), dest
);
2440 case 'p': /* program file */
2441 output( "\tSTRIPPROG=\"$(STRIP)\" %s $(INSTALL_PROGRAM_FLAGS) %s %s\n",
2442 install_sh
, obj_dir_path( make
, file
), dest
);
2444 case 's': /* script */
2445 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s %s\n",
2446 install_sh
, obj_dir_path( make
, file
), dest
);
2448 case 'S': /* script in source dir */
2449 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s %s\n",
2450 install_sh
, src_dir_path( make
, file
), dest
);
2452 case 't': /* script in tools dir */
2453 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s %s\n",
2454 install_sh
, tools_dir_path( make
, files
.str
[i
] ), dest
);
2456 case 'y': /* symlink */
2457 output_symlink_rule( files
.str
[i
], dest
, 1 );
2462 strarray_add( &make
->uninstall_files
, dest
);
2467 /*******************************************************************
2468 * output_install_rules
2470 * Rules are stored as a (file,dest) pair of values.
2471 * The first char of dest indicates the type of install.
2473 static void output_install_rules( struct makefile
*make
, enum install_rules rules
, const char *target
)
2476 struct strarray files
= make
->install_rules
[rules
];
2477 struct strarray targets
= empty_strarray
;
2479 if (!files
.count
) return;
2481 for (i
= 0; i
< files
.count
; i
+= 2)
2483 const char *file
= files
.str
[i
];
2484 switch (*files
.str
[i
+ 1])
2486 case 'c': /* cross-compiled program */
2487 case 'd': /* data file */
2488 case 'p': /* program file */
2489 case 's': /* script */
2490 strarray_add_uniq( &targets
, obj_dir_path( make
, file
));
2492 case 't': /* script in tools dir */
2493 strarray_add_uniq( &targets
, tools_dir_path( make
, file
));
2498 output( "%s %s::", obj_dir_path( make
, "install" ), obj_dir_path( make
, target
));
2499 output_filenames( targets
);
2501 output_install_commands( make
, files
);
2502 strarray_add_uniq( &make
->phony_targets
, obj_dir_path( make
, "install" ));
2503 strarray_add_uniq( &make
->phony_targets
, obj_dir_path( make
, target
));
2507 static int cmp_string_length( const char **a
, const char **b
)
2509 int paths_a
= 0, paths_b
= 0;
2512 for (p
= *a
; *p
; p
++) if (*p
== '/') paths_a
++;
2513 for (p
= *b
; *p
; p
++) if (*p
== '/') paths_b
++;
2514 if (paths_b
!= paths_a
) return paths_b
- paths_a
;
2515 return strcmp( *a
, *b
);
2518 /*******************************************************************
2519 * output_uninstall_rules
2521 static void output_uninstall_rules( struct makefile
*make
)
2523 static const char *dirs_order
[] =
2524 { "$(includedir)", "$(mandir)", "$(fontdir)", "$(nlsdir)", "$(datadir)", "$(dlldir)" };
2526 struct strarray uninstall_dirs
= empty_strarray
;
2529 if (!make
->uninstall_files
.count
) return;
2530 output( "uninstall::\n" );
2531 output_rm_filenames( make
->uninstall_files
);
2532 strarray_add_uniq( &make
->phony_targets
, "uninstall" );
2534 if (!subdirs
.count
) return;
2535 for (i
= 0; i
< make
->uninstall_files
.count
; i
++)
2537 char *dir
= xstrdup( make
->uninstall_files
.str
[i
] );
2538 while (strchr( dir
, '/' ))
2540 *strrchr( dir
, '/' ) = 0;
2541 strarray_add_uniq( &uninstall_dirs
, xstrdup(dir
) );
2544 strarray_qsort( &uninstall_dirs
, cmp_string_length
);
2545 output( "\t-rmdir" );
2546 for (i
= 0; i
< sizeof(dirs_order
)/sizeof(dirs_order
[0]); i
++)
2548 for (j
= 0; j
< uninstall_dirs
.count
; j
++)
2550 if (!uninstall_dirs
.str
[j
]) continue;
2551 if (strncmp( uninstall_dirs
.str
[j
] + strlen("$(DESTDIR)"), dirs_order
[i
], strlen(dirs_order
[i
]) ))
2553 output_filename( uninstall_dirs
.str
[j
] );
2554 uninstall_dirs
.str
[j
] = NULL
;
2557 for (j
= 0; j
< uninstall_dirs
.count
; j
++)
2558 if (uninstall_dirs
.str
[j
]) output_filename( uninstall_dirs
.str
[j
] );
2563 /*******************************************************************
2566 static void output_po_files( struct makefile
*make
)
2568 const char *po_dir
= src_dir_path( make
, "po" );
2573 for (i
= 0; i
< linguas
.count
; i
++)
2574 output_filename( strmake( "%s/%s.po", po_dir
, linguas
.str
[i
] ));
2575 output( ": %s/wine.pot\n", po_dir
);
2576 output( "\t%smsgmerge --previous -q $@ %s/wine.pot | msgattrib --no-obsolete -o $@.new && mv $@.new $@\n",
2577 cmd_prefix( "MSG" ), po_dir
);
2578 output( "po/all:" );
2579 for (i
= 0; i
< linguas
.count
; i
++)
2580 output_filename( strmake( "%s/%s.po", po_dir
, linguas
.str
[i
] ));
2583 output( "%s/wine.pot:", po_dir
);
2584 output_filenames( make
->pot_files
);
2586 output( "\t%smsgcat -o $@", cmd_prefix( "MSG" ));
2587 output_filenames( make
->pot_files
);
2589 strarray_add( &make
->maintainerclean_files
, strmake( "%s/wine.pot", po_dir
));
2593 /*******************************************************************
2596 static void output_source_y( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2598 /* add source file dependency for parallel makes */
2599 char *header
= strmake( "%s.tab.h", obj
);
2601 if (find_include_file( make
, header
))
2603 output( "%s: %s\n", obj_dir_path( make
, header
), source
->filename
);
2604 output( "\t%s%s -o %s.tab.c -d %s\n",
2605 cmd_prefix( "BISON" ), bison
, obj_dir_path( make
, obj
), source
->filename
);
2606 output( "%s.tab.c: %s %s\n", obj_dir_path( make
, obj
),
2607 source
->filename
, obj_dir_path( make
, header
));
2608 strarray_add( &make
->clean_files
, header
);
2610 else output( "%s.tab.c: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2612 output( "\t%s%s -o $@ %s\n", cmd_prefix( "BISON" ), bison
, source
->filename
);
2616 /*******************************************************************
2619 static void output_source_l( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2621 output( "%s.yy.c: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2622 output( "\t%s%s -o$@ %s\n", cmd_prefix( "FLEX" ), flex
, source
->filename
);
2626 /*******************************************************************
2629 static void output_source_h( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2631 if (source
->file
->flags
& FLAG_GENERATED
)
2632 strarray_add( &make
->all_targets
, source
->name
);
2634 add_install_rule( make
, source
->name
, source
->name
,
2635 strmake( "D$(includedir)/wine/%s", get_include_install_path( source
->name
) ));
2639 /*******************************************************************
2642 static void output_source_rc( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2644 struct strarray defines
= get_source_defines( make
, source
, obj
);
2645 const char *po_dir
= NULL
;
2648 if (source
->file
->flags
& FLAG_GENERATED
) strarray_add( &make
->clean_files
, source
->name
);
2649 if (linguas
.count
&& (source
->file
->flags
& FLAG_RC_PO
)) po_dir
= "po";
2650 strarray_add( &make
->res_files
, strmake( "%s.res", obj
));
2651 if (source
->file
->flags
& FLAG_RC_PO
)
2653 strarray_add( &make
->pot_files
, strmake( "%s.pot", obj
));
2654 output( "%s.pot ", obj_dir_path( make
, obj
) );
2656 output( "%s.res: %s", obj_dir_path( make
, obj
), source
->filename
);
2657 output_filename( tools_path( make
, "wrc" ));
2658 if (make
->src_dir
) output_filename( "nls/locale.nls" );
2659 output_filenames( source
->dependencies
);
2661 output( "\t%s%s -u -o $@", cmd_prefix( "WRC" ), tools_path( make
, "wrc" ) );
2662 if (make
->is_win16
) output_filename( "-m16" );
2663 output_filename( "--nostdinc" );
2664 if (po_dir
) output_filename( strmake( "--po-dir=%s", po_dir
));
2665 output_filenames( defines
);
2666 output_filename( source
->filename
);
2670 output( "%s.res:", obj_dir_path( make
, obj
));
2671 for (i
= 0; i
< linguas
.count
; i
++)
2672 output_filename( strmake( "%s/%s.mo", po_dir
, linguas
.str
[i
] ));
2678 /*******************************************************************
2681 static void output_source_mc( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2684 char *obj_path
= obj_dir_path( make
, obj
);
2686 strarray_add( &make
->res_files
, strmake( "%s.res", obj
));
2687 strarray_add( &make
->pot_files
, strmake( "%s.pot", obj
));
2688 output( "%s.pot %s.res: %s", obj_path
, obj_path
, source
->filename
);
2689 output_filename( tools_path( make
, "wmc" ));
2690 output_filenames( source
->dependencies
);
2692 output( "\t%s%s -u -o $@ %s", cmd_prefix( "WMC" ), tools_path( make
, "wmc" ), source
->filename
);
2695 output_filename( "--po-dir=po" );
2697 output( "%s.res:", obj_dir_path( make
, obj
));
2698 for (i
= 0; i
< linguas
.count
; i
++)
2699 output_filename( strmake( "po/%s.mo", linguas
.str
[i
] ));
2705 /*******************************************************************
2708 static void output_source_res( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2710 strarray_add( &make
->res_files
, source
->name
);
2714 /*******************************************************************
2717 static void output_source_idl( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2719 struct strarray defines
= get_source_defines( make
, source
, obj
);
2720 struct strarray targets
= empty_strarray
;
2724 if (!source
->file
->flags
) source
->file
->flags
|= FLAG_IDL_HEADER
| FLAG_INSTALL
;
2725 if (find_include_file( make
, strmake( "%s.h", obj
))) source
->file
->flags
|= FLAG_IDL_HEADER
;
2727 for (i
= 0; i
< sizeof(idl_outputs
) / sizeof(idl_outputs
[0]); i
++)
2729 if (!(source
->file
->flags
& idl_outputs
[i
].flag
)) continue;
2730 dest
= strmake( "%s%s", obj
, idl_outputs
[i
].ext
);
2731 if (!find_src_file( make
, dest
)) strarray_add( &make
->clean_files
, dest
);
2732 strarray_add( &targets
, dest
);
2734 if (source
->file
->flags
& FLAG_IDL_PROXY
) strarray_add( &make
->dlldata_files
, source
->name
);
2735 if (source
->file
->flags
& FLAG_INSTALL
)
2737 add_install_rule( make
, source
->name
, xstrdup( source
->name
),
2738 strmake( "D$(includedir)/wine/%s.idl", get_include_install_path( obj
) ));
2739 if (source
->file
->flags
& FLAG_IDL_HEADER
)
2740 add_install_rule( make
, source
->name
, strmake( "%s.h", obj
),
2741 strmake( "d$(includedir)/wine/%s.h", get_include_install_path( obj
) ));
2743 if (!targets
.count
) return;
2745 output_filenames_obj_dir( make
, targets
);
2746 output( ": %s\n", tools_path( make
, "widl" ));
2747 output( "\t%s%s -o $@", cmd_prefix( "WIDL" ), tools_path( make
, "widl" ) );
2748 output_filenames( target_flags
);
2749 output_filename( "--nostdinc" );
2750 output_filename( "-Ldlls/\\*" );
2751 output_filenames( defines
);
2752 output_filenames( get_expanded_make_var_array( make
, "EXTRAIDLFLAGS" ));
2753 output_filenames( get_expanded_file_local_var( make
, obj
, "EXTRAIDLFLAGS" ));
2754 output_filename( source
->filename
);
2756 output_filenames_obj_dir( make
, targets
);
2757 output( ": %s", source
->filename
);
2758 output_filenames( source
->dependencies
);
2759 for (i
= 0; i
< source
->importlibdeps
.count
; i
++)
2761 struct makefile
*submake
= find_importlib_module( source
->importlibdeps
.str
[i
] );
2762 output_filename( obj_dir_path( submake
, submake
->module
));
2768 /*******************************************************************
2771 static void output_source_x( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2773 output( "%s.h: %s%s %s\n", obj_dir_path( make
, obj
),
2774 tools_dir_path( make
, "make_xftmpl" ), tools_ext
, source
->filename
);
2775 output( "\t%s%s%s -H -o $@ %s\n", cmd_prefix( "GEN" ),
2776 tools_dir_path( make
, "make_xftmpl" ), tools_ext
, source
->filename
);
2777 if (source
->file
->flags
& FLAG_INSTALL
)
2779 add_install_rule( make
, source
->name
, source
->name
,
2780 strmake( "D$(includedir)/wine/%s", get_include_install_path( source
->name
) ));
2781 add_install_rule( make
, source
->name
, strmake( "%s.h", obj
),
2782 strmake( "d$(includedir)/wine/%s.h", get_include_install_path( obj
) ));
2787 /*******************************************************************
2790 static void output_source_sfd( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2793 char *ttf_obj
= strmake( "%s.ttf", obj
);
2794 char *ttf_file
= src_dir_path( make
, ttf_obj
);
2796 if (fontforge
&& !make
->src_dir
)
2798 output( "%s: %s\n", ttf_file
, source
->filename
);
2799 output( "\t%s%s -script %s %s $@\n", cmd_prefix( "GEN" ),
2800 fontforge
, root_src_dir_path( "fonts/genttf.ff" ), source
->filename
);
2801 if (!(source
->file
->flags
& FLAG_SFD_FONTS
)) strarray_add( &make
->font_files
, ttf_obj
);
2802 strarray_add( &make
->maintainerclean_files
, ttf_obj
);
2804 if (source
->file
->flags
& FLAG_INSTALL
)
2806 add_install_rule( make
, source
->name
, ttf_obj
, strmake( "D$(fontdir)/%s", ttf_obj
));
2807 output_srcdir_symlink( make
, ttf_obj
);
2810 if (source
->file
->flags
& FLAG_SFD_FONTS
)
2812 struct strarray
*array
= source
->file
->args
;
2814 for (i
= 0; i
< array
->count
; i
++)
2816 char *font
= strtok( xstrdup(array
->str
[i
]), " \t" );
2817 char *args
= strtok( NULL
, "" );
2819 strarray_add( &make
->all_targets
, xstrdup( font
));
2820 output( "%s: %s %s\n", obj_dir_path( make
, font
),
2821 tools_path( make
, "sfnt2fon" ), ttf_file
);
2822 output( "\t%s%s -q -o $@ %s %s\n", cmd_prefix( "GEN" ),
2823 tools_path( make
, "sfnt2fon" ), ttf_file
, args
);
2824 add_install_rule( make
, source
->name
, xstrdup(font
), strmake( "d$(fontdir)/%s", font
));
2830 /*******************************************************************
2833 static void output_source_svg( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2835 static const char * const images
[] = { "bmp", "cur", "ico", NULL
};
2838 if (convert
&& rsvg
&& icotool
)
2840 for (i
= 0; images
[i
]; i
++)
2841 if (find_include_file( make
, strmake( "%s.%s", obj
, images
[i
] ))) break;
2845 output( "%s.%s: %s\n", src_dir_path( make
, obj
), images
[i
], source
->filename
);
2846 output( "\t%sCONVERT=\"%s\" ICOTOOL=\"%s\" RSVG=\"%s\" %s %s $@\n",
2847 cmd_prefix( "GEN" ), convert
, icotool
, rsvg
,
2848 root_src_dir_path( "tools/buildimage" ), source
->filename
);
2849 strarray_add( &make
->maintainerclean_files
, strmake( "%s.%s", obj
, images
[i
] ));
2855 /*******************************************************************
2858 static void output_source_nls( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2860 add_install_rule( make
, source
->name
, source
->name
,
2861 strmake( "D$(nlsdir)/%s", source
->name
));
2862 output_srcdir_symlink( make
, strmake( "%s.nls", obj
));
2866 /*******************************************************************
2867 * output_source_desktop
2869 static void output_source_desktop( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2871 add_install_rule( make
, source
->name
, source
->name
,
2872 strmake( "D$(datadir)/applications/%s", source
->name
));
2876 /*******************************************************************
2879 static void output_source_po( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2881 output( "%s.mo: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2882 output( "\t%s%s -o $@ %s\n", cmd_prefix( "MSG" ), msgfmt
, source
->filename
);
2883 strarray_add( &make
->all_targets
, strmake( "%s.mo", obj
));
2887 /*******************************************************************
2890 static void output_source_in( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2894 if (strendswith( obj
, ".man" ) && source
->file
->args
)
2896 struct strarray symlinks
;
2897 char *dir
, *dest
= replace_extension( obj
, ".man", "" );
2898 char *lang
= strchr( dest
, '.' );
2899 char *section
= source
->file
->args
;
2903 dir
= strmake( "$(mandir)/%s/man%s", lang
, section
);
2905 else dir
= strmake( "$(mandir)/man%s", section
);
2906 add_install_rule( make
, dest
, xstrdup(obj
), strmake( "d%s/%s.%s", dir
, dest
, section
));
2907 symlinks
= get_expanded_file_local_var( make
, dest
, "SYMLINKS" );
2908 for (i
= 0; i
< symlinks
.count
; i
++)
2909 add_install_rule( make
, symlinks
.str
[i
], strmake( "%s.%s", dest
, section
),
2910 strmake( "y%s/%s.%s", dir
, symlinks
.str
[i
], section
));
2914 strarray_add( &make
->in_files
, xstrdup(obj
) );
2915 strarray_add( &make
->all_targets
, xstrdup(obj
) );
2916 output( "%s: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2917 output( "\t%s%s %s >$@ || (rm -f $@ && false)\n", cmd_prefix( "SED" ), sed_cmd
, source
->filename
);
2918 output( "%s:", obj_dir_path( make
, obj
));
2919 output_filenames( source
->dependencies
);
2921 add_install_rule( make
, obj
, xstrdup( obj
), strmake( "d$(datadir)/wine/%s", obj
));
2925 /*******************************************************************
2926 * output_source_spec
2928 static void output_source_spec( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2930 struct strarray imports
= get_expanded_file_local_var( make
, obj
, "IMPORTS" );
2931 struct strarray dll_flags
= get_expanded_file_local_var( make
, obj
, "EXTRADLLFLAGS" );
2932 struct strarray all_libs
, dep_libs
= empty_strarray
;
2933 char *dll_name
, *obj_name
, *output_file
;
2934 const char *debug_file
;
2936 if (!imports
.count
) imports
= make
->imports
;
2937 if (!dll_flags
.count
) dll_flags
= make
->extradllflags
;
2938 if (!strarray_exists( &dll_flags
, "-nodefaultlibs" )) imports
= add_default_imports( make
, imports
);
2940 all_libs
= add_import_libs( make
, &dep_libs
, imports
, 0, make
->is_cross
);
2941 dll_name
= strmake( "%s.dll%s", obj
, make
->is_cross
? "" : dll_ext
);
2942 obj_name
= strmake( "%s%s", obj_dir_path( make
, obj
), make
->is_cross
? ".cross.o" : ".o" );
2943 output_file
= obj_dir_path( make
, dll_name
);
2945 strarray_add( &make
->clean_files
, dll_name
);
2946 strarray_add( &make
->res_files
, strmake( "%s.res", obj
));
2947 output( "%s.res:", obj_dir_path( make
, obj
));
2948 output_filename( obj_dir_path( make
, dll_name
));
2949 output_filename( tools_path( make
, "wrc" ));
2951 output( "\t%secho \"%s.dll TESTDLL \\\"%s\\\"\" | %s -u -o $@\n", cmd_prefix( "WRC" ), obj
, output_file
,
2952 tools_path( make
, "wrc" ));
2954 output( "%s:", output_file
);
2955 output_filename( source
->filename
);
2956 output_filename( obj_name
);
2957 output_filenames( dep_libs
);
2958 output_filename( tools_path( make
, "winebuild" ));
2959 output_filename( tools_path( make
, "winegcc" ));
2961 output_winegcc_command( make
, make
->is_cross
);
2962 output_filename( "-s" );
2963 output_filenames( dll_flags
);
2964 output_filename( "-shared" );
2965 output_filename( source
->filename
);
2966 output_filename( obj_name
);
2967 if ((debug_file
= get_debug_file( make
, dll_name
)))
2968 output_filename( strmake( "-Wl,--debug-file,%s", obj_dir_path( make
, debug_file
)));
2969 output_filenames( all_libs
);
2970 output_filename( make
->is_cross
? "$(CROSSLDFLAGS)" : "$(LDFLAGS)" );
2975 /*******************************************************************
2976 * output_source_default
2978 static void output_source_default( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2980 struct strarray defines
= get_source_defines( make
, source
, obj
);
2981 int is_dll_src
= (make
->testdll
&&
2982 strendswith( source
->name
, ".c" ) &&
2983 find_src_file( make
, replace_extension( source
->name
, ".c", ".spec" )));
2984 int need_cross
= (crosstarget
&&
2985 !(source
->file
->flags
& FLAG_C_UNIX
) &&
2986 (make
->is_cross
|| make
->staticlib
||
2987 (source
->file
->flags
& FLAG_C_IMPLIB
)));
2988 int need_obj
= ((*dll_ext
|| !(source
->file
->flags
& FLAG_C_UNIX
)) &&
2990 (source
->file
->flags
& FLAG_C_IMPLIB
) ||
2991 (make
->staticlib
&& !make
->extlib
)));
2993 if ((source
->file
->flags
& FLAG_GENERATED
) &&
2994 (!make
->testdll
|| !strendswith( source
->filename
, "testlist.c" )))
2995 strarray_add( &make
->clean_files
, source
->basename
);
2999 if ((source
->file
->flags
& FLAG_C_UNIX
) && *dll_ext
)
3000 strarray_add( &make
->unixobj_files
, strmake( "%s.o", obj
));
3001 else if (source
->file
->flags
& FLAG_C_IMPLIB
)
3002 strarray_add( &make
->implib_files
, strmake( "%s.o", obj
));
3003 else if (!is_dll_src
)
3004 strarray_add( &make
->object_files
, strmake( "%s.o", obj
));
3006 strarray_add( &make
->clean_files
, strmake( "%s.o", obj
));
3007 output( "%s.o: %s\n", obj_dir_path( make
, obj
), source
->filename
);
3008 output( "\t%s$(CC) -c -o $@ %s", cmd_prefix( "CC" ), source
->filename
);
3009 output_filenames( defines
);
3010 if (!source
->use_msvcrt
) output_filenames( make
->unix_cflags
);
3011 output_filenames( make
->extlib
? extra_cflags_extlib
: extra_cflags
);
3012 if (make
->sharedlib
|| (source
->file
->flags
& FLAG_C_UNIX
))
3014 output_filenames( unix_dllflags
);
3016 else if (make
->module
|| make
->testdll
)
3018 output_filenames( dll_flags
);
3019 if (source
->use_msvcrt
) output_filenames( msvcrt_flags
);
3020 if (!*dll_ext
&& make
->module
&& is_crt_module( make
->module
))
3021 output_filename( "-fno-builtin" );
3023 output_filenames( cpp_flags
);
3024 output_filename( "$(CFLAGS)" );
3029 if (source
->file
->flags
& FLAG_C_IMPLIB
)
3030 strarray_add( &make
->crossimplib_files
, strmake( "%s.cross.o", obj
));
3031 else if (!is_dll_src
)
3032 strarray_add( &make
->crossobj_files
, strmake( "%s.cross.o", obj
));
3034 strarray_add( &make
->clean_files
, strmake( "%s.cross.o", obj
));
3035 output( "%s.cross.o: %s\n", obj_dir_path( make
, obj
), source
->filename
);
3036 output( "\t%s$(CROSSCC) -c -o $@ %s", cmd_prefix( "CC" ), source
->filename
);
3037 output_filenames( defines
);
3038 output_filenames( make
->extlib
? extra_cross_cflags_extlib
: extra_cross_cflags
);
3039 if (make
->module
&& is_crt_module( make
->module
))
3040 output_filename( "-fno-builtin" );
3041 /* force -Wformat when using 'long' types, until all modules have been converted
3042 * and we can remove -Wno-format */
3043 if (!make
->extlib
&& strarray_exists( &extra_cross_cflags
, "-Wno-format" ) &&
3044 !strarray_exists( &defines
, "-DWINE_NO_LONG_TYPES" ))
3045 output_filename( "-Wformat" );
3046 output_filenames( cpp_flags
);
3047 output_filename( "$(CROSSCFLAGS)" );
3050 if (make
->testdll
&& !is_dll_src
&& strendswith( source
->name
, ".c" ) &&
3051 !(source
->file
->flags
& FLAG_GENERATED
))
3053 strarray_add( &make
->test_files
, obj
);
3054 strarray_add( &make
->ok_files
, strmake( "%s.ok", obj
));
3055 output( "%s.ok:\n", obj_dir_path( make
, obj
));
3056 output( "\t%s%s $(RUNTESTFLAGS) -T . -M %s -p %s%s %s && touch $@\n",
3057 cmd_prefix( "TEST" ),
3058 root_src_dir_path( "tools/runtest" ), make
->testdll
,
3059 obj_dir_path( make
, replace_extension( make
->testdll
, ".dll", "_test.exe" )),
3060 make
->is_cross
? "" : dll_ext
, obj
);
3062 if (need_obj
) output_filename( strmake( "%s.o", obj_dir_path( make
, obj
)));
3063 if (need_cross
) output_filename( strmake( "%s.cross.o", obj_dir_path( make
, obj
)));
3065 output_filenames( source
->dependencies
);
3070 /* dispatch table to output rules for a single source file */
3074 void (*fn
)( struct makefile
*make
, struct incl_file
*source
, const char *obj
);
3075 } output_source_funcs
[] =
3077 { "y", output_source_y
},
3078 { "l", output_source_l
},
3079 { "h", output_source_h
},
3080 { "rh", output_source_h
},
3081 { "inl", output_source_h
},
3082 { "rc", output_source_rc
},
3083 { "mc", output_source_mc
},
3084 { "res", output_source_res
},
3085 { "idl", output_source_idl
},
3086 { "sfd", output_source_sfd
},
3087 { "svg", output_source_svg
},
3088 { "nls", output_source_nls
},
3089 { "desktop", output_source_desktop
},
3090 { "po", output_source_po
},
3091 { "in", output_source_in
},
3092 { "x", output_source_x
},
3093 { "spec", output_source_spec
},
3094 { NULL
, output_source_default
}
3098 /*******************************************************************
3101 static char *get_unix_lib_name( struct makefile
*make
)
3103 struct incl_file
*source
;
3105 if (!*dll_ext
) return NULL
;
3106 LIST_FOR_EACH_ENTRY( source
, &make
->sources
, struct incl_file
, entry
)
3108 if (!(source
->file
->flags
& FLAG_C_UNIX
)) continue;
3109 return strmake( "%s%s", get_base_name( make
->module
), dll_ext
);
3115 /*******************************************************************
3118 static void output_module( struct makefile
*make
)
3120 struct strarray all_libs
= empty_strarray
;
3121 struct strarray dep_libs
= empty_strarray
;
3122 struct strarray imports
= make
->imports
;
3123 const char *module_name
= make
->module
;
3124 const char *debug_file
;
3125 const char *delay_load
= delay_load_flag
;
3126 char *spec_file
= NULL
;
3129 if (!make
->is_exe
) spec_file
= src_dir_path( make
, replace_extension( make
->module
, ".dll", ".spec" ));
3131 if (!make
->data_only
)
3133 if (*dll_ext
&& !make
->is_cross
&& !make
->data_only
)
3134 module_name
= strmake( "%s%s", make
->module
, dll_ext
);
3136 if (!strarray_exists( &make
->extradllflags
, "-nodefaultlibs" ))
3137 imports
= add_default_imports( make
, imports
);
3139 strarray_addall( &all_libs
, add_import_libs( make
, &dep_libs
, make
->delayimports
, 1, make
->is_cross
));
3140 strarray_addall( &all_libs
, add_import_libs( make
, &dep_libs
, imports
, 0, make
->is_cross
));
3142 if (!make
->use_msvcrt
)
3144 strarray_addall( &all_libs
, get_expanded_make_var_array( make
, "UNIX_LIBS" ));
3145 strarray_addall( &all_libs
, libs
);
3148 if (!make
->is_cross
&& *dll_ext
) delay_load
= "-Wl,-delayload,";
3151 for (i
= 0; i
< make
->delayimports
.count
; i
++)
3152 strarray_add( &all_libs
, strmake( "%s%s%s", delay_load
, make
->delayimports
.str
[i
],
3153 strchr( make
->delayimports
.str
[i
], '.' ) ? "" : ".dll" ));
3156 strarray_add( &make
->all_targets
, module_name
);
3158 if (make
->data_only
)
3159 add_install_rule( make
, make
->module
, module_name
,
3160 strmake( "d%s/%s", *dll_ext
? pe_dir
: "$(dlldir)", module_name
));
3161 else if (make
->is_cross
)
3162 add_install_rule( make
, make
->module
, module_name
, strmake( "c%s/%s", pe_dir
, module_name
));
3164 add_install_rule( make
, make
->module
, module_name
, strmake( "p%s/%s", so_dir
, module_name
));
3166 add_install_rule( make
, make
->module
, module_name
,
3167 strmake( "p$(%s)/%s", spec_file
? "dlldir" : "bindir", module_name
));
3169 output( "%s:", obj_dir_path( make
, module_name
));
3170 if (spec_file
) output_filename( spec_file
);
3171 output_filenames_obj_dir( make
, make
->is_cross
? make
->crossobj_files
: make
->object_files
);
3172 output_filenames_obj_dir( make
, make
->res_files
);
3173 output_filenames( dep_libs
);
3174 output_filename( tools_path( make
, "winebuild" ));
3175 output_filename( tools_path( make
, "winegcc" ));
3177 output_winegcc_command( make
, make
->is_cross
);
3178 if (make
->is_cross
) output_filename( "-Wl,--wine-builtin" );
3181 output_filename( "-shared" );
3182 output_filename( spec_file
);
3184 output_filenames( make
->extradllflags
);
3185 output_filenames_obj_dir( make
, make
->is_cross
? make
->crossobj_files
: make
->object_files
);
3186 output_filenames_obj_dir( make
, make
->res_files
);
3187 debug_file
= get_debug_file( make
, make
->module
);
3188 if (debug_file
) output_filename( strmake( "-Wl,--debug-file,%s", obj_dir_path( make
, debug_file
)));
3189 output_filenames( all_libs
);
3190 output_filename( make
->is_cross
? "$(CROSSLDFLAGS)" : "$(LDFLAGS)" );
3193 if (*dll_ext
&& make
->is_exe
&& !make
->is_win16
&& strendswith( make
->module
, ".exe" ))
3195 char *binary
= replace_extension( make
->module
, ".exe", "" );
3196 add_install_rule( make
, binary
, "wineapploader", strmake( "t$(bindir)/%s", binary
));
3201 /*******************************************************************
3202 * output_fake_module
3204 static void output_fake_module( struct makefile
*make
)
3206 char *spec_file
= NULL
;
3208 if (!make
->is_exe
) spec_file
= src_dir_path( make
, replace_extension( make
->module
, ".dll", ".spec" ));
3210 strarray_add( &make
->all_targets
, make
->module
);
3211 add_install_rule( make
, make
->module
, make
->module
, strmake( "d%s/%s", pe_dir
, make
->module
));
3213 output( "%s:", obj_dir_path( make
, make
->module
));
3214 if (spec_file
) output_filename( spec_file
);
3215 output_filenames_obj_dir( make
, make
->res_files
);
3216 output_filename( tools_path( make
, "winebuild" ));
3217 output_filename( tools_path( make
, "winegcc" ));
3219 output_winegcc_command( make
, make
->is_cross
);
3220 output_filename( "-Wb,--fake-module" );
3223 output_filename( "-shared" );
3224 output_filename( spec_file
);
3226 output_filenames( make
->extradllflags
);
3227 output_filenames_obj_dir( make
, make
->res_files
);
3232 /*******************************************************************
3235 static void output_import_lib( struct makefile
*make
)
3237 char *spec_file
= src_dir_path( make
, replace_extension( make
->module
, ".dll", ".spec" ));
3238 char *importlib_path
= obj_dir_path( make
, strmake( "lib%s", make
->importlib
));
3240 strarray_add( &make
->clean_files
, strmake( "lib%s.a", make
->importlib
));
3241 if (!*dll_ext
&& needs_delay_lib( make
))
3243 strarray_add( &make
->clean_files
, strmake( "lib%s.delay.a", make
->importlib
));
3244 output( "%s.delay.a ", importlib_path
);
3246 output( "%s.a: %s %s", importlib_path
, tools_path( make
, "winebuild" ), spec_file
);
3247 output_filenames_obj_dir( make
, make
->implib_files
);
3249 output( "\t%s%s -w --implib -o $@", cmd_prefix( "BUILD" ), tools_path( make
, "winebuild" ) );
3250 output_filenames( target_flags
);
3251 if (make
->is_win16
) output_filename( "-m16" );
3252 output_filename( "--export" );
3253 output_filename( spec_file
);
3254 output_filenames_obj_dir( make
, make
->implib_files
);
3256 add_install_rule( make
, make
->importlib
,
3257 strmake( "lib%s.a", make
->importlib
),
3258 strmake( "d%s/lib%s.a", so_dir
, make
->importlib
));
3262 strarray_add( &make
->clean_files
, strmake( "lib%s.cross.a", make
->importlib
));
3263 output_filename( strmake( "%s.cross.a", importlib_path
));
3264 if (needs_delay_lib( make
))
3266 strarray_add( &make
->clean_files
, strmake( "lib%s.delay.a", make
->importlib
));
3267 output_filename( strmake( "%s.delay.a", importlib_path
));
3269 output( ": %s %s", tools_path( make
, "winebuild" ), spec_file
);
3270 output_filenames_obj_dir( make
, make
->crossimplib_files
);
3272 output( "\t%s%s -b %s -w --implib -o $@", cmd_prefix( "BUILD" ),
3273 tools_path( make
, "winebuild" ), crosstarget
);
3274 if (make
->is_win16
) output_filename( "-m16" );
3275 output_filename( "--export" );
3276 output_filename( spec_file
);
3277 output_filenames_obj_dir( make
, make
->crossimplib_files
);
3279 add_install_rule( make
, make
->importlib
,
3280 strmake( "lib%s.cross.a", make
->importlib
),
3281 strmake( "d%s/lib%s.a", pe_dir
, make
->importlib
));
3286 /*******************************************************************
3289 static void output_unix_lib( struct makefile
*make
)
3291 struct strarray unix_libs
= empty_strarray
;
3292 struct strarray unix_deps
= empty_strarray
;
3293 char *spec_file
= src_dir_path( make
, replace_extension( make
->module
, ".dll", ".spec" ));
3295 if (!make
->native_unix_lib
)
3297 struct strarray unix_imports
= empty_strarray
;
3299 strarray_add( &unix_imports
, "ntdll" );
3300 strarray_add( &unix_deps
, obj_dir_path( top_makefile
, "dlls/ntdll/ntdll.so" ));
3301 strarray_add( &unix_imports
, "winecrt0" );
3302 if (spec_file
) strarray_add( &unix_deps
, spec_file
);
3304 strarray_addall( &unix_libs
, add_import_libs( make
, &unix_deps
, unix_imports
, 0, 0 ));
3305 strarray_addall( &unix_libs
, get_expanded_make_var_array( make
, "UNIX_LIBS" ));
3306 strarray_addall( &unix_libs
, libs
);
3308 else unix_libs
= add_unix_libraries( make
, &unix_deps
);
3310 strarray_add( &make
->all_targets
, make
->unixlib
);
3311 add_install_rule( make
, make
->module
, make
->unixlib
, strmake( "p%s/%s", so_dir
, make
->unixlib
));
3312 output( "%s:", obj_dir_path( make
, make
->unixlib
));
3313 output_filenames_obj_dir( make
, make
->unixobj_files
);
3314 output_filenames( unix_deps
);
3316 if (make
->native_unix_lib
)
3319 output( "\t%s$(CC) -o $@", cmd_prefix( "CCLD" ));
3320 output_filenames( get_expanded_make_var_array( make
, "UNIXLDFLAGS" ));
3324 output_filename( tools_path( make
, "winebuild" ));
3325 output_filename( tools_path( make
, "winegcc" ));
3327 output_winegcc_command( make
, 0 );
3328 output_filename( "-munix" );
3329 output_filename( "-shared" );
3330 if (spec_file
) output_filename( spec_file
);
3332 output_filenames_obj_dir( make
, make
->unixobj_files
);
3333 output_filenames( unix_libs
);
3334 output_filename( "$(LDFLAGS)" );
3339 /*******************************************************************
3342 static void output_static_lib( struct makefile
*make
)
3344 if (!crosstarget
|| !make
->extlib
)
3346 strarray_add( &make
->clean_files
, make
->staticlib
);
3347 output( "%s: %s", obj_dir_path( make
, make
->staticlib
), tools_path( make
, "winebuild" ));
3348 output_filenames_obj_dir( make
, make
->object_files
);
3349 output_filenames_obj_dir( make
, make
->unixobj_files
);
3351 output( "\t%s%s -w --staticlib -o $@", cmd_prefix( "BUILD" ), tools_path( make
, "winebuild" ));
3352 output_filenames( target_flags
);
3353 output_filenames_obj_dir( make
, make
->object_files
);
3354 output_filenames_obj_dir( make
, make
->unixobj_files
);
3357 add_install_rule( make
, make
->staticlib
, make
->staticlib
,
3358 strmake( "d%s/%s", so_dir
, make
->staticlib
));
3362 char *name
= replace_extension( make
->staticlib
, ".a", ".cross.a" );
3364 strarray_add( &make
->clean_files
, name
);
3365 output( "%s: %s", obj_dir_path( make
, name
), tools_path( make
, "winebuild" ));
3366 output_filenames_obj_dir( make
, make
->crossobj_files
);
3368 output( "\t%s%s -b %s -w --staticlib -o $@", cmd_prefix( "BUILD" ),
3369 tools_path( make
, "winebuild" ), crosstarget
);
3370 output_filenames_obj_dir( make
, make
->crossobj_files
);
3373 add_install_rule( make
, make
->staticlib
, name
,
3374 strmake( "d%s/%s", pe_dir
, make
->staticlib
));
3379 /*******************************************************************
3382 static void output_shared_lib( struct makefile
*make
)
3386 struct strarray names
= get_shared_lib_names( make
->sharedlib
);
3387 struct strarray all_libs
= empty_strarray
;
3388 struct strarray dep_libs
= empty_strarray
;
3390 basename
= xstrdup( make
->sharedlib
);
3391 if ((p
= strchr( basename
, '.' ))) *p
= 0;
3393 strarray_addall( &dep_libs
, get_local_dependencies( make
, basename
, make
->in_files
));
3394 strarray_addall( &all_libs
, get_expanded_file_local_var( make
, basename
, "LDFLAGS" ));
3395 strarray_addall( &all_libs
, get_expanded_make_var_array( make
, "UNIX_LIBS" ));
3396 strarray_addall( &all_libs
, libs
);
3398 output( "%s:", obj_dir_path( make
, make
->sharedlib
));
3399 output_filenames_obj_dir( make
, make
->object_files
);
3400 output_filenames( dep_libs
);
3402 output( "\t%s$(CC) -o $@", cmd_prefix( "CCLD" ));
3403 output_filenames_obj_dir( make
, make
->object_files
);
3404 output_filenames( all_libs
);
3405 output_filename( "$(LDFLAGS)" );
3407 add_install_rule( make
, make
->sharedlib
, make
->sharedlib
, strmake( "p%s/%s", so_dir
, make
->sharedlib
));
3408 for (i
= 1; i
< names
.count
; i
++)
3410 output( "%s: %s\n", obj_dir_path( make
, names
.str
[i
] ), obj_dir_path( make
, names
.str
[i
-1] ));
3411 output_symlink_rule( names
.str
[i
-1], obj_dir_path( make
, names
.str
[i
] ), 0 );
3412 add_install_rule( make
, names
.str
[i
], names
.str
[i
-1], strmake( "y%s/%s", so_dir
, names
.str
[i
] ));
3414 strarray_addall( &make
->all_targets
, names
);
3418 /*******************************************************************
3419 * output_test_module
3421 static void output_test_module( struct makefile
*make
)
3423 char *testmodule
= replace_extension( make
->testdll
, ".dll", "_test.exe" );
3424 char *stripped
= replace_extension( make
->testdll
, ".dll", "_test-stripped.exe" );
3425 char *testres
= replace_extension( make
->testdll
, ".dll", "_test.res" );
3426 struct strarray dep_libs
= empty_strarray
;
3427 struct strarray all_libs
= add_import_libs( make
, &dep_libs
, add_default_imports( make
, make
->imports
),
3428 0, make
->is_cross
);
3429 struct makefile
*parent
= get_parent_makefile( make
);
3430 const char *ext
= make
->is_cross
? "" : dll_ext
;
3431 const char *debug_file
;
3434 strarray_add( &make
->all_targets
, strmake( "%s%s", testmodule
, ext
));
3435 strarray_add( &make
->clean_files
, strmake( "%s%s", stripped
, ext
));
3436 output_file
= strmake( "%s%s", obj_dir_path( make
, testmodule
), ext
);
3437 output( "%s:\n", output_file
);
3438 output_winegcc_command( make
, make
->is_cross
);
3439 output_filenames( make
->extradllflags
);
3440 output_filenames_obj_dir( make
, make
->is_cross
? make
->crossobj_files
: make
->object_files
);
3441 output_filenames_obj_dir( make
, make
->res_files
);
3442 if ((debug_file
= get_debug_file( make
, testmodule
)))
3443 output_filename( strmake( "-Wl,--debug-file,%s", obj_dir_path( make
, debug_file
)));
3444 output_filenames( all_libs
);
3445 output_filename( make
->is_cross
? "$(CROSSLDFLAGS)" : "$(LDFLAGS)" );
3447 output( "%s%s:\n", obj_dir_path( make
, stripped
), ext
);
3448 output_winegcc_command( make
, make
->is_cross
);
3449 output_filename( "-s" );
3450 output_filename( strmake( "-Wb,-F,%s", testmodule
));
3451 output_filenames( make
->extradllflags
);
3452 output_filenames_obj_dir( make
, make
->is_cross
? make
->crossobj_files
: make
->object_files
);
3453 output_filenames_obj_dir( make
, make
->res_files
);
3454 output_filenames( all_libs
);
3455 output_filename( make
->is_cross
? "$(CROSSLDFLAGS)" : "$(LDFLAGS)" );
3457 output( "%s%s %s%s:", obj_dir_path( make
, testmodule
), ext
, obj_dir_path( make
, stripped
), ext
);
3458 output_filenames_obj_dir( make
, make
->is_cross
? make
->crossobj_files
: make
->object_files
);
3459 output_filenames_obj_dir( make
, make
->res_files
);
3460 output_filenames( dep_libs
);
3461 output_filename( tools_path( make
, "winebuild" ));
3462 output_filename( tools_path( make
, "winegcc" ));
3465 output( "programs/winetest/%s: %s%s\n", testres
, obj_dir_path( make
, stripped
), ext
);
3466 output( "\t%secho \"%s TESTRES \\\"%s%s\\\"\" | %s -u -o $@\n", cmd_prefix( "WRC" ),
3467 testmodule
, obj_dir_path( make
, stripped
), ext
, tools_path( make
, "wrc" ));
3469 output_filenames_obj_dir( make
, make
->ok_files
);
3470 output( ": %s%s", obj_dir_path( make
, testmodule
), ext
);
3473 output_filename( parent
->is_cross
? obj_dir_path( parent
, make
->testdll
)
3474 : strmake( "%s%s", obj_dir_path( parent
, make
->testdll
), dll_ext
));
3475 if (parent
->unixlib
) output_filename( obj_dir_path( parent
, parent
->unixlib
));
3478 output( "%s %s:", obj_dir_path( make
, "check" ), obj_dir_path( make
, "test" ));
3479 if (!make
->disabled
&& parent
&& !parent
->disabled
) output_filenames_obj_dir( make
, make
->ok_files
);
3481 strarray_add_uniq( &make
->phony_targets
, obj_dir_path( make
, "check" ));
3482 strarray_add_uniq( &make
->phony_targets
, obj_dir_path( make
, "test" ));
3483 output( "%s::\n", obj_dir_path( make
, "testclean" ));
3484 output( "\trm -f" );
3485 output_filenames_obj_dir( make
, make
->ok_files
);
3487 strarray_addall( &make
->clean_files
, make
->ok_files
);
3488 strarray_add_uniq( &make
->phony_targets
, obj_dir_path( make
, "testclean" ));
3492 /*******************************************************************
3495 static void output_programs( struct makefile
*make
)
3499 for (i
= 0; i
< make
->programs
.count
; i
++)
3501 char *program_installed
= NULL
;
3502 char *program
= strmake( "%s%s", make
->programs
.str
[i
], exe_ext
);
3503 struct strarray deps
= get_local_dependencies( make
, make
->programs
.str
[i
], make
->in_files
);
3504 struct strarray all_libs
= get_expanded_file_local_var( make
, make
->programs
.str
[i
], "LDFLAGS" );
3505 struct strarray objs
= get_expanded_file_local_var( make
, make
->programs
.str
[i
], "OBJS" );
3506 struct strarray symlinks
= get_expanded_file_local_var( make
, make
->programs
.str
[i
], "SYMLINKS" );
3508 if (!objs
.count
) objs
= make
->object_files
;
3509 if (!strarray_exists( &all_libs
, "-nodefaultlibs" ))
3511 strarray_addall( &all_libs
, get_expanded_make_var_array( make
, "UNIX_LIBS" ));
3512 strarray_addall( &all_libs
, libs
);
3515 output( "%s:", obj_dir_path( make
, program
) );
3516 output_filenames_obj_dir( make
, objs
);
3517 output_filenames( deps
);
3519 output( "\t%s$(CC) -o $@", cmd_prefix( "CCLD" ));
3520 output_filenames_obj_dir( make
, objs
);
3521 output_filenames( all_libs
);
3522 output_filename( "$(LDFLAGS)" );
3524 strarray_add( &make
->all_targets
, program
);
3526 for (j
= 0; j
< symlinks
.count
; j
++)
3528 output( "%s: %s\n", obj_dir_path( make
, symlinks
.str
[j
] ), obj_dir_path( make
, program
));
3529 output_symlink_rule( program
, obj_dir_path( make
, symlinks
.str
[j
] ), 0 );
3531 strarray_addall( &make
->all_targets
, symlinks
);
3533 add_install_rule( make
, program
, program_installed
? program_installed
: program
,
3534 strmake( "p$(bindir)/%s", program
));
3535 for (j
= 0; j
< symlinks
.count
; j
++)
3536 add_install_rule( make
, symlinks
.str
[j
], program
,
3537 strmake( "y$(bindir)/%s%s", symlinks
.str
[j
], exe_ext
));
3542 /*******************************************************************
3545 static void output_subdirs( struct makefile
*make
)
3547 struct strarray all_targets
= empty_strarray
;
3548 struct strarray makefile_deps
= empty_strarray
;
3549 struct strarray clean_files
= empty_strarray
;
3550 struct strarray testclean_files
= empty_strarray
;
3551 struct strarray distclean_files
= empty_strarray
;
3552 struct strarray dependencies
= empty_strarray
;
3553 struct strarray install_lib_deps
= empty_strarray
;
3554 struct strarray install_dev_deps
= empty_strarray
;
3555 struct strarray tooldeps_deps
= empty_strarray
;
3556 struct strarray buildtest_deps
= empty_strarray
;
3559 strarray_addall( &clean_files
, make
->clean_files
);
3560 strarray_addall( &distclean_files
, make
->distclean_files
);
3561 strarray_addall( &all_targets
, make
->all_targets
);
3562 for (i
= 0; i
< subdirs
.count
; i
++)
3564 strarray_add( &makefile_deps
, src_dir_path( submakes
[i
], "Makefile.in" ));
3565 strarray_addall_uniq( &make
->phony_targets
, submakes
[i
]->phony_targets
);
3566 strarray_addall_uniq( &make
->uninstall_files
, submakes
[i
]->uninstall_files
);
3567 strarray_addall_uniq( &dependencies
, submakes
[i
]->dependencies
);
3568 strarray_addall_path( &clean_files
, submakes
[i
]->obj_dir
, submakes
[i
]->clean_files
);
3569 strarray_addall_path( &distclean_files
, submakes
[i
]->obj_dir
, submakes
[i
]->distclean_files
);
3570 strarray_addall_path( &make
->maintainerclean_files
, submakes
[i
]->obj_dir
, submakes
[i
]->maintainerclean_files
);
3571 strarray_addall_path( &testclean_files
, submakes
[i
]->obj_dir
, submakes
[i
]->ok_files
);
3572 strarray_addall_path( &make
->pot_files
, submakes
[i
]->obj_dir
, submakes
[i
]->pot_files
);
3574 if (submakes
[i
]->disabled
) continue;
3576 strarray_addall_path( &all_targets
, submakes
[i
]->obj_dir
, submakes
[i
]->all_targets
);
3577 strarray_addall_path( &all_targets
, submakes
[i
]->obj_dir
, submakes
[i
]->font_files
);
3578 if (!strcmp( submakes
[i
]->obj_dir
, "tools" ) || !strncmp( submakes
[i
]->obj_dir
, "tools/", 6 ))
3579 strarray_add( &tooldeps_deps
, obj_dir_path( submakes
[i
], "all" ));
3580 if (submakes
[i
]->testdll
)
3581 strarray_add( &buildtest_deps
, obj_dir_path( submakes
[i
], "all" ));
3582 if (submakes
[i
]->install_rules
[INSTALL_LIB
].count
)
3583 strarray_add( &install_lib_deps
, obj_dir_path( submakes
[i
], "install-lib" ));
3584 if (submakes
[i
]->install_rules
[INSTALL_DEV
].count
)
3585 strarray_add( &install_dev_deps
, obj_dir_path( submakes
[i
], "install-dev" ));
3587 strarray_addall( &dependencies
, makefile_deps
);
3589 output_filenames( all_targets
);
3591 output( "Makefile:" );
3592 output_filenames( makefile_deps
);
3594 output_filenames( dependencies
);
3596 if (install_lib_deps
.count
)
3598 output( "install install-lib::" );
3599 output_filenames( install_lib_deps
);
3601 strarray_add_uniq( &make
->phony_targets
, "install" );
3602 strarray_add_uniq( &make
->phony_targets
, "install-lib" );
3604 if (install_dev_deps
.count
)
3606 output( "install install-dev::" );
3607 output_filenames( install_dev_deps
);
3609 strarray_add_uniq( &make
->phony_targets
, "install" );
3610 strarray_add_uniq( &make
->phony_targets
, "install-dev" );
3612 output_uninstall_rules( make
);
3613 if (buildtest_deps
.count
)
3615 output( "buildtests:" );
3616 output_filenames( buildtest_deps
);
3618 strarray_add_uniq( &make
->phony_targets
, "buildtests" );
3620 output( "check test:" );
3621 output_filenames( testclean_files
);
3623 strarray_add_uniq( &make
->phony_targets
, "check" );
3624 strarray_add_uniq( &make
->phony_targets
, "test" );
3626 if (get_expanded_make_variable( make
, "GETTEXTPO_LIBS" )) output_po_files( make
);
3628 output( "clean::\n");
3629 output_rm_filenames( clean_files
);
3630 output( "testclean::\n");
3631 output_rm_filenames( testclean_files
);
3632 output( "distclean::\n");
3633 output_rm_filenames( distclean_files
);
3634 output( "maintainer-clean::\n");
3635 output_rm_filenames( make
->maintainerclean_files
);
3636 strarray_add_uniq( &make
->phony_targets
, "distclean" );
3637 strarray_add_uniq( &make
->phony_targets
, "testclean" );
3638 strarray_add_uniq( &make
->phony_targets
, "maintainer-clean" );
3640 if (tooldeps_deps
.count
)
3642 output( "__tooldeps__:" );
3643 output_filenames( tooldeps_deps
);
3645 strarray_add_uniq( &make
->phony_targets
, "__tooldeps__" );
3648 if (make
->phony_targets
.count
)
3650 output( ".PHONY:" );
3651 output_filenames( make
->phony_targets
);
3657 /*******************************************************************
3660 static void output_sources( struct makefile
*make
)
3662 struct strarray all_targets
= empty_strarray
;
3663 struct incl_file
*source
;
3666 strarray_add_uniq( &make
->phony_targets
, "all" );
3668 LIST_FOR_EACH_ENTRY( source
, &make
->sources
, struct incl_file
, entry
)
3670 char *obj
= xstrdup( source
->name
);
3671 char *ext
= get_extension( obj
);
3673 if (!ext
) fatal_error( "unsupported file type %s\n", source
->name
);
3676 for (j
= 0; output_source_funcs
[j
].ext
; j
++)
3677 if (!strcmp( ext
, output_source_funcs
[j
].ext
)) break;
3679 output_source_funcs
[j
].fn( make
, source
, obj
);
3680 strarray_addall_uniq( &make
->dependencies
, source
->dependencies
);
3683 /* special case for winetest: add resource files from other test dirs */
3684 if (make
->obj_dir
&& !strcmp( make
->obj_dir
, "programs/winetest" ))
3686 struct strarray tests
= enable_tests
;
3688 for (i
= 0; i
< subdirs
.count
; i
++)
3689 if (submakes
[i
]->testdll
&& !submakes
[i
]->disabled
)
3690 strarray_add( &tests
, submakes
[i
]->testdll
);
3691 for (i
= 0; i
< tests
.count
; i
++)
3692 strarray_add( &make
->res_files
, replace_extension( tests
.str
[i
], ".dll", "_test.res" ));
3695 if (make
->dlldata_files
.count
)
3697 output( "%s: %s %s\n", obj_dir_path( make
, "dlldata.c" ),
3698 tools_path( make
, "widl" ), src_dir_path( make
, "Makefile.in" ));
3699 output( "\t%s%s --dlldata-only -o $@", cmd_prefix( "WIDL" ), tools_path( make
, "widl" ));
3700 output_filenames( make
->dlldata_files
);
3704 if (make
->staticlib
) output_static_lib( make
);
3705 else if (make
->module
)
3707 output_module( make
);
3708 if (*dll_ext
&& !make
->is_cross
&& !make
->data_only
) output_fake_module( make
);
3709 if (make
->unixlib
) output_unix_lib( make
);
3710 if (make
->importlib
) output_import_lib( make
);
3712 else if (make
->testdll
) output_test_module( make
);
3713 else if (make
->sharedlib
) output_shared_lib( make
);
3714 else if (make
->programs
.count
) output_programs( make
);
3716 for (i
= 0; i
< make
->scripts
.count
; i
++)
3717 add_install_rule( make
, make
->scripts
.str
[i
], make
->scripts
.str
[i
],
3718 strmake( "S$(bindir)/%s", make
->scripts
.str
[i
] ));
3720 for (i
= 0; i
< make
->extra_targets
.count
; i
++)
3721 if (strarray_exists( &make
->dependencies
, obj_dir_path( make
, make
->extra_targets
.str
[i
] )))
3722 strarray_add( &make
->clean_files
, make
->extra_targets
.str
[i
] );
3724 strarray_add( &make
->all_targets
, make
->extra_targets
.str
[i
] );
3726 if (!make
->src_dir
) strarray_add( &make
->distclean_files
, ".gitignore" );
3727 strarray_add( &make
->distclean_files
, "Makefile" );
3728 if (make
->testdll
) strarray_add( &make
->distclean_files
, "testlist.c" );
3731 strarray_addall( &make
->distclean_files
, get_expanded_make_var_array( make
, "CONFIGURE_TARGETS" ));
3732 else if (!strcmp( make
->obj_dir
, "po" ))
3733 strarray_add( &make
->distclean_files
, "LINGUAS" );
3735 strarray_addall( &make
->clean_files
, make
->object_files
);
3736 strarray_addall( &make
->clean_files
, make
->crossobj_files
);
3737 strarray_addall( &make
->clean_files
, make
->implib_files
);
3738 strarray_addall( &make
->clean_files
, make
->crossimplib_files
);
3739 strarray_addall( &make
->clean_files
, make
->unixobj_files
);
3740 strarray_addall( &make
->clean_files
, make
->res_files
);
3741 strarray_addall( &make
->clean_files
, make
->pot_files
);
3742 strarray_addall( &make
->clean_files
, make
->debug_files
);
3743 strarray_addall( &make
->clean_files
, make
->all_targets
);
3745 if (make
== top_makefile
)
3747 output_subdirs( make
);
3751 strarray_addall( &all_targets
, make
->all_targets
);
3752 strarray_addall( &all_targets
, make
->font_files
);
3753 if (all_targets
.count
)
3755 output( "%s:", obj_dir_path( make
, "all" ));
3756 output_filenames_obj_dir( make
, all_targets
);
3758 strarray_add_uniq( &make
->phony_targets
, obj_dir_path( make
, "all" ));
3760 output_install_rules( make
, INSTALL_LIB
, "install-lib" );
3761 output_install_rules( make
, INSTALL_DEV
, "install-dev" );
3763 if (make
->clean_files
.count
)
3765 output( "%s::\n", obj_dir_path( make
, "clean" ));
3766 output( "\trm -f" );
3767 output_filenames_obj_dir( make
, make
->clean_files
);
3769 strarray_add( &make
->phony_targets
, obj_dir_path( make
, "clean" ));
3774 /*******************************************************************
3777 static FILE *create_temp_file( const char *orig
)
3779 char *name
= xmalloc( strlen(orig
) + 13 );
3780 unsigned int i
, id
= getpid();
3784 for (i
= 0; i
< 100; i
++)
3786 sprintf( name
, "%s.tmp%08x", orig
, id
);
3787 if ((fd
= open( name
, O_RDWR
| O_CREAT
| O_EXCL
, 0666 )) != -1)
3789 ret
= fdopen( fd
, "w" );
3792 if (errno
!= EEXIST
) break;
3795 if (!ret
) fatal_error( "failed to create output file for '%s'\n", orig
);
3796 temp_file_name
= name
;
3801 /*******************************************************************
3804 static void rename_temp_file( const char *dest
)
3806 int ret
= rename( temp_file_name
, dest
);
3807 if (ret
== -1 && errno
== EEXIST
)
3809 /* rename doesn't overwrite on windows */
3811 ret
= rename( temp_file_name
, dest
);
3813 if (ret
== -1) fatal_error( "failed to rename output file to '%s'\n", dest
);
3814 temp_file_name
= NULL
;
3818 /*******************************************************************
3819 * are_files_identical
3821 static int are_files_identical( FILE *file1
, FILE *file2
)
3825 char buffer1
[8192], buffer2
[8192];
3826 int size1
= fread( buffer1
, 1, sizeof(buffer1
), file1
);
3827 int size2
= fread( buffer2
, 1, sizeof(buffer2
), file2
);
3828 if (size1
!= size2
) return 0;
3829 if (!size1
) return feof( file1
) && feof( file2
);
3830 if (memcmp( buffer1
, buffer2
, size1
)) return 0;
3835 /*******************************************************************
3836 * rename_temp_file_if_changed
3838 static void rename_temp_file_if_changed( const char *dest
)
3840 FILE *file1
, *file2
;
3843 if ((file1
= fopen( dest
, "r" )))
3845 if ((file2
= fopen( temp_file_name
, "r" )))
3847 do_rename
= !are_files_identical( file1
, file2
);
3854 unlink( temp_file_name
);
3855 temp_file_name
= NULL
;
3857 else rename_temp_file( dest
);
3861 /*******************************************************************
3864 static void output_linguas( const struct makefile
*make
)
3866 const char *dest
= obj_dir_path( make
, "LINGUAS" );
3867 struct incl_file
*source
;
3869 output_file
= create_temp_file( dest
);
3871 output( "# Automatically generated by make depend; DO NOT EDIT!!\n" );
3872 LIST_FOR_EACH_ENTRY( source
, &make
->sources
, struct incl_file
, entry
)
3873 if (strendswith( source
->name
, ".po" ))
3874 output( "%s\n", replace_extension( source
->name
, ".po", "" ));
3876 if (fclose( output_file
)) fatal_perror( "write" );
3878 rename_temp_file_if_changed( dest
);
3882 /*******************************************************************
3885 static void output_testlist( const struct makefile
*make
)
3887 const char *dest
= obj_dir_path( make
, "testlist.c" );
3890 output_file
= create_temp_file( dest
);
3892 output( "/* Automatically generated by make depend; DO NOT EDIT!! */\n\n" );
3893 output( "#define WIN32_LEAN_AND_MEAN\n" );
3894 output( "#include <windows.h>\n\n" );
3895 output( "#define STANDALONE\n" );
3896 output( "#include \"wine/test.h\"\n\n" );
3898 for (i
= 0; i
< make
->test_files
.count
; i
++)
3899 output( "extern void func_%s(void);\n", make
->test_files
.str
[i
] );
3901 output( "const struct test winetest_testlist[] =\n" );
3903 for (i
= 0; i
< make
->test_files
.count
; i
++)
3904 output( " { \"%s\", func_%s },\n", make
->test_files
.str
[i
], make
->test_files
.str
[i
] );
3905 output( " { 0, 0 }\n" );
3908 if (fclose( output_file
)) fatal_perror( "write" );
3910 rename_temp_file_if_changed( dest
);
3914 /*******************************************************************
3917 static void output_gitignore( const char *dest
, struct strarray files
)
3921 output_file
= create_temp_file( dest
);
3923 output( "# Automatically generated by make depend; DO NOT EDIT!!\n" );
3924 for (i
= 0; i
< files
.count
; i
++)
3926 if (!strchr( files
.str
[i
], '/' )) output( "/" );
3927 output( "%s\n", files
.str
[i
] );
3930 if (fclose( output_file
)) fatal_perror( "write" );
3932 rename_temp_file( dest
);
3936 /*******************************************************************
3937 * output_stub_makefile
3939 static void output_stub_makefile( struct makefile
*make
)
3941 struct strarray targets
= empty_strarray
;
3942 const char *make_var
= strarray_get_value( &top_makefile
->vars
, "MAKE" );
3944 if (make
->obj_dir
) create_dir( make
->obj_dir
);
3946 output_file_name
= obj_dir_path( make
, "Makefile" );
3947 output_file
= create_temp_file( output_file_name
);
3949 output( "# Auto-generated stub makefile; all rules forward to the top-level makefile\n\n" );
3951 if (make_var
) output( "MAKE = %s\n\n", make_var
);
3954 if (make
->all_targets
.count
) strarray_add( &targets
, "all" );
3955 if (make
->install_rules
[INSTALL_LIB
].count
|| make
->install_rules
[INSTALL_DEV
].count
)
3956 strarray_add( &targets
, "install" );
3957 if (make
->install_rules
[INSTALL_LIB
].count
) strarray_add( &targets
, "install-lib" );
3958 if (make
->install_rules
[INSTALL_DEV
].count
) strarray_add( &targets
, "install-dev" );
3959 if (make
->clean_files
.count
) strarray_add( &targets
, "clean" );
3960 if (make
->test_files
.count
)
3962 strarray_add( &targets
, "check" );
3963 strarray_add( &targets
, "test" );
3964 strarray_add( &targets
, "testclean" );
3967 output_filenames( targets
);
3968 output_filenames( make
->clean_files
);
3970 output( "\t@cd %s && $(MAKE) %s/$@\n", get_relative_path( make
->obj_dir
, "" ), make
->obj_dir
);
3971 output( ".PHONY:" );
3972 output_filenames( targets
);
3975 fclose( output_file
);
3977 rename_temp_file( output_file_name
);
3981 /*******************************************************************
3982 * output_silent_rules
3984 static void output_silent_rules(void)
3986 static const char *cmds
[] =
4004 output( "V = 0\n" );
4005 for (i
= 0; i
< sizeof(cmds
) / sizeof(cmds
[0]); i
++)
4007 output( "quiet_%s = $(quiet_%s_$(V))\n", cmds
[i
], cmds
[i
] );
4008 output( "quiet_%s_0 = @echo \" %-5s \" $@;\n", cmds
[i
], cmds
[i
] );
4009 output( "quiet_%s_1 =\n", cmds
[i
] );
4014 /*******************************************************************
4015 * output_top_makefile
4017 static void output_top_makefile( struct makefile
*make
)
4024 output_file_name
= obj_dir_path( make
, output_makefile_name
);
4025 output_file
= create_temp_file( output_file_name
);
4027 /* copy the contents of the source makefile */
4028 src_file
= open_input_makefile( make
);
4029 while (fgets( buffer
, sizeof(buffer
), src_file
) && !found
)
4031 if (fwrite( buffer
, 1, strlen(buffer
), output_file
) != strlen(buffer
)) fatal_perror( "write" );
4032 found
= !strncmp( buffer
, separator
, strlen(separator
) );
4034 if (fclose( src_file
)) fatal_perror( "close" );
4035 input_file_name
= NULL
;
4037 if (!found
) output( "\n%s (everything below this line is auto-generated; DO NOT EDIT!!)\n", separator
);
4039 if (silent_rules
) output_silent_rules();
4040 for (i
= 0; i
< subdirs
.count
; i
++) output_sources( submakes
[i
] );
4041 output_sources( make
);
4042 /* disable implicit rules */
4043 output( ".SUFFIXES:\n" );
4045 fclose( output_file
);
4047 rename_temp_file( output_file_name
);
4051 /*******************************************************************
4052 * output_dependencies
4054 static void output_dependencies( struct makefile
*make
)
4056 struct strarray ignore_files
= empty_strarray
;
4058 if (make
->obj_dir
) create_dir( make
->obj_dir
);
4060 if (make
== top_makefile
) output_top_makefile( make
);
4061 else output_stub_makefile( make
);
4063 strarray_addall( &ignore_files
, make
->distclean_files
);
4064 strarray_addall( &ignore_files
, make
->clean_files
);
4065 if (make
->testdll
) output_testlist( make
);
4066 if (make
->obj_dir
&& !strcmp( make
->obj_dir
, "po" )) output_linguas( make
);
4067 if (!make
->src_dir
) output_gitignore( obj_dir_path( make
, ".gitignore" ), ignore_files
);
4069 create_file_directories( make
, ignore_files
);
4071 output_file_name
= NULL
;
4075 /*******************************************************************
4078 static void load_sources( struct makefile
*make
)
4080 static const char *source_vars
[] =
4101 struct strarray value
;
4102 struct incl_file
*file
;
4104 strarray_set_value( &make
->vars
, "top_srcdir", root_src_dir_path( "" ));
4105 strarray_set_value( &make
->vars
, "srcdir", src_dir_path( make
, "" ));
4107 make
->parent_dir
= get_expanded_make_variable( make
, "PARENTSRC" );
4108 make
->module
= get_expanded_make_variable( make
, "MODULE" );
4109 make
->testdll
= get_expanded_make_variable( make
, "TESTDLL" );
4110 make
->sharedlib
= get_expanded_make_variable( make
, "SHAREDLIB" );
4111 make
->staticlib
= get_expanded_make_variable( make
, "STATICLIB" );
4112 make
->importlib
= get_expanded_make_variable( make
, "IMPORTLIB" );
4113 make
->extlib
= get_expanded_make_variable( make
, "EXTLIB" );
4114 if (*dll_ext
) make
->unixlib
= get_expanded_make_variable( make
, "UNIXLIB" );
4116 make
->programs
= get_expanded_make_var_array( make
, "PROGRAMS" );
4117 make
->scripts
= get_expanded_make_var_array( make
, "SCRIPTS" );
4118 make
->imports
= get_expanded_make_var_array( make
, "IMPORTS" );
4119 make
->delayimports
= get_expanded_make_var_array( make
, "DELAYIMPORTS" );
4120 make
->extradllflags
= get_expanded_make_var_array( make
, "EXTRADLLFLAGS" );
4121 make
->install_lib
= get_expanded_make_var_array( make
, "INSTALL_LIB" );
4122 make
->install_dev
= get_expanded_make_var_array( make
, "INSTALL_DEV" );
4123 make
->extra_targets
= get_expanded_make_var_array( make
, "EXTRA_TARGETS" );
4125 if (make
->extlib
) make
->staticlib
= make
->extlib
;
4126 if (make
->staticlib
) make
->module
= make
->staticlib
;
4130 value
= get_expanded_file_local_var( make
, host_cpu
, "EXTRADLLFLAGS" );
4131 if (value
.count
) make
->extradllflags
= value
;
4134 make
->disabled
= make
->obj_dir
&& strarray_exists( &disabled_dirs
, make
->obj_dir
);
4135 make
->is_win16
= strarray_exists( &make
->extradllflags
, "-m16" );
4136 make
->data_only
= strarray_exists( &make
->extradllflags
, "-Wb,--data-only" );
4137 make
->use_msvcrt
= (make
->module
|| make
->testdll
|| make
->is_win16
) &&
4138 !strarray_exists( &make
->extradllflags
, "-mcygwin" );
4139 make
->is_exe
= strarray_exists( &make
->extradllflags
, "-mconsole" ) ||
4140 strarray_exists( &make
->extradllflags
, "-mwindows" );
4141 make
->native_unix_lib
= !!make
->unixlib
;
4143 if (make
->use_msvcrt
) strarray_add_uniq( &make
->extradllflags
, "-mno-cygwin" );
4145 if (make
->module
&& !make
->install_lib
.count
&& !make
->install_dev
.count
)
4147 if (make
->importlib
) strarray_add( &make
->install_dev
, make
->importlib
);
4148 if (make
->staticlib
) strarray_add( &make
->install_dev
, make
->staticlib
);
4149 else strarray_add( &make
->install_lib
, make
->module
);
4152 make
->include_paths
= empty_strarray
;
4153 make
->include_args
= empty_strarray
;
4154 make
->define_args
= empty_strarray
;
4155 make
->unix_cflags
= empty_strarray
;
4156 if (!make
->extlib
) strarray_add( &make
->define_args
, "-D__WINESRC__" );
4158 value
= get_expanded_make_var_array( make
, "EXTRAINCL" );
4159 for (i
= 0; i
< value
.count
; i
++)
4161 if (!strncmp( value
.str
[i
], "-I", 2 ))
4163 const char *dir
= value
.str
[i
] + 2;
4164 if (!strncmp( dir
, "./", 2 ))
4167 while (*dir
== '/') dir
++;
4169 strarray_add_uniq( &make
->include_paths
, dir
);
4171 else if (!strncmp( value
.str
[i
], "-D", 2 ) || !strncmp( value
.str
[i
], "-U", 2 ))
4172 strarray_add_uniq( &make
->define_args
, value
.str
[i
] );
4174 strarray_addall( &make
->define_args
, get_expanded_make_var_array( make
, "EXTRADEFS" ));
4175 strarray_addall_uniq( &make
->unix_cflags
, get_expanded_make_var_array( make
, "UNIX_CFLAGS" ));
4177 strarray_add( &make
->include_args
, strmake( "-I%s", obj_dir_path( make
, "" )));
4179 strarray_add( &make
->include_args
, strmake( "-I%s", make
->src_dir
));
4180 if (make
->parent_dir
)
4181 strarray_add( &make
->include_args
, strmake( "-I%s", src_dir_path( make
, make
->parent_dir
)));
4182 strarray_add( &make
->include_args
, "-Iinclude" );
4183 if (root_src_dir
) strarray_add( &make
->include_args
, strmake( "-I%s", root_src_dir_path( "include" )));
4185 list_init( &make
->sources
);
4186 list_init( &make
->includes
);
4188 for (var
= source_vars
; *var
; var
++)
4190 value
= get_expanded_make_var_array( make
, *var
);
4191 for (i
= 0; i
< value
.count
; i
++) add_src_file( make
, value
.str
[i
] );
4194 add_generated_sources( make
);
4195 if (!make
->unixlib
) make
->unixlib
= get_unix_lib_name( make
);
4197 if (make
->use_msvcrt
) strarray_add( &make
->define_args
, get_crt_define( make
));
4199 LIST_FOR_EACH_ENTRY( file
, &make
->includes
, struct incl_file
, entry
) parse_file( make
, file
, 0 );
4200 LIST_FOR_EACH_ENTRY( file
, &make
->sources
, struct incl_file
, entry
) get_dependencies( file
, file
);
4202 make
->is_cross
= crosstarget
&& make
->use_msvcrt
;
4204 if (!*dll_ext
|| make
->is_cross
)
4205 for (i
= 0; i
< make
->delayimports
.count
; i
++)
4206 strarray_add_uniq( &delay_import_libs
, get_base_name( make
->delayimports
.str
[i
] ));
4210 /*******************************************************************
4213 static void parse_makeflags( const char *flags
)
4215 const char *p
= flags
;
4216 char *var
, *buffer
= xmalloc( strlen(flags
) + 1 );
4220 while (isspace(*p
)) p
++;
4222 while (*p
&& !isspace(*p
))
4224 if (*p
== '\\' && p
[1]) p
++;
4228 if (var
> buffer
) set_make_variable( &cmdline_vars
, buffer
);
4233 /*******************************************************************
4236 static int parse_option( const char *opt
)
4240 if (strchr( opt
, '=' )) return set_make_variable( &cmdline_vars
, opt
);
4246 if (opt
[2]) output_makefile_name
= opt
+ 2;
4249 relative_dir_mode
= 1;
4255 fprintf( stderr
, "Unknown option '%s'\n%s", opt
, Usage
);
4262 /*******************************************************************
4265 int main( int argc
, char *argv
[] )
4267 const char *makeflags
= getenv( "MAKEFLAGS" );
4270 if (makeflags
) parse_makeflags( makeflags
);
4275 if (parse_option( argv
[i
] ))
4277 for (j
= i
; j
< argc
; j
++) argv
[j
] = argv
[j
+1];
4283 if (relative_dir_mode
)
4289 fprintf( stderr
, "Option -R needs two directories\n%s", Usage
);
4292 relpath
= get_relative_path( argv
[1], argv
[2] );
4293 printf( "%s\n", relpath
? relpath
: "." );
4297 if (argc
> 1) fatal_error( "Directory arguments not supported in this mode\n" );
4299 atexit( cleanup_files
);
4300 signal( SIGTERM
, exit_on_signal
);
4301 signal( SIGINT
, exit_on_signal
);
4303 signal( SIGHUP
, exit_on_signal
);
4306 for (i
= 0; i
< HASH_SIZE
; i
++) list_init( &files
[i
] );
4308 top_makefile
= parse_makefile( NULL
);
4310 target_flags
= get_expanded_make_var_array( top_makefile
, "TARGETFLAGS" );
4311 msvcrt_flags
= get_expanded_make_var_array( top_makefile
, "MSVCRTFLAGS" );
4312 dll_flags
= get_expanded_make_var_array( top_makefile
, "DLLFLAGS" );
4313 extra_cflags
= get_expanded_make_var_array( top_makefile
, "EXTRACFLAGS" );
4314 extra_cross_cflags
= get_expanded_make_var_array( top_makefile
, "EXTRACROSSCFLAGS" );
4315 unix_dllflags
= get_expanded_make_var_array( top_makefile
, "UNIXDLLFLAGS" );
4316 cpp_flags
= get_expanded_make_var_array( top_makefile
, "CPPFLAGS" );
4317 lddll_flags
= get_expanded_make_var_array( top_makefile
, "LDDLLFLAGS" );
4318 libs
= get_expanded_make_var_array( top_makefile
, "LIBS" );
4319 enable_tests
= get_expanded_make_var_array( top_makefile
, "ENABLE_TESTS" );
4320 top_install_lib
= get_expanded_make_var_array( top_makefile
, "TOP_INSTALL_LIB" );
4321 top_install_dev
= get_expanded_make_var_array( top_makefile
, "TOP_INSTALL_DEV" );
4323 delay_load_flag
= get_expanded_make_variable( top_makefile
, "DELAYLOADFLAG" );
4324 root_src_dir
= get_expanded_make_variable( top_makefile
, "srcdir" );
4325 tools_dir
= get_expanded_make_variable( top_makefile
, "toolsdir" );
4326 tools_ext
= get_expanded_make_variable( top_makefile
, "toolsext" );
4327 exe_ext
= get_expanded_make_variable( top_makefile
, "EXEEXT" );
4328 dll_ext
= (exe_ext
&& !strcmp( exe_ext
, ".exe" )) ? "" : ".so";
4329 host_cpu
= get_expanded_make_variable( top_makefile
, "host_cpu" );
4330 crosstarget
= get_expanded_make_variable( top_makefile
, "CROSSTARGET" );
4331 crossdebug
= get_expanded_make_variable( top_makefile
, "CROSSDEBUG" );
4332 fontforge
= get_expanded_make_variable( top_makefile
, "FONTFORGE" );
4333 convert
= get_expanded_make_variable( top_makefile
, "CONVERT" );
4334 flex
= get_expanded_make_variable( top_makefile
, "FLEX" );
4335 bison
= get_expanded_make_variable( top_makefile
, "BISON" );
4336 ar
= get_expanded_make_variable( top_makefile
, "AR" );
4337 ranlib
= get_expanded_make_variable( top_makefile
, "RANLIB" );
4338 rsvg
= get_expanded_make_variable( top_makefile
, "RSVG" );
4339 icotool
= get_expanded_make_variable( top_makefile
, "ICOTOOL" );
4340 dlltool
= get_expanded_make_variable( top_makefile
, "DLLTOOL" );
4341 msgfmt
= get_expanded_make_variable( top_makefile
, "MSGFMT" );
4342 sed_cmd
= get_expanded_make_variable( top_makefile
, "SED_CMD" );
4343 ln_s
= get_expanded_make_variable( top_makefile
, "LN_S" );
4345 if (root_src_dir
&& !strcmp( root_src_dir
, "." )) root_src_dir
= NULL
;
4346 if (tools_dir
&& !strcmp( tools_dir
, "." )) tools_dir
= NULL
;
4347 if (!exe_ext
) exe_ext
= "";
4348 if (!tools_ext
) tools_ext
= "";
4349 if (host_cpu
&& (host_cpu
= normalize_arch( host_cpu
)))
4351 so_dir
= strmake( "$(dlldir)/%s-unix", host_cpu
);
4352 pe_dir
= strmake( "$(dlldir)/%s-windows", host_cpu
);
4355 so_dir
= pe_dir
= "$(dlldir)";
4357 extra_cflags_extlib
= remove_warning_flags( extra_cflags
);
4358 extra_cross_cflags_extlib
= remove_warning_flags( extra_cross_cflags
);
4360 top_makefile
->src_dir
= root_src_dir
;
4361 subdirs
= get_expanded_make_var_array( top_makefile
, "SUBDIRS" );
4362 disabled_dirs
= get_expanded_make_var_array( top_makefile
, "DISABLED_SUBDIRS" );
4363 submakes
= xmalloc( subdirs
.count
* sizeof(*submakes
) );
4365 for (i
= 0; i
< subdirs
.count
; i
++) submakes
[i
] = parse_makefile( subdirs
.str
[i
] );
4367 load_sources( top_makefile
);
4368 for (i
= 0; i
< subdirs
.count
; i
++) load_sources( submakes
[i
] );
4370 output_dependencies( top_makefile
);
4371 for (i
= 0; i
< subdirs
.count
; i
++) output_dependencies( submakes
[i
] );