reorganized Config file
[hdw-linux/hdw-linux.git] / scripts / Config
1 #
2 # hdw-linux Config script
3 #
4 # author:       hackbard
5 #
6 # script initializing environment
7
8
9 hdw_status=""
10
11 while [ "$1" ] ; do
12         case "$1" in
13                 -stage)         hdw_status="$2"         ; shift 2 ;;
14                 *)              echo 
15                                 echo "Usage:"
16                                 echo
17                                 echo " ./scripts/Config -stage <stagelevel>"
18                                 echo ;;
19         esac
20 done
21
22 if [ -z "$hdw_status" ]; then
23         echo "something went wrong. stage needs to be specified."
24         exit 1
25 fi
26
27 # execute  Config file & create symlink to doc/README + doc/BUILD
28 if [ -f ./Config ] ; then
29         hdw_home_dir=`pwd`
30         echo "setting hdw_home_dir to $hdw_home_dir"
31         echo "reading ./Config file"
32         . ./Config
33         [ ! -s ./README ] && ln -s ./doc/README .
34         [ ! -s ./BUILD ] && ln -s ./doc/BUILD .
35         [ ! -s ./INSTALL ] && ln -s ./doc/INSTALL .
36         [ ! -s ./License ] && ln -s ./doc/License .
37 else
38         echo "./Config file not found. are you in correct directory?"
39         exit 1
40 fi
41
42 # define the stage 0/1 prefix to use
43 # default "static", though no static linking is done anymore in stage1
44 if [ -z "$hdw_stage1_prefix" ] ; then
45          s1_prefix="static" # default
46 else
47         s1_prefix=$hdw_stage1_prefix
48 fi
49
50 # lets see what root is:
51 root=""
52 if [ "$hdw_crossbuild" != "0" -o "$hdw_status" -lt "2" ] ; then
53         # check for properly configured build directory
54         if [ -z "$hdw_build_dir" ] ; then
55                 echo "please set hdw_build_dir in ./Config!"
56                 exit 1
57         elif [ ! -d $hdw_build_dir ] ; then
58                 echo "please set _existing_ hdw_build_dir in ./Config"
59                 exit 1
60         else
61                 echo "hdw_build_dir variable set to $hdw_build_dir"
62                 root="$hdw_build_dir"
63         fi
64 fi
65
66 # setting up general environment, now that we know $root
67 set +h
68 umask 022
69 export LC_ALL=POSIX
70 [ "$hdw_status" -lt "2" -o "$hdw_crossbuild" != "0" ] && \
71         export PATH="$root/${s1_prefix}/bin:$PATH"
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 [ "$hdw_status" != "0" ] && hdw_arch_host=${hdw_arch_target}
137
138 # -O flag
139 # optimization only at stages >= 1
140 [ -n "$hdw_opt" ] && hdw_cflags="-O${hdw_opt} $hdw_cflags"
141
142 # build tools to use
143 # should be the same like host imho, right?
144 hdw_arch_prefix="$hdw_arch_host-"
145
146 # print decissions for debugging ...
147 echo "root variable set to '$root'"
148 echo "hdw_arch_target variable set to $hdw_arch_target"
149 echo "hdw_arch_build variable set to $hdw_arch_build"
150 echo "hdw_arch_host variable ste to $hdw_arch_host"
151 echo "hdw_arch_prefix variable set to $hdw_arch_prefix"
152 echo "hdw_cflags variable set to $hdw_cflags"
153 [ "$hdw_status" = "1" ] && echo "hdw_stage1_prefix set to '$s1_prefix'"
154
155 # lets see what we are going to build
156 if [ -z $hdw_target ] ; then 
157         echo "please set hdw_target in ./Config!"
158         exit 1
159 elif [ ! -d ./targets/$hdw_target ] ; then 
160         echo "please set _existing_ hdw_target in ./Config!"
161         exit 1
162 else
163         echo "hdw_target variable set to $hdw_target"
164 fi
165