Datatype descriptor for D64/T64 files added.
[cake.git] / tools / genmodule / writeinclibdefs.c
blobd01830d60e8a9cbec0baa1deba5568bd98bc4ed4
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;
18 residentflags[0] = 0;
21 if (cfg->residentpri >= 105)
22 strcpy(residentflags, "RTF_SINGLETASK");
23 else if (cfg->residentpri >= -50)
24 strcpy(residentflags, "RTF_COLDSTART");
25 else if (cfg->residentpri < -120)
26 strcpy(residentflags, "RTF_AFTERDOS");
28 if (cfg->modtype != RESOURCE)
30 if(strlen(residentflags) > 0)
31 strcat(residentflags, "|");
32 strcat(residentflags, "RTF_AUTOINIT");
35 if (strlen(residentflags) == 0)
36 strcpy(residentflags, "0");
38 snprintf(line, 1023, "%s/%s_libdefs.h", cfg->gendir, cfg->modulename);
40 out = fopen(line, "w");
42 if (out == NULL)
44 perror(line);
45 exit(20);
48 fprintf
50 out,
51 "#ifndef _%s_LIBDEFS_H\n"
52 "#define _%s_LIBDEFS_H\n"
53 "\n"
54 "#include <exec/types.h>\n"
55 "\n",
56 cfg->modulenameupper, cfg->modulenameupper
59 fprintf
61 out,
62 "#define GM_UNIQUENAME(n) %s_ ## n\n"
63 "#define LIBBASE %s\n"
64 "#define LIBBASETYPE %s\n"
65 "#define LIBBASETYPEPTR %s *\n"
66 "#define MOD_NAME_STRING \"%s.%s\"\n"
67 "#define VERSION_NUMBER %u\n"
68 "#define MAJOR_VERSION %u\n"
69 "#define REVISION_NUMBER %u\n"
70 "#define MINOR_VERSION %u\n"
71 "#define VERSION_STRING \"%s.%s %u.%u (%s)%s%s\\r\\n\"\n"
72 "#define COPYRIGHT_STRING \"%s\"\n"
73 "#define LIBEND GM_UNIQUENAME(End)\n"
74 "#define LIBFUNCTABLE GM_UNIQUENAME(FuncTable)\n"
75 "#define RESIDENTPRI %d\n"
76 "#define RESIDENTFLAGS %s\n",
77 cfg->basename,
78 cfg->libbase, _libbasetype, _libbasetype,
79 cfg->modulename, cfg->suffix,
80 cfg->majorversion, cfg->majorversion,
81 cfg->minorversion, cfg->minorversion,
82 cfg->modulename, cfg->suffix, cfg->majorversion, cfg->minorversion,
83 cfg->datestring, cfg->copyright[0] != '\0' ? " " : "", cfg->copyright,
84 cfg->copyright,
85 cfg->residentpri,
86 residentflags
89 for (linelistit = cfg->cdefprivatelines; linelistit!=NULL; linelistit = linelistit->next)
90 fprintf(out, "%s\n", linelistit->s);
92 /* Following code assumes that the input was checked to be consistent during the
93 * parsing of the .conf file in config.c, no checks are done here
95 if (cfg->sysbase_field != NULL)
96 fprintf(out,
97 "#define GM_SYSBASE_FIELD(lh) (((LIBBASETYPEPTR)lh)->%s)\n",
98 cfg->sysbase_field
100 if (cfg->seglist_field != NULL)
101 fprintf(out,
102 "#define GM_SEGLIST_FIELD(lh) (((LIBBASETYPEPTR)lh)->%s)\n",
103 cfg->seglist_field
105 if (cfg->getidfunc != NULL)
106 fprintf(out, "#define GM_GETID ((IPTR)%s())\n", cfg->getidfunc);
107 for (classlistit = cfg->classlist; classlistit != NULL; classlistit = classlistit->next)
109 int storeptr;
111 if (classlistit->classptr_field != NULL)
113 storeptr = 1;
114 snprintf(line, 1023, "((LIBBASETYPEPTR)lh)->%s", classlistit->classptr_field);
116 else if (classlistit->classptr_var != NULL)
118 storeptr = 1;
119 snprintf(line, 1023, "%s", classlistit->classptr_var);
121 else if ((classlistit->classid != NULL) && !(classlistit->options & COPTION_PRIVATE))
123 storeptr = 0;
124 snprintf(line, 1023, "FindClass(%s)", classlistit->classid);
126 else
127 /* Don't write anything */
128 continue;
130 fprintf(out,
131 "#define %s_STORE_CLASSPTR %d\n",
132 classlistit->basename, storeptr
135 /* When class is the main class also define GM_CLASSPTR_FIELD for legacy */
136 if (strcmp(classlistit->basename, cfg->basename) == 0)
137 fprintf(out, "#define GM_CLASSPTR_FIELD(lh) (%s)\n", line);
139 fprintf(out,
140 "#define %s_CLASSPTR_FIELD(lh) (%s)\n",
141 classlistit->basename, line
145 if ((cfg->options & OPTION_DUPBASE) && cfg->rootbase_field != NULL)
146 fprintf(out,
147 "#define GM_ROOTBASE_FIELD(lh) (((LIBBASETYPEPTR)lh)->%s)\n",
148 cfg->rootbase_field
151 if (cfg->options & OPTION_DUPPERID)
153 fprintf(out,
154 "\n"
155 "#ifndef GM_GETID\n"
156 "#define GM_GETID ((IPTR)FindTask(NULL))\n"
157 "\n"
158 "IPTR __GM_Id2(void);\n"
159 "#define GM_GETID2 __GM_Id2()\n"
160 "\n"
161 "#define __GM_OWNGETID\n"
162 "#endif\n"
163 "\n"
164 "#if defined(GM_GETID2) && !defined(GM_GETPARENTBASEID2)\n"
165 "LIBBASETYPEPTR GM_UNIQUENAME(__GetParentLibbase)(LIBBASETYPEPTR lh);\n"
166 "#define GM_GETPARENTBASEID2(lh) GM_UNIQUENAME(__GetParentLibbase)(lh)\n"
167 "\n"
168 "#define __GM_OWNPARENTBASEID2\n"
169 "#endif\n"
173 fprintf
175 out,
176 "\n"
177 "#endif /* _%s_LIBDEFS_H */\n",
178 cfg->modulenameupper
181 if (ferror(out))
183 perror("Error writing libdefs.h");
184 fclose(out);
185 exit(20);
188 fclose(out);