Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Makefile w. Protocol Buffer and Automatic Dependency

I have a Makefile something like this:

.SECONDARY:

NVCC = nvcc
NVCCFLAGS = --gpu-architecture compute_20

CXX = g++
CXXFLAGS = -O3 -std=c++0x -Wall

CXXLINT = python cpplint.py
CXXLINTFLAGS = --filter=-build/include,-readability/streams,-runtime/sizeof,-whitespace/parens

PROTOC = protoc
PROTOCFLAGS = --cpp_out=.

BINS = my_binary
LIBS = -lcublas -lcusparse
PROTOS = $(wildcard *.proto)
SOURCES = $(wildcard *.cu)
HEADERS = $(wildcard *.cuh)
PBS = $(PROTOS:%.proto=%.pb)
DEPS = $(SOURCES:%.cu=%.d)
TESTS = my_test

all: lint protos
all: deps
all: bins
protos: ${PBS}
deps: ${DEPS}
bins: ${BINS}

clean:
    rm -rf *.o *.d *.pb.cc *.pb.h ${BINS} ${TESTS}

lint:
    ${CXXLINT} ${CXXLINTFLAGS} ${SOURCES}
    ${CXXLINT} ${CXXLINTFLAGS} ${HEADERS}

tests: lint protos
tests: deps
tests: ${TESTS}
tests: tests-run
tests-run: ${TESTS}
    for f in $^; do eval "/usr/bin/time -f \"$$f runtime: %E\" ./$$f"; done

%: %.o
    ${NVCC} ${NVCCFLAGS} -o $@ $^ ${LIBS}

%.d: %.cu
#   ${CXXLINT} ${CXXLINTFLAGS} $*.cu
    ${NVCC} -M -o $*.d $*.cu

%.o: %.cu
    ${NVCC} ${NVCCFLAGS} -c -o $@ $*.cu
    rm $*.d

%.pb: %.proto
    ${PROTOC} ${PROTOCFLAGS} $*.proto
    ${CXX} ${CXXFLAGS} -c -o $*.pb.o $*.pb.cc

ifneq ($(MAKECMDGOALS),clean)
-include ${DEPS}
endif

The problem occurs since I can not generate my DEPS until my proto target is built. Because building the protocol buffers will add a new header file to the tree, if this isn't done first before the DEPS, the nvcc -M (make dependency) will fail since it can not find the *.pb.h that is generated. Any ideas how to fix this?

like image 815
user1510702 Avatar asked Jul 09 '12 17:07

user1510702


1 Answers

When building the dependencies, you could opt to continue even if header files are missing. Using cpp or gcc, that can be achieved by using the options -MM -MG. I have no experience with NVCC, but I did not see any support those flags in the manual. If that is true, then you could try switching to cpp for the dependency generation only. From the cpp man page:

-MG assumes missing header files are generated files and adds them to the dependency list without raising an error.

Your pattern rule %.pb: %.proto does not seem right to me, by the way. It is %.pb.h and %.pb.cc that depend on %.proto and with the current approach, make will not know how to resolve any dependencies on %.pb.h because it will not know how to create the .pb.h file.

like image 123
Reinier Torenbeek Avatar answered Nov 16 '22 19:11

Reinier Torenbeek