Removed codesetslib because we have now external repo.
[cake.git] / tools / genmodule / writeinclibdefs.c
blob6d984f8667bda916ad78aa94ec79dc58703c8f74
1 /*
2 Copyright © 1995-2006, 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 cfg->modulenameupper, cfg->modulenameupper
57 fprintf
59 out,
60 "#define GM_UNIQUENAME(n) %s_ ## n\n"
61 "#define LIBBASE %s\n"
62 "#define LIBBASETYPE %s\n"
63 "#define LIBBASETYPEPTR %s *\n"
64 "#define MOD_NAME_STRING \"%s.%s\"\n"
65 "#define VERSION_NUMBER %u\n"
66 "#define MAJOR_VERSION %u\n"
67 "#define REVISION_NUMBER %u\n"
68 "#define MINOR_VERSION %u\n"
69 "#define VERSION_STRING \"$VER: %s.%s %u.%u (%s) %s\\r\\n\"\n"
70 "#define COPYRIGHT_STRING \"%s\"\n"
71 "#define LIBEND GM_UNIQUENAME(End)\n"
72 "#define LIBFUNCTABLE GM_UNIQUENAME(FuncTable)\n"
73 "#define RESIDENTPRI %d\n"
74 "#define RESIDENTFLAGS %s\n",
75 cfg->basename,
76 cfg->libbase, _libbasetype, _libbasetype,
77 cfg->modulename, cfg->suffix,
78 cfg->majorversion, cfg->majorversion,
79 cfg->minorversion, cfg->minorversion,
80 cfg->modulename, cfg->suffix, cfg->majorversion, cfg->minorversion, cfg->datestring,
81 cfg->copyright, cfg->copyright,
82 cfg->residentpri,
83 residentflags
86 for (linelistit = cfg->cdefprivatelines; linelistit!=NULL; linelistit = linelistit->next)
87 fprintf(out, "%s\n", linelistit->s);
89 /* Following code assumes that the input was checked to be consistent during the
90 * parsing of the .conf file in config.c, no checks are done here
92 if (cfg->sysbase_field != NULL)
93 fprintf(out,
94 "#define GM_SYSBASE_FIELD(lh) (((LIBBASETYPEPTR)lh)->%s)\n",
95 cfg->sysbase_field
97 if (cfg->seglist_field != NULL)
98 fprintf(out,
99 "#define GM_SEGLIST_FIELD(lh) (((LIBBASETYPEPTR)lh)->%s)\n",
100 cfg->seglist_field
102 for (classlistit = cfg->classlist; classlistit != NULL; classlistit = classlistit->next)
104 int storeptr;
106 if (classlistit->classptr_field != NULL)
108 storeptr = 1;
109 snprintf(line, 1023, "((LIBBASETYPEPTR)lh)->%s", classlistit->classptr_field);
111 else if (classlistit->classptr_var != NULL)
113 storeptr = 1;
114 snprintf(line, 1023, "%s", classlistit->classptr_var);
116 else if ((classlistit->classid != NULL) && !(classlistit->options & COPTION_PRIVATE))
118 storeptr = 0;
119 snprintf(line, 1023, "FindClass(%s)", classlistit->classid);
121 else
122 /* Don't write anything */
123 continue;
125 fprintf(out,
126 "#define %s_STORE_CLASSPTR %d\n",
127 classlistit->basename, storeptr
130 /* When class is the main class also define GM_CLASSPTR_FIELD for legacy */
131 if (strcmp(classlistit->basename, cfg->basename) == 0)
132 fprintf(out, "#define GM_CLASSPTR_FIELD(lh) (%s)\n", line);
134 fprintf(out,
135 "#define %s_CLASSPTR_FIELD(lh) (%s)\n",
136 classlistit->basename, line
140 if ((cfg->options & OPTION_DUPBASE) && cfg->rootbase_field != NULL)
141 fprintf(out,
142 "#define GM_ROOTBASE_FIELD(lh) (((LIBBASETYPEPTR)lh)->%s)\n",
143 cfg->rootbase_field
146 fprintf
148 out,
149 "\n"
150 "#endif /* _%s_LIBDEFS_H */\n",
151 cfg->modulenameupper
154 if (ferror(out))
156 perror("Error writing libdefs.h");
157 fclose(out);
158 exit(20);
161 fclose(out);