我发现最好的方法是在项目目录的子目录中生成带有 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.
构建.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