[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Recursive use of make
From: |
livoriolcc |
Subject: |
Re: Recursive use of make |
Date: |
Sun, 28 Aug 2005 10:04:37 -0700 |
>
> Can you post an actual example of what you are doing?
>
> John.
> --
> John Graham-Cumming
> address@hidden
>
> Home: http://www.jgc.org/
> POPFile: http://getpopfile.org/
Hi, thanks for the answers to my question allready posted, im stuck with school
stuff so i havent had the chance to implement the recomendations. An example of
what im doing:
I have a file structure similar to the one that java uses; folders that maps
the design's logic structure of a system.
cppapis/
|-- bin
|-- doc
|-- obj
`-- src
|-- bar
| |-- Bar.cpp
| |-- Bar.h
| |-- Bar.mk
| `-- BarTest.cpp
`-- foo
|-- Foo.cpp
|-- Foo.h
|-- Foo.mk
`-- FooTest.cpp
the folders foo and bar are packages and each one contain a class (a .cpp file
and a .h file for each class), and for each class i have a .mk file that
describes the path and class name of each class that is needed by the class
that the .mk file belongs to. All the object code is stored in obj and the
executables in bin. An example. The Foo class haves a relation of composition
with the Bar class, so it needs the .h and .cpp (or .o) of Bar at compilation
time and the Foo.mk contents looks like this:
IMPORT := /prueba/bar/Bar
THISCPP:= Foo
THISH := Foo
MAIN := FooTest
include $(APIS_ROOT)/makefile
MAIN is a variable that contains the executable, in case that exists one, in
this case is a test of the class. Initially, the makefile is invoked on the .mk
file of the class we want to compile, in this case we invoke make like this:
make -f Foo.mk. In the example there is no much problem because the Bar class
does not import any class, but if it would, then it becomes neccesary to keep
the path of the folder and the name of the object code. Te first to compile
THISCPP, the second to link MAIN. The makefile looks like this:
PROY_ROOT:= $(APIS_ROOT)
PROY_SRC := $(PROY_ROOT)/src
PROY_OBJ := $(PROY_ROOT)/obj
PROY_BIN := $(PROY_ROOT)/bin
IMPORT := $(foreach CLASS, $(IMPORT), $(patsubst %, $(PROY_SRC)%, $(CLASE)))
#####################################
# this is where im wrong, because i thought that
# a variable could keep its value in upper levels
#
ifeq ($(MAKELEVEL), 0)
CCFLAGS := $(foreach CLASE, $(IMPORT), $(patsubst %, -I%, $(dir $(CLASE))))
export CCFLAGS
else
CCFLAGS += $(foreach CLASE, $(IMPORT), $(patsubst %, -I%, $(dir $(CLASE))))
endif
ifeq ($(MAKELEVEL), 0)
COD_OBJ := $(PROY_OBJ)/$(THISCPP).o
export COD_OBJ
else
COD_OBJ += $(PROY_OBJ)/$(THISCPP).o
endif
#
#
###################################
all : dependencies this executable
.PHONY : all
# ===========================================================================
# dependencies
# ===========================================================================
dependencies : classes $(IMPORT)
classes : $(IMPORT)
$(IMPORT) :
$(foreach CLASS, $(IMPORT), \
@$(MAKE) -C $(dir $(IMPORT)) -f $(CLASS).mk dependencies this)
# ===========================================================================
# this
# ===========================================================================
this : $(PROY_OBJ)/$(THISCPP).o
$(PROY_OBJ)/$(THISCPP).o : $(THISCPP).cpp $(THISCPP).h
@g++ -c $(THISCPP).cpp -o $@ $(CCFLAGS)
# ===========================================================================
# executable
# ===========================================================================
executable : $(PROY_BIN)/$(MAIN)
$(PROY_BIN)/$(MAIN) : $(MAIN).cpp
@g++ $(MAIN).cpp -o $@ $(CCFLAGS) $(COD_OBJ)
hope i have make myself clear. Thank you so much in advanced, this is my first
posting experience. I thought that posting in forums was only for gurus.
----- Mensaje original -----
De: John Graham-Cumming <address@hidden>
Fecha: Domingo, Agosto 28, 2005 5:35 am
Asunto: Re: Recursive use of make
---
[Este correo revisado contra virus por Inmune01 usando Declude Virus]
[This E-mail scanned for viruses by Inmune01 using Declude Virus]