makefile not taking -D flags


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting makefile not taking -D flags
# 1  
Old 04-22-2005
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

Code:
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.
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
Code:
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:

Code:
$(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
# 2  
Old 04-22-2005
You are supplying the -D flag too late. Your rule:
Code:
$(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.
# 3  
Old 04-22-2005
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.


Code:
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.
Code:
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
# 4  
Old 04-22-2005
Just add a rule for that one cpp.

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

# 5  
Old 04-25-2005
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Ifconfig Flags

Hi there, I need your help in understanding the below Solaris 10 ifconfig output; athnetspns02>ifconfig -a lo0: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1 inet 127.0.0.1 netmask ff000000 e1000g0:... (2 Replies)
Discussion started by: wthomas
2 Replies

2. UNIX for Dummies Questions & Answers

WHat are flags?

Can anybody actually tell, what is flag? I know they are termed as permission flags and various others. Please explain (3 Replies)
Discussion started by: nixhead
3 Replies

3. Homework & Coursework Questions

Help with Simple Multi-Level Makefile (Extremely New at Makefile)

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Basically, the prompt is make a makefile with various sub makefiles in their respective subdirectories. All code... (1 Reply)
Discussion started by: Tatl
1 Replies

4. UNIX for Dummies Questions & Answers

XLF90 Flags to PGF90

Hello, I am running into a bit of an issue running a Makefile. The problem is it was written for a xlf90 compiler when I have a pgf90 on the machine. Therefore, I keep getting errors regarding the xlf90 flags because they don't correspond with the pgf90. Here is the code: ... (0 Replies)
Discussion started by: lepagano
0 Replies

5. Shell Programming and Scripting

Need help to identify the flags by scripts.

Hi, I have two different scripts sap_ftp.sh and sap_ftp_dd.sh which are running continously in background. I am using another script called start.sh to launch these two scripts. Either one script will process files at a time . During that time other script will sleep.. Each script will... (1 Reply)
Discussion started by: bhargav20
1 Replies

6. UNIX for Advanced & Expert Users

Makefile problem - How to run module load in a Makefile

Hi, I'm trying to run the module load command in a Makefile and i'm getting the following error: make: module: command not found Why is this? Is there any way to run this command in a Makefile? NOTE: command - module load msjava/sunjdk/1.5.0 works fine outside of the Makefile (2 Replies)
Discussion started by: hernandinho
2 Replies

7. IP Networking

arp output (flags)

I'm running an arp -an on a Solaris 10 box. We're using IPMP. One of the systems is not able to see a host on the same network. The only difference between the two systems (one is having a problem, the other isn't) at least so far is the output of arp: # arp -an | grep 224.55 e1000g5... (1 Reply)
Discussion started by: BOFH
1 Replies

8. UNIX for Advanced & Expert Users

Processes Communication Only with flags!

hello everybody and a happy new year! i am trying the client-server model...i have no problem with sockets etc... especially for server:there is a father who is listening for TCP connections from clients,the later send commands which parent shares to his children. then children execute... (1 Reply)
Discussion started by: vaggelakis
1 Replies

9. AIX

question concerning Grep flags

Hey all. I am trying to find a process that is running and appending it to a file. The comman I am using is ps -eaf |grep tctl. The problem is, it returns the tctl process as well as the grep process that I just ran. Is there a flag that will prevent the command from returning itself? ... (2 Replies)
Discussion started by: jalge2
2 Replies

10. UNIX for Dummies Questions & Answers

if flags

Hi folks. I'm just starting to teach myself shell scripting and am having some trouble with an if statement. I am working with a directory where only one file will reside at a time and need to evaluate if this file is compressed to determine subsequent steps. I'm using echo for testing purposes.... (2 Replies)
Discussion started by: kristy
2 Replies
Login or Register to Ask a Question