Fix create_patch macro.
[AROS.git] / tools / genmodule / writemakefile.c
blob82cf0691e11d7432269a4023ee3865c3f0e35cf5
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
81 if (cfg->interfacelist)
83 struct interfaceinfo *in;
84 for (in = cfg->interfacelist; in; in = in->next)
85 fprintf(out,
86 " interface/%s.h"
87 , in->interfacename
90 fprintf(out, "\n");
92 fprintf(out, "%s_CFLAGS +=", cfg->modulename);
93 for (s = cfg->rellibs; s ; s = s->next)
94 fprintf(out, " -D__%s_RELLIBBASE__", upname(s->s));
95 fprintf(out, "\n");
97 fprintf(out, "%s_DFLAGS +=", cfg->modulename);
98 for (s = cfg->rellibs; s ; s = s->next)
99 fprintf(out, " -D__%s_RELLIBBASE__", upname(s->s));
100 fprintf(out, "\n");
102 fprintf(out, "%s_LDFLAGS +=", cfg->modulename);
103 fprintf(out,"\n");
105 fprintf(out, "%s_LIBS +=", cfg->modulename);
106 for (s = cfg->rellibs; s ; s = s->next)
107 fprintf(out, " %s_rel", s->s);
108 fprintf(out,"\n");
110 if (ferror(out))
112 perror("Error writing Makefile");
113 fclose(out);
114 exit(20);
117 fclose(out);