Search code examples
c++makefileopenwrt

Build error: make: Nothing to be done for 'compile'


I need to add my own package to the openwrt image. On the wiki of the project I found this article.

I tried to follow the instructions for it, but in the end I did not manage to add my own package to the source code tree (the build ignored its presence).

Because of this, I tried to find some other way. And it turned out to be a this instruction. I followed the directions from there and compiled my own package.

But as you can see, the source code of that package does not depend on others and does not require any other build header files. Also, his Makefile completely includes instructions for compiling.

define Build/Compile
    $(TARGET_CC) $(TARGET_CFLAGS) -o $(PKG_BUILD_DIR)/helloworld.o -c $(PKG_BUILD_DIR)/helloworld.c
    $(TARGET_CC) $(TARGET_LDFLAGS) -o $(PKG_BUILD_DIR)/$1 $(PKG_BUILD_DIR)/helloworld.o
endef

But now this does not suit me, since another package that I want to add already has such dependencies. I tried to bypass them like this (copy the source code to the build folder and call the makefile located there) but nothing came of it:

define Build/Prepare
    echo $PKG_NAME
    mkdir -p $(PKG_BUILD_DIR)
    cp $(SOURCE_DIR)/* $(PKG_BUILD_DIR)
    $(Build/Patch)
endef

define Build/Compile
    $(PKG_BUILD_DIR) $(MAKE)
endef

I am getting next output:

    $ make -C package/feeds/mypackages/helloworld compile TOPDIR=$PWD
make: Entering directory '/home/username/mypackages/examples/helloworld'
bash: mkhash: command not found
bash: mkhash: command not found
bash: mkhash: command not found
bash: mkhash: command not found
bash: mkhash: command not found
bash: mkhash: command not found
bash: mkhash: command not found
bash: mkhash: command not found
make: Nothing to be done for 'compile'.
make: Leaving directory '/home/username/mypackages/examples/helloworld'

My full Makefile for both package and binary:

include $(TOPDIR)/rules.mk
PKG_NAME:=helloworld
PKG_VERSION:=1.0
PKG_RELEASE:=1
SOURCE_DIR:=/home/username/helloworld
include $(INCLUDE_DIR)/package.mk
define Package/$(PKG_NAME)
    SECTION:=utils
    DEPENDS:= +libstdcpp
    TITLE:=helloworld
endef
define Package/helloworld/description
    A simple "Hello, world!" -application.
endef
define Build/Prepare
    echo $PKG_NAME
    mkdir -p $(PKG_BUILD_DIR)
    cp $(SOURCE_DIR)/* $(PKG_BUILD_DIR)
    $(Build/Patch)
endef
define Build/Compile
    $(PKG_BUILD_DIR) $(MAKE)
endef
define Package/helloworld/install
    # Install binary
    #$(INSTALL_DIR) $(1)/usr/bin
    #$(INSTALL_BIN) $(PKG_BUILD_DIR)/helloworld $(1)/usr/bin/
endef
$(eval $(call BuildPackage,$(PKG_NAME)))

,

TARGET = heloworld
OBJS = heloworld.o
CFLAGS += -Wall -Wextra 
LDFLAGS += -lxsacpp -lxsac -lubus -lubox 
CXXFLAGS += $(CFLAGS) -std=c++14

%.o : %.cpp
    $(CXX) -c $(CXXFLAGS) $< -o $@

all: $(TARGET)

$(TARGET): $(OBJS)
    $(CXX) $(LDFLAGS) -o $@ $^

clean:
    rm *.o $(TARGET)

And actually my question is, what needs to be set in the Makefile to copy files correctly and call the local Makefile for package binary?


Solution

  • In order to copy files and directories you can use below step:

    # copy all files and directories using **cp -r -f **
    define Build/Prepare
        echo $PKG_NAME
        mkdir -p $(PKG_BUILD_DIR)
        cp -r -f $(SOURCE_DIR)/* $(PKG_BUILD_DIR)
        $(Build/Patch)
    endef
    

    In order to execute the local makefile use below step:

    # Execute local makefile by giving path using '-C' option
    define Build/Compile
         `$(MAKE) -C $(PKG_BUILD_DIR)`
    endef