From 659e292fc741163f6e4370ff682e3e42312cd51d Mon Sep 17 00:00:00 2001
From: Natanael Copa <ncopa@alpinelinux.org>
Date: Wed, 26 Jun 2013 06:33:15 +0000
Subject: [PATCH] Use pkg-config to detect cflags or fallback to
 LUA_INCLUDE_DIR

---
 Makefile | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index 6fdb1f2..ed0f925 100644
--- a/Makefile
+++ b/Makefile
@@ -18,10 +18,13 @@ PREFIX =            /usr/local
 CFLAGS =            -O3 -Wall -pedantic -DNDEBUG
 CJSON_CFLAGS =      -fpic
 CJSON_LDFLAGS =     -shared
+LUA_PC =            lua$(LUA_VERSION)
 LUA_INCLUDE_DIR =   $(PREFIX)/include
 LUA_CMODULE_DIR =   $(PREFIX)/lib/lua/$(LUA_VERSION)
 LUA_MODULE_DIR =    $(PREFIX)/share/lua/$(LUA_VERSION)
 LUA_BIN_DIR =       $(PREFIX)/bin
+LUA_CFLAGS =        $(shell pkg-config $(LUA_PC) --cflags --silence-errors \
+	|| echo "-I$(LUA_INCLUDE_DIR)")
 
 ##### Platform overrides #####
 ##
@@ -79,7 +82,7 @@ EXECPERM =          755
 
 ASCIIDOC =          asciidoc
 
-BUILD_CFLAGS =      -I$(LUA_INCLUDE_DIR) $(CJSON_CFLAGS)
+BUILD_CFLAGS =      $(LUA_CFLAGS) $(CJSON_CFLAGS)
 OBJS =              lua_cjson.o strbuf.o $(FPCONV_OBJS)
 
 .PHONY: all clean install install-extra doc
-- 
1.8.3.1

