another fix :/
[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 [ "$hdw_status" = "2" -o "$hdw_status" = "3" ] && root=""
52 if [ "$hdw_status" -lt 2 -o "$hdw_crossbuild" != "0" ] ; then
53         if [ -z "$hdw_build_dir" ] ; then
54                 echo "please set hdw_build_dir in ./Config!"
55                 exit 1
56         elif [ ! -d $hdw_build_dir ] ; then
57                 echo "please set _existing_ hdw_build_dir in ./Config"
58                 exit 1
59         else
60                 echo "hdw_build_dir variable set to $hdw_build_dir"
61                 root="$hdw_build_dir"
62         fi
63 fi
64
65 # setting up general environment, now that we know $root
66 set +h
67 umask 022
68 export LC_ALL=POSIX
69 [ "$hdw_status" -lt "2" ] && export PATH="$root/${s1_prefix}/bin:$PATH"
70
71 # let's do optimization and care for crossbuilds
72 if [ ! -z "`uname --version | grep sh-utils`" ] ; then
73         hdw_arch_build="`uname -m -p | tr " " -`-linux-gnu"
74 else
75         hdw_arch_build="`uname -m`-unknown-linux-gnu"
76 fi
77 case "$hdw_arch" in
78         ia32)   if [ -z "$hdw_arch_opt" ] ; then
79                         hdw_arch_target="i386-pc-linux-gnu"
80                 elif [ ! -z "$hdw_arch_opt" ] ; then
81                         hdw_arch_target="${hdw_arch_opt}-pc-linux-gnu"
82                         hdw_cflags="-march=${hdw_arch_opt}"
83                 fi
84                 hdw_arch_build=${hdw_arch_build//unknown/pc} ;;
85         sparc*) if [ -z "$hdw_arch_opt" ] ; then
86                         hdw_arch_target="$hdw_arch-unknown-linux-gnu"
87                 else
88                         # hack this! :)
89                         echo "pls hack sparc* opt. options and submit :)"
90                         echo "no optimization used!"
91                         hdw_arch_target="$hdw_arch-unknown-linux-gnu"
92                         hdw_cflags="-march={hdw_arch_opt}"
93                 fi ;;
94         ppc)
95                 hdw_arch_target="powerpc-unknown-linux-gnu"
96                 [ ! -z "$hdw_arch_opt" ] && hdw_cflags="-march=${hdw_arch_opt}"
97                 hdw_arch_build=${hdw_arch_build//ppc/powerpc} ;;
98         *)      echo "not supported yet"
99                 echo "please choose a valid optimization and build platform."
100                 exit 1 ;;
101 esac
102 # -O flag
103 [ ! -z "$hdw_opt" ] && hdw_cflags="-O${hdw_opt} $hdw_cflags"
104
105 # build tools to use
106 hdw_arch_prefix=""
107 if [ "$hdw_crossbuild" != "0" ] ; then
108         hdw_arch_prefix="$hdw_arch_target-"
109         if [ "$hdw_real_build" ] ; then
110                 if [ "$hdw_arch" = "ia32" ] ; then
111                 hdw_arch_build=${hdw_arch_build//$hdw_arch_opt/$hdw_real_build}
112                 else
113                 hdw_arch_build=${hdw_arch_build//$hdw_arch/$hdw_real_build}
114                 fi
115         fi
116 fi
117 # test: actually we always use the compilers for target
118 # hdw_arch_prefix="$hdw_arch_target-"
119
120 # resume ...
121 echo "hdw_arch_target variable set to $hdw_arch_target"
122 echo "hdw_arch_build variable set to $hdw_arch_build"
123 echo "hdw_cflags variable set to $hdw_cflags"
124 [ "$hdw_status" = "1" ] && echo "hdw_stage1_prefix set to '$s1_prefix'"
125
126 # lets see what we are going to build
127 if [ -z $hdw_target ] ; then 
128         echo "please set hdw_target in ./Config!"
129         exit 1
130 elif [ ! -d ./targets/$hdw_target ] ; then 
131         echo "please set _existing_ hdw_target in ./Config!"
132         exit 1
133 else
134         echo "hdw_target variable set to $hdw_target"
135 fi
136