--- /dev/null
+From: Jakub Jirutka <jakub@jirutka.cz>
+
+Fix Makefile to respect system CFLAGS, LDFLAGS, and CC provided by environment.
+Allow to specify pkg-config command using variable, to be friendly with
+cross-compiling etc.
+
+diff --git a/Makefile b/Makefile
+index 195ef6b..375fb65 100644
+--- a/Makefile
++++ b/Makefile
+@@ -2,9 +2,10 @@ T=openssl
+ \r
+ PREFIX ?=/usr/local\r
+ LIB_OPTION ?= -shared \r
++PKG_CONFIG ?= pkg-config\r
+ \r
+ #Lua auto detect\r
+-LUA_VERSION ?= $(shell pkg-config luajit --print-provides)\r
++LUA_VERSION ?= $(shell $(PKG_CONFIG) luajit --print-provides)\r
+ ifeq ($(LUA_VERSION),) ############ Not use luajit\r
+ LUAV ?= $(shell lua -e "_,_,v=string.find(_VERSION,'Lua (.+)');print(v)")\r
+ LUA_CFLAGS ?= -I$(PREFIX)/include/lua$(LUAV)\r
+@@ -12,8 +13,8 @@ LUA_LIBS ?= -L$(PREFIX)/lib
+ LUA_LIBDIR ?= $(PREFIX)/lib/lua/$(LUAV)\r
+ else\r
+ LUAV ?= $(shell lua -e "_,_,v=string.find(_VERSION,'Lua (.+)');print(v)")\r
+-LUA_CFLAGS ?= $(shell pkg-config luajit --cflags)\r
+-LUA_LIBS ?= $(shell pkg-config luajit --libs)\r
++LUA_CFLAGS ?= $(shell $(PKG_CONFIG) luajit --cflags)\r
++LUA_LIBS ?= $(shell $(PKG_CONFIG) luajit --libs)\r
+ LUA_LIBDIR ?= $(PREFIX)/lib/lua/$(LUAV)\r
+ endif\r
+ \r
+@@ -22,30 +23,30 @@ SYS := $(shell gcc -dumpmachine)
+ \r
+ ifneq (, $(findstring linux, $(SYS)))\r
+ # Do linux things\r
+-LDFLAGS = -fPIC -lrt -ldl\r
+-OPENSSL_LIBS ?= $(shell pkg-config openssl --libs) \r
+-OPENSSL_CFLAGS ?= $(shell pkg-config openssl --cflags)\r
+-CFLAGS = -fPIC $(OPENSSL_CFLAGS) $(LUA_CFLAGS)\r
++LDFLAGS += -fPIC -lrt -ldl\r
++OPENSSL_LIBS ?= $(shell $(PKG_CONFIG) openssl --libs) \r
++OPENSSL_CFLAGS ?= $(shell $(PKG_CONFIG) openssl --cflags)\r
++CFLAGS += -fPIC $(OPENSSL_CFLAGS) $(LUA_CFLAGS)\r
+ endif\r
+ ifneq (, $(findstring apple, $(SYS)))\r
+ # Do darwin things\r
+-LDFLAGS = -fPIC -lrt -ldl\r
+-OPENSSL_LIBS ?= $(shell pkg-config openssl --libs) \r
+-OPENSSL_CFLAGS ?= $(shell pkg-config openssl --cflags)\r
+-CFLAGS = -fPIC $(OPENSSL_CFLAGS) $(LUA_CFLAGS)\r
++LDFLAGS += -fPIC -lrt -ldl\r
++OPENSSL_LIBS ?= $(shell $(PKG_CONFIG) openssl --libs) \r
++OPENSSL_CFLAGS ?= $(shell $(PKG_CONFIG) openssl --cflags)\r
++CFLAGS += -fPIC $(OPENSSL_CFLAGS) $(LUA_CFLAGS)\r
+ endif\r
+ ifneq (, $(findstring mingw, $(SYS)))\r
+ # Do mingw things\r
+ V = $(shell lua -e "v=string.gsub('$(LUAV)','%.','');print(v)")\r
+-LDFLAGS = -mwindows -lcrypt32 -lssl -lcrypto -lws2_32 $(PREFIX)/bin/lua$(V).dll \r
++LDFLAGS += -mwindows -lcrypt32 -lssl -lcrypto -lws2_32 $(PREFIX)/bin/lua$(V).dll\r
+ LUA_CFLAGS = -DLUA_LIB -DLUA_BUILD_AS_DLL -I$(PREFIX)/include/\r
+-CFLAGS = $(OPENSSL_CFLAGS) $(LUA_CFLAGS)\r
++CFLAGS += $(OPENSSL_CFLAGS) $(LUA_CFLAGS)\r
+ endif\r
+ ifneq (, $(findstring cygwin, $(SYS)))\r
+ # Do cygwin things\r
+-OPENSSL_LIBS ?= $(shell pkg-config openssl --libs) \r
+-OPENSSL_CFLAGS ?= $(shell pkg-config openssl --cflags)\r
+-CFLAGS = -fPIC $(OPENSSL_CFLAGS) $(LUA_CFLAGS)\r
++OPENSSL_LIBS ?= $(shell $(PKG_CONFIG) openssl --libs) \r
++OPENSSL_CFLAGS ?= $(shell $(PKG_CONFIG) openssl --cflags)\r
++CFLAGS += -fPIC $(OPENSSL_CFLAGS) $(LUA_CFLAGS)\r
+ endif\r
+ #custome config\r
+ ifeq (.config, $(wildcard .config))\r
+@@ -61,7 +62,7 @@ WARN_MOST = -Wall -W -Waggregate-return -Wcast-align -Wmissing-prototypes -Wnest
+ WARN = -Wall -Wno-unused-value\r
+ WARN_MIN = \r
+ CFLAGS += $(WARN_MIN) -DPTHREADS \r
+-CC= gcc -g $(CFLAGS) -Ideps\r
++CC ?= gcc -g $(CFLAGS) -Ideps\r
+ \r
+ \r
+ OBJS=src/asn1.o src/auxiliar.o src/bio.o src/cipher.o src/cms.o src/compat.o src/crl.o src/csr.o src/dh.o src/digest.o src/dsa.o \\r
--- /dev/null
+# Copyright 1999-2015 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id$
+
+EAPI=5
+
+inherit eutils toolchain-funcs
+
+DESCRIPTION="OpenSSL binding for Lua"
+HOMEPAGE="https://github.com/zhaozg/lua-openssl"
+SRC_URI="https://github.com/zhaozg/lua-openssl/archive/${PV}.tar.gz -> ${P}.tar.gz"
+
+LICENSE="MIT openssl PHP-3"
+SLOT="0"
+KEYWORDS="~amd64 ~x86"
+IUSE="luajit"
+
+RDEPEND="
+ luajit? ( dev-lang/luajit:2 )
+ !luajit? ( >=dev-lang/lua-5.1:0 )
+ dev-libs/openssl:0"
+DEPEND="${RDEPEND}
+ virtual/pkgconfig"
+
+src_prepare() {
+ epatch "${FILESDIR}/${P}-Makefile.patch"
+ use luajit && LUAV=luajit || LUAV=lua
+}
+
+src_compile() {
+ local pkgconfig=$(tc-getPKG_CONFIG)
+ emake \
+ CC="$(tc-getCC) \$(CFLAGS) -Ideps" \
+ PKG_CONFIG="$pkgconfig" \
+ LUA_CFLAGS="$($pkgconfig --cflags $LUAV)" \
+ LUA_LIBS="$($pkgconfig --libs $LUAV)" \
+ LUA_LIBDIR="$($pkgconfig --variable INSTALL_CMOD $LUAV)"
+}
+
+src_install() {
+ emake \
+ LUA_LIBDIR="${D}$($(tc-getPKG_CONFIG) --variable INSTALL_CMOD $LUAV)" \
+ install
+ einstalldocs
+}