2 Copyright © 2005-2019, The AROS Development Team. All rights reserved.
5 Code to write a Makefile with variables that provides the files
6 and configuration for building the module
12 #include "genmodule.h"
15 static inline const char *upname(const char *s
)
17 static char name
[512];
20 while (s
&& i
< (sizeof(name
)-1))
21 name
[i
++] = toupper(*(s
++));
27 static inline void writemakefilestubs(struct config
*cfg
, int is_rel
, FILE *out
)
29 struct functionhead
*funclistit
;
31 for (funclistit
= cfg
->funclist
;
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
)
48 char moduleversname
[512];
54 snprintf(moduleversname
, sizeof(moduleversname
), "%s", cfg
->modulename
);
58 snprintf(moduleversname
, sizeof(moduleversname
), "%s_%s", cfg
->modulename
, cfg
->flavour
);
61 snprintf(name
, sizeof(name
), "%s/Makefile.%s%s", cfg
->gendir
, moduleversname
, cfg
->modtypestr
);
62 out
= fopen(name
, "w");
71 "%s_STARTFILES += %s_start\n"
72 "%s_ENDFILES += %s_end\n"
74 moduleversname
, cfg
->modulename
,
75 moduleversname
, cfg
->modulename
,
76 moduleversname
, cfg
->moddir
79 fprintf(out
, "%s_LINKLIBFILES +=", moduleversname
);
80 if (cfg
->options
& OPTION_STUBS
)
81 writemakefilestubs(cfg
, 0, out
);
82 if (cfg
->options
& OPTION_AUTOINIT
)
83 fprintf(out
, " %s_autoinit", cfg
->modulename
);
84 if (cfg
->modtype
== LIBRARY
)
85 fprintf(out
, " %s_getlibbase", cfg
->modulename
);
87 fprintf(out
, "%s_RELLINKLIBFILES +=", moduleversname
);
88 if (cfg
->options
& OPTION_RELLINKLIB
)
90 if (cfg
->options
& OPTION_STUBS
)
91 writemakefilestubs(cfg
, 1, out
);
92 if (cfg
->options
& OPTION_AUTOINIT
)
93 fprintf(out
, " %s_relautoinit", cfg
->modulename
);
94 if (cfg
->modtype
== LIBRARY
)
95 fprintf(out
, " %s_relgetlibbase", cfg
->modulename
);
99 /* Currently there are no asm files anymore */
100 fprintf(out
, "%s_LINKLIBAFILES +=\n", moduleversname
);
101 fprintf(out
, "%s_RELLINKLIBAFILES +=\n", moduleversname
);
103 fprintf(out
, "%s_INCLUDES += ", moduleversname
);
104 if (cfg
->options
& OPTION_INCLUDES
)
107 "clib/%s_protos.h inline/%s.h defines/%s.h proto/%s.h",
108 cfg
->includename
, cfg
->includename
, cfg
->includename
, cfg
->includename
111 if (cfg
->interfacelist
)
113 struct interfaceinfo
*in
;
114 for (in
= cfg
->interfacelist
; in
; in
= in
->next
)
123 fprintf(out
, "%s_CPPFLAGS +=", moduleversname
);
124 for (s
= cfg
->rellibs
; s
; s
= s
->next
)
125 fprintf(out
, " -D__%s_RELLIBBASE__", upname(s
->s
));
126 if (cfg
->options
& OPTION_RELLINKLIB
)
127 fprintf(out
, " -D__%s_NOLIBBASE__", upname(cfg
->modulename
));
129 fprintf(out
, "%s_LINKLIBCPPFLAGS +=", moduleversname
);
130 for (s
= cfg
->rellibs
; s
; s
= s
->next
)
131 fprintf(out
, " -D__%s_RELLIBBASE__", upname(s
->s
));
134 fprintf(out
, "%s_CFLAGS +=", moduleversname
);
136 fprintf(out
, "%s_LINKLIBCFLAGS +=", moduleversname
);
138 fprintf(out
, "%s_CXXFLAGS +=", moduleversname
);
140 fprintf(out
, "%s_LINKLIBCXXFLAGS +=", moduleversname
);
143 fprintf(out
, "%s_LDFLAGS +=", moduleversname
);
146 fprintf(out
, "%s_LIBS +=", moduleversname
);
147 for (s
= cfg
->rellibs
; s
; s
= s
->next
)
148 fprintf(out
, " %s_rel", s
->s
);
153 perror("Error writing Makefile");