]> www.hackdaworld.org Git - hdw-linux/hdw-linux.git/blob - scripts/Config
updated xfsutils
[hdw-linux/hdw-linux.git] / scripts / Config
1 #
2 # hdw-linux Config script
3 #
4 # author: hackbard@hackdaworld.org
5 #
6 # script initializing environment
7
8
9 stage=""
10
11 while [ "$1" ] ; do
12         case "$1" in
13                 -stage)         stage="$2"              ; shift 2 ;;
14                 *)              echo 
15                                 echo "Usage:"
16                                 echo
17                                 echo " ./scripts/Config -stage <stagelevel>"
18                                 echo
19                                 shift 1 ; exit 1 ;;
20         esac
21 done
22
23 if [ -z "$stage" ]; then
24         echo "something went wrong, no stage specified."
25         exit 1
26 fi
27
28 # execute  Config file & create symlink to doc/README + doc/BUILD
29 if [ -f ./Config ] ; then
30         hdw_home_dir=`pwd`
31         echo "setting hdw_home_dir to $hdw_home_dir"
32         echo "reading ./Config file"
33         . ./Config
34         [ ! -s ./README ] && ln -s ./doc/README .
35         [ ! -s ./BUILD ] && ln -s ./doc/BUILD .
36         [ ! -s ./INSTALL ] && ln -s ./doc/INSTALL .
37         [ ! -s ./License ] && ln -s ./doc/License .
38 else
39         echo "./Config file not found. are you in correct directory?"
40         exit 1
41 fi
42
43 # define the toolchain name, default: "toolchain"
44 [ -z "$hdw_tc_name" ] && hdw_tc_name="toolchain"
45 export tc_name=$hdw_tc_name
46
47 # lets see what root is:
48 root=""
49 if [ "$hdw_crossbuild" != "0" -o "$stage" -lt "2" ] ; then
50         # check for properly configured build directory
51         if [ -z "$hdw_build_dir" ] ; then
52                 echo "please set hdw_build_dir in ./Config!"
53                 exit 1
54         elif [ ! -d $hdw_build_dir ] ; then
55                 echo "please set _existing_ hdw_build_dir in ./Config"
56                 exit 1
57         else
58                 echo "hdw_build_dir variable set to $hdw_build_dir"
59                 root="$hdw_build_dir"
60         fi
61 fi
62
63 # setting up general environment, now that we know $root
64 set +h
65 umask 022
66 export LC_ALL=POSIX
67 if [ "$stage" -lt "2" -a "$hdw_crossbuild" = "0" ] ; then
68         export PATH="/${tc_name}/bin:/${tc_name}/sbin:$PATH"
69 elif [ "$hdw_crossbuild" != "0" ] ; then
70         export PATH="$root/${tc_name}/bin:$root/${tc_name}/sbin:$PATH"
71 fi
72
73 # let's do optimization and care for crossbuilds
74 #
75 # as gnu autoconf terminology has been confusing me again and again,
76 # there are a few comments following ;)
77 #
78 # ref: gcc docs - hardware models and configurations
79 #      @ http://gcc.gnu.org/onlinedocs/
80 #
81
82 # --build: the system the actual executable is created on. uname will tell us.
83 #          you may set hdw_real_build, or
84 #          you may fake uname output using fake_utsname kernel module!
85 if [ -n "`uname --version | grep sh-utils`" ] ; then
86         hdw_arch_build="`uname -m -p | tr " " -`-linux-gnu"
87 else
88         hdw_arch_build="`uname -m`-unknown-linux-gnu"
89 fi
90 [ -n "$hdw_real_build" ] && hdw_arch_build="${hdw_real_build}-unknown-linux-gnu"
91
92 # --target: the system for which the executable is going to produce code.
93 case "$hdw_arch" in
94         ia32)   if [ -z "$hdw_arch_opt" ] ; then
95                         hdw_arch_target="i386-pc-linux-gnu"
96                 else
97                         hdw_arch_target="${hdw_arch_opt}-pc-linux-gnu"
98                         hdw_cflags="-march=${hdw_arch_opt}"
99                 fi
100                 hdw_arch_build=${hdw_arch_build//unknown/pc} ;;
101         sparc*) if [ -z "$hdw_arch_opt" ] ; then
102                         hdw_arch_target="$hdw_arch-unknown-linux-gnu"
103                 else
104                         hdw_arch_target="$hdw_arch-unknown-linux-gnu"
105                         hdw_cflags="-march={hdw_arch_opt}"
106                 fi ;;
107         ppc)
108                 hdw_arch_target="powerpc-unknown-linux-gnu"
109                 if [ -z "$hdw_arch_opt" ] ; then
110                         hdw_cflags="-mcpu=common"
111                 else
112                         hdw_cflags="-mcpu=${hdw_arch_opt}"
113                 fi
114                 hdw_arch_build=${hdw_arch_build//ppc/powerpc} ;;
115         ppc64)
116                 hdw_arch_target="powerpc64-unknown-linux-gnu"
117                 if [ -z "$hdw_arch_opt" ] ; then
118                         hdw_cflags="-mcpu=common"
119                 else
120                         hdw_cflags="-mcpu=${hdw_arch_opt}"
121                 fi
122                 hdw_arch_build=${hdw_arch_build//ppc64/powerpc64} ;;
123         mips)   hdw_arch_target="mips-unknown-linux-gnu"
124                 if [ -z "$hdw_arch_opt" ] ; then
125                         echo "info: no optimization set"
126                 else
127                         hdw_cflags="-march=${hdw_arch_opt}"
128                 fi ;;
129         *)      echo "$hdw_arch_target not supported yet"
130                 echo "please choose a valid optimization and build platform."
131                 exit 1 ;;
132 esac
133
134 # --host: system where the created executable runs on.
135 hdw_arch_host=${hdw_arch_build}
136 [ "$stage" != "0" -a "$hdw_crossbuild" = "0" ] && \
137         hdw_arch_host=${hdw_arch_target}
138
139 # -O flag
140 # optimization only at stages >= 1
141 if [ -n "$hdw_opt" -a "$stage" != "0" ] ; then
142         hdw_cflags="-O${hdw_opt} $hdw_cflags"
143 else
144         unset hdw_cflags
145 fi
146
147 # build tools to use
148 hdw_arch_prefix=""
149 [ "$stage" != "0" ] && hdw_arch_prefix="$hdw_arch_target-"
150
151 # print decissions for debugging ...
152 echo "root variable set to '$root'"
153 echo "hdw_arch_target variable set to $hdw_arch_target"
154 echo "hdw_arch_build variable set to $hdw_arch_build"
155 echo "hdw_arch_host variable set to $hdw_arch_host"
156 echo "hdw_arch_prefix variable set to '$hdw_arch_prefix'"
157 echo "hdw_cflags variable set to '$hdw_cflags'"
158 echo "hdw_tc_name set to '$hdw_tc_name'"
159
160 # lets see what we are going to build
161 if [ -z $hdw_target ] ; then 
162         echo "please set hdw_target in ./Config!"
163         exit 1
164 elif [ ! -d ./targets/$hdw_target ] ; then 
165         echo "please set _existing_ hdw_target in ./Config!"
166         exit 1
167 else
168         echo "hdw_target variable set to $hdw_target"
169 fi
170