2 Copyright © 1995-2009, 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
;
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");
51 "#ifndef _%s_LIBDEFS_H\n"
52 "#define _%s_LIBDEFS_H\n"
54 "#include <exec/types.h>\n"
56 cfg
->modulenameupper
, cfg
->modulenameupper
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",
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
,
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
)
97 "#define GM_SYSBASE_FIELD(lh) (((LIBBASETYPEPTR)lh)->%s)\n",
100 if (cfg
->seglist_field
!= NULL
)
102 "#define GM_SEGLIST_FIELD(lh) (((LIBBASETYPEPTR)lh)->%s)\n",
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
)
111 if (classlistit
->classptr_field
!= NULL
)
114 snprintf(line
, 1023, "((LIBBASETYPEPTR)lh)->%s", classlistit
->classptr_field
);
116 else if (classlistit
->classptr_var
!= NULL
)
119 snprintf(line
, 1023, "%s", classlistit
->classptr_var
);
121 else if ((classlistit
->classid
!= NULL
) && !(classlistit
->options
& COPTION_PRIVATE
))
124 snprintf(line
, 1023, "FindClass(%s)", classlistit
->classid
);
127 /* Don't write anything */
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
);
140 "#define %s_CLASSPTR_FIELD(lh) (%s)\n",
141 classlistit
->basename
, line
145 if ((cfg
->options
& OPTION_DUPBASE
) && cfg
->rootbase_field
!= NULL
)
147 "#define GM_ROOTBASE_FIELD(lh) (((LIBBASETYPEPTR)lh)->%s)\n",
151 if (cfg
->options
& OPTION_DUPPERID
)
156 "#define GM_GETID ((IPTR)FindTask(NULL))\n"
158 "IPTR __GM_Id2(void);\n"
159 "#define GM_GETID2 __GM_Id2()\n"
161 "#define __GM_OWNGETID\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"
168 "#define __GM_OWNPARENTBASEID2\n"
177 "#endif /* _%s_LIBDEFS_H */\n",
183 perror("Error writing libdefs.h");