Skip to content

Instantly share code, notes, and snippets.

@deryni
deryni / helpsystem.mk
Created March 31, 2013 22:43
My version of the self-documenting makefile trick. Haven't used this too thoroughly yet so I'm not sure what I think of it but it seems ok so far. It was built for use in a project that doesn't have a meaningful 'all' target. It would probably want the filter changed back to something more like in the original for use in a more normal project.
# Modified version of http://www.cmcrossroads.com/article/self-documenting-makefiles
all:
@printf -- "$(HELPTGT)\n$(ETCTGT)\n" | column -t -s :
HELPTGT := --- Primary Targets ---
helptgt = $1$(eval $(if $(filter-out $(.DEFAULT_GOAL),$(MAKECMDGOALS)),,HELPTGT+=\n$(subst %,<name>,$1): - $2))
ETCTGT := --- Extra Targets ---
etctgt = $1$(eval $(if $(filter-out $(.DEFAULT_GOAL),$(MAKECMDGOALS)),,ETCTGT+=\n$1: - $2))
@deryni
deryni / Explanation
Last active December 19, 2015 01:39
Kickstart scripts and related install.log files illustrating CentOS 6 kickstart update problem.
Attempting to kickstart CentOS 6 works correctly. Attempting to include post-DVD updates during kickstart causes lots of scriptlet failures. Can someone tell me why this happens?
Specifically, I know why the failures happen (look at the order of package installation between the two outputs). I also know why rpm doesn't get the transaction order right (the scriplets are missing appropriate requires entries). What I don't understand is why pulling in update packages triggers this issue or why a regular install seems to always work.
I believe there are couple of bugs involved here:
- the sudo package does not contain a Requires(post): /bin/chmod
- the anaconda transaction order solver doesn't take scriplet requires ordering considerations into account beyond one dependency level (so the Requires(pre): /usr/sbin/useradd requirement is fulfilled by the time openssh is installed but anaconda doesn't extend that to ensuring that regular Requires: entries for shadow-utils are ordered correctly)
- that for some r
@deryni
deryni / gist:7328699
Created November 6, 2013 00:15
'git describe --contains --abbrev=0' doesn't seem to work.
$ git --version
git version 1.8.2.1
$ git lol
* f09682e (HEAD, tag: second-tag, master) add c
* 86db014 add b
* b8c7c3e (tag: initial-tag) initial
$ git describe 86db014
initial-tag-1-g86db014
$ git describe --abbrev=0 86db014
initial-tag
@deryni
deryni / lua-detect-test.mk
Created November 26, 2013 03:37
lua-detect.mk test
LUA_VERSION := $(or $(LUA_VERSION), $(shell \
(pkg-config --exists lua5.2 && echo 5.2) \
|| (pkg-config --exists lua5.1 && echo 5.1) \
|| (pkg-config --exists lua && echo 5.0)))
LUA_VERSION2 := $(or $(LUA_VERSION2), $(shell \
for ver in 5.2 5.1 ""; do\
pkg-config --exists lua$$ver && echo "lua$$ver" && exit;\
done))
# Find highest known lua version.
#
# It uses pkg-config to do this, but will fail if you have liblua, but
# not the corresponding interpreter/compiler. Let's say you have liblua5.2
# but want to build with liblua5.1 (for which you have the lib, interpreter
# and compiler), you can override by setting LUA_SUFFIX=5.1 when invoking
# make.
#
# If successful, sets the following variables:
# * LUA_SUFFIX (unless already set)
@deryni
deryni / Makefile
Last active January 1, 2016 11:59
Make snippet to construct a lua command.
# Construct LUA_{,C}PATH strings from input modules.
# $1 - list of modules
# $2 - suffix of valid module names
luapath = $(subst $e ,;,$(filter $(addprefix %.,$2),$(join $(foreach m,$1,$(dir $m)),$(foreach m,$1,?$(suffix $m)))))
# Create -l arguments from the input modules.
# $1 - list of modules
luamodules = $(addprefix -l,$(filter-out ?,$(basename $(notdir $1))))
# Create a dummy loaded package for the given names.
# 'lua_dummymod_$modname' variables will be included as the contents of the
# dummy tables created.
@deryni
deryni / powershell.exe
Last active January 2, 2016 03:39
Alright powershell people. Explain this behaviour to me if you would.
PS> help .\test.ps1
test.ps1 [-FirstParam] <Object> [-SecondParam] <Object> [<CommonParameters>]
PS> .\test.ps1 -fi<tab>
# Nothing happens at all.
PS> .\test.ps1
.\test.ps1 : The script 'test.ps1' cannot be run because the following snap-ins that are specified by the "#requires"
statements of the script are missing: VMware.VimAutomation.Core.
...
@deryni
deryni / worddiff.awk
Last active August 29, 2015 14:06
Line+word diff for git changes. Created for http://stackoverflow.com/a/25620599/258523
BEGIN {
RS="\n?~\n"
FS="\n"
}
# Special case the diff header/chunk header lines.
/^diff --git/ {
print
next
}
@deryni
deryni / silent_rules.mk
Created September 3, 2014 16:08
Automake-style Silent Rules support for GNU Make.
SR_PREFIX ?= SR
# Manual automake silent rule stuff
$(SR_PREFIX)_DEFAULT_VERBOSITY = 0
$(SR_PREFIX)_SILENT_VERBOSITY = -1
V ?= $($(SR_PREFIX)_DEFAULT_VERBOSITY)
SILENT := $(and $(filter $($(SR_PREFIX)_SILENT_VERBOSITY),$(V)),silent)
DEFAULT := $(and $(filter $($(SR_PREFIX)_DEFAULT_VERBOSITY),$(V)),default)
import sys, os, rpm
def readRpmHeader(ts, filename):
""" Read an rpm header. """
fd = os.open(filename, os.O_RDONLY)
h = None
try:
h = ts.hdrFromFdno(fd)
finally:
os.close(fd)