Skip to content
Permalink
Browse files
Improve Arch Linux compatibility and etc/errors.lua
 - The makefile now uses either the "lua5.1" (Debian/Ubuntu) or the
   "lua" (Arch Linux) pkg-config name
 - The makefile now expands the pkg-config invocations using $(shell ..)
   instead of passing them on literally to every build command line
 - etc/errors.lua now also checks /usr/include/apr-1/apr_errno.h,
   this means it should work on Arch Linux and Mac OS X
 - The repository now includes a generated src/errno.c just in case
   the error handling code generator doesn't work for everyone
 - I added a file header to etc/docs.lua while I was at it
  • Loading branch information
xolox committed Feb 20, 2011
1 parent 2289ffb commit 0ce159f
Show file tree
Hide file tree
Showing 3 changed files with 285 additions and 5 deletions.
@@ -1,7 +1,7 @@
# This is the UNIX makefile for the Lua/APR binding.
#
# Author: Peter Odding <peter@peterodding.com>
# Last Change: February 19, 2011
# Last Change: February 20, 2011
# Homepage: http://peterodding.com/code/lua/apr/
# License: MIT
#
@@ -55,9 +55,14 @@ SOURCES = src/base64.c \
OBJECTS = $(patsubst %.c,%.o,$(SOURCES))

# If you're building Lua/APR with LuaRocks it should locate the external
# dependencies automatically, otherwise we fall back to `pkg-config'.
CFLAGS = `pkg-config --cflags lua5.1` `pkg-config --cflags apr-1` `pkg-config --cflags apr-util-1`
LFLAGS = `pkg-config --libs apr-1` `pkg-config --libs apr-util-1`
# dependencies automatically, otherwise we fall back to `pkg-config'. On
# Debian/Ubuntu the Lua pkg-config file is called "lua5.1", on Arch Linux its
# just "lua".
CFLAGS = $(shell pkg-config --cflags lua5.1 --silence-errors || pkg-config --cflags lua) \
$(shell pkg-config --cflags apr-1) \
$(shell pkg-config --cflags apr-util-1)
LFLAGS = $(shell pkg-config --libs apr-1) \
$(shell pkg-config --libs apr-util-1)

# Create debug builds by default but enable release
# builds using the command line "make RELEASE=1".
@@ -1,3 +1,20 @@
--[[
Error handling code generator for the Lua/APR binding.
Author: Peter Odding <peter@peterodding.com>
Last Change: February 20, 2011
Homepage: http://peterodding.com/code/lua/apr/
License: MIT
The Apache Portable Runtime defines a long list of error codes whose integer
value differs between platforms and to make it even more complex several
integer values can map to the same error code. This script goes through the
APR header file, extracts the defined error codes (by name) and generates some
C source code that will convert APR error codes to symbolic strings.
--]]

local verbose = false
local constants = {}
local tests = {}
@@ -27,14 +44,35 @@ local ignored = {
APR_UTIL_START_STATUS = true,
}

local function check(path)
io.stderr:write("Looking for headers at ", path, " .. ")
local status, msg = io.input(path)
if status then
io.stderr:write "Found them!\n"
return true
end
io.stderr:write("\nFailed to open headers: ", msg, "\n")
end

if not (check '/usr/include/apr-1.0/apr_errno.h' -- Debian / Ubuntu
or check '/usr/include/apr-1/apr_errno.h') then -- Arch Linux / Mac OS X
io.stderr:write [[
Failed to determine where apr_errno.h is defined! This means the error
handling module can't be regenerated, but don't worry: The Lua/APR
repository includes a generated "errno.c" for just these situations.
]]
os.exit(1)
end

-- Parse the header file. {{{1

local function add(table, token)
if not table[token] then
table[#table + 1] = token
table[token] = true
end
end

assert(io.input '/usr/include/apr-1.0/apr_errno.h')
local source = io.read '*a'
source = source:gsub('/%*.-%*/', '')
local longest_constant, longest_test = 0, 0
@@ -53,6 +91,8 @@ end
table.sort(constants)
table.sort(tests)

-- Report intermediate results? {{{1

if verbose then

io.write('Found ', #constants, ' error constants:\n')
@@ -77,6 +117,10 @@ if verbose then

end

-- Generate the error handling module's source code. {{{1

-- Documentation. {{{2

io.write([[
/* Error handling module for the Lua/APR binding.
*
@@ -159,6 +203,8 @@ void status_to_name(lua_State *L, apr_status_t status)
switch (status) {
]])

-- }}}2

local template = ' case %s: %slua_pushliteral(L, %q); %sreturn;\n'
for i, constant in ipairs(constants) do
local name = constant:gsub('^APR_', '')

0 comments on commit 0ce159f

Please sign in to comment.