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 (strendswith( source
->name
, ".x" ))
1707 add_generated_source( make
, replace_extension( source
->name
, ".x", ".h" ), NULL
);
1709 if (strendswith( source
->name
, ".y" ))
1711 file
= add_generated_source( make
, replace_extension( source
->name
, ".y", ".tab.c" ), NULL
);
1712 /* steal the includes list from the source file */
1713 file
->files_count
= source
->files_count
;
1714 file
->files_size
= source
->files_size
;
1715 file
->files
= source
->files
;
1716 source
->files_count
= source
->files_size
= 0;
1717 source
->files
= NULL
;
1719 if (strendswith( source
->name
, ".l" ))
1721 file
= add_generated_source( make
, replace_extension( source
->name
, ".l", ".yy.c" ), NULL
);
1722 /* steal the includes list from the source file */
1723 file
->files_count
= source
->files_count
;
1724 file
->files_size
= source
->files_size
;
1725 file
->files
= source
->files
;
1726 source
->files_count
= source
->files_size
= 0;
1727 source
->files
= NULL
;
1730 if (get_make_variable( make
, "TESTDLL" ))
1732 file
= add_generated_source( make
, "testlist.o", "testlist.c" );
1733 add_dependency( file
->file
, "wine/test.h", INCL_NORMAL
);
1734 add_all_includes( make
, file
, file
->file
);
1739 /*******************************************************************
1742 static void create_dir( const char *dir
)
1746 p
= path
= xstrdup( dir
);
1747 while ((p
= strchr( p
, '/' )))
1750 if (mkdir( path
, 0755 ) == -1 && errno
!= EEXIST
) fatal_perror( "mkdir %s", path
);
1752 while (*p
== '/') p
++;
1754 if (mkdir( path
, 0755 ) == -1 && errno
!= EEXIST
) fatal_perror( "mkdir %s", path
);
1759 /*******************************************************************
1760 * output_filenames_obj_dir
1762 static void output_filenames_obj_dir( struct makefile
*make
, struct strarray array
)
1766 for (i
= 0; i
< array
.count
; i
++) output_filename( obj_dir_path( make
, array
.str
[i
] ));
1770 /*******************************************************************
1773 static void output_include( struct incl_file
*pFile
, struct incl_file
*owner
)
1777 if (pFile
->owner
== owner
) return;
1778 if (!pFile
->filename
) return;
1779 pFile
->owner
= owner
;
1780 output_filename( pFile
->filename
);
1781 for (i
= 0; i
< pFile
->files_count
; i
++) output_include( pFile
->files
[i
], owner
);
1785 /*******************************************************************
1788 static void add_install_rule( struct makefile
*make
, const char *target
,
1789 const char *file
, const char *dest
)
1791 if (strarray_exists( &make
->install_lib
, target
))
1793 strarray_add( &make
->install_lib_rules
, file
);
1794 strarray_add( &make
->install_lib_rules
, dest
);
1796 else if (strarray_exists( &make
->install_dev
, target
))
1798 strarray_add( &make
->install_dev_rules
, file
);
1799 strarray_add( &make
->install_dev_rules
, dest
);
1804 /*******************************************************************
1805 * get_include_install_path
1807 * Determine the installation path for a given include file.
1809 static const char *get_include_install_path( const char *name
)
1811 if (!strncmp( name
, "wine/", 5 )) return name
+ 5;
1812 if (!strncmp( name
, "msvcrt/", 7 )) return name
;
1813 return strmake( "windows/%s", name
);
1817 /*******************************************************************
1818 * output_install_rules
1820 * Rules are stored as a (file,dest) pair of values.
1821 * The first char of dest indicates the type of install.
1823 static void output_install_rules( struct makefile
*make
, struct strarray files
,
1824 const char *target
, struct strarray
*phony_targets
)
1828 struct strarray targets
= empty_strarray
;
1830 if (!files
.count
) return;
1832 for (i
= 0; i
< files
.count
; i
+= 2)
1833 if (strchr( "dps", files
.str
[i
+ 1][0] )) /* only for files copied from object dir */
1834 strarray_add_uniq( &targets
, files
.str
[i
] );
1836 output( "install %s::", target
);
1837 output_filenames_obj_dir( make
, targets
);
1840 install_sh
= top_dir_path( make
, "tools/install-sh" );
1841 for (i
= 0; i
< files
.count
; i
+= 2)
1843 const char *file
= files
.str
[i
];
1844 const char *dest
= files
.str
[i
+ 1];
1848 case 'd': /* data file */
1849 output( "\t%s -m 644 $(INSTALL_DATA_FLAGS) %s $(DESTDIR)%s\n",
1850 install_sh
, obj_dir_path( make
, file
), dest
+ 1 );
1852 case 'D': /* data file in source dir */
1853 output( "\t%s -m 644 $(INSTALL_DATA_FLAGS) %s $(DESTDIR)%s\n",
1854 install_sh
, src_dir_path( make
, file
), dest
+ 1 );
1856 case 'p': /* program file */
1857 output( "\tSTRIPPROG=\"$(STRIP)\" %s $(INSTALL_PROGRAM_FLAGS) %s $(DESTDIR)%s\n",
1858 install_sh
, obj_dir_path( make
, file
), dest
+ 1 );
1860 case 's': /* script */
1861 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s $(DESTDIR)%s\n",
1862 install_sh
, obj_dir_path( make
, file
), dest
+ 1 );
1864 case 'S': /* script in source dir */
1865 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s $(DESTDIR)%s\n",
1866 install_sh
, src_dir_path( make
, file
), dest
+ 1 );
1868 case 'y': /* symlink */
1869 output( "\t$(RM) $(DESTDIR)%s && $(LN_S) %s $(DESTDIR)%s\n", dest
+ 1, file
, dest
+ 1 );
1876 output( "uninstall::\n" );
1877 output( "\t$(RM)" );
1878 for (i
= 0; i
< files
.count
; i
+= 2) output_filename( strmake( "$(DESTDIR)%s", files
.str
[i
+ 1] + 1 ));
1881 strarray_add( phony_targets
, "install" );
1882 strarray_add( phony_targets
, target
);
1883 strarray_add( phony_targets
, "uninstall" );
1887 /*******************************************************************
1890 static struct strarray
output_sources( struct makefile
*make
, struct strarray
*testlist_files
)
1892 struct incl_file
*source
;
1894 struct strarray object_files
= empty_strarray
;
1895 struct strarray crossobj_files
= empty_strarray
;
1896 struct strarray res_files
= empty_strarray
;
1897 struct strarray clean_files
= empty_strarray
;
1898 struct strarray po_files
= empty_strarray
;
1899 struct strarray mo_files
= empty_strarray
;
1900 struct strarray mc_files
= empty_strarray
;
1901 struct strarray ok_files
= empty_strarray
;
1902 struct strarray dlldata_files
= empty_strarray
;
1903 struct strarray c2man_files
= empty_strarray
;
1904 struct strarray implib_objs
= empty_strarray
;
1905 struct strarray includes
= empty_strarray
;
1906 struct strarray subdirs
= empty_strarray
;
1907 struct strarray phony_targets
= empty_strarray
;
1908 struct strarray all_targets
= empty_strarray
;
1909 char *ldrpath_local
= get_expanded_make_variable( make
, "LDRPATH_LOCAL" );
1910 char *ldrpath_install
= get_expanded_make_variable( make
, "LDRPATH_INSTALL" );
1912 for (i
= 0; i
< linguas
.count
; i
++)
1913 strarray_add( &mo_files
, strmake( "%s/%s.mo", top_obj_dir_path( make
, "po" ), linguas
.str
[i
] ));
1915 strarray_add( &phony_targets
, "all" );
1916 strarray_add( &includes
, strmake( "-I%s", obj_dir_path( make
, "" )));
1917 if (make
->src_dir
) strarray_add( &includes
, strmake( "-I%s", make
->src_dir
));
1918 if (make
->parent_dir
) strarray_add( &includes
, strmake( "-I%s", src_dir_path( make
, make
->parent_dir
)));
1919 if (make
->top_obj_dir
) strarray_add( &includes
, strmake( "-I%s", top_obj_dir_path( make
, "include" )));
1920 if (make
->top_src_dir
) strarray_add( &includes
, strmake( "-I%s", top_dir_path( make
, "include" )));
1921 if (make
->use_msvcrt
) strarray_add( &includes
, strmake( "-I%s", top_dir_path( make
, "include/msvcrt" )));
1922 strarray_addall( &includes
, make
->include_args
);
1924 LIST_FOR_EACH_ENTRY( source
, &make
->sources
, struct incl_file
, entry
)
1926 struct strarray extradefs
;
1927 char *obj
= xstrdup( source
->name
);
1928 char *ext
= get_extension( obj
);
1930 if (!ext
) fatal_error( "unsupported file type %s\n", source
->name
);
1933 if (make
->src_dir
&& strchr( obj
, '/' ))
1935 char *subdir
= base_dir_path( make
, obj
);
1936 *strrchr( subdir
, '/' ) = 0;
1937 strarray_add_uniq( &subdirs
, subdir
);
1940 extradefs
= get_expanded_make_var_array( make
, file_local_var( obj
, "EXTRADEFS" ));
1942 if (!strcmp( ext
, "y" )) /* yacc file */
1944 /* add source file dependency for parallel makes */
1945 char *header
= strmake( "%s.tab.h", obj
);
1947 if (find_include_file( make
, header
))
1949 output( "%s: %s\n", obj_dir_path( make
, header
), source
->filename
);
1950 output( "\t$(BISON) -p %s_ -o %s.tab.c -d %s\n",
1951 obj
, obj_dir_path( make
, obj
), source
->filename
);
1952 output( "%s.tab.c: %s %s\n", obj_dir_path( make
, obj
),
1953 source
->filename
, obj_dir_path( make
, header
));
1954 strarray_add( &clean_files
, header
);
1956 else output( "%s.tab.c: %s\n", obj
, source
->filename
);
1958 output( "\t$(BISON) -p %s_ -o $@ %s\n", obj
, source
->filename
);
1959 continue; /* no dependencies */
1961 else if (!strcmp( ext
, "x" )) /* template file */
1963 output( "%s.h: %s%s %s\n", obj_dir_path( make
, obj
),
1964 tools_dir_path( make
, "make_xftmpl" ), tools_ext
, source
->filename
);
1965 output( "\t%s%s -H -o $@ %s\n",
1966 tools_dir_path( make
, "make_xftmpl" ), tools_ext
, source
->filename
);
1967 if (source
->file
->flags
& FLAG_INSTALL
)
1969 strarray_add( &make
->install_dev_rules
, source
->name
);
1970 strarray_add( &make
->install_dev_rules
,
1971 strmake( "D$(includedir)/%s", get_include_install_path( source
->name
) ));
1972 strarray_add( &make
->install_dev_rules
, strmake( "%s.h", obj
));
1973 strarray_add( &make
->install_dev_rules
,
1974 strmake( "d$(includedir)/%s.h", get_include_install_path( obj
) ));
1976 continue; /* no dependencies */
1978 else if (!strcmp( ext
, "l" )) /* lex file */
1980 output( "%s.yy.c: %s\n", obj_dir_path( make
, obj
), source
->filename
);
1981 output( "\t$(FLEX) -o$@ %s\n", source
->filename
);
1982 continue; /* no dependencies */
1984 else if (!strcmp( ext
, "rc" )) /* resource file */
1986 strarray_add( &res_files
, strmake( "%s.res", obj
));
1987 output( "%s.res: %s %s\n", obj_dir_path( make
, obj
),
1988 tools_path( make
, "wrc" ), source
->filename
);
1989 output( "\t%s -o $@", tools_path( make
, "wrc" ) );
1990 if (make
->is_win16
) output_filename( "-m16" );
1991 else output_filenames( target_flags
);
1992 output_filename( "--nostdinc" );
1993 output_filenames( includes
);
1994 output_filenames( make
->define_args
);
1995 output_filenames( extradefs
);
1996 if (mo_files
.count
&& (source
->file
->flags
& FLAG_RC_PO
))
1998 strarray_add( &po_files
, source
->filename
);
1999 output_filename( strmake( "--po-dir=%s", top_obj_dir_path( make
, "po" )));
2000 output_filename( source
->filename
);
2002 output( "%s.res:", obj_dir_path( make
, obj
));
2003 output_filenames( mo_files
);
2005 output( "%s ", obj_dir_path( make
, "rsrc.pot" ));
2009 output_filename( source
->filename
);
2012 output( "%s.res:", obj_dir_path( make
, obj
));
2014 else if (!strcmp( ext
, "mc" )) /* message file */
2016 strarray_add( &res_files
, strmake( "%s.res", obj
));
2017 output( "%s.res: %s %s\n", obj_dir_path( make
, obj
),
2018 tools_path( make
, "wmc" ), source
->filename
);
2019 output( "\t%s -U -O res -o $@ %s", tools_path( make
, "wmc" ), source
->filename
);
2022 strarray_add( &mc_files
, source
->filename
);
2023 output_filename( strmake( "--po-dir=%s", top_obj_dir_path( make
, "po" )));
2025 output( "%s.res:", obj_dir_path( make
, obj
));
2026 output_filenames( mo_files
);
2028 output( "%s ", obj_dir_path( make
, "msg.pot" ));
2030 else output( "\n" );
2031 output( "%s.res:", obj_dir_path( make
, obj
));
2033 else if (!strcmp( ext
, "idl" )) /* IDL file */
2035 struct strarray targets
= empty_strarray
;
2038 if (!source
->file
->flags
|| find_include_file( make
, strmake( "%s.h", obj
)))
2039 source
->file
->flags
|= FLAG_IDL_HEADER
;
2041 for (i
= 0; i
< sizeof(idl_outputs
) / sizeof(idl_outputs
[0]); i
++)
2043 if (!(source
->file
->flags
& idl_outputs
[i
].flag
)) continue;
2044 dest
= strmake( "%s%s", obj
, idl_outputs
[i
].ext
);
2045 if (!find_src_file( make
, dest
)) strarray_add( &clean_files
, dest
);
2046 strarray_add( &targets
, dest
);
2048 if (source
->file
->flags
& FLAG_IDL_PROXY
) strarray_add( &dlldata_files
, source
->name
);
2049 output_filenames_obj_dir( make
, targets
);
2050 output( ": %s\n", tools_path( make
, "widl" ));
2051 output( "\t%s -o $@", tools_path( make
, "widl" ) );
2052 output_filenames( target_flags
);
2053 output_filenames( includes
);
2054 output_filenames( make
->define_args
);
2055 output_filenames( extradefs
);
2056 output_filenames( get_expanded_make_var_array( make
, "EXTRAIDLFLAGS" ));
2057 output_filename( source
->filename
);
2059 output_filenames_obj_dir( make
, targets
);
2060 output( ": %s", source
->filename
);
2062 else if (!strcmp( ext
, "in" )) /* .in file or man page */
2064 if (strendswith( obj
, ".man" ) && source
->file
->args
)
2066 struct strarray symlinks
;
2067 char *dir
, *dest
= replace_extension( obj
, ".man", "" );
2068 char *lang
= strchr( dest
, '.' );
2069 char *section
= source
->file
->args
;
2073 dir
= strmake( "$(mandir)/%s/man%s", lang
, section
);
2075 else dir
= strmake( "$(mandir)/man%s", section
);
2076 add_install_rule( make
, dest
, xstrdup(obj
), strmake( "d%s/%s.%s", dir
, dest
, section
));
2077 symlinks
= get_expanded_make_var_array( make
, file_local_var( dest
, "SYMLINKS" ));
2078 for (i
= 0; i
< symlinks
.count
; i
++)
2079 add_install_rule( make
, symlinks
.str
[i
], strmake( "%s.%s", dest
, section
),
2080 strmake( "y%s/%s.%s", dir
, symlinks
.str
[i
], section
));
2083 strarray_add( &all_targets
, xstrdup(obj
) );
2085 else strarray_add( &clean_files
, xstrdup(obj
) );
2086 output( "%s: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2087 output( "\t$(SED_CMD) %s >$@ || ($(RM) $@ && false)\n", source
->filename
);
2088 output( "%s:", obj_dir_path( make
, obj
));
2090 else if (!strcmp( ext
, "sfd" )) /* font file */
2092 char *ttf_file
= src_dir_path( make
, strmake( "%s.ttf", obj
));
2093 if (fontforge
&& !make
->src_dir
)
2095 output( "%s: %s\n", ttf_file
, source
->filename
);
2096 output( "\t%s -script %s %s $@\n",
2097 fontforge
, top_dir_path( make
, "fonts/genttf.ff" ), source
->filename
);
2098 if (!(source
->file
->flags
& FLAG_SFD_FONTS
)) output( "all: %s\n", ttf_file
);
2100 if (source
->file
->flags
& FLAG_INSTALL
)
2102 strarray_add( &make
->install_lib_rules
, strmake( "%s.ttf", obj
));
2103 strarray_add( &make
->install_lib_rules
, strmake( "D$(fontdir)/%s.ttf", obj
));
2105 if (source
->file
->flags
& FLAG_SFD_FONTS
)
2107 struct strarray
*array
= source
->file
->args
;
2109 for (i
= 0; i
< array
->count
; i
++)
2111 char *font
= strtok( xstrdup(array
->str
[i
]), " \t" );
2112 char *args
= strtok( NULL
, "" );
2114 strarray_add( &all_targets
, xstrdup( font
));
2115 output( "%s: %s %s\n", obj_dir_path( make
, font
),
2116 tools_path( make
, "sfnt2fon" ), ttf_file
);
2117 output( "\t%s -o $@ %s %s\n", tools_path( make
, "sfnt2fon" ), ttf_file
, args
);
2118 strarray_add( &make
->install_lib_rules
, xstrdup(font
) );
2119 strarray_add( &make
->install_lib_rules
, strmake( "d$(fontdir)/%s", font
));
2122 continue; /* no dependencies */
2124 else if (!strcmp( ext
, "svg" )) /* svg file */
2126 if (convert
&& rsvg
&& icotool
&& !make
->src_dir
)
2128 output( "%s.ico %s.bmp: %s\n",
2129 src_dir_path( make
, obj
), src_dir_path( make
, obj
), source
->filename
);
2130 output( "\tCONVERT=\"%s\" ICOTOOL=\"%s\" RSVG=\"%s\" %s %s $@\n", convert
, icotool
, rsvg
,
2131 top_dir_path( make
, "tools/buildimage" ), source
->filename
);
2133 continue; /* no dependencies */
2135 else if (!strcmp( ext
, "res" ))
2137 strarray_add( &res_files
, source
->name
);
2138 continue; /* no dependencies */
2140 else if (!strcmp( ext
, "h" ) || !strcmp( ext
, "rh" ) || !strcmp( ext
, "inl" )) /* header file */
2142 if (source
->file
->flags
& FLAG_GENERATED
)
2144 strarray_add( &all_targets
, source
->name
);
2148 strarray_add( &make
->install_dev_rules
, source
->name
);
2149 strarray_add( &make
->install_dev_rules
,
2150 strmake( "D$(includedir)/%s", get_include_install_path( source
->name
) ));
2152 continue; /* no dependencies */
2156 int need_cross
= make
->testdll
||
2157 (source
->file
->flags
& FLAG_C_IMPLIB
) ||
2158 (make
->module
&& make
->staticlib
);
2160 if ((source
->file
->flags
& FLAG_GENERATED
) &&
2161 (!make
->testdll
|| !strendswith( source
->filename
, "testlist.c" )))
2162 strarray_add( &clean_files
, source
->filename
);
2163 if (source
->file
->flags
& FLAG_C_IMPLIB
) strarray_add( &implib_objs
, strmake( "%s.o", obj
));
2164 strarray_add( &object_files
, strmake( "%s.o", obj
));
2165 output( "%s.o: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2166 output( "\t$(CC) -c -o $@ %s", source
->filename
);
2167 output_filenames( includes
);
2168 output_filenames( make
->define_args
);
2169 output_filenames( extradefs
);
2170 if (make
->module
|| make
->staticlib
|| make
->testdll
)
2172 output_filenames( dll_flags
);
2173 if (make
->use_msvcrt
) output_filenames( msvcrt_flags
);
2175 output_filenames( extra_cflags
);
2176 output_filenames( cpp_flags
);
2177 output_filename( "$(CFLAGS)" );
2179 if (crosstarget
&& need_cross
)
2181 strarray_add( &crossobj_files
, strmake( "%s.cross.o", obj
));
2182 output( "%s.cross.o: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2183 output( "\t$(CROSSCC) -c -o $@ %s", source
->filename
);
2184 output_filenames( includes
);
2185 output_filenames( make
->define_args
);
2186 output_filenames( extradefs
);
2187 output_filename( "-DWINE_CROSSTEST" );
2188 output_filenames( cpp_flags
);
2189 output_filename( "$(CFLAGS)" );
2192 if (make
->testdll
&& !strcmp( ext
, "c" ) && !(source
->file
->flags
& FLAG_GENERATED
))
2194 strarray_add( &ok_files
, strmake( "%s.ok", obj
));
2195 output( "%s.ok:\n", obj_dir_path( make
, obj
));
2196 output( "\t%s $(RUNTESTFLAGS) -T %s -M %s -p %s%s %s && touch $@\n",
2197 top_dir_path( make
, "tools/runtest" ), top_obj_dir_path( make
, "" ), make
->testdll
,
2198 replace_extension( make
->testdll
, ".dll", "_test.exe" ), dll_ext
, obj
);
2200 if (!strcmp( ext
, "c" ) && !(source
->file
->flags
& FLAG_GENERATED
))
2201 strarray_add( &c2man_files
, source
->filename
);
2202 output( "%s.o", obj_dir_path( make
, obj
));
2203 if (crosstarget
&& need_cross
) output( " %s.cross.o", obj_dir_path( make
, obj
));
2208 for (i
= 0; i
< source
->files_count
; i
++) output_include( source
->files
[i
], source
);
2212 /* rules for files that depend on multiple sources */
2216 output( "%s: %s", obj_dir_path( make
, "rsrc.pot" ), tools_path( make
, "wrc" ) );
2217 output_filenames( po_files
);
2219 output( "\t%s -O pot -o $@", tools_path( make
, "wrc" ));
2220 if (make
->is_win16
) output_filename( "-m16" );
2221 else output_filenames( target_flags
);
2222 output_filename( "--nostdinc" );
2223 output_filenames( includes
);
2224 output_filenames( make
->define_args
);
2225 output_filenames( po_files
);
2227 strarray_add( &clean_files
, "rsrc.pot" );
2232 output( "%s: %s", obj_dir_path( make
, "msg.pot" ), tools_path( make
, "wmc" ));
2233 output_filenames( mc_files
);
2235 output( "\t%s -O pot -o $@", tools_path( make
, "wmc" ));
2236 output_filenames( mc_files
);
2238 strarray_add( &clean_files
, "msg.pot" );
2241 if (dlldata_files
.count
)
2243 output( "%s: %s %s\n", obj_dir_path( make
, "dlldata.c" ),
2244 tools_path( make
, "widl" ), src_dir_path( make
, "Makefile.in" ));
2245 output( "\t%s --dlldata-only -o $@", tools_path( make
, "widl" ));
2246 output_filenames( dlldata_files
);
2250 if (make
->module
&& !make
->staticlib
)
2252 struct strarray all_libs
= empty_strarray
;
2253 char *module_path
= obj_dir_path( make
, make
->module
);
2254 char *spec_file
= NULL
;
2256 if (!make
->appmode
.count
)
2257 spec_file
= src_dir_path( make
, replace_extension( make
->module
, ".dll", ".spec" ));
2258 for (i
= 0; i
< make
->delayimports
.count
; i
++)
2259 strarray_add( &all_libs
, strmake( "-l%s", make
->delayimports
.str
[i
] ));
2260 for (i
= 0; i
< make
->imports
.count
; i
++)
2261 strarray_add( &all_libs
, strmake( "-l%s", make
->imports
.str
[i
] ));
2262 for (i
= 0; i
< make
->delayimports
.count
; i
++)
2263 strarray_add( &all_libs
, strmake( "-Wb,-d%s", make
->delayimports
.str
[i
] ));
2264 strarray_add( &all_libs
, "-lwine" );
2265 strarray_add( &all_libs
, top_obj_dir_path( make
, "libs/port/libwine_port.a" ));
2266 strarray_addall( &all_libs
, get_expanded_make_var_array( make
, "EXTRALIBS" ));
2267 strarray_addall( &all_libs
, libs
);
2271 strarray_add( &all_targets
, strmake( "%s%s", make
->module
, dll_ext
));
2272 strarray_add( &all_targets
, strmake( "%s.fake", make
->module
));
2273 add_install_rule( make
, make
->module
, strmake( "%s%s", make
->module
, dll_ext
),
2274 strmake( "p$(dlldir)/%s%s", make
->module
, dll_ext
));
2275 add_install_rule( make
, make
->module
, strmake( "%s.fake", make
->module
),
2276 strmake( "d$(fakedlldir)/%s", make
->module
));
2277 output( "%s%s %s.fake:", module_path
, dll_ext
, module_path
);
2281 strarray_add( &all_targets
, make
->module
);
2282 add_install_rule( make
, make
->module
, make
->module
,
2283 strmake( "p$(%s)/%s", spec_file
? "dlldir" : "bindir", make
->module
));
2284 output( "%s:", module_path
);
2286 if (spec_file
) output_filename( spec_file
);
2287 output_filenames_obj_dir( make
, object_files
);
2288 output_filenames_obj_dir( make
, res_files
);
2290 output( "\t%s -o $@", tools_path( make
, "winegcc" ));
2291 output_filename( strmake( "-B%s", tools_dir_path( make
, "winebuild" )));
2292 if (tools_dir
) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make
, "" )));
2293 output_filenames( target_flags
);
2294 output_filenames( unwind_flags
);
2297 output( " -shared %s", spec_file
);
2298 output_filenames( make
->extradllflags
);
2300 else output_filenames( make
->appmode
);
2301 output_filenames_obj_dir( make
, object_files
);
2302 output_filenames_obj_dir( make
, res_files
);
2303 output_filenames( all_libs
);
2304 output_filename( "$(LDFLAGS)" );
2307 if (spec_file
&& make
->importlib
)
2309 char *importlib_path
= obj_dir_path( make
, strmake( "lib%s", make
->importlib
));
2312 strarray_add( &clean_files
, strmake( "lib%s.def", make
->importlib
));
2313 output( "%s.def: %s %s\n", importlib_path
, tools_path( make
, "winebuild" ), spec_file
);
2314 output( "\t%s -w --def -o $@ --export %s", tools_path( make
, "winebuild" ), spec_file
);
2315 output_filenames( target_flags
);
2316 if (make
->is_win16
) output_filename( "-m16" );
2318 add_install_rule( make
, make
->importlib
, strmake( "lib%s.def", make
->importlib
),
2319 strmake( "d$(dlldir)/lib%s.def", make
->importlib
));
2320 if (implib_objs
.count
)
2322 strarray_add( &clean_files
, strmake( "lib%s.def.a", make
->importlib
));
2323 output( "%s.def.a:", importlib_path
);
2324 output_filenames_obj_dir( make
, implib_objs
);
2326 output( "\t$(RM) $@\n" );
2327 output( "\t$(AR) $(ARFLAGS) $@" );
2328 output_filenames_obj_dir( make
, implib_objs
);
2330 output( "\t$(RANLIB) $@\n" );
2331 add_install_rule( make
, make
->importlib
, strmake( "lib%s.def.a", make
->importlib
),
2332 strmake( "d$(dlldir)/lib%s.def.a", make
->importlib
));
2337 strarray_add( &clean_files
, strmake( "lib%s.a", make
->importlib
));
2338 output( "%s.a: %s %s", importlib_path
, tools_path( make
, "winebuild" ), spec_file
);
2339 output_filenames_obj_dir( make
, implib_objs
);
2341 output( "\t%s -w --implib -o $@ --export %s", tools_path( make
, "winebuild" ), spec_file
);
2342 output_filenames( target_flags
);
2343 output_filenames_obj_dir( make
, implib_objs
);
2345 add_install_rule( make
, make
->importlib
, strmake( "lib%s.a", make
->importlib
),
2346 strmake( "d$(dlldir)/lib%s.a", make
->importlib
));
2348 if (crosstarget
&& !make
->is_win16
)
2350 struct strarray cross_files
= strarray_replace_extension( &implib_objs
, ".o", ".cross.o" );
2351 strarray_add( &clean_files
, strmake( "lib%s.cross.a", make
->importlib
));
2352 output( "%s.cross.a: %s %s", importlib_path
, tools_path( make
, "winebuild" ), spec_file
);
2353 output_filenames_obj_dir( make
, cross_files
);
2355 output( "\t%s -b %s -w --implib -o $@ --export %s",
2356 tools_path( make
, "winebuild" ), crosstarget
, spec_file
);
2357 output_filenames_obj_dir( make
, cross_files
);
2364 if (c2man_files
.count
)
2366 output( "manpages::\n" );
2367 output( "\t%s -w %s", top_dir_path( make
, "tools/c2man.pl" ), spec_file
);
2368 output_filename( strmake( "-R%s", top_dir_path( make
, "" )));
2369 output_filename( strmake( "-I%s", top_dir_path( make
, "include" )));
2370 output_filename( strmake( "-o %s/man%s",
2371 top_obj_dir_path( make
, "documentation" ), man_ext
));
2372 output_filenames( c2man_files
);
2374 output( "htmlpages::\n" );
2375 output( "\t%s -Th -w %s", top_dir_path( make
, "tools/c2man.pl" ), spec_file
);
2376 output_filename( strmake( "-R%s", top_dir_path( make
, "" )));
2377 output_filename( strmake( "-I%s", top_dir_path( make
, "include" )));
2378 output_filename( strmake( "-o %s",
2379 top_obj_dir_path( make
, "documentation/html" )));
2380 output_filenames( c2man_files
);
2382 output( "sgmlpages::\n" );
2383 output( "\t%s -Ts -w %s", top_dir_path( make
, "tools/c2man.pl" ), spec_file
);
2384 output_filename( strmake( "-R%s", top_dir_path( make
, "" )));
2385 output_filename( strmake( "-I%s", top_dir_path( make
, "include" )));
2386 output_filename( strmake( "-o %s",
2387 top_obj_dir_path( make
, "documentation/api-guide" )));
2388 output_filenames( c2man_files
);
2390 output( "xmlpages::\n" );
2391 output( "\t%s -Tx -w %s", top_dir_path( make
, "tools/c2man.pl" ), spec_file
);
2392 output_filename( strmake( "-R%s", top_dir_path( make
, "" )));
2393 output_filename( strmake( "-I%s", top_dir_path( make
, "include" )));
2394 output_filename( strmake( "-o %s",
2395 top_obj_dir_path( make
, "documentation/api-guide-xml" )));
2396 output_filenames( c2man_files
);
2398 strarray_add( &phony_targets
, "manpages" );
2399 strarray_add( &phony_targets
, "htmlpages" );
2400 strarray_add( &phony_targets
, "sgmlpages" );
2401 strarray_add( &phony_targets
, "xmlpages" );
2403 else output( "manpages htmlpages sgmlpages xmlpages::\n" );
2407 char *binary
= replace_extension( make
->module
, ".exe", "" );
2408 add_install_rule( make
, binary
, tools_dir_path( make
, "wineapploader" ),
2409 strmake( "s$(bindir)/%s", binary
));
2413 if (make
->staticlib
)
2415 strarray_add( &all_targets
, make
->staticlib
);
2416 output( "%s:", obj_dir_path( make
, make
->staticlib
));
2417 output_filenames_obj_dir( make
, object_files
);
2418 output( "\n\t$(RM) $@\n" );
2419 output( "\t$(AR) $(ARFLAGS) $@" );
2420 output_filenames_obj_dir( make
, object_files
);
2421 output( "\n\t$(RANLIB) $@\n" );
2422 if (crosstarget
&& make
->module
)
2424 char *name
= replace_extension( make
->staticlib
, ".a", ".cross.a" );
2426 strarray_add( &all_targets
, name
);
2427 output( "%s:", obj_dir_path( make
, name
));
2428 output_filenames_obj_dir( make
, crossobj_files
);
2429 output( "\n\t$(RM) $@\n" );
2430 output( "\t%s-ar $(ARFLAGS) $@", crosstarget
);
2431 output_filenames_obj_dir( make
, crossobj_files
);
2432 output( "\n\t%s-ranlib $@\n", crosstarget
);
2438 char *testmodule
= replace_extension( make
->testdll
, ".dll", "_test.exe" );
2439 char *stripped
= replace_extension( make
->testdll
, ".dll", "_test-stripped.exe" );
2440 char *testres
= replace_extension( make
->testdll
, ".dll", "_test.res" );
2441 struct strarray all_libs
= empty_strarray
;
2443 for (i
= 0; i
< make
->imports
.count
; i
++)
2444 strarray_add( &all_libs
, strmake( "-l%s", make
->imports
.str
[i
] ));
2445 strarray_addall( &all_libs
, libs
);
2447 strarray_add( &all_targets
, strmake( "%s%s", testmodule
, dll_ext
));
2448 strarray_add( &clean_files
, strmake( "%s%s", stripped
, dll_ext
));
2449 output( "%s%s:\n", obj_dir_path( make
, testmodule
), dll_ext
);
2450 output( "\t%s -o $@", tools_path( make
, "winegcc" ));
2451 output_filename( strmake( "-B%s", tools_dir_path( make
, "winebuild" )));
2452 if (tools_dir
) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make
, "" )));
2453 output_filenames( target_flags
);
2454 output_filenames( unwind_flags
);
2455 output_filenames( make
->appmode
);
2456 output_filenames_obj_dir( make
, object_files
);
2457 output_filenames_obj_dir( make
, res_files
);
2458 output_filenames( all_libs
);
2459 output_filename( "$(LDFLAGS)" );
2461 output( "%s%s:\n", obj_dir_path( make
, stripped
), dll_ext
);
2462 output( "\t%s -o $@", tools_path( make
, "winegcc" ));
2463 output_filename( strmake( "-B%s", tools_dir_path( make
, "winebuild" )));
2464 if (tools_dir
) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make
, "" )));
2465 output_filenames( target_flags
);
2466 output_filenames( unwind_flags
);
2467 output_filename( strmake( "-Wb,-F,%s", testmodule
));
2468 output_filenames( make
->appmode
);
2469 output_filenames_obj_dir( make
, object_files
);
2470 output_filenames_obj_dir( make
, res_files
);
2471 output_filenames( all_libs
);
2472 output_filename( "$(LDFLAGS)" );
2474 output( "%s%s %s%s:", obj_dir_path( make
, testmodule
), dll_ext
,
2475 obj_dir_path( make
, stripped
), dll_ext
);
2476 output_filenames_obj_dir( make
, object_files
);
2477 output_filenames_obj_dir( make
, res_files
);
2480 output( "all: %s/%s\n", top_obj_dir_path( make
, "programs/winetest" ), testres
);
2481 output( "%s/%s: %s%s\n", top_obj_dir_path( make
, "programs/winetest" ), testres
,
2482 obj_dir_path( make
, stripped
), dll_ext
);
2483 output( "\techo \"%s TESTRES \\\"%s%s\\\"\" | %s -o $@\n",
2484 testmodule
, obj_dir_path( make
, stripped
), dll_ext
, tools_path( make
, "wrc" ));
2488 char *crosstest
= replace_extension( make
->testdll
, ".dll", "_crosstest.exe" );
2490 strarray_add( &clean_files
, crosstest
);
2491 output( "%s: %s\n", obj_dir_path( make
, "crosstest" ), obj_dir_path( make
, crosstest
));
2492 output( "%s:", obj_dir_path( make
, crosstest
));
2493 output_filenames_obj_dir( make
, crossobj_files
);
2494 output_filenames_obj_dir( make
, res_files
);
2496 output( "\t%s -o $@ -b %s", tools_path( make
, "winegcc" ), crosstarget
);
2497 output_filename( strmake( "-B%s", tools_dir_path( make
, "winebuild" )));
2498 if (tools_dir
) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make
, "" )));
2499 output_filename( "--lib-suffix=.cross.a" );
2500 output_filenames_obj_dir( make
, crossobj_files
);
2501 output_filenames_obj_dir( make
, res_files
);
2502 output_filenames( all_libs
);
2503 output_filename( "$(LDFLAGS)" );
2505 strarray_add( &phony_targets
, obj_dir_path( make
, "crosstest" ));
2506 if (make
->obj_dir
) output( "crosstest: %s\n", obj_dir_path( make
, "crosstest" ));
2509 output_filenames_obj_dir( make
, ok_files
);
2510 output( ": %s%s ../%s%s\n", testmodule
, dll_ext
, make
->testdll
, dll_ext
);
2511 output( "check test:" );
2512 output_filenames_obj_dir( make
, ok_files
);
2514 output( "testclean::\n" );
2515 output( "\t$(RM)" );
2516 output_filenames_obj_dir( make
, ok_files
);
2518 strarray_addall( &clean_files
, ok_files
);
2519 strarray_add( &phony_targets
, "check" );
2520 strarray_add( &phony_targets
, "test" );
2521 strarray_add( &phony_targets
, "testclean" );
2522 *testlist_files
= strarray_replace_extension( &ok_files
, ".ok", "" );
2525 for (i
= 0; i
< make
->programs
.count
; i
++)
2527 char *program_installed
= NULL
;
2528 char *program
= strmake( "%s%s", make
->programs
.str
[i
], exe_ext
);
2529 struct strarray all_libs
= empty_strarray
;
2530 struct strarray objs
= get_expanded_make_var_array( make
,
2531 file_local_var( make
->programs
.str
[i
], "OBJS" ));
2532 struct strarray symlinks
= get_expanded_make_var_array( make
,
2533 file_local_var( make
->programs
.str
[i
], "SYMLINKS" ));
2535 if (!objs
.count
) objs
= object_files
;
2536 output( "%s:", obj_dir_path( make
, program
) );
2537 output_filenames_obj_dir( make
, objs
);
2539 output( "\t$(CC) -o $@" );
2540 output_filenames_obj_dir( make
, objs
);
2541 strarray_add( &all_libs
, top_obj_dir_path( make
, "libs/port/libwine_port.a" ));
2542 strarray_addall( &all_libs
, get_expanded_make_var_array( make
, "EXTRALIBS" ));
2543 strarray_addall( &all_libs
, libs
);
2544 strarray_addall( &all_libs
, get_expanded_make_var_array( make
,
2545 file_local_var( make
->programs
.str
[i
], "LDFLAGS" )));
2547 if (strarray_exists( &all_libs
, "-lwine" ))
2549 strarray_add( &all_libs
, strmake( "-L%s", top_obj_dir_path( make
, "libs/wine" )));
2550 if (ldrpath_local
&& ldrpath_install
)
2552 program_installed
= strmake( "%s-installed%s", make
->programs
.str
[i
], exe_ext
);
2553 output_filename( ldrpath_local
);
2554 output_filenames( all_libs
);
2555 output_filename( "$(LDFLAGS)" );
2557 output( "%s:", obj_dir_path( make
, program_installed
) );
2558 output_filenames_obj_dir( make
, objs
);
2560 output( "\t$(CC) -o $@" );
2561 output_filenames_obj_dir( make
, objs
);
2562 output_filename( ldrpath_install
);
2563 strarray_add( &all_targets
, program_installed
);
2567 output_filenames( all_libs
);
2568 output_filename( "$(LDFLAGS)" );
2570 strarray_add( &all_targets
, program
);
2574 output_filenames_obj_dir( make
, symlinks
);
2575 output( ": %s\n", obj_dir_path( make
, program
));
2576 output( "\t$(RM) $@ && $(LN_S) %s $@\n", obj_dir_path( make
, program
));
2577 strarray_addall( &all_targets
, symlinks
);
2580 add_install_rule( make
, program
, program_installed
? program_installed
: program
,
2581 strmake( "p$(bindir)/%s", program
));
2582 for (j
= 0; j
< symlinks
.count
; j
++)
2583 add_install_rule( make
, symlinks
.str
[j
], program
,
2584 strmake( "y$(bindir)/%s%s", symlinks
.str
[j
], exe_ext
));
2587 for (i
= 0; i
< make
->scripts
.count
; i
++)
2588 add_install_rule( make
, make
->scripts
.str
[i
], make
->scripts
.str
[i
],
2589 strmake( "S$(bindir)/%s", make
->scripts
.str
[i
] ));
2591 if (all_targets
.count
)
2594 output_filenames_obj_dir( make
, all_targets
);
2598 output_install_rules( make
, make
->install_lib_rules
, "install-lib", &phony_targets
);
2599 output_install_rules( make
, make
->install_dev_rules
, "install-dev", &phony_targets
);
2601 strarray_addall( &clean_files
, object_files
);
2602 strarray_addall( &clean_files
, crossobj_files
);
2603 strarray_addall( &clean_files
, res_files
);
2604 strarray_addall( &clean_files
, all_targets
);
2605 strarray_addall( &clean_files
, get_expanded_make_var_array( make
, "EXTRA_TARGETS" ));
2607 if (clean_files
.count
)
2609 output( "%s::\n", obj_dir_path( make
, "clean" ));
2610 output( "\t$(RM)" );
2611 output_filenames_obj_dir( make
, clean_files
);
2613 if (make
->obj_dir
) output( "__clean__: %s\n", obj_dir_path( make
, "clean" ));
2614 strarray_add( &phony_targets
, obj_dir_path( make
, "clean" ));
2617 if (make
->top_obj_dir
)
2619 output( "depend:\n" );
2620 output( "\t@cd %s && $(MAKE) %s\n", make
->top_obj_dir
, base_dir_path( make
, "depend" ));
2621 strarray_add( &phony_targets
, "depend" );
2624 if (phony_targets
.count
)
2626 output( ".PHONY:" );
2627 output_filenames( phony_targets
);
2631 for (i
= 0; i
< subdirs
.count
; i
++) create_dir( subdirs
.str
[i
] );
2637 /*******************************************************************
2640 static FILE *create_temp_file( const char *orig
)
2642 char *name
= xmalloc( strlen(orig
) + 13 );
2643 unsigned int i
, id
= getpid();
2647 for (i
= 0; i
< 100; i
++)
2649 sprintf( name
, "%s.tmp%08x", orig
, id
);
2650 if ((fd
= open( name
, O_RDWR
| O_CREAT
| O_EXCL
, 0666 )) != -1)
2652 ret
= fdopen( fd
, "w" );
2655 if (errno
!= EEXIST
) break;
2658 if (!ret
) fatal_error( "failed to create output file for '%s'\n", orig
);
2659 temp_file_name
= name
;
2664 /*******************************************************************
2667 static void rename_temp_file( const char *dest
)
2669 int ret
= rename( temp_file_name
, dest
);
2670 if (ret
== -1 && errno
== EEXIST
)
2672 /* rename doesn't overwrite on windows */
2674 ret
= rename( temp_file_name
, dest
);
2676 if (ret
== -1) fatal_error( "failed to rename output file to '%s'\n", dest
);
2677 temp_file_name
= NULL
;
2681 /*******************************************************************
2682 * are_files_identical
2684 static int are_files_identical( FILE *file1
, FILE *file2
)
2688 char buffer1
[8192], buffer2
[8192];
2689 int size1
= fread( buffer1
, 1, sizeof(buffer1
), file1
);
2690 int size2
= fread( buffer2
, 1, sizeof(buffer2
), file2
);
2691 if (size1
!= size2
) return 0;
2692 if (!size1
) return feof( file1
) && feof( file2
);
2693 if (memcmp( buffer1
, buffer2
, size1
)) return 0;
2698 /*******************************************************************
2699 * rename_temp_file_if_changed
2701 static void rename_temp_file_if_changed( const char *dest
)
2703 FILE *file1
, *file2
;
2706 if ((file1
= fopen( dest
, "r" )))
2708 if ((file2
= fopen( temp_file_name
, "r" )))
2710 do_rename
= !are_files_identical( file1
, file2
);
2717 unlink( temp_file_name
);
2718 temp_file_name
= NULL
;
2720 else rename_temp_file( dest
);
2724 /*******************************************************************
2727 static void output_testlist( const char *dest
, struct strarray files
)
2731 output_file
= create_temp_file( dest
);
2733 output( "/* Automatically generated by make depend; DO NOT EDIT!! */\n\n" );
2734 output( "#define WIN32_LEAN_AND_MEAN\n" );
2735 output( "#include <windows.h>\n\n" );
2736 output( "#define STANDALONE\n" );
2737 output( "#include \"wine/test.h\"\n\n" );
2739 for (i
= 0; i
< files
.count
; i
++) output( "extern void func_%s(void);\n", files
.str
[i
] );
2741 output( "const struct test winetest_testlist[] =\n" );
2743 for (i
= 0; i
< files
.count
; i
++) output( " { \"%s\", func_%s },\n", files
.str
[i
], files
.str
[i
] );
2744 output( " { 0, 0 }\n" );
2747 if (fclose( output_file
)) fatal_perror( "write" );
2749 rename_temp_file_if_changed( dest
);
2753 /*******************************************************************
2756 static void output_gitignore( const char *dest
, struct strarray files
)
2760 output_file
= create_temp_file( dest
);
2762 output( "# Automatically generated by make depend; DO NOT EDIT!!\n" );
2763 for (i
= 0; i
< files
.count
; i
++)
2765 if (!strchr( files
.str
[i
], '/' )) output( "/" );
2766 output( "%s\n", files
.str
[i
] );
2769 if (fclose( output_file
)) fatal_perror( "write" );
2771 rename_temp_file( dest
);
2775 /*******************************************************************
2776 * output_top_variables
2778 static void output_top_variables( struct makefile
*make
)
2781 struct strarray
*vars
= &top_makefile
->vars
;
2783 if (!make
->base_dir
) return; /* don't output variables in the top makefile */
2785 output( "# Automatically generated by make depend; DO NOT EDIT!!\n\n" );
2786 output( "all:\n\n" );
2787 for (i
= 0; i
< vars
->count
; i
+= 2)
2788 output( "%s = %s\n", vars
->str
[i
], get_make_variable( make
, vars
->str
[i
] ));
2793 /*******************************************************************
2794 * output_dependencies
2796 static void output_dependencies( struct makefile
*make
)
2798 struct strarray targets
, testlist_files
= empty_strarray
, ignore_files
= empty_strarray
;
2802 output_file_name
= base_dir_path( make
, output_makefile_name
);
2803 output_file
= create_temp_file( output_file_name
);
2804 output_top_variables( make
);
2806 /* copy the contents of the source makefile */
2807 src_file
= open_input_makefile( make
);
2808 while (fgets( buffer
, sizeof(buffer
), src_file
))
2809 if (fwrite( buffer
, 1, strlen(buffer
), output_file
) != strlen(buffer
)) fatal_perror( "write" );
2810 if (fclose( src_file
)) fatal_perror( "close" );
2811 input_file_name
= NULL
;
2813 targets
= output_sources( make
, &testlist_files
);
2815 fclose( output_file
);
2817 rename_temp_file( output_file_name
);
2819 strarray_add( &ignore_files
, ".gitignore" );
2820 strarray_add( &ignore_files
, "Makefile" );
2821 if (testlist_files
.count
) strarray_add( &ignore_files
, "testlist.c" );
2822 strarray_addall( &ignore_files
, targets
);
2824 if (testlist_files
.count
)
2825 output_testlist( base_dir_path( make
, "testlist.c" ), testlist_files
);
2826 if (!make
->src_dir
&& make
->base_dir
)
2827 output_gitignore( base_dir_path( make
, ".gitignore" ), ignore_files
);
2829 output_file_name
= NULL
;
2833 /*******************************************************************
2836 static void update_makefile( const char *path
)
2838 static const char *source_vars
[] =
2857 struct strarray value
;
2858 struct incl_file
*file
;
2859 struct makefile
*make
;
2861 make
= parse_makefile( path
, NULL
);
2865 make
->top_src_dir
= concat_paths( make
->top_obj_dir
, root_src_dir
);
2866 make
->src_dir
= concat_paths( make
->top_src_dir
, make
->base_dir
);
2868 strarray_set_value( &make
->vars
, "top_builddir", top_obj_dir_path( make
, "" ));
2869 strarray_set_value( &make
->vars
, "top_srcdir", top_dir_path( make
, "" ));
2870 strarray_set_value( &make
->vars
, "srcdir", src_dir_path( make
, "" ));
2872 make
->parent_dir
= get_expanded_make_variable( make
, "PARENTSRC" );
2873 make
->module
= get_expanded_make_variable( make
, "MODULE" );
2874 make
->testdll
= get_expanded_make_variable( make
, "TESTDLL" );
2875 make
->staticlib
= get_expanded_make_variable( make
, "STATICLIB" );
2876 make
->importlib
= get_expanded_make_variable( make
, "IMPORTLIB" );
2878 make
->programs
= get_expanded_make_var_array( make
, "PROGRAMS" );
2879 make
->scripts
= get_expanded_make_var_array( make
, "SCRIPTS" );
2880 make
->appmode
= get_expanded_make_var_array( make
, "APPMODE" );
2881 make
->imports
= get_expanded_make_var_array( make
, "IMPORTS" );
2882 make
->delayimports
= get_expanded_make_var_array( make
, "DELAYIMPORTS" );
2883 make
->extradllflags
= get_expanded_make_var_array( make
, "EXTRADLLFLAGS" );
2884 make
->install_lib
= get_expanded_make_var_array( make
, "INSTALL_LIB" );
2885 make
->install_dev
= get_expanded_make_var_array( make
, "INSTALL_DEV" );
2887 if (make
->module
&& strendswith( make
->module
, ".a" )) make
->staticlib
= make
->module
;
2889 make
->is_win16
= strarray_exists( &make
->extradllflags
, "-m16" );
2890 make
->use_msvcrt
= strarray_exists( &make
->appmode
, "-mno-cygwin" );
2892 for (i
= 0; i
< make
->imports
.count
&& !make
->use_msvcrt
; i
++)
2893 make
->use_msvcrt
= !strncmp( make
->imports
.str
[i
], "msvcr", 5 );
2895 make
->install_lib_rules
= empty_strarray
;
2896 make
->install_dev_rules
= empty_strarray
;
2897 if (make
->module
&& !make
->install_lib
.count
) strarray_add( &make
->install_lib
, make
->module
);
2899 make
->include_args
= empty_strarray
;
2900 make
->define_args
= empty_strarray
;
2901 strarray_add( &make
->define_args
, "-D__WINESRC__" );
2903 value
= get_expanded_make_var_array( make
, "EXTRAINCL" );
2904 for (i
= 0; i
< value
.count
; i
++)
2905 if (!strncmp( value
.str
[i
], "-I", 2 ))
2906 strarray_add_uniq( &make
->include_args
, value
.str
[i
] );
2908 strarray_add_uniq( &make
->define_args
, value
.str
[i
] );
2909 strarray_addall( &make
->define_args
, get_expanded_make_var_array( make
, "EXTRADEFS" ));
2911 list_init( &make
->sources
);
2912 list_init( &make
->includes
);
2914 /* FIXME: target dir has to exist to allow locating srcdir-relative include files */
2915 if (make
->base_dir
) create_dir( make
->base_dir
);
2917 for (var
= source_vars
; *var
; var
++)
2919 value
= get_expanded_make_var_array( make
, *var
);
2920 for (i
= 0; i
< value
.count
; i
++) add_src_file( make
, value
.str
[i
] );
2923 add_generated_sources( make
);
2925 value
= get_expanded_make_var_array( make
, "EXTRA_OBJS" );
2926 for (i
= 0; i
< value
.count
; i
++)
2928 /* default to .c for unknown extra object files */
2929 if (strendswith( value
.str
[i
], ".o" ))
2930 add_generated_source( make
, value
.str
[i
], replace_extension( value
.str
[i
], ".o", ".c" ) );
2932 add_generated_source( make
, value
.str
[i
], NULL
);
2935 LIST_FOR_EACH_ENTRY( file
, &make
->includes
, struct incl_file
, entry
) parse_file( make
, file
, 0 );
2937 output_dependencies( make
);
2941 /*******************************************************************
2944 static void parse_makeflags( const char *flags
)
2946 const char *p
= flags
;
2947 char *var
, *buffer
= xmalloc( strlen(flags
) + 1 );
2951 while (isspace(*p
)) p
++;
2953 while (*p
&& !isspace(*p
))
2955 if (*p
== '\\' && p
[1]) p
++;
2959 if (var
> buffer
) set_make_variable( &cmdline_vars
, buffer
);
2964 /*******************************************************************
2967 static int parse_option( const char *opt
)
2971 if (strchr( opt
, '=' )) return set_make_variable( &cmdline_vars
, opt
);
2977 if (opt
[2]) output_makefile_name
= opt
+ 2;
2980 if (opt
[2]) input_makefile_name
= opt
+ 2;
2983 relative_dir_mode
= 1;
2986 fprintf( stderr
, "Unknown option '%s'\n%s", opt
, Usage
);
2993 /*******************************************************************
2996 int main( int argc
, char *argv
[] )
2998 const char *makeflags
= getenv( "MAKEFLAGS" );
3001 if (makeflags
) parse_makeflags( makeflags
);
3006 if (parse_option( argv
[i
] ))
3008 for (j
= i
; j
< argc
; j
++) argv
[j
] = argv
[j
+1];
3014 if (relative_dir_mode
)
3020 fprintf( stderr
, "Option -r needs two directories\n%s", Usage
);
3023 relpath
= get_relative_path( argv
[1], argv
[2] );
3024 printf( "%s\n", relpath
? relpath
: "." );
3030 fprintf( stderr
, "%s", Usage
);
3033 atexit( cleanup_files
);
3034 signal( SIGTERM
, exit_on_signal
);
3035 signal( SIGINT
, exit_on_signal
);
3037 signal( SIGHUP
, exit_on_signal
);
3040 for (i
= 0; i
< HASH_SIZE
; i
++) list_init( &files
[i
] );
3042 if (!input_makefile_name
) input_makefile_name
= strmake( "%s.in", output_makefile_name
);
3044 top_makefile
= parse_makefile( NULL
, "# End of common header" );
3046 linguas
= get_expanded_make_var_array( top_makefile
, "LINGUAS" );
3047 target_flags
= get_expanded_make_var_array( top_makefile
, "TARGETFLAGS" );
3048 msvcrt_flags
= get_expanded_make_var_array( top_makefile
, "MSVCRTFLAGS" );
3049 dll_flags
= get_expanded_make_var_array( top_makefile
, "DLLFLAGS" );
3050 extra_cflags
= get_expanded_make_var_array( top_makefile
, "EXTRACFLAGS" );
3051 cpp_flags
= get_expanded_make_var_array( top_makefile
, "CPPFLAGS" );
3052 unwind_flags
= get_expanded_make_var_array( top_makefile
, "UNWINDFLAGS" );
3053 libs
= get_expanded_make_var_array( top_makefile
, "LIBS" );
3055 root_src_dir
= get_expanded_make_variable( top_makefile
, "srcdir" );
3056 tools_dir
= get_expanded_make_variable( top_makefile
, "TOOLSDIR" );
3057 tools_ext
= get_expanded_make_variable( top_makefile
, "TOOLSEXT" );
3058 exe_ext
= get_expanded_make_variable( top_makefile
, "EXEEXT" );
3059 man_ext
= get_expanded_make_variable( top_makefile
, "api_manext" );
3060 dll_ext
= (exe_ext
&& !strcmp( exe_ext
, ".exe" )) ? "" : ".so";
3061 dll_prefix
= get_expanded_make_variable( top_makefile
, "DLLPREFIX" );
3062 crosstarget
= get_expanded_make_variable( top_makefile
, "CROSSTARGET" );
3063 fontforge
= get_expanded_make_variable( top_makefile
, "FONTFORGE" );
3064 convert
= get_expanded_make_variable( top_makefile
, "CONVERT" );
3065 rsvg
= get_expanded_make_variable( top_makefile
, "RSVG" );
3066 icotool
= get_expanded_make_variable( top_makefile
, "ICOTOOL" );
3068 if (root_src_dir
&& !strcmp( root_src_dir
, "." )) root_src_dir
= NULL
;
3069 if (tools_dir
&& !strcmp( tools_dir
, "." )) tools_dir
= NULL
;
3070 if (!exe_ext
) exe_ext
= "";
3071 if (!tools_ext
) tools_ext
= "";
3072 if (!dll_prefix
) dll_prefix
= "";
3073 if (!man_ext
) man_ext
= "3w";
3075 for (i
= 1; i
< argc
; i
++) update_makefile( argv
[i
] );