2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
5 Function to write libdefs.h. Part of genmodule.
9 void writeinclibdefs(struct config
*cfg
)
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
;
21 if (funclistit
== NULL
)
22 funccount
= cfg
->firstlvo
-1;
25 while (funclistit
->next
!= NULL
)
26 funclistit
= funclistit
->next
;
28 funccount
= funclistit
->lvo
;
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");
63 "#ifndef _%s_LIBDEFS_H\n"
64 "#define _%s_LIBDEFS_H\n"
66 "#include <exec/types.h>\n"
68 cfg
->modulenameupper
, cfg
->modulenameupper
71 sep
= strcmp(cfg
->suffix
, "handler") ? '.' : '-';
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 ",
87 cfg
->libbase
, _libbasetype
, _libbasetype
,
88 cfg
->modulename
, sep
, cfg
->suffix
,
89 cfg
->majorversion
, cfg
->majorversion
,
90 cfg
->minorversion
, cfg
->minorversion
,
91 cfg
->modulename
, cfg
->suffix
93 if (cfg
->versionextra
)
94 fprintf(out
, "%s ", cfg
->versionextra
);
96 "%u.%u (%s)%s%s\\r\\n\"\n"
97 "#define COPYRIGHT_STRING \"%s\"\n"
98 "#define LIBEND GM_UNIQUENAME(End)\n"
99 "#define LIBFUNCTABLE GM_UNIQUENAME(FuncTable)\n"
100 "#define RESIDENTPRI %d\n"
101 "#define RESIDENTFLAGS %s\n"
102 "#define FUNCTIONS_COUNT %u\n",
103 cfg
->majorversion
, cfg
->minorversion
,
104 cfg
->datestring
, cfg
->copyright
[0] != '\0' ? " " : "", cfg
->copyright
,
111 for (linelistit
= cfg
->cdefprivatelines
; linelistit
!=NULL
; linelistit
= linelistit
->next
)
112 fprintf(out
, "%s\n", linelistit
->s
);
114 /* Following code assumes that the input was checked to be consistent during the
115 * parsing of the .conf file in config.c, no checks are done here
117 if (cfg
->sysbase_field
!= NULL
)
119 "#define GM_SYSBASE_FIELD(lh) (((LIBBASETYPEPTR)lh)->%s)\n",
122 if (cfg
->oopbase_field
!= NULL
)
124 "#define GM_OOPBASE_FIELD(lh) (((LIBBASETYPEPTR)lh)->%s)\n",
127 if (cfg
->seglist_field
!= NULL
)
129 "#define GM_SEGLIST_FIELD(lh) (((LIBBASETYPEPTR)lh)->%s)\n",
132 for (classlistit
= cfg
->classlist
; classlistit
!= NULL
; classlistit
= classlistit
->next
)
136 if (classlistit
->classptr_field
!= NULL
)
139 snprintf(line
, 1023, "((LIBBASETYPEPTR)lh)->%s", classlistit
->classptr_field
);
141 else if ((classlistit
->classid
!= NULL
) && !(classlistit
->options
& COPTION_PRIVATE
))
144 snprintf(line
, 1023, "FindClass(%s)", classlistit
->classid
);
147 /* Don't write anything */
151 "#define %s_STORE_CLASSPTR %d\n",
152 classlistit
->basename
, storeptr
155 /* When class is the main class also define GM_CLASSPTR_FIELD for legacy */
156 if (strcmp(classlistit
->basename
, cfg
->basename
) == 0)
157 fprintf(out
, "#define GM_CLASSPTR_FIELD(lh) (%s)\n", line
);
160 "#define %s_CLASSPTR_FIELD(lh) (%s)\n",
161 classlistit
->basename
, line
165 if (cfg
->options
& OPTION_DUPBASE
)
167 if (cfg
->rootbase_field
!= NULL
)
169 "#define GM_ROOTBASE_FIELD(lh) (((LIBBASETYPEPTR)lh)->%s)\n",
174 if (cfg
->rellibs
|| (cfg
->options
& OPTION_DUPBASE
) || (cfg
->options
& OPTION_STACKCALL
))
178 "char *__aros_getoffsettable(void);\n"
180 , !(cfg
->options
& OPTION_STACKCALL
) ? "#ifndef __aros_getoffsettable" : "/* Thus must be externally visible for stackcall libs */"
181 , !(cfg
->options
& OPTION_STACKCALL
) ? "#endif" : ""
184 if (cfg
->options
& OPTION_PERTASKBASE
)
188 "LIBBASETYPEPTR __GM_GetBaseParent(LIBBASETYPEPTR);\n"
196 "#endif /* _%s_LIBDEFS_H */\n",
202 perror("Error writing libdefs.h");