【问题标题】:Makefiles in openwrt, the difference between cp and $(CP)?openwrt中的makefile,cp和$(CP)的区别?
【发布时间】:2011-11-02 03:33:26
【问题描述】:

我正在学习在 openwrt 中编译我自己的包的教程。

在/package/helloworld目录下:

.../packege/helloworld$ ls
src Makefile
.../packege/helloworld$ ls src
hello.c main.c Makefile
.../packege/helloworld$vi Makefile

#helloworld makefile
include $(TOPDIR)/rules.mk

PKG_NAME:=helloworld
PKG_RELEASE:=1
PKG_VERSION:=0.1

PKG_BUILD_DEPENDS:=

include $(INCLUDE_DIR)/package.mk

define Package/helloworld
  SECTION:=utils
  CATEGORY:=Utilities
  DEPENDS:=@TARGET_etrax
  TITLE:=Yet Another Helloworld Application
endef

define Package/helloworld/description
 This is helloworld :p
endef

define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
$(CP) ./src/* $(PKG_BUILD_DIR)/
endef

define Build/Compile
$(MAKE) -C $(PKG_BUILD_DIR) \
    $(TARGET_CONFIGURE_OPTS) \
    CFLAGS="$(TARGET_CFLAGS)"
endef

define Package/helloworld/install
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/helloworld $(1)/usr/bin/
endef

$(eval $(call BuildPackage,helloworld))

我有两个关于这个 Makefile 的问题:

  1. 发现有mkdir、$(CP)、$(MAKE)等命令。我把$(CP)改成cp,编译顺利。所以我不明白为什么存在这两种格式。

  2. $(PKG_BUILD_DIR)、$(INSTALL_DIR)等参数在openwrt中定义在哪里?我刚刚找到了定义 $(TOPDIR) 的地方,但没有找到其他地方。

谢谢

【问题讨论】:

    标签: makefile embedded openwrt


    【解决方案1】:
    1. 这些不是不同种类的格式,cpLinux command,$(CP) 是用于“获取 make 变量 CP 的值”的 makefile 结构.因此,在 Linux 下它应该扩展为 cp (即应该在某处用这个值初始化),并且最有可能在 Windows 下扩展为 copy (这都是特殊的设置-依赖,因为 cpcopy 不完全相同)。 $(MKDIR) 和其他系统工具也是如此。

      1.1。 $(MAKE) 实际上是另一回事 - 这是一个特殊的 make 变量,它扩展为使用从命令行传递的参数/标志来制作工具名称。阅读this

    2. 这些都是控制构建位置和安装位置的变量。见描述here

    【讨论】:

      猜你喜欢
      • 2018-08-01
      • 2018-01-13
      • 2012-08-08
      • 1970-01-01
      • 1970-01-01
      • 2018-03-23
      • 2018-03-29
      • 2014-05-26
      相关资源
      最近更新 更多