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_RELLINKLIB
)
81 if (cfg
->options
& OPTION_STUBS
)
82 writemakefilestubs(cfg
, 1, out
);
83 if (cfg
->options
& OPTION_AUTOINIT
)
84 fprintf(out
, " %s_relautoinit", cfg
->modulename
);
85 if (cfg
->modtype
== LIBRARY
)
86 fprintf(out
, " %s_relgetlibbase", cfg
->modulename
);
90 /* Currently there are no asm files anymore */
91 fprintf(out
, "%s_LINKLIBAFILES +=\n", cfg
->modulename
);
92 fprintf(out
, "%s_RELLINKLIBAFILES +=\n", cfg
->modulename
);
94 fprintf(out
, "%s_INCLUDES += ", cfg
->modulename
);
95 if (cfg
->options
& OPTION_INCLUDES
)
98 "clib/%s_protos.h inline/%s.h defines/%s.h proto/%s.h",
99 cfg
->includename
, cfg
->includename
, cfg
->includename
, cfg
->includename
102 if (cfg
->interfacelist
)
104 struct interfaceinfo
*in
;
105 for (in
= cfg
->interfacelist
; in
; in
= in
->next
)
113 fprintf(out
, "%s_CFLAGS +=", cfg
->modulename
);
114 for (s
= cfg
->rellibs
; s
; s
= s
->next
)
115 fprintf(out
, " -D__%s_RELLIBBASE__", upname(s
->s
));
118 fprintf(out
, "%s_DFLAGS +=", cfg
->modulename
);
119 for (s
= cfg
->rellibs
; s
; s
= s
->next
)
120 fprintf(out
, " -D__%s_RELLIBBASE__", upname(s
->s
));
123 fprintf(out
, "%s_LDFLAGS +=", cfg
->modulename
);
126 fprintf(out
, "%s_LIBS +=", cfg
->modulename
);
127 for (s
= cfg
->rellibs
; s
; s
= s
->next
)
128 fprintf(out
, " %s_rel", s
->s
);
133 perror("Error writing Makefile");