Support for generation of .def files from .spec files.
[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
9 #ifndef __WINE_BUILD_H
10 #define __WINE_BUILD_H
11
12 #ifndef __WINE_CONFIG_H  
13 # error You must include config.h to use this header  
14 #endif  
15
16 #include <stdio.h>
17 #include <stdlib.h>
18
19 #ifdef NEED_UNDERSCORE_PREFIX
20 # define PREFIX "_"
21 #else
22 # define PREFIX
23 #endif
24
25 #ifdef HAVE_ASM_STRING
26 # define STRING ".string"
27 #else
28 # define STRING ".ascii"
29 #endif
30
31 #if defined(__GNUC__) && !defined(__svr4__)
32 # define USE_STABS
33 #else
34 # undef USE_STABS
35 #endif
36
37 typedef enum
38 {
39     TYPE_VARIABLE,     /* variable */
40     TYPE_PASCAL_16,    /* pascal function with 16-bit return (Win16) */
41     TYPE_PASCAL,       /* pascal function with 32-bit return (Win16) */
42     TYPE_ABS,          /* absolute value (Win16) */
43     TYPE_STUB,         /* unimplemented stub */
44     TYPE_STDCALL,      /* stdcall function (Win32) */
45     TYPE_CDECL,        /* cdecl function (Win32) */
46     TYPE_VARARGS,      /* varargs function (Win32) */
47     TYPE_EXTERN,       /* external symbol (Win32) */
48     TYPE_FORWARD,      /* forwarded function (Win32) */
49     TYPE_NBTYPES
50 } ORD_TYPE;
51
52 typedef enum
53 {
54     SPEC_INVALID,
55     SPEC_WIN16,
56     SPEC_WIN32
57 } SPEC_TYPE;
58
59 typedef enum
60 {
61     SPEC_MODE_DLL,
62     SPEC_MODE_GUIEXE,
63     SPEC_MODE_CUIEXE,
64     SPEC_MODE_GUIEXE_UNICODE,
65     SPEC_MODE_CUIEXE_UNICODE
66 } SPEC_MODE;
67
68 typedef struct
69 {
70     int n_values;
71     int *values;
72 } ORD_VARIABLE;
73
74 typedef struct
75 {
76     int  n_args;
77     char arg_types[21];
78 } ORD_FUNCTION;
79
80 typedef struct
81 {
82     int value;
83 } ORD_ABS;
84
85 typedef struct
86 {
87     ORD_TYPE    type;
88     int         ordinal;
89     int         offset;
90     int         lineno;
91     int         flags;
92     char       *name;
93     char       *link_name;
94     union
95     {
96         ORD_VARIABLE   var;
97         ORD_FUNCTION   func;
98         ORD_ABS        abs;
99     } u;
100 } ORDDEF;
101
102 /* entry point flags */
103 #define FLAG_NOIMPORT  0x01  /* don't make function available for importing */
104 #define FLAG_NORELAY   0x02  /* don't use relay debugging for this function */
105 #define FLAG_RET64     0x04  /* function returns a 64-bit value */
106 #define FLAG_I386      0x08  /* function is i386 only */
107 #define FLAG_REGISTER  0x10  /* use register calling convention */
108 #define FLAG_INTERRUPT 0x20  /* function is an interrupt handler */
109
110   /* Offset of a structure field relative to the start of the struct */
111 #define STRUCTOFFSET(type,field) ((int)&((type *)0)->field)
112
113   /* Offset of register relative to the start of the CONTEXT struct */
114 #define CONTEXTOFFSET(reg)  STRUCTOFFSET(CONTEXT86,reg)
115
116   /* Offset of register relative to the start of the STACK16FRAME struct */
117 #define STACK16OFFSET(reg)  STRUCTOFFSET(STACK16FRAME,reg)
118
119   /* Offset of register relative to the start of the STACK32FRAME struct */
120 #define STACK32OFFSET(reg)  STRUCTOFFSET(STACK32FRAME,reg)
121
122   /* Offset of the stack pointer relative to %fs:(0) */
123 #define STACKOFFSET (STRUCTOFFSET(TEB,cur_stack))
124
125
126 #define MAX_ORDINALS  65535
127
128 /* global functions */
129
130 extern void *xmalloc (size_t size);
131 extern void *xrealloc (void *ptr, size_t size);
132 extern char *xstrdup( const char *str );
133 extern char *strupper(char *s);
134 extern void fatal_error( const char *msg, ... );
135 extern void fatal_perror( const char *msg, ... );
136 extern void warning( const char *msg, ... );
137 extern void dump_bytes( FILE *outfile, const unsigned char *data, int len,
138                         const char *label, int constant );
139 extern int get_alignment(int alignBoundary);
140
141 extern void add_import_dll( const char *name, int delay );
142 extern void add_ignore_symbol( const char *name );
143 extern int resolve_imports( void );
144 extern int output_imports( FILE *outfile );
145 extern void load_res32_file( const char *name );
146 extern int output_resources( FILE *outfile );
147 extern void load_res16_file( const char *name );
148 extern int output_res16_data( FILE *outfile );
149 extern int output_res16_directory( unsigned char *buffer );
150
151 extern void BuildGlue( FILE *outfile, FILE *infile );
152 extern void BuildRelays16( FILE *outfile );
153 extern void BuildRelays32( FILE *outfile );
154 extern void BuildSpec16File( FILE *outfile );
155 extern void BuildSpec32File( FILE *outfile );
156 extern void BuildDef32File( FILE *outfile );
157 extern SPEC_TYPE ParseTopLevel( FILE *file );
158
159 /* global variables */
160
161 extern int current_line;
162 extern int nb_entry_points;
163 extern int nb_names;
164 extern int Base;
165 extern int Limit;
166 extern int DLLHeapSize;
167 extern int UsePIC;
168 extern int debugging;
169 extern int stack_size;
170 extern int nb_debug_channels;
171 extern int nb_lib_paths;
172
173 extern char DLLName[80];
174 extern char DLLFileName[80];
175 extern char owner_name[80];
176 extern char *init_func;
177 extern const char *input_file_name;
178 extern const char *output_file_name;
179 extern char **debug_channels;
180 extern char **lib_path;
181
182 extern ORDDEF *EntryPoints[MAX_ORDINALS];
183 extern ORDDEF *Ordinals[MAX_ORDINALS];
184 extern ORDDEF *Names[MAX_ORDINALS];
185 extern SPEC_MODE SpecMode;
186
187 #endif  /* __WINE_BUILD_H */