Import SB128-v5.24 to main branch
[AROS.git] / tools / genmodule / writeinclibdefs.c
blobb236da9f2f63656621edd04ddb1e5bb4390118a0
1 /*
2 Copyright © 1995-2009, 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 %u.%u (%s)%s%s\\r\\n\"\n"
86 "#define COPYRIGHT_STRING \"%s\"\n"
87 "#define LIBEND GM_UNIQUENAME(End)\n"
88 "#define LIBFUNCTABLE GM_UNIQUENAME(FuncTable)\n"
89 "#define RESIDENTPRI %d\n"
90 "#define RESIDENTFLAGS %s\n"
91 "#define FUNCTIONS_COUNT %u\n",
92 cfg->basename,
93 cfg->libbase, _libbasetype, _libbasetype,
94 cfg->modulename, sep, cfg->suffix,
95 cfg->majorversion, cfg->majorversion,
96 cfg->minorversion, cfg->minorversion,
97 cfg->modulename, cfg->suffix, cfg->majorversion, cfg->minorversion,
98 cfg->datestring, cfg->copyright[0] != '\0' ? " " : "", cfg->copyright,
99 cfg->copyright,
100 cfg->residentpri,
101 residentflags,
102 funccount
105 for (linelistit = cfg->cdefprivatelines; linelistit!=NULL; linelistit = linelistit->next)
106 fprintf(out, "%s\n", linelistit->s);
108 /* Following code assumes that the input was checked to be consistent during the
109 * parsing of the .conf file in config.c, no checks are done here
111 if (cfg->sysbase_field != NULL)
112 fprintf(out,
113 "#define GM_SYSBASE_FIELD(lh) (((LIBBASETYPEPTR)lh)->%s)\n",
114 cfg->sysbase_field
116 if (cfg->seglist_field != NULL)
117 fprintf(out,
118 "#define GM_SEGLIST_FIELD(lh) (((LIBBASETYPEPTR)lh)->%s)\n",
119 cfg->seglist_field
121 if (cfg->getidfunc != NULL)
122 fprintf(out, "#define GM_GETID ((IPTR)%s())\n", cfg->getidfunc);
123 for (classlistit = cfg->classlist; classlistit != NULL; classlistit = classlistit->next)
125 int storeptr;
127 if (classlistit->classptr_field != NULL)
129 storeptr = 1;
130 snprintf(line, 1023, "((LIBBASETYPEPTR)lh)->%s", classlistit->classptr_field);
132 else if (classlistit->classptr_var != NULL)
134 storeptr = 1;
135 snprintf(line, 1023, "%s", classlistit->classptr_var);
137 else if ((classlistit->classid != NULL) && !(classlistit->options & COPTION_PRIVATE))
139 storeptr = 0;
140 snprintf(line, 1023, "FindClass(%s)", classlistit->classid);
142 else
143 /* Don't write anything */
144 continue;
146 fprintf(out,
147 "#define %s_STORE_CLASSPTR %d\n",
148 classlistit->basename, storeptr
151 /* When class is the main class also define GM_CLASSPTR_FIELD for legacy */
152 if (strcmp(classlistit->basename, cfg->basename) == 0)
153 fprintf(out, "#define GM_CLASSPTR_FIELD(lh) (%s)\n", line);
155 fprintf(out,
156 "#define %s_CLASSPTR_FIELD(lh) (%s)\n",
157 classlistit->basename, line
161 if ((cfg->options & OPTION_DUPBASE) && cfg->rootbase_field != NULL)
162 fprintf(out,
163 "#define GM_ROOTBASE_FIELD(lh) (((LIBBASETYPEPTR)lh)->%s)\n",
164 cfg->rootbase_field
167 if (cfg->options & OPTION_DUPPERID)
169 fprintf(out,
170 "\n"
171 "#ifndef GM_GETID\n"
172 "#define GM_GETID ((IPTR)FindTask(NULL))\n"
173 "\n"
174 "IPTR __GM_Id2(void);\n"
175 "#define GM_GETID2 __GM_Id2()\n"
176 "\n"
177 "#define __GM_OWNGETID\n"
178 "#endif\n"
179 "\n"
180 "#if defined(GM_GETID2) && !defined(GM_GETPARENTBASEID2)\n"
181 "LIBBASETYPEPTR GM_UNIQUENAME(__GetParentLibbase)(LIBBASETYPEPTR lh);\n"
182 "#define GM_GETPARENTBASEID2(lh) GM_UNIQUENAME(__GetParentLibbase)(lh)\n"
183 "\n"
184 "#define __GM_OWNPARENTBASEID2\n"
185 "#endif\n"
189 fprintf
191 out,
192 "\n"
193 "#endif /* _%s_LIBDEFS_H */\n",
194 cfg->modulenameupper
197 if (ferror(out))
199 perror("Error writing libdefs.h");
200 fclose(out);
201 exit(20);
204 fclose(out);