pkg-config file now has script pathes
[unitool.git] / base / LinkerParam.java
blobafa8b4659ce2230c003eba748c9a38d1d1c75648
2 package org.de.metux.unitool.base;
4 import org.de.metux.util.PathNormalizer;
5 import org.de.metux.util.UniqueValues;
6 import org.de.metux.util.StrUtil;
7 import org.de.metux.util.StrReplace;
8 import org.de.metux.propertylist.IPropertylist;
10 public class LinkerParam extends ToolParam
12 // FIXME !!!
13 public static final boolean hack_link_intree_so_direct = false;
15 public static final String cf_linktype = "link-type";
16 public static final String cf_linktype_shared = "shared";
17 public static final String cf_linktype_executable = "executable";
18 public static final String cf_runtime_library_path = "runtime-library-path";
19 public static final String cf_library_path = "library-path";
20 public static final String cf_object_links = "link-object";
21 public static final String cf_static_links = "link-static";
22 public static final String cf_shared_links = "link-shared";
23 public static final String cf_library_name = "library-name";
24 public static final String cf_library_dlname = "library-dlname";
25 public static final String cf_module_name = "module-name";
26 public static final String cf_linker_command = "linker-command";
27 public static final String cf_linker_flag = "linker-flag";
28 public static final String cf_output_file = "output-file";
29 public static final String cf_version_info = "version-info";
30 public static final String cf_version_current = "version-current";
31 public static final String cf_version_age = "version-age";
32 public static final String cf_version_revision = "version-revision";
33 public static final String cf_export_symbols_regex = "export-symbols-regex";
34 public static final String cf_export_symbols = "export-symbols";
35 public static final String cf_import_libtool = "import-libtool";
36 public static final String cf_linker_dll_command = "tools/linker/link-dll/linker-command";
37 public static final String cf_linker_executable_command = "tools/linker/link-executable/linker-command";
39 public LinkerParam(ToolConfig cf)
41 super(cf);
44 public String[] getRuntimeLibraryPathes()
46 return get_path_list_strip_sysroot(cf_runtime_library_path);
49 public void addRuntimeLibraryPath(String path[])
51 if (path!=null)
52 for (int x=0; x<path.length; x++)
53 addRuntimeLibraryPath(path[x]);
56 public void clearRuntimeLibraryPath()
58 remove(cf_runtime_library_path);
61 public String[] getObjectLinks_add_sysroot()
63 String[] pathes = getObjectLinks();
64 for (int x=0; x<pathes.length; x++)
65 pathes[x] = normalizer.dec_sysroot(pathes[x]);
66 return pathes;
69 public String[] getObjectLinks()
71 return get_str_list(cf_object_links);
74 public String[] getStaticLinks()
76 return get_str_list(cf_static_links);
79 public void setLinktypeShared()
81 set(cf_linktype, cf_linktype_shared);
84 public void clearLinktype()
86 remove(cf_linktype);
89 public boolean isLinktypeShared()
91 return (get_str_def(cf_linktype,cf_linktype_executable).equals(cf_linktype_shared));
94 public void setModuleName(String name)
96 set(cf_module_name, name);
99 public String getModuleName()
101 return get(cf_module_name);
104 public void setLibraryName(String name)
106 set(cf_library_name, name);
109 public String getLibraryName()
111 return get(cf_library_name);
114 // dlname == soname
115 public void setDLName(String name)
117 set(cf_library_dlname,name);
120 public String getDLName()
122 return get(cf_library_dlname);
125 public void clearLibraryName()
127 remove(cf_library_name);
130 public void clearLinkerCommand()
132 remove(cf_linker_command);
135 public void setLinkerCommand(String cmd)
137 set(cf_linker_command, cmd);
140 public String getLinkerCommand()
142 return get(cf_linker_command);
145 public void addObjectLink(String obj)
147 add(cf_object_links, obj);
150 public void addObjectLink(String objs[])
152 if (objs!=null)
153 for (int x=0; x<objs.length; x++)
154 addObjectLink(objs[x]);
157 public void addSharedLink(String libname)
159 if (!StrUtil.isEmpty(libname))
160 add(cf_shared_links, libname);
163 public void addSharedLink(String libs[])
165 if (libs!=null)
166 for (int x=0; x<libs.length; x++)
167 addSharedLink(libs[x]);
170 public void addStaticLink(String libfile)
172 add(cf_static_links, libfile);
175 public void addStaticLink(String libs[])
177 add(cf_static_links, libs);
180 // fixme: we also should kick off sysroot-prefixes here
181 // we assume its already in sysroot'ed notation !
182 // aehm, ... no, it always should be ABSOLUTE notation
183 public void addRuntimeLibraryPath(String path)
185 add(cf_runtime_library_path, PathNormalizer.normalize(path));
188 public void addLinkFlag(String flag)
190 add(cf_linker_flag, flag);
193 public void addLinkFlag(String flag[])
195 add(cf_linker_flag, flag);
198 public String getLinkFlag()
200 return get(cf_linker_flag);
203 public String[] getLinkFlags()
205 return get_str_list(cf_linker_flag);
208 public void clearLinkFlag()
210 remove(cf_linker_flag);
213 public String[] getSharedLinks()
215 return UniqueValues.unique(get_str_list(cf_shared_links));
218 // fixme: we also should kick off sysroot-prefixes here
219 public void addLibraryPath(String path)
221 add(cf_library_path, PathNormalizer.normalize(path));
224 public void addLibraryPath_enc_sysroot(String[] path)
226 if (path!=null)
227 for (int x=0; x<path.length; x++)
229 String px = normalizer.enc_sysroot(path[x]);
230 add(cf_library_path, px);
234 public void addLibraryPath_enc_sysroot(String path)
236 add(cf_library_path, normalizer.enc_sysroot(path));
239 public void addLibraryPath(String path[])
241 if (path!=null)
242 for (int x=0; x<path.length; x++)
243 addLibraryPath(path[x]);
246 public void clearLibraryPath()
248 remove(cf_library_path);
251 public String[] getLibraryPathes()
253 return get_path_list(cf_library_path);
256 public String[] getLibraryPathes_dec_sysroot()
258 String[] pathes = getLibraryPathes();
259 for (int x=0; x<pathes.length; x++)
260 pathes[x] = normalizer.dec_sysroot(pathes[x]);
261 pathes = UniqueValues.unique(pathes);
262 return pathes;
265 public void clearObjectLink()
267 remove(cf_object_links);
270 public void clearSharedLink()
272 remove(cf_shared_links);
275 public void clearStaticLink()
277 remove(cf_static_links);
280 public void setOutputFile(String fn)
282 set(cf_output_file,fn);
285 public String getOutputFile()
287 return get(cf_output_file);
290 public void clearOutputFile()
292 remove(cf_output_file);
295 public void setVersionCurrent(int c)
297 set(cf_version_current,c);
299 public void setVersionAge(int c)
301 set(cf_version_age,c);
304 public void setVersionRevision(int c)
306 set(cf_version_revision,c);
308 public int getVersionRevision_i()
310 return get_int(cf_version_revision);
312 public int getVersionCurrent_i()
314 return get_int(cf_version_current);
316 public int getVersionAge_i()
318 return get_int(cf_version_age);
321 public void clearVersionInfo()
323 remove(cf_version_current);
324 remove(cf_version_age);
325 remove(cf_version_revision);
326 remove(cf_version_info);
329 public String getVersionInfo()
331 return get(cf_version_info);
334 public void setVersionInfo(String version)
335 throws EVersionSyntaxError
337 int x;
339 version = StrReplace.replace(".",":",version).trim();
340 set(cf_version_info, version);
342 if ((x=version.indexOf(":"))<1)
343 throw new EVersionSyntaxError(version);
345 set(cf_version_current, version.substring(0,x));
346 version = version.substring(x+1);
348 if ((x=version.indexOf(":"))<1)
349 throw new EVersionSyntaxError(version);
351 set(cf_version_age, version.substring(0,x));
352 version = version.substring(x+1);
354 set(cf_version_revision, version);
357 public void addExportSymbols(String fn)
359 add(cf_export_symbols,fn);
362 public void addExportSymbols(String fn[])
364 add(cf_export_symbols,fn);
367 public void addExportSymbolsRegex(String re)
369 add(cf_export_symbols_regex, re);
372 public void addExportSymbolsRegex(String[] re)
374 add(cf_export_symbols_regex, re);
377 public String[] getExportSymbols()
379 return get_str_list(cf_export_symbols);
382 public String[] getExportSymbolsRegex()
384 return get_str_list(cf_export_symbols_regex);
387 public void clearExportSymbols()
389 remove(cf_export_symbols);
392 public void clearExportSymbolsRegex()
394 remove(cf_export_symbols_regex);
397 public void clearLibraryImport()
399 remove(cf_import_libtool);
402 public void addLibraryImport(String lib)
404 if (lib.endsWith(".la"))
405 add(cf_import_libtool,PathNormalizer.normalize(lib));
406 else
407 throw new RuntimeException("unhandled library import: "+lib);
410 public void addLibraryImport(String lib[])
412 for (int x=0; x<lib.length; x++)
413 addLibraryImport(lib[x]);
416 public String[] getLibraryImports()
418 return get_str_list(cf_import_libtool);
421 public void addLibraryImport(PackageInfo libinf[])
423 if (libinf!=null)
424 for (int x=0; x<libinf.length; x++)
425 addLibraryImport(libinf[x]);
428 public void addLibraryImport(PackageInfo libinf)
430 System.err.println("addLibraryImport(): "+libinf.name);
432 // FIXME: perhaps not finished yet
433 addLibraryPath_enc_sysroot(libinf.library_pathes.getNames());
434 addSharedLink(libinf.libraries.getNames());
436 if (!StrUtil.isEmpty(libinf.ldflags))
437 throw new RuntimeException("verbatim ldflags not supported yet");
438 if (!StrUtil.isEmpty(libinf.ldflags_private))
439 throw new RuntimeException("verbatim ldflags_private not supported yet");
440 if (!StrUtil.isEmpty(libinf.requires))
441 throw new RuntimeException("requires in pkginf not supported yet");
442 if (!StrUtil.isEmpty(libinf.requires_private))
443 throw new RuntimeException("require_private in pkginf not supprted yet");
446 public void addLibraryImport(LibraryInfo libinf)
448 // FIXME we probably should compare the sysroot w/ the LinkerParam
449 if ((!StrUtil.isEmpty(libinf.sysroot)) &&
450 (!PathNormalizer.normalize_dir(libinf.sysroot).equals
451 (PathNormalizer.normalize_dir(getSysroot()))))
452 throw new RuntimeException("mismatching sysroot inf->"+libinf.sysroot+" self->"+getSysroot());
454 if (libinf.link_static)
456 System.out.println("LinkerParam::addLibraryImport() linking static: "+libinf.library_name);
458 if (StrUtil.isEmpty(libinf.arname))
459 throw new RuntimeException("missing arname for static linking");
461 if (libinf.installed)
462 throw new RuntimeException("linking statically against installed libs not supported yet");
463 else
465 String fullpath = libinf.prefix+libinf.uninstalled_libdir+libinf.arname;
466 System.out.println("addLibraryImport(): linking static against noninstalled: "+fullpath+" (arname="+libinf.arname+")");
467 addStaticLink(fullpath);
470 else
473 if (libinf.installed)
475 System.out.println("addLibraryImport(): linking dynamic against installed: "+libinf.module_name+" / "+libinf.library_name);
476 addLibraryPath_enc_sysroot(libinf.libdir);
478 else
480 System.out.println("addLibraryImport(): linking dynamically against an uninstalled so "+libinf.library_name+" "+libinf.cf+" "+libinf.dlname);
481 addLibraryPath_enc_sysroot(libinf.prefix+libinf.uninstalled_libdir);
484 if (StrUtil.isEmpty(libinf.module_name))
485 throw new RuntimeException("missing dynamic module name");
487 if (StrUtil.isEmpty(libinf.library_name))
488 throw new RuntimeException("missing dynamic library name");
490 if ((libinf.cf!=null)&&
491 libinf.cf.startsWith("../") &&
492 hack_link_intree_so_direct)
494 String objname = libinf.prefix+libinf.uninstalled_libdir+libinf.library_name+".so";
496 System.out.println("addLibraryImport(): enabled hack_link_intree_direct");
497 System.out.println(" dlname="+libinf.dlname);
498 System.out.println(" library_name="+libinf.library_name);
499 System.out.println(" uninstalled_libdir="+libinf.uninstalled_libdir);
500 System.out.println(" prefix="+libinf.prefix);
501 System.out.println(" --> objname="+objname);
503 addObjectLink(objname);
505 else
506 addSharedLink(libinf.module_name);
509 if (libinf.search_pathes!=null)
510 for (int x=0; x<libinf.search_pathes.length; x++)
511 addLibraryPath_enc_sysroot(libinf.search_pathes[x]);
513 System.out.println("addLibraryImport["+libinf.library_name+"] processing imports");
514 if (libinf.dependencies!=null)
515 for (int x=0; x<libinf.dependencies.length; x++)
516 if (libinf.dependencies[x]!=null)
517 addLibraryImport(libinf.dependencies[x]);
518 System.out.println("addLibraryImport["+libinf.library_name+"] finished imports");
522 setVersionInfo(
523 libinf.version_current+"."+
524 libinf.version_age+"."+
525 libinf.version_revision
528 catch (Exception e) // FIXME !!!
530 throw new RuntimeException(e);
533 // setVersionCurrent(libinf.version_current);
534 // setVersionAge(libinf.version_age);
535 // setVersionRevision(libinf.version_revision);