Fixed to work with ABIv1.
[AROS.git] / tools / genmodule / writeincproto.c
blob8b0bd79c033537e935090552e83eb51c8ceb1753
1 /*
2 Copyright © 1995-2017, The AROS Development Team. All rights reserved.
4 Desc: Function to write proto/modulename(_rel).h. Part of genmodule.
5 */
7 #include "genmodule.h"
9 void writeincproto(struct config *cfg)
11 FILE *out;
12 char line[256], define[256], *banner;
13 struct linelist *linelistit;
15 snprintf(line, 255, "%s/proto/%s.h",
16 cfg->gendir, cfg->includename
18 out = fopen(line, "w");
20 if (out == NULL)
22 perror(line);
23 exit(20);
26 banner = getBanner(cfg);
27 fprintf(out,
28 "#ifndef PROTO_%s_H\n"
29 "#define PROTO_%s_H\n"
30 "\n"
31 "%s"
32 "\n"
33 , cfg->includenameupper
34 , cfg->includenameupper
35 , banner
37 fprintf(out,
38 "#include <exec/types.h>\n"
39 "%s"
40 "#include <aros/system.h>\n"
41 "\n"
42 "#include <clib/%s_protos.h>\n"
43 "\n",
44 (cfg->modtype == DEVICE) ? "#include <exec/devices.h>\n" : "",
45 cfg->includename
47 freeBanner(banner);
48 if (!(cfg->options & OPTION_DUPBASE))
50 /* If single libbase store libbase in global variable.
51 This is here to be legacy compliant for code that expects this
52 global libbase. If that would not be needed we could always use
53 __aros_getbase_ModName() to access libbase
55 fprintf(out,
56 "#ifndef __%s_RELLIBBASE__\n"
57 " #if !defined(__NOLIBBASE__) && !defined(__%s_NOLIBBASE__)\n"
58 " #if !defined(%s)\n"
59 " #ifdef __%s_STDLIBBASE__\n"
60 " extern struct Library *%s;\n"
61 " #else\n"
62 " extern %s%s;\n"
63 " #endif\n"
64 " #endif\n"
65 " #ifndef __aros_getbase_%s\n"
66 " #define __aros_getbase_%s() (%s)\n"
67 " #endif\n"
68 " #endif /* defined(__NOLIBBASE__) || defined(__DUMMY_NOLIBBASE__) */\n"
69 "#else /* __%s_RELLIBASE__ */\n"
70 " extern const IPTR __aros_rellib_offset_%s;\n"
71 " #define AROS_RELLIB_OFFSET_%s __aros_rellib_offset_%s\n"
72 " #define AROS_RELLIB_BASE_%s __aros_rellib_base_%s\n"
73 " #ifndef __aros_getbase_%s\n"
74 " #ifndef __aros_getoffsettable\n"
75 " char *__aros_getoffsettable(void);\n"
76 " #endif\n"
77 " #define __aros_getbase_%s() (*(%s*)(__aros_getoffsettable()+__aros_rellib_offset_%s))\n"
78 " #endif\n"
79 "#endif\n"
80 "\n"
81 "#ifndef __aros_getbase_%s\n"
82 "extern %s__aros_getbase_%s(void);\n"
83 "#endif\n"
84 "\n",
85 cfg->includenameupper,
86 cfg->includenameupper,
87 cfg->libbase,
88 cfg->includenameupper,
89 cfg->libbase,
90 cfg->libbasetypeptrextern, cfg->libbase,
91 cfg->libbase,
92 cfg->libbase, cfg->libbase,
93 cfg->includenameupper,
94 cfg->libbase,
95 cfg->includenameupper, cfg->libbase,
96 cfg->includenameupper, cfg->libbase,
97 cfg->libbase,
98 cfg->libbase, cfg->libbasetypeptrextern, cfg->libbase,
99 cfg->libbase, cfg->libbasetypeptrextern, cfg->libbase
102 else /* cfg->options & OPTION_DUPBASE */
104 /* If multiple libbase access libbase through __aros_getbase_ModName() */
105 fprintf(out,
106 "%s__aros_getbase_%s(void);\n"
107 " extern const IPTR __aros_rellib_offset_%s;\n"
108 " #define AROS_RELLIB_OFFSET_%s __aros_rellib_offset_%s\n"
109 " #define AROS_RELLIB_BASE_%s __aros_rellib_base_%s\n"
110 "\n",
111 cfg->libbasetypeptrextern, cfg->libbase,
112 cfg->libbase,
113 cfg->includenameupper, cfg->libbase,
114 cfg->includenameupper, cfg->libbase
118 // define name must not start with a digit
119 // this solves a problem with proto/8svx.h
120 if (isdigit(cfg->includenameupper[0]))
122 snprintf(define, sizeof define, "X%s", cfg->includenameupper);
124 else
126 strncpy(define, cfg->includenameupper, sizeof define);
129 fprintf(out,
130 "#if !defined(NOLIBINLINE) && !defined(%s_NOLIBINLINE) && !defined(__%s_RELLIBBASE__)\n"
131 "# include <inline/%s.h>\n"
132 "#elif !defined(NOLIBDEFINES) && !defined(%s_NOLIBDEFINES)\n"
133 "# include <defines/%s.h>\n"
134 "#endif\n"
135 "\n"
136 "#endif /* PROTO_%s_H */\n",
137 define, cfg->includenameupper,
138 cfg->includename,
139 define,
140 cfg->includename,
141 cfg->includenameupper
144 fclose(out);