aboutsummaryrefslogtreecommitdiffstats
path: root/cppMakefile/!readme.asciidoc
blob: da89fc413e8187dff01df183b82965c03710501e (plain) (blame)
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



.Description

這是一個簡單的 *GNU makefile for 'C++' project*
類似AutoTool等工具, 不過又更簡化了, 操作方法是利用GNUMakefile裡的targets
當作指令, 生出一個targets檔, 以後鍵入 `make all` 就會自動把所有targets都
編譯出來.

.Commands

* `make init` +
初始化, 設定完之後所在位置會多幾個資料夾如下

** 'bin/' 放編譯出來的執行檔
** 'dep/' dependency相關資料, 內容會自動生成, 不用理它
** 'inc/' 自定義的include file放置位置
** 'src/' source code放置位置
** 'obj/' obj file放置位置, 會自動生成, 不用理它

* `make new NAME=<name> [OBJS=<OBJ_FILES> LIBS=<LIBRARIES>]` +
新增一個target, 須給定目標名 , 並且此Makefile會假定 `main() { ... }` 放在
'src/<name>.cpp' 而最終輸出會是 'bin/<name>' . +
關於 'OBJS=' 與 'LIBS=' 參考下面說明

* `make add NAME=<name> [OBJS=<OBJ_FILES> LIBS=<LIBRARIES>]` +
針對target為 '<name>' 的目標新增需要的 '<OBJ_FILES>' , 與 '<LIBRARIES>'. 
'<LIBRARIES>' 的部份會用 `pkg-config` 去解讀, 例如 '<LIBRARIES>' 為
'opencv lapackpp' 則link時會被以下指令展開 +
`pkg-config --libs opencv lapackpp` +
而 '<OBJ_FILES>' 的部份則只需要給 *name* 就好, 不需要有完整個 pathname, 例如
例如 '<OBJ_FILES>' 是 'a b c' 則此makefile會視為

** source code: 'src/a.cpp src/b.cpp src/c.cpp'
** obj file: 'obj/a.o obj/b.o obj/c.o'

* `make del NAME=<name> [OBJS=<OBJ_FILES> LIBS=<LIBRARIES>]` +
與 add相反, 嘗試將指定target所需的'<OBJ_FILES>'和'<LIBRARIES>'移除

* `make clean` +
將 'bin/*' 'dep/*' 'obj/*' 清除, 有時候覺得dependency怪怪的
時可以嘗試執行此指令

[NOTE]
其中整個project到底有哪些obj file會完全依照 *src/* 裡面有哪些 `.cpp` 檔決定

===== GNUMakefile

就是一個 Makefile, 不過裡面有些東西是 `GNU-make` only的

===== GNUMakefile.dependency.bash

產生 dependency檔用的