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