enable genmodule to generate files for different flavours of a module. (NicJA)
[AROS.git] / tools / genmodule / writeinclibdefs.c
blobeb95816b396d8096dc97f7a6f32c7afdb8bdccc7
1 /*
2 Copyright © 1995-2019, 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 if (!cfg->flavour)
52 snprintf(line, sizeof(line) - 1, "%s/%s_libdefs.h", cfg->gendir, cfg->modulename);
54 else
56 snprintf(line, sizeof(line) - 1, "%s/%s_%s_libdefs.h", cfg->gendir, cfg->modulename, cfg->flavour);
59 out = fopen(line, "w");
61 if (out == NULL)
63 perror(line);
64 exit(20);
67 fprintf
69 out,
70 "#ifndef _%s_LIBDEFS_H\n"
71 "#define _%s_LIBDEFS_H\n"
72 "\n"
73 "#include <exec/types.h>\n"
74 "\n",
75 cfg->modulenameupper, cfg->modulenameupper
78 sep = strcmp(cfg->suffix, "handler") ? '.' : '-';
80 fprintf
82 out,
83 "#define GM_UNIQUENAME(n) %s_ ## n\n"
84 "#define LIBBASE %s\n"
85 "#define LIBBASETYPE %s\n"
86 "#define LIBBASETYPEPTR %s *\n"
87 "#define MOD_NAME_STRING \"%s%c%s\"\n"
88 "#define VERSION_NUMBER %u\n"
89 "#define MAJOR_VERSION %u\n"
90 "#define REVISION_NUMBER %u\n"
91 "#define MINOR_VERSION %u\n"
92 "#define VERSION_STRING \"$VER: %s.%s ",
93 cfg->basename,
94 cfg->libbase, _libbasetype, _libbasetype,
95 cfg->modulename, sep, cfg->suffix,
96 cfg->majorversion, cfg->majorversion,
97 cfg->minorversion, cfg->minorversion,
98 cfg->modulename, cfg->suffix
100 if (cfg->versionextra)
101 fprintf(out, "%s ", cfg->versionextra);
102 if (cfg->flavour)
103 fprintf(out, "%s ", cfg->flavour);
104 fprintf(out,
105 "%u.%u (%s)%s%s\\r\\n\"\n"
106 "#define COPYRIGHT_STRING \"%s\"\n"
107 "#define LIBEND GM_UNIQUENAME(End)\n"
108 "#define LIBFUNCTABLE GM_UNIQUENAME(FuncTable)\n"
109 "#define RESIDENTPRI %d\n"
110 "#define RESIDENTFLAGS %s\n"
111 "#define FUNCTIONS_COUNT %u\n",
112 cfg->majorversion, cfg->minorversion,
113 cfg->datestring, cfg->copyright[0] != '\0' ? " " : "", cfg->copyright,
114 cfg->copyright,
115 cfg->residentpri,
116 residentflags,
117 funccount
120 for (linelistit = cfg->cdefprivatelines; linelistit!=NULL; linelistit = linelistit->next)
121 fprintf(out, "%s\n", linelistit->s);
123 /* Following code assumes that the input was checked to be consistent during the
124 * parsing of the .conf file in config.c, no checks are done here
126 if (cfg->sysbase_field != NULL)
127 fprintf(out,
128 "#define GM_SYSBASE_FIELD(lh) (((LIBBASETYPEPTR)lh)->%s)\n",
129 cfg->sysbase_field
131 if (cfg->oopbase_field != NULL)
132 fprintf(out,
133 "#define GM_OOPBASE_FIELD(lh) (((LIBBASETYPEPTR)lh)->%s)\n",
134 cfg->oopbase_field
136 if (cfg->seglist_field != NULL)
137 fprintf(out,
138 "#define GM_SEGLIST_FIELD(lh) (((LIBBASETYPEPTR)lh)->%s)\n",
139 cfg->seglist_field
141 for (classlistit = cfg->classlist; classlistit != NULL; classlistit = classlistit->next)
143 int storeptr;
145 if (classlistit->classptr_field != NULL)
147 storeptr = 1;
148 snprintf(line, 1023, "((LIBBASETYPEPTR)lh)->%s", classlistit->classptr_field);
150 else if ((classlistit->classid != NULL) && !(classlistit->options & COPTION_PRIVATE))
152 storeptr = 0;
153 snprintf(line, 1023, "FindClass(%s)", classlistit->classid);
155 else
156 /* Don't write anything */
157 continue;
159 fprintf(out,
160 "#define %s_STORE_CLASSPTR %d\n",
161 classlistit->basename, storeptr
164 /* When class is the main class also define GM_CLASSPTR_FIELD for legacy */
165 if (strcmp(classlistit->basename, cfg->basename) == 0)
166 fprintf(out, "#define GM_CLASSPTR_FIELD(lh) (%s)\n", line);
168 fprintf(out,
169 "#define %s_CLASSPTR_FIELD(lh) (%s)\n",
170 classlistit->basename, line
174 if (cfg->options & OPTION_DUPBASE)
176 if (cfg->rootbase_field != NULL)
177 fprintf(out,
178 "#define GM_ROOTBASE_FIELD(lh) (((LIBBASETYPEPTR)lh)->%s)\n",
179 cfg->rootbase_field
183 if (cfg->rellibs || (cfg->options & OPTION_DUPBASE) || (cfg->options & OPTION_STACKCALL))
184 fprintf(out,
185 "\n"
186 "%s\n"
187 "char *__aros_getoffsettable(void);\n"
188 "%s\n"
189 , !(cfg->options & OPTION_STACKCALL) ? "#ifndef __aros_getoffsettable" : "/* Thus must be externally visible for stackcall libs */"
190 , !(cfg->options & OPTION_STACKCALL) ? "#endif" : ""
193 if (cfg->options & OPTION_PERTASKBASE)
195 fprintf(out,
196 "\n"
197 "LIBBASETYPEPTR __GM_GetBaseParent(LIBBASETYPEPTR);\n"
201 fprintf
203 out,
204 "\n"
205 "#endif /* _%s_LIBDEFS_H */\n",
206 cfg->modulenameupper
209 if (ferror(out))
211 perror("Error writing libdefs.h");
212 fclose(out);
213 exit(20);
216 fclose(out);