LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-03-2012, 09:07 PM   #1
diamond_D
Member
 
Registered: Jul 2005
Posts: 51

Rep: Reputation: 0
Makefile question


I'm just reading trying to get a further understanding of building and installing kernel modules. I'm looking at some Makefile examples and notice the pattern that they seem to follow, For example:
Quote:
obj-m := hello.o
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
I'm not much of a scripting guy but I'm confused about the KDIR target when it uses variable $(shell uname -r) as the target. Shouldn't it be just $(uname -r), command substitution does not work for me with shell included.

Quote:
[delslige@Fedora-VM1 modules]$ echo $(uname -r)
2.6.40.4-5.fc15.i686.PAE
[delslige@Fedora-VM1 modules]$ echo $(shell uname -r)
-bash: shell: command not found
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 03-03-2012, 09:13 PM   #2
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 370Reputation: 370Reputation: 370Reputation: 370
A Makefile is not a shell script. A Makefile has its own variable assignment and substitution syntax.

What is confusing is that the Makefile syntax uses some very similar syntax to bash shell scripts. So it's easy to get them confused.

In the Makefile, you must use $(shell [command]) to tell the make command to issue a shell command and substitute the output. That's just how it works. See the GNU Make Manual for all the gory details.

And as a side note, in your example, neither KDIR nor $(shell ...) is a "target." KDIR is a Makefile variable and $(shell ...) is a function call. A target is always defined as "<target name> : <target dependencies>"

Last edited by Dark_Helmet; 03-03-2012 at 09:15 PM.
 
2 members found this post helpful.
Old 03-03-2012, 09:16 PM   #3
diamond_D
Member
 
Registered: Jul 2005
Posts: 51

Original Poster
Rep: Reputation: 0
I have a lot to learn. Thanks for clearing that up.
 
  


Reply


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
Question about a makefile axelfc Programming 5 10-08-2010 07:40 AM
Makefile question orgcandman Programming 3 02-27-2008 01:04 PM
makefile question ashwin.tanugula Programming 2 10-26-2005 04:08 PM
Question about makefile taureanyang Programming 1 03-26-2005 12:57 AM
makefile question blackzone Programming 2 12-20-2004 08:03 AM


All times are GMT -5. The time now is 04:27 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration