grub2: bring back build of aros-side grub2 tools
[AROS.git] / tools / genmodule / writemakefile.c
blobf2eef4c85e02c8c92451ebfbb9c6f6a341e31cdd
1 /*
2 Copyright © 2005-2014, 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");
113 fprintf(out, "%s_CFLAGS +=", cfg->modulename);
114 for (s = cfg->rellibs; s ; s = s->next)
115 fprintf(out, " -D__%s_RELLIBBASE__", upname(s->s));
116 fprintf(out, "\n");
118 fprintf(out, "%s_DFLAGS +=", cfg->modulename);
119 for (s = cfg->rellibs; s ; s = s->next)
120 fprintf(out, " -D__%s_RELLIBBASE__", upname(s->s));
121 fprintf(out, "\n");
123 fprintf(out, "%s_LDFLAGS +=", cfg->modulename);
124 fprintf(out,"\n");
126 fprintf(out, "%s_LIBS +=", cfg->modulename);
127 for (s = cfg->rellibs; s ; s = s->next)
128 fprintf(out, " %s_rel", s->s);
129 fprintf(out,"\n");
131 if (ferror(out))
133 perror("Error writing Makefile");
134 fclose(out);
135 exit(20);
138 fclose(out);