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 extra_cross_cflags
;
136 static struct strarray cpp_flags
;
137 static struct strarray unwind_flags
;
138 static struct strarray libs
;
139 static struct strarray enable_tests
;
140 static struct strarray cmdline_vars
;
141 static struct strarray disabled_dirs
;
142 static struct strarray top_install_lib
;
143 static struct strarray top_install_dev
;
144 static const char *root_src_dir
;
145 static const char *tools_dir
;
146 static const char *tools_ext
;
147 static const char *exe_ext
;
148 static const char *dll_ext
;
149 static const char *man_ext
;
150 static const char *crosstarget
;
151 static const char *fontforge
;
152 static const char *convert
;
153 static const char *flex
;
154 static const char *bison
;
155 static const char *ar
;
156 static const char *ranlib
;
157 static const char *rsvg
;
158 static const char *icotool
;
159 static const char *dlltool
;
160 static const char *msgfmt
;
161 static const char *ln_s
;
162 static const char *sed_cmd
;
166 /* values determined from input makefile */
167 struct strarray vars
;
168 struct strarray include_paths
;
169 struct strarray include_args
;
170 struct strarray define_args
;
171 struct strarray programs
;
172 struct strarray scripts
;
173 struct strarray appmode
;
174 struct strarray imports
;
175 struct strarray subdirs
;
176 struct strarray delayimports
;
177 struct strarray extradllflags
;
178 struct strarray install_lib
;
179 struct strarray install_dev
;
180 struct strarray extra_targets
;
182 struct list includes
;
183 const char *base_dir
;
186 const char *top_src_dir
;
187 const char *top_obj_dir
;
188 const char *parent_dir
;
191 const char *sharedlib
;
192 const char *staticlib
;
193 const char *staticimplib
;
194 const char *importlib
;
198 struct makefile
**submakes
;
200 /* values generated at output time */
201 struct strarray in_files
;
202 struct strarray ok_files
;
203 struct strarray clean_files
;
204 struct strarray distclean_files
;
205 struct strarray uninstall_files
;
206 struct strarray object_files
;
207 struct strarray crossobj_files
;
208 struct strarray c2man_files
;
209 struct strarray dlldata_files
;
210 struct strarray implib_objs
;
211 struct strarray all_targets
;
212 struct strarray phony_targets
;
213 struct strarray dependencies
;
214 struct strarray install_rules
[NB_INSTALL_RULES
];
217 static struct makefile
*top_makefile
;
219 static const char separator
[] = "### Dependencies";
220 static const char *output_makefile_name
= "Makefile";
221 static const char *input_file_name
;
222 static const char *output_file_name
;
223 static const char *temp_file_name
;
224 static int relative_dir_mode
;
225 static int input_line
;
226 static int output_column
;
227 static FILE *output_file
;
229 static const char Usage
[] =
230 "Usage: makedep [options] [directories]\n"
232 " -R from to Compute the relative path between two directories\n"
233 " -fxxx Store output in file 'xxx' (default: Makefile)\n";
237 #define __attribute__(x)
240 static void fatal_error( const char *msg
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
241 static void fatal_perror( const char *msg
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
242 static void output( const char *format
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
243 static char *strmake( const char* fmt
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
245 /*******************************************************************
248 static void fatal_error( const char *msg
, ... )
251 va_start( valist
, msg
);
254 fprintf( stderr
, "%s:", input_file_name
);
255 if (input_line
) fprintf( stderr
, "%d:", input_line
);
256 fprintf( stderr
, " error: " );
258 else fprintf( stderr
, "makedep: error: " );
259 vfprintf( stderr
, msg
, valist
);
265 /*******************************************************************
268 static void fatal_perror( const char *msg
, ... )
271 va_start( valist
, msg
);
274 fprintf( stderr
, "%s:", input_file_name
);
275 if (input_line
) fprintf( stderr
, "%d:", input_line
);
276 fprintf( stderr
, " error: " );
278 else fprintf( stderr
, "makedep: error: " );
279 vfprintf( stderr
, msg
, valist
);
286 /*******************************************************************
289 static void cleanup_files(void)
291 if (temp_file_name
) unlink( temp_file_name
);
292 if (output_file_name
) unlink( output_file_name
);
296 /*******************************************************************
299 static void exit_on_signal( int sig
)
301 exit( 1 ); /* this will call the atexit functions */
305 /*******************************************************************
308 static void *xmalloc( size_t size
)
311 if (!(res
= malloc (size
? size
: 1)))
312 fatal_error( "Virtual memory exhausted.\n" );
317 /*******************************************************************
320 static void *xrealloc (void *ptr
, size_t size
)
324 if (!(res
= realloc( ptr
, size
)))
325 fatal_error( "Virtual memory exhausted.\n" );
329 /*******************************************************************
332 static char *xstrdup( const char *str
)
334 char *res
= strdup( str
);
335 if (!res
) fatal_error( "Virtual memory exhausted.\n" );
340 /*******************************************************************
343 static char *strmake( const char* fmt
, ... )
351 char *p
= xmalloc (size
);
353 n
= vsnprintf (p
, size
, fmt
, ap
);
355 if (n
== -1) size
*= 2;
356 else if ((size_t)n
>= size
) size
= n
+ 1;
357 else return xrealloc( p
, n
+ 1 );
363 /*******************************************************************
366 static int strendswith( const char* str
, const char* end
)
368 size_t l
= strlen( str
);
369 size_t m
= strlen( end
);
371 return l
>= m
&& strcmp(str
+ l
- m
, end
) == 0;
375 /*******************************************************************
378 static void output( const char *format
, ... )
383 va_start( valist
, format
);
384 ret
= vfprintf( output_file
, format
, valist
);
386 if (ret
< 0) fatal_perror( "output" );
387 if (format
[0] && format
[strlen(format
) - 1] == '\n') output_column
= 0;
388 else output_column
+= ret
;
392 /*******************************************************************
395 static void strarray_add( struct strarray
*array
, const char *str
)
397 if (array
->count
== array
->size
)
399 if (array
->size
) array
->size
*= 2;
400 else array
->size
= 16;
401 array
->str
= xrealloc( array
->str
, sizeof(array
->str
[0]) * array
->size
);
403 array
->str
[array
->count
++] = str
;
407 /*******************************************************************
410 static void strarray_addall( struct strarray
*array
, struct strarray added
)
414 for (i
= 0; i
< added
.count
; i
++) strarray_add( array
, added
.str
[i
] );
418 /*******************************************************************
421 static int strarray_exists( const struct strarray
*array
, const char *str
)
425 for (i
= 0; i
< array
->count
; i
++) if (!strcmp( array
->str
[i
], str
)) return 1;
430 /*******************************************************************
433 static void strarray_add_uniq( struct strarray
*array
, const char *str
)
435 if (!strarray_exists( array
, str
)) strarray_add( array
, str
);
439 /*******************************************************************
440 * strarray_addall_uniq
442 static void strarray_addall_uniq( struct strarray
*array
, struct strarray added
)
446 for (i
= 0; i
< added
.count
; i
++) strarray_add_uniq( array
, added
.str
[i
] );
450 /*******************************************************************
453 * Find a value in a name/value pair string array.
455 static const char *strarray_get_value( const struct strarray
*array
, const char *name
)
457 int pos
, res
, min
= 0, max
= array
->count
/ 2 - 1;
461 pos
= (min
+ max
) / 2;
462 if (!(res
= strcmp( array
->str
[pos
* 2], name
))) return array
->str
[pos
* 2 + 1];
463 if (res
< 0) min
= pos
+ 1;
470 /*******************************************************************
473 * Define a value in a name/value pair string array.
475 static void strarray_set_value( struct strarray
*array
, const char *name
, const char *value
)
477 int i
, pos
, res
, min
= 0, max
= array
->count
/ 2 - 1;
481 pos
= (min
+ max
) / 2;
482 if (!(res
= strcmp( array
->str
[pos
* 2], name
)))
484 /* redefining a variable replaces the previous value */
485 array
->str
[pos
* 2 + 1] = value
;
488 if (res
< 0) min
= pos
+ 1;
491 strarray_add( array
, NULL
);
492 strarray_add( array
, NULL
);
493 for (i
= array
->count
- 1; i
> min
* 2 + 1; i
--) array
->str
[i
] = array
->str
[i
- 2];
494 array
->str
[min
* 2] = name
;
495 array
->str
[min
* 2 + 1] = value
;
499 /*******************************************************************
502 static void strarray_qsort( struct strarray
*array
, int (*func
)(const char **, const char **) )
504 if (array
->count
) qsort( array
->str
, array
->count
, sizeof(*array
->str
), (void *)func
);
508 /*******************************************************************
511 static void output_filename( const char *name
)
513 if (output_column
+ strlen(name
) + 1 > 100)
518 else if (output_column
) output( " " );
519 output( "%s", name
);
523 /*******************************************************************
526 static void output_filenames( struct strarray array
)
530 for (i
= 0; i
< array
.count
; i
++) output_filename( array
.str
[i
] );
534 /*******************************************************************
535 * output_rm_filenames
537 static void output_rm_filenames( struct strarray array
)
539 static const unsigned int max_cmdline
= 30000; /* to be on the safe side */
542 if (!array
.count
) return;
544 for (i
= len
= 0; i
< array
.count
; i
++)
546 if (len
> max_cmdline
)
552 output_filename( array
.str
[i
] );
553 len
+= strlen( array
.str
[i
] ) + 1;
559 /*******************************************************************
562 static char *get_extension( char *filename
)
564 char *ext
= strrchr( filename
, '.' );
565 if (ext
&& strchr( ext
, '/' )) ext
= NULL
;
570 /*******************************************************************
573 static char *replace_extension( const char *name
, const char *old_ext
, const char *new_ext
)
576 size_t name_len
= strlen( name
);
577 size_t ext_len
= strlen( old_ext
);
579 if (name_len
>= ext_len
&& !strcmp( name
+ name_len
- ext_len
, old_ext
)) name_len
-= ext_len
;
580 ret
= xmalloc( name_len
+ strlen( new_ext
) + 1 );
581 memcpy( ret
, name
, name_len
);
582 strcpy( ret
+ name_len
, new_ext
);
587 /*******************************************************************
590 static char *replace_filename( const char *path
, const char *name
)
596 if (!path
) return xstrdup( name
);
597 if (!(p
= strrchr( path
, '/' ))) return xstrdup( name
);
599 ret
= xmalloc( len
+ strlen( name
) + 1 );
600 memcpy( ret
, path
, len
);
601 strcpy( ret
+ len
, name
);
606 /*******************************************************************
607 * strarray_replace_extension
609 static struct strarray
strarray_replace_extension( const struct strarray
*array
,
610 const char *old_ext
, const char *new_ext
)
615 ret
.count
= ret
.size
= array
->count
;
616 ret
.str
= xmalloc( sizeof(ret
.str
[0]) * ret
.size
);
617 for (i
= 0; i
< array
->count
; i
++) ret
.str
[i
] = replace_extension( array
->str
[i
], old_ext
, new_ext
);
622 /*******************************************************************
625 static char *replace_substr( const char *str
, const char *start
, size_t len
, const char *replace
)
627 size_t pos
= start
- str
;
628 char *ret
= xmalloc( pos
+ strlen(replace
) + strlen(start
+ len
) + 1 );
629 memcpy( ret
, str
, pos
);
630 strcpy( ret
+ pos
, replace
);
631 strcat( ret
+ pos
, start
+ len
);
636 /*******************************************************************
639 * Determine where the destination path is located relative to the 'from' path.
641 static char *get_relative_path( const char *from
, const char *dest
)
645 unsigned int dotdots
= 0;
647 /* a path of "." is equivalent to an empty path */
648 if (!strcmp( from
, "." )) from
= "";
652 while (*from
== '/') from
++;
653 while (*dest
== '/') dest
++;
654 start
= dest
; /* save start of next path element */
657 while (*from
&& *from
!= '/' && *from
== *dest
) { from
++; dest
++; }
658 if ((!*from
|| *from
== '/') && (!*dest
|| *dest
== '/')) continue;
660 /* count remaining elements in 'from' */
664 while (*from
&& *from
!= '/') from
++;
665 while (*from
== '/') from
++;
671 if (!start
[0] && !dotdots
) return NULL
; /* empty path */
673 ret
= xmalloc( 3 * dotdots
+ strlen( start
) + 1 );
674 for (p
= ret
; dotdots
; dotdots
--, p
+= 3) memcpy( p
, "../", 3 );
676 if (start
[0]) strcpy( p
, start
);
677 else p
[-1] = 0; /* remove trailing slash */
682 /*******************************************************************
685 static char *concat_paths( const char *base
, const char *path
)
687 if (!base
|| !base
[0]) return xstrdup( path
&& path
[0] ? path
: "." );
688 if (!path
|| !path
[0]) return xstrdup( base
);
689 if (path
[0] == '/') return xstrdup( path
);
690 return strmake( "%s/%s", base
, path
);
694 /*******************************************************************
697 static char *base_dir_path( const struct makefile
*make
, const char *path
)
699 return concat_paths( make
->base_dir
, path
);
703 /*******************************************************************
706 static char *obj_dir_path( const struct makefile
*make
, const char *path
)
708 return concat_paths( make
->obj_dir
, path
);
712 /*******************************************************************
715 static char *src_dir_path( const struct makefile
*make
, const char *path
)
717 if (make
->src_dir
) return concat_paths( make
->src_dir
, path
);
718 return obj_dir_path( make
, path
);
722 /*******************************************************************
725 static char *top_obj_dir_path( const struct makefile
*make
, const char *path
)
727 return concat_paths( make
->top_obj_dir
, path
);
731 /*******************************************************************
734 static char *top_src_dir_path( const struct makefile
*make
, const char *path
)
736 if (make
->top_src_dir
) return concat_paths( make
->top_src_dir
, path
);
737 return top_obj_dir_path( make
, path
);
741 /*******************************************************************
744 static char *root_dir_path( const char *path
)
746 return concat_paths( root_src_dir
, path
);
750 /*******************************************************************
753 static char *tools_dir_path( const struct makefile
*make
, const char *path
)
755 if (tools_dir
) return top_obj_dir_path( make
, strmake( "%s/tools/%s", tools_dir
, path
));
756 return top_obj_dir_path( make
, strmake( "tools/%s", path
));
760 /*******************************************************************
763 static char *tools_path( const struct makefile
*make
, const char *name
)
765 return strmake( "%s/%s%s", tools_dir_path( make
, name
), name
, tools_ext
);
769 /*******************************************************************
772 static char *get_line( FILE *file
)
780 buffer
= xmalloc( size
);
782 if (!fgets( buffer
, size
, file
)) return NULL
;
787 char *p
= buffer
+ strlen(buffer
);
788 /* if line is larger than buffer, resize buffer */
789 while (p
== buffer
+ size
- 1 && p
[-1] != '\n')
791 buffer
= xrealloc( buffer
, size
* 2 );
792 if (!fgets( buffer
+ size
- 1, size
+ 1, file
)) break;
793 p
= buffer
+ strlen(buffer
);
796 if (p
> buffer
&& p
[-1] == '\n')
799 if (p
> buffer
&& p
[-1] == '\r') *(--p
) = 0;
800 if (p
> buffer
&& p
[-1] == '\\')
803 /* line ends in backslash, read continuation line */
804 if (!fgets( p
, size
- (p
- buffer
), file
)) return buffer
;
814 /*******************************************************************
817 static unsigned int hash_filename( const char *name
)
820 unsigned int ret
= 2166136261u;
821 while (*name
) ret
= (ret
* 16777619) ^ *name
++;
822 return ret
% HASH_SIZE
;
826 /*******************************************************************
829 static struct file
*add_file( const char *name
)
831 struct file
*file
= xmalloc( sizeof(*file
) );
832 memset( file
, 0, sizeof(*file
) );
833 file
->name
= xstrdup( name
);
838 /*******************************************************************
841 static void add_dependency( struct file
*file
, const char *name
, enum incl_type type
)
843 /* enforce some rules for the Wine tree */
845 if (!memcmp( name
, "../", 3 ))
846 fatal_error( "#include directive with relative path not allowed\n" );
848 if (!strcmp( name
, "config.h" ))
850 if (strendswith( file
->name
, ".h" ))
851 fatal_error( "config.h must not be included by a header file\n" );
852 if (file
->deps_count
)
853 fatal_error( "config.h must be included before anything else\n" );
855 else if (!strcmp( name
, "wine/port.h" ))
857 if (strendswith( file
->name
, ".h" ))
858 fatal_error( "wine/port.h must not be included by a header file\n" );
859 if (!file
->deps_count
) fatal_error( "config.h must be included before wine/port.h\n" );
860 if (file
->deps_count
> 1)
861 fatal_error( "wine/port.h must be included before everything except config.h\n" );
862 if (strcmp( file
->deps
[0].name
, "config.h" ))
863 fatal_error( "config.h must be included before wine/port.h\n" );
866 if (file
->deps_count
>= file
->deps_size
)
868 file
->deps_size
*= 2;
869 if (file
->deps_size
< 16) file
->deps_size
= 16;
870 file
->deps
= xrealloc( file
->deps
, file
->deps_size
* sizeof(*file
->deps
) );
872 file
->deps
[file
->deps_count
].line
= input_line
;
873 file
->deps
[file
->deps_count
].type
= type
;
874 file
->deps
[file
->deps_count
].name
= xstrdup( name
);
879 /*******************************************************************
882 static struct incl_file
*find_src_file( const struct makefile
*make
, const char *name
)
884 struct incl_file
*file
;
886 LIST_FOR_EACH_ENTRY( file
, &make
->sources
, struct incl_file
, entry
)
887 if (!strcmp( name
, file
->name
)) return file
;
891 /*******************************************************************
894 static struct incl_file
*find_include_file( const struct makefile
*make
, const char *name
)
896 struct incl_file
*file
;
898 LIST_FOR_EACH_ENTRY( file
, &make
->includes
, struct incl_file
, entry
)
899 if (!strcmp( name
, file
->name
)) return file
;
903 /*******************************************************************
906 * Add an include file if it doesn't already exists.
908 static struct incl_file
*add_include( struct makefile
*make
, struct incl_file
*parent
,
909 const char *name
, int line
, enum incl_type type
)
911 struct incl_file
*include
;
913 if (parent
->files_count
>= parent
->files_size
)
915 parent
->files_size
*= 2;
916 if (parent
->files_size
< 16) parent
->files_size
= 16;
917 parent
->files
= xrealloc( parent
->files
, parent
->files_size
* sizeof(*parent
->files
) );
920 LIST_FOR_EACH_ENTRY( include
, &make
->includes
, struct incl_file
, entry
)
921 if (!strcmp( name
, include
->name
)) goto found
;
923 include
= xmalloc( sizeof(*include
) );
924 memset( include
, 0, sizeof(*include
) );
925 include
->name
= xstrdup(name
);
926 include
->included_by
= parent
;
927 include
->included_line
= line
;
928 include
->type
= type
;
929 list_add_tail( &make
->includes
, &include
->entry
);
931 parent
->files
[parent
->files_count
++] = include
;
936 /*******************************************************************
937 * add_generated_source
939 * Add a generated source file to the list.
941 static struct incl_file
*add_generated_source( struct makefile
*make
,
942 const char *name
, const char *filename
)
944 struct incl_file
*file
;
946 if ((file
= find_src_file( make
, name
))) return file
; /* we already have it */
947 file
= xmalloc( sizeof(*file
) );
948 memset( file
, 0, sizeof(*file
) );
949 file
->file
= add_file( name
);
950 file
->name
= xstrdup( name
);
951 file
->filename
= obj_dir_path( make
, filename
? filename
: name
);
952 file
->file
->flags
= FLAG_GENERATED
;
953 list_add_tail( &make
->sources
, &file
->entry
);
958 /*******************************************************************
959 * parse_include_directive
961 static void parse_include_directive( struct file
*source
, char *str
)
963 char quote
, *include
, *p
= str
;
965 while (*p
&& isspace(*p
)) p
++;
966 if (*p
!= '\"' && *p
!= '<' ) return;
968 if (quote
== '<') quote
= '>';
970 while (*p
&& (*p
!= quote
)) p
++;
971 if (!*p
) fatal_error( "malformed include directive '%s'\n", str
);
973 add_dependency( source
, include
, (quote
== '>') ? INCL_SYSTEM
: INCL_NORMAL
);
977 /*******************************************************************
978 * parse_pragma_directive
980 static void parse_pragma_directive( struct file
*source
, char *str
)
982 char *flag
, *p
= str
;
984 if (!isspace( *p
)) return;
985 while (*p
&& isspace(*p
)) p
++;
986 p
= strtok( p
, " \t" );
987 if (strcmp( p
, "makedep" )) return;
989 while ((flag
= strtok( NULL
, " \t" )))
991 if (!strcmp( flag
, "depend" ))
993 while ((p
= strtok( NULL
, " \t" ))) add_dependency( source
, p
, INCL_NORMAL
);
996 else if (!strcmp( flag
, "install" )) source
->flags
|= FLAG_INSTALL
;
998 if (strendswith( source
->name
, ".idl" ))
1000 if (!strcmp( flag
, "header" )) source
->flags
|= FLAG_IDL_HEADER
;
1001 else if (!strcmp( flag
, "proxy" )) source
->flags
|= FLAG_IDL_PROXY
;
1002 else if (!strcmp( flag
, "client" )) source
->flags
|= FLAG_IDL_CLIENT
;
1003 else if (!strcmp( flag
, "server" )) source
->flags
|= FLAG_IDL_SERVER
;
1004 else if (!strcmp( flag
, "ident" )) source
->flags
|= FLAG_IDL_IDENT
;
1005 else if (!strcmp( flag
, "typelib" )) source
->flags
|= FLAG_IDL_TYPELIB
;
1006 else if (!strcmp( flag
, "register" )) source
->flags
|= FLAG_IDL_REGISTER
;
1007 else if (!strcmp( flag
, "regtypelib" )) source
->flags
|= FLAG_IDL_REGTYPELIB
;
1009 else if (strendswith( source
->name
, ".rc" ))
1011 if (!strcmp( flag
, "po" )) source
->flags
|= FLAG_RC_PO
;
1013 else if (strendswith( source
->name
, ".sfd" ))
1015 if (!strcmp( flag
, "font" ))
1017 struct strarray
*array
= source
->args
;
1021 source
->args
= array
= xmalloc( sizeof(*array
) );
1022 *array
= empty_strarray
;
1023 source
->flags
|= FLAG_SFD_FONTS
;
1025 strarray_add( array
, xstrdup( strtok( NULL
, "" )));
1029 else if (!strcmp( flag
, "implib" )) source
->flags
|= FLAG_C_IMPLIB
;
1034 /*******************************************************************
1035 * parse_cpp_directive
1037 static void parse_cpp_directive( struct file
*source
, char *str
)
1039 while (*str
&& isspace(*str
)) str
++;
1040 if (*str
++ != '#') return;
1041 while (*str
&& isspace(*str
)) str
++;
1043 if (!strncmp( str
, "include", 7 ))
1044 parse_include_directive( source
, str
+ 7 );
1045 else if (!strncmp( str
, "import", 6 ) && strendswith( source
->name
, ".m" ))
1046 parse_include_directive( source
, str
+ 6 );
1047 else if (!strncmp( str
, "pragma", 6 ))
1048 parse_pragma_directive( source
, str
+ 6 );
1052 /*******************************************************************
1055 static void parse_idl_file( struct file
*source
, FILE *file
)
1057 char *buffer
, *include
;
1061 while ((buffer
= get_line( file
)))
1065 while (*p
&& isspace(*p
)) p
++;
1067 if (!strncmp( p
, "importlib", 9 ))
1070 while (*p
&& isspace(*p
)) p
++;
1071 if (*p
++ != '(') continue;
1072 while (*p
&& isspace(*p
)) p
++;
1073 if (*p
++ != '"') continue;
1075 while (*p
&& (*p
!= '"')) p
++;
1076 if (!*p
) fatal_error( "malformed importlib directive\n" );
1078 add_dependency( source
, include
, INCL_IMPORTLIB
);
1082 if (!strncmp( p
, "import", 6 ))
1085 while (*p
&& isspace(*p
)) p
++;
1086 if (*p
!= '"') continue;
1088 while (*p
&& (*p
!= '"')) p
++;
1089 if (!*p
) fatal_error( "malformed import directive\n" );
1091 add_dependency( source
, include
, INCL_IMPORT
);
1095 /* check for #include inside cpp_quote */
1096 if (!strncmp( p
, "cpp_quote", 9 ))
1099 while (*p
&& isspace(*p
)) p
++;
1100 if (*p
++ != '(') continue;
1101 while (*p
&& isspace(*p
)) p
++;
1102 if (*p
++ != '"') continue;
1103 if (*p
++ != '#') continue;
1104 while (*p
&& isspace(*p
)) p
++;
1105 if (strncmp( p
, "include", 7 )) continue;
1107 while (*p
&& isspace(*p
)) p
++;
1108 if (*p
== '\\' && p
[1] == '"')
1115 if (*p
++ != '<' ) continue;
1119 while (*p
&& (*p
!= quote
)) p
++;
1120 if (!*p
|| (quote
== '"' && p
[-1] != '\\'))
1121 fatal_error( "malformed #include directive inside cpp_quote\n" );
1122 if (quote
== '"') p
--; /* remove backslash */
1124 add_dependency( source
, include
, (quote
== '>') ? INCL_CPP_QUOTE_SYSTEM
: INCL_CPP_QUOTE
);
1128 parse_cpp_directive( source
, p
);
1132 /*******************************************************************
1135 static void parse_c_file( struct file
*source
, FILE *file
)
1140 while ((buffer
= get_line( file
)))
1142 parse_cpp_directive( source
, buffer
);
1147 /*******************************************************************
1150 static void parse_rc_file( struct file
*source
, FILE *file
)
1152 char *buffer
, *include
;
1155 while ((buffer
= get_line( file
)))
1159 while (*p
&& isspace(*p
)) p
++;
1161 if (p
[0] == '/' && p
[1] == '*') /* check for magic makedep comment */
1164 while (*p
&& isspace(*p
)) p
++;
1165 if (strncmp( p
, "@makedep:", 9 )) continue;
1167 while (*p
&& isspace(*p
)) p
++;
1172 while (*p
&& *p
!= quote
) p
++;
1177 while (*p
&& !isspace(*p
) && *p
!= '*') p
++;
1180 fatal_error( "malformed makedep comment\n" );
1182 add_dependency( source
, include
, (quote
== '>') ? INCL_SYSTEM
: INCL_NORMAL
);
1186 parse_cpp_directive( source
, buffer
);
1191 /*******************************************************************
1194 static void parse_in_file( struct file
*source
, FILE *file
)
1198 /* make sure it gets rebuilt when the version changes */
1199 add_dependency( source
, "config.h", INCL_SYSTEM
);
1201 if (!strendswith( source
->name
, ".man.in" )) return; /* not a man page */
1204 while ((buffer
= get_line( file
)))
1206 if (strncmp( buffer
, ".TH", 3 )) continue;
1207 if (!(p
= strtok( buffer
, " \t" ))) continue; /* .TH */
1208 if (!(p
= strtok( NULL
, " \t" ))) continue; /* program name */
1209 if (!(p
= strtok( NULL
, " \t" ))) continue; /* man section */
1210 source
->args
= xstrdup( p
);
1216 /*******************************************************************
1219 static void parse_sfd_file( struct file
*source
, FILE *file
)
1221 char *p
, *eol
, *buffer
;
1224 while ((buffer
= get_line( file
)))
1226 if (strncmp( buffer
, "UComments:", 10 )) continue;
1228 while (*p
== ' ') p
++;
1229 if (p
[0] == '"' && p
[1] && buffer
[strlen(buffer
) - 1] == '"')
1232 buffer
[strlen(buffer
) - 1] = 0;
1234 while ((eol
= strstr( p
, "+AAoA" )))
1237 while (*p
&& isspace(*p
)) p
++;
1240 while (*p
&& isspace(*p
)) p
++;
1241 if (!strncmp( p
, "pragma", 6 )) parse_pragma_directive( source
, p
+ 6 );
1245 while (*p
&& isspace(*p
)) p
++;
1246 if (*p
++ != '#') return;
1247 while (*p
&& isspace(*p
)) p
++;
1248 if (!strncmp( p
, "pragma", 6 )) parse_pragma_directive( source
, p
+ 6 );
1257 void (*parse
)( struct file
*file
, FILE *f
);
1258 } parse_functions
[] =
1260 { ".c", parse_c_file
},
1261 { ".h", parse_c_file
},
1262 { ".inl", parse_c_file
},
1263 { ".l", parse_c_file
},
1264 { ".m", parse_c_file
},
1265 { ".rh", parse_c_file
},
1266 { ".x", parse_c_file
},
1267 { ".y", parse_c_file
},
1268 { ".idl", parse_idl_file
},
1269 { ".rc", parse_rc_file
},
1270 { ".in", parse_in_file
},
1271 { ".sfd", parse_sfd_file
}
1274 /*******************************************************************
1277 static struct file
*load_file( const char *name
)
1281 unsigned int i
, hash
= hash_filename( name
);
1283 LIST_FOR_EACH_ENTRY( file
, &files
[hash
], struct file
, entry
)
1284 if (!strcmp( name
, file
->name
)) return file
;
1286 if (!(f
= fopen( name
, "r" ))) return NULL
;
1288 file
= add_file( name
);
1289 list_add_tail( &files
[hash
], &file
->entry
);
1290 input_file_name
= file
->name
;
1293 for (i
= 0; i
< sizeof(parse_functions
) / sizeof(parse_functions
[0]); i
++)
1295 if (!strendswith( name
, parse_functions
[i
].ext
)) continue;
1296 parse_functions
[i
].parse( file
, f
);
1301 input_file_name
= NULL
;
1307 /*******************************************************************
1308 * open_include_path_file
1310 * Open a file from a directory on the include path.
1312 static struct file
*open_include_path_file( const struct makefile
*make
, const char *dir
,
1313 const char *name
, char **filename
)
1315 char *src_path
= base_dir_path( make
, concat_paths( dir
, name
));
1316 struct file
*ret
= load_file( src_path
);
1318 if (ret
) *filename
= src_dir_path( make
, concat_paths( dir
, name
));
1323 /*******************************************************************
1324 * open_file_same_dir
1326 * Open a file in the same directory as the parent.
1328 static struct file
*open_file_same_dir( const struct incl_file
*parent
, const char *name
, char **filename
)
1330 char *src_path
= replace_filename( parent
->file
->name
, name
);
1331 struct file
*ret
= load_file( src_path
);
1333 if (ret
) *filename
= replace_filename( parent
->filename
, name
);
1339 /*******************************************************************
1342 * Open a file in the source directory of the makefile.
1344 static struct file
*open_local_file( const struct makefile
*make
, const char *path
, char **filename
)
1346 char *src_path
= root_dir_path( base_dir_path( make
, path
));
1347 struct file
*ret
= load_file( src_path
);
1349 /* if not found, try parent dir */
1350 if (!ret
&& make
->parent_dir
)
1353 path
= strmake( "%s/%s", make
->parent_dir
, path
);
1354 src_path
= root_dir_path( base_dir_path( make
, path
));
1355 ret
= load_file( src_path
);
1356 if (ret
) ret
->flags
|= FLAG_PARENTDIR
;
1359 if (ret
) *filename
= src_dir_path( make
, path
);
1365 /*******************************************************************
1368 * Open a file in the top-level source directory.
1370 static struct file
*open_global_file( const struct makefile
*make
, const char *path
, char **filename
)
1372 char *src_path
= root_dir_path( path
);
1373 struct file
*ret
= load_file( src_path
);
1375 if (ret
) *filename
= top_src_dir_path( make
, path
);
1381 /*******************************************************************
1382 * open_global_header
1384 * Open a file in the global include source directory.
1386 static struct file
*open_global_header( const struct makefile
*make
, const char *path
, char **filename
)
1388 return open_global_file( make
, strmake( "include/%s", path
), filename
);
1392 /*******************************************************************
1395 static struct file
*open_src_file( const struct makefile
*make
, struct incl_file
*pFile
)
1397 struct file
*file
= open_local_file( make
, pFile
->name
, &pFile
->filename
);
1399 if (!file
) fatal_perror( "open %s", pFile
->name
);
1404 /*******************************************************************
1407 static struct file
*open_include_file( const struct makefile
*make
, struct incl_file
*pFile
)
1409 struct file
*file
= NULL
;
1411 unsigned int i
, len
;
1415 /* check for generated bison header */
1417 if (strendswith( pFile
->name
, ".tab.h" ) &&
1418 (file
= open_local_file( make
, replace_extension( pFile
->name
, ".tab.h", ".y" ), &filename
)))
1420 pFile
->sourcename
= filename
;
1421 pFile
->filename
= obj_dir_path( make
, pFile
->name
);
1425 /* check for corresponding idl file in source dir */
1427 if (strendswith( pFile
->name
, ".h" ) &&
1428 (file
= open_local_file( make
, replace_extension( pFile
->name
, ".h", ".idl" ), &filename
)))
1430 pFile
->sourcename
= filename
;
1431 pFile
->filename
= obj_dir_path( make
, pFile
->name
);
1435 /* check for corresponding tlb file in source dir */
1437 if (strendswith( pFile
->name
, ".tlb" ) &&
1438 (file
= open_local_file( make
, replace_extension( pFile
->name
, ".tlb", ".idl" ), &filename
)))
1440 pFile
->sourcename
= filename
;
1441 pFile
->filename
= obj_dir_path( make
, pFile
->name
);
1445 /* check for extra targets */
1446 if (strarray_exists( &make
->extra_targets
, pFile
->name
))
1448 pFile
->sourcename
= filename
;
1449 pFile
->filename
= obj_dir_path( make
, pFile
->name
);
1453 /* now try in source dir */
1454 if ((file
= open_local_file( make
, pFile
->name
, &pFile
->filename
))) return file
;
1456 /* check for corresponding idl file in global includes */
1458 if (strendswith( pFile
->name
, ".h" ) &&
1459 (file
= open_global_header( make
, replace_extension( pFile
->name
, ".h", ".idl" ), &filename
)))
1461 pFile
->sourcename
= filename
;
1462 pFile
->filename
= top_obj_dir_path( make
, strmake( "include/%s", pFile
->name
));
1466 /* check for corresponding .in file in global includes (for config.h.in) */
1468 if (strendswith( pFile
->name
, ".h" ) &&
1469 (file
= open_global_header( make
, replace_extension( pFile
->name
, ".h", ".h.in" ), &filename
)))
1471 pFile
->sourcename
= filename
;
1472 pFile
->filename
= top_obj_dir_path( make
, strmake( "include/%s", pFile
->name
));
1476 /* check for corresponding .x file in global includes */
1478 if (strendswith( pFile
->name
, "tmpl.h" ) &&
1479 (file
= open_global_header( make
, replace_extension( pFile
->name
, ".h", ".x" ), &filename
)))
1481 pFile
->sourcename
= filename
;
1482 pFile
->filename
= top_obj_dir_path( make
, strmake( "include/%s", pFile
->name
));
1486 /* check for corresponding .tlb file in global includes */
1488 if (strendswith( pFile
->name
, ".tlb" ) &&
1489 (file
= open_global_header( make
, replace_extension( pFile
->name
, ".tlb", ".idl" ), &filename
)))
1491 pFile
->sourcename
= filename
;
1492 pFile
->filename
= top_obj_dir_path( make
, strmake( "include/%s", pFile
->name
));
1496 /* check in global includes source dir */
1498 if ((file
= open_global_header( make
, pFile
->name
, &pFile
->filename
))) return file
;
1500 /* check in global msvcrt includes */
1501 if (make
->use_msvcrt
&&
1502 (file
= open_global_header( make
, strmake( "msvcrt/%s", pFile
->name
), &pFile
->filename
)))
1505 /* now search in include paths */
1506 for (i
= 0; i
< make
->include_paths
.count
; i
++)
1508 const char *dir
= make
->include_paths
.str
[i
];
1509 const char *prefix
= make
->top_src_dir
? make
->top_src_dir
: make
->top_obj_dir
;
1513 len
= strlen( prefix
);
1514 if (!strncmp( dir
, prefix
, len
) && (!dir
[len
] || dir
[len
] == '/'))
1516 while (dir
[len
] == '/') len
++;
1517 file
= open_global_file( make
, concat_paths( dir
+ len
, pFile
->name
), &pFile
->filename
);
1518 if (file
) return file
;
1520 if (make
->top_src_dir
) continue; /* ignore paths that don't point to the top source dir */
1524 if ((file
= open_include_path_file( make
, dir
, pFile
->name
, &pFile
->filename
)))
1528 if (pFile
->type
== INCL_SYSTEM
) return NULL
; /* ignore system files we cannot find */
1530 /* try in src file directory */
1531 if ((file
= open_file_same_dir( pFile
->included_by
, pFile
->name
, &pFile
->filename
))) return file
;
1533 fprintf( stderr
, "%s:%d: error: ", pFile
->included_by
->file
->name
, pFile
->included_line
);
1534 perror( pFile
->name
);
1535 pFile
= pFile
->included_by
;
1536 while (pFile
&& pFile
->included_by
)
1538 const char *parent
= pFile
->included_by
->sourcename
;
1539 if (!parent
) parent
= pFile
->included_by
->file
->name
;
1540 fprintf( stderr
, "%s:%d: note: %s was first included here\n",
1541 parent
, pFile
->included_line
, pFile
->name
);
1542 pFile
= pFile
->included_by
;
1548 /*******************************************************************
1551 static void add_all_includes( struct makefile
*make
, struct incl_file
*parent
, struct file
*file
)
1555 parent
->files_count
= 0;
1556 parent
->files_size
= file
->deps_count
;
1557 parent
->files
= xmalloc( parent
->files_size
* sizeof(*parent
->files
) );
1558 for (i
= 0; i
< file
->deps_count
; i
++)
1560 switch (file
->deps
[i
].type
)
1564 add_include( make
, parent
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_NORMAL
);
1566 case INCL_IMPORTLIB
:
1567 add_include( make
, parent
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_IMPORTLIB
);
1570 add_include( make
, parent
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_SYSTEM
);
1572 case INCL_CPP_QUOTE
:
1573 case INCL_CPP_QUOTE_SYSTEM
:
1580 /*******************************************************************
1583 static void parse_file( struct makefile
*make
, struct incl_file
*source
, int src
)
1585 struct file
*file
= src
? open_src_file( make
, source
) : open_include_file( make
, source
);
1589 source
->file
= file
;
1590 source
->files_count
= 0;
1591 source
->files_size
= file
->deps_count
;
1592 source
->files
= xmalloc( source
->files_size
* sizeof(*source
->files
) );
1594 if (source
->sourcename
)
1596 if (strendswith( source
->sourcename
, ".idl" ))
1600 if (strendswith( source
->name
, ".tlb" )) return; /* typelibs don't include anything */
1602 /* generated .h file always includes these */
1603 add_include( make
, source
, "rpc.h", 0, INCL_NORMAL
);
1604 add_include( make
, source
, "rpcndr.h", 0, INCL_NORMAL
);
1605 for (i
= 0; i
< file
->deps_count
; i
++)
1607 switch (file
->deps
[i
].type
)
1610 if (strendswith( file
->deps
[i
].name
, ".idl" ))
1611 add_include( make
, source
, replace_extension( file
->deps
[i
].name
, ".idl", ".h" ),
1612 file
->deps
[i
].line
, INCL_NORMAL
);
1614 add_include( make
, source
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_NORMAL
);
1616 case INCL_CPP_QUOTE
:
1617 add_include( make
, source
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_NORMAL
);
1619 case INCL_CPP_QUOTE_SYSTEM
:
1620 add_include( make
, source
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_SYSTEM
);
1624 case INCL_IMPORTLIB
:
1630 if (strendswith( source
->sourcename
, ".y" ))
1631 return; /* generated .tab.h doesn't include anything */
1634 add_all_includes( make
, source
, file
);
1638 /*******************************************************************
1641 * Add a source file to the list.
1643 static struct incl_file
*add_src_file( struct makefile
*make
, const char *name
)
1645 struct incl_file
*file
;
1647 if ((file
= find_src_file( make
, name
))) return file
; /* we already have it */
1648 file
= xmalloc( sizeof(*file
) );
1649 memset( file
, 0, sizeof(*file
) );
1650 file
->name
= xstrdup(name
);
1651 list_add_tail( &make
->sources
, &file
->entry
);
1652 parse_file( make
, file
, 1 );
1657 /*******************************************************************
1658 * open_input_makefile
1660 static FILE *open_input_makefile( const struct makefile
*make
)
1665 input_file_name
= root_dir_path( base_dir_path( make
, strmake( "%s.in", output_makefile_name
)));
1667 input_file_name
= output_makefile_name
; /* always use output name for main Makefile */
1670 if (!(ret
= fopen( input_file_name
, "r" ))) fatal_perror( "open" );
1675 /*******************************************************************
1678 static const char *get_make_variable( const struct makefile
*make
, const char *name
)
1682 if ((ret
= strarray_get_value( &cmdline_vars
, name
))) return ret
;
1683 if ((ret
= strarray_get_value( &make
->vars
, name
))) return ret
;
1684 if (top_makefile
&& (ret
= strarray_get_value( &top_makefile
->vars
, name
))) return ret
;
1689 /*******************************************************************
1690 * get_expanded_make_variable
1692 static char *get_expanded_make_variable( const struct makefile
*make
, const char *name
)
1695 char *p
, *end
, *expand
, *tmp
;
1697 var
= get_make_variable( make
, name
);
1698 if (!var
) return NULL
;
1700 p
= expand
= xstrdup( var
);
1701 while ((p
= strchr( p
, '$' )))
1705 if (!(end
= strchr( p
+ 2, ')' ))) fatal_error( "syntax error in '%s'\n", expand
);
1707 if (strchr( p
+ 2, ':' )) fatal_error( "pattern replacement not supported for '%s'\n", p
+ 2 );
1708 var
= get_make_variable( make
, p
+ 2 );
1709 tmp
= replace_substr( expand
, p
, end
- p
, var
? var
: "" );
1710 /* switch to the new string */
1711 p
= tmp
+ (p
- expand
);
1715 else if (p
[1] == '{') /* don't expand ${} variables */
1717 if (!(end
= strchr( p
+ 2, '}' ))) fatal_error( "syntax error in '%s'\n", expand
);
1720 else if (p
[1] == '$')
1724 else fatal_error( "syntax error in '%s'\n", expand
);
1727 /* consider empty variables undefined */
1729 while (*p
&& isspace(*p
)) p
++;
1730 if (*p
) return expand
;
1736 /*******************************************************************
1737 * get_expanded_make_var_array
1739 static struct strarray
get_expanded_make_var_array( const struct makefile
*make
, const char *name
)
1741 struct strarray ret
= empty_strarray
;
1742 char *value
, *token
;
1744 if ((value
= get_expanded_make_variable( make
, name
)))
1745 for (token
= strtok( value
, " \t" ); token
; token
= strtok( NULL
, " \t" ))
1746 strarray_add( &ret
, token
);
1751 /*******************************************************************
1752 * get_expanded_file_local_var
1754 static struct strarray
get_expanded_file_local_var( const struct makefile
*make
, const char *file
,
1757 char *p
, *var
= strmake( "%s_%s", file
, name
);
1759 for (p
= var
; *p
; p
++) if (!isalnum( *p
)) *p
= '_';
1760 return get_expanded_make_var_array( make
, var
);
1764 /*******************************************************************
1767 static int set_make_variable( struct strarray
*array
, const char *assignment
)
1771 p
= name
= xstrdup( assignment
);
1772 while (isalnum(*p
) || *p
== '_') p
++;
1773 if (name
== p
) return 0; /* not a variable */
1777 while (isspace(*p
)) p
++;
1779 if (*p
!= '=') return 0; /* not an assignment */
1781 while (isspace(*p
)) p
++;
1783 strarray_set_value( array
, name
, p
);
1788 /*******************************************************************
1791 static struct makefile
*parse_makefile( const char *path
)
1795 struct makefile
*make
= xmalloc( sizeof(*make
) );
1797 memset( make
, 0, sizeof(*make
) );
1800 make
->top_obj_dir
= get_relative_path( path
, "" );
1801 make
->base_dir
= path
;
1802 if (!strcmp( make
->base_dir
, "." )) make
->base_dir
= NULL
;
1805 file
= open_input_makefile( make
);
1806 while ((buffer
= get_line( file
)))
1808 if (!strncmp( buffer
, separator
, strlen(separator
) )) break;
1809 if (*buffer
== '\t') continue; /* command */
1810 while (isspace( *buffer
)) buffer
++;
1811 if (*buffer
== '#') continue; /* comment */
1812 set_make_variable( &make
->vars
, buffer
);
1815 input_file_name
= NULL
;
1820 /*******************************************************************
1821 * add_generated_sources
1823 static void add_generated_sources( struct makefile
*make
)
1826 struct incl_file
*source
, *next
, *file
;
1827 struct strarray objs
= get_expanded_make_var_array( make
, "EXTRA_OBJS" );
1829 LIST_FOR_EACH_ENTRY_SAFE( source
, next
, &make
->sources
, struct incl_file
, entry
)
1831 if (source
->file
->flags
& FLAG_IDL_CLIENT
)
1833 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_c.c" ), NULL
);
1834 add_dependency( file
->file
, replace_extension( source
->name
, ".idl", ".h" ), INCL_NORMAL
);
1835 add_all_includes( make
, file
, file
->file
);
1837 if (source
->file
->flags
& FLAG_IDL_SERVER
)
1839 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_s.c" ), NULL
);
1840 add_dependency( file
->file
, "wine/exception.h", INCL_NORMAL
);
1841 add_dependency( file
->file
, replace_extension( source
->name
, ".idl", ".h" ), INCL_NORMAL
);
1842 add_all_includes( make
, file
, file
->file
);
1844 if (source
->file
->flags
& FLAG_IDL_IDENT
)
1846 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_i.c" ), NULL
);
1847 add_dependency( file
->file
, "rpc.h", INCL_NORMAL
);
1848 add_dependency( file
->file
, "rpcndr.h", INCL_NORMAL
);
1849 add_dependency( file
->file
, "guiddef.h", INCL_NORMAL
);
1850 add_all_includes( make
, file
, file
->file
);
1852 if (source
->file
->flags
& FLAG_IDL_PROXY
)
1854 file
= add_generated_source( make
, "dlldata.o", "dlldata.c" );
1855 add_dependency( file
->file
, "objbase.h", INCL_NORMAL
);
1856 add_dependency( file
->file
, "rpcproxy.h", INCL_NORMAL
);
1857 add_all_includes( make
, file
, file
->file
);
1858 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_p.c" ), NULL
);
1859 add_dependency( file
->file
, "objbase.h", INCL_NORMAL
);
1860 add_dependency( file
->file
, "rpcproxy.h", INCL_NORMAL
);
1861 add_dependency( file
->file
, "wine/exception.h", INCL_NORMAL
);
1862 add_dependency( file
->file
, replace_extension( source
->name
, ".idl", ".h" ), INCL_NORMAL
);
1863 add_all_includes( make
, file
, file
->file
);
1865 if (source
->file
->flags
& FLAG_IDL_TYPELIB
)
1867 add_generated_source( make
, replace_extension( source
->name
, ".idl", ".tlb" ), NULL
);
1869 if (source
->file
->flags
& FLAG_IDL_REGTYPELIB
)
1871 add_generated_source( make
, replace_extension( source
->name
, ".idl", "_t.res" ), NULL
);
1873 if (source
->file
->flags
& FLAG_IDL_REGISTER
)
1875 add_generated_source( make
, replace_extension( source
->name
, ".idl", "_r.res" ), NULL
);
1877 if (source
->file
->flags
& FLAG_IDL_HEADER
)
1879 add_generated_source( make
, replace_extension( source
->name
, ".idl", ".h" ), NULL
);
1881 if (!source
->file
->flags
&& strendswith( source
->name
, ".idl" ))
1883 add_generated_source( make
, replace_extension( source
->name
, ".idl", ".h" ), NULL
);
1885 if (strendswith( source
->name
, ".x" ))
1887 add_generated_source( make
, replace_extension( source
->name
, ".x", ".h" ), NULL
);
1889 if (strendswith( source
->name
, ".y" ))
1891 file
= add_generated_source( make
, replace_extension( source
->name
, ".y", ".tab.c" ), NULL
);
1892 /* steal the includes list from the source file */
1893 file
->files_count
= source
->files_count
;
1894 file
->files_size
= source
->files_size
;
1895 file
->files
= source
->files
;
1896 source
->files_count
= source
->files_size
= 0;
1897 source
->files
= NULL
;
1899 if (strendswith( source
->name
, ".l" ))
1901 file
= add_generated_source( make
, replace_extension( source
->name
, ".l", ".yy.c" ), NULL
);
1902 /* steal the includes list from the source file */
1903 file
->files_count
= source
->files_count
;
1904 file
->files_size
= source
->files_size
;
1905 file
->files
= source
->files
;
1906 source
->files_count
= source
->files_size
= 0;
1907 source
->files
= NULL
;
1909 if (source
->file
->flags
& FLAG_C_IMPLIB
)
1911 if (!make
->staticimplib
&& make
->importlib
&& *dll_ext
)
1912 make
->staticimplib
= strmake( "lib%s.a", make
->importlib
);
1914 if (strendswith( source
->name
, ".po" ))
1916 if (!make
->disabled
)
1917 strarray_add_uniq( &linguas
, replace_extension( source
->name
, ".po", "" ));
1922 file
= add_generated_source( make
, "testlist.o", "testlist.c" );
1923 add_dependency( file
->file
, "wine/test.h", INCL_NORMAL
);
1924 add_all_includes( make
, file
, file
->file
);
1926 for (i
= 0; i
< objs
.count
; i
++)
1928 /* default to .c for unknown extra object files */
1929 if (strendswith( objs
.str
[i
], ".o" ))
1930 add_generated_source( make
, objs
.str
[i
], replace_extension( objs
.str
[i
], ".o", ".c" ));
1931 else if (strendswith( objs
.str
[i
], ".res" ))
1932 add_generated_source( make
, replace_extension( objs
.str
[i
], ".res", ".rc" ), NULL
);
1934 add_generated_source( make
, objs
.str
[i
], NULL
);
1939 /*******************************************************************
1942 static void create_dir( const char *dir
)
1946 p
= path
= xstrdup( dir
);
1947 while ((p
= strchr( p
, '/' )))
1950 if (mkdir( path
, 0755 ) == -1 && errno
!= EEXIST
) fatal_perror( "mkdir %s", path
);
1952 while (*p
== '/') p
++;
1954 if (mkdir( path
, 0755 ) == -1 && errno
!= EEXIST
) fatal_perror( "mkdir %s", path
);
1959 /*******************************************************************
1960 * create_file_directories
1962 * Create the base directories of all the files.
1964 static void create_file_directories( const struct makefile
*make
, struct strarray files
)
1966 struct strarray subdirs
= empty_strarray
;
1970 for (i
= 0; i
< files
.count
; i
++)
1972 if (!strchr( files
.str
[i
], '/' )) continue;
1973 dir
= base_dir_path( make
, files
.str
[i
] );
1974 *strrchr( dir
, '/' ) = 0;
1975 strarray_add_uniq( &subdirs
, dir
);
1978 for (i
= 0; i
< subdirs
.count
; i
++) create_dir( subdirs
.str
[i
] );
1982 /*******************************************************************
1983 * output_filenames_obj_dir
1985 static void output_filenames_obj_dir( const struct makefile
*make
, struct strarray array
)
1989 for (i
= 0; i
< array
.count
; i
++) output_filename( obj_dir_path( make
, array
.str
[i
] ));
1993 /*******************************************************************
1996 static void get_dependencies( struct incl_file
*file
, struct incl_file
*source
)
2000 if (!file
->filename
) return;
2004 if (file
->owner
== source
) return; /* already processed */
2005 if (file
->type
== INCL_IMPORTLIB
&&
2006 !(source
->file
->flags
& (FLAG_IDL_TYPELIB
| FLAG_IDL_REGTYPELIB
)))
2007 return; /* library is imported only when building a typelib */
2008 file
->owner
= source
;
2009 strarray_add( &source
->dependencies
, file
->filename
);
2011 for (i
= 0; i
< file
->files_count
; i
++) get_dependencies( file
->files
[i
], source
);
2015 /*******************************************************************
2016 * get_local_dependencies
2018 * Get the local dependencies of a given target.
2020 static struct strarray
get_local_dependencies( const struct makefile
*make
, const char *name
,
2021 struct strarray targets
)
2024 struct strarray deps
= get_expanded_file_local_var( make
, name
, "DEPS" );
2026 for (i
= 0; i
< deps
.count
; i
++)
2028 if (strarray_exists( &targets
, deps
.str
[i
] ))
2029 deps
.str
[i
] = obj_dir_path( make
, deps
.str
[i
] );
2031 deps
.str
[i
] = src_dir_path( make
, deps
.str
[i
] );
2037 /*******************************************************************
2040 * Check if makefile builds the named static library and return the full lib path.
2042 static const char *get_static_lib( const struct makefile
*make
, const char *name
)
2044 if (!make
->staticlib
) return NULL
;
2045 if (strncmp( make
->staticlib
, "lib", 3 )) return NULL
;
2046 if (strncmp( make
->staticlib
+ 3, name
, strlen(name
) )) return NULL
;
2047 if (strcmp( make
->staticlib
+ 3 + strlen(name
), ".a" )) return NULL
;
2048 return base_dir_path( make
, make
->staticlib
);
2052 /*******************************************************************
2053 * add_default_libraries
2055 static struct strarray
add_default_libraries( const struct makefile
*make
, struct strarray
*deps
)
2057 struct strarray ret
= empty_strarray
;
2058 struct strarray all_libs
= empty_strarray
;
2061 if (!make
->use_msvcrt
) strarray_add( &all_libs
, "-lwine_port" );
2062 strarray_addall( &all_libs
, get_expanded_make_var_array( make
, "EXTRALIBS" ));
2063 strarray_addall( &all_libs
, libs
);
2065 for (i
= 0; i
< all_libs
.count
; i
++)
2067 const char *lib
= NULL
;
2069 if (!strncmp( all_libs
.str
[i
], "-l", 2 ))
2071 const char *name
= all_libs
.str
[i
] + 2;
2073 for (j
= 0; j
< top_makefile
->subdirs
.count
; j
++)
2075 const struct makefile
*submake
= top_makefile
->submakes
[j
];
2077 if ((lib
= get_static_lib( submake
, name
))) break;
2083 lib
= top_obj_dir_path( make
, lib
);
2084 strarray_add( deps
, lib
);
2085 strarray_add( &ret
, lib
);
2087 else strarray_add( &ret
, all_libs
.str
[i
] );
2093 /*******************************************************************
2096 static struct strarray
add_import_libs( const struct makefile
*make
, struct strarray
*deps
,
2097 struct strarray imports
, int cross
)
2099 struct strarray ret
= empty_strarray
;
2102 for (i
= 0; i
< imports
.count
; i
++)
2104 const char *name
= imports
.str
[i
];
2105 const char *lib
= NULL
;
2107 for (j
= 0; j
< top_makefile
->subdirs
.count
; j
++)
2109 const struct makefile
*submake
= top_makefile
->submakes
[j
];
2111 if (submake
->importlib
&& !strcmp( submake
->importlib
, name
))
2113 if (cross
|| !*dll_ext
|| submake
->staticimplib
)
2114 lib
= base_dir_path( submake
, strmake( "lib%s.a", name
));
2116 strarray_add( deps
, top_obj_dir_path( make
,
2117 strmake( "%s/lib%s.def", submake
->base_dir
, name
)));
2121 if ((lib
= get_static_lib( submake
, name
))) break;
2126 if (cross
) lib
= replace_extension( lib
, ".a", ".cross.a" );
2127 lib
= top_obj_dir_path( make
, lib
);
2128 strarray_add( deps
, lib
);
2129 strarray_add( &ret
, lib
);
2131 else strarray_add( &ret
, strmake( "-l%s", name
));
2137 /*******************************************************************
2138 * get_default_imports
2140 static struct strarray
get_default_imports( const struct makefile
*make
)
2142 struct strarray ret
= empty_strarray
;
2144 if (strarray_exists( &make
->extradllflags
, "-nodefaultlibs" )) return ret
;
2145 if (strarray_exists( &make
->appmode
, "-mno-cygwin" )) strarray_add( &ret
, "msvcrt" );
2146 if (make
->is_win16
) strarray_add( &ret
, "kernel" );
2147 strarray_add( &ret
, "kernel32" );
2148 strarray_add( &ret
, "ntdll" );
2149 strarray_add( &ret
, "winecrt0" );
2154 /*******************************************************************
2157 static void add_install_rule( struct makefile
*make
, const char *target
,
2158 const char *file
, const char *dest
)
2160 if (strarray_exists( &make
->install_lib
, target
) ||
2161 strarray_exists( &top_install_lib
, make
->base_dir
) ||
2162 strarray_exists( &top_install_lib
, base_dir_path( make
, target
)))
2164 strarray_add( &make
->install_rules
[INSTALL_LIB
], file
);
2165 strarray_add( &make
->install_rules
[INSTALL_LIB
], dest
);
2167 else if (strarray_exists( &make
->install_dev
, target
) ||
2168 strarray_exists( &top_install_dev
, make
->base_dir
) ||
2169 strarray_exists( &top_install_dev
, base_dir_path( make
, target
)))
2171 strarray_add( &make
->install_rules
[INSTALL_DEV
], file
);
2172 strarray_add( &make
->install_rules
[INSTALL_DEV
], dest
);
2177 /*******************************************************************
2178 * get_include_install_path
2180 * Determine the installation path for a given include file.
2182 static const char *get_include_install_path( const char *name
)
2184 if (!strncmp( name
, "wine/", 5 )) return name
+ 5;
2185 if (!strncmp( name
, "msvcrt/", 7 )) return name
;
2186 return strmake( "windows/%s", name
);
2190 /*******************************************************************
2191 * get_shared_library_name
2193 * Determine possible names for a shared library with a version number.
2195 static struct strarray
get_shared_lib_names( const char *libname
)
2197 struct strarray ret
= empty_strarray
;
2198 const char *ext
, *p
;
2199 char *name
, *first
, *second
;
2202 strarray_add( &ret
, libname
);
2204 for (p
= libname
; (p
= strchr( p
, '.' )); p
++)
2205 if ((len
= strspn( p
+ 1, "0123456789." ))) break;
2207 if (!len
) return ret
;
2209 if (*ext
&& ext
[-1] == '.') ext
--;
2211 /* keep only the first group of digits */
2212 name
= xstrdup( libname
);
2213 first
= name
+ (p
- libname
);
2214 if ((second
= strchr( first
+ 1, '.' )))
2216 strcpy( second
, ext
);
2217 strarray_add( &ret
, xstrdup( name
));
2219 /* now remove all digits */
2220 strcpy( first
, ext
);
2221 strarray_add( &ret
, name
);
2226 /*******************************************************************
2227 * output_symlink_rule
2229 * Output a rule to create a symlink.
2231 static void output_symlink_rule( const char *src_name
, const char *link_name
)
2235 output( "\trm -f %s && ", link_name
);
2237 /* dest path with a directory needs special handling if ln -s isn't supported */
2238 if (strcmp( ln_s
, "ln -s" ) && ((name
= strrchr( link_name
, '/' ))))
2240 char *dir
= xstrdup( link_name
);
2241 dir
[name
- link_name
] = 0;
2242 output( "cd %s && %s %s %s\n", *dir
? dir
: "/", ln_s
, src_name
, name
+ 1 );
2247 output( "%s %s %s\n", ln_s
, src_name
, link_name
);
2252 /*******************************************************************
2253 * output_install_commands
2255 static void output_install_commands( struct makefile
*make
, const struct makefile
*submake
,
2256 struct strarray files
)
2259 char *install_sh
= top_src_dir_path( make
, "tools/install-sh" );
2261 for (i
= 0; i
< files
.count
; i
+= 2)
2263 const char *file
= files
.str
[i
];
2264 const char *dest
= strmake( "$(DESTDIR)%s", files
.str
[i
+ 1] + 1 );
2266 if (submake
) file
= base_dir_path( submake
, file
);
2267 switch (*files
.str
[i
+ 1])
2269 case 'd': /* data file */
2270 output( "\t%s -m 644 $(INSTALL_DATA_FLAGS) %s %s\n",
2271 install_sh
, obj_dir_path( make
, file
), dest
);
2273 case 'D': /* data file in source dir */
2274 output( "\t%s -m 644 $(INSTALL_DATA_FLAGS) %s %s\n",
2275 install_sh
, src_dir_path( make
, file
), dest
);
2277 case 'p': /* program file */
2278 output( "\tSTRIPPROG=\"$(STRIP)\" %s $(INSTALL_PROGRAM_FLAGS) %s %s\n",
2279 install_sh
, obj_dir_path( make
, file
), dest
);
2281 case 's': /* script */
2282 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s %s\n",
2283 install_sh
, obj_dir_path( make
, file
), dest
);
2285 case 'S': /* script in source dir */
2286 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s %s\n",
2287 install_sh
, src_dir_path( make
, file
), dest
);
2289 case 't': /* script in tools dir */
2290 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s %s\n",
2291 install_sh
, tools_dir_path( make
, files
.str
[i
] ), dest
);
2293 case 'y': /* symlink */
2294 output_symlink_rule( files
.str
[i
], dest
);
2299 strarray_add( &make
->uninstall_files
, dest
);
2304 /*******************************************************************
2305 * output_install_rules
2307 * Rules are stored as a (file,dest) pair of values.
2308 * The first char of dest indicates the type of install.
2310 static void output_install_rules( struct makefile
*make
, enum install_rules rules
, const char *target
)
2313 struct strarray files
= make
->install_rules
[rules
];
2314 struct strarray targets
= empty_strarray
;
2316 if (!files
.count
) return;
2318 for (i
= 0; i
< files
.count
; i
+= 2)
2320 const char *file
= files
.str
[i
];
2321 switch (*files
.str
[i
+ 1])
2323 case 'd': /* data file */
2324 case 'p': /* program file */
2325 case 's': /* script */
2326 strarray_add_uniq( &targets
, obj_dir_path( make
, file
));
2328 case 't': /* script in tools dir */
2329 strarray_add_uniq( &targets
, tools_dir_path( make
, file
));
2334 output( "install %s::", target
);
2335 output_filenames( targets
);
2337 output_install_commands( make
, NULL
, files
);
2339 strarray_add_uniq( &make
->phony_targets
, "install" );
2340 strarray_add_uniq( &make
->phony_targets
, target
);
2344 static int cmp_string_length( const char **a
, const char **b
)
2346 int paths_a
= 0, paths_b
= 0;
2349 for (p
= *a
; *p
; p
++) if (*p
== '/') paths_a
++;
2350 for (p
= *b
; *p
; p
++) if (*p
== '/') paths_b
++;
2351 if (paths_b
!= paths_a
) return paths_b
- paths_a
;
2352 return strcmp( *a
, *b
);
2355 /*******************************************************************
2356 * output_uninstall_rules
2358 static void output_uninstall_rules( struct makefile
*make
)
2360 static const char *dirs_order
[] =
2361 { "$(includedir)", "$(mandir)", "$(fontdir)", "$(datadir)", "$(dlldir)" };
2363 struct strarray subdirs
= empty_strarray
;
2366 if (!make
->uninstall_files
.count
) return;
2367 output( "uninstall::\n" );
2368 output_rm_filenames( make
->uninstall_files
);
2369 strarray_add_uniq( &make
->phony_targets
, "uninstall" );
2371 if (!make
->subdirs
.count
) return;
2372 for (i
= 0; i
< make
->uninstall_files
.count
; i
++)
2374 char *dir
= xstrdup( make
->uninstall_files
.str
[i
] );
2375 while (strchr( dir
, '/' ))
2377 *strrchr( dir
, '/' ) = 0;
2378 strarray_add_uniq( &subdirs
, xstrdup(dir
) );
2381 strarray_qsort( &subdirs
, cmp_string_length
);
2382 output( "\t-rmdir" );
2383 for (i
= 0; i
< sizeof(dirs_order
)/sizeof(dirs_order
[0]); i
++)
2385 for (j
= 0; j
< subdirs
.count
; j
++)
2387 if (!subdirs
.str
[j
]) continue;
2388 if (strncmp( subdirs
.str
[j
] + strlen("$(DESTDIR)"), dirs_order
[i
], strlen(dirs_order
[i
]) ))
2390 output_filename( subdirs
.str
[j
] );
2391 subdirs
.str
[j
] = NULL
;
2394 for (j
= 0; j
< subdirs
.count
; j
++)
2395 if (subdirs
.str
[j
]) output_filename( subdirs
.str
[j
] );
2400 /*******************************************************************
2401 * output_importlib_symlinks
2403 static struct strarray
output_importlib_symlinks( const struct makefile
*parent
,
2404 const struct makefile
*make
)
2406 struct strarray ret
= empty_strarray
;
2407 const char *lib
, *dst
;
2409 if (!make
->module
) return ret
;
2410 if (!make
->importlib
) return ret
;
2411 if (make
->is_win16
&& make
->disabled
) return ret
;
2412 if (strncmp( make
->base_dir
, "dlls/", 5 )) return ret
;
2413 if (!strcmp( make
->module
, make
->importlib
)) return ret
;
2414 if (!strchr( make
->importlib
, '.' ) &&
2415 !strncmp( make
->module
, make
->importlib
, strlen( make
->importlib
)) &&
2416 !strcmp( make
->module
+ strlen( make
->importlib
), ".dll" ))
2419 lib
= strmake( "lib%s.%s", make
->importlib
, *dll_ext
? "def" : "a" );
2420 dst
= concat_paths( obj_dir_path( parent
, "dlls" ), lib
);
2421 output( "%s: %s\n", dst
, base_dir_path( make
, lib
));
2422 output_symlink_rule( concat_paths( make
->base_dir
+ strlen("dlls/"), lib
), dst
);
2423 strarray_add( &ret
, dst
);
2425 if (crosstarget
&& !make
->is_win16
)
2427 lib
= strmake( "lib%s.cross.a", make
->importlib
);
2428 dst
= concat_paths( obj_dir_path( parent
, "dlls" ), lib
);
2429 output( "%s: %s\n", dst
, base_dir_path( make
, lib
));
2430 output_symlink_rule( concat_paths( make
->base_dir
+ strlen("dlls/"), lib
), dst
);
2431 strarray_add( &ret
, dst
);
2437 /*******************************************************************
2440 static void output_po_files( const struct makefile
*make
)
2442 const char *po_dir
= src_dir_path( make
, "po" );
2443 struct strarray pot_files
= empty_strarray
;
2444 struct incl_file
*source
;
2447 for (i
= 0; i
< make
->subdirs
.count
; i
++)
2449 struct makefile
*submake
= make
->submakes
[i
];
2451 LIST_FOR_EACH_ENTRY( source
, &submake
->sources
, struct incl_file
, entry
)
2453 if (source
->file
->flags
& FLAG_PARENTDIR
) continue;
2454 if (strendswith( source
->name
, ".rc" ) && (source
->file
->flags
& FLAG_RC_PO
))
2456 char *pot_file
= replace_extension( source
->name
, ".rc", ".pot" );
2457 char *pot_path
= base_dir_path( submake
, pot_file
);
2458 output( "%s: tools/wrc include dummy\n", pot_path
);
2459 output( "\t@cd %s && $(MAKE) %s\n", base_dir_path( submake
, "" ), pot_file
);
2460 strarray_add( &pot_files
, pot_path
);
2462 else if (strendswith( source
->name
, ".mc" ))
2464 char *pot_file
= replace_extension( source
->name
, ".mc", ".pot" );
2465 char *pot_path
= base_dir_path( submake
, pot_file
);
2466 output( "%s: tools/wmc include dummy\n", pot_path
);
2467 output( "\t@cd %s && $(MAKE) %s\n", base_dir_path( submake
, "" ), pot_file
);
2468 strarray_add( &pot_files
, pot_path
);
2474 for (i
= 0; i
< linguas
.count
; i
++)
2475 output_filename( strmake( "%s/%s.po", po_dir
, linguas
.str
[i
] ));
2476 output( ": %s/wine.pot\n", po_dir
);
2477 output( "\tmsgmerge --previous -q $@ %s/wine.pot | msgattrib --no-obsolete -o $@.new && mv $@.new $@\n",
2480 for (i
= 0; i
< linguas
.count
; i
++)
2481 output_filename( strmake( "%s/%s.po", po_dir
, linguas
.str
[i
] ));
2484 output( "%s/wine.pot:", po_dir
);
2485 output_filenames( pot_files
);
2487 output( "\tmsgcat -o $@" );
2488 output_filenames( pot_files
);
2493 /*******************************************************************
2496 static void output_source_y( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2498 /* add source file dependency for parallel makes */
2499 char *header
= strmake( "%s.tab.h", obj
);
2501 if (find_include_file( make
, header
))
2503 output( "%s: %s\n", obj_dir_path( make
, header
), source
->filename
);
2504 output( "\t%s -p %s_ -o %s.tab.c -d %s\n",
2505 bison
, obj
, obj_dir_path( make
, obj
), source
->filename
);
2506 output( "%s.tab.c: %s %s\n", obj_dir_path( make
, obj
),
2507 source
->filename
, obj_dir_path( make
, header
));
2508 strarray_add( &make
->clean_files
, header
);
2510 else output( "%s.tab.c: %s\n", obj
, source
->filename
);
2512 output( "\t%s -p %s_ -o $@ %s\n", bison
, obj
, source
->filename
);
2516 /*******************************************************************
2519 static void output_source_l( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2521 output( "%s.yy.c: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2522 output( "\t%s -o$@ %s\n", flex
, source
->filename
);
2526 /*******************************************************************
2529 static void output_source_h( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2531 if (source
->file
->flags
& FLAG_GENERATED
)
2532 strarray_add( &make
->all_targets
, source
->name
);
2534 add_install_rule( make
, source
->name
, source
->name
,
2535 strmake( "D$(includedir)/wine/%s", get_include_install_path( source
->name
) ));
2539 /*******************************************************************
2542 static void output_source_rc( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2544 struct strarray extradefs
= get_expanded_file_local_var( make
, obj
, "EXTRADEFS" );
2547 if (source
->file
->flags
& FLAG_GENERATED
) strarray_add( &make
->clean_files
, source
->name
);
2548 strarray_add( &make
->object_files
, strmake( "%s.res", obj
));
2549 if (crosstarget
) strarray_add( &make
->crossobj_files
, strmake( "%s.res", obj
));
2550 output( "%s.res: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2551 output( "\t%s -o $@", tools_path( make
, "wrc" ) );
2552 if (make
->is_win16
) output_filename( "-m16" );
2553 else output_filenames( target_flags
);
2554 output_filename( "--nostdinc" );
2555 output_filenames( make
->include_args
);
2556 output_filenames( make
->define_args
);
2557 output_filenames( extradefs
);
2558 if (linguas
.count
&& (source
->file
->flags
& FLAG_RC_PO
))
2560 char *po_dir
= top_obj_dir_path( make
, "po" );
2561 output_filename( strmake( "--po-dir=%s", po_dir
));
2562 output_filename( source
->filename
);
2564 output( "%s.res:", obj_dir_path( make
, obj
));
2565 for (i
= 0; i
< linguas
.count
; i
++)
2566 output_filename( strmake( "%s/%s.mo", po_dir
, linguas
.str
[i
] ));
2571 output_filename( source
->filename
);
2574 if (source
->file
->flags
& FLAG_RC_PO
&& !(source
->file
->flags
& FLAG_PARENTDIR
))
2576 strarray_add( &make
->clean_files
, strmake( "%s.pot", obj
));
2577 output( "%s.pot: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2578 output( "\t%s -O pot -o $@", tools_path( make
, "wrc" ) );
2579 if (make
->is_win16
) output_filename( "-m16" );
2580 else output_filenames( target_flags
);
2581 output_filename( "--nostdinc" );
2582 output_filenames( make
->include_args
);
2583 output_filenames( make
->define_args
);
2584 output_filenames( extradefs
);
2585 output_filename( source
->filename
);
2587 output( "%s.pot ", obj_dir_path( make
, obj
));
2589 output( "%s.res:", obj_dir_path( make
, obj
));
2590 output_filename( tools_path( make
, "wrc" ));
2591 output_filenames( source
->dependencies
);
2596 /*******************************************************************
2599 static void output_source_mc( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2603 strarray_add( &make
->object_files
, strmake( "%s.res", obj
));
2604 if (crosstarget
) strarray_add( &make
->crossobj_files
, strmake( "%s.res", obj
));
2605 strarray_add( &make
->clean_files
, strmake( "%s.pot", obj
));
2606 output( "%s.res: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2607 output( "\t%s -U -O res -o $@ %s", tools_path( make
, "wmc" ), source
->filename
);
2610 char *po_dir
= top_obj_dir_path( make
, "po" );
2611 output_filename( strmake( "--po-dir=%s", po_dir
));
2613 output( "%s.res:", obj_dir_path( make
, obj
));
2614 for (i
= 0; i
< linguas
.count
; i
++)
2615 output_filename( strmake( "%s/%s.mo", po_dir
, linguas
.str
[i
] ));
2618 output( "%s.pot: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2619 output( "\t%s -O pot -o $@ %s", tools_path( make
, "wmc" ), source
->filename
);
2621 output( "%s.pot %s.res:", obj_dir_path( make
, obj
), obj_dir_path( make
, obj
));
2622 output_filename( tools_path( make
, "wmc" ));
2623 output_filenames( source
->dependencies
);
2628 /*******************************************************************
2631 static void output_source_res( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2633 strarray_add( &make
->object_files
, source
->name
);
2634 if (crosstarget
) strarray_add( &make
->crossobj_files
, source
->name
);
2638 /*******************************************************************
2641 static void output_source_idl( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2643 struct strarray extradefs
= get_expanded_file_local_var( make
, obj
, "EXTRADEFS" );
2644 struct strarray targets
= empty_strarray
;
2648 if (!source
->file
->flags
) source
->file
->flags
|= FLAG_IDL_HEADER
| FLAG_INSTALL
;
2649 if (find_include_file( make
, strmake( "%s.h", obj
))) source
->file
->flags
|= FLAG_IDL_HEADER
;
2651 for (i
= 0; i
< sizeof(idl_outputs
) / sizeof(idl_outputs
[0]); i
++)
2653 if (!(source
->file
->flags
& idl_outputs
[i
].flag
)) continue;
2654 dest
= strmake( "%s%s", obj
, idl_outputs
[i
].ext
);
2655 if (!find_src_file( make
, dest
)) strarray_add( &make
->clean_files
, dest
);
2656 strarray_add( &targets
, dest
);
2658 if (source
->file
->flags
& FLAG_IDL_PROXY
) strarray_add( &make
->dlldata_files
, source
->name
);
2659 if (source
->file
->flags
& FLAG_INSTALL
)
2661 add_install_rule( make
, source
->name
, xstrdup( source
->name
),
2662 strmake( "D$(includedir)/wine/%s.idl", get_include_install_path( obj
) ));
2663 if (source
->file
->flags
& FLAG_IDL_HEADER
)
2664 add_install_rule( make
, source
->name
, strmake( "%s.h", obj
),
2665 strmake( "d$(includedir)/wine/%s.h", get_include_install_path( obj
) ));
2667 if (!targets
.count
) return;
2669 output_filenames_obj_dir( make
, targets
);
2670 output( ": %s\n", tools_path( make
, "widl" ));
2671 output( "\t%s -o $@", tools_path( make
, "widl" ) );
2672 output_filenames( target_flags
);
2673 output_filenames( make
->include_args
);
2674 output_filenames( make
->define_args
);
2675 output_filenames( extradefs
);
2676 output_filenames( get_expanded_make_var_array( make
, "EXTRAIDLFLAGS" ));
2677 output_filenames( get_expanded_file_local_var( make
, obj
, "EXTRAIDLFLAGS" ));
2678 output_filename( source
->filename
);
2680 output_filenames_obj_dir( make
, targets
);
2681 output( ": %s", source
->filename
);
2682 output_filenames( source
->dependencies
);
2687 /*******************************************************************
2690 static void output_source_tlb( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2692 strarray_add( &make
->all_targets
, source
->name
);
2696 /*******************************************************************
2699 static void output_source_x( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2701 output( "%s.h: %s%s %s\n", obj_dir_path( make
, obj
),
2702 tools_dir_path( make
, "make_xftmpl" ), tools_ext
, source
->filename
);
2703 output( "\t%s%s -H -o $@ %s\n",
2704 tools_dir_path( make
, "make_xftmpl" ), tools_ext
, source
->filename
);
2705 if (source
->file
->flags
& FLAG_INSTALL
)
2707 add_install_rule( make
, source
->name
, source
->name
,
2708 strmake( "D$(includedir)/wine/%s", get_include_install_path( source
->name
) ));
2709 add_install_rule( make
, source
->name
, strmake( "%s.h", obj
),
2710 strmake( "d$(includedir)/wine/%s.h", get_include_install_path( obj
) ));
2715 /*******************************************************************
2718 static void output_source_sfd( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2721 char *ttf_obj
= strmake( "%s.ttf", obj
);
2722 char *ttf_file
= src_dir_path( make
, ttf_obj
);
2724 if (fontforge
&& !make
->src_dir
)
2726 output( "%s: %s\n", ttf_file
, source
->filename
);
2727 output( "\t%s -script %s %s $@\n",
2728 fontforge
, top_src_dir_path( make
, "fonts/genttf.ff" ), source
->filename
);
2729 if (!(source
->file
->flags
& FLAG_SFD_FONTS
)) output( "all: %s\n", ttf_file
);
2731 if (source
->file
->flags
& FLAG_INSTALL
)
2732 add_install_rule( make
, source
->name
, ttf_obj
, strmake( "D$(fontdir)/%s", ttf_obj
));
2734 if (source
->file
->flags
& FLAG_SFD_FONTS
)
2736 struct strarray
*array
= source
->file
->args
;
2738 for (i
= 0; i
< array
->count
; i
++)
2740 char *font
= strtok( xstrdup(array
->str
[i
]), " \t" );
2741 char *args
= strtok( NULL
, "" );
2743 strarray_add( &make
->all_targets
, xstrdup( font
));
2744 output( "%s: %s %s\n", obj_dir_path( make
, font
),
2745 tools_path( make
, "sfnt2fon" ), ttf_file
);
2746 output( "\t%s -o $@ %s %s\n", tools_path( make
, "sfnt2fon" ), ttf_file
, args
);
2747 add_install_rule( make
, source
->name
, xstrdup(font
), strmake( "d$(fontdir)/%s", font
));
2753 /*******************************************************************
2756 static void output_source_svg( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2758 static const char * const images
[] = { "bmp", "cur", "ico", NULL
};
2761 if (convert
&& rsvg
&& icotool
&& !make
->src_dir
)
2763 for (i
= 0; images
[i
]; i
++)
2764 if (find_include_file( make
, strmake( "%s.%s", obj
, images
[i
] ))) break;
2768 output( "%s.%s: %s\n", src_dir_path( make
, obj
), images
[i
], source
->filename
);
2769 output( "\tCONVERT=\"%s\" ICOTOOL=\"%s\" RSVG=\"%s\" %s %s $@\n", convert
, icotool
, rsvg
,
2770 top_src_dir_path( make
, "tools/buildimage" ), source
->filename
);
2776 /*******************************************************************
2779 static void output_source_nls( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2781 add_install_rule( make
, source
->name
, source
->name
,
2782 strmake( "D$(datadir)/wine/%s", source
->name
));
2786 /*******************************************************************
2787 * output_source_desktop
2789 static void output_source_desktop( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2791 add_install_rule( make
, source
->name
, source
->name
,
2792 strmake( "D$(datadir)/applications/%s", source
->name
));
2796 /*******************************************************************
2799 static void output_source_po( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2801 output( "%s.mo: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2802 output( "\t%s -o $@ %s\n", msgfmt
, source
->filename
);
2803 strarray_add( &make
->all_targets
, strmake( "%s.mo", obj
));
2807 /*******************************************************************
2810 static void output_source_in( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2814 if (strendswith( obj
, ".man" ) && source
->file
->args
)
2816 struct strarray symlinks
;
2817 char *dir
, *dest
= replace_extension( obj
, ".man", "" );
2818 char *lang
= strchr( dest
, '.' );
2819 char *section
= source
->file
->args
;
2823 dir
= strmake( "$(mandir)/%s/man%s", lang
, section
);
2825 else dir
= strmake( "$(mandir)/man%s", section
);
2826 add_install_rule( make
, dest
, xstrdup(obj
), strmake( "d%s/%s.%s", dir
, dest
, section
));
2827 symlinks
= get_expanded_file_local_var( make
, dest
, "SYMLINKS" );
2828 for (i
= 0; i
< symlinks
.count
; i
++)
2829 add_install_rule( make
, symlinks
.str
[i
], strmake( "%s.%s", dest
, section
),
2830 strmake( "y%s/%s.%s", dir
, symlinks
.str
[i
], section
));
2834 strarray_add( &make
->in_files
, xstrdup(obj
) );
2835 strarray_add( &make
->all_targets
, xstrdup(obj
) );
2836 output( "%s: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2837 output( "\t%s %s >$@ || (rm -f $@ && false)\n", sed_cmd
, source
->filename
);
2838 output( "%s:", obj_dir_path( make
, obj
));
2839 output_filenames( source
->dependencies
);
2841 add_install_rule( make
, obj
, xstrdup( obj
), strmake( "d$(datadir)/wine/%s", obj
));
2845 /*******************************************************************
2846 * output_source_spec
2848 static void output_source_spec( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2850 struct strarray imports
= get_expanded_file_local_var( make
, obj
, "IMPORTS" );
2851 struct strarray dll_flags
= get_expanded_file_local_var( make
, obj
, "EXTRADLLFLAGS" );
2852 struct strarray all_libs
, dep_libs
= empty_strarray
;
2854 if (!imports
.count
) imports
= make
->imports
;
2855 if (!dll_flags
.count
) dll_flags
= make
->extradllflags
;
2856 all_libs
= add_import_libs( make
, &dep_libs
, imports
, 0 );
2857 add_import_libs( make
, &dep_libs
, get_default_imports( make
), 0 ); /* dependencies only */
2858 strarray_addall( &all_libs
, libs
);
2860 strarray_add( &make
->clean_files
, strmake( "%s.dll%s", obj
, dll_ext
));
2861 strarray_add( &make
->object_files
, strmake( "%s.res", obj
));
2862 output( "%s.res: %s.dll%s\n", obj_dir_path( make
, obj
), obj_dir_path( make
, obj
), dll_ext
);
2863 output( "\techo \"%s.dll TESTDLL \\\"%s.dll%s\\\"\" | %s -o $@\n", obj
,
2864 obj_dir_path( make
, obj
), dll_ext
, tools_path( make
, "wrc" ));
2866 output( "%s.dll%s:", obj_dir_path( make
, obj
), dll_ext
);
2867 output_filename( source
->filename
);
2868 output_filename( strmake( "%s.o", obj_dir_path( make
, obj
)));
2869 output_filenames( dep_libs
);
2870 output_filename( tools_path( make
, "winebuild" ));
2871 output_filename( tools_path( make
, "winegcc" ));
2873 output( "\t%s -s -o $@", tools_path( make
, "winegcc" ));
2874 output_filename( strmake( "-B%s", tools_dir_path( make
, "winebuild" )));
2875 if (tools_dir
) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make
, "" )));
2876 output_filenames( target_flags
);
2877 output_filenames( unwind_flags
);
2878 output_filenames( dll_flags
);
2879 output_filename( "-shared" );
2880 output_filename( source
->filename
);
2881 output_filename( strmake( "%s.o", obj_dir_path( make
, obj
)));
2882 output_filenames( all_libs
);
2883 output_filename( "$(LDFLAGS)" );
2888 dep_libs
= empty_strarray
;
2889 all_libs
= add_import_libs( make
, &dep_libs
, imports
, 1 );
2890 add_import_libs( make
, &dep_libs
, get_default_imports( make
), 1 ); /* dependencies only */
2891 strarray_addall( &all_libs
, libs
);
2893 strarray_add( &make
->clean_files
, strmake( "%s.dll", obj
));
2894 strarray_add( &make
->crossobj_files
, strmake( "%s.cross.res", obj
));
2895 output( "%s.cross.res: %s.dll\n", obj_dir_path( make
, obj
), obj_dir_path( make
, obj
) );
2896 output( "\techo \"%s.dll TESTDLL \\\"%s.dll\\\"\" | %s -o $@\n", obj
,
2897 obj_dir_path( make
, obj
), tools_path( make
, "wrc" ));
2899 output( "%s.dll:", obj_dir_path( make
, obj
));
2900 output_filename( source
->filename
);
2901 output_filename( strmake( "%s.cross.o", obj_dir_path( make
, obj
)));
2902 output_filenames( dep_libs
);
2903 output_filename( tools_path( make
, "winebuild" ));
2904 output_filename( tools_path( make
, "winegcc" ));
2906 output( "\t%s -s -o $@ -b %s", tools_path( make
, "winegcc" ), crosstarget
);
2907 output_filename( strmake( "-B%s", tools_dir_path( make
, "winebuild" )));
2908 if (tools_dir
) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make
, "" )));
2909 output_filename( "--lib-suffix=.cross.a" );
2910 output_filenames( dll_flags
);
2911 output_filename( "-shared" );
2912 output_filename( source
->filename
);
2913 output_filename( strmake( "%s.cross.o", obj_dir_path( make
, obj
)));
2914 output_filenames( all_libs
);
2915 output_filename( "$(LDFLAGS)" );
2921 /*******************************************************************
2922 * output_source_default
2924 static void output_source_default( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2926 struct strarray extradefs
= get_expanded_file_local_var( make
, obj
, "EXTRADEFS" );
2927 int is_dll_src
= (make
->testdll
&&
2928 strendswith( source
->name
, ".c" ) &&
2929 find_src_file( make
, replace_extension( source
->name
, ".c", ".spec" )));
2930 int need_cross
= (make
->testdll
||
2931 (source
->file
->flags
& FLAG_C_IMPLIB
) ||
2932 (make
->module
&& make
->staticlib
));
2934 if ((source
->file
->flags
& FLAG_GENERATED
) &&
2935 (!make
->testdll
|| !strendswith( source
->filename
, "testlist.c" )))
2936 strarray_add( &make
->clean_files
, source
->filename
);
2937 if (source
->file
->flags
& FLAG_C_IMPLIB
) strarray_add( &make
->implib_objs
, strmake( "%s.o", obj
));
2938 strarray_add( is_dll_src
? &make
->clean_files
: &make
->object_files
, strmake( "%s.o", obj
));
2939 output( "%s.o: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2940 output( "\t$(CC) -c -o $@ %s", source
->filename
);
2941 output_filenames( make
->include_args
);
2942 output_filenames( make
->define_args
);
2943 output_filenames( extradefs
);
2944 if (make
->module
|| make
->staticlib
|| make
->sharedlib
|| make
->testdll
)
2946 output_filenames( dll_flags
);
2947 if (make
->use_msvcrt
) output_filenames( msvcrt_flags
);
2949 output_filenames( extra_cflags
);
2950 output_filenames( cpp_flags
);
2951 output_filename( "$(CFLAGS)" );
2953 if (crosstarget
&& need_cross
)
2955 strarray_add( is_dll_src
? &make
->clean_files
: &make
->crossobj_files
, strmake( "%s.cross.o", obj
));
2956 output( "%s.cross.o: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2957 output( "\t$(CROSSCC) -c -o $@ %s", source
->filename
);
2958 output_filenames( make
->include_args
);
2959 output_filenames( make
->define_args
);
2960 output_filenames( extradefs
);
2961 if (make
->use_msvcrt
) output_filenames( msvcrt_flags
);
2962 output_filenames( extra_cross_cflags
);
2963 output_filenames( cpp_flags
);
2964 output_filename( "$(CROSSCFLAGS)" );
2967 if (strendswith( source
->name
, ".c" ) && !(source
->file
->flags
& FLAG_GENERATED
))
2969 strarray_add( &make
->c2man_files
, source
->filename
);
2970 if (make
->testdll
&& !is_dll_src
)
2972 strarray_add( &make
->ok_files
, strmake( "%s.ok", obj
));
2973 output( "%s.ok:\n", obj_dir_path( make
, obj
));
2974 output( "\t%s $(RUNTESTFLAGS) -T %s -M %s -p %s%s %s && touch $@\n",
2975 top_src_dir_path( make
, "tools/runtest" ), top_obj_dir_path( make
, "" ),
2976 make
->testdll
, replace_extension( make
->testdll
, ".dll", "_test.exe" ),
2980 output( "%s.o", obj_dir_path( make
, obj
));
2981 if (crosstarget
&& need_cross
) output( " %s.cross.o", obj_dir_path( make
, obj
));
2983 output_filenames( source
->dependencies
);
2988 /* dispatch table to output rules for a single source file */
2992 void (*fn
)( struct makefile
*make
, struct incl_file
*source
, const char *obj
);
2993 } output_source_funcs
[] =
2995 { "y", output_source_y
},
2996 { "l", output_source_l
},
2997 { "h", output_source_h
},
2998 { "rh", output_source_h
},
2999 { "inl", output_source_h
},
3000 { "rc", output_source_rc
},
3001 { "mc", output_source_mc
},
3002 { "res", output_source_res
},
3003 { "idl", output_source_idl
},
3004 { "tlb", output_source_tlb
},
3005 { "sfd", output_source_sfd
},
3006 { "svg", output_source_svg
},
3007 { "nls", output_source_nls
},
3008 { "desktop", output_source_desktop
},
3009 { "po", output_source_po
},
3010 { "in", output_source_in
},
3011 { "x", output_source_x
},
3012 { "spec", output_source_spec
},
3013 { NULL
, output_source_default
}
3017 /*******************************************************************
3020 static void output_man_pages( struct makefile
*make
)
3022 if (make
->c2man_files
.count
)
3024 char *spec_file
= src_dir_path( make
, replace_extension( make
->module
, ".dll", ".spec" ));
3026 output( "manpages::\n" );
3027 output( "\t%s -w %s", top_src_dir_path( make
, "tools/c2man.pl" ), spec_file
);
3028 output_filename( strmake( "-R%s", top_src_dir_path( make
, "" )));
3029 output_filename( strmake( "-I%s", top_src_dir_path( make
, "include" )));
3030 output_filename( strmake( "-o %s/man%s",
3031 top_obj_dir_path( make
, "documentation" ), man_ext
));
3032 output_filenames( make
->c2man_files
);
3034 output( "htmlpages::\n" );
3035 output( "\t%s -Th -w %s", top_src_dir_path( make
, "tools/c2man.pl" ), spec_file
);
3036 output_filename( strmake( "-R%s", top_src_dir_path( make
, "" )));
3037 output_filename( strmake( "-I%s", top_src_dir_path( make
, "include" )));
3038 output_filename( strmake( "-o %s",
3039 top_obj_dir_path( make
, "documentation/html" )));
3040 output_filenames( make
->c2man_files
);
3042 output( "sgmlpages::\n" );
3043 output( "\t%s -Ts -w %s", top_src_dir_path( make
, "tools/c2man.pl" ), spec_file
);
3044 output_filename( strmake( "-R%s", top_src_dir_path( make
, "" )));
3045 output_filename( strmake( "-I%s", top_src_dir_path( make
, "include" )));
3046 output_filename( strmake( "-o %s",
3047 top_obj_dir_path( make
, "documentation/api-guide" )));
3048 output_filenames( make
->c2man_files
);
3050 output( "xmlpages::\n" );
3051 output( "\t%s -Tx -w %s", top_src_dir_path( make
, "tools/c2man.pl" ), spec_file
);
3052 output_filename( strmake( "-R%s", top_src_dir_path( make
, "" )));
3053 output_filename( strmake( "-I%s", top_src_dir_path( make
, "include" )));
3054 output_filename( strmake( "-o %s",
3055 top_obj_dir_path( make
, "documentation/api-guide-xml" )));
3056 output_filenames( make
->c2man_files
);
3058 strarray_add( &make
->phony_targets
, "manpages" );
3059 strarray_add( &make
->phony_targets
, "htmlpages" );
3060 strarray_add( &make
->phony_targets
, "sgmlpages" );
3061 strarray_add( &make
->phony_targets
, "xmlpages" );
3063 else output( "manpages htmlpages sgmlpages xmlpages::\n" );
3067 /*******************************************************************
3070 static void output_module( struct makefile
*make
)
3072 struct strarray all_libs
= empty_strarray
;
3073 struct strarray dep_libs
= empty_strarray
;
3074 char *module_path
= obj_dir_path( make
, make
->module
);
3075 char *spec_file
= NULL
;
3078 if (!make
->appmode
.count
)
3079 spec_file
= src_dir_path( make
, replace_extension( make
->module
, ".dll", ".spec" ));
3080 strarray_addall( &all_libs
, add_import_libs( make
, &dep_libs
, make
->delayimports
, 0 ));
3081 strarray_addall( &all_libs
, add_import_libs( make
, &dep_libs
, make
->imports
, 0 ));
3082 add_import_libs( make
, &dep_libs
, get_default_imports( make
), 0 ); /* dependencies only */
3083 strarray_addall( &all_libs
, add_default_libraries( make
, &dep_libs
));
3087 for (i
= 0; i
< make
->delayimports
.count
; i
++)
3088 strarray_add( &all_libs
, strmake( "-Wb,-d%s", make
->delayimports
.str
[i
] ));
3089 strarray_add( &make
->all_targets
, strmake( "%s%s", make
->module
, dll_ext
));
3090 strarray_add( &make
->all_targets
, strmake( "%s.fake", make
->module
));
3091 add_install_rule( make
, make
->module
, strmake( "%s%s", make
->module
, dll_ext
),
3092 strmake( "p$(dlldir)/%s%s", make
->module
, dll_ext
));
3093 add_install_rule( make
, make
->module
, strmake( "%s.fake", make
->module
),
3094 strmake( "d$(dlldir)/fakedlls/%s", make
->module
));
3095 output( "%s%s %s.fake:", module_path
, dll_ext
, module_path
);
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 /*******************************************************************
3249 * output_test_module
3251 static void output_test_module( struct makefile
*make
)
3253 char *testmodule
= replace_extension( make
->testdll
, ".dll", "_test.exe" );
3254 char *stripped
= replace_extension( make
->testdll
, ".dll", "_test-stripped.exe" );
3255 char *testres
= replace_extension( make
->testdll
, ".dll", "_test.res" );
3256 struct strarray dep_libs
= empty_strarray
;
3257 struct strarray all_libs
= add_import_libs( make
, &dep_libs
, make
->imports
, 0 );
3258 int parent_disabled
= 0;
3260 add_import_libs( make
, &dep_libs
, get_default_imports( make
), 0 ); /* dependencies only */
3261 strarray_addall( &all_libs
, libs
);
3262 strarray_add( &make
->all_targets
, strmake( "%s%s", testmodule
, dll_ext
));
3263 strarray_add( &make
->clean_files
, strmake( "%s%s", stripped
, dll_ext
));
3264 output( "%s%s:\n", obj_dir_path( make
, testmodule
), dll_ext
);
3265 output( "\t%s -o $@", tools_path( make
, "winegcc" ));
3266 output_filename( strmake( "-B%s", tools_dir_path( make
, "winebuild" )));
3267 if (tools_dir
) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make
, "" )));
3268 output_filenames( target_flags
);
3269 output_filenames( unwind_flags
);
3270 output_filenames( make
->appmode
);
3271 output_filenames_obj_dir( make
, make
->object_files
);
3272 output_filenames( all_libs
);
3273 output_filename( "$(LDFLAGS)" );
3275 output( "%s%s:\n", obj_dir_path( make
, stripped
), dll_ext
);
3276 output( "\t%s -s -o $@", tools_path( make
, "winegcc" ));
3277 output_filename( strmake( "-B%s", tools_dir_path( make
, "winebuild" )));
3278 if (tools_dir
) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make
, "" )));
3279 output_filenames( target_flags
);
3280 output_filenames( unwind_flags
);
3281 output_filename( strmake( "-Wb,-F,%s", testmodule
));
3282 output_filenames( make
->appmode
);
3283 output_filenames_obj_dir( make
, make
->object_files
);
3284 output_filenames( all_libs
);
3285 output_filename( "$(LDFLAGS)" );
3287 output( "%s%s %s%s:", obj_dir_path( make
, testmodule
), dll_ext
,
3288 obj_dir_path( make
, stripped
), dll_ext
);
3289 output_filenames_obj_dir( make
, make
->object_files
);
3290 output_filenames( dep_libs
);
3291 output_filename( tools_path( make
, "winebuild" ));
3292 output_filename( tools_path( make
, "winegcc" ));
3295 if (!make
->disabled
&& !strarray_exists( &disabled_dirs
, "programs/winetest" ))
3296 output( "all: %s/%s\n", top_obj_dir_path( make
, "programs/winetest" ), testres
);
3297 output( "%s/%s: %s%s\n", top_obj_dir_path( make
, "programs/winetest" ), testres
,
3298 obj_dir_path( make
, stripped
), dll_ext
);
3299 output( "\techo \"%s TESTRES \\\"%s%s\\\"\" | %s -o $@\n",
3300 testmodule
, obj_dir_path( make
, stripped
), dll_ext
, tools_path( make
, "wrc" ));
3304 char *crosstest
= replace_extension( make
->testdll
, ".dll", "_crosstest.exe" );
3306 dep_libs
= empty_strarray
;
3307 all_libs
= add_import_libs( make
, &dep_libs
, make
->imports
, 1 );
3308 add_import_libs( make
, &dep_libs
, get_default_imports( make
), 1 ); /* dependencies only */
3309 strarray_addall( &all_libs
, libs
);
3310 strarray_add( &make
->clean_files
, crosstest
);
3311 output( "%s:", obj_dir_path( make
, crosstest
));
3312 output_filenames_obj_dir( make
, make
->crossobj_files
);
3313 output_filenames( dep_libs
);
3314 output_filename( tools_path( make
, "winebuild" ));
3315 output_filename( tools_path( make
, "winegcc" ));
3317 output( "\t%s -o $@ -b %s", tools_path( make
, "winegcc" ), crosstarget
);
3318 output_filename( strmake( "-B%s", tools_dir_path( make
, "winebuild" )));
3319 if (tools_dir
) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make
, "" )));
3320 output_filename( "--lib-suffix=.cross.a" );
3321 output_filenames_obj_dir( make
, make
->crossobj_files
);
3322 output_filenames( all_libs
);
3323 output_filename( "$(LDFLAGS)" );
3325 if (!make
->disabled
)
3327 output( "%s: %s\n", obj_dir_path( make
, "crosstest" ), obj_dir_path( make
, crosstest
));
3328 strarray_add( &make
->phony_targets
, obj_dir_path( make
, "crosstest" ));
3329 if (make
->obj_dir
) output( "crosstest: %s\n", obj_dir_path( make
, "crosstest" ));
3333 if (strendswith( make
->base_dir
, "/tests" ))
3335 char *dir
= xstrdup( make
->base_dir
);
3336 dir
[strlen( dir
) - 6] = 0;
3337 parent_disabled
= strarray_exists( &disabled_dirs
, dir
);
3339 output_filenames_obj_dir( make
, make
->ok_files
);
3340 output( ": %s%s ../%s%s\n", testmodule
, dll_ext
, make
->testdll
, dll_ext
);
3341 output( "check test:" );
3342 if (!make
->disabled
&& !parent_disabled
) output_filenames_obj_dir( make
, make
->ok_files
);
3344 strarray_add( &make
->phony_targets
, "check" );
3345 strarray_add( &make
->phony_targets
, "test" );
3346 output( "testclean::\n" );
3347 output( "\trm -f" );
3348 output_filenames_obj_dir( make
, make
->ok_files
);
3350 strarray_addall( &make
->clean_files
, make
->ok_files
);
3351 strarray_add( &make
->phony_targets
, "testclean" );
3355 /*******************************************************************
3358 static void output_programs( struct makefile
*make
)
3361 char *ldrpath_local
= get_expanded_make_variable( make
, "LDRPATH_LOCAL" );
3362 char *ldrpath_install
= get_expanded_make_variable( make
, "LDRPATH_INSTALL" );
3364 for (i
= 0; i
< make
->programs
.count
; i
++)
3366 char *program_installed
= NULL
;
3367 char *program
= strmake( "%s%s", make
->programs
.str
[i
], exe_ext
);
3368 struct strarray deps
= get_local_dependencies( make
, make
->programs
.str
[i
], make
->in_files
);
3369 struct strarray all_libs
= get_expanded_file_local_var( make
, make
->programs
.str
[i
], "LDFLAGS" );
3370 struct strarray objs
= get_expanded_file_local_var( make
, make
->programs
.str
[i
], "OBJS" );
3371 struct strarray symlinks
= get_expanded_file_local_var( make
, make
->programs
.str
[i
], "SYMLINKS" );
3373 if (!objs
.count
) objs
= make
->object_files
;
3374 strarray_addall( &all_libs
, add_default_libraries( make
, &deps
));
3376 output( "%s:", obj_dir_path( make
, program
) );
3377 output_filenames_obj_dir( make
, objs
);
3378 output_filenames( deps
);
3380 output( "\t$(CC) -o $@" );
3381 output_filenames_obj_dir( make
, objs
);
3383 if (strarray_exists( &all_libs
, "-lwine" ))
3385 strarray_add( &all_libs
, strmake( "-L%s", top_obj_dir_path( make
, "libs/wine" )));
3386 if (ldrpath_local
&& ldrpath_install
)
3388 program_installed
= strmake( "%s-installed%s", make
->programs
.str
[i
], exe_ext
);
3389 output_filename( ldrpath_local
);
3390 output_filenames( all_libs
);
3391 output_filename( "$(LDFLAGS)" );
3393 output( "%s:", obj_dir_path( make
, program_installed
) );
3394 output_filenames_obj_dir( make
, objs
);
3395 output_filenames( deps
);
3397 output( "\t$(CC) -o $@" );
3398 output_filenames_obj_dir( make
, objs
);
3399 output_filename( ldrpath_install
);
3400 strarray_add( &make
->all_targets
, program_installed
);
3404 output_filenames( all_libs
);
3405 output_filename( "$(LDFLAGS)" );
3407 strarray_add( &make
->all_targets
, program
);
3409 for (j
= 0; j
< symlinks
.count
; j
++)
3411 output( "%s: %s\n", obj_dir_path( make
, symlinks
.str
[j
] ), obj_dir_path( make
, program
));
3412 output_symlink_rule( obj_dir_path( make
, program
), obj_dir_path( make
, symlinks
.str
[j
] ));
3414 strarray_addall( &make
->all_targets
, symlinks
);
3416 add_install_rule( make
, program
, program_installed
? program_installed
: program
,
3417 strmake( "p$(bindir)/%s", program
));
3418 for (j
= 0; j
< symlinks
.count
; j
++)
3419 add_install_rule( make
, symlinks
.str
[j
], program
,
3420 strmake( "y$(bindir)/%s%s", symlinks
.str
[j
], exe_ext
));
3425 /*******************************************************************
3428 static void output_subdirs( struct makefile
*make
)
3430 struct strarray symlinks
= empty_strarray
;
3431 struct strarray all_deps
= empty_strarray
;
3432 struct strarray build_deps
= empty_strarray
;
3433 struct strarray builddeps_deps
= empty_strarray
;
3434 struct strarray makefile_deps
= empty_strarray
;
3435 struct strarray clean_files
= empty_strarray
;
3436 struct strarray testclean_files
= empty_strarray
;
3437 struct strarray distclean_files
= empty_strarray
;
3438 struct strarray tools_deps
= empty_strarray
;
3439 struct strarray tooldeps_deps
= empty_strarray
;
3440 struct strarray winetest_deps
= empty_strarray
;
3441 struct strarray crosstest_deps
= empty_strarray
;
3444 strarray_addall( &distclean_files
, make
->distclean_files
);
3445 for (i
= 0; i
< make
->subdirs
.count
; i
++)
3447 const struct makefile
*submake
= make
->submakes
[i
];
3448 char *subdir
= base_dir_path( submake
, "" );
3450 strarray_add( &makefile_deps
, top_src_dir_path( make
, base_dir_path( submake
,
3451 strmake ( "%s.in", output_makefile_name
))));
3452 for (j
= 0; j
< submake
->clean_files
.count
; j
++)
3453 strarray_add( &clean_files
, base_dir_path( submake
, submake
->clean_files
.str
[j
] ));
3454 for (j
= 0; j
< submake
->distclean_files
.count
; j
++)
3455 strarray_add( &distclean_files
, base_dir_path( submake
, submake
->distclean_files
.str
[j
] ));
3456 for (j
= 0; j
< submake
->ok_files
.count
; j
++)
3457 strarray_add( &testclean_files
, base_dir_path( submake
, submake
->ok_files
.str
[j
] ));
3459 /* import libs are still created for disabled dirs, except for win16 ones */
3460 if (submake
->module
&& submake
->importlib
&& !(submake
->disabled
&& submake
->is_win16
))
3462 char *importlib_path
= base_dir_path( submake
, strmake( "lib%s", submake
->importlib
));
3463 if (submake
->implib_objs
.count
)
3465 output( "%s.a: dummy\n", importlib_path
);
3466 output( "\t@cd %s && $(MAKE) lib%s.a\n", subdir
, submake
->importlib
);
3467 strarray_add( &tools_deps
, strmake( "%s.a", importlib_path
));
3470 output( "%s.cross.a: dummy\n", importlib_path
);
3471 output( "\t@cd %s && $(MAKE) lib%s.cross.a\n", subdir
, submake
->importlib
);
3472 strarray_add( &tools_deps
, strmake( "%s.cross.a", importlib_path
));
3477 const char *libext
= *dll_ext
? ".def" : ".a";
3478 char *spec_file
= top_src_dir_path( make
, base_dir_path( submake
,
3479 replace_extension( submake
->module
, ".dll", ".spec" )));
3480 output( "%s%s: %s", importlib_path
, libext
, spec_file
);
3481 output_filename( tools_path( make
, "winebuild" ));
3483 output( "\t%s -w -o $@", tools_path( make
, "winebuild" ));
3484 output_filename( *dll_ext
? "--def" : "--implib" );
3485 output_filenames( target_flags
);
3486 if (submake
->is_win16
) output_filename( "-m16" );
3487 output_filename( "--export" );
3488 output_filename( spec_file
);
3490 strarray_add( &build_deps
, strmake( "%s%s", importlib_path
, libext
));
3491 if (crosstarget
&& !submake
->is_win16
)
3493 output( "%s.cross.a: %s", importlib_path
, spec_file
);
3494 output_filename( tools_path( make
, "winebuild" ));
3496 output( "\t%s -b %s -w -o $@", tools_path( make
, "winebuild" ), crosstarget
);
3497 output_filename( "--implib" );
3498 output_filename( "--export" );
3499 output_filename( spec_file
);
3501 strarray_add( &build_deps
, strmake( "%s.cross.a", importlib_path
));
3504 strarray_addall( &symlinks
, output_importlib_symlinks( make
, submake
));
3507 if (submake
->disabled
) continue;
3508 strarray_add( &all_deps
, subdir
);
3510 if (submake
->module
)
3512 if (!submake
->staticlib
)
3514 strarray_add( &builddeps_deps
, subdir
);
3515 if (!submake
->appmode
.count
)
3517 output( "manpages htmlpages sgmlpages xmlpages::\n" );
3518 output( "\t@cd %s && $(MAKE) $@\n", subdir
);
3521 else strarray_add( &tools_deps
, subdir
);
3523 else if (submake
->testdll
)
3525 output( "%s/test: dummy\n", subdir
);
3526 output( "\t@cd %s && $(MAKE) test\n", subdir
);
3527 strarray_add( &winetest_deps
, subdir
);
3528 strarray_add( &builddeps_deps
, subdir
);
3531 char *target
= base_dir_path( submake
, "crosstest" );
3532 output( "crosstest: %s\n", target
);
3533 output( "%s: dummy\n", target
);
3534 output( "\t@cd %s && $(MAKE) crosstest\n", subdir
);
3535 strarray_add( &crosstest_deps
, target
);
3536 strarray_add( &builddeps_deps
, target
);
3541 if (!strcmp( submake
->base_dir
, "tools" ) || !strncmp( submake
->base_dir
, "tools/", 6 ))
3543 strarray_add( &tooldeps_deps
, submake
->base_dir
);
3544 for (j
= 0; j
< submake
->programs
.count
; j
++)
3545 output( "%s/%s%s: %s\n", submake
->base_dir
,
3546 submake
->programs
.str
[j
], tools_ext
, submake
->base_dir
);
3548 if (submake
->programs
.count
|| submake
->sharedlib
)
3550 struct strarray libs
= get_expanded_make_var_array( submake
, "EXTRALIBS" );
3551 for (j
= 0; j
< submake
->programs
.count
; j
++)
3552 strarray_addall( &libs
, get_expanded_file_local_var( submake
,
3553 submake
->programs
.str
[j
], "LDFLAGS" ));
3554 output( "%s: libs/port", submake
->base_dir
);
3555 for (j
= 0; j
< libs
.count
; j
++)
3557 if (!strcmp( libs
.str
[j
], "-lwpp" )) output_filename( "libs/wpp" );
3558 if (!strcmp( libs
.str
[j
], "-lwine" )) output_filename( "libs/wine" );
3564 if (submake
->install_rules
[INSTALL_LIB
].count
)
3566 output( "install install-lib:: %s\n", submake
->base_dir
);
3567 output_install_commands( make
, submake
, submake
->install_rules
[INSTALL_LIB
] );
3569 if (submake
->install_rules
[INSTALL_DEV
].count
)
3571 output( "install install-dev:: %s\n", submake
->base_dir
);
3572 output_install_commands( make
, submake
, submake
->install_rules
[INSTALL_DEV
] );
3576 output_filenames( all_deps
);
3578 output_filenames( all_deps
);
3579 output( ": dummy\n" );
3580 output( "\t@cd $@ && $(MAKE)\n" );
3581 output( "Makefile:" );
3582 output_filenames( makefile_deps
);
3584 output_filenames( makefile_deps
);
3586 if (tooldeps_deps
.count
)
3588 output( "__tooldeps__:" );
3589 output_filenames( tooldeps_deps
);
3591 strarray_add( &make
->phony_targets
, "__tooldeps__" );
3593 if (winetest_deps
.count
)
3595 output( "buildtests programs/winetest:" );
3596 output_filenames( winetest_deps
);
3598 output( "check test:" );
3599 for (i
= 0; i
< winetest_deps
.count
; i
++)
3601 char *target
= strmake( "%s/test", winetest_deps
.str
[i
] );
3602 output_filename( target
);
3603 strarray_add( &make
->phony_targets
, target
);
3606 strarray_add( &make
->phony_targets
, "buildtests" );
3607 strarray_add( &make
->phony_targets
, "check" );
3608 strarray_add( &make
->phony_targets
, "test" );
3610 output( "crosstest:" );
3611 output_filenames( crosstest_deps
);
3613 if (!crosstest_deps
.count
)
3614 output( "\t@echo \"crosstest is not supported (mingw not installed?)\" && false\n" );
3615 strarray_add( &make
->phony_targets
, "crosstest" );
3617 output( "clean::\n");
3618 output_rm_filenames( clean_files
);
3619 output( "testclean::\n");
3620 output_rm_filenames( testclean_files
);
3621 output( "distclean::\n");
3622 output_rm_filenames( distclean_files
);
3623 output_filenames( tools_deps
);
3625 output_filename( tools_dir_path( make
, "widl" ));
3626 output_filename( tools_dir_path( make
, "winebuild" ));
3627 output_filename( tools_dir_path( make
, "winegcc" ));
3628 output_filename( obj_dir_path( make
, "include" ));
3630 output_filenames( builddeps_deps
);
3631 output( ": __builddeps__\n" );
3632 strarray_add( &make
->phony_targets
, "distclean" );
3633 strarray_add( &make
->phony_targets
, "testclean" );
3634 strarray_addall( &make
->phony_targets
, all_deps
);
3635 strarray_addall( &make
->phony_targets
, crosstest_deps
);
3637 strarray_addall( &make
->clean_files
, symlinks
);
3638 strarray_addall( &build_deps
, tools_deps
);
3639 strarray_addall( &build_deps
, symlinks
);
3640 if (build_deps
.count
)
3642 output( "__builddeps__:" );
3643 output_filenames( build_deps
);
3645 strarray_add( &make
->phony_targets
, "__builddeps__" );
3647 if (get_expanded_make_variable( make
, "GETTEXTPO_LIBS" )) output_po_files( make
);
3651 /*******************************************************************
3654 static void output_sources( struct makefile
*make
)
3656 struct incl_file
*source
;
3659 strarray_add( &make
->phony_targets
, "all" );
3661 LIST_FOR_EACH_ENTRY( source
, &make
->sources
, struct incl_file
, entry
)
3663 char *obj
= xstrdup( source
->name
);
3664 char *ext
= get_extension( obj
);
3666 if (!ext
) fatal_error( "unsupported file type %s\n", source
->name
);
3669 for (j
= 0; output_source_funcs
[j
].ext
; j
++)
3670 if (!strcmp( ext
, output_source_funcs
[j
].ext
)) break;
3672 output_source_funcs
[j
].fn( make
, source
, obj
);
3673 strarray_addall_uniq( &make
->dependencies
, source
->dependencies
);
3676 /* special case for winetest: add resource files from other test dirs */
3677 if (make
->base_dir
&& !strcmp( make
->base_dir
, "programs/winetest" ))
3679 struct strarray tests
= enable_tests
;
3681 for (i
= 0; i
< top_makefile
->subdirs
.count
; i
++)
3682 if (top_makefile
->submakes
[i
]->testdll
&& !top_makefile
->submakes
[i
]->disabled
)
3683 strarray_add( &tests
, top_makefile
->submakes
[i
]->testdll
);
3684 for (i
= 0; i
< tests
.count
; i
++)
3685 strarray_add( &make
->object_files
, replace_extension( tests
.str
[i
], ".dll", "_test.res" ));
3688 if (make
->dlldata_files
.count
)
3690 output( "%s: %s %s\n", obj_dir_path( make
, "dlldata.c" ),
3691 tools_path( make
, "widl" ), src_dir_path( make
, "Makefile.in" ));
3692 output( "\t%s --dlldata-only -o $@", tools_path( make
, "widl" ));
3693 output_filenames( make
->dlldata_files
);
3697 if (make
->staticlib
) output_static_lib( make
);
3698 else if (make
->module
) output_module( make
);
3699 else if (make
->testdll
) output_test_module( make
);
3700 else if (make
->sharedlib
) output_shared_lib( make
);
3701 else if (make
->programs
.count
) output_programs( make
);
3703 for (i
= 0; i
< make
->scripts
.count
; i
++)
3704 add_install_rule( make
, make
->scripts
.str
[i
], make
->scripts
.str
[i
],
3705 strmake( "S$(bindir)/%s", make
->scripts
.str
[i
] ));
3707 if (!make
->src_dir
) strarray_add( &make
->distclean_files
, ".gitignore" );
3708 strarray_add( &make
->distclean_files
, "Makefile" );
3709 if (make
->testdll
) strarray_add( &make
->distclean_files
, "testlist.c" );
3711 if (!make
->base_dir
)
3712 strarray_addall( &make
->distclean_files
, get_expanded_make_var_array( make
, "CONFIGURE_TARGETS" ));
3713 else if (!strcmp( make
->base_dir
, "po" ))
3714 strarray_add( &make
->distclean_files
, "LINGUAS" );
3716 if (make
->subdirs
.count
) output_subdirs( make
);
3718 if (!make
->disabled
)
3720 if (make
->all_targets
.count
)
3723 output_filenames_obj_dir( make
, make
->all_targets
);
3726 output_install_rules( make
, INSTALL_LIB
, "install-lib" );
3727 output_install_rules( make
, INSTALL_DEV
, "install-dev" );
3728 output_uninstall_rules( make
);
3731 if (make
->dependencies
.count
)
3733 output_filenames( make
->dependencies
);
3737 strarray_addall( &make
->clean_files
, make
->object_files
);
3738 strarray_addall_uniq( &make
->clean_files
, make
->crossobj_files
);
3739 strarray_addall( &make
->clean_files
, make
->all_targets
);
3740 strarray_addall( &make
->clean_files
, make
->extra_targets
);
3742 if (make
->clean_files
.count
)
3744 output( "%s::\n", obj_dir_path( make
, "clean" ));
3745 output( "\trm -f" );
3746 output_filenames_obj_dir( make
, make
->clean_files
);
3748 if (make
->obj_dir
) output( "__clean__: %s\n", obj_dir_path( make
, "clean" ));
3749 strarray_add( &make
->phony_targets
, obj_dir_path( make
, "clean" ));
3752 if (make
->phony_targets
.count
)
3754 output( ".PHONY:" );
3755 output_filenames( make
->phony_targets
);
3761 /*******************************************************************
3764 static FILE *create_temp_file( const char *orig
)
3766 char *name
= xmalloc( strlen(orig
) + 13 );
3767 unsigned int i
, id
= getpid();
3771 for (i
= 0; i
< 100; i
++)
3773 sprintf( name
, "%s.tmp%08x", orig
, id
);
3774 if ((fd
= open( name
, O_RDWR
| O_CREAT
| O_EXCL
, 0666 )) != -1)
3776 ret
= fdopen( fd
, "w" );
3779 if (errno
!= EEXIST
) break;
3782 if (!ret
) fatal_error( "failed to create output file for '%s'\n", orig
);
3783 temp_file_name
= name
;
3788 /*******************************************************************
3791 static void rename_temp_file( const char *dest
)
3793 int ret
= rename( temp_file_name
, dest
);
3794 if (ret
== -1 && errno
== EEXIST
)
3796 /* rename doesn't overwrite on windows */
3798 ret
= rename( temp_file_name
, dest
);
3800 if (ret
== -1) fatal_error( "failed to rename output file to '%s'\n", dest
);
3801 temp_file_name
= NULL
;
3805 /*******************************************************************
3806 * are_files_identical
3808 static int are_files_identical( FILE *file1
, FILE *file2
)
3812 char buffer1
[8192], buffer2
[8192];
3813 int size1
= fread( buffer1
, 1, sizeof(buffer1
), file1
);
3814 int size2
= fread( buffer2
, 1, sizeof(buffer2
), file2
);
3815 if (size1
!= size2
) return 0;
3816 if (!size1
) return feof( file1
) && feof( file2
);
3817 if (memcmp( buffer1
, buffer2
, size1
)) return 0;
3822 /*******************************************************************
3823 * rename_temp_file_if_changed
3825 static void rename_temp_file_if_changed( const char *dest
)
3827 FILE *file1
, *file2
;
3830 if ((file1
= fopen( dest
, "r" )))
3832 if ((file2
= fopen( temp_file_name
, "r" )))
3834 do_rename
= !are_files_identical( file1
, file2
);
3841 unlink( temp_file_name
);
3842 temp_file_name
= NULL
;
3844 else rename_temp_file( dest
);
3848 /*******************************************************************
3851 static void output_linguas( const struct makefile
*make
)
3853 const char *dest
= base_dir_path( make
, "LINGUAS" );
3854 struct incl_file
*source
;
3856 output_file
= create_temp_file( dest
);
3858 output( "# Automatically generated by make depend; DO NOT EDIT!!\n" );
3859 LIST_FOR_EACH_ENTRY( source
, &make
->sources
, struct incl_file
, entry
)
3860 if (strendswith( source
->name
, ".po" ))
3861 output( "%s\n", replace_extension( source
->name
, ".po", "" ));
3863 if (fclose( output_file
)) fatal_perror( "write" );
3865 rename_temp_file_if_changed( dest
);
3869 /*******************************************************************
3872 static void output_testlist( const struct makefile
*make
)
3874 const char *dest
= base_dir_path( make
, "testlist.c" );
3875 struct strarray files
= empty_strarray
;
3878 for (i
= 0; i
< make
->ok_files
.count
; i
++)
3879 strarray_add( &files
, replace_extension( make
->ok_files
.str
[i
], ".ok", "" ));
3881 output_file
= create_temp_file( dest
);
3883 output( "/* Automatically generated by make depend; DO NOT EDIT!! */\n\n" );
3884 output( "#define WIN32_LEAN_AND_MEAN\n" );
3885 output( "#include <windows.h>\n\n" );
3886 output( "#define STANDALONE\n" );
3887 output( "#include \"wine/test.h\"\n\n" );
3889 for (i
= 0; i
< files
.count
; i
++) output( "extern void func_%s(void);\n", files
.str
[i
] );
3891 output( "const struct test winetest_testlist[] =\n" );
3893 for (i
= 0; i
< files
.count
; i
++) output( " { \"%s\", func_%s },\n", files
.str
[i
], files
.str
[i
] );
3894 output( " { 0, 0 }\n" );
3897 if (fclose( output_file
)) fatal_perror( "write" );
3899 rename_temp_file_if_changed( dest
);
3903 /*******************************************************************
3906 static void output_gitignore( const char *dest
, struct strarray files
)
3910 output_file
= create_temp_file( dest
);
3912 output( "# Automatically generated by make depend; DO NOT EDIT!!\n" );
3913 for (i
= 0; i
< files
.count
; i
++)
3915 if (!strchr( files
.str
[i
], '/' )) output( "/" );
3916 output( "%s\n", files
.str
[i
] );
3919 if (fclose( output_file
)) fatal_perror( "write" );
3921 rename_temp_file( dest
);
3925 /*******************************************************************
3926 * output_top_variables
3928 static void output_top_variables( const struct makefile
*make
)
3931 struct strarray
*vars
= &top_makefile
->vars
;
3933 if (!make
->base_dir
) return; /* don't output variables in the top makefile */
3935 output( "# Automatically generated by make depend; DO NOT EDIT!!\n\n" );
3936 output( "all:\n\n" );
3937 for (i
= 0; i
< vars
->count
; i
+= 2)
3939 if (!strcmp( vars
->str
[i
], "SUBDIRS" )) continue; /* not inherited */
3940 output( "%s = %s\n", vars
->str
[i
], get_make_variable( make
, vars
->str
[i
] ));
3946 /*******************************************************************
3947 * output_dependencies
3949 static void output_dependencies( struct makefile
*make
)
3951 struct strarray ignore_files
= empty_strarray
;
3956 if (make
->base_dir
) create_dir( make
->base_dir
);
3958 output_file_name
= base_dir_path( make
, output_makefile_name
);
3959 output_file
= create_temp_file( output_file_name
);
3960 output_top_variables( make
);
3962 /* copy the contents of the source makefile */
3963 src_file
= open_input_makefile( make
);
3964 while (fgets( buffer
, sizeof(buffer
), src_file
) && !found
)
3966 if (fwrite( buffer
, 1, strlen(buffer
), output_file
) != strlen(buffer
)) fatal_perror( "write" );
3967 found
= !strncmp( buffer
, separator
, strlen(separator
) );
3969 if (fclose( src_file
)) fatal_perror( "close" );
3970 input_file_name
= NULL
;
3972 if (!found
) output( "\n%s (everything below this line is auto-generated; DO NOT EDIT!!)\n", separator
);
3973 output_sources( make
);
3975 fclose( output_file
);
3977 rename_temp_file( output_file_name
);
3979 strarray_addall( &ignore_files
, make
->distclean_files
);
3980 strarray_addall( &ignore_files
, make
->clean_files
);
3981 if (make
->testdll
) output_testlist( make
);
3982 if (make
->base_dir
&& !strcmp( make
->base_dir
, "po" )) output_linguas( make
);
3983 if (!make
->src_dir
) output_gitignore( base_dir_path( make
, ".gitignore" ), ignore_files
);
3985 create_file_directories( make
, ignore_files
);
3987 output_file_name
= NULL
;
3991 /*******************************************************************
3994 static void load_sources( struct makefile
*make
)
3996 static const char *source_vars
[] =
4017 struct strarray value
;
4018 struct incl_file
*file
;
4022 make
->top_src_dir
= concat_paths( make
->top_obj_dir
, root_src_dir
);
4023 make
->src_dir
= concat_paths( make
->top_src_dir
, make
->base_dir
);
4025 strarray_set_value( &make
->vars
, "top_builddir", top_obj_dir_path( make
, "" ));
4026 strarray_set_value( &make
->vars
, "top_srcdir", top_src_dir_path( make
, "" ));
4027 strarray_set_value( &make
->vars
, "srcdir", src_dir_path( make
, "" ));
4029 make
->parent_dir
= get_expanded_make_variable( make
, "PARENTSRC" );
4030 make
->module
= get_expanded_make_variable( make
, "MODULE" );
4031 make
->testdll
= get_expanded_make_variable( make
, "TESTDLL" );
4032 make
->sharedlib
= get_expanded_make_variable( make
, "SHAREDLIB" );
4033 make
->staticlib
= get_expanded_make_variable( make
, "STATICLIB" );
4034 make
->importlib
= get_expanded_make_variable( make
, "IMPORTLIB" );
4036 make
->programs
= get_expanded_make_var_array( make
, "PROGRAMS" );
4037 make
->scripts
= get_expanded_make_var_array( make
, "SCRIPTS" );
4038 make
->appmode
= get_expanded_make_var_array( make
, "APPMODE" );
4039 make
->imports
= get_expanded_make_var_array( make
, "IMPORTS" );
4040 make
->delayimports
= get_expanded_make_var_array( make
, "DELAYIMPORTS" );
4041 make
->extradllflags
= get_expanded_make_var_array( make
, "EXTRADLLFLAGS" );
4042 make
->install_lib
= get_expanded_make_var_array( make
, "INSTALL_LIB" );
4043 make
->install_dev
= get_expanded_make_var_array( make
, "INSTALL_DEV" );
4044 make
->extra_targets
= get_expanded_make_var_array( make
, "EXTRA_TARGETS" );
4046 if (make
->module
&& strendswith( make
->module
, ".a" )) make
->staticlib
= make
->module
;
4048 make
->disabled
= make
->base_dir
&& strarray_exists( &disabled_dirs
, make
->base_dir
);
4049 make
->is_win16
= strarray_exists( &make
->extradllflags
, "-m16" ) || strarray_exists( &make
->appmode
, "-m16" );
4050 make
->use_msvcrt
= strarray_exists( &make
->appmode
, "-mno-cygwin" );
4052 for (i
= 0; i
< make
->imports
.count
&& !make
->use_msvcrt
; i
++)
4053 make
->use_msvcrt
= !strncmp( make
->imports
.str
[i
], "msvcr", 5 ) ||
4054 !strcmp( make
->imports
.str
[i
], "ucrtbase" );
4056 if (make
->module
&& !make
->install_lib
.count
&& !make
->install_dev
.count
)
4058 if (make
->importlib
) strarray_add( &make
->install_dev
, make
->importlib
);
4059 if (make
->staticlib
) strarray_add( &make
->install_dev
, make
->staticlib
);
4060 else strarray_add( &make
->install_lib
, make
->module
);
4063 make
->include_paths
= empty_strarray
;
4064 make
->include_args
= empty_strarray
;
4065 make
->define_args
= empty_strarray
;
4066 strarray_add( &make
->define_args
, "-D__WINESRC__" );
4068 value
= get_expanded_make_var_array( make
, "EXTRAINCL" );
4069 for (i
= 0; i
< value
.count
; i
++)
4070 if (!strncmp( value
.str
[i
], "-I", 2 ))
4071 strarray_add_uniq( &make
->include_paths
, value
.str
[i
] + 2 );
4073 strarray_add_uniq( &make
->define_args
, value
.str
[i
] );
4074 strarray_addall( &make
->define_args
, get_expanded_make_var_array( make
, "EXTRADEFS" ));
4076 strarray_add( &make
->include_args
, strmake( "-I%s", obj_dir_path( make
, "" )));
4078 strarray_add( &make
->include_args
, strmake( "-I%s", make
->src_dir
));
4079 if (make
->parent_dir
)
4080 strarray_add( &make
->include_args
, strmake( "-I%s", src_dir_path( make
, make
->parent_dir
)));
4081 strarray_add( &make
->include_args
, strmake( "-I%s", top_obj_dir_path( make
, "include" )));
4082 if (make
->top_src_dir
)
4083 strarray_add( &make
->include_args
, strmake( "-I%s", top_src_dir_path( make
, "include" )));
4084 if (make
->use_msvcrt
)
4085 strarray_add( &make
->include_args
, strmake( "-I%s", top_src_dir_path( make
, "include/msvcrt" )));
4086 for (i
= 0; i
< make
->include_paths
.count
; i
++)
4087 strarray_add( &make
->include_args
, strmake( "-I%s", obj_dir_path( make
, make
->include_paths
.str
[i
] )));
4089 list_init( &make
->sources
);
4090 list_init( &make
->includes
);
4092 for (var
= source_vars
; *var
; var
++)
4094 value
= get_expanded_make_var_array( make
, *var
);
4095 for (i
= 0; i
< value
.count
; i
++) add_src_file( make
, value
.str
[i
] );
4098 add_generated_sources( make
);
4100 LIST_FOR_EACH_ENTRY( file
, &make
->includes
, struct incl_file
, entry
) parse_file( make
, file
, 0 );
4101 LIST_FOR_EACH_ENTRY( file
, &make
->sources
, struct incl_file
, entry
) get_dependencies( file
, file
);
4105 /*******************************************************************
4108 static void parse_makeflags( const char *flags
)
4110 const char *p
= flags
;
4111 char *var
, *buffer
= xmalloc( strlen(flags
) + 1 );
4115 while (isspace(*p
)) p
++;
4117 while (*p
&& !isspace(*p
))
4119 if (*p
== '\\' && p
[1]) p
++;
4123 if (var
> buffer
) set_make_variable( &cmdline_vars
, buffer
);
4128 /*******************************************************************
4131 static int parse_option( const char *opt
)
4135 if (strchr( opt
, '=' )) return set_make_variable( &cmdline_vars
, opt
);
4141 if (opt
[2]) output_makefile_name
= opt
+ 2;
4144 relative_dir_mode
= 1;
4147 fprintf( stderr
, "Unknown option '%s'\n%s", opt
, Usage
);
4154 /*******************************************************************
4157 int main( int argc
, char *argv
[] )
4159 const char *makeflags
= getenv( "MAKEFLAGS" );
4162 if (makeflags
) parse_makeflags( makeflags
);
4167 if (parse_option( argv
[i
] ))
4169 for (j
= i
; j
< argc
; j
++) argv
[j
] = argv
[j
+1];
4175 if (relative_dir_mode
)
4181 fprintf( stderr
, "Option -R needs two directories\n%s", Usage
);
4184 relpath
= get_relative_path( argv
[1], argv
[2] );
4185 printf( "%s\n", relpath
? relpath
: "." );
4189 atexit( cleanup_files
);
4190 signal( SIGTERM
, exit_on_signal
);
4191 signal( SIGINT
, exit_on_signal
);
4193 signal( SIGHUP
, exit_on_signal
);
4196 for (i
= 0; i
< HASH_SIZE
; i
++) list_init( &files
[i
] );
4198 top_makefile
= parse_makefile( NULL
);
4200 target_flags
= get_expanded_make_var_array( top_makefile
, "TARGETFLAGS" );
4201 msvcrt_flags
= get_expanded_make_var_array( top_makefile
, "MSVCRTFLAGS" );
4202 dll_flags
= get_expanded_make_var_array( top_makefile
, "DLLFLAGS" );
4203 extra_cflags
= get_expanded_make_var_array( top_makefile
, "EXTRACFLAGS" );
4204 extra_cross_cflags
= get_expanded_make_var_array( top_makefile
, "EXTRACROSSCFLAGS" );
4205 cpp_flags
= get_expanded_make_var_array( top_makefile
, "CPPFLAGS" );
4206 unwind_flags
= get_expanded_make_var_array( top_makefile
, "UNWINDFLAGS" );
4207 libs
= get_expanded_make_var_array( top_makefile
, "LIBS" );
4208 enable_tests
= get_expanded_make_var_array( top_makefile
, "ENABLE_TESTS" );
4209 top_install_lib
= get_expanded_make_var_array( top_makefile
, "TOP_INSTALL_LIB" );
4210 top_install_dev
= get_expanded_make_var_array( top_makefile
, "TOP_INSTALL_DEV" );
4212 root_src_dir
= get_expanded_make_variable( top_makefile
, "srcdir" );
4213 tools_dir
= get_expanded_make_variable( top_makefile
, "TOOLSDIR" );
4214 tools_ext
= get_expanded_make_variable( top_makefile
, "TOOLSEXT" );
4215 exe_ext
= get_expanded_make_variable( top_makefile
, "EXEEXT" );
4216 man_ext
= get_expanded_make_variable( top_makefile
, "api_manext" );
4217 dll_ext
= (exe_ext
&& !strcmp( exe_ext
, ".exe" )) ? "" : ".so";
4218 crosstarget
= get_expanded_make_variable( top_makefile
, "CROSSTARGET" );
4219 fontforge
= get_expanded_make_variable( top_makefile
, "FONTFORGE" );
4220 convert
= get_expanded_make_variable( top_makefile
, "CONVERT" );
4221 flex
= get_expanded_make_variable( top_makefile
, "FLEX" );
4222 bison
= get_expanded_make_variable( top_makefile
, "BISON" );
4223 ar
= get_expanded_make_variable( top_makefile
, "AR" );
4224 ranlib
= get_expanded_make_variable( top_makefile
, "RANLIB" );
4225 rsvg
= get_expanded_make_variable( top_makefile
, "RSVG" );
4226 icotool
= get_expanded_make_variable( top_makefile
, "ICOTOOL" );
4227 dlltool
= get_expanded_make_variable( top_makefile
, "DLLTOOL" );
4228 msgfmt
= get_expanded_make_variable( top_makefile
, "MSGFMT" );
4229 sed_cmd
= get_expanded_make_variable( top_makefile
, "SED_CMD" );
4230 ln_s
= get_expanded_make_variable( top_makefile
, "LN_S" );
4232 if (root_src_dir
&& !strcmp( root_src_dir
, "." )) root_src_dir
= NULL
;
4233 if (tools_dir
&& !strcmp( tools_dir
, "." )) tools_dir
= NULL
;
4234 if (!exe_ext
) exe_ext
= "";
4235 if (!tools_ext
) tools_ext
= "";
4236 if (!man_ext
) man_ext
= "3w";
4240 disabled_dirs
= get_expanded_make_var_array( top_makefile
, "DISABLED_SUBDIRS" );
4241 top_makefile
->subdirs
= get_expanded_make_var_array( top_makefile
, "SUBDIRS" );
4242 top_makefile
->submakes
= xmalloc( top_makefile
->subdirs
.count
* sizeof(*top_makefile
->submakes
) );
4244 for (i
= 0; i
< top_makefile
->subdirs
.count
; i
++)
4245 top_makefile
->submakes
[i
] = parse_makefile( top_makefile
->subdirs
.str
[i
] );
4247 load_sources( top_makefile
);
4248 for (i
= 0; i
< top_makefile
->subdirs
.count
; i
++)
4249 load_sources( top_makefile
->submakes
[i
] );
4251 for (i
= 0; i
< top_makefile
->subdirs
.count
; i
++)
4252 output_dependencies( top_makefile
->submakes
[i
] );
4254 output_dependencies( top_makefile
);
4258 for (i
= 1; i
< argc
; i
++)
4260 struct makefile
*make
= parse_makefile( argv
[i
] );
4261 load_sources( make
);
4262 output_dependencies( make
);