refactored some code. compiles now without suppresing any warning with gcc-6.3.0.
[AROS.git] / tools / genmodule / writemakefile.c
blob70e83be6f7f882a8a51983271f23ac4ccfc57943
1 /*
2 Copyright © 2005-2017, 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 name[512];
49 struct stringlist *s;
51 snprintf(name, sizeof(name), "%s/Makefile.%s%s", cfg->gendir, cfg->modulename, cfg->modtypestr);
53 out = fopen(name, "w");
55 if (out == NULL)
57 perror(name);
58 exit(20);
61 fprintf(out,
62 "%s_STARTFILES += %s_start\n"
63 "%s_ENDFILES += %s_end\n"
64 "%s_MODDIR += %s\n",
65 cfg->modulename, cfg->modulename,
66 cfg->modulename, cfg->modulename,
67 cfg->modulename, cfg->moddir
70 fprintf(out, "%s_LINKLIBFILES +=", cfg->modulename);
71 if (cfg->options & OPTION_STUBS)
72 writemakefilestubs(cfg, 0, out);
73 if (cfg->options & OPTION_AUTOINIT)
74 fprintf(out, " %s_autoinit", cfg->modulename);
75 if (cfg->modtype == LIBRARY)
76 fprintf(out, " %s_getlibbase", cfg->modulename);
77 fprintf(out, "\n");
78 fprintf(out, "%s_RELLINKLIBFILES +=", cfg->modulename);
79 if (cfg->options & OPTION_RELLINKLIB)
81 if (cfg->options & OPTION_STUBS)
82 writemakefilestubs(cfg, 1, out);
83 if (cfg->options & OPTION_AUTOINIT)
84 fprintf(out, " %s_relautoinit", cfg->modulename);
85 if (cfg->modtype == LIBRARY)
86 fprintf(out, " %s_relgetlibbase", cfg->modulename);
88 fprintf(out, "\n");
90 /* Currently there are no asm files anymore */
91 fprintf(out, "%s_LINKLIBAFILES +=\n", cfg->modulename);
92 fprintf(out, "%s_RELLINKLIBAFILES +=\n", cfg->modulename);
94 fprintf(out, "%s_INCLUDES += ", cfg->modulename);
95 if (cfg->options & OPTION_INCLUDES)
97 fprintf(out,
98 "clib/%s_protos.h inline/%s.h defines/%s.h proto/%s.h",
99 cfg->includename, cfg->includename, cfg->includename, cfg->includename
102 if (cfg->interfacelist)
104 struct interfaceinfo *in;
105 for (in = cfg->interfacelist; in; in = in->next)
106 fprintf(out,
107 " interface/%s.h"
108 , in->interfacename
111 fprintf(out, "\n");
114 fprintf(out, "%s_LINKLIBCFLAGS +=", cfg->modulename);
115 for (s = cfg->rellibs; s ; s = s->next)
116 fprintf(out, " -D__%s_RELLIBBASE__", upname(s->s));
117 fprintf(out, "\n");
119 fprintf(out, "%s_CFLAGS += $(%s_LINKLIBCFLAGS)", cfg->modulename, cfg->modulename);
120 if (cfg->options & OPTION_RELLINKLIB)
121 fprintf(out, " -D__%s_NOLIBBASE__", upname(cfg->modulename));
122 fprintf(out, "\n");
124 fprintf(out, "%s_LINKLIBDFLAGS +=", cfg->modulename);
125 for (s = cfg->rellibs; s ; s = s->next)
126 fprintf(out, " -D__%s_RELLIBBASE__", upname(s->s));
127 fprintf(out, "\n");
129 fprintf(out, "%s_DFLAGS += $(%s_LINKLIBDFLAGS)", cfg->modulename, cfg->modulename);
130 if (cfg->options & OPTION_RELLINKLIB)
131 fprintf(out, " -D__%s_NOLIBBASE__", upname(cfg->modulename));
132 fprintf(out, "\n");
134 fprintf(out, "%s_LDFLAGS +=", cfg->modulename);
135 fprintf(out,"\n");
137 fprintf(out, "%s_LIBS +=", cfg->modulename);
138 for (s = cfg->rellibs; s ; s = s->next)
139 fprintf(out, " %s_rel", s->s);
140 fprintf(out,"\n");
142 if (ferror(out))
144 perror("Error writing Makefile");
145 fclose(out);
146 exit(20);
149 fclose(out);