Generic Makefile

Here is a generic Makefile that I have been using for some of my projects. I thought it might be useful for someone else that didn’t want to use the SDK templates like I didn’t. Feel free to use it or make sugestions to make it better.

# Makefile

#

# author      : sam adams

# version     : 0.1

# date        : 20071017

# discription : generic Makefile for making cuda programs

#

BIN               := gpu_program

# flags

CUDA_INSTALL_PATH := /usr/local/cuda

INCLUDES          += -I. -I$(CUDA_INSTALL_PATH)/include

LIBS              := -L$(CUDA_INSTALL_PATH)/lib

CFLAGS            := -O3

LDFLAGS           := -lrt -lm -lcudart

# compilers

NVCC              := nvcc

CC                := g++

LINKER            := g++

# files

C_SOURCES         := $(wildcard *.c)

CU_SOURCES        := $(wildcard *.cu)

HEADERS           := $(wildcard *.h)

C_OBJS            := $(patsubst %.c, %.o, $(C_SOURCES))

CU_OBJS           := $(patsubst %.cu, %.o, $(CU_SOURCES))

$(BIN): clean $(C_OBJS) $(CU_OBJS) $(HEADERS)

        $(LINKER) -o $(BIN) $(CU_OBJS) $(C_OBJS) $(LDFLAGS) $(INCLUDES) $(LIBS)

$(C_OBJS): $(C_SOURCES) $(HEADERS)

        $(CC) -c $(C_SOURCES) $(CFLAGS) $(INCLUDES)

$(CU_OBJS): $(CU_SOURCES) $(HEADERS)

        $(NVCC) -c $(CU_SOURCES) $(INCLUDES)

run: $(BIN) 

        LD_LIBRARY_PATH=$(CUDA_INSTALL_PATH)/lib ./$(BIN)

clean:

        rm -f $(BIN) *.o

Hallo Sam,

I implemented a makefile system for building my application, it can either use MS ‘nmake’ or the classical GNU ‘make’. The strange thing is that nvcc cannot start if I launch it from the ‘make’ tool, while everything is ok if I use GNU ‘make’… see my post
http://forums.nvidia.com/index.php?showtopic=56803&hl=tasora

Have you experienced the same thing?

Has someone used ‘nmake’ and nvcc? …

Alessandro Tasora