help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Dependency scanning using GNU make + Visual C++


From: Chad Loder
Subject: Dependency scanning using GNU make + Visual C++
Date: Thu, 05 Oct 2000 11:17:37 -0700

Hello all. I have been playing around with generating source
file dependencies for C and C++ files. For those of you using
GNUMake + gcc it will be trivial to accomplish, but for anyone
using Visual C++ there are some other considerations. I have
an implementation using makedepend (from the imake/X11 package)
which I believe to be correct, so I thought I would share it
and see if anyone has any corrections, improvements, etc.

What makes this problem somewhat difficult is that Visual C++
has some predefined preprocessor constants whose value depends
on which compiler flags you use. Another consideration is that
Visual C++ also has some #pragma directives which may affect
the preprocessor (and hence the dependency chain for a source
file).

The first problem is fairly easy to solve, except for 4 macros
whose values depend on the version of VC++ you're using. I
guess you could invoke CL.EXE (the compiler) and sed the version
string out of the "logo" it prints out. For convenience, I have
just defined these macros outright.

The other macro values depend on your compile flags (this is
well documented in MSDN). Therefore, I define them (or not)
depending on the value of $(CPPFLAGS) (so this has to be
done in the Makefile after CPPFLAGS has been set in stone).

# These are the correct values for Visual C++ 6.0.
DEFINES_MAKEDEPS += _M_IX86=500
DEFINES_MAKEDEPS += _MFC_VER=0x0421
DEFINES_MAKEDEPS += _MSC_VER=1200
DEFINES_MAKEDEPS += _WIN32=1

ifneq (,$(filter /J,$(CPPFLAGS)))
 DEFINES_MAKEDEPS += _CHAR_UNSIGNED=1
endif

ifneq (,$(filter /GR,$(CPPFLAGS)))
 DEFINES_MAKEDEPS += _CPPRTTI=1
endif

ifneq (,$(filter /GX,$(CPPFLAGS)))
 DEFINES_MAKEDEPS += _CPPUNWIND=1
endif

ifneq (,$(filter /MD,$(CPPFLAGS)))
 DEFINES_MAKEDEPS += _DLL=1
endif

ifneq (,$(filter /MDd,$(CPPFLAGS)))
 DEFINES_MAKEDEPS += _DLL=1
endif

ifneq (,$(filter /Za,$(CPPFLAGS)))
 DEFINES_MAKEDEPS += _MSC_EXTENSIONS=0
else
 DEFINES_MAKEDEPS += _MSC_EXTENSIONS=1
endif

# C++ files must have this defined by default. The compiler will do this
# for us, but makedepends knows nothing of it.
#
%.cppdeps : DEFINES_MAKEDEPS += __cplusplus=1

%.cppdeps : %.cpp
        echo \# DO NOT DELETE THIS LINE > $@
        makedepend -Y $(addprefix -D,$(DEFINES)) $(addprefix
-D,$(DEFINES_MAKEDEPS))    $(addprefix -I,$(INCLUDE)) $(addprefix
-I,$(INCLUDE_STD)) -f$@ -o$(O) $<

-include $(SOURCES:.cpp=.cppdeps)



And that's basically it -- you get the idea. It works for me.
I also have a "hack" that lets you read the dependency information
generated by Microsoft's compiler. VC++ can generate a .IDB file
containing dependency information in some alien, unreadable binary
format. I played around with extracting dependencies using the
following command:

strings /tmp/cl/Debug/vc60.idb | grep /ipm/header/
  | sed -e 's/\/ipm\/header\///' | grep \.h | sort | uniq

This appears to give the same results as makedepend, but if you
can get the makedepend solution to work, I would trust makedepend
more than this kludge. :)

I hope this helps someone.

        c





reply via email to

[Prev in Thread] Current Thread [Next in Thread]