revert 213 commits (to 56092) from the last month. 10 still need work to resolve...
[AROS.git] / tools / genmodule / writemakefile.c
blob1e82ca3ef56cd02e0d9a490a9469a0713d0c772b
1 /*
2 Copyright © 2005-2019, The AROS Development Team. All rights reserved.
3 $Id$
5 Code to write a Makefile with variables that provides the files
6 and configuration for building the module
7 */
8 #include <stdio.h>
9 #include <stddef.h>
10 #include <string.h>
12 #include "genmodule.h"
13 #include "config.h"
15 static inline const char *upname(const char *s)
17 static char name[512];
18 int i = 0;
20 while (s && i < (sizeof(name)-1))
21 name[i++] = toupper(*(s++));
22 name[i] = 0;
24 return &name[0];
27 static inline void writemakefilestubs(struct config *cfg, int is_rel, FILE *out)
29 struct functionhead *funclistit;
31 for (funclistit = cfg->funclist;
32 funclistit!=NULL;
33 funclistit = funclistit->next
36 if (funclistit->lvo >= cfg->firstlvo && funclistit->libcall == STACK)
38 fprintf(out, " %s_%s_%sstub\\\n", cfg->modulename, funclistit->name, is_rel ? "rel" : "");
42 fprintf(out, " %s_regcall_%sstubs", cfg->modulename, is_rel ? "rel" : "");
45 void writemakefile(struct config *cfg)
47 FILE *out;
48 char moduleversname[512];
49 char name[512];
50 struct stringlist *s;
52 if (!cfg->flavour)
54 snprintf(moduleversname, sizeof(moduleversname), "%s", cfg->modulename);
56 else
58 snprintf(moduleversname, sizeof(moduleversname), "%s_%s", cfg->modulename, cfg->flavour);
61 snprintf(name, sizeof(name), "%s/Makefile.%s%s", cfg->gendir, moduleversname, cfg->modtypestr);
62 out = fopen(name, "w");
64 if (out == NULL)
66 perror(name);
67 exit(20);
70 fprintf(out,
71 "%s_STARTFILES += %s_start\n"
72 "%s_ENDFILES += %s_end\n"
73 "%s_MODDIR += %s\n",
74 moduleversname, cfg->modulename,
75 moduleversname, cfg->modulename,
76 moduleversname, cfg->moddir
79 fprintf(out, "%s_LINKLIBFILES +=", moduleversname);
80 if (cfg->options & OPTION_STUBS)
81 writemakefilestubs(cfg, 0, out);
82 if (cfg->options & OPTION_AUTOINIT)
83 fprintf(out, " %s_autoinit", cfg->modulename);
84 if (cfg->modtype == LIBRARY)
85 fprintf(out, " %s_getlibbase", cfg->modulename);
86 fprintf(out, "\n");
87 fprintf(out, "%s_RELLINKLIBFILES +=", moduleversname);
88 if (cfg->options & OPTION_RELLINKLIB)
90 if (cfg->options & OPTION_STUBS)
91 writemakefilestubs(cfg, 1, out);
92 if (cfg->options & OPTION_AUTOINIT)
93 fprintf(out, " %s_relautoinit", cfg->modulename);
94 if (cfg->modtype == LIBRARY)
95 fprintf(out, " %s_relgetlibbase", cfg->modulename);
97 fprintf(out, "\n");
99 /* Currently there are no asm files anymore */
100 fprintf(out, "%s_LINKLIBAFILES +=\n", moduleversname);
101 fprintf(out, "%s_RELLINKLIBAFILES +=\n", moduleversname);
103 fprintf(out, "%s_INCLUDES += ", moduleversname);
104 if (cfg->options & OPTION_INCLUDES)
106 fprintf(out,
107 "clib/%s_protos.h inline/%s.h defines/%s.h proto/%s.h",
108 cfg->includename, cfg->includename, cfg->includename, cfg->includename
111 if (cfg->interfacelist)
113 struct interfaceinfo *in;
114 for (in = cfg->interfacelist; in; in = in->next)
115 fprintf(out,
116 " interface/%s.h"
117 , in->interfacename
120 fprintf(out, "\n");
123 fprintf(out, "%s_CPPFLAGS +=", moduleversname);
124 for (s = cfg->rellibs; s ; s = s->next)
125 fprintf(out, " -D__%s_RELLIBBASE__", upname(s->s));
126 if (cfg->options & OPTION_RELLINKLIB)
127 fprintf(out, " -D__%s_NOLIBBASE__", upname(cfg->modulename));
128 fprintf(out, "\n");
129 fprintf(out, "%s_LINKLIBCPPFLAGS +=", moduleversname);
130 for (s = cfg->rellibs; s ; s = s->next)
131 fprintf(out, " -D__%s_RELLIBBASE__", upname(s->s));
132 fprintf(out, "\n");
134 fprintf(out, "%s_CFLAGS +=", moduleversname);
135 fprintf(out,"\n");
136 fprintf(out, "%s_LINKLIBCFLAGS +=", moduleversname);
137 fprintf(out,"\n");
138 fprintf(out, "%s_CXXFLAGS +=", moduleversname);
139 fprintf(out,"\n");
140 fprintf(out, "%s_LINKLIBCXXFLAGS +=", moduleversname);
141 fprintf(out,"\n");
143 fprintf(out, "%s_LDFLAGS +=", moduleversname);
144 fprintf(out,"\n");
146 fprintf(out, "%s_LIBS +=", moduleversname);
147 for (s = cfg->rellibs; s ; s = s->next)
148 fprintf(out, " %s_rel", s->s);
149 fprintf(out,"\n");
151 if (ferror(out))
153 perror("Error writing Makefile");
154 fclose(out);
155 exit(20);
158 fclose(out);