- Now emits and accepts dates for version strings in canonical format (no
[tangerine.git] / tools / genmodule / writeinclibdefs.c
blob1bc33ff802761aaa9b1f662e7b25b716a29854a3
1 /*
2 Copyright © 1995-2008, 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 \"%s.%s %u.%u (%s)%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,
81 cfg->datestring, cfg->copyright[0] != '\0' ? " " : "", cfg->copyright,
82 cfg->copyright,
83 cfg->residentpri,
84 residentflags
87 for (linelistit = cfg->cdefprivatelines; linelistit!=NULL; linelistit = linelistit->next)
88 fprintf(out, "%s\n", linelistit->s);
90 /* Following code assumes that the input was checked to be consistent during the
91 * parsing of the .conf file in config.c, no checks are done here
93 if (cfg->sysbase_field != NULL)
94 fprintf(out,
95 "#define GM_SYSBASE_FIELD(lh) (((LIBBASETYPEPTR)lh)->%s)\n",
96 cfg->sysbase_field
98 if (cfg->seglist_field != NULL)
99 fprintf(out,
100 "#define GM_SEGLIST_FIELD(lh) (((LIBBASETYPEPTR)lh)->%s)\n",
101 cfg->seglist_field
103 if (cfg->getidfunc != NULL)
104 fprintf(out, "#define GM_GETID ((IPTR)%s())\n", cfg->getidfunc);
105 for (classlistit = cfg->classlist; classlistit != NULL; classlistit = classlistit->next)
107 int storeptr;
109 if (classlistit->classptr_field != NULL)
111 storeptr = 1;
112 snprintf(line, 1023, "((LIBBASETYPEPTR)lh)->%s", classlistit->classptr_field);
114 else if (classlistit->classptr_var != NULL)
116 storeptr = 1;
117 snprintf(line, 1023, "%s", classlistit->classptr_var);
119 else if ((classlistit->classid != NULL) && !(classlistit->options & COPTION_PRIVATE))
121 storeptr = 0;
122 snprintf(line, 1023, "FindClass(%s)", classlistit->classid);
124 else
125 /* Don't write anything */
126 continue;
128 fprintf(out,
129 "#define %s_STORE_CLASSPTR %d\n",
130 classlistit->basename, storeptr
133 /* When class is the main class also define GM_CLASSPTR_FIELD for legacy */
134 if (strcmp(classlistit->basename, cfg->basename) == 0)
135 fprintf(out, "#define GM_CLASSPTR_FIELD(lh) (%s)\n", line);
137 fprintf(out,
138 "#define %s_CLASSPTR_FIELD(lh) (%s)\n",
139 classlistit->basename, line
143 if ((cfg->options & OPTION_DUPBASE) && cfg->rootbase_field != NULL)
144 fprintf(out,
145 "#define GM_ROOTBASE_FIELD(lh) (((LIBBASETYPEPTR)lh)->%s)\n",
146 cfg->rootbase_field
149 fprintf
151 out,
152 "\n"
153 "#endif /* _%s_LIBDEFS_H */\n",
154 cfg->modulenameupper
157 if (ferror(out))
159 perror("Error writing libdefs.h");
160 fclose(out);
161 exit(20);
164 fclose(out);