summaryrefslogtreecommitdiffstats
path: root/enea-init-build-env
blob: 2e53f8e69f5129e81a946c7ca7f42bf1d0b352c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/bin/bash
if [ "$_" = "$0" ]; then
    echo "Error: This script needs to be sourced."
    echo "Please run as 'source $0'."
    exit
fi

# always unset these in case something goes wrong in the previous run
unset OPTERR OPTIND OPTION MACHINE EXITME SSTATE_DIR DOWNLOAD_DLDIR METALAYERS
unset DOWNLOAD_MIRRORS LOCAL_CONF_EXISTS BBLAYERS_CONF_EXISTS 

NUM_CORES=$(grep -c processor /proc/cpuinfo || echo 2)
BUILD_PATH="build"
METALAYERS="meta-enea"

function usage() {
cat <<EOF
Usage:
    source $(basename $BASH_SOURCE) [OPTIONS]

OPTIONS:
    -b <build dir>
      Build dir
      default: build

    -g <url>
      download mirror e.g., file:///media/downloads
      default: http://linux.enea.com

    -j <cores>
      Number of cores to use in build.
      default: all

    -k <sstate dir>
      Shared local sstate cache, type -k <build dir>/sstate
      if you want to use private sstate cache.

    -l <list of meta-layers>
      List of meta-layers, e.g., -l meta-fsl-ppc,meta-enea-lwrt
      default: none

    -m <machine name>
      Machine name (required)

    -h
      Help - this text
EOF
}

DOWNLOAD_MIRRORS='http://linux.enea.com/${DISTRO_VERSION}/sources/'
SSTATE_MIRRORS='http://linux.enea.com/${DISTRO_VERSION}/sstate-cache/PATH'

while getopts ":hb:d:f:g:j:k:l:m:t:" OPTION; do
    case $OPTION in
        b)
            BUILD_PATH=$OPTARG
            ;;
        d)
            # set DL_DIR. be careful when using this, as it's easy to
            # introduce isseues if this dir is shared
            DOWNLOAD_DLDIR=$(readlink -m $OPTARG)
            ;;
        g)
            DOWNLOAD_MIRRORS=$OPTARG
            ;;
        j)
            NUM_CORES=$OPTARG
            ;;
        k)
            SSTATE_DIR=$(readlink -m $OPTARG)
            ;;
        l)
            METALAYERS="$METALAYERS,$OPTARG"
            ;;
        m)
            MACHINE=$OPTARG
            ;;
        h)
            usage
            EXITME=1
            ;;
        \?)
            echo "Unknown option '-$OPTARG'"
            usage
            EXITME=1
            ;;
    esac
done

ENEAROOT="$(pwd)"
ENEAROOT=$(readlink -f "$ENEAROOT")

if [[ ! -d $SSTATE_DIR && ! -z $SSTATE_DIR ]]; then
    mkdir -p $SSTATE_DIR
    if [[ $? -ne 0 ]]; then
        echo "Error: Unable to create directory $SSTATE_DIR. Do you have permissions?"
        EXITME=1
    fi
fi
if [[ ! -d $DOWNLOAD_DLDIR && ! -z $DOWNLOAD_DLDIR ]]; then
    mkdir -p $DOWNLOAD_DLDIR
    if [[ $? -ne 0 ]]; then
        echo "Error: Unable to create directory $DOWNLOAD_DLDIR. Do you have permissions?"
        EXITME=1
    fi
fi

if [[ -n $EXITME ]]; then
    echo
elif [[ -z $BASH_VERSINFO ]]; then
    echo "This script requires bash."
elif [ "$MACHINE"x = "x" -a ! -r "$BUILD_PATH/conf/local.conf" ]; then
cat <<EOF
error: When creating a new build dir, you must at least specify -m MACHINE.

Use option -h for help.
EOF
else

    if ! (test -r "$BUILD_PATH/conf/local.conf"); then
        LOCAL_CONF_EXISTS=1
    fi

    if ! (test -r "$BUILD_PATH/conf/bblayers.conf"); then
        BBLAYERS_CONF_EXISTS=1
    fi

    source ./oe-init-build-env $BUILD_PATH

    if [[ -n $LOCAL_CONF_EXISTS ]]; then
        sed -i \
            -e "s|^#BB_NUMBER_THREADS.*|BB_NUMBER_THREADS \?= \"$NUM_CORES\"|" \
            -e "s|^#PARALLEL_MAKE.*|PARALLEL_MAKE \?= \"-j $NUM_CORES\"|" \
            -e 's|^DISTRO ?= "poky"|DISTRO ?= "enea"|' \
            conf/local.conf
        echo "*** Info: Setting BB_NUMBER_THREADS to $NUM_CORES"
        echo "*** Info: Setting PARALLEL_MAKE to -j$NUM_CORES"
        echo "*** Info: Setting DISTRO to enea"
        
        if [[ -n $MACHINE ]]; then
            sed -i -e "s|^MACHINE.*|MACHINE = \"$MACHINE\"|" conf/local.conf
            echo "*** Info: Setting MACHINE to $MACHINE"
        fi
        
        echo "SSTATE_MIRRORS ?= \"file://.* $SSTATE_MIRRORS\"" >> conf/local.conf
        echo "*** Info: Setting SSTATE_MIRRORS to http://linux.enea.com"

        if [[ -n $SSTATE_DIR ]]; then
            sed -i -e "s|^#SSTATE_DIR ?=.*|SSTATE_DIR ?= \"$SSTATE_DIR\"|" conf/local.conf
            echo "*** Info: Setting SSTATE_DIR to $SSTATE_DIR"
        fi

        sed -i -e 's|^PACKAGE_CLASSES ?= "package_rpm"|PACKAGE_CLASSES ?= "package_ipk"|' conf/local.conf
        echo "*** Info: Setting PACKAGE_CLASSES to ipk"

        echo "SOURCE_MIRROR_URL ?= \"$DOWNLOAD_MIRRORS\"" >> conf/local.conf
        echo "INHERIT += \"own-mirrors\"" >> conf/local.conf
        echo "*** Info: Setting SOURCE_MIRROR_URL to http://linux.enea.com"

        if [[ -n $DOWNLOAD_DLDIR ]]; then
            sed -i -e "s|^#DL_DIR ?=.*|DL_DIR ?= \"$DOWNLOAD_DLDIR\"|" conf/local.conf
            echo "*** Info: Setting DL_DIR to $DOWNLOAD_DLDIR"
        fi
    else
        echo "You already had conf/local.conf file, no modification is done."
    fi

    if [[ -n $BBLAYERS_CONF_EXISTS ]]; then
        if [[ ""x != "${METALAYERS}"x ]]; then
            for layer in $(echo $METALAYERS | tr ',' ' '); do
                layer=$ENEAROOT/$layer
                if [[ ! -d $layer ]]; then
                    echo "*** Error: There is no meta-layer called: $layer"
                else
                    egrep "$layer " conf/bblayers.conf >/dev/null ||
                    sed -i -e '/.*meta-yocto .*/i\'"  $layer \\\\" conf/bblayers.conf
                    echo "*** Info: Adding $layer to bblayers.conf"
                fi
            done
        fi
    else
        echo "You already had conf/bblayers.conf file, no modification is done."
    fi
fi

unset OPTERR OPTIND OPTION MACHINE EXITME SSTATE_DIR DOWNLOAD_DLDIR METALAYERS
unset DOWNLOAD_MIRRORS LOCAL_CONF_EXISTS BBLAYERS_CONF_EXISTS SSTATE_MIRRORS