2 * Generate include file dependencies
4 * Copyright 1996, 2013, 2020 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
32 #include <sys/types.h>
37 #if defined(_WIN32) && !defined(__CYGWIN__)
40 #define mkdir(path,mode) mkdir(path)
42 #include "wine/list.h"
46 unsigned int count
; /* strings in use */
47 unsigned int size
; /* total allocated size */
53 INCL_NORMAL
, /* #include "foo.h" */
54 INCL_SYSTEM
, /* #include <foo.h> */
55 INCL_IMPORT
, /* idl import "foo.idl" */
56 INCL_IMPORTLIB
, /* idl importlib "foo.tlb" */
57 INCL_CPP_QUOTE
, /* idl cpp_quote("#include \"foo.h\"") */
58 INCL_CPP_QUOTE_SYSTEM
/* idl cpp_quote("#include <foo.h>") */
63 int line
; /* source line where this header is included */
64 enum incl_type type
; /* type of include */
65 char *name
; /* header name */
71 char *name
; /* full file name relative to cwd */
72 void *args
; /* custom arguments for makefile rule */
73 unsigned int flags
; /* flags (see below) */
74 unsigned int deps_count
; /* files in use */
75 unsigned int deps_size
; /* total allocated size */
76 struct dependency
*deps
; /* all header dependencies */
85 char *basename
; /* base target name for generated files */
86 char *sourcename
; /* source file name for generated headers */
87 struct incl_file
*included_by
; /* file that included this one */
88 int included_line
; /* line where this file was included */
89 enum incl_type type
; /* type of include */
90 int use_msvcrt
; /* put msvcrt headers in the search path? */
91 struct incl_file
*owner
;
92 unsigned int files_count
; /* files in use */
93 unsigned int files_size
; /* total allocated size */
94 struct incl_file
**files
;
95 struct strarray dependencies
; /* file dependencies */
98 #define FLAG_GENERATED 0x000001 /* generated file */
99 #define FLAG_INSTALL 0x000002 /* file to install */
100 #define FLAG_IDL_PROXY 0x000100 /* generates a proxy (_p.c) file */
101 #define FLAG_IDL_CLIENT 0x000200 /* generates a client (_c.c) file */
102 #define FLAG_IDL_SERVER 0x000400 /* generates a server (_s.c) file */
103 #define FLAG_IDL_IDENT 0x000800 /* generates an ident (_i.c) file */
104 #define FLAG_IDL_REGISTER 0x001000 /* generates a registration (_r.res) file */
105 #define FLAG_IDL_TYPELIB 0x002000 /* generates a typelib (.tlb) file */
106 #define FLAG_IDL_REGTYPELIB 0x004000 /* generates a registered typelib (_t.res) file */
107 #define FLAG_IDL_HEADER 0x008000 /* generates a header (.h) file */
108 #define FLAG_RC_PO 0x010000 /* rc file contains translations */
109 #define FLAG_C_IMPLIB 0x020000 /* file is part of an import library */
110 #define FLAG_C_UNIX 0x040000 /* file is part of a Unix library */
111 #define FLAG_SFD_FONTS 0x080000 /* sfd file generated bitmap fonts */
119 { FLAG_IDL_TYPELIB
, ".tlb" },
120 { FLAG_IDL_REGTYPELIB
, "_t.res" },
121 { FLAG_IDL_CLIENT
, "_c.c" },
122 { FLAG_IDL_IDENT
, "_i.c" },
123 { FLAG_IDL_PROXY
, "_p.c" },
124 { FLAG_IDL_SERVER
, "_s.c" },
125 { FLAG_IDL_REGISTER
, "_r.res" },
126 { FLAG_IDL_HEADER
, ".h" }
129 #define HASH_SIZE 997
131 static struct list files
[HASH_SIZE
];
133 static const struct strarray empty_strarray
;
135 enum install_rules
{ INSTALL_LIB
, INSTALL_DEV
, NB_INSTALL_RULES
};
137 /* variables common to all makefiles */
138 static struct strarray linguas
;
139 static struct strarray dll_flags
;
140 static struct strarray target_flags
;
141 static struct strarray msvcrt_flags
;
142 static struct strarray extra_cflags
;
143 static struct strarray extra_cross_cflags
;
144 static struct strarray cpp_flags
;
145 static struct strarray lddll_flags
;
146 static struct strarray libs
;
147 static struct strarray enable_tests
;
148 static struct strarray cmdline_vars
;
149 static struct strarray subdirs
;
150 static struct strarray disabled_dirs
;
151 static struct strarray cross_import_libs
;
152 static struct strarray delay_import_libs
;
153 static struct strarray top_install_lib
;
154 static struct strarray top_install_dev
;
155 static const char *root_src_dir
;
156 static const char *tools_dir
;
157 static const char *tools_ext
;
158 static const char *exe_ext
;
159 static const char *dll_ext
;
160 static const char *man_ext
;
161 static const char *crosstarget
;
162 static const char *crossdebug
;
163 static const char *fontforge
;
164 static const char *convert
;
165 static const char *flex
;
166 static const char *bison
;
167 static const char *ar
;
168 static const char *ranlib
;
169 static const char *rsvg
;
170 static const char *icotool
;
171 static const char *dlltool
;
172 static const char *msgfmt
;
173 static const char *ln_s
;
174 static const char *sed_cmd
;
175 static const char *delay_load_flag
;
179 /* values determined from input makefile */
180 struct strarray vars
;
181 struct strarray include_paths
;
182 struct strarray include_args
;
183 struct strarray define_args
;
184 struct strarray programs
;
185 struct strarray scripts
;
186 struct strarray imports
;
187 struct strarray delayimports
;
188 struct strarray extradllflags
;
189 struct strarray install_lib
;
190 struct strarray install_dev
;
191 struct strarray extra_targets
;
192 struct strarray extra_imports
;
194 struct list includes
;
197 const char *parent_dir
;
200 const char *sharedlib
;
201 const char *staticlib
;
202 const char *staticimplib
;
203 const char *importlib
;
210 /* values generated at output time */
211 struct strarray in_files
;
212 struct strarray ok_files
;
213 struct strarray pot_files
;
214 struct strarray clean_files
;
215 struct strarray distclean_files
;
216 struct strarray uninstall_files
;
217 struct strarray object_files
;
218 struct strarray crossobj_files
;
219 struct strarray unixobj_files
;
220 struct strarray res_files
;
221 struct strarray font_files
;
222 struct strarray c2man_files
;
223 struct strarray debug_files
;
224 struct strarray dlldata_files
;
225 struct strarray implib_objs
;
226 struct strarray all_targets
;
227 struct strarray phony_targets
;
228 struct strarray dependencies
;
229 struct strarray install_rules
[NB_INSTALL_RULES
];
232 static struct makefile
*top_makefile
;
233 static struct makefile
**submakes
;
235 static const char separator
[] = "### Dependencies";
236 static const char *output_makefile_name
= "Makefile";
237 static const char *input_file_name
;
238 static const char *output_file_name
;
239 static const char *temp_file_name
;
240 static int relative_dir_mode
;
241 static int input_line
;
242 static int output_column
;
243 static FILE *output_file
;
245 static const char Usage
[] =
246 "Usage: makedep [options] [directories]\n"
248 " -R from to Compute the relative path between two directories\n"
249 " -fxxx Store output in file 'xxx' (default: Makefile)\n";
253 #define __attribute__(x)
256 static void fatal_error( const char *msg
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
257 static void fatal_perror( const char *msg
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
258 static void output( const char *format
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
259 static char *strmake( const char* fmt
, ... ) __attribute__ ((__format__ (__printf__
, 1, 2)));
261 /*******************************************************************
264 static void fatal_error( const char *msg
, ... )
267 va_start( valist
, msg
);
270 fprintf( stderr
, "%s:", input_file_name
);
271 if (input_line
) fprintf( stderr
, "%d:", input_line
);
272 fprintf( stderr
, " error: " );
274 else fprintf( stderr
, "makedep: error: " );
275 vfprintf( stderr
, msg
, valist
);
281 /*******************************************************************
284 static void fatal_perror( const char *msg
, ... )
287 va_start( valist
, msg
);
290 fprintf( stderr
, "%s:", input_file_name
);
291 if (input_line
) fprintf( stderr
, "%d:", input_line
);
292 fprintf( stderr
, " error: " );
294 else fprintf( stderr
, "makedep: error: " );
295 vfprintf( stderr
, msg
, valist
);
302 /*******************************************************************
305 static void cleanup_files(void)
307 if (temp_file_name
) unlink( temp_file_name
);
308 if (output_file_name
) unlink( output_file_name
);
312 /*******************************************************************
315 static void exit_on_signal( int sig
)
317 exit( 1 ); /* this will call the atexit functions */
321 /*******************************************************************
324 static void *xmalloc( size_t size
)
327 if (!(res
= malloc (size
? size
: 1)))
328 fatal_error( "Virtual memory exhausted.\n" );
333 /*******************************************************************
336 static void *xrealloc (void *ptr
, size_t size
)
340 if (!(res
= realloc( ptr
, size
)))
341 fatal_error( "Virtual memory exhausted.\n" );
345 /*******************************************************************
348 static char *xstrdup( const char *str
)
350 char *res
= strdup( str
);
351 if (!res
) fatal_error( "Virtual memory exhausted.\n" );
356 /*******************************************************************
359 static char *strmake( const char* fmt
, ... )
367 char *p
= xmalloc (size
);
369 n
= vsnprintf (p
, size
, fmt
, ap
);
371 if (n
== -1) size
*= 2;
372 else if ((size_t)n
>= size
) size
= n
+ 1;
373 else return xrealloc( p
, n
+ 1 );
379 /*******************************************************************
382 static int strendswith( const char* str
, const char* end
)
384 size_t l
= strlen( str
);
385 size_t m
= strlen( end
);
387 return l
>= m
&& strcmp(str
+ l
- m
, end
) == 0;
391 /*******************************************************************
394 static void output( const char *format
, ... )
399 va_start( valist
, format
);
400 ret
= vfprintf( output_file
, format
, valist
);
402 if (ret
< 0) fatal_perror( "output" );
403 if (format
[0] && format
[strlen(format
) - 1] == '\n') output_column
= 0;
404 else output_column
+= ret
;
408 /*******************************************************************
411 static void strarray_add( struct strarray
*array
, const char *str
)
413 if (array
->count
== array
->size
)
415 if (array
->size
) array
->size
*= 2;
416 else array
->size
= 16;
417 array
->str
= xrealloc( array
->str
, sizeof(array
->str
[0]) * array
->size
);
419 array
->str
[array
->count
++] = str
;
423 /*******************************************************************
426 static void strarray_addall( struct strarray
*array
, struct strarray added
)
430 for (i
= 0; i
< added
.count
; i
++) strarray_add( array
, added
.str
[i
] );
434 /*******************************************************************
437 static int strarray_exists( const struct strarray
*array
, const char *str
)
441 for (i
= 0; i
< array
->count
; i
++) if (!strcmp( array
->str
[i
], str
)) return 1;
446 /*******************************************************************
449 static void strarray_add_uniq( struct strarray
*array
, const char *str
)
451 if (!strarray_exists( array
, str
)) strarray_add( array
, str
);
455 /*******************************************************************
456 * strarray_addall_uniq
458 static void strarray_addall_uniq( struct strarray
*array
, struct strarray added
)
462 for (i
= 0; i
< added
.count
; i
++) strarray_add_uniq( array
, added
.str
[i
] );
466 /*******************************************************************
469 * Find a value in a name/value pair string array.
471 static const char *strarray_get_value( const struct strarray
*array
, const char *name
)
473 int pos
, res
, min
= 0, max
= array
->count
/ 2 - 1;
477 pos
= (min
+ max
) / 2;
478 if (!(res
= strcmp( array
->str
[pos
* 2], name
))) return array
->str
[pos
* 2 + 1];
479 if (res
< 0) min
= pos
+ 1;
486 /*******************************************************************
489 * Define a value in a name/value pair string array.
491 static void strarray_set_value( struct strarray
*array
, const char *name
, const char *value
)
493 int i
, pos
, res
, min
= 0, max
= array
->count
/ 2 - 1;
497 pos
= (min
+ max
) / 2;
498 if (!(res
= strcmp( array
->str
[pos
* 2], name
)))
500 /* redefining a variable replaces the previous value */
501 array
->str
[pos
* 2 + 1] = value
;
504 if (res
< 0) min
= pos
+ 1;
507 strarray_add( array
, NULL
);
508 strarray_add( array
, NULL
);
509 for (i
= array
->count
- 1; i
> min
* 2 + 1; i
--) array
->str
[i
] = array
->str
[i
- 2];
510 array
->str
[min
* 2] = name
;
511 array
->str
[min
* 2 + 1] = value
;
515 /*******************************************************************
518 static void strarray_qsort( struct strarray
*array
, int (*func
)(const char **, const char **) )
520 if (array
->count
) qsort( array
->str
, array
->count
, sizeof(*array
->str
), (void *)func
);
524 /*******************************************************************
527 static void output_filename( const char *name
)
529 if (output_column
+ strlen(name
) + 1 > 100)
534 else if (output_column
) output( " " );
535 output( "%s", name
);
539 /*******************************************************************
542 static void output_filenames( struct strarray array
)
546 for (i
= 0; i
< array
.count
; i
++) output_filename( array
.str
[i
] );
550 /*******************************************************************
551 * output_rm_filenames
553 static void output_rm_filenames( struct strarray array
)
555 static const unsigned int max_cmdline
= 30000; /* to be on the safe side */
558 if (!array
.count
) return;
560 for (i
= len
= 0; i
< array
.count
; i
++)
562 if (len
> max_cmdline
)
568 output_filename( array
.str
[i
] );
569 len
+= strlen( array
.str
[i
] ) + 1;
575 /*******************************************************************
578 static char *get_extension( char *filename
)
580 char *ext
= strrchr( filename
, '.' );
581 if (ext
&& strchr( ext
, '/' )) ext
= NULL
;
586 /*******************************************************************
589 static const char *get_base_name( const char *name
)
592 if (!strchr( name
, '.' )) return name
;
593 base
= strdup( name
);
594 *strrchr( base
, '.' ) = 0;
599 /*******************************************************************
602 static char *replace_extension( const char *name
, const char *old_ext
, const char *new_ext
)
605 size_t name_len
= strlen( name
);
606 size_t ext_len
= strlen( old_ext
);
608 if (name_len
>= ext_len
&& !strcmp( name
+ name_len
- ext_len
, old_ext
)) name_len
-= ext_len
;
609 ret
= xmalloc( name_len
+ strlen( new_ext
) + 1 );
610 memcpy( ret
, name
, name_len
);
611 strcpy( ret
+ name_len
, new_ext
);
616 /*******************************************************************
619 static char *replace_filename( const char *path
, const char *name
)
625 if (!path
) return xstrdup( name
);
626 if (!(p
= strrchr( path
, '/' ))) return xstrdup( name
);
628 ret
= xmalloc( len
+ strlen( name
) + 1 );
629 memcpy( ret
, path
, len
);
630 strcpy( ret
+ len
, name
);
635 /*******************************************************************
636 * strarray_replace_extension
638 static struct strarray
strarray_replace_extension( const struct strarray
*array
,
639 const char *old_ext
, const char *new_ext
)
644 ret
.count
= ret
.size
= array
->count
;
645 ret
.str
= xmalloc( sizeof(ret
.str
[0]) * ret
.size
);
646 for (i
= 0; i
< array
->count
; i
++) ret
.str
[i
] = replace_extension( array
->str
[i
], old_ext
, new_ext
);
651 /*******************************************************************
654 static char *replace_substr( const char *str
, const char *start
, size_t len
, const char *replace
)
656 size_t pos
= start
- str
;
657 char *ret
= xmalloc( pos
+ strlen(replace
) + strlen(start
+ len
) + 1 );
658 memcpy( ret
, str
, pos
);
659 strcpy( ret
+ pos
, replace
);
660 strcat( ret
+ pos
, start
+ len
);
665 /*******************************************************************
668 * Determine where the destination path is located relative to the 'from' path.
670 static char *get_relative_path( const char *from
, const char *dest
)
674 unsigned int dotdots
= 0;
676 /* a path of "." is equivalent to an empty path */
677 if (!strcmp( from
, "." )) from
= "";
681 while (*from
== '/') from
++;
682 while (*dest
== '/') dest
++;
683 start
= dest
; /* save start of next path element */
686 while (*from
&& *from
!= '/' && *from
== *dest
) { from
++; dest
++; }
687 if ((!*from
|| *from
== '/') && (!*dest
|| *dest
== '/')) continue;
689 /* count remaining elements in 'from' */
693 while (*from
&& *from
!= '/') from
++;
694 while (*from
== '/') from
++;
700 if (!start
[0] && !dotdots
) return NULL
; /* empty path */
702 ret
= xmalloc( 3 * dotdots
+ strlen( start
) + 1 );
703 for (p
= ret
; dotdots
; dotdots
--, p
+= 3) memcpy( p
, "../", 3 );
705 if (start
[0]) strcpy( p
, start
);
706 else p
[-1] = 0; /* remove trailing slash */
711 /*******************************************************************
714 static char *concat_paths( const char *base
, const char *path
)
719 if (!base
|| !base
[0]) return xstrdup( path
&& path
[0] ? path
: "." );
720 if (!path
|| !path
[0]) return xstrdup( base
);
721 if (path
[0] == '/') return xstrdup( path
);
723 len
= strlen( base
);
724 while (len
&& base
[len
- 1] == '/') len
--;
725 while (len
&& !strncmp( path
, "..", 2 ) && (!path
[2] || path
[2] == '/'))
727 for (i
= len
; i
> 0; i
--) if (base
[i
- 1] == '/') break;
728 if (i
== len
- 2 && !memcmp( base
+ i
, "..", 2 )) break; /* we can't go up if we already have ".." */
729 if (i
!= len
- 1 || base
[i
] != '.')
732 while (*path
== '/') path
++;
734 /* else ignore "." element */
735 while (i
> 0 && base
[i
- 1] == '/') i
--;
738 if (!len
&& base
[0] != '/') return xstrdup( path
[0] ? path
: "." );
739 ret
= xmalloc( len
+ strlen( path
) + 2 );
740 memcpy( ret
, base
, len
);
742 strcpy( ret
+ len
, path
);
747 /*******************************************************************
750 static char *obj_dir_path( const struct makefile
*make
, const char *path
)
752 return concat_paths( make
->obj_dir
, path
);
756 /*******************************************************************
759 static char *src_dir_path( const struct makefile
*make
, const char *path
)
761 if (make
->src_dir
) return concat_paths( make
->src_dir
, path
);
762 return obj_dir_path( make
, path
);
766 /*******************************************************************
769 static char *root_src_dir_path( const char *path
)
771 return concat_paths( root_src_dir
, path
);
775 /*******************************************************************
778 static char *tools_dir_path( const struct makefile
*make
, const char *path
)
780 if (tools_dir
) return strmake( "%s/tools/%s", tools_dir
, path
);
781 return strmake( "tools/%s", path
);
785 /*******************************************************************
788 static char *tools_path( const struct makefile
*make
, const char *name
)
790 return strmake( "%s/%s%s", tools_dir_path( make
, name
), name
, tools_ext
);
794 /*******************************************************************
795 * strarray_addall_path
797 static void strarray_addall_path( struct strarray
*array
, const char *dir
, struct strarray added
)
801 for (i
= 0; i
< added
.count
; i
++) strarray_add( array
, concat_paths( dir
, added
.str
[i
] ));
805 /*******************************************************************
808 static char *get_line( FILE *file
)
816 buffer
= xmalloc( size
);
818 if (!fgets( buffer
, size
, file
)) return NULL
;
823 char *p
= buffer
+ strlen(buffer
);
824 /* if line is larger than buffer, resize buffer */
825 while (p
== buffer
+ size
- 1 && p
[-1] != '\n')
827 buffer
= xrealloc( buffer
, size
* 2 );
828 if (!fgets( buffer
+ size
- 1, size
+ 1, file
)) break;
829 p
= buffer
+ strlen(buffer
);
832 if (p
> buffer
&& p
[-1] == '\n')
835 if (p
> buffer
&& p
[-1] == '\r') *(--p
) = 0;
836 if (p
> buffer
&& p
[-1] == '\\')
839 /* line ends in backslash, read continuation line */
840 if (!fgets( p
, size
- (p
- buffer
), file
)) return buffer
;
850 /*******************************************************************
853 static unsigned int hash_filename( const char *name
)
856 unsigned int ret
= 2166136261u;
857 while (*name
) ret
= (ret
* 16777619) ^ *name
++;
858 return ret
% HASH_SIZE
;
862 /*******************************************************************
865 static struct file
*add_file( const char *name
)
867 struct file
*file
= xmalloc( sizeof(*file
) );
868 memset( file
, 0, sizeof(*file
) );
869 file
->name
= xstrdup( name
);
874 /*******************************************************************
877 static void add_dependency( struct file
*file
, const char *name
, enum incl_type type
)
879 /* enforce some rules for the Wine tree */
881 if (!memcmp( name
, "../", 3 ))
882 fatal_error( "#include directive with relative path not allowed\n" );
884 if (!strcmp( name
, "config.h" ))
886 if (strendswith( file
->name
, ".h" ))
887 fatal_error( "config.h must not be included by a header file\n" );
888 if (file
->deps_count
)
889 fatal_error( "config.h must be included before anything else\n" );
891 else if (!strcmp( name
, "wine/port.h" ))
893 if (strendswith( file
->name
, ".h" ))
894 fatal_error( "wine/port.h must not be included by a header file\n" );
895 if (!file
->deps_count
) fatal_error( "config.h must be included before wine/port.h\n" );
896 if (file
->deps_count
> 1)
897 fatal_error( "wine/port.h must be included before everything except config.h\n" );
898 if (strcmp( file
->deps
[0].name
, "config.h" ))
899 fatal_error( "config.h must be included before wine/port.h\n" );
902 if (file
->deps_count
>= file
->deps_size
)
904 file
->deps_size
*= 2;
905 if (file
->deps_size
< 16) file
->deps_size
= 16;
906 file
->deps
= xrealloc( file
->deps
, file
->deps_size
* sizeof(*file
->deps
) );
908 file
->deps
[file
->deps_count
].line
= input_line
;
909 file
->deps
[file
->deps_count
].type
= type
;
910 file
->deps
[file
->deps_count
].name
= xstrdup( name
);
915 /*******************************************************************
918 static struct incl_file
*find_src_file( const struct makefile
*make
, const char *name
)
920 struct incl_file
*file
;
922 LIST_FOR_EACH_ENTRY( file
, &make
->sources
, struct incl_file
, entry
)
923 if (!strcmp( name
, file
->name
)) return file
;
927 /*******************************************************************
930 static struct incl_file
*find_include_file( const struct makefile
*make
, const char *name
)
932 struct incl_file
*file
;
934 LIST_FOR_EACH_ENTRY( file
, &make
->includes
, struct incl_file
, entry
)
935 if (!strcmp( name
, file
->name
)) return file
;
939 /*******************************************************************
942 * Add an include file if it doesn't already exists.
944 static struct incl_file
*add_include( struct makefile
*make
, struct incl_file
*parent
,
945 const char *name
, int line
, enum incl_type type
)
947 struct incl_file
*include
;
949 if (parent
->files_count
>= parent
->files_size
)
951 parent
->files_size
*= 2;
952 if (parent
->files_size
< 16) parent
->files_size
= 16;
953 parent
->files
= xrealloc( parent
->files
, parent
->files_size
* sizeof(*parent
->files
) );
956 LIST_FOR_EACH_ENTRY( include
, &make
->includes
, struct incl_file
, entry
)
957 if (!parent
->use_msvcrt
== !include
->use_msvcrt
&& !strcmp( name
, include
->name
))
960 include
= xmalloc( sizeof(*include
) );
961 memset( include
, 0, sizeof(*include
) );
962 include
->name
= xstrdup(name
);
963 include
->included_by
= parent
;
964 include
->included_line
= line
;
965 include
->type
= type
;
966 include
->use_msvcrt
= parent
->use_msvcrt
;
967 list_add_tail( &make
->includes
, &include
->entry
);
969 parent
->files
[parent
->files_count
++] = include
;
974 /*******************************************************************
975 * add_generated_source
977 * Add a generated source file to the list.
979 static struct incl_file
*add_generated_source( struct makefile
*make
,
980 const char *name
, const char *filename
)
982 struct incl_file
*file
;
984 if ((file
= find_src_file( make
, name
))) return file
; /* we already have it */
985 file
= xmalloc( sizeof(*file
) );
986 memset( file
, 0, sizeof(*file
) );
987 file
->file
= add_file( name
);
988 file
->name
= xstrdup( name
);
989 file
->basename
= xstrdup( filename
? filename
: name
);
990 file
->filename
= obj_dir_path( make
, file
->basename
);
991 file
->file
->flags
= FLAG_GENERATED
;
992 file
->use_msvcrt
= make
->use_msvcrt
;
993 list_add_tail( &make
->sources
, &file
->entry
);
998 /*******************************************************************
999 * parse_include_directive
1001 static void parse_include_directive( struct file
*source
, char *str
)
1003 char quote
, *include
, *p
= str
;
1005 while (*p
&& isspace(*p
)) p
++;
1006 if (*p
!= '\"' && *p
!= '<' ) return;
1008 if (quote
== '<') quote
= '>';
1010 while (*p
&& (*p
!= quote
)) p
++;
1011 if (!*p
) fatal_error( "malformed include directive '%s'\n", str
);
1013 add_dependency( source
, include
, (quote
== '>') ? INCL_SYSTEM
: INCL_NORMAL
);
1017 /*******************************************************************
1018 * parse_pragma_directive
1020 static void parse_pragma_directive( struct file
*source
, char *str
)
1022 char *flag
, *p
= str
;
1024 if (!isspace( *p
)) return;
1025 while (*p
&& isspace(*p
)) p
++;
1026 p
= strtok( p
, " \t" );
1027 if (strcmp( p
, "makedep" )) return;
1029 while ((flag
= strtok( NULL
, " \t" )))
1031 if (!strcmp( flag
, "depend" ))
1033 while ((p
= strtok( NULL
, " \t" ))) add_dependency( source
, p
, INCL_NORMAL
);
1036 else if (!strcmp( flag
, "install" )) source
->flags
|= FLAG_INSTALL
;
1038 if (strendswith( source
->name
, ".idl" ))
1040 if (!strcmp( flag
, "header" )) source
->flags
|= FLAG_IDL_HEADER
;
1041 else if (!strcmp( flag
, "proxy" )) source
->flags
|= FLAG_IDL_PROXY
;
1042 else if (!strcmp( flag
, "client" )) source
->flags
|= FLAG_IDL_CLIENT
;
1043 else if (!strcmp( flag
, "server" )) source
->flags
|= FLAG_IDL_SERVER
;
1044 else if (!strcmp( flag
, "ident" )) source
->flags
|= FLAG_IDL_IDENT
;
1045 else if (!strcmp( flag
, "typelib" )) source
->flags
|= FLAG_IDL_TYPELIB
;
1046 else if (!strcmp( flag
, "register" )) source
->flags
|= FLAG_IDL_REGISTER
;
1047 else if (!strcmp( flag
, "regtypelib" )) source
->flags
|= FLAG_IDL_REGTYPELIB
;
1049 else if (strendswith( source
->name
, ".rc" ))
1051 if (!strcmp( flag
, "po" )) source
->flags
|= FLAG_RC_PO
;
1053 else if (strendswith( source
->name
, ".sfd" ))
1055 if (!strcmp( flag
, "font" ))
1057 struct strarray
*array
= source
->args
;
1061 source
->args
= array
= xmalloc( sizeof(*array
) );
1062 *array
= empty_strarray
;
1063 source
->flags
|= FLAG_SFD_FONTS
;
1065 strarray_add( array
, xstrdup( strtok( NULL
, "" )));
1071 if (!strcmp( flag
, "implib" )) source
->flags
|= FLAG_C_IMPLIB
;
1072 if (!strcmp( flag
, "unix" )) source
->flags
|= FLAG_C_UNIX
;
1078 /*******************************************************************
1079 * parse_cpp_directive
1081 static void parse_cpp_directive( struct file
*source
, char *str
)
1083 while (*str
&& isspace(*str
)) str
++;
1084 if (*str
++ != '#') return;
1085 while (*str
&& isspace(*str
)) str
++;
1087 if (!strncmp( str
, "include", 7 ))
1088 parse_include_directive( source
, str
+ 7 );
1089 else if (!strncmp( str
, "import", 6 ) && strendswith( source
->name
, ".m" ))
1090 parse_include_directive( source
, str
+ 6 );
1091 else if (!strncmp( str
, "pragma", 6 ))
1092 parse_pragma_directive( source
, str
+ 6 );
1096 /*******************************************************************
1099 static void parse_idl_file( struct file
*source
, FILE *file
)
1101 char *buffer
, *include
;
1105 while ((buffer
= get_line( file
)))
1109 while (*p
&& isspace(*p
)) p
++;
1111 if (!strncmp( p
, "importlib", 9 ))
1114 while (*p
&& isspace(*p
)) p
++;
1115 if (*p
++ != '(') continue;
1116 while (*p
&& isspace(*p
)) p
++;
1117 if (*p
++ != '"') continue;
1119 while (*p
&& (*p
!= '"')) p
++;
1120 if (!*p
) fatal_error( "malformed importlib directive\n" );
1122 add_dependency( source
, include
, INCL_IMPORTLIB
);
1126 if (!strncmp( p
, "import", 6 ))
1129 while (*p
&& isspace(*p
)) p
++;
1130 if (*p
!= '"') continue;
1132 while (*p
&& (*p
!= '"')) p
++;
1133 if (!*p
) fatal_error( "malformed import directive\n" );
1135 add_dependency( source
, include
, INCL_IMPORT
);
1139 /* check for #include inside cpp_quote */
1140 if (!strncmp( p
, "cpp_quote", 9 ))
1143 while (*p
&& isspace(*p
)) p
++;
1144 if (*p
++ != '(') continue;
1145 while (*p
&& isspace(*p
)) p
++;
1146 if (*p
++ != '"') continue;
1147 if (*p
++ != '#') continue;
1148 while (*p
&& isspace(*p
)) p
++;
1149 if (strncmp( p
, "include", 7 )) continue;
1151 while (*p
&& isspace(*p
)) p
++;
1152 if (*p
== '\\' && p
[1] == '"')
1159 if (*p
++ != '<' ) continue;
1163 while (*p
&& (*p
!= quote
)) p
++;
1164 if (!*p
|| (quote
== '"' && p
[-1] != '\\'))
1165 fatal_error( "malformed #include directive inside cpp_quote\n" );
1166 if (quote
== '"') p
--; /* remove backslash */
1168 add_dependency( source
, include
, (quote
== '>') ? INCL_CPP_QUOTE_SYSTEM
: INCL_CPP_QUOTE
);
1172 parse_cpp_directive( source
, p
);
1176 /*******************************************************************
1179 static void parse_c_file( struct file
*source
, FILE *file
)
1184 while ((buffer
= get_line( file
)))
1186 parse_cpp_directive( source
, buffer
);
1191 /*******************************************************************
1194 static void parse_rc_file( struct file
*source
, FILE *file
)
1196 char *buffer
, *include
;
1199 while ((buffer
= get_line( file
)))
1203 while (*p
&& isspace(*p
)) p
++;
1205 if (p
[0] == '/' && p
[1] == '*') /* check for magic makedep comment */
1208 while (*p
&& isspace(*p
)) p
++;
1209 if (strncmp( p
, "@makedep:", 9 )) continue;
1211 while (*p
&& isspace(*p
)) p
++;
1216 while (*p
&& *p
!= quote
) p
++;
1221 while (*p
&& !isspace(*p
) && *p
!= '*') p
++;
1224 fatal_error( "malformed makedep comment\n" );
1226 add_dependency( source
, include
, (quote
== '>') ? INCL_SYSTEM
: INCL_NORMAL
);
1230 parse_cpp_directive( source
, buffer
);
1235 /*******************************************************************
1238 static void parse_in_file( struct file
*source
, FILE *file
)
1242 /* make sure it gets rebuilt when the version changes */
1243 add_dependency( source
, "config.h", INCL_SYSTEM
);
1245 if (!strendswith( source
->name
, ".man.in" )) return; /* not a man page */
1248 while ((buffer
= get_line( file
)))
1250 if (strncmp( buffer
, ".TH", 3 )) continue;
1251 if (!(p
= strtok( buffer
, " \t" ))) continue; /* .TH */
1252 if (!(p
= strtok( NULL
, " \t" ))) continue; /* program name */
1253 if (!(p
= strtok( NULL
, " \t" ))) continue; /* man section */
1254 source
->args
= xstrdup( p
);
1260 /*******************************************************************
1263 static void parse_sfd_file( struct file
*source
, FILE *file
)
1265 char *p
, *eol
, *buffer
;
1268 while ((buffer
= get_line( file
)))
1270 if (strncmp( buffer
, "UComments:", 10 )) continue;
1272 while (*p
== ' ') p
++;
1273 if (p
[0] == '"' && p
[1] && buffer
[strlen(buffer
) - 1] == '"')
1276 buffer
[strlen(buffer
) - 1] = 0;
1278 while ((eol
= strstr( p
, "+AAoA" )))
1281 while (*p
&& isspace(*p
)) p
++;
1284 while (*p
&& isspace(*p
)) p
++;
1285 if (!strncmp( p
, "pragma", 6 )) parse_pragma_directive( source
, p
+ 6 );
1289 while (*p
&& isspace(*p
)) p
++;
1290 if (*p
++ != '#') return;
1291 while (*p
&& isspace(*p
)) p
++;
1292 if (!strncmp( p
, "pragma", 6 )) parse_pragma_directive( source
, p
+ 6 );
1301 void (*parse
)( struct file
*file
, FILE *f
);
1302 } parse_functions
[] =
1304 { ".c", parse_c_file
},
1305 { ".h", parse_c_file
},
1306 { ".inl", parse_c_file
},
1307 { ".l", parse_c_file
},
1308 { ".m", parse_c_file
},
1309 { ".rh", parse_c_file
},
1310 { ".x", parse_c_file
},
1311 { ".y", parse_c_file
},
1312 { ".idl", parse_idl_file
},
1313 { ".rc", parse_rc_file
},
1314 { ".in", parse_in_file
},
1315 { ".sfd", parse_sfd_file
}
1318 /*******************************************************************
1321 static struct file
*load_file( const char *name
)
1325 unsigned int i
, hash
= hash_filename( name
);
1327 LIST_FOR_EACH_ENTRY( file
, &files
[hash
], struct file
, entry
)
1328 if (!strcmp( name
, file
->name
)) return file
;
1330 if (!(f
= fopen( name
, "r" ))) return NULL
;
1332 file
= add_file( name
);
1333 list_add_tail( &files
[hash
], &file
->entry
);
1334 input_file_name
= file
->name
;
1337 for (i
= 0; i
< sizeof(parse_functions
) / sizeof(parse_functions
[0]); i
++)
1339 if (!strendswith( name
, parse_functions
[i
].ext
)) continue;
1340 parse_functions
[i
].parse( file
, f
);
1345 input_file_name
= NULL
;
1351 /*******************************************************************
1352 * open_include_path_file
1354 * Open a file from a directory on the include path.
1356 static struct file
*open_include_path_file( const struct makefile
*make
, const char *dir
,
1357 const char *name
, char **filename
)
1359 char *src_path
= concat_paths( dir
, name
);
1360 struct file
*ret
= load_file( src_path
);
1362 if (ret
) *filename
= src_path
;
1367 /*******************************************************************
1368 * open_file_same_dir
1370 * Open a file in the same directory as the parent.
1372 static struct file
*open_file_same_dir( const struct incl_file
*parent
, const char *name
, char **filename
)
1374 char *src_path
= replace_filename( parent
->file
->name
, name
);
1375 struct file
*ret
= load_file( src_path
);
1377 if (ret
) *filename
= replace_filename( parent
->filename
, name
);
1382 /*******************************************************************
1385 * Open a file in the source directory of the makefile.
1387 static struct file
*open_local_file( const struct makefile
*make
, const char *path
, char **filename
)
1389 char *src_path
= src_dir_path( make
, path
);
1390 struct file
*ret
= load_file( src_path
);
1392 /* if not found, try parent dir */
1393 if (!ret
&& make
->parent_dir
)
1396 path
= strmake( "%s/%s", make
->parent_dir
, path
);
1397 src_path
= src_dir_path( make
, path
);
1398 ret
= load_file( src_path
);
1401 if (ret
) *filename
= src_path
;
1406 /*******************************************************************
1409 * Open a file in the top-level source directory.
1411 static struct file
*open_global_file( const struct makefile
*make
, const char *path
, char **filename
)
1413 char *src_path
= root_src_dir_path( path
);
1414 struct file
*ret
= load_file( src_path
);
1416 if (ret
) *filename
= src_path
;
1421 /*******************************************************************
1422 * open_global_header
1424 * Open a file in the global include source directory.
1426 static struct file
*open_global_header( const struct makefile
*make
, const char *path
, char **filename
)
1428 return open_global_file( make
, strmake( "include/%s", path
), filename
);
1432 /*******************************************************************
1435 static struct file
*open_src_file( const struct makefile
*make
, struct incl_file
*pFile
)
1437 struct file
*file
= open_local_file( make
, pFile
->name
, &pFile
->filename
);
1439 if (!file
) fatal_perror( "open %s", pFile
->name
);
1444 /*******************************************************************
1447 static struct file
*open_include_file( const struct makefile
*make
, struct incl_file
*pFile
)
1449 struct file
*file
= NULL
;
1451 unsigned int i
, len
;
1455 /* check for generated bison header */
1457 if (strendswith( pFile
->name
, ".tab.h" ) &&
1458 (file
= open_local_file( make
, replace_extension( pFile
->name
, ".tab.h", ".y" ), &filename
)))
1460 pFile
->sourcename
= filename
;
1461 pFile
->filename
= obj_dir_path( make
, pFile
->name
);
1465 /* check for corresponding idl file in source dir */
1467 if (strendswith( pFile
->name
, ".h" ) &&
1468 (file
= open_local_file( make
, replace_extension( pFile
->name
, ".h", ".idl" ), &filename
)))
1470 pFile
->sourcename
= filename
;
1471 pFile
->filename
= obj_dir_path( make
, pFile
->name
);
1475 /* check for corresponding tlb file in source dir */
1477 if (strendswith( pFile
->name
, ".tlb" ) &&
1478 (file
= open_local_file( make
, replace_extension( pFile
->name
, ".tlb", ".idl" ), &filename
)))
1480 pFile
->sourcename
= filename
;
1481 pFile
->filename
= obj_dir_path( make
, pFile
->name
);
1485 /* check for extra targets */
1486 if (strarray_exists( &make
->extra_targets
, pFile
->name
))
1488 pFile
->sourcename
= src_dir_path( make
, pFile
->name
);
1489 pFile
->filename
= obj_dir_path( make
, pFile
->name
);
1493 /* now try in source dir */
1494 if ((file
= open_local_file( make
, pFile
->name
, &pFile
->filename
))) return file
;
1496 /* check for corresponding idl file in global includes */
1498 if (strendswith( pFile
->name
, ".h" ) &&
1499 (file
= open_global_header( make
, replace_extension( pFile
->name
, ".h", ".idl" ), &filename
)))
1501 pFile
->sourcename
= filename
;
1502 pFile
->filename
= strmake( "include/%s", pFile
->name
);
1506 /* check for corresponding .in file in global includes (for config.h.in) */
1508 if (strendswith( pFile
->name
, ".h" ) &&
1509 (file
= open_global_header( make
, replace_extension( pFile
->name
, ".h", ".h.in" ), &filename
)))
1511 pFile
->sourcename
= filename
;
1512 pFile
->filename
= strmake( "include/%s", pFile
->name
);
1516 /* check for corresponding .x file in global includes */
1518 if (strendswith( pFile
->name
, "tmpl.h" ) &&
1519 (file
= open_global_header( make
, replace_extension( pFile
->name
, ".h", ".x" ), &filename
)))
1521 pFile
->sourcename
= filename
;
1522 pFile
->filename
= strmake( "include/%s", pFile
->name
);
1526 /* check for corresponding .tlb file in global includes */
1528 if (strendswith( pFile
->name
, ".tlb" ) &&
1529 (file
= open_global_header( make
, replace_extension( pFile
->name
, ".tlb", ".idl" ), &filename
)))
1531 pFile
->sourcename
= filename
;
1532 pFile
->filename
= strmake( "include/%s", pFile
->name
);
1536 /* check in global includes source dir */
1538 if ((file
= open_global_header( make
, pFile
->name
, &pFile
->filename
))) return file
;
1540 /* check in global msvcrt includes */
1541 if (pFile
->use_msvcrt
&&
1542 (file
= open_global_header( make
, strmake( "msvcrt/%s", pFile
->name
), &pFile
->filename
)))
1545 /* now search in include paths */
1546 for (i
= 0; i
< make
->include_paths
.count
; i
++)
1548 const char *dir
= make
->include_paths
.str
[i
];
1552 len
= strlen( root_src_dir
);
1553 if (!strncmp( dir
, root_src_dir
, len
) && (!dir
[len
] || dir
[len
] == '/'))
1555 while (dir
[len
] == '/') len
++;
1556 file
= open_global_file( make
, concat_paths( dir
+ len
, pFile
->name
), &pFile
->filename
);
1557 if (file
) return file
;
1559 continue; /* ignore paths that don't point to the top source dir */
1563 if ((file
= open_include_path_file( make
, dir
, pFile
->name
, &pFile
->filename
)))
1568 if (pFile
->type
== INCL_SYSTEM
&& pFile
->use_msvcrt
)
1570 if (!strcmp( pFile
->name
, "stdarg.h" )) return NULL
;
1571 fprintf( stderr
, "%s:%d: error: system header %s cannot be used with msvcrt\n",
1572 pFile
->included_by
->file
->name
, pFile
->included_line
, pFile
->name
);
1576 if (pFile
->type
== INCL_SYSTEM
) return NULL
; /* ignore system files we cannot find */
1578 /* try in src file directory */
1579 if ((file
= open_file_same_dir( pFile
->included_by
, pFile
->name
, &pFile
->filename
))) return file
;
1581 fprintf( stderr
, "%s:%d: error: ", pFile
->included_by
->file
->name
, pFile
->included_line
);
1582 perror( pFile
->name
);
1583 pFile
= pFile
->included_by
;
1584 while (pFile
&& pFile
->included_by
)
1586 const char *parent
= pFile
->included_by
->sourcename
;
1587 if (!parent
) parent
= pFile
->included_by
->file
->name
;
1588 fprintf( stderr
, "%s:%d: note: %s was first included here\n",
1589 parent
, pFile
->included_line
, pFile
->name
);
1590 pFile
= pFile
->included_by
;
1596 /*******************************************************************
1599 static void add_all_includes( struct makefile
*make
, struct incl_file
*parent
, struct file
*file
)
1603 parent
->files_count
= 0;
1604 parent
->files_size
= file
->deps_count
;
1605 parent
->files
= xmalloc( parent
->files_size
* sizeof(*parent
->files
) );
1606 for (i
= 0; i
< file
->deps_count
; i
++)
1608 switch (file
->deps
[i
].type
)
1612 add_include( make
, parent
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_NORMAL
);
1614 case INCL_IMPORTLIB
:
1615 add_include( make
, parent
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_IMPORTLIB
);
1618 add_include( make
, parent
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_SYSTEM
);
1620 case INCL_CPP_QUOTE
:
1621 case INCL_CPP_QUOTE_SYSTEM
:
1628 /*******************************************************************
1631 static void parse_file( struct makefile
*make
, struct incl_file
*source
, int src
)
1633 struct file
*file
= src
? open_src_file( make
, source
) : open_include_file( make
, source
);
1637 source
->file
= file
;
1638 source
->files_count
= 0;
1639 source
->files_size
= file
->deps_count
;
1640 source
->files
= xmalloc( source
->files_size
* sizeof(*source
->files
) );
1641 if (file
->flags
& FLAG_C_UNIX
) source
->use_msvcrt
= 0;
1642 else if (file
->flags
& FLAG_C_IMPLIB
) source
->use_msvcrt
= 1;
1644 if (source
->sourcename
)
1646 if (strendswith( source
->sourcename
, ".idl" ))
1650 if (strendswith( source
->name
, ".tlb" )) return; /* typelibs don't include anything */
1652 /* generated .h file always includes these */
1653 add_include( make
, source
, "rpc.h", 0, INCL_NORMAL
);
1654 add_include( make
, source
, "rpcndr.h", 0, INCL_NORMAL
);
1655 for (i
= 0; i
< file
->deps_count
; i
++)
1657 switch (file
->deps
[i
].type
)
1660 if (strendswith( file
->deps
[i
].name
, ".idl" ))
1661 add_include( make
, source
, replace_extension( file
->deps
[i
].name
, ".idl", ".h" ),
1662 file
->deps
[i
].line
, INCL_NORMAL
);
1664 add_include( make
, source
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_NORMAL
);
1666 case INCL_CPP_QUOTE
:
1667 add_include( make
, source
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_NORMAL
);
1669 case INCL_CPP_QUOTE_SYSTEM
:
1670 add_include( make
, source
, file
->deps
[i
].name
, file
->deps
[i
].line
, INCL_SYSTEM
);
1674 case INCL_IMPORTLIB
:
1680 if (strendswith( source
->sourcename
, ".y" ))
1681 return; /* generated .tab.h doesn't include anything */
1684 add_all_includes( make
, source
, file
);
1688 /*******************************************************************
1691 * Add a source file to the list.
1693 static struct incl_file
*add_src_file( struct makefile
*make
, const char *name
)
1695 struct incl_file
*file
;
1697 if ((file
= find_src_file( make
, name
))) return file
; /* we already have it */
1698 file
= xmalloc( sizeof(*file
) );
1699 memset( file
, 0, sizeof(*file
) );
1700 file
->name
= xstrdup(name
);
1701 file
->use_msvcrt
= make
->use_msvcrt
;
1702 list_add_tail( &make
->sources
, &file
->entry
);
1703 parse_file( make
, file
, 1 );
1708 /*******************************************************************
1709 * open_input_makefile
1711 static FILE *open_input_makefile( const struct makefile
*make
)
1716 input_file_name
= root_src_dir_path( obj_dir_path( make
, strmake( "%s.in", output_makefile_name
)));
1718 input_file_name
= output_makefile_name
; /* always use output name for main Makefile */
1721 if (!(ret
= fopen( input_file_name
, "r" ))) fatal_perror( "open" );
1726 /*******************************************************************
1729 static const char *get_make_variable( const struct makefile
*make
, const char *name
)
1733 if ((ret
= strarray_get_value( &cmdline_vars
, name
))) return ret
;
1734 if ((ret
= strarray_get_value( &make
->vars
, name
))) return ret
;
1735 if (top_makefile
&& (ret
= strarray_get_value( &top_makefile
->vars
, name
))) return ret
;
1740 /*******************************************************************
1741 * get_expanded_make_variable
1743 static char *get_expanded_make_variable( const struct makefile
*make
, const char *name
)
1746 char *p
, *end
, *expand
, *tmp
;
1748 var
= get_make_variable( make
, name
);
1749 if (!var
) return NULL
;
1751 p
= expand
= xstrdup( var
);
1752 while ((p
= strchr( p
, '$' )))
1756 if (!(end
= strchr( p
+ 2, ')' ))) fatal_error( "syntax error in '%s'\n", expand
);
1758 if (strchr( p
+ 2, ':' )) fatal_error( "pattern replacement not supported for '%s'\n", p
+ 2 );
1759 var
= get_make_variable( make
, p
+ 2 );
1760 tmp
= replace_substr( expand
, p
, end
- p
, var
? var
: "" );
1761 /* switch to the new string */
1762 p
= tmp
+ (p
- expand
);
1766 else if (p
[1] == '{') /* don't expand ${} variables */
1768 if (!(end
= strchr( p
+ 2, '}' ))) fatal_error( "syntax error in '%s'\n", expand
);
1771 else if (p
[1] == '$')
1775 else fatal_error( "syntax error in '%s'\n", expand
);
1778 /* consider empty variables undefined */
1780 while (*p
&& isspace(*p
)) p
++;
1781 if (*p
) return expand
;
1787 /*******************************************************************
1788 * get_expanded_make_var_array
1790 static struct strarray
get_expanded_make_var_array( const struct makefile
*make
, const char *name
)
1792 struct strarray ret
= empty_strarray
;
1793 char *value
, *token
;
1795 if ((value
= get_expanded_make_variable( make
, name
)))
1796 for (token
= strtok( value
, " \t" ); token
; token
= strtok( NULL
, " \t" ))
1797 strarray_add( &ret
, token
);
1802 /*******************************************************************
1803 * get_expanded_file_local_var
1805 static struct strarray
get_expanded_file_local_var( const struct makefile
*make
, const char *file
,
1808 char *p
, *var
= strmake( "%s_%s", file
, name
);
1810 for (p
= var
; *p
; p
++) if (!isalnum( *p
)) *p
= '_';
1811 return get_expanded_make_var_array( make
, var
);
1815 /*******************************************************************
1818 static int set_make_variable( struct strarray
*array
, const char *assignment
)
1822 p
= name
= xstrdup( assignment
);
1823 while (isalnum(*p
) || *p
== '_') p
++;
1824 if (name
== p
) return 0; /* not a variable */
1828 while (isspace(*p
)) p
++;
1830 if (*p
!= '=') return 0; /* not an assignment */
1832 while (isspace(*p
)) p
++;
1834 strarray_set_value( array
, name
, p
);
1839 /*******************************************************************
1842 static struct makefile
*parse_makefile( const char *path
)
1846 struct makefile
*make
= xmalloc( sizeof(*make
) );
1848 memset( make
, 0, sizeof(*make
) );
1849 make
->obj_dir
= path
;
1850 if (root_src_dir
) make
->src_dir
= root_src_dir_path( make
->obj_dir
);
1852 file
= open_input_makefile( make
);
1853 while ((buffer
= get_line( file
)))
1855 if (!strncmp( buffer
, separator
, strlen(separator
) )) break;
1856 if (*buffer
== '\t') continue; /* command */
1857 while (isspace( *buffer
)) buffer
++;
1858 if (*buffer
== '#') continue; /* comment */
1859 set_make_variable( &make
->vars
, buffer
);
1862 input_file_name
= NULL
;
1867 /*******************************************************************
1868 * add_generated_sources
1870 static void add_generated_sources( struct makefile
*make
)
1873 struct incl_file
*source
, *next
, *file
;
1874 struct strarray objs
= get_expanded_make_var_array( make
, "EXTRA_OBJS" );
1876 LIST_FOR_EACH_ENTRY_SAFE( source
, next
, &make
->sources
, struct incl_file
, entry
)
1878 if (source
->file
->flags
& FLAG_IDL_CLIENT
)
1880 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_c.c" ), NULL
);
1881 add_dependency( file
->file
, replace_extension( source
->name
, ".idl", ".h" ), INCL_NORMAL
);
1882 add_all_includes( make
, file
, file
->file
);
1884 if (source
->file
->flags
& FLAG_IDL_SERVER
)
1886 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_s.c" ), NULL
);
1887 add_dependency( file
->file
, "wine/exception.h", INCL_NORMAL
);
1888 add_dependency( file
->file
, replace_extension( source
->name
, ".idl", ".h" ), INCL_NORMAL
);
1889 add_all_includes( make
, file
, file
->file
);
1891 if (source
->file
->flags
& FLAG_IDL_IDENT
)
1893 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_i.c" ), NULL
);
1894 add_dependency( file
->file
, "rpc.h", INCL_NORMAL
);
1895 add_dependency( file
->file
, "rpcndr.h", INCL_NORMAL
);
1896 add_dependency( file
->file
, "guiddef.h", INCL_NORMAL
);
1897 add_all_includes( make
, file
, file
->file
);
1899 if (source
->file
->flags
& FLAG_IDL_PROXY
)
1901 file
= add_generated_source( make
, "dlldata.o", "dlldata.c" );
1902 add_dependency( file
->file
, "objbase.h", INCL_NORMAL
);
1903 add_dependency( file
->file
, "rpcproxy.h", INCL_NORMAL
);
1904 add_all_includes( make
, file
, file
->file
);
1905 file
= add_generated_source( make
, replace_extension( source
->name
, ".idl", "_p.c" ), NULL
);
1906 add_dependency( file
->file
, "objbase.h", INCL_NORMAL
);
1907 add_dependency( file
->file
, "rpcproxy.h", INCL_NORMAL
);
1908 add_dependency( file
->file
, "wine/exception.h", INCL_NORMAL
);
1909 add_dependency( file
->file
, replace_extension( source
->name
, ".idl", ".h" ), INCL_NORMAL
);
1910 add_all_includes( make
, file
, file
->file
);
1912 if (source
->file
->flags
& FLAG_IDL_TYPELIB
)
1914 add_generated_source( make
, replace_extension( source
->name
, ".idl", ".tlb" ), NULL
);
1916 if (source
->file
->flags
& FLAG_IDL_REGTYPELIB
)
1918 add_generated_source( make
, replace_extension( source
->name
, ".idl", "_t.res" ), NULL
);
1920 if (source
->file
->flags
& FLAG_IDL_REGISTER
)
1922 add_generated_source( make
, replace_extension( source
->name
, ".idl", "_r.res" ), NULL
);
1924 if (source
->file
->flags
& FLAG_IDL_HEADER
)
1926 add_generated_source( make
, replace_extension( source
->name
, ".idl", ".h" ), NULL
);
1928 if (!source
->file
->flags
&& strendswith( source
->name
, ".idl" ))
1930 add_generated_source( make
, replace_extension( source
->name
, ".idl", ".h" ), NULL
);
1932 if (strendswith( source
->name
, ".x" ))
1934 add_generated_source( make
, replace_extension( source
->name
, ".x", ".h" ), NULL
);
1936 if (strendswith( source
->name
, ".y" ))
1938 file
= add_generated_source( make
, replace_extension( source
->name
, ".y", ".tab.c" ), NULL
);
1939 /* steal the includes list from the source file */
1940 file
->files_count
= source
->files_count
;
1941 file
->files_size
= source
->files_size
;
1942 file
->files
= source
->files
;
1943 source
->files_count
= source
->files_size
= 0;
1944 source
->files
= NULL
;
1946 if (strendswith( source
->name
, ".l" ))
1948 file
= add_generated_source( make
, replace_extension( source
->name
, ".l", ".yy.c" ), NULL
);
1949 /* steal the includes list from the source file */
1950 file
->files_count
= source
->files_count
;
1951 file
->files_size
= source
->files_size
;
1952 file
->files
= source
->files
;
1953 source
->files_count
= source
->files_size
= 0;
1954 source
->files
= NULL
;
1956 if (source
->file
->flags
& FLAG_C_IMPLIB
)
1958 if (!make
->staticimplib
&& make
->importlib
&& *dll_ext
)
1959 make
->staticimplib
= strmake( "lib%s.a", make
->importlib
);
1961 if (strendswith( source
->name
, ".po" ))
1963 if (!make
->disabled
)
1964 strarray_add_uniq( &linguas
, replace_extension( source
->name
, ".po", "" ));
1966 if (strendswith( source
->name
, ".spec" ))
1968 char *obj
= replace_extension( source
->name
, ".spec", "" );
1969 strarray_addall_uniq( &make
->extra_imports
,
1970 get_expanded_file_local_var( make
, obj
, "IMPORTS" ));
1975 file
= add_generated_source( make
, "testlist.o", "testlist.c" );
1976 add_dependency( file
->file
, "wine/test.h", INCL_NORMAL
);
1977 add_all_includes( make
, file
, file
->file
);
1979 for (i
= 0; i
< objs
.count
; i
++)
1981 /* default to .c for unknown extra object files */
1982 if (strendswith( objs
.str
[i
], ".o" ))
1984 file
= add_generated_source( make
, objs
.str
[i
], replace_extension( objs
.str
[i
], ".o", ".c" ));
1985 if (make
->module
|| make
->staticlib
) file
->file
->flags
|= FLAG_C_UNIX
;
1987 else if (strendswith( objs
.str
[i
], ".res" ))
1988 add_generated_source( make
, replace_extension( objs
.str
[i
], ".res", ".rc" ), NULL
);
1990 add_generated_source( make
, objs
.str
[i
], NULL
);
1995 /*******************************************************************
1998 static void create_dir( const char *dir
)
2002 p
= path
= xstrdup( dir
);
2003 while ((p
= strchr( p
, '/' )))
2006 if (mkdir( path
, 0755 ) == -1 && errno
!= EEXIST
) fatal_perror( "mkdir %s", path
);
2008 while (*p
== '/') p
++;
2010 if (mkdir( path
, 0755 ) == -1 && errno
!= EEXIST
) fatal_perror( "mkdir %s", path
);
2015 /*******************************************************************
2016 * create_file_directories
2018 * Create the base directories of all the files.
2020 static void create_file_directories( const struct makefile
*make
, struct strarray files
)
2022 struct strarray subdirs
= empty_strarray
;
2026 for (i
= 0; i
< files
.count
; i
++)
2028 if (!strchr( files
.str
[i
], '/' )) continue;
2029 dir
= obj_dir_path( make
, files
.str
[i
] );
2030 *strrchr( dir
, '/' ) = 0;
2031 strarray_add_uniq( &subdirs
, dir
);
2034 for (i
= 0; i
< subdirs
.count
; i
++) create_dir( subdirs
.str
[i
] );
2038 /*******************************************************************
2039 * output_filenames_obj_dir
2041 static void output_filenames_obj_dir( const struct makefile
*make
, struct strarray array
)
2045 for (i
= 0; i
< array
.count
; i
++) output_filename( obj_dir_path( make
, array
.str
[i
] ));
2049 /*******************************************************************
2052 static void get_dependencies( struct incl_file
*file
, struct incl_file
*source
)
2056 if (!file
->filename
) return;
2060 if (file
->owner
== source
) return; /* already processed */
2061 if (file
->type
== INCL_IMPORTLIB
&&
2062 !(source
->file
->flags
& (FLAG_IDL_TYPELIB
| FLAG_IDL_REGTYPELIB
)))
2063 return; /* library is imported only when building a typelib */
2064 file
->owner
= source
;
2065 strarray_add( &source
->dependencies
, file
->filename
);
2067 for (i
= 0; i
< file
->files_count
; i
++) get_dependencies( file
->files
[i
], source
);
2071 /*******************************************************************
2072 * get_local_dependencies
2074 * Get the local dependencies of a given target.
2076 static struct strarray
get_local_dependencies( const struct makefile
*make
, const char *name
,
2077 struct strarray targets
)
2080 struct strarray deps
= get_expanded_file_local_var( make
, name
, "DEPS" );
2082 for (i
= 0; i
< deps
.count
; i
++)
2084 if (strarray_exists( &targets
, deps
.str
[i
] ))
2085 deps
.str
[i
] = obj_dir_path( make
, deps
.str
[i
] );
2087 deps
.str
[i
] = src_dir_path( make
, deps
.str
[i
] );
2093 /*******************************************************************
2096 * Check if makefile builds the named static library and return the full lib path.
2098 static const char *get_static_lib( const struct makefile
*make
, const char *name
)
2100 if (!make
->staticlib
) return NULL
;
2101 if (strncmp( make
->staticlib
, "lib", 3 )) return NULL
;
2102 if (strncmp( make
->staticlib
+ 3, name
, strlen(name
) )) return NULL
;
2103 if (strcmp( make
->staticlib
+ 3 + strlen(name
), ".a" )) return NULL
;
2104 return obj_dir_path( make
, make
->staticlib
);
2108 /*******************************************************************
2109 * get_parent_makefile
2111 static struct makefile
*get_parent_makefile( struct makefile
*make
)
2116 if (!make
->obj_dir
) return NULL
;
2117 dir
= xstrdup( make
->obj_dir
);
2118 if (!(p
= strrchr( dir
, '/' ))) return NULL
;
2120 for (i
= 0; i
< subdirs
.count
; i
++)
2121 if (!strcmp( submakes
[i
]->obj_dir
, dir
)) return submakes
[i
];
2126 /*******************************************************************
2129 static int needs_cross_lib( const struct makefile
*make
)
2132 if (!crosstarget
) return 0;
2133 if (make
->importlib
) name
= make
->importlib
;
2134 else if (make
->staticlib
)
2136 name
= replace_extension( make
->staticlib
, ".a", "" );
2137 if (!strncmp( name
, "lib", 3 )) name
+= 3;
2140 if (strarray_exists( &cross_import_libs
, name
)) return 1;
2141 if (delay_load_flag
&& strarray_exists( &delay_import_libs
, name
)) return 1;
2146 /*******************************************************************
2149 static int needs_delay_lib( const struct makefile
*make
)
2151 if (delay_load_flag
) return 0;
2152 if (*dll_ext
&& !crosstarget
) return 0;
2153 if (!make
->importlib
) return 0;
2154 return strarray_exists( &delay_import_libs
, make
->importlib
);
2158 /*******************************************************************
2159 * needs_implib_symlink
2161 static int needs_implib_symlink( const struct makefile
*make
)
2163 if (!make
->module
) return 0;
2164 if (!make
->importlib
) return 0;
2165 if (make
->is_win16
&& make
->disabled
) return 0;
2166 if (strncmp( make
->obj_dir
, "dlls/", 5 )) return 0;
2167 if (!strcmp( make
->module
, make
->importlib
)) return 0;
2168 if (!strchr( make
->importlib
, '.' ) &&
2169 !strncmp( make
->module
, make
->importlib
, strlen( make
->importlib
)) &&
2170 !strcmp( make
->module
+ strlen( make
->importlib
), ".dll" ))
2176 /*******************************************************************
2177 * add_unix_libraries
2179 static struct strarray
add_unix_libraries( const struct makefile
*make
, struct strarray
*deps
)
2181 struct strarray ret
= empty_strarray
;
2182 struct strarray all_libs
= empty_strarray
;
2185 strarray_add( &all_libs
, "-lwine_port" );
2186 strarray_addall( &all_libs
, get_expanded_make_var_array( make
, "EXTRALIBS" ));
2187 strarray_addall( &all_libs
, libs
);
2189 for (i
= 0; i
< all_libs
.count
; i
++)
2191 const char *lib
= NULL
;
2193 if (!strncmp( all_libs
.str
[i
], "-l", 2 ))
2195 const char *name
= all_libs
.str
[i
] + 2;
2197 for (j
= 0; j
< subdirs
.count
; j
++)
2198 if ((lib
= get_static_lib( submakes
[j
], name
))) break;
2203 strarray_add( deps
, lib
);
2204 strarray_add( &ret
, lib
);
2206 else strarray_add( &ret
, all_libs
.str
[i
] );
2212 /*******************************************************************
2215 static struct strarray
add_import_libs( const struct makefile
*make
, struct strarray
*deps
,
2216 struct strarray imports
, int delay
, int is_unix
)
2218 struct strarray ret
= empty_strarray
;
2220 int is_cross
= make
->is_cross
&& !is_unix
;
2222 for (i
= 0; i
< imports
.count
; i
++)
2224 const char *name
= get_base_name( imports
.str
[i
] );
2225 const char *lib
= NULL
;
2227 for (j
= 0; j
< subdirs
.count
; j
++)
2229 if (submakes
[j
]->importlib
&& !strcmp( submakes
[j
]->importlib
, name
))
2231 if (is_cross
|| !*dll_ext
|| submakes
[j
]->staticimplib
)
2232 lib
= obj_dir_path( submakes
[j
], strmake( "lib%s.a", name
));
2235 strarray_add( deps
, strmake( "%s/lib%s.def", submakes
[j
]->obj_dir
, name
));
2236 if (needs_implib_symlink( submakes
[j
] ))
2237 strarray_add( deps
, strmake( "dlls/lib%s.def", name
));
2242 if ((lib
= get_static_lib( submakes
[j
], name
))) break;
2247 const char *ext
= NULL
;
2249 if (delay
&& !delay_load_flag
&& (is_cross
|| !*dll_ext
)) ext
= ".delay.a";
2250 else if (is_cross
) ext
= ".cross.a";
2251 if (ext
) lib
= replace_extension( lib
, ".a", ext
);
2252 strarray_add( deps
, lib
);
2253 strarray_add( &ret
, lib
);
2254 if (needs_implib_symlink( submakes
[j
] ))
2255 strarray_add( deps
, strmake( "dlls/lib%s%s", name
, ext
? ext
: ".a" ));
2257 else strarray_add( &ret
, strmake( "-l%s", name
));
2263 /*******************************************************************
2264 * get_default_imports
2266 static struct strarray
get_default_imports( const struct makefile
*make
)
2268 struct strarray ret
= empty_strarray
;
2270 if (strarray_exists( &make
->extradllflags
, "-nodefaultlibs" )) return ret
;
2271 strarray_add( &ret
, "winecrt0" );
2272 if (make
->is_win16
) strarray_add( &ret
, "kernel" );
2273 strarray_add( &ret
, "kernel32" );
2274 strarray_add( &ret
, "ntdll" );
2279 /*******************************************************************
2282 static void add_crt_import( const struct makefile
*make
, struct strarray
*imports
, struct strarray
*defs
)
2285 const char *crt_dll
= NULL
;
2287 for (i
= 0; i
< imports
->count
; i
++)
2289 if (strncmp( imports
->str
[i
], "msvcr", 5 ) && strncmp( imports
->str
[i
], "ucrt", 4 )) continue;
2290 if (crt_dll
) fatal_error( "More than one C runtime DLL imported: %s and %s\n", crt_dll
, imports
->str
[i
] );
2291 crt_dll
= imports
->str
[i
];
2293 if (!crt_dll
&& !strarray_exists( &make
->extradllflags
, "-nodefaultlibs" ))
2296 (!strncmp( make
->module
, "msvcr", 5 ) ||
2297 !strncmp( make
->module
, "ucrt", 4 ) ||
2298 !strcmp( make
->module
, "crtdll.dll" )))
2300 crt_dll
= make
->module
;
2304 crt_dll
= !make
->testdll
&& !make
->staticlib
? "ucrtbase" : "msvcrt";
2305 strarray_add( imports
, crt_dll
);
2310 if (crt_dll
&& !strncmp( crt_dll
, "ucrt", 4 )) strarray_add( defs
, "-D_UCRT" );
2313 unsigned int version
= 0;
2314 if (crt_dll
) sscanf( crt_dll
, "msvcr%u", &version
);
2315 strarray_add( defs
, strmake( "-D_MSVCR_VER=%u", version
));
2320 /*******************************************************************
2323 static void add_install_rule( struct makefile
*make
, const char *target
,
2324 const char *file
, const char *dest
)
2326 if (strarray_exists( &make
->install_lib
, target
) ||
2327 strarray_exists( &top_install_lib
, make
->obj_dir
) ||
2328 strarray_exists( &top_install_lib
, obj_dir_path( make
, target
)))
2330 strarray_add( &make
->install_rules
[INSTALL_LIB
], file
);
2331 strarray_add( &make
->install_rules
[INSTALL_LIB
], dest
);
2333 else if (strarray_exists( &make
->install_dev
, target
) ||
2334 strarray_exists( &top_install_dev
, make
->obj_dir
) ||
2335 strarray_exists( &top_install_dev
, obj_dir_path( make
, target
)))
2337 strarray_add( &make
->install_rules
[INSTALL_DEV
], file
);
2338 strarray_add( &make
->install_rules
[INSTALL_DEV
], dest
);
2343 /*******************************************************************
2344 * get_include_install_path
2346 * Determine the installation path for a given include file.
2348 static const char *get_include_install_path( const char *name
)
2350 if (!strncmp( name
, "wine/", 5 )) return name
+ 5;
2351 if (!strncmp( name
, "msvcrt/", 7 )) return name
;
2352 return strmake( "windows/%s", name
);
2356 /*******************************************************************
2357 * get_shared_library_name
2359 * Determine possible names for a shared library with a version number.
2361 static struct strarray
get_shared_lib_names( const char *libname
)
2363 struct strarray ret
= empty_strarray
;
2364 const char *ext
, *p
;
2365 char *name
, *first
, *second
;
2368 strarray_add( &ret
, libname
);
2370 for (p
= libname
; (p
= strchr( p
, '.' )); p
++)
2371 if ((len
= strspn( p
+ 1, "0123456789." ))) break;
2373 if (!len
) return ret
;
2375 if (*ext
&& ext
[-1] == '.') ext
--;
2377 /* keep only the first group of digits */
2378 name
= xstrdup( libname
);
2379 first
= name
+ (p
- libname
);
2380 if ((second
= strchr( first
+ 1, '.' )))
2382 strcpy( second
, ext
);
2383 strarray_add( &ret
, xstrdup( name
));
2385 /* now remove all digits */
2386 strcpy( first
, ext
);
2387 strarray_add( &ret
, name
);
2392 /*******************************************************************
2393 * get_source_defines
2395 static struct strarray
get_source_defines( struct makefile
*make
, struct incl_file
*source
,
2399 struct strarray ret
= empty_strarray
;
2401 strarray_addall( &ret
, make
->include_args
);
2402 if (source
->use_msvcrt
)
2403 strarray_add( &ret
, strmake( "-I%s", root_src_dir_path( "include/msvcrt" )));
2404 for (i
= 0; i
< make
->include_paths
.count
; i
++)
2405 strarray_add( &ret
, strmake( "-I%s", make
->include_paths
.str
[i
] ));
2406 strarray_addall( &ret
, make
->define_args
);
2407 strarray_addall( &ret
, get_expanded_file_local_var( make
, obj
, "EXTRADEFS" ));
2408 if ((source
->file
->flags
& FLAG_C_UNIX
) && *dll_ext
) strarray_add( &ret
, "-DWINE_UNIX_LIB" );
2413 /*******************************************************************
2416 static const char *get_debug_file( struct makefile
*make
, const char *name
)
2418 const char *debug_file
= NULL
;
2419 if (!make
->is_cross
|| !crossdebug
) return NULL
;
2420 if (!strcmp( crossdebug
, "pdb" )) debug_file
= strmake( "%s.pdb", get_base_name( name
));
2421 else if(!strncmp( crossdebug
, "split", 5 )) debug_file
= strmake( "%s.debug", name
);
2422 if (debug_file
) strarray_add( &make
->debug_files
, debug_file
);
2427 /*******************************************************************
2428 * output_winegcc_command
2430 static void output_winegcc_command( struct makefile
*make
, int is_cross
)
2432 output( "\t%s -o $@", tools_path( make
, "winegcc" ));
2433 output_filename( "--wine-objdir ." );
2436 output_filename( "--winebuild" );
2437 output_filename( tools_path( make
, "winebuild" ));
2441 output_filename( "-b" );
2442 output_filename( crosstarget
);
2443 output_filename( "--lib-suffix=.cross.a" );
2447 output_filenames( target_flags
);
2448 output_filenames( lddll_flags
);
2453 /*******************************************************************
2454 * output_symlink_rule
2456 * Output a rule to create a symlink.
2458 static void output_symlink_rule( const char *src_name
, const char *link_name
, int create_dir
)
2460 const char *name
= strrchr( link_name
, '/' );
2465 dir
= xstrdup( link_name
);
2466 dir
[name
- link_name
] = 0;
2470 if (create_dir
&& dir
&& *dir
) output( "%s -d %s && ", root_src_dir_path( "tools/install-sh" ), dir
);
2471 output( "rm -f %s && ", link_name
);
2473 /* dest path with a directory needs special handling if ln -s isn't supported */
2474 if (dir
&& strcmp( ln_s
, "ln -s" ))
2475 output( "cd %s && %s %s %s\n", *dir
? dir
: "/", ln_s
, src_name
, name
+ 1 );
2477 output( "%s %s %s\n", ln_s
, src_name
, link_name
);
2483 /*******************************************************************
2484 * output_srcdir_symlink
2486 * Output rule to create a symlink back to the source directory, for source files
2487 * that are needed at run-time.
2489 static void output_srcdir_symlink( struct makefile
*make
, const char *obj
)
2491 char *src_file
, *dst_file
, *src_name
;
2493 if (!make
->src_dir
) return;
2494 src_file
= src_dir_path( make
, obj
);
2495 dst_file
= obj_dir_path( make
, obj
);
2496 output( "%s: %s\n", dst_file
, src_file
);
2498 src_name
= src_file
;
2499 if (src_name
[0] != '/' && make
->obj_dir
)
2500 src_name
= concat_paths( get_relative_path( make
->obj_dir
, "" ), src_name
);
2502 output_symlink_rule( src_name
, dst_file
, 0 );
2503 strarray_add( &make
->all_targets
, obj
);
2507 /*******************************************************************
2508 * output_install_commands
2510 static void output_install_commands( struct makefile
*make
, struct strarray files
)
2513 char *install_sh
= root_src_dir_path( "tools/install-sh" );
2515 for (i
= 0; i
< files
.count
; i
+= 2)
2517 const char *file
= files
.str
[i
];
2518 const char *dest
= strmake( "$(DESTDIR)%s", files
.str
[i
+ 1] + 1 );
2520 switch (*files
.str
[i
+ 1])
2522 case 'c': /* cross-compiled program */
2523 output( "\tSTRIPPROG=%s-strip %s -m 644 $(INSTALL_PROGRAM_FLAGS) %s %s\n",
2524 crosstarget
, install_sh
, obj_dir_path( make
, file
), dest
);
2525 output( "\t%s --builtin %s\n", tools_path( make
, "winebuild" ), dest
);
2527 case 'd': /* data file */
2528 output( "\t%s -m 644 $(INSTALL_DATA_FLAGS) %s %s\n",
2529 install_sh
, obj_dir_path( make
, file
), dest
);
2531 case 'D': /* data file in source dir */
2532 output( "\t%s -m 644 $(INSTALL_DATA_FLAGS) %s %s\n",
2533 install_sh
, src_dir_path( make
, file
), dest
);
2535 case 'p': /* program file */
2536 output( "\tSTRIPPROG=\"$(STRIP)\" %s $(INSTALL_PROGRAM_FLAGS) %s %s\n",
2537 install_sh
, obj_dir_path( make
, file
), dest
);
2539 case 's': /* script */
2540 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s %s\n",
2541 install_sh
, obj_dir_path( make
, file
), dest
);
2543 case 'S': /* script in source dir */
2544 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s %s\n",
2545 install_sh
, src_dir_path( make
, file
), dest
);
2547 case 't': /* script in tools dir */
2548 output( "\t%s $(INSTALL_SCRIPT_FLAGS) %s %s\n",
2549 install_sh
, tools_dir_path( make
, files
.str
[i
] ), dest
);
2551 case 'y': /* symlink */
2552 output_symlink_rule( files
.str
[i
], dest
, 1 );
2557 strarray_add( &make
->uninstall_files
, dest
);
2562 /*******************************************************************
2563 * output_install_rules
2565 * Rules are stored as a (file,dest) pair of values.
2566 * The first char of dest indicates the type of install.
2568 static void output_install_rules( struct makefile
*make
, enum install_rules rules
, const char *target
)
2571 struct strarray files
= make
->install_rules
[rules
];
2572 struct strarray targets
= empty_strarray
;
2574 if (!files
.count
) return;
2576 for (i
= 0; i
< files
.count
; i
+= 2)
2578 const char *file
= files
.str
[i
];
2579 switch (*files
.str
[i
+ 1])
2581 case 'c': /* cross-compiled program */
2582 case 'd': /* data file */
2583 case 'p': /* program file */
2584 case 's': /* script */
2585 strarray_add_uniq( &targets
, obj_dir_path( make
, file
));
2587 case 't': /* script in tools dir */
2588 strarray_add_uniq( &targets
, tools_dir_path( make
, file
));
2593 output( "%s %s::", obj_dir_path( make
, "install" ), obj_dir_path( make
, target
));
2594 output_filenames( targets
);
2596 output_install_commands( make
, files
);
2597 strarray_add_uniq( &make
->phony_targets
, obj_dir_path( make
, "install" ));
2598 strarray_add_uniq( &make
->phony_targets
, obj_dir_path( make
, target
));
2602 static int cmp_string_length( const char **a
, const char **b
)
2604 int paths_a
= 0, paths_b
= 0;
2607 for (p
= *a
; *p
; p
++) if (*p
== '/') paths_a
++;
2608 for (p
= *b
; *p
; p
++) if (*p
== '/') paths_b
++;
2609 if (paths_b
!= paths_a
) return paths_b
- paths_a
;
2610 return strcmp( *a
, *b
);
2613 /*******************************************************************
2614 * output_uninstall_rules
2616 static void output_uninstall_rules( struct makefile
*make
)
2618 static const char *dirs_order
[] =
2619 { "$(includedir)", "$(mandir)", "$(fontdir)", "$(datadir)", "$(dlldir)" };
2621 struct strarray uninstall_dirs
= empty_strarray
;
2624 if (!make
->uninstall_files
.count
) return;
2625 output( "uninstall::\n" );
2626 output_rm_filenames( make
->uninstall_files
);
2627 strarray_add_uniq( &make
->phony_targets
, "uninstall" );
2629 if (!subdirs
.count
) return;
2630 for (i
= 0; i
< make
->uninstall_files
.count
; i
++)
2632 char *dir
= xstrdup( make
->uninstall_files
.str
[i
] );
2633 while (strchr( dir
, '/' ))
2635 *strrchr( dir
, '/' ) = 0;
2636 strarray_add_uniq( &uninstall_dirs
, xstrdup(dir
) );
2639 strarray_qsort( &uninstall_dirs
, cmp_string_length
);
2640 output( "\t-rmdir" );
2641 for (i
= 0; i
< sizeof(dirs_order
)/sizeof(dirs_order
[0]); i
++)
2643 for (j
= 0; j
< uninstall_dirs
.count
; j
++)
2645 if (!uninstall_dirs
.str
[j
]) continue;
2646 if (strncmp( uninstall_dirs
.str
[j
] + strlen("$(DESTDIR)"), dirs_order
[i
], strlen(dirs_order
[i
]) ))
2648 output_filename( uninstall_dirs
.str
[j
] );
2649 uninstall_dirs
.str
[j
] = NULL
;
2652 for (j
= 0; j
< uninstall_dirs
.count
; j
++)
2653 if (uninstall_dirs
.str
[j
]) output_filename( uninstall_dirs
.str
[j
] );
2658 /*******************************************************************
2659 * output_importlib_symlinks
2661 static struct strarray
output_importlib_symlinks( const struct makefile
*make
)
2663 struct strarray ret
= empty_strarray
;
2664 const char *lib
, *dst
, *ext
[4];
2667 ext
[count
++] = (*dll_ext
&& !make
->implib_objs
.count
) ? "def" : "a";
2668 if (needs_delay_lib( make
)) ext
[count
++] = "delay.a";
2669 if (needs_cross_lib( make
)) ext
[count
++] = "cross.a";
2671 for (i
= 0; i
< count
; i
++)
2673 lib
= strmake( "lib%s.%s", make
->importlib
, ext
[i
] );
2674 dst
= strmake( "dlls/%s", lib
);
2675 output( "%s: %s\n", dst
, obj_dir_path( make
, lib
));
2676 output_symlink_rule( concat_paths( make
->obj_dir
+ strlen("dlls/"), lib
), dst
, 0 );
2677 strarray_add( &ret
, dst
);
2683 /*******************************************************************
2686 static void output_po_files( const struct makefile
*make
)
2688 const char *po_dir
= src_dir_path( make
, "po" );
2693 for (i
= 0; i
< linguas
.count
; i
++)
2694 output_filename( strmake( "%s/%s.po", po_dir
, linguas
.str
[i
] ));
2695 output( ": %s/wine.pot\n", po_dir
);
2696 output( "\tmsgmerge --previous -q $@ %s/wine.pot | msgattrib --no-obsolete -o $@.new && mv $@.new $@\n",
2699 for (i
= 0; i
< linguas
.count
; i
++)
2700 output_filename( strmake( "%s/%s.po", po_dir
, linguas
.str
[i
] ));
2703 output( "%s/wine.pot:", po_dir
);
2704 output_filenames( make
->pot_files
);
2706 output( "\tmsgcat -o $@" );
2707 output_filenames( make
->pot_files
);
2712 /*******************************************************************
2715 static void output_source_y( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2717 /* add source file dependency for parallel makes */
2718 char *header
= strmake( "%s.tab.h", obj
);
2720 if (find_include_file( make
, header
))
2722 output( "%s: %s\n", obj_dir_path( make
, header
), source
->filename
);
2723 output( "\t%s -p %s_ -o %s.tab.c -d %s\n",
2724 bison
, obj
, obj_dir_path( make
, obj
), source
->filename
);
2725 output( "%s.tab.c: %s %s\n", obj_dir_path( make
, obj
),
2726 source
->filename
, obj_dir_path( make
, header
));
2727 strarray_add( &make
->clean_files
, header
);
2729 else output( "%s.tab.c: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2731 output( "\t%s -p %s_ -o $@ %s\n", bison
, obj
, source
->filename
);
2735 /*******************************************************************
2738 static void output_source_l( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2740 output( "%s.yy.c: %s\n", obj_dir_path( make
, obj
), source
->filename
);
2741 output( "\t%s -o$@ %s\n", flex
, source
->filename
);
2745 /*******************************************************************
2748 static void output_source_h( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2750 if (source
->file
->flags
& FLAG_GENERATED
)
2751 strarray_add( &make
->all_targets
, source
->name
);
2753 add_install_rule( make
, source
->name
, source
->name
,
2754 strmake( "D$(includedir)/wine/%s", get_include_install_path( source
->name
) ));
2758 /*******************************************************************
2761 static void output_source_rc( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2763 struct strarray defines
= get_source_defines( make
, source
, obj
);
2764 const char *po_dir
= NULL
;
2767 if (source
->file
->flags
& FLAG_GENERATED
) strarray_add( &make
->clean_files
, source
->name
);
2768 if (linguas
.count
&& (source
->file
->flags
& FLAG_RC_PO
)) po_dir
= "po";
2769 strarray_add( &make
->res_files
, strmake( "%s.res", obj
));
2770 if (source
->file
->flags
& FLAG_RC_PO
)
2772 strarray_add( &make
->pot_files
, strmake( "%s.pot", obj
));
2773 output( "%s.pot ", obj_dir_path( make
, obj
) );
2775 output( "%s.res: %s", obj_dir_path( make
, obj
), source
->filename
);
2776 output_filename( tools_path( make
, "wrc" ));
2777 output_filenames( source
->dependencies
);
2779 output( "\t%s -u -o $@", tools_path( make
, "wrc" ) );
2780 if (make
->is_win16
) output_filename( "-m16" );
2781 else output_filenames( target_flags
);
2782 output_filename( "--nostdinc" );
2783 if (po_dir
) output_filename( strmake( "--po-dir=%s", po_dir
));
2784 output_filenames( defines
);
2785 output_filename( source
->filename
);
2789 output( "%s.res:", obj_dir_path( make
, obj
));
2790 for (i
= 0; i
< linguas
.count
; i
++)
2791 output_filename( strmake( "%s/%s.mo", po_dir
, linguas
.str
[i
] ));
2797 /*******************************************************************
2800 static void output_source_mc( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2803 char *obj_path
= obj_dir_path( make
, obj
);
2805 strarray_add( &make
->res_files
, strmake( "%s.res", obj
));
2806 strarray_add( &make
->pot_files
, strmake( "%s.pot", obj
));
2807 output( "%s.pot %s.res: %s", obj_path
, obj_path
, source
->filename
);
2808 output_filename( tools_path( make
, "wmc" ));
2809 output_filenames( source
->dependencies
);
2811 output( "\t%s -u -o $@ %s", tools_path( make
, "wmc" ), source
->filename
);
2814 output_filename( "--po-dir=po" );
2816 output( "%s.res:", obj_dir_path( make
, obj
));
2817 for (i
= 0; i
< linguas
.count
; i
++)
2818 output_filename( strmake( "po/%s.mo", linguas
.str
[i
] ));
2824 /*******************************************************************
2827 static void output_source_res( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2829 strarray_add( &make
->res_files
, source
->name
);
2833 /*******************************************************************
2836 static void output_source_idl( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2838 struct strarray defines
= get_source_defines( make
, source
, obj
);
2839 struct strarray targets
= empty_strarray
;
2843 if (!source
->file
->flags
) source
->file
->flags
|= FLAG_IDL_HEADER
| FLAG_INSTALL
;
2844 if (find_include_file( make
, strmake( "%s.h", obj
))) source
->file
->flags
|= FLAG_IDL_HEADER
;
2846 for (i
= 0; i
< sizeof(idl_outputs
) / sizeof(idl_outputs
[0]); i
++)
2848 if (!(source
->file
->flags
& idl_outputs
[i
].flag
)) continue;
2849 dest
= strmake( "%s%s", obj
, idl_outputs
[i
].ext
);
2850 if (!find_src_file( make
, dest
)) strarray_add( &make
->clean_files
, dest
);
2851 strarray_add( &targets
, dest
);
2853 if (source
->file
->flags
& FLAG_IDL_PROXY
) strarray_add( &make
->dlldata_files
, source
->name
);
2854 if (source
->file
->flags
& FLAG_INSTALL
)
2856 add_install_rule( make
, source
->name
, xstrdup( source
->name
),
2857 strmake( "D$(includedir)/wine/%s.idl", get_include_install_path( obj
) ));
2858 if (source
->file
->flags
& FLAG_IDL_HEADER
)
2859 add_install_rule( make
, source
->name
, strmake( "%s.h", obj
),
2860 strmake( "d$(includedir)/wine/%s.h", get_include_install_path( obj
) ));
2861 if (source
->file
->flags
& FLAG_IDL_TYPELIB
)
2862 add_install_rule( make
, source
->name
, strmake( "%s.tlb", obj
),
2863 strmake( "d$(includedir)/wine/%s.tlb", get_include_install_path( obj
) ));
2865 if (!targets
.count
) return;
2867 output_filenames_obj_dir( make
, targets
);
2868 output( ": %s\n", tools_path( make
, "widl" ));
2869 output( "\t%s -o $@", tools_path( make
, "widl" ) );
2870 output_filenames( target_flags
);
2871 output_filename( "--nostdinc" );
2872 output_filenames( defines
);
2873 output_filenames( get_expanded_make_var_array( make
, "EXTRAIDLFLAGS" ));
2874 output_filenames( get_expanded_file_local_var( make
, obj
, "EXTRAIDLFLAGS" ));
2875 output_filename( source
->filename
);
2877 output_filenames_obj_dir( make
, targets
);
2878 output( ": %s", source
->filename
);
2879 output_filenames( source
->dependencies
);
2884 /*******************************************************************
2887 static void output_source_tlb( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2889 strarray_add( &make
->all_targets
, source
->name
);
2893 /*******************************************************************
2896 static void output_source_x( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2898 output( "%s.h: %s%s %s\n", obj_dir_path( make
, obj
),
2899 tools_dir_path( make
, "make_xftmpl" ), tools_ext
, source
->filename
);
2900 output( "\t%s%s -H -o $@ %s\n",
2901 tools_dir_path( make
, "make_xftmpl" ), tools_ext
, source
->filename
);
2902 if (source
->file
->flags
& FLAG_INSTALL
)
2904 add_install_rule( make
, source
->name
, source
->name
,
2905 strmake( "D$(includedir)/wine/%s", get_include_install_path( source
->name
) ));
2906 add_install_rule( make
, source
->name
, strmake( "%s.h", obj
),
2907 strmake( "d$(includedir)/wine/%s.h", get_include_install_path( obj
) ));
2912 /*******************************************************************
2915 static void output_source_sfd( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2918 char *ttf_obj
= strmake( "%s.ttf", obj
);
2919 char *ttf_file
= src_dir_path( make
, ttf_obj
);
2921 if (fontforge
&& !make
->src_dir
)
2923 output( "%s: %s\n", ttf_file
, source
->filename
);
2924 output( "\t%s -script %s %s $@\n",
2925 fontforge
, root_src_dir_path( "fonts/genttf.ff" ), source
->filename
);
2926 if (!(source
->file
->flags
& FLAG_SFD_FONTS
)) strarray_add( &make
->font_files
, ttf_obj
);
2928 if (source
->file
->flags
& FLAG_INSTALL
)
2930 add_install_rule( make
, source
->name
, ttf_obj
, strmake( "D$(fontdir)/%s", ttf_obj
));
2931 output_srcdir_symlink( make
, ttf_obj
);
2934 if (source
->file
->flags
& FLAG_SFD_FONTS
)
2936 struct strarray
*array
= source
->file
->args
;
2938 for (i
= 0; i
< array
->count
; i
++)
2940 char *font
= strtok( xstrdup(array
->str
[i
]), " \t" );
2941 char *args
= strtok( NULL
, "" );
2943 strarray_add( &make
->all_targets
, xstrdup( font
));
2944 output( "%s: %s %s\n", obj_dir_path( make
, font
),
2945 tools_path( make
, "sfnt2fon" ), ttf_file
);
2946 output( "\t%s -q -o $@ %s %s\n", tools_path( make
, "sfnt2fon" ), ttf_file
, args
);
2947 add_install_rule( make
, source
->name
, xstrdup(font
), strmake( "d$(fontdir)/%s", font
));
2953 /*******************************************************************
2956 static void output_source_svg( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2958 static const char * const images
[] = { "bmp", "cur", "ico", NULL
};
2961 if (convert
&& rsvg
&& icotool
&& !make
->src_dir
)
2963 for (i
= 0; images
[i
]; i
++)
2964 if (find_include_file( make
, strmake( "%s.%s", obj
, images
[i
] ))) break;
2968 output( "%s.%s: %s\n", src_dir_path( make
, obj
), images
[i
], source
->filename
);
2969 output( "\tCONVERT=\"%s\" ICOTOOL=\"%s\" RSVG=\"%s\" %s %s $@\n", convert
, icotool
, rsvg
,
2970 root_src_dir_path( "tools/buildimage" ), source
->filename
);
2976 /*******************************************************************
2979 static void output_source_nls( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2981 add_install_rule( make
, source
->name
, source
->name
,
2982 strmake( "D$(nlsdir)/%s", source
->name
));
2983 output_srcdir_symlink( make
, strmake( "%s.nls", obj
));
2987 /*******************************************************************
2988 * output_source_desktop
2990 static void output_source_desktop( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
2992 add_install_rule( make
, source
->name
, source
->name
,
2993 strmake( "D$(datadir)/applications/%s", source
->name
));
2997 /*******************************************************************
3000 static void output_source_po( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
3002 output( "%s.mo: %s\n", obj_dir_path( make
, obj
), source
->filename
);
3003 output( "\t%s -o $@ %s\n", msgfmt
, source
->filename
);
3004 strarray_add( &make
->all_targets
, strmake( "%s.mo", obj
));
3008 /*******************************************************************
3011 static void output_source_in( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
3015 if (strendswith( obj
, ".man" ) && source
->file
->args
)
3017 struct strarray symlinks
;
3018 char *dir
, *dest
= replace_extension( obj
, ".man", "" );
3019 char *lang
= strchr( dest
, '.' );
3020 char *section
= source
->file
->args
;
3024 dir
= strmake( "$(mandir)/%s/man%s", lang
, section
);
3026 else dir
= strmake( "$(mandir)/man%s", section
);
3027 add_install_rule( make
, dest
, xstrdup(obj
), strmake( "d%s/%s.%s", dir
, dest
, section
));
3028 symlinks
= get_expanded_file_local_var( make
, dest
, "SYMLINKS" );
3029 for (i
= 0; i
< symlinks
.count
; i
++)
3030 add_install_rule( make
, symlinks
.str
[i
], strmake( "%s.%s", dest
, section
),
3031 strmake( "y%s/%s.%s", dir
, symlinks
.str
[i
], section
));
3035 strarray_add( &make
->in_files
, xstrdup(obj
) );
3036 strarray_add( &make
->all_targets
, xstrdup(obj
) );
3037 output( "%s: %s\n", obj_dir_path( make
, obj
), source
->filename
);
3038 output( "\t%s %s >$@ || (rm -f $@ && false)\n", sed_cmd
, source
->filename
);
3039 output( "%s:", obj_dir_path( make
, obj
));
3040 output_filenames( source
->dependencies
);
3042 add_install_rule( make
, obj
, xstrdup( obj
), strmake( "d$(datadir)/wine/%s", obj
));
3046 /*******************************************************************
3047 * output_source_spec
3049 static void output_source_spec( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
3051 struct strarray imports
= get_expanded_file_local_var( make
, obj
, "IMPORTS" );
3052 struct strarray dll_flags
= get_expanded_file_local_var( make
, obj
, "EXTRADLLFLAGS" );
3053 struct strarray all_libs
, dep_libs
= empty_strarray
;
3054 char *dll_name
, *obj_name
, *output_file
;
3055 const char *debug_file
;
3057 if (!imports
.count
) imports
= make
->imports
;
3058 else if (make
->use_msvcrt
) add_crt_import( make
, &imports
, NULL
);
3060 if (!dll_flags
.count
) dll_flags
= make
->extradllflags
;
3061 all_libs
= add_import_libs( make
, &dep_libs
, imports
, 0, 0 );
3062 add_import_libs( make
, &dep_libs
, get_default_imports( make
), 0, 0 ); /* dependencies only */
3063 dll_name
= strmake( "%s.dll%s", obj
, make
->is_cross
? "" : dll_ext
);
3064 obj_name
= strmake( "%s%s", obj_dir_path( make
, obj
), make
->is_cross
? ".cross.o" : ".o" );
3065 output_file
= obj_dir_path( make
, dll_name
);
3067 strarray_add( &make
->clean_files
, dll_name
);
3068 strarray_add( &make
->res_files
, strmake( "%s.res", obj
));
3069 output( "%s.res: %s\n", obj_dir_path( make
, obj
), obj_dir_path( make
, dll_name
));
3070 output( "\techo \"%s.dll TESTDLL \\\"%s\\\"\" | %s -u -o $@\n", obj
, output_file
,
3071 tools_path( make
, "wrc" ));
3073 output( "%s:", output_file
);
3074 output_filename( source
->filename
);
3075 output_filename( obj_name
);
3076 output_filenames( dep_libs
);
3077 output_filename( tools_path( make
, "winebuild" ));
3078 output_filename( tools_path( make
, "winegcc" ));
3080 output_winegcc_command( make
, make
->is_cross
);
3081 output_filename( "-s" );
3082 output_filenames( dll_flags
);
3083 output_filename( "-shared" );
3084 output_filename( source
->filename
);
3085 output_filename( obj_name
);
3086 if ((debug_file
= get_debug_file( make
, dll_name
)))
3087 output_filename( strmake( "-Wl,--debug-file,%s", obj_dir_path( make
, debug_file
)));
3088 output_filenames( all_libs
);
3089 output_filename( make
->is_cross
? "$(CROSSLDFLAGS)" : "$(LDFLAGS)" );
3094 /*******************************************************************
3095 * output_source_default
3097 static void output_source_default( struct makefile
*make
, struct incl_file
*source
, const char *obj
)
3099 struct strarray defines
= get_source_defines( make
, source
, obj
);
3100 int is_dll_src
= (make
->testdll
&&
3101 strendswith( source
->name
, ".c" ) &&
3102 find_src_file( make
, replace_extension( source
->name
, ".c", ".spec" )));
3103 int need_cross
= (crosstarget
&&
3104 !(source
->file
->flags
& FLAG_C_UNIX
) &&
3106 ((source
->file
->flags
& FLAG_C_IMPLIB
) &&
3107 (needs_cross_lib( make
) || needs_delay_lib( make
))) ||
3108 (make
->staticlib
&& needs_cross_lib( make
))));
3109 int need_obj
= ((*dll_ext
|| !(source
->file
->flags
& FLAG_C_UNIX
)) &&
3111 (source
->file
->flags
& FLAG_C_IMPLIB
) ||
3112 (make
->module
&& make
->staticlib
)));
3114 if ((source
->file
->flags
& FLAG_GENERATED
) &&
3115 (!make
->testdll
|| !strendswith( source
->filename
, "testlist.c" )))
3116 strarray_add( &make
->clean_files
, source
->basename
);
3117 if (source
->file
->flags
& FLAG_C_IMPLIB
) strarray_add( &make
->implib_objs
, strmake( "%s.o", obj
));
3121 if ((source
->file
->flags
& FLAG_C_UNIX
) && *dll_ext
)
3122 strarray_add( &make
->unixobj_files
, strmake( "%s.o", obj
));
3123 else if (!is_dll_src
&& !(source
->file
->flags
& FLAG_C_IMPLIB
))
3124 strarray_add( &make
->object_files
, strmake( "%s.o", obj
));
3126 strarray_add( &make
->clean_files
, strmake( "%s.o", obj
));
3127 output( "%s.o: %s\n", obj_dir_path( make
, obj
), source
->filename
);
3128 output( "\t$(CC) -c -o $@ %s", source
->filename
);
3129 output_filenames( defines
);
3130 if (make
->module
|| make
->staticlib
|| make
->sharedlib
|| make
->testdll
)
3132 output_filenames( dll_flags
);
3133 if (source
->use_msvcrt
) output_filenames( msvcrt_flags
);
3135 output_filenames( extra_cflags
);
3136 output_filenames( cpp_flags
);
3137 output_filename( "$(CFLAGS)" );
3142 if (!is_dll_src
&& !(source
->file
->flags
& FLAG_C_IMPLIB
))
3143 strarray_add( &make
->crossobj_files
, strmake( "%s.cross.o", obj
));
3145 strarray_add( &make
->clean_files
, strmake( "%s.cross.o", obj
));
3146 output( "%s.cross.o: %s\n", obj_dir_path( make
, obj
), source
->filename
);
3147 output( "\t$(CROSSCC) -c -o $@ %s", source
->filename
);
3148 output_filenames( defines
);
3149 output_filenames( extra_cross_cflags
);
3150 if (source
->file
->flags
& FLAG_C_IMPLIB
) output_filename( "-fno-builtin" );
3151 output_filenames( cpp_flags
);
3152 output_filename( "$(CROSSCFLAGS)" );
3155 if (strendswith( source
->name
, ".c" ) && !(source
->file
->flags
& FLAG_GENERATED
))
3157 strarray_add( &make
->c2man_files
, source
->filename
);
3158 if (make
->testdll
&& !is_dll_src
)
3160 strarray_add( &make
->ok_files
, strmake( "%s.ok", obj
));
3161 output( "%s.ok:\n", obj_dir_path( make
, obj
));
3162 output( "\t%s $(RUNTESTFLAGS) -T . -M %s -p %s%s %s && touch $@\n",
3163 root_src_dir_path( "tools/runtest" ), make
->testdll
,
3164 obj_dir_path( make
, replace_extension( make
->testdll
, ".dll", "_test.exe" )),
3165 make
->is_cross
? "" : dll_ext
, obj
);
3168 if (need_obj
) output_filename( strmake( "%s.o", obj_dir_path( make
, obj
)));
3169 if (need_cross
) output_filename( strmake( "%s.cross.o", obj_dir_path( make
, obj
)));
3171 output_filenames( source
->dependencies
);
3176 /* dispatch table to output rules for a single source file */
3180 void (*fn
)( struct makefile
*make
, struct incl_file
*source
, const char *obj
);
3181 } output_source_funcs
[] =
3183 { "y", output_source_y
},
3184 { "l", output_source_l
},
3185 { "h", output_source_h
},
3186 { "rh", output_source_h
},
3187 { "inl", output_source_h
},
3188 { "rc", output_source_rc
},
3189 { "mc", output_source_mc
},
3190 { "res", output_source_res
},
3191 { "idl", output_source_idl
},
3192 { "tlb", output_source_tlb
},
3193 { "sfd", output_source_sfd
},
3194 { "svg", output_source_svg
},
3195 { "nls", output_source_nls
},
3196 { "desktop", output_source_desktop
},
3197 { "po", output_source_po
},
3198 { "in", output_source_in
},
3199 { "x", output_source_x
},
3200 { "spec", output_source_spec
},
3201 { NULL
, output_source_default
}
3205 /*******************************************************************
3208 static int has_object_file( struct makefile
*make
)
3210 struct incl_file
*source
;
3213 LIST_FOR_EACH_ENTRY( source
, &make
->sources
, struct incl_file
, entry
)
3215 char *ext
= get_extension( source
->name
);
3217 if (!ext
) fatal_error( "unsupported file type %s\n", source
->name
);
3220 for (i
= 0; output_source_funcs
[i
].ext
; i
++)
3221 if (!strcmp( ext
, output_source_funcs
[i
].ext
)) break;
3223 if (!output_source_funcs
[i
].ext
) return 1; /* default extension builds to an object file */
3229 /*******************************************************************
3232 static void output_man_pages( struct makefile
*make
)
3234 if (make
->c2man_files
.count
)
3236 char *spec_file
= src_dir_path( make
, replace_extension( make
->module
, ".dll", ".spec" ));
3238 output( "manpages::\n" );
3239 output( "\t%s -w %s", root_src_dir_path( "tools/c2man.pl" ), spec_file
);
3240 output_filename( strmake( "-R%s", root_src_dir_path( "" )));
3241 output_filename( strmake( "-I%s", root_src_dir_path( "include" )));
3242 output_filename( strmake( "-o documentation/man%s", man_ext
));
3243 output_filenames( make
->c2man_files
);
3245 output( "htmlpages::\n" );
3246 output( "\t%s -Th -w %s", root_src_dir_path( "tools/c2man.pl" ), spec_file
);
3247 output_filename( strmake( "-R%s", root_src_dir_path( "" )));
3248 output_filename( strmake( "-I%s", root_src_dir_path( "include" )));
3249 output_filename( "-o documentation/html" );
3250 output_filenames( make
->c2man_files
);
3252 output( "sgmlpages::\n" );
3253 output( "\t%s -Ts -w %s", root_src_dir_path( "tools/c2man.pl" ), spec_file
);
3254 output_filename( strmake( "-R%s", root_src_dir_path( "" )));
3255 output_filename( strmake( "-I%s", root_src_dir_path( "include" )));
3256 output_filename( "-o documentation/api-guide" );
3257 output_filenames( make
->c2man_files
);
3259 output( "xmlpages::\n" );
3260 output( "\t%s -Tx -w %s", root_src_dir_path( "tools/c2man.pl" ), spec_file
);
3261 output_filename( strmake( "-R%s", root_src_dir_path( "" )));
3262 output_filename( strmake( "-I%s", root_src_dir_path( "include" )));
3263 output_filename( "-o documentation/api-guide-xml" );
3264 output_filenames( make
->c2man_files
);
3266 strarray_add( &make
->phony_targets
, "manpages" );
3267 strarray_add( &make
->phony_targets
, "htmlpages" );
3268 strarray_add( &make
->phony_targets
, "sgmlpages" );
3269 strarray_add( &make
->phony_targets
, "xmlpages" );
3274 /*******************************************************************
3277 static void output_module( struct makefile
*make
)
3279 struct strarray all_libs
= empty_strarray
;
3280 struct strarray dep_libs
= empty_strarray
;
3281 char *module_path
= obj_dir_path( make
, make
->module
);
3282 const char *debug_file
= NULL
;
3283 char *spec_file
= NULL
;
3286 if (!make
->is_exe
) spec_file
= src_dir_path( make
, replace_extension( make
->module
, ".dll", ".spec" ));
3287 strarray_addall( &all_libs
, add_import_libs( make
, &dep_libs
, make
->delayimports
, 1, 0 ));
3288 strarray_addall( &all_libs
, add_import_libs( make
, &dep_libs
, make
->imports
, 0, 0 ));
3289 add_import_libs( make
, &dep_libs
, get_default_imports( make
), 0, 0 ); /* dependencies only */
3293 if (delay_load_flag
)
3295 for (i
= 0; i
< make
->delayimports
.count
; i
++)
3296 strarray_add( &all_libs
, strmake( "%s%s%s", delay_load_flag
, make
->delayimports
.str
[i
],
3297 strchr( make
->delayimports
.str
[i
], '.' ) ? "" : ".dll" ));
3299 strarray_add( &make
->all_targets
, strmake( "%s", make
->module
));
3300 add_install_rule( make
, make
->module
, strmake( "%s", make
->module
),
3301 strmake( "c$(dlldir)/%s", make
->module
));
3302 debug_file
= get_debug_file( make
, make
->module
);
3303 output( "%s:", module_path
);
3307 if (!make
->use_msvcrt
) strarray_addall( &all_libs
, add_unix_libraries( make
, &dep_libs
));
3308 for (i
= 0; i
< make
->delayimports
.count
; i
++)
3309 strarray_add( &all_libs
, strmake( "-Wl,-delayload,%s%s", make
->delayimports
.str
[i
],
3310 strchr( make
->delayimports
.str
[i
], '.' ) ? "" : ".dll" ));
3311 strarray_add( &make
->all_targets
, strmake( "%s%s", make
->module
, dll_ext
));
3312 strarray_add( &make
->all_targets
, strmake( "%s.fake", make
->module
));
3313 add_install_rule( make
, make
->module
, strmake( "%s%s", make
->module
, dll_ext
),
3314 strmake( "p$(dlldir)/%s%s", make
->module
, dll_ext
));
3315 add_install_rule( make
, make
->module
, strmake( "%s.fake", make
->module
),
3316 strmake( "d$(dlldir)/fakedlls/%s", make
->module
));
3317 output( "%s%s %s.fake:", module_path
, dll_ext
, module_path
);
3321 strarray_addall( &all_libs
, add_unix_libraries( make
, &dep_libs
));
3322 strarray_add( &make
->all_targets
, make
->module
);
3323 add_install_rule( make
, make
->module
, make
->module
,
3324 strmake( "p$(%s)/%s", spec_file
? "dlldir" : "bindir", make
->module
));
3325 debug_file
= get_debug_file( make
, make
->module
);
3326 output( "%s:", module_path
);
3329 if (spec_file
) output_filename( spec_file
);
3330 output_filenames_obj_dir( make
, make
->is_cross
? make
->crossobj_files
: make
->object_files
);
3331 output_filenames_obj_dir( make
, make
->res_files
);
3332 output_filenames( dep_libs
);
3333 output_filename( tools_path( make
, "winebuild" ));
3334 output_filename( tools_path( make
, "winegcc" ));
3336 output_winegcc_command( make
, make
->is_cross
);
3337 if (make
->is_cross
) output_filename( "-Wl,--wine-builtin" );
3340 output_filename( "-shared" );
3341 output_filename( spec_file
);
3343 output_filenames( make
->extradllflags
);
3344 output_filenames_obj_dir( make
, make
->is_cross
? make
->crossobj_files
: make
->object_files
);
3345 output_filenames_obj_dir( make
, make
->res_files
);
3346 if (debug_file
) output_filename( strmake( "-Wl,--debug-file,%s", obj_dir_path( make
, debug_file
)));
3347 output_filenames( all_libs
);
3348 output_filename( make
->is_cross
? "$(CROSSLDFLAGS)" : "$(LDFLAGS)" );
3351 if (make
->unixobj_files
.count
)
3353 struct strarray unix_imports
= empty_strarray
;
3354 struct strarray unix_libs
= empty_strarray
;
3355 struct strarray unix_deps
= empty_strarray
;
3356 char *ext
, *unix_lib
= xmalloc( strlen( make
->module
) + strlen( dll_ext
) + 1 );
3357 strcpy( unix_lib
, make
->module
);
3358 if ((ext
= get_extension( unix_lib
))) *ext
= 0;
3359 strcat( unix_lib
, dll_ext
);
3361 if (!strarray_exists( &make
->extradllflags
, "-nodefaultlibs" ))
3362 strarray_add( &unix_imports
, "ntdll" );
3363 strarray_add( &unix_imports
, "winecrt0" );
3365 strarray_addall( &unix_libs
, add_import_libs( make
, &unix_deps
, unix_imports
, 0, 1 ));
3366 strarray_addall( &unix_libs
, add_unix_libraries( make
, &unix_deps
));
3368 strarray_add( &make
->all_targets
, unix_lib
);
3369 add_install_rule( make
, make
->module
, unix_lib
, strmake( "p$(dlldir)/%s", unix_lib
));
3370 output( "%s:", obj_dir_path( make
, unix_lib
));
3371 if (spec_file
) output_filename( spec_file
);
3372 output_filenames_obj_dir( make
, make
->unixobj_files
);
3373 output_filenames( unix_deps
);
3374 output_filename( tools_path( make
, "winebuild" ));
3375 output_filename( tools_path( make
, "winegcc" ));
3377 output_winegcc_command( make
, 0 );
3378 output_filename( "-munix" );
3379 output_filename( "-shared" );
3380 if (spec_file
) output_filename( spec_file
);
3381 if (strarray_exists( &make
->extradllflags
, "-nodefaultlibs" )) output_filename( "-nodefaultlibs" );
3382 output_filenames_obj_dir( make
, make
->unixobj_files
);
3383 output_filenames( unix_libs
);
3384 output_filename( "$(LDFLAGS)" );
3388 if (spec_file
&& make
->importlib
)
3390 char *importlib_path
= obj_dir_path( make
, strmake( "lib%s", make
->importlib
));
3391 if (*dll_ext
&& !make
->implib_objs
.count
)
3393 strarray_add( &make
->clean_files
, strmake( "lib%s.def", make
->importlib
));
3394 output( "%s.def: %s %s\n", importlib_path
, tools_path( make
, "winebuild" ), spec_file
);
3395 output( "\t%s -w --def -o $@", tools_path( make
, "winebuild" ) );
3396 output_filenames( target_flags
);
3397 if (make
->is_win16
) output_filename( "-m16" );
3398 output_filename( "--export" );
3399 output_filename( spec_file
);
3401 add_install_rule( make
, make
->importlib
,
3402 strmake( "lib%s.def", make
->importlib
),
3403 strmake( "d$(dlldir)/lib%s.def", make
->importlib
));
3407 strarray_add( &make
->clean_files
, strmake( "lib%s.a", make
->importlib
));
3408 if (!*dll_ext
&& needs_delay_lib( make
))
3410 strarray_add( &make
->clean_files
, strmake( "lib%s.delay.a", make
->importlib
));
3411 output( "%s.delay.a ", importlib_path
);
3413 output( "%s.a: %s %s", importlib_path
, tools_path( make
, "winebuild" ), spec_file
);
3414 output_filenames_obj_dir( make
, make
->implib_objs
);
3416 output( "\t%s -w --implib -o $@", tools_path( make
, "winebuild" ) );
3417 output_filenames( target_flags
);
3418 if (make
->is_win16
) output_filename( "-m16" );
3419 output_filename( "--export" );
3420 output_filename( spec_file
);
3421 output_filenames_obj_dir( make
, make
->implib_objs
);
3423 add_install_rule( make
, make
->importlib
,
3424 strmake( "lib%s.a", make
->importlib
),
3425 strmake( "d$(dlldir)/lib%s.a", make
->importlib
));
3427 if (crosstarget
&& (needs_cross_lib( make
) || needs_delay_lib( make
)))
3429 struct strarray cross_files
= strarray_replace_extension( &make
->implib_objs
, ".o", ".cross.o" );
3430 if (needs_cross_lib( make
))
3432 strarray_add( &make
->clean_files
, strmake( "lib%s.cross.a", make
->importlib
));
3433 output_filename( strmake( "%s.cross.a", importlib_path
));
3435 if (needs_delay_lib( make
))
3437 strarray_add( &make
->clean_files
, strmake( "lib%s.delay.a", make
->importlib
));
3438 output_filename( strmake( "%s.delay.a", importlib_path
));
3440 output( ": %s %s", tools_path( make
, "winebuild" ), spec_file
);
3441 output_filenames_obj_dir( make
, cross_files
);
3443 output( "\t%s -b %s -w --implib -o $@", tools_path( make
, "winebuild" ), crosstarget
);
3444 if (make
->is_win16
) output_filename( "-m16" );
3445 output_filename( "--export" );
3446 output_filename( spec_file
);
3447 output_filenames_obj_dir( make
, cross_files
);
3450 if (needs_implib_symlink( make
))
3451 strarray_addall( &top_makefile
->clean_files
, output_importlib_symlinks( make
));
3455 output_man_pages( make
);
3456 else if (*dll_ext
&& !make
->is_win16
&& strendswith( make
->module
, ".exe" ))
3458 char *binary
= replace_extension( make
->module
, ".exe", "" );
3459 add_install_rule( make
, binary
, "wineapploader", strmake( "t$(bindir)/%s", binary
));
3464 /*******************************************************************
3467 static void output_static_lib( struct makefile
*make
)
3469 strarray_add( &make
->all_targets
, make
->staticlib
);
3470 output( "%s:", obj_dir_path( make
, make
->staticlib
));
3471 output_filenames_obj_dir( make
, make
->object_files
);
3472 output_filenames_obj_dir( make
, make
->unixobj_files
);
3473 output( "\n\trm -f $@\n" );
3474 output( "\t%s rc $@", ar
);
3475 output_filenames_obj_dir( make
, make
->object_files
);
3476 output_filenames_obj_dir( make
, make
->unixobj_files
);
3477 output( "\n\t%s $@\n", ranlib
);
3478 add_install_rule( make
, make
->staticlib
, make
->staticlib
,
3479 strmake( "d$(dlldir)/%s", make
->staticlib
));
3480 if (needs_cross_lib( make
))
3482 char *name
= replace_extension( make
->staticlib
, ".a", ".cross.a" );
3484 strarray_add( &make
->all_targets
, name
);
3485 output( "%s: %s", obj_dir_path( make
, name
), tools_path( make
, "winebuild" ));
3486 output_filenames_obj_dir( make
, make
->crossobj_files
);
3488 output( "\t%s -b %s -w --staticlib -o $@", tools_path( make
, "winebuild" ), crosstarget
);
3489 output_filenames_obj_dir( make
, make
->crossobj_files
);
3495 /*******************************************************************
3498 static void output_shared_lib( struct makefile
*make
)
3502 struct strarray names
= get_shared_lib_names( make
->sharedlib
);
3503 struct strarray all_libs
= empty_strarray
;
3504 struct strarray dep_libs
= empty_strarray
;
3506 basename
= xstrdup( make
->sharedlib
);
3507 if ((p
= strchr( basename
, '.' ))) *p
= 0;
3509 strarray_addall( &dep_libs
, get_local_dependencies( make
, basename
, make
->in_files
));
3510 strarray_addall( &all_libs
, get_expanded_file_local_var( make
, basename
, "LDFLAGS" ));
3511 strarray_addall( &all_libs
, add_unix_libraries( make
, &dep_libs
));
3513 output( "%s:", obj_dir_path( make
, make
->sharedlib
));
3514 output_filenames_obj_dir( make
, make
->object_files
);
3515 output_filenames( dep_libs
);
3517 output( "\t$(CC) -o $@" );
3518 output_filenames_obj_dir( make
, make
->object_files
);
3519 output_filenames( all_libs
);
3520 output_filename( "$(LDFLAGS)" );
3522 add_install_rule( make
, make
->sharedlib
, make
->sharedlib
,
3523 strmake( "p$(libdir)/%s", make
->sharedlib
));
3524 for (i
= 1; i
< names
.count
; i
++)
3526 output( "%s: %s\n", obj_dir_path( make
, names
.str
[i
] ), obj_dir_path( make
, names
.str
[i
-1] ));
3527 output_symlink_rule( names
.str
[i
-1], obj_dir_path( make
, names
.str
[i
] ), 0 );
3528 add_install_rule( make
, names
.str
[i
], names
.str
[i
-1],
3529 strmake( "y$(libdir)/%s", names
.str
[i
] ));
3531 strarray_addall( &make
->all_targets
, names
);
3535 /*******************************************************************
3536 * output_test_module
3538 static void output_test_module( struct makefile
*make
)
3540 char *testmodule
= replace_extension( make
->testdll
, ".dll", "_test.exe" );
3541 char *stripped
= replace_extension( make
->testdll
, ".dll", "_test-stripped.exe" );
3542 char *testres
= replace_extension( make
->testdll
, ".dll", "_test.res" );
3543 struct strarray dep_libs
= empty_strarray
;
3544 struct strarray all_libs
= add_import_libs( make
, &dep_libs
, make
->imports
, 0, 0 );
3545 struct makefile
*parent
= get_parent_makefile( make
);
3546 const char *ext
= make
->is_cross
? "" : dll_ext
;
3547 const char *parent_ext
= parent
&& parent
->is_cross
? "" : dll_ext
;
3548 const char *debug_file
;
3551 add_import_libs( make
, &dep_libs
, get_default_imports( make
), 0, 0 ); /* dependencies only */
3552 strarray_add( &make
->all_targets
, strmake( "%s%s", testmodule
, ext
));
3553 strarray_add( &make
->clean_files
, strmake( "%s%s", stripped
, ext
));
3554 output_file
= strmake( "%s%s", obj_dir_path( make
, testmodule
), ext
);
3555 output( "%s:\n", output_file
);
3556 output_winegcc_command( make
, make
->is_cross
);
3557 output_filenames( make
->extradllflags
);
3558 output_filenames_obj_dir( make
, make
->is_cross
? make
->crossobj_files
: make
->object_files
);
3559 output_filenames_obj_dir( make
, make
->res_files
);
3560 if ((debug_file
= get_debug_file( make
, testmodule
)))
3561 output_filename( strmake( "-Wl,--debug-file,%s", obj_dir_path( make
, debug_file
)));
3562 output_filenames( all_libs
);
3563 output_filename( make
->is_cross
? "$(CROSSLDFLAGS)" : "$(LDFLAGS)" );
3565 output( "%s%s:\n", obj_dir_path( make
, stripped
), ext
);
3566 output_winegcc_command( make
, make
->is_cross
);
3567 output_filename( "-s" );
3568 output_filename( strmake( "-Wb,-F,%s", testmodule
));
3569 output_filenames( make
->extradllflags
);
3570 output_filenames_obj_dir( make
, make
->is_cross
? make
->crossobj_files
: make
->object_files
);
3571 output_filenames_obj_dir( make
, make
->res_files
);
3572 output_filenames( all_libs
);
3573 output_filename( make
->is_cross
? "$(CROSSLDFLAGS)" : "$(LDFLAGS)" );
3575 output( "%s%s %s%s:", obj_dir_path( make
, testmodule
), ext
, obj_dir_path( make
, stripped
), ext
);
3576 output_filenames_obj_dir( make
, make
->is_cross
? make
->crossobj_files
: make
->object_files
);
3577 output_filenames_obj_dir( make
, make
->res_files
);
3578 output_filenames( dep_libs
);
3579 output_filename( tools_path( make
, "winebuild" ));
3580 output_filename( tools_path( make
, "winegcc" ));
3583 output( "programs/winetest/%s: %s%s\n", testres
, obj_dir_path( make
, stripped
), ext
);
3584 output( "\techo \"%s TESTRES \\\"%s%s\\\"\" | %s -u -o $@\n",
3585 testmodule
, obj_dir_path( make
, stripped
), ext
, tools_path( make
, "wrc" ));
3587 output_filenames_obj_dir( make
, make
->ok_files
);
3588 output( ": %s%s", obj_dir_path( make
, testmodule
), ext
);
3589 if (parent
) output( " %s%s", obj_dir_path( parent
, make
->testdll
), parent_ext
);
3591 output( "%s %s:", obj_dir_path( make
, "check" ), obj_dir_path( make
, "test" ));
3592 if (!make
->disabled
&& parent
&& !parent
->disabled
) output_filenames_obj_dir( make
, make
->ok_files
);
3594 strarray_add_uniq( &make
->phony_targets
, obj_dir_path( make
, "check" ));
3595 strarray_add_uniq( &make
->phony_targets
, obj_dir_path( make
, "test" ));
3596 output( "%s::\n", obj_dir_path( make
, "testclean" ));
3597 output( "\trm -f" );
3598 output_filenames_obj_dir( make
, make
->ok_files
);
3600 strarray_addall( &make
->clean_files
, make
->ok_files
);
3601 strarray_add_uniq( &make
->phony_targets
, obj_dir_path( make
, "testclean" ));
3605 /*******************************************************************
3608 static void output_programs( struct makefile
*make
)
3612 for (i
= 0; i
< make
->programs
.count
; i
++)
3614 char *program_installed
= NULL
;
3615 char *program
= strmake( "%s%s", make
->programs
.str
[i
], exe_ext
);
3616 struct strarray deps
= get_local_dependencies( make
, make
->programs
.str
[i
], make
->in_files
);
3617 struct strarray all_libs
= get_expanded_file_local_var( make
, make
->programs
.str
[i
], "LDFLAGS" );
3618 struct strarray objs
= get_expanded_file_local_var( make
, make
->programs
.str
[i
], "OBJS" );
3619 struct strarray symlinks
= get_expanded_file_local_var( make
, make
->programs
.str
[i
], "SYMLINKS" );
3621 if (!objs
.count
) objs
= make
->object_files
;
3622 if (!strarray_exists( &all_libs
, "-nodefaultlibs" ))
3623 strarray_addall( &all_libs
, add_unix_libraries( make
, &deps
));
3625 output( "%s:", obj_dir_path( make
, program
) );
3626 output_filenames_obj_dir( make
, objs
);
3627 output_filenames( deps
);
3629 output( "\t$(CC) -o $@" );
3630 output_filenames_obj_dir( make
, objs
);
3631 output_filenames( all_libs
);
3632 output_filename( "$(LDFLAGS)" );
3634 strarray_add( &make
->all_targets
, program
);
3636 for (j
= 0; j
< symlinks
.count
; j
++)
3638 output( "%s: %s\n", obj_dir_path( make
, symlinks
.str
[j
] ), obj_dir_path( make
, program
));
3639 output_symlink_rule( program
, obj_dir_path( make
, symlinks
.str
[j
] ), 0 );
3641 strarray_addall( &make
->all_targets
, symlinks
);
3643 add_install_rule( make
, program
, program_installed
? program_installed
: program
,
3644 strmake( "p$(bindir)/%s", program
));
3645 for (j
= 0; j
< symlinks
.count
; j
++)
3646 add_install_rule( make
, symlinks
.str
[j
], program
,
3647 strmake( "y$(bindir)/%s%s", symlinks
.str
[j
], exe_ext
));
3652 /*******************************************************************
3655 static void output_subdirs( struct makefile
*make
)
3657 struct strarray all_targets
= empty_strarray
;
3658 struct strarray makefile_deps
= empty_strarray
;
3659 struct strarray clean_files
= empty_strarray
;
3660 struct strarray testclean_files
= empty_strarray
;
3661 struct strarray distclean_files
= empty_strarray
;
3662 struct strarray dependencies
= empty_strarray
;
3663 struct strarray install_lib_deps
= empty_strarray
;
3664 struct strarray install_dev_deps
= empty_strarray
;
3665 struct strarray tooldeps_deps
= empty_strarray
;
3666 struct strarray buildtest_deps
= empty_strarray
;
3669 strarray_addall( &clean_files
, make
->clean_files
);
3670 strarray_addall( &distclean_files
, make
->distclean_files
);
3671 strarray_addall( &all_targets
, make
->all_targets
);
3672 for (i
= 0; i
< subdirs
.count
; i
++)
3674 strarray_add( &makefile_deps
, src_dir_path( submakes
[i
], strmake ( "%s.in", output_makefile_name
)));
3675 strarray_addall_uniq( &make
->phony_targets
, submakes
[i
]->phony_targets
);
3676 strarray_addall_uniq( &make
->uninstall_files
, submakes
[i
]->uninstall_files
);
3677 strarray_addall_uniq( &dependencies
, submakes
[i
]->dependencies
);
3678 strarray_addall_path( &clean_files
, submakes
[i
]->obj_dir
, submakes
[i
]->clean_files
);
3679 strarray_addall_path( &distclean_files
, submakes
[i
]->obj_dir
, submakes
[i
]->distclean_files
);
3680 strarray_addall_path( &testclean_files
, submakes
[i
]->obj_dir
, submakes
[i
]->ok_files
);
3681 strarray_addall_path( &make
->pot_files
, submakes
[i
]->obj_dir
, submakes
[i
]->pot_files
);
3683 if (submakes
[i
]->disabled
) continue;
3685 strarray_addall_path( &all_targets
, submakes
[i
]->obj_dir
, submakes
[i
]->all_targets
);
3686 if (!strcmp( submakes
[i
]->obj_dir
, "tools" ) || !strncmp( submakes
[i
]->obj_dir
, "tools/", 6 ))
3687 strarray_add( &tooldeps_deps
, obj_dir_path( submakes
[i
], "all" ));
3688 if (submakes
[i
]->testdll
)
3689 strarray_add( &buildtest_deps
, obj_dir_path( submakes
[i
], "all" ));
3690 if (submakes
[i
]->install_rules
[INSTALL_LIB
].count
)
3691 strarray_add( &install_lib_deps
, obj_dir_path( submakes
[i
], "install-lib" ));
3692 if (submakes
[i
]->install_rules
[INSTALL_DEV
].count
)
3693 strarray_add( &install_dev_deps
, obj_dir_path( submakes
[i
], "install-dev" ));
3695 strarray_addall( &dependencies
, makefile_deps
);
3697 output_filenames( all_targets
);
3699 output( "Makefile:" );
3700 output_filenames( makefile_deps
);
3702 output_filenames( dependencies
);
3704 if (install_lib_deps
.count
)
3706 output( "install install-lib::" );
3707 output_filenames( install_lib_deps
);
3709 strarray_add_uniq( &make
->phony_targets
, "install" );
3710 strarray_add_uniq( &make
->phony_targets
, "install-lib" );
3712 if (install_dev_deps
.count
)
3714 output( "install install-dev::" );
3715 output_filenames( install_dev_deps
);
3717 strarray_add_uniq( &make
->phony_targets
, "install" );
3718 strarray_add_uniq( &make
->phony_targets
, "install-dev" );
3720 output_uninstall_rules( make
);
3721 if (buildtest_deps
.count
)
3723 output( "buildtests:" );
3724 output_filenames( buildtest_deps
);
3726 strarray_add_uniq( &make
->phony_targets
, "buildtests" );
3728 output( "check test:" );
3729 output_filenames( testclean_files
);
3731 strarray_add_uniq( &make
->phony_targets
, "check" );
3732 strarray_add_uniq( &make
->phony_targets
, "test" );
3734 output( "clean::\n");
3735 output_rm_filenames( clean_files
);
3736 output( "testclean::\n");
3737 output_rm_filenames( testclean_files
);
3738 output( "distclean::\n");
3739 output_rm_filenames( distclean_files
);
3740 strarray_add_uniq( &make
->phony_targets
, "distclean" );
3741 strarray_add_uniq( &make
->phony_targets
, "testclean" );
3743 if (tooldeps_deps
.count
)
3745 output( "__tooldeps__:" );
3746 output_filenames( tooldeps_deps
);
3748 strarray_add_uniq( &make
->phony_targets
, "__tooldeps__" );
3751 if (get_expanded_make_variable( make
, "GETTEXTPO_LIBS" )) output_po_files( make
);
3753 if (make
->phony_targets
.count
)
3755 output( ".PHONY:" );
3756 output_filenames( make
->phony_targets
);
3762 /*******************************************************************
3765 static void output_sources( struct makefile
*make
)
3767 struct strarray all_targets
= empty_strarray
;
3768 struct incl_file
*source
;
3771 strarray_add_uniq( &make
->phony_targets
, "all" );
3773 LIST_FOR_EACH_ENTRY( source
, &make
->sources
, struct incl_file
, entry
)
3775 char *obj
= xstrdup( source
->name
);
3776 char *ext
= get_extension( obj
);
3778 if (!ext
) fatal_error( "unsupported file type %s\n", source
->name
);
3781 for (j
= 0; output_source_funcs
[j
].ext
; j
++)
3782 if (!strcmp( ext
, output_source_funcs
[j
].ext
)) break;
3784 output_source_funcs
[j
].fn( make
, source
, obj
);
3785 strarray_addall_uniq( &make
->dependencies
, source
->dependencies
);
3788 /* special case for winetest: add resource files from other test dirs */
3789 if (make
->obj_dir
&& !strcmp( make
->obj_dir
, "programs/winetest" ))
3791 struct strarray tests
= enable_tests
;
3793 for (i
= 0; i
< subdirs
.count
; i
++)
3794 if (submakes
[i
]->testdll
&& !submakes
[i
]->disabled
)
3795 strarray_add( &tests
, submakes
[i
]->testdll
);
3796 for (i
= 0; i
< tests
.count
; i
++)
3797 strarray_add( &make
->res_files
, replace_extension( tests
.str
[i
], ".dll", "_test.res" ));
3800 if (make
->dlldata_files
.count
)
3802 output( "%s: %s %s\n", obj_dir_path( make
, "dlldata.c" ),
3803 tools_path( make
, "widl" ), src_dir_path( make
, "Makefile.in" ));
3804 output( "\t%s --dlldata-only -o $@", tools_path( make
, "widl" ));
3805 output_filenames( make
->dlldata_files
);
3809 if (make
->staticlib
) output_static_lib( make
);
3810 else if (make
->module
) output_module( make
);
3811 else if (make
->testdll
) output_test_module( make
);
3812 else if (make
->sharedlib
) output_shared_lib( make
);
3813 else if (make
->programs
.count
) output_programs( make
);
3815 for (i
= 0; i
< make
->scripts
.count
; i
++)
3816 add_install_rule( make
, make
->scripts
.str
[i
], make
->scripts
.str
[i
],
3817 strmake( "S$(bindir)/%s", make
->scripts
.str
[i
] ));
3819 for (i
= 0; i
< make
->extra_targets
.count
; i
++)
3820 if (strarray_exists( &make
->dependencies
, obj_dir_path( make
, make
->extra_targets
.str
[i
] )))
3821 strarray_add( &make
->clean_files
, make
->extra_targets
.str
[i
] );
3823 strarray_add( &make
->all_targets
, make
->extra_targets
.str
[i
] );
3825 if (!make
->src_dir
) strarray_add( &make
->distclean_files
, ".gitignore" );
3826 strarray_add( &make
->distclean_files
, "Makefile" );
3827 if (make
->testdll
) strarray_add( &make
->distclean_files
, "testlist.c" );
3830 strarray_addall( &make
->distclean_files
, get_expanded_make_var_array( make
, "CONFIGURE_TARGETS" ));
3831 else if (!strcmp( make
->obj_dir
, "po" ))
3832 strarray_add( &make
->distclean_files
, "LINGUAS" );
3834 strarray_addall( &make
->clean_files
, make
->object_files
);
3835 strarray_addall( &make
->clean_files
, make
->crossobj_files
);
3836 strarray_addall( &make
->clean_files
, make
->unixobj_files
);
3837 strarray_addall( &make
->clean_files
, make
->res_files
);
3838 strarray_addall( &make
->clean_files
, make
->pot_files
);
3839 strarray_addall( &make
->clean_files
, make
->debug_files
);
3840 strarray_addall( &make
->clean_files
, make
->all_targets
);
3842 if (make
== top_makefile
)
3844 output_subdirs( make
);
3848 strarray_addall( &all_targets
, make
->all_targets
);
3849 strarray_addall( &all_targets
, make
->font_files
);
3850 if (all_targets
.count
)
3852 output( "%s:", obj_dir_path( make
, "all" ));
3853 output_filenames_obj_dir( make
, all_targets
);
3855 strarray_add_uniq( &make
->phony_targets
, obj_dir_path( make
, "all" ));
3857 output_install_rules( make
, INSTALL_LIB
, "install-lib" );
3858 output_install_rules( make
, INSTALL_DEV
, "install-dev" );
3860 if (make
->clean_files
.count
)
3862 output( "%s::\n", obj_dir_path( make
, "clean" ));
3863 output( "\trm -f" );
3864 output_filenames_obj_dir( make
, make
->clean_files
);
3866 strarray_add( &make
->phony_targets
, obj_dir_path( make
, "clean" ));
3871 /*******************************************************************
3874 static FILE *create_temp_file( const char *orig
)
3876 char *name
= xmalloc( strlen(orig
) + 13 );
3877 unsigned int i
, id
= getpid();
3881 for (i
= 0; i
< 100; i
++)
3883 sprintf( name
, "%s.tmp%08x", orig
, id
);
3884 if ((fd
= open( name
, O_RDWR
| O_CREAT
| O_EXCL
, 0666 )) != -1)
3886 ret
= fdopen( fd
, "w" );
3889 if (errno
!= EEXIST
) break;
3892 if (!ret
) fatal_error( "failed to create output file for '%s'\n", orig
);
3893 temp_file_name
= name
;
3898 /*******************************************************************
3901 static void rename_temp_file( const char *dest
)
3903 int ret
= rename( temp_file_name
, dest
);
3904 if (ret
== -1 && errno
== EEXIST
)
3906 /* rename doesn't overwrite on windows */
3908 ret
= rename( temp_file_name
, dest
);
3910 if (ret
== -1) fatal_error( "failed to rename output file to '%s'\n", dest
);
3911 temp_file_name
= NULL
;
3915 /*******************************************************************
3916 * are_files_identical
3918 static int are_files_identical( FILE *file1
, FILE *file2
)
3922 char buffer1
[8192], buffer2
[8192];
3923 int size1
= fread( buffer1
, 1, sizeof(buffer1
), file1
);
3924 int size2
= fread( buffer2
, 1, sizeof(buffer2
), file2
);
3925 if (size1
!= size2
) return 0;
3926 if (!size1
) return feof( file1
) && feof( file2
);
3927 if (memcmp( buffer1
, buffer2
, size1
)) return 0;
3932 /*******************************************************************
3933 * rename_temp_file_if_changed
3935 static void rename_temp_file_if_changed( const char *dest
)
3937 FILE *file1
, *file2
;
3940 if ((file1
= fopen( dest
, "r" )))
3942 if ((file2
= fopen( temp_file_name
, "r" )))
3944 do_rename
= !are_files_identical( file1
, file2
);
3951 unlink( temp_file_name
);
3952 temp_file_name
= NULL
;
3954 else rename_temp_file( dest
);
3958 /*******************************************************************
3961 static void output_linguas( const struct makefile
*make
)
3963 const char *dest
= obj_dir_path( make
, "LINGUAS" );
3964 struct incl_file
*source
;
3966 output_file
= create_temp_file( dest
);
3968 output( "# Automatically generated by make depend; DO NOT EDIT!!\n" );
3969 LIST_FOR_EACH_ENTRY( source
, &make
->sources
, struct incl_file
, entry
)
3970 if (strendswith( source
->name
, ".po" ))
3971 output( "%s\n", replace_extension( source
->name
, ".po", "" ));
3973 if (fclose( output_file
)) fatal_perror( "write" );
3975 rename_temp_file_if_changed( dest
);
3979 /*******************************************************************
3982 static void output_testlist( const struct makefile
*make
)
3984 const char *dest
= obj_dir_path( make
, "testlist.c" );
3985 struct strarray files
= empty_strarray
;
3988 for (i
= 0; i
< make
->ok_files
.count
; i
++)
3989 strarray_add( &files
, replace_extension( make
->ok_files
.str
[i
], ".ok", "" ));
3991 output_file
= create_temp_file( dest
);
3993 output( "/* Automatically generated by make depend; DO NOT EDIT!! */\n\n" );
3994 output( "#define WIN32_LEAN_AND_MEAN\n" );
3995 output( "#include <windows.h>\n\n" );
3996 output( "#define STANDALONE\n" );
3997 output( "#include \"wine/test.h\"\n\n" );
3999 for (i
= 0; i
< files
.count
; i
++) output( "extern void func_%s(void);\n", files
.str
[i
] );
4001 output( "const struct test winetest_testlist[] =\n" );
4003 for (i
= 0; i
< files
.count
; i
++) output( " { \"%s\", func_%s },\n", files
.str
[i
], files
.str
[i
] );
4004 output( " { 0, 0 }\n" );
4007 if (fclose( output_file
)) fatal_perror( "write" );
4009 rename_temp_file_if_changed( dest
);
4013 /*******************************************************************
4016 static void output_gitignore( const char *dest
, struct strarray files
)
4020 output_file
= create_temp_file( dest
);
4022 output( "# Automatically generated by make depend; DO NOT EDIT!!\n" );
4023 for (i
= 0; i
< files
.count
; i
++)
4025 if (!strchr( files
.str
[i
], '/' )) output( "/" );
4026 output( "%s\n", files
.str
[i
] );
4029 if (fclose( output_file
)) fatal_perror( "write" );
4031 rename_temp_file( dest
);
4035 /*******************************************************************
4036 * output_stub_makefile
4038 static void output_stub_makefile( struct makefile
*make
)
4040 struct strarray targets
= empty_strarray
;
4041 const char *make_var
= strarray_get_value( &top_makefile
->vars
, "MAKE" );
4043 if (make_var
) output( "MAKE = %s\n\n", make_var
);
4046 if (make
->all_targets
.count
) strarray_add( &targets
, "all" );
4047 if (make
->install_rules
[INSTALL_LIB
].count
|| make
->install_rules
[INSTALL_DEV
].count
)
4048 strarray_add( &targets
, "install" );
4049 if (make
->install_rules
[INSTALL_LIB
].count
) strarray_add( &targets
, "install-lib" );
4050 if (make
->install_rules
[INSTALL_DEV
].count
) strarray_add( &targets
, "install-dev" );
4051 if (make
->clean_files
.count
) strarray_add( &targets
, "clean" );
4052 if (make
->ok_files
.count
)
4054 strarray_add( &targets
, "check" );
4055 strarray_add( &targets
, "test" );
4056 strarray_add( &targets
, "testclean" );
4059 output_filenames( targets
);
4060 output_filenames( make
->clean_files
);
4062 output( "\t@cd %s && $(MAKE) %s/$@\n", get_relative_path( make
->obj_dir
, "" ), make
->obj_dir
);
4063 output( ".PHONY:" );
4064 output_filenames( targets
);
4069 /*******************************************************************
4070 * output_dependencies
4072 static void output_dependencies( struct makefile
*make
)
4074 struct strarray ignore_files
= empty_strarray
;
4079 if (make
->obj_dir
) create_dir( make
->obj_dir
);
4081 output_file_name
= obj_dir_path( make
, output_makefile_name
);
4082 output_file
= create_temp_file( output_file_name
);
4084 /* copy the contents of the source makefile */
4085 src_file
= open_input_makefile( make
);
4086 while (fgets( buffer
, sizeof(buffer
), src_file
) && !found
)
4088 if (fwrite( buffer
, 1, strlen(buffer
), output_file
) != strlen(buffer
)) fatal_perror( "write" );
4089 found
= !strncmp( buffer
, separator
, strlen(separator
) );
4091 if (fclose( src_file
)) fatal_perror( "close" );
4092 input_file_name
= NULL
;
4094 if (!found
) output( "\n%s (everything below this line is auto-generated; DO NOT EDIT!!)\n", separator
);
4096 if (make
== top_makefile
)
4098 for (i
= 0; i
< subdirs
.count
; i
++) output_sources( submakes
[i
] );
4099 output_sources( make
);
4101 else output_stub_makefile( make
);
4103 /* disable implicit rules */
4104 output( ".SUFFIXES:\n" );
4106 fclose( output_file
);
4108 rename_temp_file( output_file_name
);
4110 strarray_addall( &ignore_files
, make
->distclean_files
);
4111 strarray_addall( &ignore_files
, make
->clean_files
);
4112 if (make
->testdll
) output_testlist( make
);
4113 if (make
->obj_dir
&& !strcmp( make
->obj_dir
, "po" )) output_linguas( make
);
4114 if (!make
->src_dir
) output_gitignore( obj_dir_path( make
, ".gitignore" ), ignore_files
);
4116 create_file_directories( make
, ignore_files
);
4118 output_file_name
= NULL
;
4122 /*******************************************************************
4125 static void load_sources( struct makefile
*make
)
4127 static const char *source_vars
[] =
4148 struct strarray value
;
4149 struct incl_file
*file
;
4151 strarray_set_value( &make
->vars
, "top_srcdir", root_src_dir_path( "" ));
4152 strarray_set_value( &make
->vars
, "srcdir", src_dir_path( make
, "" ));
4154 make
->parent_dir
= get_expanded_make_variable( make
, "PARENTSRC" );
4155 make
->module
= get_expanded_make_variable( make
, "MODULE" );
4156 make
->testdll
= get_expanded_make_variable( make
, "TESTDLL" );
4157 make
->sharedlib
= get_expanded_make_variable( make
, "SHAREDLIB" );
4158 make
->staticlib
= get_expanded_make_variable( make
, "STATICLIB" );
4159 make
->importlib
= get_expanded_make_variable( make
, "IMPORTLIB" );
4161 make
->programs
= get_expanded_make_var_array( make
, "PROGRAMS" );
4162 make
->scripts
= get_expanded_make_var_array( make
, "SCRIPTS" );
4163 make
->imports
= get_expanded_make_var_array( make
, "IMPORTS" );
4164 make
->delayimports
= get_expanded_make_var_array( make
, "DELAYIMPORTS" );
4165 make
->extradllflags
= get_expanded_make_var_array( make
, "EXTRADLLFLAGS" );
4166 make
->install_lib
= get_expanded_make_var_array( make
, "INSTALL_LIB" );
4167 make
->install_dev
= get_expanded_make_var_array( make
, "INSTALL_DEV" );
4168 make
->extra_targets
= get_expanded_make_var_array( make
, "EXTRA_TARGETS" );
4170 if (make
->module
&& strendswith( make
->module
, ".a" )) make
->staticlib
= make
->module
;
4172 make
->is_win16
= strarray_exists( &make
->extradllflags
, "-m16" );
4173 if ((make
->module
&& make
->staticlib
) || make
->testdll
|| make
->is_win16
)
4174 strarray_add_uniq( &make
->extradllflags
, "-mno-cygwin" );
4176 strarray_addall( &make
->extradllflags
, get_expanded_make_var_array( make
, "APPMODE" ));
4177 make
->disabled
= make
->obj_dir
&& strarray_exists( &disabled_dirs
, make
->obj_dir
);
4178 make
->use_msvcrt
= strarray_exists( &make
->extradllflags
, "-mno-cygwin" );
4179 make
->is_exe
= strarray_exists( &make
->extradllflags
, "-mconsole" ) ||
4180 strarray_exists( &make
->extradllflags
, "-mwindows" );
4182 if (make
->module
&& !make
->install_lib
.count
&& !make
->install_dev
.count
)
4184 if (make
->importlib
) strarray_add( &make
->install_dev
, make
->importlib
);
4185 if (make
->staticlib
) strarray_add( &make
->install_dev
, make
->staticlib
);
4186 else strarray_add( &make
->install_lib
, make
->module
);
4189 make
->include_paths
= empty_strarray
;
4190 make
->include_args
= empty_strarray
;
4191 make
->define_args
= empty_strarray
;
4192 strarray_add( &make
->define_args
, "-D__WINESRC__" );
4194 value
= get_expanded_make_var_array( make
, "EXTRAINCL" );
4195 for (i
= 0; i
< value
.count
; i
++)
4196 if (!strncmp( value
.str
[i
], "-I", 2 ))
4197 strarray_add_uniq( &make
->include_paths
, value
.str
[i
] + 2 );
4199 strarray_add_uniq( &make
->define_args
, value
.str
[i
] );
4200 strarray_addall( &make
->define_args
, get_expanded_make_var_array( make
, "EXTRADEFS" ));
4202 strarray_add( &make
->include_args
, strmake( "-I%s", obj_dir_path( make
, "" )));
4204 strarray_add( &make
->include_args
, strmake( "-I%s", make
->src_dir
));
4205 if (make
->parent_dir
)
4206 strarray_add( &make
->include_args
, strmake( "-I%s", src_dir_path( make
, make
->parent_dir
)));
4207 strarray_add( &make
->include_args
, "-Iinclude" );
4208 if (root_src_dir
) strarray_add( &make
->include_args
, strmake( "-I%s", root_src_dir_path( "include" )));
4210 list_init( &make
->sources
);
4211 list_init( &make
->includes
);
4213 for (var
= source_vars
; *var
; var
++)
4215 value
= get_expanded_make_var_array( make
, *var
);
4216 for (i
= 0; i
< value
.count
; i
++) add_src_file( make
, value
.str
[i
] );
4219 add_generated_sources( make
);
4221 if (!make
->use_msvcrt
&& !has_object_file( make
))
4223 strarray_add( &make
->extradllflags
, "-mno-cygwin" );
4224 make
->use_msvcrt
= 1;
4227 if (make
->use_msvcrt
) add_crt_import( make
, &make
->imports
, &make
->define_args
);
4229 LIST_FOR_EACH_ENTRY( file
, &make
->includes
, struct incl_file
, entry
) parse_file( make
, file
, 0 );
4230 LIST_FOR_EACH_ENTRY( file
, &make
->sources
, struct incl_file
, entry
) get_dependencies( file
, file
);
4232 make
->is_cross
= crosstarget
&& make
->use_msvcrt
;
4236 strarray_addall_uniq( &cross_import_libs
, make
->imports
);
4237 strarray_addall_uniq( &cross_import_libs
, make
->extra_imports
);
4238 if (make
->is_win16
) strarray_add_uniq( &cross_import_libs
, "kernel" );
4239 strarray_add_uniq( &cross_import_libs
, "winecrt0" );
4240 strarray_add_uniq( &cross_import_libs
, "kernel32" );
4241 strarray_add_uniq( &cross_import_libs
, "ntdll" );
4244 if (!*dll_ext
|| make
->is_cross
)
4245 for (i
= 0; i
< make
->delayimports
.count
; i
++)
4246 strarray_add_uniq( &delay_import_libs
, get_base_name( make
->delayimports
.str
[i
] ));
4250 /*******************************************************************
4253 static void parse_makeflags( const char *flags
)
4255 const char *p
= flags
;
4256 char *var
, *buffer
= xmalloc( strlen(flags
) + 1 );
4260 while (isspace(*p
)) p
++;
4262 while (*p
&& !isspace(*p
))
4264 if (*p
== '\\' && p
[1]) p
++;
4268 if (var
> buffer
) set_make_variable( &cmdline_vars
, buffer
);
4273 /*******************************************************************
4276 static int parse_option( const char *opt
)
4280 if (strchr( opt
, '=' )) return set_make_variable( &cmdline_vars
, opt
);
4286 if (opt
[2]) output_makefile_name
= opt
+ 2;
4289 relative_dir_mode
= 1;
4292 fprintf( stderr
, "Unknown option '%s'\n%s", opt
, Usage
);
4299 /*******************************************************************
4302 int main( int argc
, char *argv
[] )
4304 const char *makeflags
= getenv( "MAKEFLAGS" );
4307 if (makeflags
) parse_makeflags( makeflags
);
4312 if (parse_option( argv
[i
] ))
4314 for (j
= i
; j
< argc
; j
++) argv
[j
] = argv
[j
+1];
4320 if (relative_dir_mode
)
4326 fprintf( stderr
, "Option -R needs two directories\n%s", Usage
);
4329 relpath
= get_relative_path( argv
[1], argv
[2] );
4330 printf( "%s\n", relpath
? relpath
: "." );
4334 if (argc
> 1) fatal_error( "Directory arguments not supported in this mode\n" );
4336 atexit( cleanup_files
);
4337 signal( SIGTERM
, exit_on_signal
);
4338 signal( SIGINT
, exit_on_signal
);
4340 signal( SIGHUP
, exit_on_signal
);
4343 for (i
= 0; i
< HASH_SIZE
; i
++) list_init( &files
[i
] );
4345 top_makefile
= parse_makefile( NULL
);
4347 target_flags
= get_expanded_make_var_array( top_makefile
, "TARGETFLAGS" );
4348 msvcrt_flags
= get_expanded_make_var_array( top_makefile
, "MSVCRTFLAGS" );
4349 dll_flags
= get_expanded_make_var_array( top_makefile
, "DLLFLAGS" );
4350 extra_cflags
= get_expanded_make_var_array( top_makefile
, "EXTRACFLAGS" );
4351 extra_cross_cflags
= get_expanded_make_var_array( top_makefile
, "EXTRACROSSCFLAGS" );
4352 cpp_flags
= get_expanded_make_var_array( top_makefile
, "CPPFLAGS" );
4353 lddll_flags
= get_expanded_make_var_array( top_makefile
, "LDDLLFLAGS" );
4354 libs
= get_expanded_make_var_array( top_makefile
, "LIBS" );
4355 enable_tests
= get_expanded_make_var_array( top_makefile
, "ENABLE_TESTS" );
4356 delay_load_flag
= get_expanded_make_variable( top_makefile
, "DELAYLOADFLAG" );
4357 top_install_lib
= get_expanded_make_var_array( top_makefile
, "TOP_INSTALL_LIB" );
4358 top_install_dev
= get_expanded_make_var_array( top_makefile
, "TOP_INSTALL_DEV" );
4360 root_src_dir
= get_expanded_make_variable( top_makefile
, "srcdir" );
4361 tools_dir
= get_expanded_make_variable( top_makefile
, "TOOLSDIR" );
4362 tools_ext
= get_expanded_make_variable( top_makefile
, "TOOLSEXT" );
4363 exe_ext
= get_expanded_make_variable( top_makefile
, "EXEEXT" );
4364 man_ext
= get_expanded_make_variable( top_makefile
, "api_manext" );
4365 dll_ext
= (exe_ext
&& !strcmp( exe_ext
, ".exe" )) ? "" : ".so";
4366 crosstarget
= get_expanded_make_variable( top_makefile
, "CROSSTARGET" );
4367 crossdebug
= get_expanded_make_variable( top_makefile
, "CROSSDEBUG" );
4368 fontforge
= get_expanded_make_variable( top_makefile
, "FONTFORGE" );
4369 convert
= get_expanded_make_variable( top_makefile
, "CONVERT" );
4370 flex
= get_expanded_make_variable( top_makefile
, "FLEX" );
4371 bison
= get_expanded_make_variable( top_makefile
, "BISON" );
4372 ar
= get_expanded_make_variable( top_makefile
, "AR" );
4373 ranlib
= get_expanded_make_variable( top_makefile
, "RANLIB" );
4374 rsvg
= get_expanded_make_variable( top_makefile
, "RSVG" );
4375 icotool
= get_expanded_make_variable( top_makefile
, "ICOTOOL" );
4376 dlltool
= get_expanded_make_variable( top_makefile
, "DLLTOOL" );
4377 msgfmt
= get_expanded_make_variable( top_makefile
, "MSGFMT" );
4378 sed_cmd
= get_expanded_make_variable( top_makefile
, "SED_CMD" );
4379 ln_s
= get_expanded_make_variable( top_makefile
, "LN_S" );
4381 if (root_src_dir
&& !strcmp( root_src_dir
, "." )) root_src_dir
= NULL
;
4382 if (tools_dir
&& !strcmp( tools_dir
, "." )) tools_dir
= NULL
;
4383 if (!exe_ext
) exe_ext
= "";
4384 if (!tools_ext
) tools_ext
= "";
4385 if (!man_ext
) man_ext
= "3w";
4387 top_makefile
->src_dir
= root_src_dir
;
4388 subdirs
= get_expanded_make_var_array( top_makefile
, "SUBDIRS" );
4389 disabled_dirs
= get_expanded_make_var_array( top_makefile
, "DISABLED_SUBDIRS" );
4390 submakes
= xmalloc( subdirs
.count
* sizeof(*submakes
) );
4392 for (i
= 0; i
< subdirs
.count
; i
++) submakes
[i
] = parse_makefile( subdirs
.str
[i
] );
4394 load_sources( top_makefile
);
4395 for (i
= 0; i
< subdirs
.count
; i
++) load_sources( submakes
[i
] );
4397 output_dependencies( top_makefile
);
4398 for (i
= 0; i
< subdirs
.count
; i
++) output_dependencies( submakes
[i
] );