]> Dogcows Code - chaz/yoink/blobdiff - tools/link.lua
improved build tools
[chaz/yoink] / tools / link.lua
diff --git a/tools/link.lua b/tools/link.lua
new file mode 100755 (executable)
index 0000000..d0eed0c
--- /dev/null
@@ -0,0 +1,83 @@
+#!/usr/bin/env lua
+
+--
+-- Yoink
+-- Run this script to link the executable with fewer direct dependencies.
+--
+-- You shouldn't call this directly; instead, use the configure script's
+-- --enable-asneeded option and run make normally.  This isn't enabled by
+-- default because there is the potential for runtime linking problems on
+-- some platforms.  If you have a newer version of GCC, you should prefer
+-- the --as-needed linker flag over this method, though they both should
+-- accomplish the same thing.
+--
+
+
+-- List here any libraries that are known to not be needed on some
+-- platform.
+libraries = {
+       "atk-1.0",
+       "cairo",
+       "fontconfig",
+       "freetype",
+       "gdk-x11-2.0",
+       "gio-2.0",
+       "glib-2.0",
+       "gmodule-2.0",
+       "ogg",
+       "pango-1.0",
+       "pangocairo-1.0",
+       "pangoft2-1.0",
+       "pthread",
+       "vorbis"
+}
+
+
+-- We want to print only if verbose is set to true.
+do
+       local verbose   = os.getenv("verbose") == "true"
+       local oldprint  = print
+
+       print = function(...) if verbose then oldprint(unpack(arg)) end end
+end
+
+
+command                = arg[1]
+removed                = {}
+
+-- Get the link command as passed on the command-line.
+for i,arg in ipairs(arg) do
+       if i ~= 1 then
+               command = string.format("%s %q", command, arg)
+       end
+end
+
+original = command
+
+
+-- Check for libraries which aren't needed for successful linking.
+for i,library in ipairs(libraries) do
+       local new_command = command:gsub("%s\"%-l"..library.."+\"%s", " ")
+       if new_command ~= command then
+               if os.execute(new_command.." >/dev/null 2>&1") == 0 then
+                       print("We DON'T need "..library)
+                       table.insert(removed, library)
+                       command = new_command
+               else
+                       print("We DO need "..library)
+               end
+       end
+end
+
+
+-- Perform the final link.
+if 0 < #removed and os.execute(command.." >/dev/null 2>&1") == 0 then
+       local removed = table.concat(removed, ", ")
+       print("Linked fine without some libraries: "..removed)
+elseif os.execute(original.." >/dev/null 2>&1") == 0 then
+       print("Linked with the original link command.")
+else
+       print("The link failed.  :-(")
+       os.exit(1)
+end
+
This page took 0.017783 seconds and 4 git commands to generate.