2 * Generate include file dependencies
4 * Copyright 1996, 2013 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #define NO_LIBWINE_PORT
23 #include "wine/port.h"
36 #include "wine/list.h"
40 INCL_NORMAL
, /* #include "foo.h" */
41 INCL_SYSTEM
, /* #include <foo.h> */
42 INCL_IMPORT
, /* idl import "foo.idl" */
43 INCL_IMPORTLIB
, /* idl importlib "foo.tlb" */
44 INCL_CPP_QUOTE
, /* idl cpp_quote("#include \"foo.h\"") */
45 INCL_CPP_QUOTE_SYSTEM
/* idl cpp_quote("#include <foo.h>") */
50 int line
; /* source line where this header is included */
51 enum incl_type type
; /* type of include */
52 char *name
; /* header name */
58 char *name
; /* full file name relative to cwd */
59 void *args
; /* custom arguments for makefile rule */
60 unsigned int flags
; /* flags (see below) */
61 unsigned int deps_count
; /* files in use */
62 unsigned int deps_size
; /* total allocated size */
63 struct dependency
*deps
; /* all header dependencies */
72 char *sourcename
; /* source file name for generated headers */
73 struct incl_file
*included_by
; /* file that included this one */
74 int included_line
; /* line where this file was included */
75 enum incl_type type
; /* type of include */
76 struct incl_file
*owner
;
77 unsigned int files_count
; /* files in use */
78 unsigned int files_size
; /* total allocated size */
79 struct incl_file
**files
;
82 #define FLAG_GENERATED 0x000001 /* generated file */
83 #define FLAG_INSTALL 0x000002 /* file to install */
84 #define FLAG_IDL_PROXY 0x000100 /* generates a proxy (_p.c) file */
85 #define FLAG_IDL_CLIENT 0x000200 /* generates a client (_c.c) file */
86 #define FLAG_IDL_SERVER 0x000400 /* generates a server (_s.c) file */
87 #define FLAG_IDL_IDENT 0x000800 /* generates an ident (_i.c) file */
88 #define FLAG_IDL_REGISTER 0x001000 /* generates a registration (_r.res) file */
89 #define FLAG_IDL_TYPELIB 0x002000 /* generates a typelib (.tlb) file */
90 #define FLAG_IDL_REGTYPELIB 0x004000 /* generates a registered typelib (_t.res) file */
91 #define FLAG_IDL_HEADER 0x008000 /* generates a header (.h) file */
92 #define FLAG_RC_PO 0x010000 /* rc file contains translations */
93 #define FLAG_C_IMPLIB 0x020000 /* file is part of an import library */
94 #define FLAG_SFD_FONTS 0x040000 /* sfd file generated bitmap fonts */
102 { FLAG_IDL_TYPELIB
, ".tlb" },
103 { FLAG_IDL_REGTYPELIB
, "_t.res" },
104 { FLAG_IDL_CLIENT
, "_c.c" },
105 { FLAG_IDL_IDENT
, "_i.c" },
106 { FLAG_IDL_PROXY
, "_p.c" },
107 { FLAG_IDL_SERVER
, "_s.c" },
108 { FLAG_IDL_REGISTER
, "_r.res" },
109 { FLAG_IDL_HEADER
, ".h" }
112 #define HASH_SIZE 137
114 static struct list files
[HASH_SIZE
];
118 unsigned int count
; /* strings in use */
119 unsigned int size
; /* total allocated size */
123 static const struct strarray empty_strarray
;
125 enum install_rules
{ INSTALL_LIB
, INSTALL_DEV
, NB_INSTALL_RULES
};
127 /* variables common to all makefiles */
128 static struct strarray linguas
;
129 static struct strarray dll_flags
;
130 static struct strarray target_flags
;
131 static struct strarray msvcrt_flags
;
132 static struct strarray extra_cflags
;
133 static struct strarray cpp_flags
;
134 static struct strarray unwind_flags
;
135 static struct strarray libs
;
136 static struct strarray cmdline_vars
;
137 static const char *root_src_dir
;
138 static const char *tools_dir
;
139 static const char *tools_ext
;
140 static const char *exe_ext
;
141 static const char *dll_ext
;
142 static const char *man_ext
;
143 static const char *crosstarget
;
144 static const char *fontforge
;
145 static const char *convert
;
146 static const char *rsvg
;
147 static const char *icotool
;
148 static const char *dlltool
;
152 struct strarray vars
;
153 struct strarray include_paths
;
154 struct strarray define_args
;
155 struct strarray programs
;
156 struct strarray scripts
;
157 struct strarray appmode
;
158 struct strarray imports
;
159 struct strarray delayimports
;
160 struct strarray extradllflags
;
161 struct strarray install_lib
;
162 struct strarray install_dev
;
164 struct list includes
;
165 const char *base_dir
;
168 const char *top_src_dir
;
169 const char *top_obj_dir
;
170 const char *parent_dir
;
173 const char *sharedlib
;
174 const char *staticlib
;
175 const char *importlib
;
180 static struct makefile
*top_makefile
;
182 static const char *output_makefile_name
= "Makefile";
183 static const char *input_file_name
;
184 static const char *output_file_name
;
185 static const char *temp_file_name
;
186 static int relative_dir_mode
;
187 static int input_line
;
188 static int output_column
;
189 static FILE *output_file
;
191 static const char Usage
[] =
192 "Usage: makedep [options] directories\n"
194 " -R from to Compute the relative path between two directories\n"
195 " -fxxx Store output in file 'xxx' (default: Makefile)\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;
319 else return xrealloc( p
, n
+ 1 );
325 /*******************************************************************
328 static int strendswith( const char* str
, const char* end
)
330 size_t l
= strlen( str
);
331 size_t m
= strlen( 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( const 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 const 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 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 size_t name_len
= strlen( name
);
481 size_t 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 /*******************************************************************
494 static char *replace_filename( const char *path
, const char *name
)
500 if (!path
) return xstrdup( name
);
501 if (!(p
= strrchr( path
, '/' ))) return xstrdup( name
);
503 ret
= xmalloc( len
+ strlen( name
) + 1 );
504 memcpy( ret
, path
, len
);
505 strcpy( ret
+ len
, name
);
510 /*******************************************************************
511 * strarray_replace_extension
513 static struct strarray
strarray_replace_extension( const struct strarray
*array
,
514 const char *old_ext
, const char *new_ext
)
519 ret
.count
= ret
.size
= array
->count
;
520 ret
.str
= xmalloc( sizeof(ret
.str
[0]) * ret
.size
);
521 for (i
= 0; i
< array
->count
; i
++) ret
.str
[i
] = replace_extension( array
->str
[i
], old_ext
, new_ext
);
526 /*******************************************************************
529 static char *replace_substr( const char *str
, const char *start
, size_t len
, const char *replace
)
531 size_t pos
= start
- str
;
532 char *ret
= xmalloc( pos
+ strlen(replace
) + strlen(start
+ len
) + 1 );
533 memcpy( ret
, str
, pos
);
534 strcpy( ret
+ pos
, replace
);
535 strcat( ret
+ pos
, start
+ len
);
540 /*******************************************************************
543 * Determine where the destination path is located relative to the 'from' path.
545 static char *get_relative_path( const char *from
, const char *dest
)
549 unsigned int dotdots
= 0;
551 /* a path of "." is equivalent to an empty path */
552 if (!strcmp( from
, "." )) from
= "";
556 while (*from
== '/') from
++;
557 while (*dest
== '/') dest
++;
558 start
= dest
; /* save start of next path element */
561 while (*from
&& *from
!= '/' && *from
== *dest
) { from
++; dest
++; }
562 if ((!*from
|| *from
== '/') && (!*dest
|| *dest
== '/')) continue;
564 /* count remaining elements in 'from' */
568 while (*from
&& *from
!= '/') from
++;
569 while (*from
== '/') from
++;
575 if (!start
[0] && !dotdots
) return NULL
; /* empty path */
577 ret
= xmalloc( 3 * dotdots
+ strlen( start
) + 1 );
578 for (p
= ret
; dotdots
; dotdots
--, p
+= 3) memcpy( p
, "../", 3 );
580 if (start
[0]) strcpy( p
, start
);
581 else p
[-1] = 0; /* remove trailing slash */
586 /*******************************************************************
589 static char *concat_paths( const char *base
, const char *path
)
591 if (!base
|| !base
[0]) return xstrdup( path
&& path
[0] ? path
: "." );
592 if (!path
|| !path
[0]) return xstrdup( base
);
593 if (path
[0] == '/') return xstrdup( path
);
594 return strmake( "%s/%s", base
, path
);
598 /*******************************************************************
601 static char *base_dir_path( const struct makefile
*make
, const char *path
)
603 return concat_paths( make
->base_dir
, path
);
607 /*******************************************************************
610 static char *obj_dir_path( const struct makefile
*make
, const char *path
)
612 return concat_paths( make
->obj_dir
, path
);
616 /*******************************************************************
619 static char *src_dir_path( const struct makefile
*make
, const char *path
)
621 if (make
->src_dir
) return concat_paths( make
->src_dir
, path
);
622 return obj_dir_path( make
, path
);
626 /*******************************************************************
629 static char *top_obj_dir_path( const struct makefile
*make
, const char *path
)
631 return concat_paths( make
->top_obj_dir
, path
);
635 /*******************************************************************
638 static char *top_dir_path( const struct makefile
*make
, const char *path
)
640 if (make
->top_src_dir
) return concat_paths( make
->top_src_dir
, path
);
641 return top_obj_dir_path( make
, path
);
645 /*******************************************************************
648 static char *root_dir_path( const char *path
)
650 return concat_paths( root_src_dir
, path
);
654 /*******************************************************************
657 static char *tools_dir_path( const struct makefile
*make
, const char *path
)
659 if (tools_dir
) return top_obj_dir_path( make
, strmake( "%s/tools/%s", tools_dir
, path
));
660 return top_obj_dir_path( make
, strmake( "tools/%s", path
));
664 /*******************************************************************
667 static char *tools_path( const struct makefile
*make
, const char *name
)
669 return strmake( "%s/%s%s", tools_dir_path( make
, name
), name
, tools_ext
);
673 /*******************************************************************
676 static char *get_line( FILE *file
)
684 buffer
= xmalloc( size
);
686 if (!fgets( buffer
, size
, file
)) return NULL
;
691 char *p
= buffer
+ strlen(buffer
);
692 /* if line is larger than buffer, resize buffer */
693 while (p
== buffer
+ size
- 1 && p
[-1] != '\n')
695 buffer
= xrealloc( buffer
, size
* 2 );
696 if (!fgets( buffer
+ size
- 1, size
+ 1, file
)) break;
697 p
= buffer
+ strlen(buffer
);
700 if (p
> buffer
&& p
[-1] == '\n')
703 if (p
> buffer
&& p
[-1] == '\r') *(--p
) = 0;
704 if (p
> buffer
&& p
[-1] == '\\')
707 /* line ends in backslash, read continuation line */
708 if (!fgets( p
, size
- (p
- buffer
), file
)) return buffer
;
718 /*******************************************************************
721 static unsigned int hash_filename( const char *name
)
723 unsigned int ret
= 0;
724 while (*name
) ret
= (ret
<< 7) + (ret
<< 3) + *name
++;
725 return ret
% HASH_SIZE
;
729 /*******************************************************************
732 static struct file
*add_file( const char *name
)
734 struct file
*file
= xmalloc( sizeof(*file
) );
735 memset( file
, 0, sizeof(*file
) );
736 file
->name
= xstrdup( name
);
737 list_add_tail( &files
[hash_filename( name
)], &file
->entry
);
742 /*******************************************************************
745 static void add_dependency( struct file
*file
, const char *name
, enum incl_type type
)
747 /* enforce some rules for the Wine tree */
749 if (!memcmp( name
, "../", 3 ))
750 fatal_error( "#include directive with relative path not allowed\n" );
752 if (!strcmp( name
, "config.h" ))
754 if (strendswith( file
->name
, ".h" ))
755 fatal_error( "config.h must not be included by a header file\n" );
756 if (file
->deps_count
)
757 fatal_error( "config.h must be included before anything else\n" );
759 else if (!strcmp( name
, "wine/port.h" ))
761 if (strendswith( file
->name
, ".h" ))
762 fatal_error( "wine/port.h must not be included by a header file\n" );
763 if (!file
->deps_count
) fatal_error( "config.h must be included before wine/port.h\n" );
764 if (file
->deps_count
> 1)
765 fatal_error( "wine/port.h must be included before everything except config.h\n" );
766 if (strcmp( file
->deps
[0].name
, "config.h" ))
767 fatal_error( "config.h must be included before wine/port.h\n" );
770 if (file
->deps_count
>= file
->deps_size
)
772 file
->deps_size
*= 2;
773 if (file
->deps_size
< 16) file
->deps_size
= 16;
774 file
->deps
= xrealloc( file
->deps
, file
->deps_size
* sizeof(*file
->deps
) );
776 file
->deps
[file
->deps_count
].line
= input_line
;
777 file
->deps
[file
->deps_count
].type
= type
;
778 file
->deps
[file
->deps_count
].name
= xstrdup( name
);
783 /*******************************************************************
786 static struct incl_file
*find_src_file( const struct makefile
*make
, const char *name
)
788 struct incl_file
*file
;
790 LIST_FOR_EACH_ENTRY( file
, &make
->sources
, struct incl_file
, entry
)
791 if (!strcmp( name
, file
->name
)) return file
;
795 /*******************************************************************
798 static struct incl_file
*find_include_file( const struct makefile
*make
, const char *name
)
800 struct incl_file
*file
;
802 LIST_FOR_EACH_ENTRY( file
, &make
->includes
, struct incl_file
, entry
)
803 if (!strcmp( name
, file
->name
)) return file
;
807 /*******************************************************************
810 * Add an include file if it doesn't already exists.
812 static struct incl_file
*add_include( struct makefile
*make
, struct incl_file
*parent
,
813 const char *name
, int line
, enum incl_type type
)
815 struct incl_file
*include
;
817 if (parent
->files_count
>= parent
->files_size
)
819 parent
->files_size
*= 2;
820 if (parent
->files_size
< 16) parent
->files_size
= 16;
821 parent
->files
= xrealloc( parent
->files
, parent
->files_size
* sizeof(*parent
->files
) );
824 LIST_FOR_EACH_ENTRY( include
, &make
->includes
, struct incl_file
, entry
)
825 if (!strcmp( name
, include
->name
)) goto found
;
827 include
= xmalloc( sizeof(*include
) );
828 memset( include
, 0, sizeof(*include
) );
829 include
->name
= xstrdup(name
);
830 include
->included_by
= parent
;
831 include
->included_line
= line
;
832 include
->type
= type
;
833 list_add_tail( &make
->includes
, &include
->entry
);
835 parent
->files
[parent
->files_count
++] = include
;
840 /*******************************************************************
841 * add_generated_source
843 * Add a generated source file to the list.
845 static struct incl_file
*add_generated_source( struct makefile
*make
,
846 const char *name
, const char *filename
)
848 struct incl_file
*file
;
850 if ((file
= find_src_file( make
, name
))) return file
; /* we already have it */
851 file
= xmalloc( sizeof(*file
) );
852 memset( file
, 0, sizeof(*file
) );
853 file
->file
= add_file( name
);
854 file
->name
= xstrdup( name
);
855 file
->filename
= obj_dir_path( make
, filename
? filename
: name
);
856 file
->file
->flags
= FLAG_GENERATED
;
857 list_add_tail( &make
->sources
, &file
->entry
);
862 /*******************************************************************
863 * parse_include_directive
865 static void parse_include_directive( struct file
*source
, char *str
)
867 char quote
, *include
, *p
= str
;
869 while (*p
&& isspace(*p
)) p
++;
870 if (*p
!= '\"' && *p
!= '<' ) return;
872 if (quote
== '<') quote
= '>';
874 while (*p
&& (*p
!= quote
)) p
++;
875 if (!*p
) fatal_error( "malformed include directive '%s'\n", str
);
877 add_dependency( source
, include
, (quote
== '>') ? INCL_SYSTEM
: INCL_NORMAL
);
881 /*******************************************************************
882 * parse_pragma_directive
884 static void parse_pragma_directive( struct file
*source
, char *str
)
886 char *flag
, *p
= str
;
888 if (!isspace( *p
)) return;
889 while (*p
&& isspace(*p
)) p
++;
890 p
= strtok( p
, " \t" );
891 if (strcmp( p
, "makedep" )) return;
893 while ((flag
= strtok( NULL
, " \t" )))
895 if (!strcmp( flag
, "depend" ))
897 while ((p
= strtok( NULL
, " \t" ))) add_dependency( source
, p
, INCL_NORMAL
);
900 else if (!strcmp( flag
, "install" )) source
->flags
|= FLAG_INSTALL
;
902 if (strendswith( source
->name
, ".idl" ))
904 if (!strcmp( flag
, "header" )) source
->flags
|= FLAG_IDL_HEADER
;
905 else if (!strcmp( flag
, "proxy" )) source
->flags
|= FLAG_IDL_PROXY
;
906 else if (!strcmp( flag
, "client" )) source
->flags
|= FLAG_IDL_CLIENT
;
907 else if (!strcmp( flag
, "server" )) source
->flags
|= FLAG_IDL_SERVER
;
908 else if (!strcmp( flag
, "ident" )) source
->flags
|= FLAG_IDL_IDENT
;
909 else if (!strcmp( flag
, "typelib" )) source
->flags
|= FLAG_IDL_TYPELIB
;
910 else if (!strcmp( flag
, "register" )) source
->flags
|= FLAG_IDL_REGISTER
;
911 else if (!strcmp( flag
, "regtypelib" )) source
->flags
|= FLAG_IDL_REGTYPELIB
;
913 else if (strendswith( source
->name
, ".rc" ))
915 if (!strcmp( flag
, "po" )) source
->flags
|= FLAG_RC_PO
;
917 else if (strendswith( source
->name
, ".sfd" ))
919 if (!strcmp( flag
, "font" ))
921 struct strarray
*array
= source
->args
;
925 source
->args
= array
= xmalloc( sizeof(*array
) );
926 *array
= empty_strarray
;
927 source
->flags
|= FLAG_SFD_FONTS
;
929 strarray_add( array
, xstrdup( strtok( NULL
, "" )));
933 else if (!strcmp( flag
, "implib" )) source
->flags
|= FLAG_C_IMPLIB
;
938 /*******************************************************************
939 * parse_cpp_directive
941 static void parse_cpp_directive( struct file
*source
, char *str
)
943 while (*str
&& isspace(*str
)) str
++;
944 if (*str
++ != '#') return;
945 while (*str
&& isspace(*str
)) str
++;
947 if (!strncmp( str
, "include", 7 ))
948 parse_include_directive( source
, str
+ 7 );
949 else if (!strncmp( str
, "import", 6 ) && strendswith( source
->name
, ".m" ))
950 parse_include_directive( source
, str
+ 6 );
951 else if (!strncmp( str
, "pragma", 6 ))
952 parse_pragma_directive( source
, str
+ 6 );
956 /*******************************************************************
959 static void parse_idl_file( struct file
*source
, FILE *file
)
961 char *buffer
, *include
;
965 while ((buffer
= get_line( file
)))
969 while (*p
&& isspace(*p
)) p
++;
971 if (!strncmp( p
, "importlib", 9 ))
974 while (*p
&& isspace(*p
)) p
++;
975 if (*p
++ != '(') continue;
976 while (*p
&& isspace(*p
)) p
++;
977 if (*p
++ != '"') continue;
979 while (*p
&& (*p
!= '"')) p
++;
980 if (!*p
) fatal_error( "malformed importlib directive\n" );
982 add_dependency( source
, include
, INCL_IMPORTLIB
);
986 if (!strncmp( p
, "import", 6 ))
989 while (*p
&& isspace(*p
)) p
++;
990 if (*p
!= '"') continue;
992 while (*p
&& (*p
!= '"')) p
++;
993 if (!*p
) fatal_error( "malformed import directive\n" );
995 add_dependency( source
, include
, INCL_IMPORT
);
999 /* check for #include inside cpp_quote */
1000 if (!strncmp( p
, "cpp_quote", 9 ))
1003 while (*p
&& isspace(*p
)) p
++;
1004 if (*p
++ != '(') continue;
1005 while (*p
&& isspace(*p
)) p
++;
1006 if (*p
++ != '"') continue;
1007 if (*p
++ != '#') continue;
1008 while (*p
&& isspace(*p
)) p
++;
1009 if (strncmp( p
, "include", 7 )) continue;
1011 while (*p
&& isspace(*p
)) p
++;
1012 if (*p
== '\\' && p
[1] == '"')
1019 if (*p
++ != '<' ) continue;
1023 while (*p
&& (*p
!= quote
)) p
++;
1024 if (!*p
|| (quote
== '"' && p
[-1] != '\\'))
1025 fatal_error( "malformed #include directive inside cpp_quote\n" );
1026 if (quote
== '"') p
--; /* remove backslash */
1028 add_dependency( source
, include
, (quote
== '>') ? INCL_CPP_QUOTE_SYSTEM
: INCL_CPP_QUOTE
);
1032 parse_cpp_directive( source
, p
);
1036 /*******************************************************************
1039 static void parse_c_file( struct file
*source
, FILE *file
)
1044 while ((buffer
= get_line( file
)))
1046 parse_cpp_directive( source
, buffer
);
1051 /*******************************************************************
1054 static void parse_rc_file( struct file
*source
, FILE *file
)
1056 char *buffer
, *include
;
1059 while ((buffer
= get_line( file
)))
1063 while (*p
&& isspace(*p
)) p
++;
1065 if (p
[0] == '/' && p
[1] == '*') /* check for magic makedep comment */
1068 while (*p
&& isspace(*p
)) p
++;
1069 if (strncmp( p
, "@makedep:", 9 )) continue;
1071 while (*p
&& isspace(*p
)) p
++;
1076 while (*p
&& *p
!= quote
) p
++;
1081 while (*p
&& !isspace(*p
) && *p
!= '*') p
++;
1084 fatal_error( "malformed makedep comment\n" );
1086 add_dependency( source
, include
, (quote
== '>') ? INCL_SYSTEM
: INCL_NORMAL
);
1090 parse_cpp_directive( source
, buffer
);
1095 /*******************************************************************
1098 static void parse_in_file( struct file
*source
, FILE *file
)
1102 /* make sure it gets rebuilt when the version changes */
1103 add_dependency( source
, "config.h", INCL_SYSTEM
);
1105 if (!strendswith( source
->name
, ".man.in" )) return; /* not a man page */
1108 while ((buffer
= get_line( file
)))
1110 if (strncmp( buffer
, ".TH", 3 )) continue;
1111 if (!(p
= strtok( buffer
, " \t" ))) continue; /* .TH */
1112 if (!(p
= strtok( NULL
, " \t" ))) continue; /* program name */
1113 if (!(p
= strtok( NULL
, " \t" ))) continue; /* man section */
1114 source
->args
= xstrdup( p
);
1120 /*******************************************************************
1123 static void parse_sfd_file( struct file
*source
, FILE *file
)
1125 char *p
, *eol
, *buffer
;
1128 while ((buffer
= get_line( file
)))
1130 if (strncmp( buffer
, "UComments:", 10 )) continue;
1132 while (*p
== ' ') p
++;
1133 if (p
[0] == '"' && p
[1] && buffer
[strlen(buffer
) - 1] == '"')
1136 buffer
[strlen(buffer
) - 1] = 0;
1138 while ((eol
= strstr( p
, "+AAoA" )))
1141 while (*p
&& isspace(*p
)) p
++;
1144 while (*p
&& isspace(*p
)) p
++;
1145 if (!strncmp( p
, "pragma", 6 )) parse_pragma_directive( source
, p
+ 6 );
1149 while (*p
&& isspace(*p
)) p
++;
1150 if (*p
++ != '#') return;
1151 while (*p
&& isspace(*p
)) p
++;
1152 if (!strncmp( p
, "pragma", 6 )) parse_pragma_directive( source
, p
+ 6 );
1161 void (*parse
)( struct file
*file
, FILE *f
);
1162 } parse_functions
[] =
1164 { ".c", parse_c_file
},
1165 { ".h", parse_c_file
},
1166 { ".inl", parse_c_file
},
1167 { ".l", parse_c_file
},
1168 { ".m", parse_c_file
},
1169 { ".rh", parse_c_file
},
1170 { ".x", parse_c_file
},
1171 { ".y", parse_c_file
},
1172 { ".idl", parse_idl_file
},
1173 { ".rc", parse_rc_file
},
1174 { ".in", parse_in_file
},
1175 { ".sfd", parse_sfd_file
}
1178 /*******************************************************************
1181 static struct file
*load_file( const char *name
)
1185 unsigned int i
, hash
= hash_filename( name
);
1187 LIST_FOR_EACH_ENTRY( file
, &files
[hash
], struct file
, entry
)
1188 if (!strcmp( name
, file
->name
)) return file
;
1190 if (!(f
= fopen( name
, "r" ))) return NULL
;
1192 file
= add_file( name
);
1193 input_file_name
= file
->name
;
1196 for (i
= 0; i
< sizeof(parse_functions
) / sizeof(parse_functions
[0]); i
++)
1198 if (!strendswith( name
, parse_functions
[i
].ext
)) continue;
1199 parse_functions
[i
].parse( file
, f
);
1204 input_file_name
= NULL
;
1210 /*******************************************************************
1211 * open_include_path_file
1213 * Open a file from a directory on the include path.
1215 static struct file
*open_include_path_file( const struct makefile
*make
, const char *dir
,
1216 const char *name
, char **filename
)
1218 char *src_path
= base_dir_path( make
, concat_paths( dir
, name
));
1219 struct file
*ret
= load_file( src_path
);
1221 if (ret
) *filename
= src_dir_path( make
, concat_paths( dir
, name
));
1226 /*******************************************************************
1227 * open_file_same_dir
1229 * Open a file in the same directory as the parent.
1231 static struct file
*open_file_same_dir( const struct incl_file
*parent
, const char *name
, char **filename
)
1233 char *src_path
= replace_filename( parent
->file
->name
, name
);
1234 struct file
*ret
= load_file( src_path
);
1236 if (ret
) *filename
= replace_filename( parent
->filename
, name
);
1242 /*******************************************************************
1245 * Open a file in the source directory of the makefile.
1247 static struct file
*open_local_file( const struct makefile
*make
, const char *path
, char **filename
)
1249 char *src_path
= root_dir_path( base_dir_path( make
, path
));
1250 struct file
*ret
= load_file( src_path
);
1252 /* if not found, try parent dir */
1253 if (!ret
&& make
->parent_dir
)
1256 path
= strmake( "%s/%s", make
->parent_dir
, path
);
1257 src_path
= root_dir_path( base_dir_path( make
, path
));
1258 ret
= load_file( src_path
);
1261 if (ret
) *filename
= src_dir_path( make
, path
);
1267 /*******************************************************************
1270 * Open a file in the top-level source directory.
1272 static struct file
*open_global_file( const struct makefile
*make
, const char *path
, char **filename
)
1274 char *src_path
= root_dir_path( path
);
1275 struct file
*ret
= load_file( src_path
);
1277 if (ret
) *filename
= top_dir_path( make
, path
);
1283 /*******************************************************************
1284 * open_global_header
1286 * Open a file in the global include source directory.
1288 static struct file
*open_global_header( const struct makefile
*make
, const char *path
, char **filename
)
1290 return open_global_file( make
, strmake( "include/%s", path
), filename
);
1294 /*******************************************************************
1297 static struct file
*open_src_file( const struct makefile
*make
, struct incl_file
*pFile
)
1299 struct file
*file
= open_local_file( make
, pFile
->name
, &pFile
->filename
);
1301 if (!file
) fatal_perror( "open %s", pFile
->name
);
1306 /*******************************************************************
1309 static struct file
*open_include_file( const struct makefile
*make
, struct incl_file
*pFile
)
1311 struct file
*file
= NULL
;
1313 unsigned int i
, len
;
1317 /* check for generated bison header */
1319 if (strendswith( pFile
->name
, ".tab.h" ) &&
1320 (file
= open_local_file( make
, replace_extension( pFile
->name
, ".tab.h", ".y" ), &filename
)))
1322 pFile
->sourcename
= filename
;
1323 pFile
->filename
= obj_dir_path( make
, pFile
->name
);
1327 /* check for corresponding idl file in source dir */
1329 if (strendswith( pFile
->name
, ".h" ) &&
1330 (file
= open_local_file( make
, replace_extension( pFile
->name
, ".h", ".idl" ), &filename
)))
1332 pFile
->sourcename
= filename
;
1333 pFile
->filename
= obj_dir_path( make
, pFile
->name
);
1337 /* check for corresponding tlb file in source dir */
1339 if (strendswith( pFile
->name
, ".tlb" ) &&
1340 (file
= open_local_file( make
, replace_extension( pFile
->name
, ".tlb", ".idl" ), &filename
)))
1342 pFile
->sourcename
= filename
;
1343 pFile
->filename
= obj_dir_path( make
, pFile
->name
);
1347 /* now try in source dir */
1348 if ((file
= open_local_file( make
, pFile
->name
, &pFile
->filename
))) return file
;
1350 /* check for corresponding idl file in global includes */
1352 if (strendswith( pFile
->name
, ".h" ) &&
1353 (file
= open_global_header( make
, replace_extension( pFile
->name
, ".h", ".idl" ), &filename
)))
1355 pFile
->sourcename
= filename
;
1356 pFile
->filename
= top_obj_dir_path( make
, strmake( "include/%s", pFile
->name
));
1360 /* check for corresponding .in file in global includes (for config.h.in) */
1362 if (strendswith( pFile
->name
, ".h" ) &&
1363 (file
= open_global_header( make
, replace_extension( pFile
->name
, ".h", ".h.in" ), &filename
)))
1365 pFile
->sourcename
= filename
;
1366 pFile
->filename
= top_obj_dir_path( make
, strmake( "include/%s", pFile
->name
));
1370 /* check for corresponding .x file in global includes */
1372 if (strendswith( pFile
->name
, "tmpl.h" ) &&
1373 (file
= open_global_header( make
, replace_extension( pFile
->name
, ".h", ".x" ), &filename
)))
1375 pFile
->sourcename
= filename
;
1376 pFile
->filename
= top_obj_dir_path( make
, strmake( "include/%s", pFile
->name
));
1380 /* check for corresponding .tlb file in global includes */
1382 if (strendswith( pFile
->name
, ".tlb" ) &&
1383 (file
= open_global_header( make
, replace_extension( pFile
->name
, ".tlb", ".idl" ), &filename
)))
1385 pFile
->sourcename
= filename
;
1386 pFile
->filename
= top_obj_dir_path( make
, strmake( "include/%s", pFile
->name
));
1390 /* check in global includes source dir */
1392 if ((file
= open_global_header( make
, pFile
->name
, &pFile
->filename
))) return file
;
1394 /* check in global msvcrt includes */
1395 if (make
->use_msvcrt
&&
1396 (file
= open_global_header( make
, strmake( "msvcrt/%s", pFile
->name
), &pFile
->filename
)))
1399 /* now search in include paths */
1400 for (i
= 0; i
< make
->include_paths
.count
; i
++)
1402 const char *dir
= make
->include_paths
.str
[i
];
1403 const char *prefix
= make
->top_src_dir
? make
->top_src_dir
: make
->top_obj_dir
;
1407 len
= strlen( prefix
);
1408 if (!strncmp( dir
, prefix
, len
) && (!dir
[len
] || dir
[len
] == '/'))
1410 while (dir
[len
] == '/') len
++;
1411 file
= open_global_file( make
, concat_paths( dir
+ len
, pFile
->name
), &pFile
->filename
);
1412 if (file
) return file
;
1414 if (make
->top_src_dir
) continue; /* ignore paths that don't point to the top source dir */
1418 if ((file
= open_include_path_file( make
, dir
, pFile
->name
, &pFile
->filename
)))
1422 if (pFile
->type
== INCL_SYSTEM
) return NULL
; /* ignore system files we cannot find */
1424 /* try in src file directory */
1425 if ((file
= open_file_same_dir( pFile
->included_by
, pFile
->name
, &pFile
->filename
))) return file
;
1427 fprintf( stderr
, "%s:%d: error: ", pFile
->included_by
->file
->name
, pFile
->included_line
);
1428 perror( pFile
->name
);
1429 pFile
= pFile
->included_by
;
1430 while (pFile
&& pFile
->included_by
)
1432 const char *parent
= pFile
->included_by
->sourcename
;
1433 if (!parent
) parent
= pFile
->included_by
->file
->name
;
1434 fprintf( stderr
, "%s:%d: note: %s was first included here\n",
1435 parent
, pFile
->included_line
, pFile
->name
);
1436 pFile
= pFile
->included_by
;
1442 /*******************************************************************
1445 static void add_all_includes( struct makefile
*make
, struct incl_file
*parent
, struct file
*file
)
1449 parent
->files_count
= 0;
1450 parent
->files_size
= file
->deps_count
;
1451 parent
->files
= xmalloc( parent
->files_size
* sizeof(*parent
->files
) );
1452 for (i
= 0; i
< file
->deps_count
; i
++)
1454 switch (file
->deps
[i
].type
)
1458 add_include( make
, parent
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_NORMAL
);
1460 case INCL_IMPORTLIB
:
1461 add_include( make
, parent
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_IMPORTLIB
);
1464 add_include( make
, parent
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_SYSTEM
);
1466 case INCL_CPP_QUOTE
:
1467 case INCL_CPP_QUOTE_SYSTEM
:
1474 /*******************************************************************
1477 static void parse_file( struct makefile
*make
, struct incl_file
*source
, int src
)
1479 struct file
*file
= src
? open_src_file( make
, source
) : open_include_file( make
, source
);
1483 source
->file
= file
;
1484 source
->files_count
= 0;
1485 source
->files_size
= file
->deps_count
;
1486 source
->files
= xmalloc( source
->files_size
* sizeof(*source
->files
) );
1488 if (source
->sourcename
)
1490 if (strendswith( source
->sourcename
, ".idl" ))
1494 if (strendswith( source
->name
, ".tlb" )) return; /* typelibs don't include anything */
1496 /* generated .h file always includes these */
1497 add_include( make
, source
, "rpc.h", 0, INCL_NORMAL
);
1498 add_include( make
, source
, "rpcndr.h", 0, INCL_NORMAL
);
1499 for (i
= 0; i
< file
->deps_count
; i
++)
1501 switch (file
->deps
[i
].type
)
1504 if (strendswith( file
->deps
[i
].name
, ".idl" ))
1505 add_include( make
, source
, replace_extension( file
->deps
[i
].name
, ".idl", ".h" ),
1506 file
->deps
[i
].line
, INCL_NORMAL
);
1508 add_include( make
, source
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_NORMAL
);
1510 case INCL_CPP_QUOTE
:
1511 add_include( make
, source
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_NORMAL
);
1513 case INCL_CPP_QUOTE_SYSTEM
:
1514 add_include( make
, source
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_SYSTEM
);
1518 case INCL_IMPORTLIB
:
1524 if (strendswith( source
->sourcename
, ".y" ))
1525 return; /* generated .tab.h doesn't include anything */
1528 add_all_includes( make
, source
, file
);
1532 /*******************************************************************
1535 * Add a source file to the list.
1537 static struct incl_file
*add_src_file( struct makefile
*make
, const char *name
)
1539 struct incl_file
*file
;
1541 if ((file
= find_src_file( make
, name
))) return file
; /* we already have it */
1542 file
= xmalloc( sizeof(*file
) );
1543 memset( file
, 0, sizeof(*file
) );
1544 file
->name
= xstrdup(name
);
1545 list_add_tail( &make
->sources
, &file
->entry
);
1546 parse_file( make
, file
, 1 );
1551 /*******************************************************************
1552 * open_input_makefile
1554 static FILE *open_input_makefile( const struct makefile
*make
)
1559 input_file_name
= root_dir_path( base_dir_path( make
, strmake( "%s.in", output_makefile_name
)));
1561 input_file_name
= output_makefile_name
; /* always use output name for main Makefile */
1564 if (!(ret
= fopen( input_file_name
, "r" ))) fatal_perror( "open" );
1569 /*******************************************************************
1572 static const char *get_make_variable( const struct makefile
*make
, const char *name
)
1576 if ((ret
= strarray_get_value( &cmdline_vars
, name
))) return ret
;
1577 if ((ret
= strarray_get_value( &make
->vars
, name
))) return ret
;
1578 if (top_makefile
&& (ret
= strarray_get_value( &top_makefile
->vars
, name
))) return ret
;
1583 /*******************************************************************
1584 * get_expanded_make_variable
1586 static char *get_expanded_make_variable( const struct makefile
*make
, const char *name
)
1589 char *p
, *end
, *expand
, *tmp
;
1591 var
= get_make_variable( make
, name
);
1592 if (!var
) return NULL
;
1594 p
= expand
= xstrdup( var
);
1595 while ((p
= strchr( p
, '$' )))
1599 if (!(end
= strchr( p
+ 2, ')' ))) fatal_error( "syntax error in '%s'\n", expand
);
1601 if (strchr( p
+ 2, ':' )) fatal_error( "pattern replacement not supported for '%s'\n", p
+ 2 );
1602 var
= get_make_variable( make
, p
+ 2 );
1603 tmp
= replace_substr( expand
, p
, end
- p
, var
? var
: "" );
1604 /* switch to the new string */
1605 p
= tmp
+ (p
- expand
);
1609 else if (p
[1] == '{') /* don't expand ${} variables */
1611 if (!(end
= strchr( p
+ 2, '}' ))) fatal_error( "syntax error in '%s'\n", expand
);
1614 else if (p
[1] == '$')
1618 else fatal_error( "syntax error in '%s'\n", expand
);
1621 /* consider empty variables undefined */
1623 while (*p
&& isspace(*p
)) p
++;
1624 if (*p
) return expand
;
1630 /*******************************************************************
1631 * get_expanded_make_var_array
1633 static struct strarray
get_expanded_make_var_array( const struct makefile
*make
, const char *name
)
1635 struct strarray ret
= empty_strarray
;
1636 char *value
, *token
;
1638 if ((value
= get_expanded_make_variable( make
, name
)))
1639 for (token
= strtok( value
, " \t" ); token
; token
= strtok( NULL
, " \t" ))
1640 strarray_add( &ret
, token
);
1645 /*******************************************************************
1648 static char *file_local_var( const char *file
, const char *name
)
1652 var
= strmake( "%s_%s", file
, name
);
1653 for (p
= var
; *p
; p
++) if (!isalnum( *p
)) *p
= '_';
1658 /*******************************************************************
1661 static int set_make_variable( struct strarray
*array
, const char *assignment
)
1665 p
= name
= xstrdup( assignment
);
1666 while (isalnum(*p
) || *p
== '_') p
++;
1667 if (name
== p
) return 0; /* not a variable */
1671 while (isspace(*p
)) p
++;
1673 if (*p
!= '=') return 0; /* not an assignment */
1675 while (isspace(*p
)) p
++;
1677 strarray_set_value( array
, name
, p
);
1682 /*******************************************************************
1685 static struct makefile
*parse_makefile( const char *path
, const char *separator
)
1689 struct makefile
*make
= xmalloc( sizeof(*make
) );
1691 memset( make
, 0, sizeof(*make
) );
1694 make
->top_obj_dir
= get_relative_path( path
, "" );
1695 make
->base_dir
= path
;
1696 if (!strcmp( make
->base_dir
, "." )) make
->base_dir
= NULL
;
1699 file
= open_input_makefile( make
);
1700 while ((buffer
= get_line( file
)))
1702 if (separator
&& !strncmp( buffer
, separator
, strlen(separator
) )) break;
1703 if (*buffer
== '\t') continue; /* command */
1704 while (isspace( *buffer
)) buffer
++;
1705 if (*buffer
== '#') continue; /* comment */
1706 set_make_variable( &make
->vars
, buffer
);
1709 input_file_name
= NULL
;
1714 /*******************************************************************
1715 * add_generated_sources
1717 static void add_generated_sources( struct makefile
*make
)
1719 struct incl_file
*source
, *next
, *file
;
1721 LIST_FOR_EACH_ENTRY_SAFE( source
, next
, &make
->sources
, struct incl_file
, entry
)
1723 if (source
->file
->flags
& FLAG_IDL_CLIENT
)
1725 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_c.c" ), NULL
);
1726 add_dependency( file
->file
, replace_extension( source
->name
, ".idl", ".h" ), INCL_NORMAL
);
1727 add_all_includes( make
, file
, file
->file
);
1729 if (source
->file
->flags
& FLAG_IDL_SERVER
)
1731 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_s.c" ), NULL
);
1732 add_dependency( file
->file
, "wine/exception.h", INCL_NORMAL
);
1733 add_dependency( file
->file
, replace_extension( source
->name
, ".idl", ".h" ), INCL_NORMAL
);
1734 add_all_includes( make
, file
, file
->file
);
1736 if (source
->file
->flags
& FLAG_IDL_IDENT
)
1738 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_i.c" ), NULL
);
1739 add_dependency( file
->file
, "rpc.h", INCL_NORMAL
);
1740 add_dependency( file
->file
, "rpcndr.h", INCL_NORMAL
);
1741 add_dependency( file
->file
, "guiddef.h", INCL_NORMAL
);
1742 add_all_includes( make
, file
, file
->file
);
1744 if (source
->file
->flags
& FLAG_IDL_PROXY
)
1746 file
= add_generated_source( make
, "dlldata.o", "dlldata.c" );
1747 add_dependency( file
->file
, "objbase.h", INCL_NORMAL
);
1748 add_dependency( file
->file
, "rpcproxy.h", INCL_NORMAL
);
1749 add_all_includes( make
, file
, file
->file
);
1750 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_p.c" ), NULL
);
1751 add_dependency( file
->file
, "objbase.h", INCL_NORMAL
);
1752 add_dependency( file
->file
, "rpcproxy.h", INCL_NORMAL
);
1753 add_dependency( file
->file
, "wine/exception.h", INCL_NORMAL
);
1754 add_dependency( file
->file
, replace_extension( source
->name
, ".idl", ".h" ), INCL_NORMAL
);
1755 add_all_includes( make
, file
, file
->file
);
1757 if (source
->file
->flags
& FLAG_IDL_TYPELIB
)
1759 add_generated_source( make
, replace_extension( source
->name
, ".idl", ".tlb" ), NULL
);
1761 if (source
->file
->flags
& FLAG_IDL_REGTYPELIB
)
1763 add_generated_source( make
, replace_extension( source
->name
, ".idl", "_t.res" ), NULL
);
1765 if (source
->file
->flags
& FLAG_IDL_REGISTER
)
1767 add_generated_source( make
, replace_extension( source
->name
, ".idl", "_r.res" ), NULL
);
1769 if (source
->file
->flags
& FLAG_IDL_HEADER
)
1771 add_generated_source( make
, replace_extension( source
->name
, ".idl", ".h" ), NULL
);
1773 if (!source
->file
->flags
&& strendswith( source
->name
, ".idl" ))
1775 add_generated_source( make
, replace_extension( source
->name
, ".idl", ".h" ), NULL
);
1777 if (strendswith( source
->name
, ".x" ))
1779 add_generated_source( make
, replace_extension( source
->name
, ".x", ".h" ), NULL
);
1781 if (strendswith( source
->name
, ".y" ))
1783 file
= add_generated_source( make
, replace_extension( source
->name
, ".y", ".tab.c" ), NULL
);
1784 /* steal the includes list from the source file */
1785 file
->files_count
= source
->files_count
;
1786 file
->files_size
= source
->files_size
;
1787 file
->files
= source
->files
;
1788 source
->files_count
= source
->files_size
= 0;
1789 source
->files
= NULL
;
1791 if (strendswith( source
->name
, ".l" ))
1793 file
= add_generated_source( make
, replace_extension( source
->name
, ".l", ".yy.c" ), NULL
);
1794 /* steal the includes list from the source file */
1795 file
->files_count
= source
->files_count
;
1796 file
->files_size
= source
->files_size
;
1797 file
->files
= source
->files
;
1798 source
->files_count
= source
->files_size
= 0;
1799 source
->files
= NULL
;
1804 file
= add_generated_source( make
, "testlist.o", "testlist.c" );
1805 add_dependency( file
->file
, "wine/test.h", INCL_NORMAL
);
1806 add_all_includes( make
, file
, file
->file
);
1811 /*******************************************************************
1814 static void create_dir( const char *dir
)
1818 p
= path
= xstrdup( dir
);
1819 while ((p
= strchr( p
, '/' )))
1822 if (mkdir( path
, 0755 ) == -1 && errno
!= EEXIST
) fatal_perror( "mkdir %s", path
);
1824 while (*p
== '/') p
++;
1826 if (mkdir( path
, 0755 ) == -1 && errno
!= EEXIST
) fatal_perror( "mkdir %s", path
);
1831 /*******************************************************************
1832 * output_filenames_obj_dir
1834 static void output_filenames_obj_dir( const struct makefile
*make
, struct strarray array
)
1838 for (i
= 0; i
< array
.count
; i
++) output_filename( obj_dir_path( make
, array
.str
[i
] ));
1842 /*******************************************************************
1845 static void get_dependencies( struct strarray
*deps
, struct incl_file
*file
, struct incl_file
*source
)
1849 if (!file
->filename
) return;
1853 if (file
->owner
== source
) return; /* already processed */
1854 if (file
->type
== INCL_IMPORTLIB
&&
1855 !(source
->file
->flags
& (FLAG_IDL_TYPELIB
| FLAG_IDL_REGTYPELIB
)))
1856 return; /* library is imported only when building a typelib */
1857 file
->owner
= source
;
1858 strarray_add( deps
, file
->filename
);
1860 for (i
= 0; i
< file
->files_count
; i
++) get_dependencies( deps
, file
->files
[i
], source
);
1864 /*******************************************************************
1865 * get_local_dependencies
1867 * Get the local dependencies of a given target.
1869 static struct strarray
get_local_dependencies( const struct makefile
*make
, const char *name
,
1870 struct strarray targets
)
1873 struct strarray deps
= get_expanded_make_var_array( make
, file_local_var( name
, "DEPS" ));
1875 for (i
= 0; i
< deps
.count
; i
++)
1877 if (strarray_exists( &targets
, deps
.str
[i
] ))
1878 deps
.str
[i
] = obj_dir_path( make
, deps
.str
[i
] );
1880 deps
.str
[i
] = src_dir_path( make
, deps
.str
[i
] );
1886 /*******************************************************************
1889 static void add_install_rule( const struct makefile
*make
, struct strarray
*install_rules
,
1890 const char *target
, const char *file
, const char *dest
)
1892 if (strarray_exists( &make
->install_lib
, target
))
1894 strarray_add( &install_rules
[INSTALL_LIB
], file
);
1895 strarray_add( &install_rules
[INSTALL_LIB
], dest
);
1897 else if (strarray_exists( &make
->install_dev
, target
))
1899 strarray_add( &install_rules
[INSTALL_DEV
], file
);
1900 strarray_add( &install_rules
[INSTALL_DEV
], dest
);
1905 /*******************************************************************
1906 * get_include_install_path
1908 * Determine the installation path for a given include file.
1910 static const char *get_include_install_path( const char *name
)
1912 if (!strncmp( name
, "wine/", 5 )) return name
+ 5;
1913 if (!strncmp( name
, "msvcrt/", 7 )) return name
;
1914 return strmake( "windows/%s", name
);
1918 /*******************************************************************
1919 * get_shared_library_name
1921 * Determine possible names for a shared library with a version number.
1923 static struct strarray
get_shared_lib_names( const char *libname
)
1925 struct strarray ret
= empty_strarray
;
1926 const char *ext
, *p
;
1927 char *name
, *first
, *second
;
1930 strarray_add( &ret
, libname
);
1932 for (p
= libname
; (p
= strchr( p
, '.' )); p
++)
1933 if ((len
= strspn( p
+ 1, "0123456789." ))) break;
1935 if (!len
) return ret
;
1937 if (*ext
&& ext
[-1] == '.') ext
--;
1939 /* keep only the first group of digits */
1940 name
= xstrdup( libname
);
1941 first
= name
+ (p
- libname
);
1942 if ((second
= strchr( first
+ 1, '.' )))
1944 strcpy( second
, ext
);
1945 strarray_add( &ret
, xstrdup( name
));
1947 /* now remove all digits */
1948 strcpy( first
, ext
);
1949 strarray_add( &ret
, name
);
1954 /*******************************************************************
1955 * output_install_rules
1957 * Rules are stored as a (file,dest) pair of values.
1958 * The first char of dest indicates the type of install.
1960 static struct strarray
output_install_rules( const struct makefile
*make
, struct strarray files
,
1961 const char *target
, struct strarray
*phony_targets
)
1965 struct strarray uninstall
= empty_strarray
;
1966 struct strarray targets
= empty_strarray
;
1968 if (!files
.count
) return uninstall
;
1970 for (i
= 0; i
< files
.count
; i
+= 2)
1971 if (strchr( "dps", files
.str
[i
+ 1][0] )) /* only for files copied from object dir */
1972 strarray_add_uniq( &targets
, files
.str
[i
] );
1974 output( "install %s::", target
);
1975 output_filenames_obj_dir( make
, targets
);
1978 install_sh
= top_dir_path( make
, "tools/install-sh" );
1979 for (i
= 0; i
< files
.count
; i
+= 2)
1981 const char *file
= files
.str
[i
];
1982 const char *dest
= files
.str
[i
+ 1];
1986 case 'd': /* data file */
1987 output( "\t%s -m 644 $(INSTALL_DATA_FLAGS) %s $(DESTDIR)%s\n",
1988 install_sh
, obj_dir_path( make
, file
), dest
+ 1 );
1990 case 'D': /* data file in source dir */
1991 output( "\t%s -m 644 $(INSTALL_DATA_FLAGS) %s $(DESTDIR)%s\n",
1992 install_sh
, src_dir_path( make
, file
), dest
+ 1 );
1994 case 'p': /* program file */
1995 output( "\tSTRIPPROG=\"$(STRIP)\" %s $(INSTALL_PROGRAM_FLAGS) %s $(DESTDIR)%s\n",
1996 install_sh
, obj_dir_path( make
, file
), dest
+ 1 );
1998 case 's': /* script */
1999 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s $(DESTDIR)%s\n",
2000 install_sh
, obj_dir_path( make
, file
), dest
+ 1 );
2002 case 'S': /* script in source dir */
2003 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s $(DESTDIR)%s\n",
2004 install_sh
, src_dir_path( make
, file
), dest
+ 1 );
2006 case 'y': /* symlink */
2007 output( "\trm -f $(DESTDIR)%s && $(LN_S) %s $(DESTDIR)%s\n", dest
+ 1, file
, dest
+ 1 );
2014 for (i
= 0; i
< files
.count
; i
+= 2)
2015 strarray_add( &uninstall
, strmake( "$(DESTDIR)%s", files
.str
[i
+ 1] + 1 ));
2017 strarray_add_uniq( phony_targets
, "install" );
2018 strarray_add_uniq( phony_targets
, target
);
2023 /*******************************************************************
2026 static struct strarray
output_sources( const struct makefile
*make
, struct strarray
*testlist_files
)
2028 struct incl_file
*source
;
2030 struct strarray object_files
= empty_strarray
;
2031 struct strarray crossobj_files
= empty_strarray
;
2032 struct strarray res_files
= empty_strarray
;
2033 struct strarray clean_files
= empty_strarray
;
2034 struct strarray uninstall_files
= empty_strarray
;
2035 struct strarray po_files
= empty_strarray
;
2036 struct strarray mo_files
= empty_strarray
;
2037 struct strarray mc_files
= empty_strarray
;
2038 struct strarray ok_files
= empty_strarray
;
2039 struct strarray in_files
= empty_strarray
;
2040 struct strarray dlldata_files
= empty_strarray
;
2041 struct strarray c2man_files
= empty_strarray
;
2042 struct strarray implib_objs
= empty_strarray
;
2043 struct strarray includes
= empty_strarray
;
2044 struct strarray subdirs
= empty_strarray
;
2045 struct strarray phony_targets
= empty_strarray
;
2046 struct strarray all_targets
= empty_strarray
;
2047 struct strarray install_rules
[NB_INSTALL_RULES
];
2048 char *ldrpath_local
= get_expanded_make_variable( make
, "LDRPATH_LOCAL" );
2049 char *ldrpath_install
= get_expanded_make_variable( make
, "LDRPATH_INSTALL" );
2051 for (i
= 0; i
< NB_INSTALL_RULES
; i
++) install_rules
[i
] = empty_strarray
;
2053 for (i
= 0; i
< linguas
.count
; i
++)
2054 strarray_add( &mo_files
, strmake( "%s/%s.mo", top_obj_dir_path( make
, "po" ), linguas
.str
[i
] ));
2056 strarray_add( &phony_targets
, "all" );
2057 strarray_add( &includes
, strmake( "-I%s", obj_dir_path( make
, "" )));
2058 if (make
->src_dir
) strarray_add( &includes
, strmake( "-I%s", make
->src_dir
));
2059 if (make
->parent_dir
) strarray_add( &includes
, strmake( "-I%s", src_dir_path( make
, make
->parent_dir
)));
2060 strarray_add( &includes
, strmake( "-I%s", top_obj_dir_path( make
, "include" )));
2061 if (make
->top_src_dir
) strarray_add( &includes
, strmake( "-I%s", top_dir_path( make
, "include" )));
2062 if (make
->use_msvcrt
) strarray_add( &includes
, strmake( "-I%s", top_dir_path( make
, "include/msvcrt" )));
2063 for (i
= 0; i
< make
->include_paths
.count
; i
++)
2064 strarray_add( &includes
, strmake( "-I%s", obj_dir_path( make
, make
->include_paths
.str
[i
] )));
2066 LIST_FOR_EACH_ENTRY( source
, &make
->sources
, struct incl_file
, entry
)
2068 struct strarray dependencies
= empty_strarray
;
2069 struct strarray extradefs
;
2070 char *obj
= xstrdup( source
->name
);
2071 char *ext
= get_extension( obj
);
2073 if (!ext
) fatal_error( "unsupported file type %s\n", source
->name
);
2076 if (make
->src_dir
&& strchr( obj
, '/' ))
2078 char *subdir
= base_dir_path( make
, obj
);
2079 *strrchr( subdir
, '/' ) = 0;
2080 strarray_add_uniq( &subdirs
, subdir
);
2083 extradefs
= get_expanded_make_var_array( make
, file_local_var( obj
, "EXTRADEFS" ));
2084 get_dependencies( &dependencies
, source
, source
);
2086 if (!strcmp( ext
, "y" )) /* yacc file */
2088 /* add source file dependency for parallel makes */
2089 char *header
= strmake( "%s.tab.h", obj
);
2091 if (find_include_file( make
, header
))
2093 output( "%s: %s\n", obj_dir_path( make
, header
), source
->filename
);
2094 output( "\t$(BISON) -p %s_ -o %s.tab.c -d %s\n",
2095 obj
, obj_dir_path( make
, obj
), source
->filename
);
2096 output( "%s.tab.c: %s %s\n", obj_dir_path( make
, obj
),
2097 source
->filename
, obj_dir_path( make
, header
));
2098 strarray_add( &clean_files
, header
);
2100 else output( "%s.tab.c: %s\n", obj
, source
->filename
);
2102 output( "\t$(BISON) -p %s_ -o $@ %s\n", obj
, source
->filename
);
2104 else if (!strcmp( ext
, "x" )) /* template file */
2106 output( "%s.h: %s%s %s\n", obj_dir_path( make
, obj
),
2107 tools_dir_path( make
, "make_xftmpl" ), tools_ext
, source
->filename
);
2108 output( "\t%s%s -H -o $@ %s\n",
2109 tools_dir_path( make
, "make_xftmpl" ), tools_ext
, source
->filename
);
2110 if (source
->file
->flags
& FLAG_INSTALL
)
2112 strarray_add( &install_rules
[INSTALL_DEV
], source
->name
);
2113 strarray_add( &install_rules
[INSTALL_DEV
],
2114 strmake( "D$(includedir)/%s", get_include_install_path( source
->name
) ));
2115 strarray_add( &install_rules
[INSTALL_DEV
], strmake( "%s.h", obj
));
2116 strarray_add( &install_rules
[INSTALL_DEV
],
2117 strmake( "d$(includedir)/%s.h", get_include_install_path( obj
) ));
2120 else if (!strcmp( ext
, "l" )) /* lex file */
2122 output( "%s.yy.c: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2123 output( "\t$(FLEX) -o$@ %s\n", source
->filename
);
2125 else if (!strcmp( ext
, "rc" )) /* resource file */
2127 strarray_add( &res_files
, strmake( "%s.res", obj
));
2128 output( "%s.res: %s %s\n", obj_dir_path( make
, obj
),
2129 tools_path( make
, "wrc" ), source
->filename
);
2130 output( "\t%s -o $@", tools_path( make
, "wrc" ) );
2131 if (make
->is_win16
) output_filename( "-m16" );
2132 else output_filenames( target_flags
);
2133 output_filename( "--nostdinc" );
2134 output_filenames( includes
);
2135 output_filenames( make
->define_args
);
2136 output_filenames( extradefs
);
2137 if (mo_files
.count
&& (source
->file
->flags
& FLAG_RC_PO
))
2139 strarray_add( &po_files
, source
->filename
);
2140 output_filename( strmake( "--po-dir=%s", top_obj_dir_path( make
, "po" )));
2141 output_filename( source
->filename
);
2143 output( "%s.res:", obj_dir_path( make
, obj
));
2144 output_filenames( mo_files
);
2146 output( "%s ", obj_dir_path( make
, "rsrc.pot" ));
2150 output_filename( source
->filename
);
2153 output( "%s.res:", obj_dir_path( make
, obj
));
2154 output_filenames( dependencies
);
2157 else if (!strcmp( ext
, "mc" )) /* message file */
2159 strarray_add( &res_files
, strmake( "%s.res", obj
));
2160 output( "%s.res: %s %s\n", obj_dir_path( make
, obj
),
2161 tools_path( make
, "wmc" ), source
->filename
);
2162 output( "\t%s -U -O res -o $@ %s", tools_path( make
, "wmc" ), source
->filename
);
2165 strarray_add( &mc_files
, source
->filename
);
2166 output_filename( strmake( "--po-dir=%s", top_obj_dir_path( make
, "po" )));
2168 output( "%s.res:", obj_dir_path( make
, obj
));
2169 output_filenames( mo_files
);
2171 output( "%s ", obj_dir_path( make
, "msg.pot" ));
2173 else output( "\n" );
2174 output( "%s.res:", obj_dir_path( make
, obj
));
2175 output_filenames( dependencies
);
2178 else if (!strcmp( ext
, "idl" )) /* IDL file */
2180 struct strarray targets
= empty_strarray
;
2183 if (!source
->file
->flags
) source
->file
->flags
|= FLAG_IDL_HEADER
| FLAG_INSTALL
;
2184 if (find_include_file( make
, strmake( "%s.h", obj
))) source
->file
->flags
|= FLAG_IDL_HEADER
;
2186 for (i
= 0; i
< sizeof(idl_outputs
) / sizeof(idl_outputs
[0]); i
++)
2188 if (!(source
->file
->flags
& idl_outputs
[i
].flag
)) continue;
2189 dest
= strmake( "%s%s", obj
, idl_outputs
[i
].ext
);
2190 if (!find_src_file( make
, dest
)) strarray_add( &clean_files
, dest
);
2191 strarray_add( &targets
, dest
);
2193 if (source
->file
->flags
& FLAG_IDL_PROXY
) strarray_add( &dlldata_files
, source
->name
);
2194 if (source
->file
->flags
& FLAG_INSTALL
)
2196 strarray_add( &install_rules
[INSTALL_DEV
], xstrdup( source
->name
));
2197 strarray_add( &install_rules
[INSTALL_DEV
],
2198 strmake( "D$(includedir)/%s.idl", get_include_install_path( obj
) ));
2199 if (source
->file
->flags
& FLAG_IDL_HEADER
)
2201 strarray_add( &install_rules
[INSTALL_DEV
], strmake( "%s.h", obj
));
2202 strarray_add( &install_rules
[INSTALL_DEV
],
2203 strmake( "d$(includedir)/%s.h", get_include_install_path( obj
) ));
2206 if (!targets
.count
) continue;
2207 output_filenames_obj_dir( make
, targets
);
2208 output( ": %s\n", tools_path( make
, "widl" ));
2209 output( "\t%s -o $@", tools_path( make
, "widl" ) );
2210 output_filenames( target_flags
);
2211 output_filenames( includes
);
2212 output_filenames( make
->define_args
);
2213 output_filenames( extradefs
);
2214 output_filenames( get_expanded_make_var_array( make
, "EXTRAIDLFLAGS" ));
2215 output_filename( source
->filename
);
2217 output_filenames_obj_dir( make
, targets
);
2218 output( ": %s", source
->filename
);
2219 output_filenames( dependencies
);
2222 else if (!strcmp( ext
, "in" )) /* .in file or man page */
2224 if (strendswith( obj
, ".man" ) && source
->file
->args
)
2226 struct strarray symlinks
;
2227 char *dir
, *dest
= replace_extension( obj
, ".man", "" );
2228 char *lang
= strchr( dest
, '.' );
2229 char *section
= source
->file
->args
;
2233 dir
= strmake( "$(mandir)/%s/man%s", lang
, section
);
2235 else dir
= strmake( "$(mandir)/man%s", section
);
2236 add_install_rule( make
, install_rules
, dest
, xstrdup(obj
),
2237 strmake( "d%s/%s.%s", dir
, dest
, section
));
2238 symlinks
= get_expanded_make_var_array( make
, file_local_var( dest
, "SYMLINKS" ));
2239 for (i
= 0; i
< symlinks
.count
; i
++)
2240 add_install_rule( make
, install_rules
, symlinks
.str
[i
],
2241 strmake( "%s.%s", dest
, section
),
2242 strmake( "y%s/%s.%s", dir
, symlinks
.str
[i
], section
));
2246 strarray_add( &in_files
, xstrdup(obj
) );
2247 strarray_add( &all_targets
, xstrdup(obj
) );
2248 output( "%s: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2249 output( "\t$(SED_CMD) %s >$@ || (rm -f $@ && false)\n", source
->filename
);
2250 output( "%s:", obj_dir_path( make
, obj
));
2251 output_filenames( dependencies
);
2253 add_install_rule( make
, install_rules
, obj
, xstrdup( obj
),
2254 strmake( "d$(datadir)/wine/%s", obj
));
2256 else if (!strcmp( ext
, "sfd" )) /* font file */
2258 char *ttf_file
= src_dir_path( make
, strmake( "%s.ttf", obj
));
2259 if (fontforge
&& !make
->src_dir
)
2261 output( "%s: %s\n", ttf_file
, source
->filename
);
2262 output( "\t%s -script %s %s $@\n",
2263 fontforge
, top_dir_path( make
, "fonts/genttf.ff" ), source
->filename
);
2264 if (!(source
->file
->flags
& FLAG_SFD_FONTS
)) output( "all: %s\n", ttf_file
);
2266 if (source
->file
->flags
& FLAG_INSTALL
)
2268 strarray_add( &install_rules
[INSTALL_LIB
], strmake( "%s.ttf", obj
));
2269 strarray_add( &install_rules
[INSTALL_LIB
], strmake( "D$(fontdir)/%s.ttf", obj
));
2271 if (source
->file
->flags
& FLAG_SFD_FONTS
)
2273 struct strarray
*array
= source
->file
->args
;
2275 for (i
= 0; i
< array
->count
; i
++)
2277 char *font
= strtok( xstrdup(array
->str
[i
]), " \t" );
2278 char *args
= strtok( NULL
, "" );
2280 strarray_add( &all_targets
, xstrdup( font
));
2281 output( "%s: %s %s\n", obj_dir_path( make
, font
),
2282 tools_path( make
, "sfnt2fon" ), ttf_file
);
2283 output( "\t%s -o $@ %s %s\n", tools_path( make
, "sfnt2fon" ), ttf_file
, args
);
2284 strarray_add( &install_rules
[INSTALL_LIB
], xstrdup(font
) );
2285 strarray_add( &install_rules
[INSTALL_LIB
], strmake( "d$(fontdir)/%s", font
));
2289 else if (!strcmp( ext
, "svg" )) /* svg file */
2291 if (convert
&& rsvg
&& icotool
&& !make
->src_dir
)
2293 output( "%s.ico %s.bmp: %s\n",
2294 src_dir_path( make
, obj
), src_dir_path( make
, obj
), source
->filename
);
2295 output( "\tCONVERT=\"%s\" ICOTOOL=\"%s\" RSVG=\"%s\" %s %s $@\n", convert
, icotool
, rsvg
,
2296 top_dir_path( make
, "tools/buildimage" ), source
->filename
);
2299 else if (!strcmp( ext
, "res" ))
2301 strarray_add( &res_files
, source
->name
);
2303 else if (!strcmp( ext
, "tlb" ))
2305 strarray_add( &all_targets
, source
->name
);
2307 else if (!strcmp( ext
, "h" ) || !strcmp( ext
, "rh" ) || !strcmp( ext
, "inl" )) /* header file */
2309 if (source
->file
->flags
& FLAG_GENERATED
)
2311 strarray_add( &all_targets
, source
->name
);
2315 strarray_add( &install_rules
[INSTALL_DEV
], source
->name
);
2316 strarray_add( &install_rules
[INSTALL_DEV
],
2317 strmake( "D$(includedir)/%s", get_include_install_path( source
->name
) ));
2322 int need_cross
= make
->testdll
||
2323 (source
->file
->flags
& FLAG_C_IMPLIB
) ||
2324 (make
->module
&& make
->staticlib
);
2326 if ((source
->file
->flags
& FLAG_GENERATED
) &&
2327 (!make
->testdll
|| !strendswith( source
->filename
, "testlist.c" )))
2328 strarray_add( &clean_files
, source
->filename
);
2329 if (source
->file
->flags
& FLAG_C_IMPLIB
) strarray_add( &implib_objs
, strmake( "%s.o", obj
));
2330 strarray_add( &object_files
, strmake( "%s.o", obj
));
2331 output( "%s.o: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2332 output( "\t$(CC) -c -o $@ %s", source
->filename
);
2333 output_filenames( includes
);
2334 output_filenames( make
->define_args
);
2335 output_filenames( extradefs
);
2336 if (make
->module
|| make
->staticlib
|| make
->testdll
)
2338 output_filenames( dll_flags
);
2339 if (make
->use_msvcrt
) output_filenames( msvcrt_flags
);
2341 output_filenames( extra_cflags
);
2342 output_filenames( cpp_flags
);
2343 output_filename( "$(CFLAGS)" );
2345 if (crosstarget
&& need_cross
)
2347 strarray_add( &crossobj_files
, strmake( "%s.cross.o", obj
));
2348 output( "%s.cross.o: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2349 output( "\t$(CROSSCC) -c -o $@ %s", source
->filename
);
2350 output_filenames( includes
);
2351 output_filenames( make
->define_args
);
2352 output_filenames( extradefs
);
2353 output_filename( "-DWINE_CROSSTEST" );
2354 output_filenames( cpp_flags
);
2355 output_filename( "$(CFLAGS)" );
2358 if (make
->testdll
&& !strcmp( ext
, "c" ) && !(source
->file
->flags
& FLAG_GENERATED
))
2360 strarray_add( &ok_files
, strmake( "%s.ok", obj
));
2361 output( "%s.ok:\n", obj_dir_path( make
, obj
));
2362 output( "\t%s $(RUNTESTFLAGS) -T %s -M %s -p %s%s %s && touch $@\n",
2363 top_dir_path( make
, "tools/runtest" ), top_obj_dir_path( make
, "" ), make
->testdll
,
2364 replace_extension( make
->testdll
, ".dll", "_test.exe" ), dll_ext
, obj
);
2366 if (!strcmp( ext
, "c" ) && !(source
->file
->flags
& FLAG_GENERATED
))
2367 strarray_add( &c2man_files
, source
->filename
);
2368 output( "%s.o", obj_dir_path( make
, obj
));
2369 if (crosstarget
&& need_cross
) output( " %s.cross.o", obj_dir_path( make
, obj
));
2371 output_filenames( dependencies
);
2377 /* rules for files that depend on multiple sources */
2381 output( "%s: %s", obj_dir_path( make
, "rsrc.pot" ), tools_path( make
, "wrc" ) );
2382 output_filenames( po_files
);
2384 output( "\t%s -O pot -o $@", tools_path( make
, "wrc" ));
2385 if (make
->is_win16
) output_filename( "-m16" );
2386 else output_filenames( target_flags
);
2387 output_filename( "--nostdinc" );
2388 output_filenames( includes
);
2389 output_filenames( make
->define_args
);
2390 output_filenames( po_files
);
2392 strarray_add( &clean_files
, "rsrc.pot" );
2397 output( "%s: %s", obj_dir_path( make
, "msg.pot" ), tools_path( make
, "wmc" ));
2398 output_filenames( mc_files
);
2400 output( "\t%s -O pot -o $@", tools_path( make
, "wmc" ));
2401 output_filenames( mc_files
);
2403 strarray_add( &clean_files
, "msg.pot" );
2406 if (dlldata_files
.count
)
2408 output( "%s: %s %s\n", obj_dir_path( make
, "dlldata.c" ),
2409 tools_path( make
, "widl" ), src_dir_path( make
, "Makefile.in" ));
2410 output( "\t%s --dlldata-only -o $@", tools_path( make
, "widl" ));
2411 output_filenames( dlldata_files
);
2415 if (make
->module
&& !make
->staticlib
)
2417 struct strarray all_libs
= empty_strarray
;
2418 char *module_path
= obj_dir_path( make
, make
->module
);
2419 char *spec_file
= NULL
;
2421 if (!make
->appmode
.count
)
2422 spec_file
= src_dir_path( make
, replace_extension( make
->module
, ".dll", ".spec" ));
2423 for (i
= 0; i
< make
->delayimports
.count
; i
++)
2424 strarray_add( &all_libs
, strmake( "-l%s", make
->delayimports
.str
[i
] ));
2425 for (i
= 0; i
< make
->imports
.count
; i
++)
2426 strarray_add( &all_libs
, strmake( "-l%s", make
->imports
.str
[i
] ));
2427 for (i
= 0; i
< make
->delayimports
.count
; i
++)
2428 strarray_add( &all_libs
, strmake( "-Wb,-d%s", make
->delayimports
.str
[i
] ));
2429 strarray_add( &all_libs
, "-lwine" );
2430 strarray_add( &all_libs
, top_obj_dir_path( make
, "libs/port/libwine_port.a" ));
2431 strarray_addall( &all_libs
, get_expanded_make_var_array( make
, "EXTRALIBS" ));
2432 strarray_addall( &all_libs
, libs
);
2436 strarray_add( &all_targets
, strmake( "%s%s", make
->module
, dll_ext
));
2437 strarray_add( &all_targets
, strmake( "%s.fake", make
->module
));
2438 add_install_rule( make
, install_rules
, make
->module
, strmake( "%s%s", make
->module
, dll_ext
),
2439 strmake( "p$(dlldir)/%s%s", make
->module
, dll_ext
));
2440 add_install_rule( make
, install_rules
, make
->module
, strmake( "%s.fake", make
->module
),
2441 strmake( "d$(fakedlldir)/%s", make
->module
));
2442 output( "%s%s %s.fake:", module_path
, dll_ext
, module_path
);
2446 strarray_add( &all_targets
, make
->module
);
2447 add_install_rule( make
, install_rules
, make
->module
, make
->module
,
2448 strmake( "p$(%s)/%s", spec_file
? "dlldir" : "bindir", make
->module
));
2449 output( "%s:", module_path
);
2451 if (spec_file
) output_filename( spec_file
);
2452 output_filenames_obj_dir( make
, object_files
);
2453 output_filenames_obj_dir( make
, res_files
);
2455 output( "\t%s -o $@", tools_path( make
, "winegcc" ));
2456 output_filename( strmake( "-B%s", tools_dir_path( make
, "winebuild" )));
2457 if (tools_dir
) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make
, "" )));
2458 output_filenames( target_flags
);
2459 output_filenames( unwind_flags
);
2462 output( " -shared %s", spec_file
);
2463 output_filenames( make
->extradllflags
);
2465 else output_filenames( make
->appmode
);
2466 output_filenames_obj_dir( make
, object_files
);
2467 output_filenames_obj_dir( make
, res_files
);
2468 output_filenames( all_libs
);
2469 output_filename( "$(LDFLAGS)" );
2472 if (spec_file
&& make
->importlib
)
2474 char *importlib_path
= obj_dir_path( make
, strmake( "lib%s", make
->importlib
));
2477 strarray_add( &clean_files
, strmake( "lib%s.def", make
->importlib
));
2478 output( "%s.def: %s %s\n", importlib_path
, tools_path( make
, "winebuild" ), spec_file
);
2479 output( "\t%s -w --def -o $@ --export %s", tools_path( make
, "winebuild" ), spec_file
);
2480 output_filenames( target_flags
);
2481 if (make
->is_win16
) output_filename( "-m16" );
2483 add_install_rule( make
, install_rules
, make
->importlib
,
2484 strmake( "lib%s.def", make
->importlib
),
2485 strmake( "d$(dlldir)/lib%s.def", make
->importlib
));
2486 if (implib_objs
.count
)
2488 strarray_add( &clean_files
, strmake( "lib%s.def.a", make
->importlib
));
2489 output( "%s.def.a:", importlib_path
);
2490 output_filenames_obj_dir( make
, implib_objs
);
2492 output( "\trm -f $@\n" );
2493 output( "\t$(AR) $(ARFLAGS) $@" );
2494 output_filenames_obj_dir( make
, implib_objs
);
2496 output( "\t$(RANLIB) $@\n" );
2497 add_install_rule( make
, install_rules
, make
->importlib
,
2498 strmake( "lib%s.def.a", make
->importlib
),
2499 strmake( "d$(dlldir)/lib%s.def.a", make
->importlib
));
2504 strarray_add( &clean_files
, strmake( "lib%s.a", make
->importlib
));
2505 output( "%s.a: %s %s", importlib_path
, tools_path( make
, "winebuild" ), spec_file
);
2506 output_filenames_obj_dir( make
, implib_objs
);
2508 output( "\t%s -w --implib -o $@ --export %s", tools_path( make
, "winebuild" ), spec_file
);
2509 output_filenames( target_flags
);
2510 output_filenames_obj_dir( make
, implib_objs
);
2512 add_install_rule( make
, install_rules
, make
->importlib
,
2513 strmake( "lib%s.a", make
->importlib
),
2514 strmake( "d$(dlldir)/lib%s.a", make
->importlib
));
2516 if (crosstarget
&& !make
->is_win16
)
2518 struct strarray cross_files
= strarray_replace_extension( &implib_objs
, ".o", ".cross.o" );
2519 strarray_add( &clean_files
, strmake( "lib%s.cross.a", make
->importlib
));
2520 output( "%s.cross.a: %s %s", importlib_path
, tools_path( make
, "winebuild" ), spec_file
);
2521 output_filenames_obj_dir( make
, cross_files
);
2523 output( "\t%s -b %s -w --implib -o $@ --export %s",
2524 tools_path( make
, "winebuild" ), crosstarget
, spec_file
);
2525 output_filenames_obj_dir( make
, cross_files
);
2532 if (c2man_files
.count
)
2534 output( "manpages::\n" );
2535 output( "\t%s -w %s", top_dir_path( make
, "tools/c2man.pl" ), spec_file
);
2536 output_filename( strmake( "-R%s", top_dir_path( make
, "" )));
2537 output_filename( strmake( "-I%s", top_dir_path( make
, "include" )));
2538 output_filename( strmake( "-o %s/man%s",
2539 top_obj_dir_path( make
, "documentation" ), man_ext
));
2540 output_filenames( c2man_files
);
2542 output( "htmlpages::\n" );
2543 output( "\t%s -Th -w %s", top_dir_path( make
, "tools/c2man.pl" ), spec_file
);
2544 output_filename( strmake( "-R%s", top_dir_path( make
, "" )));
2545 output_filename( strmake( "-I%s", top_dir_path( make
, "include" )));
2546 output_filename( strmake( "-o %s",
2547 top_obj_dir_path( make
, "documentation/html" )));
2548 output_filenames( c2man_files
);
2550 output( "sgmlpages::\n" );
2551 output( "\t%s -Ts -w %s", top_dir_path( make
, "tools/c2man.pl" ), spec_file
);
2552 output_filename( strmake( "-R%s", top_dir_path( make
, "" )));
2553 output_filename( strmake( "-I%s", top_dir_path( make
, "include" )));
2554 output_filename( strmake( "-o %s",
2555 top_obj_dir_path( make
, "documentation/api-guide" )));
2556 output_filenames( c2man_files
);
2558 output( "xmlpages::\n" );
2559 output( "\t%s -Tx -w %s", top_dir_path( make
, "tools/c2man.pl" ), spec_file
);
2560 output_filename( strmake( "-R%s", top_dir_path( make
, "" )));
2561 output_filename( strmake( "-I%s", top_dir_path( make
, "include" )));
2562 output_filename( strmake( "-o %s",
2563 top_obj_dir_path( make
, "documentation/api-guide-xml" )));
2564 output_filenames( c2man_files
);
2566 strarray_add( &phony_targets
, "manpages" );
2567 strarray_add( &phony_targets
, "htmlpages" );
2568 strarray_add( &phony_targets
, "sgmlpages" );
2569 strarray_add( &phony_targets
, "xmlpages" );
2571 else output( "manpages htmlpages sgmlpages xmlpages::\n" );
2575 char *binary
= replace_extension( make
->module
, ".exe", "" );
2576 add_install_rule( make
, install_rules
, binary
, tools_dir_path( make
, "wineapploader" ),
2577 strmake( "s$(bindir)/%s", binary
));
2581 if (make
->staticlib
)
2583 strarray_add( &all_targets
, make
->staticlib
);
2584 output( "%s:", obj_dir_path( make
, make
->staticlib
));
2585 output_filenames_obj_dir( make
, object_files
);
2586 output( "\n\trm -f $@\n" );
2587 output( "\t$(AR) $(ARFLAGS) $@" );
2588 output_filenames_obj_dir( make
, object_files
);
2589 output( "\n\t$(RANLIB) $@\n" );
2590 if (crosstarget
&& make
->module
)
2592 char *name
= replace_extension( make
->staticlib
, ".a", ".cross.a" );
2594 strarray_add( &all_targets
, name
);
2595 output( "%s:", obj_dir_path( make
, name
));
2596 output_filenames_obj_dir( make
, crossobj_files
);
2597 output( "\n\trm -f $@\n" );
2598 output( "\t%s-ar $(ARFLAGS) $@", crosstarget
);
2599 output_filenames_obj_dir( make
, crossobj_files
);
2600 output( "\n\t%s-ranlib $@\n", crosstarget
);
2604 if (make
->sharedlib
)
2607 struct strarray names
= get_shared_lib_names( make
->sharedlib
);
2608 struct strarray all_libs
= empty_strarray
;
2610 basename
= xstrdup( make
->sharedlib
);
2611 if ((p
= strchr( basename
, '.' ))) *p
= 0;
2613 strarray_addall( &all_libs
, get_expanded_make_var_array( make
,
2614 file_local_var( basename
, "LDFLAGS" )));
2615 strarray_addall( &all_libs
, get_expanded_make_var_array( make
, "EXTRALIBS" ));
2616 strarray_addall( &all_libs
, libs
);
2618 output( "%s:", obj_dir_path( make
, make
->sharedlib
));
2619 output_filenames_obj_dir( make
, object_files
);
2620 output_filenames( get_local_dependencies( make
, basename
, in_files
));
2622 output( "\t$(CC) -o $@" );
2623 output_filenames_obj_dir( make
, object_files
);
2624 output_filenames( all_libs
);
2625 output_filename( "$(LDFLAGS)" );
2627 add_install_rule( make
, install_rules
, make
->sharedlib
, make
->sharedlib
,
2628 strmake( "p$(libdir)/%s", make
->sharedlib
));
2629 for (i
= 1; i
< names
.count
; i
++)
2631 output( "%s: %s\n", obj_dir_path( make
, names
.str
[i
] ), obj_dir_path( make
, names
.str
[i
-1] ));
2632 output( "\trm -f $@ && $(LN_S) %s $@\n", names
.str
[i
-1] );
2633 add_install_rule( make
, install_rules
, names
.str
[i
], names
.str
[i
-1],
2634 strmake( "y$(libdir)/%s", names
.str
[i
] ));
2636 strarray_addall( &all_targets
, names
);
2639 if (make
->importlib
&& !make
->module
) /* stand-alone import lib (for libwine) */
2641 char *def_file
= replace_extension( make
->importlib
, ".a", ".def" );
2643 if (!strncmp( def_file
, "lib", 3 )) def_file
+= 3;
2644 output( "%s: %s\n", obj_dir_path( make
, make
->importlib
), src_dir_path( make
, def_file
));
2645 output( "\t%s -l $@ -d %s\n", dlltool
, src_dir_path( make
, def_file
));
2646 add_install_rule( make
, install_rules
, make
->importlib
, make
->importlib
,
2647 strmake( "d$(libdir)/%s", make
->importlib
));
2648 strarray_add( &all_targets
, make
->importlib
);
2653 char *testmodule
= replace_extension( make
->testdll
, ".dll", "_test.exe" );
2654 char *stripped
= replace_extension( make
->testdll
, ".dll", "_test-stripped.exe" );
2655 char *testres
= replace_extension( make
->testdll
, ".dll", "_test.res" );
2656 struct strarray all_libs
= empty_strarray
;
2658 for (i
= 0; i
< make
->imports
.count
; i
++)
2659 strarray_add( &all_libs
, strmake( "-l%s", make
->imports
.str
[i
] ));
2660 strarray_addall( &all_libs
, libs
);
2662 strarray_add( &all_targets
, strmake( "%s%s", testmodule
, dll_ext
));
2663 strarray_add( &clean_files
, strmake( "%s%s", stripped
, dll_ext
));
2664 output( "%s%s:\n", obj_dir_path( make
, testmodule
), dll_ext
);
2665 output( "\t%s -o $@", tools_path( make
, "winegcc" ));
2666 output_filename( strmake( "-B%s", tools_dir_path( make
, "winebuild" )));
2667 if (tools_dir
) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make
, "" )));
2668 output_filenames( target_flags
);
2669 output_filenames( unwind_flags
);
2670 output_filenames( make
->appmode
);
2671 output_filenames_obj_dir( make
, object_files
);
2672 output_filenames_obj_dir( make
, res_files
);
2673 output_filenames( all_libs
);
2674 output_filename( "$(LDFLAGS)" );
2676 output( "%s%s:\n", obj_dir_path( make
, stripped
), dll_ext
);
2677 output( "\t%s -o $@", tools_path( make
, "winegcc" ));
2678 output_filename( strmake( "-B%s", tools_dir_path( make
, "winebuild" )));
2679 if (tools_dir
) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make
, "" )));
2680 output_filenames( target_flags
);
2681 output_filenames( unwind_flags
);
2682 output_filename( strmake( "-Wb,-F,%s", testmodule
));
2683 output_filenames( make
->appmode
);
2684 output_filenames_obj_dir( make
, object_files
);
2685 output_filenames_obj_dir( make
, res_files
);
2686 output_filenames( all_libs
);
2687 output_filename( "$(LDFLAGS)" );
2689 output( "%s%s %s%s:", obj_dir_path( make
, testmodule
), dll_ext
,
2690 obj_dir_path( make
, stripped
), dll_ext
);
2691 output_filenames_obj_dir( make
, object_files
);
2692 output_filenames_obj_dir( make
, res_files
);
2695 output( "all: %s/%s\n", top_obj_dir_path( make
, "programs/winetest" ), testres
);
2696 output( "%s/%s: %s%s\n", top_obj_dir_path( make
, "programs/winetest" ), testres
,
2697 obj_dir_path( make
, stripped
), dll_ext
);
2698 output( "\techo \"%s TESTRES \\\"%s%s\\\"\" | %s -o $@\n",
2699 testmodule
, obj_dir_path( make
, stripped
), dll_ext
, tools_path( make
, "wrc" ));
2703 char *crosstest
= replace_extension( make
->testdll
, ".dll", "_crosstest.exe" );
2705 strarray_add( &clean_files
, crosstest
);
2706 output( "%s: %s\n", obj_dir_path( make
, "crosstest" ), obj_dir_path( make
, crosstest
));
2707 output( "%s:", obj_dir_path( make
, crosstest
));
2708 output_filenames_obj_dir( make
, crossobj_files
);
2709 output_filenames_obj_dir( make
, res_files
);
2711 output( "\t%s -o $@ -b %s", tools_path( make
, "winegcc" ), crosstarget
);
2712 output_filename( strmake( "-B%s", tools_dir_path( make
, "winebuild" )));
2713 if (tools_dir
) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make
, "" )));
2714 output_filename( "--lib-suffix=.cross.a" );
2715 output_filenames_obj_dir( make
, crossobj_files
);
2716 output_filenames_obj_dir( make
, res_files
);
2717 output_filenames( all_libs
);
2718 output_filename( "$(LDFLAGS)" );
2720 strarray_add( &phony_targets
, obj_dir_path( make
, "crosstest" ));
2721 if (make
->obj_dir
) output( "crosstest: %s\n", obj_dir_path( make
, "crosstest" ));
2724 output_filenames_obj_dir( make
, ok_files
);
2725 output( ": %s%s ../%s%s\n", testmodule
, dll_ext
, make
->testdll
, dll_ext
);
2726 output( "check test:" );
2727 output_filenames_obj_dir( make
, ok_files
);
2729 output( "testclean::\n" );
2730 output( "\trm -f" );
2731 output_filenames_obj_dir( make
, ok_files
);
2733 strarray_addall( &clean_files
, ok_files
);
2734 strarray_add( &phony_targets
, "check" );
2735 strarray_add( &phony_targets
, "test" );
2736 strarray_add( &phony_targets
, "testclean" );
2737 *testlist_files
= strarray_replace_extension( &ok_files
, ".ok", "" );
2740 for (i
= 0; i
< make
->programs
.count
; i
++)
2742 char *program_installed
= NULL
;
2743 char *program
= strmake( "%s%s", make
->programs
.str
[i
], exe_ext
);
2744 struct strarray all_libs
= empty_strarray
;
2745 struct strarray deps
= get_local_dependencies( make
, make
->programs
.str
[i
], in_files
);
2746 struct strarray objs
= get_expanded_make_var_array( make
,
2747 file_local_var( make
->programs
.str
[i
], "OBJS" ));
2748 struct strarray symlinks
= get_expanded_make_var_array( make
,
2749 file_local_var( make
->programs
.str
[i
], "SYMLINKS" ));
2751 if (!objs
.count
) objs
= object_files
;
2752 output( "%s:", obj_dir_path( make
, program
) );
2753 output_filenames_obj_dir( make
, objs
);
2754 output_filenames( deps
);
2756 output( "\t$(CC) -o $@" );
2757 output_filenames_obj_dir( make
, objs
);
2758 strarray_add( &all_libs
, top_obj_dir_path( make
, "libs/port/libwine_port.a" ));
2759 strarray_addall( &all_libs
, get_expanded_make_var_array( make
, "EXTRALIBS" ));
2760 strarray_addall( &all_libs
, libs
);
2761 strarray_addall( &all_libs
, get_expanded_make_var_array( make
,
2762 file_local_var( make
->programs
.str
[i
], "LDFLAGS" )));
2764 if (strarray_exists( &all_libs
, "-lwine" ))
2766 strarray_add( &all_libs
, strmake( "-L%s", top_obj_dir_path( make
, "libs/wine" )));
2767 if (ldrpath_local
&& ldrpath_install
)
2769 program_installed
= strmake( "%s-installed%s", make
->programs
.str
[i
], exe_ext
);
2770 output_filename( ldrpath_local
);
2771 output_filenames( all_libs
);
2772 output_filename( "$(LDFLAGS)" );
2774 output( "%s:", obj_dir_path( make
, program_installed
) );
2775 output_filenames_obj_dir( make
, objs
);
2776 output_filenames( deps
);
2778 output( "\t$(CC) -o $@" );
2779 output_filenames_obj_dir( make
, objs
);
2780 output_filename( ldrpath_install
);
2781 strarray_add( &all_targets
, program_installed
);
2785 output_filenames( all_libs
);
2786 output_filename( "$(LDFLAGS)" );
2788 strarray_add( &all_targets
, program
);
2792 output_filenames_obj_dir( make
, symlinks
);
2793 output( ": %s\n", obj_dir_path( make
, program
));
2794 output( "\trm -f $@ && $(LN_S) %s $@\n", obj_dir_path( make
, program
));
2795 strarray_addall( &all_targets
, symlinks
);
2798 add_install_rule( make
, install_rules
, program
, program_installed
? program_installed
: program
,
2799 strmake( "p$(bindir)/%s", program
));
2800 for (j
= 0; j
< symlinks
.count
; j
++)
2801 add_install_rule( make
, install_rules
, symlinks
.str
[j
], program
,
2802 strmake( "y$(bindir)/%s%s", symlinks
.str
[j
], exe_ext
));
2805 for (i
= 0; i
< make
->scripts
.count
; i
++)
2806 add_install_rule( make
, install_rules
, make
->scripts
.str
[i
], make
->scripts
.str
[i
],
2807 strmake( "S$(bindir)/%s", make
->scripts
.str
[i
] ));
2809 if (all_targets
.count
)
2812 output_filenames_obj_dir( make
, all_targets
);
2816 strarray_addall( &uninstall_files
, output_install_rules( make
, install_rules
[INSTALL_LIB
],
2817 "install-lib", &phony_targets
));
2818 strarray_addall( &uninstall_files
, output_install_rules( make
, install_rules
[INSTALL_DEV
],
2819 "install-dev", &phony_targets
));
2820 if (uninstall_files
.count
)
2822 output( "uninstall::\n" );
2823 output( "\trm -f" );
2824 output_filenames( uninstall_files
);
2826 strarray_add_uniq( &phony_targets
, "uninstall" );
2829 strarray_addall( &clean_files
, object_files
);
2830 strarray_addall( &clean_files
, crossobj_files
);
2831 strarray_addall( &clean_files
, res_files
);
2832 strarray_addall( &clean_files
, all_targets
);
2833 strarray_addall( &clean_files
, get_expanded_make_var_array( make
, "EXTRA_TARGETS" ));
2835 if (clean_files
.count
)
2837 output( "%s::\n", obj_dir_path( make
, "clean" ));
2838 output( "\trm -f" );
2839 output_filenames_obj_dir( make
, clean_files
);
2841 if (make
->obj_dir
) output( "__clean__: %s\n", obj_dir_path( make
, "clean" ));
2842 strarray_add( &phony_targets
, obj_dir_path( make
, "clean" ));
2845 if (make
->top_obj_dir
)
2847 output( "depend:\n" );
2848 output( "\t@cd %s && $(MAKE) %s\n", make
->top_obj_dir
, base_dir_path( make
, "depend" ));
2849 strarray_add( &phony_targets
, "depend" );
2852 if (phony_targets
.count
)
2854 output( ".PHONY:" );
2855 output_filenames( phony_targets
);
2859 for (i
= 0; i
< subdirs
.count
; i
++) create_dir( subdirs
.str
[i
] );
2865 /*******************************************************************
2868 static FILE *create_temp_file( const char *orig
)
2870 char *name
= xmalloc( strlen(orig
) + 13 );
2871 unsigned int i
, id
= getpid();
2875 for (i
= 0; i
< 100; i
++)
2877 sprintf( name
, "%s.tmp%08x", orig
, id
);
2878 if ((fd
= open( name
, O_RDWR
| O_CREAT
| O_EXCL
, 0666 )) != -1)
2880 ret
= fdopen( fd
, "w" );
2883 if (errno
!= EEXIST
) break;
2886 if (!ret
) fatal_error( "failed to create output file for '%s'\n", orig
);
2887 temp_file_name
= name
;
2892 /*******************************************************************
2895 static void rename_temp_file( const char *dest
)
2897 int ret
= rename( temp_file_name
, dest
);
2898 if (ret
== -1 && errno
== EEXIST
)
2900 /* rename doesn't overwrite on windows */
2902 ret
= rename( temp_file_name
, dest
);
2904 if (ret
== -1) fatal_error( "failed to rename output file to '%s'\n", dest
);
2905 temp_file_name
= NULL
;
2909 /*******************************************************************
2910 * are_files_identical
2912 static int are_files_identical( FILE *file1
, FILE *file2
)
2916 char buffer1
[8192], buffer2
[8192];
2917 int size1
= fread( buffer1
, 1, sizeof(buffer1
), file1
);
2918 int size2
= fread( buffer2
, 1, sizeof(buffer2
), file2
);
2919 if (size1
!= size2
) return 0;
2920 if (!size1
) return feof( file1
) && feof( file2
);
2921 if (memcmp( buffer1
, buffer2
, size1
)) return 0;
2926 /*******************************************************************
2927 * rename_temp_file_if_changed
2929 static void rename_temp_file_if_changed( const char *dest
)
2931 FILE *file1
, *file2
;
2934 if ((file1
= fopen( dest
, "r" )))
2936 if ((file2
= fopen( temp_file_name
, "r" )))
2938 do_rename
= !are_files_identical( file1
, file2
);
2945 unlink( temp_file_name
);
2946 temp_file_name
= NULL
;
2948 else rename_temp_file( dest
);
2952 /*******************************************************************
2955 static void output_testlist( const char *dest
, struct strarray files
)
2959 output_file
= create_temp_file( dest
);
2961 output( "/* Automatically generated by make depend; DO NOT EDIT!! */\n\n" );
2962 output( "#define WIN32_LEAN_AND_MEAN\n" );
2963 output( "#include <windows.h>\n\n" );
2964 output( "#define STANDALONE\n" );
2965 output( "#include \"wine/test.h\"\n\n" );
2967 for (i
= 0; i
< files
.count
; i
++) output( "extern void func_%s(void);\n", files
.str
[i
] );
2969 output( "const struct test winetest_testlist[] =\n" );
2971 for (i
= 0; i
< files
.count
; i
++) output( " { \"%s\", func_%s },\n", files
.str
[i
], files
.str
[i
] );
2972 output( " { 0, 0 }\n" );
2975 if (fclose( output_file
)) fatal_perror( "write" );
2977 rename_temp_file_if_changed( dest
);
2981 /*******************************************************************
2984 static void output_gitignore( const char *dest
, struct strarray files
)
2988 output_file
= create_temp_file( dest
);
2990 output( "# Automatically generated by make depend; DO NOT EDIT!!\n" );
2991 for (i
= 0; i
< files
.count
; i
++)
2993 if (!strchr( files
.str
[i
], '/' )) output( "/" );
2994 output( "%s\n", files
.str
[i
] );
2997 if (fclose( output_file
)) fatal_perror( "write" );
2999 rename_temp_file( dest
);
3003 /*******************************************************************
3004 * output_top_variables
3006 static void output_top_variables( const struct makefile
*make
)
3009 struct strarray
*vars
= &top_makefile
->vars
;
3011 if (!make
->base_dir
) return; /* don't output variables in the top makefile */
3013 output( "# Automatically generated by make depend; DO NOT EDIT!!\n\n" );
3014 output( "all:\n\n" );
3015 for (i
= 0; i
< vars
->count
; i
+= 2)
3016 output( "%s = %s\n", vars
->str
[i
], get_make_variable( make
, vars
->str
[i
] ));
3021 /*******************************************************************
3022 * output_dependencies
3024 static void output_dependencies( const struct makefile
*make
)
3026 struct strarray targets
, testlist_files
= empty_strarray
, ignore_files
= empty_strarray
;
3030 output_file_name
= base_dir_path( make
, output_makefile_name
);
3031 output_file
= create_temp_file( output_file_name
);
3032 output_top_variables( make
);
3034 /* copy the contents of the source makefile */
3035 src_file
= open_input_makefile( make
);
3036 while (fgets( buffer
, sizeof(buffer
), src_file
))
3037 if (fwrite( buffer
, 1, strlen(buffer
), output_file
) != strlen(buffer
)) fatal_perror( "write" );
3038 if (fclose( src_file
)) fatal_perror( "close" );
3039 input_file_name
= NULL
;
3041 targets
= output_sources( make
, &testlist_files
);
3043 fclose( output_file
);
3045 rename_temp_file( output_file_name
);
3047 strarray_add( &ignore_files
, ".gitignore" );
3048 strarray_add( &ignore_files
, "Makefile" );
3049 if (testlist_files
.count
) strarray_add( &ignore_files
, "testlist.c" );
3050 strarray_addall( &ignore_files
, targets
);
3052 if (testlist_files
.count
)
3053 output_testlist( base_dir_path( make
, "testlist.c" ), testlist_files
);
3054 if (!make
->src_dir
&& make
->base_dir
)
3055 output_gitignore( base_dir_path( make
, ".gitignore" ), ignore_files
);
3057 output_file_name
= NULL
;
3061 /*******************************************************************
3064 static void update_makefile( const char *path
)
3066 static const char *source_vars
[] =
3085 struct strarray value
;
3086 struct incl_file
*file
;
3087 struct makefile
*make
;
3089 make
= parse_makefile( path
, NULL
);
3093 make
->top_src_dir
= concat_paths( make
->top_obj_dir
, root_src_dir
);
3094 make
->src_dir
= concat_paths( make
->top_src_dir
, make
->base_dir
);
3096 strarray_set_value( &make
->vars
, "top_builddir", top_obj_dir_path( make
, "" ));
3097 strarray_set_value( &make
->vars
, "top_srcdir", top_dir_path( make
, "" ));
3098 strarray_set_value( &make
->vars
, "srcdir", src_dir_path( make
, "" ));
3100 make
->parent_dir
= get_expanded_make_variable( make
, "PARENTSRC" );
3101 make
->module
= get_expanded_make_variable( make
, "MODULE" );
3102 make
->testdll
= get_expanded_make_variable( make
, "TESTDLL" );
3103 make
->sharedlib
= get_expanded_make_variable( make
, "SHAREDLIB" );
3104 make
->staticlib
= get_expanded_make_variable( make
, "STATICLIB" );
3105 make
->importlib
= get_expanded_make_variable( make
, "IMPORTLIB" );
3107 make
->programs
= get_expanded_make_var_array( make
, "PROGRAMS" );
3108 make
->scripts
= get_expanded_make_var_array( make
, "SCRIPTS" );
3109 make
->appmode
= get_expanded_make_var_array( make
, "APPMODE" );
3110 make
->imports
= get_expanded_make_var_array( make
, "IMPORTS" );
3111 make
->delayimports
= get_expanded_make_var_array( make
, "DELAYIMPORTS" );
3112 make
->extradllflags
= get_expanded_make_var_array( make
, "EXTRADLLFLAGS" );
3113 make
->install_lib
= get_expanded_make_var_array( make
, "INSTALL_LIB" );
3114 make
->install_dev
= get_expanded_make_var_array( make
, "INSTALL_DEV" );
3116 if (make
->module
&& strendswith( make
->module
, ".a" )) make
->staticlib
= make
->module
;
3118 make
->is_win16
= strarray_exists( &make
->extradllflags
, "-m16" );
3119 make
->use_msvcrt
= strarray_exists( &make
->appmode
, "-mno-cygwin" );
3121 for (i
= 0; i
< make
->imports
.count
&& !make
->use_msvcrt
; i
++)
3122 make
->use_msvcrt
= !strncmp( make
->imports
.str
[i
], "msvcr", 5 ) ||
3123 !strcmp( make
->imports
.str
[i
], "ucrtbase" );
3125 if (make
->module
&& !make
->install_lib
.count
) strarray_add( &make
->install_lib
, make
->module
);
3127 make
->include_paths
= empty_strarray
;
3128 make
->define_args
= empty_strarray
;
3129 strarray_add( &make
->define_args
, "-D__WINESRC__" );
3131 value
= get_expanded_make_var_array( make
, "EXTRAINCL" );
3132 for (i
= 0; i
< value
.count
; i
++)
3133 if (!strncmp( value
.str
[i
], "-I", 2 ))
3134 strarray_add_uniq( &make
->include_paths
, value
.str
[i
] + 2 );
3136 strarray_add_uniq( &make
->define_args
, value
.str
[i
] );
3137 strarray_addall( &make
->define_args
, get_expanded_make_var_array( make
, "EXTRADEFS" ));
3139 list_init( &make
->sources
);
3140 list_init( &make
->includes
);
3142 /* FIXME: target dir has to exist to allow locating srcdir-relative include files */
3143 if (make
->base_dir
) create_dir( make
->base_dir
);
3145 for (var
= source_vars
; *var
; var
++)
3147 value
= get_expanded_make_var_array( make
, *var
);
3148 for (i
= 0; i
< value
.count
; i
++) add_src_file( make
, value
.str
[i
] );
3151 add_generated_sources( make
);
3153 value
= get_expanded_make_var_array( make
, "EXTRA_OBJS" );
3154 for (i
= 0; i
< value
.count
; i
++)
3156 /* default to .c for unknown extra object files */
3157 if (strendswith( value
.str
[i
], ".o" ))
3158 add_generated_source( make
, value
.str
[i
], replace_extension( value
.str
[i
], ".o", ".c" ) );
3160 add_generated_source( make
, value
.str
[i
], NULL
);
3163 LIST_FOR_EACH_ENTRY( file
, &make
->includes
, struct incl_file
, entry
) parse_file( make
, file
, 0 );
3165 output_dependencies( make
);
3169 /*******************************************************************
3172 static void parse_makeflags( const char *flags
)
3174 const char *p
= flags
;
3175 char *var
, *buffer
= xmalloc( strlen(flags
) + 1 );
3179 while (isspace(*p
)) p
++;
3181 while (*p
&& !isspace(*p
))
3183 if (*p
== '\\' && p
[1]) p
++;
3187 if (var
> buffer
) set_make_variable( &cmdline_vars
, buffer
);
3192 /*******************************************************************
3195 static int parse_option( const char *opt
)
3199 if (strchr( opt
, '=' )) return set_make_variable( &cmdline_vars
, opt
);
3205 if (opt
[2]) output_makefile_name
= opt
+ 2;
3208 relative_dir_mode
= 1;
3211 fprintf( stderr
, "Unknown option '%s'\n%s", opt
, Usage
);
3218 /*******************************************************************
3221 int main( int argc
, char *argv
[] )
3223 const char *makeflags
= getenv( "MAKEFLAGS" );
3226 if (makeflags
) parse_makeflags( makeflags
);
3231 if (parse_option( argv
[i
] ))
3233 for (j
= i
; j
< argc
; j
++) argv
[j
] = argv
[j
+1];
3239 if (relative_dir_mode
)
3245 fprintf( stderr
, "Option -R needs two directories\n%s", Usage
);
3248 relpath
= get_relative_path( argv
[1], argv
[2] );
3249 printf( "%s\n", relpath
? relpath
: "." );
3255 fprintf( stderr
, "%s", Usage
);
3258 atexit( cleanup_files
);
3259 signal( SIGTERM
, exit_on_signal
);
3260 signal( SIGINT
, exit_on_signal
);
3262 signal( SIGHUP
, exit_on_signal
);
3265 for (i
= 0; i
< HASH_SIZE
; i
++) list_init( &files
[i
] );
3267 top_makefile
= parse_makefile( NULL
, "# End of common header" );
3269 linguas
= get_expanded_make_var_array( top_makefile
, "LINGUAS" );
3270 target_flags
= get_expanded_make_var_array( top_makefile
, "TARGETFLAGS" );
3271 msvcrt_flags
= get_expanded_make_var_array( top_makefile
, "MSVCRTFLAGS" );
3272 dll_flags
= get_expanded_make_var_array( top_makefile
, "DLLFLAGS" );
3273 extra_cflags
= get_expanded_make_var_array( top_makefile
, "EXTRACFLAGS" );
3274 cpp_flags
= get_expanded_make_var_array( top_makefile
, "CPPFLAGS" );
3275 unwind_flags
= get_expanded_make_var_array( top_makefile
, "UNWINDFLAGS" );
3276 libs
= get_expanded_make_var_array( top_makefile
, "LIBS" );
3278 root_src_dir
= get_expanded_make_variable( top_makefile
, "srcdir" );
3279 tools_dir
= get_expanded_make_variable( top_makefile
, "TOOLSDIR" );
3280 tools_ext
= get_expanded_make_variable( top_makefile
, "TOOLSEXT" );
3281 exe_ext
= get_expanded_make_variable( top_makefile
, "EXEEXT" );
3282 man_ext
= get_expanded_make_variable( top_makefile
, "api_manext" );
3283 dll_ext
= (exe_ext
&& !strcmp( exe_ext
, ".exe" )) ? "" : ".so";
3284 crosstarget
= get_expanded_make_variable( top_makefile
, "CROSSTARGET" );
3285 fontforge
= get_expanded_make_variable( top_makefile
, "FONTFORGE" );
3286 convert
= get_expanded_make_variable( top_makefile
, "CONVERT" );
3287 rsvg
= get_expanded_make_variable( top_makefile
, "RSVG" );
3288 icotool
= get_expanded_make_variable( top_makefile
, "ICOTOOL" );
3289 dlltool
= get_expanded_make_variable( top_makefile
, "DLLTOOL" );
3291 if (root_src_dir
&& !strcmp( root_src_dir
, "." )) root_src_dir
= NULL
;
3292 if (tools_dir
&& !strcmp( tools_dir
, "." )) tools_dir
= NULL
;
3293 if (!exe_ext
) exe_ext
= "";
3294 if (!tools_ext
) tools_ext
= "";
3295 if (!man_ext
) man_ext
= "3w";
3297 for (i
= 1; i
< argc
; i
++) update_makefile( argv
[i
] );