2 * Generate include file dependencies
4 * Copyright 1996, 2013 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
22 #define NO_LIBWINE_PORT
23 #include "wine/port.h"
36 #include "wine/list.h"
40 unsigned int count
; /* strings in use */
41 unsigned int size
; /* total allocated size */
47 INCL_NORMAL
, /* #include "foo.h" */
48 INCL_SYSTEM
, /* #include <foo.h> */
49 INCL_IMPORT
, /* idl import "foo.idl" */
50 INCL_IMPORTLIB
, /* idl importlib "foo.tlb" */
51 INCL_CPP_QUOTE
, /* idl cpp_quote("#include \"foo.h\"") */
52 INCL_CPP_QUOTE_SYSTEM
/* idl cpp_quote("#include <foo.h>") */
57 int line
; /* source line where this header is included */
58 enum incl_type type
; /* type of include */
59 char *name
; /* header name */
65 char *name
; /* full file name relative to cwd */
66 void *args
; /* custom arguments for makefile rule */
67 unsigned int flags
; /* flags (see below) */
68 unsigned int deps_count
; /* files in use */
69 unsigned int deps_size
; /* total allocated size */
70 struct dependency
*deps
; /* all header dependencies */
79 char *sourcename
; /* source file name for generated headers */
80 struct incl_file
*included_by
; /* file that included this one */
81 int included_line
; /* line where this file was included */
82 enum incl_type type
; /* type of include */
83 int use_msvcrt
; /* put msvcrt headers in the search path? */
84 struct incl_file
*owner
;
85 unsigned int files_count
; /* files in use */
86 unsigned int files_size
; /* total allocated size */
87 struct incl_file
**files
;
88 struct strarray dependencies
; /* file dependencies */
91 #define FLAG_GENERATED 0x000001 /* generated file */
92 #define FLAG_INSTALL 0x000002 /* file to install */
93 #define FLAG_PARENTDIR 0x000004 /* file comes from parent dir */
94 #define FLAG_IDL_PROXY 0x000100 /* generates a proxy (_p.c) file */
95 #define FLAG_IDL_CLIENT 0x000200 /* generates a client (_c.c) file */
96 #define FLAG_IDL_SERVER 0x000400 /* generates a server (_s.c) file */
97 #define FLAG_IDL_IDENT 0x000800 /* generates an ident (_i.c) file */
98 #define FLAG_IDL_REGISTER 0x001000 /* generates a registration (_r.res) file */
99 #define FLAG_IDL_TYPELIB 0x002000 /* generates a typelib (.tlb) file */
100 #define FLAG_IDL_REGTYPELIB 0x004000 /* generates a registered typelib (_t.res) file */
101 #define FLAG_IDL_HEADER 0x008000 /* generates a header (.h) file */
102 #define FLAG_RC_PO 0x010000 /* rc file contains translations */
103 #define FLAG_C_IMPLIB 0x020000 /* file is part of an import library */
104 #define FLAG_C_UNIX 0x040000 /* file is part of a Unix library */
105 #define FLAG_SFD_FONTS 0x080000 /* sfd file generated bitmap fonts */
113 { FLAG_IDL_TYPELIB
, ".tlb" },
114 { FLAG_IDL_REGTYPELIB
, "_t.res" },
115 { FLAG_IDL_CLIENT
, "_c.c" },
116 { FLAG_IDL_IDENT
, "_i.c" },
117 { FLAG_IDL_PROXY
, "_p.c" },
118 { FLAG_IDL_SERVER
, "_s.c" },
119 { FLAG_IDL_REGISTER
, "_r.res" },
120 { FLAG_IDL_HEADER
, ".h" }
123 #define HASH_SIZE 997
125 static struct list files
[HASH_SIZE
];
127 static const struct strarray empty_strarray
;
129 enum install_rules
{ INSTALL_LIB
, INSTALL_DEV
, NB_INSTALL_RULES
};
131 /* variables common to all makefiles */
132 static struct strarray linguas
;
133 static struct strarray dll_flags
;
134 static struct strarray target_flags
;
135 static struct strarray msvcrt_flags
;
136 static struct strarray extra_cflags
;
137 static struct strarray extra_cross_cflags
;
138 static struct strarray cpp_flags
;
139 static struct strarray lddll_flags
;
140 static struct strarray libs
;
141 static struct strarray enable_tests
;
142 static struct strarray cmdline_vars
;
143 static struct strarray disabled_dirs
;
144 static struct strarray cross_import_libs
;
145 static struct strarray delay_import_libs
;
146 static struct strarray top_install_lib
;
147 static struct strarray top_install_dev
;
148 static const char *root_src_dir
;
149 static const char *tools_dir
;
150 static const char *tools_ext
;
151 static const char *exe_ext
;
152 static const char *dll_ext
;
153 static const char *man_ext
;
154 static const char *crosstarget
;
155 static const char *fontforge
;
156 static const char *convert
;
157 static const char *flex
;
158 static const char *bison
;
159 static const char *ar
;
160 static const char *ranlib
;
161 static const char *rsvg
;
162 static const char *icotool
;
163 static const char *dlltool
;
164 static const char *msgfmt
;
165 static const char *ln_s
;
166 static const char *sed_cmd
;
167 static const char *delay_load_flag
;
171 /* values determined from input makefile */
172 struct strarray vars
;
173 struct strarray include_paths
;
174 struct strarray include_args
;
175 struct strarray define_args
;
176 struct strarray programs
;
177 struct strarray scripts
;
178 struct strarray imports
;
179 struct strarray subdirs
;
180 struct strarray delayimports
;
181 struct strarray extradllflags
;
182 struct strarray install_lib
;
183 struct strarray install_dev
;
184 struct strarray extra_targets
;
186 struct list includes
;
187 const char *base_dir
;
190 const char *top_src_dir
;
191 const char *top_obj_dir
;
192 const char *parent_dir
;
195 const char *sharedlib
;
196 const char *staticlib
;
197 const char *staticimplib
;
198 const char *importlib
;
204 struct makefile
**submakes
;
206 /* values generated at output time */
207 struct strarray in_files
;
208 struct strarray ok_files
;
209 struct strarray clean_files
;
210 struct strarray distclean_files
;
211 struct strarray uninstall_files
;
212 struct strarray object_files
;
213 struct strarray crossobj_files
;
214 struct strarray unixobj_files
;
215 struct strarray res_files
;
216 struct strarray c2man_files
;
217 struct strarray dlldata_files
;
218 struct strarray implib_objs
;
219 struct strarray all_targets
;
220 struct strarray phony_targets
;
221 struct strarray dependencies
;
222 struct strarray install_rules
[NB_INSTALL_RULES
];
225 static struct makefile
*top_makefile
;
227 static const char separator
[] = "### Dependencies";
228 static const char *output_makefile_name
= "Makefile";
229 static const char *input_file_name
;
230 static const char *output_file_name
;
231 static const char *temp_file_name
;
232 static int relative_dir_mode
;
233 static int input_line
;
234 static int output_column
;
235 static FILE *output_file
;
237 static const char Usage
[] =
238 "Usage: makedep [options] [directories]\n"
240 " -R from to Compute the relative path between two directories\n"
241 " -fxxx Store output in file 'xxx' (default: Makefile)\n";
245 #define __attribute__(x)
248 static void fatal_error( const char *msg
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
249 static void fatal_perror( const char *msg
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
250 static void output( const char *format
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
251 static char *strmake( const char* fmt
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
253 /*******************************************************************
256 static void fatal_error( const char *msg
, ... )
259 va_start( valist
, msg
);
262 fprintf( stderr
, "%s:", input_file_name
);
263 if (input_line
) fprintf( stderr
, "%d:", input_line
);
264 fprintf( stderr
, " error: " );
266 else fprintf( stderr
, "makedep: error: " );
267 vfprintf( stderr
, msg
, valist
);
273 /*******************************************************************
276 static void fatal_perror( const char *msg
, ... )
279 va_start( valist
, msg
);
282 fprintf( stderr
, "%s:", input_file_name
);
283 if (input_line
) fprintf( stderr
, "%d:", input_line
);
284 fprintf( stderr
, " error: " );
286 else fprintf( stderr
, "makedep: error: " );
287 vfprintf( stderr
, msg
, valist
);
294 /*******************************************************************
297 static void cleanup_files(void)
299 if (temp_file_name
) unlink( temp_file_name
);
300 if (output_file_name
) unlink( output_file_name
);
304 /*******************************************************************
307 static void exit_on_signal( int sig
)
309 exit( 1 ); /* this will call the atexit functions */
313 /*******************************************************************
316 static void *xmalloc( size_t size
)
319 if (!(res
= malloc (size
? size
: 1)))
320 fatal_error( "Virtual memory exhausted.\n" );
325 /*******************************************************************
328 static void *xrealloc (void *ptr
, size_t size
)
332 if (!(res
= realloc( ptr
, size
)))
333 fatal_error( "Virtual memory exhausted.\n" );
337 /*******************************************************************
340 static char *xstrdup( const char *str
)
342 char *res
= strdup( str
);
343 if (!res
) fatal_error( "Virtual memory exhausted.\n" );
348 /*******************************************************************
351 static char *strmake( const char* fmt
, ... )
359 char *p
= xmalloc (size
);
361 n
= vsnprintf (p
, size
, fmt
, ap
);
363 if (n
== -1) size
*= 2;
364 else if ((size_t)n
>= size
) size
= n
+ 1;
365 else return xrealloc( p
, n
+ 1 );
371 /*******************************************************************
374 static int strendswith( const char* str
, const char* end
)
376 size_t l
= strlen( str
);
377 size_t m
= strlen( end
);
379 return l
>= m
&& strcmp(str
+ l
- m
, end
) == 0;
383 /*******************************************************************
386 static void output( const char *format
, ... )
391 va_start( valist
, format
);
392 ret
= vfprintf( output_file
, format
, valist
);
394 if (ret
< 0) fatal_perror( "output" );
395 if (format
[0] && format
[strlen(format
) - 1] == '\n') output_column
= 0;
396 else output_column
+= ret
;
400 /*******************************************************************
403 static void strarray_add( struct strarray
*array
, const char *str
)
405 if (array
->count
== array
->size
)
407 if (array
->size
) array
->size
*= 2;
408 else array
->size
= 16;
409 array
->str
= xrealloc( array
->str
, sizeof(array
->str
[0]) * array
->size
);
411 array
->str
[array
->count
++] = str
;
415 /*******************************************************************
418 static void strarray_addall( struct strarray
*array
, struct strarray added
)
422 for (i
= 0; i
< added
.count
; i
++) strarray_add( array
, added
.str
[i
] );
426 /*******************************************************************
429 static int strarray_exists( const struct strarray
*array
, const char *str
)
433 for (i
= 0; i
< array
->count
; i
++) if (!strcmp( array
->str
[i
], str
)) return 1;
438 /*******************************************************************
441 static void strarray_add_uniq( struct strarray
*array
, const char *str
)
443 if (!strarray_exists( array
, str
)) strarray_add( array
, str
);
447 /*******************************************************************
448 * strarray_addall_uniq
450 static void strarray_addall_uniq( struct strarray
*array
, struct strarray added
)
454 for (i
= 0; i
< added
.count
; i
++) strarray_add_uniq( array
, added
.str
[i
] );
458 /*******************************************************************
461 * Find a value in a name/value pair string array.
463 static const char *strarray_get_value( const struct strarray
*array
, const char *name
)
465 int pos
, res
, min
= 0, max
= array
->count
/ 2 - 1;
469 pos
= (min
+ max
) / 2;
470 if (!(res
= strcmp( array
->str
[pos
* 2], name
))) return array
->str
[pos
* 2 + 1];
471 if (res
< 0) min
= pos
+ 1;
478 /*******************************************************************
481 * Define a value in a name/value pair string array.
483 static void strarray_set_value( struct strarray
*array
, const char *name
, const char *value
)
485 int i
, pos
, res
, min
= 0, max
= array
->count
/ 2 - 1;
489 pos
= (min
+ max
) / 2;
490 if (!(res
= strcmp( array
->str
[pos
* 2], name
)))
492 /* redefining a variable replaces the previous value */
493 array
->str
[pos
* 2 + 1] = value
;
496 if (res
< 0) min
= pos
+ 1;
499 strarray_add( array
, NULL
);
500 strarray_add( array
, NULL
);
501 for (i
= array
->count
- 1; i
> min
* 2 + 1; i
--) array
->str
[i
] = array
->str
[i
- 2];
502 array
->str
[min
* 2] = name
;
503 array
->str
[min
* 2 + 1] = value
;
507 /*******************************************************************
510 static void strarray_qsort( struct strarray
*array
, int (*func
)(const char **, const char **) )
512 if (array
->count
) qsort( array
->str
, array
->count
, sizeof(*array
->str
), (void *)func
);
516 /*******************************************************************
519 static void output_filename( const char *name
)
521 if (output_column
+ strlen(name
) + 1 > 100)
526 else if (output_column
) output( " " );
527 output( "%s", name
);
531 /*******************************************************************
534 static void output_filenames( struct strarray array
)
538 for (i
= 0; i
< array
.count
; i
++) output_filename( array
.str
[i
] );
542 /*******************************************************************
543 * output_rm_filenames
545 static void output_rm_filenames( struct strarray array
)
547 static const unsigned int max_cmdline
= 30000; /* to be on the safe side */
550 if (!array
.count
) return;
552 for (i
= len
= 0; i
< array
.count
; i
++)
554 if (len
> max_cmdline
)
560 output_filename( array
.str
[i
] );
561 len
+= strlen( array
.str
[i
] ) + 1;
567 /*******************************************************************
570 static char *get_extension( char *filename
)
572 char *ext
= strrchr( filename
, '.' );
573 if (ext
&& strchr( ext
, '/' )) ext
= NULL
;
578 /*******************************************************************
581 static const char *get_base_name( const char *name
)
584 if (!strchr( name
, '.' )) return name
;
585 base
= strdup( name
);
586 *strrchr( base
, '.' ) = 0;
591 /*******************************************************************
594 static char *replace_extension( const char *name
, const char *old_ext
, const char *new_ext
)
597 size_t name_len
= strlen( name
);
598 size_t ext_len
= strlen( old_ext
);
600 if (name_len
>= ext_len
&& !strcmp( name
+ name_len
- ext_len
, old_ext
)) name_len
-= ext_len
;
601 ret
= xmalloc( name_len
+ strlen( new_ext
) + 1 );
602 memcpy( ret
, name
, name_len
);
603 strcpy( ret
+ name_len
, new_ext
);
608 /*******************************************************************
611 static char *replace_filename( const char *path
, const char *name
)
617 if (!path
) return xstrdup( name
);
618 if (!(p
= strrchr( path
, '/' ))) return xstrdup( name
);
620 ret
= xmalloc( len
+ strlen( name
) + 1 );
621 memcpy( ret
, path
, len
);
622 strcpy( ret
+ len
, name
);
627 /*******************************************************************
628 * strarray_replace_extension
630 static struct strarray
strarray_replace_extension( const struct strarray
*array
,
631 const char *old_ext
, const char *new_ext
)
636 ret
.count
= ret
.size
= array
->count
;
637 ret
.str
= xmalloc( sizeof(ret
.str
[0]) * ret
.size
);
638 for (i
= 0; i
< array
->count
; i
++) ret
.str
[i
] = replace_extension( array
->str
[i
], old_ext
, new_ext
);
643 /*******************************************************************
646 static char *replace_substr( const char *str
, const char *start
, size_t len
, const char *replace
)
648 size_t pos
= start
- str
;
649 char *ret
= xmalloc( pos
+ strlen(replace
) + strlen(start
+ len
) + 1 );
650 memcpy( ret
, str
, pos
);
651 strcpy( ret
+ pos
, replace
);
652 strcat( ret
+ pos
, start
+ len
);
657 /*******************************************************************
660 * Determine where the destination path is located relative to the 'from' path.
662 static char *get_relative_path( const char *from
, const char *dest
)
666 unsigned int dotdots
= 0;
668 /* a path of "." is equivalent to an empty path */
669 if (!strcmp( from
, "." )) from
= "";
673 while (*from
== '/') from
++;
674 while (*dest
== '/') dest
++;
675 start
= dest
; /* save start of next path element */
678 while (*from
&& *from
!= '/' && *from
== *dest
) { from
++; dest
++; }
679 if ((!*from
|| *from
== '/') && (!*dest
|| *dest
== '/')) continue;
681 /* count remaining elements in 'from' */
685 while (*from
&& *from
!= '/') from
++;
686 while (*from
== '/') from
++;
692 if (!start
[0] && !dotdots
) return NULL
; /* empty path */
694 ret
= xmalloc( 3 * dotdots
+ strlen( start
) + 1 );
695 for (p
= ret
; dotdots
; dotdots
--, p
+= 3) memcpy( p
, "../", 3 );
697 if (start
[0]) strcpy( p
, start
);
698 else p
[-1] = 0; /* remove trailing slash */
703 /*******************************************************************
706 static char *concat_paths( const char *base
, const char *path
)
708 if (!base
|| !base
[0]) return xstrdup( path
&& path
[0] ? path
: "." );
709 if (!path
|| !path
[0]) return xstrdup( base
);
710 if (path
[0] == '/') return xstrdup( path
);
711 return strmake( "%s/%s", base
, path
);
715 /*******************************************************************
718 static char *base_dir_path( const struct makefile
*make
, const char *path
)
720 return concat_paths( make
->base_dir
, path
);
724 /*******************************************************************
727 static char *obj_dir_path( const struct makefile
*make
, const char *path
)
729 return concat_paths( make
->obj_dir
, path
);
733 /*******************************************************************
736 static char *src_dir_path( const struct makefile
*make
, const char *path
)
738 if (make
->src_dir
) return concat_paths( make
->src_dir
, path
);
739 return obj_dir_path( make
, path
);
743 /*******************************************************************
746 static char *top_obj_dir_path( const struct makefile
*make
, const char *path
)
748 return concat_paths( make
->top_obj_dir
, path
);
752 /*******************************************************************
755 static char *top_src_dir_path( const struct makefile
*make
, const char *path
)
757 if (make
->top_src_dir
) return concat_paths( make
->top_src_dir
, path
);
758 return top_obj_dir_path( make
, path
);
762 /*******************************************************************
765 static char *root_dir_path( const char *path
)
767 return concat_paths( root_src_dir
, path
);
771 /*******************************************************************
774 static char *tools_dir_path( const struct makefile
*make
, const char *path
)
776 if (tools_dir
) return top_obj_dir_path( make
, strmake( "%s/tools/%s", tools_dir
, path
));
777 return top_obj_dir_path( make
, strmake( "tools/%s", path
));
781 /*******************************************************************
784 static char *tools_path( const struct makefile
*make
, const char *name
)
786 return strmake( "%s/%s%s", tools_dir_path( make
, name
), name
, tools_ext
);
790 /*******************************************************************
793 static char *get_line( FILE *file
)
801 buffer
= xmalloc( size
);
803 if (!fgets( buffer
, size
, file
)) return NULL
;
808 char *p
= buffer
+ strlen(buffer
);
809 /* if line is larger than buffer, resize buffer */
810 while (p
== buffer
+ size
- 1 && p
[-1] != '\n')
812 buffer
= xrealloc( buffer
, size
* 2 );
813 if (!fgets( buffer
+ size
- 1, size
+ 1, file
)) break;
814 p
= buffer
+ strlen(buffer
);
817 if (p
> buffer
&& p
[-1] == '\n')
820 if (p
> buffer
&& p
[-1] == '\r') *(--p
) = 0;
821 if (p
> buffer
&& p
[-1] == '\\')
824 /* line ends in backslash, read continuation line */
825 if (!fgets( p
, size
- (p
- buffer
), file
)) return buffer
;
835 /*******************************************************************
838 static unsigned int hash_filename( const char *name
)
841 unsigned int ret
= 2166136261u;
842 while (*name
) ret
= (ret
* 16777619) ^ *name
++;
843 return ret
% HASH_SIZE
;
847 /*******************************************************************
850 static struct file
*add_file( const char *name
)
852 struct file
*file
= xmalloc( sizeof(*file
) );
853 memset( file
, 0, sizeof(*file
) );
854 file
->name
= xstrdup( name
);
859 /*******************************************************************
862 static void add_dependency( struct file
*file
, const char *name
, enum incl_type type
)
864 /* enforce some rules for the Wine tree */
866 if (!memcmp( name
, "../", 3 ))
867 fatal_error( "#include directive with relative path not allowed\n" );
869 if (!strcmp( name
, "config.h" ))
871 if (strendswith( file
->name
, ".h" ))
872 fatal_error( "config.h must not be included by a header file\n" );
873 if (file
->deps_count
)
874 fatal_error( "config.h must be included before anything else\n" );
876 else if (!strcmp( name
, "wine/port.h" ))
878 if (strendswith( file
->name
, ".h" ))
879 fatal_error( "wine/port.h must not be included by a header file\n" );
880 if (!file
->deps_count
) fatal_error( "config.h must be included before wine/port.h\n" );
881 if (file
->deps_count
> 1)
882 fatal_error( "wine/port.h must be included before everything except config.h\n" );
883 if (strcmp( file
->deps
[0].name
, "config.h" ))
884 fatal_error( "config.h must be included before wine/port.h\n" );
887 if (file
->deps_count
>= file
->deps_size
)
889 file
->deps_size
*= 2;
890 if (file
->deps_size
< 16) file
->deps_size
= 16;
891 file
->deps
= xrealloc( file
->deps
, file
->deps_size
* sizeof(*file
->deps
) );
893 file
->deps
[file
->deps_count
].line
= input_line
;
894 file
->deps
[file
->deps_count
].type
= type
;
895 file
->deps
[file
->deps_count
].name
= xstrdup( name
);
900 /*******************************************************************
903 static struct incl_file
*find_src_file( const struct makefile
*make
, const char *name
)
905 struct incl_file
*file
;
907 LIST_FOR_EACH_ENTRY( file
, &make
->sources
, struct incl_file
, entry
)
908 if (!strcmp( name
, file
->name
)) return file
;
912 /*******************************************************************
915 static struct incl_file
*find_include_file( const struct makefile
*make
, const char *name
)
917 struct incl_file
*file
;
919 LIST_FOR_EACH_ENTRY( file
, &make
->includes
, struct incl_file
, entry
)
920 if (!strcmp( name
, file
->name
)) return file
;
924 /*******************************************************************
927 * Add an include file if it doesn't already exists.
929 static struct incl_file
*add_include( struct makefile
*make
, struct incl_file
*parent
,
930 const char *name
, int line
, enum incl_type type
)
932 struct incl_file
*include
;
934 if (parent
->files_count
>= parent
->files_size
)
936 parent
->files_size
*= 2;
937 if (parent
->files_size
< 16) parent
->files_size
= 16;
938 parent
->files
= xrealloc( parent
->files
, parent
->files_size
* sizeof(*parent
->files
) );
941 LIST_FOR_EACH_ENTRY( include
, &make
->includes
, struct incl_file
, entry
)
942 if (!parent
->use_msvcrt
== !include
->use_msvcrt
&& !strcmp( name
, include
->name
))
945 include
= xmalloc( sizeof(*include
) );
946 memset( include
, 0, sizeof(*include
) );
947 include
->name
= xstrdup(name
);
948 include
->included_by
= parent
;
949 include
->included_line
= line
;
950 include
->type
= type
;
951 include
->use_msvcrt
= parent
->use_msvcrt
;
952 list_add_tail( &make
->includes
, &include
->entry
);
954 parent
->files
[parent
->files_count
++] = include
;
959 /*******************************************************************
960 * add_generated_source
962 * Add a generated source file to the list.
964 static struct incl_file
*add_generated_source( struct makefile
*make
,
965 const char *name
, const char *filename
)
967 struct incl_file
*file
;
969 if ((file
= find_src_file( make
, name
))) return file
; /* we already have it */
970 file
= xmalloc( sizeof(*file
) );
971 memset( file
, 0, sizeof(*file
) );
972 file
->file
= add_file( name
);
973 file
->name
= xstrdup( name
);
974 file
->filename
= obj_dir_path( make
, filename
? filename
: name
);
975 file
->file
->flags
= FLAG_GENERATED
;
976 file
->use_msvcrt
= make
->use_msvcrt
;
977 list_add_tail( &make
->sources
, &file
->entry
);
982 /*******************************************************************
983 * parse_include_directive
985 static void parse_include_directive( struct file
*source
, char *str
)
987 char quote
, *include
, *p
= str
;
989 while (*p
&& isspace(*p
)) p
++;
990 if (*p
!= '\"' && *p
!= '<' ) return;
992 if (quote
== '<') quote
= '>';
994 while (*p
&& (*p
!= quote
)) p
++;
995 if (!*p
) fatal_error( "malformed include directive '%s'\n", str
);
997 add_dependency( source
, include
, (quote
== '>') ? INCL_SYSTEM
: INCL_NORMAL
);
1001 /*******************************************************************
1002 * parse_pragma_directive
1004 static void parse_pragma_directive( struct file
*source
, char *str
)
1006 char *flag
, *p
= str
;
1008 if (!isspace( *p
)) return;
1009 while (*p
&& isspace(*p
)) p
++;
1010 p
= strtok( p
, " \t" );
1011 if (strcmp( p
, "makedep" )) return;
1013 while ((flag
= strtok( NULL
, " \t" )))
1015 if (!strcmp( flag
, "depend" ))
1017 while ((p
= strtok( NULL
, " \t" ))) add_dependency( source
, p
, INCL_NORMAL
);
1020 else if (!strcmp( flag
, "install" )) source
->flags
|= FLAG_INSTALL
;
1022 if (strendswith( source
->name
, ".idl" ))
1024 if (!strcmp( flag
, "header" )) source
->flags
|= FLAG_IDL_HEADER
;
1025 else if (!strcmp( flag
, "proxy" )) source
->flags
|= FLAG_IDL_PROXY
;
1026 else if (!strcmp( flag
, "client" )) source
->flags
|= FLAG_IDL_CLIENT
;
1027 else if (!strcmp( flag
, "server" )) source
->flags
|= FLAG_IDL_SERVER
;
1028 else if (!strcmp( flag
, "ident" )) source
->flags
|= FLAG_IDL_IDENT
;
1029 else if (!strcmp( flag
, "typelib" )) source
->flags
|= FLAG_IDL_TYPELIB
;
1030 else if (!strcmp( flag
, "register" )) source
->flags
|= FLAG_IDL_REGISTER
;
1031 else if (!strcmp( flag
, "regtypelib" )) source
->flags
|= FLAG_IDL_REGTYPELIB
;
1033 else if (strendswith( source
->name
, ".rc" ))
1035 if (!strcmp( flag
, "po" )) source
->flags
|= FLAG_RC_PO
;
1037 else if (strendswith( source
->name
, ".sfd" ))
1039 if (!strcmp( flag
, "font" ))
1041 struct strarray
*array
= source
->args
;
1045 source
->args
= array
= xmalloc( sizeof(*array
) );
1046 *array
= empty_strarray
;
1047 source
->flags
|= FLAG_SFD_FONTS
;
1049 strarray_add( array
, xstrdup( strtok( NULL
, "" )));
1055 if (!strcmp( flag
, "implib" )) source
->flags
|= FLAG_C_IMPLIB
;
1056 if (!strcmp( flag
, "unix" )) source
->flags
|= FLAG_C_UNIX
;
1062 /*******************************************************************
1063 * parse_cpp_directive
1065 static void parse_cpp_directive( struct file
*source
, char *str
)
1067 while (*str
&& isspace(*str
)) str
++;
1068 if (*str
++ != '#') return;
1069 while (*str
&& isspace(*str
)) str
++;
1071 if (!strncmp( str
, "include", 7 ))
1072 parse_include_directive( source
, str
+ 7 );
1073 else if (!strncmp( str
, "import", 6 ) && strendswith( source
->name
, ".m" ))
1074 parse_include_directive( source
, str
+ 6 );
1075 else if (!strncmp( str
, "pragma", 6 ))
1076 parse_pragma_directive( source
, str
+ 6 );
1080 /*******************************************************************
1083 static void parse_idl_file( struct file
*source
, FILE *file
)
1085 char *buffer
, *include
;
1089 while ((buffer
= get_line( file
)))
1093 while (*p
&& isspace(*p
)) p
++;
1095 if (!strncmp( p
, "importlib", 9 ))
1098 while (*p
&& isspace(*p
)) p
++;
1099 if (*p
++ != '(') continue;
1100 while (*p
&& isspace(*p
)) p
++;
1101 if (*p
++ != '"') continue;
1103 while (*p
&& (*p
!= '"')) p
++;
1104 if (!*p
) fatal_error( "malformed importlib directive\n" );
1106 add_dependency( source
, include
, INCL_IMPORTLIB
);
1110 if (!strncmp( p
, "import", 6 ))
1113 while (*p
&& isspace(*p
)) p
++;
1114 if (*p
!= '"') continue;
1116 while (*p
&& (*p
!= '"')) p
++;
1117 if (!*p
) fatal_error( "malformed import directive\n" );
1119 add_dependency( source
, include
, INCL_IMPORT
);
1123 /* check for #include inside cpp_quote */
1124 if (!strncmp( p
, "cpp_quote", 9 ))
1127 while (*p
&& isspace(*p
)) p
++;
1128 if (*p
++ != '(') continue;
1129 while (*p
&& isspace(*p
)) p
++;
1130 if (*p
++ != '"') continue;
1131 if (*p
++ != '#') continue;
1132 while (*p
&& isspace(*p
)) p
++;
1133 if (strncmp( p
, "include", 7 )) continue;
1135 while (*p
&& isspace(*p
)) p
++;
1136 if (*p
== '\\' && p
[1] == '"')
1143 if (*p
++ != '<' ) continue;
1147 while (*p
&& (*p
!= quote
)) p
++;
1148 if (!*p
|| (quote
== '"' && p
[-1] != '\\'))
1149 fatal_error( "malformed #include directive inside cpp_quote\n" );
1150 if (quote
== '"') p
--; /* remove backslash */
1152 add_dependency( source
, include
, (quote
== '>') ? INCL_CPP_QUOTE_SYSTEM
: INCL_CPP_QUOTE
);
1156 parse_cpp_directive( source
, p
);
1160 /*******************************************************************
1163 static void parse_c_file( struct file
*source
, FILE *file
)
1168 while ((buffer
= get_line( file
)))
1170 parse_cpp_directive( source
, buffer
);
1175 /*******************************************************************
1178 static void parse_rc_file( struct file
*source
, FILE *file
)
1180 char *buffer
, *include
;
1183 while ((buffer
= get_line( file
)))
1187 while (*p
&& isspace(*p
)) p
++;
1189 if (p
[0] == '/' && p
[1] == '*') /* check for magic makedep comment */
1192 while (*p
&& isspace(*p
)) p
++;
1193 if (strncmp( p
, "@makedep:", 9 )) continue;
1195 while (*p
&& isspace(*p
)) p
++;
1200 while (*p
&& *p
!= quote
) p
++;
1205 while (*p
&& !isspace(*p
) && *p
!= '*') p
++;
1208 fatal_error( "malformed makedep comment\n" );
1210 add_dependency( source
, include
, (quote
== '>') ? INCL_SYSTEM
: INCL_NORMAL
);
1214 parse_cpp_directive( source
, buffer
);
1219 /*******************************************************************
1222 static void parse_in_file( struct file
*source
, FILE *file
)
1226 /* make sure it gets rebuilt when the version changes */
1227 add_dependency( source
, "config.h", INCL_SYSTEM
);
1229 if (!strendswith( source
->name
, ".man.in" )) return; /* not a man page */
1232 while ((buffer
= get_line( file
)))
1234 if (strncmp( buffer
, ".TH", 3 )) continue;
1235 if (!(p
= strtok( buffer
, " \t" ))) continue; /* .TH */
1236 if (!(p
= strtok( NULL
, " \t" ))) continue; /* program name */
1237 if (!(p
= strtok( NULL
, " \t" ))) continue; /* man section */
1238 source
->args
= xstrdup( p
);
1244 /*******************************************************************
1247 static void parse_sfd_file( struct file
*source
, FILE *file
)
1249 char *p
, *eol
, *buffer
;
1252 while ((buffer
= get_line( file
)))
1254 if (strncmp( buffer
, "UComments:", 10 )) continue;
1256 while (*p
== ' ') p
++;
1257 if (p
[0] == '"' && p
[1] && buffer
[strlen(buffer
) - 1] == '"')
1260 buffer
[strlen(buffer
) - 1] = 0;
1262 while ((eol
= strstr( p
, "+AAoA" )))
1265 while (*p
&& isspace(*p
)) p
++;
1268 while (*p
&& isspace(*p
)) p
++;
1269 if (!strncmp( p
, "pragma", 6 )) parse_pragma_directive( source
, p
+ 6 );
1273 while (*p
&& isspace(*p
)) p
++;
1274 if (*p
++ != '#') return;
1275 while (*p
&& isspace(*p
)) p
++;
1276 if (!strncmp( p
, "pragma", 6 )) parse_pragma_directive( source
, p
+ 6 );
1285 void (*parse
)( struct file
*file
, FILE *f
);
1286 } parse_functions
[] =
1288 { ".c", parse_c_file
},
1289 { ".h", parse_c_file
},
1290 { ".inl", parse_c_file
},
1291 { ".l", parse_c_file
},
1292 { ".m", parse_c_file
},
1293 { ".rh", parse_c_file
},
1294 { ".x", parse_c_file
},
1295 { ".y", parse_c_file
},
1296 { ".idl", parse_idl_file
},
1297 { ".rc", parse_rc_file
},
1298 { ".in", parse_in_file
},
1299 { ".sfd", parse_sfd_file
}
1302 /*******************************************************************
1305 static struct file
*load_file( const char *name
)
1309 unsigned int i
, hash
= hash_filename( name
);
1311 LIST_FOR_EACH_ENTRY( file
, &files
[hash
], struct file
, entry
)
1312 if (!strcmp( name
, file
->name
)) return file
;
1314 if (!(f
= fopen( name
, "r" ))) return NULL
;
1316 file
= add_file( name
);
1317 list_add_tail( &files
[hash
], &file
->entry
);
1318 input_file_name
= file
->name
;
1321 for (i
= 0; i
< sizeof(parse_functions
) / sizeof(parse_functions
[0]); i
++)
1323 if (!strendswith( name
, parse_functions
[i
].ext
)) continue;
1324 parse_functions
[i
].parse( file
, f
);
1329 input_file_name
= NULL
;
1335 /*******************************************************************
1336 * open_include_path_file
1338 * Open a file from a directory on the include path.
1340 static struct file
*open_include_path_file( const struct makefile
*make
, const char *dir
,
1341 const char *name
, char **filename
)
1343 char *src_path
= base_dir_path( make
, concat_paths( dir
, name
));
1344 struct file
*ret
= load_file( src_path
);
1346 if (ret
) *filename
= src_dir_path( make
, concat_paths( dir
, name
));
1351 /*******************************************************************
1352 * open_file_same_dir
1354 * Open a file in the same directory as the parent.
1356 static struct file
*open_file_same_dir( const struct incl_file
*parent
, const char *name
, char **filename
)
1358 char *src_path
= replace_filename( parent
->file
->name
, name
);
1359 struct file
*ret
= load_file( src_path
);
1361 if (ret
) *filename
= replace_filename( parent
->filename
, name
);
1367 /*******************************************************************
1370 * Open a file in the source directory of the makefile.
1372 static struct file
*open_local_file( const struct makefile
*make
, const char *path
, char **filename
)
1374 char *src_path
= root_dir_path( base_dir_path( make
, path
));
1375 struct file
*ret
= load_file( src_path
);
1377 /* if not found, try parent dir */
1378 if (!ret
&& make
->parent_dir
)
1381 path
= strmake( "%s/%s", make
->parent_dir
, path
);
1382 src_path
= root_dir_path( base_dir_path( make
, path
));
1383 ret
= load_file( src_path
);
1384 if (ret
) ret
->flags
|= FLAG_PARENTDIR
;
1387 if (ret
) *filename
= src_dir_path( make
, path
);
1393 /*******************************************************************
1396 * Open a file in the top-level source directory.
1398 static struct file
*open_global_file( const struct makefile
*make
, const char *path
, char **filename
)
1400 char *src_path
= root_dir_path( path
);
1401 struct file
*ret
= load_file( src_path
);
1403 if (ret
) *filename
= top_src_dir_path( make
, path
);
1409 /*******************************************************************
1410 * open_global_header
1412 * Open a file in the global include source directory.
1414 static struct file
*open_global_header( const struct makefile
*make
, const char *path
, char **filename
)
1416 return open_global_file( make
, strmake( "include/%s", path
), filename
);
1420 /*******************************************************************
1423 static struct file
*open_src_file( const struct makefile
*make
, struct incl_file
*pFile
)
1425 struct file
*file
= open_local_file( make
, pFile
->name
, &pFile
->filename
);
1427 if (!file
) fatal_perror( "open %s", pFile
->name
);
1432 /*******************************************************************
1435 static struct file
*open_include_file( const struct makefile
*make
, struct incl_file
*pFile
)
1437 struct file
*file
= NULL
;
1439 unsigned int i
, len
;
1443 /* check for generated bison header */
1445 if (strendswith( pFile
->name
, ".tab.h" ) &&
1446 (file
= open_local_file( make
, replace_extension( pFile
->name
, ".tab.h", ".y" ), &filename
)))
1448 pFile
->sourcename
= filename
;
1449 pFile
->filename
= obj_dir_path( make
, pFile
->name
);
1453 /* check for corresponding idl file in source dir */
1455 if (strendswith( pFile
->name
, ".h" ) &&
1456 (file
= open_local_file( make
, replace_extension( pFile
->name
, ".h", ".idl" ), &filename
)))
1458 pFile
->sourcename
= filename
;
1459 pFile
->filename
= obj_dir_path( make
, pFile
->name
);
1463 /* check for corresponding tlb file in source dir */
1465 if (strendswith( pFile
->name
, ".tlb" ) &&
1466 (file
= open_local_file( make
, replace_extension( pFile
->name
, ".tlb", ".idl" ), &filename
)))
1468 pFile
->sourcename
= filename
;
1469 pFile
->filename
= obj_dir_path( make
, pFile
->name
);
1473 /* check for extra targets */
1474 if (strarray_exists( &make
->extra_targets
, pFile
->name
))
1476 pFile
->sourcename
= filename
;
1477 pFile
->filename
= obj_dir_path( make
, pFile
->name
);
1481 /* now try in source dir */
1482 if ((file
= open_local_file( make
, pFile
->name
, &pFile
->filename
))) return file
;
1484 /* check for corresponding idl file in global includes */
1486 if (strendswith( pFile
->name
, ".h" ) &&
1487 (file
= open_global_header( make
, replace_extension( pFile
->name
, ".h", ".idl" ), &filename
)))
1489 pFile
->sourcename
= filename
;
1490 pFile
->filename
= top_obj_dir_path( make
, strmake( "include/%s", pFile
->name
));
1494 /* check for corresponding .in file in global includes (for config.h.in) */
1496 if (strendswith( pFile
->name
, ".h" ) &&
1497 (file
= open_global_header( make
, replace_extension( pFile
->name
, ".h", ".h.in" ), &filename
)))
1499 pFile
->sourcename
= filename
;
1500 pFile
->filename
= top_obj_dir_path( make
, strmake( "include/%s", pFile
->name
));
1504 /* check for corresponding .x file in global includes */
1506 if (strendswith( pFile
->name
, "tmpl.h" ) &&
1507 (file
= open_global_header( make
, replace_extension( pFile
->name
, ".h", ".x" ), &filename
)))
1509 pFile
->sourcename
= filename
;
1510 pFile
->filename
= top_obj_dir_path( make
, strmake( "include/%s", pFile
->name
));
1514 /* check for corresponding .tlb file in global includes */
1516 if (strendswith( pFile
->name
, ".tlb" ) &&
1517 (file
= open_global_header( make
, replace_extension( pFile
->name
, ".tlb", ".idl" ), &filename
)))
1519 pFile
->sourcename
= filename
;
1520 pFile
->filename
= top_obj_dir_path( make
, strmake( "include/%s", pFile
->name
));
1524 /* check in global includes source dir */
1526 if ((file
= open_global_header( make
, pFile
->name
, &pFile
->filename
))) return file
;
1528 /* check in global msvcrt includes */
1529 if (pFile
->use_msvcrt
&&
1530 (file
= open_global_header( make
, strmake( "msvcrt/%s", pFile
->name
), &pFile
->filename
)))
1533 /* now search in include paths */
1534 for (i
= 0; i
< make
->include_paths
.count
; i
++)
1536 const char *dir
= make
->include_paths
.str
[i
];
1537 const char *prefix
= make
->top_src_dir
? make
->top_src_dir
: make
->top_obj_dir
;
1541 len
= strlen( prefix
);
1542 if (!strncmp( dir
, prefix
, len
) && (!dir
[len
] || dir
[len
] == '/'))
1544 while (dir
[len
] == '/') len
++;
1545 file
= open_global_file( make
, concat_paths( dir
+ len
, pFile
->name
), &pFile
->filename
);
1546 if (file
) return file
;
1548 if (make
->top_src_dir
) continue; /* ignore paths that don't point to the top source dir */
1552 if ((file
= open_include_path_file( make
, dir
, pFile
->name
, &pFile
->filename
)))
1557 if (pFile
->type
== INCL_SYSTEM
&& pFile
->use_msvcrt
)
1559 if (!strcmp( pFile
->name
, "stdarg.h" )) return NULL
;
1560 fprintf( stderr
, "%s:%d: error: system header %s cannot be used with msvcrt\n",
1561 pFile
->included_by
->file
->name
, pFile
->included_line
, pFile
->name
);
1565 if (pFile
->type
== INCL_SYSTEM
) return NULL
; /* ignore system files we cannot find */
1567 /* try in src file directory */
1568 if ((file
= open_file_same_dir( pFile
->included_by
, pFile
->name
, &pFile
->filename
))) return file
;
1570 fprintf( stderr
, "%s:%d: error: ", pFile
->included_by
->file
->name
, pFile
->included_line
);
1571 perror( pFile
->name
);
1572 pFile
= pFile
->included_by
;
1573 while (pFile
&& pFile
->included_by
)
1575 const char *parent
= pFile
->included_by
->sourcename
;
1576 if (!parent
) parent
= pFile
->included_by
->file
->name
;
1577 fprintf( stderr
, "%s:%d: note: %s was first included here\n",
1578 parent
, pFile
->included_line
, pFile
->name
);
1579 pFile
= pFile
->included_by
;
1585 /*******************************************************************
1588 static void add_all_includes( struct makefile
*make
, struct incl_file
*parent
, struct file
*file
)
1592 parent
->files_count
= 0;
1593 parent
->files_size
= file
->deps_count
;
1594 parent
->files
= xmalloc( parent
->files_size
* sizeof(*parent
->files
) );
1595 for (i
= 0; i
< file
->deps_count
; i
++)
1597 switch (file
->deps
[i
].type
)
1601 add_include( make
, parent
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_NORMAL
);
1603 case INCL_IMPORTLIB
:
1604 add_include( make
, parent
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_IMPORTLIB
);
1607 add_include( make
, parent
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_SYSTEM
);
1609 case INCL_CPP_QUOTE
:
1610 case INCL_CPP_QUOTE_SYSTEM
:
1617 /*******************************************************************
1620 static void parse_file( struct makefile
*make
, struct incl_file
*source
, int src
)
1622 struct file
*file
= src
? open_src_file( make
, source
) : open_include_file( make
, source
);
1626 source
->file
= file
;
1627 source
->files_count
= 0;
1628 source
->files_size
= file
->deps_count
;
1629 source
->files
= xmalloc( source
->files_size
* sizeof(*source
->files
) );
1630 if (file
->flags
& FLAG_C_UNIX
) source
->use_msvcrt
= 0;
1631 else if (file
->flags
& FLAG_C_IMPLIB
) source
->use_msvcrt
= 1;
1633 if (source
->sourcename
)
1635 if (strendswith( source
->sourcename
, ".idl" ))
1639 if (strendswith( source
->name
, ".tlb" )) return; /* typelibs don't include anything */
1641 /* generated .h file always includes these */
1642 add_include( make
, source
, "rpc.h", 0, INCL_NORMAL
);
1643 add_include( make
, source
, "rpcndr.h", 0, INCL_NORMAL
);
1644 for (i
= 0; i
< file
->deps_count
; i
++)
1646 switch (file
->deps
[i
].type
)
1649 if (strendswith( file
->deps
[i
].name
, ".idl" ))
1650 add_include( make
, source
, replace_extension( file
->deps
[i
].name
, ".idl", ".h" ),
1651 file
->deps
[i
].line
, INCL_NORMAL
);
1653 add_include( make
, source
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_NORMAL
);
1655 case INCL_CPP_QUOTE
:
1656 add_include( make
, source
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_NORMAL
);
1658 case INCL_CPP_QUOTE_SYSTEM
:
1659 add_include( make
, source
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_SYSTEM
);
1663 case INCL_IMPORTLIB
:
1669 if (strendswith( source
->sourcename
, ".y" ))
1670 return; /* generated .tab.h doesn't include anything */
1673 add_all_includes( make
, source
, file
);
1677 /*******************************************************************
1680 * Add a source file to the list.
1682 static struct incl_file
*add_src_file( struct makefile
*make
, const char *name
)
1684 struct incl_file
*file
;
1686 if ((file
= find_src_file( make
, name
))) return file
; /* we already have it */
1687 file
= xmalloc( sizeof(*file
) );
1688 memset( file
, 0, sizeof(*file
) );
1689 file
->name
= xstrdup(name
);
1690 file
->use_msvcrt
= make
->use_msvcrt
;
1691 list_add_tail( &make
->sources
, &file
->entry
);
1692 parse_file( make
, file
, 1 );
1697 /*******************************************************************
1698 * open_input_makefile
1700 static FILE *open_input_makefile( const struct makefile
*make
)
1705 input_file_name
= root_dir_path( base_dir_path( make
, strmake( "%s.in", output_makefile_name
)));
1707 input_file_name
= output_makefile_name
; /* always use output name for main Makefile */
1710 if (!(ret
= fopen( input_file_name
, "r" ))) fatal_perror( "open" );
1715 /*******************************************************************
1718 static const char *get_make_variable( const struct makefile
*make
, const char *name
)
1722 if ((ret
= strarray_get_value( &cmdline_vars
, name
))) return ret
;
1723 if ((ret
= strarray_get_value( &make
->vars
, name
))) return ret
;
1724 if (top_makefile
&& (ret
= strarray_get_value( &top_makefile
->vars
, name
))) return ret
;
1729 /*******************************************************************
1730 * get_expanded_make_variable
1732 static char *get_expanded_make_variable( const struct makefile
*make
, const char *name
)
1735 char *p
, *end
, *expand
, *tmp
;
1737 var
= get_make_variable( make
, name
);
1738 if (!var
) return NULL
;
1740 p
= expand
= xstrdup( var
);
1741 while ((p
= strchr( p
, '$' )))
1745 if (!(end
= strchr( p
+ 2, ')' ))) fatal_error( "syntax error in '%s'\n", expand
);
1747 if (strchr( p
+ 2, ':' )) fatal_error( "pattern replacement not supported for '%s'\n", p
+ 2 );
1748 var
= get_make_variable( make
, p
+ 2 );
1749 tmp
= replace_substr( expand
, p
, end
- p
, var
? var
: "" );
1750 /* switch to the new string */
1751 p
= tmp
+ (p
- expand
);
1755 else if (p
[1] == '{') /* don't expand ${} variables */
1757 if (!(end
= strchr( p
+ 2, '}' ))) fatal_error( "syntax error in '%s'\n", expand
);
1760 else if (p
[1] == '$')
1764 else fatal_error( "syntax error in '%s'\n", expand
);
1767 /* consider empty variables undefined */
1769 while (*p
&& isspace(*p
)) p
++;
1770 if (*p
) return expand
;
1776 /*******************************************************************
1777 * get_expanded_make_var_array
1779 static struct strarray
get_expanded_make_var_array( const struct makefile
*make
, const char *name
)
1781 struct strarray ret
= empty_strarray
;
1782 char *value
, *token
;
1784 if ((value
= get_expanded_make_variable( make
, name
)))
1785 for (token
= strtok( value
, " \t" ); token
; token
= strtok( NULL
, " \t" ))
1786 strarray_add( &ret
, token
);
1791 /*******************************************************************
1792 * get_expanded_file_local_var
1794 static struct strarray
get_expanded_file_local_var( const struct makefile
*make
, const char *file
,
1797 char *p
, *var
= strmake( "%s_%s", file
, name
);
1799 for (p
= var
; *p
; p
++) if (!isalnum( *p
)) *p
= '_';
1800 return get_expanded_make_var_array( make
, var
);
1804 /*******************************************************************
1807 static int set_make_variable( struct strarray
*array
, const char *assignment
)
1811 p
= name
= xstrdup( assignment
);
1812 while (isalnum(*p
) || *p
== '_') p
++;
1813 if (name
== p
) return 0; /* not a variable */
1817 while (isspace(*p
)) p
++;
1819 if (*p
!= '=') return 0; /* not an assignment */
1821 while (isspace(*p
)) p
++;
1823 strarray_set_value( array
, name
, p
);
1828 /*******************************************************************
1831 static struct makefile
*parse_makefile( const char *path
)
1835 struct makefile
*make
= xmalloc( sizeof(*make
) );
1837 memset( make
, 0, sizeof(*make
) );
1840 make
->top_obj_dir
= get_relative_path( path
, "" );
1841 make
->base_dir
= path
;
1842 if (!strcmp( make
->base_dir
, "." )) make
->base_dir
= NULL
;
1845 file
= open_input_makefile( make
);
1846 while ((buffer
= get_line( file
)))
1848 if (!strncmp( buffer
, separator
, strlen(separator
) )) break;
1849 if (*buffer
== '\t') continue; /* command */
1850 while (isspace( *buffer
)) buffer
++;
1851 if (*buffer
== '#') continue; /* comment */
1852 set_make_variable( &make
->vars
, buffer
);
1855 input_file_name
= NULL
;
1860 /*******************************************************************
1861 * add_generated_sources
1863 static void add_generated_sources( struct makefile
*make
)
1866 struct incl_file
*source
, *next
, *file
;
1867 struct strarray objs
= get_expanded_make_var_array( make
, "EXTRA_OBJS" );
1869 LIST_FOR_EACH_ENTRY_SAFE( source
, next
, &make
->sources
, struct incl_file
, entry
)
1871 if (source
->file
->flags
& FLAG_IDL_CLIENT
)
1873 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_c.c" ), NULL
);
1874 add_dependency( file
->file
, replace_extension( source
->name
, ".idl", ".h" ), INCL_NORMAL
);
1875 add_all_includes( make
, file
, file
->file
);
1877 if (source
->file
->flags
& FLAG_IDL_SERVER
)
1879 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_s.c" ), NULL
);
1880 add_dependency( file
->file
, "wine/exception.h", INCL_NORMAL
);
1881 add_dependency( file
->file
, replace_extension( source
->name
, ".idl", ".h" ), INCL_NORMAL
);
1882 add_all_includes( make
, file
, file
->file
);
1884 if (source
->file
->flags
& FLAG_IDL_IDENT
)
1886 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_i.c" ), NULL
);
1887 add_dependency( file
->file
, "rpc.h", INCL_NORMAL
);
1888 add_dependency( file
->file
, "rpcndr.h", INCL_NORMAL
);
1889 add_dependency( file
->file
, "guiddef.h", INCL_NORMAL
);
1890 add_all_includes( make
, file
, file
->file
);
1892 if (source
->file
->flags
& FLAG_IDL_PROXY
)
1894 file
= add_generated_source( make
, "dlldata.o", "dlldata.c" );
1895 add_dependency( file
->file
, "objbase.h", INCL_NORMAL
);
1896 add_dependency( file
->file
, "rpcproxy.h", INCL_NORMAL
);
1897 add_all_includes( make
, file
, file
->file
);
1898 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_p.c" ), NULL
);
1899 add_dependency( file
->file
, "objbase.h", INCL_NORMAL
);
1900 add_dependency( file
->file
, "rpcproxy.h", INCL_NORMAL
);
1901 add_dependency( file
->file
, "wine/exception.h", INCL_NORMAL
);
1902 add_dependency( file
->file
, replace_extension( source
->name
, ".idl", ".h" ), INCL_NORMAL
);
1903 add_all_includes( make
, file
, file
->file
);
1905 if (source
->file
->flags
& FLAG_IDL_TYPELIB
)
1907 add_generated_source( make
, replace_extension( source
->name
, ".idl", ".tlb" ), NULL
);
1909 if (source
->file
->flags
& FLAG_IDL_REGTYPELIB
)
1911 add_generated_source( make
, replace_extension( source
->name
, ".idl", "_t.res" ), NULL
);
1913 if (source
->file
->flags
& FLAG_IDL_REGISTER
)
1915 add_generated_source( make
, replace_extension( source
->name
, ".idl", "_r.res" ), NULL
);
1917 if (source
->file
->flags
& FLAG_IDL_HEADER
)
1919 add_generated_source( make
, replace_extension( source
->name
, ".idl", ".h" ), NULL
);
1921 if (!source
->file
->flags
&& strendswith( source
->name
, ".idl" ))
1923 add_generated_source( make
, replace_extension( source
->name
, ".idl", ".h" ), NULL
);
1925 if (strendswith( source
->name
, ".x" ))
1927 add_generated_source( make
, replace_extension( source
->name
, ".x", ".h" ), NULL
);
1929 if (strendswith( source
->name
, ".y" ))
1931 file
= add_generated_source( make
, replace_extension( source
->name
, ".y", ".tab.c" ), NULL
);
1932 /* steal the includes list from the source file */
1933 file
->files_count
= source
->files_count
;
1934 file
->files_size
= source
->files_size
;
1935 file
->files
= source
->files
;
1936 source
->files_count
= source
->files_size
= 0;
1937 source
->files
= NULL
;
1939 if (strendswith( source
->name
, ".l" ))
1941 file
= add_generated_source( make
, replace_extension( source
->name
, ".l", ".yy.c" ), NULL
);
1942 /* steal the includes list from the source file */
1943 file
->files_count
= source
->files_count
;
1944 file
->files_size
= source
->files_size
;
1945 file
->files
= source
->files
;
1946 source
->files_count
= source
->files_size
= 0;
1947 source
->files
= NULL
;
1949 if (source
->file
->flags
& FLAG_C_IMPLIB
)
1951 if (!make
->staticimplib
&& make
->importlib
&& *dll_ext
)
1952 make
->staticimplib
= strmake( "lib%s.a", make
->importlib
);
1954 if (strendswith( source
->name
, ".po" ))
1956 if (!make
->disabled
)
1957 strarray_add_uniq( &linguas
, replace_extension( source
->name
, ".po", "" ));
1962 file
= add_generated_source( make
, "testlist.o", "testlist.c" );
1963 add_dependency( file
->file
, "wine/test.h", INCL_NORMAL
);
1964 add_all_includes( make
, file
, file
->file
);
1966 for (i
= 0; i
< objs
.count
; i
++)
1968 /* default to .c for unknown extra object files */
1969 if (strendswith( objs
.str
[i
], ".o" ))
1970 add_generated_source( make
, objs
.str
[i
], replace_extension( objs
.str
[i
], ".o", ".c" ));
1971 else if (strendswith( objs
.str
[i
], ".res" ))
1972 add_generated_source( make
, replace_extension( objs
.str
[i
], ".res", ".rc" ), NULL
);
1974 add_generated_source( make
, objs
.str
[i
], NULL
);
1979 /*******************************************************************
1982 static void create_dir( const char *dir
)
1986 p
= path
= xstrdup( dir
);
1987 while ((p
= strchr( p
, '/' )))
1990 if (mkdir( path
, 0755 ) == -1 && errno
!= EEXIST
) fatal_perror( "mkdir %s", path
);
1992 while (*p
== '/') p
++;
1994 if (mkdir( path
, 0755 ) == -1 && errno
!= EEXIST
) fatal_perror( "mkdir %s", path
);
1999 /*******************************************************************
2000 * create_file_directories
2002 * Create the base directories of all the files.
2004 static void create_file_directories( const struct makefile
*make
, struct strarray files
)
2006 struct strarray subdirs
= empty_strarray
;
2010 for (i
= 0; i
< files
.count
; i
++)
2012 if (!strchr( files
.str
[i
], '/' )) continue;
2013 dir
= base_dir_path( make
, files
.str
[i
] );
2014 *strrchr( dir
, '/' ) = 0;
2015 strarray_add_uniq( &subdirs
, dir
);
2018 for (i
= 0; i
< subdirs
.count
; i
++) create_dir( subdirs
.str
[i
] );
2022 /*******************************************************************
2023 * output_filenames_obj_dir
2025 static void output_filenames_obj_dir( const struct makefile
*make
, struct strarray array
)
2029 for (i
= 0; i
< array
.count
; i
++) output_filename( obj_dir_path( make
, array
.str
[i
] ));
2033 /*******************************************************************
2036 static void get_dependencies( struct incl_file
*file
, struct incl_file
*source
)
2040 if (!file
->filename
) return;
2044 if (file
->owner
== source
) return; /* already processed */
2045 if (file
->type
== INCL_IMPORTLIB
&&
2046 !(source
->file
->flags
& (FLAG_IDL_TYPELIB
| FLAG_IDL_REGTYPELIB
)))
2047 return; /* library is imported only when building a typelib */
2048 file
->owner
= source
;
2049 strarray_add( &source
->dependencies
, file
->filename
);
2051 for (i
= 0; i
< file
->files_count
; i
++) get_dependencies( file
->files
[i
], source
);
2055 /*******************************************************************
2056 * get_local_dependencies
2058 * Get the local dependencies of a given target.
2060 static struct strarray
get_local_dependencies( const struct makefile
*make
, const char *name
,
2061 struct strarray targets
)
2064 struct strarray deps
= get_expanded_file_local_var( make
, name
, "DEPS" );
2066 for (i
= 0; i
< deps
.count
; i
++)
2068 if (strarray_exists( &targets
, deps
.str
[i
] ))
2069 deps
.str
[i
] = obj_dir_path( make
, deps
.str
[i
] );
2071 deps
.str
[i
] = src_dir_path( make
, deps
.str
[i
] );
2077 /*******************************************************************
2080 * Check if makefile builds the named static library and return the full lib path.
2082 static const char *get_static_lib( const struct makefile
*make
, const char *name
)
2084 if (!make
->staticlib
) return NULL
;
2085 if (strncmp( make
->staticlib
, "lib", 3 )) return NULL
;
2086 if (strncmp( make
->staticlib
+ 3, name
, strlen(name
) )) return NULL
;
2087 if (strcmp( make
->staticlib
+ 3 + strlen(name
), ".a" )) return NULL
;
2088 return base_dir_path( make
, make
->staticlib
);
2092 /*******************************************************************
2093 * get_parent_makefile
2095 static struct makefile
*get_parent_makefile( struct makefile
*make
)
2100 if (!make
->base_dir
) return NULL
;
2101 dir
= xstrdup( make
->base_dir
);
2102 if (!(p
= strrchr( dir
, '/' ))) return NULL
;
2104 for (i
= 0; i
< top_makefile
->subdirs
.count
; i
++)
2105 if (!strcmp( top_makefile
->submakes
[i
]->base_dir
, dir
)) return top_makefile
->submakes
[i
];
2110 /*******************************************************************
2113 static int needs_cross_lib( const struct makefile
*make
)
2116 if (!crosstarget
) return 0;
2117 if (make
->importlib
) name
= make
->importlib
;
2118 else if (make
->staticlib
)
2120 name
= replace_extension( make
->staticlib
, ".a", "" );
2121 if (!strncmp( name
, "lib", 3 )) name
+= 3;
2124 if (strarray_exists( &cross_import_libs
, name
)) return 1;
2125 if (delay_load_flag
&& strarray_exists( &delay_import_libs
, name
)) return 1;
2130 /*******************************************************************
2133 static int needs_delay_lib( const struct makefile
*make
)
2135 if (delay_load_flag
) return 0;
2136 if (*dll_ext
&& !crosstarget
) return 0;
2137 if (!make
->importlib
) return 0;
2138 return strarray_exists( &delay_import_libs
, make
->importlib
);
2142 /*******************************************************************
2143 * add_default_libraries
2145 static struct strarray
add_default_libraries( const struct makefile
*make
, struct strarray
*deps
)
2147 struct strarray ret
= empty_strarray
;
2148 struct strarray all_libs
= empty_strarray
;
2151 if (!make
->use_msvcrt
) strarray_add( &all_libs
, "-lwine_port" );
2152 strarray_addall( &all_libs
, get_expanded_make_var_array( make
, "EXTRALIBS" ));
2153 strarray_addall( &all_libs
, libs
);
2155 for (i
= 0; i
< all_libs
.count
; i
++)
2157 const char *lib
= NULL
;
2159 if (!strncmp( all_libs
.str
[i
], "-l", 2 ))
2161 const char *name
= all_libs
.str
[i
] + 2;
2163 for (j
= 0; j
< top_makefile
->subdirs
.count
; j
++)
2165 const struct makefile
*submake
= top_makefile
->submakes
[j
];
2167 if ((lib
= get_static_lib( submake
, name
))) break;
2173 lib
= top_obj_dir_path( make
, lib
);
2174 strarray_add( deps
, lib
);
2175 strarray_add( &ret
, lib
);
2177 else strarray_add( &ret
, all_libs
.str
[i
] );
2183 /*******************************************************************
2186 static struct strarray
add_import_libs( const struct makefile
*make
, struct strarray
*deps
,
2187 struct strarray imports
, int delay
)
2189 struct strarray ret
= empty_strarray
;
2192 for (i
= 0; i
< imports
.count
; i
++)
2194 const char *name
= get_base_name( imports
.str
[i
] );
2195 const char *lib
= NULL
;
2197 /* skip module's own importlib, its object files will be linked directly */
2198 if (make
->importlib
&& !strcmp( make
->importlib
, imports
.str
[i
] )) continue;
2200 for (j
= 0; j
< top_makefile
->subdirs
.count
; j
++)
2202 const struct makefile
*submake
= top_makefile
->submakes
[j
];
2204 if (submake
->importlib
&& !strcmp( submake
->importlib
, name
))
2206 if (make
->is_cross
|| !*dll_ext
|| submake
->staticimplib
)
2207 lib
= base_dir_path( submake
, strmake( "lib%s.a", name
));
2209 strarray_add( deps
, top_obj_dir_path( make
,
2210 strmake( "%s/lib%s.def", submake
->base_dir
, name
)));
2214 if ((lib
= get_static_lib( submake
, name
))) break;
2219 if (delay
&& !delay_load_flag
) lib
= replace_extension( lib
, ".a", ".delay.a" );
2220 else if (make
->is_cross
) lib
= replace_extension( lib
, ".a", ".cross.a" );
2221 lib
= top_obj_dir_path( make
, lib
);
2222 strarray_add( deps
, lib
);
2223 strarray_add( &ret
, lib
);
2225 else strarray_add( &ret
, strmake( "-l%s", name
));
2231 /*******************************************************************
2232 * get_default_imports
2234 static struct strarray
get_default_imports( const struct makefile
*make
)
2236 struct strarray ret
= empty_strarray
;
2238 if (strarray_exists( &make
->extradllflags
, "-nodefaultlibs" )) return ret
;
2239 if (make
->use_msvcrt
) strarray_add( &ret
, "msvcrt" );
2240 strarray_add( &ret
, "winecrt0" );
2241 if (make
->is_win16
) strarray_add( &ret
, "kernel" );
2242 strarray_add( &ret
, "kernel32" );
2243 strarray_add( &ret
, "ntdll" );
2248 /*******************************************************************
2251 static void add_install_rule( struct makefile
*make
, const char *target
,
2252 const char *file
, const char *dest
)
2254 if (strarray_exists( &make
->install_lib
, target
) ||
2255 strarray_exists( &top_install_lib
, make
->base_dir
) ||
2256 strarray_exists( &top_install_lib
, base_dir_path( make
, target
)))
2258 strarray_add( &make
->install_rules
[INSTALL_LIB
], file
);
2259 strarray_add( &make
->install_rules
[INSTALL_LIB
], dest
);
2261 else if (strarray_exists( &make
->install_dev
, target
) ||
2262 strarray_exists( &top_install_dev
, make
->base_dir
) ||
2263 strarray_exists( &top_install_dev
, base_dir_path( make
, target
)))
2265 strarray_add( &make
->install_rules
[INSTALL_DEV
], file
);
2266 strarray_add( &make
->install_rules
[INSTALL_DEV
], dest
);
2271 /*******************************************************************
2272 * get_include_install_path
2274 * Determine the installation path for a given include file.
2276 static const char *get_include_install_path( const char *name
)
2278 if (!strncmp( name
, "wine/", 5 )) return name
+ 5;
2279 if (!strncmp( name
, "msvcrt/", 7 )) return name
;
2280 return strmake( "windows/%s", name
);
2284 /*******************************************************************
2285 * get_shared_library_name
2287 * Determine possible names for a shared library with a version number.
2289 static struct strarray
get_shared_lib_names( const char *libname
)
2291 struct strarray ret
= empty_strarray
;
2292 const char *ext
, *p
;
2293 char *name
, *first
, *second
;
2296 strarray_add( &ret
, libname
);
2298 for (p
= libname
; (p
= strchr( p
, '.' )); p
++)
2299 if ((len
= strspn( p
+ 1, "0123456789." ))) break;
2301 if (!len
) return ret
;
2303 if (*ext
&& ext
[-1] == '.') ext
--;
2305 /* keep only the first group of digits */
2306 name
= xstrdup( libname
);
2307 first
= name
+ (p
- libname
);
2308 if ((second
= strchr( first
+ 1, '.' )))
2310 strcpy( second
, ext
);
2311 strarray_add( &ret
, xstrdup( name
));
2313 /* now remove all digits */
2314 strcpy( first
, ext
);
2315 strarray_add( &ret
, name
);
2320 /*******************************************************************
2321 * get_source_defines
2323 static struct strarray
get_source_defines( struct makefile
*make
, struct incl_file
*source
,
2327 struct strarray ret
= empty_strarray
;
2329 strarray_addall( &ret
, make
->include_args
);
2330 if (source
->use_msvcrt
)
2331 strarray_add( &ret
, strmake( "-I%s", top_src_dir_path( make
, "include/msvcrt" )));
2332 for (i
= 0; i
< make
->include_paths
.count
; i
++)
2333 strarray_add( &ret
, strmake( "-I%s", obj_dir_path( make
, make
->include_paths
.str
[i
] )));
2334 strarray_addall( &ret
, make
->define_args
);
2335 strarray_addall( &ret
, get_expanded_file_local_var( make
, obj
, "EXTRADEFS" ));
2340 /*******************************************************************
2341 * output_winegcc_command
2343 static void output_winegcc_command( struct makefile
*make
)
2345 output( "\t%s -o $@", tools_path( make
, "winegcc" ));
2346 output_filename( "--wine-objdir" );
2347 output_filename( top_obj_dir_path( make
, "" ));
2350 output_filename( "--winebuild" );
2351 output_filename( tools_path( make
, "winebuild" ));
2355 output_filename( "-b" );
2356 output_filename( crosstarget
);
2357 output_filename( "--lib-suffix=.cross.a" );
2361 output_filenames( target_flags
);
2362 output_filenames( lddll_flags
);
2367 /*******************************************************************
2368 * output_symlink_rule
2370 * Output a rule to create a symlink.
2372 static void output_symlink_rule( const char *src_name
, const char *link_name
)
2376 output( "\trm -f %s && ", link_name
);
2378 /* dest path with a directory needs special handling if ln -s isn't supported */
2379 if (strcmp( ln_s
, "ln -s" ) && ((name
= strrchr( link_name
, '/' ))))
2381 char *dir
= xstrdup( link_name
);
2382 dir
[name
- link_name
] = 0;
2383 output( "cd %s && %s %s %s\n", *dir
? dir
: "/", ln_s
, src_name
, name
+ 1 );
2388 output( "%s %s %s\n", ln_s
, src_name
, link_name
);
2393 /*******************************************************************
2394 * output_srcdir_symlink
2396 * Output rule to create a symlink back to the source directory, for source files
2397 * that are needed at run-time.
2399 static void output_srcdir_symlink( struct makefile
*make
, const char *obj
)
2403 if (!make
->src_dir
) return;
2404 src_file
= src_dir_path( make
, obj
);
2405 output( "%s: %s\n", obj
, src_file
);
2406 output_symlink_rule( src_file
, obj
);
2407 strarray_add( &make
->all_targets
, obj
);
2411 /*******************************************************************
2412 * output_install_commands
2414 static void output_install_commands( struct makefile
*make
, const struct makefile
*submake
,
2415 struct strarray files
)
2418 char *install_sh
= top_src_dir_path( make
, "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 if (submake
) file
= base_dir_path( submake
, file
);
2426 switch (*files
.str
[i
+ 1])
2428 case 'c': /* cross-compiled program */
2429 output( "\tSTRIPPROG=%s-strip %s -m 644 $(INSTALL_PROGRAM_FLAGS) %s %s\n",
2430 crosstarget
, install_sh
, obj_dir_path( make
, file
), dest
);
2431 output( "\t%s --builtin %s\n", tools_path( make
, "winebuild" ), dest
);
2433 case 'd': /* data file */
2434 output( "\t%s -m 644 $(INSTALL_DATA_FLAGS) %s %s\n",
2435 install_sh
, obj_dir_path( make
, file
), dest
);
2437 case 'D': /* data file in source dir */
2438 output( "\t%s -m 644 $(INSTALL_DATA_FLAGS) %s %s\n",
2439 install_sh
, src_dir_path( make
, file
), dest
);
2441 case 'p': /* program file */
2442 output( "\tSTRIPPROG=\"$(STRIP)\" %s $(INSTALL_PROGRAM_FLAGS) %s %s\n",
2443 install_sh
, obj_dir_path( make
, file
), dest
);
2445 case 's': /* script */
2446 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s %s\n",
2447 install_sh
, obj_dir_path( make
, file
), dest
);
2449 case 'S': /* script in source dir */
2450 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s %s\n",
2451 install_sh
, src_dir_path( make
, file
), dest
);
2453 case 't': /* script in tools dir */
2454 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s %s\n",
2455 install_sh
, tools_dir_path( make
, files
.str
[i
] ), dest
);
2457 case 'y': /* symlink */
2458 output_symlink_rule( files
.str
[i
], dest
);
2463 strarray_add( &make
->uninstall_files
, dest
);
2468 /*******************************************************************
2469 * output_install_rules
2471 * Rules are stored as a (file,dest) pair of values.
2472 * The first char of dest indicates the type of install.
2474 static void output_install_rules( struct makefile
*make
, enum install_rules rules
, const char *target
)
2477 struct strarray files
= make
->install_rules
[rules
];
2478 struct strarray targets
= empty_strarray
;
2480 if (!files
.count
) return;
2482 for (i
= 0; i
< files
.count
; i
+= 2)
2484 const char *file
= files
.str
[i
];
2485 switch (*files
.str
[i
+ 1])
2487 case 'c': /* cross-compiled program */
2488 case 'd': /* data file */
2489 case 'p': /* program file */
2490 case 's': /* script */
2491 strarray_add_uniq( &targets
, obj_dir_path( make
, file
));
2493 case 't': /* script in tools dir */
2494 strarray_add_uniq( &targets
, tools_dir_path( make
, file
));
2499 output( "install %s::", target
);
2500 output_filenames( targets
);
2502 output_install_commands( make
, NULL
, files
);
2504 strarray_add_uniq( &make
->phony_targets
, "install" );
2505 strarray_add_uniq( &make
->phony_targets
, target
);
2509 static int cmp_string_length( const char **a
, const char **b
)
2511 int paths_a
= 0, paths_b
= 0;
2514 for (p
= *a
; *p
; p
++) if (*p
== '/') paths_a
++;
2515 for (p
= *b
; *p
; p
++) if (*p
== '/') paths_b
++;
2516 if (paths_b
!= paths_a
) return paths_b
- paths_a
;
2517 return strcmp( *a
, *b
);
2520 /*******************************************************************
2521 * output_uninstall_rules
2523 static void output_uninstall_rules( struct makefile
*make
)
2525 static const char *dirs_order
[] =
2526 { "$(includedir)", "$(mandir)", "$(fontdir)", "$(datadir)", "$(dlldir)" };
2528 struct strarray subdirs
= empty_strarray
;
2531 if (!make
->uninstall_files
.count
) return;
2532 output( "uninstall::\n" );
2533 output_rm_filenames( make
->uninstall_files
);
2534 strarray_add_uniq( &make
->phony_targets
, "uninstall" );
2536 if (!make
->subdirs
.count
) return;
2537 for (i
= 0; i
< make
->uninstall_files
.count
; i
++)
2539 char *dir
= xstrdup( make
->uninstall_files
.str
[i
] );
2540 while (strchr( dir
, '/' ))
2542 *strrchr( dir
, '/' ) = 0;
2543 strarray_add_uniq( &subdirs
, xstrdup(dir
) );
2546 strarray_qsort( &subdirs
, cmp_string_length
);
2547 output( "\t-rmdir" );
2548 for (i
= 0; i
< sizeof(dirs_order
)/sizeof(dirs_order
[0]); i
++)
2550 for (j
= 0; j
< subdirs
.count
; j
++)
2552 if (!subdirs
.str
[j
]) continue;
2553 if (strncmp( subdirs
.str
[j
] + strlen("$(DESTDIR)"), dirs_order
[i
], strlen(dirs_order
[i
]) ))
2555 output_filename( subdirs
.str
[j
] );
2556 subdirs
.str
[j
] = NULL
;
2559 for (j
= 0; j
< subdirs
.count
; j
++)
2560 if (subdirs
.str
[j
]) output_filename( subdirs
.str
[j
] );
2565 /*******************************************************************
2566 * output_importlib_symlinks
2568 static struct strarray
output_importlib_symlinks( const struct makefile
*parent
,
2569 const struct makefile
*make
)
2571 struct strarray ret
= empty_strarray
;
2572 const char *lib
, *dst
, *ext
[4];
2575 if (!make
->module
) return ret
;
2576 if (!make
->importlib
) return ret
;
2577 if (make
->is_win16
&& make
->disabled
) return ret
;
2578 if (strncmp( make
->base_dir
, "dlls/", 5 )) return ret
;
2579 if (!strcmp( make
->module
, make
->importlib
)) return ret
;
2580 if (!strchr( make
->importlib
, '.' ) &&
2581 !strncmp( make
->module
, make
->importlib
, strlen( make
->importlib
)) &&
2582 !strcmp( make
->module
+ strlen( make
->importlib
), ".dll" ))
2585 ext
[count
++] = *dll_ext
? "def" : "a";
2586 if (needs_delay_lib( make
)) ext
[count
++] = "delay.a";
2587 if (needs_cross_lib( make
)) ext
[count
++] = "cross.a";
2589 for (i
= 0; i
< count
; i
++)
2591 lib
= strmake( "lib%s.%s", make
->importlib
, ext
[i
] );
2592 dst
= concat_paths( obj_dir_path( parent
, "dlls" ), lib
);
2593 output( "%s: %s\n", dst
, base_dir_path( make
, lib
));
2594 output_symlink_rule( concat_paths( make
->base_dir
+ strlen("dlls/"), lib
), dst
);
2595 strarray_add( &ret
, dst
);
2601 /*******************************************************************
2604 static void output_po_files( const struct makefile
*make
)
2606 const char *po_dir
= src_dir_path( make
, "po" );
2607 struct strarray pot_files
= empty_strarray
;
2608 struct incl_file
*source
;
2611 for (i
= 0; i
< make
->subdirs
.count
; i
++)
2613 struct makefile
*submake
= make
->submakes
[i
];
2615 LIST_FOR_EACH_ENTRY( source
, &submake
->sources
, struct incl_file
, entry
)
2617 if (source
->file
->flags
& FLAG_PARENTDIR
) continue;
2618 if (strendswith( source
->name
, ".rc" ) && (source
->file
->flags
& FLAG_RC_PO
))
2620 char *pot_file
= replace_extension( source
->name
, ".rc", ".pot" );
2621 char *pot_path
= base_dir_path( submake
, pot_file
);
2622 output( "%s: tools/wrc include dummy\n", pot_path
);
2623 output( "\t@cd %s && $(MAKE) %s\n", base_dir_path( submake
, "" ), pot_file
);
2624 strarray_add( &pot_files
, pot_path
);
2626 else if (strendswith( source
->name
, ".mc" ))
2628 char *pot_file
= replace_extension( source
->name
, ".mc", ".pot" );
2629 char *pot_path
= base_dir_path( submake
, pot_file
);
2630 output( "%s: tools/wmc include dummy\n", pot_path
);
2631 output( "\t@cd %s && $(MAKE) %s\n", base_dir_path( submake
, "" ), pot_file
);
2632 strarray_add( &pot_files
, pot_path
);
2638 for (i
= 0; i
< linguas
.count
; i
++)
2639 output_filename( strmake( "%s/%s.po", po_dir
, linguas
.str
[i
] ));
2640 output( ": %s/wine.pot\n", po_dir
);
2641 output( "\tmsgmerge --previous -q $@ %s/wine.pot | msgattrib --no-obsolete -o $@.new && mv $@.new $@\n",
2644 for (i
= 0; i
< linguas
.count
; i
++)
2645 output_filename( strmake( "%s/%s.po", po_dir
, linguas
.str
[i
] ));
2648 output( "%s/wine.pot:", po_dir
);
2649 output_filenames( pot_files
);
2651 output( "\tmsgcat -o $@" );
2652 output_filenames( pot_files
);
2657 /*******************************************************************
2660 static void output_source_y( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2662 /* add source file dependency for parallel makes */
2663 char *header
= strmake( "%s.tab.h", obj
);
2665 if (find_include_file( make
, header
))
2667 output( "%s: %s\n", obj_dir_path( make
, header
), source
->filename
);
2668 output( "\t%s -p %s_ -o %s.tab.c -d %s\n",
2669 bison
, obj
, obj_dir_path( make
, obj
), source
->filename
);
2670 output( "%s.tab.c: %s %s\n", obj_dir_path( make
, obj
),
2671 source
->filename
, obj_dir_path( make
, header
));
2672 strarray_add( &make
->clean_files
, header
);
2674 else output( "%s.tab.c: %s\n", obj
, source
->filename
);
2676 output( "\t%s -p %s_ -o $@ %s\n", bison
, obj
, source
->filename
);
2680 /*******************************************************************
2683 static void output_source_l( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2685 output( "%s.yy.c: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2686 output( "\t%s -o$@ %s\n", flex
, source
->filename
);
2690 /*******************************************************************
2693 static void output_source_h( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2695 if (source
->file
->flags
& FLAG_GENERATED
)
2696 strarray_add( &make
->all_targets
, source
->name
);
2698 add_install_rule( make
, source
->name
, source
->name
,
2699 strmake( "D$(includedir)/wine/%s", get_include_install_path( source
->name
) ));
2703 /*******************************************************************
2706 static void output_source_rc( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2708 struct strarray defines
= get_source_defines( make
, source
, obj
);
2709 char *po_dir
= NULL
;
2712 if (source
->file
->flags
& FLAG_GENERATED
) strarray_add( &make
->clean_files
, source
->name
);
2713 if (linguas
.count
&& (source
->file
->flags
& FLAG_RC_PO
)) po_dir
= top_obj_dir_path( make
, "po" );
2714 strarray_add( &make
->res_files
, strmake( "%s.res", obj
));
2715 if (source
->file
->flags
& FLAG_RC_PO
&& !(source
->file
->flags
& FLAG_PARENTDIR
))
2717 strarray_add( &make
->clean_files
, strmake( "%s.pot", obj
));
2718 output( "%s.pot ", obj_dir_path( make
, obj
) );
2720 output( "%s.res: %s", obj_dir_path( make
, obj
), source
->filename
);
2721 output_filename( tools_path( make
, "wrc" ));
2722 output_filenames( source
->dependencies
);
2724 output( "\t%s -u -o $@", tools_path( make
, "wrc" ) );
2725 if (make
->is_win16
) output_filename( "-m16" );
2726 else output_filenames( target_flags
);
2727 output_filename( "--nostdinc" );
2728 if (po_dir
) output_filename( strmake( "--po-dir=%s", po_dir
));
2729 output_filenames( defines
);
2730 output_filename( source
->filename
);
2734 output( "%s.res:", obj_dir_path( make
, obj
));
2735 for (i
= 0; i
< linguas
.count
; i
++)
2736 output_filename( strmake( "%s/%s.mo", po_dir
, linguas
.str
[i
] ));
2742 /*******************************************************************
2745 static void output_source_mc( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2748 char *obj_path
= obj_dir_path( make
, obj
);
2750 strarray_add( &make
->res_files
, strmake( "%s.res", obj
));
2751 strarray_add( &make
->clean_files
, strmake( "%s.pot", obj
));
2752 output( "%s.pot %s.res: %s", obj_path
, obj_path
, source
->filename
);
2753 output_filename( tools_path( make
, "wmc" ));
2754 output_filenames( source
->dependencies
);
2756 output( "\t%s -u -o $@ %s", tools_path( make
, "wmc" ), source
->filename
);
2759 char *po_dir
= top_obj_dir_path( make
, "po" );
2760 output_filename( strmake( "--po-dir=%s", po_dir
));
2762 output( "%s.res:", obj_dir_path( make
, obj
));
2763 for (i
= 0; i
< linguas
.count
; i
++)
2764 output_filename( strmake( "%s/%s.mo", po_dir
, linguas
.str
[i
] ));
2770 /*******************************************************************
2773 static void output_source_res( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2775 strarray_add( &make
->res_files
, source
->name
);
2779 /*******************************************************************
2782 static void output_source_idl( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2784 struct strarray defines
= get_source_defines( make
, source
, obj
);
2785 struct strarray targets
= empty_strarray
;
2789 if (!source
->file
->flags
) source
->file
->flags
|= FLAG_IDL_HEADER
| FLAG_INSTALL
;
2790 if (find_include_file( make
, strmake( "%s.h", obj
))) source
->file
->flags
|= FLAG_IDL_HEADER
;
2792 for (i
= 0; i
< sizeof(idl_outputs
) / sizeof(idl_outputs
[0]); i
++)
2794 if (!(source
->file
->flags
& idl_outputs
[i
].flag
)) continue;
2795 dest
= strmake( "%s%s", obj
, idl_outputs
[i
].ext
);
2796 if (!find_src_file( make
, dest
)) strarray_add( &make
->clean_files
, dest
);
2797 strarray_add( &targets
, dest
);
2799 if (source
->file
->flags
& FLAG_IDL_PROXY
) strarray_add( &make
->dlldata_files
, source
->name
);
2800 if (source
->file
->flags
& FLAG_INSTALL
)
2802 add_install_rule( make
, source
->name
, xstrdup( source
->name
),
2803 strmake( "D$(includedir)/wine/%s.idl", get_include_install_path( obj
) ));
2804 if (source
->file
->flags
& FLAG_IDL_HEADER
)
2805 add_install_rule( make
, source
->name
, strmake( "%s.h", obj
),
2806 strmake( "d$(includedir)/wine/%s.h", get_include_install_path( obj
) ));
2808 if (!targets
.count
) return;
2810 output_filenames_obj_dir( make
, targets
);
2811 output( ": %s\n", tools_path( make
, "widl" ));
2812 output( "\t%s -o $@", tools_path( make
, "widl" ) );
2813 output_filenames( target_flags
);
2814 output_filename( "--nostdinc" );
2815 output_filenames( defines
);
2816 output_filenames( get_expanded_make_var_array( make
, "EXTRAIDLFLAGS" ));
2817 output_filenames( get_expanded_file_local_var( make
, obj
, "EXTRAIDLFLAGS" ));
2818 output_filename( source
->filename
);
2820 output_filenames_obj_dir( make
, targets
);
2821 output( ": %s", source
->filename
);
2822 output_filenames( source
->dependencies
);
2827 /*******************************************************************
2830 static void output_source_tlb( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2832 strarray_add( &make
->all_targets
, source
->name
);
2836 /*******************************************************************
2839 static void output_source_x( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2841 output( "%s.h: %s%s %s\n", obj_dir_path( make
, obj
),
2842 tools_dir_path( make
, "make_xftmpl" ), tools_ext
, source
->filename
);
2843 output( "\t%s%s -H -o $@ %s\n",
2844 tools_dir_path( make
, "make_xftmpl" ), tools_ext
, source
->filename
);
2845 if (source
->file
->flags
& FLAG_INSTALL
)
2847 add_install_rule( make
, source
->name
, source
->name
,
2848 strmake( "D$(includedir)/wine/%s", get_include_install_path( source
->name
) ));
2849 add_install_rule( make
, source
->name
, strmake( "%s.h", obj
),
2850 strmake( "d$(includedir)/wine/%s.h", get_include_install_path( obj
) ));
2855 /*******************************************************************
2858 static void output_source_sfd( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2861 char *ttf_obj
= strmake( "%s.ttf", obj
);
2862 char *ttf_file
= src_dir_path( make
, ttf_obj
);
2864 if (fontforge
&& !make
->src_dir
)
2866 output( "%s: %s\n", ttf_file
, source
->filename
);
2867 output( "\t%s -script %s %s $@\n",
2868 fontforge
, top_src_dir_path( make
, "fonts/genttf.ff" ), source
->filename
);
2869 if (!(source
->file
->flags
& FLAG_SFD_FONTS
)) output( "all: %s\n", ttf_file
);
2871 if (source
->file
->flags
& FLAG_INSTALL
)
2873 add_install_rule( make
, source
->name
, ttf_obj
, strmake( "D$(fontdir)/%s", ttf_obj
));
2874 output_srcdir_symlink( make
, ttf_obj
);
2877 if (source
->file
->flags
& FLAG_SFD_FONTS
)
2879 struct strarray
*array
= source
->file
->args
;
2881 for (i
= 0; i
< array
->count
; i
++)
2883 char *font
= strtok( xstrdup(array
->str
[i
]), " \t" );
2884 char *args
= strtok( NULL
, "" );
2886 strarray_add( &make
->all_targets
, xstrdup( font
));
2887 output( "%s: %s %s\n", obj_dir_path( make
, font
),
2888 tools_path( make
, "sfnt2fon" ), ttf_file
);
2889 output( "\t%s -q -o $@ %s %s\n", tools_path( make
, "sfnt2fon" ), ttf_file
, args
);
2890 add_install_rule( make
, source
->name
, xstrdup(font
), strmake( "d$(fontdir)/%s", font
));
2896 /*******************************************************************
2899 static void output_source_svg( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2901 static const char * const images
[] = { "bmp", "cur", "ico", NULL
};
2904 if (convert
&& rsvg
&& icotool
&& !make
->src_dir
)
2906 for (i
= 0; images
[i
]; i
++)
2907 if (find_include_file( make
, strmake( "%s.%s", obj
, images
[i
] ))) break;
2911 output( "%s.%s: %s\n", src_dir_path( make
, obj
), images
[i
], source
->filename
);
2912 output( "\tCONVERT=\"%s\" ICOTOOL=\"%s\" RSVG=\"%s\" %s %s $@\n", convert
, icotool
, rsvg
,
2913 top_src_dir_path( make
, "tools/buildimage" ), source
->filename
);
2919 /*******************************************************************
2922 static void output_source_nls( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2924 add_install_rule( make
, source
->name
, source
->name
,
2925 strmake( "D$(nlsdir)/%s", source
->name
));
2926 output_srcdir_symlink( make
, strmake( "%s.nls", obj
));
2930 /*******************************************************************
2931 * output_source_desktop
2933 static void output_source_desktop( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2935 add_install_rule( make
, source
->name
, source
->name
,
2936 strmake( "D$(datadir)/applications/%s", source
->name
));
2940 /*******************************************************************
2943 static void output_source_po( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2945 output( "%s.mo: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2946 output( "\t%s -o $@ %s\n", msgfmt
, source
->filename
);
2947 strarray_add( &make
->all_targets
, strmake( "%s.mo", obj
));
2951 /*******************************************************************
2954 static void output_source_in( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2958 if (strendswith( obj
, ".man" ) && source
->file
->args
)
2960 struct strarray symlinks
;
2961 char *dir
, *dest
= replace_extension( obj
, ".man", "" );
2962 char *lang
= strchr( dest
, '.' );
2963 char *section
= source
->file
->args
;
2967 dir
= strmake( "$(mandir)/%s/man%s", lang
, section
);
2969 else dir
= strmake( "$(mandir)/man%s", section
);
2970 add_install_rule( make
, dest
, xstrdup(obj
), strmake( "d%s/%s.%s", dir
, dest
, section
));
2971 symlinks
= get_expanded_file_local_var( make
, dest
, "SYMLINKS" );
2972 for (i
= 0; i
< symlinks
.count
; i
++)
2973 add_install_rule( make
, symlinks
.str
[i
], strmake( "%s.%s", dest
, section
),
2974 strmake( "y%s/%s.%s", dir
, symlinks
.str
[i
], section
));
2978 strarray_add( &make
->in_files
, xstrdup(obj
) );
2979 strarray_add( &make
->all_targets
, xstrdup(obj
) );
2980 output( "%s: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2981 output( "\t%s %s >$@ || (rm -f $@ && false)\n", sed_cmd
, source
->filename
);
2982 output( "%s:", obj_dir_path( make
, obj
));
2983 output_filenames( source
->dependencies
);
2985 add_install_rule( make
, obj
, xstrdup( obj
), strmake( "d$(datadir)/wine/%s", obj
));
2989 /*******************************************************************
2990 * output_source_spec
2992 static void output_source_spec( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2994 struct strarray imports
= get_expanded_file_local_var( make
, obj
, "IMPORTS" );
2995 struct strarray dll_flags
= get_expanded_file_local_var( make
, obj
, "EXTRADLLFLAGS" );
2996 struct strarray all_libs
, dep_libs
= empty_strarray
;
2997 char *dll_name
, *obj_name
;
2999 if (!imports
.count
) imports
= make
->imports
;
3000 if (!dll_flags
.count
) dll_flags
= make
->extradllflags
;
3001 all_libs
= add_import_libs( make
, &dep_libs
, imports
, 0 );
3002 add_import_libs( make
, &dep_libs
, get_default_imports( make
), 0 ); /* dependencies only */
3003 strarray_addall( &all_libs
, libs
);
3004 dll_name
= strmake( "%s.dll%s", obj
, make
->is_cross
? "" : dll_ext
);
3005 obj_name
= strmake( "%s%s", obj_dir_path( make
, obj
), make
->is_cross
? ".cross.o" : ".o" );
3007 strarray_add( &make
->clean_files
, dll_name
);
3008 strarray_add( &make
->res_files
, strmake( "%s.res", obj
));
3009 output( "%s.res: %s\n", obj_dir_path( make
, obj
), obj_dir_path( make
, dll_name
));
3010 output( "\techo \"%s.dll TESTDLL \\\"%s\\\"\" | %s -u -o $@\n", obj
,
3011 obj_dir_path( make
, dll_name
), tools_path( make
, "wrc" ));
3013 output( "%s:", obj_dir_path( make
, dll_name
));
3014 output_filename( source
->filename
);
3015 output_filename( obj_name
);
3016 output_filenames( dep_libs
);
3017 output_filename( tools_path( make
, "winebuild" ));
3018 output_filename( tools_path( make
, "winegcc" ));
3020 output_winegcc_command( make
);
3021 output_filename( "-s" );
3022 output_filenames( dll_flags
);
3023 output_filename( "-shared" );
3024 output_filename( source
->filename
);
3025 output_filename( obj_name
);
3026 output_filenames( all_libs
);
3027 output_filename( make
->is_cross
? "$(CROSSLDFLAGS)" : "$(LDFLAGS)" );
3032 /*******************************************************************
3033 * output_source_default
3035 static void output_source_default( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
3037 struct strarray defines
= get_source_defines( make
, source
, obj
);
3038 int is_dll_src
= (make
->testdll
&&
3039 strendswith( source
->name
, ".c" ) &&
3040 find_src_file( make
, replace_extension( source
->name
, ".c", ".spec" )));
3041 int need_cross
= (crosstarget
&&
3042 !(source
->file
->flags
& FLAG_C_UNIX
) &&
3044 ((source
->file
->flags
& FLAG_C_IMPLIB
) &&
3045 (needs_cross_lib( make
) || needs_delay_lib( make
))) ||
3046 (make
->staticlib
&& needs_cross_lib( make
))));
3047 int need_obj
= ((*dll_ext
|| !make
->staticlib
|| !(source
->file
->flags
& FLAG_C_UNIX
)) &&
3049 (source
->file
->flags
& FLAG_C_IMPLIB
) ||
3050 (make
->module
&& make
->staticlib
)));
3052 if ((source
->file
->flags
& FLAG_GENERATED
) &&
3053 (!make
->testdll
|| !strendswith( source
->filename
, "testlist.c" )))
3054 strarray_add( &make
->clean_files
, source
->filename
);
3055 if (source
->file
->flags
& FLAG_C_IMPLIB
) strarray_add( &make
->implib_objs
, strmake( "%s.o", obj
));
3059 if ((source
->file
->flags
& FLAG_C_UNIX
) && *dll_ext
)
3060 strarray_add( &make
->unixobj_files
, strmake( "%s.o", obj
));
3061 else if (!is_dll_src
&& (!(source
->file
->flags
& FLAG_C_IMPLIB
) || (make
->importlib
&& strarray_exists( &make
->imports
, make
->importlib
))))
3062 strarray_add( &make
->object_files
, strmake( "%s.o", obj
));
3064 strarray_add( &make
->clean_files
, strmake( "%s.o", obj
));
3065 output( "%s.o: %s\n", obj_dir_path( make
, obj
), source
->filename
);
3066 output( "\t$(CC) -c -o $@ %s", source
->filename
);
3067 output_filenames( defines
);
3068 if (make
->module
|| make
->staticlib
|| make
->sharedlib
|| make
->testdll
)
3070 output_filenames( dll_flags
);
3071 if (source
->use_msvcrt
) output_filenames( msvcrt_flags
);
3073 output_filenames( extra_cflags
);
3074 output_filenames( cpp_flags
);
3075 output_filename( "$(CFLAGS)" );
3080 strarray_add( is_dll_src
? &make
->clean_files
: &make
->crossobj_files
, strmake( "%s.cross.o", obj
));
3081 output( "%s.cross.o: %s\n", obj_dir_path( make
, obj
), source
->filename
);
3082 output( "\t$(CROSSCC) -c -o $@ %s", source
->filename
);
3083 output_filenames( defines
);
3084 output_filenames( extra_cross_cflags
);
3085 if (source
->file
->flags
& FLAG_C_IMPLIB
) output_filename( "-fno-builtin" );
3086 output_filenames( cpp_flags
);
3087 output_filename( "$(CROSSCFLAGS)" );
3090 if (strendswith( source
->name
, ".c" ) && !(source
->file
->flags
& FLAG_GENERATED
))
3092 strarray_add( &make
->c2man_files
, source
->filename
);
3093 if (make
->testdll
&& !is_dll_src
)
3095 strarray_add( &make
->ok_files
, strmake( "%s.ok", obj
));
3096 output( "%s.ok:\n", obj_dir_path( make
, obj
));
3097 output( "\t%s $(RUNTESTFLAGS) -T %s -M %s -p %s%s %s && touch $@\n",
3098 top_src_dir_path( make
, "tools/runtest" ), top_obj_dir_path( make
, "" ),
3099 make
->testdll
, replace_extension( make
->testdll
, ".dll", "_test.exe" ),
3100 make
->is_cross
? "" : dll_ext
, obj
);
3103 if (need_obj
) output_filename( strmake( "%s.o", obj_dir_path( make
, obj
)));
3104 if (need_cross
) output_filename( strmake( "%s.cross.o", obj_dir_path( make
, obj
)));
3106 output_filenames( source
->dependencies
);
3111 /* dispatch table to output rules for a single source file */
3115 void (*fn
)( struct makefile
*make
, struct incl_file
*source
, const char *obj
);
3116 } output_source_funcs
[] =
3118 { "y", output_source_y
},
3119 { "l", output_source_l
},
3120 { "h", output_source_h
},
3121 { "rh", output_source_h
},
3122 { "inl", output_source_h
},
3123 { "rc", output_source_rc
},
3124 { "mc", output_source_mc
},
3125 { "res", output_source_res
},
3126 { "idl", output_source_idl
},
3127 { "tlb", output_source_tlb
},
3128 { "sfd", output_source_sfd
},
3129 { "svg", output_source_svg
},
3130 { "nls", output_source_nls
},
3131 { "desktop", output_source_desktop
},
3132 { "po", output_source_po
},
3133 { "in", output_source_in
},
3134 { "x", output_source_x
},
3135 { "spec", output_source_spec
},
3136 { NULL
, output_source_default
}
3140 /*******************************************************************
3143 static int has_object_file( struct makefile
*make
)
3145 struct incl_file
*source
;
3148 LIST_FOR_EACH_ENTRY( source
, &make
->sources
, struct incl_file
, entry
)
3150 char *ext
= get_extension( source
->name
);
3152 if (!ext
) fatal_error( "unsupported file type %s\n", source
->name
);
3155 for (i
= 0; output_source_funcs
[i
].ext
; i
++)
3156 if (!strcmp( ext
, output_source_funcs
[i
].ext
)) break;
3158 if (!output_source_funcs
[i
].ext
) return 1; /* default extension builds to an object file */
3164 /*******************************************************************
3167 static void output_man_pages( struct makefile
*make
)
3169 if (make
->c2man_files
.count
)
3171 char *spec_file
= src_dir_path( make
, replace_extension( make
->module
, ".dll", ".spec" ));
3173 output( "manpages::\n" );
3174 output( "\t%s -w %s", top_src_dir_path( make
, "tools/c2man.pl" ), spec_file
);
3175 output_filename( strmake( "-R%s", top_src_dir_path( make
, "" )));
3176 output_filename( strmake( "-I%s", top_src_dir_path( make
, "include" )));
3177 output_filename( strmake( "-o %s/man%s",
3178 top_obj_dir_path( make
, "documentation" ), man_ext
));
3179 output_filenames( make
->c2man_files
);
3181 output( "htmlpages::\n" );
3182 output( "\t%s -Th -w %s", top_src_dir_path( make
, "tools/c2man.pl" ), spec_file
);
3183 output_filename( strmake( "-R%s", top_src_dir_path( make
, "" )));
3184 output_filename( strmake( "-I%s", top_src_dir_path( make
, "include" )));
3185 output_filename( strmake( "-o %s",
3186 top_obj_dir_path( make
, "documentation/html" )));
3187 output_filenames( make
->c2man_files
);
3189 output( "sgmlpages::\n" );
3190 output( "\t%s -Ts -w %s", top_src_dir_path( make
, "tools/c2man.pl" ), spec_file
);
3191 output_filename( strmake( "-R%s", top_src_dir_path( make
, "" )));
3192 output_filename( strmake( "-I%s", top_src_dir_path( make
, "include" )));
3193 output_filename( strmake( "-o %s",
3194 top_obj_dir_path( make
, "documentation/api-guide" )));
3195 output_filenames( make
->c2man_files
);
3197 output( "xmlpages::\n" );
3198 output( "\t%s -Tx -w %s", top_src_dir_path( make
, "tools/c2man.pl" ), spec_file
);
3199 output_filename( strmake( "-R%s", top_src_dir_path( make
, "" )));
3200 output_filename( strmake( "-I%s", top_src_dir_path( make
, "include" )));
3201 output_filename( strmake( "-o %s",
3202 top_obj_dir_path( make
, "documentation/api-guide-xml" )));
3203 output_filenames( make
->c2man_files
);
3205 strarray_add( &make
->phony_targets
, "manpages" );
3206 strarray_add( &make
->phony_targets
, "htmlpages" );
3207 strarray_add( &make
->phony_targets
, "sgmlpages" );
3208 strarray_add( &make
->phony_targets
, "xmlpages" );
3210 else output( "manpages htmlpages sgmlpages xmlpages::\n" );
3214 /*******************************************************************
3217 static void output_module( struct makefile
*make
)
3219 struct strarray all_libs
= empty_strarray
;
3220 struct strarray dep_libs
= empty_strarray
;
3221 char *module_path
= obj_dir_path( make
, make
->module
);
3222 char *spec_file
= NULL
;
3225 if (!make
->is_exe
) spec_file
= src_dir_path( make
, replace_extension( make
->module
, ".dll", ".spec" ));
3226 strarray_addall( &all_libs
, add_import_libs( make
, &dep_libs
, make
->delayimports
, 1 ));
3227 strarray_addall( &all_libs
, add_import_libs( make
, &dep_libs
, make
->imports
, 0 ));
3228 add_import_libs( make
, &dep_libs
, get_default_imports( make
), 0 ); /* dependencies only */
3232 if (delay_load_flag
)
3234 for (i
= 0; i
< make
->delayimports
.count
; i
++)
3235 strarray_add( &all_libs
, strmake( "%s%s%s", delay_load_flag
, make
->delayimports
.str
[i
],
3236 strchr( make
->delayimports
.str
[i
], '.' ) ? "" : ".dll" ));
3238 strarray_add( &make
->all_targets
, strmake( "%s", make
->module
));
3239 add_install_rule( make
, make
->module
, strmake( "%s", make
->module
),
3240 strmake( "c$(dlldir)/%s", make
->module
));
3241 output( "%s:", module_path
);
3245 strarray_addall( &all_libs
, add_default_libraries( make
, &dep_libs
));
3249 for (i
= 0; i
< make
->delayimports
.count
; i
++)
3250 strarray_add( &all_libs
, strmake( "-Wl,-delayload,%s%s", make
->delayimports
.str
[i
],
3251 strchr( make
->delayimports
.str
[i
], '.' ) ? "" : ".dll" ));
3252 strarray_add( &make
->all_targets
, strmake( "%s%s", make
->module
, dll_ext
));
3253 strarray_add( &make
->all_targets
, strmake( "%s.fake", make
->module
));
3254 add_install_rule( make
, make
->module
, strmake( "%s%s", make
->module
, dll_ext
),
3255 strmake( "p$(dlldir)/%s%s", make
->module
, dll_ext
));
3256 add_install_rule( make
, make
->module
, strmake( "%s.fake", make
->module
),
3257 strmake( "d$(dlldir)/fakedlls/%s", make
->module
));
3258 output( "%s%s %s.fake:", module_path
, dll_ext
, module_path
);
3262 strarray_add( &make
->all_targets
, make
->module
);
3263 add_install_rule( make
, make
->module
, make
->module
,
3264 strmake( "p$(%s)/%s", spec_file
? "dlldir" : "bindir", make
->module
));
3265 output( "%s:", module_path
);
3269 if (spec_file
) output_filename( spec_file
);
3270 output_filenames_obj_dir( make
, make
->is_cross
? make
->crossobj_files
: make
->object_files
);
3271 output_filenames_obj_dir( make
, make
->res_files
);
3272 output_filenames( dep_libs
);
3273 output_filename( tools_path( make
, "winebuild" ));
3274 output_filename( tools_path( make
, "winegcc" ));
3276 output_winegcc_command( make
);
3277 if (make
->is_cross
) output_filename( "-Wl,--wine-builtin" );
3280 output_filename( "-shared" );
3281 output_filename( spec_file
);
3283 output_filenames( make
->extradllflags
);
3284 output_filenames_obj_dir( make
, make
->is_cross
? make
->crossobj_files
: make
->object_files
);
3285 output_filenames_obj_dir( make
, make
->res_files
);
3286 output_filenames( all_libs
);
3287 output_filename( make
->is_cross
? "$(CROSSLDFLAGS)" : "$(LDFLAGS)" );
3290 if (spec_file
&& make
->importlib
)
3292 char *importlib_path
= obj_dir_path( make
, strmake( "lib%s", make
->importlib
));
3293 if (*dll_ext
&& !make
->implib_objs
.count
)
3295 strarray_add( &make
->clean_files
, strmake( "lib%s.def", make
->importlib
));
3296 output( "%s.def: %s %s\n", importlib_path
, tools_path( make
, "winebuild" ), spec_file
);
3297 output( "\t%s -w --def -o $@", tools_path( make
, "winebuild" ) );
3298 output_filenames( target_flags
);
3299 if (make
->is_win16
) output_filename( "-m16" );
3300 output_filename( "--export" );
3301 output_filename( spec_file
);
3303 add_install_rule( make
, make
->importlib
,
3304 strmake( "lib%s.def", make
->importlib
),
3305 strmake( "d$(dlldir)/lib%s.def", make
->importlib
));
3309 strarray_add( &make
->clean_files
, strmake( "lib%s.a", make
->importlib
));
3310 if (!*dll_ext
&& needs_delay_lib( make
))
3312 strarray_add( &make
->clean_files
, strmake( "lib%s.delay.a", make
->importlib
));
3313 output( "%s.delay.a ", importlib_path
);
3315 output( "%s.a: %s %s", importlib_path
, tools_path( make
, "winebuild" ), spec_file
);
3316 output_filenames_obj_dir( make
, make
->implib_objs
);
3318 output( "\t%s -w --implib -o $@", tools_path( make
, "winebuild" ) );
3319 output_filenames( target_flags
);
3320 if (make
->is_win16
) output_filename( "-m16" );
3321 output_filename( "--export" );
3322 output_filename( spec_file
);
3323 output_filenames_obj_dir( make
, make
->implib_objs
);
3325 add_install_rule( make
, make
->importlib
,
3326 strmake( "lib%s.a", make
->importlib
),
3327 strmake( "d$(dlldir)/lib%s.a", make
->importlib
));
3329 if (crosstarget
&& (needs_cross_lib( make
) || needs_delay_lib( make
)))
3331 struct strarray cross_files
= strarray_replace_extension( &make
->implib_objs
, ".o", ".cross.o" );
3332 if (needs_cross_lib( make
))
3334 strarray_add( &make
->clean_files
, strmake( "lib%s.cross.a", make
->importlib
));
3335 output_filename( strmake( "%s.cross.a", importlib_path
));
3337 if (needs_delay_lib( make
))
3339 strarray_add( &make
->clean_files
, strmake( "lib%s.delay.a", make
->importlib
));
3340 output_filename( strmake( "%s.delay.a", importlib_path
));
3342 output( ": %s %s", tools_path( make
, "winebuild" ), spec_file
);
3343 output_filenames_obj_dir( make
, cross_files
);
3345 output( "\t%s -b %s -w --implib -o $@", tools_path( make
, "winebuild" ), crosstarget
);
3346 if (make
->is_win16
) output_filename( "-m16" );
3347 output_filename( "--export" );
3348 output_filename( spec_file
);
3349 output_filenames_obj_dir( make
, cross_files
);
3355 output_man_pages( make
);
3356 else if (*dll_ext
&& !make
->is_win16
&& strendswith( make
->module
, ".exe" ))
3358 char *binary
= replace_extension( make
->module
, ".exe", "" );
3359 add_install_rule( make
, binary
, "wineapploader", strmake( "t$(bindir)/%s", binary
));
3364 /*******************************************************************
3367 static void output_static_lib( struct makefile
*make
)
3369 strarray_add( &make
->all_targets
, make
->staticlib
);
3370 output( "%s:", obj_dir_path( make
, make
->staticlib
));
3371 output_filenames_obj_dir( make
, make
->object_files
);
3372 output_filenames_obj_dir( make
, make
->unixobj_files
);
3373 output( "\n\trm -f $@\n" );
3374 output( "\t%s rc $@", ar
);
3375 output_filenames_obj_dir( make
, make
->object_files
);
3376 output_filenames_obj_dir( make
, make
->unixobj_files
);
3377 output( "\n\t%s $@\n", ranlib
);
3378 add_install_rule( make
, make
->staticlib
, make
->staticlib
,
3379 strmake( "d$(dlldir)/%s", make
->staticlib
));
3380 if (needs_cross_lib( make
))
3382 char *name
= replace_extension( make
->staticlib
, ".a", ".cross.a" );
3384 strarray_add( &make
->all_targets
, name
);
3385 output( "%s: %s", obj_dir_path( make
, name
), tools_path( make
, "winebuild" ));
3386 output_filenames_obj_dir( make
, make
->crossobj_files
);
3388 output( "\t%s -b %s -w --staticlib -o $@", tools_path( make
, "winebuild" ), crosstarget
);
3389 output_filenames_obj_dir( make
, make
->crossobj_files
);
3395 /*******************************************************************
3398 static void output_shared_lib( struct makefile
*make
)
3402 struct strarray names
= get_shared_lib_names( make
->sharedlib
);
3403 struct strarray all_libs
= empty_strarray
;
3404 struct strarray dep_libs
= empty_strarray
;
3406 basename
= xstrdup( make
->sharedlib
);
3407 if ((p
= strchr( basename
, '.' ))) *p
= 0;
3409 strarray_addall( &dep_libs
, get_local_dependencies( make
, basename
, make
->in_files
));
3410 strarray_addall( &all_libs
, get_expanded_file_local_var( make
, basename
, "LDFLAGS" ));
3411 strarray_addall( &all_libs
, add_default_libraries( make
, &dep_libs
));
3413 output( "%s:", obj_dir_path( make
, make
->sharedlib
));
3414 output_filenames_obj_dir( make
, make
->object_files
);
3415 output_filenames( dep_libs
);
3417 output( "\t$(CC) -o $@" );
3418 output_filenames_obj_dir( make
, make
->object_files
);
3419 output_filenames( all_libs
);
3420 output_filename( "$(LDFLAGS)" );
3422 add_install_rule( make
, make
->sharedlib
, make
->sharedlib
,
3423 strmake( "p$(libdir)/%s", make
->sharedlib
));
3424 for (i
= 1; i
< names
.count
; i
++)
3426 output( "%s: %s\n", obj_dir_path( make
, names
.str
[i
] ), obj_dir_path( make
, names
.str
[i
-1] ));
3427 output_symlink_rule( obj_dir_path( make
, names
.str
[i
-1] ), obj_dir_path( make
, names
.str
[i
] ));
3428 add_install_rule( make
, names
.str
[i
], names
.str
[i
-1],
3429 strmake( "y$(libdir)/%s", names
.str
[i
] ));
3431 strarray_addall( &make
->all_targets
, names
);
3435 /*******************************************************************
3436 * output_test_module
3438 static void output_test_module( struct makefile
*make
)
3440 char *testmodule
= replace_extension( make
->testdll
, ".dll", "_test.exe" );
3441 char *stripped
= replace_extension( make
->testdll
, ".dll", "_test-stripped.exe" );
3442 char *testres
= replace_extension( make
->testdll
, ".dll", "_test.res" );
3443 struct strarray dep_libs
= empty_strarray
;
3444 struct strarray all_libs
= add_import_libs( make
, &dep_libs
, make
->imports
, 0 );
3445 struct makefile
*parent
= get_parent_makefile( make
);
3446 const char *ext
= make
->is_cross
? "" : dll_ext
;
3447 const char *parent_ext
= parent
&& parent
->is_cross
? "" : dll_ext
;
3449 add_import_libs( make
, &dep_libs
, get_default_imports( make
), 0 ); /* dependencies only */
3450 strarray_addall( &all_libs
, libs
);
3451 strarray_add( &make
->all_targets
, strmake( "%s%s", testmodule
, ext
));
3452 strarray_add( &make
->clean_files
, strmake( "%s%s", stripped
, ext
));
3453 output( "%s%s:\n", obj_dir_path( make
, testmodule
), ext
);
3454 output_winegcc_command( make
);
3455 output_filenames( make
->extradllflags
);
3456 output_filenames_obj_dir( make
, make
->is_cross
? make
->crossobj_files
: make
->object_files
);
3457 output_filenames_obj_dir( make
, make
->res_files
);
3458 output_filenames( all_libs
);
3459 output_filename( make
->is_cross
? "$(CROSSLDFLAGS)" : "$(LDFLAGS)" );
3461 output( "%s%s:\n", obj_dir_path( make
, stripped
), ext
);
3462 output_winegcc_command( make
);
3463 output_filename( "-s" );
3464 output_filename( strmake( "-Wb,-F,%s", testmodule
));
3465 output_filenames( make
->extradllflags
);
3466 output_filenames_obj_dir( make
, make
->is_cross
? make
->crossobj_files
: make
->object_files
);
3467 output_filenames_obj_dir( make
, make
->res_files
);
3468 output_filenames( all_libs
);
3469 output_filename( make
->is_cross
? "$(CROSSLDFLAGS)" : "$(LDFLAGS)" );
3471 output( "%s%s %s%s:", obj_dir_path( make
, testmodule
), ext
, obj_dir_path( make
, stripped
), ext
);
3472 output_filenames_obj_dir( make
, make
->is_cross
? make
->crossobj_files
: make
->object_files
);
3473 output_filenames_obj_dir( make
, make
->res_files
);
3474 output_filenames( dep_libs
);
3475 output_filename( tools_path( make
, "winebuild" ));
3476 output_filename( tools_path( make
, "winegcc" ));
3479 if (!make
->disabled
&& !strarray_exists( &disabled_dirs
, "programs/winetest" ))
3480 output( "all: %s/%s\n", top_obj_dir_path( make
, "programs/winetest" ), testres
);
3481 output( "%s/%s: %s%s\n", top_obj_dir_path( make
, "programs/winetest" ), testres
,
3482 obj_dir_path( make
, stripped
), ext
);
3483 output( "\techo \"%s TESTRES \\\"%s%s\\\"\" | %s -u -o $@\n",
3484 testmodule
, obj_dir_path( make
, stripped
), ext
, tools_path( make
, "wrc" ));
3486 output_filenames_obj_dir( make
, make
->ok_files
);
3487 output( ": %s%s ../%s%s\n", testmodule
, ext
, make
->testdll
, parent_ext
);
3488 output( "check test:" );
3489 if (!make
->disabled
&& parent
&& !parent
->disabled
) output_filenames_obj_dir( make
, make
->ok_files
);
3491 strarray_add( &make
->phony_targets
, "check" );
3492 strarray_add( &make
->phony_targets
, "test" );
3493 output( "testclean::\n" );
3494 output( "\trm -f" );
3495 output_filenames_obj_dir( make
, make
->ok_files
);
3497 strarray_addall( &make
->clean_files
, make
->ok_files
);
3498 strarray_add( &make
->phony_targets
, "testclean" );
3502 /*******************************************************************
3505 static void output_programs( struct makefile
*make
)
3508 char *ldrpath_local
= get_expanded_make_variable( make
, "LDRPATH_LOCAL" );
3509 char *ldrpath_install
= get_expanded_make_variable( make
, "LDRPATH_INSTALL" );
3511 for (i
= 0; i
< make
->programs
.count
; i
++)
3513 char *program_installed
= NULL
;
3514 char *program
= strmake( "%s%s", make
->programs
.str
[i
], exe_ext
);
3515 struct strarray deps
= get_local_dependencies( make
, make
->programs
.str
[i
], make
->in_files
);
3516 struct strarray all_libs
= get_expanded_file_local_var( make
, make
->programs
.str
[i
], "LDFLAGS" );
3517 struct strarray objs
= get_expanded_file_local_var( make
, make
->programs
.str
[i
], "OBJS" );
3518 struct strarray symlinks
= get_expanded_file_local_var( make
, make
->programs
.str
[i
], "SYMLINKS" );
3520 if (!objs
.count
) objs
= make
->object_files
;
3521 strarray_addall( &all_libs
, add_default_libraries( make
, &deps
));
3523 output( "%s:", obj_dir_path( make
, program
) );
3524 output_filenames_obj_dir( make
, objs
);
3525 output_filenames( deps
);
3527 output( "\t$(CC) -o $@" );
3528 output_filenames_obj_dir( make
, objs
);
3530 if (strarray_exists( &all_libs
, "-lwine" ))
3532 strarray_add( &all_libs
, strmake( "-L%s", top_obj_dir_path( make
, "libs/wine" )));
3533 if (ldrpath_local
&& ldrpath_install
)
3535 program_installed
= strmake( "%s-installed%s", make
->programs
.str
[i
], exe_ext
);
3536 output_filename( ldrpath_local
);
3537 output_filenames( all_libs
);
3538 output_filename( "$(LDFLAGS)" );
3540 output( "%s:", obj_dir_path( make
, program_installed
) );
3541 output_filenames_obj_dir( make
, objs
);
3542 output_filenames( deps
);
3544 output( "\t$(CC) -o $@" );
3545 output_filenames_obj_dir( make
, objs
);
3546 output_filename( ldrpath_install
);
3547 strarray_add( &make
->all_targets
, program_installed
);
3551 output_filenames( all_libs
);
3552 output_filename( "$(LDFLAGS)" );
3554 strarray_add( &make
->all_targets
, program
);
3556 for (j
= 0; j
< symlinks
.count
; j
++)
3558 output( "%s: %s\n", obj_dir_path( make
, symlinks
.str
[j
] ), obj_dir_path( make
, program
));
3559 output_symlink_rule( obj_dir_path( make
, program
), obj_dir_path( make
, symlinks
.str
[j
] ));
3561 strarray_addall( &make
->all_targets
, symlinks
);
3563 add_install_rule( make
, program
, program_installed
? program_installed
: program
,
3564 strmake( "p$(bindir)/%s", program
));
3565 for (j
= 0; j
< symlinks
.count
; j
++)
3566 add_install_rule( make
, symlinks
.str
[j
], program
,
3567 strmake( "y$(bindir)/%s%s", symlinks
.str
[j
], exe_ext
));
3572 /*******************************************************************
3575 static void output_subdirs( struct makefile
*make
)
3577 struct strarray symlinks
= empty_strarray
;
3578 struct strarray all_deps
= empty_strarray
;
3579 struct strarray build_deps
= empty_strarray
;
3580 struct strarray builddeps_deps
= empty_strarray
;
3581 struct strarray makefile_deps
= empty_strarray
;
3582 struct strarray clean_files
= empty_strarray
;
3583 struct strarray testclean_files
= empty_strarray
;
3584 struct strarray distclean_files
= empty_strarray
;
3585 struct strarray tools_deps
= empty_strarray
;
3586 struct strarray tooldeps_deps
= empty_strarray
;
3587 struct strarray winetest_deps
= empty_strarray
;
3590 strarray_addall( &distclean_files
, make
->distclean_files
);
3591 for (i
= 0; i
< make
->subdirs
.count
; i
++)
3593 const struct makefile
*submake
= make
->submakes
[i
];
3594 char *subdir
= base_dir_path( submake
, "" );
3596 strarray_add( &makefile_deps
, top_src_dir_path( make
, base_dir_path( submake
,
3597 strmake ( "%s.in", output_makefile_name
))));
3598 for (j
= 0; j
< submake
->clean_files
.count
; j
++)
3599 strarray_add( &clean_files
, base_dir_path( submake
, submake
->clean_files
.str
[j
] ));
3600 for (j
= 0; j
< submake
->distclean_files
.count
; j
++)
3601 strarray_add( &distclean_files
, base_dir_path( submake
, submake
->distclean_files
.str
[j
] ));
3602 for (j
= 0; j
< submake
->ok_files
.count
; j
++)
3603 strarray_add( &testclean_files
, base_dir_path( submake
, submake
->ok_files
.str
[j
] ));
3605 /* import libs are still created for disabled dirs, except for win16 ones */
3606 if (submake
->module
&& submake
->importlib
&& !(submake
->disabled
&& submake
->is_win16
))
3608 char *importlib_path
= base_dir_path( submake
, strmake( "lib%s", submake
->importlib
));
3609 if (submake
->implib_objs
.count
)
3611 output( "%s.a: dummy\n", importlib_path
);
3612 output( "\t@cd %s && $(MAKE) lib%s.a\n", subdir
, submake
->importlib
);
3613 strarray_add( &tools_deps
, strmake( "%s.a", importlib_path
));
3614 if (needs_cross_lib( submake
))
3616 output( "%s.cross.a: dummy\n", importlib_path
);
3617 output( "\t@cd %s && $(MAKE) lib%s.cross.a\n", subdir
, submake
->importlib
);
3618 strarray_add( &tools_deps
, strmake( "%s.cross.a", importlib_path
));
3620 if (needs_delay_lib( submake
))
3622 output( "%s.delay.a: dummy\n", importlib_path
);
3623 output( "\t@cd %s && $(MAKE) lib%s.delay.a\n", subdir
, submake
->importlib
);
3624 strarray_add( &tools_deps
, strmake( "%s.delay.a", importlib_path
));
3629 char *spec_file
= top_src_dir_path( make
, base_dir_path( submake
,
3630 replace_extension( submake
->module
, ".dll", ".spec" )));
3633 output( "%s.def: %s", importlib_path
, spec_file
);
3634 strarray_add( &build_deps
, strmake( "%s.def", importlib_path
));
3638 if (needs_delay_lib( submake
))
3640 output( "%s.delay.a ", importlib_path
);
3641 strarray_add( &build_deps
, strmake( "%s.delay.a", importlib_path
));
3643 output( "%s.a: %s", importlib_path
, spec_file
);
3644 strarray_add( &build_deps
, strmake( "%s.a", importlib_path
));
3646 output_filename( tools_path( make
, "winebuild" ));
3648 output( "\t%s -w -o $@", tools_path( make
, "winebuild" ));
3649 output_filename( *dll_ext
? "--def" : "--implib" );
3650 output_filenames( target_flags
);
3651 if (submake
->is_win16
) output_filename( "-m16" );
3652 output_filename( "--export" );
3653 output_filename( spec_file
);
3655 if (crosstarget
&& (needs_cross_lib( submake
) || needs_delay_lib( submake
)))
3657 if (needs_cross_lib( submake
))
3659 output_filename( strmake( "%s.cross.a", importlib_path
));
3660 strarray_add( &build_deps
, strmake( "%s.cross.a", importlib_path
));
3662 if (needs_delay_lib( submake
))
3664 output_filename( strmake( "%s.delay.a", importlib_path
));
3665 strarray_add( &build_deps
, strmake( "%s.delay.a", importlib_path
));
3667 output( ": %s", spec_file
);
3668 output_filename( tools_path( make
, "winebuild" ));
3670 output( "\t%s -b %s -w -o $@", tools_path( make
, "winebuild" ), crosstarget
);
3671 if (submake
->is_win16
) output_filename( "-m16" );
3672 output_filename( "--implib" );
3673 output_filename( "--export" );
3674 output_filename( spec_file
);
3678 strarray_addall( &symlinks
, output_importlib_symlinks( make
, submake
));
3681 if (submake
->disabled
) continue;
3682 strarray_add( &all_deps
, subdir
);
3684 if (submake
->module
)
3686 if (!submake
->staticlib
)
3688 strarray_add( &builddeps_deps
, subdir
);
3689 if (!submake
->is_exe
)
3691 output( "manpages htmlpages sgmlpages xmlpages::\n" );
3692 output( "\t@cd %s && $(MAKE) $@\n", subdir
);
3695 else strarray_add( &tools_deps
, subdir
);
3697 else if (submake
->testdll
)
3699 output( "%s/test: dummy\n", subdir
);
3700 output( "\t@cd %s && $(MAKE) test\n", subdir
);
3701 strarray_add( &winetest_deps
, subdir
);
3702 strarray_add( &builddeps_deps
, subdir
);
3706 if (!strcmp( submake
->base_dir
, "tools" ) || !strncmp( submake
->base_dir
, "tools/", 6 ))
3708 strarray_add( &tooldeps_deps
, submake
->base_dir
);
3709 for (j
= 0; j
< submake
->programs
.count
; j
++)
3710 output( "%s/%s%s: %s\n", submake
->base_dir
,
3711 submake
->programs
.str
[j
], tools_ext
, submake
->base_dir
);
3713 if (submake
->programs
.count
|| submake
->sharedlib
)
3715 struct strarray libs
= get_expanded_make_var_array( submake
, "EXTRALIBS" );
3716 for (j
= 0; j
< submake
->programs
.count
; j
++)
3717 strarray_addall( &libs
, get_expanded_file_local_var( submake
,
3718 submake
->programs
.str
[j
], "LDFLAGS" ));
3719 output( "%s: libs/port", submake
->base_dir
);
3720 for (j
= 0; j
< libs
.count
; j
++)
3722 if (!strcmp( libs
.str
[j
], "-lwpp" )) output_filename( "libs/wpp" );
3723 if (!strcmp( libs
.str
[j
], "-lwine" )) output_filename( "libs/wine" );
3729 if (submake
->install_rules
[INSTALL_LIB
].count
)
3731 output( "install install-lib:: %s\n", submake
->base_dir
);
3732 output_install_commands( make
, submake
, submake
->install_rules
[INSTALL_LIB
] );
3734 if (submake
->install_rules
[INSTALL_DEV
].count
)
3736 output( "install install-dev:: %s\n", submake
->base_dir
);
3737 output_install_commands( make
, submake
, submake
->install_rules
[INSTALL_DEV
] );
3741 output_filenames( all_deps
);
3743 output_filenames( all_deps
);
3744 output( ": dummy\n" );
3745 output( "\t@cd $@ && $(MAKE)\n" );
3746 output( "Makefile:" );
3747 output_filenames( makefile_deps
);
3749 output_filenames( makefile_deps
);
3751 if (tooldeps_deps
.count
)
3753 output( "__tooldeps__:" );
3754 output_filenames( tooldeps_deps
);
3756 strarray_add( &make
->phony_targets
, "__tooldeps__" );
3758 if (winetest_deps
.count
)
3760 output( "buildtests programs/winetest:" );
3761 output_filenames( winetest_deps
);
3763 output( "check test:" );
3764 for (i
= 0; i
< winetest_deps
.count
; i
++)
3766 char *target
= strmake( "%s/test", winetest_deps
.str
[i
] );
3767 output_filename( target
);
3768 strarray_add( &make
->phony_targets
, target
);
3771 strarray_add( &make
->phony_targets
, "buildtests" );
3772 strarray_add( &make
->phony_targets
, "check" );
3773 strarray_add( &make
->phony_targets
, "test" );
3776 output( "clean::\n");
3777 output_rm_filenames( clean_files
);
3778 output( "testclean::\n");
3779 output_rm_filenames( testclean_files
);
3780 output( "distclean::\n");
3781 output_rm_filenames( distclean_files
);
3782 output_filenames( tools_deps
);
3784 output_filename( tools_dir_path( make
, "widl" ));
3785 output_filename( tools_dir_path( make
, "winebuild" ));
3786 output_filename( tools_dir_path( make
, "winegcc" ));
3787 output_filename( obj_dir_path( make
, "include" ));
3789 output_filenames( builddeps_deps
);
3790 output( ": __builddeps__\n" );
3791 strarray_add( &make
->phony_targets
, "distclean" );
3792 strarray_add( &make
->phony_targets
, "testclean" );
3793 strarray_addall( &make
->phony_targets
, all_deps
);
3795 strarray_addall( &make
->clean_files
, symlinks
);
3796 strarray_addall( &build_deps
, tools_deps
);
3797 strarray_addall( &build_deps
, symlinks
);
3798 if (build_deps
.count
)
3800 output( "__builddeps__:" );
3801 output_filenames( build_deps
);
3803 strarray_add( &make
->phony_targets
, "__builddeps__" );
3805 if (get_expanded_make_variable( make
, "GETTEXTPO_LIBS" )) output_po_files( make
);
3809 /*******************************************************************
3812 static void output_sources( struct makefile
*make
)
3814 struct incl_file
*source
;
3817 strarray_add( &make
->phony_targets
, "all" );
3819 LIST_FOR_EACH_ENTRY( source
, &make
->sources
, struct incl_file
, entry
)
3821 char *obj
= xstrdup( source
->name
);
3822 char *ext
= get_extension( obj
);
3824 if (!ext
) fatal_error( "unsupported file type %s\n", source
->name
);
3827 for (j
= 0; output_source_funcs
[j
].ext
; j
++)
3828 if (!strcmp( ext
, output_source_funcs
[j
].ext
)) break;
3830 output_source_funcs
[j
].fn( make
, source
, obj
);
3831 strarray_addall_uniq( &make
->dependencies
, source
->dependencies
);
3834 /* special case for winetest: add resource files from other test dirs */
3835 if (make
->base_dir
&& !strcmp( make
->base_dir
, "programs/winetest" ))
3837 struct strarray tests
= enable_tests
;
3839 for (i
= 0; i
< top_makefile
->subdirs
.count
; i
++)
3840 if (top_makefile
->submakes
[i
]->testdll
&& !top_makefile
->submakes
[i
]->disabled
)
3841 strarray_add( &tests
, top_makefile
->submakes
[i
]->testdll
);
3842 for (i
= 0; i
< tests
.count
; i
++)
3843 strarray_add( &make
->res_files
, replace_extension( tests
.str
[i
], ".dll", "_test.res" ));
3846 if (make
->dlldata_files
.count
)
3848 output( "%s: %s %s\n", obj_dir_path( make
, "dlldata.c" ),
3849 tools_path( make
, "widl" ), src_dir_path( make
, "Makefile.in" ));
3850 output( "\t%s --dlldata-only -o $@", tools_path( make
, "widl" ));
3851 output_filenames( make
->dlldata_files
);
3855 if (make
->staticlib
) output_static_lib( make
);
3856 else if (make
->module
) output_module( make
);
3857 else if (make
->testdll
) output_test_module( make
);
3858 else if (make
->sharedlib
) output_shared_lib( make
);
3859 else if (make
->programs
.count
) output_programs( make
);
3861 for (i
= 0; i
< make
->scripts
.count
; i
++)
3862 add_install_rule( make
, make
->scripts
.str
[i
], make
->scripts
.str
[i
],
3863 strmake( "S$(bindir)/%s", make
->scripts
.str
[i
] ));
3865 if (!make
->src_dir
) strarray_add( &make
->distclean_files
, ".gitignore" );
3866 strarray_add( &make
->distclean_files
, "Makefile" );
3867 if (make
->testdll
) strarray_add( &make
->distclean_files
, "testlist.c" );
3869 if (!make
->base_dir
)
3870 strarray_addall( &make
->distclean_files
, get_expanded_make_var_array( make
, "CONFIGURE_TARGETS" ));
3871 else if (!strcmp( make
->base_dir
, "po" ))
3872 strarray_add( &make
->distclean_files
, "LINGUAS" );
3874 if (make
->subdirs
.count
) output_subdirs( make
);
3876 if (!make
->disabled
)
3878 if (make
->all_targets
.count
)
3881 output_filenames_obj_dir( make
, make
->all_targets
);
3884 output_install_rules( make
, INSTALL_LIB
, "install-lib" );
3885 output_install_rules( make
, INSTALL_DEV
, "install-dev" );
3886 output_uninstall_rules( make
);
3889 if (make
->dependencies
.count
)
3891 output_filenames( make
->dependencies
);
3895 strarray_addall( &make
->clean_files
, make
->object_files
);
3896 strarray_addall( &make
->clean_files
, make
->crossobj_files
);
3897 strarray_addall( &make
->clean_files
, make
->unixobj_files
);
3898 strarray_addall( &make
->clean_files
, make
->res_files
);
3899 strarray_addall( &make
->clean_files
, make
->all_targets
);
3900 strarray_addall( &make
->clean_files
, make
->extra_targets
);
3902 if (make
->clean_files
.count
)
3904 output( "%s::\n", obj_dir_path( make
, "clean" ));
3905 output( "\trm -f" );
3906 output_filenames_obj_dir( make
, make
->clean_files
);
3908 if (make
->obj_dir
) output( "__clean__: %s\n", obj_dir_path( make
, "clean" ));
3909 strarray_add( &make
->phony_targets
, obj_dir_path( make
, "clean" ));
3912 if (make
->phony_targets
.count
)
3914 output( ".PHONY:" );
3915 output_filenames( make
->phony_targets
);
3921 /*******************************************************************
3924 static FILE *create_temp_file( const char *orig
)
3926 char *name
= xmalloc( strlen(orig
) + 13 );
3927 unsigned int i
, id
= getpid();
3931 for (i
= 0; i
< 100; i
++)
3933 sprintf( name
, "%s.tmp%08x", orig
, id
);
3934 if ((fd
= open( name
, O_RDWR
| O_CREAT
| O_EXCL
, 0666 )) != -1)
3936 ret
= fdopen( fd
, "w" );
3939 if (errno
!= EEXIST
) break;
3942 if (!ret
) fatal_error( "failed to create output file for '%s'\n", orig
);
3943 temp_file_name
= name
;
3948 /*******************************************************************
3951 static void rename_temp_file( const char *dest
)
3953 int ret
= rename( temp_file_name
, dest
);
3954 if (ret
== -1 && errno
== EEXIST
)
3956 /* rename doesn't overwrite on windows */
3958 ret
= rename( temp_file_name
, dest
);
3960 if (ret
== -1) fatal_error( "failed to rename output file to '%s'\n", dest
);
3961 temp_file_name
= NULL
;
3965 /*******************************************************************
3966 * are_files_identical
3968 static int are_files_identical( FILE *file1
, FILE *file2
)
3972 char buffer1
[8192], buffer2
[8192];
3973 int size1
= fread( buffer1
, 1, sizeof(buffer1
), file1
);
3974 int size2
= fread( buffer2
, 1, sizeof(buffer2
), file2
);
3975 if (size1
!= size2
) return 0;
3976 if (!size1
) return feof( file1
) && feof( file2
);
3977 if (memcmp( buffer1
, buffer2
, size1
)) return 0;
3982 /*******************************************************************
3983 * rename_temp_file_if_changed
3985 static void rename_temp_file_if_changed( const char *dest
)
3987 FILE *file1
, *file2
;
3990 if ((file1
= fopen( dest
, "r" )))
3992 if ((file2
= fopen( temp_file_name
, "r" )))
3994 do_rename
= !are_files_identical( file1
, file2
);
4001 unlink( temp_file_name
);
4002 temp_file_name
= NULL
;
4004 else rename_temp_file( dest
);
4008 /*******************************************************************
4011 static void output_linguas( const struct makefile
*make
)
4013 const char *dest
= base_dir_path( make
, "LINGUAS" );
4014 struct incl_file
*source
;
4016 output_file
= create_temp_file( dest
);
4018 output( "# Automatically generated by make depend; DO NOT EDIT!!\n" );
4019 LIST_FOR_EACH_ENTRY( source
, &make
->sources
, struct incl_file
, entry
)
4020 if (strendswith( source
->name
, ".po" ))
4021 output( "%s\n", replace_extension( source
->name
, ".po", "" ));
4023 if (fclose( output_file
)) fatal_perror( "write" );
4025 rename_temp_file_if_changed( dest
);
4029 /*******************************************************************
4032 static void output_testlist( const struct makefile
*make
)
4034 const char *dest
= base_dir_path( make
, "testlist.c" );
4035 struct strarray files
= empty_strarray
;
4038 for (i
= 0; i
< make
->ok_files
.count
; i
++)
4039 strarray_add( &files
, replace_extension( make
->ok_files
.str
[i
], ".ok", "" ));
4041 output_file
= create_temp_file( dest
);
4043 output( "/* Automatically generated by make depend; DO NOT EDIT!! */\n\n" );
4044 output( "#define WIN32_LEAN_AND_MEAN\n" );
4045 output( "#include <windows.h>\n\n" );
4046 output( "#define STANDALONE\n" );
4047 output( "#include \"wine/test.h\"\n\n" );
4049 for (i
= 0; i
< files
.count
; i
++) output( "extern void func_%s(void);\n", files
.str
[i
] );
4051 output( "const struct test winetest_testlist[] =\n" );
4053 for (i
= 0; i
< files
.count
; i
++) output( " { \"%s\", func_%s },\n", files
.str
[i
], files
.str
[i
] );
4054 output( " { 0, 0 }\n" );
4057 if (fclose( output_file
)) fatal_perror( "write" );
4059 rename_temp_file_if_changed( dest
);
4063 /*******************************************************************
4066 static void output_gitignore( const char *dest
, struct strarray files
)
4070 output_file
= create_temp_file( dest
);
4072 output( "# Automatically generated by make depend; DO NOT EDIT!!\n" );
4073 for (i
= 0; i
< files
.count
; i
++)
4075 if (!strchr( files
.str
[i
], '/' )) output( "/" );
4076 output( "%s\n", files
.str
[i
] );
4079 if (fclose( output_file
)) fatal_perror( "write" );
4081 rename_temp_file( dest
);
4085 /*******************************************************************
4086 * output_top_variables
4088 static void output_top_variables( const struct makefile
*make
)
4091 struct strarray
*vars
= &top_makefile
->vars
;
4093 if (!make
->base_dir
) return; /* don't output variables in the top makefile */
4095 output( "# Automatically generated by make depend; DO NOT EDIT!!\n\n" );
4096 output( "all:\n\n" );
4097 for (i
= 0; i
< vars
->count
; i
+= 2)
4099 if (!strcmp( vars
->str
[i
], "SUBDIRS" )) continue; /* not inherited */
4100 output( "%s = %s\n", vars
->str
[i
], get_make_variable( make
, vars
->str
[i
] ));
4106 /*******************************************************************
4107 * output_dependencies
4109 static void output_dependencies( struct makefile
*make
)
4111 struct strarray ignore_files
= empty_strarray
;
4116 if (make
->base_dir
) create_dir( make
->base_dir
);
4118 output_file_name
= base_dir_path( make
, output_makefile_name
);
4119 output_file
= create_temp_file( output_file_name
);
4120 output_top_variables( make
);
4122 /* copy the contents of the source makefile */
4123 src_file
= open_input_makefile( make
);
4124 while (fgets( buffer
, sizeof(buffer
), src_file
) && !found
)
4126 if (fwrite( buffer
, 1, strlen(buffer
), output_file
) != strlen(buffer
)) fatal_perror( "write" );
4127 found
= !strncmp( buffer
, separator
, strlen(separator
) );
4129 if (fclose( src_file
)) fatal_perror( "close" );
4130 input_file_name
= NULL
;
4132 if (!found
) output( "\n%s (everything below this line is auto-generated; DO NOT EDIT!!)\n", separator
);
4133 output_sources( make
);
4135 fclose( output_file
);
4137 rename_temp_file( output_file_name
);
4139 strarray_addall( &ignore_files
, make
->distclean_files
);
4140 strarray_addall( &ignore_files
, make
->clean_files
);
4141 if (make
->testdll
) output_testlist( make
);
4142 if (make
->base_dir
&& !strcmp( make
->base_dir
, "po" )) output_linguas( make
);
4143 if (!make
->src_dir
) output_gitignore( base_dir_path( make
, ".gitignore" ), ignore_files
);
4145 create_file_directories( make
, ignore_files
);
4147 output_file_name
= NULL
;
4151 /*******************************************************************
4154 static void load_sources( struct makefile
*make
)
4156 static const char *source_vars
[] =
4175 const char **var
, *crt_dll
= NULL
;
4177 struct strarray value
;
4178 struct incl_file
*file
;
4182 make
->top_src_dir
= concat_paths( make
->top_obj_dir
, root_src_dir
);
4183 make
->src_dir
= concat_paths( make
->top_src_dir
, make
->base_dir
);
4185 strarray_set_value( &make
->vars
, "top_builddir", top_obj_dir_path( make
, "" ));
4186 strarray_set_value( &make
->vars
, "top_srcdir", top_src_dir_path( make
, "" ));
4187 strarray_set_value( &make
->vars
, "srcdir", src_dir_path( make
, "" ));
4189 make
->parent_dir
= get_expanded_make_variable( make
, "PARENTSRC" );
4190 make
->module
= get_expanded_make_variable( make
, "MODULE" );
4191 make
->testdll
= get_expanded_make_variable( make
, "TESTDLL" );
4192 make
->sharedlib
= get_expanded_make_variable( make
, "SHAREDLIB" );
4193 make
->staticlib
= get_expanded_make_variable( make
, "STATICLIB" );
4194 make
->importlib
= get_expanded_make_variable( make
, "IMPORTLIB" );
4196 make
->programs
= get_expanded_make_var_array( make
, "PROGRAMS" );
4197 make
->scripts
= get_expanded_make_var_array( make
, "SCRIPTS" );
4198 make
->imports
= get_expanded_make_var_array( make
, "IMPORTS" );
4199 make
->delayimports
= get_expanded_make_var_array( make
, "DELAYIMPORTS" );
4200 make
->extradllflags
= get_expanded_make_var_array( make
, "EXTRADLLFLAGS" );
4201 make
->install_lib
= get_expanded_make_var_array( make
, "INSTALL_LIB" );
4202 make
->install_dev
= get_expanded_make_var_array( make
, "INSTALL_DEV" );
4203 make
->extra_targets
= get_expanded_make_var_array( make
, "EXTRA_TARGETS" );
4205 if (make
->module
&& strendswith( make
->module
, ".a" )) make
->staticlib
= make
->module
;
4207 if ((make
->module
&& make
->staticlib
) || make
->testdll
)
4208 strarray_add( &make
->extradllflags
, "-mno-cygwin" );
4210 strarray_addall( &make
->extradllflags
, get_expanded_make_var_array( make
, "APPMODE" ));
4211 make
->disabled
= make
->base_dir
&& strarray_exists( &disabled_dirs
, make
->base_dir
);
4212 make
->is_win16
= strarray_exists( &make
->extradllflags
, "-m16" );
4213 make
->use_msvcrt
= strarray_exists( &make
->extradllflags
, "-mno-cygwin" );
4214 make
->is_exe
= strarray_exists( &make
->extradllflags
, "-mconsole" ) ||
4215 strarray_exists( &make
->extradllflags
, "-mwindows" );
4217 if (make
->module
&& !make
->install_lib
.count
&& !make
->install_dev
.count
)
4219 if (make
->importlib
) strarray_add( &make
->install_dev
, make
->importlib
);
4220 if (make
->staticlib
) strarray_add( &make
->install_dev
, make
->staticlib
);
4221 else strarray_add( &make
->install_lib
, make
->module
);
4224 make
->include_paths
= empty_strarray
;
4225 make
->include_args
= empty_strarray
;
4226 make
->define_args
= empty_strarray
;
4227 strarray_add( &make
->define_args
, "-D__WINESRC__" );
4229 value
= get_expanded_make_var_array( make
, "EXTRAINCL" );
4230 for (i
= 0; i
< value
.count
; i
++)
4231 if (!strncmp( value
.str
[i
], "-I", 2 ))
4232 strarray_add_uniq( &make
->include_paths
, value
.str
[i
] + 2 );
4234 strarray_add_uniq( &make
->define_args
, value
.str
[i
] );
4235 strarray_addall( &make
->define_args
, get_expanded_make_var_array( make
, "EXTRADEFS" ));
4237 strarray_add( &make
->include_args
, strmake( "-I%s", obj_dir_path( make
, "" )));
4239 strarray_add( &make
->include_args
, strmake( "-I%s", make
->src_dir
));
4240 if (make
->parent_dir
)
4241 strarray_add( &make
->include_args
, strmake( "-I%s", src_dir_path( make
, make
->parent_dir
)));
4242 strarray_add( &make
->include_args
, strmake( "-I%s", top_obj_dir_path( make
, "include" )));
4243 if (make
->top_src_dir
)
4244 strarray_add( &make
->include_args
, strmake( "-I%s", top_src_dir_path( make
, "include" )));
4246 list_init( &make
->sources
);
4247 list_init( &make
->includes
);
4249 for (var
= source_vars
; *var
; var
++)
4251 value
= get_expanded_make_var_array( make
, *var
);
4252 for (i
= 0; i
< value
.count
; i
++) add_src_file( make
, value
.str
[i
] );
4255 add_generated_sources( make
);
4257 if (!make
->use_msvcrt
&& !has_object_file( make
))
4259 strarray_add( &make
->extradllflags
, "-mno-cygwin" );
4260 make
->use_msvcrt
= 1;
4263 if (make
->use_msvcrt
)
4265 for (i
= 0; i
< make
->imports
.count
; i
++)
4267 if (strncmp( make
->imports
.str
[i
], "msvcr", 5 ) && strncmp( make
->imports
.str
[i
], "ucrt", 4 )) continue;
4268 if (crt_dll
) fatal_error( "More than one crt DLL imported: %s %s\n", crt_dll
, make
->imports
.str
[i
] );
4269 crt_dll
= make
->imports
.str
[i
];
4271 if (!crt_dll
&& !strarray_exists( &make
->extradllflags
, "-nodefaultlibs" ))
4273 if (make
->use_msvcrt
&& !make
->testdll
&& !make
->staticlib
)
4275 strarray_add( &make
->imports
, "ucrtbase" );
4276 crt_dll
= "ucrtbase";
4278 else crt_dll
= "msvcrt";
4280 if (crt_dll
&& !strncmp( crt_dll
, "ucrt", 4 )) strarray_add( &make
->define_args
, "-D_UCRT" );
4283 LIST_FOR_EACH_ENTRY( file
, &make
->includes
, struct incl_file
, entry
) parse_file( make
, file
, 0 );
4284 LIST_FOR_EACH_ENTRY( file
, &make
->sources
, struct incl_file
, entry
) get_dependencies( file
, file
);
4286 make
->is_cross
= crosstarget
&& make
->use_msvcrt
;
4290 for (i
= 0; i
< make
->imports
.count
; i
++)
4291 strarray_add_uniq( &cross_import_libs
, make
->imports
.str
[i
] );
4292 if (crt_dll
) strarray_add_uniq( &cross_import_libs
, crt_dll
);
4293 if (make
->is_win16
) strarray_add_uniq( &cross_import_libs
, "kernel" );
4294 strarray_add_uniq( &cross_import_libs
, "winecrt0" );
4295 strarray_add_uniq( &cross_import_libs
, "kernel32" );
4296 strarray_add_uniq( &cross_import_libs
, "ntdll" );
4299 if (!*dll_ext
|| make
->is_cross
)
4300 for (i
= 0; i
< make
->delayimports
.count
; i
++)
4301 strarray_add_uniq( &delay_import_libs
, get_base_name( make
->delayimports
.str
[i
] ));
4305 /*******************************************************************
4308 static void parse_makeflags( const char *flags
)
4310 const char *p
= flags
;
4311 char *var
, *buffer
= xmalloc( strlen(flags
) + 1 );
4315 while (isspace(*p
)) p
++;
4317 while (*p
&& !isspace(*p
))
4319 if (*p
== '\\' && p
[1]) p
++;
4323 if (var
> buffer
) set_make_variable( &cmdline_vars
, buffer
);
4328 /*******************************************************************
4331 static int parse_option( const char *opt
)
4335 if (strchr( opt
, '=' )) return set_make_variable( &cmdline_vars
, opt
);
4341 if (opt
[2]) output_makefile_name
= opt
+ 2;
4344 relative_dir_mode
= 1;
4347 fprintf( stderr
, "Unknown option '%s'\n%s", opt
, Usage
);
4354 /*******************************************************************
4357 int main( int argc
, char *argv
[] )
4359 const char *makeflags
= getenv( "MAKEFLAGS" );
4362 if (makeflags
) parse_makeflags( makeflags
);
4367 if (parse_option( argv
[i
] ))
4369 for (j
= i
; j
< argc
; j
++) argv
[j
] = argv
[j
+1];
4375 if (relative_dir_mode
)
4381 fprintf( stderr
, "Option -R needs two directories\n%s", Usage
);
4384 relpath
= get_relative_path( argv
[1], argv
[2] );
4385 printf( "%s\n", relpath
? relpath
: "." );
4389 atexit( cleanup_files
);
4390 signal( SIGTERM
, exit_on_signal
);
4391 signal( SIGINT
, exit_on_signal
);
4393 signal( SIGHUP
, exit_on_signal
);
4396 for (i
= 0; i
< HASH_SIZE
; i
++) list_init( &files
[i
] );
4398 top_makefile
= parse_makefile( NULL
);
4400 target_flags
= get_expanded_make_var_array( top_makefile
, "TARGETFLAGS" );
4401 msvcrt_flags
= get_expanded_make_var_array( top_makefile
, "MSVCRTFLAGS" );
4402 dll_flags
= get_expanded_make_var_array( top_makefile
, "DLLFLAGS" );
4403 extra_cflags
= get_expanded_make_var_array( top_makefile
, "EXTRACFLAGS" );
4404 extra_cross_cflags
= get_expanded_make_var_array( top_makefile
, "EXTRACROSSCFLAGS" );
4405 cpp_flags
= get_expanded_make_var_array( top_makefile
, "CPPFLAGS" );
4406 lddll_flags
= get_expanded_make_var_array( top_makefile
, "LDDLLFLAGS" );
4407 libs
= get_expanded_make_var_array( top_makefile
, "LIBS" );
4408 enable_tests
= get_expanded_make_var_array( top_makefile
, "ENABLE_TESTS" );
4409 delay_load_flag
= get_expanded_make_variable( top_makefile
, "DELAYLOADFLAG" );
4410 top_install_lib
= get_expanded_make_var_array( top_makefile
, "TOP_INSTALL_LIB" );
4411 top_install_dev
= get_expanded_make_var_array( top_makefile
, "TOP_INSTALL_DEV" );
4413 root_src_dir
= get_expanded_make_variable( top_makefile
, "srcdir" );
4414 tools_dir
= get_expanded_make_variable( top_makefile
, "TOOLSDIR" );
4415 tools_ext
= get_expanded_make_variable( top_makefile
, "TOOLSEXT" );
4416 exe_ext
= get_expanded_make_variable( top_makefile
, "EXEEXT" );
4417 man_ext
= get_expanded_make_variable( top_makefile
, "api_manext" );
4418 dll_ext
= (exe_ext
&& !strcmp( exe_ext
, ".exe" )) ? "" : ".so";
4419 crosstarget
= get_expanded_make_variable( top_makefile
, "CROSSTARGET" );
4420 fontforge
= get_expanded_make_variable( top_makefile
, "FONTFORGE" );
4421 convert
= get_expanded_make_variable( top_makefile
, "CONVERT" );
4422 flex
= get_expanded_make_variable( top_makefile
, "FLEX" );
4423 bison
= get_expanded_make_variable( top_makefile
, "BISON" );
4424 ar
= get_expanded_make_variable( top_makefile
, "AR" );
4425 ranlib
= get_expanded_make_variable( top_makefile
, "RANLIB" );
4426 rsvg
= get_expanded_make_variable( top_makefile
, "RSVG" );
4427 icotool
= get_expanded_make_variable( top_makefile
, "ICOTOOL" );
4428 dlltool
= get_expanded_make_variable( top_makefile
, "DLLTOOL" );
4429 msgfmt
= get_expanded_make_variable( top_makefile
, "MSGFMT" );
4430 sed_cmd
= get_expanded_make_variable( top_makefile
, "SED_CMD" );
4431 ln_s
= get_expanded_make_variable( top_makefile
, "LN_S" );
4433 if (root_src_dir
&& !strcmp( root_src_dir
, "." )) root_src_dir
= NULL
;
4434 if (tools_dir
&& !strcmp( tools_dir
, "." )) tools_dir
= NULL
;
4435 if (!exe_ext
) exe_ext
= "";
4436 if (!tools_ext
) tools_ext
= "";
4437 if (!man_ext
) man_ext
= "3w";
4441 disabled_dirs
= get_expanded_make_var_array( top_makefile
, "DISABLED_SUBDIRS" );
4442 top_makefile
->subdirs
= get_expanded_make_var_array( top_makefile
, "SUBDIRS" );
4443 top_makefile
->submakes
= xmalloc( top_makefile
->subdirs
.count
* sizeof(*top_makefile
->submakes
) );
4445 for (i
= 0; i
< top_makefile
->subdirs
.count
; i
++)
4446 top_makefile
->submakes
[i
] = parse_makefile( top_makefile
->subdirs
.str
[i
] );
4448 load_sources( top_makefile
);
4449 for (i
= 0; i
< top_makefile
->subdirs
.count
; i
++)
4450 load_sources( top_makefile
->submakes
[i
] );
4452 for (i
= 0; i
< top_makefile
->subdirs
.count
; i
++)
4453 output_dependencies( top_makefile
->submakes
[i
] );
4455 output_dependencies( top_makefile
);
4459 for (i
= 1; i
< argc
; i
++)
4461 struct makefile
*make
= parse_makefile( argv
[i
] );
4462 load_sources( make
);
4463 output_dependencies( make
);