I'm using gyp to generate makefiles for my project. Makefiles work, cause working binaries to pop up in "out" directory, all is dandy here.
However, I would like my makefiles to have some "standard" actions/targets, namely "install" "uninstall", and "clean".
I've added "install" target to .gyp files, but I have doubts if that is the correct way of doing that, especially that it seems there is no way to exclude "install" target from "all" in make using gyp.
I am also wondering if there is a tool to generate ./configure files for gyp, or if those should be written by developer and only run gyp with some needed options.
What is the correct way to add those targets ("install"...) to makefiles generated by gyp? Can it be made in such way, that once specified those actions will work with other build systems too? (ninja, etc.)
The best way I found to do it, is to generate makefiles with gyp in subdirectory of project directory, and then have manually written makefile with "install", "clean" etc. targets that executes Makefile generated by gyp.
To make sure that gyp is called with proper arguments, I call it from ./configure
Directory structure:
+ build
|- Makefile (generated by gyp)
|- Makefile (written by hand)
|- configure (written by hand)
|- build.gyp (written by hand)
./configure:
#!/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
Makefile:
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'
]
},
// (...)
]
}
And then, all I need to do to install is classic and inimitable:
./configure --prefix="/home/me/local_builds"
make
make install