海思3518e mpp2/sample/venc makefile简析

最近因为需要,将mpp2/sample/venc下的makefile进行了简单的分析,具体过程如下。

sdk版本:Hi3518E_V100R001C01SPC081

mpp2的目录结构如下:

mpp2
|-----component
|-----extdrv
|-----include
|-----lib
|-----sample
       |-----audio
       |-----common
       |-----hifb
       |-----iq
       |-----ive
       |-----regin
       |-----tde
       |-----vda
       |-----venc
             |-----***makefile***
             |-----sample_venc.c
       |-----vio
       |-----***makefile.param***    
 |-----tools
 |-----***makefile.param***       

主要分析的三个文件:
1. mpp2下的makefile.param
2. mpp2/sample下的makefile.param
3. mpp2/sample/venc下的makefile

开始分析
mpp2/sample/venc下的makefile如下:

# Hisilicon Hi3516 sample Makefile

include ../Makefile.param   # 引用 Makefile.param ,将其加载进来
#ifeq ($(SAMPLE_PARAM_FILE), )
# SAMPLE_PARAM_FILE:=../Makefile.param
# include $(SAMPLE_PARAM_FILE)
#endif

# target source
SRC  := $(wildcard *.c)  #通配符在变量中展开
OBJ  := $(SRC:%.c=%.o)

TARGET := $(OBJ:%.o=%)
.PHONY : clean all

all: $(TARGET)

MPI_LIBS := $(REL_LIB)/libmpi.a

$(TARGET):%:%.o $(COMM_OBJ)
    $(CC) $(CFLAGS) -lpthread -lm -o $@ $^ $(MPI_LIBS) $(AUDIO_LIBA) $(SENSOR_LIBS)

clean:
    @rm -f $(TARGET)
    @rm -f $(OBJ)
    @rm -f $(COMM_OBJ)

cleanstream:
    @rm -f *.h264
    @rm -f *.jpg
    @rm -f *.mjp
    @rm -f *.mp4

其中以‘#’开头的为注释语句,可以忽略,则第一句话便是

include ../Makefile.param 

这个代表将上层目录里面的makefile.param文件包含进来,或者说将上层的makefile.param原封不动的加载到本makefile中。

因此,makefile会先将上层目录makefile.param内容加载,并先执行makefile.param里面的内容。
/mpp2/sample/Makefile.param 如下:

# Hisilicon Hi3518 sample Makefile.param

ifeq ($(PARAM_FILE), )
     PARAM_FILE:=../../Makefile.param
     include $(PARAM_FILE)
endif

################# select sensor type for your sample ####################
#SENSOR_TYPE ?= APTINA_AR0130_DC_720P_30FPS
#SENSOR_TYPE ?= SONY_ICX692_DC_720P_30FPS
#SENSOR_TYPE ?= SONY_IMX104_DC_720P_30FPS
#SENSOR_TYPE ?= SONY_IMX138_DC_720P_30FPS
#SENSOR_TYPE ?= SONY_IMX122_DC_1080P_30FPS
#SENSOR_TYPE ?= SONY_IMX236_DC_1080P_30FPS
#SENSOR_TYPE ?= APTINA_9M034_DC_720P_30FPS
#SENSOR_TYPE ?= APTINA_MT9P006_DC_1080P_30FPS
SENSOR_TYPE ?= OMNI_OV9712_DC_720P_30FPS  #sensor的类型
#SENSOR_TYPE ?= OMNI_OV2710_DC_1080P_30FPS
#SENSOR_TYPE ?= SOI_H22_DC_720P_30FPS
#SENSOR_TYPE ?= HIMAX_1375_DC_720P_30FPS
#SENSOR_TYPE ?= APTINA_AR0330_DC_1080P_30FPS
#SENSOR_TYPE ?= PIXELPLUS_3100K_DC_720P_30FPS

SENSOR_LIBS := $(REL_LIB)/libisp.a#/root/hi3518/mpp2/lib/libisp.a

ifeq ($(SENSOR_TYPE), APTINA_AR0130_DC_720P_30FPS)
    SENSOR_LIBS += $(REL_LIB)/libsns_ar0130_720p.a
endif

ifeq ($(SENSOR_TYPE), PANASONIC_MN34031_DC_720P_30FPS)
    SENSOR_LIBS += $(REL_LIB)/libsns_mn34031_720p.a
endif

ifeq ($(SENSOR_TYPE), SONY_ICX692_DC_720P_30FPS)
    SENSOR_LIBS += $(REL_LIB)/libsns_icx692.a
endif

ifeq ($(SENSOR_TYPE), SONY_IMX104_DC_720P_30FPS)
    SENSOR_LIBS += $(REL_LIB)/libsns_imx104.a
endif

ifeq ($(SENSOR_TYPE), SONY_IMX138_DC_720P_30FPS)
    SENSOR_LIBS += $(REL_LIB)/libsns_imx138.a
endif

ifeq ($(SENSOR_TYPE), APTINA_9M034_DC_720P_30FPS)
    SENSOR_LIBS += $(REL_LIB)/libsns_9m034.a
endif

ifeq ($(SENSOR_TYPE), OMNI_OV9712_DC_720P_30FPS)   #SENSOR_LIBS /root/hi3518/mpp2/lib/libisp.a /root/hi3518/mpp2/lib/libsns_ov9712.a
    SENSOR_LIBS += $(REL_LIB)/libsns_ov9712.a  
endif

ifeq ($(SENSOR_TYPE), OMNI_OV2710_DC_1080P_30FPS)
    SENSOR_LIBS += $(REL_LIB)/libsns_ov2710.a
endif

ifeq ($(SENSOR_TYPE), SOI_H22_DC_720P_30FPS)
    SENSOR_LIBS += $(REL_LIB)/libsns_soih22.a
endif

ifeq ($(SENSOR_TYPE), HIMAX_1375_DC_720P_30FPS)
    SENSOR_LIBS += $(REL_LIB)/libsns_himax1375.a
endif

ifeq ($(SENSOR_TYPE), SONY_IMX122_DC_1080P_30FPS)
    SENSOR_LIBS += $(REL_LIB)/libsns_imx122.a
endif

ifeq ($(SENSOR_TYPE), APTINA_MT9P006_DC_1080P_30FPS)
    SENSOR_LIBS += $(REL_LIB)/libsns_mt9p006.a
endif

ifeq ($(SENSOR_TYPE), APTINA_AR0330_DC_1080P_30FPS)
    SENSOR_LIBS += $(REL_LIB)/libsns_ar0330_1080p.a
endif

ifeq ($(SENSOR_TYPE), SONY_IMX236_DC_1080P_30FPS)
    SENSOR_LIBS += $(REL_LIB)/libsns_imx236.a
endif

ifeq ($(SENSOR_TYPE), PIXELPLUS_3100K_DC_720P_30FPS)
    SENSOR_LIBS += $(REL_LIB)/libsns_po3100k.a
endif

#########################################################################
COMMON_DIR:=$(PWD)/../common
                                #/root/hi3518/mpp2/sample/venc/../common
INC_FLAGS := -I$(COMMON_DIR)
  #-I/root/hi3518/mpp2/sample/venc/../common/
INC_FLAGS += -I$(REL_INC)
#-I/root/hi3518/mpp2/include
INC_FLAGS += -I$(MPP_PATH)/component/acodec
#-I/root/hi3518/mpp2/component/acodec
ifeq ($(MPP_BUILD), y)
INC_FLAGS += -I$(MPP_PATH)/$(EXTDRV)/tw2865
else
    INC_FLAGS += -I$(MPP_PATH)/extdrv/tw2865   #-I/root/hi3518/mpp2/extdrv/tw2865 
endif

ifeq ($(CONFIG_ISP), y)  #在上文中定义为n
ISP_VERSION := ISP_V1
else
ISP_VERSION := ISP_V2
SENSOR_LIBS += $(REL_LIB)/lib_hiae.a
SENSOR_LIBS += $(REL_LIB)/lib_hiawb.a
SENSOR_LIBS += $(REL_LIB)/lib_hiaf.a
endif

CFLAGS := -Wall -g $(INC_FLAGS) -D$(HIARCH) -DHICHIP=$(HICHIP) -DSENSOR_TYPE=$(SENSOR_TYPE) -D$(HIDBG) -D$(HI_FPGA) -lpthread -lm -D$(ISP_VERSION)

COMM_SRC := $(wildcard $(COMMON_DIR)/*.c)
COMM_OBJ := $(COMM_SRC:%.c=%.o)

其第一条语句

ifeq ($(PARAM_FILE), )
     PARAM_FILE:=../../Makefile.param
     include $(PARAM_FILE)
endif

表示如果PARAM_FILE这个变量为空,则定义其为../../Makefile.param 即mpp2/目录下的Makefile.param
并将其加载进来,因为PARAM_FILE这个变量再之前并没有定义,则为空,所以需要将上上层的Makefile.param即mpp2目录下的Makefile.param加载进来。

如下:

# Makefile.param 
# Only global variable should be defined here.
# All the variables must be used as "export" and "?=".
# Otherwise, there will be some errors, when Makefile.param is nested.

# Use this file as the following sample
# ifeq ($(PARAM_FILE), )
# PARAM_FILE:=../Makefile.param
# include $(PARAM_FILE)
# endif

# Define the default OS link directory.
export HIWORK_PATH?=/hiwork
                               #export 代表可以把变量传递到下一级的makefile中去 
                               #?= 代表HIWORK_PATH这个变量若以前定义过了,则使用以前的定义,这个不起作用
export ARCH=arm
export MPP_BUILD=n

# use HIARCH indicate chip, use libc to choose cross compiler.
export HIARCH?=hi3518
export LIBC?=uclibc

# Whether support the debug information. HI_DEBUG or HI_RELEASE
export HIDBG?=HI_DEBUG

# Whether open -g 
#export HIGDB?=y
export HIGDB?=n

# FPGA board or not
export FPGA?=n

ifeq ($(HIARCH), )  #如果HIARCH为空,即没有定义,则打印出错
$(error HIARCH not defined! Please check!)
endif

ifeq ($(LIBC), )    #同上
$(error LIBC not defined! Please check!)
endif

ifeq ($(HIARCH),hi3531)
    export HICHIP?=0x35310100
    export ARCH_DIR?=hi3531
endif

ifeq ($(HIARCH),hi3532)
    export HICHIP?=0x35320100
    export ARCH_DIR?=hi3531
endif

ifeq ($(HIARCH),hi3521)
    export HICHIP?=0x35210100
    export ARCH_DIR?=hi3521
endif

ifeq ($(HIARCH),hi3520A)
    export HICHIP?=0x3520A100
    export ARCH_DIR?=hi3521
endif

ifeq ($(HIARCH),hi3520D)
    export HICHIP?=0x3520D100
    export ARCH_DIR?=hi3520D
endif

ifeq ($(HIARCH),hi3518)     #HIARCH 在上文中定义为hi3518 
    export HICHIP?=0x35180100
    export ARCH_DIR?=hi3518
endif

# use C01 to indicate uclibc, C02 to indicate glibc, C00 to indicate FPGA.
ifeq ($(LIBC),glibc)
    export CVER?=.C02
else
    export CVER?=.C01#LIBC已经在上文定义为uclibc 因此 CVER 变量为.C01
endif

ifeq ($(FPGA),y)
    export CVER=.C00
    export HI_FPGA:=HI_FPGA
    export EXTDRV:=extdrv/$(HIARCH)_fpga
else
    export HI_FPGA:=HI_XXXX#FPGA 在上文中定义为 n 
    export EXTDRV:=extdrv/$(HIARCH)
endif

# Get the local SDK_ROOT path or RELEASE_ROOT path by PARAM_FILE.
# PARAM_FILE is configed at Makefile before include this file
export PARAM_FILE
export SDK_PATH?=$(shell cd $(PWD)/`dirname $(PARAM_FILE)`/..; pwd)#SDK_PATH mpp2存放的目录 我的是/root/hi3518
export DRV_ROOT?=$(SDK_PATH)/drv
export MPP_PATH?=$(SDK_PATH)/mpp2

# Allocated the linux position
#ifneq ($(shell ls $(HIWORK_PATH)/osdrv$(HIARCH)$(CVER)), )
# export LINUX_ROOT?=$(HIWORK_PATH)/osdrv$(HIARCH)$(CVER)/kernel/linux-3.0.y
#else
# export LINUX_ROOT?=$(SDK_PATH)/osdrv/kernel/linux-3.0.y#确定Linux内核的位置
#endif

# Define cross compiler
ifeq ($(LIBC),glibc)
    export CROSS_COMPILE?= arm-hisiv200-linux-
    export CROSS?= arm-hisiv200-linux-
else
    export CROSS_COMPILE?= arm-hisiv100nptl-linux-#LIBC已经在上文定义为uclibc
    export CROSS?= arm-hisiv100nptl-linux-
endif

export CC:=$(CROSS)gcc  #arm-hisiv100nptl-linux-gcc
export AR:=$(CROSS)ar   #arm-hisiv100nptl-linux-ar

export MPP_CFLAGS:= -Wall

ifeq ($(HIGDB), y)
    MPP_CFLAGS += -g
else
    MPP_CFLAGS += -O2# HIGDB 在上文中定义为n
endif

# Define the object output directory
ifeq ($(MPP_BUILD), y)   #在上文定义为 n
    REL_DIR=$(SDK_PATH)/mpp2/release/$(HIARCH)
    SAMPLE_DIR=$(SDK_PATH)/mpp2/sample/$(HIARCH)
else
    REL_DIR=$(MPP_PATH)#/root/hi3518/mpp2
    EXTDRV=extdrv
    SAMPLE_DIR=$(MPP_PATH)/sample#/root/hi3518/mpp2/sample
endif

#/root/hi3518/mpp2/include
export REL_INC := $(REL_DIR)/include
#/root/hi3518/mpp2/lib
export REL_LIB := $(REL_DIR)/lib
#/root/hi3518/mpp2/ko
export REL_KO  := $(REL_DIR)/ko

# Define the lib of audio codec
ifeq ($(HIARCH),hi3518)                #HIARCH 在上文定义为 hi3518
export AUDIO_PATH?=$(MPP_PATH)/component/audio2/lib/$(CROSS)
else
export AUDIO_PATH?=$(MPP_PATH)/component/audio/lib/$(CROSS)
endif

export AUDIO_LIBA := $(REL_LIB)/libVoiceEngine.a \
        $(REL_LIB)/libaec.a    \
        $(REL_LIB)/libresampler.a \
        $(REL_LIB)/libanr.a

# Define the lib of jpeg codec
export JPEGD_PATH?=$(MPP_PATH)/component/jpegd   #/root/hi3518/mpp2/component/jpegd
export JPEGD_LIBA:=$(REL_LIB)/libjpeg.a   #/root/hi3518/mpp2/lib/libjpeg.a

#********************* Macro for version management***************************** 
VER_X ?= 1
VER_Y ?= 0
VER_Z ?= 0
VER_P ?= 0
MPP_CFLAGS += -DVER_X=$(VER_X) -DVER_Y=$(VER_Y) -DVER_Z=$(VER_Z) -DVER_P=$(VER_P)
#******************************************************************************* 

# include the config file of platform
ifeq ($(MPP_BUILD), y)
    -include $(SDK_PATH)/mpp2/configs/config.mk
else
    export CONFIG_ISP=n   #在上文中定义为 n
endif

# End!!

上面的makefile里面,我已经在关键地方做了注释,请注意查看。

综合上面三个makefile可知,其先后顺序为:

mpp2/Makefile.param ----> mpp2/sample/Makefile.param ----> mpp2/sample/venc/makefile  

而mpp2/Makefile.param和 mpp2/sample/Makefile.param则是定义了很多变量,记录如下:

***MPP_PATH***      /root/hi3518/mpp2
***CROSS_COMPILE*** arm-hisiv100nptl-linux-
***CROSS***         arm-hisiv100nptl-linux-
***CC***            arm-hisiv100nptl-linux-gcc
***AR***            arm-hisiv100nptl-linux-ar
***MPP_CFLAGS***    -Wall -O2
***REL_DIR***       /root/hi3518/mpp2
***SAMPLE_DIR***    /root/hi3518/mpp2/sample
***REL_INC***       /root/hi3518/mpp2/include
***REL_LIB***       /root/hi3518/mpp2/lib
***REL_KO***        /root/hi3518/mpp2/ko
***CONFIG_ISP***    n
***SENSOR_TYPE***   OMNI_OV9712_DC_720P_30FPS
***SENSOR_LIBS***   /root/hi3518/mpp2/lib/libisp.a 
          /root/hi3518/mpp2/lib/libsns_ov9712.a
              /root/hi3518/mpp2/lib/lib_hiae.a
          /root/hi3518/mpp2/lib/lib_hiawb.a
              /root/hi3518/mpp2/lib/lib_hiaf.a
***COMMON_DIR***    /root/hi3518/mpp2/sample/venc/../common
***INC_FLAGS***     -I/root/hi3518/mpp2/sample/venc/../common/
              -I/root/hi3518/mpp2/include
          -I/root/hi3518/mpp2/component/acodec
          -I/root/hi3518/mpp2/extdrv/tw2865 
***ISP_VERSION***   ISP_V2
***CFLAGS***        -Wall -g -I/root/hi3518/mpp2/sample/venc/../common/   -
I/root/hi3518/mpp2/include -I/root/hi3518/mpp2/component/acodec -
I/root/hi3518/mpp2/extdrv/tw2865 -Dhi3518 -DHICHIP=0x35180100 -
DSENSOR_TYPE=OMNI_OV9712_DC_720P_30FPS -DHI_DEBUG -DHI_XXXX -lpthread -lm -DISP_V2   
***COMM_SRC***       /root/hi3518/mpp2/sample/venc/../common所有的.c文件
***COMM_OBJ***       /root/hi3518/mpp2/sample/venc/../common所有的.c文件对应的.o文件
***SRC***            sample_venc.c
***OBJ***            sample_venc.o
***TARGET***         sample_venc
***MPI_LIBS***       /root/hi3518/mpp2/lib/libmpi.a

以上便是全部过程,分析部分在makefile里面’#’标明了,若有错误的地方,敬请指教。

你可能感兴趣的:(sdk,makefile)