From f220524b5a383a7945a1d834a3600bd07f7b2edc Mon Sep 17 00:00:00 2001
From: Joe Rozner <joe@prevoty.com>
Date: Wed, 20 Nov 2013 13:04:07 -0800
Subject: [PATCH] Generate pkg-config for Hammer

Create a pkg-config file and install it to $prefix/lib/pkgconfig
---
 SConstruct            |   6 ++++--
 libhammer.pc.in       |  10 ++++++++++
 src/SConscript        |   1 +
 tools/scanreplace.py  |  15 +++++++++++++++
 tools/scanreplace.pyc | Bin 0 -> 1263 bytes
 5 files changed, 30 insertions(+), 2 deletions(-)
 create mode 100644 libhammer.pc.in
 create mode 100644 tools/scanreplace.py
 create mode 100644 tools/scanreplace.pyc

diff --git a/SConstruct b/SConstruct
index 78090c3a..422efe64 100644
--- a/SConstruct
+++ b/SConstruct
@@ -8,7 +8,7 @@ vars = Variables(None, ARGUMENTS)
 vars.Add(PathVariable('DESTDIR', "Root directory to install in (useful for packaging scripts)", None, PathVariable.PathIsDirCreate))
 vars.Add(PathVariable('prefix', "Where to install in the FHS", "/usr/local", PathVariable.PathAccept))
 
-env = Environment(ENV = {'PATH' : os.environ['PATH']}, variables = vars)
+env = Environment(ENV = {'PATH' : os.environ['PATH']}, variables = vars, tools=['default', 'scanreplace'], toolpath=['tools'])
 
 def calcInstallPath(*elements):
     path = os.path.abspath(os.path.join(*map(env.subst, elements)))
@@ -28,7 +28,8 @@ if 'DESTDIR' in env:
 
 env['libpath'] = calcInstallPath("$prefix", "lib")
 env['incpath'] = calcInstallPath("$prefix", "include", "hammer")
-# TODO: Add pkgconfig
+env['pkgconfigpath'] = calcInstallPath("$prefix", "lib", "pkgconfig")
+env.ScanReplace('libhammer.pc.in')
 
 env.MergeFlags("-std=gnu99 -Wall -Wextra -Werror -Wno-unused-parameter -Wno-attributes")
 
@@ -89,3 +90,4 @@ env.Command('test', 'build/$VARIANT/src/test_suite', 'env LD_LIBRARY_PATH=build/
 
 env.Alias("install", "$libpath")
 env.Alias("install", "$incpath")
+env.Alias("install", "$pkgconfigpath")
diff --git a/libhammer.pc.in b/libhammer.pc.in
new file mode 100644
index 00000000..97ded13f
--- /dev/null
+++ b/libhammer.pc.in
@@ -0,0 +1,10 @@
+prefix=/usr
+exec_prefix=${prefix}
+includedir=${prefix}/include
+libdir=${exec_prefix}/lib
+
+Name: libhammer
+Description: The Hammer parsing library
+Version: 0.9.0
+Cflags: -I${includedir}/hammer
+Libs: -L${libdir} -lhammer
diff --git a/src/SConscript b/src/SConscript
index 03308dd9..a06244b9 100644
--- a/src/SConscript
+++ b/src/SConscript
@@ -64,6 +64,7 @@ libhammer_static = env.StaticLibrary('hammer', parsers + backends + misc_hammer_
 
 env.Install("$libpath", [libhammer_static, libhammer_shared])
 env.Install("$incpath", dist_headers)
+env.Install("$pkgconfigpath", "../../../libhammer.pc")
 
 testenv = env.Clone()
 testenv.ParseConfig('pkg-config --cflags --libs glib-2.0')
diff --git a/tools/scanreplace.py b/tools/scanreplace.py
new file mode 100644
index 00000000..5321e481
--- /dev/null
+++ b/tools/scanreplace.py
@@ -0,0 +1,15 @@
+from string import Template
+
+def replace_action(target, source, env):
+  open(str(target[0]), 'w').write(Template(open(str(source[0]), 'r').read()).safe_substitute(env))
+  return 0
+
+def replace_string(target, source, env):
+  return "building '%s' from '%s'" % (str(target[0]), str(source[0]))
+
+def generate(env, **kw):
+  action = env.Action(replace_action, replace_string)
+  env['BUILDERS']['ScanReplace'] = env.Builder(action=action, src_suffix='.in', single_source=True)
+
+def exists(env):
+  return 1
diff --git a/tools/scanreplace.pyc b/tools/scanreplace.pyc
new file mode 100644
index 0000000000000000000000000000000000000000..c37386cee5c446284c300e734bcd48d69842fc26
GIT binary patch
literal 1263
zcmb_b!EVz)5S_J?LJ9@MA*i<s3Dp-Gi4%tiK?@RyDhH>%^isL@rZ_luw7aGSl~cI#
zA$%Vn0Pl?hy+b3<WOinEXXee@_~+K<kKy+;m-R2g|4WE}4prbYQi&{#oER}hB;Q0%
zA}L}uVkvrR^rYyk(U)RFrpYZFE`Q;d7+B#p)RA2*t1Q?&#)7f|Ie_>>sDRJNmFC-C
z89}C1B=bl@{3iyd5sk$f>&Z$4Tjzbb!fwOQV9PY=;lfD?#XChVRJ();17pq7*0>j`
zgA0A`aAmM5j4tkMR)qVEXES^1+cO`^&<30EOwemGcW#54zG+=<^*URBN_dGX{|wgX
z*jwjE^Tv+6%SRuw#lpI$bJu*Sts8}=sr<<2S?w&a$?e|qbGV0N>*Z;dhq9@)Qr0cz
zt@#Td>pp<^$53b+2ok<XA>u+oBwn*fhEuJ5;vZr2SzA^`S)cFhKJmLdGuJHCQowXx
zDU<1el#@#bRGaicZmv6^k19wNPu7XaIW2Ze-+PE3L!qm=PBJJbzDDW+^}rV}QOO7z
zVzMiV2|-`BLBeq%Ya&i`P92tkZD16b>TFhCdS=@z>##*Ps;MyVZlLUZ|M=bE>o@5%
z+`(dsIi=m45`wR{zS0S$jHh?$Wa;|^*gECfk!w5ND1c}|<l{xkbpH<~OFXw=5}uXz
z)sf_32PDCyC`lO6x4{A?CH-A~S~oOXJ`8(V`rygo^-L$-vtz8Aw?4CLz|tWLAT6))
cQ0rgc4?!6(nxd`j3pVHJcn}SGgLu&U4RhuJtN;K2

literal 0
HcmV?d00001

-- 
GitLab