2 Copyright © 2005-2014, 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
)
51 snprintf(name
, sizeof(name
), "%s/Makefile.%s%s", cfg
->gendir
, cfg
->modulename
, cfg
->modtypestr
);
53 out
= fopen(name
, "w");
62 "%s_STARTFILES += %s_start\n"
63 "%s_ENDFILES += %s_end\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
);
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
);
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
)
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
)
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
));
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
));
120 fprintf(out
, "%s_LDFLAGS +=", cfg
->modulename
);
123 fprintf(out
, "%s_LIBS +=", cfg
->modulename
);
124 for (s
= cfg
->rellibs
; s
; s
= s
->next
)
125 fprintf(out
, " %s_rel", s
->s
);
130 perror("Error writing Makefile");