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 subdirs
;
160 struct strarray delayimports
;
161 struct strarray extradllflags
;
162 struct strarray install_lib
;
163 struct strarray install_dev
;
165 struct list includes
;
166 const char *base_dir
;
169 const char *top_src_dir
;
170 const char *top_obj_dir
;
171 const char *parent_dir
;
174 const char *sharedlib
;
175 const char *staticlib
;
176 const char *staticimplib
;
177 const char *importlib
;
180 struct makefile
**submakes
;
183 static struct makefile
*top_makefile
;
185 static const char *output_makefile_name
= "Makefile";
186 static const char *input_file_name
;
187 static const char *output_file_name
;
188 static const char *temp_file_name
;
189 static int relative_dir_mode
;
190 static int input_line
;
191 static int output_column
;
192 static FILE *output_file
;
194 static const char Usage
[] =
195 "Usage: makedep [options] [directories]\n"
197 " -R from to Compute the relative path between two directories\n"
198 " -fxxx Store output in file 'xxx' (default: Makefile)\n";
202 #define __attribute__(x)
205 static void fatal_error( const char *msg
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
206 static void fatal_perror( const char *msg
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
207 static void output( const char *format
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
208 static char *strmake( const char* fmt
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
210 /*******************************************************************
213 static void fatal_error( const char *msg
, ... )
216 va_start( valist
, msg
);
219 fprintf( stderr
, "%s:", input_file_name
);
220 if (input_line
) fprintf( stderr
, "%d:", input_line
);
221 fprintf( stderr
, " error: " );
223 else fprintf( stderr
, "makedep: error: " );
224 vfprintf( stderr
, msg
, valist
);
230 /*******************************************************************
233 static void fatal_perror( const char *msg
, ... )
236 va_start( valist
, msg
);
239 fprintf( stderr
, "%s:", input_file_name
);
240 if (input_line
) fprintf( stderr
, "%d:", input_line
);
241 fprintf( stderr
, " error: " );
243 else fprintf( stderr
, "makedep: error: " );
244 vfprintf( stderr
, msg
, valist
);
251 /*******************************************************************
254 static void cleanup_files(void)
256 if (temp_file_name
) unlink( temp_file_name
);
257 if (output_file_name
) unlink( output_file_name
);
261 /*******************************************************************
264 static void exit_on_signal( int sig
)
266 exit( 1 ); /* this will call the atexit functions */
270 /*******************************************************************
273 static void *xmalloc( size_t size
)
276 if (!(res
= malloc (size
? size
: 1)))
277 fatal_error( "Virtual memory exhausted.\n" );
282 /*******************************************************************
285 static void *xrealloc (void *ptr
, size_t size
)
289 if (!(res
= realloc( ptr
, size
)))
290 fatal_error( "Virtual memory exhausted.\n" );
294 /*******************************************************************
297 static char *xstrdup( const char *str
)
299 char *res
= strdup( str
);
300 if (!res
) fatal_error( "Virtual memory exhausted.\n" );
305 /*******************************************************************
308 static char *strmake( const char* fmt
, ... )
316 char *p
= xmalloc (size
);
318 n
= vsnprintf (p
, size
, fmt
, ap
);
320 if (n
== -1) size
*= 2;
321 else if ((size_t)n
>= size
) size
= n
+ 1;
322 else return xrealloc( p
, n
+ 1 );
328 /*******************************************************************
331 static int strendswith( const char* str
, const char* end
)
333 size_t l
= strlen( str
);
334 size_t m
= strlen( end
);
336 return l
>= m
&& strcmp(str
+ l
- m
, end
) == 0;
340 /*******************************************************************
343 static void output( const char *format
, ... )
348 va_start( valist
, format
);
349 ret
= vfprintf( output_file
, format
, valist
);
351 if (ret
< 0) fatal_perror( "output" );
352 if (format
[0] && format
[strlen(format
) - 1] == '\n') output_column
= 0;
353 else output_column
+= ret
;
357 /*******************************************************************
360 static void strarray_add( struct strarray
*array
, const char *str
)
362 if (array
->count
== array
->size
)
364 if (array
->size
) array
->size
*= 2;
365 else array
->size
= 16;
366 array
->str
= xrealloc( array
->str
, sizeof(array
->str
[0]) * array
->size
);
368 array
->str
[array
->count
++] = str
;
372 /*******************************************************************
375 static void strarray_addall( struct strarray
*array
, struct strarray added
)
379 for (i
= 0; i
< added
.count
; i
++) strarray_add( array
, added
.str
[i
] );
383 /*******************************************************************
386 static int strarray_exists( const struct strarray
*array
, const char *str
)
390 for (i
= 0; i
< array
->count
; i
++) if (!strcmp( array
->str
[i
], str
)) return 1;
395 /*******************************************************************
398 static void strarray_add_uniq( struct strarray
*array
, const char *str
)
400 if (!strarray_exists( array
, str
)) strarray_add( array
, str
);
404 /*******************************************************************
407 * Find a value in a name/value pair string array.
409 static const char *strarray_get_value( const struct strarray
*array
, const char *name
)
413 for (i
= 0; i
< array
->count
; i
+= 2)
414 if (!strcmp( array
->str
[i
], name
)) return array
->str
[i
+ 1];
419 /*******************************************************************
422 * Define a value in a name/value pair string array.
424 static void strarray_set_value( struct strarray
*array
, const char *name
, const char *value
)
428 /* redefining a variable replaces the previous value */
429 for (i
= 0; i
< array
->count
; i
+= 2)
431 if (strcmp( array
->str
[i
], name
)) continue;
432 array
->str
[i
+ 1] = value
;
435 strarray_add( array
, name
);
436 strarray_add( array
, value
);
440 /*******************************************************************
443 static void output_filename( const char *name
)
445 if (output_column
+ strlen(name
) + 1 > 100)
450 else if (output_column
) output( " " );
451 output( "%s", name
);
455 /*******************************************************************
458 static void output_filenames( struct strarray array
)
462 for (i
= 0; i
< array
.count
; i
++) output_filename( array
.str
[i
] );
466 /*******************************************************************
469 static char *get_extension( char *filename
)
471 char *ext
= strrchr( filename
, '.' );
472 if (ext
&& strchr( ext
, '/' )) ext
= NULL
;
477 /*******************************************************************
480 static char *replace_extension( const char *name
, const char *old_ext
, const char *new_ext
)
483 size_t name_len
= strlen( name
);
484 size_t ext_len
= strlen( old_ext
);
486 if (name_len
>= ext_len
&& !strcmp( name
+ name_len
- ext_len
, old_ext
)) name_len
-= ext_len
;
487 ret
= xmalloc( name_len
+ strlen( new_ext
) + 1 );
488 memcpy( ret
, name
, name_len
);
489 strcpy( ret
+ name_len
, new_ext
);
494 /*******************************************************************
497 static char *replace_filename( const char *path
, const char *name
)
503 if (!path
) return xstrdup( name
);
504 if (!(p
= strrchr( path
, '/' ))) return xstrdup( name
);
506 ret
= xmalloc( len
+ strlen( name
) + 1 );
507 memcpy( ret
, path
, len
);
508 strcpy( ret
+ len
, name
);
513 /*******************************************************************
514 * strarray_replace_extension
516 static struct strarray
strarray_replace_extension( const struct strarray
*array
,
517 const char *old_ext
, const char *new_ext
)
522 ret
.count
= ret
.size
= array
->count
;
523 ret
.str
= xmalloc( sizeof(ret
.str
[0]) * ret
.size
);
524 for (i
= 0; i
< array
->count
; i
++) ret
.str
[i
] = replace_extension( array
->str
[i
], old_ext
, new_ext
);
529 /*******************************************************************
532 static char *replace_substr( const char *str
, const char *start
, size_t len
, const char *replace
)
534 size_t pos
= start
- str
;
535 char *ret
= xmalloc( pos
+ strlen(replace
) + strlen(start
+ len
) + 1 );
536 memcpy( ret
, str
, pos
);
537 strcpy( ret
+ pos
, replace
);
538 strcat( ret
+ pos
, start
+ len
);
543 /*******************************************************************
546 * Determine where the destination path is located relative to the 'from' path.
548 static char *get_relative_path( const char *from
, const char *dest
)
552 unsigned int dotdots
= 0;
554 /* a path of "." is equivalent to an empty path */
555 if (!strcmp( from
, "." )) from
= "";
559 while (*from
== '/') from
++;
560 while (*dest
== '/') dest
++;
561 start
= dest
; /* save start of next path element */
564 while (*from
&& *from
!= '/' && *from
== *dest
) { from
++; dest
++; }
565 if ((!*from
|| *from
== '/') && (!*dest
|| *dest
== '/')) continue;
567 /* count remaining elements in 'from' */
571 while (*from
&& *from
!= '/') from
++;
572 while (*from
== '/') from
++;
578 if (!start
[0] && !dotdots
) return NULL
; /* empty path */
580 ret
= xmalloc( 3 * dotdots
+ strlen( start
) + 1 );
581 for (p
= ret
; dotdots
; dotdots
--, p
+= 3) memcpy( p
, "../", 3 );
583 if (start
[0]) strcpy( p
, start
);
584 else p
[-1] = 0; /* remove trailing slash */
589 /*******************************************************************
592 static char *concat_paths( const char *base
, const char *path
)
594 if (!base
|| !base
[0]) return xstrdup( path
&& path
[0] ? path
: "." );
595 if (!path
|| !path
[0]) return xstrdup( base
);
596 if (path
[0] == '/') return xstrdup( path
);
597 return strmake( "%s/%s", base
, path
);
601 /*******************************************************************
604 static char *base_dir_path( const struct makefile
*make
, const char *path
)
606 return concat_paths( make
->base_dir
, path
);
610 /*******************************************************************
613 static char *obj_dir_path( const struct makefile
*make
, const char *path
)
615 return concat_paths( make
->obj_dir
, path
);
619 /*******************************************************************
622 static char *src_dir_path( const struct makefile
*make
, const char *path
)
624 if (make
->src_dir
) return concat_paths( make
->src_dir
, path
);
625 return obj_dir_path( make
, path
);
629 /*******************************************************************
632 static char *top_obj_dir_path( const struct makefile
*make
, const char *path
)
634 return concat_paths( make
->top_obj_dir
, path
);
638 /*******************************************************************
641 static char *top_dir_path( const struct makefile
*make
, const char *path
)
643 if (make
->top_src_dir
) return concat_paths( make
->top_src_dir
, path
);
644 return top_obj_dir_path( make
, path
);
648 /*******************************************************************
651 static char *root_dir_path( const char *path
)
653 return concat_paths( root_src_dir
, path
);
657 /*******************************************************************
660 static char *tools_dir_path( const struct makefile
*make
, const char *path
)
662 if (tools_dir
) return top_obj_dir_path( make
, strmake( "%s/tools/%s", tools_dir
, path
));
663 return top_obj_dir_path( make
, strmake( "tools/%s", path
));
667 /*******************************************************************
670 static char *tools_path( const struct makefile
*make
, const char *name
)
672 return strmake( "%s/%s%s", tools_dir_path( make
, name
), name
, tools_ext
);
676 /*******************************************************************
679 static char *get_line( FILE *file
)
687 buffer
= xmalloc( size
);
689 if (!fgets( buffer
, size
, file
)) return NULL
;
694 char *p
= buffer
+ strlen(buffer
);
695 /* if line is larger than buffer, resize buffer */
696 while (p
== buffer
+ size
- 1 && p
[-1] != '\n')
698 buffer
= xrealloc( buffer
, size
* 2 );
699 if (!fgets( buffer
+ size
- 1, size
+ 1, file
)) break;
700 p
= buffer
+ strlen(buffer
);
703 if (p
> buffer
&& p
[-1] == '\n')
706 if (p
> buffer
&& p
[-1] == '\r') *(--p
) = 0;
707 if (p
> buffer
&& p
[-1] == '\\')
710 /* line ends in backslash, read continuation line */
711 if (!fgets( p
, size
- (p
- buffer
), file
)) return buffer
;
721 /*******************************************************************
724 static unsigned int hash_filename( const char *name
)
726 unsigned int ret
= 0;
727 while (*name
) ret
= (ret
<< 7) + (ret
<< 3) + *name
++;
728 return ret
% HASH_SIZE
;
732 /*******************************************************************
735 static struct file
*add_file( const char *name
)
737 struct file
*file
= xmalloc( sizeof(*file
) );
738 memset( file
, 0, sizeof(*file
) );
739 file
->name
= xstrdup( name
);
740 list_add_tail( &files
[hash_filename( name
)], &file
->entry
);
745 /*******************************************************************
748 static void add_dependency( struct file
*file
, const char *name
, enum incl_type type
)
750 /* enforce some rules for the Wine tree */
752 if (!memcmp( name
, "../", 3 ))
753 fatal_error( "#include directive with relative path not allowed\n" );
755 if (!strcmp( name
, "config.h" ))
757 if (strendswith( file
->name
, ".h" ))
758 fatal_error( "config.h must not be included by a header file\n" );
759 if (file
->deps_count
)
760 fatal_error( "config.h must be included before anything else\n" );
762 else if (!strcmp( name
, "wine/port.h" ))
764 if (strendswith( file
->name
, ".h" ))
765 fatal_error( "wine/port.h must not be included by a header file\n" );
766 if (!file
->deps_count
) fatal_error( "config.h must be included before wine/port.h\n" );
767 if (file
->deps_count
> 1)
768 fatal_error( "wine/port.h must be included before everything except config.h\n" );
769 if (strcmp( file
->deps
[0].name
, "config.h" ))
770 fatal_error( "config.h must be included before wine/port.h\n" );
773 if (file
->deps_count
>= file
->deps_size
)
775 file
->deps_size
*= 2;
776 if (file
->deps_size
< 16) file
->deps_size
= 16;
777 file
->deps
= xrealloc( file
->deps
, file
->deps_size
* sizeof(*file
->deps
) );
779 file
->deps
[file
->deps_count
].line
= input_line
;
780 file
->deps
[file
->deps_count
].type
= type
;
781 file
->deps
[file
->deps_count
].name
= xstrdup( name
);
786 /*******************************************************************
789 static struct incl_file
*find_src_file( const struct makefile
*make
, const char *name
)
791 struct incl_file
*file
;
793 LIST_FOR_EACH_ENTRY( file
, &make
->sources
, struct incl_file
, entry
)
794 if (!strcmp( name
, file
->name
)) return file
;
798 /*******************************************************************
801 static struct incl_file
*find_include_file( const struct makefile
*make
, const char *name
)
803 struct incl_file
*file
;
805 LIST_FOR_EACH_ENTRY( file
, &make
->includes
, struct incl_file
, entry
)
806 if (!strcmp( name
, file
->name
)) return file
;
810 /*******************************************************************
813 * Add an include file if it doesn't already exists.
815 static struct incl_file
*add_include( struct makefile
*make
, struct incl_file
*parent
,
816 const char *name
, int line
, enum incl_type type
)
818 struct incl_file
*include
;
820 if (parent
->files_count
>= parent
->files_size
)
822 parent
->files_size
*= 2;
823 if (parent
->files_size
< 16) parent
->files_size
= 16;
824 parent
->files
= xrealloc( parent
->files
, parent
->files_size
* sizeof(*parent
->files
) );
827 LIST_FOR_EACH_ENTRY( include
, &make
->includes
, struct incl_file
, entry
)
828 if (!strcmp( name
, include
->name
)) goto found
;
830 include
= xmalloc( sizeof(*include
) );
831 memset( include
, 0, sizeof(*include
) );
832 include
->name
= xstrdup(name
);
833 include
->included_by
= parent
;
834 include
->included_line
= line
;
835 include
->type
= type
;
836 list_add_tail( &make
->includes
, &include
->entry
);
838 parent
->files
[parent
->files_count
++] = include
;
843 /*******************************************************************
844 * add_generated_source
846 * Add a generated source file to the list.
848 static struct incl_file
*add_generated_source( struct makefile
*make
,
849 const char *name
, const char *filename
)
851 struct incl_file
*file
;
853 if ((file
= find_src_file( make
, name
))) return file
; /* we already have it */
854 file
= xmalloc( sizeof(*file
) );
855 memset( file
, 0, sizeof(*file
) );
856 file
->file
= add_file( name
);
857 file
->name
= xstrdup( name
);
858 file
->filename
= obj_dir_path( make
, filename
? filename
: name
);
859 file
->file
->flags
= FLAG_GENERATED
;
860 list_add_tail( &make
->sources
, &file
->entry
);
865 /*******************************************************************
866 * parse_include_directive
868 static void parse_include_directive( struct file
*source
, char *str
)
870 char quote
, *include
, *p
= str
;
872 while (*p
&& isspace(*p
)) p
++;
873 if (*p
!= '\"' && *p
!= '<' ) return;
875 if (quote
== '<') quote
= '>';
877 while (*p
&& (*p
!= quote
)) p
++;
878 if (!*p
) fatal_error( "malformed include directive '%s'\n", str
);
880 add_dependency( source
, include
, (quote
== '>') ? INCL_SYSTEM
: INCL_NORMAL
);
884 /*******************************************************************
885 * parse_pragma_directive
887 static void parse_pragma_directive( struct file
*source
, char *str
)
889 char *flag
, *p
= str
;
891 if (!isspace( *p
)) return;
892 while (*p
&& isspace(*p
)) p
++;
893 p
= strtok( p
, " \t" );
894 if (strcmp( p
, "makedep" )) return;
896 while ((flag
= strtok( NULL
, " \t" )))
898 if (!strcmp( flag
, "depend" ))
900 while ((p
= strtok( NULL
, " \t" ))) add_dependency( source
, p
, INCL_NORMAL
);
903 else if (!strcmp( flag
, "install" )) source
->flags
|= FLAG_INSTALL
;
905 if (strendswith( source
->name
, ".idl" ))
907 if (!strcmp( flag
, "header" )) source
->flags
|= FLAG_IDL_HEADER
;
908 else if (!strcmp( flag
, "proxy" )) source
->flags
|= FLAG_IDL_PROXY
;
909 else if (!strcmp( flag
, "client" )) source
->flags
|= FLAG_IDL_CLIENT
;
910 else if (!strcmp( flag
, "server" )) source
->flags
|= FLAG_IDL_SERVER
;
911 else if (!strcmp( flag
, "ident" )) source
->flags
|= FLAG_IDL_IDENT
;
912 else if (!strcmp( flag
, "typelib" )) source
->flags
|= FLAG_IDL_TYPELIB
;
913 else if (!strcmp( flag
, "register" )) source
->flags
|= FLAG_IDL_REGISTER
;
914 else if (!strcmp( flag
, "regtypelib" )) source
->flags
|= FLAG_IDL_REGTYPELIB
;
916 else if (strendswith( source
->name
, ".rc" ))
918 if (!strcmp( flag
, "po" )) source
->flags
|= FLAG_RC_PO
;
920 else if (strendswith( source
->name
, ".sfd" ))
922 if (!strcmp( flag
, "font" ))
924 struct strarray
*array
= source
->args
;
928 source
->args
= array
= xmalloc( sizeof(*array
) );
929 *array
= empty_strarray
;
930 source
->flags
|= FLAG_SFD_FONTS
;
932 strarray_add( array
, xstrdup( strtok( NULL
, "" )));
936 else if (!strcmp( flag
, "implib" )) source
->flags
|= FLAG_C_IMPLIB
;
941 /*******************************************************************
942 * parse_cpp_directive
944 static void parse_cpp_directive( struct file
*source
, char *str
)
946 while (*str
&& isspace(*str
)) str
++;
947 if (*str
++ != '#') return;
948 while (*str
&& isspace(*str
)) str
++;
950 if (!strncmp( str
, "include", 7 ))
951 parse_include_directive( source
, str
+ 7 );
952 else if (!strncmp( str
, "import", 6 ) && strendswith( source
->name
, ".m" ))
953 parse_include_directive( source
, str
+ 6 );
954 else if (!strncmp( str
, "pragma", 6 ))
955 parse_pragma_directive( source
, str
+ 6 );
959 /*******************************************************************
962 static void parse_idl_file( struct file
*source
, FILE *file
)
964 char *buffer
, *include
;
968 while ((buffer
= get_line( file
)))
972 while (*p
&& isspace(*p
)) p
++;
974 if (!strncmp( p
, "importlib", 9 ))
977 while (*p
&& isspace(*p
)) p
++;
978 if (*p
++ != '(') continue;
979 while (*p
&& isspace(*p
)) p
++;
980 if (*p
++ != '"') continue;
982 while (*p
&& (*p
!= '"')) p
++;
983 if (!*p
) fatal_error( "malformed importlib directive\n" );
985 add_dependency( source
, include
, INCL_IMPORTLIB
);
989 if (!strncmp( p
, "import", 6 ))
992 while (*p
&& isspace(*p
)) p
++;
993 if (*p
!= '"') continue;
995 while (*p
&& (*p
!= '"')) p
++;
996 if (!*p
) fatal_error( "malformed import directive\n" );
998 add_dependency( source
, include
, INCL_IMPORT
);
1002 /* check for #include inside cpp_quote */
1003 if (!strncmp( p
, "cpp_quote", 9 ))
1006 while (*p
&& isspace(*p
)) p
++;
1007 if (*p
++ != '(') continue;
1008 while (*p
&& isspace(*p
)) p
++;
1009 if (*p
++ != '"') continue;
1010 if (*p
++ != '#') continue;
1011 while (*p
&& isspace(*p
)) p
++;
1012 if (strncmp( p
, "include", 7 )) continue;
1014 while (*p
&& isspace(*p
)) p
++;
1015 if (*p
== '\\' && p
[1] == '"')
1022 if (*p
++ != '<' ) continue;
1026 while (*p
&& (*p
!= quote
)) p
++;
1027 if (!*p
|| (quote
== '"' && p
[-1] != '\\'))
1028 fatal_error( "malformed #include directive inside cpp_quote\n" );
1029 if (quote
== '"') p
--; /* remove backslash */
1031 add_dependency( source
, include
, (quote
== '>') ? INCL_CPP_QUOTE_SYSTEM
: INCL_CPP_QUOTE
);
1035 parse_cpp_directive( source
, p
);
1039 /*******************************************************************
1042 static void parse_c_file( struct file
*source
, FILE *file
)
1047 while ((buffer
= get_line( file
)))
1049 parse_cpp_directive( source
, buffer
);
1054 /*******************************************************************
1057 static void parse_rc_file( struct file
*source
, FILE *file
)
1059 char *buffer
, *include
;
1062 while ((buffer
= get_line( file
)))
1066 while (*p
&& isspace(*p
)) p
++;
1068 if (p
[0] == '/' && p
[1] == '*') /* check for magic makedep comment */
1071 while (*p
&& isspace(*p
)) p
++;
1072 if (strncmp( p
, "@makedep:", 9 )) continue;
1074 while (*p
&& isspace(*p
)) p
++;
1079 while (*p
&& *p
!= quote
) p
++;
1084 while (*p
&& !isspace(*p
) && *p
!= '*') p
++;
1087 fatal_error( "malformed makedep comment\n" );
1089 add_dependency( source
, include
, (quote
== '>') ? INCL_SYSTEM
: INCL_NORMAL
);
1093 parse_cpp_directive( source
, buffer
);
1098 /*******************************************************************
1101 static void parse_in_file( struct file
*source
, FILE *file
)
1105 /* make sure it gets rebuilt when the version changes */
1106 add_dependency( source
, "config.h", INCL_SYSTEM
);
1108 if (!strendswith( source
->name
, ".man.in" )) return; /* not a man page */
1111 while ((buffer
= get_line( file
)))
1113 if (strncmp( buffer
, ".TH", 3 )) continue;
1114 if (!(p
= strtok( buffer
, " \t" ))) continue; /* .TH */
1115 if (!(p
= strtok( NULL
, " \t" ))) continue; /* program name */
1116 if (!(p
= strtok( NULL
, " \t" ))) continue; /* man section */
1117 source
->args
= xstrdup( p
);
1123 /*******************************************************************
1126 static void parse_sfd_file( struct file
*source
, FILE *file
)
1128 char *p
, *eol
, *buffer
;
1131 while ((buffer
= get_line( file
)))
1133 if (strncmp( buffer
, "UComments:", 10 )) continue;
1135 while (*p
== ' ') p
++;
1136 if (p
[0] == '"' && p
[1] && buffer
[strlen(buffer
) - 1] == '"')
1139 buffer
[strlen(buffer
) - 1] = 0;
1141 while ((eol
= strstr( p
, "+AAoA" )))
1144 while (*p
&& isspace(*p
)) p
++;
1147 while (*p
&& isspace(*p
)) p
++;
1148 if (!strncmp( p
, "pragma", 6 )) parse_pragma_directive( source
, p
+ 6 );
1152 while (*p
&& isspace(*p
)) p
++;
1153 if (*p
++ != '#') return;
1154 while (*p
&& isspace(*p
)) p
++;
1155 if (!strncmp( p
, "pragma", 6 )) parse_pragma_directive( source
, p
+ 6 );
1164 void (*parse
)( struct file
*file
, FILE *f
);
1165 } parse_functions
[] =
1167 { ".c", parse_c_file
},
1168 { ".h", parse_c_file
},
1169 { ".inl", parse_c_file
},
1170 { ".l", parse_c_file
},
1171 { ".m", parse_c_file
},
1172 { ".rh", parse_c_file
},
1173 { ".x", parse_c_file
},
1174 { ".y", parse_c_file
},
1175 { ".idl", parse_idl_file
},
1176 { ".rc", parse_rc_file
},
1177 { ".in", parse_in_file
},
1178 { ".sfd", parse_sfd_file
}
1181 /*******************************************************************
1184 static struct file
*load_file( const char *name
)
1188 unsigned int i
, hash
= hash_filename( name
);
1190 LIST_FOR_EACH_ENTRY( file
, &files
[hash
], struct file
, entry
)
1191 if (!strcmp( name
, file
->name
)) return file
;
1193 if (!(f
= fopen( name
, "r" ))) return NULL
;
1195 file
= add_file( name
);
1196 input_file_name
= file
->name
;
1199 for (i
= 0; i
< sizeof(parse_functions
) / sizeof(parse_functions
[0]); i
++)
1201 if (!strendswith( name
, parse_functions
[i
].ext
)) continue;
1202 parse_functions
[i
].parse( file
, f
);
1207 input_file_name
= NULL
;
1213 /*******************************************************************
1214 * open_include_path_file
1216 * Open a file from a directory on the include path.
1218 static struct file
*open_include_path_file( const struct makefile
*make
, const char *dir
,
1219 const char *name
, char **filename
)
1221 char *src_path
= base_dir_path( make
, concat_paths( dir
, name
));
1222 struct file
*ret
= load_file( src_path
);
1224 if (ret
) *filename
= src_dir_path( make
, concat_paths( dir
, name
));
1229 /*******************************************************************
1230 * open_file_same_dir
1232 * Open a file in the same directory as the parent.
1234 static struct file
*open_file_same_dir( const struct incl_file
*parent
, const char *name
, char **filename
)
1236 char *src_path
= replace_filename( parent
->file
->name
, name
);
1237 struct file
*ret
= load_file( src_path
);
1239 if (ret
) *filename
= replace_filename( parent
->filename
, name
);
1245 /*******************************************************************
1248 * Open a file in the source directory of the makefile.
1250 static struct file
*open_local_file( const struct makefile
*make
, const char *path
, char **filename
)
1252 char *src_path
= root_dir_path( base_dir_path( make
, path
));
1253 struct file
*ret
= load_file( src_path
);
1255 /* if not found, try parent dir */
1256 if (!ret
&& make
->parent_dir
)
1259 path
= strmake( "%s/%s", make
->parent_dir
, path
);
1260 src_path
= root_dir_path( base_dir_path( make
, path
));
1261 ret
= load_file( src_path
);
1264 if (ret
) *filename
= src_dir_path( make
, path
);
1270 /*******************************************************************
1273 * Open a file in the top-level source directory.
1275 static struct file
*open_global_file( const struct makefile
*make
, const char *path
, char **filename
)
1277 char *src_path
= root_dir_path( path
);
1278 struct file
*ret
= load_file( src_path
);
1280 if (ret
) *filename
= top_dir_path( make
, path
);
1286 /*******************************************************************
1287 * open_global_header
1289 * Open a file in the global include source directory.
1291 static struct file
*open_global_header( const struct makefile
*make
, const char *path
, char **filename
)
1293 return open_global_file( make
, strmake( "include/%s", path
), filename
);
1297 /*******************************************************************
1300 static struct file
*open_src_file( const struct makefile
*make
, struct incl_file
*pFile
)
1302 struct file
*file
= open_local_file( make
, pFile
->name
, &pFile
->filename
);
1304 if (!file
) fatal_perror( "open %s", pFile
->name
);
1309 /*******************************************************************
1312 static struct file
*open_include_file( const struct makefile
*make
, struct incl_file
*pFile
)
1314 struct file
*file
= NULL
;
1316 unsigned int i
, len
;
1320 /* check for generated bison header */
1322 if (strendswith( pFile
->name
, ".tab.h" ) &&
1323 (file
= open_local_file( make
, replace_extension( pFile
->name
, ".tab.h", ".y" ), &filename
)))
1325 pFile
->sourcename
= filename
;
1326 pFile
->filename
= obj_dir_path( make
, pFile
->name
);
1330 /* check for corresponding idl file in source dir */
1332 if (strendswith( pFile
->name
, ".h" ) &&
1333 (file
= open_local_file( make
, replace_extension( pFile
->name
, ".h", ".idl" ), &filename
)))
1335 pFile
->sourcename
= filename
;
1336 pFile
->filename
= obj_dir_path( make
, pFile
->name
);
1340 /* check for corresponding tlb file in source dir */
1342 if (strendswith( pFile
->name
, ".tlb" ) &&
1343 (file
= open_local_file( make
, replace_extension( pFile
->name
, ".tlb", ".idl" ), &filename
)))
1345 pFile
->sourcename
= filename
;
1346 pFile
->filename
= obj_dir_path( make
, pFile
->name
);
1350 /* now try in source dir */
1351 if ((file
= open_local_file( make
, pFile
->name
, &pFile
->filename
))) return file
;
1353 /* check for corresponding idl file in global includes */
1355 if (strendswith( pFile
->name
, ".h" ) &&
1356 (file
= open_global_header( make
, replace_extension( pFile
->name
, ".h", ".idl" ), &filename
)))
1358 pFile
->sourcename
= filename
;
1359 pFile
->filename
= top_obj_dir_path( make
, strmake( "include/%s", pFile
->name
));
1363 /* check for corresponding .in file in global includes (for config.h.in) */
1365 if (strendswith( pFile
->name
, ".h" ) &&
1366 (file
= open_global_header( make
, replace_extension( pFile
->name
, ".h", ".h.in" ), &filename
)))
1368 pFile
->sourcename
= filename
;
1369 pFile
->filename
= top_obj_dir_path( make
, strmake( "include/%s", pFile
->name
));
1373 /* check for corresponding .x file in global includes */
1375 if (strendswith( pFile
->name
, "tmpl.h" ) &&
1376 (file
= open_global_header( make
, replace_extension( pFile
->name
, ".h", ".x" ), &filename
)))
1378 pFile
->sourcename
= filename
;
1379 pFile
->filename
= top_obj_dir_path( make
, strmake( "include/%s", pFile
->name
));
1383 /* check for corresponding .tlb file in global includes */
1385 if (strendswith( pFile
->name
, ".tlb" ) &&
1386 (file
= open_global_header( make
, replace_extension( pFile
->name
, ".tlb", ".idl" ), &filename
)))
1388 pFile
->sourcename
= filename
;
1389 pFile
->filename
= top_obj_dir_path( make
, strmake( "include/%s", pFile
->name
));
1393 /* check in global includes source dir */
1395 if ((file
= open_global_header( make
, pFile
->name
, &pFile
->filename
))) return file
;
1397 /* check in global msvcrt includes */
1398 if (make
->use_msvcrt
&&
1399 (file
= open_global_header( make
, strmake( "msvcrt/%s", pFile
->name
), &pFile
->filename
)))
1402 /* now search in include paths */
1403 for (i
= 0; i
< make
->include_paths
.count
; i
++)
1405 const char *dir
= make
->include_paths
.str
[i
];
1406 const char *prefix
= make
->top_src_dir
? make
->top_src_dir
: make
->top_obj_dir
;
1410 len
= strlen( prefix
);
1411 if (!strncmp( dir
, prefix
, len
) && (!dir
[len
] || dir
[len
] == '/'))
1413 while (dir
[len
] == '/') len
++;
1414 file
= open_global_file( make
, concat_paths( dir
+ len
, pFile
->name
), &pFile
->filename
);
1415 if (file
) return file
;
1417 if (make
->top_src_dir
) continue; /* ignore paths that don't point to the top source dir */
1421 if ((file
= open_include_path_file( make
, dir
, pFile
->name
, &pFile
->filename
)))
1425 if (pFile
->type
== INCL_SYSTEM
) return NULL
; /* ignore system files we cannot find */
1427 /* try in src file directory */
1428 if ((file
= open_file_same_dir( pFile
->included_by
, pFile
->name
, &pFile
->filename
))) return file
;
1430 fprintf( stderr
, "%s:%d: error: ", pFile
->included_by
->file
->name
, pFile
->included_line
);
1431 perror( pFile
->name
);
1432 pFile
= pFile
->included_by
;
1433 while (pFile
&& pFile
->included_by
)
1435 const char *parent
= pFile
->included_by
->sourcename
;
1436 if (!parent
) parent
= pFile
->included_by
->file
->name
;
1437 fprintf( stderr
, "%s:%d: note: %s was first included here\n",
1438 parent
, pFile
->included_line
, pFile
->name
);
1439 pFile
= pFile
->included_by
;
1445 /*******************************************************************
1448 static void add_all_includes( struct makefile
*make
, struct incl_file
*parent
, struct file
*file
)
1452 parent
->files_count
= 0;
1453 parent
->files_size
= file
->deps_count
;
1454 parent
->files
= xmalloc( parent
->files_size
* sizeof(*parent
->files
) );
1455 for (i
= 0; i
< file
->deps_count
; i
++)
1457 switch (file
->deps
[i
].type
)
1461 add_include( make
, parent
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_NORMAL
);
1463 case INCL_IMPORTLIB
:
1464 add_include( make
, parent
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_IMPORTLIB
);
1467 add_include( make
, parent
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_SYSTEM
);
1469 case INCL_CPP_QUOTE
:
1470 case INCL_CPP_QUOTE_SYSTEM
:
1477 /*******************************************************************
1480 static void parse_file( struct makefile
*make
, struct incl_file
*source
, int src
)
1482 struct file
*file
= src
? open_src_file( make
, source
) : open_include_file( make
, source
);
1486 source
->file
= file
;
1487 source
->files_count
= 0;
1488 source
->files_size
= file
->deps_count
;
1489 source
->files
= xmalloc( source
->files_size
* sizeof(*source
->files
) );
1491 if (source
->sourcename
)
1493 if (strendswith( source
->sourcename
, ".idl" ))
1497 if (strendswith( source
->name
, ".tlb" )) return; /* typelibs don't include anything */
1499 /* generated .h file always includes these */
1500 add_include( make
, source
, "rpc.h", 0, INCL_NORMAL
);
1501 add_include( make
, source
, "rpcndr.h", 0, INCL_NORMAL
);
1502 for (i
= 0; i
< file
->deps_count
; i
++)
1504 switch (file
->deps
[i
].type
)
1507 if (strendswith( file
->deps
[i
].name
, ".idl" ))
1508 add_include( make
, source
, replace_extension( file
->deps
[i
].name
, ".idl", ".h" ),
1509 file
->deps
[i
].line
, INCL_NORMAL
);
1511 add_include( make
, source
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_NORMAL
);
1513 case INCL_CPP_QUOTE
:
1514 add_include( make
, source
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_NORMAL
);
1516 case INCL_CPP_QUOTE_SYSTEM
:
1517 add_include( make
, source
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_SYSTEM
);
1521 case INCL_IMPORTLIB
:
1527 if (strendswith( source
->sourcename
, ".y" ))
1528 return; /* generated .tab.h doesn't include anything */
1531 add_all_includes( make
, source
, file
);
1535 /*******************************************************************
1538 * Add a source file to the list.
1540 static struct incl_file
*add_src_file( struct makefile
*make
, const char *name
)
1542 struct incl_file
*file
;
1544 if ((file
= find_src_file( make
, name
))) return file
; /* we already have it */
1545 file
= xmalloc( sizeof(*file
) );
1546 memset( file
, 0, sizeof(*file
) );
1547 file
->name
= xstrdup(name
);
1548 list_add_tail( &make
->sources
, &file
->entry
);
1549 parse_file( make
, file
, 1 );
1554 /*******************************************************************
1555 * open_input_makefile
1557 static FILE *open_input_makefile( const struct makefile
*make
)
1562 input_file_name
= root_dir_path( base_dir_path( make
, strmake( "%s.in", output_makefile_name
)));
1564 input_file_name
= output_makefile_name
; /* always use output name for main Makefile */
1567 if (!(ret
= fopen( input_file_name
, "r" ))) fatal_perror( "open" );
1572 /*******************************************************************
1575 static const char *get_make_variable( const struct makefile
*make
, const char *name
)
1579 if ((ret
= strarray_get_value( &cmdline_vars
, name
))) return ret
;
1580 if ((ret
= strarray_get_value( &make
->vars
, name
))) return ret
;
1581 if (top_makefile
&& (ret
= strarray_get_value( &top_makefile
->vars
, name
))) return ret
;
1586 /*******************************************************************
1587 * get_expanded_make_variable
1589 static char *get_expanded_make_variable( const struct makefile
*make
, const char *name
)
1592 char *p
, *end
, *expand
, *tmp
;
1594 var
= get_make_variable( make
, name
);
1595 if (!var
) return NULL
;
1597 p
= expand
= xstrdup( var
);
1598 while ((p
= strchr( p
, '$' )))
1602 if (!(end
= strchr( p
+ 2, ')' ))) fatal_error( "syntax error in '%s'\n", expand
);
1604 if (strchr( p
+ 2, ':' )) fatal_error( "pattern replacement not supported for '%s'\n", p
+ 2 );
1605 var
= get_make_variable( make
, p
+ 2 );
1606 tmp
= replace_substr( expand
, p
, end
- p
, var
? var
: "" );
1607 /* switch to the new string */
1608 p
= tmp
+ (p
- expand
);
1612 else if (p
[1] == '{') /* don't expand ${} variables */
1614 if (!(end
= strchr( p
+ 2, '}' ))) fatal_error( "syntax error in '%s'\n", expand
);
1617 else if (p
[1] == '$')
1621 else fatal_error( "syntax error in '%s'\n", expand
);
1624 /* consider empty variables undefined */
1626 while (*p
&& isspace(*p
)) p
++;
1627 if (*p
) return expand
;
1633 /*******************************************************************
1634 * get_expanded_make_var_array
1636 static struct strarray
get_expanded_make_var_array( const struct makefile
*make
, const char *name
)
1638 struct strarray ret
= empty_strarray
;
1639 char *value
, *token
;
1641 if ((value
= get_expanded_make_variable( make
, name
)))
1642 for (token
= strtok( value
, " \t" ); token
; token
= strtok( NULL
, " \t" ))
1643 strarray_add( &ret
, token
);
1648 /*******************************************************************
1651 static char *file_local_var( const char *file
, const char *name
)
1655 var
= strmake( "%s_%s", file
, name
);
1656 for (p
= var
; *p
; p
++) if (!isalnum( *p
)) *p
= '_';
1661 /*******************************************************************
1664 static int set_make_variable( struct strarray
*array
, const char *assignment
)
1668 p
= name
= xstrdup( assignment
);
1669 while (isalnum(*p
) || *p
== '_') p
++;
1670 if (name
== p
) return 0; /* not a variable */
1674 while (isspace(*p
)) p
++;
1676 if (*p
!= '=') return 0; /* not an assignment */
1678 while (isspace(*p
)) p
++;
1680 strarray_set_value( array
, name
, p
);
1685 /*******************************************************************
1688 static struct makefile
*parse_makefile( const char *path
, const char *separator
)
1692 struct makefile
*make
= xmalloc( sizeof(*make
) );
1694 memset( make
, 0, sizeof(*make
) );
1697 make
->top_obj_dir
= get_relative_path( path
, "" );
1698 make
->base_dir
= path
;
1699 if (!strcmp( make
->base_dir
, "." )) make
->base_dir
= NULL
;
1702 file
= open_input_makefile( make
);
1703 while ((buffer
= get_line( file
)))
1705 if (separator
&& !strncmp( buffer
, separator
, strlen(separator
) )) break;
1706 if (*buffer
== '\t') continue; /* command */
1707 while (isspace( *buffer
)) buffer
++;
1708 if (*buffer
== '#') continue; /* comment */
1709 set_make_variable( &make
->vars
, buffer
);
1712 input_file_name
= NULL
;
1717 /*******************************************************************
1718 * add_generated_sources
1720 static void add_generated_sources( struct makefile
*make
)
1722 struct incl_file
*source
, *next
, *file
;
1724 LIST_FOR_EACH_ENTRY_SAFE( source
, next
, &make
->sources
, struct incl_file
, entry
)
1726 if (source
->file
->flags
& FLAG_IDL_CLIENT
)
1728 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_c.c" ), NULL
);
1729 add_dependency( file
->file
, replace_extension( source
->name
, ".idl", ".h" ), INCL_NORMAL
);
1730 add_all_includes( make
, file
, file
->file
);
1732 if (source
->file
->flags
& FLAG_IDL_SERVER
)
1734 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_s.c" ), NULL
);
1735 add_dependency( file
->file
, "wine/exception.h", INCL_NORMAL
);
1736 add_dependency( file
->file
, replace_extension( source
->name
, ".idl", ".h" ), INCL_NORMAL
);
1737 add_all_includes( make
, file
, file
->file
);
1739 if (source
->file
->flags
& FLAG_IDL_IDENT
)
1741 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_i.c" ), NULL
);
1742 add_dependency( file
->file
, "rpc.h", INCL_NORMAL
);
1743 add_dependency( file
->file
, "rpcndr.h", INCL_NORMAL
);
1744 add_dependency( file
->file
, "guiddef.h", INCL_NORMAL
);
1745 add_all_includes( make
, file
, file
->file
);
1747 if (source
->file
->flags
& FLAG_IDL_PROXY
)
1749 file
= add_generated_source( make
, "dlldata.o", "dlldata.c" );
1750 add_dependency( file
->file
, "objbase.h", INCL_NORMAL
);
1751 add_dependency( file
->file
, "rpcproxy.h", INCL_NORMAL
);
1752 add_all_includes( make
, file
, file
->file
);
1753 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_p.c" ), NULL
);
1754 add_dependency( file
->file
, "objbase.h", INCL_NORMAL
);
1755 add_dependency( file
->file
, "rpcproxy.h", INCL_NORMAL
);
1756 add_dependency( file
->file
, "wine/exception.h", INCL_NORMAL
);
1757 add_dependency( file
->file
, replace_extension( source
->name
, ".idl", ".h" ), INCL_NORMAL
);
1758 add_all_includes( make
, file
, file
->file
);
1760 if (source
->file
->flags
& FLAG_IDL_TYPELIB
)
1762 add_generated_source( make
, replace_extension( source
->name
, ".idl", ".tlb" ), NULL
);
1764 if (source
->file
->flags
& FLAG_IDL_REGTYPELIB
)
1766 add_generated_source( make
, replace_extension( source
->name
, ".idl", "_t.res" ), NULL
);
1768 if (source
->file
->flags
& FLAG_IDL_REGISTER
)
1770 add_generated_source( make
, replace_extension( source
->name
, ".idl", "_r.res" ), NULL
);
1772 if (source
->file
->flags
& FLAG_IDL_HEADER
)
1774 add_generated_source( make
, replace_extension( source
->name
, ".idl", ".h" ), NULL
);
1776 if (!source
->file
->flags
&& strendswith( source
->name
, ".idl" ))
1778 add_generated_source( make
, replace_extension( source
->name
, ".idl", ".h" ), NULL
);
1780 if (strendswith( source
->name
, ".x" ))
1782 add_generated_source( make
, replace_extension( source
->name
, ".x", ".h" ), NULL
);
1784 if (strendswith( source
->name
, ".y" ))
1786 file
= add_generated_source( make
, replace_extension( source
->name
, ".y", ".tab.c" ), NULL
);
1787 /* steal the includes list from the source file */
1788 file
->files_count
= source
->files_count
;
1789 file
->files_size
= source
->files_size
;
1790 file
->files
= source
->files
;
1791 source
->files_count
= source
->files_size
= 0;
1792 source
->files
= NULL
;
1794 if (strendswith( source
->name
, ".l" ))
1796 file
= add_generated_source( make
, replace_extension( source
->name
, ".l", ".yy.c" ), NULL
);
1797 /* steal the includes list from the source file */
1798 file
->files_count
= source
->files_count
;
1799 file
->files_size
= source
->files_size
;
1800 file
->files
= source
->files
;
1801 source
->files_count
= source
->files_size
= 0;
1802 source
->files
= NULL
;
1804 if (source
->file
->flags
& FLAG_C_IMPLIB
)
1806 if (!make
->staticimplib
&& make
->importlib
&& *dll_ext
)
1807 make
->staticimplib
= strmake( "lib%s.def.a", make
->importlib
);
1812 file
= add_generated_source( make
, "testlist.o", "testlist.c" );
1813 add_dependency( file
->file
, "wine/test.h", INCL_NORMAL
);
1814 add_all_includes( make
, file
, file
->file
);
1819 /*******************************************************************
1822 static void create_dir( const char *dir
)
1826 p
= path
= xstrdup( dir
);
1827 while ((p
= strchr( p
, '/' )))
1830 if (mkdir( path
, 0755 ) == -1 && errno
!= EEXIST
) fatal_perror( "mkdir %s", path
);
1832 while (*p
== '/') p
++;
1834 if (mkdir( path
, 0755 ) == -1 && errno
!= EEXIST
) fatal_perror( "mkdir %s", path
);
1839 /*******************************************************************
1840 * output_filenames_obj_dir
1842 static void output_filenames_obj_dir( const struct makefile
*make
, struct strarray array
)
1846 for (i
= 0; i
< array
.count
; i
++) output_filename( obj_dir_path( make
, array
.str
[i
] ));
1850 /*******************************************************************
1853 static void get_dependencies( struct strarray
*deps
, struct incl_file
*file
, struct incl_file
*source
)
1857 if (!file
->filename
) return;
1861 if (file
->owner
== source
) return; /* already processed */
1862 if (file
->type
== INCL_IMPORTLIB
&&
1863 !(source
->file
->flags
& (FLAG_IDL_TYPELIB
| FLAG_IDL_REGTYPELIB
)))
1864 return; /* library is imported only when building a typelib */
1865 file
->owner
= source
;
1866 strarray_add( deps
, file
->filename
);
1868 for (i
= 0; i
< file
->files_count
; i
++) get_dependencies( deps
, file
->files
[i
], source
);
1872 /*******************************************************************
1873 * get_local_dependencies
1875 * Get the local dependencies of a given target.
1877 static struct strarray
get_local_dependencies( const struct makefile
*make
, const char *name
,
1878 struct strarray targets
)
1881 struct strarray deps
= get_expanded_make_var_array( make
, file_local_var( name
, "DEPS" ));
1883 for (i
= 0; i
< deps
.count
; i
++)
1885 if (strarray_exists( &targets
, deps
.str
[i
] ))
1886 deps
.str
[i
] = obj_dir_path( make
, deps
.str
[i
] );
1888 deps
.str
[i
] = src_dir_path( make
, deps
.str
[i
] );
1894 /*******************************************************************
1897 * Check if makefile builds the named static library.
1899 static int has_static_lib( const struct makefile
*make
, const char *name
)
1901 if (!make
->staticlib
) return 0;
1902 if (strncmp( make
->staticlib
, "lib", 3 )) return 0;
1903 if (strncmp( make
->staticlib
+ 3, name
, strlen(name
) )) return 0;
1904 return !strcmp( make
->staticlib
+ 3 + strlen(name
), ".a" );
1908 /*******************************************************************
1909 * add_default_libraries
1911 static struct strarray
add_default_libraries( const struct makefile
*make
, struct strarray
*deps
)
1913 struct strarray ret
= empty_strarray
;
1914 struct strarray all_libs
= empty_strarray
;
1917 strarray_add( &all_libs
, "-lwine_port" );
1918 strarray_addall( &all_libs
, get_expanded_make_var_array( make
, "EXTRALIBS" ));
1919 strarray_addall( &all_libs
, libs
);
1921 for (i
= 0; i
< all_libs
.count
; i
++)
1924 if (!strncmp( all_libs
.str
[i
], "-l", 2 ))
1926 const char *name
= all_libs
.str
[i
] + 2;
1928 for (j
= 0; j
< top_makefile
->subdirs
.count
; j
++)
1930 const struct makefile
*submake
= top_makefile
->submakes
[j
];
1932 if ((found
= has_static_lib( submake
, name
)))
1934 const char *lib
= strmake( "%s/lib%s.a",
1935 top_obj_dir_path( make
, submake
->base_dir
), name
);
1936 strarray_add( deps
, lib
);
1937 strarray_add( &ret
, lib
);
1942 if (!found
) strarray_add( &ret
, all_libs
.str
[i
] );
1948 /*******************************************************************
1951 static struct strarray
add_import_libs( const struct makefile
*make
, struct strarray
*deps
,
1952 struct strarray imports
, int cross
)
1954 struct strarray ret
= empty_strarray
;
1957 for (i
= 0; i
< imports
.count
; i
++)
1959 const char *name
= imports
.str
[i
];
1961 for (j
= 0; j
< top_makefile
->subdirs
.count
; j
++)
1963 const struct makefile
*submake
= top_makefile
->submakes
[j
];
1965 if (submake
->importlib
&& !strcmp( submake
->importlib
, name
))
1967 const char *dir
= top_obj_dir_path( make
, submake
->base_dir
);
1968 const char *ext
= cross
? "cross.a" : *dll_ext
? "def" : "a";
1970 strarray_add( deps
, strmake( "%s/lib%s.%s", dir
, name
, ext
));
1971 if (!cross
&& submake
->staticimplib
)
1972 strarray_add( deps
, strmake( "%s/%s", dir
, submake
->staticimplib
));
1976 if (has_static_lib( submake
, name
))
1978 const char *dir
= top_obj_dir_path( make
, submake
->base_dir
);
1980 strarray_add( deps
, strmake( "%s/lib%s.a", dir
, name
));
1984 strarray_add( &ret
, strmake( "-l%s", name
));
1990 /*******************************************************************
1993 static void add_install_rule( const struct makefile
*make
, struct strarray
*install_rules
,
1994 const char *target
, const char *file
, const char *dest
)
1996 if (strarray_exists( &make
->install_lib
, target
))
1998 strarray_add( &install_rules
[INSTALL_LIB
], file
);
1999 strarray_add( &install_rules
[INSTALL_LIB
], dest
);
2001 else if (strarray_exists( &make
->install_dev
, target
))
2003 strarray_add( &install_rules
[INSTALL_DEV
], file
);
2004 strarray_add( &install_rules
[INSTALL_DEV
], dest
);
2009 /*******************************************************************
2010 * get_include_install_path
2012 * Determine the installation path for a given include file.
2014 static const char *get_include_install_path( const char *name
)
2016 if (!strncmp( name
, "wine/", 5 )) return name
+ 5;
2017 if (!strncmp( name
, "msvcrt/", 7 )) return name
;
2018 return strmake( "windows/%s", name
);
2022 /*******************************************************************
2023 * get_shared_library_name
2025 * Determine possible names for a shared library with a version number.
2027 static struct strarray
get_shared_lib_names( const char *libname
)
2029 struct strarray ret
= empty_strarray
;
2030 const char *ext
, *p
;
2031 char *name
, *first
, *second
;
2034 strarray_add( &ret
, libname
);
2036 for (p
= libname
; (p
= strchr( p
, '.' )); p
++)
2037 if ((len
= strspn( p
+ 1, "0123456789." ))) break;
2039 if (!len
) return ret
;
2041 if (*ext
&& ext
[-1] == '.') ext
--;
2043 /* keep only the first group of digits */
2044 name
= xstrdup( libname
);
2045 first
= name
+ (p
- libname
);
2046 if ((second
= strchr( first
+ 1, '.' )))
2048 strcpy( second
, ext
);
2049 strarray_add( &ret
, xstrdup( name
));
2051 /* now remove all digits */
2052 strcpy( first
, ext
);
2053 strarray_add( &ret
, name
);
2058 /*******************************************************************
2059 * output_install_rules
2061 * Rules are stored as a (file,dest) pair of values.
2062 * The first char of dest indicates the type of install.
2064 static struct strarray
output_install_rules( const struct makefile
*make
, struct strarray files
,
2065 const char *target
, struct strarray
*phony_targets
)
2069 struct strarray uninstall
= empty_strarray
;
2070 struct strarray targets
= empty_strarray
;
2072 if (!files
.count
) return uninstall
;
2074 for (i
= 0; i
< files
.count
; i
+= 2)
2075 if (strchr( "dps", files
.str
[i
+ 1][0] )) /* only for files copied from object dir */
2076 strarray_add_uniq( &targets
, files
.str
[i
] );
2078 output( "install %s::", target
);
2079 output_filenames_obj_dir( make
, targets
);
2082 install_sh
= top_dir_path( make
, "tools/install-sh" );
2083 for (i
= 0; i
< files
.count
; i
+= 2)
2085 const char *file
= files
.str
[i
];
2086 const char *dest
= files
.str
[i
+ 1];
2090 case 'd': /* data file */
2091 output( "\t%s -m 644 $(INSTALL_DATA_FLAGS) %s $(DESTDIR)%s\n",
2092 install_sh
, obj_dir_path( make
, file
), dest
+ 1 );
2094 case 'D': /* data file in source dir */
2095 output( "\t%s -m 644 $(INSTALL_DATA_FLAGS) %s $(DESTDIR)%s\n",
2096 install_sh
, src_dir_path( make
, file
), dest
+ 1 );
2098 case 'p': /* program file */
2099 output( "\tSTRIPPROG=\"$(STRIP)\" %s $(INSTALL_PROGRAM_FLAGS) %s $(DESTDIR)%s\n",
2100 install_sh
, obj_dir_path( make
, file
), dest
+ 1 );
2102 case 's': /* script */
2103 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s $(DESTDIR)%s\n",
2104 install_sh
, obj_dir_path( make
, file
), dest
+ 1 );
2106 case 'S': /* script in source dir */
2107 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s $(DESTDIR)%s\n",
2108 install_sh
, src_dir_path( make
, file
), dest
+ 1 );
2110 case 'y': /* symlink */
2111 output( "\trm -f $(DESTDIR)%s && $(LN_S) %s $(DESTDIR)%s\n", dest
+ 1, file
, dest
+ 1 );
2118 for (i
= 0; i
< files
.count
; i
+= 2)
2119 strarray_add( &uninstall
, strmake( "$(DESTDIR)%s", files
.str
[i
+ 1] + 1 ));
2121 strarray_add_uniq( phony_targets
, "install" );
2122 strarray_add_uniq( phony_targets
, target
);
2127 /*******************************************************************
2130 static struct strarray
output_sources( const struct makefile
*make
)
2132 struct incl_file
*source
;
2134 struct strarray object_files
= empty_strarray
;
2135 struct strarray crossobj_files
= empty_strarray
;
2136 struct strarray res_files
= empty_strarray
;
2137 struct strarray clean_files
= empty_strarray
;
2138 struct strarray uninstall_files
= empty_strarray
;
2139 struct strarray po_files
= empty_strarray
;
2140 struct strarray mo_files
= empty_strarray
;
2141 struct strarray mc_files
= empty_strarray
;
2142 struct strarray ok_files
= empty_strarray
;
2143 struct strarray in_files
= empty_strarray
;
2144 struct strarray dlldata_files
= empty_strarray
;
2145 struct strarray c2man_files
= empty_strarray
;
2146 struct strarray implib_objs
= empty_strarray
;
2147 struct strarray includes
= empty_strarray
;
2148 struct strarray subdirs
= empty_strarray
;
2149 struct strarray phony_targets
= empty_strarray
;
2150 struct strarray all_targets
= empty_strarray
;
2151 struct strarray install_rules
[NB_INSTALL_RULES
];
2152 char *ldrpath_local
= get_expanded_make_variable( make
, "LDRPATH_LOCAL" );
2153 char *ldrpath_install
= get_expanded_make_variable( make
, "LDRPATH_INSTALL" );
2155 for (i
= 0; i
< NB_INSTALL_RULES
; i
++) install_rules
[i
] = empty_strarray
;
2157 for (i
= 0; i
< linguas
.count
; i
++)
2158 strarray_add( &mo_files
, strmake( "%s/%s.mo", top_obj_dir_path( make
, "po" ), linguas
.str
[i
] ));
2160 strarray_add( &phony_targets
, "all" );
2161 strarray_add( &includes
, strmake( "-I%s", obj_dir_path( make
, "" )));
2162 if (make
->src_dir
) strarray_add( &includes
, strmake( "-I%s", make
->src_dir
));
2163 if (make
->parent_dir
) strarray_add( &includes
, strmake( "-I%s", src_dir_path( make
, make
->parent_dir
)));
2164 strarray_add( &includes
, strmake( "-I%s", top_obj_dir_path( make
, "include" )));
2165 if (make
->top_src_dir
) strarray_add( &includes
, strmake( "-I%s", top_dir_path( make
, "include" )));
2166 if (make
->use_msvcrt
) strarray_add( &includes
, strmake( "-I%s", top_dir_path( make
, "include/msvcrt" )));
2167 for (i
= 0; i
< make
->include_paths
.count
; i
++)
2168 strarray_add( &includes
, strmake( "-I%s", obj_dir_path( make
, make
->include_paths
.str
[i
] )));
2170 LIST_FOR_EACH_ENTRY( source
, &make
->sources
, struct incl_file
, entry
)
2172 struct strarray dependencies
= empty_strarray
;
2173 struct strarray extradefs
;
2174 char *obj
= xstrdup( source
->name
);
2175 char *ext
= get_extension( obj
);
2177 if (!ext
) fatal_error( "unsupported file type %s\n", source
->name
);
2180 if (make
->src_dir
&& strchr( obj
, '/' ))
2182 char *subdir
= base_dir_path( make
, obj
);
2183 *strrchr( subdir
, '/' ) = 0;
2184 strarray_add_uniq( &subdirs
, subdir
);
2187 extradefs
= get_expanded_make_var_array( make
, file_local_var( obj
, "EXTRADEFS" ));
2188 get_dependencies( &dependencies
, source
, source
);
2190 if (!strcmp( ext
, "y" )) /* yacc file */
2192 /* add source file dependency for parallel makes */
2193 char *header
= strmake( "%s.tab.h", obj
);
2195 if (find_include_file( make
, header
))
2197 output( "%s: %s\n", obj_dir_path( make
, header
), source
->filename
);
2198 output( "\t$(BISON) -p %s_ -o %s.tab.c -d %s\n",
2199 obj
, obj_dir_path( make
, obj
), source
->filename
);
2200 output( "%s.tab.c: %s %s\n", obj_dir_path( make
, obj
),
2201 source
->filename
, obj_dir_path( make
, header
));
2202 strarray_add( &clean_files
, header
);
2204 else output( "%s.tab.c: %s\n", obj
, source
->filename
);
2206 output( "\t$(BISON) -p %s_ -o $@ %s\n", obj
, source
->filename
);
2208 else if (!strcmp( ext
, "x" )) /* template file */
2210 output( "%s.h: %s%s %s\n", obj_dir_path( make
, obj
),
2211 tools_dir_path( make
, "make_xftmpl" ), tools_ext
, source
->filename
);
2212 output( "\t%s%s -H -o $@ %s\n",
2213 tools_dir_path( make
, "make_xftmpl" ), tools_ext
, source
->filename
);
2214 if (source
->file
->flags
& FLAG_INSTALL
)
2216 strarray_add( &install_rules
[INSTALL_DEV
], source
->name
);
2217 strarray_add( &install_rules
[INSTALL_DEV
],
2218 strmake( "D$(includedir)/%s", get_include_install_path( source
->name
) ));
2219 strarray_add( &install_rules
[INSTALL_DEV
], strmake( "%s.h", obj
));
2220 strarray_add( &install_rules
[INSTALL_DEV
],
2221 strmake( "d$(includedir)/%s.h", get_include_install_path( obj
) ));
2224 else if (!strcmp( ext
, "l" )) /* lex file */
2226 output( "%s.yy.c: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2227 output( "\t$(FLEX) -o$@ %s\n", source
->filename
);
2229 else if (!strcmp( ext
, "rc" )) /* resource file */
2231 strarray_add( &res_files
, strmake( "%s.res", obj
));
2232 output( "%s.res: %s %s\n", obj_dir_path( make
, obj
),
2233 tools_path( make
, "wrc" ), source
->filename
);
2234 output( "\t%s -o $@", tools_path( make
, "wrc" ) );
2235 if (make
->is_win16
) output_filename( "-m16" );
2236 else output_filenames( target_flags
);
2237 output_filename( "--nostdinc" );
2238 output_filenames( includes
);
2239 output_filenames( make
->define_args
);
2240 output_filenames( extradefs
);
2241 if (mo_files
.count
&& (source
->file
->flags
& FLAG_RC_PO
))
2243 strarray_add( &po_files
, source
->filename
);
2244 output_filename( strmake( "--po-dir=%s", top_obj_dir_path( make
, "po" )));
2245 output_filename( source
->filename
);
2247 output( "%s.res:", obj_dir_path( make
, obj
));
2248 output_filenames( mo_files
);
2250 output( "%s ", obj_dir_path( make
, "rsrc.pot" ));
2254 output_filename( source
->filename
);
2257 output( "%s.res:", obj_dir_path( make
, obj
));
2258 output_filenames( dependencies
);
2261 else if (!strcmp( ext
, "mc" )) /* message file */
2263 strarray_add( &res_files
, strmake( "%s.res", obj
));
2264 output( "%s.res: %s %s\n", obj_dir_path( make
, obj
),
2265 tools_path( make
, "wmc" ), source
->filename
);
2266 output( "\t%s -U -O res -o $@ %s", tools_path( make
, "wmc" ), source
->filename
);
2269 strarray_add( &mc_files
, source
->filename
);
2270 output_filename( strmake( "--po-dir=%s", top_obj_dir_path( make
, "po" )));
2272 output( "%s.res:", obj_dir_path( make
, obj
));
2273 output_filenames( mo_files
);
2275 output( "%s ", obj_dir_path( make
, "msg.pot" ));
2277 else output( "\n" );
2278 output( "%s.res:", obj_dir_path( make
, obj
));
2279 output_filenames( dependencies
);
2282 else if (!strcmp( ext
, "idl" )) /* IDL file */
2284 struct strarray targets
= empty_strarray
;
2287 if (!source
->file
->flags
) source
->file
->flags
|= FLAG_IDL_HEADER
| FLAG_INSTALL
;
2288 if (find_include_file( make
, strmake( "%s.h", obj
))) source
->file
->flags
|= FLAG_IDL_HEADER
;
2290 for (i
= 0; i
< sizeof(idl_outputs
) / sizeof(idl_outputs
[0]); i
++)
2292 if (!(source
->file
->flags
& idl_outputs
[i
].flag
)) continue;
2293 dest
= strmake( "%s%s", obj
, idl_outputs
[i
].ext
);
2294 if (!find_src_file( make
, dest
)) strarray_add( &clean_files
, dest
);
2295 strarray_add( &targets
, dest
);
2297 if (source
->file
->flags
& FLAG_IDL_PROXY
) strarray_add( &dlldata_files
, source
->name
);
2298 if (source
->file
->flags
& FLAG_INSTALL
)
2300 strarray_add( &install_rules
[INSTALL_DEV
], xstrdup( source
->name
));
2301 strarray_add( &install_rules
[INSTALL_DEV
],
2302 strmake( "D$(includedir)/%s.idl", get_include_install_path( obj
) ));
2303 if (source
->file
->flags
& FLAG_IDL_HEADER
)
2305 strarray_add( &install_rules
[INSTALL_DEV
], strmake( "%s.h", obj
));
2306 strarray_add( &install_rules
[INSTALL_DEV
],
2307 strmake( "d$(includedir)/%s.h", get_include_install_path( obj
) ));
2310 if (!targets
.count
) continue;
2311 output_filenames_obj_dir( make
, targets
);
2312 output( ": %s\n", tools_path( make
, "widl" ));
2313 output( "\t%s -o $@", tools_path( make
, "widl" ) );
2314 output_filenames( target_flags
);
2315 output_filenames( includes
);
2316 output_filenames( make
->define_args
);
2317 output_filenames( extradefs
);
2318 output_filenames( get_expanded_make_var_array( make
, "EXTRAIDLFLAGS" ));
2319 output_filename( source
->filename
);
2321 output_filenames_obj_dir( make
, targets
);
2322 output( ": %s", source
->filename
);
2323 output_filenames( dependencies
);
2326 else if (!strcmp( ext
, "in" )) /* .in file or man page */
2328 if (strendswith( obj
, ".man" ) && source
->file
->args
)
2330 struct strarray symlinks
;
2331 char *dir
, *dest
= replace_extension( obj
, ".man", "" );
2332 char *lang
= strchr( dest
, '.' );
2333 char *section
= source
->file
->args
;
2337 dir
= strmake( "$(mandir)/%s/man%s", lang
, section
);
2339 else dir
= strmake( "$(mandir)/man%s", section
);
2340 add_install_rule( make
, install_rules
, dest
, xstrdup(obj
),
2341 strmake( "d%s/%s.%s", dir
, dest
, section
));
2342 symlinks
= get_expanded_make_var_array( make
, file_local_var( dest
, "SYMLINKS" ));
2343 for (i
= 0; i
< symlinks
.count
; i
++)
2344 add_install_rule( make
, install_rules
, symlinks
.str
[i
],
2345 strmake( "%s.%s", dest
, section
),
2346 strmake( "y%s/%s.%s", dir
, symlinks
.str
[i
], section
));
2350 strarray_add( &in_files
, xstrdup(obj
) );
2351 strarray_add( &all_targets
, xstrdup(obj
) );
2352 output( "%s: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2353 output( "\t$(SED_CMD) %s >$@ || (rm -f $@ && false)\n", source
->filename
);
2354 output( "%s:", obj_dir_path( make
, obj
));
2355 output_filenames( dependencies
);
2357 add_install_rule( make
, install_rules
, obj
, xstrdup( obj
),
2358 strmake( "d$(datadir)/wine/%s", obj
));
2360 else if (!strcmp( ext
, "sfd" )) /* font file */
2362 char *ttf_file
= src_dir_path( make
, strmake( "%s.ttf", obj
));
2363 if (fontforge
&& !make
->src_dir
)
2365 output( "%s: %s\n", ttf_file
, source
->filename
);
2366 output( "\t%s -script %s %s $@\n",
2367 fontforge
, top_dir_path( make
, "fonts/genttf.ff" ), source
->filename
);
2368 if (!(source
->file
->flags
& FLAG_SFD_FONTS
)) output( "all: %s\n", ttf_file
);
2370 if (source
->file
->flags
& FLAG_INSTALL
)
2372 strarray_add( &install_rules
[INSTALL_LIB
], strmake( "%s.ttf", obj
));
2373 strarray_add( &install_rules
[INSTALL_LIB
], strmake( "D$(fontdir)/%s.ttf", obj
));
2375 if (source
->file
->flags
& FLAG_SFD_FONTS
)
2377 struct strarray
*array
= source
->file
->args
;
2379 for (i
= 0; i
< array
->count
; i
++)
2381 char *font
= strtok( xstrdup(array
->str
[i
]), " \t" );
2382 char *args
= strtok( NULL
, "" );
2384 strarray_add( &all_targets
, xstrdup( font
));
2385 output( "%s: %s %s\n", obj_dir_path( make
, font
),
2386 tools_path( make
, "sfnt2fon" ), ttf_file
);
2387 output( "\t%s -o $@ %s %s\n", tools_path( make
, "sfnt2fon" ), ttf_file
, args
);
2388 strarray_add( &install_rules
[INSTALL_LIB
], xstrdup(font
) );
2389 strarray_add( &install_rules
[INSTALL_LIB
], strmake( "d$(fontdir)/%s", font
));
2393 else if (!strcmp( ext
, "svg" )) /* svg file */
2395 if (convert
&& rsvg
&& icotool
&& !make
->src_dir
)
2397 output( "%s.ico %s.bmp: %s\n",
2398 src_dir_path( make
, obj
), src_dir_path( make
, obj
), source
->filename
);
2399 output( "\tCONVERT=\"%s\" ICOTOOL=\"%s\" RSVG=\"%s\" %s %s $@\n", convert
, icotool
, rsvg
,
2400 top_dir_path( make
, "tools/buildimage" ), source
->filename
);
2403 else if (!strcmp( ext
, "res" ))
2405 strarray_add( &res_files
, source
->name
);
2407 else if (!strcmp( ext
, "tlb" ))
2409 strarray_add( &all_targets
, source
->name
);
2411 else if (!strcmp( ext
, "h" ) || !strcmp( ext
, "rh" ) || !strcmp( ext
, "inl" )) /* header file */
2413 if (source
->file
->flags
& FLAG_GENERATED
)
2415 strarray_add( &all_targets
, source
->name
);
2419 strarray_add( &install_rules
[INSTALL_DEV
], source
->name
);
2420 strarray_add( &install_rules
[INSTALL_DEV
],
2421 strmake( "D$(includedir)/%s", get_include_install_path( source
->name
) ));
2426 int need_cross
= make
->testdll
||
2427 (source
->file
->flags
& FLAG_C_IMPLIB
) ||
2428 (make
->module
&& make
->staticlib
);
2430 if ((source
->file
->flags
& FLAG_GENERATED
) &&
2431 (!make
->testdll
|| !strendswith( source
->filename
, "testlist.c" )))
2432 strarray_add( &clean_files
, source
->filename
);
2433 if (source
->file
->flags
& FLAG_C_IMPLIB
) strarray_add( &implib_objs
, strmake( "%s.o", obj
));
2434 strarray_add( &object_files
, strmake( "%s.o", obj
));
2435 output( "%s.o: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2436 output( "\t$(CC) -c -o $@ %s", source
->filename
);
2437 output_filenames( includes
);
2438 output_filenames( make
->define_args
);
2439 output_filenames( extradefs
);
2440 if (make
->module
|| make
->staticlib
|| make
->sharedlib
|| make
->testdll
)
2442 output_filenames( dll_flags
);
2443 if (make
->use_msvcrt
) output_filenames( msvcrt_flags
);
2445 output_filenames( extra_cflags
);
2446 output_filenames( cpp_flags
);
2447 output_filename( "$(CFLAGS)" );
2449 if (crosstarget
&& need_cross
)
2451 strarray_add( &crossobj_files
, strmake( "%s.cross.o", obj
));
2452 output( "%s.cross.o: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2453 output( "\t$(CROSSCC) -c -o $@ %s", source
->filename
);
2454 output_filenames( includes
);
2455 output_filenames( make
->define_args
);
2456 output_filenames( extradefs
);
2457 output_filename( "-DWINE_CROSSTEST" );
2458 output_filenames( cpp_flags
);
2459 output_filename( "$(CFLAGS)" );
2462 if (make
->testdll
&& !strcmp( ext
, "c" ) && !(source
->file
->flags
& FLAG_GENERATED
))
2464 strarray_add( &ok_files
, strmake( "%s.ok", obj
));
2465 output( "%s.ok:\n", obj_dir_path( make
, obj
));
2466 output( "\t%s $(RUNTESTFLAGS) -T %s -M %s -p %s%s %s && touch $@\n",
2467 top_dir_path( make
, "tools/runtest" ), top_obj_dir_path( make
, "" ), make
->testdll
,
2468 replace_extension( make
->testdll
, ".dll", "_test.exe" ), dll_ext
, obj
);
2470 if (!strcmp( ext
, "c" ) && !(source
->file
->flags
& FLAG_GENERATED
))
2471 strarray_add( &c2man_files
, source
->filename
);
2472 output( "%s.o", obj_dir_path( make
, obj
));
2473 if (crosstarget
&& need_cross
) output( " %s.cross.o", obj_dir_path( make
, obj
));
2475 output_filenames( dependencies
);
2481 /* rules for files that depend on multiple sources */
2485 output( "%s: %s", obj_dir_path( make
, "rsrc.pot" ), tools_path( make
, "wrc" ) );
2486 output_filenames( po_files
);
2488 output( "\t%s -O pot -o $@", tools_path( make
, "wrc" ));
2489 if (make
->is_win16
) output_filename( "-m16" );
2490 else output_filenames( target_flags
);
2491 output_filename( "--nostdinc" );
2492 output_filenames( includes
);
2493 output_filenames( make
->define_args
);
2494 output_filenames( po_files
);
2496 strarray_add( &clean_files
, "rsrc.pot" );
2501 output( "%s: %s", obj_dir_path( make
, "msg.pot" ), tools_path( make
, "wmc" ));
2502 output_filenames( mc_files
);
2504 output( "\t%s -O pot -o $@", tools_path( make
, "wmc" ));
2505 output_filenames( mc_files
);
2507 strarray_add( &clean_files
, "msg.pot" );
2510 if (dlldata_files
.count
)
2512 output( "%s: %s %s\n", obj_dir_path( make
, "dlldata.c" ),
2513 tools_path( make
, "widl" ), src_dir_path( make
, "Makefile.in" ));
2514 output( "\t%s --dlldata-only -o $@", tools_path( make
, "widl" ));
2515 output_filenames( dlldata_files
);
2519 if (make
->module
&& !make
->staticlib
)
2521 struct strarray all_libs
= empty_strarray
;
2522 struct strarray dep_libs
= empty_strarray
;
2523 char *module_path
= obj_dir_path( make
, make
->module
);
2524 char *spec_file
= NULL
;
2526 if (!make
->appmode
.count
)
2527 spec_file
= src_dir_path( make
, replace_extension( make
->module
, ".dll", ".spec" ));
2528 strarray_addall( &all_libs
, add_import_libs( make
, &dep_libs
, make
->delayimports
, 0 ));
2529 strarray_addall( &all_libs
, add_import_libs( make
, &dep_libs
, make
->imports
, 0 ));
2530 for (i
= 0; i
< make
->delayimports
.count
; i
++)
2531 strarray_add( &all_libs
, strmake( "-Wb,-d%s", make
->delayimports
.str
[i
] ));
2532 strarray_add( &all_libs
, "-lwine" );
2533 strarray_addall( &all_libs
, add_default_libraries( make
, &dep_libs
));
2537 strarray_add( &all_targets
, strmake( "%s%s", make
->module
, dll_ext
));
2538 strarray_add( &all_targets
, strmake( "%s.fake", make
->module
));
2539 add_install_rule( make
, install_rules
, make
->module
, strmake( "%s%s", make
->module
, dll_ext
),
2540 strmake( "p$(dlldir)/%s%s", make
->module
, dll_ext
));
2541 add_install_rule( make
, install_rules
, make
->module
, strmake( "%s.fake", make
->module
),
2542 strmake( "d$(fakedlldir)/%s", make
->module
));
2543 output( "%s%s %s.fake:", module_path
, dll_ext
, module_path
);
2547 strarray_add( &all_targets
, make
->module
);
2548 add_install_rule( make
, install_rules
, make
->module
, make
->module
,
2549 strmake( "p$(%s)/%s", spec_file
? "dlldir" : "bindir", make
->module
));
2550 output( "%s:", module_path
);
2552 if (spec_file
) output_filename( spec_file
);
2553 output_filenames_obj_dir( make
, object_files
);
2554 output_filenames_obj_dir( make
, res_files
);
2555 output_filenames( dep_libs
);
2557 output( "\t%s -o $@", tools_path( make
, "winegcc" ));
2558 output_filename( strmake( "-B%s", tools_dir_path( make
, "winebuild" )));
2559 if (tools_dir
) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make
, "" )));
2560 output_filenames( target_flags
);
2561 output_filenames( unwind_flags
);
2564 output( " -shared %s", spec_file
);
2565 output_filenames( make
->extradllflags
);
2567 else output_filenames( make
->appmode
);
2568 output_filenames_obj_dir( make
, object_files
);
2569 output_filenames_obj_dir( make
, res_files
);
2570 output_filenames( all_libs
);
2571 output_filename( "$(LDFLAGS)" );
2574 if (spec_file
&& make
->importlib
)
2576 char *importlib_path
= obj_dir_path( make
, strmake( "lib%s", make
->importlib
));
2579 strarray_add( &clean_files
, strmake( "lib%s.def", make
->importlib
));
2580 output( "%s.def: %s %s\n", importlib_path
, tools_path( make
, "winebuild" ), spec_file
);
2581 output( "\t%s -w --def -o $@ --export %s", tools_path( make
, "winebuild" ), spec_file
);
2582 output_filenames( target_flags
);
2583 if (make
->is_win16
) output_filename( "-m16" );
2585 add_install_rule( make
, install_rules
, make
->importlib
,
2586 strmake( "lib%s.def", make
->importlib
),
2587 strmake( "d$(dlldir)/lib%s.def", make
->importlib
));
2588 if (implib_objs
.count
)
2590 strarray_add( &clean_files
, strmake( "lib%s.def.a", make
->importlib
));
2591 output( "%s.def.a:", importlib_path
);
2592 output_filenames_obj_dir( make
, implib_objs
);
2594 output( "\trm -f $@\n" );
2595 output( "\t$(AR) $(ARFLAGS) $@" );
2596 output_filenames_obj_dir( make
, implib_objs
);
2598 output( "\t$(RANLIB) $@\n" );
2599 add_install_rule( make
, install_rules
, make
->importlib
,
2600 strmake( "lib%s.def.a", make
->importlib
),
2601 strmake( "d$(dlldir)/lib%s.def.a", make
->importlib
));
2606 strarray_add( &clean_files
, strmake( "lib%s.a", make
->importlib
));
2607 output( "%s.a: %s %s", importlib_path
, tools_path( make
, "winebuild" ), spec_file
);
2608 output_filenames_obj_dir( make
, implib_objs
);
2610 output( "\t%s -w --implib -o $@ --export %s", tools_path( make
, "winebuild" ), spec_file
);
2611 output_filenames( target_flags
);
2612 output_filenames_obj_dir( make
, implib_objs
);
2614 add_install_rule( make
, install_rules
, make
->importlib
,
2615 strmake( "lib%s.a", make
->importlib
),
2616 strmake( "d$(dlldir)/lib%s.a", make
->importlib
));
2618 if (crosstarget
&& !make
->is_win16
)
2620 struct strarray cross_files
= strarray_replace_extension( &implib_objs
, ".o", ".cross.o" );
2621 strarray_add( &clean_files
, strmake( "lib%s.cross.a", make
->importlib
));
2622 output( "%s.cross.a: %s %s", importlib_path
, tools_path( make
, "winebuild" ), spec_file
);
2623 output_filenames_obj_dir( make
, cross_files
);
2625 output( "\t%s -b %s -w --implib -o $@ --export %s",
2626 tools_path( make
, "winebuild" ), crosstarget
, spec_file
);
2627 output_filenames_obj_dir( make
, cross_files
);
2634 if (c2man_files
.count
)
2636 output( "manpages::\n" );
2637 output( "\t%s -w %s", top_dir_path( make
, "tools/c2man.pl" ), spec_file
);
2638 output_filename( strmake( "-R%s", top_dir_path( make
, "" )));
2639 output_filename( strmake( "-I%s", top_dir_path( make
, "include" )));
2640 output_filename( strmake( "-o %s/man%s",
2641 top_obj_dir_path( make
, "documentation" ), man_ext
));
2642 output_filenames( c2man_files
);
2644 output( "htmlpages::\n" );
2645 output( "\t%s -Th -w %s", top_dir_path( make
, "tools/c2man.pl" ), spec_file
);
2646 output_filename( strmake( "-R%s", top_dir_path( make
, "" )));
2647 output_filename( strmake( "-I%s", top_dir_path( make
, "include" )));
2648 output_filename( strmake( "-o %s",
2649 top_obj_dir_path( make
, "documentation/html" )));
2650 output_filenames( c2man_files
);
2652 output( "sgmlpages::\n" );
2653 output( "\t%s -Ts -w %s", top_dir_path( make
, "tools/c2man.pl" ), spec_file
);
2654 output_filename( strmake( "-R%s", top_dir_path( make
, "" )));
2655 output_filename( strmake( "-I%s", top_dir_path( make
, "include" )));
2656 output_filename( strmake( "-o %s",
2657 top_obj_dir_path( make
, "documentation/api-guide" )));
2658 output_filenames( c2man_files
);
2660 output( "xmlpages::\n" );
2661 output( "\t%s -Tx -w %s", top_dir_path( make
, "tools/c2man.pl" ), spec_file
);
2662 output_filename( strmake( "-R%s", top_dir_path( make
, "" )));
2663 output_filename( strmake( "-I%s", top_dir_path( make
, "include" )));
2664 output_filename( strmake( "-o %s",
2665 top_obj_dir_path( make
, "documentation/api-guide-xml" )));
2666 output_filenames( c2man_files
);
2668 strarray_add( &phony_targets
, "manpages" );
2669 strarray_add( &phony_targets
, "htmlpages" );
2670 strarray_add( &phony_targets
, "sgmlpages" );
2671 strarray_add( &phony_targets
, "xmlpages" );
2673 else output( "manpages htmlpages sgmlpages xmlpages::\n" );
2677 char *binary
= replace_extension( make
->module
, ".exe", "" );
2678 add_install_rule( make
, install_rules
, binary
, tools_dir_path( make
, "wineapploader" ),
2679 strmake( "s$(bindir)/%s", binary
));
2683 if (make
->staticlib
)
2685 strarray_add( &all_targets
, make
->staticlib
);
2686 output( "%s:", obj_dir_path( make
, make
->staticlib
));
2687 output_filenames_obj_dir( make
, object_files
);
2688 output( "\n\trm -f $@\n" );
2689 output( "\t$(AR) $(ARFLAGS) $@" );
2690 output_filenames_obj_dir( make
, object_files
);
2691 output( "\n\t$(RANLIB) $@\n" );
2692 if (crosstarget
&& make
->module
)
2694 char *name
= replace_extension( make
->staticlib
, ".a", ".cross.a" );
2696 strarray_add( &all_targets
, name
);
2697 output( "%s:", obj_dir_path( make
, name
));
2698 output_filenames_obj_dir( make
, crossobj_files
);
2699 output( "\n\trm -f $@\n" );
2700 output( "\t%s-ar $(ARFLAGS) $@", crosstarget
);
2701 output_filenames_obj_dir( make
, crossobj_files
);
2702 output( "\n\t%s-ranlib $@\n", crosstarget
);
2706 if (make
->sharedlib
)
2709 struct strarray names
= get_shared_lib_names( make
->sharedlib
);
2710 struct strarray all_libs
= empty_strarray
;
2711 struct strarray dep_libs
= empty_strarray
;
2713 basename
= xstrdup( make
->sharedlib
);
2714 if ((p
= strchr( basename
, '.' ))) *p
= 0;
2716 strarray_addall( &dep_libs
, get_local_dependencies( make
, basename
, in_files
));
2717 strarray_addall( &all_libs
, get_expanded_make_var_array( make
,
2718 file_local_var( basename
, "LDFLAGS" )));
2719 strarray_addall( &all_libs
, add_default_libraries( make
, &dep_libs
));
2721 output( "%s:", obj_dir_path( make
, make
->sharedlib
));
2722 output_filenames_obj_dir( make
, object_files
);
2723 output_filenames( dep_libs
);
2725 output( "\t$(CC) -o $@" );
2726 output_filenames_obj_dir( make
, object_files
);
2727 output_filenames( all_libs
);
2728 output_filename( "$(LDFLAGS)" );
2730 add_install_rule( make
, install_rules
, make
->sharedlib
, make
->sharedlib
,
2731 strmake( "p$(libdir)/%s", make
->sharedlib
));
2732 for (i
= 1; i
< names
.count
; i
++)
2734 output( "%s: %s\n", obj_dir_path( make
, names
.str
[i
] ), obj_dir_path( make
, names
.str
[i
-1] ));
2735 output( "\trm -f $@ && $(LN_S) %s $@\n", names
.str
[i
-1] );
2736 add_install_rule( make
, install_rules
, names
.str
[i
], names
.str
[i
-1],
2737 strmake( "y$(libdir)/%s", names
.str
[i
] ));
2739 strarray_addall( &all_targets
, names
);
2742 if (make
->importlib
&& !make
->module
) /* stand-alone import lib (for libwine) */
2744 char *def_file
= replace_extension( make
->importlib
, ".a", ".def" );
2746 if (!strncmp( def_file
, "lib", 3 )) def_file
+= 3;
2747 output( "%s: %s\n", obj_dir_path( make
, make
->importlib
), src_dir_path( make
, def_file
));
2748 output( "\t%s -l $@ -d %s\n", dlltool
, src_dir_path( make
, def_file
));
2749 add_install_rule( make
, install_rules
, make
->importlib
, make
->importlib
,
2750 strmake( "d$(libdir)/%s", make
->importlib
));
2751 strarray_add( &all_targets
, make
->importlib
);
2756 char *testmodule
= replace_extension( make
->testdll
, ".dll", "_test.exe" );
2757 char *stripped
= replace_extension( make
->testdll
, ".dll", "_test-stripped.exe" );
2758 char *testres
= replace_extension( make
->testdll
, ".dll", "_test.res" );
2759 struct strarray dep_libs
= empty_strarray
;
2760 struct strarray all_libs
= add_import_libs( make
, &dep_libs
, make
->imports
, 0 );
2762 strarray_addall( &all_libs
, libs
);
2763 strarray_add( &all_targets
, strmake( "%s%s", testmodule
, dll_ext
));
2764 strarray_add( &clean_files
, strmake( "%s%s", stripped
, dll_ext
));
2765 output( "%s%s:\n", obj_dir_path( make
, testmodule
), dll_ext
);
2766 output( "\t%s -o $@", tools_path( make
, "winegcc" ));
2767 output_filename( strmake( "-B%s", tools_dir_path( make
, "winebuild" )));
2768 if (tools_dir
) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make
, "" )));
2769 output_filenames( target_flags
);
2770 output_filenames( unwind_flags
);
2771 output_filenames( make
->appmode
);
2772 output_filenames_obj_dir( make
, object_files
);
2773 output_filenames_obj_dir( make
, res_files
);
2774 output_filenames( all_libs
);
2775 output_filename( "$(LDFLAGS)" );
2777 output( "%s%s:\n", obj_dir_path( make
, stripped
), dll_ext
);
2778 output( "\t%s -o $@", tools_path( make
, "winegcc" ));
2779 output_filename( strmake( "-B%s", tools_dir_path( make
, "winebuild" )));
2780 if (tools_dir
) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make
, "" )));
2781 output_filenames( target_flags
);
2782 output_filenames( unwind_flags
);
2783 output_filename( strmake( "-Wb,-F,%s", testmodule
));
2784 output_filenames( make
->appmode
);
2785 output_filenames_obj_dir( make
, object_files
);
2786 output_filenames_obj_dir( make
, res_files
);
2787 output_filenames( all_libs
);
2788 output_filename( "$(LDFLAGS)" );
2790 output( "%s%s %s%s:", obj_dir_path( make
, testmodule
), dll_ext
,
2791 obj_dir_path( make
, stripped
), dll_ext
);
2792 output_filenames_obj_dir( make
, object_files
);
2793 output_filenames_obj_dir( make
, res_files
);
2794 output_filenames( dep_libs
);
2797 output( "all: %s/%s\n", top_obj_dir_path( make
, "programs/winetest" ), testres
);
2798 output( "%s/%s: %s%s\n", top_obj_dir_path( make
, "programs/winetest" ), testres
,
2799 obj_dir_path( make
, stripped
), dll_ext
);
2800 output( "\techo \"%s TESTRES \\\"%s%s\\\"\" | %s -o $@\n",
2801 testmodule
, obj_dir_path( make
, stripped
), dll_ext
, tools_path( make
, "wrc" ));
2805 char *crosstest
= replace_extension( make
->testdll
, ".dll", "_crosstest.exe" );
2807 dep_libs
= empty_strarray
;
2808 all_libs
= add_import_libs( make
, &dep_libs
, make
->imports
, 1 );
2809 strarray_addall( &all_libs
, libs
);
2810 strarray_add( &clean_files
, crosstest
);
2811 output( "%s: %s\n", obj_dir_path( make
, "crosstest" ), obj_dir_path( make
, crosstest
));
2812 output( "%s:", obj_dir_path( make
, crosstest
));
2813 output_filenames_obj_dir( make
, crossobj_files
);
2814 output_filenames_obj_dir( make
, res_files
);
2815 output_filenames( dep_libs
);
2817 output( "\t%s -o $@ -b %s", tools_path( make
, "winegcc" ), crosstarget
);
2818 output_filename( strmake( "-B%s", tools_dir_path( make
, "winebuild" )));
2819 if (tools_dir
) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make
, "" )));
2820 output_filename( "--lib-suffix=.cross.a" );
2821 output_filenames_obj_dir( make
, crossobj_files
);
2822 output_filenames_obj_dir( make
, res_files
);
2823 output_filenames( all_libs
);
2824 output_filename( "$(LDFLAGS)" );
2826 strarray_add( &phony_targets
, obj_dir_path( make
, "crosstest" ));
2827 if (make
->obj_dir
) output( "crosstest: %s\n", obj_dir_path( make
, "crosstest" ));
2830 output_filenames_obj_dir( make
, ok_files
);
2831 output( ": %s%s ../%s%s\n", testmodule
, dll_ext
, make
->testdll
, dll_ext
);
2832 output( "check test:" );
2833 output_filenames_obj_dir( make
, ok_files
);
2835 output( "testclean::\n" );
2836 output( "\trm -f" );
2837 output_filenames_obj_dir( make
, ok_files
);
2839 strarray_addall( &clean_files
, ok_files
);
2840 strarray_add( &phony_targets
, "check" );
2841 strarray_add( &phony_targets
, "test" );
2842 strarray_add( &phony_targets
, "testclean" );
2845 for (i
= 0; i
< make
->programs
.count
; i
++)
2847 char *program_installed
= NULL
;
2848 char *program
= strmake( "%s%s", make
->programs
.str
[i
], exe_ext
);
2849 struct strarray deps
= get_local_dependencies( make
, make
->programs
.str
[i
], in_files
);
2850 struct strarray all_libs
= get_expanded_make_var_array( make
,
2851 file_local_var( make
->programs
.str
[i
], "LDFLAGS" ));
2852 struct strarray objs
= get_expanded_make_var_array( make
,
2853 file_local_var( make
->programs
.str
[i
], "OBJS" ));
2854 struct strarray symlinks
= get_expanded_make_var_array( make
,
2855 file_local_var( make
->programs
.str
[i
], "SYMLINKS" ));
2857 if (!objs
.count
) objs
= object_files
;
2858 strarray_addall( &all_libs
, add_default_libraries( make
, &deps
));
2860 output( "%s:", obj_dir_path( make
, program
) );
2861 output_filenames_obj_dir( make
, objs
);
2862 output_filenames( deps
);
2864 output( "\t$(CC) -o $@" );
2865 output_filenames_obj_dir( make
, objs
);
2867 if (strarray_exists( &all_libs
, "-lwine" ))
2869 strarray_add( &all_libs
, strmake( "-L%s", top_obj_dir_path( make
, "libs/wine" )));
2870 if (ldrpath_local
&& ldrpath_install
)
2872 program_installed
= strmake( "%s-installed%s", make
->programs
.str
[i
], exe_ext
);
2873 output_filename( ldrpath_local
);
2874 output_filenames( all_libs
);
2875 output_filename( "$(LDFLAGS)" );
2877 output( "%s:", obj_dir_path( make
, program_installed
) );
2878 output_filenames_obj_dir( make
, objs
);
2879 output_filenames( deps
);
2881 output( "\t$(CC) -o $@" );
2882 output_filenames_obj_dir( make
, objs
);
2883 output_filename( ldrpath_install
);
2884 strarray_add( &all_targets
, program_installed
);
2888 output_filenames( all_libs
);
2889 output_filename( "$(LDFLAGS)" );
2891 strarray_add( &all_targets
, program
);
2895 output_filenames_obj_dir( make
, symlinks
);
2896 output( ": %s\n", obj_dir_path( make
, program
));
2897 output( "\trm -f $@ && $(LN_S) %s $@\n", obj_dir_path( make
, program
));
2898 strarray_addall( &all_targets
, symlinks
);
2901 add_install_rule( make
, install_rules
, program
, program_installed
? program_installed
: program
,
2902 strmake( "p$(bindir)/%s", program
));
2903 for (j
= 0; j
< symlinks
.count
; j
++)
2904 add_install_rule( make
, install_rules
, symlinks
.str
[j
], program
,
2905 strmake( "y$(bindir)/%s%s", symlinks
.str
[j
], exe_ext
));
2908 for (i
= 0; i
< make
->scripts
.count
; i
++)
2909 add_install_rule( make
, install_rules
, make
->scripts
.str
[i
], make
->scripts
.str
[i
],
2910 strmake( "S$(bindir)/%s", make
->scripts
.str
[i
] ));
2912 if (all_targets
.count
)
2915 output_filenames_obj_dir( make
, all_targets
);
2919 strarray_addall( &uninstall_files
, output_install_rules( make
, install_rules
[INSTALL_LIB
],
2920 "install-lib", &phony_targets
));
2921 strarray_addall( &uninstall_files
, output_install_rules( make
, install_rules
[INSTALL_DEV
],
2922 "install-dev", &phony_targets
));
2923 if (uninstall_files
.count
)
2925 output( "uninstall::\n" );
2926 output( "\trm -f" );
2927 output_filenames( uninstall_files
);
2929 strarray_add_uniq( &phony_targets
, "uninstall" );
2932 strarray_addall( &clean_files
, object_files
);
2933 strarray_addall( &clean_files
, crossobj_files
);
2934 strarray_addall( &clean_files
, res_files
);
2935 strarray_addall( &clean_files
, all_targets
);
2936 strarray_addall( &clean_files
, get_expanded_make_var_array( make
, "EXTRA_TARGETS" ));
2938 if (clean_files
.count
)
2940 output( "%s::\n", obj_dir_path( make
, "clean" ));
2941 output( "\trm -f" );
2942 output_filenames_obj_dir( make
, clean_files
);
2944 if (make
->obj_dir
) output( "__clean__: %s\n", obj_dir_path( make
, "clean" ));
2945 strarray_add( &phony_targets
, obj_dir_path( make
, "clean" ));
2948 if (make
->subdirs
.count
)
2950 struct strarray makefile_deps
= empty_strarray
;
2951 struct strarray distclean_files
= empty_strarray
;
2953 for (i
= 0; i
< make
->subdirs
.count
; i
++)
2955 strarray_add( &makefile_deps
, top_dir_path( make
, base_dir_path( make
->submakes
[i
],
2956 strmake ( "%s.in", output_makefile_name
))));
2957 strarray_add( &distclean_files
, base_dir_path( make
->submakes
[i
], output_makefile_name
));
2959 strarray_add( &distclean_files
, base_dir_path( make
->submakes
[i
], ".gitignore" ));
2960 if (make
->submakes
[i
]->testdll
)
2961 strarray_add( &distclean_files
, base_dir_path( make
->submakes
[i
], "testlist.c" ));
2963 output( "Makefile:" );
2964 output_filenames( makefile_deps
);
2966 output( "distclean::\n");
2967 output( "\trm -f" );
2968 output_filenames( distclean_files
);
2970 strarray_add( &phony_targets
, "distclean" );
2973 if (phony_targets
.count
)
2975 output( ".PHONY:" );
2976 output_filenames( phony_targets
);
2980 for (i
= 0; i
< subdirs
.count
; i
++) create_dir( subdirs
.str
[i
] );
2986 /*******************************************************************
2989 static FILE *create_temp_file( const char *orig
)
2991 char *name
= xmalloc( strlen(orig
) + 13 );
2992 unsigned int i
, id
= getpid();
2996 for (i
= 0; i
< 100; i
++)
2998 sprintf( name
, "%s.tmp%08x", orig
, id
);
2999 if ((fd
= open( name
, O_RDWR
| O_CREAT
| O_EXCL
, 0666 )) != -1)
3001 ret
= fdopen( fd
, "w" );
3004 if (errno
!= EEXIST
) break;
3007 if (!ret
) fatal_error( "failed to create output file for '%s'\n", orig
);
3008 temp_file_name
= name
;
3013 /*******************************************************************
3016 static void rename_temp_file( const char *dest
)
3018 int ret
= rename( temp_file_name
, dest
);
3019 if (ret
== -1 && errno
== EEXIST
)
3021 /* rename doesn't overwrite on windows */
3023 ret
= rename( temp_file_name
, dest
);
3025 if (ret
== -1) fatal_error( "failed to rename output file to '%s'\n", dest
);
3026 temp_file_name
= NULL
;
3030 /*******************************************************************
3031 * are_files_identical
3033 static int are_files_identical( FILE *file1
, FILE *file2
)
3037 char buffer1
[8192], buffer2
[8192];
3038 int size1
= fread( buffer1
, 1, sizeof(buffer1
), file1
);
3039 int size2
= fread( buffer2
, 1, sizeof(buffer2
), file2
);
3040 if (size1
!= size2
) return 0;
3041 if (!size1
) return feof( file1
) && feof( file2
);
3042 if (memcmp( buffer1
, buffer2
, size1
)) return 0;
3047 /*******************************************************************
3048 * rename_temp_file_if_changed
3050 static void rename_temp_file_if_changed( const char *dest
)
3052 FILE *file1
, *file2
;
3055 if ((file1
= fopen( dest
, "r" )))
3057 if ((file2
= fopen( temp_file_name
, "r" )))
3059 do_rename
= !are_files_identical( file1
, file2
);
3066 unlink( temp_file_name
);
3067 temp_file_name
= NULL
;
3069 else rename_temp_file( dest
);
3073 /*******************************************************************
3076 static void output_testlist( const struct makefile
*make
)
3078 const char *dest
= base_dir_path( make
, "testlist.c" );
3079 struct strarray files
= empty_strarray
;
3080 struct incl_file
*source
;
3083 LIST_FOR_EACH_ENTRY( source
, &make
->sources
, struct incl_file
, entry
)
3085 if (source
->file
->flags
& FLAG_GENERATED
) continue;
3086 if (!strendswith( source
->name
, ".c" )) continue;
3087 strarray_add( &files
, replace_extension( source
->name
, ".c", "" ));
3090 output_file
= create_temp_file( dest
);
3092 output( "/* Automatically generated by make depend; DO NOT EDIT!! */\n\n" );
3093 output( "#define WIN32_LEAN_AND_MEAN\n" );
3094 output( "#include <windows.h>\n\n" );
3095 output( "#define STANDALONE\n" );
3096 output( "#include \"wine/test.h\"\n\n" );
3098 for (i
= 0; i
< files
.count
; i
++) output( "extern void func_%s(void);\n", files
.str
[i
] );
3100 output( "const struct test winetest_testlist[] =\n" );
3102 for (i
= 0; i
< files
.count
; i
++) output( " { \"%s\", func_%s },\n", files
.str
[i
], files
.str
[i
] );
3103 output( " { 0, 0 }\n" );
3106 if (fclose( output_file
)) fatal_perror( "write" );
3108 rename_temp_file_if_changed( dest
);
3112 /*******************************************************************
3115 static void output_gitignore( const char *dest
, struct strarray files
)
3119 output_file
= create_temp_file( dest
);
3121 output( "# Automatically generated by make depend; DO NOT EDIT!!\n" );
3122 for (i
= 0; i
< files
.count
; i
++)
3124 if (!strchr( files
.str
[i
], '/' )) output( "/" );
3125 output( "%s\n", files
.str
[i
] );
3128 if (fclose( output_file
)) fatal_perror( "write" );
3130 rename_temp_file( dest
);
3134 /*******************************************************************
3135 * output_top_variables
3137 static void output_top_variables( const struct makefile
*make
)
3140 struct strarray
*vars
= &top_makefile
->vars
;
3142 if (!make
->base_dir
) return; /* don't output variables in the top makefile */
3144 output( "# Automatically generated by make depend; DO NOT EDIT!!\n\n" );
3145 output( "all:\n\n" );
3146 for (i
= 0; i
< vars
->count
; i
+= 2)
3148 if (!strcmp( vars
->str
[i
], "SUBDIRS" )) continue; /* not inherited */
3149 output( "%s = %s\n", vars
->str
[i
], get_make_variable( make
, vars
->str
[i
] ));
3155 /*******************************************************************
3156 * output_dependencies
3158 static void output_dependencies( const struct makefile
*make
)
3160 static const char separator
[] = "### Dependencies";
3161 struct strarray targets
, ignore_files
= empty_strarray
;
3166 output_file_name
= base_dir_path( make
, output_makefile_name
);
3167 output_file
= create_temp_file( output_file_name
);
3168 output_top_variables( make
);
3170 /* copy the contents of the source makefile */
3171 src_file
= open_input_makefile( make
);
3172 while (fgets( buffer
, sizeof(buffer
), src_file
) && !found
)
3174 if (fwrite( buffer
, 1, strlen(buffer
), output_file
) != strlen(buffer
)) fatal_perror( "write" );
3175 found
= !strncmp( buffer
, separator
, strlen(separator
) );
3177 if (fclose( src_file
)) fatal_perror( "close" );
3178 input_file_name
= NULL
;
3180 if (!found
) output( "\n%s (everything below this line is auto-generated; DO NOT EDIT!!)\n", separator
);
3181 targets
= output_sources( make
);
3183 fclose( output_file
);
3185 rename_temp_file( output_file_name
);
3187 strarray_add( &ignore_files
, ".gitignore" );
3188 strarray_add( &ignore_files
, "Makefile" );
3191 output_testlist( make
);
3192 strarray_add( &ignore_files
, "testlist.c" );
3194 strarray_addall( &ignore_files
, targets
);
3195 if (!make
->src_dir
&& make
->base_dir
)
3196 output_gitignore( base_dir_path( make
, ".gitignore" ), ignore_files
);
3198 output_file_name
= NULL
;
3202 /*******************************************************************
3205 static void load_sources( struct makefile
*make
)
3207 static const char *source_vars
[] =
3226 struct strarray value
;
3227 struct incl_file
*file
;
3231 make
->top_src_dir
= concat_paths( make
->top_obj_dir
, root_src_dir
);
3232 make
->src_dir
= concat_paths( make
->top_src_dir
, make
->base_dir
);
3234 strarray_set_value( &make
->vars
, "top_builddir", top_obj_dir_path( make
, "" ));
3235 strarray_set_value( &make
->vars
, "top_srcdir", top_dir_path( make
, "" ));
3236 strarray_set_value( &make
->vars
, "srcdir", src_dir_path( make
, "" ));
3238 make
->parent_dir
= get_expanded_make_variable( make
, "PARENTSRC" );
3239 make
->module
= get_expanded_make_variable( make
, "MODULE" );
3240 make
->testdll
= get_expanded_make_variable( make
, "TESTDLL" );
3241 make
->sharedlib
= get_expanded_make_variable( make
, "SHAREDLIB" );
3242 make
->staticlib
= get_expanded_make_variable( make
, "STATICLIB" );
3243 make
->importlib
= get_expanded_make_variable( make
, "IMPORTLIB" );
3245 make
->programs
= get_expanded_make_var_array( make
, "PROGRAMS" );
3246 make
->scripts
= get_expanded_make_var_array( make
, "SCRIPTS" );
3247 make
->appmode
= get_expanded_make_var_array( make
, "APPMODE" );
3248 make
->imports
= get_expanded_make_var_array( make
, "IMPORTS" );
3249 make
->delayimports
= get_expanded_make_var_array( make
, "DELAYIMPORTS" );
3250 make
->extradllflags
= get_expanded_make_var_array( make
, "EXTRADLLFLAGS" );
3251 make
->install_lib
= get_expanded_make_var_array( make
, "INSTALL_LIB" );
3252 make
->install_dev
= get_expanded_make_var_array( make
, "INSTALL_DEV" );
3254 if (make
->module
&& strendswith( make
->module
, ".a" )) make
->staticlib
= make
->module
;
3256 make
->is_win16
= strarray_exists( &make
->extradllflags
, "-m16" );
3257 make
->use_msvcrt
= strarray_exists( &make
->appmode
, "-mno-cygwin" );
3259 for (i
= 0; i
< make
->imports
.count
&& !make
->use_msvcrt
; i
++)
3260 make
->use_msvcrt
= !strncmp( make
->imports
.str
[i
], "msvcr", 5 ) ||
3261 !strcmp( make
->imports
.str
[i
], "ucrtbase" );
3263 if (make
->module
&& !make
->install_lib
.count
) strarray_add( &make
->install_lib
, make
->module
);
3265 make
->include_paths
= empty_strarray
;
3266 make
->define_args
= empty_strarray
;
3267 strarray_add( &make
->define_args
, "-D__WINESRC__" );
3269 value
= get_expanded_make_var_array( make
, "EXTRAINCL" );
3270 for (i
= 0; i
< value
.count
; i
++)
3271 if (!strncmp( value
.str
[i
], "-I", 2 ))
3272 strarray_add_uniq( &make
->include_paths
, value
.str
[i
] + 2 );
3274 strarray_add_uniq( &make
->define_args
, value
.str
[i
] );
3275 strarray_addall( &make
->define_args
, get_expanded_make_var_array( make
, "EXTRADEFS" ));
3277 list_init( &make
->sources
);
3278 list_init( &make
->includes
);
3280 /* FIXME: target dir has to exist to allow locating srcdir-relative include files */
3281 if (make
->base_dir
) create_dir( make
->base_dir
);
3283 for (var
= source_vars
; *var
; var
++)
3285 value
= get_expanded_make_var_array( make
, *var
);
3286 for (i
= 0; i
< value
.count
; i
++) add_src_file( make
, value
.str
[i
] );
3289 add_generated_sources( make
);
3291 value
= get_expanded_make_var_array( make
, "EXTRA_OBJS" );
3292 for (i
= 0; i
< value
.count
; i
++)
3294 /* default to .c for unknown extra object files */
3295 if (strendswith( value
.str
[i
], ".o" ))
3296 add_generated_source( make
, value
.str
[i
], replace_extension( value
.str
[i
], ".o", ".c" ) );
3298 add_generated_source( make
, value
.str
[i
], NULL
);
3301 LIST_FOR_EACH_ENTRY( file
, &make
->includes
, struct incl_file
, entry
) parse_file( make
, file
, 0 );
3305 /*******************************************************************
3308 static void parse_makeflags( const char *flags
)
3310 const char *p
= flags
;
3311 char *var
, *buffer
= xmalloc( strlen(flags
) + 1 );
3315 while (isspace(*p
)) p
++;
3317 while (*p
&& !isspace(*p
))
3319 if (*p
== '\\' && p
[1]) p
++;
3323 if (var
> buffer
) set_make_variable( &cmdline_vars
, buffer
);
3328 /*******************************************************************
3331 static int parse_option( const char *opt
)
3335 if (strchr( opt
, '=' )) return set_make_variable( &cmdline_vars
, opt
);
3341 if (opt
[2]) output_makefile_name
= opt
+ 2;
3344 relative_dir_mode
= 1;
3347 fprintf( stderr
, "Unknown option '%s'\n%s", opt
, Usage
);
3354 /*******************************************************************
3357 int main( int argc
, char *argv
[] )
3359 const char *makeflags
= getenv( "MAKEFLAGS" );
3362 if (makeflags
) parse_makeflags( makeflags
);
3367 if (parse_option( argv
[i
] ))
3369 for (j
= i
; j
< argc
; j
++) argv
[j
] = argv
[j
+1];
3375 if (relative_dir_mode
)
3381 fprintf( stderr
, "Option -R needs two directories\n%s", Usage
);
3384 relpath
= get_relative_path( argv
[1], argv
[2] );
3385 printf( "%s\n", relpath
? relpath
: "." );
3389 atexit( cleanup_files
);
3390 signal( SIGTERM
, exit_on_signal
);
3391 signal( SIGINT
, exit_on_signal
);
3393 signal( SIGHUP
, exit_on_signal
);
3396 for (i
= 0; i
< HASH_SIZE
; i
++) list_init( &files
[i
] );
3398 top_makefile
= parse_makefile( NULL
, "# End of common header" );
3400 linguas
= get_expanded_make_var_array( top_makefile
, "LINGUAS" );
3401 target_flags
= get_expanded_make_var_array( top_makefile
, "TARGETFLAGS" );
3402 msvcrt_flags
= get_expanded_make_var_array( top_makefile
, "MSVCRTFLAGS" );
3403 dll_flags
= get_expanded_make_var_array( top_makefile
, "DLLFLAGS" );
3404 extra_cflags
= get_expanded_make_var_array( top_makefile
, "EXTRACFLAGS" );
3405 cpp_flags
= get_expanded_make_var_array( top_makefile
, "CPPFLAGS" );
3406 unwind_flags
= get_expanded_make_var_array( top_makefile
, "UNWINDFLAGS" );
3407 libs
= get_expanded_make_var_array( top_makefile
, "LIBS" );
3409 root_src_dir
= get_expanded_make_variable( top_makefile
, "srcdir" );
3410 tools_dir
= get_expanded_make_variable( top_makefile
, "TOOLSDIR" );
3411 tools_ext
= get_expanded_make_variable( top_makefile
, "TOOLSEXT" );
3412 exe_ext
= get_expanded_make_variable( top_makefile
, "EXEEXT" );
3413 man_ext
= get_expanded_make_variable( top_makefile
, "api_manext" );
3414 dll_ext
= (exe_ext
&& !strcmp( exe_ext
, ".exe" )) ? "" : ".so";
3415 crosstarget
= get_expanded_make_variable( top_makefile
, "CROSSTARGET" );
3416 fontforge
= get_expanded_make_variable( top_makefile
, "FONTFORGE" );
3417 convert
= get_expanded_make_variable( top_makefile
, "CONVERT" );
3418 rsvg
= get_expanded_make_variable( top_makefile
, "RSVG" );
3419 icotool
= get_expanded_make_variable( top_makefile
, "ICOTOOL" );
3420 dlltool
= get_expanded_make_variable( top_makefile
, "DLLTOOL" );
3422 if (root_src_dir
&& !strcmp( root_src_dir
, "." )) root_src_dir
= NULL
;
3423 if (tools_dir
&& !strcmp( tools_dir
, "." )) tools_dir
= NULL
;
3424 if (!exe_ext
) exe_ext
= "";
3425 if (!tools_ext
) tools_ext
= "";
3426 if (!man_ext
) man_ext
= "3w";
3430 top_makefile
->subdirs
= get_expanded_make_var_array( top_makefile
, "SUBDIRS" );
3431 top_makefile
->submakes
= xmalloc( top_makefile
->subdirs
.count
* sizeof(*top_makefile
->submakes
) );
3433 for (i
= 0; i
< top_makefile
->subdirs
.count
; i
++)
3434 top_makefile
->submakes
[i
] = parse_makefile( top_makefile
->subdirs
.str
[i
], NULL
);
3436 load_sources( top_makefile
);
3437 for (i
= 0; i
< top_makefile
->subdirs
.count
; i
++)
3438 load_sources( top_makefile
->submakes
[i
] );
3440 for (i
= 0; i
< top_makefile
->subdirs
.count
; i
++)
3441 output_dependencies( top_makefile
->submakes
[i
] );
3443 output_dependencies( top_makefile
);
3447 for (i
= 1; i
< argc
; i
++)
3449 struct makefile
*make
= parse_makefile( argv
[i
], NULL
);
3450 load_sources( make
);
3451 output_dependencies( make
);