196670Sfanf#!/bin/sh 296670Sfanf# 3199813Sfanf# unifdefall: remove all the #if's from a source file 496670Sfanf# 5248849Sfanf# Copyright (c) 2002 - 2013 Tony Finch <dot@dotat.at> 6202636Sfanf# Copyright (c) 2009 - 2010 Jonathan Nieder <jrnieder@gmail.com> 7199813Sfanf# 8199813Sfanf# Redistribution and use in source and binary forms, with or without 9199813Sfanf# modification, are permitted provided that the following conditions 10199813Sfanf# are met: 11199813Sfanf# 1. Redistributions of source code must retain the above copyright 12199813Sfanf# notice, this list of conditions and the following disclaimer. 13199813Sfanf# 2. Redistributions in binary form must reproduce the above copyright 14199813Sfanf# notice, this list of conditions and the following disclaimer in the 15199813Sfanf# documentation and/or other materials provided with the distribution. 16199813Sfanf# 17199813Sfanf# THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18199813Sfanf# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19199813Sfanf# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20199813Sfanf# ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 21199813Sfanf# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22199813Sfanf# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23199813Sfanf# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24199813Sfanf# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25199813Sfanf# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26199813Sfanf# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27199813Sfanf# SUCH DAMAGE. 28199813Sfanf# 2996670Sfanf# $FreeBSD: releng/10.2/usr.bin/unifdef/unifdefall.sh 279639 2015-03-05 09:39:29Z hselasky $ 3096670Sfanf 3196670Sfanfset -e 3296670Sfanf 33202636Sfanfunifdef="$(dirname "$0")/unifdef" 34202636Sfanfif [ ! -e "$unifdef" ] 35202636Sfanfthen 36202636Sfanf unifdef=unifdef 37202636Sfanffi 38202636Sfanf 39205089Sfanfcase "$@" in 40205089Sfanf"-d "*) echo DEBUGGING 1>&2 41205089Sfanf debug=-d 42205089Sfanf shift 43205089Sfanfesac 44205089Sfanf 45248258Sobrientmp=$(mktemp -d "${TMPDIR:-/tmp}/${0##*/}.XXXXXXXXXX") || exit 2 46205089Sfanftrap 'rm -r "$tmp" || exit 2' EXIT 4796670Sfanf 48199813Sfanfexport LC_ALL=C 4996670Sfanf 50279639Shselasky# list of all controlling macros; assume these are undefined 51279639Shselasky"$unifdef" $debug -s "$@" | sort -u | sed 's/^/#undef /' >"$tmp/undefs" 52199842Sfanf# list of all macro definitions 53279639Shselaskycc -E -dM "$@" | sort >"$tmp/defs" 54279639Shselasky 55205089Sfanfcase $debug in 56279639Shselasky-d) cat "$tmp/undefs" "$tmp/defs" 1>&2 57205089Sfanfesac 58279639Shselasky 59279639Shselasky# order of -f arguments means definitions override undefs 60279639Shselasky"$unifdef" $debug -k -f "$tmp/undefs" -f "$tmp/defs" "$@" 61