2 * (c) Oleg Puchinin 2006
3 * graycardinalster@gmail.com
7 #include <gclib/gclib.h>
13 extern "C" DArray
* plugin_init (struct env_t
*env
);
17 char * __name2obj (char * name
)
22 S
= rindex (m_buf
, '.');
26 return strdup (m_buf
);
29 void __aa (EArray
* a
, DArray
* b
)
37 count
= b
->get_size ();
38 for (i
= 0; i
< count
; ++i
)
39 a
->add (strdup (LPCHAR (b
->get (i
))));
42 void __astr (EArray
* a
, char *str
)
49 d_split
= Dsplit (str
, " ");
54 d_split
->foreach (free
);
58 void __array_log (EArray
* a
)
63 for (i
= 0; i
< a
->get_size (); ++i
) {
65 printf ("%s ", a
->get (i
));
70 int compile_cppfile (char * name
)
75 char * oname
= __name2obj (name
);
81 d_param
= new EArray(32);
82 d_param
->add (compile_env
->get ("CXX"));
83 __astr (d_param
, compile_env
->get ("CXXFLAGS"));
84 if (compile_env
->get ("OPTS"))
85 __astr (d_param
, compile_env
->get ("OPTS"));
90 d_param
->add (LPCHAR (NULL
));
92 if (SB_FLGET (SB_FLVERBOSE
))
93 __array_log (d_param
);
95 printf ("\tCXX\t%s\n", oname
);
99 execvp (compile_env
->get ("CXX"), d_param
->get_skeleton ());
101 waitpid (pid
, &status
, 0);
106 int compile_cfile (char * name
)
111 char * oname
= __name2obj (name
);
117 d_param
= new EArray(32);
118 d_param
->add (compile_env
->get ("CC"));
119 __astr (d_param
, compile_env
->get ("CFLAGS"));
120 if (compile_env
->get ("OPTS"))
121 __astr (d_param
, compile_env
->get ("OPTS"));
124 d_param
->add (oname
);
126 d_param
->add (LPCHAR (NULL
));
128 if (SB_FLGET (SB_FLVERBOSE
))
129 __array_log (d_param
);
131 printf ("\tCC\t%s\n", oname
);
135 execvp (compile_env
->get ("CC"), d_param
->get_skeleton ());
137 waitpid (pid
, &status
, 0);
148 count
= ENV
->d_files
->get_size ();
149 for (i
= 0; i
< count
; ++i
) {
150 S
= rindex (ENV
->d_files
->get (i
), '.');
153 if (EQ (S
, ".cpp") || EQ (S
, ".cxx"))
154 compile_cppfile (ENV
->d_files
->get (i
));
156 compile_cfile (ENV
->d_files
->get (i
));
162 void __init_compile_env ()
170 compile_env
= new EHash
;
171 cc
= ENV
->settings
->get ("CC");
172 cxx
= ENV
->settings
->get ("CXX");
173 cflags
= ENV
->settings
->get ("CFLAGS");
174 cxxflags
= ENV
->settings
->get ("CXXFLAGS");
175 opts
= ENV
->settings
->get ("OPTS");
182 cflags
= "-O3 -Wall -pipe";
186 if (SB_FLGET (SB_FLVERBOSE
)) {
187 printf ("C compiler: %s\n", cc
);
188 printf ("C++ compiler: %s\n", cxx
);
189 printf ("C flags: %s\n", cflags
);
190 printf ("C++ flags: %s\n", cxxflags
);
192 compile_env
->set ("CC", strdup (cc
));
193 compile_env
->set ("CXX", strdup (cxx
));
194 compile_env
->set ("CFLAGS", strdup (cflags
));
195 compile_env
->set ("CXXFLAGS", strdup (cxxflags
));
197 compile_env
->set ("OPTS", strdup (opts
));
200 char compile_opt2 (DArray
* d_opts
, int * pos
)
205 if (! d_opts
|| ! pos
)
208 S
= d_opts
->get (*pos
);
209 if (EQ (S
, "--compile")) {
210 __init_compile_env ();
220 printf ("C/C++ compilation plugin.\n");
221 printf ("Version: 0.2\n");
222 printf ("options: --compile\n");
225 DArray
* plugin_init (struct env_t
*env
)
228 struct mod_feature
* pm
;
231 Ret
= new DArray (1);
232 pm
= CNEW (mod_feature
, 1);
233 memset (pm
, 0, sizeof (mod_feature
));
234 pm
->mod
.Type
= TYPE_FEATURE
;
235 pm
->mod
.Version
= strdup ("1.0");
236 pm
->mod
.info
= compile_info
;
237 pm
->opt2
= compile_opt2
;
239 Ret
->add (LPCHAR (pm
));