Creating dependency file using rule


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Creating dependency file using rule
# 1  
Old 05-15-2011
Creating dependency file using rule

hi,
I am trying to create dependency files using this rule, and I am having trouble with the $@.$$$$

Code:
%.d: %.cpp
 $(CC) -MM $< > $@.$$$$; \
	sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
	rm -f $@.$$$$

when I run the command, it generates the following:
Code:
$gcc  -MM foo.cpp > foo.d.$$
sed 's'\(foo\)\.o[ :],\1.o foo.d : ,g' <foo.d.$$> foo.d
rm -f foo.d.$$
/bin/sh: foo.d.4325: No such file or directory
make: *** [foo.d] Error 1

can anybody pls tell me how I can fix this foo.d.$$ problem

thx,
BA

Last edited by Franklin52; 05-16-2011 at 03:58 AM.. Reason: Please use code tags
# 2  
Old 05-16-2011
The $$ in the gcc line, I believe, will be different from the one in the sed line, so your sed will be operating on a different file from the one generated by the gcc. Try storing $$ into another variable and then using that everywhere.
This User Gave Thanks to JerryHone For This Post:
# 3  
Old 05-16-2011
thanks.
I'll try that and let you know if it works!
# 4  
Old 05-17-2011
It looks like you're just using $@.$$$$ very briefly as a temporary file, whose name doesn't matter.
Why not use a different name that doesn't use dollar signs?

$@.TEMP

Or even the same filename for every rule, with no $s or @ at all, since it will be deleted before the next command begins.

BTW, I trust you are working on Makefile rules, though you never mentioned it. Smilie
This User Gave Thanks to KenJackson For This Post:
# 5  
Old 05-17-2011
yes indeed, I am working on a makefile - sorry for not having mentioned that earlier.
I actually replaced $@.$$$$ with $@.tmp and it did work, so you're right. but I was stuck upon understanding why it shouldn't work with the $'s.
It seems like what JerryHone mentioned regd. the sed and gcc having a different $$ value could be the problem - trying to play around with that.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Get the missing dependency from two files

#cat hwlock-full.dep libx11-6 >= 1.4.4 libz1 >= 1.2.7 libtinfo5 >= 5.9 libxcb1 >= 1.8.1 numactl >= 2.0.8+rc4 libpixman-1-0 >= 0.29.2 libxml2 >= 2.7.8 libxext6 >= 1.3.1 libxrender1 >= 0.9.7 libfreetype6 >= 2.4.9 libxcb-render0 >= 1.8.1 libcairo2 >= 1.12.14 libc6 >= 2.15 libxcb-shm0... (7 Replies)
Discussion started by: yanglei_fage
7 Replies

2. Shell Programming and Scripting

Processing Dependency Printing

Gurus, I came across a typical requirement where the input is like- TRANS FIRM DEPT CUST TRANS CUST TRANS DEPT FIRM CUST & the expected Output is- CUST DEPT FIRM TRANS This is basically a dependency list for processing the tables where FIRM is feeding data to TRANS... (3 Replies)
Discussion started by: kapeeljoshi
3 Replies

3. UNIX for Advanced & Expert Users

Scan all mail messages through the server and save a copy into file system following a rule

In our company we work for our customer with a job# philosophy, managing all the informations about a job in a share with directories whose name is starting with job number. Under this entry point we have a standard structure of folders, comprising a "communications" folder. When we send emails... (0 Replies)
Discussion started by: vroby67
0 Replies

4. Emergency UNIX and Linux Support

Changing executable dependency

hello, can anyone help in changing the executable dependency on a certain shared library. eg, .. say i am having an executable by name utest. when i run UNIX ldd command on it then it shows the libraries on which it depends as follows: ldd release/utest release/utest needs: ... (4 Replies)
Discussion started by: skyineyes
4 Replies

5. HP-UX

Library dependency coming out of nowhere

I'm building on a HP-UX ia64 system. During building, I'm getting an error ld: Can't find dependent library "libnnz10.so" Nowhere in my makefile do I link with this library. This library is there in the directory /databases/oracle10.2.0_64BIT/lib. I'm having two source files ora8ibulk.cpp... (1 Reply)
Discussion started by: old_as_a_fossil
1 Replies

6. Shell Programming and Scripting

generate a file from existing file based on some rule

Hi guys, i have a file in below format.let me explain first what i am trying to do . i am making a file from this file , will rearrange these columns, then i will run several command(start/stop mentioned in this file) on unix environment. my requirements : 1. i have 27 servers , on each server... (4 Replies)
Discussion started by: deepakiniimt
4 Replies

7. UNIX for Dummies Questions & Answers

make -j dependency

Hi, I had a make file, something like that, all: cd dir1; make cd dir2; make the problem is the makefile under dir2 need some objs from dir1, so I need to set some dependency let dir2 run only after the dir1 run is done. how to set the dependency? Thanks. peter (2 Replies)
Discussion started by: laopi
2 Replies

8. Infrastructure Monitoring

Weird dependency problem!

Hi, I want to install net-snmp-devel package but i have following dependecy problem. It's very odd, i don't get it. One of packages is depended on the other one, the other one is depended on the previous one as well. :S :S Could you help me please? Here are the steps: # ls -l total... (4 Replies)
Discussion started by: oduth
4 Replies

9. Solaris

Dependency problem

Hi all am new to solaris ............ i installed amanda client pkg that time am getting lots of dependency problem.......... is there any Yum server like things in solaris Regards ' prAn (8 Replies)
Discussion started by: pran
8 Replies

10. UNIX for Dummies Questions & Answers

process dependency

how to find all the processes associated with a given process in unix,is there any command for this. (3 Replies)
Discussion started by: laddu
3 Replies
Login or Register to Ask a Question

Featured Tech Videos