make sure the romtag structure and associated parts arent optimised away.
[AROS.git] / tools / genmodule / writeinclibdefs.c
blob21ea465115bc3d39ed33bd87d00ee1da593c3e56
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Function to write libdefs.h. Part of genmodule.
6 */
7 #include "genmodule.h"
9 void writeinclibdefs(struct config *cfg)
11 FILE *out;
12 char line[1024];
13 struct stringlist *linelistit;
14 char *_libbasetype = (cfg->libbasetype==NULL) ? "struct Library" : cfg->libbasetype;
15 char residentflags[256];
16 struct classinfo *classlistit;
17 unsigned int funccount;
18 struct functionhead *funclistit = cfg->funclist;
19 char sep;
21 if (funclistit == NULL)
22 funccount = cfg->firstlvo-1;
23 else
25 while (funclistit->next != NULL)
26 funclistit = funclistit->next;
28 funccount = funclistit->lvo;
31 residentflags[0] = 0;
33 if (cfg->residentpri >= 105)
34 strcpy(residentflags, "RTF_SINGLETASK");
35 else if (cfg->residentpri >= -60)
36 strcpy(residentflags, "RTF_COLDSTART");
37 else if (cfg->residentpri < -120)
38 strcpy(residentflags, "RTF_AFTERDOS");
40 if (cfg->options & OPTION_RESAUTOINIT)
42 if(strlen(residentflags) > 0)
43 strcat(residentflags, "|");
44 strcat(residentflags, "RTF_AUTOINIT");
47 if (strlen(residentflags) == 0)
48 strcpy(residentflags, "0");
50 snprintf(line, 1023, "%s/%s_libdefs.h", cfg->gendir, cfg->modulename);
52 out = fopen(line, "w");
54 if (out == NULL)
56 perror(line);
57 exit(20);
60 fprintf
62 out,
63 "#ifndef _%s_LIBDEFS_H\n"
64 "#define _%s_LIBDEFS_H\n"
65 "\n"
66 "#include <exec/types.h>\n"
67 "\n",
68 cfg->modulenameupper, cfg->modulenameupper
71 sep = strcmp(cfg->suffix, "handler") ? '.' : '-';
73 fprintf
75 out,
76 "#define GM_UNIQUENAME(n) %s_ ## n\n"
77 "#define LIBBASE %s\n"
78 "#define LIBBASETYPE %s\n"
79 "#define LIBBASETYPEPTR %s *\n"
80 "#define MOD_NAME_STRING \"%s%c%s\"\n"
81 "#define VERSION_NUMBER %u\n"
82 "#define MAJOR_VERSION %u\n"
83 "#define REVISION_NUMBER %u\n"
84 "#define MINOR_VERSION %u\n"
85 "#define VERSION_STRING \"$VER: %s.%s ",
86 cfg->basename,
87 cfg->libbase, _libbasetype, _libbasetype,
88 cfg->modulename, sep, cfg->suffix,
89 cfg->majorversion, cfg->majorversion,
90 cfg->minorversion, cfg->minorversion,
91 cfg->modulename, cfg->suffix
93 if (cfg->versionextra)
94 fprintf(out, "%s ", cfg->versionextra);
95 fprintf(out,
96 "%u.%u (%s)%s%s\\r\\n\"\n"
97 "#define COPYRIGHT_STRING \"%s\"\n"
98 "#define LIBEND GM_UNIQUENAME(End)\n"
99 "#define LIBFUNCTABLE GM_UNIQUENAME(FuncTable)\n"
100 "#define RESIDENTPRI %d\n"
101 "#define RESIDENTFLAGS %s\n"
102 "#define FUNCTIONS_COUNT %u\n",
103 cfg->majorversion, cfg->minorversion,
104 cfg->datestring, cfg->copyright[0] != '\0' ? " " : "", cfg->copyright,
105 cfg->copyright,
106 cfg->residentpri,
107 residentflags,
108 funccount
111 for (linelistit = cfg->cdefprivatelines; linelistit!=NULL; linelistit = linelistit->next)
112 fprintf(out, "%s\n", linelistit->s);
114 /* Following code assumes that the input was checked to be consistent during the
115 * parsing of the .conf file in config.c, no checks are done here
117 if (cfg->sysbase_field != NULL)
118 fprintf(out,
119 "#define GM_SYSBASE_FIELD(lh) (((LIBBASETYPEPTR)lh)->%s)\n",
120 cfg->sysbase_field
122 if (cfg->oopbase_field != NULL)
123 fprintf(out,
124 "#define GM_OOPBASE_FIELD(lh) (((LIBBASETYPEPTR)lh)->%s)\n",
125 cfg->oopbase_field
127 if (cfg->seglist_field != NULL)
128 fprintf(out,
129 "#define GM_SEGLIST_FIELD(lh) (((LIBBASETYPEPTR)lh)->%s)\n",
130 cfg->seglist_field
132 for (classlistit = cfg->classlist; classlistit != NULL; classlistit = classlistit->next)
134 int storeptr;
136 if (classlistit->classptr_field != NULL)
138 storeptr = 1;
139 snprintf(line, 1023, "((LIBBASETYPEPTR)lh)->%s", classlistit->classptr_field);
141 else if ((classlistit->classid != NULL) && !(classlistit->options & COPTION_PRIVATE))
143 storeptr = 0;
144 snprintf(line, 1023, "FindClass(%s)", classlistit->classid);
146 else
147 /* Don't write anything */
148 continue;
150 fprintf(out,
151 "#define %s_STORE_CLASSPTR %d\n",
152 classlistit->basename, storeptr
155 /* When class is the main class also define GM_CLASSPTR_FIELD for legacy */
156 if (strcmp(classlistit->basename, cfg->basename) == 0)
157 fprintf(out, "#define GM_CLASSPTR_FIELD(lh) (%s)\n", line);
159 fprintf(out,
160 "#define %s_CLASSPTR_FIELD(lh) (%s)\n",
161 classlistit->basename, line
165 if (cfg->options & OPTION_DUPBASE)
167 if (cfg->rootbase_field != NULL)
168 fprintf(out,
169 "#define GM_ROOTBASE_FIELD(lh) (((LIBBASETYPEPTR)lh)->%s)\n",
170 cfg->rootbase_field
174 if (cfg->rellibs || (cfg->options & OPTION_DUPBASE) || (cfg->options & OPTION_STACKCALL))
175 fprintf(out,
176 "\n"
177 "%s\n"
178 "char *__aros_getoffsettable(void);\n"
179 "%s\n"
180 , !(cfg->options & OPTION_STACKCALL) ? "#ifndef __aros_getoffsettable" : "/* Thus must be externally visible for stackcall libs */"
181 , !(cfg->options & OPTION_STACKCALL) ? "#endif" : ""
184 if (cfg->options & OPTION_PERTASKBASE)
186 fprintf(out,
187 "\n"
188 "LIBBASETYPEPTR __GM_GetBaseParent(LIBBASETYPEPTR);\n"
192 fprintf
194 out,
195 "\n"
196 "#endif /* _%s_LIBDEFS_H */\n",
197 cfg->modulenameupper
200 if (ferror(out))
202 perror("Error writing libdefs.h");
203 fclose(out);
204 exit(20);
207 fclose(out);