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 );
1124 /*******************************************************************
1127 static struct file
*load_file( const char *name
)
1131 unsigned int hash
= hash_filename( name
);
1133 LIST_FOR_EACH_ENTRY( file
, &files
[hash
], struct file
, entry
)
1134 if (!strcmp( name
, file
->name
)) return file
;
1136 if (!(f
= fopen( name
, "r" ))) return NULL
;
1138 file
= add_file( name
);
1139 input_file_name
= file
->name
;
1142 if (strendswith( name
, ".idl" )) parse_idl_file( file
, f
);
1143 else if (strendswith( name
, ".rc" )) parse_rc_file( file
, f
);
1144 else if (strendswith( name
, ".in" )) parse_in_file( file
, f
);
1145 else if (strendswith( name
, ".sfd" )) parse_sfd_file( file
, f
);
1146 else if (strendswith( name
, ".c" ) ||
1147 strendswith( name
, ".m" ) ||
1148 strendswith( name
, ".h" ) ||
1149 strendswith( name
, ".l" ) ||
1150 strendswith( name
, ".y" )) parse_c_file( file
, f
);
1153 input_file_name
= NULL
;
1159 /*******************************************************************
1162 static struct file
*open_file( struct makefile
*make
, const char *path
, char **filename
)
1164 struct file
*ret
= load_file( base_dir_path( make
, path
));
1166 if (ret
) *filename
= xstrdup( path
);
1171 /*******************************************************************
1174 * Open a file in the source directory of the makefile.
1176 static struct file
*open_local_file( struct makefile
*make
, const char *path
, char **filename
)
1178 char *src_path
= root_dir_path( base_dir_path( make
, path
));
1179 struct file
*ret
= load_file( src_path
);
1181 /* if not found, try parent dir */
1182 if (!ret
&& make
->parent_dir
)
1185 path
= strmake( "%s/%s", make
->parent_dir
, path
);
1186 src_path
= root_dir_path( base_dir_path( make
, path
));
1187 ret
= load_file( src_path
);
1190 if (ret
) *filename
= src_dir_path( make
, path
);
1196 /*******************************************************************
1199 * Open a file in the top-level source directory.
1201 static struct file
*open_global_file( struct makefile
*make
, const char *path
, char **filename
)
1203 char *src_path
= root_dir_path( path
);
1204 struct file
*ret
= load_file( src_path
);
1206 if (ret
) *filename
= top_dir_path( make
, path
);
1212 /*******************************************************************
1213 * open_global_header
1215 * Open a file in the global include source directory.
1217 static struct file
*open_global_header( struct makefile
*make
, const char *path
, char **filename
)
1219 return open_global_file( make
, strmake( "include/%s", path
), filename
);
1223 /*******************************************************************
1226 static struct file
*open_src_file( struct makefile
*make
, struct incl_file
*pFile
)
1228 struct file
*file
= open_local_file( make
, pFile
->name
, &pFile
->filename
);
1230 if (!file
) fatal_perror( "open %s", pFile
->name
);
1235 /*******************************************************************
1238 static struct file
*open_include_file( struct makefile
*make
, struct incl_file
*pFile
)
1240 struct file
*file
= NULL
;
1242 unsigned int i
, len
;
1246 /* check for generated bison header */
1248 if (strendswith( pFile
->name
, ".tab.h" ) &&
1249 (file
= open_local_file( make
, replace_extension( pFile
->name
, ".tab.h", ".y" ), &filename
)))
1251 pFile
->sourcename
= filename
;
1252 pFile
->filename
= obj_dir_path( make
, pFile
->name
);
1256 /* check for corresponding idl file in source dir */
1258 if (strendswith( pFile
->name
, ".h" ) &&
1259 (file
= open_local_file( make
, replace_extension( pFile
->name
, ".h", ".idl" ), &filename
)))
1261 pFile
->sourcename
= filename
;
1262 pFile
->filename
= obj_dir_path( make
, pFile
->name
);
1266 /* now try in source dir */
1267 if ((file
= open_local_file( make
, pFile
->name
, &pFile
->filename
))) return file
;
1269 /* check for corresponding idl file in global includes */
1271 if (strendswith( pFile
->name
, ".h" ) &&
1272 (file
= open_global_header( make
, replace_extension( pFile
->name
, ".h", ".idl" ), &filename
)))
1274 pFile
->sourcename
= filename
;
1275 pFile
->filename
= top_obj_dir_path( make
, strmake( "include/%s", pFile
->name
));
1279 /* check for corresponding .in file in global includes (for config.h.in) */
1281 if (strendswith( pFile
->name
, ".h" ) &&
1282 (file
= open_global_header( make
, replace_extension( pFile
->name
, ".h", ".h.in" ), &filename
)))
1284 pFile
->sourcename
= filename
;
1285 pFile
->filename
= top_obj_dir_path( make
, strmake( "include/%s", pFile
->name
));
1289 /* check for corresponding .x file in global includes */
1291 if (strendswith( pFile
->name
, "tmpl.h" ) &&
1292 (file
= open_global_header( make
, replace_extension( pFile
->name
, ".h", ".x" ), &filename
)))
1294 pFile
->sourcename
= filename
;
1295 pFile
->filename
= top_obj_dir_path( make
, strmake( "include/%s", pFile
->name
));
1299 /* check in global includes source dir */
1301 if ((file
= open_global_header( make
, pFile
->name
, &pFile
->filename
))) return file
;
1303 /* check in global msvcrt includes */
1304 if (make
->use_msvcrt
&&
1305 (file
= open_global_header( make
, strmake( "msvcrt/%s", pFile
->name
), &pFile
->filename
)))
1308 /* now search in include paths */
1309 for (i
= 0; i
< make
->include_args
.count
; i
++)
1311 const char *dir
= make
->include_args
.str
[i
] + 2; /* skip -I */
1312 const char *prefix
= make
->top_src_dir
? make
->top_src_dir
: make
->top_obj_dir
;
1316 len
= strlen( prefix
);
1317 if (!strncmp( dir
, prefix
, len
) && (!dir
[len
] || dir
[len
] == '/'))
1319 while (dir
[len
] == '/') len
++;
1320 file
= open_global_file( make
, concat_paths( dir
+ len
, pFile
->name
), &pFile
->filename
);
1321 if (file
) return file
;
1323 if (make
->top_src_dir
) continue; /* ignore paths that don't point to the top source dir */
1327 if ((file
= open_file( make
, concat_paths( dir
, pFile
->name
), &pFile
->filename
)))
1331 if (pFile
->system
) return NULL
; /* ignore system files we cannot find */
1333 /* try in src file directory */
1334 if ((p
= strrchr(pFile
->included_by
->filename
, '/')))
1336 int l
= p
- pFile
->included_by
->filename
+ 1;
1337 filename
= xmalloc(l
+ strlen(pFile
->name
) + 1);
1338 memcpy( filename
, pFile
->included_by
->filename
, l
);
1339 strcpy( filename
+ l
, pFile
->name
);
1340 if ((file
= open_file( make
, filename
, &pFile
->filename
))) return file
;
1344 fprintf( stderr
, "%s:%d: error: ", pFile
->included_by
->file
->name
, pFile
->included_line
);
1345 perror( pFile
->name
);
1346 pFile
= pFile
->included_by
;
1347 while (pFile
&& pFile
->included_by
)
1349 const char *parent
= pFile
->included_by
->sourcename
;
1350 if (!parent
) parent
= pFile
->included_by
->file
->name
;
1351 fprintf( stderr
, "%s:%d: note: %s was first included here\n",
1352 parent
, pFile
->included_line
, pFile
->name
);
1353 pFile
= pFile
->included_by
;
1359 /*******************************************************************
1362 static void add_all_includes( struct makefile
*make
, struct incl_file
*parent
, struct file
*file
)
1366 parent
->files_count
= 0;
1367 parent
->files_size
= file
->deps_count
;
1368 parent
->files
= xmalloc( parent
->files_size
* sizeof(*parent
->files
) );
1369 for (i
= 0; i
< file
->deps_count
; i
++)
1371 switch (file
->deps
[i
].type
)
1375 add_include( make
, parent
, file
->deps
[i
].name
, file
->deps
[i
].line
, 0 );
1378 add_include( make
, parent
, file
->deps
[i
].name
, file
->deps
[i
].line
, 1 );
1380 case INCL_CPP_QUOTE
:
1381 case INCL_CPP_QUOTE_SYSTEM
:
1388 /*******************************************************************
1391 static void parse_file( struct makefile
*make
, struct incl_file
*source
, int src
)
1395 /* don't try to open certain types of files */
1396 if (strendswith( source
->name
, ".tlb" ))
1398 source
->filename
= obj_dir_path( make
, source
->name
);
1402 file
= src
? open_src_file( make
, source
) : open_include_file( make
, source
);
1405 source
->file
= file
;
1406 source
->files_count
= 0;
1407 source
->files_size
= file
->deps_count
;
1408 source
->files
= xmalloc( source
->files_size
* sizeof(*source
->files
) );
1410 if (source
->sourcename
)
1412 if (strendswith( source
->sourcename
, ".idl" ))
1416 /* generated .h file always includes these */
1417 add_include( make
, source
, "rpc.h", 0, 1 );
1418 add_include( make
, source
, "rpcndr.h", 0, 1 );
1419 for (i
= 0; i
< file
->deps_count
; i
++)
1421 switch (file
->deps
[i
].type
)
1424 if (strendswith( file
->deps
[i
].name
, ".idl" ))
1425 add_include( make
, source
, replace_extension( file
->deps
[i
].name
, ".idl", ".h" ),
1426 file
->deps
[i
].line
, 0 );
1428 add_include( make
, source
, file
->deps
[i
].name
, file
->deps
[i
].line
, 0 );
1430 case INCL_CPP_QUOTE
:
1431 add_include( make
, source
, file
->deps
[i
].name
, file
->deps
[i
].line
, 0 );
1433 case INCL_CPP_QUOTE_SYSTEM
:
1434 add_include( make
, source
, file
->deps
[i
].name
, file
->deps
[i
].line
, 1 );
1443 if (strendswith( source
->sourcename
, ".y" ))
1444 return; /* generated .tab.h doesn't include anything */
1447 add_all_includes( make
, source
, file
);
1451 /*******************************************************************
1454 * Add a source file to the list.
1456 static struct incl_file
*add_src_file( struct makefile
*make
, const char *name
)
1458 struct incl_file
*file
;
1460 if ((file
= find_src_file( make
, name
))) return file
; /* we already have it */
1461 file
= xmalloc( sizeof(*file
) );
1462 memset( file
, 0, sizeof(*file
) );
1463 file
->name
= xstrdup(name
);
1464 list_add_tail( &make
->sources
, &file
->entry
);
1465 parse_file( make
, file
, 1 );
1470 /*******************************************************************
1471 * open_input_makefile
1473 static FILE *open_input_makefile( struct makefile
*make
)
1478 input_file_name
= base_dir_path( make
, input_makefile_name
);
1480 input_file_name
= output_makefile_name
; /* always use output name for main Makefile */
1483 if (!(ret
= fopen( input_file_name
, "r" )))
1485 input_file_name
= root_dir_path( input_file_name
);
1486 if (!(ret
= fopen( input_file_name
, "r" ))) fatal_perror( "open" );
1492 /*******************************************************************
1495 static char *get_make_variable( struct makefile
*make
, const char *name
)
1499 if ((ret
= strarray_get_value( &cmdline_vars
, name
))) return ret
;
1500 if ((ret
= strarray_get_value( &make
->vars
, name
))) return ret
;
1501 if (top_makefile
&& (ret
= strarray_get_value( &top_makefile
->vars
, name
))) return ret
;
1506 /*******************************************************************
1507 * get_expanded_make_variable
1509 static char *get_expanded_make_variable( struct makefile
*make
, const char *name
)
1511 char *p
, *end
, *var
, *expand
, *tmp
;
1513 expand
= get_make_variable( make
, name
);
1514 if (!expand
) return NULL
;
1517 while ((p
= strchr( p
, '$' )))
1521 if (!(end
= strchr( p
+ 2, ')' ))) fatal_error( "syntax error in '%s'\n", expand
);
1523 if (strchr( p
+ 2, ':' )) fatal_error( "pattern replacement not supported for '%s'\n", p
+ 2 );
1524 var
= get_make_variable( make
, p
+ 2 );
1525 tmp
= replace_substr( expand
, p
, end
- p
, var
? var
: "" );
1527 /* switch to the new string */
1528 p
= tmp
+ (p
- expand
);
1532 else if (p
[1] == '{') /* don't expand ${} variables */
1534 if (!(end
= strchr( p
+ 2, '}' ))) fatal_error( "syntax error in '%s'\n", expand
);
1537 else if (p
[1] == '$')
1541 else fatal_error( "syntax error in '%s'\n", expand
);
1544 /* consider empty variables undefined */
1546 while (*p
&& isspace(*p
)) p
++;
1547 if (*p
) return expand
;
1553 /*******************************************************************
1554 * get_expanded_make_var_array
1556 static struct strarray
get_expanded_make_var_array( struct makefile
*make
, const char *name
)
1558 struct strarray ret
= empty_strarray
;
1559 char *value
, *token
;
1561 if ((value
= get_expanded_make_variable( make
, name
)))
1562 for (token
= strtok( value
, " \t" ); token
; token
= strtok( NULL
, " \t" ))
1563 strarray_add( &ret
, token
);
1568 /*******************************************************************
1571 static char *file_local_var( const char *file
, const char *name
)
1575 var
= strmake( "%s_%s", file
, name
);
1576 for (p
= var
; *p
; p
++) if (!isalnum( *p
)) *p
= '_';
1581 /*******************************************************************
1584 static int set_make_variable( struct strarray
*array
, const char *assignment
)
1588 p
= name
= xstrdup( assignment
);
1589 while (isalnum(*p
) || *p
== '_') p
++;
1590 if (name
== p
) return 0; /* not a variable */
1594 while (isspace(*p
)) p
++;
1596 if (*p
!= '=') return 0; /* not an assignment */
1598 while (isspace(*p
)) p
++;
1600 strarray_set_value( array
, name
, p
);
1605 /*******************************************************************
1608 static struct makefile
*parse_makefile( const char *path
, const char *separator
)
1612 struct makefile
*make
= xmalloc( sizeof(*make
) );
1614 memset( make
, 0, sizeof(*make
) );
1617 make
->top_obj_dir
= get_relative_path( path
, "" );
1618 make
->base_dir
= path
;
1619 if (!strcmp( make
->base_dir
, "." )) make
->base_dir
= NULL
;
1622 file
= open_input_makefile( make
);
1623 while ((buffer
= get_line( file
)))
1625 if (separator
&& !strncmp( buffer
, separator
, strlen(separator
) )) break;
1626 if (*buffer
== '\t') continue; /* command */
1627 while (isspace( *buffer
)) buffer
++;
1628 if (*buffer
== '#') continue; /* comment */
1629 set_make_variable( &make
->vars
, buffer
);
1632 input_file_name
= NULL
;
1637 /*******************************************************************
1638 * add_generated_sources
1640 static void add_generated_sources( struct makefile
*make
)
1642 struct incl_file
*source
, *next
, *file
;
1644 LIST_FOR_EACH_ENTRY_SAFE( source
, next
, &make
->sources
, struct incl_file
, entry
)
1646 if (source
->file
->flags
& FLAG_IDL_CLIENT
)
1648 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_c.c" ), NULL
);
1649 add_dependency( file
->file
, replace_extension( source
->name
, ".idl", ".h" ), INCL_NORMAL
);
1650 add_all_includes( make
, file
, file
->file
);
1652 if (source
->file
->flags
& FLAG_IDL_SERVER
)
1654 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_s.c" ), NULL
);
1655 add_dependency( file
->file
, "wine/exception.h", INCL_NORMAL
);
1656 add_dependency( file
->file
, replace_extension( source
->name
, ".idl", ".h" ), INCL_NORMAL
);
1657 add_all_includes( make
, file
, file
->file
);
1659 if (source
->file
->flags
& FLAG_IDL_IDENT
)
1661 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_i.c" ), NULL
);
1662 add_dependency( file
->file
, "rpc.h", INCL_NORMAL
);
1663 add_dependency( file
->file
, "rpcndr.h", INCL_NORMAL
);
1664 add_dependency( file
->file
, "guiddef.h", INCL_NORMAL
);
1665 add_all_includes( make
, file
, file
->file
);
1667 if (source
->file
->flags
& FLAG_IDL_PROXY
)
1669 file
= add_generated_source( make
, "dlldata.o", "dlldata.c" );
1670 add_dependency( file
->file
, "objbase.h", INCL_NORMAL
);
1671 add_dependency( file
->file
, "rpcproxy.h", INCL_NORMAL
);
1672 add_all_includes( make
, file
, file
->file
);
1673 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_p.c" ), NULL
);
1674 add_dependency( file
->file
, "objbase.h", INCL_NORMAL
);
1675 add_dependency( file
->file
, "rpcproxy.h", INCL_NORMAL
);
1676 add_dependency( file
->file
, "wine/exception.h", INCL_NORMAL
);
1677 add_dependency( file
->file
, replace_extension( source
->name
, ".idl", ".h" ), INCL_NORMAL
);
1678 add_all_includes( make
, file
, file
->file
);
1680 if (source
->file
->flags
& FLAG_IDL_REGTYPELIB
)
1682 add_generated_source( make
, replace_extension( source
->name
, ".idl", "_t.res" ), NULL
);
1684 if (source
->file
->flags
& FLAG_IDL_REGISTER
)
1686 add_generated_source( make
, replace_extension( source
->name
, ".idl", "_r.res" ), NULL
);
1688 if (strendswith( source
->name
, ".y" ))
1690 file
= add_generated_source( make
, replace_extension( source
->name
, ".y", ".tab.c" ), NULL
);
1691 /* steal the includes list from the source file */
1692 file
->files_count
= source
->files_count
;
1693 file
->files_size
= source
->files_size
;
1694 file
->files
= source
->files
;
1695 source
->files_count
= source
->files_size
= 0;
1696 source
->files
= NULL
;
1698 if (strendswith( source
->name
, ".l" ))
1700 file
= add_generated_source( make
, replace_extension( source
->name
, ".l", ".yy.c" ), NULL
);
1701 /* steal the includes list from the source file */
1702 file
->files_count
= source
->files_count
;
1703 file
->files_size
= source
->files_size
;
1704 file
->files
= source
->files
;
1705 source
->files_count
= source
->files_size
= 0;
1706 source
->files
= NULL
;
1709 if (get_make_variable( make
, "TESTDLL" ))
1711 file
= add_generated_source( make
, "testlist.o", "testlist.c" );
1712 add_dependency( file
->file
, "wine/test.h", INCL_NORMAL
);
1713 add_all_includes( make
, file
, file
->file
);
1718 /*******************************************************************
1721 static void create_dir( const char *dir
)
1725 p
= path
= xstrdup( dir
);
1726 while ((p
= strchr( p
, '/' )))
1729 if (mkdir( path
, 0755 ) == -1 && errno
!= EEXIST
) fatal_perror( "mkdir %s", path
);
1731 while (*p
== '/') p
++;
1733 if (mkdir( path
, 0755 ) == -1 && errno
!= EEXIST
) fatal_perror( "mkdir %s", path
);
1738 /*******************************************************************
1739 * output_filenames_obj_dir
1741 static void output_filenames_obj_dir( struct makefile
*make
, struct strarray array
)
1745 for (i
= 0; i
< array
.count
; i
++) output_filename( obj_dir_path( make
, array
.str
[i
] ));
1749 /*******************************************************************
1752 static void output_include( struct incl_file
*pFile
, struct incl_file
*owner
)
1756 if (pFile
->owner
== owner
) return;
1757 if (!pFile
->filename
) return;
1758 pFile
->owner
= owner
;
1759 output_filename( pFile
->filename
);
1760 for (i
= 0; i
< pFile
->files_count
; i
++) output_include( pFile
->files
[i
], owner
);
1764 /*******************************************************************
1767 static void add_install_rule( struct makefile
*make
, const char *target
,
1768 const char *file
, const char *dest
)
1770 if (strarray_exists( &make
->install_lib
, target
))
1772 strarray_add( &make
->install_lib_rules
, file
);
1773 strarray_add( &make
->install_lib_rules
, dest
);
1775 else if (strarray_exists( &make
->install_dev
, target
))
1777 strarray_add( &make
->install_dev_rules
, file
);
1778 strarray_add( &make
->install_dev_rules
, dest
);
1783 /*******************************************************************
1784 * output_install_rules
1786 * Rules are stored as a (file,dest) pair of values.
1787 * The first char of dest indicates the type of install.
1789 static void output_install_rules( struct makefile
*make
, struct strarray files
,
1790 const char *target
, struct strarray
*phony_targets
)
1794 struct strarray targets
= empty_strarray
;
1796 if (!files
.count
) return;
1798 for (i
= 0; i
< files
.count
; i
+= 2)
1799 if (strchr( "dps", files
.str
[i
+ 1][0] )) /* only for files copied from object dir */
1800 strarray_add_uniq( &targets
, files
.str
[i
] );
1802 output( "install %s::", target
);
1803 output_filenames_obj_dir( make
, targets
);
1806 install_sh
= top_dir_path( make
, "tools/install-sh" );
1807 for (i
= 0; i
< files
.count
; i
+= 2)
1809 const char *file
= files
.str
[i
];
1810 const char *dest
= files
.str
[i
+ 1];
1814 case 'd': /* data file */
1815 output( "\t%s -m 644 $(INSTALL_DATA_FLAGS) %s $(DESTDIR)%s\n",
1816 install_sh
, obj_dir_path( make
, file
), dest
+ 1 );
1818 case 'D': /* data file in source dir */
1819 output( "\t%s -m 644 $(INSTALL_DATA_FLAGS) %s $(DESTDIR)%s\n",
1820 install_sh
, src_dir_path( make
, file
), dest
+ 1 );
1822 case 'p': /* program file */
1823 output( "\tSTRIPPROG=\"$(STRIP)\" %s $(INSTALL_PROGRAM_FLAGS) %s $(DESTDIR)%s\n",
1824 install_sh
, obj_dir_path( make
, file
), dest
+ 1 );
1826 case 's': /* script */
1827 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s $(DESTDIR)%s\n",
1828 install_sh
, obj_dir_path( make
, file
), dest
+ 1 );
1830 case 'S': /* script in source dir */
1831 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s $(DESTDIR)%s\n",
1832 install_sh
, src_dir_path( make
, file
), dest
+ 1 );
1834 case 'y': /* symlink */
1835 output( "\t$(RM) $(DESTDIR)%s && $(LN_S) %s $(DESTDIR)%s\n", dest
+ 1, file
, dest
+ 1 );
1842 output( "uninstall::\n" );
1843 output( "\t$(RM)" );
1844 for (i
= 0; i
< files
.count
; i
+= 2) output_filename( strmake( "$(DESTDIR)%s", files
.str
[i
+ 1] + 1 ));
1847 strarray_add( phony_targets
, "install" );
1848 strarray_add( phony_targets
, target
);
1849 strarray_add( phony_targets
, "uninstall" );
1853 /*******************************************************************
1856 static struct strarray
output_sources( struct makefile
*make
, struct strarray
*testlist_files
)
1858 struct incl_file
*source
;
1860 struct strarray object_files
= empty_strarray
;
1861 struct strarray crossobj_files
= empty_strarray
;
1862 struct strarray res_files
= empty_strarray
;
1863 struct strarray clean_files
= empty_strarray
;
1864 struct strarray po_files
= empty_strarray
;
1865 struct strarray mo_files
= empty_strarray
;
1866 struct strarray mc_files
= empty_strarray
;
1867 struct strarray ok_files
= empty_strarray
;
1868 struct strarray dlldata_files
= empty_strarray
;
1869 struct strarray c2man_files
= empty_strarray
;
1870 struct strarray implib_objs
= empty_strarray
;
1871 struct strarray includes
= empty_strarray
;
1872 struct strarray subdirs
= empty_strarray
;
1873 struct strarray phony_targets
= empty_strarray
;
1874 struct strarray all_targets
= empty_strarray
;
1875 char *ldrpath_local
= get_expanded_make_variable( make
, "LDRPATH_LOCAL" );
1876 char *ldrpath_install
= get_expanded_make_variable( make
, "LDRPATH_INSTALL" );
1878 for (i
= 0; i
< linguas
.count
; i
++)
1879 strarray_add( &mo_files
, strmake( "%s/%s.mo", top_obj_dir_path( make
, "po" ), linguas
.str
[i
] ));
1881 strarray_add( &phony_targets
, "all" );
1882 strarray_add( &includes
, strmake( "-I%s", obj_dir_path( make
, "" )));
1883 if (make
->src_dir
) strarray_add( &includes
, strmake( "-I%s", make
->src_dir
));
1884 if (make
->parent_dir
) strarray_add( &includes
, strmake( "-I%s", src_dir_path( make
, make
->parent_dir
)));
1885 if (make
->top_obj_dir
) strarray_add( &includes
, strmake( "-I%s", top_obj_dir_path( make
, "include" )));
1886 if (make
->top_src_dir
) strarray_add( &includes
, strmake( "-I%s", top_dir_path( make
, "include" )));
1887 if (make
->use_msvcrt
) strarray_add( &includes
, strmake( "-I%s", top_dir_path( make
, "include/msvcrt" )));
1888 strarray_addall( &includes
, make
->include_args
);
1890 LIST_FOR_EACH_ENTRY( source
, &make
->sources
, struct incl_file
, entry
)
1892 struct strarray extradefs
;
1893 char *obj
= xstrdup( source
->name
);
1894 char *ext
= get_extension( obj
);
1896 if (!ext
) fatal_error( "unsupported file type %s\n", source
->name
);
1899 if (make
->src_dir
&& strchr( obj
, '/' ))
1901 char *subdir
= base_dir_path( make
, obj
);
1902 *strrchr( subdir
, '/' ) = 0;
1903 strarray_add_uniq( &subdirs
, subdir
);
1906 extradefs
= get_expanded_make_var_array( make
, file_local_var( obj
, "EXTRADEFS" ));
1908 if (!strcmp( ext
, "y" )) /* yacc file */
1910 /* add source file dependency for parallel makes */
1911 char *header
= strmake( "%s.tab.h", obj
);
1913 if (find_include_file( make
, header
))
1915 output( "%s: %s\n", obj_dir_path( make
, header
), source
->filename
);
1916 output( "\t$(BISON) -p %s_ -o %s.tab.c -d %s\n",
1917 obj
, obj_dir_path( make
, obj
), source
->filename
);
1918 output( "%s.tab.c: %s %s\n", obj_dir_path( make
, obj
),
1919 source
->filename
, obj_dir_path( make
, header
));
1920 strarray_add( &clean_files
, header
);
1922 else output( "%s.tab.c: %s\n", obj
, source
->filename
);
1924 output( "\t$(BISON) -p %s_ -o $@ %s\n", obj
, source
->filename
);
1925 continue; /* no dependencies */
1927 else if (!strcmp( ext
, "x" )) /* template file */
1929 output( "%s.h: %s%s %s\n", obj_dir_path( make
, obj
),
1930 tools_dir_path( make
, "make_xftmpl" ), tools_ext
, source
->filename
);
1931 output( "\t%s%s -H -o $@ %s\n",
1932 tools_dir_path( make
, "make_xftmpl" ), tools_ext
, source
->filename
);
1933 strarray_add( &clean_files
, strmake( "%s.h", obj
));
1934 continue; /* no dependencies */
1936 else if (!strcmp( ext
, "l" )) /* lex file */
1938 output( "%s.yy.c: %s\n", obj_dir_path( make
, obj
), source
->filename
);
1939 output( "\t$(FLEX) -o$@ %s\n", source
->filename
);
1940 continue; /* no dependencies */
1942 else if (!strcmp( ext
, "rc" )) /* resource file */
1944 strarray_add( &res_files
, strmake( "%s.res", obj
));
1945 output( "%s.res: %s %s\n", obj_dir_path( make
, obj
),
1946 tools_path( make
, "wrc" ), source
->filename
);
1947 output( "\t%s -o $@", tools_path( make
, "wrc" ) );
1948 if (make
->is_win16
) output_filename( "-m16" );
1949 else output_filenames( target_flags
);
1950 output_filename( "--nostdinc" );
1951 output_filenames( includes
);
1952 output_filenames( make
->define_args
);
1953 output_filenames( extradefs
);
1954 if (mo_files
.count
&& (source
->file
->flags
& FLAG_RC_PO
))
1956 strarray_add( &po_files
, source
->filename
);
1957 output_filename( strmake( "--po-dir=%s", top_obj_dir_path( make
, "po" )));
1958 output_filename( source
->filename
);
1960 output( "%s.res:", obj_dir_path( make
, obj
));
1961 output_filenames( mo_files
);
1963 output( "%s ", obj_dir_path( make
, "rsrc.pot" ));
1967 output_filename( source
->filename
);
1970 output( "%s.res:", obj_dir_path( make
, obj
));
1972 else if (!strcmp( ext
, "mc" )) /* message file */
1974 strarray_add( &res_files
, strmake( "%s.res", obj
));
1975 output( "%s.res: %s %s\n", obj_dir_path( make
, obj
),
1976 tools_path( make
, "wmc" ), source
->filename
);
1977 output( "\t%s -U -O res -o $@ %s", tools_path( make
, "wmc" ), source
->filename
);
1980 strarray_add( &mc_files
, source
->filename
);
1981 output_filename( strmake( "--po-dir=%s", top_obj_dir_path( make
, "po" )));
1983 output( "%s.res:", obj_dir_path( make
, obj
));
1984 output_filenames( mo_files
);
1986 output( "%s ", obj_dir_path( make
, "msg.pot" ));
1988 else output( "\n" );
1989 output( "%s.res:", obj_dir_path( make
, obj
));
1991 else if (!strcmp( ext
, "idl" )) /* IDL file */
1993 struct strarray targets
= empty_strarray
;
1996 if (!source
->file
->flags
|| find_include_file( make
, strmake( "%s.h", obj
)))
1997 source
->file
->flags
|= FLAG_IDL_HEADER
;
1999 for (i
= 0; i
< sizeof(idl_outputs
) / sizeof(idl_outputs
[0]); i
++)
2001 if (!(source
->file
->flags
& idl_outputs
[i
].flag
)) continue;
2002 dest
= strmake( "%s%s", obj
, idl_outputs
[i
].ext
);
2003 if (!find_src_file( make
, dest
)) strarray_add( &clean_files
, dest
);
2004 strarray_add( &targets
, dest
);
2006 if (source
->file
->flags
& FLAG_IDL_PROXY
) strarray_add( &dlldata_files
, source
->name
);
2007 output_filenames_obj_dir( make
, targets
);
2008 output( ": %s\n", tools_path( make
, "widl" ));
2009 output( "\t%s -o $@", tools_path( make
, "widl" ) );
2010 output_filenames( target_flags
);
2011 output_filenames( includes
);
2012 output_filenames( make
->define_args
);
2013 output_filenames( extradefs
);
2014 output_filenames( get_expanded_make_var_array( make
, "EXTRAIDLFLAGS" ));
2015 output_filename( source
->filename
);
2017 output_filenames_obj_dir( make
, targets
);
2018 output( ": %s", source
->filename
);
2020 else if (!strcmp( ext
, "in" )) /* .in file or man page */
2022 if (strendswith( obj
, ".man" ) && source
->file
->args
)
2024 struct strarray symlinks
;
2025 char *dir
, *dest
= replace_extension( obj
, ".man", "" );
2026 char *lang
= strchr( dest
, '.' );
2027 char *section
= source
->file
->args
;
2031 dir
= strmake( "$(mandir)/%s/man%s", lang
, section
);
2033 else dir
= strmake( "$(mandir)/man%s", section
);
2034 add_install_rule( make
, dest
, xstrdup(obj
), strmake( "d%s/%s.%s", dir
, dest
, section
));
2035 symlinks
= get_expanded_make_var_array( make
, file_local_var( dest
, "SYMLINKS" ));
2036 for (j
= 0; j
< symlinks
.count
; j
++)
2037 add_install_rule( make
, symlinks
.str
[j
], strmake( "%s.%s", dest
, section
),
2038 strmake( "y%s/%s.%s", dir
, symlinks
.str
[j
], section
));
2041 strarray_add( &all_targets
, xstrdup(obj
) );
2043 else strarray_add( &clean_files
, xstrdup(obj
) );
2044 output( "%s: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2045 output( "\t$(SED_CMD) %s >$@ || ($(RM) $@ && false)\n", source
->filename
);
2046 output( "%s:", obj_dir_path( make
, obj
));
2048 else if (!strcmp( ext
, "sfd" )) /* font file */
2050 char *ttf_file
= src_dir_path( make
, strmake( "%s.ttf", obj
));
2051 if (fontforge
&& !make
->src_dir
)
2053 output( "%s: %s\n", ttf_file
, source
->filename
);
2054 output( "\t%s -script %s %s $@\n",
2055 fontforge
, top_dir_path( make
, "fonts/genttf.ff" ), source
->filename
);
2056 if (!(source
->file
->flags
& FLAG_SFD_FONTS
)) output( "all: %s\n", ttf_file
);
2058 if (source
->file
->flags
& FLAG_INSTALL
)
2060 strarray_add( &make
->install_lib_rules
, strmake( "%s.ttf", obj
));
2061 strarray_add( &make
->install_lib_rules
, strmake( "D$(fontdir)/%s.ttf", obj
));
2063 if (source
->file
->flags
& FLAG_SFD_FONTS
)
2065 struct strarray
*array
= source
->file
->args
;
2067 for (i
= 0; i
< array
->count
; i
++)
2069 char *font
= strtok( xstrdup(array
->str
[i
]), " \t" );
2070 char *args
= strtok( NULL
, "" );
2072 strarray_add( &all_targets
, xstrdup( font
));
2073 output( "%s: %s %s\n", obj_dir_path( make
, font
),
2074 tools_path( make
, "sfnt2fon" ), ttf_file
);
2075 output( "\t%s -o $@ %s %s\n", tools_path( make
, "sfnt2fon" ), ttf_file
, args
);
2076 strarray_add( &make
->install_lib_rules
, xstrdup(font
) );
2077 strarray_add( &make
->install_lib_rules
, strmake( "d$(fontdir)/%s", font
));
2080 continue; /* no dependencies */
2082 else if (!strcmp( ext
, "svg" )) /* svg file */
2084 if (convert
&& rsvg
&& icotool
&& !make
->src_dir
)
2086 output( "%s.ico %s.bmp: %s\n",
2087 src_dir_path( make
, obj
), src_dir_path( make
, obj
), source
->filename
);
2088 output( "\tCONVERT=\"%s\" ICOTOOL=\"%s\" RSVG=\"%s\" %s %s $@\n", convert
, icotool
, rsvg
,
2089 top_dir_path( make
, "tools/buildimage" ), source
->filename
);
2091 continue; /* no dependencies */
2093 else if (!strcmp( ext
, "res" ))
2095 strarray_add( &res_files
, source
->name
);
2096 continue; /* no dependencies */
2100 int need_cross
= make
->testdll
||
2101 (source
->file
->flags
& FLAG_C_IMPLIB
) ||
2102 (make
->module
&& make
->staticlib
);
2104 if ((source
->file
->flags
& FLAG_GENERATED
) &&
2105 (!make
->testdll
|| !strendswith( source
->filename
, "testlist.c" )))
2106 strarray_add( &clean_files
, source
->filename
);
2107 if (source
->file
->flags
& FLAG_C_IMPLIB
) strarray_add( &implib_objs
, strmake( "%s.o", obj
));
2108 strarray_add( &object_files
, strmake( "%s.o", obj
));
2109 output( "%s.o: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2110 output( "\t$(CC) -c -o $@ %s", source
->filename
);
2111 output_filenames( includes
);
2112 output_filenames( make
->define_args
);
2113 output_filenames( extradefs
);
2114 if (make
->module
|| make
->staticlib
|| make
->testdll
)
2116 output_filenames( dll_flags
);
2117 if (make
->use_msvcrt
) output_filenames( msvcrt_flags
);
2119 output_filenames( extra_cflags
);
2120 output_filenames( cpp_flags
);
2121 output_filename( "$(CFLAGS)" );
2123 if (crosstarget
&& need_cross
)
2125 strarray_add( &crossobj_files
, strmake( "%s.cross.o", obj
));
2126 output( "%s.cross.o: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2127 output( "\t$(CROSSCC) -c -o $@ %s", source
->filename
);
2128 output_filenames( includes
);
2129 output_filenames( make
->define_args
);
2130 output_filenames( extradefs
);
2131 output_filename( "-DWINE_CROSSTEST" );
2132 output_filenames( cpp_flags
);
2133 output_filename( "$(CFLAGS)" );
2136 if (make
->testdll
&& !strcmp( ext
, "c" ) && !(source
->file
->flags
& FLAG_GENERATED
))
2138 strarray_add( &ok_files
, strmake( "%s.ok", obj
));
2139 output( "%s.ok:\n", obj_dir_path( make
, obj
));
2140 output( "\t%s $(RUNTESTFLAGS) -T %s -M %s -p %s%s %s && touch $@\n",
2141 top_dir_path( make
, "tools/runtest" ), top_obj_dir_path( make
, "" ), make
->testdll
,
2142 replace_extension( make
->testdll
, ".dll", "_test.exe" ), dll_ext
, obj
);
2144 if (!strcmp( ext
, "c" ) && !(source
->file
->flags
& FLAG_GENERATED
))
2145 strarray_add( &c2man_files
, source
->filename
);
2146 output( "%s.o", obj_dir_path( make
, obj
));
2147 if (crosstarget
&& need_cross
) output( " %s.cross.o", obj_dir_path( make
, obj
));
2152 for (i
= 0; i
< source
->files_count
; i
++) output_include( source
->files
[i
], source
);
2156 /* rules for files that depend on multiple sources */
2160 output( "%s: %s", obj_dir_path( make
, "rsrc.pot" ), tools_path( make
, "wrc" ) );
2161 output_filenames( po_files
);
2163 output( "\t%s -O pot -o $@", tools_path( make
, "wrc" ));
2164 if (make
->is_win16
) output_filename( "-m16" );
2165 else output_filenames( target_flags
);
2166 output_filename( "--nostdinc" );
2167 output_filenames( includes
);
2168 output_filenames( make
->define_args
);
2169 output_filenames( po_files
);
2171 strarray_add( &clean_files
, "rsrc.pot" );
2176 output( "%s: %s", obj_dir_path( make
, "msg.pot" ), tools_path( make
, "wmc" ));
2177 output_filenames( mc_files
);
2179 output( "\t%s -O pot -o $@", tools_path( make
, "wmc" ));
2180 output_filenames( mc_files
);
2182 strarray_add( &clean_files
, "msg.pot" );
2185 if (dlldata_files
.count
)
2187 output( "%s: %s %s\n", obj_dir_path( make
, "dlldata.c" ),
2188 tools_path( make
, "widl" ), src_dir_path( make
, "Makefile.in" ));
2189 output( "\t%s --dlldata-only -o $@", tools_path( make
, "widl" ));
2190 output_filenames( dlldata_files
);
2194 if (make
->module
&& !make
->staticlib
)
2196 struct strarray all_libs
= empty_strarray
;
2197 char *module_path
= obj_dir_path( make
, make
->module
);
2198 char *spec_file
= NULL
;
2200 if (!make
->appmode
.count
)
2201 spec_file
= src_dir_path( make
, replace_extension( make
->module
, ".dll", ".spec" ));
2202 for (i
= 0; i
< make
->delayimports
.count
; i
++)
2203 strarray_add( &all_libs
, strmake( "-l%s", make
->delayimports
.str
[i
] ));
2204 for (i
= 0; i
< make
->imports
.count
; i
++)
2205 strarray_add( &all_libs
, strmake( "-l%s", make
->imports
.str
[i
] ));
2206 for (i
= 0; i
< make
->delayimports
.count
; i
++)
2207 strarray_add( &all_libs
, strmake( "-Wb,-d%s", make
->delayimports
.str
[i
] ));
2208 strarray_add( &all_libs
, "-lwine" );
2209 strarray_add( &all_libs
, top_obj_dir_path( make
, "libs/port/libwine_port.a" ));
2210 strarray_addall( &all_libs
, get_expanded_make_var_array( make
, "EXTRALIBS" ));
2211 strarray_addall( &all_libs
, libs
);
2215 strarray_add( &all_targets
, strmake( "%s%s", make
->module
, dll_ext
));
2216 strarray_add( &all_targets
, strmake( "%s.fake", make
->module
));
2217 add_install_rule( make
, make
->module
, strmake( "%s%s", make
->module
, dll_ext
),
2218 strmake( "p$(dlldir)/%s%s", make
->module
, dll_ext
));
2219 add_install_rule( make
, make
->module
, strmake( "%s.fake", make
->module
),
2220 strmake( "d$(fakedlldir)/%s", make
->module
));
2221 output( "%s%s %s.fake:", module_path
, dll_ext
, module_path
);
2225 strarray_add( &all_targets
, make
->module
);
2226 add_install_rule( make
, make
->module
, make
->module
,
2227 strmake( "p$(%s)/%s", spec_file
? "dlldir" : "bindir", make
->module
));
2228 output( "%s:", module_path
);
2230 if (spec_file
) output_filename( spec_file
);
2231 output_filenames_obj_dir( make
, object_files
);
2232 output_filenames_obj_dir( make
, res_files
);
2234 output( "\t%s -o $@", tools_path( make
, "winegcc" ));
2235 output_filename( strmake( "-B%s", tools_dir_path( make
, "winebuild" )));
2236 if (tools_dir
) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make
, "" )));
2237 output_filenames( target_flags
);
2238 output_filenames( unwind_flags
);
2241 output( " -shared %s", spec_file
);
2242 output_filenames( make
->extradllflags
);
2244 else output_filenames( make
->appmode
);
2245 output_filenames_obj_dir( make
, object_files
);
2246 output_filenames_obj_dir( make
, res_files
);
2247 output_filenames( all_libs
);
2248 output_filename( "$(LDFLAGS)" );
2251 if (spec_file
&& make
->importlib
)
2253 char *importlib_path
= obj_dir_path( make
, strmake( "lib%s", make
->importlib
));
2256 strarray_add( &clean_files
, strmake( "lib%s.def", make
->importlib
));
2257 output( "%s.def: %s %s\n", importlib_path
, tools_path( make
, "winebuild" ), spec_file
);
2258 output( "\t%s -w --def -o $@ --export %s", tools_path( make
, "winebuild" ), spec_file
);
2259 output_filenames( target_flags
);
2260 if (make
->is_win16
) output_filename( "-m16" );
2262 add_install_rule( make
, make
->importlib
, strmake( "lib%s.def", make
->importlib
),
2263 strmake( "d$(dlldir)/lib%s.def", make
->importlib
));
2264 if (implib_objs
.count
)
2266 strarray_add( &clean_files
, strmake( "lib%s.def.a", make
->importlib
));
2267 output( "%s.def.a:", importlib_path
);
2268 output_filenames_obj_dir( make
, implib_objs
);
2270 output( "\t$(RM) $@\n" );
2271 output( "\t$(AR) $(ARFLAGS) $@" );
2272 output_filenames_obj_dir( make
, implib_objs
);
2274 output( "\t$(RANLIB) $@\n" );
2275 add_install_rule( make
, make
->importlib
, strmake( "lib%s.def.a", make
->importlib
),
2276 strmake( "d$(dlldir)/lib%s.def.a", make
->importlib
));
2281 strarray_add( &clean_files
, strmake( "lib%s.a", make
->importlib
));
2282 output( "%s.a: %s %s", importlib_path
, tools_path( make
, "winebuild" ), spec_file
);
2283 output_filenames_obj_dir( make
, implib_objs
);
2285 output( "\t%s -w --implib -o $@ --export %s", tools_path( make
, "winebuild" ), spec_file
);
2286 output_filenames( target_flags
);
2287 output_filenames_obj_dir( make
, implib_objs
);
2289 add_install_rule( make
, make
->importlib
, strmake( "lib%s.a", make
->importlib
),
2290 strmake( "d$(dlldir)/lib%s.a", make
->importlib
));
2292 if (crosstarget
&& !make
->is_win16
)
2294 struct strarray cross_files
= strarray_replace_extension( &implib_objs
, ".o", ".cross.o" );
2295 strarray_add( &clean_files
, strmake( "lib%s.cross.a", make
->importlib
));
2296 output( "%s.cross.a: %s %s", importlib_path
, tools_path( make
, "winebuild" ), spec_file
);
2297 output_filenames_obj_dir( make
, cross_files
);
2299 output( "\t%s -b %s -w --implib -o $@ --export %s",
2300 tools_path( make
, "winebuild" ), crosstarget
, spec_file
);
2301 output_filenames_obj_dir( make
, cross_files
);
2308 if (c2man_files
.count
)
2310 output( "manpages::\n" );
2311 output( "\t%s -w %s", top_dir_path( make
, "tools/c2man.pl" ), spec_file
);
2312 output_filename( strmake( "-R%s", top_dir_path( make
, "" )));
2313 output_filename( strmake( "-I%s", top_dir_path( make
, "include" )));
2314 output_filename( strmake( "-o %s/man%s",
2315 top_obj_dir_path( make
, "documentation" ), man_ext
));
2316 output_filenames( c2man_files
);
2318 output( "htmlpages::\n" );
2319 output( "\t%s -Th -w %s", top_dir_path( make
, "tools/c2man.pl" ), spec_file
);
2320 output_filename( strmake( "-R%s", top_dir_path( make
, "" )));
2321 output_filename( strmake( "-I%s", top_dir_path( make
, "include" )));
2322 output_filename( strmake( "-o %s",
2323 top_obj_dir_path( make
, "documentation/html" )));
2324 output_filenames( c2man_files
);
2326 output( "sgmlpages::\n" );
2327 output( "\t%s -Ts -w %s", top_dir_path( make
, "tools/c2man.pl" ), spec_file
);
2328 output_filename( strmake( "-R%s", top_dir_path( make
, "" )));
2329 output_filename( strmake( "-I%s", top_dir_path( make
, "include" )));
2330 output_filename( strmake( "-o %s",
2331 top_obj_dir_path( make
, "documentation/api-guide" )));
2332 output_filenames( c2man_files
);
2334 output( "xmlpages::\n" );
2335 output( "\t%s -Tx -w %s", top_dir_path( make
, "tools/c2man.pl" ), spec_file
);
2336 output_filename( strmake( "-R%s", top_dir_path( make
, "" )));
2337 output_filename( strmake( "-I%s", top_dir_path( make
, "include" )));
2338 output_filename( strmake( "-o %s",
2339 top_obj_dir_path( make
, "documentation/api-guide-xml" )));
2340 output_filenames( c2man_files
);
2342 strarray_add( &phony_targets
, "manpages" );
2343 strarray_add( &phony_targets
, "htmlpages" );
2344 strarray_add( &phony_targets
, "sgmlpages" );
2345 strarray_add( &phony_targets
, "xmlpages" );
2347 else output( "manpages htmlpages sgmlpages xmlpages::\n" );
2351 char *binary
= replace_extension( make
->module
, ".exe", "" );
2352 add_install_rule( make
, binary
, tools_dir_path( make
, "wineapploader" ),
2353 strmake( "s$(bindir)/%s", binary
));
2357 if (make
->staticlib
)
2359 strarray_add( &all_targets
, make
->staticlib
);
2360 output( "%s:", obj_dir_path( make
, make
->staticlib
));
2361 output_filenames_obj_dir( make
, object_files
);
2362 output( "\n\t$(RM) $@\n" );
2363 output( "\t$(AR) $(ARFLAGS) $@" );
2364 output_filenames_obj_dir( make
, object_files
);
2365 output( "\n\t$(RANLIB) $@\n" );
2366 if (crosstarget
&& make
->module
)
2368 char *name
= replace_extension( make
->staticlib
, ".a", ".cross.a" );
2370 strarray_add( &all_targets
, name
);
2371 output( "%s:", obj_dir_path( make
, name
));
2372 output_filenames_obj_dir( make
, crossobj_files
);
2373 output( "\n\t$(RM) $@\n" );
2374 output( "\t%s-ar $(ARFLAGS) $@", crosstarget
);
2375 output_filenames_obj_dir( make
, crossobj_files
);
2376 output( "\n\t%s-ranlib $@\n", crosstarget
);
2382 char *testmodule
= replace_extension( make
->testdll
, ".dll", "_test.exe" );
2383 char *stripped
= replace_extension( make
->testdll
, ".dll", "_test-stripped.exe" );
2384 char *testres
= replace_extension( make
->testdll
, ".dll", "_test.res" );
2385 struct strarray all_libs
= empty_strarray
;
2387 for (i
= 0; i
< make
->imports
.count
; i
++)
2388 strarray_add( &all_libs
, strmake( "-l%s", make
->imports
.str
[i
] ));
2389 strarray_addall( &all_libs
, libs
);
2391 strarray_add( &all_targets
, strmake( "%s%s", testmodule
, dll_ext
));
2392 strarray_add( &clean_files
, strmake( "%s%s", stripped
, dll_ext
));
2393 output( "%s%s:\n", obj_dir_path( make
, testmodule
), dll_ext
);
2394 output( "\t%s -o $@", tools_path( make
, "winegcc" ));
2395 output_filename( strmake( "-B%s", tools_dir_path( make
, "winebuild" )));
2396 if (tools_dir
) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make
, "" )));
2397 output_filenames( target_flags
);
2398 output_filenames( unwind_flags
);
2399 output_filenames( make
->appmode
);
2400 output_filenames_obj_dir( make
, object_files
);
2401 output_filenames_obj_dir( make
, res_files
);
2402 output_filenames( all_libs
);
2403 output_filename( "$(LDFLAGS)" );
2405 output( "%s%s:\n", obj_dir_path( make
, stripped
), dll_ext
);
2406 output( "\t%s -o $@", tools_path( make
, "winegcc" ));
2407 output_filename( strmake( "-B%s", tools_dir_path( make
, "winebuild" )));
2408 if (tools_dir
) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make
, "" )));
2409 output_filenames( target_flags
);
2410 output_filenames( unwind_flags
);
2411 output_filename( strmake( "-Wb,-F,%s", testmodule
));
2412 output_filenames( make
->appmode
);
2413 output_filenames_obj_dir( make
, object_files
);
2414 output_filenames_obj_dir( make
, res_files
);
2415 output_filenames( all_libs
);
2416 output_filename( "$(LDFLAGS)" );
2418 output( "%s%s %s%s:", obj_dir_path( make
, testmodule
), dll_ext
,
2419 obj_dir_path( make
, stripped
), dll_ext
);
2420 output_filenames_obj_dir( make
, object_files
);
2421 output_filenames_obj_dir( make
, res_files
);
2424 output( "all: %s/%s\n", top_obj_dir_path( make
, "programs/winetest" ), testres
);
2425 output( "%s/%s: %s%s\n", top_obj_dir_path( make
, "programs/winetest" ), testres
,
2426 obj_dir_path( make
, stripped
), dll_ext
);
2427 output( "\techo \"%s TESTRES \\\"%s%s\\\"\" | %s -o $@\n",
2428 testmodule
, obj_dir_path( make
, stripped
), dll_ext
, tools_path( make
, "wrc" ));
2432 char *crosstest
= replace_extension( make
->testdll
, ".dll", "_crosstest.exe" );
2434 strarray_add( &clean_files
, crosstest
);
2435 output( "%s: %s\n", obj_dir_path( make
, "crosstest" ), obj_dir_path( make
, crosstest
));
2436 output( "%s:", obj_dir_path( make
, crosstest
));
2437 output_filenames_obj_dir( make
, crossobj_files
);
2438 output_filenames_obj_dir( make
, res_files
);
2440 output( "\t%s -o $@ -b %s", tools_path( make
, "winegcc" ), crosstarget
);
2441 output_filename( strmake( "-B%s", tools_dir_path( make
, "winebuild" )));
2442 if (tools_dir
) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make
, "" )));
2443 output_filename( "--lib-suffix=.cross.a" );
2444 output_filenames_obj_dir( make
, crossobj_files
);
2445 output_filenames_obj_dir( make
, res_files
);
2446 output_filenames( all_libs
);
2447 output_filename( "$(LDFLAGS)" );
2449 strarray_add( &phony_targets
, obj_dir_path( make
, "crosstest" ));
2450 if (make
->obj_dir
) output( "crosstest: %s\n", obj_dir_path( make
, "crosstest" ));
2453 output_filenames_obj_dir( make
, ok_files
);
2454 output( ": %s%s ../%s%s\n", testmodule
, dll_ext
, make
->testdll
, dll_ext
);
2455 output( "check test:" );
2456 output_filenames_obj_dir( make
, ok_files
);
2458 output( "testclean::\n" );
2459 output( "\t$(RM)" );
2460 output_filenames_obj_dir( make
, ok_files
);
2462 strarray_addall( &clean_files
, ok_files
);
2463 strarray_add( &phony_targets
, "check" );
2464 strarray_add( &phony_targets
, "test" );
2465 strarray_add( &phony_targets
, "testclean" );
2466 *testlist_files
= strarray_replace_extension( &ok_files
, ".ok", "" );
2469 for (i
= 0; i
< make
->programs
.count
; i
++)
2471 char *program_installed
= NULL
;
2472 char *program
= strmake( "%s%s", make
->programs
.str
[i
], exe_ext
);
2473 struct strarray all_libs
= empty_strarray
;
2474 struct strarray objs
= get_expanded_make_var_array( make
,
2475 file_local_var( make
->programs
.str
[i
], "OBJS" ));
2476 struct strarray symlinks
= get_expanded_make_var_array( make
,
2477 file_local_var( make
->programs
.str
[i
], "SYMLINKS" ));
2479 if (!objs
.count
) objs
= object_files
;
2480 output( "%s:", obj_dir_path( make
, program
) );
2481 output_filenames_obj_dir( make
, objs
);
2483 output( "\t$(CC) -o $@" );
2484 output_filenames_obj_dir( make
, objs
);
2485 strarray_add( &all_libs
, top_obj_dir_path( make
, "libs/port/libwine_port.a" ));
2486 strarray_addall( &all_libs
, get_expanded_make_var_array( make
, "EXTRALIBS" ));
2487 strarray_addall( &all_libs
, libs
);
2488 strarray_addall( &all_libs
, get_expanded_make_var_array( make
,
2489 file_local_var( make
->programs
.str
[i
], "LDFLAGS" )));
2491 if (strarray_exists( &all_libs
, "-lwine" ))
2493 strarray_add( &all_libs
, strmake( "-L%s", top_obj_dir_path( make
, "libs/wine" )));
2494 if (ldrpath_local
&& ldrpath_install
)
2496 program_installed
= strmake( "%s-installed%s", make
->programs
.str
[i
], exe_ext
);
2497 output_filename( ldrpath_local
);
2498 output_filenames( all_libs
);
2499 output_filename( "$(LDFLAGS)" );
2501 output( "%s:", obj_dir_path( make
, program_installed
) );
2502 output_filenames_obj_dir( make
, objs
);
2504 output( "\t$(CC) -o $@" );
2505 output_filenames_obj_dir( make
, objs
);
2506 output_filename( ldrpath_install
);
2507 strarray_add( &all_targets
, program_installed
);
2511 output_filenames( all_libs
);
2512 output_filename( "$(LDFLAGS)" );
2514 strarray_add( &all_targets
, program
);
2518 output_filenames_obj_dir( make
, symlinks
);
2519 output( ": %s\n", obj_dir_path( make
, program
));
2520 output( "\t$(RM) $@ && $(LN_S) %s $@\n", obj_dir_path( make
, program
));
2521 strarray_addall( &all_targets
, symlinks
);
2524 add_install_rule( make
, program
, program_installed
? program_installed
: program
,
2525 strmake( "p$(bindir)/%s", program
));
2526 for (j
= 0; j
< symlinks
.count
; j
++)
2527 add_install_rule( make
, symlinks
.str
[j
], program
,
2528 strmake( "y$(bindir)/%s%s", symlinks
.str
[j
], exe_ext
));
2531 for (i
= 0; i
< make
->scripts
.count
; i
++)
2532 add_install_rule( make
, make
->scripts
.str
[i
], make
->scripts
.str
[i
],
2533 strmake( "S$(bindir)/%s", make
->scripts
.str
[i
] ));
2535 if (all_targets
.count
)
2538 output_filenames_obj_dir( make
, all_targets
);
2542 output_install_rules( make
, make
->install_lib_rules
, "install-lib", &phony_targets
);
2543 output_install_rules( make
, make
->install_dev_rules
, "install-dev", &phony_targets
);
2545 strarray_addall( &clean_files
, object_files
);
2546 strarray_addall( &clean_files
, crossobj_files
);
2547 strarray_addall( &clean_files
, res_files
);
2548 strarray_addall( &clean_files
, all_targets
);
2549 strarray_addall( &clean_files
, get_expanded_make_var_array( make
, "EXTRA_TARGETS" ));
2551 if (clean_files
.count
)
2553 output( "%s::\n", obj_dir_path( make
, "clean" ));
2554 output( "\t$(RM)" );
2555 output_filenames_obj_dir( make
, clean_files
);
2557 if (make
->obj_dir
) output( "__clean__: %s\n", obj_dir_path( make
, "clean" ));
2558 strarray_add( &phony_targets
, obj_dir_path( make
, "clean" ));
2561 if (make
->top_obj_dir
)
2563 output( "depend:\n" );
2564 output( "\t@cd %s && $(MAKE) %s\n", make
->top_obj_dir
, base_dir_path( make
, "depend" ));
2565 strarray_add( &phony_targets
, "depend" );
2568 if (phony_targets
.count
)
2570 output( ".PHONY:" );
2571 output_filenames( phony_targets
);
2575 for (i
= 0; i
< subdirs
.count
; i
++) create_dir( subdirs
.str
[i
] );
2581 /*******************************************************************
2584 static FILE *create_temp_file( const char *orig
)
2586 char *name
= xmalloc( strlen(orig
) + 13 );
2587 unsigned int i
, id
= getpid();
2591 for (i
= 0; i
< 100; i
++)
2593 sprintf( name
, "%s.tmp%08x", orig
, id
);
2594 if ((fd
= open( name
, O_RDWR
| O_CREAT
| O_EXCL
, 0666 )) != -1)
2596 ret
= fdopen( fd
, "w" );
2599 if (errno
!= EEXIST
) break;
2602 if (!ret
) fatal_error( "failed to create output file for '%s'\n", orig
);
2603 temp_file_name
= name
;
2608 /*******************************************************************
2611 static void rename_temp_file( const char *dest
)
2613 int ret
= rename( temp_file_name
, dest
);
2614 if (ret
== -1 && errno
== EEXIST
)
2616 /* rename doesn't overwrite on windows */
2618 ret
= rename( temp_file_name
, dest
);
2620 if (ret
== -1) fatal_error( "failed to rename output file to '%s'\n", dest
);
2621 temp_file_name
= NULL
;
2625 /*******************************************************************
2626 * are_files_identical
2628 static int are_files_identical( FILE *file1
, FILE *file2
)
2632 char buffer1
[8192], buffer2
[8192];
2633 int size1
= fread( buffer1
, 1, sizeof(buffer1
), file1
);
2634 int size2
= fread( buffer2
, 1, sizeof(buffer2
), file2
);
2635 if (size1
!= size2
) return 0;
2636 if (!size1
) return feof( file1
) && feof( file2
);
2637 if (memcmp( buffer1
, buffer2
, size1
)) return 0;
2642 /*******************************************************************
2643 * rename_temp_file_if_changed
2645 static void rename_temp_file_if_changed( const char *dest
)
2647 FILE *file1
, *file2
;
2650 if ((file1
= fopen( dest
, "r" )))
2652 if ((file2
= fopen( temp_file_name
, "r" )))
2654 do_rename
= !are_files_identical( file1
, file2
);
2661 unlink( temp_file_name
);
2662 temp_file_name
= NULL
;
2664 else rename_temp_file( dest
);
2668 /*******************************************************************
2671 static void output_testlist( const char *dest
, struct strarray files
)
2675 output_file
= create_temp_file( dest
);
2677 output( "/* Automatically generated by make depend; DO NOT EDIT!! */\n\n" );
2678 output( "#define WIN32_LEAN_AND_MEAN\n" );
2679 output( "#include <windows.h>\n\n" );
2680 output( "#define STANDALONE\n" );
2681 output( "#include \"wine/test.h\"\n\n" );
2683 for (i
= 0; i
< files
.count
; i
++) output( "extern void func_%s(void);\n", files
.str
[i
] );
2685 output( "const struct test winetest_testlist[] =\n" );
2687 for (i
= 0; i
< files
.count
; i
++) output( " { \"%s\", func_%s },\n", files
.str
[i
], files
.str
[i
] );
2688 output( " { 0, 0 }\n" );
2691 if (fclose( output_file
)) fatal_perror( "write" );
2693 rename_temp_file_if_changed( dest
);
2697 /*******************************************************************
2700 static void output_gitignore( const char *dest
, struct strarray files
)
2704 output_file
= create_temp_file( dest
);
2706 output( "# Automatically generated by make depend; DO NOT EDIT!!\n" );
2707 for (i
= 0; i
< files
.count
; i
++)
2709 if (!strchr( files
.str
[i
], '/' )) output( "/" );
2710 output( "%s\n", files
.str
[i
] );
2713 if (fclose( output_file
)) fatal_perror( "write" );
2715 rename_temp_file( dest
);
2719 /*******************************************************************
2720 * output_top_variables
2722 static void output_top_variables( struct makefile
*make
)
2725 struct strarray
*vars
= &top_makefile
->vars
;
2727 if (!make
->base_dir
) return; /* don't output variables in the top makefile */
2729 output( "# Automatically generated by make depend; DO NOT EDIT!!\n\n" );
2730 output( "all:\n\n" );
2731 for (i
= 0; i
< vars
->count
; i
+= 2)
2732 output( "%s = %s\n", vars
->str
[i
], get_make_variable( make
, vars
->str
[i
] ));
2737 /*******************************************************************
2738 * output_dependencies
2740 static void output_dependencies( struct makefile
*make
)
2742 struct strarray targets
, testlist_files
= empty_strarray
, ignore_files
= empty_strarray
;
2746 output_file_name
= base_dir_path( make
, output_makefile_name
);
2747 output_file
= create_temp_file( output_file_name
);
2748 output_top_variables( make
);
2750 /* copy the contents of the source makefile */
2751 src_file
= open_input_makefile( make
);
2752 while (fgets( buffer
, sizeof(buffer
), src_file
))
2753 if (fwrite( buffer
, 1, strlen(buffer
), output_file
) != strlen(buffer
)) fatal_perror( "write" );
2754 if (fclose( src_file
)) fatal_perror( "close" );
2755 input_file_name
= NULL
;
2757 targets
= output_sources( make
, &testlist_files
);
2759 fclose( output_file
);
2761 rename_temp_file( output_file_name
);
2763 strarray_add( &ignore_files
, ".gitignore" );
2764 strarray_add( &ignore_files
, "Makefile" );
2765 if (testlist_files
.count
) strarray_add( &ignore_files
, "testlist.c" );
2766 strarray_addall( &ignore_files
, targets
);
2768 if (testlist_files
.count
)
2769 output_testlist( base_dir_path( make
, "testlist.c" ), testlist_files
);
2770 if (!make
->src_dir
&& make
->base_dir
)
2771 output_gitignore( base_dir_path( make
, ".gitignore" ), ignore_files
);
2773 output_file_name
= NULL
;
2777 /*******************************************************************
2780 static void update_makefile( const char *path
)
2782 static const char *source_vars
[] =
2800 struct strarray value
;
2801 struct incl_file
*file
;
2802 struct makefile
*make
;
2804 make
= parse_makefile( path
, NULL
);
2808 make
->top_src_dir
= concat_paths( make
->top_obj_dir
, root_src_dir
);
2809 make
->src_dir
= concat_paths( make
->top_src_dir
, make
->base_dir
);
2811 strarray_set_value( &make
->vars
, "top_builddir", top_obj_dir_path( make
, "" ));
2812 strarray_set_value( &make
->vars
, "top_srcdir", top_dir_path( make
, "" ));
2813 strarray_set_value( &make
->vars
, "srcdir", src_dir_path( make
, "" ));
2815 make
->parent_dir
= get_expanded_make_variable( make
, "PARENTSRC" );
2816 make
->module
= get_expanded_make_variable( make
, "MODULE" );
2817 make
->testdll
= get_expanded_make_variable( make
, "TESTDLL" );
2818 make
->staticlib
= get_expanded_make_variable( make
, "STATICLIB" );
2819 make
->importlib
= get_expanded_make_variable( make
, "IMPORTLIB" );
2821 make
->programs
= get_expanded_make_var_array( make
, "PROGRAMS" );
2822 make
->scripts
= get_expanded_make_var_array( make
, "SCRIPTS" );
2823 make
->appmode
= get_expanded_make_var_array( make
, "APPMODE" );
2824 make
->imports
= get_expanded_make_var_array( make
, "IMPORTS" );
2825 make
->delayimports
= get_expanded_make_var_array( make
, "DELAYIMPORTS" );
2826 make
->extradllflags
= get_expanded_make_var_array( make
, "EXTRADLLFLAGS" );
2827 make
->install_lib
= get_expanded_make_var_array( make
, "INSTALL_LIB" );
2828 make
->install_dev
= get_expanded_make_var_array( make
, "INSTALL_DEV" );
2830 if (make
->module
&& strendswith( make
->module
, ".a" )) make
->staticlib
= make
->module
;
2832 make
->is_win16
= strarray_exists( &make
->extradllflags
, "-m16" );
2833 make
->use_msvcrt
= strarray_exists( &make
->appmode
, "-mno-cygwin" );
2835 for (i
= 0; i
< make
->imports
.count
&& !make
->use_msvcrt
; i
++)
2836 make
->use_msvcrt
= !strncmp( make
->imports
.str
[i
], "msvcr", 5 );
2838 make
->install_lib_rules
= empty_strarray
;
2839 make
->install_dev_rules
= empty_strarray
;
2840 if (make
->module
&& !make
->install_lib
.count
) strarray_add( &make
->install_lib
, make
->module
);
2842 make
->include_args
= empty_strarray
;
2843 make
->define_args
= empty_strarray
;
2844 strarray_add( &make
->define_args
, "-D__WINESRC__" );
2846 value
= get_expanded_make_var_array( make
, "EXTRAINCL" );
2847 for (i
= 0; i
< value
.count
; i
++)
2848 if (!strncmp( value
.str
[i
], "-I", 2 ))
2849 strarray_add_uniq( &make
->include_args
, value
.str
[i
] );
2851 strarray_add_uniq( &make
->define_args
, value
.str
[i
] );
2852 strarray_addall( &make
->define_args
, get_expanded_make_var_array( make
, "EXTRADEFS" ));
2854 list_init( &make
->sources
);
2855 list_init( &make
->includes
);
2857 /* FIXME: target dir has to exist to allow locating srcdir-relative include files */
2858 if (make
->base_dir
) create_dir( make
->base_dir
);
2860 for (var
= source_vars
; *var
; var
++)
2862 value
= get_expanded_make_var_array( make
, *var
);
2863 for (i
= 0; i
< value
.count
; i
++) add_src_file( make
, value
.str
[i
] );
2866 add_generated_sources( make
);
2868 value
= get_expanded_make_var_array( make
, "EXTRA_OBJS" );
2869 for (i
= 0; i
< value
.count
; i
++)
2871 /* default to .c for unknown extra object files */
2872 if (strendswith( value
.str
[i
], ".o" ))
2873 add_generated_source( make
, value
.str
[i
], replace_extension( value
.str
[i
], ".o", ".c" ) );
2875 add_generated_source( make
, value
.str
[i
], NULL
);
2878 LIST_FOR_EACH_ENTRY( file
, &make
->includes
, struct incl_file
, entry
) parse_file( make
, file
, 0 );
2880 output_dependencies( make
);
2884 /*******************************************************************
2887 static void parse_makeflags( const char *flags
)
2889 const char *p
= flags
;
2890 char *var
, *buffer
= xmalloc( strlen(flags
) + 1 );
2894 while (isspace(*p
)) p
++;
2896 while (*p
&& !isspace(*p
))
2898 if (*p
== '\\' && p
[1]) p
++;
2902 if (var
> buffer
) set_make_variable( &cmdline_vars
, buffer
);
2907 /*******************************************************************
2910 static int parse_option( const char *opt
)
2914 if (strchr( opt
, '=' )) return set_make_variable( &cmdline_vars
, opt
);
2920 if (opt
[2]) output_makefile_name
= opt
+ 2;
2923 if (opt
[2]) input_makefile_name
= opt
+ 2;
2926 relative_dir_mode
= 1;
2929 fprintf( stderr
, "Unknown option '%s'\n%s", opt
, Usage
);
2936 /*******************************************************************
2939 int main( int argc
, char *argv
[] )
2941 const char *makeflags
= getenv( "MAKEFLAGS" );
2944 if (makeflags
) parse_makeflags( makeflags
);
2949 if (parse_option( argv
[i
] ))
2951 for (j
= i
; j
< argc
; j
++) argv
[j
] = argv
[j
+1];
2957 if (relative_dir_mode
)
2963 fprintf( stderr
, "Option -r needs two directories\n%s", Usage
);
2966 relpath
= get_relative_path( argv
[1], argv
[2] );
2967 printf( "%s\n", relpath
? relpath
: "." );
2973 fprintf( stderr
, "%s", Usage
);
2976 atexit( cleanup_files
);
2977 signal( SIGTERM
, exit_on_signal
);
2978 signal( SIGINT
, exit_on_signal
);
2980 signal( SIGHUP
, exit_on_signal
);
2983 for (i
= 0; i
< HASH_SIZE
; i
++) list_init( &files
[i
] );
2985 if (!input_makefile_name
) input_makefile_name
= strmake( "%s.in", output_makefile_name
);
2987 top_makefile
= parse_makefile( NULL
, "# End of common header" );
2989 linguas
= get_expanded_make_var_array( top_makefile
, "LINGUAS" );
2990 target_flags
= get_expanded_make_var_array( top_makefile
, "TARGETFLAGS" );
2991 msvcrt_flags
= get_expanded_make_var_array( top_makefile
, "MSVCRTFLAGS" );
2992 dll_flags
= get_expanded_make_var_array( top_makefile
, "DLLFLAGS" );
2993 extra_cflags
= get_expanded_make_var_array( top_makefile
, "EXTRACFLAGS" );
2994 cpp_flags
= get_expanded_make_var_array( top_makefile
, "CPPFLAGS" );
2995 unwind_flags
= get_expanded_make_var_array( top_makefile
, "UNWINDFLAGS" );
2996 libs
= get_expanded_make_var_array( top_makefile
, "LIBS" );
2998 root_src_dir
= get_expanded_make_variable( top_makefile
, "srcdir" );
2999 tools_dir
= get_expanded_make_variable( top_makefile
, "TOOLSDIR" );
3000 tools_ext
= get_expanded_make_variable( top_makefile
, "TOOLSEXT" );
3001 exe_ext
= get_expanded_make_variable( top_makefile
, "EXEEXT" );
3002 man_ext
= get_expanded_make_variable( top_makefile
, "api_manext" );
3003 dll_ext
= (exe_ext
&& !strcmp( exe_ext
, ".exe" )) ? "" : ".so";
3004 dll_prefix
= get_expanded_make_variable( top_makefile
, "DLLPREFIX" );
3005 crosstarget
= get_expanded_make_variable( top_makefile
, "CROSSTARGET" );
3006 fontforge
= get_expanded_make_variable( top_makefile
, "FONTFORGE" );
3007 convert
= get_expanded_make_variable( top_makefile
, "CONVERT" );
3008 rsvg
= get_expanded_make_variable( top_makefile
, "RSVG" );
3009 icotool
= get_expanded_make_variable( top_makefile
, "ICOTOOL" );
3011 if (root_src_dir
&& !strcmp( root_src_dir
, "." )) root_src_dir
= NULL
;
3012 if (tools_dir
&& !strcmp( tools_dir
, "." )) tools_dir
= NULL
;
3013 if (!exe_ext
) exe_ext
= "";
3014 if (!tools_ext
) tools_ext
= "";
3015 if (!dll_prefix
) dll_prefix
= "";
3016 if (!man_ext
) man_ext
= "3w";
3018 for (i
= 1; i
< argc
; i
++) update_makefile( argv
[i
] );