Other Makefile techniques
Building C files
This is very similar to C++ files
Standard definitions
Addtional definitiions are required for C files
# Standard rules and flags
CC = gcc
CCALLFLAGS =
Setting the build rules
And a new build rule is required
$(BUILD)/%.o : %.c Makefile
$(CC) -c $(CCALLFLAGS) $(INCLUDES) -o $@ $<
Including all files in a subdirectory
The following will create a list of all .cpp files in a directory, in this case cisGenomeLib. Useful if you want all of the files, and the Makefile to automatically adjust for the inclusion of any additional files.
LIBSRCDIR = cisGenomeLib
LIBSRC = $(shell find $(LIBSRCDIR) -name *.cpp)
Adding a path to a file list
The following will add a common prefix to a list of files. Useful if you want a lengthy subset of files from a subdirectory
LOCALLIBDIR = cfiles
LIBSRCFILES = AffyLib.c GenomeLib.c MathLib.c MatrixLib.c MicroarrayLib.c MotifLib.c RandomLib.c \
SequenceLib.c StringLib.c PhysicalNetworkLib.c WorkLib.c FlexModuleInterface.c
LIBSRC = $(addprefix $(LOCALLIBDIR)/, $(LIBSRCFILES) )
Making a static library
A static library is essentially a tar file containg a set of object files. Two changes are required in order to build a static library
Specify the build outputs
The following specifys the .a library file, assuming that cygwin is being used
################################################################################
# Outputs of this Makefile
LIBCISGENOME = $(BUILD)/libcisGenome.a
TARGS = $(LIBCISGENOME)
The target definitions
These are typically much simpler for a static library as there is typically no linking to other libraries at this stage
$(LIBCISGENOME) : $(LIBOBJS)
ar -r $@ $(LIBOBJS)