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, %.o, $(CU_SOURCES))

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

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


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


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

run: $(BIN) 



        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

Have you experienced the same thing?

Has someone used ‘nmake’ and nvcc? …

Alessandro Tasora