一、简介
工程目录如下:
二、建立工程目录
在demo目录下操作:
参数 i 用来指定工程目录的层级,可以使用 addvariant -i OS/CPU/VARIANT xxx xxx xxx 指定工程目录的层级。
LIST=OS (if three levels are specified)
LIST=CPU (if two levels are specified)
LIST=VARIANT (if one level is specified)
-
新建execute工程
addvariant -i OS bin aarch64 o-le
-
新建lib工程
addvariant -i OS lib aarch64 so-le
-
文件修改
将bin/aarch64/o-le/Makefile和lib/aarch64/o-le/Makefile原内容为
../../../common.mk
修改为
../../common.mk
-
文件补充
目录建好后,编译需要补充三类特定文件。
-
在lib和src增加.qnx_internal.mk
#VERSION 4.7.0
cpu_variants:=$(if $(filter arm,$(CPU)),v7,$(if $(filter ppc,$(CPU)),spe))
ifeq ($(filter g, $(VARIANT_LIST)),g)
DEBUG_SUFFIX=_g
LIB_SUFFIX=_g
else
DEBUG_SUFFIX=$(filter-out $(VARIANT_BUILD_TYPE) le be $(cpu_variants),$(VARIANT_LIST))
ifeq ($(DEBUG_SUFFIX),)
DEBUG_SUFFIX=_r
else
DEBUG_SUFFIX:=_$(DEBUG_SUFFIX)
endif
endif
CPU_VARIANT:=$(CPUDIR)$(subst $(space),,$(foreach v,$(filter $(cpu_variants),$(VARIANT_LIST)),_$(v)))
EXPRESSION = $(firstword $(foreach a, $(1)_$(CPU_VARIANT)$(DEBUG_SUFFIX) $(1)$(DEBUG_SUFFIX) \
$(1)_$(CPU_VARIANT) $(1), $(if $($(a)),$(a),)))
MERGE_EXPRESSION= $(foreach a, $(1)_$(CPU_VARIANT)$(2)$(DEBUG_SUFFIX) $(1)$(2)$(DEBUG_SUFFIX) \
$(1)_$(CPU_VARIANT)$(2) $(1)$(2) , $($(a)))
FIX_LIB_SUFFIXES= \
$(if $(1), \
$(if $(filter $(1), -Bstatic -Bdynamic),\
$(1) \
$(if $(2),\
$(call FIX_LIB_SUFFIXES,\
$(firstword $(2)),$(wordlist 2,$(words $(2)), $(2)),$(1))),\
$(if $(filter -Bstatic,$(3) ),\
$($(1):%.so,%.a),$($(1):%.a,%.so)) \
$(if $(2),\
$(call FIX_LIB_SUFFIXES,\
$(firstword $(2)), $(wordlist 2, $(words $(2)), $(2)), $(3)))))
GCC_VERSION:=$($(call EXPRESSION,GCC_VERSION))
DEFCOMPILER_TYPE:= $($(call EXPRESSION, DEFCOMPILER_TYPE))
EXTRA_LIBVPATH := $(call MERGE_EXPRESSION, EXTRA_LIBVPATH)
extra_incvpath_tmp:=$(call MERGE_EXPRESSION,EXTRA_INCVPATH,)
EXTRA_INCVPATH = $(call MERGE_EXPRESSION,EXTRA_INCVPATH,_@$(basename $@)) \
$(extra_incvpath_tmp)
LATE_SRCVPATH := $(call MERGE_EXPRESSION, EXTRA_SRCVPATH)
EXTRA_OBJS := $($(call EXPRESSION,EXTRA_OBJS))
CCFLAGS_D = $(CCFLAGS$(DEBUG_SUFFIX)) $(CCFLAGS_$(CPU_VARIANT)$(DEBUG_SUFFIX)) \
$(CCFLAGS_@$(basename $@)$(DEBUG_SUFFIX)) \
$(CCFLAGS_$(CPU_VARIANT)_@$(basename $@)$(DEBUG_SUFFIX))
LDFLAGS_D = $(LDFLAGS$(DEBUG_SUFFIX)) $(LDFLAGS_$(CPU_VARIANT)$(DEBUG_SUFFIX))
CCFLAGS += $(CCFLAGS_$(CPU_VARIANT)) $(CCFLAGS_@$(basename $@)) \
$(CCFLAGS_$(CPU_VARIANT)_@$(basename $@)) $(CCFLAGS_D)
LDFLAGS += $(LDFLAGS_$(CPU_VARIANT)) $(LDFLAGS_D)
LIBS:= $(LIBSOPT) $(patsubst %S_g, %_gS, $(foreach token, $($(call EXPRESSION,LIBS)),$(if $(findstring ^, $(token)), $(subst ^,,$(token))$(LIB_SUFFIX), $(token))))
ifdef LIBNAMES
LIBNAMES:= $(subst lib-Bdynamic.a, ,$(subst lib-Bstatic.a, , $(LIBNAMES)))
LIBNAMES := $(call FIX_LIB_SUFFIXES,$(firstword $(LIBNAMES)),$(wordslist 2, $(words $(LIBNAMES))),-Bdynamic)
endif
libopts := $(subst -l-B,-B, $(libopts))
ifneq ($(LIBS),)
EXTRA_DEPS += $(wildcard $(foreach a,$(EXTRA_LIBVPATH),$(a)/*.a))
endif
BUILDNAME:=$($(call EXPRESSION,BUILDNAME))$(if $(suffix $(BUILDNAME)),,$(IMAGE_SUFF_$(BUILD_TYPE)))
BUILDNAME_SAR:= $(patsubst %$(IMAGE_SUFF_$(BUILD_TYPE)),%S.a,$(BUILDNAME))
POST_BUILD:=$($(call EXPRESSION,POST_BUILD))
-
在demo目录新增installdir.mk
ifndef MULTIMEDIA_INSTALLDIR_ROOT
MULTIMEDIA_INSTALLDIR_ROOT=lib/amss/multimedia
endif
-
在lib和bin目录下新增common.mk,并调整编译字段。
ifndef QCONFIG
QCONFIG=qconfig.mk
endif
include $(QCONFIG)
#===== USEFILE - the file containing the usage message for the application.
USEFILE=
#===== NAME - name of the project (default - name of project directory).
NAME=
#===== PINFO - the file containing the packaging information for the application.
define PINFO
PINFO DESCRIPTION=
endef
#===== CCFLAGS - add the flags to the C compiler command line.
CCFLAGS += -Werror
#===== EXTRA_SRCVPATH - a space-separated list of directories to search for source files.
EXTRA_SRCVPATH+=$(PROJECT_ROOT)/src
#===== EXTRA_INCVPATH - a space-separated list of directories to search for include files.
EXTRA_INCVPATH+=$(PROJECT_ROOT)/inc
#===== EXTRA_LIBVPATH - a space-separated list of directories to search for library files.
EXTRA_LIBVPATH += $(PROJECT_ROOT)/../other/libs
#===== LIBS - a space-separated list of library items to be included in the link.
LIBS += crypto
#===== VERSION_TAG_SO - version tag for SONAME. Use it only if you don't like SONAME_VERSION
override VERSION_TAG_SO=
include $(MKFILES_ROOT)/qmacros.mk
ifndef QNX_INTERNAL
QNX_INTERNAL=$(PROJECT_ROOT)/.qnx_internal.mk
endif
include $(QNX_INTERNAL)
include $(MKFILES_ROOT)/qtargets.mk
include ../../../installdir.mk
OPTIMIZE_TYPE_g=none
OPTIMIZE_TYPE=$(OPTIMIZE_TYPE_$(filter g, $(VARIANTS)))
-
目录结构
最终目录结构如下:
三、静态库
-
编写动态库
ifndef QCONFIG QCONFIG=qconfig.mk endif include $(QCONFIG) #===== USEFILE - the file containing the usage message for the application. USEFILE= #===== NAME - name of the project (default - name of project directory). NAME=UpdateInstall #===== PINFO - the file containing the packaging information for the application. define PINFO PINFO DESCRIPTION= endef #===== CCFLAGS - add the flags to the C compiler command line. CCFLAGS += -Werror CCFLAGS += -DYF_UDS #===== EXTRA_SRCVPATH - a space-separated list of directories to search for source files. EXTRA_SRCVPATH+=$(PROJECT_ROOT)/src #===== EXTRA_INCVPATH - a space-separated list of directories to search for include files. EXTRA_INCVPATH+=$(PROJECT_ROOT)/inc \ $(PROJECT_ROOT)/../base/inc \ $(PROJECT_ROOT)/../UpdateLog/inc \ $(PROJECT_ROOT)/../UpdateCommon/inc \ $(PROJECT_ROOT)/../UpdateCJson/inc \ $(PROJECT_ROOT)/../UpdateRpc/inc \ $(PROJECT_ROOT)/../UpdatePackageAnalyze/inc \ $(PROJECT_ROOT)/../UpdateEngineCore/inc \ $(PROJECT_ROOT)/../bsdiff/inc \ $(PROJECT_ROOT)/../3rd/inc #===== EXTRA_LIBVPATH - a space-separated list of directories to search for library files. EXTRA_LIBVPATH += $(PROJECT_ROOT)/../3rd/libs \ $(PROJECT_ROOT)/../UpdateLog/aarch64/so-le \ $(PROJECT_ROOT)/../UpdateCommon/aarch64/so-le #===== LIBS - a space-separated list of library items to be included in the link. LIBS += UpdateLog UpdateCommon LIBS += mcuUpgrade socketComm switch_part update_part #===== VERSION_TAG_SO - version tag for SONAME. Use it only if you don't like SONAME_VERSION override VERSION_TAG_SO= include $(MKFILES_ROOT)/qmacros.mk ifndef QNX_INTERNAL QNX_INTERNAL=$(PROJECT_ROOT)/.qnx_internal.mk endif include $(QNX_INTERNAL) include $(MKFILES_ROOT)/qtargets.mk include ../../../installdir.mk OPTIMIZE_TYPE_g=none OPTIMIZE_TYPE=$(OPTIMIZE_TYPE_$(filter g, $(VARIANTS)))
-
编写静态库
注释override VERSION_TAG_SO,最终生成libbrotliS.a
ifndef QCONFIG
QCONFIG=qconfig.mk
endif
include $(QCONFIG)
#===== USEFILE - the file containing the usage message for the application.
USEFILE=
#===== NAME - name of the project (default - name of project directory).
NAME=brotli
#===== PINFO - the file containing the packaging information for the application.
define PINFO
PINFO DESCRIPTION=
endef
#===== CCFLAGS - add the flags to the C compiler command line.
CFLAGS += -Werror -Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64
CCFLAGS += -Werror -Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64
#===== EXTRA_SRCVPATH - a space-separated list of directories to search for source files.
EXTRA_SRCVPATH+=$(PROJECT_ROOT)/src/c/common \
$(PROJECT_ROOT)/src/c/enc \
$(PROJECT_ROOT)/src/c/dec
#===== EXTRA_INCVPATH - a space-separated list of directories to search for include files.
EXTRA_INCVPATH+=$(PROJECT_ROOT)/inc \
$(PROJECT_ROOT)/inc/c/common \
$(PROJECT_ROOT)/inc/c/enc \
$(PROJECT_ROOT)/inc/c/dec
#===== LIBS - a space-separated list of library items to be included in the link.
LIBS +=
#===== VERSION_TAG_SO - version tag for SONAME. Use it only if you don't like SONAME_VERSION
# override VERSION_TAG_SO=
include $(MKFILES_ROOT)/qmacros.mk
ifndef QNX_INTERNAL
QNX_INTERNAL=$(PROJECT_ROOT)/.qnx_internal.mk
endif
include $(QNX_INTERNAL)
include $(MKFILES_ROOT)/qtargets.mk
include ../../../installdir.mk
OPTIMIZE_TYPE_g=none
OPTIMIZE_TYPE=$(OPTIMIZE_TYPE_$(filter g, $(VARIANTS)))
=
-
依赖动态库和静态库
-
动态库添加到LIBS即可;
-
静态库需要添加关键字,以
-Wl,--whole-archive -Bstatic
开头,以-Bdynamic -Wl,--no-whole-archive -Wl,-E
结束。
ifndef QCONFIG QCONFIG=qconfig.mk endif include $(QCONFIG) #===== USEFILE - the file containing the usage message for the application. USEFILE= #===== NAME - name of the project (default - name of project directory). NAME=updateengine #===== PINFO - the file containing the packaging information for the application. define PINFO PINFO DESCRIPTION= endef #===== CCFLAGS - add the flags to the C compiler command line. CCFLAGS += -Werror CCFLAGS += -DYF_UDS # CCFLAGS += -DTEST_YF #===== EXTRA_SRCVPATH - a space-separated list of directories to search for source files. EXTRA_SRCVPATH+=$(PROJECT_ROOT)/src #===== EXTRA_INCVPATH - a space-separated list of directories to search for include files. EXTRA_INCVPATH+=$(PROJECT_ROOT)/inc \ $(PROJECT_ROOT)/../base/inc \ $(PROJECT_ROOT)/../UpdateLog/inc \ $(PROJECT_ROOT)/../UpdateCommon/inc \ $(PROJECT_ROOT)/../UpdateInstall/inc \ $(PROJECT_ROOT)/../UpdatePackageAnalyze/inc \ $(PROJECT_ROOT)/../UpdateRpc/inc \ $(PROJECT_ROOT)/../UpdateRpc/inc/uds \ $(PROJECT_ROOT)/../UpdateEngineCore/inc \ $(PROJECT_ROOT)/../3rd/inc #===== EXTRA_LIBVPATH - a space-separated list of directories to search for library files. EXTRA_LIBVPATH += $(PROJECT_ROOT)/../3rd/libs \ $(PROJECT_ROOT)/../UpdateLog/aarch64/so-le \ $(PROJECT_ROOT)/../UpdateCJson/aarch64/so-le \ $(PROJECT_ROOT)/../UpdateCommon/aarch64/so-le \ $(PROJECT_ROOT)/../UpdateInstall/aarch64/so-le \ $(PROJECT_ROOT)/../UpdatePackageAnalyze/aarch64/so-le \ $(PROJECT_ROOT)/../UpdateRpc/aarch64/so-le \ $(PROJECT_ROOT)/../UpdateEngineCore/aarch64/so-le \ $(PROJECT_ROOT)/../SimuUpdateDoip/aarch64/so-le #===== LIBS - a space-separated list of library items to be included in the link. LIBS += UpdateLog UpdateEngineCore #===== static libraries LDFLAGS += -Wl,--whole-archive -Bstatic -lbz2S -lbrotliS -lbspatchS \ -Bdynamic -Wl,--no-whole-archive -Wl,-E #===== VERSION_TAG_SO - version tag for SONAME. Use it only if you don't like SONAME_VERSION override VERSION_TAG_SO= include $(MKFILES_ROOT)/qmacros.mk ifndef QNX_INTERNAL QNX_INTERNAL=$(PROJECT_ROOT)/.qnx_internal.mk endif include $(QNX_INTERNAL) include $(MKFILES_ROOT)/qtargets.mk include ../../../installdir.mk OPTIMIZE_TYPE_g=none OPTIMIZE_TYPE=$(OPTIMIZE_TYPE_$(filter g, $(VARIANTS)))
-