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_CPP_QUOTE
, /* idl cpp_quote("#include \"foo.h\"") */
44 INCL_CPP_QUOTE_SYSTEM
/* idl cpp_quote("#include <foo.h>") */
49 int line
; /* source line where this header is included */
50 enum incl_type type
; /* type of include */
51 char *name
; /* header name */
57 char *name
; /* full file name relative to cwd */
58 void *args
; /* custom arguments for makefile rule */
59 unsigned int flags
; /* flags (see below) */
60 unsigned int deps_count
; /* files in use */
61 unsigned int deps_size
; /* total allocated size */
62 struct dependency
*deps
; /* all header dependencies */
71 char *sourcename
; /* source file name for generated headers */
72 struct incl_file
*included_by
; /* file that included this one */
73 int included_line
; /* line where this file was included */
74 int system
; /* is it a system include (#include <name>) */
75 struct incl_file
*owner
;
76 unsigned int files_count
; /* files in use */
77 unsigned int files_size
; /* total allocated size */
78 struct incl_file
**files
;
81 #define FLAG_GENERATED 0x000001 /* generated file */
82 #define FLAG_INSTALL 0x000002 /* file to install */
83 #define FLAG_IDL_PROXY 0x000100 /* generates a proxy (_p.c) file */
84 #define FLAG_IDL_CLIENT 0x000200 /* generates a client (_c.c) file */
85 #define FLAG_IDL_SERVER 0x000400 /* generates a server (_s.c) file */
86 #define FLAG_IDL_IDENT 0x000800 /* generates an ident (_i.c) file */
87 #define FLAG_IDL_REGISTER 0x001000 /* generates a registration (_r.res) file */
88 #define FLAG_IDL_TYPELIB 0x002000 /* generates a typelib (.tlb) file */
89 #define FLAG_IDL_REGTYPELIB 0x004000 /* generates a registered typelib (_t.res) file */
90 #define FLAG_IDL_HEADER 0x008000 /* generates a header (.h) file */
91 #define FLAG_RC_PO 0x010000 /* rc file contains translations */
92 #define FLAG_C_IMPLIB 0x020000 /* file is part of an import library */
93 #define FLAG_SFD_FONTS 0x040000 /* sfd file generated bitmap fonts */
101 { FLAG_IDL_TYPELIB
, ".tlb" },
102 { FLAG_IDL_REGTYPELIB
, "_t.res" },
103 { FLAG_IDL_CLIENT
, "_c.c" },
104 { FLAG_IDL_IDENT
, "_i.c" },
105 { FLAG_IDL_PROXY
, "_p.c" },
106 { FLAG_IDL_SERVER
, "_s.c" },
107 { FLAG_IDL_REGISTER
, "_r.res" },
108 { FLAG_IDL_HEADER
, ".h" }
111 #define HASH_SIZE 137
113 static struct list files
[HASH_SIZE
];
117 unsigned int count
; /* strings in use */
118 unsigned int size
; /* total allocated size */
122 static const struct strarray empty_strarray
;
124 /* variables common to all makefiles */
125 static struct strarray linguas
;
126 static struct strarray dll_flags
;
127 static struct strarray target_flags
;
128 static struct strarray msvcrt_flags
;
129 static struct strarray extra_cflags
;
130 static struct strarray cpp_flags
;
131 static struct strarray unwind_flags
;
132 static struct strarray libs
;
133 static struct strarray cmdline_vars
;
134 static const char *root_src_dir
;
135 static const char *tools_dir
;
136 static const char *tools_ext
;
137 static const char *exe_ext
;
138 static const char *dll_ext
;
139 static const char *man_ext
;
140 static const char *dll_prefix
;
141 static const char *crosstarget
;
142 static const char *fontforge
;
143 static const char *convert
;
144 static const char *rsvg
;
145 static const char *icotool
;
149 struct strarray vars
;
150 struct strarray include_args
;
151 struct strarray define_args
;
152 struct strarray programs
;
153 struct strarray scripts
;
154 struct strarray appmode
;
155 struct strarray imports
;
156 struct strarray delayimports
;
157 struct strarray extradllflags
;
158 struct strarray install_lib
;
159 struct strarray install_dev
;
160 struct strarray install_lib_rules
;
161 struct strarray install_dev_rules
;
163 struct list includes
;
164 const char *base_dir
;
167 const char *top_src_dir
;
168 const char *top_obj_dir
;
169 const char *parent_dir
;
172 const char *staticlib
;
173 const char *importlib
;
178 static struct makefile
*top_makefile
;
180 static const char *output_makefile_name
= "Makefile";
181 static const char *input_makefile_name
;
182 static const char *input_file_name
;
183 static const char *output_file_name
;
184 static const char *temp_file_name
;
185 static int relative_dir_mode
;
186 static int input_line
;
187 static int output_column
;
188 static FILE *output_file
;
190 static const char Usage
[] =
191 "Usage: makedep [options] directories\n"
193 " -R from to Compute the relative path between two directories\n"
194 " -fxxx Store output in file 'xxx' (default: Makefile)\n"
195 " -ixxx Read input from file 'xxx' (default: Makefile.in)\n";
199 #define __attribute__(x)
202 static void fatal_error( const char *msg
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
203 static void fatal_perror( const char *msg
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
204 static void output( const char *format
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
205 static char *strmake( const char* fmt
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
207 /*******************************************************************
210 static void fatal_error( const char *msg
, ... )
213 va_start( valist
, msg
);
216 fprintf( stderr
, "%s:", input_file_name
);
217 if (input_line
) fprintf( stderr
, "%d:", input_line
);
218 fprintf( stderr
, " error: " );
220 else fprintf( stderr
, "makedep: error: " );
221 vfprintf( stderr
, msg
, valist
);
227 /*******************************************************************
230 static void fatal_perror( const char *msg
, ... )
233 va_start( valist
, msg
);
236 fprintf( stderr
, "%s:", input_file_name
);
237 if (input_line
) fprintf( stderr
, "%d:", input_line
);
238 fprintf( stderr
, " error: " );
240 else fprintf( stderr
, "makedep: error: " );
241 vfprintf( stderr
, msg
, valist
);
248 /*******************************************************************
251 static void cleanup_files(void)
253 if (temp_file_name
) unlink( temp_file_name
);
254 if (output_file_name
) unlink( output_file_name
);
258 /*******************************************************************
261 static void exit_on_signal( int sig
)
263 exit( 1 ); /* this will call the atexit functions */
267 /*******************************************************************
270 static void *xmalloc( size_t size
)
273 if (!(res
= malloc (size
? size
: 1)))
274 fatal_error( "Virtual memory exhausted.\n" );
279 /*******************************************************************
282 static void *xrealloc (void *ptr
, size_t size
)
286 if (!(res
= realloc( ptr
, size
)))
287 fatal_error( "Virtual memory exhausted.\n" );
291 /*******************************************************************
294 static char *xstrdup( const char *str
)
296 char *res
= strdup( str
);
297 if (!res
) fatal_error( "Virtual memory exhausted.\n" );
302 /*******************************************************************
305 static char *strmake( const char* fmt
, ... )
313 char *p
= xmalloc (size
);
315 n
= vsnprintf (p
, size
, fmt
, ap
);
317 if (n
== -1) size
*= 2;
318 else if ((size_t)n
>= size
) size
= n
+ 1;
325 /*******************************************************************
328 static int strendswith( const char* str
, const char* end
)
333 return l
>= m
&& strcmp(str
+ l
- m
, end
) == 0;
337 /*******************************************************************
340 static void output( const char *format
, ... )
345 va_start( valist
, format
);
346 ret
= vfprintf( output_file
, format
, valist
);
348 if (ret
< 0) fatal_perror( "output" );
349 if (format
[0] && format
[strlen(format
) - 1] == '\n') output_column
= 0;
350 else output_column
+= ret
;
354 /*******************************************************************
357 static void strarray_add( struct strarray
*array
, const char *str
)
359 if (array
->count
== array
->size
)
361 if (array
->size
) array
->size
*= 2;
362 else array
->size
= 16;
363 array
->str
= xrealloc( array
->str
, sizeof(array
->str
[0]) * array
->size
);
365 array
->str
[array
->count
++] = str
;
369 /*******************************************************************
372 static void strarray_addall( struct strarray
*array
, struct strarray added
)
376 for (i
= 0; i
< added
.count
; i
++) strarray_add( array
, added
.str
[i
] );
380 /*******************************************************************
383 static int strarray_exists( struct strarray
*array
, const char *str
)
387 for (i
= 0; i
< array
->count
; i
++) if (!strcmp( array
->str
[i
], str
)) return 1;
392 /*******************************************************************
395 static void strarray_add_uniq( struct strarray
*array
, const char *str
)
397 if (!strarray_exists( array
, str
)) strarray_add( array
, str
);
401 /*******************************************************************
404 * Find a value in a name/value pair string array.
406 static char *strarray_get_value( const struct strarray
*array
, const char *name
)
410 for (i
= 0; i
< array
->count
; i
+= 2)
411 if (!strcmp( array
->str
[i
], name
)) return xstrdup( array
->str
[i
+ 1] );
416 /*******************************************************************
419 * Define a value in a name/value pair string array.
421 static void strarray_set_value( struct strarray
*array
, const char *name
, const char *value
)
425 /* redefining a variable replaces the previous value */
426 for (i
= 0; i
< array
->count
; i
+= 2)
428 if (strcmp( array
->str
[i
], name
)) continue;
429 array
->str
[i
+ 1] = value
;
432 strarray_add( array
, name
);
433 strarray_add( array
, value
);
437 /*******************************************************************
440 static void output_filename( const char *name
)
442 if (output_column
+ strlen(name
) + 1 > 100)
447 else if (output_column
) output( " " );
448 output( "%s", name
);
452 /*******************************************************************
455 static void output_filenames( struct strarray array
)
459 for (i
= 0; i
< array
.count
; i
++) output_filename( array
.str
[i
] );
463 /*******************************************************************
466 static char *get_extension( char *filename
)
468 char *ext
= strrchr( filename
, '.' );
469 if (ext
&& strchr( ext
, '/' )) ext
= NULL
;
474 /*******************************************************************
477 static char *replace_extension( const char *name
, const char *old_ext
, const char *new_ext
)
480 int name_len
= strlen( name
);
481 int ext_len
= strlen( old_ext
);
483 if (name_len
>= ext_len
&& !strcmp( name
+ name_len
- ext_len
, old_ext
)) name_len
-= ext_len
;
484 ret
= xmalloc( name_len
+ strlen( new_ext
) + 1 );
485 memcpy( ret
, name
, name_len
);
486 strcpy( ret
+ name_len
, new_ext
);
491 /*******************************************************************
492 * strarray_replace_extension
494 static struct strarray
strarray_replace_extension( const struct strarray
*array
,
495 const char *old_ext
, const char *new_ext
)
500 ret
.count
= ret
.size
= array
->count
;
501 ret
.str
= xmalloc( sizeof(ret
.str
[0]) * ret
.size
);
502 for (i
= 0; i
< array
->count
; i
++) ret
.str
[i
] = replace_extension( array
->str
[i
], old_ext
, new_ext
);
507 /*******************************************************************
510 static char *replace_substr( const char *str
, const char *start
, unsigned int len
, const char *replace
)
512 unsigned int pos
= start
- str
;
513 char *ret
= xmalloc( pos
+ strlen(replace
) + strlen(start
+ len
) + 1 );
514 memcpy( ret
, str
, pos
);
515 strcpy( ret
+ pos
, replace
);
516 strcat( ret
+ pos
, start
+ len
);
521 /*******************************************************************
524 * Determine where the destination path is located relative to the 'from' path.
526 static char *get_relative_path( const char *from
, const char *dest
)
530 unsigned int dotdots
= 0;
532 /* a path of "." is equivalent to an empty path */
533 if (!strcmp( from
, "." )) from
= "";
537 while (*from
== '/') from
++;
538 while (*dest
== '/') dest
++;
539 start
= dest
; /* save start of next path element */
542 while (*from
&& *from
!= '/' && *from
== *dest
) { from
++; dest
++; }
543 if ((!*from
|| *from
== '/') && (!*dest
|| *dest
== '/')) continue;
545 /* count remaining elements in 'from' */
549 while (*from
&& *from
!= '/') from
++;
550 while (*from
== '/') from
++;
556 if (!start
[0] && !dotdots
) return NULL
; /* empty path */
558 ret
= xmalloc( 3 * dotdots
+ strlen( start
) + 1 );
559 for (p
= ret
; dotdots
; dotdots
--, p
+= 3) memcpy( p
, "../", 3 );
561 if (start
[0]) strcpy( p
, start
);
562 else p
[-1] = 0; /* remove trailing slash */
567 /*******************************************************************
570 static char *concat_paths( const char *base
, const char *path
)
572 if (!base
|| !base
[0]) return xstrdup( path
&& path
[0] ? path
: "." );
573 if (!path
|| !path
[0]) return xstrdup( base
);
574 if (path
[0] == '/') return xstrdup( path
);
575 return strmake( "%s/%s", base
, path
);
579 /*******************************************************************
582 static char *base_dir_path( struct makefile
*make
, const char *path
)
584 return concat_paths( make
->base_dir
, path
);
588 /*******************************************************************
591 static char *obj_dir_path( struct makefile
*make
, const char *path
)
593 return concat_paths( make
->obj_dir
, path
);
597 /*******************************************************************
600 static char *src_dir_path( struct makefile
*make
, const char *path
)
602 if (make
->src_dir
) return concat_paths( make
->src_dir
, path
);
603 return obj_dir_path( make
, path
);
607 /*******************************************************************
610 static char *top_obj_dir_path( struct makefile
*make
, const char *path
)
612 return concat_paths( make
->top_obj_dir
, path
);
616 /*******************************************************************
619 static char *top_dir_path( struct makefile
*make
, const char *path
)
621 if (make
->top_src_dir
) return concat_paths( make
->top_src_dir
, path
);
622 return top_obj_dir_path( make
, path
);
626 /*******************************************************************
629 static char *root_dir_path( const char *path
)
631 return concat_paths( root_src_dir
, path
);
635 /*******************************************************************
638 static char *tools_dir_path( struct makefile
*make
, const char *path
)
640 if (tools_dir
) return top_obj_dir_path( make
, strmake( "%s/tools/%s", tools_dir
, path
));
641 return top_obj_dir_path( make
, strmake( "tools/%s", path
));
645 /*******************************************************************
648 static char *tools_path( struct makefile
*make
, const char *name
)
650 return strmake( "%s/%s%s", tools_dir_path( make
, name
), name
, tools_ext
);
654 /*******************************************************************
657 static char *get_line( FILE *file
)
660 static unsigned int size
;
665 buffer
= xmalloc( size
);
667 if (!fgets( buffer
, size
, file
)) return NULL
;
672 char *p
= buffer
+ strlen(buffer
);
673 /* if line is larger than buffer, resize buffer */
674 while (p
== buffer
+ size
- 1 && p
[-1] != '\n')
676 buffer
= xrealloc( buffer
, size
* 2 );
677 if (!fgets( buffer
+ size
- 1, size
+ 1, file
)) break;
678 p
= buffer
+ strlen(buffer
);
681 if (p
> buffer
&& p
[-1] == '\n')
684 if (p
> buffer
&& p
[-1] == '\r') *(--p
) = 0;
685 if (p
> buffer
&& p
[-1] == '\\')
688 /* line ends in backslash, read continuation line */
689 if (!fgets( p
, size
- (p
- buffer
), file
)) return buffer
;
699 /*******************************************************************
702 static unsigned int hash_filename( const char *name
)
704 unsigned int ret
= 0;
705 while (*name
) ret
= (ret
<< 7) + (ret
<< 3) + *name
++;
706 return ret
% HASH_SIZE
;
710 /*******************************************************************
713 static struct file
*add_file( const char *name
)
715 struct file
*file
= xmalloc( sizeof(*file
) );
716 memset( file
, 0, sizeof(*file
) );
717 file
->name
= xstrdup( name
);
718 list_add_tail( &files
[hash_filename( name
)], &file
->entry
);
723 /*******************************************************************
726 static void add_dependency( struct file
*file
, const char *name
, enum incl_type type
)
728 /* enforce some rules for the Wine tree */
730 if (!memcmp( name
, "../", 3 ))
731 fatal_error( "#include directive with relative path not allowed\n" );
733 if (!strcmp( name
, "config.h" ))
735 if (strendswith( file
->name
, ".h" ))
736 fatal_error( "config.h must not be included by a header file\n" );
737 if (file
->deps_count
)
738 fatal_error( "config.h must be included before anything else\n" );
740 else if (!strcmp( name
, "wine/port.h" ))
742 if (strendswith( file
->name
, ".h" ))
743 fatal_error( "wine/port.h must not be included by a header file\n" );
744 if (!file
->deps_count
) fatal_error( "config.h must be included before wine/port.h\n" );
745 if (file
->deps_count
> 1)
746 fatal_error( "wine/port.h must be included before everything except config.h\n" );
747 if (strcmp( file
->deps
[0].name
, "config.h" ))
748 fatal_error( "config.h must be included before wine/port.h\n" );
751 if (file
->deps_count
>= file
->deps_size
)
753 file
->deps_size
*= 2;
754 if (file
->deps_size
< 16) file
->deps_size
= 16;
755 file
->deps
= xrealloc( file
->deps
, file
->deps_size
* sizeof(*file
->deps
) );
757 file
->deps
[file
->deps_count
].line
= input_line
;
758 file
->deps
[file
->deps_count
].type
= type
;
759 file
->deps
[file
->deps_count
].name
= xstrdup( name
);
764 /*******************************************************************
767 static struct incl_file
*find_src_file( struct makefile
*make
, const char *name
)
769 struct incl_file
*file
;
771 LIST_FOR_EACH_ENTRY( file
, &make
->sources
, struct incl_file
, entry
)
772 if (!strcmp( name
, file
->name
)) return file
;
776 /*******************************************************************
779 static struct incl_file
*find_include_file( struct makefile
*make
, const char *name
)
781 struct incl_file
*file
;
783 LIST_FOR_EACH_ENTRY( file
, &make
->includes
, struct incl_file
, entry
)
784 if (!strcmp( name
, file
->name
)) return file
;
788 /*******************************************************************
791 * Add an include file if it doesn't already exists.
793 static struct incl_file
*add_include( struct makefile
*make
, struct incl_file
*parent
,
794 const char *name
, int line
, int system
)
796 struct incl_file
*include
;
798 if (parent
->files_count
>= parent
->files_size
)
800 parent
->files_size
*= 2;
801 if (parent
->files_size
< 16) parent
->files_size
= 16;
802 parent
->files
= xrealloc( parent
->files
, parent
->files_size
* sizeof(*parent
->files
) );
805 LIST_FOR_EACH_ENTRY( include
, &make
->includes
, struct incl_file
, entry
)
806 if (!strcmp( name
, include
->name
)) goto found
;
808 include
= xmalloc( sizeof(*include
) );
809 memset( include
, 0, sizeof(*include
) );
810 include
->name
= xstrdup(name
);
811 include
->included_by
= parent
;
812 include
->included_line
= line
;
813 include
->system
= system
;
814 list_add_tail( &make
->includes
, &include
->entry
);
816 parent
->files
[parent
->files_count
++] = include
;
821 /*******************************************************************
822 * add_generated_source
824 * Add a generated source file to the list.
826 static struct incl_file
*add_generated_source( struct makefile
*make
,
827 const char *name
, const char *filename
)
829 struct incl_file
*file
;
831 if ((file
= find_src_file( make
, name
))) return file
; /* we already have it */
832 file
= xmalloc( sizeof(*file
) );
833 memset( file
, 0, sizeof(*file
) );
834 file
->file
= add_file( name
);
835 file
->name
= xstrdup( name
);
836 file
->filename
= obj_dir_path( make
, filename
? filename
: name
);
837 file
->file
->flags
= FLAG_GENERATED
;
838 list_add_tail( &make
->sources
, &file
->entry
);
843 /*******************************************************************
844 * parse_include_directive
846 static void parse_include_directive( struct file
*source
, char *str
)
848 char quote
, *include
, *p
= str
;
850 while (*p
&& isspace(*p
)) p
++;
851 if (*p
!= '\"' && *p
!= '<' ) return;
853 if (quote
== '<') quote
= '>';
855 while (*p
&& (*p
!= quote
)) p
++;
856 if (!*p
) fatal_error( "malformed include directive '%s'\n", str
);
858 add_dependency( source
, include
, (quote
== '>') ? INCL_SYSTEM
: INCL_NORMAL
);
862 /*******************************************************************
863 * parse_pragma_directive
865 static void parse_pragma_directive( struct file
*source
, char *str
)
867 char *flag
, *p
= str
;
869 if (!isspace( *p
)) return;
870 while (*p
&& isspace(*p
)) p
++;
871 p
= strtok( p
, " \t" );
872 if (strcmp( p
, "makedep" )) return;
874 while ((flag
= strtok( NULL
, " \t" )))
876 if (!strcmp( flag
, "depend" ))
878 while ((p
= strtok( NULL
, " \t" ))) add_dependency( source
, p
, INCL_NORMAL
);
881 else if (!strcmp( flag
, "install" )) source
->flags
|= FLAG_INSTALL
;
883 if (strendswith( source
->name
, ".idl" ))
885 if (!strcmp( flag
, "header" )) source
->flags
|= FLAG_IDL_HEADER
;
886 else if (!strcmp( flag
, "proxy" )) source
->flags
|= FLAG_IDL_PROXY
;
887 else if (!strcmp( flag
, "client" )) source
->flags
|= FLAG_IDL_CLIENT
;
888 else if (!strcmp( flag
, "server" )) source
->flags
|= FLAG_IDL_SERVER
;
889 else if (!strcmp( flag
, "ident" )) source
->flags
|= FLAG_IDL_IDENT
;
890 else if (!strcmp( flag
, "typelib" )) source
->flags
|= FLAG_IDL_TYPELIB
;
891 else if (!strcmp( flag
, "register" )) source
->flags
|= FLAG_IDL_REGISTER
;
892 else if (!strcmp( flag
, "regtypelib" )) source
->flags
|= FLAG_IDL_REGTYPELIB
;
894 else if (strendswith( source
->name
, ".rc" ))
896 if (!strcmp( flag
, "po" )) source
->flags
|= FLAG_RC_PO
;
898 else if (strendswith( source
->name
, ".sfd" ))
900 if (!strcmp( flag
, "font" ))
902 struct strarray
*array
= source
->args
;
906 source
->args
= array
= xmalloc( sizeof(*array
) );
907 *array
= empty_strarray
;
908 source
->flags
|= FLAG_SFD_FONTS
;
910 strarray_add( array
, xstrdup( strtok( NULL
, "" )));
914 else if (!strcmp( flag
, "implib" )) source
->flags
|= FLAG_C_IMPLIB
;
919 /*******************************************************************
920 * parse_cpp_directive
922 static void parse_cpp_directive( struct file
*source
, char *str
)
924 while (*str
&& isspace(*str
)) str
++;
925 if (*str
++ != '#') return;
926 while (*str
&& isspace(*str
)) str
++;
928 if (!strncmp( str
, "include", 7 ))
929 parse_include_directive( source
, str
+ 7 );
930 else if (!strncmp( str
, "import", 6 ) && strendswith( source
->name
, ".m" ))
931 parse_include_directive( source
, str
+ 6 );
932 else if (!strncmp( str
, "pragma", 6 ))
933 parse_pragma_directive( source
, str
+ 6 );
937 /*******************************************************************
940 static void parse_idl_file( struct file
*source
, FILE *file
)
942 char *buffer
, *include
;
946 while ((buffer
= get_line( file
)))
950 while (*p
&& isspace(*p
)) p
++;
952 if (!strncmp( p
, "import", 6 ))
955 while (*p
&& isspace(*p
)) p
++;
956 if (*p
!= '"') continue;
958 while (*p
&& (*p
!= '"')) p
++;
959 if (!*p
) fatal_error( "malformed import directive\n" );
961 add_dependency( source
, include
, INCL_IMPORT
);
965 /* check for #include inside cpp_quote */
966 if (!strncmp( p
, "cpp_quote", 9 ))
969 while (*p
&& isspace(*p
)) p
++;
970 if (*p
++ != '(') continue;
971 while (*p
&& isspace(*p
)) p
++;
972 if (*p
++ != '"') continue;
973 if (*p
++ != '#') continue;
974 while (*p
&& isspace(*p
)) p
++;
975 if (strncmp( p
, "include", 7 )) continue;
977 while (*p
&& isspace(*p
)) p
++;
978 if (*p
== '\\' && p
[1] == '"')
985 if (*p
++ != '<' ) continue;
989 while (*p
&& (*p
!= quote
)) p
++;
990 if (!*p
|| (quote
== '"' && p
[-1] != '\\'))
991 fatal_error( "malformed #include directive inside cpp_quote\n" );
992 if (quote
== '"') p
--; /* remove backslash */
994 add_dependency( source
, include
, (quote
== '>') ? INCL_CPP_QUOTE_SYSTEM
: INCL_CPP_QUOTE
);
998 parse_cpp_directive( source
, p
);
1002 /*******************************************************************
1005 static void parse_c_file( struct file
*source
, FILE *file
)
1010 while ((buffer
= get_line( file
)))
1012 parse_cpp_directive( source
, buffer
);
1017 /*******************************************************************
1020 static void parse_rc_file( struct file
*source
, FILE *file
)
1022 char *buffer
, *include
;
1025 while ((buffer
= get_line( file
)))
1029 while (*p
&& isspace(*p
)) p
++;
1031 if (p
[0] == '/' && p
[1] == '*') /* check for magic makedep comment */
1034 while (*p
&& isspace(*p
)) p
++;
1035 if (strncmp( p
, "@makedep:", 9 )) continue;
1037 while (*p
&& isspace(*p
)) p
++;
1042 while (*p
&& *p
!= quote
) p
++;
1047 while (*p
&& !isspace(*p
) && *p
!= '*') p
++;
1050 fatal_error( "malformed makedep comment\n" );
1052 add_dependency( source
, include
, (quote
== '>') ? INCL_SYSTEM
: INCL_NORMAL
);
1056 parse_cpp_directive( source
, buffer
);
1061 /*******************************************************************
1064 static void parse_in_file( struct file
*source
, FILE *file
)
1068 /* make sure it gets rebuilt when the version changes */
1069 add_dependency( source
, "config.h", INCL_SYSTEM
);
1071 if (!strendswith( source
->name
, ".man.in" )) return; /* not a man page */
1074 while ((buffer
= get_line( file
)))
1076 if (strncmp( buffer
, ".TH", 3 )) continue;
1077 if (!(p
= strtok( buffer
, " \t" ))) continue; /* .TH */
1078 if (!(p
= strtok( NULL
, " \t" ))) continue; /* program name */
1079 if (!(p
= strtok( NULL
, " \t" ))) continue; /* man section */
1080 source
->args
= xstrdup( p
);
1086 /*******************************************************************
1089 static void parse_sfd_file( struct file
*source
, FILE *file
)
1091 char *p
, *eol
, *buffer
;
1094 while ((buffer
= get_line( file
)))
1096 if (strncmp( buffer
, "UComments:", 10 )) continue;
1098 while (*p
== ' ') p
++;
1099 if (p
[0] == '"' && p
[1] && buffer
[strlen(buffer
) - 1] == '"')
1102 buffer
[strlen(buffer
) - 1] = 0;
1104 while ((eol
= strstr( p
, "+AAoA" )))
1107 while (*p
&& isspace(*p
)) p
++;
1110 while (*p
&& isspace(*p
)) p
++;
1111 if (!strncmp( p
, "pragma", 6 )) parse_pragma_directive( source
, p
+ 6 );
1115 while (*p
&& isspace(*p
)) p
++;
1116 if (*p
++ != '#') return;
1117 while (*p
&& isspace(*p
)) p
++;
1118 if (!strncmp( p
, "pragma", 6 )) parse_pragma_directive( source
, p
+ 6 );
1127 void (*parse
)( struct file
*file
, FILE *f
);
1128 } parse_functions
[] =
1130 { ".c", parse_c_file
},
1131 { ".h", parse_c_file
},
1132 { ".inl", parse_c_file
},
1133 { ".l", parse_c_file
},
1134 { ".m", parse_c_file
},
1135 { ".rh", parse_c_file
},
1136 { ".x", parse_c_file
},
1137 { ".y", parse_c_file
},
1138 { ".idl", parse_idl_file
},
1139 { ".rc", parse_rc_file
},
1140 { ".in", parse_in_file
},
1141 { ".sfd", parse_sfd_file
}
1144 /*******************************************************************
1147 static struct file
*load_file( const char *name
)
1151 unsigned int i
, hash
= hash_filename( name
);
1153 LIST_FOR_EACH_ENTRY( file
, &files
[hash
], struct file
, entry
)
1154 if (!strcmp( name
, file
->name
)) return file
;
1156 if (!(f
= fopen( name
, "r" ))) return NULL
;
1158 file
= add_file( name
);
1159 input_file_name
= file
->name
;
1162 for (i
= 0; i
< sizeof(parse_functions
) / sizeof(parse_functions
[0]); i
++)
1164 if (!strendswith( name
, parse_functions
[i
].ext
)) continue;
1165 parse_functions
[i
].parse( file
, f
);
1170 input_file_name
= NULL
;
1176 /*******************************************************************
1179 static struct file
*open_file( struct makefile
*make
, const char *path
, char **filename
)
1181 struct file
*ret
= load_file( base_dir_path( make
, path
));
1183 if (ret
) *filename
= xstrdup( path
);
1188 /*******************************************************************
1191 * Open a file in the source directory of the makefile.
1193 static struct file
*open_local_file( struct makefile
*make
, const char *path
, char **filename
)
1195 char *src_path
= root_dir_path( base_dir_path( make
, path
));
1196 struct file
*ret
= load_file( src_path
);
1198 /* if not found, try parent dir */
1199 if (!ret
&& make
->parent_dir
)
1202 path
= strmake( "%s/%s", make
->parent_dir
, path
);
1203 src_path
= root_dir_path( base_dir_path( make
, path
));
1204 ret
= load_file( src_path
);
1207 if (ret
) *filename
= src_dir_path( make
, path
);
1213 /*******************************************************************
1216 * Open a file in the top-level source directory.
1218 static struct file
*open_global_file( struct makefile
*make
, const char *path
, char **filename
)
1220 char *src_path
= root_dir_path( path
);
1221 struct file
*ret
= load_file( src_path
);
1223 if (ret
) *filename
= top_dir_path( make
, path
);
1229 /*******************************************************************
1230 * open_global_header
1232 * Open a file in the global include source directory.
1234 static struct file
*open_global_header( struct makefile
*make
, const char *path
, char **filename
)
1236 return open_global_file( make
, strmake( "include/%s", path
), filename
);
1240 /*******************************************************************
1243 static struct file
*open_src_file( struct makefile
*make
, struct incl_file
*pFile
)
1245 struct file
*file
= open_local_file( make
, pFile
->name
, &pFile
->filename
);
1247 if (!file
) fatal_perror( "open %s", pFile
->name
);
1252 /*******************************************************************
1255 static struct file
*open_include_file( struct makefile
*make
, struct incl_file
*pFile
)
1257 struct file
*file
= NULL
;
1259 unsigned int i
, len
;
1263 /* check for generated bison header */
1265 if (strendswith( pFile
->name
, ".tab.h" ) &&
1266 (file
= open_local_file( make
, replace_extension( pFile
->name
, ".tab.h", ".y" ), &filename
)))
1268 pFile
->sourcename
= filename
;
1269 pFile
->filename
= obj_dir_path( make
, pFile
->name
);
1273 /* check for corresponding idl file in source dir */
1275 if (strendswith( pFile
->name
, ".h" ) &&
1276 (file
= open_local_file( make
, replace_extension( pFile
->name
, ".h", ".idl" ), &filename
)))
1278 pFile
->sourcename
= filename
;
1279 pFile
->filename
= obj_dir_path( make
, pFile
->name
);
1283 /* now try in source dir */
1284 if ((file
= open_local_file( make
, pFile
->name
, &pFile
->filename
))) return file
;
1286 /* check for corresponding idl file in global includes */
1288 if (strendswith( pFile
->name
, ".h" ) &&
1289 (file
= open_global_header( make
, replace_extension( pFile
->name
, ".h", ".idl" ), &filename
)))
1291 pFile
->sourcename
= filename
;
1292 pFile
->filename
= top_obj_dir_path( make
, strmake( "include/%s", pFile
->name
));
1296 /* check for corresponding .in file in global includes (for config.h.in) */
1298 if (strendswith( pFile
->name
, ".h" ) &&
1299 (file
= open_global_header( make
, replace_extension( pFile
->name
, ".h", ".h.in" ), &filename
)))
1301 pFile
->sourcename
= filename
;
1302 pFile
->filename
= top_obj_dir_path( make
, strmake( "include/%s", pFile
->name
));
1306 /* check for corresponding .x file in global includes */
1308 if (strendswith( pFile
->name
, "tmpl.h" ) &&
1309 (file
= open_global_header( make
, replace_extension( pFile
->name
, ".h", ".x" ), &filename
)))
1311 pFile
->sourcename
= filename
;
1312 pFile
->filename
= top_obj_dir_path( make
, strmake( "include/%s", pFile
->name
));
1316 /* check in global includes source dir */
1318 if ((file
= open_global_header( make
, pFile
->name
, &pFile
->filename
))) return file
;
1320 /* check in global msvcrt includes */
1321 if (make
->use_msvcrt
&&
1322 (file
= open_global_header( make
, strmake( "msvcrt/%s", pFile
->name
), &pFile
->filename
)))
1325 /* now search in include paths */
1326 for (i
= 0; i
< make
->include_args
.count
; i
++)
1328 const char *dir
= make
->include_args
.str
[i
] + 2; /* skip -I */
1329 const char *prefix
= make
->top_src_dir
? make
->top_src_dir
: make
->top_obj_dir
;
1333 len
= strlen( prefix
);
1334 if (!strncmp( dir
, prefix
, len
) && (!dir
[len
] || dir
[len
] == '/'))
1336 while (dir
[len
] == '/') len
++;
1337 file
= open_global_file( make
, concat_paths( dir
+ len
, pFile
->name
), &pFile
->filename
);
1338 if (file
) return file
;
1340 if (make
->top_src_dir
) continue; /* ignore paths that don't point to the top source dir */
1344 if ((file
= open_file( make
, concat_paths( dir
, pFile
->name
), &pFile
->filename
)))
1348 if (pFile
->system
) return NULL
; /* ignore system files we cannot find */
1350 /* try in src file directory */
1351 if ((p
= strrchr(pFile
->included_by
->filename
, '/')))
1353 int l
= p
- pFile
->included_by
->filename
+ 1;
1354 filename
= xmalloc(l
+ strlen(pFile
->name
) + 1);
1355 memcpy( filename
, pFile
->included_by
->filename
, l
);
1356 strcpy( filename
+ l
, pFile
->name
);
1357 if ((file
= open_file( make
, filename
, &pFile
->filename
))) return file
;
1361 fprintf( stderr
, "%s:%d: error: ", pFile
->included_by
->file
->name
, pFile
->included_line
);
1362 perror( pFile
->name
);
1363 pFile
= pFile
->included_by
;
1364 while (pFile
&& pFile
->included_by
)
1366 const char *parent
= pFile
->included_by
->sourcename
;
1367 if (!parent
) parent
= pFile
->included_by
->file
->name
;
1368 fprintf( stderr
, "%s:%d: note: %s was first included here\n",
1369 parent
, pFile
->included_line
, pFile
->name
);
1370 pFile
= pFile
->included_by
;
1376 /*******************************************************************
1379 static void add_all_includes( struct makefile
*make
, struct incl_file
*parent
, struct file
*file
)
1383 parent
->files_count
= 0;
1384 parent
->files_size
= file
->deps_count
;
1385 parent
->files
= xmalloc( parent
->files_size
* sizeof(*parent
->files
) );
1386 for (i
= 0; i
< file
->deps_count
; i
++)
1388 switch (file
->deps
[i
].type
)
1392 add_include( make
, parent
, file
->deps
[i
].name
, file
->deps
[i
].line
, 0 );
1395 add_include( make
, parent
, file
->deps
[i
].name
, file
->deps
[i
].line
, 1 );
1397 case INCL_CPP_QUOTE
:
1398 case INCL_CPP_QUOTE_SYSTEM
:
1405 /*******************************************************************
1408 static void parse_file( struct makefile
*make
, struct incl_file
*source
, int src
)
1412 /* don't try to open certain types of files */
1413 if (strendswith( source
->name
, ".tlb" ))
1415 source
->filename
= obj_dir_path( make
, source
->name
);
1419 file
= src
? open_src_file( make
, source
) : open_include_file( make
, source
);
1422 source
->file
= file
;
1423 source
->files_count
= 0;
1424 source
->files_size
= file
->deps_count
;
1425 source
->files
= xmalloc( source
->files_size
* sizeof(*source
->files
) );
1427 if (source
->sourcename
)
1429 if (strendswith( source
->sourcename
, ".idl" ))
1433 /* generated .h file always includes these */
1434 add_include( make
, source
, "rpc.h", 0, 1 );
1435 add_include( make
, source
, "rpcndr.h", 0, 1 );
1436 for (i
= 0; i
< file
->deps_count
; i
++)
1438 switch (file
->deps
[i
].type
)
1441 if (strendswith( file
->deps
[i
].name
, ".idl" ))
1442 add_include( make
, source
, replace_extension( file
->deps
[i
].name
, ".idl", ".h" ),
1443 file
->deps
[i
].line
, 0 );
1445 add_include( make
, source
, file
->deps
[i
].name
, file
->deps
[i
].line
, 0 );
1447 case INCL_CPP_QUOTE
:
1448 add_include( make
, source
, file
->deps
[i
].name
, file
->deps
[i
].line
, 0 );
1450 case INCL_CPP_QUOTE_SYSTEM
:
1451 add_include( make
, source
, file
->deps
[i
].name
, file
->deps
[i
].line
, 1 );
1460 if (strendswith( source
->sourcename
, ".y" ))
1461 return; /* generated .tab.h doesn't include anything */
1464 add_all_includes( make
, source
, file
);
1468 /*******************************************************************
1471 * Add a source file to the list.
1473 static struct incl_file
*add_src_file( struct makefile
*make
, const char *name
)
1475 struct incl_file
*file
;
1477 if ((file
= find_src_file( make
, name
))) return file
; /* we already have it */
1478 file
= xmalloc( sizeof(*file
) );
1479 memset( file
, 0, sizeof(*file
) );
1480 file
->name
= xstrdup(name
);
1481 list_add_tail( &make
->sources
, &file
->entry
);
1482 parse_file( make
, file
, 1 );
1487 /*******************************************************************
1488 * open_input_makefile
1490 static FILE *open_input_makefile( struct makefile
*make
)
1495 input_file_name
= base_dir_path( make
, input_makefile_name
);
1497 input_file_name
= output_makefile_name
; /* always use output name for main Makefile */
1500 if (!(ret
= fopen( input_file_name
, "r" )))
1502 input_file_name
= root_dir_path( input_file_name
);
1503 if (!(ret
= fopen( input_file_name
, "r" ))) fatal_perror( "open" );
1509 /*******************************************************************
1512 static char *get_make_variable( struct makefile
*make
, const char *name
)
1516 if ((ret
= strarray_get_value( &cmdline_vars
, name
))) return ret
;
1517 if ((ret
= strarray_get_value( &make
->vars
, name
))) return ret
;
1518 if (top_makefile
&& (ret
= strarray_get_value( &top_makefile
->vars
, name
))) return ret
;
1523 /*******************************************************************
1524 * get_expanded_make_variable
1526 static char *get_expanded_make_variable( struct makefile
*make
, const char *name
)
1528 char *p
, *end
, *var
, *expand
, *tmp
;
1530 expand
= get_make_variable( make
, name
);
1531 if (!expand
) return NULL
;
1534 while ((p
= strchr( p
, '$' )))
1538 if (!(end
= strchr( p
+ 2, ')' ))) fatal_error( "syntax error in '%s'\n", expand
);
1540 if (strchr( p
+ 2, ':' )) fatal_error( "pattern replacement not supported for '%s'\n", p
+ 2 );
1541 var
= get_make_variable( make
, p
+ 2 );
1542 tmp
= replace_substr( expand
, p
, end
- p
, var
? var
: "" );
1544 /* switch to the new string */
1545 p
= tmp
+ (p
- expand
);
1549 else if (p
[1] == '{') /* don't expand ${} variables */
1551 if (!(end
= strchr( p
+ 2, '}' ))) fatal_error( "syntax error in '%s'\n", expand
);
1554 else if (p
[1] == '$')
1558 else fatal_error( "syntax error in '%s'\n", expand
);
1561 /* consider empty variables undefined */
1563 while (*p
&& isspace(*p
)) p
++;
1564 if (*p
) return expand
;
1570 /*******************************************************************
1571 * get_expanded_make_var_array
1573 static struct strarray
get_expanded_make_var_array( struct makefile
*make
, const char *name
)
1575 struct strarray ret
= empty_strarray
;
1576 char *value
, *token
;
1578 if ((value
= get_expanded_make_variable( make
, name
)))
1579 for (token
= strtok( value
, " \t" ); token
; token
= strtok( NULL
, " \t" ))
1580 strarray_add( &ret
, token
);
1585 /*******************************************************************
1588 static char *file_local_var( const char *file
, const char *name
)
1592 var
= strmake( "%s_%s", file
, name
);
1593 for (p
= var
; *p
; p
++) if (!isalnum( *p
)) *p
= '_';
1598 /*******************************************************************
1601 static int set_make_variable( struct strarray
*array
, const char *assignment
)
1605 p
= name
= xstrdup( assignment
);
1606 while (isalnum(*p
) || *p
== '_') p
++;
1607 if (name
== p
) return 0; /* not a variable */
1611 while (isspace(*p
)) p
++;
1613 if (*p
!= '=') return 0; /* not an assignment */
1615 while (isspace(*p
)) p
++;
1617 strarray_set_value( array
, name
, p
);
1622 /*******************************************************************
1625 static struct makefile
*parse_makefile( const char *path
, const char *separator
)
1629 struct makefile
*make
= xmalloc( sizeof(*make
) );
1631 memset( make
, 0, sizeof(*make
) );
1634 make
->top_obj_dir
= get_relative_path( path
, "" );
1635 make
->base_dir
= path
;
1636 if (!strcmp( make
->base_dir
, "." )) make
->base_dir
= NULL
;
1639 file
= open_input_makefile( make
);
1640 while ((buffer
= get_line( file
)))
1642 if (separator
&& !strncmp( buffer
, separator
, strlen(separator
) )) break;
1643 if (*buffer
== '\t') continue; /* command */
1644 while (isspace( *buffer
)) buffer
++;
1645 if (*buffer
== '#') continue; /* comment */
1646 set_make_variable( &make
->vars
, buffer
);
1649 input_file_name
= NULL
;
1654 /*******************************************************************
1655 * add_generated_sources
1657 static void add_generated_sources( struct makefile
*make
)
1659 struct incl_file
*source
, *next
, *file
;
1661 LIST_FOR_EACH_ENTRY_SAFE( source
, next
, &make
->sources
, struct incl_file
, entry
)
1663 if (source
->file
->flags
& FLAG_IDL_CLIENT
)
1665 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_c.c" ), NULL
);
1666 add_dependency( file
->file
, replace_extension( source
->name
, ".idl", ".h" ), INCL_NORMAL
);
1667 add_all_includes( make
, file
, file
->file
);
1669 if (source
->file
->flags
& FLAG_IDL_SERVER
)
1671 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_s.c" ), NULL
);
1672 add_dependency( file
->file
, "wine/exception.h", INCL_NORMAL
);
1673 add_dependency( file
->file
, replace_extension( source
->name
, ".idl", ".h" ), INCL_NORMAL
);
1674 add_all_includes( make
, file
, file
->file
);
1676 if (source
->file
->flags
& FLAG_IDL_IDENT
)
1678 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_i.c" ), NULL
);
1679 add_dependency( file
->file
, "rpc.h", INCL_NORMAL
);
1680 add_dependency( file
->file
, "rpcndr.h", INCL_NORMAL
);
1681 add_dependency( file
->file
, "guiddef.h", INCL_NORMAL
);
1682 add_all_includes( make
, file
, file
->file
);
1684 if (source
->file
->flags
& FLAG_IDL_PROXY
)
1686 file
= add_generated_source( make
, "dlldata.o", "dlldata.c" );
1687 add_dependency( file
->file
, "objbase.h", INCL_NORMAL
);
1688 add_dependency( file
->file
, "rpcproxy.h", INCL_NORMAL
);
1689 add_all_includes( make
, file
, file
->file
);
1690 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_p.c" ), NULL
);
1691 add_dependency( file
->file
, "objbase.h", INCL_NORMAL
);
1692 add_dependency( file
->file
, "rpcproxy.h", INCL_NORMAL
);
1693 add_dependency( file
->file
, "wine/exception.h", INCL_NORMAL
);
1694 add_dependency( file
->file
, replace_extension( source
->name
, ".idl", ".h" ), INCL_NORMAL
);
1695 add_all_includes( make
, file
, file
->file
);
1697 if (source
->file
->flags
& FLAG_IDL_REGTYPELIB
)
1699 add_generated_source( make
, replace_extension( source
->name
, ".idl", "_t.res" ), NULL
);
1701 if (source
->file
->flags
& FLAG_IDL_REGISTER
)
1703 add_generated_source( make
, replace_extension( source
->name
, ".idl", "_r.res" ), NULL
);
1705 if (!source
->file
->flags
&& strendswith( source
->name
, ".idl" ))
1707 add_generated_source( make
, replace_extension( source
->name
, ".idl", ".h" ), NULL
);
1709 if (strendswith( source
->name
, ".x" ))
1711 add_generated_source( make
, replace_extension( source
->name
, ".x", ".h" ), NULL
);
1713 if (strendswith( source
->name
, ".y" ))
1715 file
= add_generated_source( make
, replace_extension( source
->name
, ".y", ".tab.c" ), NULL
);
1716 /* steal the includes list from the source file */
1717 file
->files_count
= source
->files_count
;
1718 file
->files_size
= source
->files_size
;
1719 file
->files
= source
->files
;
1720 source
->files_count
= source
->files_size
= 0;
1721 source
->files
= NULL
;
1723 if (strendswith( source
->name
, ".l" ))
1725 file
= add_generated_source( make
, replace_extension( source
->name
, ".l", ".yy.c" ), NULL
);
1726 /* steal the includes list from the source file */
1727 file
->files_count
= source
->files_count
;
1728 file
->files_size
= source
->files_size
;
1729 file
->files
= source
->files
;
1730 source
->files_count
= source
->files_size
= 0;
1731 source
->files
= NULL
;
1734 if (get_make_variable( make
, "TESTDLL" ))
1736 file
= add_generated_source( make
, "testlist.o", "testlist.c" );
1737 add_dependency( file
->file
, "wine/test.h", INCL_NORMAL
);
1738 add_all_includes( make
, file
, file
->file
);
1743 /*******************************************************************
1746 static void create_dir( const char *dir
)
1750 p
= path
= xstrdup( dir
);
1751 while ((p
= strchr( p
, '/' )))
1754 if (mkdir( path
, 0755 ) == -1 && errno
!= EEXIST
) fatal_perror( "mkdir %s", path
);
1756 while (*p
== '/') p
++;
1758 if (mkdir( path
, 0755 ) == -1 && errno
!= EEXIST
) fatal_perror( "mkdir %s", path
);
1763 /*******************************************************************
1764 * output_filenames_obj_dir
1766 static void output_filenames_obj_dir( struct makefile
*make
, struct strarray array
)
1770 for (i
= 0; i
< array
.count
; i
++) output_filename( obj_dir_path( make
, array
.str
[i
] ));
1774 /*******************************************************************
1777 static void output_include( struct incl_file
*pFile
, struct incl_file
*owner
)
1781 if (pFile
->owner
== owner
) return;
1782 if (!pFile
->filename
) return;
1783 pFile
->owner
= owner
;
1784 output_filename( pFile
->filename
);
1785 for (i
= 0; i
< pFile
->files_count
; i
++) output_include( pFile
->files
[i
], owner
);
1789 /*******************************************************************
1792 static void add_install_rule( struct makefile
*make
, const char *target
,
1793 const char *file
, const char *dest
)
1795 if (strarray_exists( &make
->install_lib
, target
))
1797 strarray_add( &make
->install_lib_rules
, file
);
1798 strarray_add( &make
->install_lib_rules
, dest
);
1800 else if (strarray_exists( &make
->install_dev
, target
))
1802 strarray_add( &make
->install_dev_rules
, file
);
1803 strarray_add( &make
->install_dev_rules
, dest
);
1808 /*******************************************************************
1809 * get_include_install_path
1811 * Determine the installation path for a given include file.
1813 static const char *get_include_install_path( const char *name
)
1815 if (!strncmp( name
, "wine/", 5 )) return name
+ 5;
1816 if (!strncmp( name
, "msvcrt/", 7 )) return name
;
1817 return strmake( "windows/%s", name
);
1821 /*******************************************************************
1822 * output_install_rules
1824 * Rules are stored as a (file,dest) pair of values.
1825 * The first char of dest indicates the type of install.
1827 static void output_install_rules( struct makefile
*make
, struct strarray files
,
1828 const char *target
, struct strarray
*phony_targets
)
1832 struct strarray targets
= empty_strarray
;
1834 if (!files
.count
) return;
1836 for (i
= 0; i
< files
.count
; i
+= 2)
1837 if (strchr( "dps", files
.str
[i
+ 1][0] )) /* only for files copied from object dir */
1838 strarray_add_uniq( &targets
, files
.str
[i
] );
1840 output( "install %s::", target
);
1841 output_filenames_obj_dir( make
, targets
);
1844 install_sh
= top_dir_path( make
, "tools/install-sh" );
1845 for (i
= 0; i
< files
.count
; i
+= 2)
1847 const char *file
= files
.str
[i
];
1848 const char *dest
= files
.str
[i
+ 1];
1852 case 'd': /* data file */
1853 output( "\t%s -m 644 $(INSTALL_DATA_FLAGS) %s $(DESTDIR)%s\n",
1854 install_sh
, obj_dir_path( make
, file
), dest
+ 1 );
1856 case 'D': /* data file in source dir */
1857 output( "\t%s -m 644 $(INSTALL_DATA_FLAGS) %s $(DESTDIR)%s\n",
1858 install_sh
, src_dir_path( make
, file
), dest
+ 1 );
1860 case 'p': /* program file */
1861 output( "\tSTRIPPROG=\"$(STRIP)\" %s $(INSTALL_PROGRAM_FLAGS) %s $(DESTDIR)%s\n",
1862 install_sh
, obj_dir_path( make
, file
), dest
+ 1 );
1864 case 's': /* script */
1865 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s $(DESTDIR)%s\n",
1866 install_sh
, obj_dir_path( make
, file
), dest
+ 1 );
1868 case 'S': /* script in source dir */
1869 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s $(DESTDIR)%s\n",
1870 install_sh
, src_dir_path( make
, file
), dest
+ 1 );
1872 case 'y': /* symlink */
1873 output( "\t$(RM) $(DESTDIR)%s && $(LN_S) %s $(DESTDIR)%s\n", dest
+ 1, file
, dest
+ 1 );
1880 output( "uninstall::\n" );
1881 output( "\t$(RM)" );
1882 for (i
= 0; i
< files
.count
; i
+= 2) output_filename( strmake( "$(DESTDIR)%s", files
.str
[i
+ 1] + 1 ));
1885 strarray_add( phony_targets
, "install" );
1886 strarray_add( phony_targets
, target
);
1887 strarray_add( phony_targets
, "uninstall" );
1891 /*******************************************************************
1894 static struct strarray
output_sources( struct makefile
*make
, struct strarray
*testlist_files
)
1896 struct incl_file
*source
;
1898 struct strarray object_files
= empty_strarray
;
1899 struct strarray crossobj_files
= empty_strarray
;
1900 struct strarray res_files
= empty_strarray
;
1901 struct strarray clean_files
= empty_strarray
;
1902 struct strarray po_files
= empty_strarray
;
1903 struct strarray mo_files
= empty_strarray
;
1904 struct strarray mc_files
= empty_strarray
;
1905 struct strarray ok_files
= empty_strarray
;
1906 struct strarray dlldata_files
= empty_strarray
;
1907 struct strarray c2man_files
= empty_strarray
;
1908 struct strarray implib_objs
= empty_strarray
;
1909 struct strarray includes
= empty_strarray
;
1910 struct strarray subdirs
= empty_strarray
;
1911 struct strarray phony_targets
= empty_strarray
;
1912 struct strarray all_targets
= empty_strarray
;
1913 char *ldrpath_local
= get_expanded_make_variable( make
, "LDRPATH_LOCAL" );
1914 char *ldrpath_install
= get_expanded_make_variable( make
, "LDRPATH_INSTALL" );
1916 for (i
= 0; i
< linguas
.count
; i
++)
1917 strarray_add( &mo_files
, strmake( "%s/%s.mo", top_obj_dir_path( make
, "po" ), linguas
.str
[i
] ));
1919 strarray_add( &phony_targets
, "all" );
1920 strarray_add( &includes
, strmake( "-I%s", obj_dir_path( make
, "" )));
1921 if (make
->src_dir
) strarray_add( &includes
, strmake( "-I%s", make
->src_dir
));
1922 if (make
->parent_dir
) strarray_add( &includes
, strmake( "-I%s", src_dir_path( make
, make
->parent_dir
)));
1923 if (make
->top_obj_dir
) strarray_add( &includes
, strmake( "-I%s", top_obj_dir_path( make
, "include" )));
1924 if (make
->top_src_dir
) strarray_add( &includes
, strmake( "-I%s", top_dir_path( make
, "include" )));
1925 if (make
->use_msvcrt
) strarray_add( &includes
, strmake( "-I%s", top_dir_path( make
, "include/msvcrt" )));
1926 strarray_addall( &includes
, make
->include_args
);
1928 LIST_FOR_EACH_ENTRY( source
, &make
->sources
, struct incl_file
, entry
)
1930 struct strarray extradefs
;
1931 char *obj
= xstrdup( source
->name
);
1932 char *ext
= get_extension( obj
);
1934 if (!ext
) fatal_error( "unsupported file type %s\n", source
->name
);
1937 if (make
->src_dir
&& strchr( obj
, '/' ))
1939 char *subdir
= base_dir_path( make
, obj
);
1940 *strrchr( subdir
, '/' ) = 0;
1941 strarray_add_uniq( &subdirs
, subdir
);
1944 extradefs
= get_expanded_make_var_array( make
, file_local_var( obj
, "EXTRADEFS" ));
1946 if (!strcmp( ext
, "y" )) /* yacc file */
1948 /* add source file dependency for parallel makes */
1949 char *header
= strmake( "%s.tab.h", obj
);
1951 if (find_include_file( make
, header
))
1953 output( "%s: %s\n", obj_dir_path( make
, header
), source
->filename
);
1954 output( "\t$(BISON) -p %s_ -o %s.tab.c -d %s\n",
1955 obj
, obj_dir_path( make
, obj
), source
->filename
);
1956 output( "%s.tab.c: %s %s\n", obj_dir_path( make
, obj
),
1957 source
->filename
, obj_dir_path( make
, header
));
1958 strarray_add( &clean_files
, header
);
1960 else output( "%s.tab.c: %s\n", obj
, source
->filename
);
1962 output( "\t$(BISON) -p %s_ -o $@ %s\n", obj
, source
->filename
);
1963 continue; /* no dependencies */
1965 else if (!strcmp( ext
, "x" )) /* template file */
1967 output( "%s.h: %s%s %s\n", obj_dir_path( make
, obj
),
1968 tools_dir_path( make
, "make_xftmpl" ), tools_ext
, source
->filename
);
1969 output( "\t%s%s -H -o $@ %s\n",
1970 tools_dir_path( make
, "make_xftmpl" ), tools_ext
, source
->filename
);
1971 if (source
->file
->flags
& FLAG_INSTALL
)
1973 strarray_add( &make
->install_dev_rules
, source
->name
);
1974 strarray_add( &make
->install_dev_rules
,
1975 strmake( "D$(includedir)/%s", get_include_install_path( source
->name
) ));
1976 strarray_add( &make
->install_dev_rules
, strmake( "%s.h", obj
));
1977 strarray_add( &make
->install_dev_rules
,
1978 strmake( "d$(includedir)/%s.h", get_include_install_path( obj
) ));
1980 continue; /* no dependencies */
1982 else if (!strcmp( ext
, "l" )) /* lex file */
1984 output( "%s.yy.c: %s\n", obj_dir_path( make
, obj
), source
->filename
);
1985 output( "\t$(FLEX) -o$@ %s\n", source
->filename
);
1986 continue; /* no dependencies */
1988 else if (!strcmp( ext
, "rc" )) /* resource file */
1990 strarray_add( &res_files
, strmake( "%s.res", obj
));
1991 output( "%s.res: %s %s\n", obj_dir_path( make
, obj
),
1992 tools_path( make
, "wrc" ), source
->filename
);
1993 output( "\t%s -o $@", tools_path( make
, "wrc" ) );
1994 if (make
->is_win16
) output_filename( "-m16" );
1995 else output_filenames( target_flags
);
1996 output_filename( "--nostdinc" );
1997 output_filenames( includes
);
1998 output_filenames( make
->define_args
);
1999 output_filenames( extradefs
);
2000 if (mo_files
.count
&& (source
->file
->flags
& FLAG_RC_PO
))
2002 strarray_add( &po_files
, source
->filename
);
2003 output_filename( strmake( "--po-dir=%s", top_obj_dir_path( make
, "po" )));
2004 output_filename( source
->filename
);
2006 output( "%s.res:", obj_dir_path( make
, obj
));
2007 output_filenames( mo_files
);
2009 output( "%s ", obj_dir_path( make
, "rsrc.pot" ));
2013 output_filename( source
->filename
);
2016 output( "%s.res:", obj_dir_path( make
, obj
));
2018 else if (!strcmp( ext
, "mc" )) /* message file */
2020 strarray_add( &res_files
, strmake( "%s.res", obj
));
2021 output( "%s.res: %s %s\n", obj_dir_path( make
, obj
),
2022 tools_path( make
, "wmc" ), source
->filename
);
2023 output( "\t%s -U -O res -o $@ %s", tools_path( make
, "wmc" ), source
->filename
);
2026 strarray_add( &mc_files
, source
->filename
);
2027 output_filename( strmake( "--po-dir=%s", top_obj_dir_path( make
, "po" )));
2029 output( "%s.res:", obj_dir_path( make
, obj
));
2030 output_filenames( mo_files
);
2032 output( "%s ", obj_dir_path( make
, "msg.pot" ));
2034 else output( "\n" );
2035 output( "%s.res:", obj_dir_path( make
, obj
));
2037 else if (!strcmp( ext
, "idl" )) /* IDL file */
2039 struct strarray targets
= empty_strarray
;
2042 if (!source
->file
->flags
) source
->file
->flags
|= FLAG_IDL_HEADER
| FLAG_INSTALL
;
2043 if (find_include_file( make
, strmake( "%s.h", obj
))) source
->file
->flags
|= FLAG_IDL_HEADER
;
2045 for (i
= 0; i
< sizeof(idl_outputs
) / sizeof(idl_outputs
[0]); i
++)
2047 if (!(source
->file
->flags
& idl_outputs
[i
].flag
)) continue;
2048 dest
= strmake( "%s%s", obj
, idl_outputs
[i
].ext
);
2049 if (!find_src_file( make
, dest
)) strarray_add( &clean_files
, dest
);
2050 strarray_add( &targets
, dest
);
2052 if (source
->file
->flags
& FLAG_IDL_PROXY
) strarray_add( &dlldata_files
, source
->name
);
2053 if (source
->file
->flags
& FLAG_INSTALL
)
2055 strarray_add( &make
->install_dev_rules
, xstrdup( source
->filename
));
2056 strarray_add( &make
->install_dev_rules
,
2057 strmake( "D$(includedir)/%s.idl", get_include_install_path( obj
) ));
2058 if (source
->file
->flags
& FLAG_IDL_HEADER
)
2060 strarray_add( &make
->install_dev_rules
, strmake( "%s.h", obj
));
2061 strarray_add( &make
->install_dev_rules
,
2062 strmake( "d$(includedir)/%s.h", get_include_install_path( obj
) ));
2065 if (!targets
.count
) continue;
2066 output_filenames_obj_dir( make
, targets
);
2067 output( ": %s\n", tools_path( make
, "widl" ));
2068 output( "\t%s -o $@", tools_path( make
, "widl" ) );
2069 output_filenames( target_flags
);
2070 output_filenames( includes
);
2071 output_filenames( make
->define_args
);
2072 output_filenames( extradefs
);
2073 output_filenames( get_expanded_make_var_array( make
, "EXTRAIDLFLAGS" ));
2074 output_filename( source
->filename
);
2076 output_filenames_obj_dir( make
, targets
);
2077 output( ": %s", source
->filename
);
2079 else if (!strcmp( ext
, "in" )) /* .in file or man page */
2081 if (strendswith( obj
, ".man" ) && source
->file
->args
)
2083 struct strarray symlinks
;
2084 char *dir
, *dest
= replace_extension( obj
, ".man", "" );
2085 char *lang
= strchr( dest
, '.' );
2086 char *section
= source
->file
->args
;
2090 dir
= strmake( "$(mandir)/%s/man%s", lang
, section
);
2092 else dir
= strmake( "$(mandir)/man%s", section
);
2093 add_install_rule( make
, dest
, xstrdup(obj
), strmake( "d%s/%s.%s", dir
, dest
, section
));
2094 symlinks
= get_expanded_make_var_array( make
, file_local_var( dest
, "SYMLINKS" ));
2095 for (i
= 0; i
< symlinks
.count
; i
++)
2096 add_install_rule( make
, symlinks
.str
[i
], strmake( "%s.%s", dest
, section
),
2097 strmake( "y%s/%s.%s", dir
, symlinks
.str
[i
], section
));
2100 strarray_add( &all_targets
, xstrdup(obj
) );
2102 else strarray_add( &clean_files
, xstrdup(obj
) );
2103 output( "%s: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2104 output( "\t$(SED_CMD) %s >$@ || ($(RM) $@ && false)\n", source
->filename
);
2105 output( "%s:", obj_dir_path( make
, obj
));
2107 else if (!strcmp( ext
, "sfd" )) /* font file */
2109 char *ttf_file
= src_dir_path( make
, strmake( "%s.ttf", obj
));
2110 if (fontforge
&& !make
->src_dir
)
2112 output( "%s: %s\n", ttf_file
, source
->filename
);
2113 output( "\t%s -script %s %s $@\n",
2114 fontforge
, top_dir_path( make
, "fonts/genttf.ff" ), source
->filename
);
2115 if (!(source
->file
->flags
& FLAG_SFD_FONTS
)) output( "all: %s\n", ttf_file
);
2117 if (source
->file
->flags
& FLAG_INSTALL
)
2119 strarray_add( &make
->install_lib_rules
, strmake( "%s.ttf", obj
));
2120 strarray_add( &make
->install_lib_rules
, strmake( "D$(fontdir)/%s.ttf", obj
));
2122 if (source
->file
->flags
& FLAG_SFD_FONTS
)
2124 struct strarray
*array
= source
->file
->args
;
2126 for (i
= 0; i
< array
->count
; i
++)
2128 char *font
= strtok( xstrdup(array
->str
[i
]), " \t" );
2129 char *args
= strtok( NULL
, "" );
2131 strarray_add( &all_targets
, xstrdup( font
));
2132 output( "%s: %s %s\n", obj_dir_path( make
, font
),
2133 tools_path( make
, "sfnt2fon" ), ttf_file
);
2134 output( "\t%s -o $@ %s %s\n", tools_path( make
, "sfnt2fon" ), ttf_file
, args
);
2135 strarray_add( &make
->install_lib_rules
, xstrdup(font
) );
2136 strarray_add( &make
->install_lib_rules
, strmake( "d$(fontdir)/%s", font
));
2139 continue; /* no dependencies */
2141 else if (!strcmp( ext
, "svg" )) /* svg file */
2143 if (convert
&& rsvg
&& icotool
&& !make
->src_dir
)
2145 output( "%s.ico %s.bmp: %s\n",
2146 src_dir_path( make
, obj
), src_dir_path( make
, obj
), source
->filename
);
2147 output( "\tCONVERT=\"%s\" ICOTOOL=\"%s\" RSVG=\"%s\" %s %s $@\n", convert
, icotool
, rsvg
,
2148 top_dir_path( make
, "tools/buildimage" ), source
->filename
);
2150 continue; /* no dependencies */
2152 else if (!strcmp( ext
, "res" ))
2154 strarray_add( &res_files
, source
->name
);
2155 continue; /* no dependencies */
2157 else if (!strcmp( ext
, "h" ) || !strcmp( ext
, "rh" ) || !strcmp( ext
, "inl" )) /* header file */
2159 if (source
->file
->flags
& FLAG_GENERATED
)
2161 strarray_add( &all_targets
, source
->name
);
2165 strarray_add( &make
->install_dev_rules
, source
->name
);
2166 strarray_add( &make
->install_dev_rules
,
2167 strmake( "D$(includedir)/%s", get_include_install_path( source
->name
) ));
2169 continue; /* no dependencies */
2173 int need_cross
= make
->testdll
||
2174 (source
->file
->flags
& FLAG_C_IMPLIB
) ||
2175 (make
->module
&& make
->staticlib
);
2177 if ((source
->file
->flags
& FLAG_GENERATED
) &&
2178 (!make
->testdll
|| !strendswith( source
->filename
, "testlist.c" )))
2179 strarray_add( &clean_files
, source
->filename
);
2180 if (source
->file
->flags
& FLAG_C_IMPLIB
) strarray_add( &implib_objs
, strmake( "%s.o", obj
));
2181 strarray_add( &object_files
, strmake( "%s.o", obj
));
2182 output( "%s.o: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2183 output( "\t$(CC) -c -o $@ %s", source
->filename
);
2184 output_filenames( includes
);
2185 output_filenames( make
->define_args
);
2186 output_filenames( extradefs
);
2187 if (make
->module
|| make
->staticlib
|| make
->testdll
)
2189 output_filenames( dll_flags
);
2190 if (make
->use_msvcrt
) output_filenames( msvcrt_flags
);
2192 output_filenames( extra_cflags
);
2193 output_filenames( cpp_flags
);
2194 output_filename( "$(CFLAGS)" );
2196 if (crosstarget
&& need_cross
)
2198 strarray_add( &crossobj_files
, strmake( "%s.cross.o", obj
));
2199 output( "%s.cross.o: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2200 output( "\t$(CROSSCC) -c -o $@ %s", source
->filename
);
2201 output_filenames( includes
);
2202 output_filenames( make
->define_args
);
2203 output_filenames( extradefs
);
2204 output_filename( "-DWINE_CROSSTEST" );
2205 output_filenames( cpp_flags
);
2206 output_filename( "$(CFLAGS)" );
2209 if (make
->testdll
&& !strcmp( ext
, "c" ) && !(source
->file
->flags
& FLAG_GENERATED
))
2211 strarray_add( &ok_files
, strmake( "%s.ok", obj
));
2212 output( "%s.ok:\n", obj_dir_path( make
, obj
));
2213 output( "\t%s $(RUNTESTFLAGS) -T %s -M %s -p %s%s %s && touch $@\n",
2214 top_dir_path( make
, "tools/runtest" ), top_obj_dir_path( make
, "" ), make
->testdll
,
2215 replace_extension( make
->testdll
, ".dll", "_test.exe" ), dll_ext
, obj
);
2217 if (!strcmp( ext
, "c" ) && !(source
->file
->flags
& FLAG_GENERATED
))
2218 strarray_add( &c2man_files
, source
->filename
);
2219 output( "%s.o", obj_dir_path( make
, obj
));
2220 if (crosstarget
&& need_cross
) output( " %s.cross.o", obj_dir_path( make
, obj
));
2225 for (i
= 0; i
< source
->files_count
; i
++) output_include( source
->files
[i
], source
);
2229 /* rules for files that depend on multiple sources */
2233 output( "%s: %s", obj_dir_path( make
, "rsrc.pot" ), tools_path( make
, "wrc" ) );
2234 output_filenames( po_files
);
2236 output( "\t%s -O pot -o $@", tools_path( make
, "wrc" ));
2237 if (make
->is_win16
) output_filename( "-m16" );
2238 else output_filenames( target_flags
);
2239 output_filename( "--nostdinc" );
2240 output_filenames( includes
);
2241 output_filenames( make
->define_args
);
2242 output_filenames( po_files
);
2244 strarray_add( &clean_files
, "rsrc.pot" );
2249 output( "%s: %s", obj_dir_path( make
, "msg.pot" ), tools_path( make
, "wmc" ));
2250 output_filenames( mc_files
);
2252 output( "\t%s -O pot -o $@", tools_path( make
, "wmc" ));
2253 output_filenames( mc_files
);
2255 strarray_add( &clean_files
, "msg.pot" );
2258 if (dlldata_files
.count
)
2260 output( "%s: %s %s\n", obj_dir_path( make
, "dlldata.c" ),
2261 tools_path( make
, "widl" ), src_dir_path( make
, "Makefile.in" ));
2262 output( "\t%s --dlldata-only -o $@", tools_path( make
, "widl" ));
2263 output_filenames( dlldata_files
);
2267 if (make
->module
&& !make
->staticlib
)
2269 struct strarray all_libs
= empty_strarray
;
2270 char *module_path
= obj_dir_path( make
, make
->module
);
2271 char *spec_file
= NULL
;
2273 if (!make
->appmode
.count
)
2274 spec_file
= src_dir_path( make
, replace_extension( make
->module
, ".dll", ".spec" ));
2275 for (i
= 0; i
< make
->delayimports
.count
; i
++)
2276 strarray_add( &all_libs
, strmake( "-l%s", make
->delayimports
.str
[i
] ));
2277 for (i
= 0; i
< make
->imports
.count
; i
++)
2278 strarray_add( &all_libs
, strmake( "-l%s", make
->imports
.str
[i
] ));
2279 for (i
= 0; i
< make
->delayimports
.count
; i
++)
2280 strarray_add( &all_libs
, strmake( "-Wb,-d%s", make
->delayimports
.str
[i
] ));
2281 strarray_add( &all_libs
, "-lwine" );
2282 strarray_add( &all_libs
, top_obj_dir_path( make
, "libs/port/libwine_port.a" ));
2283 strarray_addall( &all_libs
, get_expanded_make_var_array( make
, "EXTRALIBS" ));
2284 strarray_addall( &all_libs
, libs
);
2288 strarray_add( &all_targets
, strmake( "%s%s", make
->module
, dll_ext
));
2289 strarray_add( &all_targets
, strmake( "%s.fake", make
->module
));
2290 add_install_rule( make
, make
->module
, strmake( "%s%s", make
->module
, dll_ext
),
2291 strmake( "p$(dlldir)/%s%s", make
->module
, dll_ext
));
2292 add_install_rule( make
, make
->module
, strmake( "%s.fake", make
->module
),
2293 strmake( "d$(fakedlldir)/%s", make
->module
));
2294 output( "%s%s %s.fake:", module_path
, dll_ext
, module_path
);
2298 strarray_add( &all_targets
, make
->module
);
2299 add_install_rule( make
, make
->module
, make
->module
,
2300 strmake( "p$(%s)/%s", spec_file
? "dlldir" : "bindir", make
->module
));
2301 output( "%s:", module_path
);
2303 if (spec_file
) output_filename( spec_file
);
2304 output_filenames_obj_dir( make
, object_files
);
2305 output_filenames_obj_dir( make
, res_files
);
2307 output( "\t%s -o $@", tools_path( make
, "winegcc" ));
2308 output_filename( strmake( "-B%s", tools_dir_path( make
, "winebuild" )));
2309 if (tools_dir
) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make
, "" )));
2310 output_filenames( target_flags
);
2311 output_filenames( unwind_flags
);
2314 output( " -shared %s", spec_file
);
2315 output_filenames( make
->extradllflags
);
2317 else output_filenames( make
->appmode
);
2318 output_filenames_obj_dir( make
, object_files
);
2319 output_filenames_obj_dir( make
, res_files
);
2320 output_filenames( all_libs
);
2321 output_filename( "$(LDFLAGS)" );
2324 if (spec_file
&& make
->importlib
)
2326 char *importlib_path
= obj_dir_path( make
, strmake( "lib%s", make
->importlib
));
2329 strarray_add( &clean_files
, strmake( "lib%s.def", make
->importlib
));
2330 output( "%s.def: %s %s\n", importlib_path
, tools_path( make
, "winebuild" ), spec_file
);
2331 output( "\t%s -w --def -o $@ --export %s", tools_path( make
, "winebuild" ), spec_file
);
2332 output_filenames( target_flags
);
2333 if (make
->is_win16
) output_filename( "-m16" );
2335 add_install_rule( make
, make
->importlib
, strmake( "lib%s.def", make
->importlib
),
2336 strmake( "d$(dlldir)/lib%s.def", make
->importlib
));
2337 if (implib_objs
.count
)
2339 strarray_add( &clean_files
, strmake( "lib%s.def.a", make
->importlib
));
2340 output( "%s.def.a:", importlib_path
);
2341 output_filenames_obj_dir( make
, implib_objs
);
2343 output( "\t$(RM) $@\n" );
2344 output( "\t$(AR) $(ARFLAGS) $@" );
2345 output_filenames_obj_dir( make
, implib_objs
);
2347 output( "\t$(RANLIB) $@\n" );
2348 add_install_rule( make
, make
->importlib
, strmake( "lib%s.def.a", make
->importlib
),
2349 strmake( "d$(dlldir)/lib%s.def.a", make
->importlib
));
2354 strarray_add( &clean_files
, strmake( "lib%s.a", make
->importlib
));
2355 output( "%s.a: %s %s", importlib_path
, tools_path( make
, "winebuild" ), spec_file
);
2356 output_filenames_obj_dir( make
, implib_objs
);
2358 output( "\t%s -w --implib -o $@ --export %s", tools_path( make
, "winebuild" ), spec_file
);
2359 output_filenames( target_flags
);
2360 output_filenames_obj_dir( make
, implib_objs
);
2362 add_install_rule( make
, make
->importlib
, strmake( "lib%s.a", make
->importlib
),
2363 strmake( "d$(dlldir)/lib%s.a", make
->importlib
));
2365 if (crosstarget
&& !make
->is_win16
)
2367 struct strarray cross_files
= strarray_replace_extension( &implib_objs
, ".o", ".cross.o" );
2368 strarray_add( &clean_files
, strmake( "lib%s.cross.a", make
->importlib
));
2369 output( "%s.cross.a: %s %s", importlib_path
, tools_path( make
, "winebuild" ), spec_file
);
2370 output_filenames_obj_dir( make
, cross_files
);
2372 output( "\t%s -b %s -w --implib -o $@ --export %s",
2373 tools_path( make
, "winebuild" ), crosstarget
, spec_file
);
2374 output_filenames_obj_dir( make
, cross_files
);
2381 if (c2man_files
.count
)
2383 output( "manpages::\n" );
2384 output( "\t%s -w %s", top_dir_path( make
, "tools/c2man.pl" ), spec_file
);
2385 output_filename( strmake( "-R%s", top_dir_path( make
, "" )));
2386 output_filename( strmake( "-I%s", top_dir_path( make
, "include" )));
2387 output_filename( strmake( "-o %s/man%s",
2388 top_obj_dir_path( make
, "documentation" ), man_ext
));
2389 output_filenames( c2man_files
);
2391 output( "htmlpages::\n" );
2392 output( "\t%s -Th -w %s", top_dir_path( make
, "tools/c2man.pl" ), spec_file
);
2393 output_filename( strmake( "-R%s", top_dir_path( make
, "" )));
2394 output_filename( strmake( "-I%s", top_dir_path( make
, "include" )));
2395 output_filename( strmake( "-o %s",
2396 top_obj_dir_path( make
, "documentation/html" )));
2397 output_filenames( c2man_files
);
2399 output( "sgmlpages::\n" );
2400 output( "\t%s -Ts -w %s", top_dir_path( make
, "tools/c2man.pl" ), spec_file
);
2401 output_filename( strmake( "-R%s", top_dir_path( make
, "" )));
2402 output_filename( strmake( "-I%s", top_dir_path( make
, "include" )));
2403 output_filename( strmake( "-o %s",
2404 top_obj_dir_path( make
, "documentation/api-guide" )));
2405 output_filenames( c2man_files
);
2407 output( "xmlpages::\n" );
2408 output( "\t%s -Tx -w %s", top_dir_path( make
, "tools/c2man.pl" ), spec_file
);
2409 output_filename( strmake( "-R%s", top_dir_path( make
, "" )));
2410 output_filename( strmake( "-I%s", top_dir_path( make
, "include" )));
2411 output_filename( strmake( "-o %s",
2412 top_obj_dir_path( make
, "documentation/api-guide-xml" )));
2413 output_filenames( c2man_files
);
2415 strarray_add( &phony_targets
, "manpages" );
2416 strarray_add( &phony_targets
, "htmlpages" );
2417 strarray_add( &phony_targets
, "sgmlpages" );
2418 strarray_add( &phony_targets
, "xmlpages" );
2420 else output( "manpages htmlpages sgmlpages xmlpages::\n" );
2424 char *binary
= replace_extension( make
->module
, ".exe", "" );
2425 add_install_rule( make
, binary
, tools_dir_path( make
, "wineapploader" ),
2426 strmake( "s$(bindir)/%s", binary
));
2430 if (make
->staticlib
)
2432 strarray_add( &all_targets
, make
->staticlib
);
2433 output( "%s:", obj_dir_path( make
, make
->staticlib
));
2434 output_filenames_obj_dir( make
, object_files
);
2435 output( "\n\t$(RM) $@\n" );
2436 output( "\t$(AR) $(ARFLAGS) $@" );
2437 output_filenames_obj_dir( make
, object_files
);
2438 output( "\n\t$(RANLIB) $@\n" );
2439 if (crosstarget
&& make
->module
)
2441 char *name
= replace_extension( make
->staticlib
, ".a", ".cross.a" );
2443 strarray_add( &all_targets
, name
);
2444 output( "%s:", obj_dir_path( make
, name
));
2445 output_filenames_obj_dir( make
, crossobj_files
);
2446 output( "\n\t$(RM) $@\n" );
2447 output( "\t%s-ar $(ARFLAGS) $@", crosstarget
);
2448 output_filenames_obj_dir( make
, crossobj_files
);
2449 output( "\n\t%s-ranlib $@\n", crosstarget
);
2455 char *testmodule
= replace_extension( make
->testdll
, ".dll", "_test.exe" );
2456 char *stripped
= replace_extension( make
->testdll
, ".dll", "_test-stripped.exe" );
2457 char *testres
= replace_extension( make
->testdll
, ".dll", "_test.res" );
2458 struct strarray all_libs
= empty_strarray
;
2460 for (i
= 0; i
< make
->imports
.count
; i
++)
2461 strarray_add( &all_libs
, strmake( "-l%s", make
->imports
.str
[i
] ));
2462 strarray_addall( &all_libs
, libs
);
2464 strarray_add( &all_targets
, strmake( "%s%s", testmodule
, dll_ext
));
2465 strarray_add( &clean_files
, strmake( "%s%s", stripped
, dll_ext
));
2466 output( "%s%s:\n", obj_dir_path( make
, testmodule
), dll_ext
);
2467 output( "\t%s -o $@", tools_path( make
, "winegcc" ));
2468 output_filename( strmake( "-B%s", tools_dir_path( make
, "winebuild" )));
2469 if (tools_dir
) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make
, "" )));
2470 output_filenames( target_flags
);
2471 output_filenames( unwind_flags
);
2472 output_filenames( make
->appmode
);
2473 output_filenames_obj_dir( make
, object_files
);
2474 output_filenames_obj_dir( make
, res_files
);
2475 output_filenames( all_libs
);
2476 output_filename( "$(LDFLAGS)" );
2478 output( "%s%s:\n", obj_dir_path( make
, stripped
), dll_ext
);
2479 output( "\t%s -o $@", tools_path( make
, "winegcc" ));
2480 output_filename( strmake( "-B%s", tools_dir_path( make
, "winebuild" )));
2481 if (tools_dir
) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make
, "" )));
2482 output_filenames( target_flags
);
2483 output_filenames( unwind_flags
);
2484 output_filename( strmake( "-Wb,-F,%s", testmodule
));
2485 output_filenames( make
->appmode
);
2486 output_filenames_obj_dir( make
, object_files
);
2487 output_filenames_obj_dir( make
, res_files
);
2488 output_filenames( all_libs
);
2489 output_filename( "$(LDFLAGS)" );
2491 output( "%s%s %s%s:", obj_dir_path( make
, testmodule
), dll_ext
,
2492 obj_dir_path( make
, stripped
), dll_ext
);
2493 output_filenames_obj_dir( make
, object_files
);
2494 output_filenames_obj_dir( make
, res_files
);
2497 output( "all: %s/%s\n", top_obj_dir_path( make
, "programs/winetest" ), testres
);
2498 output( "%s/%s: %s%s\n", top_obj_dir_path( make
, "programs/winetest" ), testres
,
2499 obj_dir_path( make
, stripped
), dll_ext
);
2500 output( "\techo \"%s TESTRES \\\"%s%s\\\"\" | %s -o $@\n",
2501 testmodule
, obj_dir_path( make
, stripped
), dll_ext
, tools_path( make
, "wrc" ));
2505 char *crosstest
= replace_extension( make
->testdll
, ".dll", "_crosstest.exe" );
2507 strarray_add( &clean_files
, crosstest
);
2508 output( "%s: %s\n", obj_dir_path( make
, "crosstest" ), obj_dir_path( make
, crosstest
));
2509 output( "%s:", obj_dir_path( make
, crosstest
));
2510 output_filenames_obj_dir( make
, crossobj_files
);
2511 output_filenames_obj_dir( make
, res_files
);
2513 output( "\t%s -o $@ -b %s", tools_path( make
, "winegcc" ), crosstarget
);
2514 output_filename( strmake( "-B%s", tools_dir_path( make
, "winebuild" )));
2515 if (tools_dir
) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make
, "" )));
2516 output_filename( "--lib-suffix=.cross.a" );
2517 output_filenames_obj_dir( make
, crossobj_files
);
2518 output_filenames_obj_dir( make
, res_files
);
2519 output_filenames( all_libs
);
2520 output_filename( "$(LDFLAGS)" );
2522 strarray_add( &phony_targets
, obj_dir_path( make
, "crosstest" ));
2523 if (make
->obj_dir
) output( "crosstest: %s\n", obj_dir_path( make
, "crosstest" ));
2526 output_filenames_obj_dir( make
, ok_files
);
2527 output( ": %s%s ../%s%s\n", testmodule
, dll_ext
, make
->testdll
, dll_ext
);
2528 output( "check test:" );
2529 output_filenames_obj_dir( make
, ok_files
);
2531 output( "testclean::\n" );
2532 output( "\t$(RM)" );
2533 output_filenames_obj_dir( make
, ok_files
);
2535 strarray_addall( &clean_files
, ok_files
);
2536 strarray_add( &phony_targets
, "check" );
2537 strarray_add( &phony_targets
, "test" );
2538 strarray_add( &phony_targets
, "testclean" );
2539 *testlist_files
= strarray_replace_extension( &ok_files
, ".ok", "" );
2542 for (i
= 0; i
< make
->programs
.count
; i
++)
2544 char *program_installed
= NULL
;
2545 char *program
= strmake( "%s%s", make
->programs
.str
[i
], exe_ext
);
2546 struct strarray all_libs
= empty_strarray
;
2547 struct strarray objs
= get_expanded_make_var_array( make
,
2548 file_local_var( make
->programs
.str
[i
], "OBJS" ));
2549 struct strarray symlinks
= get_expanded_make_var_array( make
,
2550 file_local_var( make
->programs
.str
[i
], "SYMLINKS" ));
2552 if (!objs
.count
) objs
= object_files
;
2553 output( "%s:", obj_dir_path( make
, program
) );
2554 output_filenames_obj_dir( make
, objs
);
2556 output( "\t$(CC) -o $@" );
2557 output_filenames_obj_dir( make
, objs
);
2558 strarray_add( &all_libs
, top_obj_dir_path( make
, "libs/port/libwine_port.a" ));
2559 strarray_addall( &all_libs
, get_expanded_make_var_array( make
, "EXTRALIBS" ));
2560 strarray_addall( &all_libs
, libs
);
2561 strarray_addall( &all_libs
, get_expanded_make_var_array( make
,
2562 file_local_var( make
->programs
.str
[i
], "LDFLAGS" )));
2564 if (strarray_exists( &all_libs
, "-lwine" ))
2566 strarray_add( &all_libs
, strmake( "-L%s", top_obj_dir_path( make
, "libs/wine" )));
2567 if (ldrpath_local
&& ldrpath_install
)
2569 program_installed
= strmake( "%s-installed%s", make
->programs
.str
[i
], exe_ext
);
2570 output_filename( ldrpath_local
);
2571 output_filenames( all_libs
);
2572 output_filename( "$(LDFLAGS)" );
2574 output( "%s:", obj_dir_path( make
, program_installed
) );
2575 output_filenames_obj_dir( make
, objs
);
2577 output( "\t$(CC) -o $@" );
2578 output_filenames_obj_dir( make
, objs
);
2579 output_filename( ldrpath_install
);
2580 strarray_add( &all_targets
, program_installed
);
2584 output_filenames( all_libs
);
2585 output_filename( "$(LDFLAGS)" );
2587 strarray_add( &all_targets
, program
);
2591 output_filenames_obj_dir( make
, symlinks
);
2592 output( ": %s\n", obj_dir_path( make
, program
));
2593 output( "\t$(RM) $@ && $(LN_S) %s $@\n", obj_dir_path( make
, program
));
2594 strarray_addall( &all_targets
, symlinks
);
2597 add_install_rule( make
, program
, program_installed
? program_installed
: program
,
2598 strmake( "p$(bindir)/%s", program
));
2599 for (j
= 0; j
< symlinks
.count
; j
++)
2600 add_install_rule( make
, symlinks
.str
[j
], program
,
2601 strmake( "y$(bindir)/%s%s", symlinks
.str
[j
], exe_ext
));
2604 for (i
= 0; i
< make
->scripts
.count
; i
++)
2605 add_install_rule( make
, make
->scripts
.str
[i
], make
->scripts
.str
[i
],
2606 strmake( "S$(bindir)/%s", make
->scripts
.str
[i
] ));
2608 if (all_targets
.count
)
2611 output_filenames_obj_dir( make
, all_targets
);
2615 output_install_rules( make
, make
->install_lib_rules
, "install-lib", &phony_targets
);
2616 output_install_rules( make
, make
->install_dev_rules
, "install-dev", &phony_targets
);
2618 strarray_addall( &clean_files
, object_files
);
2619 strarray_addall( &clean_files
, crossobj_files
);
2620 strarray_addall( &clean_files
, res_files
);
2621 strarray_addall( &clean_files
, all_targets
);
2622 strarray_addall( &clean_files
, get_expanded_make_var_array( make
, "EXTRA_TARGETS" ));
2624 if (clean_files
.count
)
2626 output( "%s::\n", obj_dir_path( make
, "clean" ));
2627 output( "\t$(RM)" );
2628 output_filenames_obj_dir( make
, clean_files
);
2630 if (make
->obj_dir
) output( "__clean__: %s\n", obj_dir_path( make
, "clean" ));
2631 strarray_add( &phony_targets
, obj_dir_path( make
, "clean" ));
2634 if (make
->top_obj_dir
)
2636 output( "depend:\n" );
2637 output( "\t@cd %s && $(MAKE) %s\n", make
->top_obj_dir
, base_dir_path( make
, "depend" ));
2638 strarray_add( &phony_targets
, "depend" );
2641 if (phony_targets
.count
)
2643 output( ".PHONY:" );
2644 output_filenames( phony_targets
);
2648 for (i
= 0; i
< subdirs
.count
; i
++) create_dir( subdirs
.str
[i
] );
2654 /*******************************************************************
2657 static FILE *create_temp_file( const char *orig
)
2659 char *name
= xmalloc( strlen(orig
) + 13 );
2660 unsigned int i
, id
= getpid();
2664 for (i
= 0; i
< 100; i
++)
2666 sprintf( name
, "%s.tmp%08x", orig
, id
);
2667 if ((fd
= open( name
, O_RDWR
| O_CREAT
| O_EXCL
, 0666 )) != -1)
2669 ret
= fdopen( fd
, "w" );
2672 if (errno
!= EEXIST
) break;
2675 if (!ret
) fatal_error( "failed to create output file for '%s'\n", orig
);
2676 temp_file_name
= name
;
2681 /*******************************************************************
2684 static void rename_temp_file( const char *dest
)
2686 int ret
= rename( temp_file_name
, dest
);
2687 if (ret
== -1 && errno
== EEXIST
)
2689 /* rename doesn't overwrite on windows */
2691 ret
= rename( temp_file_name
, dest
);
2693 if (ret
== -1) fatal_error( "failed to rename output file to '%s'\n", dest
);
2694 temp_file_name
= NULL
;
2698 /*******************************************************************
2699 * are_files_identical
2701 static int are_files_identical( FILE *file1
, FILE *file2
)
2705 char buffer1
[8192], buffer2
[8192];
2706 int size1
= fread( buffer1
, 1, sizeof(buffer1
), file1
);
2707 int size2
= fread( buffer2
, 1, sizeof(buffer2
), file2
);
2708 if (size1
!= size2
) return 0;
2709 if (!size1
) return feof( file1
) && feof( file2
);
2710 if (memcmp( buffer1
, buffer2
, size1
)) return 0;
2715 /*******************************************************************
2716 * rename_temp_file_if_changed
2718 static void rename_temp_file_if_changed( const char *dest
)
2720 FILE *file1
, *file2
;
2723 if ((file1
= fopen( dest
, "r" )))
2725 if ((file2
= fopen( temp_file_name
, "r" )))
2727 do_rename
= !are_files_identical( file1
, file2
);
2734 unlink( temp_file_name
);
2735 temp_file_name
= NULL
;
2737 else rename_temp_file( dest
);
2741 /*******************************************************************
2744 static void output_testlist( const char *dest
, struct strarray files
)
2748 output_file
= create_temp_file( dest
);
2750 output( "/* Automatically generated by make depend; DO NOT EDIT!! */\n\n" );
2751 output( "#define WIN32_LEAN_AND_MEAN\n" );
2752 output( "#include <windows.h>\n\n" );
2753 output( "#define STANDALONE\n" );
2754 output( "#include \"wine/test.h\"\n\n" );
2756 for (i
= 0; i
< files
.count
; i
++) output( "extern void func_%s(void);\n", files
.str
[i
] );
2758 output( "const struct test winetest_testlist[] =\n" );
2760 for (i
= 0; i
< files
.count
; i
++) output( " { \"%s\", func_%s },\n", files
.str
[i
], files
.str
[i
] );
2761 output( " { 0, 0 }\n" );
2764 if (fclose( output_file
)) fatal_perror( "write" );
2766 rename_temp_file_if_changed( dest
);
2770 /*******************************************************************
2773 static void output_gitignore( const char *dest
, struct strarray files
)
2777 output_file
= create_temp_file( dest
);
2779 output( "# Automatically generated by make depend; DO NOT EDIT!!\n" );
2780 for (i
= 0; i
< files
.count
; i
++)
2782 if (!strchr( files
.str
[i
], '/' )) output( "/" );
2783 output( "%s\n", files
.str
[i
] );
2786 if (fclose( output_file
)) fatal_perror( "write" );
2788 rename_temp_file( dest
);
2792 /*******************************************************************
2793 * output_top_variables
2795 static void output_top_variables( struct makefile
*make
)
2798 struct strarray
*vars
= &top_makefile
->vars
;
2800 if (!make
->base_dir
) return; /* don't output variables in the top makefile */
2802 output( "# Automatically generated by make depend; DO NOT EDIT!!\n\n" );
2803 output( "all:\n\n" );
2804 for (i
= 0; i
< vars
->count
; i
+= 2)
2805 output( "%s = %s\n", vars
->str
[i
], get_make_variable( make
, vars
->str
[i
] ));
2810 /*******************************************************************
2811 * output_dependencies
2813 static void output_dependencies( struct makefile
*make
)
2815 struct strarray targets
, testlist_files
= empty_strarray
, ignore_files
= empty_strarray
;
2819 output_file_name
= base_dir_path( make
, output_makefile_name
);
2820 output_file
= create_temp_file( output_file_name
);
2821 output_top_variables( make
);
2823 /* copy the contents of the source makefile */
2824 src_file
= open_input_makefile( make
);
2825 while (fgets( buffer
, sizeof(buffer
), src_file
))
2826 if (fwrite( buffer
, 1, strlen(buffer
), output_file
) != strlen(buffer
)) fatal_perror( "write" );
2827 if (fclose( src_file
)) fatal_perror( "close" );
2828 input_file_name
= NULL
;
2830 targets
= output_sources( make
, &testlist_files
);
2832 fclose( output_file
);
2834 rename_temp_file( output_file_name
);
2836 strarray_add( &ignore_files
, ".gitignore" );
2837 strarray_add( &ignore_files
, "Makefile" );
2838 if (testlist_files
.count
) strarray_add( &ignore_files
, "testlist.c" );
2839 strarray_addall( &ignore_files
, targets
);
2841 if (testlist_files
.count
)
2842 output_testlist( base_dir_path( make
, "testlist.c" ), testlist_files
);
2843 if (!make
->src_dir
&& make
->base_dir
)
2844 output_gitignore( base_dir_path( make
, ".gitignore" ), ignore_files
);
2846 output_file_name
= NULL
;
2850 /*******************************************************************
2853 static void update_makefile( const char *path
)
2855 static const char *source_vars
[] =
2874 struct strarray value
;
2875 struct incl_file
*file
;
2876 struct makefile
*make
;
2878 make
= parse_makefile( path
, NULL
);
2882 make
->top_src_dir
= concat_paths( make
->top_obj_dir
, root_src_dir
);
2883 make
->src_dir
= concat_paths( make
->top_src_dir
, make
->base_dir
);
2885 strarray_set_value( &make
->vars
, "top_builddir", top_obj_dir_path( make
, "" ));
2886 strarray_set_value( &make
->vars
, "top_srcdir", top_dir_path( make
, "" ));
2887 strarray_set_value( &make
->vars
, "srcdir", src_dir_path( make
, "" ));
2889 make
->parent_dir
= get_expanded_make_variable( make
, "PARENTSRC" );
2890 make
->module
= get_expanded_make_variable( make
, "MODULE" );
2891 make
->testdll
= get_expanded_make_variable( make
, "TESTDLL" );
2892 make
->staticlib
= get_expanded_make_variable( make
, "STATICLIB" );
2893 make
->importlib
= get_expanded_make_variable( make
, "IMPORTLIB" );
2895 make
->programs
= get_expanded_make_var_array( make
, "PROGRAMS" );
2896 make
->scripts
= get_expanded_make_var_array( make
, "SCRIPTS" );
2897 make
->appmode
= get_expanded_make_var_array( make
, "APPMODE" );
2898 make
->imports
= get_expanded_make_var_array( make
, "IMPORTS" );
2899 make
->delayimports
= get_expanded_make_var_array( make
, "DELAYIMPORTS" );
2900 make
->extradllflags
= get_expanded_make_var_array( make
, "EXTRADLLFLAGS" );
2901 make
->install_lib
= get_expanded_make_var_array( make
, "INSTALL_LIB" );
2902 make
->install_dev
= get_expanded_make_var_array( make
, "INSTALL_DEV" );
2904 if (make
->module
&& strendswith( make
->module
, ".a" )) make
->staticlib
= make
->module
;
2906 make
->is_win16
= strarray_exists( &make
->extradllflags
, "-m16" );
2907 make
->use_msvcrt
= strarray_exists( &make
->appmode
, "-mno-cygwin" );
2909 for (i
= 0; i
< make
->imports
.count
&& !make
->use_msvcrt
; i
++)
2910 make
->use_msvcrt
= !strncmp( make
->imports
.str
[i
], "msvcr", 5 );
2912 make
->install_lib_rules
= empty_strarray
;
2913 make
->install_dev_rules
= empty_strarray
;
2914 if (make
->module
&& !make
->install_lib
.count
) strarray_add( &make
->install_lib
, make
->module
);
2916 make
->include_args
= empty_strarray
;
2917 make
->define_args
= empty_strarray
;
2918 strarray_add( &make
->define_args
, "-D__WINESRC__" );
2920 value
= get_expanded_make_var_array( make
, "EXTRAINCL" );
2921 for (i
= 0; i
< value
.count
; i
++)
2922 if (!strncmp( value
.str
[i
], "-I", 2 ))
2923 strarray_add_uniq( &make
->include_args
, value
.str
[i
] );
2925 strarray_add_uniq( &make
->define_args
, value
.str
[i
] );
2926 strarray_addall( &make
->define_args
, get_expanded_make_var_array( make
, "EXTRADEFS" ));
2928 list_init( &make
->sources
);
2929 list_init( &make
->includes
);
2931 /* FIXME: target dir has to exist to allow locating srcdir-relative include files */
2932 if (make
->base_dir
) create_dir( make
->base_dir
);
2934 for (var
= source_vars
; *var
; var
++)
2936 value
= get_expanded_make_var_array( make
, *var
);
2937 for (i
= 0; i
< value
.count
; i
++) add_src_file( make
, value
.str
[i
] );
2940 add_generated_sources( make
);
2942 value
= get_expanded_make_var_array( make
, "EXTRA_OBJS" );
2943 for (i
= 0; i
< value
.count
; i
++)
2945 /* default to .c for unknown extra object files */
2946 if (strendswith( value
.str
[i
], ".o" ))
2947 add_generated_source( make
, value
.str
[i
], replace_extension( value
.str
[i
], ".o", ".c" ) );
2949 add_generated_source( make
, value
.str
[i
], NULL
);
2952 LIST_FOR_EACH_ENTRY( file
, &make
->includes
, struct incl_file
, entry
) parse_file( make
, file
, 0 );
2954 output_dependencies( make
);
2958 /*******************************************************************
2961 static void parse_makeflags( const char *flags
)
2963 const char *p
= flags
;
2964 char *var
, *buffer
= xmalloc( strlen(flags
) + 1 );
2968 while (isspace(*p
)) p
++;
2970 while (*p
&& !isspace(*p
))
2972 if (*p
== '\\' && p
[1]) p
++;
2976 if (var
> buffer
) set_make_variable( &cmdline_vars
, buffer
);
2981 /*******************************************************************
2984 static int parse_option( const char *opt
)
2988 if (strchr( opt
, '=' )) return set_make_variable( &cmdline_vars
, opt
);
2994 if (opt
[2]) output_makefile_name
= opt
+ 2;
2997 if (opt
[2]) input_makefile_name
= opt
+ 2;
3000 relative_dir_mode
= 1;
3003 fprintf( stderr
, "Unknown option '%s'\n%s", opt
, Usage
);
3010 /*******************************************************************
3013 int main( int argc
, char *argv
[] )
3015 const char *makeflags
= getenv( "MAKEFLAGS" );
3018 if (makeflags
) parse_makeflags( makeflags
);
3023 if (parse_option( argv
[i
] ))
3025 for (j
= i
; j
< argc
; j
++) argv
[j
] = argv
[j
+1];
3031 if (relative_dir_mode
)
3037 fprintf( stderr
, "Option -r needs two directories\n%s", Usage
);
3040 relpath
= get_relative_path( argv
[1], argv
[2] );
3041 printf( "%s\n", relpath
? relpath
: "." );
3047 fprintf( stderr
, "%s", Usage
);
3050 atexit( cleanup_files
);
3051 signal( SIGTERM
, exit_on_signal
);
3052 signal( SIGINT
, exit_on_signal
);
3054 signal( SIGHUP
, exit_on_signal
);
3057 for (i
= 0; i
< HASH_SIZE
; i
++) list_init( &files
[i
] );
3059 if (!input_makefile_name
) input_makefile_name
= strmake( "%s.in", output_makefile_name
);
3061 top_makefile
= parse_makefile( NULL
, "# End of common header" );
3063 linguas
= get_expanded_make_var_array( top_makefile
, "LINGUAS" );
3064 target_flags
= get_expanded_make_var_array( top_makefile
, "TARGETFLAGS" );
3065 msvcrt_flags
= get_expanded_make_var_array( top_makefile
, "MSVCRTFLAGS" );
3066 dll_flags
= get_expanded_make_var_array( top_makefile
, "DLLFLAGS" );
3067 extra_cflags
= get_expanded_make_var_array( top_makefile
, "EXTRACFLAGS" );
3068 cpp_flags
= get_expanded_make_var_array( top_makefile
, "CPPFLAGS" );
3069 unwind_flags
= get_expanded_make_var_array( top_makefile
, "UNWINDFLAGS" );
3070 libs
= get_expanded_make_var_array( top_makefile
, "LIBS" );
3072 root_src_dir
= get_expanded_make_variable( top_makefile
, "srcdir" );
3073 tools_dir
= get_expanded_make_variable( top_makefile
, "TOOLSDIR" );
3074 tools_ext
= get_expanded_make_variable( top_makefile
, "TOOLSEXT" );
3075 exe_ext
= get_expanded_make_variable( top_makefile
, "EXEEXT" );
3076 man_ext
= get_expanded_make_variable( top_makefile
, "api_manext" );
3077 dll_ext
= (exe_ext
&& !strcmp( exe_ext
, ".exe" )) ? "" : ".so";
3078 dll_prefix
= get_expanded_make_variable( top_makefile
, "DLLPREFIX" );
3079 crosstarget
= get_expanded_make_variable( top_makefile
, "CROSSTARGET" );
3080 fontforge
= get_expanded_make_variable( top_makefile
, "FONTFORGE" );
3081 convert
= get_expanded_make_variable( top_makefile
, "CONVERT" );
3082 rsvg
= get_expanded_make_variable( top_makefile
, "RSVG" );
3083 icotool
= get_expanded_make_variable( top_makefile
, "ICOTOOL" );
3085 if (root_src_dir
&& !strcmp( root_src_dir
, "." )) root_src_dir
= NULL
;
3086 if (tools_dir
&& !strcmp( tools_dir
, "." )) tools_dir
= NULL
;
3087 if (!exe_ext
) exe_ext
= "";
3088 if (!tools_ext
) tools_ext
= "";
3089 if (!dll_prefix
) dll_prefix
= "";
3090 if (!man_ext
) man_ext
= "3w";
3092 for (i
= 1; i
< argc
; i
++) update_makefile( argv
[i
] );