summaryrefslogtreecommitdiff
path: root/package/build.windows-64
blob: 5999e2e9639cab8f489bb3b73dba9cdcd94e016d (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
#!/bin/sh -xe

BUILD_ARCH=x86_64
BUILD_PACKAGE=emulator-common-lib
BUILD_WS=win32
META_MF=meta.mf
TMP_DIR="$SRCDIR/data"
OS_COMMON_DIR="$ROOTDIR/os-common"
BIN_DIR="$SRCDIR/package/${BUILD_PACKAGE}.package.${TARGET_OS}/data/tools/emulator/bin/"

clean()
{
    rm -rf $SRCDIR/*.zip
    rm -rf $SRCDIR/*.tar.gz
}

prepare()
{
    if [ ! -d $TMP_DIR ]
    then
        echo "make temp directory for emulator install : ( $TMP_DIR )"
        mkdir $TMP_DIR
    fi
}

trim_string()
{
    trimmed=$1
    trimmed=${trimmed%% }
    trimmed=${trimmed## }

    echo "$trimmed"
}

contains() {
    string="$1"
    substring="$2"
    if test "${string#*$substring}" != "$string"
    then
        echo $substring is in $string
    else
        echo $substring is not in $string
        exit 1
    fi
}

# $1: mf file path (e.g. xxx.mf)
# $2: original binary/library file path (e.g. xxx.dylib)
check_file()
{
    # check arch from mf file
    ARCHS=$(cat $1 | grep "Arch:" | cut -d ':' -f2)
    contains "$ARCHS" $BUILD_ARCH

    # check the library or the binary to support build_architecture
    if [ "$EXTENSION" = "dll" ] && [ "$EXTENSION" = "exe" ] ;then
        ARCH_RESULT=$(file $2)
        ARCH_OK=0
        if test "${ARCH_RESULT#*"64-bit"}" != "$ARCH_RESULT"
        then
            echo $ARCH_RESULT is in 64-bit
            ARCH_OK=1
        elif test "${ARCH_RESULT#*"32-bit"}" != "$ARCH_RESULT"
        then
            echo $ARCH_RESULT is in 32-bit
            ARCH_OK=1
        elif test "${ARCH_RESULT#*"PE32"}" != "$ARCH_RESULT"
        then
            echo $ARCH_RESULT is in PE32
            ARCH_OK=1
        elif test "${ARCH_OK}" == "0"
        then
            echo $2 is no architecture.
            exit 1
        fi
    fi

    # check OS
    OSES=$(cat $i | grep "OS:" | cut -d ':' -f2)
    contains "$OSES" $TARGET_OS

    # copy file if validation passed.
    echo "move $2 to $TMP_DIR"
    mv -f "$2" $TMP_DIR
}

# $1: root directory for traversing
traverse_manifest()
{
    for i in $(find $1 -iname '*.mf')
    do
        # skip if filename is meta.mf it's used for packaging dev
        if [ "$META_MF" = $(basename $i) ];then
            echo "skip $i"
            continue
        fi

        TEMP_PACKAGE=$(cat "$i" | grep "Package:" | cut -d ':' -f2)
        PACKAGES=$(trim_string "$(echo $TEMP_PACKAGE | tr "," "\n")")
        TEMP_EXTENSION=$(cat "$i" | grep "Extension:" | cut -d ':' -f2)
        EXTENSIONS=$(trim_string "$(echo $TEMP_EXTENSION | tr "," "\n")")
        BUILD_OK=0

        for PACKAGE in $PACKAGES
        do
            if [ ! -e $PACKAGE ] && [ "$PACKAGE" = "$BUILD_PACKAGE" ];then
                # BUILD_OK=1 means this manifest file support current build project
                BUILD_OK=1

                # find origin file(s) from manifest file
                for EXTENSION in $EXTENSIONS
                do
                    echo found \"$PACKAGE\" in $i
                    if [ ! -e $EXTENSION ];then
                        FILE=${i%%.mf}.$EXTENSION
                    else
                        FILE=${i%%.mf}
                    fi
                    if [ ! -f "$FILE" ] ;then
                        echo $FILE does not exist.
                        exit 1
                    fi
                    check_file "$i" "$FILE"
                done
            fi
        done
        if [ $BUILD_OK -eq 0 ]
        then
            echo "cannot find $BUILD_PACKAGE in $i skipped."
        fi
    done
}

build()
{
    prepare
    echo "traverse_manifest $OS_COMMON_DIR"
    traverse_manifest $OS_COMMON_DIR

    echo "traverse_manifest $ROOTDIR/$TARGET_OS"
    traverse_manifest $ROOTDIR/$TARGET_OS
}

install()
{
    cd $TMP_DIR

    # make directory structure
    mkdir -p $BIN_DIR

    # move all files in temp directory into pacakage directory
    mv * $BIN_DIR/
}

[ "$1" = "clean" ] && clean
[ "$1" = "build" ] && build
[ "$1" = "install" ] && install

echo "success"