ubuntu-build-environment-10.md 5.8 KB
Newer Older
M
mamingshuai 已提交
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
# Ubuntu Build Environment<a name="EN-US_TOPIC_0000001161257591"></a>

-   [Setting up a Ubuntu Build Environment Using a Docker Environment](#section1643363843714)
    -   [Obtaining System Source Code](#section58448331029)
    -   [Installing and Using the Docker Environment](#section22916211916)

-   [Setting up a Ubuntu Build Environment Using an Installation Package](#section25961010189)
    -   [Obtaining Standard-System Source Code](#section15424183111912)
    -   [Installing Dependent Tools](#section109262032104819)
    -   [Obtaining prebuilts](#section16453104219209)
    -   [Configuring the Node.js Environment and Obtaining the Node\_modules Dependency Package](#section133741330192119)
    -   [Installing the hc-gen Tool](#section149281248182116)


You can use either the Docker environment or installation package provided by OpenHarmony to set up a Ubuntu build environment. This section describes the two methods.

## Setting up a Ubuntu Build Environment Using a Docker Environment<a name="section1643363843714"></a>

The standard OpenHarmony system provides a Docker environment which encapsulates build tools. To use the Docker environment, perform the following steps:

1.  Obtain the system source code.
2.  Install and use the Docker environment.

### Obtaining System Source Code<a name="section58448331029"></a>

For details, see  [Source Code Acquisition](../get-code/source-code-acquisition.md).

### Installing and Using the Docker Environment<a name="section22916211916"></a>

For details, see  [Installing and Using Docker](../get-code/tool-acquisition.md).

## Setting up a Ubuntu Build Environment Using an Installation Package<a name="section25961010189"></a>

The procedure is as follows:

1.  Obtain the system source code.
2.  Install dependent tools.
3.  Obtain prebuilts.
4.  Configure the Node.js environment and obtain the Node\_modules dependency package.
5.  Install the hc-gen tool.

### Obtaining Standard-System Source Code<a name="section15424183111912"></a>

For details, see  [Source Code Acquisition](../get-code/source-code-acquisition.md).

### Installing Dependent Tools<a name="section109262032104819"></a>

The installation command is as follows:

```
X
xiaofan 已提交
51
sudo apt-get install binutils git-core git-lfs gnupg flex bison gperf build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z-dev ccache libgl1-mesa-dev libxml2-utils xsltproc unzip m4
M
mamingshuai 已提交
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
```

### Obtaining prebuilts<a name="section16453104219209"></a>

1.  Go to the OpenHarmony working directory.

    ```
    cd OpenHarmony
    ```

2.  Download the script.

    ```
    curl https://gitee.com/landwind/script-tools/raw/master/Shell/OpenHarmony/OpenHarmony_2.0_canary_prebuilts_download.sh >./prebuilts_download.sh
    ```

3.  Download and decompress the prebuilts package in a specified directory.

    ```
    bash ./prebuilts_download.sh
    ```

    By default, binary files are stored in the  **OpenHarmony\_2.0\_canary\_prebuilts**  directory, which is in the same directory as  **OpenHarmony**. To change the storage path, change the value of  **bin\_dir**  in  **prebuilts\_download.sh**.

4.  Return to the previous directory.

    ```
    cd -
    ```


### Configuring the Node.js Environment and Obtaining the Node\_modules Dependency Package<a name="section133741330192119"></a>

To build the JS framework, you need to download and configure Node.js on a Linux server. The procedure is as follows:

1.  Download Node.js on a Linux server.

    ```
    mkdir -p OpenHarmony/prebuilts/build-tools/common/nodejs                                # Create the nodejs directory.
    cd OpenHarmony/prebuilts/build-tools/common/nodejs                                      # Go to the nodejs directory.
    wget --no-check-certificate https://nodejs.org/download/release/v12.18.4/node-v12.18.4-linux-x64.tar.gz # Download the Node.js package.
    ```

2.  Decompress the Node.js package and configure the Node.js environment.

    ```
    tar -zxvf node-v12.18.4-linux-x64.tar.gz                                                      # Decompress the Node.js package.
    echo "export PATH=`pwd`/node-v12.18.4-linux-x64/bin:${PATH}" >> ~/.bashrc;source ~/.bashrc    # Set a Node.js environment variable.
    cd -                                                                                          # Return to the previous directory.
    ```

3.  Go to the  **third\_party/jsframework**  directory of the OpenHarmony code and download the  **node\_modules**  package.

    ```
    cd OpenHarmony/third_party/jsframework                  # Go to the jsframework directory.
    npm install                                             # Download the node_modules package.
    cd -                                                    # Return to the previous directory.
    ```

4.  Store the  **node\_modules**  package in the  **prebuilts/build-tools/common/js-framework**  directory of the OpenHarmony code.

    ```
    mkdir -p OpenHarmony/prebuilts/build-tools/common/js-framework          # Create the js-framework directory.
    cp -rp OpenHarmony/third_party/jsframework/node_modules OpenHarmony/prebuilts/build-tools/common/js-framework/
    ```


### Installing the hc-gen Tool<a name="section149281248182116"></a>

hc-gen is used to compile the driver. To install hc-gen, perform the following steps:

1.  Start a Linux server.
2.  Download  [hc-gen](https://repo.huaweicloud.com/harmonyos/compiler/hc-gen/0.65/linux/hc-gen-0.65-linux.tar).
3.  Decompress the hc-gen installation package to  **\~/hc-gen**  on the Linux server.

    ```
    tar -xvf hc-gen-0.65-linux.tar -C ~/
    ```

4.  Set an environment variable.

    ```
    vim ~/.bashrc
    ```

    Copy the following command to the last line of the  **.bashrc**  file, save the file, and exit.

    ```
    export PATH=~/hc-gen:$PATH
    ```

5.  Validate the environment variable.

    ```
    source ~/.bashrc
    ```