# Ubuntu & Makefile ## Week 17 ---- ## Introduction + [Linux](https://github.com/torvalds/linux) 是一種作業系統 + [Debian](https://www.debian.org/) 是一種 Linux 的發行版 + 其他還有 [Arch](https://archlinux.org/), [OpenSUSE](https://www.opensuse.org/), [Fedora](https://fedoraproject.org/), Android 等 + [Ubuntu](https://ubuntu.com/) 則是基於 Debian 的另外一種發行版 ---- ## How To Linux + Real Machine or Dual OS + Virtual Machine + Docker Container + Windows Subsystem Linux (WSL) ---- ## Virtual Machine + [Oracle VirtualBox](https://www.virtualbox.org/) + VMware Playstation ---- ## VirtualBox Setup + 前往[下載頁面](https://www.virtualbox.org/wiki/Downloads) + 點選 Windows Hosts 下載安裝檔 ![](https://hackmd.io/_uploads/H1VAi01ch.png) --- # Ubuntu Setup ---- ## Download + Ubuntu 分成 Desktop 與 Server 兩種 + Desktop 是有 GUI 桌面環境的 + Server 則是完全文字介面的 + 初學入門推薦使用 Desktop 版 ---- ## Create VM 1. 打開 VirtualBox 後點選新增 2. 輸入 VM 名稱並選取 Ubuntu 的 `.iso` 檔 3. 記憶體建議設定到 4 GB 以上 4. 設定好後點選完成 > 啟動 ---- ## Installation 1. 鍵盤配置推薦選擇 English (US) 2. Install third-party software ... 建議勾選 + 尤其是裝在筆電上的話 3. 選擇 Erase disk and install Ubuntu 4. 時區選 Taipei ---- ## Hint 如果安裝過程中游標不見了 可以點擊「**右邊的 Ctrl 鍵**」把游標叫出來 ---- ## User Information + Full Name 是顯示名稱 + Username 是登入名稱 + Computer Name 為會顯示在 Terminal 上 ![](https://hackmd.io/_uploads/B1Gt0Je53.png) ---- ## Done! ![](https://hackmd.io/_uploads/B1zE-Ggc3.png) ---- ## Environment + Ubuntu 已經內建 Python3 + Ubuntu 22.04 內建 Python 3.10 + 透過 `apt` 指令安裝各種開發工具 + `gcc`, `make`, `python3-pip` + 下載 `.deb` 安裝,例如 [VSCode](https://code.visualstudio.com/download) + 可以使用 `apt install -f` 安裝 + 也有透過 Shell Script 安裝的 + 例如 [Conda](https://docs.conda.io/en/latest/miniconda.html) 和 [Docker](https://www.docker.com/) --- # Makefile ---- ## Introduction + 用在 C 語言管理相依性的自動化建置的工具 + 但設計上十分彈性,很多場景都適用 + 1976 年由 Stuart Feldman 在 Bell Labs 製作 ---- ## Setup + 首先需要安裝 `make` 工具 ```shell= sudo apt update sudo apt install make ``` ---- ## Basic Usage + 基本上 Makefile 就是一個腳本選擇器 + 縮排一定要是 Tab 不能是空格 + 可以按 `Alt + 九宮格 9` 快速輸入 Tab ```makefile all: main.c lib.o gcc -o main main.c lib.o lib.o: lib.c gcc -c lib.c ``` ---- ## Basic Command + 預設檔名為 `Makefile` 或 `makefile` + GNU Make 則會優先使用 `GNUmakefile` + 也可以透過 `make -f` 指定檔名 + 自訂 Makefile 的副檔名為 `.make` 或 `.mk` ---- ## Basic Concept + Makefile 主要由目標、依賴與命令組成 + 必須先完成依賴的目標,才會執行命令 + 會自動分析是否需要重新編譯 ---- ## Target Selection Makefile 不只可以做編譯,也可當任務選擇器來用 ```makefile= PrepareData: python download.py Training: python train.py Validation: python eval.py ``` Shell 的 Autocomplete 會自動偵測目標名稱
{"slideOptions":"{\"transition\":\"slide\"}","description":"地獄貓旅行團第 23 週心得分享","title":"Week 17 - Ubuntu & Makefile","contributors":"[{\"id\":\"c7cbb212-2c41-4dfa-8d85-f8e7fa769bf1\",\"add\":2853,\"del\":176}]"}
    138 views
   Owned this note