zlib: Import upstream release 1.2.12.
[wine.git] / tools / winebuild / build.h
blob9918c2341f4d779ea26b6804f1c4370d5085255b
1 /*
2 * Copyright 1993 Robert J. Amstadt
3 * Copyright 1995 Martin von Loewis
4 * Copyright 1995, 1996, 1997 Alexandre Julliard
5 * Copyright 1997 Eric Youngdale
6 * Copyright 1999 Ulrich Weigand
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #ifndef __WINE_BUILD_H
24 #define __WINE_BUILD_H
26 #ifndef __WINE_CONFIG_H
27 # error You must include config.h to use this header
28 #endif
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include "../tools.h"
34 typedef enum
36 TYPE_VARIABLE, /* variable */
37 TYPE_PASCAL, /* pascal function (Win16) */
38 TYPE_ABS, /* absolute value (Win16) */
39 TYPE_STUB, /* unimplemented stub */
40 TYPE_STDCALL, /* stdcall function (Win32) */
41 TYPE_CDECL, /* cdecl function (Win32) */
42 TYPE_VARARGS, /* varargs function (Win32) */
43 TYPE_EXTERN, /* external symbol (Win32) */
44 TYPE_NBTYPES
45 } ORD_TYPE;
47 typedef enum
49 SPEC_WIN16,
50 SPEC_WIN32
51 } SPEC_TYPE;
53 enum arg_type
55 ARG_WORD, /* 16-bit word */
56 ARG_SWORD, /* 16-bit signed word */
57 ARG_SEGPTR, /* segmented pointer */
58 ARG_SEGSTR, /* segmented pointer to Ansi string */
59 ARG_LONG, /* long */
60 ARG_PTR, /* pointer */
61 ARG_STR, /* pointer to Ansi string */
62 ARG_WSTR, /* pointer to Unicode string */
63 ARG_INT64, /* 64-bit integer */
64 ARG_INT128, /* 128-bit integer */
65 ARG_FLOAT, /* 32-bit float */
66 ARG_DOUBLE, /* 64-bit float */
67 ARG_MAXARG = ARG_DOUBLE
70 #define MAX_ARGUMENTS 32
72 typedef struct
74 int n_values;
75 unsigned int *values;
76 } ORD_VARIABLE;
78 typedef struct
80 int nb_args;
81 int args_str_offset;
82 enum arg_type args[MAX_ARGUMENTS];
83 } ORD_FUNCTION;
85 typedef struct
87 unsigned short value;
88 } ORD_ABS;
90 typedef struct
92 ORD_TYPE type;
93 int ordinal;
94 int hint;
95 int lineno;
96 int flags;
97 char *name; /* public name of this function */
98 char *link_name; /* name of the C symbol to link to */
99 char *export_name; /* name exported under for noname exports */
100 union
102 ORD_VARIABLE var;
103 ORD_FUNCTION func;
104 ORD_ABS abs;
105 } u;
106 } ORDDEF;
108 struct apiset_entry
110 unsigned int name_off;
111 unsigned int name_len;
112 unsigned int hash;
113 unsigned int hash_len;
114 unsigned int val_count;
115 struct apiset_value
117 unsigned int name_off;
118 unsigned int name_len;
119 unsigned int val_off;
120 unsigned int val_len;
121 } values[4];
124 struct apiset
126 unsigned int count;
127 unsigned int size;
128 struct apiset_entry *entries;
129 unsigned int str_pos;
130 unsigned int str_size;
131 char *strings;
134 static const unsigned int apiset_hash_factor = 31;
136 typedef struct
138 char *src_name; /* file name of the source spec file */
139 char *file_name; /* file name of the dll */
140 char *dll_name; /* internal name of the dll */
141 char *c_name; /* internal name of the dll, as a C-compatible identifier */
142 char *init_func; /* initialization routine */
143 char *main_module; /* main Win32 module for Win16 specs */
144 SPEC_TYPE type; /* type of dll (Win16/Win32) */
145 int base; /* ordinal base */
146 int limit; /* ordinal limit */
147 int stack_size; /* exe stack size */
148 int heap_size; /* exe heap size */
149 int nb_entry_points; /* number of used entry points */
150 int alloc_entry_points; /* number of allocated entry points */
151 int nb_names; /* number of entry points with names */
152 unsigned int nb_resources; /* number of resources */
153 int characteristics; /* characteristics for the PE header */
154 int dll_characteristics;/* DLL characteristics for the PE header */
155 int subsystem; /* subsystem id */
156 int subsystem_major; /* subsystem version major number */
157 int subsystem_minor; /* subsystem version minor number */
158 int syscall_table; /* syscall table id */
159 int unicode_app; /* default to unicode entry point */
160 ORDDEF *entry_points; /* dll entry points */
161 ORDDEF **names; /* array of entry point names (points into entry_points) */
162 ORDDEF **ordinals; /* array of dll ordinals (points into entry_points) */
163 struct resource *resources; /* array of dll resources (format differs between Win16/Win32) */
164 struct apiset apiset; /* list of defined api sets */
165 } DLLSPEC;
167 extern char *target_alias;
168 extern struct target target;
170 static inline unsigned int get_ptr_size(void)
172 return get_target_ptr_size( target );
175 static inline int is_pe(void)
177 return target.platform == PLATFORM_MINGW || target.platform == PLATFORM_WINDOWS;
180 /* entry point flags */
181 #define FLAG_NORELAY 0x0001 /* don't use relay debugging for this function */
182 #define FLAG_NONAME 0x0002 /* don't export function by name */
183 #define FLAG_RET16 0x0004 /* function returns a 16-bit value */
184 #define FLAG_RET64 0x0008 /* function returns a 64-bit value */
185 #define FLAG_REGISTER 0x0010 /* use register calling convention */
186 #define FLAG_PRIVATE 0x0020 /* function is private (cannot be imported) */
187 #define FLAG_ORDINAL 0x0040 /* function should be imported by ordinal */
188 #define FLAG_THISCALL 0x0080 /* function uses thiscall calling convention */
189 #define FLAG_FASTCALL 0x0100 /* function uses fastcall calling convention */
190 #define FLAG_SYSCALL 0x0200 /* function is a system call */
191 #define FLAG_IMPORT 0x0400 /* export is imported from another module */
193 #define FLAG_FORWARD 0x1000 /* function is a forwarded name */
194 #define FLAG_EXT_LINK 0x2000 /* function links to an external symbol */
195 #define FLAG_EXPORT32 0x4000 /* 32-bit export in 16-bit spec file */
197 #define FLAG_CPU(cpu) (0x10000 << (cpu))
198 #define FLAG_CPU_MASK (FLAG_CPU_WIN32 | FLAG_CPU_WIN64)
199 #define FLAG_CPU_WIN64 (FLAG_CPU(CPU_x86_64) | FLAG_CPU(CPU_ARM64))
200 #define FLAG_CPU_WIN32 (FLAG_CPU(CPU_i386) | FLAG_CPU(CPU_ARM))
202 #define MAX_ORDINALS 65535
204 /* some Windows constants */
206 #define IMAGE_FILE_RELOCS_STRIPPED 0x0001 /* No relocation info */
207 #define IMAGE_FILE_EXECUTABLE_IMAGE 0x0002
208 #define IMAGE_FILE_LINE_NUMS_STRIPPED 0x0004
209 #define IMAGE_FILE_LOCAL_SYMS_STRIPPED 0x0008
210 #define IMAGE_FILE_AGGRESIVE_WS_TRIM 0x0010
211 #define IMAGE_FILE_LARGE_ADDRESS_AWARE 0x0020
212 #define IMAGE_FILE_16BIT_MACHINE 0x0040
213 #define IMAGE_FILE_BYTES_REVERSED_LO 0x0080
214 #define IMAGE_FILE_32BIT_MACHINE 0x0100
215 #define IMAGE_FILE_DEBUG_STRIPPED 0x0200
216 #define IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP 0x0400
217 #define IMAGE_FILE_NET_RUN_FROM_SWAP 0x0800
218 #define IMAGE_FILE_SYSTEM 0x1000
219 #define IMAGE_FILE_DLL 0x2000
220 #define IMAGE_FILE_UP_SYSTEM_ONLY 0x4000
221 #define IMAGE_FILE_BYTES_REVERSED_HI 0x8000
223 #define IMAGE_DLLCHARACTERISTICS_PREFER_NATIVE 0x0010 /* Wine extension */
224 #define IMAGE_DLLCHARACTERISTICS_NX_COMPAT 0x0100
226 #define IMAGE_SUBSYSTEM_NATIVE 1
227 #define IMAGE_SUBSYSTEM_WINDOWS_GUI 2
228 #define IMAGE_SUBSYSTEM_WINDOWS_CUI 3
229 #define IMAGE_SUBSYSTEM_WINDOWS_CE_GUI 9
231 /* global functions */
233 #ifndef DECLSPEC_NORETURN
234 # if defined(_MSC_VER) && (_MSC_VER >= 1200) && !defined(MIDL_PASS)
235 # define DECLSPEC_NORETURN __declspec(noreturn)
236 # else
237 # define DECLSPEC_NORETURN __attribute__((noreturn))
238 # endif
239 #endif
240 extern char *strupper(char *s);
241 extern DECLSPEC_NORETURN void fatal_error( const char *msg, ... )
242 __attribute__ ((__format__ (__printf__, 1, 2)));
243 extern DECLSPEC_NORETURN void fatal_perror( const char *msg, ... )
244 __attribute__ ((__format__ (__printf__, 1, 2)));
245 extern void error( const char *msg, ... )
246 __attribute__ ((__format__ (__printf__, 1, 2)));
247 extern void warning( const char *msg, ... )
248 __attribute__ ((__format__ (__printf__, 1, 2)));
249 extern int output( const char *format, ... )
250 __attribute__ ((__format__ (__printf__, 1, 2)));
251 extern void output_cfi( const char *format, ... )
252 __attribute__ ((__format__ (__printf__, 1, 2)));
253 extern void output_rva( const char *format, ... )
254 __attribute__ ((__format__ (__printf__, 1, 2)));
255 extern void spawn( struct strarray array );
256 extern struct strarray find_tool( const char *name, const char * const *names );
257 extern struct strarray find_link_tool(void);
258 extern struct strarray get_as_command(void);
259 extern struct strarray get_ld_command(void);
260 extern const char *get_nm_command(void);
261 extern void cleanup_tmp_files(void);
262 extern char *get_temp_file_name( const char *prefix, const char *suffix );
263 extern void output_standard_file_header(void);
264 extern FILE *open_input_file( const char *srcdir, const char *name );
265 extern void close_input_file( FILE *file );
266 extern void open_output_file(void);
267 extern void close_output_file(void);
268 extern char *open_temp_output_file( const char *suffix );
269 extern void dump_bytes( const void *buffer, unsigned int size );
270 extern int remove_stdcall_decoration( char *name );
271 extern void assemble_file( const char *src_file, const char *obj_file );
272 extern DLLSPEC *alloc_dll_spec(void);
273 extern void free_dll_spec( DLLSPEC *spec );
274 extern char *make_c_identifier( const char *str );
275 extern const char *get_stub_name( const ORDDEF *odp, const DLLSPEC *spec );
276 extern const char *get_link_name( const ORDDEF *odp );
277 extern int sort_func_list( ORDDEF **list, int count, int (*compare)(const void *, const void *) );
278 extern unsigned int get_alignment(unsigned int align);
279 extern unsigned int get_page_size(void);
280 extern unsigned int get_args_size( const ORDDEF *odp );
281 extern const char *asm_name( const char *func );
282 extern const char *func_declaration( const char *func );
283 extern const char *asm_globl( const char *func );
284 extern const char *get_asm_ptr_keyword(void);
285 extern const char *get_asm_string_keyword(void);
286 extern const char *get_asm_export_section(void);
287 extern const char *get_asm_rodata_section(void);
288 extern const char *get_asm_rsrc_section(void);
289 extern const char *get_asm_string_section(void);
290 extern const char *arm64_page( const char *sym );
291 extern const char *arm64_pageoff( const char *sym );
292 extern void output_function_size( const char *name );
293 extern void output_gnu_stack_note(void);
295 extern void add_import_dll( const char *name, const char *filename );
296 extern void add_delayed_import( const char *name );
297 extern void add_extra_ld_symbol( const char *name );
298 extern void add_spec_extra_ld_symbol( const char *name );
299 extern void read_undef_symbols( DLLSPEC *spec, struct strarray files );
300 extern void resolve_imports( DLLSPEC *spec );
301 extern int is_undefined( const char *name );
302 extern int has_imports(void);
303 extern void output_get_pc_thunk(void);
304 extern void output_module( DLLSPEC *spec );
305 extern void output_stubs( DLLSPEC *spec );
306 extern void output_syscalls( DLLSPEC *spec );
307 extern void output_imports( DLLSPEC *spec );
308 extern void output_static_lib( DLLSPEC *spec, struct strarray files );
309 extern void output_exports( DLLSPEC *spec );
310 extern int load_res32_file( const char *name, DLLSPEC *spec );
311 extern void output_resources( DLLSPEC *spec );
312 extern void output_bin_resources( DLLSPEC *spec, unsigned int start_rva );
313 extern void output_spec32_file( DLLSPEC *spec );
314 extern void output_fake_module( DLLSPEC *spec );
315 extern void output_data_module( DLLSPEC *spec );
316 extern void output_def_file( DLLSPEC *spec, int import_only );
317 extern void output_apiset_lib( DLLSPEC *spec, const struct apiset *apiset );
318 extern void load_res16_file( const char *name, DLLSPEC *spec );
319 extern void output_res16_data( DLLSPEC *spec );
320 extern void output_bin_res16_data( DLLSPEC *spec );
321 extern void output_res16_directory( DLLSPEC *spec );
322 extern void output_bin_res16_directory( DLLSPEC *spec, unsigned int data_offset );
323 extern void output_spec16_file( DLLSPEC *spec );
324 extern void output_fake_module16( DLLSPEC *spec16 );
325 extern void output_res_o_file( DLLSPEC *spec );
326 extern void output_asm_relays16(void);
327 extern void make_builtin_files( struct strarray files );
328 extern void fixup_constructors( struct strarray files );
330 extern void add_16bit_exports( DLLSPEC *spec32, DLLSPEC *spec16 );
331 extern int parse_spec_file( FILE *file, DLLSPEC *spec );
332 extern int parse_def_file( FILE *file, DLLSPEC *spec );
334 /* buffer management */
336 extern int byte_swapped;
337 extern const char *input_buffer_filename;
338 extern const unsigned char *input_buffer;
339 extern size_t input_buffer_pos;
340 extern size_t input_buffer_size;
342 extern void init_input_buffer( const char *file );
343 extern unsigned char get_byte(void);
344 extern unsigned short get_word(void);
345 extern unsigned int get_dword(void);
346 extern void put_pword( unsigned int val );
348 /* global variables */
350 extern int current_line;
351 extern int UsePIC;
352 extern int nb_errors;
353 extern int display_warnings;
354 extern int kill_at;
355 extern int verbose;
356 extern int link_ext_symbols;
357 extern int force_pointer_size;
358 extern int unwind_tables;
359 extern int use_msvcrt;
360 extern int unix_lib;
361 extern int safe_seh;
362 extern int prefer_native;
363 extern int data_only;
365 extern char *input_file_name;
366 extern char *spec_file_name;
367 extern FILE *output_file;
368 extern const char *output_file_name;
370 extern struct strarray lib_path;
371 extern struct strarray tools_path;
372 extern struct strarray as_command;
373 extern struct strarray cc_command;
374 extern struct strarray ld_command;
375 extern struct strarray nm_command;
376 extern char *cpu_option;
377 extern char *fpu_option;
378 extern char *arch_option;
379 extern const char *float_abi_option;
380 extern int thumb_mode;
381 extern int needs_get_pc_thunk;
383 #endif /* __WINE_BUILD_H */