LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 12-18-2009, 09:05 AM   #1
RudraB
Member
 
Registered: Mar 2007
Distribution: Fedora
Posts: 262

Rep: Reputation: 23
awk inside makefile


I am trying to put a time-stamp in my tar file as:
Code:
distro:
	cp -r LMTO-A LMTO-B lmto/ ASR/ makefile Doc extras
	date>date1
	tstp=`awk '{print $3,$2,$6}' date1`
#	@echo $${tsps}
	make -f extras/makefile clean
	mkdir extras/LMTO-ASR-DISTRO
	cp -r extras/LMTO-A extras/LMTO-B extras/lmto/ extras/ASR/ extras/makefile extras/Doc extras/LMTO-ASR-DISTRO
	tar -zcf extras/lmto-asr-$${tstp}.tar.gz extras/LMTO-ASR-DISTRO
	rm -rf extras/LMTO-ASR-DISTRO
Ithis part is inside a Makefile. It is not working. Where its gong wrong?
 
Old 12-18-2009, 09:42 AM   #2
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
You can certainly call "awk" from a makefile...

... but you can't use this syntax unless you're actually in the shell:
Quote:
# OK for shell, not OK for inside of a makefile:
tstp=`awk '{print $3,$2,$6}' date1`
SUGGESTIONS:
You might be able to use "bash -c" or "$shell()":

http://www.gnu.org/software/automake...Shell-Function

http://stackoverflow.com/questions/5...kefile-targets

http://www.netbsd.org/docs/pkgsrc/makefile.html

'Hope that helps .. PSM

Last edited by paulsm4; 12-18-2009 at 09:44 AM.
 
Old 12-18-2009, 11:51 AM   #3
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 2,467

Rep: Reputation: 846Reputation: 846Reputation: 846Reputation: 846Reputation: 846Reputation: 846Reputation: 846
Every command for a Makefile target is run in a shell. However, every line is run in its own shell.
Code:
tstp=`awk '{print $$3,$$2,$$6}' date1`
Is legal but useless since the assignment to tstp only remains in effect for that line. Note that you need 2 $'s otherwise Make substitutes its own variables.

psaulm4's suggestion of using the $shell() function is probably a better idea, but you could also do this:
Code:
distro:
	cp -r LMTO-A LMTO-B lmto/ ASR/ makefile Doc extras
	tstp=`date | awk '{print $$3,$$2,$$6}'` ;\
		make -f extras/makefile clean ;\
		mkdir extras/LMTO-ASR-DISTRO  ;\
		cp -r extras/LMTO-A extras/LMTO-B extras/lmto/ extras/ASR/ extras/makefile extras/Doc extras/LMTO-ASR-DISTRO ;\
		tar -zcf extras/lmto-asr-$${tstp}.tar.gz extras/LMTO-ASR-DISTRO ;\
		rm -rf extras/LMTO-ASR-DISTRO
The backslashes escape the newlines so all the commands are on a single line and therefore in the same shell.
 
1 members found this post helpful.
  


Reply

Tags
makefile


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
shell function inside foreach in Makefile germallon Linux - Software 2 10-14-2009 10:31 AM
Sed inside awk ZAMO Linux - General 1 02-26-2009 04:13 AM
shell command using awk fields inside awk one71 Programming 6 06-26-2008 04:11 PM
awk inside a makefile linux.fob Programming 2 10-12-2005 04:57 PM
Can I use grep inside awk? Helene Programming 6 04-27-2004 12:58 AM


All times are GMT -5. The time now is 06:01 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration