Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/openthread: improve package Makefile #14282

Merged
merged 1 commit into from
Jun 16, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 27 additions & 14 deletions pkg/openthread/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@ PKG_NAME=openthread
PKG_URL=https://github.com/openthread/openthread.git
PKG_VERSION=thread-reference-20180926
PKG_LICENSE=BSD-3-Clause
PKG_BUILDDIR ?= $(PKGDIRBASE)/$(PKG_NAME)

include $(RIOTBASE)/pkg/pkg.mk

ifneq (,$(filter openthread-ftd,$(USEMODULE)))
TD = ftd
$(info Compile OpenThread for FTD device)
else ifneq (,$(filter openthread-mtd,$(USEMODULE)))
$(info Compile OpenThread for MTD device)
TD = mtd
JOINER_ARG = --enable-joiner
else
Expand All @@ -23,15 +20,35 @@ endif

OPENTHREAD_ARGS += $(CLI_ARG) $(JOINER_ARG) --enable-application-coap
CONFIG_FILE = OPENTHREAD_PROJECT_CORE_CONFIG_FILE='\"platform_config.h\"'
$(info $$OPENTHREAD_ARGS is [${OPENTHREAD_ARGS}])

OPENTHREAD_COMMON_FLAGS = -fdata-sections -ffunction-sections -Os
OPENTHREAD_COMMON_FLAGS += -Wno-implicit-fallthrough -Wno-unused-parameter
OPENTHREAD_CXXFLAGS += -Wno-class-memaccess

all:
cd $(PKG_BUILDDIR) && PREFIX="/" ./bootstrap
cd $(PKG_BUILDDIR) && CPP="$(CPP)" CC="$(CC)" CXX="$(CXX)"\
OT_LIB_DIR = $(PKG_BUILDDIR)/output/lib
MODULE_LIBS = mbedcrypto.a openthread-$(TD).a
ifneq (,$(filter openthread-cli,$(USEMODULE)))
MODULE_LIBS += openthread-cli.a
endif

all: $(addprefix $(BINDIR)/,$(MODULE_LIBS))
@true

$(BINDIR)/openthread-$(TD).a: $(OT_LIB_DIR)/libopenthread-$(TD).a
@cp $< $@

$(BINDIR)/mbedcrypto.a: $(BINDIR)/openthread-$(TD).a
@cp $(OT_LIB_DIR)/libmbedcrypto.a $@

$(BINDIR)/openthread-cli.a: $(BINDIR)/openthread-$(TD).a
@cp $(OT_LIB_DIR)/libopenthread-cli-$(TD).a $@

$(OT_LIB_DIR)/libopenthread-$(TD).a: $(PKG_BUILDDIR)/Makefile
make -C $(PKG_BUILDDIR) -j4 --no-print-directory install DESTDIR=$(PKG_BUILDDIR)/output PREFIX=/
$(Q)printf "OpenThread built for %s device\n" $(TD)

$(PKG_BUILDDIR)/Makefile: $(PKG_BUILDDIR)/configure
$(Q)cd $(PKG_BUILDDIR) && CPP="$(CPP)" CC="$(CC)" CXX="$(CXX)"\
OBJC="" OBJCXX="" AR="$(AR)" RANLIB="$(RANLIB)" NM="$(NM)" \
STRIP="$(STRIP)" \
CPPFLAGS="$(OPENTHREAD_COMMON_FLAGS) $(CFLAGS_CPU) -D$(CONFIG_FILE)" \
Expand All @@ -42,11 +59,7 @@ all:
-specs=nosys.specs -Wl,--gc-sections -Wl,-Map=map.map " \
./configure --disable-docs --host=$(TARGET_ARCH) --target=$(TARGET_ARCH) \
--prefix=/ --enable-default-logging $(OPENTHREAD_ARGS)
cd $(PKG_BUILDDIR) && DESTDIR=$(PKG_BUILDDIR)/output PREFIX=/ make -j4 --no-print-directory install

cp $(PKG_BUILDDIR)/output/lib/libmbedcrypto.a ${BINDIR}/mbedcrypto.a

cp $(PKG_BUILDDIR)/output/lib/libopenthread-$(TD).a ${BINDIR}/openthread-$(TD).a
ifneq (,$(filter openthread-cli,$(USEMODULE)))
cp $(PKG_BUILDDIR)/output/lib/libopenthread-cli-$(TD).a ${BINDIR}/openthread-cli.a
endif
$(PKG_BUILDDIR)/configure: $(PKG_PREPARED)
$(Q)printf "OPENTHREAD_ARGS is [$(OPENTHREAD_ARGS)]\n"
$(Q)cd $(PKG_BUILDDIR) && PREFIX="/" ./bootstrap