jenerated

blog

Loading WebKit2Gtk Web Extensions

If you have any interest in WebKit2Gtk web extensions, you've probably found your way to this blog entry at some point. I, at least, didn't want to use automake and I was curious about what it was doing under the hood.

WebKit2Gtk's web extensions are libtool "dlopened modules". This means you'll want to use libtool for compiling rather than gcc or clang directly, as I did in the following Makefile snippet.

Note that libtool will create a .lo file rather than a standard .o object file, and a .la rather than a standard .a library file.

web_extension/asdf.c.lo: web_extension/asdf.c
  libtool --mode=compile --tag=CC $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@

web_extension/libasdf.la: web_extension/asdf.c.lo 
  libtool --mode=link --tag=CC $(CC) -o $@ $< -rpath $(INSTALLDIR)/lib/luakit/web_extension \
  -module -avoid-version -no-undefined

If you haven't noticed already, I'm poking around with a browser called luakit. You'll want to replace 'luakit' with whatever your application's name is.

.la files are actually not the libraries themselves; you can open them up in your favourite text editor and have a peek yourself. What you actually care about here is the .so file, which in my case is in web_extension/.libs (this hidden directory is created by libtool).

If you check the package contents here, you'll see that Epiphany's web extension is installed as /usr/lib/epiphany/3.14/web-extensions/libephywebextension.so, so I've decided to follow suit (modulo version in the path).

install:
  # other stuff
  install -d $(INSTALLDIR)/lib
  install -d $(INSTALLDIR)/lib/luakit
  install -d $(INSTALLDIR)/lib/luakit/web-extensions
  install -m0644 web-extension/.libs/libasdf.so $(INSTALLDIR)/lib/luakit/web-extensions

To expand on later: