makefile not taking -D flags

Hi,

I found this strange behaviour while using one of the makefiles.

Here is the snippet of the unix.mak that is necessary for this context

SO              = SvSocket.o SvStmt.o SvOdbcWrapper.o \
                  OdbcCallReader.o MgrCalls.o OdbcSvProxy.o \
                  OdbcSvApp.o SvStatus.o

DAEMON_SO = libolsv2040.so

libolsv: $(DAEMON_SO)

$(DAEMON_SO): $(SO) *.h
        $(CC) -DODBCSV_SO -shared -export-dynamic -o $(DAEMON_SO) $(SO)
        @echo $(DAEMON_SO) has been built.

There is no error that throws up when running the makefile.

The following is the snippet for the ODBCSV_SO code.

/*
#include headerfiles
*/

#if defined unix || defined ODBCSV_SO

// only for libolsv2040.so
#ifdef ODBCSV_SO
/* 
Code for libolsv2040.so
*/
#endif

#elif defined(ODBCSV_DLL) // only for olsv2040.dll
/* 
Code for olsv2040.dll
*/

#else   // only for olsv.exe
/* 
Code for olsv.exe
*/
#endif

/*
Common code for all
*/

Now when I issue

make -f unix.mak libolsv

, it should make the libolsv2040.so; i.e. it should enter into the code fragment for ODBCSV_SO.

It isnt doing so. The flags are also set in the makefile. Even then the same.

Though the so is begin created, the methods in the code fragment doesnt get exported at all.

Tried re-arranging the command like this:

$(DAEMON_SO): $(SO) *.h
        $(CC) -shared -export-dynamic -DODBCSV_SO -o $(DAEMON_SO) $(SO)

Still it doesnt help.

Any pointers on why this behaviour ?

Vino

You are supplying the -D flag too late. Your rule:

$(DAEMON_SO): $(SO) *.h
        $(CC) -DODBCSV_SO -shared -export-dynamic -o $(DAEMON_SO) $(SO)
        @echo $(DAEMON_SO) has been built.

is taking a bunch of .o files and shoving them into a so file. The -D flag can't affect a .o file. Even if the .o file does not exist when this rule is invoked the -D flag does no good. The missing .o is generated by some other rule, perhaps a builtin.

Perderabo, you are right. I did find that out on further analysis.

A question. Is there any way I can over-ride the builtin rule for .cpp.o ?

The structure of the makefiles is as follows:

There is a universal makefile for the whole component. That in turn traverses to each of the directory inside and then calls the makefile of the respective sub-component.

Now in the universal makefile, the rules are defined for .cpp.o and other targets too.

In this particular sub-comp of DAEMON_SO, the make file is such that you do a make once to create the executables, followed by a clean and then a make for the creation of .so. So for the case of .so an extra flag -DODBCSV_SO is introduced. I wrote a rule for the OdbcSvApp.o. OdbcSvApp.cpp is responsible for the .so.

SO              = SvSocket.o SvStmt.o SvOdbcWrapper.o \
                  OdbcCallReader.o MgrCalls.o OdbcSvProxy.o

OSVAPP          = OdbcSvApp.o
OSVAPP : OdbcSvApp.cpp
        $(CC) -c $(CFLAGS) -DODBCSV_SO -o $(OSVAPP) 

$(DAEMON_SO): OdbcSvApp.o $(SO) *.h
        $(CC) -shared -export-dynamic -DODBCSV_SO -o $(DAEMON_SO) $(OSVAPP) $(SO)
        @echo $(DAEMON_SO) has been built.

Now after issuing make -f unix.mak libolsv, it all goes through peacefully. But, still -DODBCSV_OS does not get included in the rule for OdbcSvApp.cpp. Which shows, my rule is not picked up. So, how can I over-ride the builtin rule for just one cpp file.

Another way out is surely introduce another make file for the .so. But since it is a workaround I dont intend to unless it is the ONLY way out.

The following is the result output( for clarity sakes) showing the compilation statement with flags and options.

g++ -DRS_V8 -DMD5Init=OLiteMD5Init -DMD5Update=OLiteMD5Update
-DMD5Final=OLiteMD5Final -Wall -Wunused -Wno-parentheses
-Wno-sign-compare -Wno-non-virtual-dtor -Wno-reorder -DNDEBUG -O3
-fomit-frame-pointer -mcpu=pentium3 -fPIC -DOOT_SHARED_MEM  
-I/usr/java/j2sdk1.4.1_07/include -I/usr/java/j2sdk1.4.1_07/include/linux -I. 
-D_REENTRANT -DOOT_SHARED_MEM -Dboolean=char -c -o OdbcSvProxy.o 
OdbcSvProxy.cpp

gcc -shared -export-dynamic -DODBCSV_SO -o libolsv2040.so OdbcSvApp.o  
SvSocket.o SvStmt.o SvOdbcWrapper.o OdbcCallReader.o MgrCalls.o 
OdbcSvProxy.o -lpthread -lrt -lm -ldl 
-L/usr/java/j2sdk1.4.1_07/jre/lib/i386/server -ljvm 
libolsv2040.so has been built.

-v

Just add a rule for that one cpp.

whatever.o: whatever.cpp
          somecompiler -Dmagicflag whatever.cpp -o whatever.o

Perderabo,

Thanks. That worked.

A question. Why did not

OSVAPP = OdbcSvApp.o
OSVAPP : OdbcSvApp.cpp
$(CC) -c $(CFLAGS) -DODBCSV_SO -o $(OSVAPP)

work ? Is it only because of the missing cpp file in the rule expansion ?

Vino