source: mainline/uspace/app/binutils/toolchain.sh@ 10a530cc

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 10a530cc was cb7c685, checked in by Petr Koupy <petr.koupy@…>, 14 years ago

Improved syntax for file appending in shell scripts.
Minor improvements in comments.

  • Property mode set to 100755
File size: 4.0 KB
Line 
1#! /bin/bash
2
3#
4# Copyright (c) 2011 Petr Koupy
5# All rights reserved.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions
9# are met:
10#
11# - Redistributions of source code must retain the above copyright
12# notice, this list of conditions and the following disclaimer.
13# - Redistributions in binary form must reproduce the above copyright
14# notice, this list of conditions and the following disclaimer in the
15# documentation and/or other materials provided with the distribution.
16# - The name of the author may not be used to endorse or promote products
17# derived from this software without specific prior written permission.
18#
19# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29#
30
31#
32# This script is intended to be called indirectly from the Makefile.
33# Given information from Makefile.common (e.g. CFLAGS), this shell
34# script generates false toolchain consisting of a short shell script
35# for each tool. Therefore, generated false tool already contains some
36# filtered information from the HelenOS side. When the actual call is
37# intercepted, information passed from the binutils side is filtered
38# and stored. Information from both sides is then joined together
39# and passed to the real tool.
40#
41# Basic idea behind filtering the information is that binutils is
42# dominant provider for the compilation, whereas HelenOS is dominant
43# for the linkage. In that way, the compilation command from binutils
44# is left untouched and only extended with a couple of flags that are
45# specific for HelenOS (i.e. include directories, preprocessor
46# directives, preprocessor flags, standard libc exclusion). Similarly,
47# the linkage command is taken from HelenOS and extended with the
48# filtered information from binutils (i.e. output binary, objects,
49# binutils libraries).
50#
51# Most of the false tools are straightforward. However, gcc needs a
52# special approach because binutils use it for both compilation and
53# linkage. In case the linking usage is detected, the call is redirected
54# to the linker.
55#
56
57case "$1" in
58 "gcc")
59 (
60 echo '#! /bin/bash'
61 echo 'AS_LINK="`echo $* | grep '\'as-new\''`"'
62 echo 'LD_LINK="`echo $* | grep '\'ld-new\''`"'
63 echo 'LINK="`echo -n "$AS_LINK""$LD_LINK"`"'
64 echo 'if [ -n "$LINK" ]; then'
65 echo ' LD_ARGS="`echo $* | \'
66 echo ' sed '\'s/-O[^ ]*//g\'' | \'
67 echo ' sed '\'s/-W[^ ]*//g\'' | \'
68 echo ' sed '\'s/-g//g\'' | \'
69 echo ' sed '\'s/-l[^ ]*//g\'' | \'
70 echo ' sed '\'s/ [ ]*/ /g\''`"'
71 echo ' ld "$LD_ARGS"'
72 echo 'else'
73 CFLAGS="`echo "$3" | \
74 sed 's/-O[^ ]*//g' | \
75 sed 's/-W[^ ]*//g' | \
76 sed 's/-pipe//g' | \
77 sed 's/-g//g' | \
78 sed 's/ [ ]*/ /g'`"
79 echo " $2" "$CFLAGS" '$@'
80 echo 'fi'
81 ) > 'gcc'
82 chmod a+x 'gcc'
83 ;;
84 "as")
85 (
86 echo '#! /bin/bash'
87 echo "$2" '$@'
88 ) > 'as'
89 chmod a+x 'as'
90 ;;
91 "ar")
92 (
93 echo '#! /bin/bash'
94 echo "$2" '$@'
95 ) > 'ar'
96 chmod a+x 'ar'
97 ;;
98 "ranlib")
99 (
100 echo '#! /bin/bash'
101 echo "ar -s" '$@'
102 ) > 'ranlib'
103 chmod a+x 'ranlib'
104 ;;
105 "ld")
106 (
107 echo '#! /bin/bash'
108 echo "$2 -n $3 -T $4" '$@' "$5"
109 ) > 'ld'
110 chmod a+x 'ld'
111 ;;
112 "objdump")
113 (
114 echo '#! /bin/bash'
115 echo "$2" '$@'
116 ) > 'objdump'
117 chmod a+x 'objdump'
118 ;;
119 "objcopy")
120 (
121 echo '#! /bin/bash'
122 echo "$2" '$@'
123 ) > 'objcopy'
124 chmod a+x 'objcopy'
125 ;;
126 "strip")
127 (
128 echo '#! /bin/bash'
129 echo "$2" '$@'
130 ) > 'strip'
131 chmod a+x 'strip'
132 ;;
133 *)
134 ;;
135esac
136
Note: See TracBrowser for help on using the repository browser.