【问题标题】:How to generate "make install" action using gyp?如何使用 gyp 生成“make install”操作?
【发布时间】:2015-01-31 19:02:38
【问题描述】:

我正在使用 gyp 为我的项目生成 makefile。 Makefiles 工作,导致工作的二进制文件在“out”目录中弹出,一切都在这里。

但是,我希望我的 makefile 有一些“标准”操作/目标,即“安装”、“卸载”和“清理”。

我已经在 .gyp 文件中添加了“安装”目标,但我怀疑这是否是正确的做法,尤其是似乎无法从 make 的“全部”中排除“安装”目标使用石膏。

我还想知道是否有一个工具可以为 gyp 生成 ./configure 文件,或者这些文件是否应该由开发人员编写并且只运行带有一些需要的选项的 gyp。

将这些目标(“安装”...)添加到 gyp 生成的 makefile 的正确方法是什么?能否以这样的方式制作,一旦指定这些操作也可以与其他构建系统一起使用? (忍者等)

【问题讨论】:

    标签: build makefile installation gyp


    【解决方案1】:

    我发现最好的方法是在项目目录的子目录中生成带有gyp的makefile,然后手动编写带有“install”、“clean”等目标的makefile来执行gyp生成的Makefile。

    为了确保使用正确的参数调用 gyp,我从 ./configure 调用它

    目录结构:

    + build
        |- Makefile (generated by gyp)
    |- Makefile (written by hand)
    |- configure (written by hand)
    |- build.gyp (written by hand)
    

    ./配置:

    #!/bin/bash
    
    PREFIX=/usr/local
    BUILDTYPE=Release
    
    
    for i in "$@"
    do
            case $i in
                -p=*|--prefix=*)
                PREFIX="${i#*=}"
    
                ;;
            esac
            case $i in
                -b=*|--buildtype=*)
                BUILDTYPE="${i#*=}"
    
                ;;
            esac
    done
    gyp -D prefix="$PREFIX" -D configuration="$BUILDTYPE" --depth=. --generator-output=./build -f make
    
    echo -e "prefix=$PREFIX\n" > ./config.mk
    

    生成文件:

    include config.mk
    
    prefix ?= /usr/local
    
    builddir=build/out
    abs_builddir := $(abspath $(builddir))
    
    all: config.mk
        $(MAKE) -C "./build" builddir="$(abs_builddir)"
    
    binaries=$(prefix)/bin/foo $(prefix)/bin/bar
    
    $(binaries): $(prefix)/bin/%: $(builddir)/%
        cp $< $@
    
    install: $(binaries) $(directories)
    
    # $(directories), uninstall, clean, .PHONY, etc.
    

    build.gyp:

    {
        'variables': {
        },
        'target_defaults': {
            // (...)
        },
        'targets': [
            {
                'target_name': 'foo',
                'type': 'executable',
                'defines': [],
                'include_dirs':[ 
                    'src/headers'
                ],
                'sources': [ 
                    'src/foo.c'
                ],
                'libraries': [
                    '-lcrypto'
                ]
            },
            // (...)
        ]
    }
    

    然后,我需要做的就是安装经典且无与伦比:

    ./configure --prefix="/home/me/local_builds"
    make
    make install
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-15
      • 1970-01-01
      • 2010-12-16
      • 2016-06-07
      • 1970-01-01
      相关资源
      最近更新 更多