help-make
[Top][All Lists]
Advanced

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

Help with makefile


From: Anthony Russello
Subject: Help with makefile
Date: Tue, 13 Jul 2010 17:58:24 +0800

Hi,

I'm trying to arrange an easy to maintain structure for some make
targets, and prevent as much as possible repeating code. Hopefully I
can explain this properly.

Our tree would look like this:

   makefile
   core/
      project1.mk
      project2.mk
      project3.mk
   targets/
      target1/
         device_config.mk
      target2/
         device_config.mk

We will be putting additional target specific files in that folder later on.

Let's say that target 1 uses project1 and project2. Let's also say
that target2 uses project 2 and project 3.

>From the top level, I want to be able to issue:

   make target1

Which I am hoping would get the configuration of permitted projects
from targets/target1/device_config.mk.

I can make this work by configuring each project makefile like this:

define build_project1
     @if [[ "$(HAVE_PROJECT1)" == "true" ]]; then \
          echo Building project 1; \
     else \
          echo Skipping project 1; \
     fi;
endef

Then, in my device_config.mk file for target1, I have this:

target override target1 : HAVE_PROJECT1 := true
target override target1 : HAVE_PROJECT2 := true
target override target1 : HAVE_PROJECT3 := false

My main.mk looks like this:

SHELL := /bin/bash
MY_TOP := $(shell pwd)
.SUFFIXES:
.DELETE_ON_ERROR:
.PHONY: install

all: target1 target2

include $(MY_TOP)/core/project1.mk
include $(MY_TOP)/core/project2.mk
include $(MY_TOP)/core/project3.mk

include $(MY_TOP)/targets/target1/device_config.mk
include $(MY_TOP)/targets/target2/device_config.mk

build_target:
        $(call build_project1)
        $(call build_project2)
        $(call build_project3)

target1:
        $(call build_target)

target2:
        $(call build_target)

So, when at the top level I run:

    make target1

It will go through and call build_project1, build_project2, and
build_project3, but based on the overrides, only products 1 and 2 are
built, the third is skipped.

Is there a better way? I'm really hoping to be able to instead just
use a device_config.mk that looks like this:

    HAVE_PROJECT1 := true
    HAVE_PROJECT2 := true
    HAVE_PROJECT3 := false

Thanks in advance,
Anthony



reply via email to

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