On Thu, 29 May 2003, AndreyB wrote:
> Does anybody know?
>
> I have no problem with compiling and linking, but all the objects live in
> the source directories - bad habit.
>
> What do I do?
I would say I owe this answer as a part of my lecture :)
This is a part of a sample makefile.in (the one I currently use). Since it
is the part after the
definitions, most of it may also get inserted straight into the makefile,
given
that MACHINE_TYPE is declared by hand.
the objects are created in $(MACHINE_TYPE)/$(OUTPUT)_o/, to
allow for different
objects to be held for debug mode (objects compiled with -g are held in
machine_type/outputg_o/, because of the recursive make in the end of this
makefile, which changes the OUTPUT to OUTPUTg.
#output name, a base name to be used to creat executables and libraries.
OUTPUT=proggie
#identify c source code
CSOURCES= $(wildcard *.c)
#identify fortran sources
F77SOURCES= $(wildcard *.f)
F90SOURCES= $(wildcard *.f90)
FSOURCES= $(F77SOURCES) $(F90SOURCES)
#create the expected object names, those that will be used to the final
#linkage
COBJS:= $(patsubst %.c,%.o,$(CSOURCES))
FOBJS:= $(patsubst %.f,%.o,$(F77SOURCES)) $(patsubst %.f90,%.o,$(F90SOURCES))
#include file, which the fortran files depend upon.
#I still need to figure out if and how to do a make depend for fortran
INCS= $(wildcard *.inc)
OTHER_OBJS= $(FOBJS) $(COBJS)
SOURCES = $(FSOURCES) $(CSOURCES)
#the list of objects
OBJS_NODIR = $(OTHER_OBJS) $(LIBOBJS)
#the list of objects, placed at the right place
OBJS = $(patsubst %.o,$(MACHINE_TYPE)/$(OUTPUT)_o/%.o,$(OBJS_NODIR))
#this is where we expect configure to insert it LIBS, and we can add to
#it.
LIBS = $(OTHER_LIBS) @LIBS@ @FLIBS@
#this target will form the executable. It should depend on target prepare,
as well, but I need to figure out the .PHONY thing yet.
#it compiles and copies the output to the machine_type directory
$(OUTPUT): $(OBJS)
$(CC) $(LDFLAGS) -o $(OUTPUT) $(OBJS) $(LIBS)
\cp -f $@ $(MACHINE_TYPE)
#an object is created into the directory of the machine_type
$(MACHINE_TYPE)/$(OUTPUT)_o/%.o:%.c
$(CC) $(CFLAGS) -c $< -o $@
$(MACHINE_TYPE)/$(OUTPUT)_o/%.o:%.f $(INCS)
$(FC) $(FFLAGS) -c $< -o $@
$(MACHINE_TYPE)/$(OUTPUT)_o/%.o:%.f90 $(INCS)
$(FC) $(FFLAGS) -c $< -o $@
#target prepare needs to be called once for each machine and each output.
#it verifies the directory exists, otherwise- creates it.
prepare:$(MACHINE_TYPE) $(MACHINE_TYPE)/$(OUTPUT)_o
$(MACHINE_TYPE)/$(OUTPUT)_o:$(MACHINE_TYPE)
if test ! -e "$@"; then mkdir $@; fi
$(MACHINE_TYPE):
if test ! -e "$@"; then mkdir $@; fi
#create a library from the correct objects.
$(MACHINE_TYPE)/$(OUTPUT).a: $(OBJS)
rm -f $@
$(AR) r $@ $(OBJS)
ranlib $@
debug:
$(MAKE) OUTPUT="$(OUTPUT)g" EXTRA_FLAGS="$(DEBUG)"
EXTRA_LIBS="$(EXTRA_LIBS_D)" $(OUTPUT)g
opt:
$(MAKE) EXTRA_FLAGS="$(OPTIMIZE)" EXTRA_LIBS="$(EXTRA_LIBS_O)"
#I use thise targets in order to list the targets to be built for a
#release. Sometimes I need the executable, sometimes the library (and the
#executable will not even link),
#sometimes both. I run a script which updates from CVS, and uses rsh on
several platforms, and does make debug-release and make opt-release on
each of them, so I need the target name to be identical
debug-release: debuglib debug
opt-release: optlib opt
debuglib:
$(MAKE) OUTPUT="$(OUTPUT)g" EXTRA_FLAGS="$(DEBUG)"
EXTRA_LIBS="$(EXTRA_LIBS_D)" $(MACHINE_TYPE)/$(OUTPUT)g.a
optlib:
$(MAKE) EXTRA_FLAGS="$(OPTIMIZE)" EXTRA_LIBS="$(EXTRA_LIBS_O)"
$(MACHINE_TYPE)/$(OUTPUT).a
clean:
rm -f *.o $(MACHINE_TYPE)/$(OUTPUT)*.a $(OUTPUT)
rm -f $(MACHINE_TYPE)/$(OUTPUT)*_o/*.o
rm -f config.cache
--
Orna. | http://vipe.technion.ac.il/~ladypine/
I am not a number, I am a free person!
--------------------------------------------------------------------------
Haifa Linux Club Mailing List (http://www.haifux.org)
To unsub send an empty message to [EMAIL PROTECTED]