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 unsigned int count
; /* strings in use */
41 unsigned int size
; /* total allocated size */
47 INCL_NORMAL
, /* #include "foo.h" */
48 INCL_SYSTEM
, /* #include <foo.h> */
49 INCL_IMPORT
, /* idl import "foo.idl" */
50 INCL_IMPORTLIB
, /* idl importlib "foo.tlb" */
51 INCL_CPP_QUOTE
, /* idl cpp_quote("#include \"foo.h\"") */
52 INCL_CPP_QUOTE_SYSTEM
/* idl cpp_quote("#include <foo.h>") */
57 int line
; /* source line where this header is included */
58 enum incl_type type
; /* type of include */
59 char *name
; /* header name */
65 char *name
; /* full file name relative to cwd */
66 void *args
; /* custom arguments for makefile rule */
67 unsigned int flags
; /* flags (see below) */
68 unsigned int deps_count
; /* files in use */
69 unsigned int deps_size
; /* total allocated size */
70 struct dependency
*deps
; /* all header dependencies */
79 char *sourcename
; /* source file name for generated headers */
80 struct incl_file
*included_by
; /* file that included this one */
81 int included_line
; /* line where this file was included */
82 enum incl_type type
; /* type of include */
83 struct incl_file
*owner
;
84 unsigned int files_count
; /* files in use */
85 unsigned int files_size
; /* total allocated size */
86 struct incl_file
**files
;
87 struct strarray dependencies
; /* file dependencies */
90 #define FLAG_GENERATED 0x000001 /* generated file */
91 #define FLAG_INSTALL 0x000002 /* file to install */
92 #define FLAG_PARENTDIR 0x000004 /* file comes from parent dir */
93 #define FLAG_IDL_PROXY 0x000100 /* generates a proxy (_p.c) file */
94 #define FLAG_IDL_CLIENT 0x000200 /* generates a client (_c.c) file */
95 #define FLAG_IDL_SERVER 0x000400 /* generates a server (_s.c) file */
96 #define FLAG_IDL_IDENT 0x000800 /* generates an ident (_i.c) file */
97 #define FLAG_IDL_REGISTER 0x001000 /* generates a registration (_r.res) file */
98 #define FLAG_IDL_TYPELIB 0x002000 /* generates a typelib (.tlb) file */
99 #define FLAG_IDL_REGTYPELIB 0x004000 /* generates a registered typelib (_t.res) file */
100 #define FLAG_IDL_HEADER 0x008000 /* generates a header (.h) file */
101 #define FLAG_RC_PO 0x010000 /* rc file contains translations */
102 #define FLAG_C_IMPLIB 0x020000 /* file is part of an import library */
103 #define FLAG_SFD_FONTS 0x040000 /* sfd file generated bitmap fonts */
111 { FLAG_IDL_TYPELIB
, ".tlb" },
112 { FLAG_IDL_REGTYPELIB
, "_t.res" },
113 { FLAG_IDL_CLIENT
, "_c.c" },
114 { FLAG_IDL_IDENT
, "_i.c" },
115 { FLAG_IDL_PROXY
, "_p.c" },
116 { FLAG_IDL_SERVER
, "_s.c" },
117 { FLAG_IDL_REGISTER
, "_r.res" },
118 { FLAG_IDL_HEADER
, ".h" }
121 #define HASH_SIZE 997
123 static struct list files
[HASH_SIZE
];
125 static const struct strarray empty_strarray
;
127 enum install_rules
{ INSTALL_LIB
, INSTALL_DEV
, NB_INSTALL_RULES
};
129 /* variables common to all makefiles */
130 static struct strarray linguas
;
131 static struct strarray dll_flags
;
132 static struct strarray target_flags
;
133 static struct strarray msvcrt_flags
;
134 static struct strarray extra_cflags
;
135 static struct strarray cpp_flags
;
136 static struct strarray unwind_flags
;
137 static struct strarray libs
;
138 static struct strarray enable_tests
;
139 static struct strarray cmdline_vars
;
140 static struct strarray disabled_dirs
;
141 static struct strarray top_install_lib
;
142 static struct strarray top_install_dev
;
143 static const char *root_src_dir
;
144 static const char *tools_dir
;
145 static const char *tools_ext
;
146 static const char *exe_ext
;
147 static const char *dll_ext
;
148 static const char *man_ext
;
149 static const char *crosstarget
;
150 static const char *fontforge
;
151 static const char *convert
;
152 static const char *flex
;
153 static const char *bison
;
154 static const char *ar
;
155 static const char *ranlib
;
156 static const char *rsvg
;
157 static const char *icotool
;
158 static const char *dlltool
;
159 static const char *msgfmt
;
160 static const char *ln_s
;
161 static const char *sed_cmd
;
165 /* values determined from input makefile */
166 struct strarray vars
;
167 struct strarray include_paths
;
168 struct strarray include_args
;
169 struct strarray define_args
;
170 struct strarray programs
;
171 struct strarray scripts
;
172 struct strarray appmode
;
173 struct strarray imports
;
174 struct strarray subdirs
;
175 struct strarray delayimports
;
176 struct strarray extradllflags
;
177 struct strarray install_lib
;
178 struct strarray install_dev
;
179 struct strarray extra_targets
;
181 struct list includes
;
182 const char *base_dir
;
185 const char *top_src_dir
;
186 const char *top_obj_dir
;
187 const char *parent_dir
;
190 const char *sharedlib
;
191 const char *staticlib
;
192 const char *staticimplib
;
193 const char *importlib
;
197 struct makefile
**submakes
;
199 /* values generated at output time */
200 struct strarray in_files
;
201 struct strarray ok_files
;
202 struct strarray clean_files
;
203 struct strarray distclean_files
;
204 struct strarray uninstall_files
;
205 struct strarray object_files
;
206 struct strarray crossobj_files
;
207 struct strarray c2man_files
;
208 struct strarray dlldata_files
;
209 struct strarray implib_objs
;
210 struct strarray all_targets
;
211 struct strarray phony_targets
;
212 struct strarray dependencies
;
213 struct strarray install_rules
[NB_INSTALL_RULES
];
216 static struct makefile
*top_makefile
;
218 static const char separator
[] = "### Dependencies";
219 static const char *output_makefile_name
= "Makefile";
220 static const char *input_file_name
;
221 static const char *output_file_name
;
222 static const char *temp_file_name
;
223 static int relative_dir_mode
;
224 static int input_line
;
225 static int output_column
;
226 static FILE *output_file
;
228 static const char Usage
[] =
229 "Usage: makedep [options] [directories]\n"
231 " -R from to Compute the relative path between two directories\n"
232 " -fxxx Store output in file 'xxx' (default: Makefile)\n";
236 #define __attribute__(x)
239 static void fatal_error( const char *msg
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
240 static void fatal_perror( const char *msg
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
241 static void output( const char *format
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
242 static char *strmake( const char* fmt
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
244 /*******************************************************************
247 static void fatal_error( const char *msg
, ... )
250 va_start( valist
, msg
);
253 fprintf( stderr
, "%s:", input_file_name
);
254 if (input_line
) fprintf( stderr
, "%d:", input_line
);
255 fprintf( stderr
, " error: " );
257 else fprintf( stderr
, "makedep: error: " );
258 vfprintf( stderr
, msg
, valist
);
264 /*******************************************************************
267 static void fatal_perror( const char *msg
, ... )
270 va_start( valist
, msg
);
273 fprintf( stderr
, "%s:", input_file_name
);
274 if (input_line
) fprintf( stderr
, "%d:", input_line
);
275 fprintf( stderr
, " error: " );
277 else fprintf( stderr
, "makedep: error: " );
278 vfprintf( stderr
, msg
, valist
);
285 /*******************************************************************
288 static void cleanup_files(void)
290 if (temp_file_name
) unlink( temp_file_name
);
291 if (output_file_name
) unlink( output_file_name
);
295 /*******************************************************************
298 static void exit_on_signal( int sig
)
300 exit( 1 ); /* this will call the atexit functions */
304 /*******************************************************************
307 static void *xmalloc( size_t size
)
310 if (!(res
= malloc (size
? size
: 1)))
311 fatal_error( "Virtual memory exhausted.\n" );
316 /*******************************************************************
319 static void *xrealloc (void *ptr
, size_t size
)
323 if (!(res
= realloc( ptr
, size
)))
324 fatal_error( "Virtual memory exhausted.\n" );
328 /*******************************************************************
331 static char *xstrdup( const char *str
)
333 char *res
= strdup( str
);
334 if (!res
) fatal_error( "Virtual memory exhausted.\n" );
339 /*******************************************************************
342 static char *strmake( const char* fmt
, ... )
350 char *p
= xmalloc (size
);
352 n
= vsnprintf (p
, size
, fmt
, ap
);
354 if (n
== -1) size
*= 2;
355 else if ((size_t)n
>= size
) size
= n
+ 1;
356 else return xrealloc( p
, n
+ 1 );
362 /*******************************************************************
365 static int strendswith( const char* str
, const char* end
)
367 size_t l
= strlen( str
);
368 size_t m
= strlen( end
);
370 return l
>= m
&& strcmp(str
+ l
- m
, end
) == 0;
374 /*******************************************************************
377 static void output( const char *format
, ... )
382 va_start( valist
, format
);
383 ret
= vfprintf( output_file
, format
, valist
);
385 if (ret
< 0) fatal_perror( "output" );
386 if (format
[0] && format
[strlen(format
) - 1] == '\n') output_column
= 0;
387 else output_column
+= ret
;
391 /*******************************************************************
394 static void strarray_add( struct strarray
*array
, const char *str
)
396 if (array
->count
== array
->size
)
398 if (array
->size
) array
->size
*= 2;
399 else array
->size
= 16;
400 array
->str
= xrealloc( array
->str
, sizeof(array
->str
[0]) * array
->size
);
402 array
->str
[array
->count
++] = str
;
406 /*******************************************************************
409 static void strarray_addall( struct strarray
*array
, struct strarray added
)
413 for (i
= 0; i
< added
.count
; i
++) strarray_add( array
, added
.str
[i
] );
417 /*******************************************************************
420 static int strarray_exists( const struct strarray
*array
, const char *str
)
424 for (i
= 0; i
< array
->count
; i
++) if (!strcmp( array
->str
[i
], str
)) return 1;
429 /*******************************************************************
432 static void strarray_add_uniq( struct strarray
*array
, const char *str
)
434 if (!strarray_exists( array
, str
)) strarray_add( array
, str
);
438 /*******************************************************************
439 * strarray_addall_uniq
441 static void strarray_addall_uniq( struct strarray
*array
, struct strarray added
)
445 for (i
= 0; i
< added
.count
; i
++) strarray_add_uniq( array
, added
.str
[i
] );
449 /*******************************************************************
452 * Find a value in a name/value pair string array.
454 static const char *strarray_get_value( const struct strarray
*array
, const char *name
)
456 int pos
, res
, min
= 0, max
= array
->count
/ 2 - 1;
460 pos
= (min
+ max
) / 2;
461 if (!(res
= strcmp( array
->str
[pos
* 2], name
))) return array
->str
[pos
* 2 + 1];
462 if (res
< 0) min
= pos
+ 1;
469 /*******************************************************************
472 * Define a value in a name/value pair string array.
474 static void strarray_set_value( struct strarray
*array
, const char *name
, const char *value
)
476 int i
, pos
, res
, min
= 0, max
= array
->count
/ 2 - 1;
480 pos
= (min
+ max
) / 2;
481 if (!(res
= strcmp( array
->str
[pos
* 2], name
)))
483 /* redefining a variable replaces the previous value */
484 array
->str
[pos
* 2 + 1] = value
;
487 if (res
< 0) min
= pos
+ 1;
490 strarray_add( array
, NULL
);
491 strarray_add( array
, NULL
);
492 for (i
= array
->count
- 1; i
> min
* 2 + 1; i
--) array
->str
[i
] = array
->str
[i
- 2];
493 array
->str
[min
* 2] = name
;
494 array
->str
[min
* 2 + 1] = value
;
498 /*******************************************************************
501 static void strarray_qsort( struct strarray
*array
, int (*func
)(const char **, const char **) )
503 if (array
->count
) qsort( array
->str
, array
->count
, sizeof(*array
->str
), (void *)func
);
507 /*******************************************************************
510 static void output_filename( const char *name
)
512 if (output_column
+ strlen(name
) + 1 > 100)
517 else if (output_column
) output( " " );
518 output( "%s", name
);
522 /*******************************************************************
525 static void output_filenames( struct strarray array
)
529 for (i
= 0; i
< array
.count
; i
++) output_filename( array
.str
[i
] );
533 /*******************************************************************
534 * output_rm_filenames
536 static void output_rm_filenames( struct strarray array
)
538 static const unsigned int max_cmdline
= 30000; /* to be on the safe side */
541 if (!array
.count
) return;
543 for (i
= len
= 0; i
< array
.count
; i
++)
545 if (len
> max_cmdline
)
551 output_filename( array
.str
[i
] );
552 len
+= strlen( array
.str
[i
] ) + 1;
558 /*******************************************************************
561 static char *get_extension( char *filename
)
563 char *ext
= strrchr( filename
, '.' );
564 if (ext
&& strchr( ext
, '/' )) ext
= NULL
;
569 /*******************************************************************
572 static char *replace_extension( const char *name
, const char *old_ext
, const char *new_ext
)
575 size_t name_len
= strlen( name
);
576 size_t ext_len
= strlen( old_ext
);
578 if (name_len
>= ext_len
&& !strcmp( name
+ name_len
- ext_len
, old_ext
)) name_len
-= ext_len
;
579 ret
= xmalloc( name_len
+ strlen( new_ext
) + 1 );
580 memcpy( ret
, name
, name_len
);
581 strcpy( ret
+ name_len
, new_ext
);
586 /*******************************************************************
589 static char *replace_filename( const char *path
, const char *name
)
595 if (!path
) return xstrdup( name
);
596 if (!(p
= strrchr( path
, '/' ))) return xstrdup( name
);
598 ret
= xmalloc( len
+ strlen( name
) + 1 );
599 memcpy( ret
, path
, len
);
600 strcpy( ret
+ len
, name
);
605 /*******************************************************************
606 * strarray_replace_extension
608 static struct strarray
strarray_replace_extension( const struct strarray
*array
,
609 const char *old_ext
, const char *new_ext
)
614 ret
.count
= ret
.size
= array
->count
;
615 ret
.str
= xmalloc( sizeof(ret
.str
[0]) * ret
.size
);
616 for (i
= 0; i
< array
->count
; i
++) ret
.str
[i
] = replace_extension( array
->str
[i
], old_ext
, new_ext
);
621 /*******************************************************************
624 static char *replace_substr( const char *str
, const char *start
, size_t len
, const char *replace
)
626 size_t pos
= start
- str
;
627 char *ret
= xmalloc( pos
+ strlen(replace
) + strlen(start
+ len
) + 1 );
628 memcpy( ret
, str
, pos
);
629 strcpy( ret
+ pos
, replace
);
630 strcat( ret
+ pos
, start
+ len
);
635 /*******************************************************************
638 * Determine where the destination path is located relative to the 'from' path.
640 static char *get_relative_path( const char *from
, const char *dest
)
644 unsigned int dotdots
= 0;
646 /* a path of "." is equivalent to an empty path */
647 if (!strcmp( from
, "." )) from
= "";
651 while (*from
== '/') from
++;
652 while (*dest
== '/') dest
++;
653 start
= dest
; /* save start of next path element */
656 while (*from
&& *from
!= '/' && *from
== *dest
) { from
++; dest
++; }
657 if ((!*from
|| *from
== '/') && (!*dest
|| *dest
== '/')) continue;
659 /* count remaining elements in 'from' */
663 while (*from
&& *from
!= '/') from
++;
664 while (*from
== '/') from
++;
670 if (!start
[0] && !dotdots
) return NULL
; /* empty path */
672 ret
= xmalloc( 3 * dotdots
+ strlen( start
) + 1 );
673 for (p
= ret
; dotdots
; dotdots
--, p
+= 3) memcpy( p
, "../", 3 );
675 if (start
[0]) strcpy( p
, start
);
676 else p
[-1] = 0; /* remove trailing slash */
681 /*******************************************************************
684 static char *concat_paths( const char *base
, const char *path
)
686 if (!base
|| !base
[0]) return xstrdup( path
&& path
[0] ? path
: "." );
687 if (!path
|| !path
[0]) return xstrdup( base
);
688 if (path
[0] == '/') return xstrdup( path
);
689 return strmake( "%s/%s", base
, path
);
693 /*******************************************************************
696 static char *base_dir_path( const struct makefile
*make
, const char *path
)
698 return concat_paths( make
->base_dir
, path
);
702 /*******************************************************************
705 static char *obj_dir_path( const struct makefile
*make
, const char *path
)
707 return concat_paths( make
->obj_dir
, path
);
711 /*******************************************************************
714 static char *src_dir_path( const struct makefile
*make
, const char *path
)
716 if (make
->src_dir
) return concat_paths( make
->src_dir
, path
);
717 return obj_dir_path( make
, path
);
721 /*******************************************************************
724 static char *top_obj_dir_path( const struct makefile
*make
, const char *path
)
726 return concat_paths( make
->top_obj_dir
, path
);
730 /*******************************************************************
733 static char *top_src_dir_path( const struct makefile
*make
, const char *path
)
735 if (make
->top_src_dir
) return concat_paths( make
->top_src_dir
, path
);
736 return top_obj_dir_path( make
, path
);
740 /*******************************************************************
743 static char *root_dir_path( const char *path
)
745 return concat_paths( root_src_dir
, path
);
749 /*******************************************************************
752 static char *tools_dir_path( const struct makefile
*make
, const char *path
)
754 if (tools_dir
) return top_obj_dir_path( make
, strmake( "%s/tools/%s", tools_dir
, path
));
755 return top_obj_dir_path( make
, strmake( "tools/%s", path
));
759 /*******************************************************************
762 static char *tools_path( const struct makefile
*make
, const char *name
)
764 return strmake( "%s/%s%s", tools_dir_path( make
, name
), name
, tools_ext
);
768 /*******************************************************************
771 static char *get_line( FILE *file
)
779 buffer
= xmalloc( size
);
781 if (!fgets( buffer
, size
, file
)) return NULL
;
786 char *p
= buffer
+ strlen(buffer
);
787 /* if line is larger than buffer, resize buffer */
788 while (p
== buffer
+ size
- 1 && p
[-1] != '\n')
790 buffer
= xrealloc( buffer
, size
* 2 );
791 if (!fgets( buffer
+ size
- 1, size
+ 1, file
)) break;
792 p
= buffer
+ strlen(buffer
);
795 if (p
> buffer
&& p
[-1] == '\n')
798 if (p
> buffer
&& p
[-1] == '\r') *(--p
) = 0;
799 if (p
> buffer
&& p
[-1] == '\\')
802 /* line ends in backslash, read continuation line */
803 if (!fgets( p
, size
- (p
- buffer
), file
)) return buffer
;
813 /*******************************************************************
816 static unsigned int hash_filename( const char *name
)
819 unsigned int ret
= 2166136261u;
820 while (*name
) ret
= (ret
* 16777619) ^ *name
++;
821 return ret
% HASH_SIZE
;
825 /*******************************************************************
828 static struct file
*add_file( const char *name
)
830 struct file
*file
= xmalloc( sizeof(*file
) );
831 memset( file
, 0, sizeof(*file
) );
832 file
->name
= xstrdup( name
);
837 /*******************************************************************
840 static void add_dependency( struct file
*file
, const char *name
, enum incl_type type
)
842 /* enforce some rules for the Wine tree */
844 if (!memcmp( name
, "../", 3 ))
845 fatal_error( "#include directive with relative path not allowed\n" );
847 if (!strcmp( name
, "config.h" ))
849 if (strendswith( file
->name
, ".h" ))
850 fatal_error( "config.h must not be included by a header file\n" );
851 if (file
->deps_count
)
852 fatal_error( "config.h must be included before anything else\n" );
854 else if (!strcmp( name
, "wine/port.h" ))
856 if (strendswith( file
->name
, ".h" ))
857 fatal_error( "wine/port.h must not be included by a header file\n" );
858 if (!file
->deps_count
) fatal_error( "config.h must be included before wine/port.h\n" );
859 if (file
->deps_count
> 1)
860 fatal_error( "wine/port.h must be included before everything except config.h\n" );
861 if (strcmp( file
->deps
[0].name
, "config.h" ))
862 fatal_error( "config.h must be included before wine/port.h\n" );
865 if (file
->deps_count
>= file
->deps_size
)
867 file
->deps_size
*= 2;
868 if (file
->deps_size
< 16) file
->deps_size
= 16;
869 file
->deps
= xrealloc( file
->deps
, file
->deps_size
* sizeof(*file
->deps
) );
871 file
->deps
[file
->deps_count
].line
= input_line
;
872 file
->deps
[file
->deps_count
].type
= type
;
873 file
->deps
[file
->deps_count
].name
= xstrdup( name
);
878 /*******************************************************************
881 static struct incl_file
*find_src_file( const struct makefile
*make
, const char *name
)
883 struct incl_file
*file
;
885 LIST_FOR_EACH_ENTRY( file
, &make
->sources
, struct incl_file
, entry
)
886 if (!strcmp( name
, file
->name
)) return file
;
890 /*******************************************************************
893 static struct incl_file
*find_include_file( const struct makefile
*make
, const char *name
)
895 struct incl_file
*file
;
897 LIST_FOR_EACH_ENTRY( file
, &make
->includes
, struct incl_file
, entry
)
898 if (!strcmp( name
, file
->name
)) return file
;
902 /*******************************************************************
905 * Add an include file if it doesn't already exists.
907 static struct incl_file
*add_include( struct makefile
*make
, struct incl_file
*parent
,
908 const char *name
, int line
, enum incl_type type
)
910 struct incl_file
*include
;
912 if (parent
->files_count
>= parent
->files_size
)
914 parent
->files_size
*= 2;
915 if (parent
->files_size
< 16) parent
->files_size
= 16;
916 parent
->files
= xrealloc( parent
->files
, parent
->files_size
* sizeof(*parent
->files
) );
919 LIST_FOR_EACH_ENTRY( include
, &make
->includes
, struct incl_file
, entry
)
920 if (!strcmp( name
, include
->name
)) goto found
;
922 include
= xmalloc( sizeof(*include
) );
923 memset( include
, 0, sizeof(*include
) );
924 include
->name
= xstrdup(name
);
925 include
->included_by
= parent
;
926 include
->included_line
= line
;
927 include
->type
= type
;
928 list_add_tail( &make
->includes
, &include
->entry
);
930 parent
->files
[parent
->files_count
++] = include
;
935 /*******************************************************************
936 * add_generated_source
938 * Add a generated source file to the list.
940 static struct incl_file
*add_generated_source( struct makefile
*make
,
941 const char *name
, const char *filename
)
943 struct incl_file
*file
;
945 if ((file
= find_src_file( make
, name
))) return file
; /* we already have it */
946 file
= xmalloc( sizeof(*file
) );
947 memset( file
, 0, sizeof(*file
) );
948 file
->file
= add_file( name
);
949 file
->name
= xstrdup( name
);
950 file
->filename
= obj_dir_path( make
, filename
? filename
: name
);
951 file
->file
->flags
= FLAG_GENERATED
;
952 list_add_tail( &make
->sources
, &file
->entry
);
957 /*******************************************************************
958 * parse_include_directive
960 static void parse_include_directive( struct file
*source
, char *str
)
962 char quote
, *include
, *p
= str
;
964 while (*p
&& isspace(*p
)) p
++;
965 if (*p
!= '\"' && *p
!= '<' ) return;
967 if (quote
== '<') quote
= '>';
969 while (*p
&& (*p
!= quote
)) p
++;
970 if (!*p
) fatal_error( "malformed include directive '%s'\n", str
);
972 add_dependency( source
, include
, (quote
== '>') ? INCL_SYSTEM
: INCL_NORMAL
);
976 /*******************************************************************
977 * parse_pragma_directive
979 static void parse_pragma_directive( struct file
*source
, char *str
)
981 char *flag
, *p
= str
;
983 if (!isspace( *p
)) return;
984 while (*p
&& isspace(*p
)) p
++;
985 p
= strtok( p
, " \t" );
986 if (strcmp( p
, "makedep" )) return;
988 while ((flag
= strtok( NULL
, " \t" )))
990 if (!strcmp( flag
, "depend" ))
992 while ((p
= strtok( NULL
, " \t" ))) add_dependency( source
, p
, INCL_NORMAL
);
995 else if (!strcmp( flag
, "install" )) source
->flags
|= FLAG_INSTALL
;
997 if (strendswith( source
->name
, ".idl" ))
999 if (!strcmp( flag
, "header" )) source
->flags
|= FLAG_IDL_HEADER
;
1000 else if (!strcmp( flag
, "proxy" )) source
->flags
|= FLAG_IDL_PROXY
;
1001 else if (!strcmp( flag
, "client" )) source
->flags
|= FLAG_IDL_CLIENT
;
1002 else if (!strcmp( flag
, "server" )) source
->flags
|= FLAG_IDL_SERVER
;
1003 else if (!strcmp( flag
, "ident" )) source
->flags
|= FLAG_IDL_IDENT
;
1004 else if (!strcmp( flag
, "typelib" )) source
->flags
|= FLAG_IDL_TYPELIB
;
1005 else if (!strcmp( flag
, "register" )) source
->flags
|= FLAG_IDL_REGISTER
;
1006 else if (!strcmp( flag
, "regtypelib" )) source
->flags
|= FLAG_IDL_REGTYPELIB
;
1008 else if (strendswith( source
->name
, ".rc" ))
1010 if (!strcmp( flag
, "po" )) source
->flags
|= FLAG_RC_PO
;
1012 else if (strendswith( source
->name
, ".sfd" ))
1014 if (!strcmp( flag
, "font" ))
1016 struct strarray
*array
= source
->args
;
1020 source
->args
= array
= xmalloc( sizeof(*array
) );
1021 *array
= empty_strarray
;
1022 source
->flags
|= FLAG_SFD_FONTS
;
1024 strarray_add( array
, xstrdup( strtok( NULL
, "" )));
1028 else if (!strcmp( flag
, "implib" )) source
->flags
|= FLAG_C_IMPLIB
;
1033 /*******************************************************************
1034 * parse_cpp_directive
1036 static void parse_cpp_directive( struct file
*source
, char *str
)
1038 while (*str
&& isspace(*str
)) str
++;
1039 if (*str
++ != '#') return;
1040 while (*str
&& isspace(*str
)) str
++;
1042 if (!strncmp( str
, "include", 7 ))
1043 parse_include_directive( source
, str
+ 7 );
1044 else if (!strncmp( str
, "import", 6 ) && strendswith( source
->name
, ".m" ))
1045 parse_include_directive( source
, str
+ 6 );
1046 else if (!strncmp( str
, "pragma", 6 ))
1047 parse_pragma_directive( source
, str
+ 6 );
1051 /*******************************************************************
1054 static void parse_idl_file( struct file
*source
, FILE *file
)
1056 char *buffer
, *include
;
1060 while ((buffer
= get_line( file
)))
1064 while (*p
&& isspace(*p
)) p
++;
1066 if (!strncmp( p
, "importlib", 9 ))
1069 while (*p
&& isspace(*p
)) p
++;
1070 if (*p
++ != '(') continue;
1071 while (*p
&& isspace(*p
)) p
++;
1072 if (*p
++ != '"') continue;
1074 while (*p
&& (*p
!= '"')) p
++;
1075 if (!*p
) fatal_error( "malformed importlib directive\n" );
1077 add_dependency( source
, include
, INCL_IMPORTLIB
);
1081 if (!strncmp( p
, "import", 6 ))
1084 while (*p
&& isspace(*p
)) p
++;
1085 if (*p
!= '"') continue;
1087 while (*p
&& (*p
!= '"')) p
++;
1088 if (!*p
) fatal_error( "malformed import directive\n" );
1090 add_dependency( source
, include
, INCL_IMPORT
);
1094 /* check for #include inside cpp_quote */
1095 if (!strncmp( p
, "cpp_quote", 9 ))
1098 while (*p
&& isspace(*p
)) p
++;
1099 if (*p
++ != '(') continue;
1100 while (*p
&& isspace(*p
)) p
++;
1101 if (*p
++ != '"') continue;
1102 if (*p
++ != '#') continue;
1103 while (*p
&& isspace(*p
)) p
++;
1104 if (strncmp( p
, "include", 7 )) continue;
1106 while (*p
&& isspace(*p
)) p
++;
1107 if (*p
== '\\' && p
[1] == '"')
1114 if (*p
++ != '<' ) continue;
1118 while (*p
&& (*p
!= quote
)) p
++;
1119 if (!*p
|| (quote
== '"' && p
[-1] != '\\'))
1120 fatal_error( "malformed #include directive inside cpp_quote\n" );
1121 if (quote
== '"') p
--; /* remove backslash */
1123 add_dependency( source
, include
, (quote
== '>') ? INCL_CPP_QUOTE_SYSTEM
: INCL_CPP_QUOTE
);
1127 parse_cpp_directive( source
, p
);
1131 /*******************************************************************
1134 static void parse_c_file( struct file
*source
, FILE *file
)
1139 while ((buffer
= get_line( file
)))
1141 parse_cpp_directive( source
, buffer
);
1146 /*******************************************************************
1149 static void parse_rc_file( struct file
*source
, FILE *file
)
1151 char *buffer
, *include
;
1154 while ((buffer
= get_line( file
)))
1158 while (*p
&& isspace(*p
)) p
++;
1160 if (p
[0] == '/' && p
[1] == '*') /* check for magic makedep comment */
1163 while (*p
&& isspace(*p
)) p
++;
1164 if (strncmp( p
, "@makedep:", 9 )) continue;
1166 while (*p
&& isspace(*p
)) p
++;
1171 while (*p
&& *p
!= quote
) p
++;
1176 while (*p
&& !isspace(*p
) && *p
!= '*') p
++;
1179 fatal_error( "malformed makedep comment\n" );
1181 add_dependency( source
, include
, (quote
== '>') ? INCL_SYSTEM
: INCL_NORMAL
);
1185 parse_cpp_directive( source
, buffer
);
1190 /*******************************************************************
1193 static void parse_in_file( struct file
*source
, FILE *file
)
1197 /* make sure it gets rebuilt when the version changes */
1198 add_dependency( source
, "config.h", INCL_SYSTEM
);
1200 if (!strendswith( source
->name
, ".man.in" )) return; /* not a man page */
1203 while ((buffer
= get_line( file
)))
1205 if (strncmp( buffer
, ".TH", 3 )) continue;
1206 if (!(p
= strtok( buffer
, " \t" ))) continue; /* .TH */
1207 if (!(p
= strtok( NULL
, " \t" ))) continue; /* program name */
1208 if (!(p
= strtok( NULL
, " \t" ))) continue; /* man section */
1209 source
->args
= xstrdup( p
);
1215 /*******************************************************************
1218 static void parse_sfd_file( struct file
*source
, FILE *file
)
1220 char *p
, *eol
, *buffer
;
1223 while ((buffer
= get_line( file
)))
1225 if (strncmp( buffer
, "UComments:", 10 )) continue;
1227 while (*p
== ' ') p
++;
1228 if (p
[0] == '"' && p
[1] && buffer
[strlen(buffer
) - 1] == '"')
1231 buffer
[strlen(buffer
) - 1] = 0;
1233 while ((eol
= strstr( p
, "+AAoA" )))
1236 while (*p
&& isspace(*p
)) p
++;
1239 while (*p
&& isspace(*p
)) p
++;
1240 if (!strncmp( p
, "pragma", 6 )) parse_pragma_directive( source
, p
+ 6 );
1244 while (*p
&& isspace(*p
)) p
++;
1245 if (*p
++ != '#') return;
1246 while (*p
&& isspace(*p
)) p
++;
1247 if (!strncmp( p
, "pragma", 6 )) parse_pragma_directive( source
, p
+ 6 );
1256 void (*parse
)( struct file
*file
, FILE *f
);
1257 } parse_functions
[] =
1259 { ".c", parse_c_file
},
1260 { ".h", parse_c_file
},
1261 { ".inl", parse_c_file
},
1262 { ".l", parse_c_file
},
1263 { ".m", parse_c_file
},
1264 { ".rh", parse_c_file
},
1265 { ".x", parse_c_file
},
1266 { ".y", parse_c_file
},
1267 { ".idl", parse_idl_file
},
1268 { ".rc", parse_rc_file
},
1269 { ".in", parse_in_file
},
1270 { ".sfd", parse_sfd_file
}
1273 /*******************************************************************
1276 static struct file
*load_file( const char *name
)
1280 unsigned int i
, hash
= hash_filename( name
);
1282 LIST_FOR_EACH_ENTRY( file
, &files
[hash
], struct file
, entry
)
1283 if (!strcmp( name
, file
->name
)) return file
;
1285 if (!(f
= fopen( name
, "r" ))) return NULL
;
1287 file
= add_file( name
);
1288 list_add_tail( &files
[hash
], &file
->entry
);
1289 input_file_name
= file
->name
;
1292 for (i
= 0; i
< sizeof(parse_functions
) / sizeof(parse_functions
[0]); i
++)
1294 if (!strendswith( name
, parse_functions
[i
].ext
)) continue;
1295 parse_functions
[i
].parse( file
, f
);
1300 input_file_name
= NULL
;
1306 /*******************************************************************
1307 * open_include_path_file
1309 * Open a file from a directory on the include path.
1311 static struct file
*open_include_path_file( const struct makefile
*make
, const char *dir
,
1312 const char *name
, char **filename
)
1314 char *src_path
= base_dir_path( make
, concat_paths( dir
, name
));
1315 struct file
*ret
= load_file( src_path
);
1317 if (ret
) *filename
= src_dir_path( make
, concat_paths( dir
, name
));
1322 /*******************************************************************
1323 * open_file_same_dir
1325 * Open a file in the same directory as the parent.
1327 static struct file
*open_file_same_dir( const struct incl_file
*parent
, const char *name
, char **filename
)
1329 char *src_path
= replace_filename( parent
->file
->name
, name
);
1330 struct file
*ret
= load_file( src_path
);
1332 if (ret
) *filename
= replace_filename( parent
->filename
, name
);
1338 /*******************************************************************
1341 * Open a file in the source directory of the makefile.
1343 static struct file
*open_local_file( const struct makefile
*make
, const char *path
, char **filename
)
1345 char *src_path
= root_dir_path( base_dir_path( make
, path
));
1346 struct file
*ret
= load_file( src_path
);
1348 /* if not found, try parent dir */
1349 if (!ret
&& make
->parent_dir
)
1352 path
= strmake( "%s/%s", make
->parent_dir
, path
);
1353 src_path
= root_dir_path( base_dir_path( make
, path
));
1354 ret
= load_file( src_path
);
1355 if (ret
) ret
->flags
|= FLAG_PARENTDIR
;
1358 if (ret
) *filename
= src_dir_path( make
, path
);
1364 /*******************************************************************
1367 * Open a file in the top-level source directory.
1369 static struct file
*open_global_file( const struct makefile
*make
, const char *path
, char **filename
)
1371 char *src_path
= root_dir_path( path
);
1372 struct file
*ret
= load_file( src_path
);
1374 if (ret
) *filename
= top_src_dir_path( make
, path
);
1380 /*******************************************************************
1381 * open_global_header
1383 * Open a file in the global include source directory.
1385 static struct file
*open_global_header( const struct makefile
*make
, const char *path
, char **filename
)
1387 return open_global_file( make
, strmake( "include/%s", path
), filename
);
1391 /*******************************************************************
1394 static struct file
*open_src_file( const struct makefile
*make
, struct incl_file
*pFile
)
1396 struct file
*file
= open_local_file( make
, pFile
->name
, &pFile
->filename
);
1398 if (!file
) fatal_perror( "open %s", pFile
->name
);
1403 /*******************************************************************
1406 static struct file
*open_include_file( const struct makefile
*make
, struct incl_file
*pFile
)
1408 struct file
*file
= NULL
;
1410 unsigned int i
, len
;
1414 /* check for generated bison header */
1416 if (strendswith( pFile
->name
, ".tab.h" ) &&
1417 (file
= open_local_file( make
, replace_extension( pFile
->name
, ".tab.h", ".y" ), &filename
)))
1419 pFile
->sourcename
= filename
;
1420 pFile
->filename
= obj_dir_path( make
, pFile
->name
);
1424 /* check for corresponding idl file in source dir */
1426 if (strendswith( pFile
->name
, ".h" ) &&
1427 (file
= open_local_file( make
, replace_extension( pFile
->name
, ".h", ".idl" ), &filename
)))
1429 pFile
->sourcename
= filename
;
1430 pFile
->filename
= obj_dir_path( make
, pFile
->name
);
1434 /* check for corresponding tlb file in source dir */
1436 if (strendswith( pFile
->name
, ".tlb" ) &&
1437 (file
= open_local_file( make
, replace_extension( pFile
->name
, ".tlb", ".idl" ), &filename
)))
1439 pFile
->sourcename
= filename
;
1440 pFile
->filename
= obj_dir_path( make
, pFile
->name
);
1444 /* check for extra targets */
1445 if (strarray_exists( &make
->extra_targets
, pFile
->name
))
1447 pFile
->sourcename
= filename
;
1448 pFile
->filename
= obj_dir_path( make
, pFile
->name
);
1452 /* now try in source dir */
1453 if ((file
= open_local_file( make
, pFile
->name
, &pFile
->filename
))) return file
;
1455 /* check for corresponding idl file in global includes */
1457 if (strendswith( pFile
->name
, ".h" ) &&
1458 (file
= open_global_header( make
, replace_extension( pFile
->name
, ".h", ".idl" ), &filename
)))
1460 pFile
->sourcename
= filename
;
1461 pFile
->filename
= top_obj_dir_path( make
, strmake( "include/%s", pFile
->name
));
1465 /* check for corresponding .in file in global includes (for config.h.in) */
1467 if (strendswith( pFile
->name
, ".h" ) &&
1468 (file
= open_global_header( make
, replace_extension( pFile
->name
, ".h", ".h.in" ), &filename
)))
1470 pFile
->sourcename
= filename
;
1471 pFile
->filename
= top_obj_dir_path( make
, strmake( "include/%s", pFile
->name
));
1475 /* check for corresponding .x file in global includes */
1477 if (strendswith( pFile
->name
, "tmpl.h" ) &&
1478 (file
= open_global_header( make
, replace_extension( pFile
->name
, ".h", ".x" ), &filename
)))
1480 pFile
->sourcename
= filename
;
1481 pFile
->filename
= top_obj_dir_path( make
, strmake( "include/%s", pFile
->name
));
1485 /* check for corresponding .tlb file in global includes */
1487 if (strendswith( pFile
->name
, ".tlb" ) &&
1488 (file
= open_global_header( make
, replace_extension( pFile
->name
, ".tlb", ".idl" ), &filename
)))
1490 pFile
->sourcename
= filename
;
1491 pFile
->filename
= top_obj_dir_path( make
, strmake( "include/%s", pFile
->name
));
1495 /* check in global includes source dir */
1497 if ((file
= open_global_header( make
, pFile
->name
, &pFile
->filename
))) return file
;
1499 /* check in global msvcrt includes */
1500 if (make
->use_msvcrt
&&
1501 (file
= open_global_header( make
, strmake( "msvcrt/%s", pFile
->name
), &pFile
->filename
)))
1504 /* now search in include paths */
1505 for (i
= 0; i
< make
->include_paths
.count
; i
++)
1507 const char *dir
= make
->include_paths
.str
[i
];
1508 const char *prefix
= make
->top_src_dir
? make
->top_src_dir
: make
->top_obj_dir
;
1512 len
= strlen( prefix
);
1513 if (!strncmp( dir
, prefix
, len
) && (!dir
[len
] || dir
[len
] == '/'))
1515 while (dir
[len
] == '/') len
++;
1516 file
= open_global_file( make
, concat_paths( dir
+ len
, pFile
->name
), &pFile
->filename
);
1517 if (file
) return file
;
1519 if (make
->top_src_dir
) continue; /* ignore paths that don't point to the top source dir */
1523 if ((file
= open_include_path_file( make
, dir
, pFile
->name
, &pFile
->filename
)))
1527 if (pFile
->type
== INCL_SYSTEM
) return NULL
; /* ignore system files we cannot find */
1529 /* try in src file directory */
1530 if ((file
= open_file_same_dir( pFile
->included_by
, pFile
->name
, &pFile
->filename
))) return file
;
1532 fprintf( stderr
, "%s:%d: error: ", pFile
->included_by
->file
->name
, pFile
->included_line
);
1533 perror( pFile
->name
);
1534 pFile
= pFile
->included_by
;
1535 while (pFile
&& pFile
->included_by
)
1537 const char *parent
= pFile
->included_by
->sourcename
;
1538 if (!parent
) parent
= pFile
->included_by
->file
->name
;
1539 fprintf( stderr
, "%s:%d: note: %s was first included here\n",
1540 parent
, pFile
->included_line
, pFile
->name
);
1541 pFile
= pFile
->included_by
;
1547 /*******************************************************************
1550 static void add_all_includes( struct makefile
*make
, struct incl_file
*parent
, struct file
*file
)
1554 parent
->files_count
= 0;
1555 parent
->files_size
= file
->deps_count
;
1556 parent
->files
= xmalloc( parent
->files_size
* sizeof(*parent
->files
) );
1557 for (i
= 0; i
< file
->deps_count
; i
++)
1559 switch (file
->deps
[i
].type
)
1563 add_include( make
, parent
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_NORMAL
);
1565 case INCL_IMPORTLIB
:
1566 add_include( make
, parent
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_IMPORTLIB
);
1569 add_include( make
, parent
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_SYSTEM
);
1571 case INCL_CPP_QUOTE
:
1572 case INCL_CPP_QUOTE_SYSTEM
:
1579 /*******************************************************************
1582 static void parse_file( struct makefile
*make
, struct incl_file
*source
, int src
)
1584 struct file
*file
= src
? open_src_file( make
, source
) : open_include_file( make
, source
);
1588 source
->file
= file
;
1589 source
->files_count
= 0;
1590 source
->files_size
= file
->deps_count
;
1591 source
->files
= xmalloc( source
->files_size
* sizeof(*source
->files
) );
1593 if (source
->sourcename
)
1595 if (strendswith( source
->sourcename
, ".idl" ))
1599 if (strendswith( source
->name
, ".tlb" )) return; /* typelibs don't include anything */
1601 /* generated .h file always includes these */
1602 add_include( make
, source
, "rpc.h", 0, INCL_NORMAL
);
1603 add_include( make
, source
, "rpcndr.h", 0, INCL_NORMAL
);
1604 for (i
= 0; i
< file
->deps_count
; i
++)
1606 switch (file
->deps
[i
].type
)
1609 if (strendswith( file
->deps
[i
].name
, ".idl" ))
1610 add_include( make
, source
, replace_extension( file
->deps
[i
].name
, ".idl", ".h" ),
1611 file
->deps
[i
].line
, INCL_NORMAL
);
1613 add_include( make
, source
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_NORMAL
);
1615 case INCL_CPP_QUOTE
:
1616 add_include( make
, source
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_NORMAL
);
1618 case INCL_CPP_QUOTE_SYSTEM
:
1619 add_include( make
, source
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_SYSTEM
);
1623 case INCL_IMPORTLIB
:
1629 if (strendswith( source
->sourcename
, ".y" ))
1630 return; /* generated .tab.h doesn't include anything */
1633 add_all_includes( make
, source
, file
);
1637 /*******************************************************************
1640 * Add a source file to the list.
1642 static struct incl_file
*add_src_file( struct makefile
*make
, const char *name
)
1644 struct incl_file
*file
;
1646 if ((file
= find_src_file( make
, name
))) return file
; /* we already have it */
1647 file
= xmalloc( sizeof(*file
) );
1648 memset( file
, 0, sizeof(*file
) );
1649 file
->name
= xstrdup(name
);
1650 list_add_tail( &make
->sources
, &file
->entry
);
1651 parse_file( make
, file
, 1 );
1656 /*******************************************************************
1657 * open_input_makefile
1659 static FILE *open_input_makefile( const struct makefile
*make
)
1664 input_file_name
= root_dir_path( base_dir_path( make
, strmake( "%s.in", output_makefile_name
)));
1666 input_file_name
= output_makefile_name
; /* always use output name for main Makefile */
1669 if (!(ret
= fopen( input_file_name
, "r" ))) fatal_perror( "open" );
1674 /*******************************************************************
1677 static const char *get_make_variable( const struct makefile
*make
, const char *name
)
1681 if ((ret
= strarray_get_value( &cmdline_vars
, name
))) return ret
;
1682 if ((ret
= strarray_get_value( &make
->vars
, name
))) return ret
;
1683 if (top_makefile
&& (ret
= strarray_get_value( &top_makefile
->vars
, name
))) return ret
;
1688 /*******************************************************************
1689 * get_expanded_make_variable
1691 static char *get_expanded_make_variable( const struct makefile
*make
, const char *name
)
1694 char *p
, *end
, *expand
, *tmp
;
1696 var
= get_make_variable( make
, name
);
1697 if (!var
) return NULL
;
1699 p
= expand
= xstrdup( var
);
1700 while ((p
= strchr( p
, '$' )))
1704 if (!(end
= strchr( p
+ 2, ')' ))) fatal_error( "syntax error in '%s'\n", expand
);
1706 if (strchr( p
+ 2, ':' )) fatal_error( "pattern replacement not supported for '%s'\n", p
+ 2 );
1707 var
= get_make_variable( make
, p
+ 2 );
1708 tmp
= replace_substr( expand
, p
, end
- p
, var
? var
: "" );
1709 /* switch to the new string */
1710 p
= tmp
+ (p
- expand
);
1714 else if (p
[1] == '{') /* don't expand ${} variables */
1716 if (!(end
= strchr( p
+ 2, '}' ))) fatal_error( "syntax error in '%s'\n", expand
);
1719 else if (p
[1] == '$')
1723 else fatal_error( "syntax error in '%s'\n", expand
);
1726 /* consider empty variables undefined */
1728 while (*p
&& isspace(*p
)) p
++;
1729 if (*p
) return expand
;
1735 /*******************************************************************
1736 * get_expanded_make_var_array
1738 static struct strarray
get_expanded_make_var_array( const struct makefile
*make
, const char *name
)
1740 struct strarray ret
= empty_strarray
;
1741 char *value
, *token
;
1743 if ((value
= get_expanded_make_variable( make
, name
)))
1744 for (token
= strtok( value
, " \t" ); token
; token
= strtok( NULL
, " \t" ))
1745 strarray_add( &ret
, token
);
1750 /*******************************************************************
1751 * get_expanded_file_local_var
1753 static struct strarray
get_expanded_file_local_var( const struct makefile
*make
, const char *file
,
1756 char *p
, *var
= strmake( "%s_%s", file
, name
);
1758 for (p
= var
; *p
; p
++) if (!isalnum( *p
)) *p
= '_';
1759 return get_expanded_make_var_array( make
, var
);
1763 /*******************************************************************
1766 static int set_make_variable( struct strarray
*array
, const char *assignment
)
1770 p
= name
= xstrdup( assignment
);
1771 while (isalnum(*p
) || *p
== '_') p
++;
1772 if (name
== p
) return 0; /* not a variable */
1776 while (isspace(*p
)) p
++;
1778 if (*p
!= '=') return 0; /* not an assignment */
1780 while (isspace(*p
)) p
++;
1782 strarray_set_value( array
, name
, p
);
1787 /*******************************************************************
1790 static struct makefile
*parse_makefile( const char *path
)
1794 struct makefile
*make
= xmalloc( sizeof(*make
) );
1796 memset( make
, 0, sizeof(*make
) );
1799 make
->top_obj_dir
= get_relative_path( path
, "" );
1800 make
->base_dir
= path
;
1801 if (!strcmp( make
->base_dir
, "." )) make
->base_dir
= NULL
;
1804 file
= open_input_makefile( make
);
1805 while ((buffer
= get_line( file
)))
1807 if (!strncmp( buffer
, separator
, strlen(separator
) )) break;
1808 if (*buffer
== '\t') continue; /* command */
1809 while (isspace( *buffer
)) buffer
++;
1810 if (*buffer
== '#') continue; /* comment */
1811 set_make_variable( &make
->vars
, buffer
);
1814 input_file_name
= NULL
;
1819 /*******************************************************************
1820 * add_generated_sources
1822 static void add_generated_sources( struct makefile
*make
)
1825 struct incl_file
*source
, *next
, *file
;
1826 struct strarray objs
= get_expanded_make_var_array( make
, "EXTRA_OBJS" );
1828 LIST_FOR_EACH_ENTRY_SAFE( source
, next
, &make
->sources
, struct incl_file
, entry
)
1830 if (source
->file
->flags
& FLAG_IDL_CLIENT
)
1832 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_c.c" ), NULL
);
1833 add_dependency( file
->file
, replace_extension( source
->name
, ".idl", ".h" ), INCL_NORMAL
);
1834 add_all_includes( make
, file
, file
->file
);
1836 if (source
->file
->flags
& FLAG_IDL_SERVER
)
1838 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_s.c" ), NULL
);
1839 add_dependency( file
->file
, "wine/exception.h", INCL_NORMAL
);
1840 add_dependency( file
->file
, replace_extension( source
->name
, ".idl", ".h" ), INCL_NORMAL
);
1841 add_all_includes( make
, file
, file
->file
);
1843 if (source
->file
->flags
& FLAG_IDL_IDENT
)
1845 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_i.c" ), NULL
);
1846 add_dependency( file
->file
, "rpc.h", INCL_NORMAL
);
1847 add_dependency( file
->file
, "rpcndr.h", INCL_NORMAL
);
1848 add_dependency( file
->file
, "guiddef.h", INCL_NORMAL
);
1849 add_all_includes( make
, file
, file
->file
);
1851 if (source
->file
->flags
& FLAG_IDL_PROXY
)
1853 file
= add_generated_source( make
, "dlldata.o", "dlldata.c" );
1854 add_dependency( file
->file
, "objbase.h", INCL_NORMAL
);
1855 add_dependency( file
->file
, "rpcproxy.h", INCL_NORMAL
);
1856 add_all_includes( make
, file
, file
->file
);
1857 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_p.c" ), NULL
);
1858 add_dependency( file
->file
, "objbase.h", INCL_NORMAL
);
1859 add_dependency( file
->file
, "rpcproxy.h", INCL_NORMAL
);
1860 add_dependency( file
->file
, "wine/exception.h", INCL_NORMAL
);
1861 add_dependency( file
->file
, replace_extension( source
->name
, ".idl", ".h" ), INCL_NORMAL
);
1862 add_all_includes( make
, file
, file
->file
);
1864 if (source
->file
->flags
& FLAG_IDL_TYPELIB
)
1866 add_generated_source( make
, replace_extension( source
->name
, ".idl", ".tlb" ), NULL
);
1868 if (source
->file
->flags
& FLAG_IDL_REGTYPELIB
)
1870 add_generated_source( make
, replace_extension( source
->name
, ".idl", "_t.res" ), NULL
);
1872 if (source
->file
->flags
& FLAG_IDL_REGISTER
)
1874 add_generated_source( make
, replace_extension( source
->name
, ".idl", "_r.res" ), NULL
);
1876 if (source
->file
->flags
& FLAG_IDL_HEADER
)
1878 add_generated_source( make
, replace_extension( source
->name
, ".idl", ".h" ), NULL
);
1880 if (!source
->file
->flags
&& strendswith( source
->name
, ".idl" ))
1882 add_generated_source( make
, replace_extension( source
->name
, ".idl", ".h" ), NULL
);
1884 if (strendswith( source
->name
, ".x" ))
1886 add_generated_source( make
, replace_extension( source
->name
, ".x", ".h" ), NULL
);
1888 if (strendswith( source
->name
, ".y" ))
1890 file
= add_generated_source( make
, replace_extension( source
->name
, ".y", ".tab.c" ), NULL
);
1891 /* steal the includes list from the source file */
1892 file
->files_count
= source
->files_count
;
1893 file
->files_size
= source
->files_size
;
1894 file
->files
= source
->files
;
1895 source
->files_count
= source
->files_size
= 0;
1896 source
->files
= NULL
;
1898 if (strendswith( source
->name
, ".l" ))
1900 file
= add_generated_source( make
, replace_extension( source
->name
, ".l", ".yy.c" ), NULL
);
1901 /* steal the includes list from the source file */
1902 file
->files_count
= source
->files_count
;
1903 file
->files_size
= source
->files_size
;
1904 file
->files
= source
->files
;
1905 source
->files_count
= source
->files_size
= 0;
1906 source
->files
= NULL
;
1908 if (source
->file
->flags
& FLAG_C_IMPLIB
)
1910 if (!make
->staticimplib
&& make
->importlib
&& *dll_ext
)
1911 make
->staticimplib
= strmake( "lib%s.a", make
->importlib
);
1913 if (strendswith( source
->name
, ".po" ))
1915 if (!make
->disabled
)
1916 strarray_add_uniq( &linguas
, replace_extension( source
->name
, ".po", "" ));
1921 file
= add_generated_source( make
, "testlist.o", "testlist.c" );
1922 add_dependency( file
->file
, "wine/test.h", INCL_NORMAL
);
1923 add_all_includes( make
, file
, file
->file
);
1925 for (i
= 0; i
< objs
.count
; i
++)
1927 /* default to .c for unknown extra object files */
1928 if (strendswith( objs
.str
[i
], ".o" ))
1929 add_generated_source( make
, objs
.str
[i
], replace_extension( objs
.str
[i
], ".o", ".c" ));
1930 else if (strendswith( objs
.str
[i
], ".res" ))
1931 add_generated_source( make
, replace_extension( objs
.str
[i
], ".res", ".rc" ), NULL
);
1933 add_generated_source( make
, objs
.str
[i
], NULL
);
1938 /*******************************************************************
1941 static void create_dir( const char *dir
)
1945 p
= path
= xstrdup( dir
);
1946 while ((p
= strchr( p
, '/' )))
1949 if (mkdir( path
, 0755 ) == -1 && errno
!= EEXIST
) fatal_perror( "mkdir %s", path
);
1951 while (*p
== '/') p
++;
1953 if (mkdir( path
, 0755 ) == -1 && errno
!= EEXIST
) fatal_perror( "mkdir %s", path
);
1958 /*******************************************************************
1959 * create_file_directories
1961 * Create the base directories of all the files.
1963 static void create_file_directories( const struct makefile
*make
, struct strarray files
)
1965 struct strarray subdirs
= empty_strarray
;
1969 for (i
= 0; i
< files
.count
; i
++)
1971 if (!strchr( files
.str
[i
], '/' )) continue;
1972 dir
= base_dir_path( make
, files
.str
[i
] );
1973 *strrchr( dir
, '/' ) = 0;
1974 strarray_add_uniq( &subdirs
, dir
);
1977 for (i
= 0; i
< subdirs
.count
; i
++) create_dir( subdirs
.str
[i
] );
1981 /*******************************************************************
1982 * output_filenames_obj_dir
1984 static void output_filenames_obj_dir( const struct makefile
*make
, struct strarray array
)
1988 for (i
= 0; i
< array
.count
; i
++) output_filename( obj_dir_path( make
, array
.str
[i
] ));
1992 /*******************************************************************
1995 static void get_dependencies( struct incl_file
*file
, struct incl_file
*source
)
1999 if (!file
->filename
) return;
2003 if (file
->owner
== source
) return; /* already processed */
2004 if (file
->type
== INCL_IMPORTLIB
&&
2005 !(source
->file
->flags
& (FLAG_IDL_TYPELIB
| FLAG_IDL_REGTYPELIB
)))
2006 return; /* library is imported only when building a typelib */
2007 file
->owner
= source
;
2008 strarray_add( &source
->dependencies
, file
->filename
);
2010 for (i
= 0; i
< file
->files_count
; i
++) get_dependencies( file
->files
[i
], source
);
2014 /*******************************************************************
2015 * get_local_dependencies
2017 * Get the local dependencies of a given target.
2019 static struct strarray
get_local_dependencies( const struct makefile
*make
, const char *name
,
2020 struct strarray targets
)
2023 struct strarray deps
= get_expanded_file_local_var( make
, name
, "DEPS" );
2025 for (i
= 0; i
< deps
.count
; i
++)
2027 if (strarray_exists( &targets
, deps
.str
[i
] ))
2028 deps
.str
[i
] = obj_dir_path( make
, deps
.str
[i
] );
2030 deps
.str
[i
] = src_dir_path( make
, deps
.str
[i
] );
2036 /*******************************************************************
2039 * Check if makefile builds the named static library and return the full lib path.
2041 static const char *get_static_lib( const struct makefile
*make
, const char *name
)
2043 if (!make
->staticlib
) return NULL
;
2044 if (strncmp( make
->staticlib
, "lib", 3 )) return NULL
;
2045 if (strncmp( make
->staticlib
+ 3, name
, strlen(name
) )) return NULL
;
2046 if (strcmp( make
->staticlib
+ 3 + strlen(name
), ".a" )) return NULL
;
2047 return base_dir_path( make
, make
->staticlib
);
2051 /*******************************************************************
2052 * add_default_libraries
2054 static struct strarray
add_default_libraries( const struct makefile
*make
, struct strarray
*deps
)
2056 struct strarray ret
= empty_strarray
;
2057 struct strarray all_libs
= empty_strarray
;
2060 strarray_add( &all_libs
, "-lwine_port" );
2061 strarray_addall( &all_libs
, get_expanded_make_var_array( make
, "EXTRALIBS" ));
2062 strarray_addall( &all_libs
, libs
);
2064 for (i
= 0; i
< all_libs
.count
; i
++)
2066 const char *lib
= NULL
;
2068 if (!strncmp( all_libs
.str
[i
], "-l", 2 ))
2070 const char *name
= all_libs
.str
[i
] + 2;
2072 for (j
= 0; j
< top_makefile
->subdirs
.count
; j
++)
2074 const struct makefile
*submake
= top_makefile
->submakes
[j
];
2076 if ((lib
= get_static_lib( submake
, name
))) break;
2082 lib
= top_obj_dir_path( make
, lib
);
2083 strarray_add( deps
, lib
);
2084 strarray_add( &ret
, lib
);
2086 else strarray_add( &ret
, all_libs
.str
[i
] );
2092 /*******************************************************************
2095 static struct strarray
add_import_libs( const struct makefile
*make
, struct strarray
*deps
,
2096 struct strarray imports
, int cross
)
2098 struct strarray ret
= empty_strarray
;
2101 for (i
= 0; i
< imports
.count
; i
++)
2103 const char *name
= imports
.str
[i
];
2104 const char *lib
= NULL
;
2106 for (j
= 0; j
< top_makefile
->subdirs
.count
; j
++)
2108 const struct makefile
*submake
= top_makefile
->submakes
[j
];
2110 if (submake
->importlib
&& !strcmp( submake
->importlib
, name
))
2112 if (cross
|| !*dll_ext
|| submake
->staticimplib
)
2113 lib
= base_dir_path( submake
, strmake( "lib%s.a", name
));
2115 strarray_add( deps
, top_obj_dir_path( make
,
2116 strmake( "%s/lib%s.def", submake
->base_dir
, name
)));
2120 if ((lib
= get_static_lib( submake
, name
))) break;
2125 if (cross
) lib
= replace_extension( lib
, ".a", ".cross.a" );
2126 lib
= top_obj_dir_path( make
, lib
);
2127 strarray_add( deps
, lib
);
2128 strarray_add( &ret
, lib
);
2130 else strarray_add( &ret
, strmake( "-l%s", name
));
2136 /*******************************************************************
2137 * get_default_imports
2139 static struct strarray
get_default_imports( const struct makefile
*make
)
2141 struct strarray ret
= empty_strarray
;
2143 if (strarray_exists( &make
->extradllflags
, "-nodefaultlibs" )) return ret
;
2144 if (strarray_exists( &make
->appmode
, "-mno-cygwin" )) strarray_add( &ret
, "msvcrt" );
2145 if (make
->is_win16
) strarray_add( &ret
, "kernel" );
2146 strarray_add( &ret
, "kernel32" );
2147 strarray_add( &ret
, "ntdll" );
2148 strarray_add( &ret
, "winecrt0" );
2153 /*******************************************************************
2156 static void add_install_rule( struct makefile
*make
, const char *target
,
2157 const char *file
, const char *dest
)
2159 if (strarray_exists( &make
->install_lib
, target
) ||
2160 strarray_exists( &top_install_lib
, make
->base_dir
) ||
2161 strarray_exists( &top_install_lib
, base_dir_path( make
, target
)))
2163 strarray_add( &make
->install_rules
[INSTALL_LIB
], file
);
2164 strarray_add( &make
->install_rules
[INSTALL_LIB
], dest
);
2166 else if (strarray_exists( &make
->install_dev
, target
) ||
2167 strarray_exists( &top_install_dev
, make
->base_dir
) ||
2168 strarray_exists( &top_install_dev
, base_dir_path( make
, target
)))
2170 strarray_add( &make
->install_rules
[INSTALL_DEV
], file
);
2171 strarray_add( &make
->install_rules
[INSTALL_DEV
], dest
);
2176 /*******************************************************************
2177 * get_include_install_path
2179 * Determine the installation path for a given include file.
2181 static const char *get_include_install_path( const char *name
)
2183 if (!strncmp( name
, "wine/", 5 )) return name
+ 5;
2184 if (!strncmp( name
, "msvcrt/", 7 )) return name
;
2185 return strmake( "windows/%s", name
);
2189 /*******************************************************************
2190 * get_shared_library_name
2192 * Determine possible names for a shared library with a version number.
2194 static struct strarray
get_shared_lib_names( const char *libname
)
2196 struct strarray ret
= empty_strarray
;
2197 const char *ext
, *p
;
2198 char *name
, *first
, *second
;
2201 strarray_add( &ret
, libname
);
2203 for (p
= libname
; (p
= strchr( p
, '.' )); p
++)
2204 if ((len
= strspn( p
+ 1, "0123456789." ))) break;
2206 if (!len
) return ret
;
2208 if (*ext
&& ext
[-1] == '.') ext
--;
2210 /* keep only the first group of digits */
2211 name
= xstrdup( libname
);
2212 first
= name
+ (p
- libname
);
2213 if ((second
= strchr( first
+ 1, '.' )))
2215 strcpy( second
, ext
);
2216 strarray_add( &ret
, xstrdup( name
));
2218 /* now remove all digits */
2219 strcpy( first
, ext
);
2220 strarray_add( &ret
, name
);
2225 /*******************************************************************
2226 * output_symlink_rule
2228 * Output a rule to create a symlink.
2230 static void output_symlink_rule( const char *src_name
, const char *link_name
)
2234 output( "\trm -f %s && ", link_name
);
2236 /* dest path with a directory needs special handling if ln -s isn't supported */
2237 if (strcmp( ln_s
, "ln -s" ) && ((name
= strrchr( link_name
, '/' ))))
2239 char *dir
= xstrdup( link_name
);
2240 dir
[name
- link_name
] = 0;
2241 output( "cd %s && %s %s %s\n", *dir
? dir
: "/", ln_s
, src_name
, name
+ 1 );
2246 output( "%s %s %s\n", ln_s
, src_name
, link_name
);
2251 /*******************************************************************
2252 * output_install_commands
2254 static void output_install_commands( struct makefile
*make
, const struct makefile
*submake
,
2255 struct strarray files
)
2258 char *install_sh
= top_src_dir_path( make
, "tools/install-sh" );
2260 for (i
= 0; i
< files
.count
; i
+= 2)
2262 const char *file
= files
.str
[i
];
2263 const char *dest
= strmake( "$(DESTDIR)%s", files
.str
[i
+ 1] + 1 );
2265 if (submake
) file
= base_dir_path( submake
, file
);
2266 switch (*files
.str
[i
+ 1])
2268 case 'd': /* data file */
2269 output( "\t%s -m 644 $(INSTALL_DATA_FLAGS) %s %s\n",
2270 install_sh
, obj_dir_path( make
, file
), dest
);
2272 case 'D': /* data file in source dir */
2273 output( "\t%s -m 644 $(INSTALL_DATA_FLAGS) %s %s\n",
2274 install_sh
, src_dir_path( make
, file
), dest
);
2276 case 'p': /* program file */
2277 output( "\tSTRIPPROG=\"$(STRIP)\" %s $(INSTALL_PROGRAM_FLAGS) %s %s\n",
2278 install_sh
, obj_dir_path( make
, file
), dest
);
2280 case 's': /* script */
2281 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s %s\n",
2282 install_sh
, obj_dir_path( make
, file
), dest
);
2284 case 'S': /* script in source dir */
2285 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s %s\n",
2286 install_sh
, src_dir_path( make
, file
), dest
);
2288 case 't': /* script in tools dir */
2289 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s %s\n",
2290 install_sh
, tools_dir_path( make
, files
.str
[i
] ), dest
);
2292 case 'y': /* symlink */
2293 output_symlink_rule( files
.str
[i
], dest
);
2298 strarray_add( &make
->uninstall_files
, dest
);
2303 /*******************************************************************
2304 * output_install_rules
2306 * Rules are stored as a (file,dest) pair of values.
2307 * The first char of dest indicates the type of install.
2309 static void output_install_rules( struct makefile
*make
, enum install_rules rules
, const char *target
)
2312 struct strarray files
= make
->install_rules
[rules
];
2313 struct strarray targets
= empty_strarray
;
2315 if (!files
.count
) return;
2317 for (i
= 0; i
< files
.count
; i
+= 2)
2319 const char *file
= files
.str
[i
];
2320 switch (*files
.str
[i
+ 1])
2322 case 'd': /* data file */
2323 case 'p': /* program file */
2324 case 's': /* script */
2325 strarray_add_uniq( &targets
, obj_dir_path( make
, file
));
2327 case 't': /* script in tools dir */
2328 strarray_add_uniq( &targets
, tools_dir_path( make
, file
));
2333 output( "install %s::", target
);
2334 output_filenames( targets
);
2336 output_install_commands( make
, NULL
, files
);
2338 strarray_add_uniq( &make
->phony_targets
, "install" );
2339 strarray_add_uniq( &make
->phony_targets
, target
);
2343 static int cmp_string_length( const char **a
, const char **b
)
2345 int paths_a
= 0, paths_b
= 0;
2348 for (p
= *a
; *p
; p
++) if (*p
== '/') paths_a
++;
2349 for (p
= *b
; *p
; p
++) if (*p
== '/') paths_b
++;
2350 if (paths_b
!= paths_a
) return paths_b
- paths_a
;
2351 return strcmp( *a
, *b
);
2354 /*******************************************************************
2355 * output_uninstall_rules
2357 static void output_uninstall_rules( struct makefile
*make
)
2359 static const char *dirs_order
[] =
2360 { "$(includedir)", "$(mandir)", "$(fontdir)", "$(datadir)", "$(dlldir)" };
2362 struct strarray subdirs
= empty_strarray
;
2365 if (!make
->uninstall_files
.count
) return;
2366 output( "uninstall::\n" );
2367 output_rm_filenames( make
->uninstall_files
);
2368 strarray_add_uniq( &make
->phony_targets
, "uninstall" );
2370 if (!make
->subdirs
.count
) return;
2371 for (i
= 0; i
< make
->uninstall_files
.count
; i
++)
2373 char *dir
= xstrdup( make
->uninstall_files
.str
[i
] );
2374 while (strchr( dir
, '/' ))
2376 *strrchr( dir
, '/' ) = 0;
2377 strarray_add_uniq( &subdirs
, xstrdup(dir
) );
2380 strarray_qsort( &subdirs
, cmp_string_length
);
2381 output( "\t-rmdir" );
2382 for (i
= 0; i
< sizeof(dirs_order
)/sizeof(dirs_order
[0]); i
++)
2384 for (j
= 0; j
< subdirs
.count
; j
++)
2386 if (!subdirs
.str
[j
]) continue;
2387 if (strncmp( subdirs
.str
[j
] + strlen("$(DESTDIR)"), dirs_order
[i
], strlen(dirs_order
[i
]) ))
2389 output_filename( subdirs
.str
[j
] );
2390 subdirs
.str
[j
] = NULL
;
2393 for (j
= 0; j
< subdirs
.count
; j
++)
2394 if (subdirs
.str
[j
]) output_filename( subdirs
.str
[j
] );
2399 /*******************************************************************
2400 * output_importlib_symlinks
2402 static struct strarray
output_importlib_symlinks( const struct makefile
*parent
,
2403 const struct makefile
*make
)
2405 struct strarray ret
= empty_strarray
;
2406 const char *lib
, *dst
;
2408 if (!make
->module
) return ret
;
2409 if (!make
->importlib
) return ret
;
2410 if (make
->is_win16
&& make
->disabled
) return ret
;
2411 if (strncmp( make
->base_dir
, "dlls/", 5 )) return ret
;
2412 if (!strcmp( make
->module
, make
->importlib
)) return ret
;
2413 if (!strchr( make
->importlib
, '.' ) &&
2414 !strncmp( make
->module
, make
->importlib
, strlen( make
->importlib
)) &&
2415 !strcmp( make
->module
+ strlen( make
->importlib
), ".dll" ))
2418 lib
= strmake( "lib%s.%s", make
->importlib
, *dll_ext
? "def" : "a" );
2419 dst
= concat_paths( obj_dir_path( parent
, "dlls" ), lib
);
2420 output( "%s: %s\n", dst
, base_dir_path( make
, lib
));
2421 output_symlink_rule( concat_paths( make
->base_dir
+ strlen("dlls/"), lib
), dst
);
2422 strarray_add( &ret
, dst
);
2424 if (crosstarget
&& !make
->is_win16
)
2426 lib
= strmake( "lib%s.cross.a", make
->importlib
);
2427 dst
= concat_paths( obj_dir_path( parent
, "dlls" ), lib
);
2428 output( "%s: %s\n", dst
, base_dir_path( make
, lib
));
2429 output_symlink_rule( concat_paths( make
->base_dir
+ strlen("dlls/"), lib
), dst
);
2430 strarray_add( &ret
, dst
);
2436 /*******************************************************************
2439 static void output_po_files( const struct makefile
*make
)
2441 const char *po_dir
= src_dir_path( make
, "po" );
2442 struct strarray pot_files
= empty_strarray
;
2443 struct incl_file
*source
;
2446 for (i
= 0; i
< make
->subdirs
.count
; i
++)
2448 struct makefile
*submake
= make
->submakes
[i
];
2450 LIST_FOR_EACH_ENTRY( source
, &submake
->sources
, struct incl_file
, entry
)
2452 if (source
->file
->flags
& FLAG_PARENTDIR
) continue;
2453 if (strendswith( source
->name
, ".rc" ) && (source
->file
->flags
& FLAG_RC_PO
))
2455 char *pot_file
= replace_extension( source
->name
, ".rc", ".pot" );
2456 char *pot_path
= base_dir_path( submake
, pot_file
);
2457 output( "%s: tools/wrc include dummy\n", pot_path
);
2458 output( "\t@cd %s && $(MAKE) %s\n", base_dir_path( submake
, "" ), pot_file
);
2459 strarray_add( &pot_files
, pot_path
);
2461 else if (strendswith( source
->name
, ".mc" ))
2463 char *pot_file
= replace_extension( source
->name
, ".mc", ".pot" );
2464 char *pot_path
= base_dir_path( submake
, pot_file
);
2465 output( "%s: tools/wmc include dummy\n", pot_path
);
2466 output( "\t@cd %s && $(MAKE) %s\n", base_dir_path( submake
, "" ), pot_file
);
2467 strarray_add( &pot_files
, pot_path
);
2473 for (i
= 0; i
< linguas
.count
; i
++)
2474 output_filename( strmake( "%s/%s.po", po_dir
, linguas
.str
[i
] ));
2475 output( ": %s/wine.pot\n", po_dir
);
2476 output( "\tmsgmerge --previous -q $@ %s/wine.pot | msgattrib --no-obsolete -o $@.new && mv $@.new $@\n",
2479 for (i
= 0; i
< linguas
.count
; i
++)
2480 output_filename( strmake( "%s/%s.po", po_dir
, linguas
.str
[i
] ));
2483 output( "%s/wine.pot:", po_dir
);
2484 output_filenames( pot_files
);
2486 output( "\tmsgcat -o $@" );
2487 output_filenames( pot_files
);
2492 /*******************************************************************
2495 static void output_source_y( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2497 /* add source file dependency for parallel makes */
2498 char *header
= strmake( "%s.tab.h", obj
);
2500 if (find_include_file( make
, header
))
2502 output( "%s: %s\n", obj_dir_path( make
, header
), source
->filename
);
2503 output( "\t%s -p %s_ -o %s.tab.c -d %s\n",
2504 bison
, obj
, obj_dir_path( make
, obj
), source
->filename
);
2505 output( "%s.tab.c: %s %s\n", obj_dir_path( make
, obj
),
2506 source
->filename
, obj_dir_path( make
, header
));
2507 strarray_add( &make
->clean_files
, header
);
2509 else output( "%s.tab.c: %s\n", obj
, source
->filename
);
2511 output( "\t%s -p %s_ -o $@ %s\n", bison
, obj
, source
->filename
);
2515 /*******************************************************************
2518 static void output_source_l( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2520 output( "%s.yy.c: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2521 output( "\t%s -o$@ %s\n", flex
, source
->filename
);
2525 /*******************************************************************
2528 static void output_source_h( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2530 if (source
->file
->flags
& FLAG_GENERATED
)
2531 strarray_add( &make
->all_targets
, source
->name
);
2533 add_install_rule( make
, source
->name
, source
->name
,
2534 strmake( "D$(includedir)/wine/%s", get_include_install_path( source
->name
) ));
2538 /*******************************************************************
2541 static void output_source_rc( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2543 struct strarray extradefs
= get_expanded_file_local_var( make
, obj
, "EXTRADEFS" );
2546 if (source
->file
->flags
& FLAG_GENERATED
) strarray_add( &make
->clean_files
, source
->name
);
2547 strarray_add( &make
->object_files
, strmake( "%s.res", obj
));
2548 if (crosstarget
) strarray_add( &make
->crossobj_files
, strmake( "%s.res", obj
));
2549 output( "%s.res: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2550 output( "\t%s -o $@", tools_path( make
, "wrc" ) );
2551 if (make
->is_win16
) output_filename( "-m16" );
2552 else output_filenames( target_flags
);
2553 output_filename( "--nostdinc" );
2554 output_filenames( make
->include_args
);
2555 output_filenames( make
->define_args
);
2556 output_filenames( extradefs
);
2557 if (linguas
.count
&& (source
->file
->flags
& FLAG_RC_PO
))
2559 char *po_dir
= top_obj_dir_path( make
, "po" );
2560 output_filename( strmake( "--po-dir=%s", po_dir
));
2561 output_filename( source
->filename
);
2563 output( "%s.res:", obj_dir_path( make
, obj
));
2564 for (i
= 0; i
< linguas
.count
; i
++)
2565 output_filename( strmake( "%s/%s.mo", po_dir
, linguas
.str
[i
] ));
2570 output_filename( source
->filename
);
2573 if (source
->file
->flags
& FLAG_RC_PO
&& !(source
->file
->flags
& FLAG_PARENTDIR
))
2575 strarray_add( &make
->clean_files
, strmake( "%s.pot", obj
));
2576 output( "%s.pot: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2577 output( "\t%s -O pot -o $@", tools_path( make
, "wrc" ) );
2578 if (make
->is_win16
) output_filename( "-m16" );
2579 else output_filenames( target_flags
);
2580 output_filename( "--nostdinc" );
2581 output_filenames( make
->include_args
);
2582 output_filenames( make
->define_args
);
2583 output_filenames( extradefs
);
2584 output_filename( source
->filename
);
2586 output( "%s.pot ", obj_dir_path( make
, obj
));
2588 output( "%s.res:", obj_dir_path( make
, obj
));
2589 output_filename( tools_path( make
, "wrc" ));
2590 output_filenames( source
->dependencies
);
2595 /*******************************************************************
2598 static void output_source_mc( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2602 strarray_add( &make
->object_files
, strmake( "%s.res", obj
));
2603 if (crosstarget
) strarray_add( &make
->crossobj_files
, strmake( "%s.res", obj
));
2604 strarray_add( &make
->clean_files
, strmake( "%s.pot", obj
));
2605 output( "%s.res: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2606 output( "\t%s -U -O res -o $@ %s", tools_path( make
, "wmc" ), source
->filename
);
2609 char *po_dir
= top_obj_dir_path( make
, "po" );
2610 output_filename( strmake( "--po-dir=%s", po_dir
));
2612 output( "%s.res:", obj_dir_path( make
, obj
));
2613 for (i
= 0; i
< linguas
.count
; i
++)
2614 output_filename( strmake( "%s/%s.mo", po_dir
, linguas
.str
[i
] ));
2617 output( "%s.pot: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2618 output( "\t%s -O pot -o $@ %s", tools_path( make
, "wmc" ), source
->filename
);
2620 output( "%s.pot %s.res:", obj_dir_path( make
, obj
), obj_dir_path( make
, obj
));
2621 output_filename( tools_path( make
, "wmc" ));
2622 output_filenames( source
->dependencies
);
2627 /*******************************************************************
2630 static void output_source_res( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2632 strarray_add( &make
->object_files
, source
->name
);
2633 if (crosstarget
) strarray_add( &make
->crossobj_files
, source
->name
);
2637 /*******************************************************************
2640 static void output_source_idl( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2642 struct strarray extradefs
= get_expanded_file_local_var( make
, obj
, "EXTRADEFS" );
2643 struct strarray targets
= empty_strarray
;
2647 if (!source
->file
->flags
) source
->file
->flags
|= FLAG_IDL_HEADER
| FLAG_INSTALL
;
2648 if (find_include_file( make
, strmake( "%s.h", obj
))) source
->file
->flags
|= FLAG_IDL_HEADER
;
2650 for (i
= 0; i
< sizeof(idl_outputs
) / sizeof(idl_outputs
[0]); i
++)
2652 if (!(source
->file
->flags
& idl_outputs
[i
].flag
)) continue;
2653 dest
= strmake( "%s%s", obj
, idl_outputs
[i
].ext
);
2654 if (!find_src_file( make
, dest
)) strarray_add( &make
->clean_files
, dest
);
2655 strarray_add( &targets
, dest
);
2657 if (source
->file
->flags
& FLAG_IDL_PROXY
) strarray_add( &make
->dlldata_files
, source
->name
);
2658 if (source
->file
->flags
& FLAG_INSTALL
)
2660 add_install_rule( make
, source
->name
, xstrdup( source
->name
),
2661 strmake( "D$(includedir)/wine/%s.idl", get_include_install_path( obj
) ));
2662 if (source
->file
->flags
& FLAG_IDL_HEADER
)
2663 add_install_rule( make
, source
->name
, strmake( "%s.h", obj
),
2664 strmake( "d$(includedir)/wine/%s.h", get_include_install_path( obj
) ));
2666 if (!targets
.count
) return;
2668 output_filenames_obj_dir( make
, targets
);
2669 output( ": %s\n", tools_path( make
, "widl" ));
2670 output( "\t%s -o $@", tools_path( make
, "widl" ) );
2671 output_filenames( target_flags
);
2672 output_filenames( make
->include_args
);
2673 output_filenames( make
->define_args
);
2674 output_filenames( extradefs
);
2675 output_filenames( get_expanded_make_var_array( make
, "EXTRAIDLFLAGS" ));
2676 output_filenames( get_expanded_file_local_var( make
, obj
, "EXTRAIDLFLAGS" ));
2677 output_filename( source
->filename
);
2679 output_filenames_obj_dir( make
, targets
);
2680 output( ": %s", source
->filename
);
2681 output_filenames( source
->dependencies
);
2686 /*******************************************************************
2689 static void output_source_tlb( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2691 strarray_add( &make
->all_targets
, source
->name
);
2695 /*******************************************************************
2698 static void output_source_x( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2700 output( "%s.h: %s%s %s\n", obj_dir_path( make
, obj
),
2701 tools_dir_path( make
, "make_xftmpl" ), tools_ext
, source
->filename
);
2702 output( "\t%s%s -H -o $@ %s\n",
2703 tools_dir_path( make
, "make_xftmpl" ), tools_ext
, source
->filename
);
2704 if (source
->file
->flags
& FLAG_INSTALL
)
2706 add_install_rule( make
, source
->name
, source
->name
,
2707 strmake( "D$(includedir)/wine/%s", get_include_install_path( source
->name
) ));
2708 add_install_rule( make
, source
->name
, strmake( "%s.h", obj
),
2709 strmake( "d$(includedir)/wine/%s.h", get_include_install_path( obj
) ));
2714 /*******************************************************************
2717 static void output_source_sfd( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2720 char *ttf_obj
= strmake( "%s.ttf", obj
);
2721 char *ttf_file
= src_dir_path( make
, ttf_obj
);
2723 if (fontforge
&& !make
->src_dir
)
2725 output( "%s: %s\n", ttf_file
, source
->filename
);
2726 output( "\t%s -script %s %s $@\n",
2727 fontforge
, top_src_dir_path( make
, "fonts/genttf.ff" ), source
->filename
);
2728 if (!(source
->file
->flags
& FLAG_SFD_FONTS
)) output( "all: %s\n", ttf_file
);
2730 if (source
->file
->flags
& FLAG_INSTALL
)
2731 add_install_rule( make
, source
->name
, ttf_obj
, strmake( "D$(fontdir)/%s", ttf_obj
));
2733 if (source
->file
->flags
& FLAG_SFD_FONTS
)
2735 struct strarray
*array
= source
->file
->args
;
2737 for (i
= 0; i
< array
->count
; i
++)
2739 char *font
= strtok( xstrdup(array
->str
[i
]), " \t" );
2740 char *args
= strtok( NULL
, "" );
2742 strarray_add( &make
->all_targets
, xstrdup( font
));
2743 output( "%s: %s %s\n", obj_dir_path( make
, font
),
2744 tools_path( make
, "sfnt2fon" ), ttf_file
);
2745 output( "\t%s -o $@ %s %s\n", tools_path( make
, "sfnt2fon" ), ttf_file
, args
);
2746 add_install_rule( make
, source
->name
, xstrdup(font
), strmake( "d$(fontdir)/%s", font
));
2752 /*******************************************************************
2755 static void output_source_svg( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2757 static const char * const images
[] = { "bmp", "cur", "ico", NULL
};
2760 if (convert
&& rsvg
&& icotool
&& !make
->src_dir
)
2762 for (i
= 0; images
[i
]; i
++)
2763 if (find_include_file( make
, strmake( "%s.%s", obj
, images
[i
] ))) break;
2767 output( "%s.%s: %s\n", src_dir_path( make
, obj
), images
[i
], source
->filename
);
2768 output( "\tCONVERT=\"%s\" ICOTOOL=\"%s\" RSVG=\"%s\" %s %s $@\n", convert
, icotool
, rsvg
,
2769 top_src_dir_path( make
, "tools/buildimage" ), source
->filename
);
2775 /*******************************************************************
2778 static void output_source_nls( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2780 add_install_rule( make
, source
->name
, source
->name
,
2781 strmake( "D$(datadir)/wine/%s", source
->name
));
2785 /*******************************************************************
2786 * output_source_desktop
2788 static void output_source_desktop( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2790 add_install_rule( make
, source
->name
, source
->name
,
2791 strmake( "D$(datadir)/applications/%s", source
->name
));
2795 /*******************************************************************
2798 static void output_source_po( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2800 output( "%s.mo: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2801 output( "\t%s -o $@ %s\n", msgfmt
, source
->filename
);
2802 strarray_add( &make
->all_targets
, strmake( "%s.mo", obj
));
2806 /*******************************************************************
2809 static void output_source_in( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2813 if (strendswith( obj
, ".man" ) && source
->file
->args
)
2815 struct strarray symlinks
;
2816 char *dir
, *dest
= replace_extension( obj
, ".man", "" );
2817 char *lang
= strchr( dest
, '.' );
2818 char *section
= source
->file
->args
;
2822 dir
= strmake( "$(mandir)/%s/man%s", lang
, section
);
2824 else dir
= strmake( "$(mandir)/man%s", section
);
2825 add_install_rule( make
, dest
, xstrdup(obj
), strmake( "d%s/%s.%s", dir
, dest
, section
));
2826 symlinks
= get_expanded_file_local_var( make
, dest
, "SYMLINKS" );
2827 for (i
= 0; i
< symlinks
.count
; i
++)
2828 add_install_rule( make
, symlinks
.str
[i
], strmake( "%s.%s", dest
, section
),
2829 strmake( "y%s/%s.%s", dir
, symlinks
.str
[i
], section
));
2833 strarray_add( &make
->in_files
, xstrdup(obj
) );
2834 strarray_add( &make
->all_targets
, xstrdup(obj
) );
2835 output( "%s: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2836 output( "\t%s %s >$@ || (rm -f $@ && false)\n", sed_cmd
, source
->filename
);
2837 output( "%s:", obj_dir_path( make
, obj
));
2838 output_filenames( source
->dependencies
);
2840 add_install_rule( make
, obj
, xstrdup( obj
), strmake( "d$(datadir)/wine/%s", obj
));
2844 /*******************************************************************
2845 * output_source_spec
2847 static void output_source_spec( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2849 struct strarray imports
= get_expanded_file_local_var( make
, obj
, "IMPORTS" );
2850 struct strarray dll_flags
= get_expanded_file_local_var( make
, obj
, "EXTRADLLFLAGS" );
2851 struct strarray all_libs
, dep_libs
= empty_strarray
;
2853 if (!imports
.count
) imports
= make
->imports
;
2854 if (!dll_flags
.count
) dll_flags
= make
->extradllflags
;
2855 all_libs
= add_import_libs( make
, &dep_libs
, imports
, 0 );
2856 add_import_libs( make
, &dep_libs
, get_default_imports( make
), 0 ); /* dependencies only */
2857 strarray_addall( &all_libs
, libs
);
2859 strarray_add( &make
->clean_files
, strmake( "%s.dll%s", obj
, dll_ext
));
2860 strarray_add( &make
->object_files
, strmake( "%s.res", obj
));
2861 output( "%s.res: %s.dll%s\n", obj_dir_path( make
, obj
), obj_dir_path( make
, obj
), dll_ext
);
2862 output( "\techo \"%s.dll TESTDLL \\\"%s.dll%s\\\"\" | %s -o $@\n", obj
,
2863 obj_dir_path( make
, obj
), dll_ext
, tools_path( make
, "wrc" ));
2865 output( "%s.dll%s:", obj_dir_path( make
, obj
), dll_ext
);
2866 output_filename( source
->filename
);
2867 output_filename( strmake( "%s.o", obj_dir_path( make
, obj
)));
2868 output_filenames( dep_libs
);
2869 output_filename( tools_path( make
, "winebuild" ));
2870 output_filename( tools_path( make
, "winegcc" ));
2872 output( "\t%s -s -o $@", tools_path( make
, "winegcc" ));
2873 output_filename( strmake( "-B%s", tools_dir_path( make
, "winebuild" )));
2874 if (tools_dir
) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make
, "" )));
2875 output_filenames( target_flags
);
2876 output_filenames( unwind_flags
);
2877 output_filenames( dll_flags
);
2878 output_filename( "-shared" );
2879 output_filename( source
->filename
);
2880 output_filename( strmake( "%s.o", obj_dir_path( make
, obj
)));
2881 output_filenames( all_libs
);
2882 output_filename( "$(LDFLAGS)" );
2887 dep_libs
= empty_strarray
;
2888 all_libs
= add_import_libs( make
, &dep_libs
, imports
, 1 );
2889 add_import_libs( make
, &dep_libs
, get_default_imports( make
), 1 ); /* dependencies only */
2890 strarray_addall( &all_libs
, libs
);
2892 strarray_add( &make
->clean_files
, strmake( "%s.dll", obj
));
2893 strarray_add( &make
->crossobj_files
, strmake( "%s.cross.res", obj
));
2894 output( "%s.cross.res: %s.dll\n", obj_dir_path( make
, obj
), obj_dir_path( make
, obj
) );
2895 output( "\techo \"%s.dll TESTDLL \\\"%s.dll\\\"\" | %s -o $@\n", obj
,
2896 obj_dir_path( make
, obj
), tools_path( make
, "wrc" ));
2898 output( "%s.dll:", obj_dir_path( make
, obj
));
2899 output_filename( source
->filename
);
2900 output_filename( strmake( "%s.cross.o", obj_dir_path( make
, obj
)));
2901 output_filenames( dep_libs
);
2902 output_filename( tools_path( make
, "winebuild" ));
2903 output_filename( tools_path( make
, "winegcc" ));
2905 output( "\t%s -s -o $@ -b %s", tools_path( make
, "winegcc" ), crosstarget
);
2906 output_filename( strmake( "-B%s", tools_dir_path( make
, "winebuild" )));
2907 if (tools_dir
) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make
, "" )));
2908 output_filename( "--lib-suffix=.cross.a" );
2909 output_filenames( dll_flags
);
2910 output_filename( "-shared" );
2911 output_filename( source
->filename
);
2912 output_filename( strmake( "%s.cross.o", obj_dir_path( make
, obj
)));
2913 output_filenames( all_libs
);
2914 output_filename( "$(LDFLAGS)" );
2920 /*******************************************************************
2921 * output_source_default
2923 static void output_source_default( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2925 struct strarray extradefs
= get_expanded_file_local_var( make
, obj
, "EXTRADEFS" );
2926 int is_dll_src
= (make
->testdll
&&
2927 strendswith( source
->name
, ".c" ) &&
2928 find_src_file( make
, replace_extension( source
->name
, ".c", ".spec" )));
2929 int need_cross
= (make
->testdll
||
2930 (source
->file
->flags
& FLAG_C_IMPLIB
) ||
2931 (make
->module
&& make
->staticlib
));
2933 if ((source
->file
->flags
& FLAG_GENERATED
) &&
2934 (!make
->testdll
|| !strendswith( source
->filename
, "testlist.c" )))
2935 strarray_add( &make
->clean_files
, source
->filename
);
2936 if (source
->file
->flags
& FLAG_C_IMPLIB
) strarray_add( &make
->implib_objs
, strmake( "%s.o", obj
));
2937 strarray_add( is_dll_src
? &make
->clean_files
: &make
->object_files
, strmake( "%s.o", obj
));
2938 output( "%s.o: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2939 output( "\t$(CC) -c -o $@ %s", source
->filename
);
2940 output_filenames( make
->include_args
);
2941 output_filenames( make
->define_args
);
2942 output_filenames( extradefs
);
2943 if (make
->module
|| make
->staticlib
|| make
->sharedlib
|| make
->testdll
)
2945 output_filenames( dll_flags
);
2946 if (make
->use_msvcrt
) output_filenames( msvcrt_flags
);
2948 output_filenames( extra_cflags
);
2949 output_filenames( cpp_flags
);
2950 output_filename( "$(CFLAGS)" );
2952 if (crosstarget
&& need_cross
)
2954 strarray_add( is_dll_src
? &make
->clean_files
: &make
->crossobj_files
, strmake( "%s.cross.o", obj
));
2955 output( "%s.cross.o: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2956 output( "\t$(CROSSCC) -c -o $@ %s", source
->filename
);
2957 output_filenames( make
->include_args
);
2958 output_filenames( make
->define_args
);
2959 output_filenames( extradefs
);
2960 if (make
->use_msvcrt
) output_filenames( msvcrt_flags
);
2961 output_filename( "-DWINE_CROSSTEST" );
2962 output_filenames( cpp_flags
);
2963 output_filename( "$(CROSSCFLAGS)" );
2966 if (strendswith( source
->name
, ".c" ) && !(source
->file
->flags
& FLAG_GENERATED
))
2968 strarray_add( &make
->c2man_files
, source
->filename
);
2969 if (make
->testdll
&& !is_dll_src
)
2971 strarray_add( &make
->ok_files
, strmake( "%s.ok", obj
));
2972 output( "%s.ok:\n", obj_dir_path( make
, obj
));
2973 output( "\t%s $(RUNTESTFLAGS) -T %s -M %s -p %s%s %s && touch $@\n",
2974 top_src_dir_path( make
, "tools/runtest" ), top_obj_dir_path( make
, "" ),
2975 make
->testdll
, replace_extension( make
->testdll
, ".dll", "_test.exe" ),
2979 output( "%s.o", obj_dir_path( make
, obj
));
2980 if (crosstarget
&& need_cross
) output( " %s.cross.o", obj_dir_path( make
, obj
));
2982 output_filenames( source
->dependencies
);
2987 /* dispatch table to output rules for a single source file */
2991 void (*fn
)( struct makefile
*make
, struct incl_file
*source
, const char *obj
);
2992 } output_source_funcs
[] =
2994 { "y", output_source_y
},
2995 { "l", output_source_l
},
2996 { "h", output_source_h
},
2997 { "rh", output_source_h
},
2998 { "inl", output_source_h
},
2999 { "rc", output_source_rc
},
3000 { "mc", output_source_mc
},
3001 { "res", output_source_res
},
3002 { "idl", output_source_idl
},
3003 { "tlb", output_source_tlb
},
3004 { "sfd", output_source_sfd
},
3005 { "svg", output_source_svg
},
3006 { "nls", output_source_nls
},
3007 { "desktop", output_source_desktop
},
3008 { "po", output_source_po
},
3009 { "in", output_source_in
},
3010 { "x", output_source_x
},
3011 { "spec", output_source_spec
},
3012 { NULL
, output_source_default
}
3016 /*******************************************************************
3019 static void output_man_pages( struct makefile
*make
)
3021 if (make
->c2man_files
.count
)
3023 char *spec_file
= src_dir_path( make
, replace_extension( make
->module
, ".dll", ".spec" ));
3025 output( "manpages::\n" );
3026 output( "\t%s -w %s", top_src_dir_path( make
, "tools/c2man.pl" ), spec_file
);
3027 output_filename( strmake( "-R%s", top_src_dir_path( make
, "" )));
3028 output_filename( strmake( "-I%s", top_src_dir_path( make
, "include" )));
3029 output_filename( strmake( "-o %s/man%s",
3030 top_obj_dir_path( make
, "documentation" ), man_ext
));
3031 output_filenames( make
->c2man_files
);
3033 output( "htmlpages::\n" );
3034 output( "\t%s -Th -w %s", top_src_dir_path( make
, "tools/c2man.pl" ), spec_file
);
3035 output_filename( strmake( "-R%s", top_src_dir_path( make
, "" )));
3036 output_filename( strmake( "-I%s", top_src_dir_path( make
, "include" )));
3037 output_filename( strmake( "-o %s",
3038 top_obj_dir_path( make
, "documentation/html" )));
3039 output_filenames( make
->c2man_files
);
3041 output( "sgmlpages::\n" );
3042 output( "\t%s -Ts -w %s", top_src_dir_path( make
, "tools/c2man.pl" ), spec_file
);
3043 output_filename( strmake( "-R%s", top_src_dir_path( make
, "" )));
3044 output_filename( strmake( "-I%s", top_src_dir_path( make
, "include" )));
3045 output_filename( strmake( "-o %s",
3046 top_obj_dir_path( make
, "documentation/api-guide" )));
3047 output_filenames( make
->c2man_files
);
3049 output( "xmlpages::\n" );
3050 output( "\t%s -Tx -w %s", top_src_dir_path( make
, "tools/c2man.pl" ), spec_file
);
3051 output_filename( strmake( "-R%s", top_src_dir_path( make
, "" )));
3052 output_filename( strmake( "-I%s", top_src_dir_path( make
, "include" )));
3053 output_filename( strmake( "-o %s",
3054 top_obj_dir_path( make
, "documentation/api-guide-xml" )));
3055 output_filenames( make
->c2man_files
);
3057 strarray_add( &make
->phony_targets
, "manpages" );
3058 strarray_add( &make
->phony_targets
, "htmlpages" );
3059 strarray_add( &make
->phony_targets
, "sgmlpages" );
3060 strarray_add( &make
->phony_targets
, "xmlpages" );
3062 else output( "manpages htmlpages sgmlpages xmlpages::\n" );
3066 /*******************************************************************
3069 static void output_module( struct makefile
*make
)
3071 struct strarray all_libs
= empty_strarray
;
3072 struct strarray dep_libs
= empty_strarray
;
3073 char *module_path
= obj_dir_path( make
, make
->module
);
3074 char *spec_file
= NULL
;
3077 if (!make
->appmode
.count
)
3078 spec_file
= src_dir_path( make
, replace_extension( make
->module
, ".dll", ".spec" ));
3079 strarray_addall( &all_libs
, add_import_libs( make
, &dep_libs
, make
->delayimports
, 0 ));
3080 strarray_addall( &all_libs
, add_import_libs( make
, &dep_libs
, make
->imports
, 0 ));
3081 add_import_libs( make
, &dep_libs
, get_default_imports( make
), 0 ); /* dependencies only */
3082 strarray_addall( &all_libs
, add_default_libraries( make
, &dep_libs
));
3086 for (i
= 0; i
< make
->delayimports
.count
; i
++)
3087 strarray_add( &all_libs
, strmake( "-Wb,-d%s", make
->delayimports
.str
[i
] ));
3088 strarray_add( &make
->all_targets
, strmake( "%s%s", make
->module
, dll_ext
));
3089 strarray_add( &make
->all_targets
, strmake( "%s.fake", make
->module
));
3090 add_install_rule( make
, make
->module
, strmake( "%s%s", make
->module
, dll_ext
),
3091 strmake( "p$(dlldir)/%s%s", make
->module
, dll_ext
));
3092 add_install_rule( make
, make
->module
, strmake( "%s.fake", make
->module
),
3093 strmake( "d$(dlldir)/fakedlls/%s", make
->module
));
3094 output( "%s%s %s.fake:", module_path
, dll_ext
, module_path
);
3098 strarray_add( &all_libs
, "-lwine" );
3099 strarray_add( &make
->all_targets
, make
->module
);
3100 add_install_rule( make
, make
->module
, make
->module
,
3101 strmake( "p$(%s)/%s", spec_file
? "dlldir" : "bindir", make
->module
));
3102 output( "%s:", module_path
);
3104 if (spec_file
) output_filename( spec_file
);
3105 output_filenames_obj_dir( make
, make
->object_files
);
3106 output_filenames( dep_libs
);
3107 output_filename( tools_path( make
, "winebuild" ));
3108 output_filename( tools_path( make
, "winegcc" ));
3110 output( "\t%s -o $@", tools_path( make
, "winegcc" ));
3111 output_filename( strmake( "-B%s", tools_dir_path( make
, "winebuild" )));
3112 if (tools_dir
) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make
, "" )));
3113 output_filenames( target_flags
);
3114 output_filenames( unwind_flags
);
3117 output( " -shared %s", spec_file
);
3118 output_filenames( make
->extradllflags
);
3120 else output_filenames( make
->appmode
);
3121 output_filenames_obj_dir( make
, make
->object_files
);
3122 output_filenames( all_libs
);
3123 output_filename( "$(LDFLAGS)" );
3126 if (spec_file
&& make
->importlib
)
3128 char *importlib_path
= obj_dir_path( make
, strmake( "lib%s", make
->importlib
));
3129 if (*dll_ext
&& !make
->implib_objs
.count
)
3131 strarray_add( &make
->clean_files
, strmake( "lib%s.def", make
->importlib
));
3132 output( "%s.def: %s %s\n", importlib_path
, tools_path( make
, "winebuild" ), spec_file
);
3133 output( "\t%s -w --def -o $@ --export %s", tools_path( make
, "winebuild" ), spec_file
);
3134 output_filenames( target_flags
);
3135 if (make
->is_win16
) output_filename( "-m16" );
3137 add_install_rule( make
, make
->importlib
,
3138 strmake( "lib%s.def", make
->importlib
),
3139 strmake( "d$(dlldir)/lib%s.def", make
->importlib
));
3143 strarray_add( &make
->clean_files
, strmake( "lib%s.a", make
->importlib
));
3144 output( "%s.a: %s %s", importlib_path
, tools_path( make
, "winebuild" ), spec_file
);
3145 output_filenames_obj_dir( make
, make
->implib_objs
);
3147 output( "\t%s -w --implib -o $@ --export %s", tools_path( make
, "winebuild" ), spec_file
);
3148 output_filenames( target_flags
);
3149 output_filenames_obj_dir( make
, make
->implib_objs
);
3151 add_install_rule( make
, make
->importlib
,
3152 strmake( "lib%s.a", make
->importlib
),
3153 strmake( "d$(dlldir)/lib%s.a", make
->importlib
));
3155 if (crosstarget
&& !make
->is_win16
)
3157 struct strarray cross_files
= strarray_replace_extension( &make
->implib_objs
, ".o", ".cross.o" );
3158 strarray_add( &make
->clean_files
, strmake( "lib%s.cross.a", make
->importlib
));
3159 output( "%s.cross.a: %s %s", importlib_path
, tools_path( make
, "winebuild" ), spec_file
);
3160 output_filenames_obj_dir( make
, cross_files
);
3162 output( "\t%s -b %s -w --implib -o $@ --export %s",
3163 tools_path( make
, "winebuild" ), crosstarget
, spec_file
);
3164 output_filenames_obj_dir( make
, cross_files
);
3170 output_man_pages( make
);
3171 else if (*dll_ext
&& !make
->is_win16
)
3173 char *binary
= replace_extension( make
->module
, ".exe", "" );
3174 add_install_rule( make
, binary
, "wineapploader", strmake( "t$(bindir)/%s", binary
));
3179 /*******************************************************************
3182 static void output_static_lib( struct makefile
*make
)
3184 strarray_add( &make
->all_targets
, make
->staticlib
);
3185 output( "%s:", obj_dir_path( make
, make
->staticlib
));
3186 output_filenames_obj_dir( make
, make
->object_files
);
3187 output( "\n\trm -f $@\n" );
3188 output( "\t%s rc $@", ar
);
3189 output_filenames_obj_dir( make
, make
->object_files
);
3190 output( "\n\t%s $@\n", ranlib
);
3191 add_install_rule( make
, make
->staticlib
, make
->staticlib
,
3192 strmake( "d$(dlldir)/%s", make
->staticlib
));
3193 if (crosstarget
&& make
->module
)
3195 char *name
= replace_extension( make
->staticlib
, ".a", ".cross.a" );
3197 strarray_add( &make
->all_targets
, name
);
3198 output( "%s:", obj_dir_path( make
, name
));
3199 output_filenames_obj_dir( make
, make
->crossobj_files
);
3200 output( "\n\trm -f $@\n" );
3201 output( "\t%s-ar rc $@", crosstarget
);
3202 output_filenames_obj_dir( make
, make
->crossobj_files
);
3203 output( "\n\t%s-ranlib $@\n", crosstarget
);
3208 /*******************************************************************
3211 static void output_shared_lib( struct makefile
*make
)
3215 struct strarray names
= get_shared_lib_names( make
->sharedlib
);
3216 struct strarray all_libs
= empty_strarray
;
3217 struct strarray dep_libs
= empty_strarray
;
3219 basename
= xstrdup( make
->sharedlib
);
3220 if ((p
= strchr( basename
, '.' ))) *p
= 0;
3222 strarray_addall( &dep_libs
, get_local_dependencies( make
, basename
, make
->in_files
));
3223 strarray_addall( &all_libs
, get_expanded_file_local_var( make
, basename
, "LDFLAGS" ));
3224 strarray_addall( &all_libs
, add_default_libraries( make
, &dep_libs
));
3226 output( "%s:", obj_dir_path( make
, make
->sharedlib
));
3227 output_filenames_obj_dir( make
, make
->object_files
);
3228 output_filenames( dep_libs
);
3230 output( "\t$(CC) -o $@" );
3231 output_filenames_obj_dir( make
, make
->object_files
);
3232 output_filenames( all_libs
);
3233 output_filename( "$(LDFLAGS)" );
3235 add_install_rule( make
, make
->sharedlib
, make
->sharedlib
,
3236 strmake( "p$(libdir)/%s", make
->sharedlib
));
3237 for (i
= 1; i
< names
.count
; i
++)
3239 output( "%s: %s\n", obj_dir_path( make
, names
.str
[i
] ), obj_dir_path( make
, names
.str
[i
-1] ));
3240 output_symlink_rule( obj_dir_path( make
, names
.str
[i
-1] ), obj_dir_path( make
, names
.str
[i
] ));
3241 add_install_rule( make
, names
.str
[i
], names
.str
[i
-1],
3242 strmake( "y$(libdir)/%s", names
.str
[i
] ));
3244 strarray_addall( &make
->all_targets
, names
);
3248 /*******************************************************************
3251 static void output_import_lib( struct makefile
*make
)
3253 char *def_file
= replace_extension( make
->importlib
, ".a", ".def" );
3255 /* stand-alone import lib (for libwine) */
3256 if (!strncmp( def_file
, "lib", 3 )) def_file
+= 3;
3257 output( "%s: %s\n", obj_dir_path( make
, make
->importlib
), src_dir_path( make
, def_file
));
3258 output( "\t%s -l $@ -d %s\n", dlltool
, src_dir_path( make
, def_file
));
3259 add_install_rule( make
, make
->importlib
, make
->importlib
, strmake( "d$(libdir)/%s", make
->importlib
));
3260 strarray_add( &make
->all_targets
, make
->importlib
);
3264 /*******************************************************************
3265 * output_test_module
3267 static void output_test_module( struct makefile
*make
)
3269 char *testmodule
= replace_extension( make
->testdll
, ".dll", "_test.exe" );
3270 char *stripped
= replace_extension( make
->testdll
, ".dll", "_test-stripped.exe" );
3271 char *testres
= replace_extension( make
->testdll
, ".dll", "_test.res" );
3272 struct strarray dep_libs
= empty_strarray
;
3273 struct strarray all_libs
= add_import_libs( make
, &dep_libs
, make
->imports
, 0 );
3274 int parent_disabled
= 0;
3276 add_import_libs( make
, &dep_libs
, get_default_imports( make
), 0 ); /* dependencies only */
3277 strarray_addall( &all_libs
, libs
);
3278 strarray_add( &make
->all_targets
, strmake( "%s%s", testmodule
, dll_ext
));
3279 strarray_add( &make
->clean_files
, strmake( "%s%s", stripped
, dll_ext
));
3280 output( "%s%s:\n", obj_dir_path( make
, testmodule
), dll_ext
);
3281 output( "\t%s -o $@", tools_path( make
, "winegcc" ));
3282 output_filename( strmake( "-B%s", tools_dir_path( make
, "winebuild" )));
3283 if (tools_dir
) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make
, "" )));
3284 output_filenames( target_flags
);
3285 output_filenames( unwind_flags
);
3286 output_filenames( make
->appmode
);
3287 output_filenames_obj_dir( make
, make
->object_files
);
3288 output_filenames( all_libs
);
3289 output_filename( "$(LDFLAGS)" );
3291 output( "%s%s:\n", obj_dir_path( make
, stripped
), dll_ext
);
3292 output( "\t%s -s -o $@", tools_path( make
, "winegcc" ));
3293 output_filename( strmake( "-B%s", tools_dir_path( make
, "winebuild" )));
3294 if (tools_dir
) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make
, "" )));
3295 output_filenames( target_flags
);
3296 output_filenames( unwind_flags
);
3297 output_filename( strmake( "-Wb,-F,%s", testmodule
));
3298 output_filenames( make
->appmode
);
3299 output_filenames_obj_dir( make
, make
->object_files
);
3300 output_filenames( all_libs
);
3301 output_filename( "$(LDFLAGS)" );
3303 output( "%s%s %s%s:", obj_dir_path( make
, testmodule
), dll_ext
,
3304 obj_dir_path( make
, stripped
), dll_ext
);
3305 output_filenames_obj_dir( make
, make
->object_files
);
3306 output_filenames( dep_libs
);
3307 output_filename( tools_path( make
, "winebuild" ));
3308 output_filename( tools_path( make
, "winegcc" ));
3311 if (!make
->disabled
&& !strarray_exists( &disabled_dirs
, "programs/winetest" ))
3312 output( "all: %s/%s\n", top_obj_dir_path( make
, "programs/winetest" ), testres
);
3313 output( "%s/%s: %s%s\n", top_obj_dir_path( make
, "programs/winetest" ), testres
,
3314 obj_dir_path( make
, stripped
), dll_ext
);
3315 output( "\techo \"%s TESTRES \\\"%s%s\\\"\" | %s -o $@\n",
3316 testmodule
, obj_dir_path( make
, stripped
), dll_ext
, tools_path( make
, "wrc" ));
3320 char *crosstest
= replace_extension( make
->testdll
, ".dll", "_crosstest.exe" );
3322 dep_libs
= empty_strarray
;
3323 all_libs
= add_import_libs( make
, &dep_libs
, make
->imports
, 1 );
3324 add_import_libs( make
, &dep_libs
, get_default_imports( make
), 1 ); /* dependencies only */
3325 strarray_addall( &all_libs
, libs
);
3326 strarray_add( &make
->clean_files
, crosstest
);
3327 output( "%s:", obj_dir_path( make
, crosstest
));
3328 output_filenames_obj_dir( make
, make
->crossobj_files
);
3329 output_filenames( dep_libs
);
3330 output_filename( tools_path( make
, "winebuild" ));
3331 output_filename( tools_path( make
, "winegcc" ));
3333 output( "\t%s -o $@ -b %s", tools_path( make
, "winegcc" ), crosstarget
);
3334 output_filename( strmake( "-B%s", tools_dir_path( make
, "winebuild" )));
3335 if (tools_dir
) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make
, "" )));
3336 output_filename( "--lib-suffix=.cross.a" );
3337 output_filenames_obj_dir( make
, make
->crossobj_files
);
3338 output_filenames( all_libs
);
3339 output_filename( "$(LDFLAGS)" );
3341 if (!make
->disabled
)
3343 output( "%s: %s\n", obj_dir_path( make
, "crosstest" ), obj_dir_path( make
, crosstest
));
3344 strarray_add( &make
->phony_targets
, obj_dir_path( make
, "crosstest" ));
3345 if (make
->obj_dir
) output( "crosstest: %s\n", obj_dir_path( make
, "crosstest" ));
3349 if (strendswith( make
->base_dir
, "/tests" ))
3351 char *dir
= xstrdup( make
->base_dir
);
3352 dir
[strlen( dir
) - 6] = 0;
3353 parent_disabled
= strarray_exists( &disabled_dirs
, dir
);
3355 output_filenames_obj_dir( make
, make
->ok_files
);
3356 output( ": %s%s ../%s%s\n", testmodule
, dll_ext
, make
->testdll
, dll_ext
);
3357 output( "check test:" );
3358 if (!make
->disabled
&& !parent_disabled
) output_filenames_obj_dir( make
, make
->ok_files
);
3360 strarray_add( &make
->phony_targets
, "check" );
3361 strarray_add( &make
->phony_targets
, "test" );
3362 output( "testclean::\n" );
3363 output( "\trm -f" );
3364 output_filenames_obj_dir( make
, make
->ok_files
);
3366 strarray_addall( &make
->clean_files
, make
->ok_files
);
3367 strarray_add( &make
->phony_targets
, "testclean" );
3371 /*******************************************************************
3374 static void output_programs( struct makefile
*make
)
3377 char *ldrpath_local
= get_expanded_make_variable( make
, "LDRPATH_LOCAL" );
3378 char *ldrpath_install
= get_expanded_make_variable( make
, "LDRPATH_INSTALL" );
3380 for (i
= 0; i
< make
->programs
.count
; i
++)
3382 char *program_installed
= NULL
;
3383 char *program
= strmake( "%s%s", make
->programs
.str
[i
], exe_ext
);
3384 struct strarray deps
= get_local_dependencies( make
, make
->programs
.str
[i
], make
->in_files
);
3385 struct strarray all_libs
= get_expanded_file_local_var( make
, make
->programs
.str
[i
], "LDFLAGS" );
3386 struct strarray objs
= get_expanded_file_local_var( make
, make
->programs
.str
[i
], "OBJS" );
3387 struct strarray symlinks
= get_expanded_file_local_var( make
, make
->programs
.str
[i
], "SYMLINKS" );
3389 if (!objs
.count
) objs
= make
->object_files
;
3390 strarray_addall( &all_libs
, add_default_libraries( make
, &deps
));
3392 output( "%s:", obj_dir_path( make
, program
) );
3393 output_filenames_obj_dir( make
, objs
);
3394 output_filenames( deps
);
3396 output( "\t$(CC) -o $@" );
3397 output_filenames_obj_dir( make
, objs
);
3399 if (strarray_exists( &all_libs
, "-lwine" ))
3401 strarray_add( &all_libs
, strmake( "-L%s", top_obj_dir_path( make
, "libs/wine" )));
3402 if (ldrpath_local
&& ldrpath_install
)
3404 program_installed
= strmake( "%s-installed%s", make
->programs
.str
[i
], exe_ext
);
3405 output_filename( ldrpath_local
);
3406 output_filenames( all_libs
);
3407 output_filename( "$(LDFLAGS)" );
3409 output( "%s:", obj_dir_path( make
, program_installed
) );
3410 output_filenames_obj_dir( make
, objs
);
3411 output_filenames( deps
);
3413 output( "\t$(CC) -o $@" );
3414 output_filenames_obj_dir( make
, objs
);
3415 output_filename( ldrpath_install
);
3416 strarray_add( &make
->all_targets
, program_installed
);
3420 output_filenames( all_libs
);
3421 output_filename( "$(LDFLAGS)" );
3423 strarray_add( &make
->all_targets
, program
);
3425 for (j
= 0; j
< symlinks
.count
; j
++)
3427 output( "%s: %s\n", obj_dir_path( make
, symlinks
.str
[j
] ), obj_dir_path( make
, program
));
3428 output_symlink_rule( obj_dir_path( make
, program
), obj_dir_path( make
, symlinks
.str
[j
] ));
3430 strarray_addall( &make
->all_targets
, symlinks
);
3432 add_install_rule( make
, program
, program_installed
? program_installed
: program
,
3433 strmake( "p$(bindir)/%s", program
));
3434 for (j
= 0; j
< symlinks
.count
; j
++)
3435 add_install_rule( make
, symlinks
.str
[j
], program
,
3436 strmake( "y$(bindir)/%s%s", symlinks
.str
[j
], exe_ext
));
3441 /*******************************************************************
3444 static void output_subdirs( struct makefile
*make
)
3446 struct strarray symlinks
= empty_strarray
;
3447 struct strarray all_deps
= empty_strarray
;
3448 struct strarray build_deps
= empty_strarray
;
3449 struct strarray builddeps_deps
= empty_strarray
;
3450 struct strarray makefile_deps
= empty_strarray
;
3451 struct strarray clean_files
= empty_strarray
;
3452 struct strarray testclean_files
= empty_strarray
;
3453 struct strarray distclean_files
= empty_strarray
;
3454 struct strarray tools_deps
= empty_strarray
;
3455 struct strarray tooldeps_deps
= empty_strarray
;
3456 struct strarray winetest_deps
= empty_strarray
;
3457 struct strarray crosstest_deps
= empty_strarray
;
3460 strarray_addall( &distclean_files
, make
->distclean_files
);
3461 for (i
= 0; i
< make
->subdirs
.count
; i
++)
3463 const struct makefile
*submake
= make
->submakes
[i
];
3464 char *subdir
= base_dir_path( submake
, "" );
3466 strarray_add( &makefile_deps
, top_src_dir_path( make
, base_dir_path( submake
,
3467 strmake ( "%s.in", output_makefile_name
))));
3468 for (j
= 0; j
< submake
->clean_files
.count
; j
++)
3469 strarray_add( &clean_files
, base_dir_path( submake
, submake
->clean_files
.str
[j
] ));
3470 for (j
= 0; j
< submake
->distclean_files
.count
; j
++)
3471 strarray_add( &distclean_files
, base_dir_path( submake
, submake
->distclean_files
.str
[j
] ));
3472 for (j
= 0; j
< submake
->ok_files
.count
; j
++)
3473 strarray_add( &testclean_files
, base_dir_path( submake
, submake
->ok_files
.str
[j
] ));
3475 /* import libs are still created for disabled dirs, except for win16 ones */
3476 if (submake
->module
&& submake
->importlib
&& !(submake
->disabled
&& submake
->is_win16
))
3478 char *importlib_path
= base_dir_path( submake
, strmake( "lib%s", submake
->importlib
));
3479 if (submake
->implib_objs
.count
)
3481 output( "%s.a: dummy\n", importlib_path
);
3482 output( "\t@cd %s && $(MAKE) lib%s.a\n", subdir
, submake
->importlib
);
3483 strarray_add( &tools_deps
, strmake( "%s.a", importlib_path
));
3486 output( "%s.cross.a: dummy\n", importlib_path
);
3487 output( "\t@cd %s && $(MAKE) lib%s.cross.a\n", subdir
, submake
->importlib
);
3488 strarray_add( &tools_deps
, strmake( "%s.cross.a", importlib_path
));
3493 const char *libext
= *dll_ext
? ".def" : ".a";
3494 char *spec_file
= top_src_dir_path( make
, base_dir_path( submake
,
3495 replace_extension( submake
->module
, ".dll", ".spec" )));
3496 output( "%s%s: %s", importlib_path
, libext
, spec_file
);
3497 output_filename( tools_path( make
, "winebuild" ));
3499 output( "\t%s -w -o $@", tools_path( make
, "winebuild" ));
3500 output_filename( *dll_ext
? "--def" : "--implib" );
3501 output_filenames( target_flags
);
3502 if (submake
->is_win16
) output_filename( "-m16" );
3503 output_filename( "--export" );
3504 output_filename( spec_file
);
3506 strarray_add( &build_deps
, strmake( "%s%s", importlib_path
, libext
));
3507 if (crosstarget
&& !submake
->is_win16
)
3509 output( "%s.cross.a: %s", importlib_path
, spec_file
);
3510 output_filename( tools_path( make
, "winebuild" ));
3512 output( "\t%s -b %s -w -o $@", tools_path( make
, "winebuild" ), crosstarget
);
3513 output_filename( "--implib" );
3514 output_filename( "--export" );
3515 output_filename( spec_file
);
3517 strarray_add( &build_deps
, strmake( "%s.cross.a", importlib_path
));
3520 strarray_addall( &symlinks
, output_importlib_symlinks( make
, submake
));
3523 if (submake
->disabled
) continue;
3524 strarray_add( &all_deps
, subdir
);
3526 if (submake
->module
)
3528 if (!submake
->staticlib
)
3530 strarray_add( &builddeps_deps
, subdir
);
3531 if (!submake
->appmode
.count
)
3533 output( "manpages htmlpages sgmlpages xmlpages::\n" );
3534 output( "\t@cd %s && $(MAKE) $@\n", subdir
);
3537 else strarray_add( &tools_deps
, subdir
);
3539 else if (submake
->testdll
)
3541 output( "%s/test: dummy\n", subdir
);
3542 output( "\t@cd %s && $(MAKE) test\n", subdir
);
3543 strarray_add( &winetest_deps
, subdir
);
3544 strarray_add( &builddeps_deps
, subdir
);
3547 char *target
= base_dir_path( submake
, "crosstest" );
3548 output( "crosstest: %s\n", target
);
3549 output( "%s: dummy\n", target
);
3550 output( "\t@cd %s && $(MAKE) crosstest\n", subdir
);
3551 strarray_add( &crosstest_deps
, target
);
3552 strarray_add( &builddeps_deps
, target
);
3557 if (!strcmp( submake
->base_dir
, "tools" ) || !strncmp( submake
->base_dir
, "tools/", 6 ))
3559 strarray_add( &tooldeps_deps
, submake
->base_dir
);
3560 for (j
= 0; j
< submake
->programs
.count
; j
++)
3561 output( "%s/%s%s: %s\n", submake
->base_dir
,
3562 submake
->programs
.str
[j
], tools_ext
, submake
->base_dir
);
3564 if (submake
->programs
.count
|| submake
->sharedlib
)
3566 struct strarray libs
= get_expanded_make_var_array( submake
, "EXTRALIBS" );
3567 for (j
= 0; j
< submake
->programs
.count
; j
++)
3568 strarray_addall( &libs
, get_expanded_file_local_var( submake
,
3569 submake
->programs
.str
[j
], "LDFLAGS" ));
3570 output( "%s: libs/port", submake
->base_dir
);
3571 for (j
= 0; j
< libs
.count
; j
++)
3573 if (!strcmp( libs
.str
[j
], "-lwpp" )) output_filename( "libs/wpp" );
3574 if (!strcmp( libs
.str
[j
], "-lwine" )) output_filename( "libs/wine" );
3580 if (submake
->install_rules
[INSTALL_LIB
].count
)
3582 output( "install install-lib:: %s\n", submake
->base_dir
);
3583 output_install_commands( make
, submake
, submake
->install_rules
[INSTALL_LIB
] );
3585 if (submake
->install_rules
[INSTALL_DEV
].count
)
3587 output( "install install-dev:: %s\n", submake
->base_dir
);
3588 output_install_commands( make
, submake
, submake
->install_rules
[INSTALL_DEV
] );
3592 output_filenames( all_deps
);
3594 output_filenames( all_deps
);
3595 output( ": dummy\n" );
3596 output( "\t@cd $@ && $(MAKE)\n" );
3597 output( "Makefile:" );
3598 output_filenames( makefile_deps
);
3600 output_filenames( makefile_deps
);
3602 if (tooldeps_deps
.count
)
3604 output( "__tooldeps__:" );
3605 output_filenames( tooldeps_deps
);
3607 strarray_add( &make
->phony_targets
, "__tooldeps__" );
3609 if (winetest_deps
.count
)
3611 output( "buildtests programs/winetest:" );
3612 output_filenames( winetest_deps
);
3614 output( "check test:" );
3615 for (i
= 0; i
< winetest_deps
.count
; i
++)
3617 char *target
= strmake( "%s/test", winetest_deps
.str
[i
] );
3618 output_filename( target
);
3619 strarray_add( &make
->phony_targets
, target
);
3622 strarray_add( &make
->phony_targets
, "buildtests" );
3623 strarray_add( &make
->phony_targets
, "check" );
3624 strarray_add( &make
->phony_targets
, "test" );
3626 output( "crosstest:" );
3627 output_filenames( crosstest_deps
);
3629 if (!crosstest_deps
.count
)
3630 output( "\t@echo \"crosstest is not supported (mingw not installed?)\" && false\n" );
3631 strarray_add( &make
->phony_targets
, "crosstest" );
3633 output( "clean::\n");
3634 output_rm_filenames( clean_files
);
3635 output( "testclean::\n");
3636 output_rm_filenames( testclean_files
);
3637 output( "distclean::\n");
3638 output_rm_filenames( distclean_files
);
3639 output_filenames( tools_deps
);
3641 output_filename( tools_dir_path( make
, "widl" ));
3642 output_filename( tools_dir_path( make
, "winebuild" ));
3643 output_filename( tools_dir_path( make
, "winegcc" ));
3644 output_filename( obj_dir_path( make
, "include" ));
3646 output_filenames( builddeps_deps
);
3647 output( ": __builddeps__\n" );
3648 strarray_add( &make
->phony_targets
, "distclean" );
3649 strarray_add( &make
->phony_targets
, "testclean" );
3650 strarray_addall( &make
->phony_targets
, all_deps
);
3651 strarray_addall( &make
->phony_targets
, crosstest_deps
);
3653 strarray_addall( &make
->clean_files
, symlinks
);
3654 strarray_addall( &build_deps
, tools_deps
);
3655 strarray_addall( &build_deps
, symlinks
);
3656 if (build_deps
.count
)
3658 output( "__builddeps__:" );
3659 output_filenames( build_deps
);
3661 strarray_add( &make
->phony_targets
, "__builddeps__" );
3663 if (get_expanded_make_variable( make
, "GETTEXTPO_LIBS" )) output_po_files( make
);
3667 /*******************************************************************
3670 static void output_sources( struct makefile
*make
)
3672 struct incl_file
*source
;
3675 strarray_add( &make
->phony_targets
, "all" );
3677 LIST_FOR_EACH_ENTRY( source
, &make
->sources
, struct incl_file
, entry
)
3679 char *obj
= xstrdup( source
->name
);
3680 char *ext
= get_extension( obj
);
3682 if (!ext
) fatal_error( "unsupported file type %s\n", source
->name
);
3685 for (j
= 0; output_source_funcs
[j
].ext
; j
++)
3686 if (!strcmp( ext
, output_source_funcs
[j
].ext
)) break;
3688 output_source_funcs
[j
].fn( make
, source
, obj
);
3689 strarray_addall_uniq( &make
->dependencies
, source
->dependencies
);
3692 /* special case for winetest: add resource files from other test dirs */
3693 if (make
->base_dir
&& !strcmp( make
->base_dir
, "programs/winetest" ))
3695 struct strarray tests
= enable_tests
;
3697 for (i
= 0; i
< top_makefile
->subdirs
.count
; i
++)
3698 if (top_makefile
->submakes
[i
]->testdll
&& !top_makefile
->submakes
[i
]->disabled
)
3699 strarray_add( &tests
, top_makefile
->submakes
[i
]->testdll
);
3700 for (i
= 0; i
< tests
.count
; i
++)
3701 strarray_add( &make
->object_files
, replace_extension( tests
.str
[i
], ".dll", "_test.res" ));
3704 if (make
->dlldata_files
.count
)
3706 output( "%s: %s %s\n", obj_dir_path( make
, "dlldata.c" ),
3707 tools_path( make
, "widl" ), src_dir_path( make
, "Makefile.in" ));
3708 output( "\t%s --dlldata-only -o $@", tools_path( make
, "widl" ));
3709 output_filenames( make
->dlldata_files
);
3713 if (make
->staticlib
) output_static_lib( make
);
3714 else if (make
->module
) output_module( make
);
3715 else if (make
->testdll
) output_test_module( make
);
3718 if (make
->importlib
) output_import_lib( make
);
3719 if (make
->sharedlib
) output_shared_lib( make
);
3720 if (make
->programs
.count
) output_programs( make
);
3723 for (i
= 0; i
< make
->scripts
.count
; i
++)
3724 add_install_rule( make
, make
->scripts
.str
[i
], make
->scripts
.str
[i
],
3725 strmake( "S$(bindir)/%s", make
->scripts
.str
[i
] ));
3727 if (!make
->src_dir
) strarray_add( &make
->distclean_files
, ".gitignore" );
3728 strarray_add( &make
->distclean_files
, "Makefile" );
3729 if (make
->testdll
) strarray_add( &make
->distclean_files
, "testlist.c" );
3731 if (!make
->base_dir
)
3732 strarray_addall( &make
->distclean_files
, get_expanded_make_var_array( make
, "CONFIGURE_TARGETS" ));
3733 else if (!strcmp( make
->base_dir
, "po" ))
3734 strarray_add( &make
->distclean_files
, "LINGUAS" );
3736 if (make
->subdirs
.count
) output_subdirs( make
);
3738 if (!make
->disabled
)
3740 if (make
->all_targets
.count
)
3743 output_filenames_obj_dir( make
, make
->all_targets
);
3746 output_install_rules( make
, INSTALL_LIB
, "install-lib" );
3747 output_install_rules( make
, INSTALL_DEV
, "install-dev" );
3748 output_uninstall_rules( make
);
3751 if (make
->dependencies
.count
)
3753 output_filenames( make
->dependencies
);
3757 strarray_addall( &make
->clean_files
, make
->object_files
);
3758 strarray_addall_uniq( &make
->clean_files
, make
->crossobj_files
);
3759 strarray_addall( &make
->clean_files
, make
->all_targets
);
3760 strarray_addall( &make
->clean_files
, make
->extra_targets
);
3762 if (make
->clean_files
.count
)
3764 output( "%s::\n", obj_dir_path( make
, "clean" ));
3765 output( "\trm -f" );
3766 output_filenames_obj_dir( make
, make
->clean_files
);
3768 if (make
->obj_dir
) output( "__clean__: %s\n", obj_dir_path( make
, "clean" ));
3769 strarray_add( &make
->phony_targets
, obj_dir_path( make
, "clean" ));
3772 if (make
->phony_targets
.count
)
3774 output( ".PHONY:" );
3775 output_filenames( make
->phony_targets
);
3781 /*******************************************************************
3784 static FILE *create_temp_file( const char *orig
)
3786 char *name
= xmalloc( strlen(orig
) + 13 );
3787 unsigned int i
, id
= getpid();
3791 for (i
= 0; i
< 100; i
++)
3793 sprintf( name
, "%s.tmp%08x", orig
, id
);
3794 if ((fd
= open( name
, O_RDWR
| O_CREAT
| O_EXCL
, 0666 )) != -1)
3796 ret
= fdopen( fd
, "w" );
3799 if (errno
!= EEXIST
) break;
3802 if (!ret
) fatal_error( "failed to create output file for '%s'\n", orig
);
3803 temp_file_name
= name
;
3808 /*******************************************************************
3811 static void rename_temp_file( const char *dest
)
3813 int ret
= rename( temp_file_name
, dest
);
3814 if (ret
== -1 && errno
== EEXIST
)
3816 /* rename doesn't overwrite on windows */
3818 ret
= rename( temp_file_name
, dest
);
3820 if (ret
== -1) fatal_error( "failed to rename output file to '%s'\n", dest
);
3821 temp_file_name
= NULL
;
3825 /*******************************************************************
3826 * are_files_identical
3828 static int are_files_identical( FILE *file1
, FILE *file2
)
3832 char buffer1
[8192], buffer2
[8192];
3833 int size1
= fread( buffer1
, 1, sizeof(buffer1
), file1
);
3834 int size2
= fread( buffer2
, 1, sizeof(buffer2
), file2
);
3835 if (size1
!= size2
) return 0;
3836 if (!size1
) return feof( file1
) && feof( file2
);
3837 if (memcmp( buffer1
, buffer2
, size1
)) return 0;
3842 /*******************************************************************
3843 * rename_temp_file_if_changed
3845 static void rename_temp_file_if_changed( const char *dest
)
3847 FILE *file1
, *file2
;
3850 if ((file1
= fopen( dest
, "r" )))
3852 if ((file2
= fopen( temp_file_name
, "r" )))
3854 do_rename
= !are_files_identical( file1
, file2
);
3861 unlink( temp_file_name
);
3862 temp_file_name
= NULL
;
3864 else rename_temp_file( dest
);
3868 /*******************************************************************
3871 static void output_linguas( const struct makefile
*make
)
3873 const char *dest
= base_dir_path( make
, "LINGUAS" );
3874 struct incl_file
*source
;
3876 output_file
= create_temp_file( dest
);
3878 output( "# Automatically generated by make depend; DO NOT EDIT!!\n" );
3879 LIST_FOR_EACH_ENTRY( source
, &make
->sources
, struct incl_file
, entry
)
3880 if (strendswith( source
->name
, ".po" ))
3881 output( "%s\n", replace_extension( source
->name
, ".po", "" ));
3883 if (fclose( output_file
)) fatal_perror( "write" );
3885 rename_temp_file_if_changed( dest
);
3889 /*******************************************************************
3892 static void output_testlist( const struct makefile
*make
)
3894 const char *dest
= base_dir_path( make
, "testlist.c" );
3895 struct strarray files
= empty_strarray
;
3898 for (i
= 0; i
< make
->ok_files
.count
; i
++)
3899 strarray_add( &files
, replace_extension( make
->ok_files
.str
[i
], ".ok", "" ));
3901 output_file
= create_temp_file( dest
);
3903 output( "/* Automatically generated by make depend; DO NOT EDIT!! */\n\n" );
3904 output( "#define WIN32_LEAN_AND_MEAN\n" );
3905 output( "#include <windows.h>\n\n" );
3906 output( "#define STANDALONE\n" );
3907 output( "#include \"wine/test.h\"\n\n" );
3909 for (i
= 0; i
< files
.count
; i
++) output( "extern void func_%s(void);\n", files
.str
[i
] );
3911 output( "const struct test winetest_testlist[] =\n" );
3913 for (i
= 0; i
< files
.count
; i
++) output( " { \"%s\", func_%s },\n", files
.str
[i
], files
.str
[i
] );
3914 output( " { 0, 0 }\n" );
3917 if (fclose( output_file
)) fatal_perror( "write" );
3919 rename_temp_file_if_changed( dest
);
3923 /*******************************************************************
3926 static void output_gitignore( const char *dest
, struct strarray files
)
3930 output_file
= create_temp_file( dest
);
3932 output( "# Automatically generated by make depend; DO NOT EDIT!!\n" );
3933 for (i
= 0; i
< files
.count
; i
++)
3935 if (!strchr( files
.str
[i
], '/' )) output( "/" );
3936 output( "%s\n", files
.str
[i
] );
3939 if (fclose( output_file
)) fatal_perror( "write" );
3941 rename_temp_file( dest
);
3945 /*******************************************************************
3946 * output_top_variables
3948 static void output_top_variables( const struct makefile
*make
)
3951 struct strarray
*vars
= &top_makefile
->vars
;
3953 if (!make
->base_dir
) return; /* don't output variables in the top makefile */
3955 output( "# Automatically generated by make depend; DO NOT EDIT!!\n\n" );
3956 output( "all:\n\n" );
3957 for (i
= 0; i
< vars
->count
; i
+= 2)
3959 if (!strcmp( vars
->str
[i
], "SUBDIRS" )) continue; /* not inherited */
3960 output( "%s = %s\n", vars
->str
[i
], get_make_variable( make
, vars
->str
[i
] ));
3966 /*******************************************************************
3967 * output_dependencies
3969 static void output_dependencies( struct makefile
*make
)
3971 struct strarray ignore_files
= empty_strarray
;
3976 if (make
->base_dir
) create_dir( make
->base_dir
);
3978 output_file_name
= base_dir_path( make
, output_makefile_name
);
3979 output_file
= create_temp_file( output_file_name
);
3980 output_top_variables( make
);
3982 /* copy the contents of the source makefile */
3983 src_file
= open_input_makefile( make
);
3984 while (fgets( buffer
, sizeof(buffer
), src_file
) && !found
)
3986 if (fwrite( buffer
, 1, strlen(buffer
), output_file
) != strlen(buffer
)) fatal_perror( "write" );
3987 found
= !strncmp( buffer
, separator
, strlen(separator
) );
3989 if (fclose( src_file
)) fatal_perror( "close" );
3990 input_file_name
= NULL
;
3992 if (!found
) output( "\n%s (everything below this line is auto-generated; DO NOT EDIT!!)\n", separator
);
3993 output_sources( make
);
3995 fclose( output_file
);
3997 rename_temp_file( output_file_name
);
3999 strarray_addall( &ignore_files
, make
->distclean_files
);
4000 strarray_addall( &ignore_files
, make
->clean_files
);
4001 if (make
->testdll
) output_testlist( make
);
4002 if (make
->base_dir
&& !strcmp( make
->base_dir
, "po" )) output_linguas( make
);
4003 if (!make
->src_dir
) output_gitignore( base_dir_path( make
, ".gitignore" ), ignore_files
);
4005 create_file_directories( make
, ignore_files
);
4007 output_file_name
= NULL
;
4011 /*******************************************************************
4014 static void load_sources( struct makefile
*make
)
4016 static const char *source_vars
[] =
4037 struct strarray value
;
4038 struct incl_file
*file
;
4042 make
->top_src_dir
= concat_paths( make
->top_obj_dir
, root_src_dir
);
4043 make
->src_dir
= concat_paths( make
->top_src_dir
, make
->base_dir
);
4045 strarray_set_value( &make
->vars
, "top_builddir", top_obj_dir_path( make
, "" ));
4046 strarray_set_value( &make
->vars
, "top_srcdir", top_src_dir_path( make
, "" ));
4047 strarray_set_value( &make
->vars
, "srcdir", src_dir_path( make
, "" ));
4049 make
->parent_dir
= get_expanded_make_variable( make
, "PARENTSRC" );
4050 make
->module
= get_expanded_make_variable( make
, "MODULE" );
4051 make
->testdll
= get_expanded_make_variable( make
, "TESTDLL" );
4052 make
->sharedlib
= get_expanded_make_variable( make
, "SHAREDLIB" );
4053 make
->staticlib
= get_expanded_make_variable( make
, "STATICLIB" );
4054 make
->importlib
= get_expanded_make_variable( make
, "IMPORTLIB" );
4056 make
->programs
= get_expanded_make_var_array( make
, "PROGRAMS" );
4057 make
->scripts
= get_expanded_make_var_array( make
, "SCRIPTS" );
4058 make
->appmode
= get_expanded_make_var_array( make
, "APPMODE" );
4059 make
->imports
= get_expanded_make_var_array( make
, "IMPORTS" );
4060 make
->delayimports
= get_expanded_make_var_array( make
, "DELAYIMPORTS" );
4061 make
->extradllflags
= get_expanded_make_var_array( make
, "EXTRADLLFLAGS" );
4062 make
->install_lib
= get_expanded_make_var_array( make
, "INSTALL_LIB" );
4063 make
->install_dev
= get_expanded_make_var_array( make
, "INSTALL_DEV" );
4064 make
->extra_targets
= get_expanded_make_var_array( make
, "EXTRA_TARGETS" );
4066 if (make
->module
&& strendswith( make
->module
, ".a" )) make
->staticlib
= make
->module
;
4068 make
->disabled
= make
->base_dir
&& strarray_exists( &disabled_dirs
, make
->base_dir
);
4069 make
->is_win16
= strarray_exists( &make
->extradllflags
, "-m16" ) || strarray_exists( &make
->appmode
, "-m16" );
4070 make
->use_msvcrt
= strarray_exists( &make
->appmode
, "-mno-cygwin" );
4072 for (i
= 0; i
< make
->imports
.count
&& !make
->use_msvcrt
; i
++)
4073 make
->use_msvcrt
= !strncmp( make
->imports
.str
[i
], "msvcr", 5 ) ||
4074 !strcmp( make
->imports
.str
[i
], "ucrtbase" );
4076 if (make
->module
&& !make
->install_lib
.count
&& !make
->install_dev
.count
)
4078 if (make
->importlib
) strarray_add( &make
->install_dev
, make
->importlib
);
4079 if (make
->staticlib
) strarray_add( &make
->install_dev
, make
->staticlib
);
4080 else strarray_add( &make
->install_lib
, make
->module
);
4083 make
->include_paths
= empty_strarray
;
4084 make
->include_args
= empty_strarray
;
4085 make
->define_args
= empty_strarray
;
4086 strarray_add( &make
->define_args
, "-D__WINESRC__" );
4088 value
= get_expanded_make_var_array( make
, "EXTRAINCL" );
4089 for (i
= 0; i
< value
.count
; i
++)
4090 if (!strncmp( value
.str
[i
], "-I", 2 ))
4091 strarray_add_uniq( &make
->include_paths
, value
.str
[i
] + 2 );
4093 strarray_add_uniq( &make
->define_args
, value
.str
[i
] );
4094 strarray_addall( &make
->define_args
, get_expanded_make_var_array( make
, "EXTRADEFS" ));
4096 strarray_add( &make
->include_args
, strmake( "-I%s", obj_dir_path( make
, "" )));
4098 strarray_add( &make
->include_args
, strmake( "-I%s", make
->src_dir
));
4099 if (make
->parent_dir
)
4100 strarray_add( &make
->include_args
, strmake( "-I%s", src_dir_path( make
, make
->parent_dir
)));
4101 strarray_add( &make
->include_args
, strmake( "-I%s", top_obj_dir_path( make
, "include" )));
4102 if (make
->top_src_dir
)
4103 strarray_add( &make
->include_args
, strmake( "-I%s", top_src_dir_path( make
, "include" )));
4104 if (make
->use_msvcrt
)
4105 strarray_add( &make
->include_args
, strmake( "-I%s", top_src_dir_path( make
, "include/msvcrt" )));
4106 for (i
= 0; i
< make
->include_paths
.count
; i
++)
4107 strarray_add( &make
->include_args
, strmake( "-I%s", obj_dir_path( make
, make
->include_paths
.str
[i
] )));
4109 list_init( &make
->sources
);
4110 list_init( &make
->includes
);
4112 for (var
= source_vars
; *var
; var
++)
4114 value
= get_expanded_make_var_array( make
, *var
);
4115 for (i
= 0; i
< value
.count
; i
++) add_src_file( make
, value
.str
[i
] );
4118 add_generated_sources( make
);
4120 LIST_FOR_EACH_ENTRY( file
, &make
->includes
, struct incl_file
, entry
) parse_file( make
, file
, 0 );
4121 LIST_FOR_EACH_ENTRY( file
, &make
->sources
, struct incl_file
, entry
) get_dependencies( file
, file
);
4125 /*******************************************************************
4128 static void parse_makeflags( const char *flags
)
4130 const char *p
= flags
;
4131 char *var
, *buffer
= xmalloc( strlen(flags
) + 1 );
4135 while (isspace(*p
)) p
++;
4137 while (*p
&& !isspace(*p
))
4139 if (*p
== '\\' && p
[1]) p
++;
4143 if (var
> buffer
) set_make_variable( &cmdline_vars
, buffer
);
4148 /*******************************************************************
4151 static int parse_option( const char *opt
)
4155 if (strchr( opt
, '=' )) return set_make_variable( &cmdline_vars
, opt
);
4161 if (opt
[2]) output_makefile_name
= opt
+ 2;
4164 relative_dir_mode
= 1;
4167 fprintf( stderr
, "Unknown option '%s'\n%s", opt
, Usage
);
4174 /*******************************************************************
4177 int main( int argc
, char *argv
[] )
4179 const char *makeflags
= getenv( "MAKEFLAGS" );
4182 if (makeflags
) parse_makeflags( makeflags
);
4187 if (parse_option( argv
[i
] ))
4189 for (j
= i
; j
< argc
; j
++) argv
[j
] = argv
[j
+1];
4195 if (relative_dir_mode
)
4201 fprintf( stderr
, "Option -R needs two directories\n%s", Usage
);
4204 relpath
= get_relative_path( argv
[1], argv
[2] );
4205 printf( "%s\n", relpath
? relpath
: "." );
4209 atexit( cleanup_files
);
4210 signal( SIGTERM
, exit_on_signal
);
4211 signal( SIGINT
, exit_on_signal
);
4213 signal( SIGHUP
, exit_on_signal
);
4216 for (i
= 0; i
< HASH_SIZE
; i
++) list_init( &files
[i
] );
4218 top_makefile
= parse_makefile( NULL
);
4220 target_flags
= get_expanded_make_var_array( top_makefile
, "TARGETFLAGS" );
4221 msvcrt_flags
= get_expanded_make_var_array( top_makefile
, "MSVCRTFLAGS" );
4222 dll_flags
= get_expanded_make_var_array( top_makefile
, "DLLFLAGS" );
4223 extra_cflags
= get_expanded_make_var_array( top_makefile
, "EXTRACFLAGS" );
4224 cpp_flags
= get_expanded_make_var_array( top_makefile
, "CPPFLAGS" );
4225 unwind_flags
= get_expanded_make_var_array( top_makefile
, "UNWINDFLAGS" );
4226 libs
= get_expanded_make_var_array( top_makefile
, "LIBS" );
4227 enable_tests
= get_expanded_make_var_array( top_makefile
, "ENABLE_TESTS" );
4228 top_install_lib
= get_expanded_make_var_array( top_makefile
, "TOP_INSTALL_LIB" );
4229 top_install_dev
= get_expanded_make_var_array( top_makefile
, "TOP_INSTALL_DEV" );
4231 root_src_dir
= get_expanded_make_variable( top_makefile
, "srcdir" );
4232 tools_dir
= get_expanded_make_variable( top_makefile
, "TOOLSDIR" );
4233 tools_ext
= get_expanded_make_variable( top_makefile
, "TOOLSEXT" );
4234 exe_ext
= get_expanded_make_variable( top_makefile
, "EXEEXT" );
4235 man_ext
= get_expanded_make_variable( top_makefile
, "api_manext" );
4236 dll_ext
= (exe_ext
&& !strcmp( exe_ext
, ".exe" )) ? "" : ".so";
4237 crosstarget
= get_expanded_make_variable( top_makefile
, "CROSSTARGET" );
4238 fontforge
= get_expanded_make_variable( top_makefile
, "FONTFORGE" );
4239 convert
= get_expanded_make_variable( top_makefile
, "CONVERT" );
4240 flex
= get_expanded_make_variable( top_makefile
, "FLEX" );
4241 bison
= get_expanded_make_variable( top_makefile
, "BISON" );
4242 ar
= get_expanded_make_variable( top_makefile
, "AR" );
4243 ranlib
= get_expanded_make_variable( top_makefile
, "RANLIB" );
4244 rsvg
= get_expanded_make_variable( top_makefile
, "RSVG" );
4245 icotool
= get_expanded_make_variable( top_makefile
, "ICOTOOL" );
4246 dlltool
= get_expanded_make_variable( top_makefile
, "DLLTOOL" );
4247 msgfmt
= get_expanded_make_variable( top_makefile
, "MSGFMT" );
4248 sed_cmd
= get_expanded_make_variable( top_makefile
, "SED_CMD" );
4249 ln_s
= get_expanded_make_variable( top_makefile
, "LN_S" );
4251 if (root_src_dir
&& !strcmp( root_src_dir
, "." )) root_src_dir
= NULL
;
4252 if (tools_dir
&& !strcmp( tools_dir
, "." )) tools_dir
= NULL
;
4253 if (!exe_ext
) exe_ext
= "";
4254 if (!tools_ext
) tools_ext
= "";
4255 if (!man_ext
) man_ext
= "3w";
4259 disabled_dirs
= get_expanded_make_var_array( top_makefile
, "DISABLED_SUBDIRS" );
4260 top_makefile
->subdirs
= get_expanded_make_var_array( top_makefile
, "SUBDIRS" );
4261 top_makefile
->submakes
= xmalloc( top_makefile
->subdirs
.count
* sizeof(*top_makefile
->submakes
) );
4263 for (i
= 0; i
< top_makefile
->subdirs
.count
; i
++)
4264 top_makefile
->submakes
[i
] = parse_makefile( top_makefile
->subdirs
.str
[i
] );
4266 load_sources( top_makefile
);
4267 for (i
= 0; i
< top_makefile
->subdirs
.count
; i
++)
4268 load_sources( top_makefile
->submakes
[i
] );
4270 for (i
= 0; i
< top_makefile
->subdirs
.count
; i
++)
4271 output_dependencies( top_makefile
->submakes
[i
] );
4273 output_dependencies( top_makefile
);
4277 for (i
= 1; i
< argc
; i
++)
4279 struct makefile
*make
= parse_makefile( argv
[i
] );
4280 load_sources( make
);
4281 output_dependencies( make
);