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 INCL_NORMAL
, /* #include "foo.h" */
41 INCL_SYSTEM
, /* #include <foo.h> */
42 INCL_IMPORT
, /* idl import "foo.idl" */
43 INCL_IMPORTLIB
, /* idl importlib "foo.tlb" */
44 INCL_CPP_QUOTE
, /* idl cpp_quote("#include \"foo.h\"") */
45 INCL_CPP_QUOTE_SYSTEM
/* idl cpp_quote("#include <foo.h>") */
50 int line
; /* source line where this header is included */
51 enum incl_type type
; /* type of include */
52 char *name
; /* header name */
58 char *name
; /* full file name relative to cwd */
59 void *args
; /* custom arguments for makefile rule */
60 unsigned int flags
; /* flags (see below) */
61 unsigned int deps_count
; /* files in use */
62 unsigned int deps_size
; /* total allocated size */
63 struct dependency
*deps
; /* all header dependencies */
72 char *sourcename
; /* source file name for generated headers */
73 struct incl_file
*included_by
; /* file that included this one */
74 int included_line
; /* line where this file was included */
75 enum incl_type type
; /* type of include */
76 struct incl_file
*owner
;
77 unsigned int files_count
; /* files in use */
78 unsigned int files_size
; /* total allocated size */
79 struct incl_file
**files
;
82 #define FLAG_GENERATED 0x000001 /* generated file */
83 #define FLAG_INSTALL 0x000002 /* file to install */
84 #define FLAG_IDL_PROXY 0x000100 /* generates a proxy (_p.c) file */
85 #define FLAG_IDL_CLIENT 0x000200 /* generates a client (_c.c) file */
86 #define FLAG_IDL_SERVER 0x000400 /* generates a server (_s.c) file */
87 #define FLAG_IDL_IDENT 0x000800 /* generates an ident (_i.c) file */
88 #define FLAG_IDL_REGISTER 0x001000 /* generates a registration (_r.res) file */
89 #define FLAG_IDL_TYPELIB 0x002000 /* generates a typelib (.tlb) file */
90 #define FLAG_IDL_REGTYPELIB 0x004000 /* generates a registered typelib (_t.res) file */
91 #define FLAG_IDL_HEADER 0x008000 /* generates a header (.h) file */
92 #define FLAG_RC_PO 0x010000 /* rc file contains translations */
93 #define FLAG_C_IMPLIB 0x020000 /* file is part of an import library */
94 #define FLAG_SFD_FONTS 0x040000 /* sfd file generated bitmap fonts */
102 { FLAG_IDL_TYPELIB
, ".tlb" },
103 { FLAG_IDL_REGTYPELIB
, "_t.res" },
104 { FLAG_IDL_CLIENT
, "_c.c" },
105 { FLAG_IDL_IDENT
, "_i.c" },
106 { FLAG_IDL_PROXY
, "_p.c" },
107 { FLAG_IDL_SERVER
, "_s.c" },
108 { FLAG_IDL_REGISTER
, "_r.res" },
109 { FLAG_IDL_HEADER
, ".h" }
112 #define HASH_SIZE 997
114 static struct list files
[HASH_SIZE
];
118 unsigned int count
; /* strings in use */
119 unsigned int size
; /* total allocated size */
123 static const struct strarray empty_strarray
;
125 enum install_rules
{ INSTALL_LIB
, INSTALL_DEV
, NB_INSTALL_RULES
};
127 /* variables common to all makefiles */
128 static struct strarray linguas
;
129 static struct strarray dll_flags
;
130 static struct strarray target_flags
;
131 static struct strarray msvcrt_flags
;
132 static struct strarray extra_cflags
;
133 static struct strarray cpp_flags
;
134 static struct strarray unwind_flags
;
135 static struct strarray libs
;
136 static struct strarray cmdline_vars
;
137 static struct strarray disabled_dirs
;
138 static const char *root_src_dir
;
139 static const char *tools_dir
;
140 static const char *tools_ext
;
141 static const char *exe_ext
;
142 static const char *dll_ext
;
143 static const char *man_ext
;
144 static const char *crosstarget
;
145 static const char *fontforge
;
146 static const char *convert
;
147 static const char *rsvg
;
148 static const char *icotool
;
149 static const char *dlltool
;
150 static const char *msgfmt
;
151 static const char *ln_s
;
155 struct strarray vars
;
156 struct strarray include_paths
;
157 struct strarray define_args
;
158 struct strarray programs
;
159 struct strarray scripts
;
160 struct strarray appmode
;
161 struct strarray imports
;
162 struct strarray subdirs
;
163 struct strarray delayimports
;
164 struct strarray extradllflags
;
165 struct strarray install_lib
;
166 struct strarray install_dev
;
168 struct list includes
;
169 const char *base_dir
;
172 const char *top_src_dir
;
173 const char *top_obj_dir
;
174 const char *parent_dir
;
177 const char *sharedlib
;
178 const char *staticlib
;
179 const char *staticimplib
;
180 const char *importlib
;
184 struct makefile
**submakes
;
187 static struct makefile
*top_makefile
;
189 static const char separator
[] = "### Dependencies";
190 static const char *output_makefile_name
= "Makefile";
191 static const char *input_file_name
;
192 static const char *output_file_name
;
193 static const char *temp_file_name
;
194 static int relative_dir_mode
;
195 static int input_line
;
196 static int output_column
;
197 static FILE *output_file
;
199 static const char Usage
[] =
200 "Usage: makedep [options] [directories]\n"
202 " -R from to Compute the relative path between two directories\n"
203 " -fxxx Store output in file 'xxx' (default: Makefile)\n";
207 #define __attribute__(x)
210 static void fatal_error( const char *msg
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
211 static void fatal_perror( const char *msg
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
212 static void output( const char *format
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
213 static char *strmake( const char* fmt
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
215 /*******************************************************************
218 static void fatal_error( const char *msg
, ... )
221 va_start( valist
, msg
);
224 fprintf( stderr
, "%s:", input_file_name
);
225 if (input_line
) fprintf( stderr
, "%d:", input_line
);
226 fprintf( stderr
, " error: " );
228 else fprintf( stderr
, "makedep: error: " );
229 vfprintf( stderr
, msg
, valist
);
235 /*******************************************************************
238 static void fatal_perror( const char *msg
, ... )
241 va_start( valist
, msg
);
244 fprintf( stderr
, "%s:", input_file_name
);
245 if (input_line
) fprintf( stderr
, "%d:", input_line
);
246 fprintf( stderr
, " error: " );
248 else fprintf( stderr
, "makedep: error: " );
249 vfprintf( stderr
, msg
, valist
);
256 /*******************************************************************
259 static void cleanup_files(void)
261 if (temp_file_name
) unlink( temp_file_name
);
262 if (output_file_name
) unlink( output_file_name
);
266 /*******************************************************************
269 static void exit_on_signal( int sig
)
271 exit( 1 ); /* this will call the atexit functions */
275 /*******************************************************************
278 static void *xmalloc( size_t size
)
281 if (!(res
= malloc (size
? size
: 1)))
282 fatal_error( "Virtual memory exhausted.\n" );
287 /*******************************************************************
290 static void *xrealloc (void *ptr
, size_t size
)
294 if (!(res
= realloc( ptr
, size
)))
295 fatal_error( "Virtual memory exhausted.\n" );
299 /*******************************************************************
302 static char *xstrdup( const char *str
)
304 char *res
= strdup( str
);
305 if (!res
) fatal_error( "Virtual memory exhausted.\n" );
310 /*******************************************************************
313 static char *strmake( const char* fmt
, ... )
321 char *p
= xmalloc (size
);
323 n
= vsnprintf (p
, size
, fmt
, ap
);
325 if (n
== -1) size
*= 2;
326 else if ((size_t)n
>= size
) size
= n
+ 1;
327 else return xrealloc( p
, n
+ 1 );
333 /*******************************************************************
336 static int strendswith( const char* str
, const char* end
)
338 size_t l
= strlen( str
);
339 size_t m
= strlen( end
);
341 return l
>= m
&& strcmp(str
+ l
- m
, end
) == 0;
345 /*******************************************************************
348 static void output( const char *format
, ... )
353 va_start( valist
, format
);
354 ret
= vfprintf( output_file
, format
, valist
);
356 if (ret
< 0) fatal_perror( "output" );
357 if (format
[0] && format
[strlen(format
) - 1] == '\n') output_column
= 0;
358 else output_column
+= ret
;
362 /*******************************************************************
365 static void strarray_add( struct strarray
*array
, const char *str
)
367 if (array
->count
== array
->size
)
369 if (array
->size
) array
->size
*= 2;
370 else array
->size
= 16;
371 array
->str
= xrealloc( array
->str
, sizeof(array
->str
[0]) * array
->size
);
373 array
->str
[array
->count
++] = str
;
377 /*******************************************************************
380 static void strarray_addall( struct strarray
*array
, struct strarray added
)
384 for (i
= 0; i
< added
.count
; i
++) strarray_add( array
, added
.str
[i
] );
388 /*******************************************************************
391 static int strarray_exists( const struct strarray
*array
, const char *str
)
395 for (i
= 0; i
< array
->count
; i
++) if (!strcmp( array
->str
[i
], str
)) return 1;
400 /*******************************************************************
403 static void strarray_add_uniq( struct strarray
*array
, const char *str
)
405 if (!strarray_exists( array
, str
)) strarray_add( array
, str
);
409 /*******************************************************************
412 * Find a value in a name/value pair string array.
414 static const char *strarray_get_value( const struct strarray
*array
, const char *name
)
416 int pos
, res
, min
= 0, max
= array
->count
/ 2 - 1;
420 pos
= (min
+ max
) / 2;
421 if (!(res
= strcmp( array
->str
[pos
* 2], name
))) return array
->str
[pos
* 2 + 1];
422 if (res
< 0) min
= pos
+ 1;
429 /*******************************************************************
432 * Define a value in a name/value pair string array.
434 static void strarray_set_value( struct strarray
*array
, const char *name
, const char *value
)
436 int i
, pos
, res
, min
= 0, max
= array
->count
/ 2 - 1;
440 pos
= (min
+ max
) / 2;
441 if (!(res
= strcmp( array
->str
[pos
* 2], name
)))
443 /* redefining a variable replaces the previous value */
444 array
->str
[pos
* 2 + 1] = value
;
447 if (res
< 0) min
= pos
+ 1;
450 strarray_add( array
, NULL
);
451 strarray_add( array
, NULL
);
452 for (i
= array
->count
- 1; i
> min
* 2 + 1; i
--) array
->str
[i
] = array
->str
[i
- 2];
453 array
->str
[min
* 2] = name
;
454 array
->str
[min
* 2 + 1] = value
;
458 /*******************************************************************
461 static void output_filename( const char *name
)
463 if (output_column
+ strlen(name
) + 1 > 100)
468 else if (output_column
) output( " " );
469 output( "%s", name
);
473 /*******************************************************************
476 static void output_filenames( struct strarray array
)
480 for (i
= 0; i
< array
.count
; i
++) output_filename( array
.str
[i
] );
484 /*******************************************************************
487 static char *get_extension( char *filename
)
489 char *ext
= strrchr( filename
, '.' );
490 if (ext
&& strchr( ext
, '/' )) ext
= NULL
;
495 /*******************************************************************
498 static char *replace_extension( const char *name
, const char *old_ext
, const char *new_ext
)
501 size_t name_len
= strlen( name
);
502 size_t ext_len
= strlen( old_ext
);
504 if (name_len
>= ext_len
&& !strcmp( name
+ name_len
- ext_len
, old_ext
)) name_len
-= ext_len
;
505 ret
= xmalloc( name_len
+ strlen( new_ext
) + 1 );
506 memcpy( ret
, name
, name_len
);
507 strcpy( ret
+ name_len
, new_ext
);
512 /*******************************************************************
515 static char *replace_filename( const char *path
, const char *name
)
521 if (!path
) return xstrdup( name
);
522 if (!(p
= strrchr( path
, '/' ))) return xstrdup( name
);
524 ret
= xmalloc( len
+ strlen( name
) + 1 );
525 memcpy( ret
, path
, len
);
526 strcpy( ret
+ len
, name
);
531 /*******************************************************************
532 * strarray_replace_extension
534 static struct strarray
strarray_replace_extension( const struct strarray
*array
,
535 const char *old_ext
, const char *new_ext
)
540 ret
.count
= ret
.size
= array
->count
;
541 ret
.str
= xmalloc( sizeof(ret
.str
[0]) * ret
.size
);
542 for (i
= 0; i
< array
->count
; i
++) ret
.str
[i
] = replace_extension( array
->str
[i
], old_ext
, new_ext
);
547 /*******************************************************************
550 static char *replace_substr( const char *str
, const char *start
, size_t len
, const char *replace
)
552 size_t pos
= start
- str
;
553 char *ret
= xmalloc( pos
+ strlen(replace
) + strlen(start
+ len
) + 1 );
554 memcpy( ret
, str
, pos
);
555 strcpy( ret
+ pos
, replace
);
556 strcat( ret
+ pos
, start
+ len
);
561 /*******************************************************************
564 * Determine where the destination path is located relative to the 'from' path.
566 static char *get_relative_path( const char *from
, const char *dest
)
570 unsigned int dotdots
= 0;
572 /* a path of "." is equivalent to an empty path */
573 if (!strcmp( from
, "." )) from
= "";
577 while (*from
== '/') from
++;
578 while (*dest
== '/') dest
++;
579 start
= dest
; /* save start of next path element */
582 while (*from
&& *from
!= '/' && *from
== *dest
) { from
++; dest
++; }
583 if ((!*from
|| *from
== '/') && (!*dest
|| *dest
== '/')) continue;
585 /* count remaining elements in 'from' */
589 while (*from
&& *from
!= '/') from
++;
590 while (*from
== '/') from
++;
596 if (!start
[0] && !dotdots
) return NULL
; /* empty path */
598 ret
= xmalloc( 3 * dotdots
+ strlen( start
) + 1 );
599 for (p
= ret
; dotdots
; dotdots
--, p
+= 3) memcpy( p
, "../", 3 );
601 if (start
[0]) strcpy( p
, start
);
602 else p
[-1] = 0; /* remove trailing slash */
607 /*******************************************************************
610 static char *concat_paths( const char *base
, const char *path
)
612 if (!base
|| !base
[0]) return xstrdup( path
&& path
[0] ? path
: "." );
613 if (!path
|| !path
[0]) return xstrdup( base
);
614 if (path
[0] == '/') return xstrdup( path
);
615 return strmake( "%s/%s", base
, path
);
619 /*******************************************************************
622 static char *base_dir_path( const struct makefile
*make
, const char *path
)
624 return concat_paths( make
->base_dir
, path
);
628 /*******************************************************************
631 static char *obj_dir_path( const struct makefile
*make
, const char *path
)
633 return concat_paths( make
->obj_dir
, path
);
637 /*******************************************************************
640 static char *src_dir_path( const struct makefile
*make
, const char *path
)
642 if (make
->src_dir
) return concat_paths( make
->src_dir
, path
);
643 return obj_dir_path( make
, path
);
647 /*******************************************************************
650 static char *top_obj_dir_path( const struct makefile
*make
, const char *path
)
652 return concat_paths( make
->top_obj_dir
, path
);
656 /*******************************************************************
659 static char *top_src_dir_path( const struct makefile
*make
, const char *path
)
661 if (make
->top_src_dir
) return concat_paths( make
->top_src_dir
, path
);
662 return top_obj_dir_path( make
, path
);
666 /*******************************************************************
669 static char *root_dir_path( const char *path
)
671 return concat_paths( root_src_dir
, path
);
675 /*******************************************************************
678 static char *tools_dir_path( const struct makefile
*make
, const char *path
)
680 if (tools_dir
) return top_obj_dir_path( make
, strmake( "%s/tools/%s", tools_dir
, path
));
681 return top_obj_dir_path( make
, strmake( "tools/%s", path
));
685 /*******************************************************************
688 static char *tools_path( const struct makefile
*make
, const char *name
)
690 return strmake( "%s/%s%s", tools_dir_path( make
, name
), name
, tools_ext
);
694 /*******************************************************************
697 static char *get_line( FILE *file
)
705 buffer
= xmalloc( size
);
707 if (!fgets( buffer
, size
, file
)) return NULL
;
712 char *p
= buffer
+ strlen(buffer
);
713 /* if line is larger than buffer, resize buffer */
714 while (p
== buffer
+ size
- 1 && p
[-1] != '\n')
716 buffer
= xrealloc( buffer
, size
* 2 );
717 if (!fgets( buffer
+ size
- 1, size
+ 1, file
)) break;
718 p
= buffer
+ strlen(buffer
);
721 if (p
> buffer
&& p
[-1] == '\n')
724 if (p
> buffer
&& p
[-1] == '\r') *(--p
) = 0;
725 if (p
> buffer
&& p
[-1] == '\\')
728 /* line ends in backslash, read continuation line */
729 if (!fgets( p
, size
- (p
- buffer
), file
)) return buffer
;
739 /*******************************************************************
742 static unsigned int hash_filename( const char *name
)
745 unsigned int ret
= 2166136261u;
746 while (*name
) ret
= (ret
* 16777619) ^ *name
++;
747 return ret
% HASH_SIZE
;
751 /*******************************************************************
754 static struct file
*add_file( const char *name
)
756 struct file
*file
= xmalloc( sizeof(*file
) );
757 memset( file
, 0, sizeof(*file
) );
758 file
->name
= xstrdup( name
);
763 /*******************************************************************
766 static void add_dependency( struct file
*file
, const char *name
, enum incl_type type
)
768 /* enforce some rules for the Wine tree */
770 if (!memcmp( name
, "../", 3 ))
771 fatal_error( "#include directive with relative path not allowed\n" );
773 if (!strcmp( name
, "config.h" ))
775 if (strendswith( file
->name
, ".h" ))
776 fatal_error( "config.h must not be included by a header file\n" );
777 if (file
->deps_count
)
778 fatal_error( "config.h must be included before anything else\n" );
780 else if (!strcmp( name
, "wine/port.h" ))
782 if (strendswith( file
->name
, ".h" ))
783 fatal_error( "wine/port.h must not be included by a header file\n" );
784 if (!file
->deps_count
) fatal_error( "config.h must be included before wine/port.h\n" );
785 if (file
->deps_count
> 1)
786 fatal_error( "wine/port.h must be included before everything except config.h\n" );
787 if (strcmp( file
->deps
[0].name
, "config.h" ))
788 fatal_error( "config.h must be included before wine/port.h\n" );
791 if (file
->deps_count
>= file
->deps_size
)
793 file
->deps_size
*= 2;
794 if (file
->deps_size
< 16) file
->deps_size
= 16;
795 file
->deps
= xrealloc( file
->deps
, file
->deps_size
* sizeof(*file
->deps
) );
797 file
->deps
[file
->deps_count
].line
= input_line
;
798 file
->deps
[file
->deps_count
].type
= type
;
799 file
->deps
[file
->deps_count
].name
= xstrdup( name
);
804 /*******************************************************************
807 static struct incl_file
*find_src_file( const struct makefile
*make
, const char *name
)
809 struct incl_file
*file
;
811 LIST_FOR_EACH_ENTRY( file
, &make
->sources
, struct incl_file
, entry
)
812 if (!strcmp( name
, file
->name
)) return file
;
816 /*******************************************************************
819 static struct incl_file
*find_include_file( const struct makefile
*make
, const char *name
)
821 struct incl_file
*file
;
823 LIST_FOR_EACH_ENTRY( file
, &make
->includes
, struct incl_file
, entry
)
824 if (!strcmp( name
, file
->name
)) return file
;
828 /*******************************************************************
831 * Add an include file if it doesn't already exists.
833 static struct incl_file
*add_include( struct makefile
*make
, struct incl_file
*parent
,
834 const char *name
, int line
, enum incl_type type
)
836 struct incl_file
*include
;
838 if (parent
->files_count
>= parent
->files_size
)
840 parent
->files_size
*= 2;
841 if (parent
->files_size
< 16) parent
->files_size
= 16;
842 parent
->files
= xrealloc( parent
->files
, parent
->files_size
* sizeof(*parent
->files
) );
845 LIST_FOR_EACH_ENTRY( include
, &make
->includes
, struct incl_file
, entry
)
846 if (!strcmp( name
, include
->name
)) goto found
;
848 include
= xmalloc( sizeof(*include
) );
849 memset( include
, 0, sizeof(*include
) );
850 include
->name
= xstrdup(name
);
851 include
->included_by
= parent
;
852 include
->included_line
= line
;
853 include
->type
= type
;
854 list_add_tail( &make
->includes
, &include
->entry
);
856 parent
->files
[parent
->files_count
++] = include
;
861 /*******************************************************************
862 * add_generated_source
864 * Add a generated source file to the list.
866 static struct incl_file
*add_generated_source( struct makefile
*make
,
867 const char *name
, const char *filename
)
869 struct incl_file
*file
;
871 if ((file
= find_src_file( make
, name
))) return file
; /* we already have it */
872 file
= xmalloc( sizeof(*file
) );
873 memset( file
, 0, sizeof(*file
) );
874 file
->file
= add_file( name
);
875 file
->name
= xstrdup( name
);
876 file
->filename
= obj_dir_path( make
, filename
? filename
: name
);
877 file
->file
->flags
= FLAG_GENERATED
;
878 list_add_tail( &make
->sources
, &file
->entry
);
883 /*******************************************************************
884 * parse_include_directive
886 static void parse_include_directive( struct file
*source
, char *str
)
888 char quote
, *include
, *p
= str
;
890 while (*p
&& isspace(*p
)) p
++;
891 if (*p
!= '\"' && *p
!= '<' ) return;
893 if (quote
== '<') quote
= '>';
895 while (*p
&& (*p
!= quote
)) p
++;
896 if (!*p
) fatal_error( "malformed include directive '%s'\n", str
);
898 add_dependency( source
, include
, (quote
== '>') ? INCL_SYSTEM
: INCL_NORMAL
);
902 /*******************************************************************
903 * parse_pragma_directive
905 static void parse_pragma_directive( struct file
*source
, char *str
)
907 char *flag
, *p
= str
;
909 if (!isspace( *p
)) return;
910 while (*p
&& isspace(*p
)) p
++;
911 p
= strtok( p
, " \t" );
912 if (strcmp( p
, "makedep" )) return;
914 while ((flag
= strtok( NULL
, " \t" )))
916 if (!strcmp( flag
, "depend" ))
918 while ((p
= strtok( NULL
, " \t" ))) add_dependency( source
, p
, INCL_NORMAL
);
921 else if (!strcmp( flag
, "install" )) source
->flags
|= FLAG_INSTALL
;
923 if (strendswith( source
->name
, ".idl" ))
925 if (!strcmp( flag
, "header" )) source
->flags
|= FLAG_IDL_HEADER
;
926 else if (!strcmp( flag
, "proxy" )) source
->flags
|= FLAG_IDL_PROXY
;
927 else if (!strcmp( flag
, "client" )) source
->flags
|= FLAG_IDL_CLIENT
;
928 else if (!strcmp( flag
, "server" )) source
->flags
|= FLAG_IDL_SERVER
;
929 else if (!strcmp( flag
, "ident" )) source
->flags
|= FLAG_IDL_IDENT
;
930 else if (!strcmp( flag
, "typelib" )) source
->flags
|= FLAG_IDL_TYPELIB
;
931 else if (!strcmp( flag
, "register" )) source
->flags
|= FLAG_IDL_REGISTER
;
932 else if (!strcmp( flag
, "regtypelib" )) source
->flags
|= FLAG_IDL_REGTYPELIB
;
934 else if (strendswith( source
->name
, ".rc" ))
936 if (!strcmp( flag
, "po" )) source
->flags
|= FLAG_RC_PO
;
938 else if (strendswith( source
->name
, ".sfd" ))
940 if (!strcmp( flag
, "font" ))
942 struct strarray
*array
= source
->args
;
946 source
->args
= array
= xmalloc( sizeof(*array
) );
947 *array
= empty_strarray
;
948 source
->flags
|= FLAG_SFD_FONTS
;
950 strarray_add( array
, xstrdup( strtok( NULL
, "" )));
954 else if (!strcmp( flag
, "implib" )) source
->flags
|= FLAG_C_IMPLIB
;
959 /*******************************************************************
960 * parse_cpp_directive
962 static void parse_cpp_directive( struct file
*source
, char *str
)
964 while (*str
&& isspace(*str
)) str
++;
965 if (*str
++ != '#') return;
966 while (*str
&& isspace(*str
)) str
++;
968 if (!strncmp( str
, "include", 7 ))
969 parse_include_directive( source
, str
+ 7 );
970 else if (!strncmp( str
, "import", 6 ) && strendswith( source
->name
, ".m" ))
971 parse_include_directive( source
, str
+ 6 );
972 else if (!strncmp( str
, "pragma", 6 ))
973 parse_pragma_directive( source
, str
+ 6 );
977 /*******************************************************************
980 static void parse_idl_file( struct file
*source
, FILE *file
)
982 char *buffer
, *include
;
986 while ((buffer
= get_line( file
)))
990 while (*p
&& isspace(*p
)) p
++;
992 if (!strncmp( p
, "importlib", 9 ))
995 while (*p
&& isspace(*p
)) p
++;
996 if (*p
++ != '(') continue;
997 while (*p
&& isspace(*p
)) p
++;
998 if (*p
++ != '"') continue;
1000 while (*p
&& (*p
!= '"')) p
++;
1001 if (!*p
) fatal_error( "malformed importlib directive\n" );
1003 add_dependency( source
, include
, INCL_IMPORTLIB
);
1007 if (!strncmp( p
, "import", 6 ))
1010 while (*p
&& isspace(*p
)) p
++;
1011 if (*p
!= '"') continue;
1013 while (*p
&& (*p
!= '"')) p
++;
1014 if (!*p
) fatal_error( "malformed import directive\n" );
1016 add_dependency( source
, include
, INCL_IMPORT
);
1020 /* check for #include inside cpp_quote */
1021 if (!strncmp( p
, "cpp_quote", 9 ))
1024 while (*p
&& isspace(*p
)) p
++;
1025 if (*p
++ != '(') continue;
1026 while (*p
&& isspace(*p
)) p
++;
1027 if (*p
++ != '"') continue;
1028 if (*p
++ != '#') continue;
1029 while (*p
&& isspace(*p
)) p
++;
1030 if (strncmp( p
, "include", 7 )) continue;
1032 while (*p
&& isspace(*p
)) p
++;
1033 if (*p
== '\\' && p
[1] == '"')
1040 if (*p
++ != '<' ) continue;
1044 while (*p
&& (*p
!= quote
)) p
++;
1045 if (!*p
|| (quote
== '"' && p
[-1] != '\\'))
1046 fatal_error( "malformed #include directive inside cpp_quote\n" );
1047 if (quote
== '"') p
--; /* remove backslash */
1049 add_dependency( source
, include
, (quote
== '>') ? INCL_CPP_QUOTE_SYSTEM
: INCL_CPP_QUOTE
);
1053 parse_cpp_directive( source
, p
);
1057 /*******************************************************************
1060 static void parse_c_file( struct file
*source
, FILE *file
)
1065 while ((buffer
= get_line( file
)))
1067 parse_cpp_directive( source
, buffer
);
1072 /*******************************************************************
1075 static void parse_rc_file( struct file
*source
, FILE *file
)
1077 char *buffer
, *include
;
1080 while ((buffer
= get_line( file
)))
1084 while (*p
&& isspace(*p
)) p
++;
1086 if (p
[0] == '/' && p
[1] == '*') /* check for magic makedep comment */
1089 while (*p
&& isspace(*p
)) p
++;
1090 if (strncmp( p
, "@makedep:", 9 )) continue;
1092 while (*p
&& isspace(*p
)) p
++;
1097 while (*p
&& *p
!= quote
) p
++;
1102 while (*p
&& !isspace(*p
) && *p
!= '*') p
++;
1105 fatal_error( "malformed makedep comment\n" );
1107 add_dependency( source
, include
, (quote
== '>') ? INCL_SYSTEM
: INCL_NORMAL
);
1111 parse_cpp_directive( source
, buffer
);
1116 /*******************************************************************
1119 static void parse_in_file( struct file
*source
, FILE *file
)
1123 /* make sure it gets rebuilt when the version changes */
1124 add_dependency( source
, "config.h", INCL_SYSTEM
);
1126 if (!strendswith( source
->name
, ".man.in" )) return; /* not a man page */
1129 while ((buffer
= get_line( file
)))
1131 if (strncmp( buffer
, ".TH", 3 )) continue;
1132 if (!(p
= strtok( buffer
, " \t" ))) continue; /* .TH */
1133 if (!(p
= strtok( NULL
, " \t" ))) continue; /* program name */
1134 if (!(p
= strtok( NULL
, " \t" ))) continue; /* man section */
1135 source
->args
= xstrdup( p
);
1141 /*******************************************************************
1144 static void parse_sfd_file( struct file
*source
, FILE *file
)
1146 char *p
, *eol
, *buffer
;
1149 while ((buffer
= get_line( file
)))
1151 if (strncmp( buffer
, "UComments:", 10 )) continue;
1153 while (*p
== ' ') p
++;
1154 if (p
[0] == '"' && p
[1] && buffer
[strlen(buffer
) - 1] == '"')
1157 buffer
[strlen(buffer
) - 1] = 0;
1159 while ((eol
= strstr( p
, "+AAoA" )))
1162 while (*p
&& isspace(*p
)) p
++;
1165 while (*p
&& isspace(*p
)) p
++;
1166 if (!strncmp( p
, "pragma", 6 )) parse_pragma_directive( source
, p
+ 6 );
1170 while (*p
&& isspace(*p
)) p
++;
1171 if (*p
++ != '#') return;
1172 while (*p
&& isspace(*p
)) p
++;
1173 if (!strncmp( p
, "pragma", 6 )) parse_pragma_directive( source
, p
+ 6 );
1182 void (*parse
)( struct file
*file
, FILE *f
);
1183 } parse_functions
[] =
1185 { ".c", parse_c_file
},
1186 { ".h", parse_c_file
},
1187 { ".inl", parse_c_file
},
1188 { ".l", parse_c_file
},
1189 { ".m", parse_c_file
},
1190 { ".rh", parse_c_file
},
1191 { ".x", parse_c_file
},
1192 { ".y", parse_c_file
},
1193 { ".idl", parse_idl_file
},
1194 { ".rc", parse_rc_file
},
1195 { ".in", parse_in_file
},
1196 { ".sfd", parse_sfd_file
}
1199 /*******************************************************************
1202 static struct file
*load_file( const char *name
)
1206 unsigned int i
, hash
= hash_filename( name
);
1208 LIST_FOR_EACH_ENTRY( file
, &files
[hash
], struct file
, entry
)
1209 if (!strcmp( name
, file
->name
)) return file
;
1211 if (!(f
= fopen( name
, "r" ))) return NULL
;
1213 file
= add_file( name
);
1214 list_add_tail( &files
[hash
], &file
->entry
);
1215 input_file_name
= file
->name
;
1218 for (i
= 0; i
< sizeof(parse_functions
) / sizeof(parse_functions
[0]); i
++)
1220 if (!strendswith( name
, parse_functions
[i
].ext
)) continue;
1221 parse_functions
[i
].parse( file
, f
);
1226 input_file_name
= NULL
;
1232 /*******************************************************************
1233 * open_include_path_file
1235 * Open a file from a directory on the include path.
1237 static struct file
*open_include_path_file( const struct makefile
*make
, const char *dir
,
1238 const char *name
, char **filename
)
1240 char *src_path
= base_dir_path( make
, concat_paths( dir
, name
));
1241 struct file
*ret
= load_file( src_path
);
1243 if (ret
) *filename
= src_dir_path( make
, concat_paths( dir
, name
));
1248 /*******************************************************************
1249 * open_file_same_dir
1251 * Open a file in the same directory as the parent.
1253 static struct file
*open_file_same_dir( const struct incl_file
*parent
, const char *name
, char **filename
)
1255 char *src_path
= replace_filename( parent
->file
->name
, name
);
1256 struct file
*ret
= load_file( src_path
);
1258 if (ret
) *filename
= replace_filename( parent
->filename
, name
);
1264 /*******************************************************************
1267 * Open a file in the source directory of the makefile.
1269 static struct file
*open_local_file( const struct makefile
*make
, const char *path
, char **filename
)
1271 char *src_path
= root_dir_path( base_dir_path( make
, path
));
1272 struct file
*ret
= load_file( src_path
);
1274 /* if not found, try parent dir */
1275 if (!ret
&& make
->parent_dir
)
1278 path
= strmake( "%s/%s", make
->parent_dir
, path
);
1279 src_path
= root_dir_path( base_dir_path( make
, path
));
1280 ret
= load_file( src_path
);
1283 if (ret
) *filename
= src_dir_path( make
, path
);
1289 /*******************************************************************
1292 * Open a file in the top-level source directory.
1294 static struct file
*open_global_file( const struct makefile
*make
, const char *path
, char **filename
)
1296 char *src_path
= root_dir_path( path
);
1297 struct file
*ret
= load_file( src_path
);
1299 if (ret
) *filename
= top_src_dir_path( make
, path
);
1305 /*******************************************************************
1306 * open_global_header
1308 * Open a file in the global include source directory.
1310 static struct file
*open_global_header( const struct makefile
*make
, const char *path
, char **filename
)
1312 return open_global_file( make
, strmake( "include/%s", path
), filename
);
1316 /*******************************************************************
1319 static struct file
*open_src_file( const struct makefile
*make
, struct incl_file
*pFile
)
1321 struct file
*file
= open_local_file( make
, pFile
->name
, &pFile
->filename
);
1323 if (!file
) fatal_perror( "open %s", pFile
->name
);
1328 /*******************************************************************
1331 static struct file
*open_include_file( const struct makefile
*make
, struct incl_file
*pFile
)
1333 struct file
*file
= NULL
;
1335 unsigned int i
, len
;
1339 /* check for generated bison header */
1341 if (strendswith( pFile
->name
, ".tab.h" ) &&
1342 (file
= open_local_file( make
, replace_extension( pFile
->name
, ".tab.h", ".y" ), &filename
)))
1344 pFile
->sourcename
= filename
;
1345 pFile
->filename
= obj_dir_path( make
, pFile
->name
);
1349 /* check for corresponding idl file in source dir */
1351 if (strendswith( pFile
->name
, ".h" ) &&
1352 (file
= open_local_file( make
, replace_extension( pFile
->name
, ".h", ".idl" ), &filename
)))
1354 pFile
->sourcename
= filename
;
1355 pFile
->filename
= obj_dir_path( make
, pFile
->name
);
1359 /* check for corresponding tlb file in source dir */
1361 if (strendswith( pFile
->name
, ".tlb" ) &&
1362 (file
= open_local_file( make
, replace_extension( pFile
->name
, ".tlb", ".idl" ), &filename
)))
1364 pFile
->sourcename
= filename
;
1365 pFile
->filename
= obj_dir_path( make
, pFile
->name
);
1369 /* now try in source dir */
1370 if ((file
= open_local_file( make
, pFile
->name
, &pFile
->filename
))) return file
;
1372 /* check for corresponding idl file in global includes */
1374 if (strendswith( pFile
->name
, ".h" ) &&
1375 (file
= open_global_header( make
, replace_extension( pFile
->name
, ".h", ".idl" ), &filename
)))
1377 pFile
->sourcename
= filename
;
1378 pFile
->filename
= top_obj_dir_path( make
, strmake( "include/%s", pFile
->name
));
1382 /* check for corresponding .in file in global includes (for config.h.in) */
1384 if (strendswith( pFile
->name
, ".h" ) &&
1385 (file
= open_global_header( make
, replace_extension( pFile
->name
, ".h", ".h.in" ), &filename
)))
1387 pFile
->sourcename
= filename
;
1388 pFile
->filename
= top_obj_dir_path( make
, strmake( "include/%s", pFile
->name
));
1392 /* check for corresponding .x file in global includes */
1394 if (strendswith( pFile
->name
, "tmpl.h" ) &&
1395 (file
= open_global_header( make
, replace_extension( pFile
->name
, ".h", ".x" ), &filename
)))
1397 pFile
->sourcename
= filename
;
1398 pFile
->filename
= top_obj_dir_path( make
, strmake( "include/%s", pFile
->name
));
1402 /* check for corresponding .tlb file in global includes */
1404 if (strendswith( pFile
->name
, ".tlb" ) &&
1405 (file
= open_global_header( make
, replace_extension( pFile
->name
, ".tlb", ".idl" ), &filename
)))
1407 pFile
->sourcename
= filename
;
1408 pFile
->filename
= top_obj_dir_path( make
, strmake( "include/%s", pFile
->name
));
1412 /* check in global includes source dir */
1414 if ((file
= open_global_header( make
, pFile
->name
, &pFile
->filename
))) return file
;
1416 /* check in global msvcrt includes */
1417 if (make
->use_msvcrt
&&
1418 (file
= open_global_header( make
, strmake( "msvcrt/%s", pFile
->name
), &pFile
->filename
)))
1421 /* now search in include paths */
1422 for (i
= 0; i
< make
->include_paths
.count
; i
++)
1424 const char *dir
= make
->include_paths
.str
[i
];
1425 const char *prefix
= make
->top_src_dir
? make
->top_src_dir
: make
->top_obj_dir
;
1429 len
= strlen( prefix
);
1430 if (!strncmp( dir
, prefix
, len
) && (!dir
[len
] || dir
[len
] == '/'))
1432 while (dir
[len
] == '/') len
++;
1433 file
= open_global_file( make
, concat_paths( dir
+ len
, pFile
->name
), &pFile
->filename
);
1434 if (file
) return file
;
1436 if (make
->top_src_dir
) continue; /* ignore paths that don't point to the top source dir */
1440 if ((file
= open_include_path_file( make
, dir
, pFile
->name
, &pFile
->filename
)))
1444 if (pFile
->type
== INCL_SYSTEM
) return NULL
; /* ignore system files we cannot find */
1446 /* try in src file directory */
1447 if ((file
= open_file_same_dir( pFile
->included_by
, pFile
->name
, &pFile
->filename
))) return file
;
1449 fprintf( stderr
, "%s:%d: error: ", pFile
->included_by
->file
->name
, pFile
->included_line
);
1450 perror( pFile
->name
);
1451 pFile
= pFile
->included_by
;
1452 while (pFile
&& pFile
->included_by
)
1454 const char *parent
= pFile
->included_by
->sourcename
;
1455 if (!parent
) parent
= pFile
->included_by
->file
->name
;
1456 fprintf( stderr
, "%s:%d: note: %s was first included here\n",
1457 parent
, pFile
->included_line
, pFile
->name
);
1458 pFile
= pFile
->included_by
;
1464 /*******************************************************************
1467 static void add_all_includes( struct makefile
*make
, struct incl_file
*parent
, struct file
*file
)
1471 parent
->files_count
= 0;
1472 parent
->files_size
= file
->deps_count
;
1473 parent
->files
= xmalloc( parent
->files_size
* sizeof(*parent
->files
) );
1474 for (i
= 0; i
< file
->deps_count
; i
++)
1476 switch (file
->deps
[i
].type
)
1480 add_include( make
, parent
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_NORMAL
);
1482 case INCL_IMPORTLIB
:
1483 add_include( make
, parent
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_IMPORTLIB
);
1486 add_include( make
, parent
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_SYSTEM
);
1488 case INCL_CPP_QUOTE
:
1489 case INCL_CPP_QUOTE_SYSTEM
:
1496 /*******************************************************************
1499 static void parse_file( struct makefile
*make
, struct incl_file
*source
, int src
)
1501 struct file
*file
= src
? open_src_file( make
, source
) : open_include_file( make
, source
);
1505 source
->file
= file
;
1506 source
->files_count
= 0;
1507 source
->files_size
= file
->deps_count
;
1508 source
->files
= xmalloc( source
->files_size
* sizeof(*source
->files
) );
1510 if (source
->sourcename
)
1512 if (strendswith( source
->sourcename
, ".idl" ))
1516 if (strendswith( source
->name
, ".tlb" )) return; /* typelibs don't include anything */
1518 /* generated .h file always includes these */
1519 add_include( make
, source
, "rpc.h", 0, INCL_NORMAL
);
1520 add_include( make
, source
, "rpcndr.h", 0, INCL_NORMAL
);
1521 for (i
= 0; i
< file
->deps_count
; i
++)
1523 switch (file
->deps
[i
].type
)
1526 if (strendswith( file
->deps
[i
].name
, ".idl" ))
1527 add_include( make
, source
, replace_extension( file
->deps
[i
].name
, ".idl", ".h" ),
1528 file
->deps
[i
].line
, INCL_NORMAL
);
1530 add_include( make
, source
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_NORMAL
);
1532 case INCL_CPP_QUOTE
:
1533 add_include( make
, source
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_NORMAL
);
1535 case INCL_CPP_QUOTE_SYSTEM
:
1536 add_include( make
, source
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_SYSTEM
);
1540 case INCL_IMPORTLIB
:
1546 if (strendswith( source
->sourcename
, ".y" ))
1547 return; /* generated .tab.h doesn't include anything */
1550 add_all_includes( make
, source
, file
);
1554 /*******************************************************************
1557 * Add a source file to the list.
1559 static struct incl_file
*add_src_file( struct makefile
*make
, const char *name
)
1561 struct incl_file
*file
;
1563 if ((file
= find_src_file( make
, name
))) return file
; /* we already have it */
1564 file
= xmalloc( sizeof(*file
) );
1565 memset( file
, 0, sizeof(*file
) );
1566 file
->name
= xstrdup(name
);
1567 list_add_tail( &make
->sources
, &file
->entry
);
1568 parse_file( make
, file
, 1 );
1573 /*******************************************************************
1574 * open_input_makefile
1576 static FILE *open_input_makefile( const struct makefile
*make
)
1581 input_file_name
= root_dir_path( base_dir_path( make
, strmake( "%s.in", output_makefile_name
)));
1583 input_file_name
= output_makefile_name
; /* always use output name for main Makefile */
1586 if (!(ret
= fopen( input_file_name
, "r" ))) fatal_perror( "open" );
1591 /*******************************************************************
1594 static const char *get_make_variable( const struct makefile
*make
, const char *name
)
1598 if ((ret
= strarray_get_value( &cmdline_vars
, name
))) return ret
;
1599 if ((ret
= strarray_get_value( &make
->vars
, name
))) return ret
;
1600 if (top_makefile
&& (ret
= strarray_get_value( &top_makefile
->vars
, name
))) return ret
;
1605 /*******************************************************************
1606 * get_expanded_make_variable
1608 static char *get_expanded_make_variable( const struct makefile
*make
, const char *name
)
1611 char *p
, *end
, *expand
, *tmp
;
1613 var
= get_make_variable( make
, name
);
1614 if (!var
) return NULL
;
1616 p
= expand
= xstrdup( var
);
1617 while ((p
= strchr( p
, '$' )))
1621 if (!(end
= strchr( p
+ 2, ')' ))) fatal_error( "syntax error in '%s'\n", expand
);
1623 if (strchr( p
+ 2, ':' )) fatal_error( "pattern replacement not supported for '%s'\n", p
+ 2 );
1624 var
= get_make_variable( make
, p
+ 2 );
1625 tmp
= replace_substr( expand
, p
, end
- p
, var
? var
: "" );
1626 /* switch to the new string */
1627 p
= tmp
+ (p
- expand
);
1631 else if (p
[1] == '{') /* don't expand ${} variables */
1633 if (!(end
= strchr( p
+ 2, '}' ))) fatal_error( "syntax error in '%s'\n", expand
);
1636 else if (p
[1] == '$')
1640 else fatal_error( "syntax error in '%s'\n", expand
);
1643 /* consider empty variables undefined */
1645 while (*p
&& isspace(*p
)) p
++;
1646 if (*p
) return expand
;
1652 /*******************************************************************
1653 * get_expanded_make_var_array
1655 static struct strarray
get_expanded_make_var_array( const struct makefile
*make
, const char *name
)
1657 struct strarray ret
= empty_strarray
;
1658 char *value
, *token
;
1660 if ((value
= get_expanded_make_variable( make
, name
)))
1661 for (token
= strtok( value
, " \t" ); token
; token
= strtok( NULL
, " \t" ))
1662 strarray_add( &ret
, token
);
1667 /*******************************************************************
1668 * get_expanded_file_local_var
1670 static struct strarray
get_expanded_file_local_var( const struct makefile
*make
, const char *file
,
1673 char *p
, *var
= strmake( "%s_%s", file
, name
);
1675 for (p
= var
; *p
; p
++) if (!isalnum( *p
)) *p
= '_';
1676 return get_expanded_make_var_array( make
, var
);
1680 /*******************************************************************
1683 static int set_make_variable( struct strarray
*array
, const char *assignment
)
1687 p
= name
= xstrdup( assignment
);
1688 while (isalnum(*p
) || *p
== '_') p
++;
1689 if (name
== p
) return 0; /* not a variable */
1693 while (isspace(*p
)) p
++;
1695 if (*p
!= '=') return 0; /* not an assignment */
1697 while (isspace(*p
)) p
++;
1699 strarray_set_value( array
, name
, p
);
1704 /*******************************************************************
1707 static struct makefile
*parse_makefile( const char *path
)
1711 struct makefile
*make
= xmalloc( sizeof(*make
) );
1713 memset( make
, 0, sizeof(*make
) );
1716 make
->top_obj_dir
= get_relative_path( path
, "" );
1717 make
->base_dir
= path
;
1718 if (!strcmp( make
->base_dir
, "." )) make
->base_dir
= NULL
;
1721 file
= open_input_makefile( make
);
1722 while ((buffer
= get_line( file
)))
1724 if (!strncmp( buffer
, separator
, strlen(separator
) )) break;
1725 if (*buffer
== '\t') continue; /* command */
1726 while (isspace( *buffer
)) buffer
++;
1727 if (*buffer
== '#') continue; /* comment */
1728 set_make_variable( &make
->vars
, buffer
);
1731 input_file_name
= NULL
;
1736 /*******************************************************************
1737 * add_generated_sources
1739 static void add_generated_sources( struct makefile
*make
)
1741 struct incl_file
*source
, *next
, *file
;
1743 LIST_FOR_EACH_ENTRY_SAFE( source
, next
, &make
->sources
, struct incl_file
, entry
)
1745 if (source
->file
->flags
& FLAG_IDL_CLIENT
)
1747 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_c.c" ), NULL
);
1748 add_dependency( file
->file
, replace_extension( source
->name
, ".idl", ".h" ), INCL_NORMAL
);
1749 add_all_includes( make
, file
, file
->file
);
1751 if (source
->file
->flags
& FLAG_IDL_SERVER
)
1753 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_s.c" ), NULL
);
1754 add_dependency( file
->file
, "wine/exception.h", INCL_NORMAL
);
1755 add_dependency( file
->file
, replace_extension( source
->name
, ".idl", ".h" ), INCL_NORMAL
);
1756 add_all_includes( make
, file
, file
->file
);
1758 if (source
->file
->flags
& FLAG_IDL_IDENT
)
1760 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_i.c" ), NULL
);
1761 add_dependency( file
->file
, "rpc.h", INCL_NORMAL
);
1762 add_dependency( file
->file
, "rpcndr.h", INCL_NORMAL
);
1763 add_dependency( file
->file
, "guiddef.h", INCL_NORMAL
);
1764 add_all_includes( make
, file
, file
->file
);
1766 if (source
->file
->flags
& FLAG_IDL_PROXY
)
1768 file
= add_generated_source( make
, "dlldata.o", "dlldata.c" );
1769 add_dependency( file
->file
, "objbase.h", INCL_NORMAL
);
1770 add_dependency( file
->file
, "rpcproxy.h", INCL_NORMAL
);
1771 add_all_includes( make
, file
, file
->file
);
1772 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_p.c" ), NULL
);
1773 add_dependency( file
->file
, "objbase.h", INCL_NORMAL
);
1774 add_dependency( file
->file
, "rpcproxy.h", INCL_NORMAL
);
1775 add_dependency( file
->file
, "wine/exception.h", INCL_NORMAL
);
1776 add_dependency( file
->file
, replace_extension( source
->name
, ".idl", ".h" ), INCL_NORMAL
);
1777 add_all_includes( make
, file
, file
->file
);
1779 if (source
->file
->flags
& FLAG_IDL_TYPELIB
)
1781 add_generated_source( make
, replace_extension( source
->name
, ".idl", ".tlb" ), NULL
);
1783 if (source
->file
->flags
& FLAG_IDL_REGTYPELIB
)
1785 add_generated_source( make
, replace_extension( source
->name
, ".idl", "_t.res" ), NULL
);
1787 if (source
->file
->flags
& FLAG_IDL_REGISTER
)
1789 add_generated_source( make
, replace_extension( source
->name
, ".idl", "_r.res" ), NULL
);
1791 if (source
->file
->flags
& FLAG_IDL_HEADER
)
1793 add_generated_source( make
, replace_extension( source
->name
, ".idl", ".h" ), NULL
);
1795 if (!source
->file
->flags
&& strendswith( source
->name
, ".idl" ))
1797 add_generated_source( make
, replace_extension( source
->name
, ".idl", ".h" ), NULL
);
1799 if (strendswith( source
->name
, ".x" ))
1801 add_generated_source( make
, replace_extension( source
->name
, ".x", ".h" ), NULL
);
1803 if (strendswith( source
->name
, ".y" ))
1805 file
= add_generated_source( make
, replace_extension( source
->name
, ".y", ".tab.c" ), NULL
);
1806 /* steal the includes list from the source file */
1807 file
->files_count
= source
->files_count
;
1808 file
->files_size
= source
->files_size
;
1809 file
->files
= source
->files
;
1810 source
->files_count
= source
->files_size
= 0;
1811 source
->files
= NULL
;
1813 if (strendswith( source
->name
, ".l" ))
1815 file
= add_generated_source( make
, replace_extension( source
->name
, ".l", ".yy.c" ), NULL
);
1816 /* steal the includes list from the source file */
1817 file
->files_count
= source
->files_count
;
1818 file
->files_size
= source
->files_size
;
1819 file
->files
= source
->files
;
1820 source
->files_count
= source
->files_size
= 0;
1821 source
->files
= NULL
;
1823 if (source
->file
->flags
& FLAG_C_IMPLIB
)
1825 if (!make
->staticimplib
&& make
->importlib
&& *dll_ext
)
1826 make
->staticimplib
= strmake( "lib%s.a", make
->importlib
);
1828 if (strendswith( source
->name
, ".po" ))
1830 if (!make
->disabled
)
1831 strarray_add_uniq( &linguas
, replace_extension( source
->name
, ".po", "" ));
1836 file
= add_generated_source( make
, "testlist.o", "testlist.c" );
1837 add_dependency( file
->file
, "wine/test.h", INCL_NORMAL
);
1838 add_all_includes( make
, file
, file
->file
);
1843 /*******************************************************************
1846 static void create_dir( const char *dir
)
1850 p
= path
= xstrdup( dir
);
1851 while ((p
= strchr( p
, '/' )))
1854 if (mkdir( path
, 0755 ) == -1 && errno
!= EEXIST
) fatal_perror( "mkdir %s", path
);
1856 while (*p
== '/') p
++;
1858 if (mkdir( path
, 0755 ) == -1 && errno
!= EEXIST
) fatal_perror( "mkdir %s", path
);
1863 /*******************************************************************
1864 * create_file_directories
1866 * Create the base directories of all the files.
1868 static void create_file_directories( const struct makefile
*make
, struct strarray files
)
1870 struct strarray subdirs
= empty_strarray
;
1874 for (i
= 0; i
< files
.count
; i
++)
1876 if (!strchr( files
.str
[i
], '/' )) continue;
1877 dir
= base_dir_path( make
, files
.str
[i
] );
1878 *strrchr( dir
, '/' ) = 0;
1879 strarray_add_uniq( &subdirs
, dir
);
1882 for (i
= 0; i
< subdirs
.count
; i
++) create_dir( subdirs
.str
[i
] );
1886 /*******************************************************************
1887 * output_filenames_obj_dir
1889 static void output_filenames_obj_dir( const struct makefile
*make
, struct strarray array
)
1893 for (i
= 0; i
< array
.count
; i
++) output_filename( obj_dir_path( make
, array
.str
[i
] ));
1897 /*******************************************************************
1900 static void get_dependencies( struct strarray
*deps
, struct incl_file
*file
, struct incl_file
*source
)
1904 if (!file
->filename
) return;
1908 if (file
->owner
== source
) return; /* already processed */
1909 if (file
->type
== INCL_IMPORTLIB
&&
1910 !(source
->file
->flags
& (FLAG_IDL_TYPELIB
| FLAG_IDL_REGTYPELIB
)))
1911 return; /* library is imported only when building a typelib */
1912 file
->owner
= source
;
1913 strarray_add( deps
, file
->filename
);
1915 for (i
= 0; i
< file
->files_count
; i
++) get_dependencies( deps
, file
->files
[i
], source
);
1919 /*******************************************************************
1920 * get_local_dependencies
1922 * Get the local dependencies of a given target.
1924 static struct strarray
get_local_dependencies( const struct makefile
*make
, const char *name
,
1925 struct strarray targets
)
1928 struct strarray deps
= get_expanded_file_local_var( make
, name
, "DEPS" );
1930 for (i
= 0; i
< deps
.count
; i
++)
1932 if (strarray_exists( &targets
, deps
.str
[i
] ))
1933 deps
.str
[i
] = obj_dir_path( make
, deps
.str
[i
] );
1935 deps
.str
[i
] = src_dir_path( make
, deps
.str
[i
] );
1941 /*******************************************************************
1944 * Check if makefile builds the named static library and return the full lib path.
1946 static const char *get_static_lib( const struct makefile
*make
, const char *name
)
1948 if (!make
->staticlib
) return NULL
;
1949 if (strncmp( make
->staticlib
, "lib", 3 )) return NULL
;
1950 if (strncmp( make
->staticlib
+ 3, name
, strlen(name
) )) return NULL
;
1951 if (strcmp( make
->staticlib
+ 3 + strlen(name
), ".a" )) return NULL
;
1952 return base_dir_path( make
, make
->staticlib
);
1956 /*******************************************************************
1957 * add_default_libraries
1959 static struct strarray
add_default_libraries( const struct makefile
*make
, struct strarray
*deps
)
1961 struct strarray ret
= empty_strarray
;
1962 struct strarray all_libs
= empty_strarray
;
1965 strarray_add( &all_libs
, "-lwine_port" );
1966 strarray_addall( &all_libs
, get_expanded_make_var_array( make
, "EXTRALIBS" ));
1967 strarray_addall( &all_libs
, libs
);
1969 for (i
= 0; i
< all_libs
.count
; i
++)
1971 const char *lib
= NULL
;
1973 if (!strncmp( all_libs
.str
[i
], "-l", 2 ))
1975 const char *name
= all_libs
.str
[i
] + 2;
1977 for (j
= 0; j
< top_makefile
->subdirs
.count
; j
++)
1979 const struct makefile
*submake
= top_makefile
->submakes
[j
];
1981 if ((lib
= get_static_lib( submake
, name
))) break;
1987 lib
= top_obj_dir_path( make
, lib
);
1988 strarray_add( deps
, lib
);
1989 strarray_add( &ret
, lib
);
1991 else strarray_add( &ret
, all_libs
.str
[i
] );
1997 /*******************************************************************
2000 static struct strarray
add_import_libs( const struct makefile
*make
, struct strarray
*deps
,
2001 struct strarray imports
, int cross
)
2003 struct strarray ret
= empty_strarray
;
2006 for (i
= 0; i
< imports
.count
; i
++)
2008 const char *name
= imports
.str
[i
];
2009 const char *lib
= NULL
;
2011 for (j
= 0; j
< top_makefile
->subdirs
.count
; j
++)
2013 const struct makefile
*submake
= top_makefile
->submakes
[j
];
2015 if (submake
->importlib
&& !strcmp( submake
->importlib
, name
))
2017 if (cross
|| !*dll_ext
|| submake
->staticimplib
)
2018 lib
= base_dir_path( submake
, strmake( "lib%s.a", name
));
2020 strarray_add( deps
, top_obj_dir_path( make
,
2021 strmake( "%s/lib%s.def", submake
->base_dir
, name
)));
2025 if ((lib
= get_static_lib( submake
, name
))) break;
2030 if (cross
) lib
= replace_extension( lib
, ".a", ".cross.a" );
2031 lib
= top_obj_dir_path( make
, lib
);
2032 strarray_add( deps
, lib
);
2033 strarray_add( &ret
, lib
);
2035 else strarray_add( &ret
, strmake( "-l%s", name
));
2041 /*******************************************************************
2042 * get_default_imports
2044 static struct strarray
get_default_imports( const struct makefile
*make
)
2046 struct strarray ret
= empty_strarray
;
2048 if (strarray_exists( &make
->extradllflags
, "-nodefaultlibs" )) return ret
;
2049 if (strarray_exists( &make
->appmode
, "-mno-cygwin" )) strarray_add( &ret
, "msvcrt" );
2050 if (make
->is_win16
) strarray_add( &ret
, "kernel" );
2051 strarray_add( &ret
, "kernel32" );
2052 strarray_add( &ret
, "ntdll" );
2053 strarray_add( &ret
, "winecrt0" );
2058 /*******************************************************************
2061 static void add_install_rule( const struct makefile
*make
, struct strarray
*install_rules
,
2062 const char *target
, const char *file
, const char *dest
)
2064 if (strarray_exists( &make
->install_lib
, target
))
2066 strarray_add( &install_rules
[INSTALL_LIB
], file
);
2067 strarray_add( &install_rules
[INSTALL_LIB
], dest
);
2069 else if (strarray_exists( &make
->install_dev
, target
))
2071 strarray_add( &install_rules
[INSTALL_DEV
], file
);
2072 strarray_add( &install_rules
[INSTALL_DEV
], dest
);
2077 /*******************************************************************
2078 * get_include_install_path
2080 * Determine the installation path for a given include file.
2082 static const char *get_include_install_path( const char *name
)
2084 if (!strncmp( name
, "wine/", 5 )) return name
+ 5;
2085 if (!strncmp( name
, "msvcrt/", 7 )) return name
;
2086 return strmake( "windows/%s", name
);
2090 /*******************************************************************
2091 * get_shared_library_name
2093 * Determine possible names for a shared library with a version number.
2095 static struct strarray
get_shared_lib_names( const char *libname
)
2097 struct strarray ret
= empty_strarray
;
2098 const char *ext
, *p
;
2099 char *name
, *first
, *second
;
2102 strarray_add( &ret
, libname
);
2104 for (p
= libname
; (p
= strchr( p
, '.' )); p
++)
2105 if ((len
= strspn( p
+ 1, "0123456789." ))) break;
2107 if (!len
) return ret
;
2109 if (*ext
&& ext
[-1] == '.') ext
--;
2111 /* keep only the first group of digits */
2112 name
= xstrdup( libname
);
2113 first
= name
+ (p
- libname
);
2114 if ((second
= strchr( first
+ 1, '.' )))
2116 strcpy( second
, ext
);
2117 strarray_add( &ret
, xstrdup( name
));
2119 /* now remove all digits */
2120 strcpy( first
, ext
);
2121 strarray_add( &ret
, name
);
2126 /*******************************************************************
2127 * output_symlink_rule
2129 * Output a rule to create a symlink.
2131 static void output_symlink_rule( const char *src_name
, const char *link_name
)
2135 output( "\trm -f %s && ", link_name
);
2137 /* dest path with a directory needs special handling if ln -s isn't supported */
2138 if (strcmp( ln_s
, "ln -s" ) && ((name
= strrchr( link_name
, '/' ))))
2140 char *dir
= xstrdup( link_name
);
2141 dir
[name
- link_name
] = 0;
2142 output( "cd %s && %s %s %s\n", *dir
? dir
: "/", ln_s
, src_name
, name
+ 1 );
2147 output( "%s %s %s\n", ln_s
, src_name
, link_name
);
2152 /*******************************************************************
2153 * output_install_rules
2155 * Rules are stored as a (file,dest) pair of values.
2156 * The first char of dest indicates the type of install.
2158 static struct strarray
output_install_rules( const struct makefile
*make
, struct strarray files
,
2159 const char *target
, struct strarray
*phony_targets
)
2163 struct strarray uninstall
= empty_strarray
;
2164 struct strarray targets
= empty_strarray
;
2166 if (!files
.count
) return uninstall
;
2168 for (i
= 0; i
< files
.count
; i
+= 2)
2170 const char *file
= files
.str
[i
];
2171 switch (*files
.str
[i
+ 1])
2173 case 'd': /* data file */
2174 case 'p': /* program file */
2175 case 's': /* script */
2176 strarray_add_uniq( &targets
, obj_dir_path( make
, file
));
2178 case 't': /* script in tools dir */
2179 strarray_add_uniq( &targets
, tools_dir_path( make
, file
));
2184 output( "install %s::", target
);
2185 output_filenames( targets
);
2188 install_sh
= top_src_dir_path( make
, "tools/install-sh" );
2189 for (i
= 0; i
< files
.count
; i
+= 2)
2191 const char *file
= files
.str
[i
];
2192 const char *dest
= strmake( "$(DESTDIR)%s", files
.str
[i
+ 1] + 1 );
2194 switch (*files
.str
[i
+ 1])
2196 case 'd': /* data file */
2197 output( "\t%s -m 644 $(INSTALL_DATA_FLAGS) %s %s\n",
2198 install_sh
, obj_dir_path( make
, file
), dest
);
2200 case 'D': /* data file in source dir */
2201 output( "\t%s -m 644 $(INSTALL_DATA_FLAGS) %s %s\n",
2202 install_sh
, src_dir_path( make
, file
), dest
);
2204 case 'p': /* program file */
2205 output( "\tSTRIPPROG=\"$(STRIP)\" %s $(INSTALL_PROGRAM_FLAGS) %s %s\n",
2206 install_sh
, obj_dir_path( make
, file
), dest
);
2208 case 's': /* script */
2209 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s %s\n",
2210 install_sh
, obj_dir_path( make
, file
), dest
);
2212 case 'S': /* script in source dir */
2213 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s %s\n",
2214 install_sh
, src_dir_path( make
, file
), dest
);
2216 case 't': /* script in tools dir */
2217 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s %s\n",
2218 install_sh
, tools_dir_path( make
, file
), dest
);
2220 case 'y': /* symlink */
2221 output_symlink_rule( file
, dest
);
2226 strarray_add( &uninstall
, dest
);
2229 strarray_add_uniq( phony_targets
, "install" );
2230 strarray_add_uniq( phony_targets
, target
);
2235 /*******************************************************************
2236 * output_importlib_symlinks
2238 static struct strarray
output_importlib_symlinks( const struct makefile
*parent
,
2239 const struct makefile
*make
)
2241 struct strarray ret
= empty_strarray
;
2242 const char *lib
, *dst
;
2244 if (!make
->module
) return ret
;
2245 if (!make
->importlib
) return ret
;
2246 if (make
->is_win16
&& make
->disabled
) return ret
;
2247 if (strncmp( make
->base_dir
, "dlls/", 5 )) return ret
;
2248 if (!strcmp( make
->module
, make
->importlib
)) return ret
;
2249 if (!strchr( make
->importlib
, '.' ) &&
2250 !strncmp( make
->module
, make
->importlib
, strlen( make
->importlib
)) &&
2251 !strcmp( make
->module
+ strlen( make
->importlib
), ".dll" ))
2254 lib
= strmake( "lib%s.%s", make
->importlib
, *dll_ext
? "def" : "a" );
2255 dst
= concat_paths( obj_dir_path( parent
, "dlls" ), lib
);
2256 output( "%s: %s\n", dst
, base_dir_path( make
, lib
));
2257 output_symlink_rule( concat_paths( make
->base_dir
+ strlen("dlls/"), lib
), dst
);
2258 strarray_add( &ret
, dst
);
2260 if (crosstarget
&& !make
->is_win16
)
2262 lib
= strmake( "lib%s.cross.a", make
->importlib
);
2263 dst
= concat_paths( obj_dir_path( parent
, "dlls" ), lib
);
2264 output( "%s: %s\n", dst
, base_dir_path( make
, lib
));
2265 output_symlink_rule( concat_paths( make
->base_dir
+ strlen("dlls/"), lib
), dst
);
2266 strarray_add( &ret
, dst
);
2272 /*******************************************************************
2275 static void output_po_files( const struct makefile
*make
)
2277 const char *po_dir
= src_dir_path( make
, "po" );
2278 struct strarray pot_files
= empty_strarray
;
2279 struct incl_file
*source
;
2282 for (i
= 0; i
< make
->subdirs
.count
; i
++)
2284 struct makefile
*submake
= make
->submakes
[i
];
2286 LIST_FOR_EACH_ENTRY( source
, &submake
->sources
, struct incl_file
, entry
)
2288 if (strendswith( source
->name
, ".rc" ) && (source
->file
->flags
& FLAG_RC_PO
))
2290 char *pot_file
= replace_extension( source
->name
, ".rc", ".pot" );
2291 char *pot_path
= base_dir_path( submake
, pot_file
);
2292 output( "%s: tools/wrc include dummy\n", pot_path
);
2293 output( "\t@cd %s && $(MAKE) %s\n", base_dir_path( submake
, "" ), pot_file
);
2294 strarray_add( &pot_files
, pot_path
);
2296 else if (strendswith( source
->name
, ".mc" ))
2298 char *pot_file
= replace_extension( source
->name
, ".mc", ".pot" );
2299 char *pot_path
= base_dir_path( submake
, pot_file
);
2300 output( "%s: tools/wmc include dummy\n", pot_path
);
2301 output( "\t@cd %s && $(MAKE) %s\n", base_dir_path( submake
, "" ), pot_file
);
2302 strarray_add( &pot_files
, pot_path
);
2308 for (i
= 0; i
< linguas
.count
; i
++)
2309 output_filename( strmake( "%s/%s.po", po_dir
, linguas
.str
[i
] ));
2310 output( ": %s/wine.pot\n", po_dir
);
2311 output( "\tmsgmerge --previous -q $@ %s/wine.pot | msgattrib --no-obsolete -o $@.new && mv $@.new $@\n",
2314 for (i
= 0; i
< linguas
.count
; i
++)
2315 output_filename( strmake( "%s/%s.po", po_dir
, linguas
.str
[i
] ));
2318 output( "%s/wine.pot:", po_dir
);
2319 output_filenames( pot_files
);
2321 output( "\tmsgcat -o $@" );
2322 output_filenames( pot_files
);
2327 /*******************************************************************
2330 static struct strarray
output_sources( const struct makefile
*make
)
2332 struct incl_file
*source
;
2334 struct strarray object_files
= empty_strarray
;
2335 struct strarray crossobj_files
= empty_strarray
;
2336 struct strarray res_files
= empty_strarray
;
2337 struct strarray clean_files
= empty_strarray
;
2338 struct strarray uninstall_files
= empty_strarray
;
2339 struct strarray mo_files
= empty_strarray
;
2340 struct strarray ok_files
= empty_strarray
;
2341 struct strarray in_files
= empty_strarray
;
2342 struct strarray dlldata_files
= empty_strarray
;
2343 struct strarray c2man_files
= empty_strarray
;
2344 struct strarray implib_objs
= empty_strarray
;
2345 struct strarray includes
= empty_strarray
;
2346 struct strarray phony_targets
= empty_strarray
;
2347 struct strarray all_targets
= empty_strarray
;
2348 struct strarray install_rules
[NB_INSTALL_RULES
];
2349 char *ldrpath_local
= get_expanded_make_variable( make
, "LDRPATH_LOCAL" );
2350 char *ldrpath_install
= get_expanded_make_variable( make
, "LDRPATH_INSTALL" );
2352 for (i
= 0; i
< NB_INSTALL_RULES
; i
++) install_rules
[i
] = empty_strarray
;
2354 for (i
= 0; i
< linguas
.count
; i
++)
2355 strarray_add( &mo_files
, strmake( "%s/%s.mo", top_obj_dir_path( make
, "po" ), linguas
.str
[i
] ));
2357 strarray_add( &phony_targets
, "all" );
2358 strarray_add( &includes
, strmake( "-I%s", obj_dir_path( make
, "" )));
2359 if (make
->src_dir
) strarray_add( &includes
, strmake( "-I%s", make
->src_dir
));
2360 if (make
->parent_dir
) strarray_add( &includes
, strmake( "-I%s", src_dir_path( make
, make
->parent_dir
)));
2361 strarray_add( &includes
, strmake( "-I%s", top_obj_dir_path( make
, "include" )));
2362 if (make
->top_src_dir
)
2363 strarray_add( &includes
, strmake( "-I%s", top_src_dir_path( make
, "include" )));
2364 if (make
->use_msvcrt
)
2365 strarray_add( &includes
, strmake( "-I%s", top_src_dir_path( make
, "include/msvcrt" )));
2366 for (i
= 0; i
< make
->include_paths
.count
; i
++)
2367 strarray_add( &includes
, strmake( "-I%s", obj_dir_path( make
, make
->include_paths
.str
[i
] )));
2369 LIST_FOR_EACH_ENTRY( source
, &make
->sources
, struct incl_file
, entry
)
2371 struct strarray dependencies
= empty_strarray
;
2372 struct strarray extradefs
;
2373 char *obj
= xstrdup( source
->name
);
2374 char *ext
= get_extension( obj
);
2376 if (!ext
) fatal_error( "unsupported file type %s\n", source
->name
);
2379 extradefs
= get_expanded_file_local_var( make
, obj
, "EXTRADEFS" );
2380 get_dependencies( &dependencies
, source
, source
);
2382 if (!strcmp( ext
, "y" )) /* yacc file */
2384 /* add source file dependency for parallel makes */
2385 char *header
= strmake( "%s.tab.h", obj
);
2387 if (find_include_file( make
, header
))
2389 output( "%s: %s\n", obj_dir_path( make
, header
), source
->filename
);
2390 output( "\t$(BISON) -p %s_ -o %s.tab.c -d %s\n",
2391 obj
, obj_dir_path( make
, obj
), source
->filename
);
2392 output( "%s.tab.c: %s %s\n", obj_dir_path( make
, obj
),
2393 source
->filename
, obj_dir_path( make
, header
));
2394 strarray_add( &clean_files
, header
);
2396 else output( "%s.tab.c: %s\n", obj
, source
->filename
);
2398 output( "\t$(BISON) -p %s_ -o $@ %s\n", obj
, source
->filename
);
2400 else if (!strcmp( ext
, "x" )) /* template file */
2402 output( "%s.h: %s%s %s\n", obj_dir_path( make
, obj
),
2403 tools_dir_path( make
, "make_xftmpl" ), tools_ext
, source
->filename
);
2404 output( "\t%s%s -H -o $@ %s\n",
2405 tools_dir_path( make
, "make_xftmpl" ), tools_ext
, source
->filename
);
2406 if (source
->file
->flags
& FLAG_INSTALL
)
2408 strarray_add( &install_rules
[INSTALL_DEV
], source
->name
);
2409 strarray_add( &install_rules
[INSTALL_DEV
],
2410 strmake( "D$(includedir)/%s", get_include_install_path( source
->name
) ));
2411 strarray_add( &install_rules
[INSTALL_DEV
], strmake( "%s.h", obj
));
2412 strarray_add( &install_rules
[INSTALL_DEV
],
2413 strmake( "d$(includedir)/%s.h", get_include_install_path( obj
) ));
2416 else if (!strcmp( ext
, "l" )) /* lex file */
2418 output( "%s.yy.c: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2419 output( "\t$(FLEX) -o$@ %s\n", source
->filename
);
2421 else if (!strcmp( ext
, "rc" )) /* resource file */
2423 strarray_add( &res_files
, strmake( "%s.res", obj
));
2424 output( "%s.res: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2425 output( "\t%s -o $@", tools_path( make
, "wrc" ) );
2426 if (make
->is_win16
) output_filename( "-m16" );
2427 else output_filenames( target_flags
);
2428 output_filename( "--nostdinc" );
2429 output_filenames( includes
);
2430 output_filenames( make
->define_args
);
2431 output_filenames( extradefs
);
2432 if (mo_files
.count
&& (source
->file
->flags
& FLAG_RC_PO
))
2434 output_filename( strmake( "--po-dir=%s", top_obj_dir_path( make
, "po" )));
2435 output_filename( source
->filename
);
2437 output( "%s.res:", obj_dir_path( make
, obj
));
2438 output_filenames( mo_files
);
2443 output_filename( source
->filename
);
2446 if (source
->file
->flags
& FLAG_RC_PO
)
2448 strarray_add( &clean_files
, strmake( "%s.pot", obj
));
2449 output( "%s.pot: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2450 output( "\t%s -O pot -o $@", tools_path( make
, "wrc" ) );
2451 if (make
->is_win16
) output_filename( "-m16" );
2452 else output_filenames( target_flags
);
2453 output_filename( "--nostdinc" );
2454 output_filenames( includes
);
2455 output_filenames( make
->define_args
);
2456 output_filenames( extradefs
);
2457 output_filename( source
->filename
);
2459 output( "%s.pot ", obj_dir_path( make
, obj
));
2461 output( "%s.res:", obj_dir_path( make
, obj
));
2462 output_filename( tools_path( make
, "wrc" ));
2463 output_filenames( dependencies
);
2466 else if (!strcmp( ext
, "mc" )) /* message file */
2468 strarray_add( &res_files
, strmake( "%s.res", obj
));
2469 strarray_add( &clean_files
, strmake( "%s.pot", obj
));
2470 output( "%s.res: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2471 output( "\t%s -U -O res -o $@ %s", tools_path( make
, "wmc" ), source
->filename
);
2474 output_filename( strmake( "--po-dir=%s", top_obj_dir_path( make
, "po" )));
2476 output( "%s.res:", obj_dir_path( make
, obj
));
2477 output_filenames( mo_files
);
2480 output( "%s.pot: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2481 output( "\t%s -O pot -o $@ %s", tools_path( make
, "wmc" ), source
->filename
);
2483 output( "%s.pot %s.res:", obj_dir_path( make
, obj
), obj_dir_path( make
, obj
));
2484 output_filename( tools_path( make
, "wmc" ));
2485 output_filenames( dependencies
);
2488 else if (!strcmp( ext
, "idl" )) /* IDL file */
2490 struct strarray targets
= empty_strarray
;
2493 if (!source
->file
->flags
) source
->file
->flags
|= FLAG_IDL_HEADER
| FLAG_INSTALL
;
2494 if (find_include_file( make
, strmake( "%s.h", obj
))) source
->file
->flags
|= FLAG_IDL_HEADER
;
2496 for (i
= 0; i
< sizeof(idl_outputs
) / sizeof(idl_outputs
[0]); i
++)
2498 if (!(source
->file
->flags
& idl_outputs
[i
].flag
)) continue;
2499 dest
= strmake( "%s%s", obj
, idl_outputs
[i
].ext
);
2500 if (!find_src_file( make
, dest
)) strarray_add( &clean_files
, dest
);
2501 strarray_add( &targets
, dest
);
2503 if (source
->file
->flags
& FLAG_IDL_PROXY
) strarray_add( &dlldata_files
, source
->name
);
2504 if (source
->file
->flags
& FLAG_INSTALL
)
2506 strarray_add( &install_rules
[INSTALL_DEV
], xstrdup( source
->name
));
2507 strarray_add( &install_rules
[INSTALL_DEV
],
2508 strmake( "D$(includedir)/%s.idl", get_include_install_path( obj
) ));
2509 if (source
->file
->flags
& FLAG_IDL_HEADER
)
2511 strarray_add( &install_rules
[INSTALL_DEV
], strmake( "%s.h", obj
));
2512 strarray_add( &install_rules
[INSTALL_DEV
],
2513 strmake( "d$(includedir)/%s.h", get_include_install_path( obj
) ));
2516 if (!targets
.count
) continue;
2517 output_filenames_obj_dir( make
, targets
);
2518 output( ": %s\n", tools_path( make
, "widl" ));
2519 output( "\t%s -o $@", tools_path( make
, "widl" ) );
2520 output_filenames( target_flags
);
2521 output_filenames( includes
);
2522 output_filenames( make
->define_args
);
2523 output_filenames( extradefs
);
2524 output_filenames( get_expanded_make_var_array( make
, "EXTRAIDLFLAGS" ));
2525 output_filename( source
->filename
);
2527 output_filenames_obj_dir( make
, targets
);
2528 output( ": %s", source
->filename
);
2529 output_filenames( dependencies
);
2532 else if (!strcmp( ext
, "in" )) /* .in file or man page */
2534 if (strendswith( obj
, ".man" ) && source
->file
->args
)
2536 struct strarray symlinks
;
2537 char *dir
, *dest
= replace_extension( obj
, ".man", "" );
2538 char *lang
= strchr( dest
, '.' );
2539 char *section
= source
->file
->args
;
2543 dir
= strmake( "$(mandir)/%s/man%s", lang
, section
);
2545 else dir
= strmake( "$(mandir)/man%s", section
);
2546 add_install_rule( make
, install_rules
, dest
, xstrdup(obj
),
2547 strmake( "d%s/%s.%s", dir
, dest
, section
));
2548 symlinks
= get_expanded_file_local_var( make
, dest
, "SYMLINKS" );
2549 for (i
= 0; i
< symlinks
.count
; i
++)
2550 add_install_rule( make
, install_rules
, symlinks
.str
[i
],
2551 strmake( "%s.%s", dest
, section
),
2552 strmake( "y%s/%s.%s", dir
, symlinks
.str
[i
], section
));
2556 strarray_add( &in_files
, xstrdup(obj
) );
2557 strarray_add( &all_targets
, xstrdup(obj
) );
2558 output( "%s: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2559 output( "\t$(SED_CMD) %s >$@ || (rm -f $@ && false)\n", source
->filename
);
2560 output( "%s:", obj_dir_path( make
, obj
));
2561 output_filenames( dependencies
);
2563 add_install_rule( make
, install_rules
, obj
, xstrdup( obj
),
2564 strmake( "d$(datadir)/wine/%s", obj
));
2566 else if (!strcmp( ext
, "sfd" )) /* font file */
2568 char *ttf_file
= src_dir_path( make
, strmake( "%s.ttf", obj
));
2569 if (fontforge
&& !make
->src_dir
)
2571 output( "%s: %s\n", ttf_file
, source
->filename
);
2572 output( "\t%s -script %s %s $@\n",
2573 fontforge
, top_src_dir_path( make
, "fonts/genttf.ff" ), source
->filename
);
2574 if (!(source
->file
->flags
& FLAG_SFD_FONTS
)) output( "all: %s\n", ttf_file
);
2576 if (source
->file
->flags
& FLAG_INSTALL
)
2578 strarray_add( &install_rules
[INSTALL_LIB
], strmake( "%s.ttf", obj
));
2579 strarray_add( &install_rules
[INSTALL_LIB
], strmake( "D$(fontdir)/%s.ttf", obj
));
2581 if (source
->file
->flags
& FLAG_SFD_FONTS
)
2583 struct strarray
*array
= source
->file
->args
;
2585 for (i
= 0; i
< array
->count
; i
++)
2587 char *font
= strtok( xstrdup(array
->str
[i
]), " \t" );
2588 char *args
= strtok( NULL
, "" );
2590 strarray_add( &all_targets
, xstrdup( font
));
2591 output( "%s: %s %s\n", obj_dir_path( make
, font
),
2592 tools_path( make
, "sfnt2fon" ), ttf_file
);
2593 output( "\t%s -o $@ %s %s\n", tools_path( make
, "sfnt2fon" ), ttf_file
, args
);
2594 strarray_add( &install_rules
[INSTALL_LIB
], xstrdup(font
) );
2595 strarray_add( &install_rules
[INSTALL_LIB
], strmake( "d$(fontdir)/%s", font
));
2599 else if (!strcmp( ext
, "svg" )) /* svg file */
2601 if (convert
&& rsvg
&& icotool
&& !make
->src_dir
)
2603 static const char * const images
[] = { "bmp", "cur", "ico", NULL
};
2605 for (i
= 0; images
[i
]; i
++)
2606 if (find_include_file( make
, strmake( "%s.%s", obj
, images
[i
] ))) break;
2610 output( "%s.%s: %s\n", src_dir_path( make
, obj
), images
[i
], source
->filename
);
2611 output( "\tCONVERT=\"%s\" ICOTOOL=\"%s\" RSVG=\"%s\" %s %s $@\n", convert
, icotool
, rsvg
,
2612 top_src_dir_path( make
, "tools/buildimage" ), source
->filename
);
2616 else if (!strcmp( ext
, "po" )) /* po file */
2618 output( "%s.mo: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2619 output( "\t%s -o $@ %s\n", msgfmt
, source
->filename
);
2620 strarray_add( &all_targets
, strmake( "%s.mo", obj
));
2622 else if (!strcmp( ext
, "res" ))
2624 strarray_add( &res_files
, source
->name
);
2626 else if (!strcmp( ext
, "tlb" ))
2628 strarray_add( &all_targets
, source
->name
);
2630 else if (!strcmp( ext
, "h" ) || !strcmp( ext
, "rh" ) || !strcmp( ext
, "inl" )) /* header file */
2632 if (source
->file
->flags
& FLAG_GENERATED
)
2634 strarray_add( &all_targets
, source
->name
);
2638 strarray_add( &install_rules
[INSTALL_DEV
], source
->name
);
2639 strarray_add( &install_rules
[INSTALL_DEV
],
2640 strmake( "D$(includedir)/%s", get_include_install_path( source
->name
) ));
2645 int need_cross
= make
->testdll
||
2646 (source
->file
->flags
& FLAG_C_IMPLIB
) ||
2647 (make
->module
&& make
->staticlib
);
2649 if ((source
->file
->flags
& FLAG_GENERATED
) &&
2650 (!make
->testdll
|| !strendswith( source
->filename
, "testlist.c" )))
2651 strarray_add( &clean_files
, source
->filename
);
2652 if (source
->file
->flags
& FLAG_C_IMPLIB
) strarray_add( &implib_objs
, strmake( "%s.o", obj
));
2653 strarray_add( &object_files
, strmake( "%s.o", obj
));
2654 output( "%s.o: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2655 output( "\t$(CC) -c -o $@ %s", source
->filename
);
2656 output_filenames( includes
);
2657 output_filenames( make
->define_args
);
2658 output_filenames( extradefs
);
2659 if (make
->module
|| make
->staticlib
|| make
->sharedlib
|| make
->testdll
)
2661 output_filenames( dll_flags
);
2662 if (make
->use_msvcrt
) output_filenames( msvcrt_flags
);
2664 output_filenames( extra_cflags
);
2665 output_filenames( cpp_flags
);
2666 output_filename( "$(CFLAGS)" );
2668 if (crosstarget
&& need_cross
)
2670 strarray_add( &crossobj_files
, strmake( "%s.cross.o", obj
));
2671 output( "%s.cross.o: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2672 output( "\t$(CROSSCC) -c -o $@ %s", source
->filename
);
2673 output_filenames( includes
);
2674 output_filenames( make
->define_args
);
2675 output_filenames( extradefs
);
2676 if (make
->use_msvcrt
) output_filenames( msvcrt_flags
);
2677 output_filename( "-DWINE_CROSSTEST" );
2678 output_filenames( cpp_flags
);
2679 output_filename( "$(CROSSCFLAGS)" );
2682 if (make
->testdll
&& !strcmp( ext
, "c" ) && !(source
->file
->flags
& FLAG_GENERATED
))
2684 strarray_add( &ok_files
, strmake( "%s.ok", obj
));
2685 output( "%s.ok:\n", obj_dir_path( make
, obj
));
2686 output( "\t%s $(RUNTESTFLAGS) -T %s -M %s -p %s%s %s && touch $@\n",
2687 top_src_dir_path( make
, "tools/runtest" ), top_obj_dir_path( make
, "" ),
2688 make
->testdll
, replace_extension( make
->testdll
, ".dll", "_test.exe" ),
2691 if (!strcmp( ext
, "c" ) && !(source
->file
->flags
& FLAG_GENERATED
))
2692 strarray_add( &c2man_files
, source
->filename
);
2693 output( "%s.o", obj_dir_path( make
, obj
));
2694 if (crosstarget
&& need_cross
) output( " %s.cross.o", obj_dir_path( make
, obj
));
2696 output_filenames( dependencies
);
2702 /* rules for files that depend on multiple sources */
2704 if (dlldata_files
.count
)
2706 output( "%s: %s %s\n", obj_dir_path( make
, "dlldata.c" ),
2707 tools_path( make
, "widl" ), src_dir_path( make
, "Makefile.in" ));
2708 output( "\t%s --dlldata-only -o $@", tools_path( make
, "widl" ));
2709 output_filenames( dlldata_files
);
2713 if (make
->module
&& !make
->staticlib
)
2715 struct strarray all_libs
= empty_strarray
;
2716 struct strarray dep_libs
= empty_strarray
;
2717 char *module_path
= obj_dir_path( make
, make
->module
);
2718 char *spec_file
= NULL
;
2720 if (!make
->appmode
.count
)
2721 spec_file
= src_dir_path( make
, replace_extension( make
->module
, ".dll", ".spec" ));
2722 strarray_addall( &all_libs
, add_import_libs( make
, &dep_libs
, make
->delayimports
, 0 ));
2723 strarray_addall( &all_libs
, add_import_libs( make
, &dep_libs
, make
->imports
, 0 ));
2724 add_import_libs( make
, &dep_libs
, get_default_imports( make
), 0 ); /* dependencies only */
2725 strarray_addall( &all_libs
, add_default_libraries( make
, &dep_libs
));
2729 for (i
= 0; i
< make
->delayimports
.count
; i
++)
2730 strarray_add( &all_libs
, strmake( "-Wb,-d%s", make
->delayimports
.str
[i
] ));
2731 strarray_add( &all_targets
, strmake( "%s%s", make
->module
, dll_ext
));
2732 strarray_add( &all_targets
, strmake( "%s.fake", make
->module
));
2733 add_install_rule( make
, install_rules
, make
->module
, strmake( "%s%s", make
->module
, dll_ext
),
2734 strmake( "p$(dlldir)/%s%s", make
->module
, dll_ext
));
2735 add_install_rule( make
, install_rules
, make
->module
, strmake( "%s.fake", make
->module
),
2736 strmake( "d$(fakedlldir)/%s", make
->module
));
2737 output( "%s%s %s.fake:", module_path
, dll_ext
, module_path
);
2741 strarray_add( &all_libs
, "-lwine" );
2742 strarray_add( &all_targets
, make
->module
);
2743 add_install_rule( make
, install_rules
, make
->module
, make
->module
,
2744 strmake( "p$(%s)/%s", spec_file
? "dlldir" : "bindir", make
->module
));
2745 output( "%s:", module_path
);
2747 if (spec_file
) output_filename( spec_file
);
2748 output_filenames_obj_dir( make
, object_files
);
2749 output_filenames_obj_dir( make
, res_files
);
2750 output_filenames( dep_libs
);
2751 output_filename( tools_path( make
, "winebuild" ));
2752 output_filename( tools_path( make
, "winegcc" ));
2754 output( "\t%s -o $@", tools_path( make
, "winegcc" ));
2755 output_filename( strmake( "-B%s", tools_dir_path( make
, "winebuild" )));
2756 if (tools_dir
) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make
, "" )));
2757 output_filenames( target_flags
);
2758 output_filenames( unwind_flags
);
2761 output( " -shared %s", spec_file
);
2762 output_filenames( make
->extradllflags
);
2764 else output_filenames( make
->appmode
);
2765 output_filenames_obj_dir( make
, object_files
);
2766 output_filenames_obj_dir( make
, res_files
);
2767 output_filenames( all_libs
);
2768 output_filename( "$(LDFLAGS)" );
2771 if (spec_file
&& make
->importlib
)
2773 char *importlib_path
= obj_dir_path( make
, strmake( "lib%s", make
->importlib
));
2774 if (*dll_ext
&& !implib_objs
.count
)
2776 strarray_add( &clean_files
, strmake( "lib%s.def", make
->importlib
));
2777 output( "%s.def: %s %s\n", importlib_path
, tools_path( make
, "winebuild" ), spec_file
);
2778 output( "\t%s -w --def -o $@ --export %s", tools_path( make
, "winebuild" ), spec_file
);
2779 output_filenames( target_flags
);
2780 if (make
->is_win16
) output_filename( "-m16" );
2782 add_install_rule( make
, install_rules
, make
->importlib
,
2783 strmake( "lib%s.def", make
->importlib
),
2784 strmake( "d$(dlldir)/lib%s.def", make
->importlib
));
2788 strarray_add( &clean_files
, strmake( "lib%s.a", make
->importlib
));
2789 output( "%s.a: %s %s", importlib_path
, tools_path( make
, "winebuild" ), spec_file
);
2790 output_filenames_obj_dir( make
, implib_objs
);
2792 output( "\t%s -w --implib -o $@ --export %s", tools_path( make
, "winebuild" ), spec_file
);
2793 output_filenames( target_flags
);
2794 output_filenames_obj_dir( make
, implib_objs
);
2796 add_install_rule( make
, install_rules
, make
->importlib
,
2797 strmake( "lib%s.a", make
->importlib
),
2798 strmake( "d$(dlldir)/lib%s.a", make
->importlib
));
2800 if (crosstarget
&& !make
->is_win16
)
2802 struct strarray cross_files
= strarray_replace_extension( &implib_objs
, ".o", ".cross.o" );
2803 strarray_add( &clean_files
, strmake( "lib%s.cross.a", make
->importlib
));
2804 output( "%s.cross.a: %s %s", importlib_path
, tools_path( make
, "winebuild" ), spec_file
);
2805 output_filenames_obj_dir( make
, cross_files
);
2807 output( "\t%s -b %s -w --implib -o $@ --export %s",
2808 tools_path( make
, "winebuild" ), crosstarget
, spec_file
);
2809 output_filenames_obj_dir( make
, cross_files
);
2816 if (c2man_files
.count
)
2818 output( "manpages::\n" );
2819 output( "\t%s -w %s", top_src_dir_path( make
, "tools/c2man.pl" ), spec_file
);
2820 output_filename( strmake( "-R%s", top_src_dir_path( make
, "" )));
2821 output_filename( strmake( "-I%s", top_src_dir_path( make
, "include" )));
2822 output_filename( strmake( "-o %s/man%s",
2823 top_obj_dir_path( make
, "documentation" ), man_ext
));
2824 output_filenames( c2man_files
);
2826 output( "htmlpages::\n" );
2827 output( "\t%s -Th -w %s", top_src_dir_path( make
, "tools/c2man.pl" ), spec_file
);
2828 output_filename( strmake( "-R%s", top_src_dir_path( make
, "" )));
2829 output_filename( strmake( "-I%s", top_src_dir_path( make
, "include" )));
2830 output_filename( strmake( "-o %s",
2831 top_obj_dir_path( make
, "documentation/html" )));
2832 output_filenames( c2man_files
);
2834 output( "sgmlpages::\n" );
2835 output( "\t%s -Ts -w %s", top_src_dir_path( make
, "tools/c2man.pl" ), spec_file
);
2836 output_filename( strmake( "-R%s", top_src_dir_path( make
, "" )));
2837 output_filename( strmake( "-I%s", top_src_dir_path( make
, "include" )));
2838 output_filename( strmake( "-o %s",
2839 top_obj_dir_path( make
, "documentation/api-guide" )));
2840 output_filenames( c2man_files
);
2842 output( "xmlpages::\n" );
2843 output( "\t%s -Tx -w %s", top_src_dir_path( make
, "tools/c2man.pl" ), spec_file
);
2844 output_filename( strmake( "-R%s", top_src_dir_path( make
, "" )));
2845 output_filename( strmake( "-I%s", top_src_dir_path( make
, "include" )));
2846 output_filename( strmake( "-o %s",
2847 top_obj_dir_path( make
, "documentation/api-guide-xml" )));
2848 output_filenames( c2man_files
);
2850 strarray_add( &phony_targets
, "manpages" );
2851 strarray_add( &phony_targets
, "htmlpages" );
2852 strarray_add( &phony_targets
, "sgmlpages" );
2853 strarray_add( &phony_targets
, "xmlpages" );
2855 else output( "manpages htmlpages sgmlpages xmlpages::\n" );
2859 char *binary
= replace_extension( make
->module
, ".exe", "" );
2860 add_install_rule( make
, install_rules
, binary
, "wineapploader",
2861 strmake( "t$(bindir)/%s", binary
));
2865 if (make
->staticlib
)
2867 strarray_add( &all_targets
, make
->staticlib
);
2868 output( "%s:", obj_dir_path( make
, make
->staticlib
));
2869 output_filenames_obj_dir( make
, object_files
);
2870 output( "\n\trm -f $@\n" );
2871 output( "\t$(AR) $(ARFLAGS) $@" );
2872 output_filenames_obj_dir( make
, object_files
);
2873 output( "\n\t$(RANLIB) $@\n" );
2874 add_install_rule( make
, install_rules
, make
->staticlib
, make
->staticlib
,
2875 strmake( "d$(dlldir)/%s", make
->staticlib
));
2876 if (crosstarget
&& make
->module
)
2878 char *name
= replace_extension( make
->staticlib
, ".a", ".cross.a" );
2880 strarray_add( &all_targets
, name
);
2881 output( "%s:", obj_dir_path( make
, name
));
2882 output_filenames_obj_dir( make
, crossobj_files
);
2883 output( "\n\trm -f $@\n" );
2884 output( "\t%s-ar $(ARFLAGS) $@", crosstarget
);
2885 output_filenames_obj_dir( make
, crossobj_files
);
2886 output( "\n\t%s-ranlib $@\n", crosstarget
);
2890 if (make
->sharedlib
)
2893 struct strarray names
= get_shared_lib_names( make
->sharedlib
);
2894 struct strarray all_libs
= empty_strarray
;
2895 struct strarray dep_libs
= empty_strarray
;
2897 basename
= xstrdup( make
->sharedlib
);
2898 if ((p
= strchr( basename
, '.' ))) *p
= 0;
2900 strarray_addall( &dep_libs
, get_local_dependencies( make
, basename
, in_files
));
2901 strarray_addall( &all_libs
, get_expanded_file_local_var( make
, basename
, "LDFLAGS" ));
2902 strarray_addall( &all_libs
, add_default_libraries( make
, &dep_libs
));
2904 output( "%s:", obj_dir_path( make
, make
->sharedlib
));
2905 output_filenames_obj_dir( make
, object_files
);
2906 output_filenames( dep_libs
);
2908 output( "\t$(CC) -o $@" );
2909 output_filenames_obj_dir( make
, object_files
);
2910 output_filenames( all_libs
);
2911 output_filename( "$(LDFLAGS)" );
2913 add_install_rule( make
, install_rules
, make
->sharedlib
, make
->sharedlib
,
2914 strmake( "p$(libdir)/%s", make
->sharedlib
));
2915 for (i
= 1; i
< names
.count
; i
++)
2917 output( "%s: %s\n", obj_dir_path( make
, names
.str
[i
] ), obj_dir_path( make
, names
.str
[i
-1] ));
2918 output_symlink_rule( obj_dir_path( make
, names
.str
[i
-1] ), obj_dir_path( make
, names
.str
[i
] ));
2919 add_install_rule( make
, install_rules
, names
.str
[i
], names
.str
[i
-1],
2920 strmake( "y$(libdir)/%s", names
.str
[i
] ));
2922 strarray_addall( &all_targets
, names
);
2925 if (make
->importlib
&& !make
->module
) /* stand-alone import lib (for libwine) */
2927 char *def_file
= replace_extension( make
->importlib
, ".a", ".def" );
2929 if (!strncmp( def_file
, "lib", 3 )) def_file
+= 3;
2930 output( "%s: %s\n", obj_dir_path( make
, make
->importlib
), src_dir_path( make
, def_file
));
2931 output( "\t%s -l $@ -d %s\n", dlltool
, src_dir_path( make
, def_file
));
2932 add_install_rule( make
, install_rules
, make
->importlib
, make
->importlib
,
2933 strmake( "d$(libdir)/%s", make
->importlib
));
2934 strarray_add( &all_targets
, make
->importlib
);
2939 char *testmodule
= replace_extension( make
->testdll
, ".dll", "_test.exe" );
2940 char *stripped
= replace_extension( make
->testdll
, ".dll", "_test-stripped.exe" );
2941 char *testres
= replace_extension( make
->testdll
, ".dll", "_test.res" );
2942 struct strarray dep_libs
= empty_strarray
;
2943 struct strarray all_libs
= add_import_libs( make
, &dep_libs
, make
->imports
, 0 );
2945 add_import_libs( make
, &dep_libs
, get_default_imports( make
), 0 ); /* dependencies only */
2946 strarray_addall( &all_libs
, libs
);
2947 strarray_add( &all_targets
, strmake( "%s%s", testmodule
, dll_ext
));
2948 strarray_add( &clean_files
, strmake( "%s%s", stripped
, dll_ext
));
2949 output( "%s%s:\n", obj_dir_path( make
, testmodule
), dll_ext
);
2950 output( "\t%s -o $@", tools_path( make
, "winegcc" ));
2951 output_filename( strmake( "-B%s", tools_dir_path( make
, "winebuild" )));
2952 if (tools_dir
) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make
, "" )));
2953 output_filenames( target_flags
);
2954 output_filenames( unwind_flags
);
2955 output_filenames( make
->appmode
);
2956 output_filenames_obj_dir( make
, object_files
);
2957 output_filenames_obj_dir( make
, res_files
);
2958 output_filenames( all_libs
);
2959 output_filename( "$(LDFLAGS)" );
2961 output( "%s%s:\n", obj_dir_path( make
, stripped
), dll_ext
);
2962 output( "\t%s -o $@", tools_path( make
, "winegcc" ));
2963 output_filename( strmake( "-B%s", tools_dir_path( make
, "winebuild" )));
2964 if (tools_dir
) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make
, "" )));
2965 output_filenames( target_flags
);
2966 output_filenames( unwind_flags
);
2967 output_filename( strmake( "-Wb,-F,%s", testmodule
));
2968 output_filenames( make
->appmode
);
2969 output_filenames_obj_dir( make
, object_files
);
2970 output_filenames_obj_dir( make
, res_files
);
2971 output_filenames( all_libs
);
2972 output_filename( "$(LDFLAGS)" );
2974 output( "%s%s %s%s:", obj_dir_path( make
, testmodule
), dll_ext
,
2975 obj_dir_path( make
, stripped
), dll_ext
);
2976 output_filenames_obj_dir( make
, object_files
);
2977 output_filenames_obj_dir( make
, res_files
);
2978 output_filenames( dep_libs
);
2979 output_filename( tools_path( make
, "winebuild" ));
2980 output_filename( tools_path( make
, "winegcc" ));
2983 if (!make
->disabled
)
2984 output( "all: %s/%s\n", top_obj_dir_path( make
, "programs/winetest" ), testres
);
2985 output( "%s/%s: %s%s\n", top_obj_dir_path( make
, "programs/winetest" ), testres
,
2986 obj_dir_path( make
, stripped
), dll_ext
);
2987 output( "\techo \"%s TESTRES \\\"%s%s\\\"\" | %s -o $@\n",
2988 testmodule
, obj_dir_path( make
, stripped
), dll_ext
, tools_path( make
, "wrc" ));
2992 char *crosstest
= replace_extension( make
->testdll
, ".dll", "_crosstest.exe" );
2994 dep_libs
= empty_strarray
;
2995 all_libs
= add_import_libs( make
, &dep_libs
, make
->imports
, 1 );
2996 add_import_libs( make
, &dep_libs
, get_default_imports( make
), 1 ); /* dependencies only */
2997 strarray_addall( &all_libs
, libs
);
2998 strarray_add( &clean_files
, crosstest
);
2999 output( "%s:", obj_dir_path( make
, crosstest
));
3000 output_filenames_obj_dir( make
, crossobj_files
);
3001 output_filenames_obj_dir( make
, res_files
);
3002 output_filenames( dep_libs
);
3003 output_filename( tools_path( make
, "winebuild" ));
3004 output_filename( tools_path( make
, "winegcc" ));
3006 output( "\t%s -o $@ -b %s", tools_path( make
, "winegcc" ), crosstarget
);
3007 output_filename( strmake( "-B%s", tools_dir_path( make
, "winebuild" )));
3008 if (tools_dir
) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make
, "" )));
3009 output_filename( "--lib-suffix=.cross.a" );
3010 output_filenames_obj_dir( make
, crossobj_files
);
3011 output_filenames_obj_dir( make
, res_files
);
3012 output_filenames( all_libs
);
3013 output_filename( "$(LDFLAGS)" );
3015 if (!make
->disabled
)
3017 output( "%s: %s\n", obj_dir_path( make
, "crosstest" ), obj_dir_path( make
, crosstest
));
3018 strarray_add( &phony_targets
, obj_dir_path( make
, "crosstest" ));
3019 if (make
->obj_dir
) output( "crosstest: %s\n", obj_dir_path( make
, "crosstest" ));
3023 output_filenames_obj_dir( make
, ok_files
);
3024 output( ": %s%s ../%s%s\n", testmodule
, dll_ext
, make
->testdll
, dll_ext
);
3025 if (!make
->disabled
)
3027 output( "check test:" );
3028 output_filenames_obj_dir( make
, ok_files
);
3030 strarray_add( &phony_targets
, "check" );
3031 strarray_add( &phony_targets
, "test" );
3033 output( "testclean::\n" );
3034 output( "\trm -f" );
3035 output_filenames_obj_dir( make
, ok_files
);
3037 strarray_addall( &clean_files
, ok_files
);
3038 strarray_add( &phony_targets
, "testclean" );
3041 for (i
= 0; i
< make
->programs
.count
; i
++)
3043 char *program_installed
= NULL
;
3044 char *program
= strmake( "%s%s", make
->programs
.str
[i
], exe_ext
);
3045 struct strarray deps
= get_local_dependencies( make
, make
->programs
.str
[i
], in_files
);
3046 struct strarray all_libs
= get_expanded_file_local_var( make
, make
->programs
.str
[i
], "LDFLAGS" );
3047 struct strarray objs
= get_expanded_file_local_var( make
, make
->programs
.str
[i
], "OBJS" );
3048 struct strarray symlinks
= get_expanded_file_local_var( make
, make
->programs
.str
[i
], "SYMLINKS" );
3050 if (!objs
.count
) objs
= object_files
;
3051 strarray_addall( &all_libs
, add_default_libraries( make
, &deps
));
3053 output( "%s:", obj_dir_path( make
, program
) );
3054 output_filenames_obj_dir( make
, objs
);
3055 output_filenames( deps
);
3057 output( "\t$(CC) -o $@" );
3058 output_filenames_obj_dir( make
, objs
);
3060 if (strarray_exists( &all_libs
, "-lwine" ))
3062 strarray_add( &all_libs
, strmake( "-L%s", top_obj_dir_path( make
, "libs/wine" )));
3063 if (ldrpath_local
&& ldrpath_install
)
3065 program_installed
= strmake( "%s-installed%s", make
->programs
.str
[i
], exe_ext
);
3066 output_filename( ldrpath_local
);
3067 output_filenames( all_libs
);
3068 output_filename( "$(LDFLAGS)" );
3070 output( "%s:", obj_dir_path( make
, program_installed
) );
3071 output_filenames_obj_dir( make
, objs
);
3072 output_filenames( deps
);
3074 output( "\t$(CC) -o $@" );
3075 output_filenames_obj_dir( make
, objs
);
3076 output_filename( ldrpath_install
);
3077 strarray_add( &all_targets
, program_installed
);
3081 output_filenames( all_libs
);
3082 output_filename( "$(LDFLAGS)" );
3084 strarray_add( &all_targets
, program
);
3086 for (j
= 0; j
< symlinks
.count
; j
++)
3088 output( "%s: %s\n", obj_dir_path( make
, symlinks
.str
[j
] ), obj_dir_path( make
, program
));
3089 output_symlink_rule( obj_dir_path( make
, program
), obj_dir_path( make
, symlinks
.str
[j
] ));
3091 strarray_addall( &all_targets
, symlinks
);
3093 add_install_rule( make
, install_rules
, program
, program_installed
? program_installed
: program
,
3094 strmake( "p$(bindir)/%s", program
));
3095 for (j
= 0; j
< symlinks
.count
; j
++)
3096 add_install_rule( make
, install_rules
, symlinks
.str
[j
], program
,
3097 strmake( "y$(bindir)/%s%s", symlinks
.str
[j
], exe_ext
));
3100 for (i
= 0; i
< make
->scripts
.count
; i
++)
3101 add_install_rule( make
, install_rules
, make
->scripts
.str
[i
], make
->scripts
.str
[i
],
3102 strmake( "S$(bindir)/%s", make
->scripts
.str
[i
] ));
3104 if (!make
->disabled
)
3106 if (all_targets
.count
)
3109 output_filenames_obj_dir( make
, all_targets
);
3112 strarray_addall( &uninstall_files
, output_install_rules( make
, install_rules
[INSTALL_LIB
],
3113 "install-lib", &phony_targets
));
3114 strarray_addall( &uninstall_files
, output_install_rules( make
, install_rules
[INSTALL_DEV
],
3115 "install-dev", &phony_targets
));
3116 if (uninstall_files
.count
)
3118 output( "uninstall::\n" );
3119 output( "\trm -f" );
3120 output_filenames( uninstall_files
);
3122 strarray_add_uniq( &phony_targets
, "uninstall" );
3126 strarray_addall( &clean_files
, object_files
);
3127 strarray_addall( &clean_files
, crossobj_files
);
3128 strarray_addall( &clean_files
, res_files
);
3129 strarray_addall( &clean_files
, all_targets
);
3130 strarray_addall( &clean_files
, get_expanded_make_var_array( make
, "EXTRA_TARGETS" ));
3132 if (make
->subdirs
.count
)
3134 struct strarray build_deps
= empty_strarray
;
3135 struct strarray makefile_deps
= empty_strarray
;
3136 struct strarray distclean_files
= get_expanded_make_var_array( make
, "CONFIGURE_TARGETS" );
3138 strarray_add( &distclean_files
, obj_dir_path( make
, output_makefile_name
));
3139 if (!make
->src_dir
) strarray_add( &distclean_files
, obj_dir_path( make
, ".gitignore" ));
3140 for (i
= 0; i
< make
->subdirs
.count
; i
++)
3142 const struct makefile
*submake
= make
->submakes
[i
];
3144 strarray_add( &makefile_deps
, top_src_dir_path( make
, base_dir_path( submake
,
3145 strmake ( "%s.in", output_makefile_name
))));
3146 strarray_add( &distclean_files
, base_dir_path( submake
, output_makefile_name
));
3147 if (!make
->src_dir
) strarray_add( &distclean_files
, base_dir_path( submake
, ".gitignore" ));
3148 if (submake
->testdll
) strarray_add( &distclean_files
, base_dir_path( submake
, "testlist.c" ));
3149 strarray_addall( &build_deps
, output_importlib_symlinks( make
, submake
));
3151 output( "Makefile:" );
3152 output_filenames( makefile_deps
);
3154 output_filenames( makefile_deps
);
3156 output( "distclean::\n");
3157 output( "\trm -f" );
3158 output_filenames( distclean_files
);
3160 strarray_add( &phony_targets
, "distclean" );
3162 if (build_deps
.count
)
3164 output( "__builddeps__:" );
3165 output_filenames( build_deps
);
3167 strarray_addall( &clean_files
, build_deps
);
3169 if (get_expanded_make_variable( make
, "GETTEXTPO_LIBS" )) output_po_files( make
);
3172 if (clean_files
.count
)
3174 output( "%s::\n", obj_dir_path( make
, "clean" ));
3175 output( "\trm -f" );
3176 output_filenames_obj_dir( make
, clean_files
);
3178 if (make
->obj_dir
) output( "__clean__: %s\n", obj_dir_path( make
, "clean" ));
3179 strarray_add( &phony_targets
, obj_dir_path( make
, "clean" ));
3182 if (phony_targets
.count
)
3184 output( ".PHONY:" );
3185 output_filenames( phony_targets
);
3189 if (!make
->base_dir
)
3190 strarray_addall( &clean_files
, get_expanded_make_var_array( make
, "CONFIGURE_TARGETS" ));
3195 /*******************************************************************
3198 static FILE *create_temp_file( const char *orig
)
3200 char *name
= xmalloc( strlen(orig
) + 13 );
3201 unsigned int i
, id
= getpid();
3205 for (i
= 0; i
< 100; i
++)
3207 sprintf( name
, "%s.tmp%08x", orig
, id
);
3208 if ((fd
= open( name
, O_RDWR
| O_CREAT
| O_EXCL
, 0666 )) != -1)
3210 ret
= fdopen( fd
, "w" );
3213 if (errno
!= EEXIST
) break;
3216 if (!ret
) fatal_error( "failed to create output file for '%s'\n", orig
);
3217 temp_file_name
= name
;
3222 /*******************************************************************
3225 static void rename_temp_file( const char *dest
)
3227 int ret
= rename( temp_file_name
, dest
);
3228 if (ret
== -1 && errno
== EEXIST
)
3230 /* rename doesn't overwrite on windows */
3232 ret
= rename( temp_file_name
, dest
);
3234 if (ret
== -1) fatal_error( "failed to rename output file to '%s'\n", dest
);
3235 temp_file_name
= NULL
;
3239 /*******************************************************************
3240 * are_files_identical
3242 static int are_files_identical( FILE *file1
, FILE *file2
)
3246 char buffer1
[8192], buffer2
[8192];
3247 int size1
= fread( buffer1
, 1, sizeof(buffer1
), file1
);
3248 int size2
= fread( buffer2
, 1, sizeof(buffer2
), file2
);
3249 if (size1
!= size2
) return 0;
3250 if (!size1
) return feof( file1
) && feof( file2
);
3251 if (memcmp( buffer1
, buffer2
, size1
)) return 0;
3256 /*******************************************************************
3257 * rename_temp_file_if_changed
3259 static void rename_temp_file_if_changed( const char *dest
)
3261 FILE *file1
, *file2
;
3264 if ((file1
= fopen( dest
, "r" )))
3266 if ((file2
= fopen( temp_file_name
, "r" )))
3268 do_rename
= !are_files_identical( file1
, file2
);
3275 unlink( temp_file_name
);
3276 temp_file_name
= NULL
;
3278 else rename_temp_file( dest
);
3282 /*******************************************************************
3285 static void output_linguas( const struct makefile
*make
)
3287 const char *dest
= base_dir_path( make
, "LINGUAS" );
3288 struct incl_file
*source
;
3290 output_file
= create_temp_file( dest
);
3292 output( "# Automatically generated by make depend; DO NOT EDIT!!\n" );
3293 LIST_FOR_EACH_ENTRY( source
, &make
->sources
, struct incl_file
, entry
)
3294 if (strendswith( source
->name
, ".po" ))
3295 output( "%s\n", replace_extension( source
->name
, ".po", "" ));
3297 if (fclose( output_file
)) fatal_perror( "write" );
3299 rename_temp_file_if_changed( dest
);
3303 /*******************************************************************
3306 static void output_testlist( const struct makefile
*make
)
3308 const char *dest
= base_dir_path( make
, "testlist.c" );
3309 struct strarray files
= empty_strarray
;
3310 struct incl_file
*source
;
3313 LIST_FOR_EACH_ENTRY( source
, &make
->sources
, struct incl_file
, entry
)
3315 if (source
->file
->flags
& FLAG_GENERATED
) continue;
3316 if (!strendswith( source
->name
, ".c" )) continue;
3317 strarray_add( &files
, replace_extension( source
->name
, ".c", "" ));
3320 output_file
= create_temp_file( dest
);
3322 output( "/* Automatically generated by make depend; DO NOT EDIT!! */\n\n" );
3323 output( "#define WIN32_LEAN_AND_MEAN\n" );
3324 output( "#include <windows.h>\n\n" );
3325 output( "#define STANDALONE\n" );
3326 output( "#include \"wine/test.h\"\n\n" );
3328 for (i
= 0; i
< files
.count
; i
++) output( "extern void func_%s(void);\n", files
.str
[i
] );
3330 output( "const struct test winetest_testlist[] =\n" );
3332 for (i
= 0; i
< files
.count
; i
++) output( " { \"%s\", func_%s },\n", files
.str
[i
], files
.str
[i
] );
3333 output( " { 0, 0 }\n" );
3336 if (fclose( output_file
)) fatal_perror( "write" );
3338 rename_temp_file_if_changed( dest
);
3342 /*******************************************************************
3345 static void output_gitignore( const char *dest
, struct strarray files
)
3349 output_file
= create_temp_file( dest
);
3351 output( "# Automatically generated by make depend; DO NOT EDIT!!\n" );
3352 for (i
= 0; i
< files
.count
; i
++)
3354 if (!strchr( files
.str
[i
], '/' )) output( "/" );
3355 output( "%s\n", files
.str
[i
] );
3358 if (fclose( output_file
)) fatal_perror( "write" );
3360 rename_temp_file( dest
);
3364 /*******************************************************************
3365 * output_top_variables
3367 static void output_top_variables( const struct makefile
*make
)
3370 struct strarray
*vars
= &top_makefile
->vars
;
3372 if (!make
->base_dir
) return; /* don't output variables in the top makefile */
3374 output( "# Automatically generated by make depend; DO NOT EDIT!!\n\n" );
3375 output( "all:\n\n" );
3376 for (i
= 0; i
< vars
->count
; i
+= 2)
3378 if (!strcmp( vars
->str
[i
], "SUBDIRS" )) continue; /* not inherited */
3379 output( "%s = %s\n", vars
->str
[i
], get_make_variable( make
, vars
->str
[i
] ));
3385 /*******************************************************************
3386 * output_dependencies
3388 static void output_dependencies( const struct makefile
*make
)
3390 struct strarray targets
, ignore_files
= empty_strarray
;
3395 if (make
->base_dir
) create_dir( make
->base_dir
);
3397 output_file_name
= base_dir_path( make
, output_makefile_name
);
3398 output_file
= create_temp_file( output_file_name
);
3399 output_top_variables( make
);
3401 /* copy the contents of the source makefile */
3402 src_file
= open_input_makefile( make
);
3403 while (fgets( buffer
, sizeof(buffer
), src_file
) && !found
)
3405 if (fwrite( buffer
, 1, strlen(buffer
), output_file
) != strlen(buffer
)) fatal_perror( "write" );
3406 found
= !strncmp( buffer
, separator
, strlen(separator
) );
3408 if (fclose( src_file
)) fatal_perror( "close" );
3409 input_file_name
= NULL
;
3411 if (!found
) output( "\n%s (everything below this line is auto-generated; DO NOT EDIT!!)\n", separator
);
3412 targets
= output_sources( make
);
3414 fclose( output_file
);
3416 rename_temp_file( output_file_name
);
3418 strarray_add( &ignore_files
, ".gitignore" );
3419 strarray_add( &ignore_files
, "Makefile" );
3422 output_testlist( make
);
3423 strarray_add( &ignore_files
, "testlist.c" );
3425 if (make
->base_dir
&& !strcmp( make
->base_dir
, "po" ))
3427 output_linguas( make
);
3428 strarray_add( &ignore_files
, "LINGUAS" );
3430 strarray_addall( &ignore_files
, targets
);
3431 if (!make
->src_dir
) output_gitignore( base_dir_path( make
, ".gitignore" ), ignore_files
);
3433 create_file_directories( make
, targets
);
3435 output_file_name
= NULL
;
3439 /*******************************************************************
3442 static void load_sources( struct makefile
*make
)
3444 static const char *source_vars
[] =
3464 struct strarray value
;
3465 struct incl_file
*file
;
3469 make
->top_src_dir
= concat_paths( make
->top_obj_dir
, root_src_dir
);
3470 make
->src_dir
= concat_paths( make
->top_src_dir
, make
->base_dir
);
3472 strarray_set_value( &make
->vars
, "top_builddir", top_obj_dir_path( make
, "" ));
3473 strarray_set_value( &make
->vars
, "top_srcdir", top_src_dir_path( make
, "" ));
3474 strarray_set_value( &make
->vars
, "srcdir", src_dir_path( make
, "" ));
3476 make
->parent_dir
= get_expanded_make_variable( make
, "PARENTSRC" );
3477 make
->module
= get_expanded_make_variable( make
, "MODULE" );
3478 make
->testdll
= get_expanded_make_variable( make
, "TESTDLL" );
3479 make
->sharedlib
= get_expanded_make_variable( make
, "SHAREDLIB" );
3480 make
->staticlib
= get_expanded_make_variable( make
, "STATICLIB" );
3481 make
->importlib
= get_expanded_make_variable( make
, "IMPORTLIB" );
3483 make
->programs
= get_expanded_make_var_array( make
, "PROGRAMS" );
3484 make
->scripts
= get_expanded_make_var_array( make
, "SCRIPTS" );
3485 make
->appmode
= get_expanded_make_var_array( make
, "APPMODE" );
3486 make
->imports
= get_expanded_make_var_array( make
, "IMPORTS" );
3487 make
->delayimports
= get_expanded_make_var_array( make
, "DELAYIMPORTS" );
3488 make
->extradllflags
= get_expanded_make_var_array( make
, "EXTRADLLFLAGS" );
3489 make
->install_lib
= get_expanded_make_var_array( make
, "INSTALL_LIB" );
3490 make
->install_dev
= get_expanded_make_var_array( make
, "INSTALL_DEV" );
3492 if (make
->module
&& strendswith( make
->module
, ".a" )) make
->staticlib
= make
->module
;
3494 make
->disabled
= make
->base_dir
&& strarray_exists( &disabled_dirs
, make
->base_dir
);
3495 make
->is_win16
= strarray_exists( &make
->extradllflags
, "-m16" );
3496 make
->use_msvcrt
= strarray_exists( &make
->appmode
, "-mno-cygwin" );
3498 for (i
= 0; i
< make
->imports
.count
&& !make
->use_msvcrt
; i
++)
3499 make
->use_msvcrt
= !strncmp( make
->imports
.str
[i
], "msvcr", 5 ) ||
3500 !strcmp( make
->imports
.str
[i
], "ucrtbase" );
3502 if (make
->module
&& !make
->install_lib
.count
&& !make
->install_dev
.count
)
3504 if (make
->importlib
) strarray_add( &make
->install_dev
, make
->importlib
);
3505 if (make
->staticlib
) strarray_add( &make
->install_dev
, make
->staticlib
);
3506 else strarray_add( &make
->install_lib
, make
->module
);
3509 make
->include_paths
= empty_strarray
;
3510 make
->define_args
= empty_strarray
;
3511 strarray_add( &make
->define_args
, "-D__WINESRC__" );
3513 value
= get_expanded_make_var_array( make
, "EXTRAINCL" );
3514 for (i
= 0; i
< value
.count
; i
++)
3515 if (!strncmp( value
.str
[i
], "-I", 2 ))
3516 strarray_add_uniq( &make
->include_paths
, value
.str
[i
] + 2 );
3518 strarray_add_uniq( &make
->define_args
, value
.str
[i
] );
3519 strarray_addall( &make
->define_args
, get_expanded_make_var_array( make
, "EXTRADEFS" ));
3521 list_init( &make
->sources
);
3522 list_init( &make
->includes
);
3524 for (var
= source_vars
; *var
; var
++)
3526 value
= get_expanded_make_var_array( make
, *var
);
3527 for (i
= 0; i
< value
.count
; i
++) add_src_file( make
, value
.str
[i
] );
3530 add_generated_sources( make
);
3532 value
= get_expanded_make_var_array( make
, "EXTRA_OBJS" );
3533 for (i
= 0; i
< value
.count
; i
++)
3535 /* default to .c for unknown extra object files */
3536 if (strendswith( value
.str
[i
], ".o" ))
3537 add_generated_source( make
, value
.str
[i
], replace_extension( value
.str
[i
], ".o", ".c" ) );
3539 add_generated_source( make
, value
.str
[i
], NULL
);
3542 LIST_FOR_EACH_ENTRY( file
, &make
->includes
, struct incl_file
, entry
) parse_file( make
, file
, 0 );
3546 /*******************************************************************
3549 static void parse_makeflags( const char *flags
)
3551 const char *p
= flags
;
3552 char *var
, *buffer
= xmalloc( strlen(flags
) + 1 );
3556 while (isspace(*p
)) p
++;
3558 while (*p
&& !isspace(*p
))
3560 if (*p
== '\\' && p
[1]) p
++;
3564 if (var
> buffer
) set_make_variable( &cmdline_vars
, buffer
);
3569 /*******************************************************************
3572 static int parse_option( const char *opt
)
3576 if (strchr( opt
, '=' )) return set_make_variable( &cmdline_vars
, opt
);
3582 if (opt
[2]) output_makefile_name
= opt
+ 2;
3585 relative_dir_mode
= 1;
3588 fprintf( stderr
, "Unknown option '%s'\n%s", opt
, Usage
);
3595 /*******************************************************************
3598 int main( int argc
, char *argv
[] )
3600 const char *makeflags
= getenv( "MAKEFLAGS" );
3603 if (makeflags
) parse_makeflags( makeflags
);
3608 if (parse_option( argv
[i
] ))
3610 for (j
= i
; j
< argc
; j
++) argv
[j
] = argv
[j
+1];
3616 if (relative_dir_mode
)
3622 fprintf( stderr
, "Option -R needs two directories\n%s", Usage
);
3625 relpath
= get_relative_path( argv
[1], argv
[2] );
3626 printf( "%s\n", relpath
? relpath
: "." );
3630 atexit( cleanup_files
);
3631 signal( SIGTERM
, exit_on_signal
);
3632 signal( SIGINT
, exit_on_signal
);
3634 signal( SIGHUP
, exit_on_signal
);
3637 for (i
= 0; i
< HASH_SIZE
; i
++) list_init( &files
[i
] );
3639 top_makefile
= parse_makefile( NULL
);
3641 target_flags
= get_expanded_make_var_array( top_makefile
, "TARGETFLAGS" );
3642 msvcrt_flags
= get_expanded_make_var_array( top_makefile
, "MSVCRTFLAGS" );
3643 dll_flags
= get_expanded_make_var_array( top_makefile
, "DLLFLAGS" );
3644 extra_cflags
= get_expanded_make_var_array( top_makefile
, "EXTRACFLAGS" );
3645 cpp_flags
= get_expanded_make_var_array( top_makefile
, "CPPFLAGS" );
3646 unwind_flags
= get_expanded_make_var_array( top_makefile
, "UNWINDFLAGS" );
3647 libs
= get_expanded_make_var_array( top_makefile
, "LIBS" );
3649 root_src_dir
= get_expanded_make_variable( top_makefile
, "srcdir" );
3650 tools_dir
= get_expanded_make_variable( top_makefile
, "TOOLSDIR" );
3651 tools_ext
= get_expanded_make_variable( top_makefile
, "TOOLSEXT" );
3652 exe_ext
= get_expanded_make_variable( top_makefile
, "EXEEXT" );
3653 man_ext
= get_expanded_make_variable( top_makefile
, "api_manext" );
3654 dll_ext
= (exe_ext
&& !strcmp( exe_ext
, ".exe" )) ? "" : ".so";
3655 crosstarget
= get_expanded_make_variable( top_makefile
, "CROSSTARGET" );
3656 fontforge
= get_expanded_make_variable( top_makefile
, "FONTFORGE" );
3657 convert
= get_expanded_make_variable( top_makefile
, "CONVERT" );
3658 rsvg
= get_expanded_make_variable( top_makefile
, "RSVG" );
3659 icotool
= get_expanded_make_variable( top_makefile
, "ICOTOOL" );
3660 dlltool
= get_expanded_make_variable( top_makefile
, "DLLTOOL" );
3661 msgfmt
= get_expanded_make_variable( top_makefile
, "MSGFMT" );
3662 ln_s
= get_expanded_make_variable( top_makefile
, "LN_S" );
3664 if (root_src_dir
&& !strcmp( root_src_dir
, "." )) root_src_dir
= NULL
;
3665 if (tools_dir
&& !strcmp( tools_dir
, "." )) tools_dir
= NULL
;
3666 if (!exe_ext
) exe_ext
= "";
3667 if (!tools_ext
) tools_ext
= "";
3668 if (!man_ext
) man_ext
= "3w";
3672 disabled_dirs
= get_expanded_make_var_array( top_makefile
, "DISABLED_SUBDIRS" );
3673 top_makefile
->subdirs
= get_expanded_make_var_array( top_makefile
, "SUBDIRS" );
3674 top_makefile
->submakes
= xmalloc( top_makefile
->subdirs
.count
* sizeof(*top_makefile
->submakes
) );
3676 for (i
= 0; i
< top_makefile
->subdirs
.count
; i
++)
3677 top_makefile
->submakes
[i
] = parse_makefile( top_makefile
->subdirs
.str
[i
] );
3679 load_sources( top_makefile
);
3680 for (i
= 0; i
< top_makefile
->subdirs
.count
; i
++)
3681 load_sources( top_makefile
->submakes
[i
] );
3683 for (i
= 0; i
< top_makefile
->subdirs
.count
; i
++)
3684 output_dependencies( top_makefile
->submakes
[i
] );
3686 output_dependencies( top_makefile
);
3690 for (i
= 1; i
< argc
; i
++)
3692 struct makefile
*make
= parse_makefile( argv
[i
] );
3693 load_sources( make
);
3694 output_dependencies( make
);