help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

VPATH, pattern rules and building from any directory.


From: Oleksandr Gavenko
Subject: VPATH, pattern rules and building from any directory.
Date: Wed, 24 Oct 2012 01:02:57 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux)

My original Makefile use pattern rules (implicit and static) and relay on fact
that build dir == source dir.

I try port my Makefile for cygport (Cygwin packaging tool) which require
separate build and source dir (source dir tar'ed to foo-1.0-1-src.tar.bz
source package so must be clean) like:

  foo-1.0/
    src/
      Makefile
    build/
    inst/

I hardcore GNU Make user and rewrite my Makefile from (I skip unnecessary
details):

  C_FILES = $(wildcard *.c)
  O_FILES = $(C_FILES:.c=.o)

  $(APP): $(O_FILES)

  $(O_FILES): %.o: %.c $(BUILD_SCRIPTS)

to:

  S := $(dir $(abspath $(firstword $(MAKEFILE_LIST))))
  B := $(abspath .)/

  C_FILES = $(wildcard ${S}*.c)
  O_FILES = $(patsubst ${S}%.c,${B}%.o,$(C_FILES))

  all: ${B}$(APP)

  ${B}$(APP): $(O_FILES)

  $(O_FILES): ${B}%.o: ${S}%.c $(MAKEFILE_LIST)

Now I can build from current dir:

  $ make

and from any dir:

  $ make -f ../src

and all build artefacts has been placed at current dir. Another benefits I can
change build dir (like this like usual proprietary standard for dev-projects,
but little trick required to create this dir if it does not exist):

  $ cat Makefile

  ifeq '' '${B}'
    B := $(abspath .)/
  else
    $(shell mkdir -p ${B})
  endif

  $ make B=_build/

================================================================

Q: What is name for ability build from non project dir? I am non-English
speaker so it is hard to make proper search query to get answer...

I look in autobook and at http://mad-scientist.net/make/multi-arch.html
That sources have phrases:

 * build packages whose source files reside in another tree
 * invoke the build from within the target directory

but how about one-two word term?

What references or articles do you recommend to read about separating build
from source directory?

================================================================

Q: Is it possible to avoid ${B} or ${S} prefixes but still use pattern rules?
I read "The Advanced VPATH Method" at

  http://mad-scientist.net/make/multi-arch.html

but example too cryptic and place some restrictions on build environment.

How about VPATH? I never use it as prefer simple explicit behaviour versus
complicated implicit...

================================================================

Anyone can check complete diff at:

  
https://sourceforge.net/u/gavenkoa/utils/ci/5183a16c5e0d5b1bb9d35ff8b589fc8e792f19ae/

-- 
Best regards!




reply via email to

[Prev in Thread] Current Thread [Next in Thread]