2 package org
.de
.metux
.unitool
.tools
;
4 import org
.de
.metux
.unitool
.base
.LibraryInfo
;
5 import org
.de
.metux
.unitool
.base
.ToolParam
;
6 import org
.de
.metux
.unitool
.base
.InstallerParam
;
7 import org
.de
.metux
.unitool
.base
.EParameterMissing
;
8 import org
.de
.metux
.unitool
.base
.EParameterInvalid
;
9 import org
.de
.metux
.unitool
.db
.StoreLibtoolArchive
;
10 import org
.de
.metux
.unitool
.db
.LoadLibtoolArchive
;
12 import org
.de
.metux
.util
.Exec
;
13 import org
.de
.metux
.util
.Environment
;
14 import org
.de
.metux
.util
.StrUtil
;
15 import org
.de
.metux
.util
.PathNormalizer
;
16 import org
.de
.metux
.util
.FileOps
;
17 import org
.de
.metux
.util
.StrSplit
;
18 import org
.de
.metux
.util
.UniqueValues
;
20 import java
.io
.IOException
;
23 public class LTLibraryInstaller
25 void __check_arname(LibraryInfo libinf
)
27 String str
= libinf
.library_name
+
28 (StrUtil
.isEmpty(libinf
.release
) ?
"" : "-"+libinf
.release
)+
31 if (!libinf
.arname
.equals(str
))
32 System
.err
.println("arname may be broken: arname="+libinf
.arname
+" modname="+libinf
.module_name
+" libname="+libinf
.library_name
+" should be="+str
);
35 String
__libdirs(LibraryInfo libinf
, PathNormalizer norm
)
39 if (!StrUtil
.isEmpty(libinf
.libdir
))
40 str
+= " -L"+libinf
.libdir
;
42 if (libinf
.search_pathes
!=null)
43 for (int x
=0; x
<libinf
.search_pathes
.length
; x
++)
44 if (!StrUtil
.isEmpty(libinf
.search_pathes
[x
]))
45 str
+= " -L"+norm
.strip_sysroot(libinf
.search_pathes
[x
]);
50 String
__dependency(LibraryInfo libinf
, LibraryInfo cur
, PathNormalizer norm
)
52 if (cur
==null) return "";
54 if (cur
.library_name
==null)
55 throw new NullPointerException("cur.library_name is null");
56 if (cur
.module_name
==null)
57 throw new NullPointerException("cur.module_name is null");
59 throw new NullPointerException("cur.prefix is null");
61 throw new NullPointerException("cur.libdir is null");
62 if (cur
.uninstalled_libdir
==null)
63 throw new NullPointerException("cur.uninstalled_libdir is null");
66 "LTLibraryInstaller: Processing dependency\n"+
67 " module_name="+cur
.module_name
+"\n"+
68 " library_name="+cur
.library_name
+"\n"+
69 " prefix="+cur
.prefix
+"\n"+
70 " libdir="+cur
.libdir
+"\n"+
71 " uninst="+cur
.uninstalled_libdir
);
77 System
.out
.println(" ==> selected to be linked statically. no dependency filed.");
78 if (!StrUtil
.isEmpty(cur
.libdir
))
79 throw new RuntimeException("uuh, why is libdir set ?");
83 System
.out
.println(" ==> selected to be linked dynamically "+cur
.library_name
+" / "+cur
.module_name
);
85 // we have no libtool file for it.
86 if (StrUtil
.isEmpty(cur
.cf
))
88 add_dep
= __libdirs(cur
, norm
) + " -l"+cur
.module_name
;
93 if (StrUtil
.isEmpty(cur
.libdir
))
94 throw new RuntimeException("uuh, why is libdir empty ?!");
95 add_dep
= cur
.libdir
+"/"+PathNormalizer
.basename(cur
.cf
);
99 System
.out
.println(" ==> adding: "+add_dep
);
103 public void run(InstallerParam param
)
104 throws EParameterMissing
, EParameterInvalid
107 String installer_cmd
= param
.getInstallerCommand();
108 String la_source
= param
.getInstallSource();
109 String la_target
= param
.getInstallTarget();
112 if (!la_source
.endsWith(".la"))
113 throw new RuntimeException("*.la as source expected");
115 if (!la_target
.endsWith(".la"))
116 throw new RuntimeException("*.la as target expected");
118 String parent
= new File(la_target
).getParent();
120 throw new RuntimeException("parent is null ! ("+la_target
+")");
122 String dirname
=PathNormalizer
.dirname(la_source
);
125 libinf
= LoadLibtoolArchive
.load_archive(
126 la_source
, param
.getSysroot(), dirname
, false);
128 catch (IOException e
)
130 throw new RuntimeException("loading .la archive failed"+e
,e
);
133 if (!StrUtil
.isEmpty(libinf
.dlname
))
134 if (libinf
.dlname
.equals("null"))
135 throw new RuntimeException("someone messed up dlname");
137 throw new RuntimeException("why isn't dlname null ?: "+libinf
.dlname
);
139 libinf
.dlname
= libinf
.library_name
+".so."+libinf
.version_current
+"."+libinf
.version_age
+"."+libinf
.version_revision
;
141 __check_arname(libinf
);
143 // libinf.dlname has the form libfoo.so.1
145 (StrUtil
.isEmpty(libinf
.prefix
) ?
"" : libinf
.prefix
+"/")+
146 libinf
.uninstalled_libdir
+
148 (StrUtil
.isEmpty(libinf
.release
) ?
"" : "-"+libinf
.release
)+
151 String so_link2
= libinf
.library_name
+".so";
152 String so_link1
= libinf
.library_name
+".so."+libinf
.version_current
;
153 String so_name
= libinf
.library_name
+".so."+libinf
.version_current
+"."+libinf
.version_age
+"."+libinf
.version_revision
;
154 String so_target
= parent
+"/"+libinf
.dlname
;
156 // do some fixes in the .la file
157 libinf
.installed
= true;
158 libinf
.dlname
= so_link1
;
159 libinf
.dynamic_libnames
= new String
[3];
160 libinf
.dynamic_libnames
[0] = so_name
;
161 libinf
.dynamic_libnames
[1] = so_link1
;
162 libinf
.dynamic_libnames
[2] = so_link2
;
165 "LTLibraryInstaller: processing .la file: "+la_source
+"\n"+
166 " parent="+parent
+"\n"+
167 " so_target="+so_target
+"\n"+
168 " so_source="+so_source
+"\n"+
169 " libdir="+libinf
.libdir
171 if (libinf
.search_pathes
== null)
172 System
.out
.println(" No search pathes");
174 for (int x
=0; x
<libinf
.search_pathes
.length
; x
++)
175 System
.out
.println(" search_path="+libinf
.search_pathes
[x
]);
177 // probably this should be moved to StoreLibtoolArchive
178 String deps
= __libdirs(libinf
, param
.normalizer
)+" ";
179 if (libinf
.dependencies
!=null)
180 for (int x
=0; x
<libinf
.dependencies
.length
; x
++)
181 deps
+= " "+__dependency(libinf
, libinf
.dependencies
[x
], param
.normalizer
);
183 libinf
.dependency_names
= UniqueValues
.unique(StrSplit
.split(deps
));
185 StoreLibtoolArchive
.store(libinf
,la_target
);
187 System
.out
.println("LTLibraryInstaller: copying so to: "+so_target
);
189 Exec exec
= new Exec();
191 FileOps
.mkdir(parent
);
192 FileOps
.rm(parent
+"/"+so_link1
);
193 FileOps
.rm(parent
+"/"+so_link2
);
195 exec
.run("cp --preserve "+so_source
+" "+so_target
);
196 exec
.run("cd "+parent
+" && ln -s "+so_name
+" "+so_link1
);
197 exec
.run("cd "+parent
+" && ln -s "+so_name
+" "+so_link2
);
199 if (param
.getInstallStrip())
202 String strip_cmd
= Environment
.getenv("STRIP");
203 if ((strip_cmd
==null)||(strip_cmd
.equals("")))
204 throw new EParameterMissing("missing STRIP command");
205 System
.out
.println("LTLibraryInstaller: stripping: "+so_target
);
206 System
.out
.println(strip_cmd
+" --strip-unneeded "+so_target
);
207 exec
.run(strip_cmd
+" --strip-debug "+so_target
);
210 System
.out
.println("LTLibraryInstaller: not stripping");
212 System
.out
.println("LTLibraryInstaller: done.");
217 // handling for imported libtool libraries.
218 // since we now natively support .la files in our toolchain,
219 // we want to use them in the dependencies, instead of
220 // their content (-l*,-L*).
222 // we have two situations here:
223 // a) the library has an installed_libdir attribute and thus
224 // is linked dynamically. in this case we have to add
225 // the libtool filename under $installed_libdir
226 // b) the library has *no* installed_libdir, so is linked
227 // statically and no more dependencies are needed.