前言
今天我們要來繼續討論 Makefile,
我們來學習如何定義自己的變數。
我們的今天的 Makefile
RM=rm
T=touch
otherfiles = myfile myotherfile
buildfiles = myfile2
all: $(buildfiles)
myfile:
$(T) myfile
myotherfile:
$(T) myotherfile
myfile2: $(otherfiles)
cat myfile myotherfile > myfile2
clean:
$(RM) $(buildfiles)
$(RM) $(otherfiles)
說明 – 變數
在這份檔案中,我們定義了四個變數,
其中有兩個是命令相關,另外兩個是檔案相關。
命令相關的變數
檔案相關的變數
- otherfiles = myfile myotherfile
- buildfiles = myfile2
說明 – 目標方法 (target)
我們在這份檔案一共定義了五種目標
- all: 1. 完成「所有 buildfiles」
- myfile: 1. touch myfile
- myotherfile: 1. touch 「所有 myotherfile」
- myfile2: 1. 前提要先完成 「所有 otherfiles」 2. 做 cat myfile myotherfile > myfile2
- clean: 清除所有檔案
我們這邊特別留意 myfile2 的寫法
myfile2: $(otherfiles)
cat myfile myotherfile > myfile2
「:(冒號)」後面只要加上 $(otherfiles) 或任何的 target,
就表示我們要先完成目標的 target 做為「前置步驟」,
所以像這邊的意思就是,先完成 $(otherfiles),再去做 myfile2
Reference
⭐C++ 基礎用法 相關文章整理⭐: |
---|
1. | 【C++】C++ compile 程式碼 使用 c++ 11 與使用相關的 package |
2. | 【C++】C/C++ 顯示資料的類別 (type) sample code (內含範例程式碼) print C data type, cout C++ data type, get variable type in c++ |
3. | 【C++】C++ 複製 2D array的方法 copy 2d array memcpy sample code (內含範例程式碼) |
⭐Modern C++ ⭐: |
| |
⭐C++ 字串處理相關文章整理⭐: |
1. | 【C++】字串 char string stringstream 相關用法總整理 (內含範例程式碼) 與利用 sprinf, snprinf assign 值的方法 |
2. | 【C++】字串 char string stringstream 「轉換」用法總整理 (內含範例程式碼) |
3. | 【C】printf, fprintf, sprintf, snprintf 相關用法總整理 (內含範例程式碼) |
4. | 【C++】C++ String 用法 連接兩個 String c++ string concat |
⭐C++ 系統偵測相關文章整理⭐: |
1. | 【C++】C++ 利用 dirent.h 計算資料夾的檔案數量 count files sample code (內含範例程式碼) |
2. | 【C++】C++ inotify sample code 偵測指定路徑底下的文件變化 (內有範例程式碼) |
⭐C++ OpenCV 相關文章整理⭐: |
1. | 【OpenCV】c++ OpenCV – 在 ubuntu 上第一次執行 OpenCV 程式 sample code (內含範例程式碼) |
2. | 【OpenCV】c++ OpenCV - 在圖片上寫上文字 cv::putText sample code (內含範例程式碼) |
3. | 【OpenCV】c++ OpenCV - cv::Rect 矩形用法與相關功能函數 sample code (內含範例程式碼) |
4. | 【OpenCV】c++ OpenCV - OpenCV 中的純量 定義顏色 cv::Scalar(255,255,255) color sample code (內含範例程式碼) |
5. | 【OpenCV】用 C++ 計算 iou 的方法 與網路算法常見錯誤(內附範例程式碼) sample code |
⭐C++ Makefile 相關文章整理⭐: |
1. | 【C++ Makefile】- 1 / 嘗試撰寫自己的第一份 Makefile |
2. | 【C++ Makefile】- 2 / 新增自己的變數 |
3. | 【C++ Makefile】- 3 / Makefile 常用變數 -「$@」, 「$^」 |
4. | 【C++ Makefile】- 4 / Makefile 常用 fake target -「.PHONY」
|
5. | 【C++ Makefile】- 5 / Makefile 內建變數 -「$@」, 「$^」, 「$<」, 「$* 」,「$? 」
|
⭐【喜歡我的文章嗎? 歡迎幫我按讚~ 讓基金會請創作者喝一杯咖啡! 】
如果喜歡我的文章,請幫我在下方【 |
---|