tools/genmodule: Added .unusedlibbase option
[AROS.git] / tools / genmodule / writemakefile.c
blob14b3e2771e3a936aec1dbaac855f348e25bdc3c8
1 /*
2 Copyright © 2005-2011, 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 void writemakefile(struct config *cfg)
29 FILE *out;
30 char name[512];
31 struct stringlist *s;
33 snprintf(name, sizeof(name), "%s/Makefile.%s", cfg->gendir, cfg->modulename);
35 out = fopen(name, "w");
37 if (out == NULL)
39 perror(name);
40 exit(20);
43 fprintf(out,
44 "%s_STARTFILES += %s_start\n"
45 "%s_ENDFILES += %s_end\n"
46 "%s_MODDIR += %s\n",
47 cfg->modulename, cfg->modulename,
48 cfg->modulename, cfg->modulename,
49 cfg->modulename, cfg->moddir
52 fprintf(out, "%s_LINKLIBFILES +=", cfg->modulename);
53 if (cfg->options & OPTION_STUBS)
54 fprintf(out, " %s_stubs", cfg->modulename);
55 if (cfg->options & OPTION_AUTOINIT)
56 fprintf(out, " %s_autoinit", cfg->modulename);
57 if (cfg->modtype == LIBRARY)
58 fprintf(out, " %s_getlibbase", cfg->modulename);
59 fprintf(out, "\n");
60 fprintf(out, "%s_RELLINKLIBFILES +=", cfg->modulename);
61 if (cfg->options & OPTION_STUBS)
62 fprintf(out, " %s_relstubs", cfg->modulename);
63 if (cfg->options & OPTION_AUTOINIT)
64 fprintf(out, " %s_relautoinit", cfg->modulename);
65 if (cfg->modtype == LIBRARY)
66 fprintf(out, " %s_relgetlibbase", cfg->modulename);
67 fprintf(out, "\n");
69 /* Currently there are no asm files anymore */
70 fprintf(out, "%s_LINKLIBAFILES +=\n", cfg->modulename);
71 fprintf(out, "%s_RELLINKLIBAFILES +=\n", cfg->modulename);
73 fprintf(out, "%s_INCLUDES += ", cfg->modulename);
74 if (cfg->options & OPTION_INCLUDES)
76 fprintf(out,
77 "clib/%s_protos.h inline/%s.h defines/%s.h proto/%s.h",
78 cfg->modulename, cfg->modulename, cfg->modulename, cfg->modulename
80 if (cfg->modtype == LIBRARY)
81 fprintf(out, " inline/%s_rel.h defines/%s_rel.h proto/%s_rel.h",
82 cfg->modulename, cfg->modulename, cfg->modulename);
84 if (cfg->interfacelist)
86 struct interfaceinfo *in;
87 for (in = cfg->interfacelist; in; in = in->next)
88 fprintf(out,
89 " interface/%s.h"
90 , in->interfacename
93 fprintf(out, "\n");
95 fprintf(out, "%s_CFLAGS +=", cfg->modulename);
96 for (s = cfg->rellibs; s ; s = s->next)
97 fprintf(out, " -D__%s_RELLIBBASE__", upname(s->s));
98 fprintf(out, "\n");
100 fprintf(out, "%s_DFLAGS +=", cfg->modulename);
101 for (s = cfg->rellibs; s ; s = s->next)
102 fprintf(out, " -D__%s_RELLIBBASE__", upname(s->s));
103 fprintf(out, "\n");
105 fprintf(out, "%s_LDFLAGS +=", cfg->modulename);
106 fprintf(out,"\n");
108 fprintf(out, "%s_LIBS +=", cfg->modulename);
109 for (s = cfg->rellibs; s ; s = s->next)
110 fprintf(out, " %s_rel", s->s);
111 fprintf(out,"\n");
113 if (ferror(out))
115 perror("Error writing Makefile");
116 fclose(out);
117 exit(20);
120 fclose(out);