Added support for a new config option, "includename". This value defaults
[AROS.git] / tools / genmodule / writemakefile.c
blobd5c3843aa069392b9402e38b9281d2241b0c0ec3
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_STUBS)
80 writemakefilestubs(cfg, 1, out);
81 if (cfg->options & OPTION_AUTOINIT)
82 fprintf(out, " %s_relautoinit", cfg->modulename);
83 if (cfg->modtype == LIBRARY)
84 fprintf(out, " %s_relgetlibbase", cfg->modulename);
85 fprintf(out, "\n");
87 /* Currently there are no asm files anymore */
88 fprintf(out, "%s_LINKLIBAFILES +=\n", cfg->modulename);
89 fprintf(out, "%s_RELLINKLIBAFILES +=\n", cfg->modulename);
91 fprintf(out, "%s_INCLUDES += ", cfg->modulename);
92 if (cfg->options & OPTION_INCLUDES)
94 fprintf(out,
95 "clib/%s_protos.h inline/%s.h defines/%s.h proto/%s.h",
96 cfg->includename, cfg->includename, cfg->includename, cfg->includename
99 if (cfg->interfacelist)
101 struct interfaceinfo *in;
102 for (in = cfg->interfacelist; in; in = in->next)
103 fprintf(out,
104 " interface/%s.h"
105 , in->interfacename
108 fprintf(out, "\n");
110 fprintf(out, "%s_CFLAGS +=", cfg->modulename);
111 for (s = cfg->rellibs; s ; s = s->next)
112 fprintf(out, " -D__%s_RELLIBBASE__", upname(s->s));
113 fprintf(out, "\n");
115 fprintf(out, "%s_DFLAGS +=", cfg->modulename);
116 for (s = cfg->rellibs; s ; s = s->next)
117 fprintf(out, " -D__%s_RELLIBBASE__", upname(s->s));
118 fprintf(out, "\n");
120 fprintf(out, "%s_LDFLAGS +=", cfg->modulename);
121 fprintf(out,"\n");
123 fprintf(out, "%s_LIBS +=", cfg->modulename);
124 for (s = cfg->rellibs; s ; s = s->next)
125 fprintf(out, " %s_rel", s->s);
126 fprintf(out,"\n");
128 if (ferror(out))
130 perror("Error writing Makefile");
131 fclose(out);
132 exit(20);
135 fclose(out);