common.mk "bug" SRCDIR variable is useless

Hi,

In trying to modify [font=“Courier”]common.mk[/font] to use it for my own purposes, I’ve run across a problem and an inconsistency when modifying the [font=“Courier”]SRCDIR[/font] variable. Apologies if this is a repeat, I’ve done some Googleing and forum searches and have turned up empty. Also apologies if this is something that should be obvious but I’m only recently becoming acquainted with the subtleties of [font=“Courier”]make[/font].

I’ve attached the modified common.mk from CUDA 2.0 Beta 1. I havn’t used Beta 2, however I did verify that this problem would still exist. I don’ think this is the issue, but I’m using a 64 bit Linux build of the SDK.

The default [font=“Courier”]common.mk[/font] from the SDK has a section that looks like this. Fine.

SRCDIR     ?= 

ROOTDIR    ?= ..

ROOTBINDIR ?= $(ROOTDIR)/../bin

If one moves a sample project outside of the SDK (and keep the resulting build in that directory), one has to make some changes. Again, fine.

SRCDIR     ?= 

ROOTDIR    ?= .

ROOTBINDIR ?= $(ROOTDIR)/bin

Now, if one wants to put all the source into a separate [font=“Courier”]src[/font] directory, and make use of the [font=“Courier”]SRCDIR[/font] variable, intuitively one would move their code, and change the section to look like this:

SRCDIR     ?= src

ROOTDIR    ?= .

ROOTBINDIR ?= $(ROOTDIR)/bin

Unfortunately, this causes [font=“Courier”]make[/font] to fail. The reason is that the [font=“Courier”]SRCDIR[/font] is not treated in a manner consistent with the other directory variables. First, anywhere [font=“Courier”]$(SRCDIR)[/font] prepends a statement, it is implied that the trailing [font=“Courier”]/[/font] is already there, not so with [font=“Courier”]OBJDIR[/font] and the like. To correct this, any [font=“Courier”]$(SRCDIR)[/font] needs to be replaced with [font=“Courier”]$(SRCDIR)/[/font]. E.g,

$(OBJDIR)/%.c_o : $(SRCDIR)%.c  $(C_DEPS)

becomes

$(OBJDIR)/%.c_o : $(SRCDIR)/%.c  $(C_DEPS)

The larger issue is that if one has dependencies listed in [font=“Courier”]C_DEPS[/font], [font=“Courier”]CC_DEPS[/font], or [font=“Courier”]CU_DEPS[/font], then the existing make file is inadequate, no matter what slash strategy is used. As it stands, the following code does not search [font=“Courier”]src[/font] for the dependencies.

$(OBJDIR)/%.cpp_o : $(SRCDIR)/%.cpp $(CC_DEPS)

This needs to be replaced with

$(OBJDIR)/%.cpp_o : $(SRCDIR)/%.cpp  $(patsubst %, $(SRCDIR)/%, $(CC_DEPS))

or you can add the [font=“Courier”]src[/font] path to every dependency, which sort of defeats the point of using the variable.

I’ve corrected this everywhere I can see, except that I didn’t muck with the cubin sections other than to fix the slash issue as I’m not familiar enough with what is used there. I’ve attached a corrected version, lines I have modified are marked with a [font=“Courier”]–RJH[/font] tag.

I hope this saves someone as or less knowledgeable than me the couple of hours I spent sorting this out.

Cheers,

Russ Hewett
common.mk.txt (9.92 KB)