Message: GNUmakefile for subdirectories? Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

Question GNUmakefile for subdirectories? 

Keywords: GNUmakefile make sub-directories
Forum: Installation and Configuration
Date: 02 Jan, 2008
From: Kareem Kazkaz <Kareem Kazkaz>

Hello everyone.

I am trying to create the correct GNUMakefiles for my GEANT4 simulation, which is split up among a number of sub-directories. For example, I have the following structure:

   GenericSimulation
      GNUmakefile
      GenericSimulation.cc
      generator
         GNUmakefile
         include
            <the generator-related header files>
         src
            <the generator-related source files>
    geometry
         GNUmakefile
         include
             <the geometry-related header files>
         src
             <the geometry-related source files>

...and so on. My sub-directories are:

      generator
      geometry
      io
      messenger
      physics
      processing

Here is my highest-level GNUmakefile. Note that for right now, the line that includes the binmake.gmk file is commented out:

 name := GenericSimulation
 G4TARGET := $(name)
 G4EXLIB := true

 ifndef G4INSTALL
	@echo G4INSTALL not defined. Defaulting to /usr/local/geant4
	G4INSTALL = /usr/local/geant4
 endif
 .PHONY: all lib bin
 all: lib bin
 #include $(G4INSTALL)/config/binmake.gmk

 # G4LECS stuff
 INCFLAGS += -I$(G4INSTALL)/include
 LDFLAGS += -L$(G4LIB)/$(G4SYSTEM)
 LDLIBS_PREFINAL += -lCompt

 # ROOT stuff
 INCFLAGS += -I$(ROOTSYS)/include/root
 LDFLAGS += -L$(ROOTSYS)/lib/root
 LDLIBS_PREFINAL += $(shell $(ROOTSYS)/bin/root-config --libs)

 # Set up compiling in the sub-directories
 SUBDIRS = generator geometry messenger io physics processing

 INCFLAGS += $(addprefix -I./, $(addsuffix /include, $(SUBDIRS)))
 LDFLAGS += $(addprefix -L./tmp/$(G4SYSTEM)/, $(SUBDIRS))
 LDLIBS_PREFINAL += $(addprefix -l, $(SUBDIRS))

 lib:
	@for dir in $(SUBDIRS); do ($(MAKE) lib -C $$dir "SUBDIRS=$(SUBDIRS)" ); done

Then in each of the subdirectories, here is the GNUmakefile I use (where the first line changes from sub-directory to sub-directory):

 name := generator

 G4TARGET := $(name)
 G4EXLIB := true

 include $(G4INSTALL)/config/binmake.gmk

 # G4LECS stuff
 INCFLAGS += -I$(G4INSTALL)/include
 LDFLAGS += -L$(G4LIB)/$(G4SYSTEM)
 LDLIBS_PREFINAL += -lCompt

 # ROOT stuff
 INCFLAGS += -I$(ROOTSYS)/include/root
 LDFLAGS += -L$(ROOTSYS)/lib/root
 LDLIBS_PREFINAL += $(shell $(ROOTSYS)/bin/root-config --libs)

 # Set up compiling in the sub-directories
 INCFLAGS += $(addprefix -I../, $(addsuffix /include, $(SUBDIRS)))

I then set $G4WORKDIR to be the GenericSimulation directory, and run make from within that same directory. The compilation creates a bunch of library files in the directories

   GenericSimulation
   tmp
      $G4SYSTEM
         generator
            libgenerator.a
         geometry
            libgeometry.a

...and so on, for every sub-directory. The compilation ends there, since the binmake.gmk line is commented out of the highest-level GNUmakefile.

Unfortunately, when I uncomment the binmake.gmk line, and run make fresh (i.e., after I've deleted the bin and tmp directories), the compilation skips all the subdirectories and library creation, with the messages

 Making dependency for file GenericSimulation.cc ...
 Creating/replacing object files in /Users/kazkaz1/Documents/GenericSimulation/tmp/Darwin-g++/GenericSimulation/libGenericSimulation.a ...
 ar: creating archive /Users/kazkaz1/Documents/GenericSimulation/tmp/Darwin-g++/GenericSimulation/libGenericSimulation.a
 ar: /Users/kazkaz1/Documents/GenericSimulation/tmp/Darwin-g++/GenericSimulation/*.o: No such file or directory
 make: *** [/Users/kazkaz1/Documents/GenericSimulation/tmp/Darwin-g++/GenericSimulation/libGenericSimulation.a] Error 1

I've almost completed the chain, but I'm having trouble with the last steps. Does anybody have any suggestions as to how to fix this? I would like to be able to run "make" once in the GenericSimulation directory, have the process compile a library for every sub-directory, compile GenericSimulation.cc and link it with all the libraries, and put the final executable in the GenericSimulation/bin directory.

Any help would be greatly appreciated. Thanks!

        Kareem Kazkaz

Inline Depth:
 1 1
 All All
Outline Depth:
 1 1
 2 2
 All All
Add message: (add)

1 None: Re: GNUmakefile for subdirectories?   (Kareem Kazkaz - 02 Jan, 2008)
(_ None: Re: GNUmakefile for subdirectories?   (John Allison - 05 Jan, 2008)
 Add Message Add Message
to: "GNUmakefile for subdirectories?"

 Subscribe Subscribe

This site runs SLAC HyperNews version 1.11-slac-98, derived from the original HyperNews


[ Geant 4 Home | Geant 4 HyperNews | Search | Request New Forum | Feedback ]