diff --git a/utils/pas2jni/pas2jni.pas b/utils/pas2jni/pas2jni.pas index 2ecd999f84..c0a8d67917 100644 --- a/utils/pas2jni/pas2jni.pas +++ b/utils/pas2jni/pas2jni.pas @@ -33,15 +33,16 @@ begin writeln; writeln('Options:'); writeln(' -U - Unit search path, semicolon delimited. Wildcards are allowed.'); - writeln(' -L - Set output library name.'); - writeln(' -P - Set Java package name.'); + writeln(' -L - Set the output library name.'); + writeln(' -P - Set the Java package name.'); writeln(' -O - Set output path for Pascal files.'); writeln(' -J - Set output path for Java files.'); - writeln(' -D - Set full path to the "ppudump" program.'); + writeln(' -D - Set the full path to the "ppudump" program.'); writeln(' -I - Include the list of specified objects in the output. The list is'); writeln(' semicolon delimited. To read the list from a file use -I@'); writeln(' -E - Exclude the list of specified objects from the output. The list is'); writeln(' semicolon delimited. To read the list from a file use -E@'); + writeln(' -N - Do not generate a Java code for auto-loading of the shared library.'); writeln(' -? - Show this help information.'); end; @@ -150,6 +151,8 @@ begin w.ExcludeList.AddStrings(sl); sl.Free; end; + 'N': + w.LibAutoLoad:=False; '?', 'H': begin ShowUsage; diff --git a/utils/pas2jni/writer.pas b/utils/pas2jni/writer.pas index 95f91b97d2..784957b7ad 100644 --- a/utils/pas2jni/writer.pas +++ b/utils/pas2jni/writer.pas @@ -155,6 +155,7 @@ type JavaOutPath: string; IncludeList: TStringList; ExcludeList: TStringList; + LibAutoLoad: boolean; constructor Create; destructor Destroy; override; @@ -1628,13 +1629,15 @@ begin end; end; - Fjs.WriteLn('static private boolean _JniLibLoaded = false;'); - Fjs.WriteLn('public static void InitJni() {'); - Fjs.WriteLn('if (!_JniLibLoaded) {', 1); - Fjs.WriteLn('_JniLibLoaded=true;', 2); - Fjs.WriteLn(Format('System.loadLibrary("%s");', [LibName]), 2); - Fjs.WriteLn('}', 1); - Fjs.WriteLn('}'); + if LibAutoLoad then begin + Fjs.WriteLn('static private boolean _JniLibLoaded = false;'); + Fjs.WriteLn('public static void InitJni() {'); + Fjs.WriteLn('if (!_JniLibLoaded) {', 1); + Fjs.WriteLn('_JniLibLoaded=true;', 2); + Fjs.WriteLn(Format('System.loadLibrary("%s");', [LibName]), 2); + Fjs.WriteLn('}', 1); + Fjs.WriteLn('}'); + end; // Support functions Fjs.WriteLn('public native static long AllocMemory(int Size);'); @@ -1644,7 +1647,8 @@ begin Fjs.WriteLn; Fjs.WriteLn('public static class PascalObject {'); Fjs.IncI; - Fjs.WriteLn(Format('static { %s.system.InitJni(); }', [JavaPackage])); + if LibAutoLoad then + Fjs.WriteLn(Format('static { %s.system.InitJni(); }', [JavaPackage])); Fjs.WriteLn('protected long _pasobj = 0;'); Fjs.WriteLn('protected PascalObject() { }'); Fjs.WriteLn('protected PascalObject(PascalObject obj) { if (obj != null) _pasobj=obj._pasobj; }'); @@ -1676,12 +1680,6 @@ begin Fjs.DecI; Fjs.WriteLn('}'); - // Class - Fjs.WriteLn; - Fjs.WriteLn('native static long GetClassRef(int index);'); - AddNativeMethod(u, '_GetClassRef', 'GetClassRef', '(I)J'); - Fjs.WriteLn('static TClass GetTClass(int index) { TClass c = new TClass(null); c._pasobj=GetClassRef(index); return c; }'); - // Record Fjs.WriteLn; Fjs.WriteLn('public static class Record extends PascalObjectEx {'); @@ -2025,8 +2023,10 @@ begin Fjs.WriteLn; end; - Fjs.WriteLn(Format('static { %s.system.InitJni(); }', [JavaPackage])); - Fjs.WriteLn; + if LibAutoLoad then begin + Fjs.WriteLn(Format('static { %s.system.InitJni(); }', [JavaPackage])); + Fjs.WriteLn; + end; // First pass for i:=0 to u.Count - 1 do begin @@ -2074,6 +2074,14 @@ begin end; end; + // Class ref helpers + if (u.Name = 'system') and (FClasses.IndexOf('system.TClass', nil) >= 0) then begin + Fjs.WriteLn('native static long GetClassRef(int index);'); + AddNativeMethod(u, '_GetClassRef', 'GetClassRef', '(I)J'); + Fjs.WriteLn('static TClass GetTClass(int index) { TClass c = new TClass(null); c._pasobj=GetClassRef(index); return c; }'); + Fjs.WriteLn; + end; + Fjs.DecI; Fjs.WriteLn('}'); finally @@ -2729,6 +2737,7 @@ begin FThisUnit:=TUnitDef.Create(nil, dtUnit); FRecords:=TObjectList.Create(False); FRealClasses:=TObjectList.Create(False); + LibAutoLoad:=True; end; function DoCanUseDef(def, refdef: TDef): boolean;