winebuild: Add support for generating stand-alone 16-bit modules.
[wine] / tools / winebuild / build.h
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
7  *
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.
12  *
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.
17  *
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
21  */
22
23 #ifndef __WINE_BUILD_H
24 #define __WINE_BUILD_H
25
26 #ifndef __WINE_CONFIG_H
27 # error You must include config.h to use this header
28 #endif
29
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33
34 typedef enum
35 {
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;
46
47 typedef enum
48 {
49     SPEC_WIN16,
50     SPEC_WIN32
51 } SPEC_TYPE;
52
53 typedef struct
54 {
55     int n_values;
56     int *values;
57 } ORD_VARIABLE;
58
59 typedef struct
60 {
61     char arg_types[21];
62 } ORD_FUNCTION;
63
64 typedef struct
65 {
66     unsigned short value;
67 } ORD_ABS;
68
69 typedef struct
70 {
71     ORD_TYPE    type;
72     int         ordinal;
73     int         lineno;
74     int         flags;
75     char       *name;         /* public name of this function */
76     char       *link_name;    /* name of the C symbol to link to */
77     char       *export_name;  /* name exported under for noname exports */
78     union
79     {
80         ORD_VARIABLE   var;
81         ORD_FUNCTION   func;
82         ORD_ABS        abs;
83     } u;
84 } ORDDEF;
85
86 typedef struct
87 {
88     char            *src_name;           /* file name of the source spec file */
89     char            *file_name;          /* file name of the dll */
90     char            *dll_name;           /* internal name of the dll */
91     char            *init_func;          /* initialization routine */
92     SPEC_TYPE        type;               /* type of dll (Win16/Win32) */
93     int              base;               /* ordinal base */
94     int              limit;              /* ordinal limit */
95     int              stack_size;         /* exe stack size */
96     int              heap_size;          /* exe heap size */
97     int              nb_entry_points;    /* number of used entry points */
98     int              alloc_entry_points; /* number of allocated entry points */
99     int              nb_names;           /* number of entry points with names */
100     unsigned int     nb_resources;       /* number of resources */
101     int              characteristics;    /* characteristics for the PE header */
102     int              dll_characteristics;/* DLL characteristics for the PE header */
103     int              subsystem;          /* subsystem id */
104     int              subsystem_major;    /* subsystem version major number */
105     int              subsystem_minor;    /* subsystem version minor number */
106     ORDDEF          *entry_points;       /* dll entry points */
107     ORDDEF         **names;              /* array of entry point names (points into entry_points) */
108     ORDDEF         **ordinals;           /* array of dll ordinals (points into entry_points) */
109     struct resource *resources;          /* array of dll resources (format differs between Win16/Win32) */
110 } DLLSPEC;
111
112 enum target_cpu
113 {
114     CPU_x86, CPU_x86_64, CPU_SPARC, CPU_ALPHA, CPU_POWERPC
115 };
116
117 enum target_platform
118 {
119     PLATFORM_UNSPECIFIED, PLATFORM_APPLE, PLATFORM_SOLARIS, PLATFORM_WINDOWS
120 };
121
122 extern char *target_alias;
123 extern enum target_cpu target_cpu;
124 extern enum target_platform target_platform;
125
126 /* entry point flags */
127 #define FLAG_NORELAY   0x01  /* don't use relay debugging for this function */
128 #define FLAG_NONAME    0x02  /* don't export function by name */
129 #define FLAG_RET16     0x04  /* function returns a 16-bit value */
130 #define FLAG_RET64     0x08  /* function returns a 64-bit value */
131 #define FLAG_REGISTER  0x10  /* use register calling convention */
132 #define FLAG_PRIVATE   0x20  /* function is private (cannot be imported) */
133 #define FLAG_ORDINAL   0x40  /* function should be imported by ordinal */
134
135 #define FLAG_FORWARD   0x100  /* function is a forwarded name */
136 #define FLAG_EXT_LINK  0x200  /* function links to an external symbol */
137
138 #define FLAG_CPU(cpu)  (0x01000 << (cpu))
139 #define FLAG_CPU_MASK  0x1f000
140
141 #define MAX_ORDINALS  65535
142
143 /* global functions */
144
145 #ifndef __GNUC__
146 #define __attribute__(X)
147 #endif
148
149 #ifndef DECLSPEC_NORETURN
150 # if defined(_MSC_VER) && (_MSC_VER >= 1200) && !defined(MIDL_PASS)
151 #  define DECLSPEC_NORETURN __declspec(noreturn)
152 # else
153 #  define DECLSPEC_NORETURN __attribute__((noreturn))
154 # endif
155 #endif
156
157 extern void *xmalloc (size_t size);
158 extern void *xrealloc (void *ptr, size_t size);
159 extern char *xstrdup( const char *str );
160 extern char *strupper(char *s);
161 extern int strendswith(const char* str, const char* end);
162 extern DECLSPEC_NORETURN void fatal_error( const char *msg, ... )
163    __attribute__ ((__format__ (__printf__, 1, 2)));
164 extern DECLSPEC_NORETURN void fatal_perror( const char *msg, ... )
165    __attribute__ ((__format__ (__printf__, 1, 2)));
166 extern void error( const char *msg, ... )
167    __attribute__ ((__format__ (__printf__, 1, 2)));
168 extern void warning( const char *msg, ... )
169    __attribute__ ((__format__ (__printf__, 1, 2)));
170 extern int output( const char *format, ... )
171    __attribute__ ((__format__ (__printf__, 1, 2)));
172 extern const char *get_as_command(void);
173 extern const char *get_ld_command(void);
174 extern const char *get_nm_command(void);
175 extern char *get_temp_file_name( const char *prefix, const char *suffix );
176 extern void output_standard_file_header(void);
177 extern FILE *open_input_file( const char *srcdir, const char *name );
178 extern void close_input_file( FILE *file );
179 extern void dump_bytes( const void *buffer, unsigned int size );
180 extern int remove_stdcall_decoration( char *name );
181 extern void assemble_file( const char *src_file, const char *obj_file );
182 extern DLLSPEC *alloc_dll_spec(void);
183 extern void free_dll_spec( DLLSPEC *spec );
184 extern const char *make_c_identifier( const char *str );
185 extern const char *get_stub_name( const ORDDEF *odp, const DLLSPEC *spec );
186 extern enum target_cpu get_cpu_from_name( const char *name );
187 extern unsigned int get_alignment(unsigned int align);
188 extern unsigned int get_page_size(void);
189 extern unsigned int get_ptr_size(void);
190 extern const char *asm_name( const char *func );
191 extern const char *func_declaration( const char *func );
192 extern const char *asm_globl( const char *func );
193 extern const char *get_asm_ptr_keyword(void);
194 extern const char *get_asm_string_keyword(void);
195 extern const char *get_asm_short_keyword(void);
196 extern const char *get_asm_rodata_section(void);
197 extern const char *get_asm_string_section(void);
198 extern void output_function_size( const char *name );
199 extern void output_gnu_stack_note(void);
200
201 extern void add_import_dll( const char *name, const char *filename );
202 extern void add_delayed_import( const char *name );
203 extern void add_ignore_symbol( const char *name );
204 extern void add_extra_ld_symbol( const char *name );
205 extern void read_undef_symbols( DLLSPEC *spec, char **argv );
206 extern int resolve_imports( DLLSPEC *spec );
207 extern int has_imports(void);
208 extern int has_relays( DLLSPEC *spec );
209 extern void output_get_pc_thunk(void);
210 extern void output_module( DLLSPEC *spec );
211 extern void output_stubs( DLLSPEC *spec );
212 extern void output_imports( DLLSPEC *spec );
213 extern void output_exports( DLLSPEC *spec );
214 extern int load_res32_file( const char *name, DLLSPEC *spec );
215 extern void output_resources( DLLSPEC *spec );
216 extern void load_res16_file( const char *name, DLLSPEC *spec );
217 extern void output_res16_data( DLLSPEC *spec );
218 extern void output_res16_directory( DLLSPEC *spec );
219 extern void output_spec16_file( DLLSPEC *spec );
220
221 extern void BuildRelays16(void);
222 extern void BuildRelays32(void);
223 extern void BuildSpec16File( DLLSPEC *spec );
224 extern void BuildSpec32File( DLLSPEC *spec );
225 extern void BuildDef32File( DLLSPEC *spec );
226
227 extern void add_16bit_exports( DLLSPEC *spec32, DLLSPEC *spec16 );
228 extern int parse_spec_file( FILE *file, DLLSPEC *spec );
229 extern int parse_def_file( FILE *file, DLLSPEC *spec );
230
231 /* global variables */
232
233 extern int current_line;
234 extern int UsePIC;
235 extern int nb_lib_paths;
236 extern int nb_errors;
237 extern int display_warnings;
238 extern int kill_at;
239 extern int verbose;
240 extern int save_temps;
241 extern int link_ext_symbols;
242 extern int force_pointer_size;
243
244 extern char *input_file_name;
245 extern char *spec_file_name;
246 extern FILE *output_file;
247 extern const char *output_file_name;
248 extern char **lib_path;
249
250 extern char *as_command;
251 extern char *ld_command;
252 extern char *nm_command;
253
254 #endif  /* __WINE_BUILD_H */