From 4910735fc3c32b09e85fc1a31c52b1cbac11782b Mon Sep 17 00:00:00 2001 From: Bart Trojanowski Date: Sat, 28 Mar 2009 22:58:38 -0400 Subject: [PATCH] generate a handful of files with substitutions from config.mk --- Makefile | 12 +--------- config.mk.dist => config.mk.in | 3 ++- src/Makefile | 27 +++++++++++++++++++++-- src/core/{wmii.lua => wmii.lua.in} | 17 +++++++------- src/{install-wmiirc-lua => install-wmiirc-lua.in} | 4 ++-- src/{wmii-lua => wmii-lua.in} | 8 +++---- src/{wmiirc.lua => wmiirc.lua.in} | 2 +- 7 files changed, 44 insertions(+), 29 deletions(-) rename config.mk.dist => config.mk.in (99%) rename src/core/{wmii.lua => wmii.lua.in} (99%) rename src/{install-wmiirc-lua => install-wmiirc-lua.in} (95%) rename src/{wmii-lua => wmii-lua.in} (81%) rename src/{wmiirc.lua => wmiirc.lua.in} (98%) diff --git a/Makefile b/Makefile index 87fb608..45ee6ff 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,7 @@ default: all # includes and defines ifneq ($(MAKECMDGOALS),gitclean) +$(if $(wildcard config.mk),,$(shell cp config.mk.in config.mk)) include config.mk endif include Makefile.ext @@ -49,17 +50,6 @@ help: @${MAKE} -s ext-help # ------------------------------------------------------------------------ -# config - -config.mk: config.mk.dist - @echo Updating $@ - ${Q} if test -f $@ ; then \ - touch $@ ; \ - else \ - cp $< $@ ; \ - fi - -# ------------------------------------------------------------------------ # local dependencies for main rules .PHONY: lcl-clean lcl-distclean diff --git a/config.mk.dist b/config.mk.in similarity index 99% rename from config.mk.dist rename to config.mk.in index b787e32..dfab244 100644 --- a/config.mk.dist +++ b/config.mk.in @@ -1,4 +1,4 @@ -# vim: set ft=make : +LOADED_CONFIG_MK := 1 # ------------------------------------------------------------------------ # standard programs CC = cc @@ -71,3 +71,4 @@ ALL_HOME_DIRS = ${HOME_CORE} \ ${HOME_PLUGINS} \ ${HOME_PLUGINS} +# vim: set ft=make : diff --git a/src/Makefile b/src/Makefile index 5001171..09afb89 100644 --- a/src/Makefile +++ b/src/Makefile @@ -29,6 +29,28 @@ help: @echo " cscope - build cscope index" # ------------------------------------------------------------------------ +# generating files from templates + +GEN_SRC = core/wmii.lua.in install-wmiirc-lua.in wmii-lua.in wmiirc.lua.in +GEN_DST = ${GEN_SRC:%.in=%} + +generate-from-in: ${GEN_DST} +${GEN_DST}: ${CONFIG_MK} +${GEN_DST}: %: %.in +ifeq (${LOADED_CONFIG_MK},) + ${MAKE} ${CONFIG_MK} + ${MAKE} $@ +else + @echo Generating $@ + ${Q} sed -e 's:%DESTDIR%:${DESTDIR}:' \ + -e 's:%PREFIX%:${PREFIX}:' \ + -e 's:%RC_DIR%:${RC_DIR}:' \ + -e 's:%LUA_BIN%:${LUA_BIN}:' \ + -e 's:%HOME_WMII%:${HOME_WMII}:' \ + $< > $@ +endif + +# ------------------------------------------------------------------------ # building libs: luaeventloop luaixp @@ -56,6 +78,7 @@ clean: -${Q} ${MAKE} -C luaeventloop clean distclean: clean + -${Q} rm -f ${GEN_DST} # ------------------------------------------------------------------------ # installing @@ -63,7 +86,7 @@ distclean: clean # # install system wide # -install: ${MAN} install-variable-check +install: ${MAN} ${GEN_DST} install-variable-check # create directories ${Q} ${INSTALL} -d ${ALL_INSTALL_DIRS} # @@ -89,7 +112,7 @@ install: ${MAN} install-variable-check # # install in user directory # -install-user: install-user-variable-check +install-user: ${MAN} ${GEN_DST} install-user-variable-check ifeq ($(shell pwd),$(wildcard ~/.wmii-3.5)) @echo "You're already in the ~/.wmii-3.5/ directory" else diff --git a/src/core/wmii.lua b/src/core/wmii.lua.in similarity index 99% rename from src/core/wmii.lua rename to src/core/wmii.lua.in index 8d98924..f69881c 100644 --- a/src/core/wmii.lua +++ b/src/core/wmii.lua.in @@ -55,7 +55,7 @@ It should be used by your wmiirc -- MODULE SETUP -- ======================================================================== -local wmiidir = os.getenv("HOME") .. "/.wmii-3.5" +local wmiidir = ("%HOME_WMII%"):gsub("^~", os.getenv("HOME")) local wmiirc = wmiidir .. "/wmiirc" package.path = wmiidir .. "/core/?.lua;" .. @@ -143,18 +143,18 @@ local prog_hist = history.new (20) local action_hist = history.new(10) -- where to find plugins -plugin_path = os.getenv("HOME") .. "/.wmii-3.5/plugins/?.so;" - .. os.getenv("HOME") .. "/.wmii-3.5/plugins/?.lua;" +plugin_path = wmiidir .. "/plugins/?.so;" + .. wmiidir .. "/plugins/?.lua;" .. "/usr/local/lib/lua/5.1/wmii/?.so;" .. "/usr/local/share/lua/5.1/wmii/?.lua;" .. "/usr/lib/lua/5.1/wmii/?.so;" .. "/usr/share/lua/5.1/wmii/?.lua" -- where to find wmiirc (see find_wmiirc()) -wmiirc_path = os.getenv("HOME") .. "/.wmii-3.5/wmiirc.lua;" - .. os.getenv("HOME") .. "/.wmii-3.5/wmiirc;" - .. "/etc/X11/wmii-3.5/wmiirc.lua;" - .. "/etc/X11/wmii-3.5/wmiirc" +wmiirc_path = wmiidir .. "/wmiirc.lua;" + .. wmiidir .. "/wmiirc;" + .. "%RC_DIR%/wmiirc.lua;" + .. "%RC_DIR%/wmiirc" -- ======================================================================== -- LOCAL HELPERS @@ -182,7 +182,7 @@ end =item find_wmiirc ( ) -Locates the wmiirc script. It looks in ~/.wmii-3.5 and /etc/X11/wmii-3.5 +Locates the wmiirc script. It looks in %HOME_WMII% and %RC_DIR% for the first lua script bearing the name wmiirc.lua or wmiirc. Returns first match. @@ -582,6 +582,7 @@ local action_handlers = { cleanup() posix.exec (wmiirc) posix.exec ("/bin/sh", "-c", "exec lua wmiirc") + posix.exec ("%LUA_BIN%", wmiirc) posix.exec ("/usr/bin/lua", wmiirc) end else diff --git a/src/install-wmiirc-lua b/src/install-wmiirc-lua.in similarity index 95% rename from src/install-wmiirc-lua rename to src/install-wmiirc-lua.in index 88500ee..acc8059 100755 --- a/src/install-wmiirc-lua +++ b/src/install-wmiirc-lua.in @@ -5,8 +5,8 @@ set -e -SRC_DIR="/etc/X11/wmii-3.5" -DST_DIR="${HOME}/.wmii-3.5" +SRC_DIR="%RC_DIR%" +DST_DIR=$(echo "%HOME_WMII%") SRC_WMIIRC="${SRC_DIR}/wmiirc.lua" DST_WMIIRC="${DST_DIR}/wmiirc" diff --git a/src/wmii-lua b/src/wmii-lua.in similarity index 81% rename from src/wmii-lua rename to src/wmii-lua.in index e48d173..2b9d179 100755 --- a/src/wmii-lua +++ b/src/wmii-lua.in @@ -6,10 +6,10 @@ # we will look for wmiirc in these directories POSSIBLE_WMIIRC=" -${HOME}/.wmii-3.5/wmiirc.lua -${HOME}/.wmii-3.5/wmiirc -/etc/X11/wmii-3.5/wmiirc.lua -/etc/X11/wmii-3.5/wmiirc +%HOME_WMII%/wmiirc.lua +%HOME_WMII%/wmiirc +%RC_DIR%/wmiirc.lua +%RC_DIR%/wmiirc " # try to find the best wmiirc written in lua diff --git a/src/wmiirc.lua b/src/wmiirc.lua.in similarity index 98% rename from src/wmiirc.lua rename to src/wmiirc.lua.in index eff4757..ec14a03 100755 --- a/src/wmiirc.lua +++ b/src/wmiirc.lua.in @@ -14,7 +14,7 @@ io.stderr:write ("----------------------------------------------\n") -- load wmii.lua -local wmiidir = os.getenv("HOME") .. "/.wmii-3.5" +local wmiidir = ("%HOME_WMII%"):gsub("^~", os.getenv("HOME")) package.path = wmiidir .. "/core/?.lua;" .. wmiidir .. "/plugins/?.lua;" .. package.path -- 2.11.4.GIT