/src/org/ooc/frontend/pkgconfig/PkgConfigFrontend.java

http://github.com/nddrylliog/ooc · Java · 51 lines · 29 code · 11 blank · 11 comment · 6 complexity · 3bd65175fe9dd6920ef284f680de3175 MD5 · raw file

  1. package org.ooc.frontend.pkgconfig;
  2. import java.io.File;
  3. import java.util.HashMap;
  4. import java.util.Map;
  5. import org.ooc.utils.ShellUtils;
  6. import org.ubi.CompilationFailedError;
  7. /**
  8. * A frontend to pkgconfig, to retrieve information for packages,
  9. * like gtk+-2.0, gtkgl-2.0, or imlib2
  10. *
  11. * @author Amos Wenger
  12. */
  13. public class PkgConfigFrontend {
  14. protected static Map<String, PkgInfo> cache = new HashMap<String, PkgInfo>();
  15. /**
  16. *
  17. * @param pkgName
  18. * @return the information concerning a package managed by pkg-manager
  19. */
  20. public static PkgInfo getInfo(String pkgName) {
  21. PkgInfo cached = cache.get(pkgName);
  22. if(cached != null) {
  23. return cached;
  24. }
  25. File path = ShellUtils.findExecutable("pkg-config");
  26. if(path == null) {
  27. throw new Error("Error! the 'pkg-config' tool, necessary to resolve package '"
  28. +pkgName+"' couldn't be find in the $PATH, which is "+System.getenv("PATH"));
  29. }
  30. String libs = ShellUtils.getOutput(path.getPath(), "--libs", pkgName);
  31. String cflags = ShellUtils.getOutput(path.getPath(), "--cflags", pkgName);
  32. if(libs == null) {
  33. throw new CompilationFailedError(null, "Can't find package '"+pkgName
  34. +"' in PKG_CONFIG_PATH. Have you configured pkg-config correctly?");
  35. }
  36. PkgInfo pkgInfo = new PkgInfo(pkgName, libs, cflags);
  37. cache.put(pkgName, pkgInfo);
  38. return pkgInfo;
  39. }
  40. }