I am trying to built two different libraries from fortran source code, one with OMP support, the other without. Thus %.o files from the same source differ dependent on the compiler flags. When changing/recompiling one source file, ar still needs all o-files to rebuild the library. To avoid recompiling all source files I want to store the o-files from un-changed source files in two different directories, one with o-files including omp support, the other with out. I am happy to have to makefiles for that in that directory where the libraries are finally located.
However, I cannot get the library rebuild in a single command because of the vpath variable behaviour. Here is the make file:
SRC := FORTRAN = ifort OPTSSEQ = -mkl=sequential -DThreadUnSafe -warn nounused -warn declarations -O3 -DTIMEDETAIL DRVOPTS = $(OPTS) NOOPT = LOADER = ifort LOADOPTS = kernel=$(shell uname -r) ARCH = ar ARCHFLAGS= cr RANLIB = ranlib LibName=Lib_LM_$(FORTRAN)_$(kernel)_1.0.a .SUFFIXES: .SUFFIXES: .f90 .o include Moduls.mk vpath %.f90 src/ vpath %.o NoOMP/ OBJS = $(patsubst %.f90,%.o,$(SRC)) $(LibName): $(OBJS) $(ARCH) $(ARCHFLAGS) $@ $? $(RANLIB) $@ %.o : %.f90 $(FORTRAN) $(OPTSSEQ) -c $? -o $(addprefix NoOMP/,$@) clean: -rm *.mod -rm NoOMP/*.o -rm *.smod -rm $(LibName)
This results in successful building all %.o files after "make clean", since all %.f90 files are read from src/ and all %.o files are written to NoOMP/. However, building the archive fails because the "NoOMP" prefix on the %.o files is dropped. Thus, ar complains that it cannot find the %.o files. Only if I run "make" again, the archive is build because then %.o files have the NoOMP prefix. Adding a prefix command to the archive build line works fine if it is build from scratch. However, if only a single file has changed, the unchanged files have a "NoOMP/NoOMP/" prefix, resulting in an abort again.
While this is terribly annoying, as far as I understood the manual that is the default behaviour of GNU make. If I am wrong, how can I repair the makefile, if I am right how can I circumvent this problem.