don't check when its clang masquerading as gcc
[AROS.git] / tools / sdk / AROS-SDK-Install
blobf396b41e4c764fe12efd5659a925a1f5df117497
1 #!/bin/bash
3 export LC_ALL=C
5 CLR="\\0033[2J\\0033[01;01H"
6 B="\\033[1m"
7 N="\\033[0;39m"
8 R="\\033[1;31m"
9 G="\\033[1;32m"
10 OK="${G}OK.${N}"
11 FAILED="${R}FAILED.${N}"
13 echo -e \
14 "${CLR}Welcome to the ${B}AROS SDK${N} installation script!\n"
16 echo -e \
17 "You are about to be asked a few ${B}questions${N}, each with a ${B}default${N} answer. This answer is written in ${B}bold${N} characters and put inside square brakets; in order to select it just press <${B}ENTER${N}>, whilst to override it write your own answer and then press <${B}ENTER${N}>.\n"
19 echo -e \
20 "Remember that in order for the installation to be successful you need a ${B}gcc${N} compiler, and related ${B}binutils${N}, able to produce ${B}i386-elf${N} executables. If you are running an x86 version of Linux, or an x86 version of any of the *BSD operating system, or an x86 version of BeOS, chances are you already have the compiler installed.\n"
22 echo -e \
23 "You can even install the SDK on a non-x86 architecture, provided that the proper crosscompiler is installed in the system.\n"
25 echo -e \
26 "If you're ready to start the installation, press <${B}ENTER${N}>\n"
28 cc=`which gcc 2>/dev/null`
30 while true; do
31 echo -e -n "Name of the gcc compiler to use, or path to it [${B}${cc}${N}]: "
32 read cc_tmp
34 if test "$cc_tmp" != ""; then
35 cc_path=$cc_tmp
36 else
37 cc_path=$cc
40 echo -e -n "Trying ${B}$cc_path${N}... "
41 cc_path=`which $cc_path 2>/dev/null`
43 if test "$cc_path" != ""; then
44 cc_cpu=`$cc_path -dumpmachine 2>/dev/null | cut -f1 -d-`
45 else
46 cc_cpu=
49 case $cc_cpu in
50 i?86)
51 echo -e "$OK"
52 cc_cpu=i386
53 break
55 x86_64)
56 echo -e "$OK"
57 cc_cpu=x86_64
58 break
61 echo -e "$FAILED"
63 if test "$cc_path" == ""; then
64 echo -e "The compiler you specified doesn't seem to exist.\n"
65 else
66 echo -e "The compiler you specified has been configured for the" \
67 "${B}$cc_cpu${N} cpu which is not supported by this SDK.\n"
69 esac
70 done
71 cc=$cc_path
73 echo -e Checking where the compiler stores its own include files...
74 cc_os=`$cc -dumpmachine 2>/dev/null | cut -f2- -d-`
75 if echo $cc_os | grep freebsd >/dev/null; then
76 cc_include=/usr/include
77 else
78 cc_include=`dirname \`$cc -print-libgcc-file-name\``/include
80 echo -e "${B}$cc_include${N}"
82 #find out where is the compiler going to search for the verious tools
83 cc_programs_path=`gcc -print-search-dirs | grep "programs: =" | cut -c 12-`
85 tools_list="ld nm as ar objcopy objdump objcopy ranlib strip"
87 for tool in $tools_list; do
88 echo -e -n "Checking ${B}$tool${N}... "
90 tool1=`which \`$cc -print-prog-name=$tool\` 2>/dev/null`
92 if test "$tool1" != ""; then
93 echo -e $OK
94 export $tool=$tool1
95 else
96 echo -e $FAILED
97 echo -e "The compiler cannot access ${B}$tool${N}, or there's no ${B}$tool${N}" \
98 "installed. Make sure you have the correct binutils installed properly."
99 exit 1
101 done
103 echo -e -n "Checking whether ${B}ld${N} supports the ELF format... "
105 ld_emu_all="`$ld -V 2>/dev/null` none"
107 for ld_emu in $ld_emu_all; do
108 case $ld_emu in
109 elf_${cc_cpu})
110 break
112 esac
113 done
115 if test "$ld_emu" != "none"; then
116 echo -e $OK
117 else
118 echo -e $FAILED
119 echo -e "Ld doesnt support the ELF executable format." \
120 "You need to configure the binutils so that they can work on ELF objects."
121 exit 1
124 aros_sdk_path=/usr/local/aros-sdk
126 while true; do
127 echo -e -n "Directory in which to install the AROS SDK [${B}${aros_sdk_path}${N}]: "
128 read aros_sdk_path_tmp
130 if test "$aros_sdk_path_tmp" != ""; then
131 aros_sdk_path=$aros_sdk_path_tmp
134 while true; do
135 if ! test -e $aros_sdk_path; then
136 echo -e -n "The directory ${B}$aros_sdk_path${N} does not exist, "
137 echo -e -n "create it [${B}yes${N}]? "
138 read answer
140 if test "$answer" = "yes" -o "$answer" = ""; then
141 break 2
144 if test "$answer" = "no"; then
145 break 1
147 else
148 if ! test -d $aros_sdk_path; then
149 echo -e "${B}$aros_sdk_path${N} already exists but it's not a directory."
150 echo -e "Chose a new name or delete the existing ${B}$aros_sdk_path${N}"
151 break 1
152 else
153 break 2
156 done
157 done
159 echo -e Making directories...
160 all_dirs="$aros_sdk_path/${cc_cpu}-aros/include $aros_sdk_path/bin $aros_sdk_path/${cc_cpu}-aros/lib/gcc-lib $aros_sdk_path/${cc_cpu}-aros/bin"
162 for dir in $all_dirs; do
163 if ! test -d $dir; then
164 mkdir -p $dir;
166 done
168 # Patch paths in env.h.
169 # For LD_NAME we can't use $aros_sdk_path/bin/${cc_cpu}-aros-ld because
170 # it would cause a recursion which creates error "Argument list too long".
171 # TODO: add a check if /usr/bin/ld really exists
172 echo -e Patching env.h...
173 sed -i -e "35 c \#define LD_NAME \"/usr/bin/ld\"" tools/collect-aros/env.h
174 sed -i -e "36 c \#define STRIP_NAME \"$aros_sdk_path/bin/${cc_cpu}-aros-strip\"" tools/collect-aros/env.h
175 sed -i -e "37 c \#define NM_NAME \"$aros_sdk_path/bin/${cc_cpu}-aros-nm -C -ul\"" tools/collect-aros/env.h
176 sed -i -e "38 c \#define OBJDUMP_NAME \"$aros_sdk_path/bin/${cc_cpu}-aros-objdump\"" tools/collect-aros/env.h
178 if ! make -s -C tools/collect-aros \
179 COLLECT-AROS=$aros_sdk_path/${cc_cpu}-aros/lib/gcc-lib/collect-aros; then
180 exit 1;
183 echo -e Building scripts...
184 sed "s,@aros_sdk_path@,$aros_sdk_path,g; s,@ld_emu@,$ld_emu,g; s,@cc_include@,$cc_include,g; s,@cc_cpu@,$cc_cpu,g" scripts/specs.in > $aros_sdk_path/${cc_cpu}-aros/lib/gcc-lib/specs
186 sed "s,@aros_sdk_path@,$aros_sdk_path,g; s,@ld@,$ld,g; s,@nm@,$nm,g; s,@cc@,$cc,g; s,@objdump@,$objdump,g; s,@cc_cpu@,$cc_cpu,g; s,@strip@,$strip,g" scripts/aros-gcc.in > $aros_sdk_path/${cc_cpu}-aros/bin/gcc
187 chmod a+x $aros_sdk_path/${cc_cpu}-aros/bin/gcc
189 sed "s,@aros_sdk_path@,$aros_sdk_path,g; s,@ld@,$ld,g; s,@nm@,$nm,g; s,@cc@,$cc,g; s,@objdump@,$objdump,g; s,@cc_cpu@,$cc_cpu,g; s,@cc_programs_path@,$cc_programs_path,g" scripts/aros-ld.in > $aros_sdk_path/${cc_cpu}-aros/bin/ld
190 chmod a+x $aros_sdk_path/${cc_cpu}-aros/bin/ld
192 sed "s,@strip@,$strip,g" scripts/aros-strip.in > $aros_sdk_path/${cc_cpu}-aros/bin/strip
193 chmod a+x $aros_sdk_path/${cc_cpu}-aros/bin/strip
195 cat <<EOF > AROS-SDK-Uninstall
196 #!/bin/bash
197 echo -e "${R}ATTENTION!${N} The AROS SDK is about to be uninstalled."
199 while true; do
200 echo -e -n "Do you really want to proceed [${B}no${N}]? "
201 read answer
203 if test "\$answer" = "yes"; then
204 echo -e Uninstalling the AROS SDK...
205 rm -Rf $aros_sdk_path/${cc_cpu}-aros $aros_sdk_path/bin/i386-aros-* \$0
206 break
209 if test "\$answer" = "no" -o "\$answer" = ""; then
210 echo -e Nothing done
211 break;
213 done
216 chmod a+x AROS-SDK-Uninstall
218 echo -e Copying files...
219 ln -sf $as $aros_sdk_path/${cc_cpu}-aros/bin/as
220 ln -sf $ar $aros_sdk_path/${cc_cpu}-aros/bin/ar
221 ln -sf $nm $aros_sdk_path/${cc_cpu}-aros/bin/nm
222 ln -sf $objcopy $aros_sdk_path/${cc_cpu}-aros/bin/objcopy
223 ln -sf $objdump $aros_sdk_path/${cc_cpu}-aros/bin/objdump
224 ln -sf $ranlib $aros_sdk_path/${cc_cpu}-aros/bin/ranlib
226 ln -sf $aros_sdk_path/${cc_cpu}-aros/bin/gcc $aros_sdk_path/bin/${cc_cpu}-aros-gcc
227 ln -sf $aros_sdk_path/${cc_cpu}-aros/bin/ld $aros_sdk_path/bin/${cc_cpu}-aros-ld
228 ln -sf $aros_sdk_path/${cc_cpu}-aros/bin/ar $aros_sdk_path/bin/${cc_cpu}-aros-ar
229 ln -sf $aros_sdk_path/${cc_cpu}-aros/bin/as $aros_sdk_path/bin/${cc_cpu}-aros-as
230 ln -sf $aros_sdk_path/${cc_cpu}-aros/bin/nm $aros_sdk_path/bin/${cc_cpu}-aros-nm
231 ln -sf $aros_sdk_path/${cc_cpu}-aros/bin/objcopy $aros_sdk_path/bin/${cc_cpu}-aros-objcopy
232 ln -sf $aros_sdk_path/${cc_cpu}-aros/bin/objdump $aros_sdk_path/bin/${cc_cpu}-aros-objdump
233 ln -sf $aros_sdk_path/${cc_cpu}-aros/bin/ranlib $aros_sdk_path/bin/${cc_cpu}-aros-ranlib
234 ln -sf $aros_sdk_path/${cc_cpu}-aros/bin/strip $aros_sdk_path/bin/${cc_cpu}-aros-strip
236 cp -a $cc_cpu/lib/* $aros_sdk_path/${cc_cpu}-aros/lib/
237 cp -a $cc_cpu/include/* $aros_sdk_path/${cc_cpu}-aros/include/
239 echo -e "\nEverything done. Remember to add ${B}$aros_sdk_path/bin${N} to your ${B}PATH${N} environment variable before using the AROS SDK."