2 Copyright © 1995-2008, 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 cfg
->modulenameupper
, cfg
->modulenameupper
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",
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
,
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
)
95 "#define GM_SYSBASE_FIELD(lh) (((LIBBASETYPEPTR)lh)->%s)\n",
98 if (cfg
->seglist_field
!= NULL
)
100 "#define GM_SEGLIST_FIELD(lh) (((LIBBASETYPEPTR)lh)->%s)\n",
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
)
109 if (classlistit
->classptr_field
!= NULL
)
112 snprintf(line
, 1023, "((LIBBASETYPEPTR)lh)->%s", classlistit
->classptr_field
);
114 else if (classlistit
->classptr_var
!= NULL
)
117 snprintf(line
, 1023, "%s", classlistit
->classptr_var
);
119 else if ((classlistit
->classid
!= NULL
) && !(classlistit
->options
& COPTION_PRIVATE
))
122 snprintf(line
, 1023, "FindClass(%s)", classlistit
->classid
);
125 /* Don't write anything */
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
);
138 "#define %s_CLASSPTR_FIELD(lh) (%s)\n",
139 classlistit
->basename
, line
143 if ((cfg
->options
& OPTION_DUPBASE
) && cfg
->rootbase_field
!= NULL
)
145 "#define GM_ROOTBASE_FIELD(lh) (((LIBBASETYPEPTR)lh)->%s)\n",
153 "#endif /* _%s_LIBDEFS_H */\n",
159 perror("Error writing libdefs.h");