@@ -50,9 +50,13 @@ static const char *J4A_LICENSE_HEADER =
50
50
" * This file is automatically generated by jni4android, do not modify.\n "
51
51
" */\n " ;
52
52
53
- void CompilationUnit::do_build (std::ostream &h_os, std::ostream &c_os)
53
+ void CompilationUnit::do_build (
54
+ std::ostream &h_os,
55
+ std::ostream &c_os,
56
+ std::ostream &j4a_include_stream,
57
+ std::ostream &j4a_loader_stream)
54
58
{
55
- Class *clazz = get_clazz ();
59
+ Class *clazz = get_clazz ();
56
60
57
61
printf (" ==========\n " );
58
62
// printf("%s\n", __func__);
@@ -81,14 +85,24 @@ void CompilationUnit::do_build(std::ostream &h_os, std::ostream &c_os)
81
85
82
86
clazz->build_c_class_decl (c_os);
83
87
clazz->build_c_func_impl (c_os);
88
+
89
+ // .include.j4a
90
+ j4a_include_stream << " #include \" " << get_include_path () << " \" " ;
91
+
92
+ // .loader.j4a
93
+ j4a_loader_stream << " J4A_LOAD_CLASS(" << clazz->get_c_class_name (false ) << " );" ;
84
94
}
85
95
86
96
void CompilationUnit::build ()
87
97
{
88
98
std::ofstream h_stream;
89
99
std::ofstream c_stream;
100
+ std::ofstream j4a_include_stream;
101
+ std::ofstream j4a_loader_stream;
90
102
std::ostream *h_stream_ptr = &std::cout;
91
103
std::ostream *c_stream_ptr = &std::cout;
104
+ std::ostream *j4a_include_stream_ptr = &std::cout;
105
+ std::ostream *j4a_loader_stream_ptr = &std::cout;
92
106
93
107
if (!Context::instance ()->get_h_file_path ().empty ()) {
94
108
h_stream.open (Context::instance ()->get_h_file_path ().c_str ());
@@ -108,5 +122,23 @@ void CompilationUnit::build()
108
122
c_stream_ptr = &c_stream;
109
123
}
110
124
111
- do_build (*h_stream_ptr, *c_stream_ptr);
125
+ if (!Context::instance ()->get_j4a_include_file_path ().empty ()) {
126
+ j4a_include_stream.open (Context::instance ()->get_j4a_include_file_path ().c_str ());
127
+ if (!j4a_include_stream) {
128
+ printf (" failed to open output .include.j4a file %s\n " , Context::instance ()->get_j4a_include_file_path ().c_str ());
129
+ return ;
130
+ }
131
+ j4a_include_stream_ptr = &j4a_include_stream;
132
+ }
133
+
134
+ if (!Context::instance ()->get_j4a_loader_file_path ().empty ()) {
135
+ j4a_loader_stream.open (Context::instance ()->get_j4a_loader_file_path ().c_str ());
136
+ if (!j4a_loader_stream) {
137
+ printf (" failed to open output .loader.j4a file %s\n " , Context::instance ()->get_j4a_loader_file_path ().c_str ());
138
+ return ;
139
+ }
140
+ j4a_loader_stream_ptr = &j4a_loader_stream;
141
+ }
142
+
143
+ do_build (*h_stream_ptr, *c_stream_ptr, *j4a_include_stream_ptr, *j4a_loader_stream_ptr);
112
144
}
0 commit comments