diff options
Diffstat (limited to 'enea-init-build-env')
| -rwxr-xr-x | enea-init-build-env | 264 |
1 files changed, 264 insertions, 0 deletions
diff --git a/enea-init-build-env b/enea-init-build-env new file mode 100755 index 0000000000..9bc5bab43f --- /dev/null +++ b/enea-init-build-env | |||
| @@ -0,0 +1,264 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | if [ "$_" = "$0" ]; then | ||
| 3 | echo "Error: This script needs to be sourced." | ||
| 4 | echo "Please run as 'source $0'." | ||
| 5 | exit | ||
| 6 | fi | ||
| 7 | |||
| 8 | # always unset these in case something goes wrong in the previous run | ||
| 9 | unset BBLAYERS_CONF_EXISTS | ||
| 10 | unset BUILD_PATH | ||
| 11 | unset CUSTOM_SCRIPTS | ||
| 12 | unset DISTRO | ||
| 13 | unset DOWNLOAD_DLDIR | ||
| 14 | unset SOURCE_MIRROR_URL | ||
| 15 | unset ENEAROOT | ||
| 16 | unset EXITME | ||
| 17 | unset LOCAL_CONF_EXISTS | ||
| 18 | unset MACHINE | ||
| 19 | unset METALAYERS | ||
| 20 | unset NUM_CORES | ||
| 21 | unset SSTATE_DIR | ||
| 22 | unset SSTATE_MIRRORS | ||
| 23 | unset TESTING_ADDITIONS | ||
| 24 | unset -f usage | ||
| 25 | unset OPTERR | ||
| 26 | unset OPTIND | ||
| 27 | unset OPTION | ||
| 28 | |||
| 29 | NUM_CORES=$(grep -c processor /proc/cpuinfo || echo 2) | ||
| 30 | BUILD_PATH="build" | ||
| 31 | METALAYERS="meta-enea" | ||
| 32 | |||
| 33 | function usage() { | ||
| 34 | cat <<EOF | ||
| 35 | Usage: | ||
| 36 | source $(basename $BASH_SOURCE) [OPTIONS] | ||
| 37 | |||
| 38 | OPTIONS: | ||
| 39 | -b <build dir> | ||
| 40 | Build dir | ||
| 41 | default: build | ||
| 42 | |||
| 43 | -c <script name> | ||
| 44 | Script to be used for further customization | ||
| 45 | Multiple executable customization scripts could be used | ||
| 46 | The customized script must have the executable bit set in order to be used | ||
| 47 | e.g. -c meta-some-layer/scripts/conf_setup.sh | ||
| 48 | |||
| 49 | -g <url> | ||
| 50 | download mirror e.g., file:///media/downloads | ||
| 51 | default: http://linux.enea.com/${DISTRO_VERSION}/sources | ||
| 52 | |||
| 53 | -j <cores> | ||
| 54 | Number of cores to use in build. | ||
| 55 | default: all | ||
| 56 | |||
| 57 | -k <sstate dir> | ||
| 58 | Shared local sstate cache, type -k <build dir>/sstate | ||
| 59 | if you want to use private sstate cache. | ||
| 60 | |||
| 61 | -l <list of meta-layers> | ||
| 62 | List of meta-layers, e.g., -l meta-fsl-ppc,meta-enea-lwrt | ||
| 63 | default: none | ||
| 64 | |||
| 65 | -m <machine name> | ||
| 66 | Machine name (required) | ||
| 67 | |||
| 68 | -t | ||
| 69 | To be used by testing framework. | ||
| 70 | Currently add the distrodata inheritance. | ||
| 71 | -s | ||
| 72 | Non-default DISTRO to use | ||
| 73 | |||
| 74 | -h | ||
| 75 | Help - this text | ||
| 76 | EOF | ||
| 77 | } | ||
| 78 | |||
| 79 | SSTATE_MIRRORS='http://linux.enea.com/${DISTRO_VERSION}/sstate-cache/PATH' | ||
| 80 | SOURCE_MIRROR_URL='http://linux.enea.com/${DISTRO_VERSION}/sources' | ||
| 81 | |||
| 82 | while getopts ":hb:c:d:f:g:j:k:l:m:ts:" OPTION; do | ||
| 83 | case $OPTION in | ||
| 84 | b) | ||
| 85 | BUILD_PATH=$OPTARG | ||
| 86 | ;; | ||
| 87 | c) | ||
| 88 | CUSTOM_SCRIPTS=$CUSTOM_SCRIPTS" eval $PWD/$OPTARG;" | ||
| 89 | ;; | ||
| 90 | d) | ||
| 91 | # set DL_DIR. be careful when using this, as it's easy to | ||
| 92 | # introduce isseues if this dir is shared | ||
| 93 | DOWNLOAD_DLDIR=$(readlink -m $OPTARG) | ||
| 94 | ;; | ||
| 95 | g) | ||
| 96 | SOURCE_MIRROR_URL=$OPTARG | ||
| 97 | ;; | ||
| 98 | j) | ||
| 99 | NUM_CORES=$OPTARG | ||
| 100 | ;; | ||
| 101 | k) | ||
| 102 | SSTATE_DIR=$(readlink -m $OPTARG) | ||
| 103 | ;; | ||
| 104 | l) | ||
| 105 | METALAYERS="$METALAYERS,$OPTARG" | ||
| 106 | ;; | ||
| 107 | m) | ||
| 108 | MACHINE=$OPTARG | ||
| 109 | ;; | ||
| 110 | t) | ||
| 111 | TESTING_ADDITIONS=1 | ||
| 112 | ;; | ||
| 113 | s) | ||
| 114 | DISTRO=$OPTARG | ||
| 115 | ;; | ||
| 116 | h) | ||
| 117 | usage | ||
| 118 | EXITME=1 | ||
| 119 | ;; | ||
| 120 | \?) | ||
| 121 | echo "Unknown option '-$OPTARG'" | ||
| 122 | usage | ||
| 123 | EXITME=1 | ||
| 124 | ;; | ||
| 125 | esac | ||
| 126 | done | ||
| 127 | |||
| 128 | METALAYERS="$METALAYERS,meta-openembedded/meta-filesystems,meta-openembedded/meta-networking,meta-openembedded/meta-oe,meta-openembedded/meta-python" | ||
| 129 | ENEAROOT="$(pwd)" | ||
| 130 | ENEAROOT=$(readlink -f "$ENEAROOT") | ||
| 131 | |||
| 132 | if [[ ! -d $SSTATE_DIR && ! -z $SSTATE_DIR ]]; then | ||
| 133 | mkdir -p $SSTATE_DIR | ||
| 134 | if [[ $? -ne 0 ]]; then | ||
| 135 | echo "Error: Unable to create directory $SSTATE_DIR. Do you have permissions?" | ||
| 136 | EXITME=1 | ||
| 137 | fi | ||
| 138 | fi | ||
| 139 | if [[ ! -d $DOWNLOAD_DLDIR && ! -z $DOWNLOAD_DLDIR ]]; then | ||
| 140 | mkdir -p $DOWNLOAD_DLDIR | ||
| 141 | if [[ $? -ne 0 ]]; then | ||
| 142 | echo "Error: Unable to create directory $DOWNLOAD_DLDIR. Do you have permissions?" | ||
| 143 | EXITME=1 | ||
| 144 | fi | ||
| 145 | fi | ||
| 146 | |||
| 147 | if [[ -n $EXITME ]]; then | ||
| 148 | echo | ||
| 149 | elif [[ -z $BASH_VERSINFO ]]; then | ||
| 150 | echo "This script requires bash." | ||
| 151 | elif [ "$MACHINE"x = "x" -a ! -r "$BUILD_PATH/conf/local.conf" ]; then | ||
| 152 | cat <<EOF | ||
| 153 | error: When creating a new build dir, you must at least specify -m MACHINE. | ||
| 154 | |||
| 155 | Use option -h for help. | ||
| 156 | EOF | ||
| 157 | else | ||
| 158 | |||
| 159 | if ! (test -r "$BUILD_PATH/conf/local.conf"); then | ||
| 160 | LOCAL_CONF_EXISTS=1 | ||
| 161 | fi | ||
| 162 | |||
| 163 | if ! (test -r "$BUILD_PATH/conf/bblayers.conf"); then | ||
| 164 | BBLAYERS_CONF_EXISTS=1 | ||
| 165 | fi | ||
| 166 | |||
| 167 | source ./oe-init-build-env $BUILD_PATH | ||
| 168 | |||
| 169 | if [[ -n $LOCAL_CONF_EXISTS ]]; then | ||
| 170 | sed -i \ | ||
| 171 | -e "s|^#BB_NUMBER_THREADS.*|BB_NUMBER_THREADS \?= \"$NUM_CORES\"|" \ | ||
| 172 | -e "s|^#PARALLEL_MAKE.*|PARALLEL_MAKE \?= \"-j $NUM_CORES\"|" \ | ||
| 173 | -e 's|^DISTRO ?= "poky"|DISTRO ?= "enea"|' \ | ||
| 174 | conf/local.conf | ||
| 175 | echo "*** Info: Setting BB_NUMBER_THREADS to $NUM_CORES" | ||
| 176 | echo "*** Info: Setting PARALLEL_MAKE to -j$NUM_CORES" | ||
| 177 | echo "*** Info: Setting DISTRO to enea" | ||
| 178 | |||
| 179 | if [[ -n $MACHINE ]]; then | ||
| 180 | sed -i -e "s|^MACHINE.*|MACHINE = \"$MACHINE\"|" conf/local.conf | ||
| 181 | echo "*** Info: Setting MACHINE to $MACHINE" | ||
| 182 | fi | ||
| 183 | |||
| 184 | echo "SSTATE_MIRRORS ?= \"file://.* $SSTATE_MIRRORS\"" >> conf/local.conf | ||
| 185 | echo "*** Info: Setting SSTATE_MIRRORS to $SSTATE_MIRRORS" | ||
| 186 | |||
| 187 | if [[ -n $SSTATE_DIR ]]; then | ||
| 188 | sed -i -e "s|^#SSTATE_DIR ?=.*|SSTATE_DIR ?= \"$SSTATE_DIR\"|" conf/local.conf | ||
| 189 | echo "*** Info: Setting SSTATE_DIR to $SSTATE_DIR" | ||
| 190 | fi | ||
| 191 | |||
| 192 | echo "SOURCE_MIRROR_URL ?= \"$SOURCE_MIRROR_URL\"" >> conf/local.conf | ||
| 193 | echo "*** Info: Setting SOURCE_MIRROR_URL to $SOURCE_MIRROR_URL" | ||
| 194 | echo "INHERIT += \"own-mirrors\"" >> conf/local.conf | ||
| 195 | echo "*** Info: Inheriting own-mirror" | ||
| 196 | |||
| 197 | |||
| 198 | if [[ -n $TESTING_ADDITIONS ]]; then | ||
| 199 | echo "INHERIT += \"distrodata\"" >> conf/local.conf | ||
| 200 | echo "*** Info: Inheriting distrodata." | ||
| 201 | fi | ||
| 202 | |||
| 203 | echo -e '\nLICENSE_FLAGS_WHITELIST += "non-commercial"\n' >> conf/local.conf | ||
| 204 | echo "*** Info: Need to set LICENSE_FLAGS_WHITELIST for netperf" | ||
| 205 | |||
| 206 | if [[ -n $DISTRO ]]; then | ||
| 207 | sed -i -e "s|^DISTRO.*|DISTRO ?= \"$DISTRO\"|" conf/local.conf | ||
| 208 | sed -i -e 's|^PACKAGE_CLASSES ?= "package_rpm"|PACKAGE_CLASSES ?= "package_rpm package_ipk"|' conf/local.conf | ||
| 209 | echo "*** Info: Setting PACKAGE_CLASSES to ipk and rpm" | ||
| 210 | echo "*** Info: Setting DISTRO to $DISTRO " | ||
| 211 | fi | ||
| 212 | |||
| 213 | |||
| 214 | if [[ -n $DOWNLOAD_DLDIR ]]; then | ||
| 215 | sed -i -e "s|^#DL_DIR ?=.*|DL_DIR ?= \"$DOWNLOAD_DLDIR\"|" conf/local.conf | ||
| 216 | echo "*** Info: Setting DL_DIR to $DOWNLOAD_DLDIR" | ||
| 217 | fi | ||
| 218 | |||
| 219 | if [[ ""x != "${CUSTOM_SCRIPTS}"x ]]; then | ||
| 220 | echo "*** Info: Appying \"${CUSTOM_SCRIPTS}\"" | ||
| 221 | ${CUSTOM_SCRIPTS} | ||
| 222 | fi | ||
| 223 | |||
| 224 | else | ||
| 225 | echo "You already had conf/local.conf file, no modification is done." | ||
| 226 | fi | ||
| 227 | |||
| 228 | if [[ -n $BBLAYERS_CONF_EXISTS ]]; then | ||
| 229 | if [[ ""x != "${METALAYERS}"x ]]; then | ||
| 230 | for layer in $(echo $METALAYERS | tr ',' ' '); do | ||
| 231 | layer=$ENEAROOT/$layer | ||
| 232 | if [[ ! -d $layer ]]; then | ||
| 233 | echo "*** Error: There is no meta-layer called: $layer" | ||
| 234 | else | ||
| 235 | egrep "$layer " conf/bblayers.conf >/dev/null || | ||
| 236 | sed -i -e '/.*meta-yocto .*/i\'" $layer \\\\" conf/bblayers.conf | ||
| 237 | echo "*** Info: Adding $layer to bblayers.conf" | ||
| 238 | fi | ||
| 239 | done | ||
| 240 | fi | ||
| 241 | else | ||
| 242 | echo "You already had conf/bblayers.conf file, no modification is done." | ||
| 243 | fi | ||
| 244 | fi | ||
| 245 | |||
| 246 | unset BBLAYERS_CONF_EXISTS | ||
| 247 | unset BUILD_PATH | ||
| 248 | unset CUSTOM_SCRIPTS | ||
| 249 | unset DISTRO | ||
| 250 | unset DOWNLOAD_DLDIR | ||
| 251 | unset SOURCE_MIRROR_URL | ||
| 252 | unset ENEAROOT | ||
| 253 | unset EXITME | ||
| 254 | unset LOCAL_CONF_EXISTS | ||
| 255 | unset MACHINE | ||
| 256 | unset METALAYERS | ||
| 257 | unset NUM_CORES | ||
| 258 | unset SSTATE_DIR | ||
| 259 | unset SSTATE_MIRRORS | ||
| 260 | unset TESTING_ADDITIONS | ||
| 261 | unset -f usage | ||
| 262 | unset OPTERR | ||
| 263 | unset OPTIND | ||
| 264 | unset OPTION | ||
