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 struct strarray disabled_dirs
;
138 static const char *root_src_dir
;
139 static const char *tools_dir
;
140 static const char *tools_ext
;
141 static const char *exe_ext
;
142 static const char *dll_ext
;
143 static const char *man_ext
;
144 static const char *crosstarget
;
145 static const char *fontforge
;
146 static const char *convert
;
147 static const char *rsvg
;
148 static const char *icotool
;
149 static const char *dlltool
;
150 static const char *msgfmt
;
151 static const char *ln_s
;
155 struct strarray vars
;
156 struct strarray include_paths
;
157 struct strarray define_args
;
158 struct strarray programs
;
159 struct strarray scripts
;
160 struct strarray appmode
;
161 struct strarray imports
;
162 struct strarray subdirs
;
163 struct strarray delayimports
;
164 struct strarray extradllflags
;
165 struct strarray install_lib
;
166 struct strarray install_dev
;
168 struct list includes
;
169 const char *base_dir
;
172 const char *top_src_dir
;
173 const char *top_obj_dir
;
174 const char *parent_dir
;
177 const char *sharedlib
;
178 const char *staticlib
;
179 const char *staticimplib
;
180 const char *importlib
;
184 struct makefile
**submakes
;
187 static struct makefile
*top_makefile
;
189 static const char separator
[] = "### Dependencies";
190 static const char *output_makefile_name
= "Makefile";
191 static const char *input_file_name
;
192 static const char *output_file_name
;
193 static const char *temp_file_name
;
194 static int relative_dir_mode
;
195 static int input_line
;
196 static int output_column
;
197 static FILE *output_file
;
199 static const char Usage
[] =
200 "Usage: makedep [options] [directories]\n"
202 " -R from to Compute the relative path between two directories\n"
203 " -fxxx Store output in file 'xxx' (default: Makefile)\n";
207 #define __attribute__(x)
210 static void fatal_error( const char *msg
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
211 static void fatal_perror( const char *msg
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
212 static void output( const char *format
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
213 static char *strmake( const char* fmt
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
215 /*******************************************************************
218 static void fatal_error( const char *msg
, ... )
221 va_start( valist
, msg
);
224 fprintf( stderr
, "%s:", input_file_name
);
225 if (input_line
) fprintf( stderr
, "%d:", input_line
);
226 fprintf( stderr
, " error: " );
228 else fprintf( stderr
, "makedep: error: " );
229 vfprintf( stderr
, msg
, valist
);
235 /*******************************************************************
238 static void fatal_perror( const char *msg
, ... )
241 va_start( valist
, msg
);
244 fprintf( stderr
, "%s:", input_file_name
);
245 if (input_line
) fprintf( stderr
, "%d:", input_line
);
246 fprintf( stderr
, " error: " );
248 else fprintf( stderr
, "makedep: error: " );
249 vfprintf( stderr
, msg
, valist
);
256 /*******************************************************************
259 static void cleanup_files(void)
261 if (temp_file_name
) unlink( temp_file_name
);
262 if (output_file_name
) unlink( output_file_name
);
266 /*******************************************************************
269 static void exit_on_signal( int sig
)
271 exit( 1 ); /* this will call the atexit functions */
275 /*******************************************************************
278 static void *xmalloc( size_t size
)
281 if (!(res
= malloc (size
? size
: 1)))
282 fatal_error( "Virtual memory exhausted.\n" );
287 /*******************************************************************
290 static void *xrealloc (void *ptr
, size_t size
)
294 if (!(res
= realloc( ptr
, size
)))
295 fatal_error( "Virtual memory exhausted.\n" );
299 /*******************************************************************
302 static char *xstrdup( const char *str
)
304 char *res
= strdup( str
);
305 if (!res
) fatal_error( "Virtual memory exhausted.\n" );
310 /*******************************************************************
313 static char *strmake( const char* fmt
, ... )
321 char *p
= xmalloc (size
);
323 n
= vsnprintf (p
, size
, fmt
, ap
);
325 if (n
== -1) size
*= 2;
326 else if ((size_t)n
>= size
) size
= n
+ 1;
327 else return xrealloc( p
, n
+ 1 );
333 /*******************************************************************
336 static int strendswith( const char* str
, const char* end
)
338 size_t l
= strlen( str
);
339 size_t m
= strlen( end
);
341 return l
>= m
&& strcmp(str
+ l
- m
, end
) == 0;
345 /*******************************************************************
348 static void output( const char *format
, ... )
353 va_start( valist
, format
);
354 ret
= vfprintf( output_file
, format
, valist
);
356 if (ret
< 0) fatal_perror( "output" );
357 if (format
[0] && format
[strlen(format
) - 1] == '\n') output_column
= 0;
358 else output_column
+= ret
;
362 /*******************************************************************
365 static void strarray_add( struct strarray
*array
, const char *str
)
367 if (array
->count
== array
->size
)
369 if (array
->size
) array
->size
*= 2;
370 else array
->size
= 16;
371 array
->str
= xrealloc( array
->str
, sizeof(array
->str
[0]) * array
->size
);
373 array
->str
[array
->count
++] = str
;
377 /*******************************************************************
380 static void strarray_addall( struct strarray
*array
, struct strarray added
)
384 for (i
= 0; i
< added
.count
; i
++) strarray_add( array
, added
.str
[i
] );
388 /*******************************************************************
391 static int strarray_exists( const struct strarray
*array
, const char *str
)
395 for (i
= 0; i
< array
->count
; i
++) if (!strcmp( array
->str
[i
], str
)) return 1;
400 /*******************************************************************
403 static void strarray_add_uniq( struct strarray
*array
, const char *str
)
405 if (!strarray_exists( array
, str
)) strarray_add( array
, str
);
409 /*******************************************************************
412 * Find a value in a name/value pair string array.
414 static const char *strarray_get_value( const struct strarray
*array
, const char *name
)
418 for (i
= 0; i
< array
->count
; i
+= 2)
419 if (!strcmp( array
->str
[i
], name
)) return array
->str
[i
+ 1];
424 /*******************************************************************
427 * Define a value in a name/value pair string array.
429 static void strarray_set_value( struct strarray
*array
, const char *name
, const char *value
)
433 /* redefining a variable replaces the previous value */
434 for (i
= 0; i
< array
->count
; i
+= 2)
436 if (strcmp( array
->str
[i
], name
)) continue;
437 array
->str
[i
+ 1] = value
;
440 strarray_add( array
, name
);
441 strarray_add( array
, value
);
445 /*******************************************************************
448 static void output_filename( const char *name
)
450 if (output_column
+ strlen(name
) + 1 > 100)
455 else if (output_column
) output( " " );
456 output( "%s", name
);
460 /*******************************************************************
463 static void output_filenames( struct strarray array
)
467 for (i
= 0; i
< array
.count
; i
++) output_filename( array
.str
[i
] );
471 /*******************************************************************
474 static char *get_extension( char *filename
)
476 char *ext
= strrchr( filename
, '.' );
477 if (ext
&& strchr( ext
, '/' )) ext
= NULL
;
482 /*******************************************************************
485 static char *replace_extension( const char *name
, const char *old_ext
, const char *new_ext
)
488 size_t name_len
= strlen( name
);
489 size_t ext_len
= strlen( old_ext
);
491 if (name_len
>= ext_len
&& !strcmp( name
+ name_len
- ext_len
, old_ext
)) name_len
-= ext_len
;
492 ret
= xmalloc( name_len
+ strlen( new_ext
) + 1 );
493 memcpy( ret
, name
, name_len
);
494 strcpy( ret
+ name_len
, new_ext
);
499 /*******************************************************************
502 static char *replace_filename( const char *path
, const char *name
)
508 if (!path
) return xstrdup( name
);
509 if (!(p
= strrchr( path
, '/' ))) return xstrdup( name
);
511 ret
= xmalloc( len
+ strlen( name
) + 1 );
512 memcpy( ret
, path
, len
);
513 strcpy( ret
+ len
, name
);
518 /*******************************************************************
519 * strarray_replace_extension
521 static struct strarray
strarray_replace_extension( const struct strarray
*array
,
522 const char *old_ext
, const char *new_ext
)
527 ret
.count
= ret
.size
= array
->count
;
528 ret
.str
= xmalloc( sizeof(ret
.str
[0]) * ret
.size
);
529 for (i
= 0; i
< array
->count
; i
++) ret
.str
[i
] = replace_extension( array
->str
[i
], old_ext
, new_ext
);
534 /*******************************************************************
537 static char *replace_substr( const char *str
, const char *start
, size_t len
, const char *replace
)
539 size_t pos
= start
- str
;
540 char *ret
= xmalloc( pos
+ strlen(replace
) + strlen(start
+ len
) + 1 );
541 memcpy( ret
, str
, pos
);
542 strcpy( ret
+ pos
, replace
);
543 strcat( ret
+ pos
, start
+ len
);
548 /*******************************************************************
551 * Determine where the destination path is located relative to the 'from' path.
553 static char *get_relative_path( const char *from
, const char *dest
)
557 unsigned int dotdots
= 0;
559 /* a path of "." is equivalent to an empty path */
560 if (!strcmp( from
, "." )) from
= "";
564 while (*from
== '/') from
++;
565 while (*dest
== '/') dest
++;
566 start
= dest
; /* save start of next path element */
569 while (*from
&& *from
!= '/' && *from
== *dest
) { from
++; dest
++; }
570 if ((!*from
|| *from
== '/') && (!*dest
|| *dest
== '/')) continue;
572 /* count remaining elements in 'from' */
576 while (*from
&& *from
!= '/') from
++;
577 while (*from
== '/') from
++;
583 if (!start
[0] && !dotdots
) return NULL
; /* empty path */
585 ret
= xmalloc( 3 * dotdots
+ strlen( start
) + 1 );
586 for (p
= ret
; dotdots
; dotdots
--, p
+= 3) memcpy( p
, "../", 3 );
588 if (start
[0]) strcpy( p
, start
);
589 else p
[-1] = 0; /* remove trailing slash */
594 /*******************************************************************
597 static char *concat_paths( const char *base
, const char *path
)
599 if (!base
|| !base
[0]) return xstrdup( path
&& path
[0] ? path
: "." );
600 if (!path
|| !path
[0]) return xstrdup( base
);
601 if (path
[0] == '/') return xstrdup( path
);
602 return strmake( "%s/%s", base
, path
);
606 /*******************************************************************
609 static char *base_dir_path( const struct makefile
*make
, const char *path
)
611 return concat_paths( make
->base_dir
, path
);
615 /*******************************************************************
618 static char *obj_dir_path( const struct makefile
*make
, const char *path
)
620 return concat_paths( make
->obj_dir
, path
);
624 /*******************************************************************
627 static char *src_dir_path( const struct makefile
*make
, const char *path
)
629 if (make
->src_dir
) return concat_paths( make
->src_dir
, path
);
630 return obj_dir_path( make
, path
);
634 /*******************************************************************
637 static char *top_obj_dir_path( const struct makefile
*make
, const char *path
)
639 return concat_paths( make
->top_obj_dir
, path
);
643 /*******************************************************************
646 static char *top_dir_path( const struct makefile
*make
, const char *path
)
648 if (make
->top_src_dir
) return concat_paths( make
->top_src_dir
, path
);
649 return top_obj_dir_path( make
, path
);
653 /*******************************************************************
656 static char *root_dir_path( const char *path
)
658 return concat_paths( root_src_dir
, path
);
662 /*******************************************************************
665 static char *tools_dir_path( const struct makefile
*make
, const char *path
)
667 if (tools_dir
) return top_obj_dir_path( make
, strmake( "%s/tools/%s", tools_dir
, path
));
668 return top_obj_dir_path( make
, strmake( "tools/%s", path
));
672 /*******************************************************************
675 static char *tools_path( const struct makefile
*make
, const char *name
)
677 return strmake( "%s/%s%s", tools_dir_path( make
, name
), name
, tools_ext
);
681 /*******************************************************************
684 static char *get_line( FILE *file
)
692 buffer
= xmalloc( size
);
694 if (!fgets( buffer
, size
, file
)) return NULL
;
699 char *p
= buffer
+ strlen(buffer
);
700 /* if line is larger than buffer, resize buffer */
701 while (p
== buffer
+ size
- 1 && p
[-1] != '\n')
703 buffer
= xrealloc( buffer
, size
* 2 );
704 if (!fgets( buffer
+ size
- 1, size
+ 1, file
)) break;
705 p
= buffer
+ strlen(buffer
);
708 if (p
> buffer
&& p
[-1] == '\n')
711 if (p
> buffer
&& p
[-1] == '\r') *(--p
) = 0;
712 if (p
> buffer
&& p
[-1] == '\\')
715 /* line ends in backslash, read continuation line */
716 if (!fgets( p
, size
- (p
- buffer
), file
)) return buffer
;
726 /*******************************************************************
729 static unsigned int hash_filename( const char *name
)
731 unsigned int ret
= 0;
732 while (*name
) ret
= (ret
<< 7) + (ret
<< 3) + *name
++;
733 return ret
% HASH_SIZE
;
737 /*******************************************************************
740 static struct file
*add_file( const char *name
)
742 struct file
*file
= xmalloc( sizeof(*file
) );
743 memset( file
, 0, sizeof(*file
) );
744 file
->name
= xstrdup( name
);
745 list_add_tail( &files
[hash_filename( name
)], &file
->entry
);
750 /*******************************************************************
753 static void add_dependency( struct file
*file
, const char *name
, enum incl_type type
)
755 /* enforce some rules for the Wine tree */
757 if (!memcmp( name
, "../", 3 ))
758 fatal_error( "#include directive with relative path not allowed\n" );
760 if (!strcmp( name
, "config.h" ))
762 if (strendswith( file
->name
, ".h" ))
763 fatal_error( "config.h must not be included by a header file\n" );
764 if (file
->deps_count
)
765 fatal_error( "config.h must be included before anything else\n" );
767 else if (!strcmp( name
, "wine/port.h" ))
769 if (strendswith( file
->name
, ".h" ))
770 fatal_error( "wine/port.h must not be included by a header file\n" );
771 if (!file
->deps_count
) fatal_error( "config.h must be included before wine/port.h\n" );
772 if (file
->deps_count
> 1)
773 fatal_error( "wine/port.h must be included before everything except config.h\n" );
774 if (strcmp( file
->deps
[0].name
, "config.h" ))
775 fatal_error( "config.h must be included before wine/port.h\n" );
778 if (file
->deps_count
>= file
->deps_size
)
780 file
->deps_size
*= 2;
781 if (file
->deps_size
< 16) file
->deps_size
= 16;
782 file
->deps
= xrealloc( file
->deps
, file
->deps_size
* sizeof(*file
->deps
) );
784 file
->deps
[file
->deps_count
].line
= input_line
;
785 file
->deps
[file
->deps_count
].type
= type
;
786 file
->deps
[file
->deps_count
].name
= xstrdup( name
);
791 /*******************************************************************
794 static struct incl_file
*find_src_file( const struct makefile
*make
, const char *name
)
796 struct incl_file
*file
;
798 LIST_FOR_EACH_ENTRY( file
, &make
->sources
, struct incl_file
, entry
)
799 if (!strcmp( name
, file
->name
)) return file
;
803 /*******************************************************************
806 static struct incl_file
*find_include_file( const struct makefile
*make
, const char *name
)
808 struct incl_file
*file
;
810 LIST_FOR_EACH_ENTRY( file
, &make
->includes
, struct incl_file
, entry
)
811 if (!strcmp( name
, file
->name
)) return file
;
815 /*******************************************************************
818 * Add an include file if it doesn't already exists.
820 static struct incl_file
*add_include( struct makefile
*make
, struct incl_file
*parent
,
821 const char *name
, int line
, enum incl_type type
)
823 struct incl_file
*include
;
825 if (parent
->files_count
>= parent
->files_size
)
827 parent
->files_size
*= 2;
828 if (parent
->files_size
< 16) parent
->files_size
= 16;
829 parent
->files
= xrealloc( parent
->files
, parent
->files_size
* sizeof(*parent
->files
) );
832 LIST_FOR_EACH_ENTRY( include
, &make
->includes
, struct incl_file
, entry
)
833 if (!strcmp( name
, include
->name
)) goto found
;
835 include
= xmalloc( sizeof(*include
) );
836 memset( include
, 0, sizeof(*include
) );
837 include
->name
= xstrdup(name
);
838 include
->included_by
= parent
;
839 include
->included_line
= line
;
840 include
->type
= type
;
841 list_add_tail( &make
->includes
, &include
->entry
);
843 parent
->files
[parent
->files_count
++] = include
;
848 /*******************************************************************
849 * add_generated_source
851 * Add a generated source file to the list.
853 static struct incl_file
*add_generated_source( struct makefile
*make
,
854 const char *name
, const char *filename
)
856 struct incl_file
*file
;
858 if ((file
= find_src_file( make
, name
))) return file
; /* we already have it */
859 file
= xmalloc( sizeof(*file
) );
860 memset( file
, 0, sizeof(*file
) );
861 file
->file
= add_file( name
);
862 file
->name
= xstrdup( name
);
863 file
->filename
= obj_dir_path( make
, filename
? filename
: name
);
864 file
->file
->flags
= FLAG_GENERATED
;
865 list_add_tail( &make
->sources
, &file
->entry
);
870 /*******************************************************************
871 * parse_include_directive
873 static void parse_include_directive( struct file
*source
, char *str
)
875 char quote
, *include
, *p
= str
;
877 while (*p
&& isspace(*p
)) p
++;
878 if (*p
!= '\"' && *p
!= '<' ) return;
880 if (quote
== '<') quote
= '>';
882 while (*p
&& (*p
!= quote
)) p
++;
883 if (!*p
) fatal_error( "malformed include directive '%s'\n", str
);
885 add_dependency( source
, include
, (quote
== '>') ? INCL_SYSTEM
: INCL_NORMAL
);
889 /*******************************************************************
890 * parse_pragma_directive
892 static void parse_pragma_directive( struct file
*source
, char *str
)
894 char *flag
, *p
= str
;
896 if (!isspace( *p
)) return;
897 while (*p
&& isspace(*p
)) p
++;
898 p
= strtok( p
, " \t" );
899 if (strcmp( p
, "makedep" )) return;
901 while ((flag
= strtok( NULL
, " \t" )))
903 if (!strcmp( flag
, "depend" ))
905 while ((p
= strtok( NULL
, " \t" ))) add_dependency( source
, p
, INCL_NORMAL
);
908 else if (!strcmp( flag
, "install" )) source
->flags
|= FLAG_INSTALL
;
910 if (strendswith( source
->name
, ".idl" ))
912 if (!strcmp( flag
, "header" )) source
->flags
|= FLAG_IDL_HEADER
;
913 else if (!strcmp( flag
, "proxy" )) source
->flags
|= FLAG_IDL_PROXY
;
914 else if (!strcmp( flag
, "client" )) source
->flags
|= FLAG_IDL_CLIENT
;
915 else if (!strcmp( flag
, "server" )) source
->flags
|= FLAG_IDL_SERVER
;
916 else if (!strcmp( flag
, "ident" )) source
->flags
|= FLAG_IDL_IDENT
;
917 else if (!strcmp( flag
, "typelib" )) source
->flags
|= FLAG_IDL_TYPELIB
;
918 else if (!strcmp( flag
, "register" )) source
->flags
|= FLAG_IDL_REGISTER
;
919 else if (!strcmp( flag
, "regtypelib" )) source
->flags
|= FLAG_IDL_REGTYPELIB
;
921 else if (strendswith( source
->name
, ".rc" ))
923 if (!strcmp( flag
, "po" )) source
->flags
|= FLAG_RC_PO
;
925 else if (strendswith( source
->name
, ".sfd" ))
927 if (!strcmp( flag
, "font" ))
929 struct strarray
*array
= source
->args
;
933 source
->args
= array
= xmalloc( sizeof(*array
) );
934 *array
= empty_strarray
;
935 source
->flags
|= FLAG_SFD_FONTS
;
937 strarray_add( array
, xstrdup( strtok( NULL
, "" )));
941 else if (!strcmp( flag
, "implib" )) source
->flags
|= FLAG_C_IMPLIB
;
946 /*******************************************************************
947 * parse_cpp_directive
949 static void parse_cpp_directive( struct file
*source
, char *str
)
951 while (*str
&& isspace(*str
)) str
++;
952 if (*str
++ != '#') return;
953 while (*str
&& isspace(*str
)) str
++;
955 if (!strncmp( str
, "include", 7 ))
956 parse_include_directive( source
, str
+ 7 );
957 else if (!strncmp( str
, "import", 6 ) && strendswith( source
->name
, ".m" ))
958 parse_include_directive( source
, str
+ 6 );
959 else if (!strncmp( str
, "pragma", 6 ))
960 parse_pragma_directive( source
, str
+ 6 );
964 /*******************************************************************
967 static void parse_idl_file( struct file
*source
, FILE *file
)
969 char *buffer
, *include
;
973 while ((buffer
= get_line( file
)))
977 while (*p
&& isspace(*p
)) p
++;
979 if (!strncmp( p
, "importlib", 9 ))
982 while (*p
&& isspace(*p
)) p
++;
983 if (*p
++ != '(') continue;
984 while (*p
&& isspace(*p
)) p
++;
985 if (*p
++ != '"') continue;
987 while (*p
&& (*p
!= '"')) p
++;
988 if (!*p
) fatal_error( "malformed importlib directive\n" );
990 add_dependency( source
, include
, INCL_IMPORTLIB
);
994 if (!strncmp( p
, "import", 6 ))
997 while (*p
&& isspace(*p
)) p
++;
998 if (*p
!= '"') continue;
1000 while (*p
&& (*p
!= '"')) p
++;
1001 if (!*p
) fatal_error( "malformed import directive\n" );
1003 add_dependency( source
, include
, INCL_IMPORT
);
1007 /* check for #include inside cpp_quote */
1008 if (!strncmp( p
, "cpp_quote", 9 ))
1011 while (*p
&& isspace(*p
)) p
++;
1012 if (*p
++ != '(') continue;
1013 while (*p
&& isspace(*p
)) p
++;
1014 if (*p
++ != '"') continue;
1015 if (*p
++ != '#') continue;
1016 while (*p
&& isspace(*p
)) p
++;
1017 if (strncmp( p
, "include", 7 )) continue;
1019 while (*p
&& isspace(*p
)) p
++;
1020 if (*p
== '\\' && p
[1] == '"')
1027 if (*p
++ != '<' ) continue;
1031 while (*p
&& (*p
!= quote
)) p
++;
1032 if (!*p
|| (quote
== '"' && p
[-1] != '\\'))
1033 fatal_error( "malformed #include directive inside cpp_quote\n" );
1034 if (quote
== '"') p
--; /* remove backslash */
1036 add_dependency( source
, include
, (quote
== '>') ? INCL_CPP_QUOTE_SYSTEM
: INCL_CPP_QUOTE
);
1040 parse_cpp_directive( source
, p
);
1044 /*******************************************************************
1047 static void parse_c_file( struct file
*source
, FILE *file
)
1052 while ((buffer
= get_line( file
)))
1054 parse_cpp_directive( source
, buffer
);
1059 /*******************************************************************
1062 static void parse_rc_file( struct file
*source
, FILE *file
)
1064 char *buffer
, *include
;
1067 while ((buffer
= get_line( file
)))
1071 while (*p
&& isspace(*p
)) p
++;
1073 if (p
[0] == '/' && p
[1] == '*') /* check for magic makedep comment */
1076 while (*p
&& isspace(*p
)) p
++;
1077 if (strncmp( p
, "@makedep:", 9 )) continue;
1079 while (*p
&& isspace(*p
)) p
++;
1084 while (*p
&& *p
!= quote
) p
++;
1089 while (*p
&& !isspace(*p
) && *p
!= '*') p
++;
1092 fatal_error( "malformed makedep comment\n" );
1094 add_dependency( source
, include
, (quote
== '>') ? INCL_SYSTEM
: INCL_NORMAL
);
1098 parse_cpp_directive( source
, buffer
);
1103 /*******************************************************************
1106 static void parse_in_file( struct file
*source
, FILE *file
)
1110 /* make sure it gets rebuilt when the version changes */
1111 add_dependency( source
, "config.h", INCL_SYSTEM
);
1113 if (!strendswith( source
->name
, ".man.in" )) return; /* not a man page */
1116 while ((buffer
= get_line( file
)))
1118 if (strncmp( buffer
, ".TH", 3 )) continue;
1119 if (!(p
= strtok( buffer
, " \t" ))) continue; /* .TH */
1120 if (!(p
= strtok( NULL
, " \t" ))) continue; /* program name */
1121 if (!(p
= strtok( NULL
, " \t" ))) continue; /* man section */
1122 source
->args
= xstrdup( p
);
1128 /*******************************************************************
1131 static void parse_sfd_file( struct file
*source
, FILE *file
)
1133 char *p
, *eol
, *buffer
;
1136 while ((buffer
= get_line( file
)))
1138 if (strncmp( buffer
, "UComments:", 10 )) continue;
1140 while (*p
== ' ') p
++;
1141 if (p
[0] == '"' && p
[1] && buffer
[strlen(buffer
) - 1] == '"')
1144 buffer
[strlen(buffer
) - 1] = 0;
1146 while ((eol
= strstr( p
, "+AAoA" )))
1149 while (*p
&& isspace(*p
)) p
++;
1152 while (*p
&& isspace(*p
)) p
++;
1153 if (!strncmp( p
, "pragma", 6 )) parse_pragma_directive( source
, p
+ 6 );
1157 while (*p
&& isspace(*p
)) p
++;
1158 if (*p
++ != '#') return;
1159 while (*p
&& isspace(*p
)) p
++;
1160 if (!strncmp( p
, "pragma", 6 )) parse_pragma_directive( source
, p
+ 6 );
1169 void (*parse
)( struct file
*file
, FILE *f
);
1170 } parse_functions
[] =
1172 { ".c", parse_c_file
},
1173 { ".h", parse_c_file
},
1174 { ".inl", parse_c_file
},
1175 { ".l", parse_c_file
},
1176 { ".m", parse_c_file
},
1177 { ".rh", parse_c_file
},
1178 { ".x", parse_c_file
},
1179 { ".y", parse_c_file
},
1180 { ".idl", parse_idl_file
},
1181 { ".rc", parse_rc_file
},
1182 { ".in", parse_in_file
},
1183 { ".sfd", parse_sfd_file
}
1186 /*******************************************************************
1189 static struct file
*load_file( const char *name
)
1193 unsigned int i
, hash
= hash_filename( name
);
1195 LIST_FOR_EACH_ENTRY( file
, &files
[hash
], struct file
, entry
)
1196 if (!strcmp( name
, file
->name
)) return file
;
1198 if (!(f
= fopen( name
, "r" ))) return NULL
;
1200 file
= add_file( name
);
1201 input_file_name
= file
->name
;
1204 for (i
= 0; i
< sizeof(parse_functions
) / sizeof(parse_functions
[0]); i
++)
1206 if (!strendswith( name
, parse_functions
[i
].ext
)) continue;
1207 parse_functions
[i
].parse( file
, f
);
1212 input_file_name
= NULL
;
1218 /*******************************************************************
1219 * open_include_path_file
1221 * Open a file from a directory on the include path.
1223 static struct file
*open_include_path_file( const struct makefile
*make
, const char *dir
,
1224 const char *name
, char **filename
)
1226 char *src_path
= base_dir_path( make
, concat_paths( dir
, name
));
1227 struct file
*ret
= load_file( src_path
);
1229 if (ret
) *filename
= src_dir_path( make
, concat_paths( dir
, name
));
1234 /*******************************************************************
1235 * open_file_same_dir
1237 * Open a file in the same directory as the parent.
1239 static struct file
*open_file_same_dir( const struct incl_file
*parent
, const char *name
, char **filename
)
1241 char *src_path
= replace_filename( parent
->file
->name
, name
);
1242 struct file
*ret
= load_file( src_path
);
1244 if (ret
) *filename
= replace_filename( parent
->filename
, name
);
1250 /*******************************************************************
1253 * Open a file in the source directory of the makefile.
1255 static struct file
*open_local_file( const struct makefile
*make
, const char *path
, char **filename
)
1257 char *src_path
= root_dir_path( base_dir_path( make
, path
));
1258 struct file
*ret
= load_file( src_path
);
1260 /* if not found, try parent dir */
1261 if (!ret
&& make
->parent_dir
)
1264 path
= strmake( "%s/%s", make
->parent_dir
, path
);
1265 src_path
= root_dir_path( base_dir_path( make
, path
));
1266 ret
= load_file( src_path
);
1269 if (ret
) *filename
= src_dir_path( make
, path
);
1275 /*******************************************************************
1278 * Open a file in the top-level source directory.
1280 static struct file
*open_global_file( const struct makefile
*make
, const char *path
, char **filename
)
1282 char *src_path
= root_dir_path( path
);
1283 struct file
*ret
= load_file( src_path
);
1285 if (ret
) *filename
= top_dir_path( make
, path
);
1291 /*******************************************************************
1292 * open_global_header
1294 * Open a file in the global include source directory.
1296 static struct file
*open_global_header( const struct makefile
*make
, const char *path
, char **filename
)
1298 return open_global_file( make
, strmake( "include/%s", path
), filename
);
1302 /*******************************************************************
1305 static struct file
*open_src_file( const struct makefile
*make
, struct incl_file
*pFile
)
1307 struct file
*file
= open_local_file( make
, pFile
->name
, &pFile
->filename
);
1309 if (!file
) fatal_perror( "open %s", pFile
->name
);
1314 /*******************************************************************
1317 static struct file
*open_include_file( const struct makefile
*make
, struct incl_file
*pFile
)
1319 struct file
*file
= NULL
;
1321 unsigned int i
, len
;
1325 /* check for generated bison header */
1327 if (strendswith( pFile
->name
, ".tab.h" ) &&
1328 (file
= open_local_file( make
, replace_extension( pFile
->name
, ".tab.h", ".y" ), &filename
)))
1330 pFile
->sourcename
= filename
;
1331 pFile
->filename
= obj_dir_path( make
, pFile
->name
);
1335 /* check for corresponding idl file in source dir */
1337 if (strendswith( pFile
->name
, ".h" ) &&
1338 (file
= open_local_file( make
, replace_extension( pFile
->name
, ".h", ".idl" ), &filename
)))
1340 pFile
->sourcename
= filename
;
1341 pFile
->filename
= obj_dir_path( make
, pFile
->name
);
1345 /* check for corresponding tlb file in source dir */
1347 if (strendswith( pFile
->name
, ".tlb" ) &&
1348 (file
= open_local_file( make
, replace_extension( pFile
->name
, ".tlb", ".idl" ), &filename
)))
1350 pFile
->sourcename
= filename
;
1351 pFile
->filename
= obj_dir_path( make
, pFile
->name
);
1355 /* now try in source dir */
1356 if ((file
= open_local_file( make
, pFile
->name
, &pFile
->filename
))) return file
;
1358 /* check for corresponding idl file in global includes */
1360 if (strendswith( pFile
->name
, ".h" ) &&
1361 (file
= open_global_header( make
, replace_extension( pFile
->name
, ".h", ".idl" ), &filename
)))
1363 pFile
->sourcename
= filename
;
1364 pFile
->filename
= top_obj_dir_path( make
, strmake( "include/%s", pFile
->name
));
1368 /* check for corresponding .in file in global includes (for config.h.in) */
1370 if (strendswith( pFile
->name
, ".h" ) &&
1371 (file
= open_global_header( make
, replace_extension( pFile
->name
, ".h", ".h.in" ), &filename
)))
1373 pFile
->sourcename
= filename
;
1374 pFile
->filename
= top_obj_dir_path( make
, strmake( "include/%s", pFile
->name
));
1378 /* check for corresponding .x file in global includes */
1380 if (strendswith( pFile
->name
, "tmpl.h" ) &&
1381 (file
= open_global_header( make
, replace_extension( pFile
->name
, ".h", ".x" ), &filename
)))
1383 pFile
->sourcename
= filename
;
1384 pFile
->filename
= top_obj_dir_path( make
, strmake( "include/%s", pFile
->name
));
1388 /* check for corresponding .tlb file in global includes */
1390 if (strendswith( pFile
->name
, ".tlb" ) &&
1391 (file
= open_global_header( make
, replace_extension( pFile
->name
, ".tlb", ".idl" ), &filename
)))
1393 pFile
->sourcename
= filename
;
1394 pFile
->filename
= top_obj_dir_path( make
, strmake( "include/%s", pFile
->name
));
1398 /* check in global includes source dir */
1400 if ((file
= open_global_header( make
, pFile
->name
, &pFile
->filename
))) return file
;
1402 /* check in global msvcrt includes */
1403 if (make
->use_msvcrt
&&
1404 (file
= open_global_header( make
, strmake( "msvcrt/%s", pFile
->name
), &pFile
->filename
)))
1407 /* now search in include paths */
1408 for (i
= 0; i
< make
->include_paths
.count
; i
++)
1410 const char *dir
= make
->include_paths
.str
[i
];
1411 const char *prefix
= make
->top_src_dir
? make
->top_src_dir
: make
->top_obj_dir
;
1415 len
= strlen( prefix
);
1416 if (!strncmp( dir
, prefix
, len
) && (!dir
[len
] || dir
[len
] == '/'))
1418 while (dir
[len
] == '/') len
++;
1419 file
= open_global_file( make
, concat_paths( dir
+ len
, pFile
->name
), &pFile
->filename
);
1420 if (file
) return file
;
1422 if (make
->top_src_dir
) continue; /* ignore paths that don't point to the top source dir */
1426 if ((file
= open_include_path_file( make
, dir
, pFile
->name
, &pFile
->filename
)))
1430 if (pFile
->type
== INCL_SYSTEM
) return NULL
; /* ignore system files we cannot find */
1432 /* try in src file directory */
1433 if ((file
= open_file_same_dir( pFile
->included_by
, pFile
->name
, &pFile
->filename
))) return file
;
1435 fprintf( stderr
, "%s:%d: error: ", pFile
->included_by
->file
->name
, pFile
->included_line
);
1436 perror( pFile
->name
);
1437 pFile
= pFile
->included_by
;
1438 while (pFile
&& pFile
->included_by
)
1440 const char *parent
= pFile
->included_by
->sourcename
;
1441 if (!parent
) parent
= pFile
->included_by
->file
->name
;
1442 fprintf( stderr
, "%s:%d: note: %s was first included here\n",
1443 parent
, pFile
->included_line
, pFile
->name
);
1444 pFile
= pFile
->included_by
;
1450 /*******************************************************************
1453 static void add_all_includes( struct makefile
*make
, struct incl_file
*parent
, struct file
*file
)
1457 parent
->files_count
= 0;
1458 parent
->files_size
= file
->deps_count
;
1459 parent
->files
= xmalloc( parent
->files_size
* sizeof(*parent
->files
) );
1460 for (i
= 0; i
< file
->deps_count
; i
++)
1462 switch (file
->deps
[i
].type
)
1466 add_include( make
, parent
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_NORMAL
);
1468 case INCL_IMPORTLIB
:
1469 add_include( make
, parent
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_IMPORTLIB
);
1472 add_include( make
, parent
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_SYSTEM
);
1474 case INCL_CPP_QUOTE
:
1475 case INCL_CPP_QUOTE_SYSTEM
:
1482 /*******************************************************************
1485 static void parse_file( struct makefile
*make
, struct incl_file
*source
, int src
)
1487 struct file
*file
= src
? open_src_file( make
, source
) : open_include_file( make
, source
);
1491 source
->file
= file
;
1492 source
->files_count
= 0;
1493 source
->files_size
= file
->deps_count
;
1494 source
->files
= xmalloc( source
->files_size
* sizeof(*source
->files
) );
1496 if (source
->sourcename
)
1498 if (strendswith( source
->sourcename
, ".idl" ))
1502 if (strendswith( source
->name
, ".tlb" )) return; /* typelibs don't include anything */
1504 /* generated .h file always includes these */
1505 add_include( make
, source
, "rpc.h", 0, INCL_NORMAL
);
1506 add_include( make
, source
, "rpcndr.h", 0, INCL_NORMAL
);
1507 for (i
= 0; i
< file
->deps_count
; i
++)
1509 switch (file
->deps
[i
].type
)
1512 if (strendswith( file
->deps
[i
].name
, ".idl" ))
1513 add_include( make
, source
, replace_extension( file
->deps
[i
].name
, ".idl", ".h" ),
1514 file
->deps
[i
].line
, INCL_NORMAL
);
1516 add_include( make
, source
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_NORMAL
);
1518 case INCL_CPP_QUOTE
:
1519 add_include( make
, source
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_NORMAL
);
1521 case INCL_CPP_QUOTE_SYSTEM
:
1522 add_include( make
, source
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_SYSTEM
);
1526 case INCL_IMPORTLIB
:
1532 if (strendswith( source
->sourcename
, ".y" ))
1533 return; /* generated .tab.h doesn't include anything */
1536 add_all_includes( make
, source
, file
);
1540 /*******************************************************************
1543 * Add a source file to the list.
1545 static struct incl_file
*add_src_file( struct makefile
*make
, const char *name
)
1547 struct incl_file
*file
;
1549 if ((file
= find_src_file( make
, name
))) return file
; /* we already have it */
1550 file
= xmalloc( sizeof(*file
) );
1551 memset( file
, 0, sizeof(*file
) );
1552 file
->name
= xstrdup(name
);
1553 list_add_tail( &make
->sources
, &file
->entry
);
1554 parse_file( make
, file
, 1 );
1559 /*******************************************************************
1560 * open_input_makefile
1562 static FILE *open_input_makefile( const struct makefile
*make
)
1567 input_file_name
= root_dir_path( base_dir_path( make
, strmake( "%s.in", output_makefile_name
)));
1569 input_file_name
= output_makefile_name
; /* always use output name for main Makefile */
1572 if (!(ret
= fopen( input_file_name
, "r" ))) fatal_perror( "open" );
1577 /*******************************************************************
1580 static const char *get_make_variable( const struct makefile
*make
, const char *name
)
1584 if ((ret
= strarray_get_value( &cmdline_vars
, name
))) return ret
;
1585 if ((ret
= strarray_get_value( &make
->vars
, name
))) return ret
;
1586 if (top_makefile
&& (ret
= strarray_get_value( &top_makefile
->vars
, name
))) return ret
;
1591 /*******************************************************************
1592 * get_expanded_make_variable
1594 static char *get_expanded_make_variable( const struct makefile
*make
, const char *name
)
1597 char *p
, *end
, *expand
, *tmp
;
1599 var
= get_make_variable( make
, name
);
1600 if (!var
) return NULL
;
1602 p
= expand
= xstrdup( var
);
1603 while ((p
= strchr( p
, '$' )))
1607 if (!(end
= strchr( p
+ 2, ')' ))) fatal_error( "syntax error in '%s'\n", expand
);
1609 if (strchr( p
+ 2, ':' )) fatal_error( "pattern replacement not supported for '%s'\n", p
+ 2 );
1610 var
= get_make_variable( make
, p
+ 2 );
1611 tmp
= replace_substr( expand
, p
, end
- p
, var
? var
: "" );
1612 /* switch to the new string */
1613 p
= tmp
+ (p
- expand
);
1617 else if (p
[1] == '{') /* don't expand ${} variables */
1619 if (!(end
= strchr( p
+ 2, '}' ))) fatal_error( "syntax error in '%s'\n", expand
);
1622 else if (p
[1] == '$')
1626 else fatal_error( "syntax error in '%s'\n", expand
);
1629 /* consider empty variables undefined */
1631 while (*p
&& isspace(*p
)) p
++;
1632 if (*p
) return expand
;
1638 /*******************************************************************
1639 * get_expanded_make_var_array
1641 static struct strarray
get_expanded_make_var_array( const struct makefile
*make
, const char *name
)
1643 struct strarray ret
= empty_strarray
;
1644 char *value
, *token
;
1646 if ((value
= get_expanded_make_variable( make
, name
)))
1647 for (token
= strtok( value
, " \t" ); token
; token
= strtok( NULL
, " \t" ))
1648 strarray_add( &ret
, token
);
1653 /*******************************************************************
1654 * get_expanded_file_local_var
1656 static struct strarray
get_expanded_file_local_var( const struct makefile
*make
, const char *file
,
1659 char *p
, *var
= strmake( "%s_%s", file
, name
);
1661 for (p
= var
; *p
; p
++) if (!isalnum( *p
)) *p
= '_';
1662 return get_expanded_make_var_array( make
, var
);
1666 /*******************************************************************
1669 static int set_make_variable( struct strarray
*array
, const char *assignment
)
1673 p
= name
= xstrdup( assignment
);
1674 while (isalnum(*p
) || *p
== '_') p
++;
1675 if (name
== p
) return 0; /* not a variable */
1679 while (isspace(*p
)) p
++;
1681 if (*p
!= '=') return 0; /* not an assignment */
1683 while (isspace(*p
)) p
++;
1685 strarray_set_value( array
, name
, p
);
1690 /*******************************************************************
1693 static struct makefile
*parse_makefile( const char *path
)
1697 struct makefile
*make
= xmalloc( sizeof(*make
) );
1699 memset( make
, 0, sizeof(*make
) );
1702 make
->top_obj_dir
= get_relative_path( path
, "" );
1703 make
->base_dir
= path
;
1704 if (!strcmp( make
->base_dir
, "." )) make
->base_dir
= NULL
;
1707 file
= open_input_makefile( make
);
1708 while ((buffer
= get_line( file
)))
1710 if (!strncmp( buffer
, separator
, strlen(separator
) )) break;
1711 if (*buffer
== '\t') continue; /* command */
1712 while (isspace( *buffer
)) buffer
++;
1713 if (*buffer
== '#') continue; /* comment */
1714 set_make_variable( &make
->vars
, buffer
);
1717 input_file_name
= NULL
;
1722 /*******************************************************************
1723 * add_generated_sources
1725 static void add_generated_sources( struct makefile
*make
)
1727 struct incl_file
*source
, *next
, *file
;
1729 LIST_FOR_EACH_ENTRY_SAFE( source
, next
, &make
->sources
, struct incl_file
, entry
)
1731 if (source
->file
->flags
& FLAG_IDL_CLIENT
)
1733 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_c.c" ), NULL
);
1734 add_dependency( file
->file
, replace_extension( source
->name
, ".idl", ".h" ), INCL_NORMAL
);
1735 add_all_includes( make
, file
, file
->file
);
1737 if (source
->file
->flags
& FLAG_IDL_SERVER
)
1739 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_s.c" ), NULL
);
1740 add_dependency( file
->file
, "wine/exception.h", INCL_NORMAL
);
1741 add_dependency( file
->file
, replace_extension( source
->name
, ".idl", ".h" ), INCL_NORMAL
);
1742 add_all_includes( make
, file
, file
->file
);
1744 if (source
->file
->flags
& FLAG_IDL_IDENT
)
1746 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_i.c" ), NULL
);
1747 add_dependency( file
->file
, "rpc.h", INCL_NORMAL
);
1748 add_dependency( file
->file
, "rpcndr.h", INCL_NORMAL
);
1749 add_dependency( file
->file
, "guiddef.h", INCL_NORMAL
);
1750 add_all_includes( make
, file
, file
->file
);
1752 if (source
->file
->flags
& FLAG_IDL_PROXY
)
1754 file
= add_generated_source( make
, "dlldata.o", "dlldata.c" );
1755 add_dependency( file
->file
, "objbase.h", INCL_NORMAL
);
1756 add_dependency( file
->file
, "rpcproxy.h", INCL_NORMAL
);
1757 add_all_includes( make
, file
, file
->file
);
1758 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_p.c" ), NULL
);
1759 add_dependency( file
->file
, "objbase.h", INCL_NORMAL
);
1760 add_dependency( file
->file
, "rpcproxy.h", INCL_NORMAL
);
1761 add_dependency( file
->file
, "wine/exception.h", INCL_NORMAL
);
1762 add_dependency( file
->file
, replace_extension( source
->name
, ".idl", ".h" ), INCL_NORMAL
);
1763 add_all_includes( make
, file
, file
->file
);
1765 if (source
->file
->flags
& FLAG_IDL_TYPELIB
)
1767 add_generated_source( make
, replace_extension( source
->name
, ".idl", ".tlb" ), NULL
);
1769 if (source
->file
->flags
& FLAG_IDL_REGTYPELIB
)
1771 add_generated_source( make
, replace_extension( source
->name
, ".idl", "_t.res" ), NULL
);
1773 if (source
->file
->flags
& FLAG_IDL_REGISTER
)
1775 add_generated_source( make
, replace_extension( source
->name
, ".idl", "_r.res" ), NULL
);
1777 if (source
->file
->flags
& FLAG_IDL_HEADER
)
1779 add_generated_source( make
, replace_extension( source
->name
, ".idl", ".h" ), NULL
);
1781 if (!source
->file
->flags
&& strendswith( source
->name
, ".idl" ))
1783 add_generated_source( make
, replace_extension( source
->name
, ".idl", ".h" ), NULL
);
1785 if (strendswith( source
->name
, ".x" ))
1787 add_generated_source( make
, replace_extension( source
->name
, ".x", ".h" ), NULL
);
1789 if (strendswith( source
->name
, ".y" ))
1791 file
= add_generated_source( make
, replace_extension( source
->name
, ".y", ".tab.c" ), NULL
);
1792 /* steal the includes list from the source file */
1793 file
->files_count
= source
->files_count
;
1794 file
->files_size
= source
->files_size
;
1795 file
->files
= source
->files
;
1796 source
->files_count
= source
->files_size
= 0;
1797 source
->files
= NULL
;
1799 if (strendswith( source
->name
, ".l" ))
1801 file
= add_generated_source( make
, replace_extension( source
->name
, ".l", ".yy.c" ), NULL
);
1802 /* steal the includes list from the source file */
1803 file
->files_count
= source
->files_count
;
1804 file
->files_size
= source
->files_size
;
1805 file
->files
= source
->files
;
1806 source
->files_count
= source
->files_size
= 0;
1807 source
->files
= NULL
;
1809 if (source
->file
->flags
& FLAG_C_IMPLIB
)
1811 if (!make
->staticimplib
&& make
->importlib
&& *dll_ext
)
1812 make
->staticimplib
= strmake( "lib%s.def.a", make
->importlib
);
1817 file
= add_generated_source( make
, "testlist.o", "testlist.c" );
1818 add_dependency( file
->file
, "wine/test.h", INCL_NORMAL
);
1819 add_all_includes( make
, file
, file
->file
);
1824 /*******************************************************************
1827 static void create_dir( const char *dir
)
1831 p
= path
= xstrdup( dir
);
1832 while ((p
= strchr( p
, '/' )))
1835 if (mkdir( path
, 0755 ) == -1 && errno
!= EEXIST
) fatal_perror( "mkdir %s", path
);
1837 while (*p
== '/') p
++;
1839 if (mkdir( path
, 0755 ) == -1 && errno
!= EEXIST
) fatal_perror( "mkdir %s", path
);
1844 /*******************************************************************
1845 * create_file_directories
1847 * Create the base directories of all the files.
1849 static void create_file_directories( const struct makefile
*make
, struct strarray files
)
1851 struct strarray subdirs
= empty_strarray
;
1855 for (i
= 0; i
< files
.count
; i
++)
1857 if (!strchr( files
.str
[i
], '/' )) continue;
1858 dir
= base_dir_path( make
, files
.str
[i
] );
1859 *strrchr( dir
, '/' ) = 0;
1860 strarray_add_uniq( &subdirs
, dir
);
1863 for (i
= 0; i
< subdirs
.count
; i
++) create_dir( subdirs
.str
[i
] );
1867 /*******************************************************************
1868 * output_filenames_obj_dir
1870 static void output_filenames_obj_dir( const struct makefile
*make
, struct strarray array
)
1874 for (i
= 0; i
< array
.count
; i
++) output_filename( obj_dir_path( make
, array
.str
[i
] ));
1878 /*******************************************************************
1881 static void get_dependencies( struct strarray
*deps
, struct incl_file
*file
, struct incl_file
*source
)
1885 if (!file
->filename
) return;
1889 if (file
->owner
== source
) return; /* already processed */
1890 if (file
->type
== INCL_IMPORTLIB
&&
1891 !(source
->file
->flags
& (FLAG_IDL_TYPELIB
| FLAG_IDL_REGTYPELIB
)))
1892 return; /* library is imported only when building a typelib */
1893 file
->owner
= source
;
1894 strarray_add( deps
, file
->filename
);
1896 for (i
= 0; i
< file
->files_count
; i
++) get_dependencies( deps
, file
->files
[i
], source
);
1900 /*******************************************************************
1901 * get_local_dependencies
1903 * Get the local dependencies of a given target.
1905 static struct strarray
get_local_dependencies( const struct makefile
*make
, const char *name
,
1906 struct strarray targets
)
1909 struct strarray deps
= get_expanded_file_local_var( make
, name
, "DEPS" );
1911 for (i
= 0; i
< deps
.count
; i
++)
1913 if (strarray_exists( &targets
, deps
.str
[i
] ))
1914 deps
.str
[i
] = obj_dir_path( make
, deps
.str
[i
] );
1916 deps
.str
[i
] = src_dir_path( make
, deps
.str
[i
] );
1922 /*******************************************************************
1925 * Check if makefile builds the named static library.
1927 static int has_static_lib( const struct makefile
*make
, const char *name
)
1929 if (!make
->staticlib
) return 0;
1930 if (strncmp( make
->staticlib
, "lib", 3 )) return 0;
1931 if (strncmp( make
->staticlib
+ 3, name
, strlen(name
) )) return 0;
1932 return !strcmp( make
->staticlib
+ 3 + strlen(name
), ".a" );
1936 /*******************************************************************
1937 * add_default_libraries
1939 static struct strarray
add_default_libraries( const struct makefile
*make
, struct strarray
*deps
)
1941 struct strarray ret
= empty_strarray
;
1942 struct strarray all_libs
= empty_strarray
;
1945 strarray_add( &all_libs
, "-lwine_port" );
1946 strarray_addall( &all_libs
, get_expanded_make_var_array( make
, "EXTRALIBS" ));
1947 strarray_addall( &all_libs
, libs
);
1949 for (i
= 0; i
< all_libs
.count
; i
++)
1952 if (!strncmp( all_libs
.str
[i
], "-l", 2 ))
1954 const char *name
= all_libs
.str
[i
] + 2;
1956 for (j
= 0; j
< top_makefile
->subdirs
.count
; j
++)
1958 const struct makefile
*submake
= top_makefile
->submakes
[j
];
1960 if ((found
= has_static_lib( submake
, name
)))
1962 const char *lib
= strmake( "%s/lib%s.a",
1963 top_obj_dir_path( make
, submake
->base_dir
), name
);
1964 strarray_add( deps
, lib
);
1965 strarray_add( &ret
, lib
);
1970 if (!found
) strarray_add( &ret
, all_libs
.str
[i
] );
1976 /*******************************************************************
1979 static struct strarray
add_import_libs( const struct makefile
*make
, struct strarray
*deps
,
1980 struct strarray imports
, int cross
)
1982 struct strarray ret
= empty_strarray
;
1985 for (i
= 0; i
< imports
.count
; i
++)
1987 const char *name
= imports
.str
[i
];
1989 for (j
= 0; j
< top_makefile
->subdirs
.count
; j
++)
1991 const struct makefile
*submake
= top_makefile
->submakes
[j
];
1993 if (submake
->importlib
&& !strcmp( submake
->importlib
, name
))
1995 const char *dir
= top_obj_dir_path( make
, submake
->base_dir
);
1996 const char *ext
= cross
? "cross.a" : *dll_ext
? "def" : "a";
1998 strarray_add( deps
, strmake( "%s/lib%s.%s", dir
, name
, ext
));
1999 if (!cross
&& submake
->staticimplib
)
2000 strarray_add( deps
, strmake( "%s/%s", dir
, submake
->staticimplib
));
2004 if (has_static_lib( submake
, name
))
2006 const char *dir
= top_obj_dir_path( make
, submake
->base_dir
);
2008 strarray_add( deps
, strmake( "%s/lib%s.a", dir
, name
));
2012 strarray_add( &ret
, strmake( "-l%s", name
));
2018 /*******************************************************************
2019 * get_default_imports
2021 static struct strarray
get_default_imports( const struct makefile
*make
)
2023 struct strarray ret
= empty_strarray
;
2025 if (strarray_exists( &make
->extradllflags
, "-nodefaultlibs" )) return ret
;
2026 if (strarray_exists( &make
->appmode
, "-mno-cygwin" )) strarray_add( &ret
, "msvcrt" );
2027 if (make
->is_win16
) strarray_add( &ret
, "kernel" );
2028 strarray_add( &ret
, "kernel32" );
2029 strarray_add( &ret
, "ntdll" );
2030 strarray_add( &ret
, "winecrt0" );
2035 /*******************************************************************
2038 static void add_install_rule( const struct makefile
*make
, struct strarray
*install_rules
,
2039 const char *target
, const char *file
, const char *dest
)
2041 if (strarray_exists( &make
->install_lib
, target
))
2043 strarray_add( &install_rules
[INSTALL_LIB
], file
);
2044 strarray_add( &install_rules
[INSTALL_LIB
], dest
);
2046 else if (strarray_exists( &make
->install_dev
, target
))
2048 strarray_add( &install_rules
[INSTALL_DEV
], file
);
2049 strarray_add( &install_rules
[INSTALL_DEV
], dest
);
2054 /*******************************************************************
2055 * get_include_install_path
2057 * Determine the installation path for a given include file.
2059 static const char *get_include_install_path( const char *name
)
2061 if (!strncmp( name
, "wine/", 5 )) return name
+ 5;
2062 if (!strncmp( name
, "msvcrt/", 7 )) return name
;
2063 return strmake( "windows/%s", name
);
2067 /*******************************************************************
2068 * get_shared_library_name
2070 * Determine possible names for a shared library with a version number.
2072 static struct strarray
get_shared_lib_names( const char *libname
)
2074 struct strarray ret
= empty_strarray
;
2075 const char *ext
, *p
;
2076 char *name
, *first
, *second
;
2079 strarray_add( &ret
, libname
);
2081 for (p
= libname
; (p
= strchr( p
, '.' )); p
++)
2082 if ((len
= strspn( p
+ 1, "0123456789." ))) break;
2084 if (!len
) return ret
;
2086 if (*ext
&& ext
[-1] == '.') ext
--;
2088 /* keep only the first group of digits */
2089 name
= xstrdup( libname
);
2090 first
= name
+ (p
- libname
);
2091 if ((second
= strchr( first
+ 1, '.' )))
2093 strcpy( second
, ext
);
2094 strarray_add( &ret
, xstrdup( name
));
2096 /* now remove all digits */
2097 strcpy( first
, ext
);
2098 strarray_add( &ret
, name
);
2103 /*******************************************************************
2104 * output_install_rules
2106 * Rules are stored as a (file,dest) pair of values.
2107 * The first char of dest indicates the type of install.
2109 static struct strarray
output_install_rules( const struct makefile
*make
, struct strarray files
,
2110 const char *target
, struct strarray
*phony_targets
)
2114 struct strarray uninstall
= empty_strarray
;
2115 struct strarray targets
= empty_strarray
;
2117 if (!files
.count
) return uninstall
;
2119 for (i
= 0; i
< files
.count
; i
+= 2)
2120 if (strchr( "dps", files
.str
[i
+ 1][0] )) /* only for files copied from object dir */
2121 strarray_add_uniq( &targets
, files
.str
[i
] );
2123 output( "install %s::", target
);
2124 output_filenames_obj_dir( make
, targets
);
2127 install_sh
= top_dir_path( make
, "tools/install-sh" );
2128 for (i
= 0; i
< files
.count
; i
+= 2)
2130 const char *file
= files
.str
[i
];
2131 const char *dest
= files
.str
[i
+ 1];
2135 case 'd': /* data file */
2136 output( "\t%s -m 644 $(INSTALL_DATA_FLAGS) %s $(DESTDIR)%s\n",
2137 install_sh
, obj_dir_path( make
, file
), dest
+ 1 );
2139 case 'D': /* data file in source dir */
2140 output( "\t%s -m 644 $(INSTALL_DATA_FLAGS) %s $(DESTDIR)%s\n",
2141 install_sh
, src_dir_path( make
, file
), dest
+ 1 );
2143 case 'p': /* program file */
2144 output( "\tSTRIPPROG=\"$(STRIP)\" %s $(INSTALL_PROGRAM_FLAGS) %s $(DESTDIR)%s\n",
2145 install_sh
, obj_dir_path( make
, file
), dest
+ 1 );
2147 case 's': /* script */
2148 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s $(DESTDIR)%s\n",
2149 install_sh
, obj_dir_path( make
, file
), dest
+ 1 );
2151 case 'S': /* script in source dir */
2152 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s $(DESTDIR)%s\n",
2153 install_sh
, src_dir_path( make
, file
), dest
+ 1 );
2155 case 'y': /* symlink */
2156 output( "\trm -f $(DESTDIR)%s && %s %s $(DESTDIR)%s\n", dest
+ 1, ln_s
, file
, dest
+ 1 );
2163 for (i
= 0; i
< files
.count
; i
+= 2)
2164 strarray_add( &uninstall
, strmake( "$(DESTDIR)%s", files
.str
[i
+ 1] + 1 ));
2166 strarray_add_uniq( phony_targets
, "install" );
2167 strarray_add_uniq( phony_targets
, target
);
2172 /*******************************************************************
2173 * output_importlib_symlinks
2175 static struct strarray
output_importlib_symlinks( const struct makefile
*parent
,
2176 const struct makefile
*make
)
2178 struct strarray ret
= empty_strarray
;
2179 const char *dir
, *lib
;
2181 if (!make
->module
) return ret
;
2182 if (!make
->importlib
) return ret
;
2183 if (make
->is_win16
&& make
->disabled
) return ret
;
2184 if (strncmp( make
->base_dir
, "dlls/", 5 )) return ret
;
2185 if (!strcmp( make
->module
, make
->importlib
)) return ret
;
2186 if (!strchr( make
->importlib
, '.' ) &&
2187 !strncmp( make
->module
, make
->importlib
, strlen( make
->importlib
)) &&
2188 !strcmp( make
->module
+ strlen( make
->importlib
), ".dll" ))
2191 dir
= obj_dir_path( parent
, "dlls" );
2192 lib
= strmake( "lib%s.%s", make
->importlib
, *dll_ext
? "def" : "a" );
2193 output( "%s/%s: %s\n", dir
, lib
, base_dir_path( make
, lib
));
2194 output( "\trm -f $@ && %s %s/%s $@\n", ln_s
, make
->base_dir
+ strlen("dlls/"), lib
);
2195 strarray_add( &ret
, strmake( "%s/%s", dir
, lib
));
2197 if (crosstarget
&& !make
->is_win16
)
2199 lib
= strmake( "lib%s.cross.a", make
->importlib
);
2200 output( "%s/%s: %s\n", dir
, lib
, base_dir_path( make
, lib
));
2201 output( "\trm -f $@ && %s %s/%s $@\n", ln_s
, make
->base_dir
+ strlen("dlls/"), lib
);
2202 strarray_add( &ret
, strmake( "%s/%s", dir
, lib
));
2208 /*******************************************************************
2211 static void output_po_files( const struct makefile
*make
)
2213 const char *po_dir
= src_dir_path( make
, "po" );
2214 struct strarray pot_files
= empty_strarray
;
2215 struct incl_file
*source
;
2218 for (i
= 0; i
< make
->subdirs
.count
; i
++)
2220 struct makefile
*submake
= make
->submakes
[i
];
2222 LIST_FOR_EACH_ENTRY( source
, &submake
->sources
, struct incl_file
, entry
)
2224 if (strendswith( source
->name
, ".rc" ) && (source
->file
->flags
& FLAG_RC_PO
))
2226 char *pot_file
= replace_extension( source
->name
, ".rc", ".pot" );
2227 char *pot_path
= base_dir_path( submake
, pot_file
);
2228 output( "%s: tools/wrc include dummy\n", pot_path
);
2229 output( "\t@cd %s && $(MAKE) %s\n", base_dir_path( submake
, "" ), pot_file
);
2230 strarray_add( &pot_files
, pot_path
);
2232 else if (strendswith( source
->name
, ".mc" ))
2234 char *pot_file
= replace_extension( source
->name
, ".mc", ".pot" );
2235 char *pot_path
= base_dir_path( submake
, pot_file
);
2236 output( "%s: tools/wmc include dummy\n", pot_path
);
2237 output( "\t@cd %s && $(MAKE) %s\n", base_dir_path( submake
, "" ), pot_file
);
2238 strarray_add( &pot_files
, pot_path
);
2244 for (i
= 0; i
< linguas
.count
; i
++)
2245 output_filename( strmake( "%s/%s.po", po_dir
, linguas
.str
[i
] ));
2246 output( ": %s/wine.pot\n", po_dir
);
2247 output( "\tmsgmerge --previous -q $@ %s/wine.pot | msgattrib --no-obsolete -o $@.new && mv $@.new $@\n",
2250 output( "%s/wine.pot:", po_dir
);
2251 output_filenames( pot_files
);
2253 output( "\tmsgcat -o $@" );
2254 output_filenames( pot_files
);
2259 /*******************************************************************
2262 static struct strarray
output_sources( const struct makefile
*make
)
2264 struct incl_file
*source
;
2266 struct strarray object_files
= empty_strarray
;
2267 struct strarray crossobj_files
= empty_strarray
;
2268 struct strarray res_files
= empty_strarray
;
2269 struct strarray clean_files
= empty_strarray
;
2270 struct strarray uninstall_files
= empty_strarray
;
2271 struct strarray mo_files
= empty_strarray
;
2272 struct strarray ok_files
= empty_strarray
;
2273 struct strarray in_files
= empty_strarray
;
2274 struct strarray dlldata_files
= empty_strarray
;
2275 struct strarray c2man_files
= empty_strarray
;
2276 struct strarray implib_objs
= empty_strarray
;
2277 struct strarray includes
= empty_strarray
;
2278 struct strarray phony_targets
= empty_strarray
;
2279 struct strarray all_targets
= empty_strarray
;
2280 struct strarray install_rules
[NB_INSTALL_RULES
];
2281 char *ldrpath_local
= get_expanded_make_variable( make
, "LDRPATH_LOCAL" );
2282 char *ldrpath_install
= get_expanded_make_variable( make
, "LDRPATH_INSTALL" );
2284 for (i
= 0; i
< NB_INSTALL_RULES
; i
++) install_rules
[i
] = empty_strarray
;
2286 for (i
= 0; i
< linguas
.count
; i
++)
2287 strarray_add( &mo_files
, strmake( "%s/%s.mo", top_obj_dir_path( make
, "po" ), linguas
.str
[i
] ));
2289 strarray_add( &phony_targets
, "all" );
2290 strarray_add( &includes
, strmake( "-I%s", obj_dir_path( make
, "" )));
2291 if (make
->src_dir
) strarray_add( &includes
, strmake( "-I%s", make
->src_dir
));
2292 if (make
->parent_dir
) strarray_add( &includes
, strmake( "-I%s", src_dir_path( make
, make
->parent_dir
)));
2293 strarray_add( &includes
, strmake( "-I%s", top_obj_dir_path( make
, "include" )));
2294 if (make
->top_src_dir
) strarray_add( &includes
, strmake( "-I%s", top_dir_path( make
, "include" )));
2295 if (make
->use_msvcrt
) strarray_add( &includes
, strmake( "-I%s", top_dir_path( make
, "include/msvcrt" )));
2296 for (i
= 0; i
< make
->include_paths
.count
; i
++)
2297 strarray_add( &includes
, strmake( "-I%s", obj_dir_path( make
, make
->include_paths
.str
[i
] )));
2299 LIST_FOR_EACH_ENTRY( source
, &make
->sources
, struct incl_file
, entry
)
2301 struct strarray dependencies
= empty_strarray
;
2302 struct strarray extradefs
;
2303 char *obj
= xstrdup( source
->name
);
2304 char *ext
= get_extension( obj
);
2306 if (!ext
) fatal_error( "unsupported file type %s\n", source
->name
);
2309 extradefs
= get_expanded_file_local_var( make
, obj
, "EXTRADEFS" );
2310 get_dependencies( &dependencies
, source
, source
);
2312 if (!strcmp( ext
, "y" )) /* yacc file */
2314 /* add source file dependency for parallel makes */
2315 char *header
= strmake( "%s.tab.h", obj
);
2317 if (find_include_file( make
, header
))
2319 output( "%s: %s\n", obj_dir_path( make
, header
), source
->filename
);
2320 output( "\t$(BISON) -p %s_ -o %s.tab.c -d %s\n",
2321 obj
, obj_dir_path( make
, obj
), source
->filename
);
2322 output( "%s.tab.c: %s %s\n", obj_dir_path( make
, obj
),
2323 source
->filename
, obj_dir_path( make
, header
));
2324 strarray_add( &clean_files
, header
);
2326 else output( "%s.tab.c: %s\n", obj
, source
->filename
);
2328 output( "\t$(BISON) -p %s_ -o $@ %s\n", obj
, source
->filename
);
2330 else if (!strcmp( ext
, "x" )) /* template file */
2332 output( "%s.h: %s%s %s\n", obj_dir_path( make
, obj
),
2333 tools_dir_path( make
, "make_xftmpl" ), tools_ext
, source
->filename
);
2334 output( "\t%s%s -H -o $@ %s\n",
2335 tools_dir_path( make
, "make_xftmpl" ), tools_ext
, source
->filename
);
2336 if (source
->file
->flags
& FLAG_INSTALL
)
2338 strarray_add( &install_rules
[INSTALL_DEV
], source
->name
);
2339 strarray_add( &install_rules
[INSTALL_DEV
],
2340 strmake( "D$(includedir)/%s", get_include_install_path( source
->name
) ));
2341 strarray_add( &install_rules
[INSTALL_DEV
], strmake( "%s.h", obj
));
2342 strarray_add( &install_rules
[INSTALL_DEV
],
2343 strmake( "d$(includedir)/%s.h", get_include_install_path( obj
) ));
2346 else if (!strcmp( ext
, "l" )) /* lex file */
2348 output( "%s.yy.c: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2349 output( "\t$(FLEX) -o$@ %s\n", source
->filename
);
2351 else if (!strcmp( ext
, "rc" )) /* resource file */
2353 strarray_add( &res_files
, strmake( "%s.res", obj
));
2354 output( "%s.res: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2355 output( "\t%s -o $@", tools_path( make
, "wrc" ) );
2356 if (make
->is_win16
) output_filename( "-m16" );
2357 else output_filenames( target_flags
);
2358 output_filename( "--nostdinc" );
2359 output_filenames( includes
);
2360 output_filenames( make
->define_args
);
2361 output_filenames( extradefs
);
2362 if (mo_files
.count
&& (source
->file
->flags
& FLAG_RC_PO
))
2364 output_filename( strmake( "--po-dir=%s", top_obj_dir_path( make
, "po" )));
2365 output_filename( source
->filename
);
2367 output( "%s.res:", obj_dir_path( make
, obj
));
2368 output_filenames( mo_files
);
2373 output_filename( source
->filename
);
2376 if (source
->file
->flags
& FLAG_RC_PO
)
2378 strarray_add( &clean_files
, strmake( "%s.pot", obj
));
2379 output( "%s.pot: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2380 output( "\t%s -O pot -o $@", tools_path( make
, "wrc" ) );
2381 if (make
->is_win16
) output_filename( "-m16" );
2382 else output_filenames( target_flags
);
2383 output_filename( "--nostdinc" );
2384 output_filenames( includes
);
2385 output_filenames( make
->define_args
);
2386 output_filenames( extradefs
);
2387 output_filename( source
->filename
);
2389 output( "%s.pot ", obj_dir_path( make
, obj
));
2391 output( "%s.res:", obj_dir_path( make
, obj
));
2392 output_filename( tools_path( make
, "wrc" ));
2393 output_filenames( dependencies
);
2396 else if (!strcmp( ext
, "mc" )) /* message file */
2398 strarray_add( &res_files
, strmake( "%s.res", obj
));
2399 strarray_add( &clean_files
, strmake( "%s.pot", obj
));
2400 output( "%s.res: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2401 output( "\t%s -U -O res -o $@ %s", tools_path( make
, "wmc" ), source
->filename
);
2404 output_filename( strmake( "--po-dir=%s", top_obj_dir_path( make
, "po" )));
2406 output( "%s.res:", obj_dir_path( make
, obj
));
2407 output_filenames( mo_files
);
2410 output( "%s.pot: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2411 output( "\t%s -O pot -o $@ %s", tools_path( make
, "wmc" ), source
->filename
);
2413 output( "%s.pot %s.res:", obj_dir_path( make
, obj
), obj_dir_path( make
, obj
));
2414 output_filename( tools_path( make
, "wmc" ));
2415 output_filenames( dependencies
);
2418 else if (!strcmp( ext
, "idl" )) /* IDL file */
2420 struct strarray targets
= empty_strarray
;
2423 if (!source
->file
->flags
) source
->file
->flags
|= FLAG_IDL_HEADER
| FLAG_INSTALL
;
2424 if (find_include_file( make
, strmake( "%s.h", obj
))) source
->file
->flags
|= FLAG_IDL_HEADER
;
2426 for (i
= 0; i
< sizeof(idl_outputs
) / sizeof(idl_outputs
[0]); i
++)
2428 if (!(source
->file
->flags
& idl_outputs
[i
].flag
)) continue;
2429 dest
= strmake( "%s%s", obj
, idl_outputs
[i
].ext
);
2430 if (!find_src_file( make
, dest
)) strarray_add( &clean_files
, dest
);
2431 strarray_add( &targets
, dest
);
2433 if (source
->file
->flags
& FLAG_IDL_PROXY
) strarray_add( &dlldata_files
, source
->name
);
2434 if (source
->file
->flags
& FLAG_INSTALL
)
2436 strarray_add( &install_rules
[INSTALL_DEV
], xstrdup( source
->name
));
2437 strarray_add( &install_rules
[INSTALL_DEV
],
2438 strmake( "D$(includedir)/%s.idl", get_include_install_path( obj
) ));
2439 if (source
->file
->flags
& FLAG_IDL_HEADER
)
2441 strarray_add( &install_rules
[INSTALL_DEV
], strmake( "%s.h", obj
));
2442 strarray_add( &install_rules
[INSTALL_DEV
],
2443 strmake( "d$(includedir)/%s.h", get_include_install_path( obj
) ));
2446 if (!targets
.count
) continue;
2447 output_filenames_obj_dir( make
, targets
);
2448 output( ": %s\n", tools_path( make
, "widl" ));
2449 output( "\t%s -o $@", tools_path( make
, "widl" ) );
2450 output_filenames( target_flags
);
2451 output_filenames( includes
);
2452 output_filenames( make
->define_args
);
2453 output_filenames( extradefs
);
2454 output_filenames( get_expanded_make_var_array( make
, "EXTRAIDLFLAGS" ));
2455 output_filename( source
->filename
);
2457 output_filenames_obj_dir( make
, targets
);
2458 output( ": %s", source
->filename
);
2459 output_filenames( dependencies
);
2462 else if (!strcmp( ext
, "in" )) /* .in file or man page */
2464 if (strendswith( obj
, ".man" ) && source
->file
->args
)
2466 struct strarray symlinks
;
2467 char *dir
, *dest
= replace_extension( obj
, ".man", "" );
2468 char *lang
= strchr( dest
, '.' );
2469 char *section
= source
->file
->args
;
2473 dir
= strmake( "$(mandir)/%s/man%s", lang
, section
);
2475 else dir
= strmake( "$(mandir)/man%s", section
);
2476 add_install_rule( make
, install_rules
, dest
, xstrdup(obj
),
2477 strmake( "d%s/%s.%s", dir
, dest
, section
));
2478 symlinks
= get_expanded_file_local_var( make
, dest
, "SYMLINKS" );
2479 for (i
= 0; i
< symlinks
.count
; i
++)
2480 add_install_rule( make
, install_rules
, symlinks
.str
[i
],
2481 strmake( "%s.%s", dest
, section
),
2482 strmake( "y%s/%s.%s", dir
, symlinks
.str
[i
], section
));
2486 strarray_add( &in_files
, xstrdup(obj
) );
2487 strarray_add( &all_targets
, xstrdup(obj
) );
2488 output( "%s: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2489 output( "\t$(SED_CMD) %s >$@ || (rm -f $@ && false)\n", source
->filename
);
2490 output( "%s:", obj_dir_path( make
, obj
));
2491 output_filenames( dependencies
);
2493 add_install_rule( make
, install_rules
, obj
, xstrdup( obj
),
2494 strmake( "d$(datadir)/wine/%s", obj
));
2496 else if (!strcmp( ext
, "sfd" )) /* font file */
2498 char *ttf_file
= src_dir_path( make
, strmake( "%s.ttf", obj
));
2499 if (fontforge
&& !make
->src_dir
)
2501 output( "%s: %s\n", ttf_file
, source
->filename
);
2502 output( "\t%s -script %s %s $@\n",
2503 fontforge
, top_dir_path( make
, "fonts/genttf.ff" ), source
->filename
);
2504 if (!(source
->file
->flags
& FLAG_SFD_FONTS
)) output( "all: %s\n", ttf_file
);
2506 if (source
->file
->flags
& FLAG_INSTALL
)
2508 strarray_add( &install_rules
[INSTALL_LIB
], strmake( "%s.ttf", obj
));
2509 strarray_add( &install_rules
[INSTALL_LIB
], strmake( "D$(fontdir)/%s.ttf", obj
));
2511 if (source
->file
->flags
& FLAG_SFD_FONTS
)
2513 struct strarray
*array
= source
->file
->args
;
2515 for (i
= 0; i
< array
->count
; i
++)
2517 char *font
= strtok( xstrdup(array
->str
[i
]), " \t" );
2518 char *args
= strtok( NULL
, "" );
2520 strarray_add( &all_targets
, xstrdup( font
));
2521 output( "%s: %s %s\n", obj_dir_path( make
, font
),
2522 tools_path( make
, "sfnt2fon" ), ttf_file
);
2523 output( "\t%s -o $@ %s %s\n", tools_path( make
, "sfnt2fon" ), ttf_file
, args
);
2524 strarray_add( &install_rules
[INSTALL_LIB
], xstrdup(font
) );
2525 strarray_add( &install_rules
[INSTALL_LIB
], strmake( "d$(fontdir)/%s", font
));
2529 else if (!strcmp( ext
, "svg" )) /* svg file */
2531 if (convert
&& rsvg
&& icotool
&& !make
->src_dir
)
2533 output( "%s.ico %s.bmp: %s\n",
2534 src_dir_path( make
, obj
), src_dir_path( make
, obj
), source
->filename
);
2535 output( "\tCONVERT=\"%s\" ICOTOOL=\"%s\" RSVG=\"%s\" %s %s $@\n", convert
, icotool
, rsvg
,
2536 top_dir_path( make
, "tools/buildimage" ), source
->filename
);
2539 else if (!strcmp( ext
, "res" ))
2541 strarray_add( &res_files
, source
->name
);
2543 else if (!strcmp( ext
, "tlb" ))
2545 strarray_add( &all_targets
, source
->name
);
2547 else if (!strcmp( ext
, "h" ) || !strcmp( ext
, "rh" ) || !strcmp( ext
, "inl" )) /* header file */
2549 if (source
->file
->flags
& FLAG_GENERATED
)
2551 strarray_add( &all_targets
, source
->name
);
2555 strarray_add( &install_rules
[INSTALL_DEV
], source
->name
);
2556 strarray_add( &install_rules
[INSTALL_DEV
],
2557 strmake( "D$(includedir)/%s", get_include_install_path( source
->name
) ));
2562 int need_cross
= make
->testdll
||
2563 (source
->file
->flags
& FLAG_C_IMPLIB
) ||
2564 (make
->module
&& make
->staticlib
);
2566 if ((source
->file
->flags
& FLAG_GENERATED
) &&
2567 (!make
->testdll
|| !strendswith( source
->filename
, "testlist.c" )))
2568 strarray_add( &clean_files
, source
->filename
);
2569 if (source
->file
->flags
& FLAG_C_IMPLIB
) strarray_add( &implib_objs
, strmake( "%s.o", obj
));
2570 strarray_add( &object_files
, strmake( "%s.o", obj
));
2571 output( "%s.o: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2572 output( "\t$(CC) -c -o $@ %s", source
->filename
);
2573 output_filenames( includes
);
2574 output_filenames( make
->define_args
);
2575 output_filenames( extradefs
);
2576 if (make
->module
|| make
->staticlib
|| make
->sharedlib
|| make
->testdll
)
2578 output_filenames( dll_flags
);
2579 if (make
->use_msvcrt
) output_filenames( msvcrt_flags
);
2581 output_filenames( extra_cflags
);
2582 output_filenames( cpp_flags
);
2583 output_filename( "$(CFLAGS)" );
2585 if (crosstarget
&& need_cross
)
2587 strarray_add( &crossobj_files
, strmake( "%s.cross.o", obj
));
2588 output( "%s.cross.o: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2589 output( "\t$(CROSSCC) -c -o $@ %s", source
->filename
);
2590 output_filenames( includes
);
2591 output_filenames( make
->define_args
);
2592 output_filenames( extradefs
);
2593 output_filename( "-DWINE_CROSSTEST" );
2594 output_filenames( cpp_flags
);
2595 output_filename( "$(CFLAGS)" );
2598 if (make
->testdll
&& !strcmp( ext
, "c" ) && !(source
->file
->flags
& FLAG_GENERATED
))
2600 strarray_add( &ok_files
, strmake( "%s.ok", obj
));
2601 output( "%s.ok:\n", obj_dir_path( make
, obj
));
2602 output( "\t%s $(RUNTESTFLAGS) -T %s -M %s -p %s%s %s && touch $@\n",
2603 top_dir_path( make
, "tools/runtest" ), top_obj_dir_path( make
, "" ), make
->testdll
,
2604 replace_extension( make
->testdll
, ".dll", "_test.exe" ), dll_ext
, obj
);
2606 if (!strcmp( ext
, "c" ) && !(source
->file
->flags
& FLAG_GENERATED
))
2607 strarray_add( &c2man_files
, source
->filename
);
2608 output( "%s.o", obj_dir_path( make
, obj
));
2609 if (crosstarget
&& need_cross
) output( " %s.cross.o", obj_dir_path( make
, obj
));
2611 output_filenames( dependencies
);
2617 /* rules for files that depend on multiple sources */
2619 if (dlldata_files
.count
)
2621 output( "%s: %s %s\n", obj_dir_path( make
, "dlldata.c" ),
2622 tools_path( make
, "widl" ), src_dir_path( make
, "Makefile.in" ));
2623 output( "\t%s --dlldata-only -o $@", tools_path( make
, "widl" ));
2624 output_filenames( dlldata_files
);
2628 if (make
->module
&& !make
->staticlib
)
2630 struct strarray all_libs
= empty_strarray
;
2631 struct strarray dep_libs
= empty_strarray
;
2632 char *module_path
= obj_dir_path( make
, make
->module
);
2633 char *spec_file
= NULL
;
2635 if (!make
->appmode
.count
)
2636 spec_file
= src_dir_path( make
, replace_extension( make
->module
, ".dll", ".spec" ));
2637 strarray_addall( &all_libs
, add_import_libs( make
, &dep_libs
, make
->delayimports
, 0 ));
2638 strarray_addall( &all_libs
, add_import_libs( make
, &dep_libs
, make
->imports
, 0 ));
2639 add_import_libs( make
, &dep_libs
, get_default_imports( make
), 0 ); /* dependencies only */
2640 strarray_addall( &all_libs
, add_default_libraries( make
, &dep_libs
));
2644 for (i
= 0; i
< make
->delayimports
.count
; i
++)
2645 strarray_add( &all_libs
, strmake( "-Wb,-d%s", make
->delayimports
.str
[i
] ));
2646 strarray_add( &all_targets
, strmake( "%s%s", make
->module
, dll_ext
));
2647 strarray_add( &all_targets
, strmake( "%s.fake", make
->module
));
2648 add_install_rule( make
, install_rules
, make
->module
, strmake( "%s%s", make
->module
, dll_ext
),
2649 strmake( "p$(dlldir)/%s%s", make
->module
, dll_ext
));
2650 add_install_rule( make
, install_rules
, make
->module
, strmake( "%s.fake", make
->module
),
2651 strmake( "d$(fakedlldir)/%s", make
->module
));
2652 output( "%s%s %s.fake:", module_path
, dll_ext
, module_path
);
2656 strarray_add( &all_libs
, "-lwine" );
2657 strarray_add( &all_targets
, make
->module
);
2658 add_install_rule( make
, install_rules
, make
->module
, make
->module
,
2659 strmake( "p$(%s)/%s", spec_file
? "dlldir" : "bindir", make
->module
));
2660 output( "%s:", module_path
);
2662 if (spec_file
) output_filename( spec_file
);
2663 output_filenames_obj_dir( make
, object_files
);
2664 output_filenames_obj_dir( make
, res_files
);
2665 output_filenames( dep_libs
);
2667 output( "\t%s -o $@", tools_path( make
, "winegcc" ));
2668 output_filename( strmake( "-B%s", tools_dir_path( make
, "winebuild" )));
2669 if (tools_dir
) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make
, "" )));
2670 output_filenames( target_flags
);
2671 output_filenames( unwind_flags
);
2674 output( " -shared %s", spec_file
);
2675 output_filenames( make
->extradllflags
);
2677 else output_filenames( make
->appmode
);
2678 output_filenames_obj_dir( make
, object_files
);
2679 output_filenames_obj_dir( make
, res_files
);
2680 output_filenames( all_libs
);
2681 output_filename( "$(LDFLAGS)" );
2684 if (spec_file
&& make
->importlib
)
2686 char *importlib_path
= obj_dir_path( make
, strmake( "lib%s", make
->importlib
));
2689 strarray_add( &clean_files
, strmake( "lib%s.def", make
->importlib
));
2690 output( "%s.def: %s %s\n", importlib_path
, tools_path( make
, "winebuild" ), spec_file
);
2691 output( "\t%s -w --def -o $@ --export %s", tools_path( make
, "winebuild" ), spec_file
);
2692 output_filenames( target_flags
);
2693 if (make
->is_win16
) output_filename( "-m16" );
2695 add_install_rule( make
, install_rules
, make
->importlib
,
2696 strmake( "lib%s.def", make
->importlib
),
2697 strmake( "d$(dlldir)/lib%s.def", make
->importlib
));
2698 if (implib_objs
.count
)
2700 strarray_add( &clean_files
, strmake( "lib%s.def.a", make
->importlib
));
2701 output( "%s.def.a:", importlib_path
);
2702 output_filenames_obj_dir( make
, implib_objs
);
2704 output( "\trm -f $@\n" );
2705 output( "\t$(AR) $(ARFLAGS) $@" );
2706 output_filenames_obj_dir( make
, implib_objs
);
2708 output( "\t$(RANLIB) $@\n" );
2709 add_install_rule( make
, install_rules
, make
->importlib
,
2710 strmake( "lib%s.def.a", make
->importlib
),
2711 strmake( "d$(dlldir)/lib%s.def.a", make
->importlib
));
2716 strarray_add( &clean_files
, strmake( "lib%s.a", make
->importlib
));
2717 output( "%s.a: %s %s", importlib_path
, tools_path( make
, "winebuild" ), spec_file
);
2718 output_filenames_obj_dir( make
, implib_objs
);
2720 output( "\t%s -w --implib -o $@ --export %s", tools_path( make
, "winebuild" ), spec_file
);
2721 output_filenames( target_flags
);
2722 output_filenames_obj_dir( make
, implib_objs
);
2724 add_install_rule( make
, install_rules
, make
->importlib
,
2725 strmake( "lib%s.a", make
->importlib
),
2726 strmake( "d$(dlldir)/lib%s.a", make
->importlib
));
2728 if (crosstarget
&& !make
->is_win16
)
2730 struct strarray cross_files
= strarray_replace_extension( &implib_objs
, ".o", ".cross.o" );
2731 strarray_add( &clean_files
, strmake( "lib%s.cross.a", make
->importlib
));
2732 output( "%s.cross.a: %s %s", importlib_path
, tools_path( make
, "winebuild" ), spec_file
);
2733 output_filenames_obj_dir( make
, cross_files
);
2735 output( "\t%s -b %s -w --implib -o $@ --export %s",
2736 tools_path( make
, "winebuild" ), crosstarget
, spec_file
);
2737 output_filenames_obj_dir( make
, cross_files
);
2744 if (c2man_files
.count
)
2746 output( "manpages::\n" );
2747 output( "\t%s -w %s", top_dir_path( make
, "tools/c2man.pl" ), spec_file
);
2748 output_filename( strmake( "-R%s", top_dir_path( make
, "" )));
2749 output_filename( strmake( "-I%s", top_dir_path( make
, "include" )));
2750 output_filename( strmake( "-o %s/man%s",
2751 top_obj_dir_path( make
, "documentation" ), man_ext
));
2752 output_filenames( c2man_files
);
2754 output( "htmlpages::\n" );
2755 output( "\t%s -Th -w %s", top_dir_path( make
, "tools/c2man.pl" ), spec_file
);
2756 output_filename( strmake( "-R%s", top_dir_path( make
, "" )));
2757 output_filename( strmake( "-I%s", top_dir_path( make
, "include" )));
2758 output_filename( strmake( "-o %s",
2759 top_obj_dir_path( make
, "documentation/html" )));
2760 output_filenames( c2man_files
);
2762 output( "sgmlpages::\n" );
2763 output( "\t%s -Ts -w %s", top_dir_path( make
, "tools/c2man.pl" ), spec_file
);
2764 output_filename( strmake( "-R%s", top_dir_path( make
, "" )));
2765 output_filename( strmake( "-I%s", top_dir_path( make
, "include" )));
2766 output_filename( strmake( "-o %s",
2767 top_obj_dir_path( make
, "documentation/api-guide" )));
2768 output_filenames( c2man_files
);
2770 output( "xmlpages::\n" );
2771 output( "\t%s -Tx -w %s", top_dir_path( make
, "tools/c2man.pl" ), spec_file
);
2772 output_filename( strmake( "-R%s", top_dir_path( make
, "" )));
2773 output_filename( strmake( "-I%s", top_dir_path( make
, "include" )));
2774 output_filename( strmake( "-o %s",
2775 top_obj_dir_path( make
, "documentation/api-guide-xml" )));
2776 output_filenames( c2man_files
);
2778 strarray_add( &phony_targets
, "manpages" );
2779 strarray_add( &phony_targets
, "htmlpages" );
2780 strarray_add( &phony_targets
, "sgmlpages" );
2781 strarray_add( &phony_targets
, "xmlpages" );
2783 else output( "manpages htmlpages sgmlpages xmlpages::\n" );
2787 char *binary
= replace_extension( make
->module
, ".exe", "" );
2788 add_install_rule( make
, install_rules
, binary
, tools_dir_path( make
, "wineapploader" ),
2789 strmake( "s$(bindir)/%s", binary
));
2793 if (make
->staticlib
)
2795 strarray_add( &all_targets
, make
->staticlib
);
2796 output( "%s:", obj_dir_path( make
, make
->staticlib
));
2797 output_filenames_obj_dir( make
, object_files
);
2798 output( "\n\trm -f $@\n" );
2799 output( "\t$(AR) $(ARFLAGS) $@" );
2800 output_filenames_obj_dir( make
, object_files
);
2801 output( "\n\t$(RANLIB) $@\n" );
2802 if (crosstarget
&& make
->module
)
2804 char *name
= replace_extension( make
->staticlib
, ".a", ".cross.a" );
2806 strarray_add( &all_targets
, name
);
2807 output( "%s:", obj_dir_path( make
, name
));
2808 output_filenames_obj_dir( make
, crossobj_files
);
2809 output( "\n\trm -f $@\n" );
2810 output( "\t%s-ar $(ARFLAGS) $@", crosstarget
);
2811 output_filenames_obj_dir( make
, crossobj_files
);
2812 output( "\n\t%s-ranlib $@\n", crosstarget
);
2816 if (make
->sharedlib
)
2819 struct strarray names
= get_shared_lib_names( make
->sharedlib
);
2820 struct strarray all_libs
= empty_strarray
;
2821 struct strarray dep_libs
= empty_strarray
;
2823 basename
= xstrdup( make
->sharedlib
);
2824 if ((p
= strchr( basename
, '.' ))) *p
= 0;
2826 strarray_addall( &dep_libs
, get_local_dependencies( make
, basename
, in_files
));
2827 strarray_addall( &all_libs
, get_expanded_file_local_var( make
, basename
, "LDFLAGS" ));
2828 strarray_addall( &all_libs
, add_default_libraries( make
, &dep_libs
));
2830 output( "%s:", obj_dir_path( make
, make
->sharedlib
));
2831 output_filenames_obj_dir( make
, object_files
);
2832 output_filenames( dep_libs
);
2834 output( "\t$(CC) -o $@" );
2835 output_filenames_obj_dir( make
, object_files
);
2836 output_filenames( all_libs
);
2837 output_filename( "$(LDFLAGS)" );
2839 add_install_rule( make
, install_rules
, make
->sharedlib
, make
->sharedlib
,
2840 strmake( "p$(libdir)/%s", make
->sharedlib
));
2841 for (i
= 1; i
< names
.count
; i
++)
2843 output( "%s: %s\n", obj_dir_path( make
, names
.str
[i
] ), obj_dir_path( make
, names
.str
[i
-1] ));
2844 output( "\trm -f $@ && %s %s $@\n", ln_s
, names
.str
[i
-1] );
2845 add_install_rule( make
, install_rules
, names
.str
[i
], names
.str
[i
-1],
2846 strmake( "y$(libdir)/%s", names
.str
[i
] ));
2848 strarray_addall( &all_targets
, names
);
2851 if (make
->importlib
&& !make
->module
) /* stand-alone import lib (for libwine) */
2853 char *def_file
= replace_extension( make
->importlib
, ".a", ".def" );
2855 if (!strncmp( def_file
, "lib", 3 )) def_file
+= 3;
2856 output( "%s: %s\n", obj_dir_path( make
, make
->importlib
), src_dir_path( make
, def_file
));
2857 output( "\t%s -l $@ -d %s\n", dlltool
, src_dir_path( make
, def_file
));
2858 add_install_rule( make
, install_rules
, make
->importlib
, make
->importlib
,
2859 strmake( "d$(libdir)/%s", make
->importlib
));
2860 strarray_add( &all_targets
, make
->importlib
);
2865 char *testmodule
= replace_extension( make
->testdll
, ".dll", "_test.exe" );
2866 char *stripped
= replace_extension( make
->testdll
, ".dll", "_test-stripped.exe" );
2867 char *testres
= replace_extension( make
->testdll
, ".dll", "_test.res" );
2868 struct strarray dep_libs
= empty_strarray
;
2869 struct strarray all_libs
= add_import_libs( make
, &dep_libs
, make
->imports
, 0 );
2871 add_import_libs( make
, &dep_libs
, get_default_imports( make
), 0 ); /* dependencies only */
2872 strarray_addall( &all_libs
, libs
);
2873 strarray_add( &all_targets
, strmake( "%s%s", testmodule
, dll_ext
));
2874 strarray_add( &clean_files
, strmake( "%s%s", stripped
, dll_ext
));
2875 output( "%s%s:\n", obj_dir_path( make
, testmodule
), dll_ext
);
2876 output( "\t%s -o $@", tools_path( make
, "winegcc" ));
2877 output_filename( strmake( "-B%s", tools_dir_path( make
, "winebuild" )));
2878 if (tools_dir
) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make
, "" )));
2879 output_filenames( target_flags
);
2880 output_filenames( unwind_flags
);
2881 output_filenames( make
->appmode
);
2882 output_filenames_obj_dir( make
, object_files
);
2883 output_filenames_obj_dir( make
, res_files
);
2884 output_filenames( all_libs
);
2885 output_filename( "$(LDFLAGS)" );
2887 output( "%s%s:\n", obj_dir_path( make
, stripped
), dll_ext
);
2888 output( "\t%s -o $@", tools_path( make
, "winegcc" ));
2889 output_filename( strmake( "-B%s", tools_dir_path( make
, "winebuild" )));
2890 if (tools_dir
) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make
, "" )));
2891 output_filenames( target_flags
);
2892 output_filenames( unwind_flags
);
2893 output_filename( strmake( "-Wb,-F,%s", testmodule
));
2894 output_filenames( make
->appmode
);
2895 output_filenames_obj_dir( make
, object_files
);
2896 output_filenames_obj_dir( make
, res_files
);
2897 output_filenames( all_libs
);
2898 output_filename( "$(LDFLAGS)" );
2900 output( "%s%s %s%s:", obj_dir_path( make
, testmodule
), dll_ext
,
2901 obj_dir_path( make
, stripped
), dll_ext
);
2902 output_filenames_obj_dir( make
, object_files
);
2903 output_filenames_obj_dir( make
, res_files
);
2904 output_filenames( dep_libs
);
2907 if (!make
->disabled
)
2908 output( "all: %s/%s\n", top_obj_dir_path( make
, "programs/winetest" ), testres
);
2909 output( "%s/%s: %s%s\n", top_obj_dir_path( make
, "programs/winetest" ), testres
,
2910 obj_dir_path( make
, stripped
), dll_ext
);
2911 output( "\techo \"%s TESTRES \\\"%s%s\\\"\" | %s -o $@\n",
2912 testmodule
, obj_dir_path( make
, stripped
), dll_ext
, tools_path( make
, "wrc" ));
2916 char *crosstest
= replace_extension( make
->testdll
, ".dll", "_crosstest.exe" );
2918 dep_libs
= empty_strarray
;
2919 all_libs
= add_import_libs( make
, &dep_libs
, make
->imports
, 1 );
2920 add_import_libs( make
, &dep_libs
, get_default_imports( make
), 1 ); /* dependencies only */
2921 strarray_addall( &all_libs
, libs
);
2922 strarray_add( &clean_files
, crosstest
);
2923 output( "%s:", obj_dir_path( make
, crosstest
));
2924 output_filenames_obj_dir( make
, crossobj_files
);
2925 output_filenames_obj_dir( make
, res_files
);
2926 output_filenames( dep_libs
);
2928 output( "\t%s -o $@ -b %s", tools_path( make
, "winegcc" ), crosstarget
);
2929 output_filename( strmake( "-B%s", tools_dir_path( make
, "winebuild" )));
2930 if (tools_dir
) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make
, "" )));
2931 output_filename( "--lib-suffix=.cross.a" );
2932 output_filenames_obj_dir( make
, crossobj_files
);
2933 output_filenames_obj_dir( make
, res_files
);
2934 output_filenames( all_libs
);
2935 output_filename( "$(LDFLAGS)" );
2937 if (!make
->disabled
)
2939 output( "%s: %s\n", obj_dir_path( make
, "crosstest" ), obj_dir_path( make
, crosstest
));
2940 strarray_add( &phony_targets
, obj_dir_path( make
, "crosstest" ));
2941 if (make
->obj_dir
) output( "crosstest: %s\n", obj_dir_path( make
, "crosstest" ));
2945 output_filenames_obj_dir( make
, ok_files
);
2946 output( ": %s%s ../%s%s\n", testmodule
, dll_ext
, make
->testdll
, dll_ext
);
2947 if (!make
->disabled
)
2949 output( "check test:" );
2950 output_filenames_obj_dir( make
, ok_files
);
2952 strarray_add( &phony_targets
, "check" );
2953 strarray_add( &phony_targets
, "test" );
2955 output( "testclean::\n" );
2956 output( "\trm -f" );
2957 output_filenames_obj_dir( make
, ok_files
);
2959 strarray_addall( &clean_files
, ok_files
);
2960 strarray_add( &phony_targets
, "testclean" );
2963 for (i
= 0; i
< make
->programs
.count
; i
++)
2965 char *program_installed
= NULL
;
2966 char *program
= strmake( "%s%s", make
->programs
.str
[i
], exe_ext
);
2967 struct strarray deps
= get_local_dependencies( make
, make
->programs
.str
[i
], in_files
);
2968 struct strarray all_libs
= get_expanded_file_local_var( make
, make
->programs
.str
[i
], "LDFLAGS" );
2969 struct strarray objs
= get_expanded_file_local_var( make
, make
->programs
.str
[i
], "OBJS" );
2970 struct strarray symlinks
= get_expanded_file_local_var( make
, make
->programs
.str
[i
], "SYMLINKS" );
2972 if (!objs
.count
) objs
= object_files
;
2973 strarray_addall( &all_libs
, add_default_libraries( make
, &deps
));
2975 output( "%s:", obj_dir_path( make
, program
) );
2976 output_filenames_obj_dir( make
, objs
);
2977 output_filenames( deps
);
2979 output( "\t$(CC) -o $@" );
2980 output_filenames_obj_dir( make
, objs
);
2982 if (strarray_exists( &all_libs
, "-lwine" ))
2984 strarray_add( &all_libs
, strmake( "-L%s", top_obj_dir_path( make
, "libs/wine" )));
2985 if (ldrpath_local
&& ldrpath_install
)
2987 program_installed
= strmake( "%s-installed%s", make
->programs
.str
[i
], exe_ext
);
2988 output_filename( ldrpath_local
);
2989 output_filenames( all_libs
);
2990 output_filename( "$(LDFLAGS)" );
2992 output( "%s:", obj_dir_path( make
, program_installed
) );
2993 output_filenames_obj_dir( make
, objs
);
2994 output_filenames( deps
);
2996 output( "\t$(CC) -o $@" );
2997 output_filenames_obj_dir( make
, objs
);
2998 output_filename( ldrpath_install
);
2999 strarray_add( &all_targets
, program_installed
);
3003 output_filenames( all_libs
);
3004 output_filename( "$(LDFLAGS)" );
3006 strarray_add( &all_targets
, program
);
3010 output_filenames_obj_dir( make
, symlinks
);
3011 output( ": %s\n", obj_dir_path( make
, program
));
3012 output( "\trm -f $@ && %s %s $@\n", ln_s
, obj_dir_path( make
, program
));
3013 strarray_addall( &all_targets
, symlinks
);
3016 add_install_rule( make
, install_rules
, program
, program_installed
? program_installed
: program
,
3017 strmake( "p$(bindir)/%s", program
));
3018 for (j
= 0; j
< symlinks
.count
; j
++)
3019 add_install_rule( make
, install_rules
, symlinks
.str
[j
], program
,
3020 strmake( "y$(bindir)/%s%s", symlinks
.str
[j
], exe_ext
));
3023 for (i
= 0; i
< make
->scripts
.count
; i
++)
3024 add_install_rule( make
, install_rules
, make
->scripts
.str
[i
], make
->scripts
.str
[i
],
3025 strmake( "S$(bindir)/%s", make
->scripts
.str
[i
] ));
3027 if (!make
->disabled
)
3029 if (all_targets
.count
)
3032 output_filenames_obj_dir( make
, all_targets
);
3035 strarray_addall( &uninstall_files
, output_install_rules( make
, install_rules
[INSTALL_LIB
],
3036 "install-lib", &phony_targets
));
3037 strarray_addall( &uninstall_files
, output_install_rules( make
, install_rules
[INSTALL_DEV
],
3038 "install-dev", &phony_targets
));
3039 if (uninstall_files
.count
)
3041 output( "uninstall::\n" );
3042 output( "\trm -f" );
3043 output_filenames( uninstall_files
);
3045 strarray_add_uniq( &phony_targets
, "uninstall" );
3049 strarray_addall( &clean_files
, object_files
);
3050 strarray_addall( &clean_files
, crossobj_files
);
3051 strarray_addall( &clean_files
, res_files
);
3052 strarray_addall( &clean_files
, all_targets
);
3053 strarray_addall( &clean_files
, get_expanded_make_var_array( make
, "EXTRA_TARGETS" ));
3055 if (make
->subdirs
.count
)
3057 struct strarray build_deps
= empty_strarray
;
3058 struct strarray makefile_deps
= empty_strarray
;
3059 struct strarray distclean_files
= get_expanded_make_var_array( make
, "CONFIGURE_TARGETS" );
3061 strarray_add( &distclean_files
, obj_dir_path( make
, output_makefile_name
));
3062 if (!make
->src_dir
) strarray_add( &distclean_files
, obj_dir_path( make
, ".gitignore" ));
3063 for (i
= 0; i
< make
->subdirs
.count
; i
++)
3065 const struct makefile
*submake
= make
->submakes
[i
];
3067 strarray_add( &makefile_deps
, top_dir_path( make
, base_dir_path( submake
,
3068 strmake ( "%s.in", output_makefile_name
))));
3069 strarray_add( &distclean_files
, base_dir_path( submake
, output_makefile_name
));
3070 if (!make
->src_dir
) strarray_add( &distclean_files
, base_dir_path( submake
, ".gitignore" ));
3071 if (submake
->testdll
) strarray_add( &distclean_files
, base_dir_path( submake
, "testlist.c" ));
3072 strarray_addall( &build_deps
, output_importlib_symlinks( make
, submake
));
3074 output( "Makefile:" );
3075 output_filenames( makefile_deps
);
3077 output( "distclean::\n");
3078 output( "\trm -f" );
3079 output_filenames( distclean_files
);
3081 strarray_add( &phony_targets
, "distclean" );
3083 if (msgfmt
&& strcmp( msgfmt
, "false" ))
3085 strarray_addall( &build_deps
, mo_files
);
3086 for (i
= 0; i
< linguas
.count
; i
++)
3088 output( "%s/%s.mo:", obj_dir_path( make
, "po" ), linguas
.str
[i
] );
3089 output( " %s/%s.po\n", src_dir_path( make
, "po" ), linguas
.str
[i
] );
3090 output( "\t%s -o $@ %s/%s.po\n", msgfmt
, src_dir_path( make
, "po" ), linguas
.str
[i
] );
3093 if (build_deps
.count
)
3095 output( "__builddeps__:" );
3096 output_filenames( build_deps
);
3098 strarray_addall( &clean_files
, build_deps
);
3100 if (get_expanded_make_variable( make
, "GETTEXTPO_LIBS" )) output_po_files( make
);
3103 if (clean_files
.count
)
3105 output( "%s::\n", obj_dir_path( make
, "clean" ));
3106 output( "\trm -f" );
3107 output_filenames_obj_dir( make
, clean_files
);
3109 if (make
->obj_dir
) output( "__clean__: %s\n", obj_dir_path( make
, "clean" ));
3110 strarray_add( &phony_targets
, obj_dir_path( make
, "clean" ));
3113 if (phony_targets
.count
)
3115 output( ".PHONY:" );
3116 output_filenames( phony_targets
);
3120 if (!make
->base_dir
)
3121 strarray_addall( &clean_files
, get_expanded_make_var_array( make
, "CONFIGURE_TARGETS" ));
3126 /*******************************************************************
3129 static FILE *create_temp_file( const char *orig
)
3131 char *name
= xmalloc( strlen(orig
) + 13 );
3132 unsigned int i
, id
= getpid();
3136 for (i
= 0; i
< 100; i
++)
3138 sprintf( name
, "%s.tmp%08x", orig
, id
);
3139 if ((fd
= open( name
, O_RDWR
| O_CREAT
| O_EXCL
, 0666 )) != -1)
3141 ret
= fdopen( fd
, "w" );
3144 if (errno
!= EEXIST
) break;
3147 if (!ret
) fatal_error( "failed to create output file for '%s'\n", orig
);
3148 temp_file_name
= name
;
3153 /*******************************************************************
3156 static void rename_temp_file( const char *dest
)
3158 int ret
= rename( temp_file_name
, dest
);
3159 if (ret
== -1 && errno
== EEXIST
)
3161 /* rename doesn't overwrite on windows */
3163 ret
= rename( temp_file_name
, dest
);
3165 if (ret
== -1) fatal_error( "failed to rename output file to '%s'\n", dest
);
3166 temp_file_name
= NULL
;
3170 /*******************************************************************
3171 * are_files_identical
3173 static int are_files_identical( FILE *file1
, FILE *file2
)
3177 char buffer1
[8192], buffer2
[8192];
3178 int size1
= fread( buffer1
, 1, sizeof(buffer1
), file1
);
3179 int size2
= fread( buffer2
, 1, sizeof(buffer2
), file2
);
3180 if (size1
!= size2
) return 0;
3181 if (!size1
) return feof( file1
) && feof( file2
);
3182 if (memcmp( buffer1
, buffer2
, size1
)) return 0;
3187 /*******************************************************************
3188 * rename_temp_file_if_changed
3190 static void rename_temp_file_if_changed( const char *dest
)
3192 FILE *file1
, *file2
;
3195 if ((file1
= fopen( dest
, "r" )))
3197 if ((file2
= fopen( temp_file_name
, "r" )))
3199 do_rename
= !are_files_identical( file1
, file2
);
3206 unlink( temp_file_name
);
3207 temp_file_name
= NULL
;
3209 else rename_temp_file( dest
);
3213 /*******************************************************************
3216 static void output_testlist( const struct makefile
*make
)
3218 const char *dest
= base_dir_path( make
, "testlist.c" );
3219 struct strarray files
= empty_strarray
;
3220 struct incl_file
*source
;
3223 LIST_FOR_EACH_ENTRY( source
, &make
->sources
, struct incl_file
, entry
)
3225 if (source
->file
->flags
& FLAG_GENERATED
) continue;
3226 if (!strendswith( source
->name
, ".c" )) continue;
3227 strarray_add( &files
, replace_extension( source
->name
, ".c", "" ));
3230 output_file
= create_temp_file( dest
);
3232 output( "/* Automatically generated by make depend; DO NOT EDIT!! */\n\n" );
3233 output( "#define WIN32_LEAN_AND_MEAN\n" );
3234 output( "#include <windows.h>\n\n" );
3235 output( "#define STANDALONE\n" );
3236 output( "#include \"wine/test.h\"\n\n" );
3238 for (i
= 0; i
< files
.count
; i
++) output( "extern void func_%s(void);\n", files
.str
[i
] );
3240 output( "const struct test winetest_testlist[] =\n" );
3242 for (i
= 0; i
< files
.count
; i
++) output( " { \"%s\", func_%s },\n", files
.str
[i
], files
.str
[i
] );
3243 output( " { 0, 0 }\n" );
3246 if (fclose( output_file
)) fatal_perror( "write" );
3248 rename_temp_file_if_changed( dest
);
3252 /*******************************************************************
3255 static void output_gitignore( const char *dest
, struct strarray files
)
3259 output_file
= create_temp_file( dest
);
3261 output( "# Automatically generated by make depend; DO NOT EDIT!!\n" );
3262 for (i
= 0; i
< files
.count
; i
++)
3264 if (!strchr( files
.str
[i
], '/' )) output( "/" );
3265 output( "%s\n", files
.str
[i
] );
3268 if (fclose( output_file
)) fatal_perror( "write" );
3270 rename_temp_file( dest
);
3274 /*******************************************************************
3275 * output_top_variables
3277 static void output_top_variables( const struct makefile
*make
)
3280 struct strarray
*vars
= &top_makefile
->vars
;
3282 if (!make
->base_dir
) return; /* don't output variables in the top makefile */
3284 output( "# Automatically generated by make depend; DO NOT EDIT!!\n\n" );
3285 output( "all:\n\n" );
3286 for (i
= 0; i
< vars
->count
; i
+= 2)
3288 if (!strcmp( vars
->str
[i
], "SUBDIRS" )) continue; /* not inherited */
3289 output( "%s = %s\n", vars
->str
[i
], get_make_variable( make
, vars
->str
[i
] ));
3295 /*******************************************************************
3296 * output_dependencies
3298 static void output_dependencies( const struct makefile
*make
)
3300 struct strarray targets
, ignore_files
= empty_strarray
;
3305 if (make
->base_dir
) create_dir( make
->base_dir
);
3307 output_file_name
= base_dir_path( make
, output_makefile_name
);
3308 output_file
= create_temp_file( output_file_name
);
3309 output_top_variables( make
);
3311 /* copy the contents of the source makefile */
3312 src_file
= open_input_makefile( make
);
3313 while (fgets( buffer
, sizeof(buffer
), src_file
) && !found
)
3315 if (fwrite( buffer
, 1, strlen(buffer
), output_file
) != strlen(buffer
)) fatal_perror( "write" );
3316 found
= !strncmp( buffer
, separator
, strlen(separator
) );
3318 if (fclose( src_file
)) fatal_perror( "close" );
3319 input_file_name
= NULL
;
3321 if (!found
) output( "\n%s (everything below this line is auto-generated; DO NOT EDIT!!)\n", separator
);
3322 targets
= output_sources( make
);
3324 fclose( output_file
);
3326 rename_temp_file( output_file_name
);
3328 strarray_add( &ignore_files
, ".gitignore" );
3329 strarray_add( &ignore_files
, "Makefile" );
3332 output_testlist( make
);
3333 strarray_add( &ignore_files
, "testlist.c" );
3335 strarray_addall( &ignore_files
, targets
);
3336 if (!make
->src_dir
) output_gitignore( base_dir_path( make
, ".gitignore" ), ignore_files
);
3338 create_file_directories( make
, targets
);
3340 output_file_name
= NULL
;
3344 /*******************************************************************
3347 static void load_sources( struct makefile
*make
)
3349 static const char *source_vars
[] =
3368 struct strarray value
;
3369 struct incl_file
*file
;
3373 make
->top_src_dir
= concat_paths( make
->top_obj_dir
, root_src_dir
);
3374 make
->src_dir
= concat_paths( make
->top_src_dir
, make
->base_dir
);
3376 strarray_set_value( &make
->vars
, "top_builddir", top_obj_dir_path( make
, "" ));
3377 strarray_set_value( &make
->vars
, "top_srcdir", top_dir_path( make
, "" ));
3378 strarray_set_value( &make
->vars
, "srcdir", src_dir_path( make
, "" ));
3380 make
->parent_dir
= get_expanded_make_variable( make
, "PARENTSRC" );
3381 make
->module
= get_expanded_make_variable( make
, "MODULE" );
3382 make
->testdll
= get_expanded_make_variable( make
, "TESTDLL" );
3383 make
->sharedlib
= get_expanded_make_variable( make
, "SHAREDLIB" );
3384 make
->staticlib
= get_expanded_make_variable( make
, "STATICLIB" );
3385 make
->importlib
= get_expanded_make_variable( make
, "IMPORTLIB" );
3387 make
->programs
= get_expanded_make_var_array( make
, "PROGRAMS" );
3388 make
->scripts
= get_expanded_make_var_array( make
, "SCRIPTS" );
3389 make
->appmode
= get_expanded_make_var_array( make
, "APPMODE" );
3390 make
->imports
= get_expanded_make_var_array( make
, "IMPORTS" );
3391 make
->delayimports
= get_expanded_make_var_array( make
, "DELAYIMPORTS" );
3392 make
->extradllflags
= get_expanded_make_var_array( make
, "EXTRADLLFLAGS" );
3393 make
->install_lib
= get_expanded_make_var_array( make
, "INSTALL_LIB" );
3394 make
->install_dev
= get_expanded_make_var_array( make
, "INSTALL_DEV" );
3396 if (make
->module
&& strendswith( make
->module
, ".a" )) make
->staticlib
= make
->module
;
3398 make
->disabled
= make
->base_dir
&& strarray_exists( &disabled_dirs
, make
->base_dir
);
3399 make
->is_win16
= strarray_exists( &make
->extradllflags
, "-m16" );
3400 make
->use_msvcrt
= strarray_exists( &make
->appmode
, "-mno-cygwin" );
3402 for (i
= 0; i
< make
->imports
.count
&& !make
->use_msvcrt
; i
++)
3403 make
->use_msvcrt
= !strncmp( make
->imports
.str
[i
], "msvcr", 5 ) ||
3404 !strcmp( make
->imports
.str
[i
], "ucrtbase" );
3406 if (make
->module
&& !make
->install_lib
.count
) strarray_add( &make
->install_lib
, make
->module
);
3408 make
->include_paths
= empty_strarray
;
3409 make
->define_args
= empty_strarray
;
3410 strarray_add( &make
->define_args
, "-D__WINESRC__" );
3412 value
= get_expanded_make_var_array( make
, "EXTRAINCL" );
3413 for (i
= 0; i
< value
.count
; i
++)
3414 if (!strncmp( value
.str
[i
], "-I", 2 ))
3415 strarray_add_uniq( &make
->include_paths
, value
.str
[i
] + 2 );
3417 strarray_add_uniq( &make
->define_args
, value
.str
[i
] );
3418 strarray_addall( &make
->define_args
, get_expanded_make_var_array( make
, "EXTRADEFS" ));
3420 list_init( &make
->sources
);
3421 list_init( &make
->includes
);
3423 for (var
= source_vars
; *var
; var
++)
3425 value
= get_expanded_make_var_array( make
, *var
);
3426 for (i
= 0; i
< value
.count
; i
++) add_src_file( make
, value
.str
[i
] );
3429 add_generated_sources( make
);
3431 value
= get_expanded_make_var_array( make
, "EXTRA_OBJS" );
3432 for (i
= 0; i
< value
.count
; i
++)
3434 /* default to .c for unknown extra object files */
3435 if (strendswith( value
.str
[i
], ".o" ))
3436 add_generated_source( make
, value
.str
[i
], replace_extension( value
.str
[i
], ".o", ".c" ) );
3438 add_generated_source( make
, value
.str
[i
], NULL
);
3441 LIST_FOR_EACH_ENTRY( file
, &make
->includes
, struct incl_file
, entry
) parse_file( make
, file
, 0 );
3445 /*******************************************************************
3448 static void parse_makeflags( const char *flags
)
3450 const char *p
= flags
;
3451 char *var
, *buffer
= xmalloc( strlen(flags
) + 1 );
3455 while (isspace(*p
)) p
++;
3457 while (*p
&& !isspace(*p
))
3459 if (*p
== '\\' && p
[1]) p
++;
3463 if (var
> buffer
) set_make_variable( &cmdline_vars
, buffer
);
3468 /*******************************************************************
3471 static int parse_option( const char *opt
)
3475 if (strchr( opt
, '=' )) return set_make_variable( &cmdline_vars
, opt
);
3481 if (opt
[2]) output_makefile_name
= opt
+ 2;
3484 relative_dir_mode
= 1;
3487 fprintf( stderr
, "Unknown option '%s'\n%s", opt
, Usage
);
3494 /*******************************************************************
3497 int main( int argc
, char *argv
[] )
3499 const char *makeflags
= getenv( "MAKEFLAGS" );
3502 if (makeflags
) parse_makeflags( makeflags
);
3507 if (parse_option( argv
[i
] ))
3509 for (j
= i
; j
< argc
; j
++) argv
[j
] = argv
[j
+1];
3515 if (relative_dir_mode
)
3521 fprintf( stderr
, "Option -R needs two directories\n%s", Usage
);
3524 relpath
= get_relative_path( argv
[1], argv
[2] );
3525 printf( "%s\n", relpath
? relpath
: "." );
3529 atexit( cleanup_files
);
3530 signal( SIGTERM
, exit_on_signal
);
3531 signal( SIGINT
, exit_on_signal
);
3533 signal( SIGHUP
, exit_on_signal
);
3536 for (i
= 0; i
< HASH_SIZE
; i
++) list_init( &files
[i
] );
3538 top_makefile
= parse_makefile( NULL
);
3540 linguas
= get_expanded_make_var_array( top_makefile
, "LINGUAS" );
3541 target_flags
= get_expanded_make_var_array( top_makefile
, "TARGETFLAGS" );
3542 msvcrt_flags
= get_expanded_make_var_array( top_makefile
, "MSVCRTFLAGS" );
3543 dll_flags
= get_expanded_make_var_array( top_makefile
, "DLLFLAGS" );
3544 extra_cflags
= get_expanded_make_var_array( top_makefile
, "EXTRACFLAGS" );
3545 cpp_flags
= get_expanded_make_var_array( top_makefile
, "CPPFLAGS" );
3546 unwind_flags
= get_expanded_make_var_array( top_makefile
, "UNWINDFLAGS" );
3547 libs
= get_expanded_make_var_array( top_makefile
, "LIBS" );
3549 root_src_dir
= get_expanded_make_variable( top_makefile
, "srcdir" );
3550 tools_dir
= get_expanded_make_variable( top_makefile
, "TOOLSDIR" );
3551 tools_ext
= get_expanded_make_variable( top_makefile
, "TOOLSEXT" );
3552 exe_ext
= get_expanded_make_variable( top_makefile
, "EXEEXT" );
3553 man_ext
= get_expanded_make_variable( top_makefile
, "api_manext" );
3554 dll_ext
= (exe_ext
&& !strcmp( exe_ext
, ".exe" )) ? "" : ".so";
3555 crosstarget
= get_expanded_make_variable( top_makefile
, "CROSSTARGET" );
3556 fontforge
= get_expanded_make_variable( top_makefile
, "FONTFORGE" );
3557 convert
= get_expanded_make_variable( top_makefile
, "CONVERT" );
3558 rsvg
= get_expanded_make_variable( top_makefile
, "RSVG" );
3559 icotool
= get_expanded_make_variable( top_makefile
, "ICOTOOL" );
3560 dlltool
= get_expanded_make_variable( top_makefile
, "DLLTOOL" );
3561 msgfmt
= get_expanded_make_variable( top_makefile
, "MSGFMT" );
3562 ln_s
= get_expanded_make_variable( top_makefile
, "LN_S" );
3564 if (root_src_dir
&& !strcmp( root_src_dir
, "." )) root_src_dir
= NULL
;
3565 if (tools_dir
&& !strcmp( tools_dir
, "." )) tools_dir
= NULL
;
3566 if (!exe_ext
) exe_ext
= "";
3567 if (!tools_ext
) tools_ext
= "";
3568 if (!man_ext
) man_ext
= "3w";
3572 disabled_dirs
= get_expanded_make_var_array( top_makefile
, "DISABLED_SUBDIRS" );
3573 top_makefile
->subdirs
= get_expanded_make_var_array( top_makefile
, "SUBDIRS" );
3574 top_makefile
->submakes
= xmalloc( top_makefile
->subdirs
.count
* sizeof(*top_makefile
->submakes
) );
3576 for (i
= 0; i
< top_makefile
->subdirs
.count
; i
++)
3577 top_makefile
->submakes
[i
] = parse_makefile( top_makefile
->subdirs
.str
[i
] );
3579 load_sources( top_makefile
);
3580 for (i
= 0; i
< top_makefile
->subdirs
.count
; i
++)
3581 load_sources( top_makefile
->submakes
[i
] );
3583 for (i
= 0; i
< top_makefile
->subdirs
.count
; i
++)
3584 output_dependencies( top_makefile
->submakes
[i
] );
3586 output_dependencies( top_makefile
);
3590 for (i
= 1; i
< argc
; i
++)
3592 struct makefile
*make
= parse_makefile( argv
[i
] );
3593 load_sources( make
);
3594 output_dependencies( make
);