130 lines
3.7 KiB
Makefile
130 lines
3.7 KiB
Makefile
#
|
|
# Copyright 2022 Google LLC. All Rights Reserved. This file and proprietary
|
|
# source code may only be used and distributed under the Widevine
|
|
# License Agreement.
|
|
#
|
|
|
|
# This makefile is a simple set of rules for compiling host apps for OP-TEE.
|
|
# Feel free to use any other system.
|
|
#
|
|
# Inputs:
|
|
# - srcdir: Relative path from parent Makefile to source file directory, eg top
|
|
# of repo.
|
|
# - builddir: Relative path from parent Makefile to destination directory.
|
|
# - srcs: List of source .c/.cpp/.cc/.S files. All entries in $(srcs)
|
|
# must be relative to $(srcdir)
|
|
# - incs: List of include paths. Must be relative to $(srcdir).
|
|
# - CROSS_COMPILE: prefix for gcc, eg arm-none-gnueabihf-
|
|
#
|
|
# Can optionally provide additional ldflags, cflags, cppflags, and global-incs
|
|
|
|
ifneq ($V,1)
|
|
q := @
|
|
cmd-echo := true
|
|
cmd-echo-silent := echo
|
|
else
|
|
q :=
|
|
cmd-echo := echo
|
|
cmd-echo-silent := true
|
|
endif
|
|
|
|
cc := $(CROSS_COMPILE)gcc
|
|
cxx := $(CROSS_COMPILE)g++
|
|
|
|
ssrc := $(patsubst %.S, %.o, $(filter %.S, $(srcs)))
|
|
csrc := $(patsubst %.c, %.o, $(filter %.c, $(srcs)))
|
|
cppsrc := $(patsubst %.cpp, %.o, $(filter %.cpp, $(srcs)))
|
|
ccsrc := $(patsubst %.cc, %.o, $(filter %.cc, $(srcs)))
|
|
objs := $(sort $(addprefix $(builddir), $(csrc) $(cppsrc) $(ccsrc) $(ssrc)))
|
|
|
|
includes := $(addprefix $(srcdir), $(incs)) $(global-incs)
|
|
|
|
cflags += \
|
|
-Wall \
|
|
-Werror \
|
|
-fPIC \
|
|
$(addprefix -I, $(includes))
|
|
|
|
cflags_c += \
|
|
$(cflags) \
|
|
-std=c11 \
|
|
-D_POSIX_C_SOURCE=200809L
|
|
|
|
cppflags += \
|
|
$(cflags) \
|
|
$(CPPFLAGS) \
|
|
-std=c++17 \
|
|
|
|
# Filter out files and directories in third_party.
|
|
filter_out_third_party = \
|
|
$(foreach path,$(1),$(if $(findstring /third_party/,$(path)),,$(path)))
|
|
|
|
clang-tidy-srcs := \
|
|
$(sort $(addprefix $(srcdir),$(call filter_out_third_party,$(srcs))))
|
|
|
|
clang-tidy-incs := $(call filter_out_third_party,$(includes))
|
|
|
|
clang-tidy-flags := \
|
|
--header-filter '$(subst $() $(),|,$(strip $(clang-tidy-incs)))' \
|
|
--quiet
|
|
|
|
.PHONY: all
|
|
all: $(builddir)$(output)
|
|
|
|
$(builddir)$(output): $(objs)
|
|
@$(cmd-echo-silent) ' LD $@'
|
|
${q}$(cxx) $(ldflags) -o $@ $(objs) $(ldadd)
|
|
|
|
.PHONY: clean
|
|
clean:
|
|
@$(cmd-echo-silent) ' CLEAN $(builddir)'
|
|
${q}rm -f $(objs) $(output)
|
|
@if [ -d $(builddir) ]; then rm -r $(builddir); fi
|
|
|
|
$(builddir)%.o: $(srcdir)%.c
|
|
${q}mkdir -p $(shell dirname $@)
|
|
@$(cmd-echo-silent) ' CC $@'
|
|
${q}$(cc) $(cflags_c) -c $< -o $@
|
|
|
|
$(builddir)%.o: $(srcdir)%.cc
|
|
${q}mkdir -p $(shell dirname $@)
|
|
@$(cmd-echo-silent) ' CPP $@'
|
|
${q}$(cxx) $(cppflags) -c $< -o $@
|
|
|
|
$(builddir)%.o: $(srcdir)%.cpp
|
|
${q}mkdir -p $(shell dirname $@)
|
|
@$(cmd-echo-silent) ' CPP $@'
|
|
${q}$(cxx) $(cppflags) -c $< -o $@
|
|
|
|
$(builddir)%.o: $(srcdir)%.S
|
|
${q}mkdir -p $(shell dirname $@)
|
|
@$(cmd-echo-silent) ' CC $@'
|
|
${q}$(cc) $(cflags_c) -c $< -o $@
|
|
|
|
# Define a rule template to run clang-tidy with a single source file.
|
|
define clang-tidy-rule
|
|
.PHONY: clang-tidy-$(1)
|
|
clang-tidy-$(1):
|
|
@$(cmd-echo-silent) ' CLANG-TIDY $(1)'
|
|
${q}clang-tidy $(clang-tidy-flags) $(1) -- $(cflags) \
|
|
$(if $(filter .c,$(suffix $(1))),-std=c11 -D_POSIX_C_SOURCE=200809L) \
|
|
$(if $(filter .cpp,$(suffix $(1))),-std=c++17)
|
|
endef
|
|
|
|
define clang-tidy-rule-cpp
|
|
.PHONY: clang-tidy-$(1)
|
|
clang-tidy-$(1):
|
|
@$(cmd-echo-silent) ' CLANG-TIDY $(1)'
|
|
${q}clang-tidy $(clang-tidy-flags) -extra-arg=-std=c++17 $(1) -- $(cflags)
|
|
endef
|
|
|
|
# Generate rules to run clang-tidy with each source file.
|
|
clang-tidy-srcs-c := $(filter %.c %.S, $(clang-tidy-srcs))
|
|
$(foreach src,$(clang-tidy-srcs-c),$(eval $(call clang-tidy-rule,$(src))))
|
|
clang-tidy-srcs-cpp := $(filter %.cpp %.cc, $(clang-tidy-srcs))
|
|
$(foreach src,$(clang-tidy-srcs-cpp),$(eval $(call clang-tidy-rule-cpp,$(src))))
|
|
|
|
# Run clang-tidy with all source files.
|
|
.PHONY: clang-tidy
|
|
clang-tidy: $(addprefix clang-tidy-,$(clang-tidy-srcs))
|