]> git.ipfire.org Git - ipfire-3.x.git/blob - tools/make-constants
Added a macro for cross-compilation.
[ipfire-3.x.git] / tools / make-constants
1 #!/bin/bash
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2008 Michael Tremer & Christian Schmidt #
6 # #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
11 # #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
16 # #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 # #
20 ###############################################################################
21 ###############################################################################
22 #
23 # Define default vars
24 #
25 ###############################################################################
26
27 # Default target
28 TARGET=i686
29 POSSIBLE_TARGETS="i586 i686 via-c3 via-c7 geodelx"
30
31 # Configuration rootdir
32 CONFIG_ROOT=/etc/$SNAME
33
34 # Nice level
35 NICE=10
36
37 # Read in kernel version
38 KVER=$(grep --max-count=1 VER lfs/linux | awk '{ print $3 }' | tr -d '\n'; grep --max-count=1 LOCALVERSION lfs/linux | awk '{ print $3 }' | tail -1)
39
40 # Read in machine type
41 MACHINE_REAL=$(uname -m)
42
43 # Read in our tag
44 GIT_TAG=$(git tag | tail -1)
45
46 # Default Security options
47 SSP=1
48 PIE=1
49 PAX=1
50
51 # Embedded build
52 EMB=0
53
54 # Default building options
55 BUILD_EXTRAS=1
56 BUILD_DEBUG=0
57
58 # Default parallelism options
59 PARALLELISMFLAGS=-j$(( $(grep processor < /proc/cpuinfo | wc -l) * 2 + 1 ))
60
61 # Default distcc options
62 DISTCC_HOSTS=localhost
63 DISTCC_PORT=3632
64 DISTCC_JOBS=4
65
66 # Default hostname
67 HOSTNAME=${HOSTNAME-$(hostname -f || hostname)}
68
69 ###############################################################################
70 #
71 # Read the local configuration to override the environment variables
72 #
73 ###############################################################################
74
75 if ! [ -e .config ]; then
76 sed -e "s/@UUID@/$(uuidgen 2>/dev/null || cat /proc/sys/kernel/random/uuid)/" \
77 -e "s/^#UUID=/UUID=/" < $BASEDIR/.config-default > $BASEDIR/.config
78 fi
79
80 . $BASEDIR/.config
81
82 ###############################################################################
83 #
84 # Variables that are not modifyable by .config
85 #
86 ###############################################################################
87
88 if [ 'i686' = $MACHINE_REAL \
89 -o 'i586' = $MACHINE_REAL \
90 -o 'i486' = $MACHINE_REAL \
91 -o 'x86_64' = $MACHINE_REAL ]; then
92 IFS_HOST="$(echo $MACHTYPE | sed "s/$(echo $MACHTYPE | cut -d- -f2)/cross/")"
93 else
94 beautify message FAIL
95 echo "Can't determine your architecture - $MACHINE_REAL"
96 exit 1
97 fi
98
99 if [ 'i686' = $TARGET -o 'i586' = $TARGET \
100 -o 'i486' = $TARGET ]; then
101 MACHINE=${TARGET}
102 MACHINE_REAL=${MACHINE_REAL}
103 LINKER=/lib/ld-linux.so.2
104 IFS_TARGET="${MACHINE}-pc-linux-gnu"
105 CFLAGS="-march=${MACHINE} -O2 -pipe -fomit-frame-pointer"
106 CXXFLAGS="${CFLAGS}"
107 elif [ 'via-c7' = $TARGET ]; then
108 MACHINE=i686
109 MACHINE_REAL=${MACHINE_REAL}
110 LINKER=/lib/ld-linux.so.2
111 IFS_TARGET="${MACHINE}-pc-linux-gnu"
112 CFLAGS="-march=${MACHINE} -mmmx -msse -msse2 -msse3 -O2 -pipe"
113 CXXFLAGS="${CFLAGS}"
114 elif [ 'via-c3' = $TARGET ]; then
115 MACHINE=i586
116 MACHINE_REAL=${MACHINE_REAL}
117 LINKER=/lib/ld-linux.so.2
118 IFS_TARGET="${MACHINE}-pc-linux-gnu"
119 CFLAGS="-march=c3 -m3dnow -O2 -pipe -fomit-frame-pointer"
120 CXXFLAGS="${CFLAGS}"
121 elif [ 'geodelx' = $TARGET ]; then
122 MACHINE=i586
123 MACHINE_REAL=${MACHINE_REAL}
124 LINKER=/lib/ld-linux.so.2
125 IFS_TARGET="${MACHINE}-pc-linux-gnu"
126 CFLAGS="-march=geode -Os -pipe -fomit-frame-pointer"
127 CXXFLAGS="${CFLAGS}"
128 else
129 beautify message FAIL
130 echo "Not a valid target arch (i686|i586|i486|via-c7|via-c3|geodelx) - $TARGET"
131 exit 1
132 fi
133
134 # Make debugging symbols
135 if [ "$BUILD_DEBUG" == "1" ]; then
136 CFLAGS=$(sed -e "s/-O[123s]/-O/g" <<< $CFLAGS)
137 CFLAGS="$CFLAGS -g"
138 CXXFLAGS=$(sed -e "s/-O[123s]/-O/g" <<< $CXXFLAGS)
139 CXXFLAGS="$CXXFLAGS -g"
140 fi
141
142 # Define IMAGENAME
143 IMAGENAME=${SNAME}-${VERSION}.${TARGET}
144
145 if [ "$BUILD_DEBUG" == "1" ]; then
146 # On debug build, append -debug
147 IMAGENAME=${IMAGENAME}-debug
148 fi
149
150 # Define TOOLCHAINNAME
151 TOOLCHAINNAME=$SNAME-$TOOLCHAINVERSION-toolchain-t${TARGET}-m${MACHINE}
152
153 # Set up what used to be /tools
154 TOOLS_DIR=/tools_${MACHINE}
155
156 # Set up /installer
157 INSTALLER_DIR=/pomona
158
159 # A place to build the iso
160 CDROM_DIR=/cdrom
161
162 # A place to keep the images
163 IMAGES_DIR=/images
164
165 # Files that indicates that we are running or failed
166 RUNNING=$BASEDIR/.running
167 FAILED=$BASEDIR/.failed