makefile for multiple units

I just separate one of my cuda program into multiple units for clarity, some of the units are .c, others are .cu. now I am having some problems to make a good makefile.

In the past, if I have a single .cu file, I have a makefile looks like this:

all:

		$(CUDACC) -c $(OPT) $(SOURCE).cu -o $(OUTPUT_DIR)/$(SOURCE)

fast:

		$(CUDACC) -c $(OPT) $(SOURCE).cu -o $(OUTPUT_DIR)/$(SOURCE) -DFAST_MATH

cache:

		$(CUDACC) -c $(OPT) $(SOURCE).cu -o $(OUTPUT_DIR)/$(SOURCE) -DUSE_CACHE

...

but now, I found nvcc can not compile and link multiple units in the same command line, i.e., the following does not work:

$(CUDACC) -c $(OPT) $(SOURCE).cu unit2.c unit3.cu -o $(OUTPUT_DIR)/$(SOURCE)

I am wondering if anyone can suggest a good structure for this type of project: compile/link multiple units for different targets?

thank you

Hi,
Probably can be nicer but this is what I’ve done:

Target name (executable or library)

TARGET=libGeoEngine${CCCNAME}${PLATFORM_TYPE}.so

nVidia compiler settings.

NVCC=/usr/local/cuda/bin/nvcc
NVCC_PARAMS=–ptxas-options=“-v -mem” -arch sm_13 -maxrregcount=30 --compiler-options=“-fno-strict-aliasing -fPIC”

CUDA related source files.

CUDA_SRC1=GenericEngine/GPU/GGPUGenericEngine.cu
CUDA_SRC2=GenericEngine/GPU/GGPUDiffractionEngine.cu
CUDA_OBJS1=GenericEngine/GPU/GGPUGenericEngine.o
CUDA_OBJS2=GenericEngine/GPU/GGPUDiffractionEngine.o

OBJS - A list of the objects linked to be the target

OBJS=GFullSearchMft.o GAngleCreCeeSearch.o GHiSearch.o GHIMatrixSearch.o G2InversMultifocusing.o

Compiling the target

$(TARGET): $(OBJS) $(CUDA_OBJS1) $(CUDA_OBJS2)
$(CCC) $(LDFLAGS) ${CPPFLAGS} $(OBJS) $(CUDA_OBJS1) $(CUDA_OBJS2)
/bin/rm -f $(SSHOME)/${LIB_DIR}/$(TARGET)
ln -fs pwd/$(TARGET) $(SSHOME)/${LIB_DIR}/$(TARGET)

$(CUDA_OBJS1): $(CUDA_SRC1)
$(NVCC) $(NVCC_PARAMS) -I ~build/NVIDIA_CUDA_SDK/common/inc/ -I /home/build/build -I /home/build/build -I. -I /usr/local/include -I /usr/include -I /usr/local/cuda/include -O3 -DUNIX -o $(CUDA_OBJS1) -c $(CUDA_SRC1)

$(CUDA_OBJS2): $(CUDA_SRC2)
$(NVCC) $(NVCC_PARAMS) -I ~build/NVIDIA_CUDA_SDK/common/inc/ -I /home/build/build -I /home/build/build -I. -I /usr/local/include -I /usr/include -I /usr/local/cuda/include -O3 -DUNIX -o $(CUDA_OBJS2) -c $(CUDA_SRC2)

clean:
/bin/rm -f $(SSHOME)/${LIB_DIR}/$(TARGET)
/bin/rm -rf $(OBJS) $(CUDA_OBJS1) $(CUDA_OBJS2) $(TARGET)

include ${SSHOME}/Infra/Make/general.mk

CCFLAGS - General compilation flags

LDFLAGS += -lcudart -lcuda -lcutil
LDFLAGS += ${SHARED_COMPILER_FLAG} -o ${TARGET}