Skip to main content Skip to navigation

Source files from elsewhere in the directory structure

In this example, I show the changes that need to be made to allow the files in the cisGenomeLib subdirectory in the previous example to be built using files from elsewhere in the directory structure, in this case ../cisgenome_tools.

All additions are in italics

Directory information

We add the information about the new source location

################################################################################
# Directory information

CISGENOMEDIR = ../cisgenome_core
CISGENOMETOOLSDIR = ../cisgenome_tools
INCLUDES=-I$(CISGENOMETOOLSDIR)/cisGenomeLib -I$(CISGENOMEDIR)/cfiles

Setting the build commands

A new build command is required in addition to ensure that .o files generated from .cpp files in the $(CISGENOMETOOLSDIR) directory which may be from somewhere else in the filesystem are placed into the local $(BUILD) directory with the $(CISGENOMETOOLSDIR) root stripped off.

##################################################################
#
# Instructions for building object files These are dependant on the Makefile so Makefile changes
# force a rebuild. Rule for files in the CISGENOMETOOLSDIR ensures that the .o is placed
# in the local object directory to keep it neat

$(BUILD)/%.o : $(CISGENOMETOOLSDIR)/%.cpp Makefile
$(CCC) -c $(CCCALLFLAGS) $(INCLUDES) -o $@ $<

$(BUILD)/%.o : %.cpp Makefile
$(CCC) -c $(CCCALLFLAGS) $(INCLUDES) -o $@ $<

Make depends

The makedepend will not show the correct location for the .o files associated with the library from elsewhere in the file system, so after makedepend has modified the Makefile, we then use sed to correct the filepaths that have been generated. After the modification, the dependancy lines are exactly the same as if the library files were local.

# do 'make depend' from the command line to update dependancies.
# This makes a dependancy list that is dynamically dependant
# on the build type. Note the default assumes that the .o location is the same as the .cpp location,
# so the .o location has to be modified to reflect that it is being compiled into a local location
# Note the use of % as an alternative separator
# sed seems to leave the file ro, so use chmod to make it readwrite

depend :
makedepend -Y $(CCCAALLFLAGS) $(INCLUDES) $(SOURCES) -p'$$(BUILD)/'
sed -i 's%$$(BUILD)/$(CISGENOMETOOLSDIR)%$$(BUILD)%g' Makefile
chmod a+rw Makefile

# DO NOT DELETE THIS LINE -- make depend depends on it.

$(BUILD)/cisGenomeLib/genomeFile.o: ../cisgenome_tools/cisGenomeLib/pch.h
$(BUILD)/cisGenomeLib/genomeFile.o: ../cisgenome_core/cfiles/StringLib.h
$(BUILD)/cisGenomeLib/genomeFile.o: ../cisgenome_core/cfiles/SequenceLib.h