# GNUmakefile for linking to an official release # This file is mostly a copy of standard.mk with a preamble added # and some small modifications for the case where the user does # not want to modify any source just link to existing libraries. # .d file generation is added for non-library object files. # It is included by GNUmakefile.link # Note that for user links the directory structure is flattened. # SHELL = /bin/sh export PWD := $(shell /bin/pwd) # set up search order - first the tmp local tree, tmp current, etc CPPFLAGS += -I. ifdef BFCURRENT CPPFLAGS += -I$(BFDIST)/releases/$(BFCURRENT)/tmp/$(BFARCH) endif # the following four assignments are overrides because they matter so much, # yet users might want to include various options override CPPFLAGS += -I$(PWD) override LDFLAGS += -L$(PWD) ifdef BFCURRENT override CPPFLAGS += -I$(BFDIST)/releases/$(BFCURRENT)/include override LDFLAGS += -L$(BFDIST)/releases/$(BFCURRENT)/lib/$(BFARCH) endif libdir = $(PWD) bindir = $(PWD) includedir = $(PWD) workdir=$(PWD) mandir = $(PWD) docdir = $(PWD) # clean is done locally by emptying directories clean: $(RM) *.o $(RM) *.d $(RM) *.a $(RM) *~ $(RM) *.exe .SUFFIXES = # standard.mk # #GNUmakefile fragment for use with the BaBar versioning system # # see also GNUmakefile.example in the SoftRelTools package # for an example of how to use this. # # Bob Jacobsen, December 1994 # # 11/12/95 T. Wenaus # - Modify rules to read dependency makefiles to not print complaints # about .d files not existing (-include) # - Add printout of what's going on for default 'quiet' case # - Add tests for file existence before attempting to use the file, # to eliminate error messages # - Protect ln -s against file existing alreadfy # ############################################################# # # Variables used to define specific products: # # INC include file products (no rules yet) # LIB library products # LIBFFILES FORTRAN source to compile into library # LIBF90FILES FORTRAN-90 source to compile into library # LIBCFILES C source to compile into library # LIBCCFILES C++ source to compile into library # FCFLAGS Flags for the FORTRAN-77 compiler # F90CFLAGS Flags for the FORTRAN-90 compiler # Note: F-90 does _not_ use the FCFLAGS # DOCS, MANPAGES Files to copy to appropriate directories # BINS executable products # SUBDIRS directories which should do recursive MAKEs # # Variables used to define destinations (note lower case): # # includedir constructed include files # libdir .a products # bindir executable products # workdir .o and .d files # mandir man files # docdir documentation # # General purpose targets: # include create any include files needed # lib build libraries # bin build executables # check do installation checks # (Note that by doing include for all packages, then lib for all packages, # then bin, you avoid worrying about dependency order.) # all include, lib, bin # .lib 'lib' request on the named subdirectory # .bin 'bin' request on the named subdirectory # clean remove *~, $(workdir)/*.d, $(workdir)*.o # (note that workdir might someday point to $(PWD), # so rm $(workdir)/* is a Bad Thing. This definition # of clean is not quite GNU standard, but works for me) # man man pages. This is also included in the bin target # doc documentation. This is also included in the bin targer # ############################################################ # Architecture Specific Information ############################################################ include $(PROJECT_DIR)/SoftRelTools/arch_spec.mk ############################################################ # standard definitions ############################################################ # define standard directories: libdir bindir includedir # It is EXPECTED that these will be overridden in the command line. # Note that these are _destination_ directories - see below for # search path directories libdir = $(shell /bin/pwd)/ bindir = $(shell /bin/pwd)/ includedir = $(shell /bin/pwd)/ # workdir is the host-specific location for creating # object files (if needed) and include dependency (.d) files workdir = $(shell /bin/pwd)/ # mandir and workdir point at tmp to avoid overwritting files # is nothing has been specified mandir = /tmp docdir = /tmp # standard definitions for external symbols SHELL = /bin/sh # next line removed Jan 11 96 as it caused trouble on AIX for .f files; # use site default instead # FC = f77bb ifeq ($(strip $(F90C)),) ifneq (,$(findstring AIX,$(BFARCH))) F90C = xlf90 else F90C = f90 endif endif curdir := $(shell /bin/pwd) moddir := $(libdir)$(F90C)/ ifeq ($(F90C),xlf90) IDLFLAGS = -Wb,xlf90 else IDLFLAGS = endif ifndef $(FIDLE) FIDLE := f90idl endif # idl make has been removed until it actually works # BobJ Oct 11 95 #override LIBCCFILES += $(IDLFILES:.idl=.ccstub.cc) #override LIBF90FILES += $(IDLFILES:.idl=.f90stub.f90) override F90CFLAGS += -I$(libdir)$(F90C) # standard targets .PHONY: all include mod lib bin check clean man doc # all references from here on to $(LIB) should get a fully qualified name ifdef LIB LIB := $(libdir)/$(LIB) endif # making .PHONEY depend on the following stops seaches into subdirs... # $(foreach v,$(SUBDIRS),$v.inc) \ # $(foreach v,$(SUBDIRS),$v.lib) $(foreach v,$(SUBDIRS),$v.bin) inc: $(INC) $(foreach v,$(SUBDIRS),$v.inc) @echo inc stage done in $(curdir) idl: $(IDLFILES) $(foreach v,$(SUBDIRS),$v.idl) @echo idl stage done in $(curdir) lib: $(LIB) $(foreach v,$(SUBDIRS),$v.lib) @echo lib stage done in $(curdir) bin: $(foreach v,$(BINS),$(bindir)$v) $(foreach v,$(SUBDIRS),$v.bin) @echo bin stage done in $(curdir) check: man: $(foreach v,$(filter $(wildcard *.1),$(MANPAGES)),$(mandir)man1/$v) man: $(foreach v,$(filter $(wildcard *.2),$(MANPAGES)),$(mandir)man2/$v) man: $(foreach v,$(filter $(wildcard *.3),$(MANPAGES)),$(mandir)man3/$v) man: $(foreach v,$(filter $(wildcard *.4),$(MANPAGES)),$(mandir)man4/$v) man: $(foreach v,$(filter $(wildcard *.5),$(MANPAGES)),$(mandir)man5/$v) doc: $(foreach v,$(DOCS),$(docdir)$v) $(foreach v,$(filter $(wildcard *.1),$(MANPAGES)),$(mandir)man1/$v) : $(MANPAGES) rm -f $@ if [ ! -d $(@D) ] ; then mkdir $(@D); fi cp $(@F) $@ chmod 444 $@ $(foreach v,$(filter $(wildcard *.2),$(MANPAGES)),$(mandir)man2/$v) : $(MANPAGES) rm -f $@ if [ ! -d $(@D) ] ; then mkdir $(@D); fi cp $(@F) $@ chmod 444 $@ $(foreach v,$(filter $(wildcard *.3),$(MANPAGES)),$(mandir)man3/$v) : $(MANPAGES) rm -f $@ if [ ! -d $(@D) ] ; then mkdir $(@D); fi cp $(@F) $@ chmod 444 $@ $(foreach v,$(filter $(wildcard *.4),$(MANPAGES)),$(mandir)man4/$v) : $(MANPAGES) rm -f $@ if [ ! -d $(@D) ] ; then mkdir $(@D); fi cp $(@F) $@ chmod 444 $@ $(foreach v,$(filter $(wildcard *.5),$(MANPAGES)),$(mandir)man5/$v) : $(MANPAGES) rm -f $@ if [ ! -d $(@D) ] ; then mkdir $(@D); fi cp $(@F) $@ chmod 444 $@ $(foreach v,$(DOCS),$(docdir)$v): $(DOCS) rm -f $@ if [ ! -d $(@D) ] ; then mkdir $(@D); fi cp $(@F) $@ chmod 444 $@ # add doc and man to bin # bin: doc man # search orders # Note that CPPFLAGS should already have the .c and .cc include search path # and LDFLAGS should have the library search path # Because $(LIB) is a fully qualified target (i.e. pathname), we can # allow searching for .a - otherwise, if $(libdir)/$(LIB) had # not already existed, we'd have found (and used as a dependency) # the one refrenced via $BFCURRENT # vpath %.a $(patsubst -L%,%,$(filter -L%,$(LDFLAGS))) vpath %.o $(workdir) vpath %.mod $(moddir) # the following three are for finding .h, .inc and .mod files in .d lists # make by awk, who does not put in full pathnames vpath %.h $(patsubst -I%,%,$(filter -I%,$(CPPFLAGS))) vpath %.inc $(patsubst -I%,%,$(filter -I%,$(CPPFLAGS))) vpath %.mod $(patsubst -I%,%,$(filter -I%,$(F90CFLAGS))) # note that we _dont_ search for .o and .d files - the rules are written # to explicitly look for and create them in workdir # create the list of modules in the library $(LIB): $(foreach V,$(LIBCCFILES),$(LIB)($(V:.cc=.o))) $(LIB): $(foreach V,$(LIBCXXFILES),$(LIB)($(V:.cxx=.o))) $(LIB): $(foreach V,$(LIBCFILES),$(LIB)($(V:.c=.o))) $(LIB): $(foreach V,$(filter %.f,$(LIBFFILES)),$(LIB)($(V:.f=.o))) $(LIB): $(foreach V,$(filter %.f90,$(LIBF90FILES)),$(LIB)($(V:.f90=.o))) $(LIB): $(foreach V,$(filter %.F,$(LIBFFILES)),$(LIB)($(V:.F=.o))) ifdef RANLIB $(RANLIB) $(libdir)$(@F) endif # standard library loading rules .SUFFIXES: .SUFFIXES: .a .o .cc .cxx .c .f .F .mod .f90 .idl .lex .d .PRECIOUS: $(IDLFILES:.idl=.f90stub.f90) $(IDLFILES:.idl=.ccstub.cc) .cc.a: echo Compiling $<; $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $< -o $(workdir)$(*F).o $(AR) $(ARFLAGS) $(libdir)$(@F) $(workdir)$(*F).o $(RM) $(workdir)$(*F).o .cxx.a: echo Compiling $<; $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $< -o $(workdir)$(*F).o $(AR) $(ARFLAGS) $(libdir)$(@F) $(workdir)$(*F).o $(RM) $(workdir)$(*F).o .c.a: echo Compiling $<; $(CC) $(CCFLAGS) $(CPPFLAGS) -c $< -o $(workdir)$(*F).o $(AR) $(ARFLAGS) $(libdir)$(@F) $(workdir)$(*F).o $(RM) $(workdir)$(*F).o # .f is NOT handled by f77bb; instead, the arch_spec.mk file # does the architecture specific things to the $(FCFLAGS) variable .f.a: echo Compiling $<; $(FC) $(FCFLAGS) -c $< -o $(workdir)$(*F).o $(AR) $(ARFLAGS) $(libdir)$(@F) $(workdir)$(*F).o $(RM) $(workdir)$(*F).o .f90.a: echo Compiling $<; if [ ! -d $(moddir) ] ; then mkdir $(moddir); fi ifeq ($(F90C),xlf90) cp $< $(workdir)$(*F).f cd $(moddir); $(F90C) $(F90CFLAGS) -c $(workdir)$(*F).f -o $(workdir)$(*F).o else cd $(moddir); $(F90C) $(F90CFLAGS) -c $(curdir)/$< -o $(workdir)$(*F).o endif $(AR) $(ARFLAGS) $(libdir)$(@F) $(workdir)$(*F).o $(RM) $(workdir)$(*F).o .f90.mod: if [ ! -d $(moddir) ] ; then mkdir $(moddir); fi ifeq ($(F90C),xlf90) cp $< $(workdir)$(*F).f cd $(moddir); $(F90C) $(F90CFLAGS) -c $(workdir)$(*F).f -o $(workdir)$(*F).o else cd $(moddir); $(F90C) $(F90CFLAGS) -c $(curdir)/$< -o $(workdir)$(*F).o endif # The following two are kludges because the source directory gets # write protected for official versions. Ideally the .f90 and .cc files # should get created somewhere else (e.g. in tmp), but that severely # complicates other rules. %.f90stub.f90: %.idl prot=0; \ if [ ! -w $(curdir) ]; then chmod u+w $(curdir); prot=1; fi; \ $(FIDLE) $(IDLFLAGS) $<; \ if [ $$prot ]; then chmod u-w $(curdir); fi %.ccstub.cc: %.idl prot=0; \ if [ ! -w $(curdir) ]; then chmod u+w $(curdir); prot=1; fi; \ $(FIDLE) $(IDLFLAGS) $<; \ if [ $$prot ]; then chmod u-w $(curdir); fi # note that f77bb -o does NOT work on IBM, and $(PWD) is sometimes the # directory in which the original make started .F.a: ifneq (,$(findstring AIX,$(BFARCH))) echo Compiling AIX .a $<; $(FCPP) $(FCPPFLAGS) $(CPPFLAGS) $< > $(workdir)$(*F).f $(FC) $(FCFLAGS) -c $(workdir)$(*F).f -o $(workdir)$*.o $(AR) r$(ARFLAGS) $(libdir)$(@F) $(workdir)$*.o $(RM) $(workdir)*.o else #FNAL-LSK We are using the gcc preprocessor (on SGI this is done with -acpp) echo Compiling Generic .a $<; $(FC) $(FCFLAGS) $(CPPFLAGS) -c $< -o $(workdir)$(*F).o $(AR) $(ARFLAGS) $(libdir)$(@F) $(workdir)$(*F).o $(RM) $(workdir)$(*F).o endif .cc.o: echo Compiling $<; $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $< -o $(workdir)$(*F).o .cxx.o: echo Compiling $<; $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $< -o $(workdir)$(*F).o .c.o: echo Compiling $<; $(CC) $(CCFLAGS) $(CPPFLAGS) -c $< -o $(workdir)$(*F).o # .f is NOT handled by f77bb; instead, the arch_spec.mk file # does the architecture specific things to the $(FCFLAGS) variable .f.o: echo Compiling $<; $(FC) $(FCFLAGS) -c $< -o $(workdir)$(*F).o .f90.o: echo Compiling $<; if [ ! -d $(moddir) ] ; then mkdir $(moddir); fi ifeq ($(F90C),xlf90) cp $< $(workdir)$*.f cd $(moddir); $(F90C) $(F90CFLAGS) -c $(workdir)$*.f -o $(workdir)$*.o else cd $(moddir); $(F90C) $(F90CFLAGS) -c $(curdir)/$< -o $(workdir)$*.o endif .F.o: ifneq (,$(findstring AIX,$(BFARCH))) echo Compiling on AIX: $< $(FCPP) $(FCPPFLAGS) $(CPPFLAGS) $< > $(workdir)$(*F).f $(FC) $(FCFLAGS) -c $(workdir)$(*F).f -o $(workdir)$*.o else echo Compiling: $(FC) -c $(FCFLAGS) $(CPPFLAGS) $< $(FC) -c $(FCFLAGS) $(CPPFLAGS) $< endif $(libdir)%.o: %.F ifneq (,$(findstring SunOS4,$(BFARCH))) echo Compiling $< $(FCPP) $(FCPPFLAGS) $(CPPFLAGS) $< $(workdir)$(*F).f $(FC) $(FCFLAGS) $(workdir)$(*F).f -c -o $(workdir)$*.o $(AR) $(ARFLAGS) $(libdir)$(@F) $(workdir)$*.o $(RM) $(workdir)*.o else ifneq (,$(findstring AIX,$(BFARCH))) echo Compiling on AIX $<; if [ $(testLink) $(workdir)$< ] ; then rm $(workdir)$< ; fi -if test ! -f $(workdir)$< ; then ln -s `/bin/pwd`/$< $(workdir)$< ; fi here=`/bin/pwd`; export here; cd $(workdir); $(FCPP) $(FCPPFLAGS) $(CPPFLAGS) $< > $(workdir)$(*F).f $(FC) $(FCFLAGS) -c $(workdir)$(*F).f -o $(workdir)$*.o mv $(workdir)$*.o $(libdir)$*.o if [ $(testLink) $(workdir)$< ] ; then rm $(workdir)$< ; fi else echo Compiling Generically $<; if [ $(testLink) $(workdir)$< ] ; then rm $(workdir)$< ; fi -if test ! -f $(workdir)$< ; then ln -s `/bin/pwd`/$< $(workdir)$< ; fi here=`/bin/pwd`; export here; cd $(workdir); f77bb -f77 "$(FCFLAGS)" -cpp "-I$$here $(CPPFLAGS)" $(F77BBOPT) $< mv $(workdir)$*.o $(libdir)$*.o if [ $(testLink) $(workdir)$< ] ; then rm $(workdir)$< ; fi endif endif # The next pattern rule is needed because the bindir prefix will not # automatically match to local (no prefix) source and I didn't want # to use vpath (it's too indiscriminant if it has no suffix to match) $(bindir)%: %.cc $(CXX) $< $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ $(LOADLIBES) $(bindir)%: %.cxx $(CXX) $< $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ $(LOADLIBES) # standard pattern rules for dependencies, puts .d in $workdir ifdef LIB # if this .d file is for a LIB the sed scipt is needed $(workdir)%.d: %.cc if test -f $< ; then echo Making $@; $(SHELL) -ec '$(CPP) -M $(CPPFLAGS) $< | sed '\''s?$*\.o?$(LIB)\($*.o) \$@ ?g'\'' > $@' ; fi $(workdir)%.d: %.cxx if test -f $< ; then echo Making $@; $(SHELL) -ec '$(CPP) -M $(CPPFLAGS) $< | sed '\''s?$*\.o?$(LIB)\($*.o) \$@ ?g'\'' > $@' ; fi $(workdir)%.d: %.c if test -f $< ; then echo Making $@; $(SHELL) -ec '$(CPP) -M $(CPPFLAGS) $< | sed '\''s?$*\.o?$(LIB)\($*.o) \$@ ?g'\'' > $@' ; fi else $(workdir)%.d: %.cc if test -f $< ; then echo Making $@; $(SHELL) -ec '$(CPP) -M $(CPPFLAGS) $< > $@' ; fi $(workdir)%.d: %.cxx if test -f $< ; then echo Making $@; $(SHELL) -ec '$(CPP) -M $(CPPFLAGS) $< > $@' ; fi $(workdir)%.d: %.c if test -f $< ; then echo Making $@; $(SHELL) -ec '$(CPP) -M $(CPPFLAGS) $< > $@' ; fi endif # Note the following rule changes depending on whether LIB is defined. # The dependency has to be taught if its making a library member, and # assumes so if LIB is defined $(workdir)%.d: %.F # LSK. Some of our files are included conditionally or multiple times. # We therefor need a full pre-processor, so we use gcc with a -x flag if test -f $< ; then echo Making $@; $(SHELL) -ec '$(CPP) -M $(FCPPMFLAGS) $(CPPFLAGS) $< | sed '\''s?$*\.f\.o?$(LIB)\($*.o) \$@ ?g'\'' > $@' ; fi $(workdir)%.d: %.f90 tr A-Z a-z < $*.f90 | awk '$$1=="module" { print $$2 ".mod" }' > $@.1 echo $(LIB)\($*.o\) $@ " : " $*.f90 "\\" > $@.2 tr A-Z a-z < $*.f90 | awk '$$1=="use" { print $$2 ".mod \\" }' >> $@.2 echo >> $@.2 echo >> $@.2 grep -v -f $@.1 $@.2 > $@ awk '{ print $$1 " : $*.f90" }' $@.1 >> $@ echo >> $@ rm -f $@.1 $@.2 %.mod: %.f90 if [ ! -d $(moddir) ] ; then mkdir $(moddir); fi ifeq ($(F90C),xlf90) cp $< $(workdir)$*.f cd $(moddir); $(F90C) $(F90CFLAGS) -c $(workdir)$*.f -o $(workdir)$*.o else cd $(moddir); $(F90C) $(F90CFLAGS) -c $(curdir)/$< -o $(workdir)$*.o endif # in theory, .f files should NOT have include files ... #$(workdir)%.d: %.f # rm -f $@ # echo $(LIB)\($*.o\) $@ " : " $*.f "\\" > $@ # awk '$$1=="#include" { print $$2 " \\" }' $*.f | tr -d \"\>\< >> $@ # echo >> $@ # the following is an alternate, ugly rule for .F -> .d using gcc # if [ $(testLink) $(workdir)$(<:.F=.c) ] ; then rm $(workdir)$(<:.F=.c) ; fi # ln -s `/bin/pwd`/$< $(workdir)/$(<:.F=.c) # here=`/bin/pwd`; export here; $(SHELL) -ec 'gcc -M -I$$here $(CPPFLAGS) $(workdir)/$(<:.F=.c) | sed '\''s?$*\.o?$(LIB)\($*.o) \$@ ?g'\'' | sed '\''s?$(workdir)/$(<:.F=.c)?$ $@' # if [ $(testLink) $(workdir)$(<:.F=.c) ] ; then rm $(workdir)$(<:.F=.c) ; fi # standard rules to read dependency makefiles # (Note problem if you have both foo.c and foo.cc) # (Note no .d files for .f, as no includes unless .F suffix used ifdef LIBCCFILES -include $(foreach var,$(LIBCCFILES:.cc=.d),$(workdir)$(var)) /dev/null endif ifdef LIBCXXFILES -include $(foreach var,$(LIBCXXFILES:.cxx=.d),$(workdir)$(var)) /dev/null endif ifdef LIBCFILES -include $(foreach var,$(LIBCFILES:.c=.d),$(workdir)$(var)) /dev/null endif ifdef LIBFFILES -include $(foreach var,$(filter %.F,$(LIBFFILES)),$(workdir)$(var:.F=.d)) /dev/null endif ifdef LIBF90FILES -include $(foreach var,$(LIBF90FILES:.f90=.d),$(workdir)$(var)) /dev/null endif # pattern rule to process subdirectories %.include: @$(MAKE) -C $(@:.include=) include %.lib: @$(MAKE) -C $(@:.lib=) lib %.bin: @$(MAKE) -C $(@:.bin=) bin