vpath problem when making static libraries

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

vpath problem when making static libraries

Karl May
Hi there,

I wanna make two different static libraries from the same FORTRAN source files,
one with OMP support, one without. Thus %.o file generated during compilation
will differ and must be keept for updating both the libraries when one files
has changed (to avoid making MAKE recompiling everything). Since the naming of
the %.o files is the same they will be kept in two different directories.

With the following setting I have managed to get full recompilation and
rebuilding after "make clean", and, if one source file has changed,
recompilation of that file and library update:

#makefile
SRC :=
FORTRAN  = ifort
OPTS     = -O3 -mkl=sequential -warn nounused -warn declarations
DRVOPTS  = $(OPTS)
LOADER   = ifort
ARCH     = ar
ARCHFLAGS= cr
RANLIB   = ranlib

kernel=$(shell uname -r)
LibName=Lib_Tools_$(FORTRAN)_$(kernel)_1.0.a

.SUFFIXES:
.SUFFIXES: .f90

include src/Moduls_MKL.mk

vpath %.o NoOMP/
vpath %.f90 src/

OBJS = $(subst .f90,.o,$(SRC))
%.o: %.f90
        $(FORTRAN) $(OPTS) -c $< -o $(addprefix NoOMP/,$@)


$(LibName): $(OBJS)
        $(ARCH) $(ARCHFLAGS) $@ $(addprefix NoOMP/,$?)
        $(RANLIB) $@

clean:
        -rm *.smod
        -rm *.mod
        -rm NoOMP/*.o
        -rm $(LibName)


However, if I remove the library from the folder, MAKE tries to rebuilt the
target. Since none of the %.o files need to be rebuilt, their filename is
expanded by "NoOMP/". Thus "$(addprefix NoOMP/,$?)" will result in an
additional expansion and AR will complain that it could not find files named
"NoOMP/NoOMP/*.o". The same holds when removing the library and in addition
changing one source file.

The only remedy I could figure out is to execute "make clean; make". Then
filename prefixes introduced by vpath will be dropped and expansion via "$
(addprefix)" will yield the correct results. Or I change to "$(ARCH) $
(ARCHFLAGS) $@ $?", which will cause subsequent trouble for re-compiled files.

Thus, the final goal is, in addition to the already correct behaviour, to get
MAKE rebuilding the library from scratch using old %.o files only in "NoOMP/",
or using old %.o files and new %.o files in "NoOMP/".

Is there any way to achive that without an additional makefile.

Thanks a lot

Karl

_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make
Reply | Threaded
Open this post in threaded view
|

Re: vpath problem when making static libraries

Paul Smith-20
On Sat, 2016-09-24 at 10:31 +1000, Karl May wrote:
> I wanna make two different static libraries from the same FORTRAN source files,
> one with OMP support, one without. Thus %.o file generated during compilation
> will differ and must be keept for updating both the libraries when one files
> has changed (to avoid making MAKE recompiling everything). Since the naming of
> the %.o files is the same they will be kept in two different directories.

VPATH is intended only for locating remote _source_ files.  It cannot be
used to find object files.

More detailed discussion of this issue can be found here:
http://make.mad-scientist.net/papers/how-not-to-use-vpath/

The fact that you had to write your rules such that they violate Paul's
Second Rule of Makefiles should be a hint that you're in the weeds :)
http://make.mad-scientist.net/papers/rules-of-makefiles/#rule2

If you want to create two different sets of object files you need to
write two different pattern rules with different directories.  Since
your makefile is not complete (you didn't show what operations you
wanted for the OMP version, nor how you are going to decide which
version to build) it's hard to give an example.

_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make