1.獲取 系統 位數
ARCH =x64
ifeq ($(shell getconf LONG_BIT), 32)
ARCH = x86
endif
all:
ifeq ($(ARCH),x64)
echo "x64"
else
echo "x86"
endif
備註 這裏 的 標紅部分不能有縮進,否則 會引起、
ifeq (x64, x64)
/bin/sh: -c: line 0: syntax error near unexpected token `x64,'
/bin/sh: -c: line 0: `ifeq (x64, x64)'
原因
Makefile中,當 ifeq, else 和 endif 沒有縮進時,make會正確識別它們,將其作爲分支選擇的標識
當 ifeq, else 和 endif 有縮進時,make將它們當做普通的shell script
參考http://blog.csdn.net/yasi_xi/article/details/39155529 感謝博主
2. make 遍歷 目錄
有時候,在開發目錄,依賴的 動態庫 是 放在不同的 子目錄下,防止混淆,便於管理,但發佈到現網時,又希望這寫依賴庫能放到同一個 目錄lib下,
在makefile 尾部 增加 下述,可以遍歷 依賴庫 子目錄,並拷貝其 lib.so, 注,要求 所有的 依賴庫子目錄下都有 lib子目錄
DEP_DIRS := $(shell ls ./dep/)
DEP_LIB_CP:
for dir_dep in $(DEP_DIRS);\
do \
cp -f ./dep/$$dir_dep/lib/lib* ./lib/; \
done \
3.make 傳參數 和多個condition
make args=value
舉例
ifeq ($(VV),suse32) echo $(VV) else ifeq ($(VV), suse64) echo $(VV) else echo $(VV) endif endif
make VV=suse32 輸出suse32
make VV=suse64 輸出suse64
make VV=other 輸出other