pkgsrc/mk/wrapper/arg-source
maya 6c25dec844 Remove clauses 3,4 from TNF-only copyright blocks.
This is based on the decision The NetBSD Foundation made in 2008 to
do so, which was already applied to src.

This change has been applied to code which is likely not in other
repositories.

ok board@, reviewed by riastradh@
2018-08-22 20:48:36 +00:00

197 lines
7.2 KiB
Text

# $NetBSD: arg-source,v 1.22 2018/08/22 20:48:37 maya Exp $
#
# Copyright (c) 2004 The NetBSD Foundation, Inc.
# All rights reserved.
#
# This code is derived from software contributed to The NetBSD Foundation
# by Johnny C. Lam.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
# This script manages a buffer through which arguments from the command
# line are funneled. Along the way, the arguments are potentially
# merged and split in various ways to canonicalize their representation.
# This script should be sourced within a loop and upon exiting returns
# an argument in $arg.
#
# This is done by pushing the next command-line argument onto a queue,
# then using a processing loop to pop an argument off of the top of
# the queue, transform it, and possibly push more arguments back onto
# the queue.
# Push arguments from the command line into the argument buffer.
while $test $# -gt 0; do
arg="$1"; shift
case $arg in
##############################################################
# Merge "-I /dir" into a single "-I/dir". Same for -l, -D,
# -L and -R.
##############################################################
-[lDILR])
nextarg="$1"; shift
case "$nextarg" in
-*) msg_log $wrapperlog "WARNING: [arg-source] An $arg option must not be followed by another option, $nextarg." ;;
esac
append_queue argbuf "$arg$nextarg"
$debug_log $wrapperlog " (arg-source) push: $arg$nextarg"
;;
##############################################################
# Convert "-isystem /dir" into a single "-isystem,/dir".
# cmd-sync will put it back
##############################################################
-isystem)
nextarg="$1"; shift
case "$nextarg" in
-*) msg_log $wrapperlog "WARNING: [arg-source] An $arg option must not be followed by another option, $nextarg." ;;
esac
append_queue argbuf "$arg,$nextarg"
$debug_log $wrapperlog " (arg-source) push: $arg,$nextarg"
;;
##############################################################
# Split -Wl,option1,option2 into -Wl,option1 -Wl,option2 and
# process them again.
#
# XXX: The sunpro manual page says: A comma can be part of an
# argument by escaping it with an immediately preceding
# backslash. The manual pages for gcc and mipspro do not
# mention commas in those options at all.
##############################################################
-Wl,*,*)
$debug_log $wrapperlog " (arg-source) before-split: $arg $*"
saved_IFS="$IFS"
new_args=""
IFS=","
for o in ${arg#-Wl,}; do
IFS="$saved_IFS"
shquote "$o"; o="$shquoted"
new_args="$new_args -Wl,$o"
done
IFS="$saved_IFS"
eval "set args $new_args \"\$@\""; shift
$debug_log $wrapperlog " (arg-source) after-split: $*"
continue
;;
##############################################################
# Split "-Wl,-R/dir1:/dir2" into "-Wl,-R/dir1 -Wl,-R/dir2".
# Same for -R and -Wl,-rpath and -Wl,-rpath-link.
# (at the same time suppress the double dash in --rpath to -rpath)
##############################################################
-R*:*|-Wl,-R*:*|\
-Wl,-rpath,*:*|-Wl,-rpath-link,*:*|-Wl,--rpath,*:*)
case $arg in
-R*) R="-R" ;;
-Wl,-R*) R="-Wl,-R" ;;
-Wl,-rpath,*) R="-Wl,-rpath," ;;
-Wl,-rpath-link,*) R="-Wl,-rpath-link," ;;
-Wl,--rpath,*) R="-Wl,-rpath," ;;
esac
list="${arg#$R}"
save_IFS="${IFS}"; IFS=":"
for dir in $list; do
IFS="${save_IFS}"
append_queue argbuf "$R$dir"
$debug_log $wrapperlog " (arg-source) push: $R$dir"
done
IFS="${save_IFS}"
;;
##############################################################
# Merge and split "-Wl,-R -Wl,/dir1:/dir2" into
# "-Wl,-R/dir1 -Wl,-R/dir2". Same for -Wl,-rpath and
# -Wl,-rpath-link.
# (at the same time suppress the double dash in --rpath to -rpath)
##############################################################
-Wl,-R|-Wl,-rpath|-Wl,-rpath-link|-Wl,--rpath)
nextarg="$1"; shift
case $arg in
-Wl,-R) R="-Wl,-R" ;;
-Wl,-rpath) R="-Wl,-rpath," ;;
-Wl,-rpath-link) R="-Wl,-rpath-link," ;;
-Wl,--rpath) R="-Wl,-rpath," ;;
esac
nextarg="${nextarg#-Wl,}"
case $nextarg in
*:*)
save_IFS="${IFS}"; IFS=":"
for dir in $nextarg; do
IFS="${save_IFS}"
append_queue argbuf "$R$dir"
$debug_log $wrapperlog " (arg-source) push: $R$dir"
done
IFS="${save_IFS}"
;;
*)
append_queue argbuf "$R$nextarg"
$debug_log $wrapperlog " (arg-source) push: $R$nextarg"
;;
esac
;;
##############################################################
# "-Xlinker arg" is the equivalent of "-Wl,arg" so convert it
# here before queueing it up.
##############################################################
-Xlinker)
nextarg="$1"; shift
case $nextarg in
-Wl,*)
append_queue argbuf "$nextarg"
$debug_log $wrapperlog " (arg-source) push: $nextarg"
;;
*)
append_queue argbuf "-Wl,$nextarg"
$debug_log $wrapperlog " (arg-source) push: -Wl,$nextarg"
;;
esac
;;
##############################################################
# Remember whether running the linker is desired.
##############################################################
-c|-S|-E)
dont_link=yes
dont_link_binary=yes
append_queue argbuf "$arg"
$debug_log $wrapperlog " (arg-source) push: $arg"
;;
-Wl,-N|-Wl,-r|-shared)
dont_link_binary=yes
append_queue argbuf "$arg"
$debug_log $wrapperlog " (arg-source) push: $arg"
;;
##############################################################
# Determine if we are compiling anything from source.
##############################################################
*.C|*.CPP|*.c|*.c++|*.cc|*.cp|*.cpp|*.cxx|*.go|\
*.H|*.HPP|*.h|*.h++|*.hh|*.hp|*.hpp|*.hxx|*.i|*.ii|\
*.M|*.m|*.mi|*.mii|*.mm|*.S|*.s|*.sx|*.tcc)
has_source=yes
append_queue argbuf "$arg"
$debug_log $wrapperlog " (arg-source) push: $arg"
;;
##############################################################
# For everything else, just queue it up.
##############################################################
*)
append_queue argbuf "$arg"
$debug_log $wrapperlog " (arg-source) push: $arg"
;;
esac
done