return to OCLUG Web Site
A Django site.
December 16, 2012

Michael P. Soulier
msoulier
But I Digress
» Getting started with autotools

So, I'm still reading O'Rielly's 21st Century C. I know, too many books on the go and I read slowly, and not often enough. I'm going through the section on GNU autotools, which I've never been a heavy user of, albiet I'm a heavy consumer of. I just don't spend much time distributing C/C++ across platforms.

I have a little C tool that I figured I'd try it on, a small replacement for GNU tree that I wrote a while back, and since tree isn't available on OS X, it seemed a good excuse to port it. Previously I just had a Makefile that I maintained, and it works fine, but it's a good excuse to learn how to use autotools for the future. I do have some libraries, and they're harder to port, which is where libtool comes in.

This build script outlines the process of using autotools for the first time. This script borrows very heavily from the book's author.

#!/bin/sh

echo "Creating Makefile.am"
cat > Makefile.am <<EOF
bin_PROGRAMS=twig
twig_SOURCES=twig.c
EOF

echo "Running autoscan..."
autoscan

echo "Creating configure.ac..."
sed -e 's/FULL-PACKAGE-NAME/twig/' \
    -e 's/VERSION/1.0/'   \
    -e 's|BUG-REPORT-ADDRESS|msoulier@digitaltorque.ca|' \
    -e '10i\
    AM_INIT_AUTOMAKE' \
        < configure.scan > configure.ac

echo "Creating additional files..."
touch NEWS README AUTHORS ChangeLog

echo "Running autoreconf..."
autoreconf -iv

echo "Running configure..."
./configure

echo "Running make distcheck to package sources..."
make distcheck

At this point, it's not ready to ship, as the NEWS, README, AUTHORS and ChangeLog aren't populated yet. But it's close. The configure script works, and I could then build it on OS X using the expected.

./configure --prefix=/usr/local
make
make install

My next project to package is a shared library for work, so that will be more interesting. Still, if you're looking to use autotools for the first time for something simple, this should take the mystery out of kick-starting it. Sure, there's some magic like the AM_INIT_AUTOMAKE macro, and I've a ton to learn yet, but this worked on the first try, and the resulting tarball is good to push to SourceForge or elsewhere if you want to.

As I pick up more, I'll try to share it. I don't find autotools intuitive at all, but with some simple recipes I think I'll survive.

November 28, 2012

Michael P. Soulier
msoulier
But I Digress
» Customizing Awesome

As I mentioned previously, I'm currently running Awesome on my netbook. While I added suspend on lid close, I still need to customize the crap out of it. I had nothing showing me my current battery status, so I searched around to find the appropriate lua code, a language that I'm still picking up.

So, I hacked my $HOME/.config/awesome/rc.lua and added this:

-- {{{ Battery state

-- Initialize widget
batwidget = widget({ type = "textbox" })
baticon = widget({ type = "imagebox" })

-- Register widget
vicious.register(batwidget, vicious.widgets.bat,
    function (widget, args)
        if args[2] == 0 then return ""
        else
            baticon.image = image(beautiful.widget_bat)
            return "<span color='white'>".. args[2] .. "%</span>"
        end
    end, 61, "BAT0"
)

-- }}}

And then added the widget to the top of my screen. I was warned on the awesome mailing list (the name does confuse the english language) that I had to be careful where to put it, since the tasklist is greedy and will take all available space.

mywibox[s].widgets = {
    {
        mylauncher,
        mytaglist[s],
        mypromptbox[s],
        layout = awful.widget.layout.horizontal.leftright
    },
    mylayoutbox[s],
    mytextclock,
    s == 1 and mysystray or nil,
    baticon.image and separator, batwidget, baticon or nil,
    separator, mytasklist[s],
    layout = awful.widget.layout.horizontal.rightleft
}

And, it works. Now I need a system load, cpu load, etc. And I should hack the keybindings, although I'm getting used to the default ones. Maybe update the default layout since I prefer maximized layout.