jcs's openbsd hax
openbsd
1#!/bin/ksh
2# $OpenBSD: cpp.sh,v 1.10 2019/09/28 17:30:07 ajacoutot Exp $
3
4#
5# Copyright (c) 1990 The Regents of the University of California.
6# All rights reserved.
7#
8# This code is derived from software contributed to Berkeley by
9# the Systems Programming Group of the University of Utah Computer
10# Science Department.
11#
12# Redistribution and use in source and binary forms, with or without
13# modification, are permitted provided that the following conditions
14# are met:
15# 1. Redistributions of source code must retain the above copyright
16# notice, this list of conditions and the following disclaimer.
17# 2. Redistributions in binary form must reproduce the above copyright
18# notice, this list of conditions and the following disclaimer in the
19# documentation and/or other materials provided with the distribution.
20# 3. Neither the name of the University nor the names of its contributors
21# may be used to endorse or promote products derived from this software
22# without specific prior written permission.
23#
24# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34# SUCH DAMAGE.
35#
36# @(#)usr.bin.cpp.sh 6.5 (Berkeley) 4/1/91
37#
38# Transitional front end to CCCP to make it behave like (Reiser) CCP:
39# specifies -traditional
40# doesn't search gcc-include
41#
42PATH=/usr/bin:/bin:/usr/sbin:/sbin
43TRAD=-traditional
44DGNUC="@GNUC@"
45STDINC="-I/usr/include"
46set -A OPTS
47set -A INCS -- "-nostdinc"
48FOUNDFILES=false
49
50CPP=/usr/libexec/cpp
51if [ ! -x $CPP ]; then
52 CPP=`cc -print-search-dirs | sed -ne '/^install: /s/install: \(.*\)/\1cpp/p'`;
53 if [ ! -x $CPP ]; then
54 echo "$0: installation problem: $CPP not found/executable" >&2
55 exit 1
56 fi
57fi
58
59while [ $# -gt 0 ]
60do
61 A="$1"
62 shift
63
64 case $A in
65 -nostdinc)
66 STDINC=
67 ;;
68 -traditional)
69 TRAD=-traditional
70 ;;
71 -notraditional)
72 TRAD=
73 ;;
74 # options that take an argument and that should be sorted before
75 # the $STDINC option
76 -I | -imacros | -include | -idirafter | -iprefix | -iwithprefix | \
77 -iwithprefixbefore | -isysroot | -imultilib | -isystem | -iquote)
78 INCS[${#INCS[@]}]=$A
79 INCS[${#INCS[@]}]=$1
80 shift
81 ;;
82 -I*)
83 INCS[${#INCS[@]}]=$A
84 ;;
85 # other options that take an argument
86 -MF | -MT | -MQ | -x | -D | -U | -o | -A)
87 OPTS[${#OPTS[@]}]=$A
88 OPTS[${#OPTS[@]}]=$1
89 shift
90 ;;
91 -U__GNUC__)
92 DGNUC=
93 OPTS[${#OPTS[@]}]=$A
94 ;;
95 -*)
96 OPTS[${#OPTS[@]}]=$A
97 ;;
98 *)
99 FOUNDFILES=true
100 $CPP $TRAD $DGNUC "${INCS[@]}" $STDINC "${OPTS[@]}" "$A" ||
101 exit
102 ;;
103 esac
104done
105
106if ! $FOUNDFILES
107then
108 # read standard input
109 exec $CPP $TRAD $DGNUC "${INCS[@]}" $STDINC "${OPTS[@]}"
110fi
111
112exit 0