LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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


Closed Thread
  Search this Thread
Old 03-06-2012, 01:35 PM   #1
abhishekgit
Member
 
Registered: Jan 2012
Location: India
Distribution: Ubuntu, Gentoo, Fedora, Rhel5,openSUSE
Posts: 165

Rep: Reputation: 12
Regarding makefiles


Hey everyone, I need your help.
After writeing a simple hello world kernel module named hello-world.c, I require to write a make file to compile it. Now, where to write this make file and what should be its extention. Kindly help, Thanks...
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 03-06-2012, 01:43 PM   #2
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,552

Rep: Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112
For the simplest solution, write the makefile in the same directory as your source. There is no extension, name it "makefile" if you want make to find it automatically, or name it anything you want and tell make where to find it with the -f flag, eg:
Code:
make -f sally

Last edited by suicidaleggroll; 03-06-2012 at 01:44 PM.
 
Old 03-06-2012, 01:44 PM   #3
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 19,272

Rep: Reputation: 4440Reputation: 4440Reputation: 4440Reputation: 4440Reputation: 4440Reputation: 4440Reputation: 4440Reputation: 4440Reputation: 4440Reputation: 4440Reputation: 4440
Quote:
Originally Posted by abhishekgit View Post
Hey everyone, I need your help.
After writeing a simple hello world kernel module named hello-world.c, I require to write a make file to compile it. Now, where to write this make file and what should be its extention. Kindly help, Thanks...
Putting "linux kernel module programming tutorial" into Google pulls this up as the first hit:
http://tldp.org/LDP/lkmpg/2.6/html/

Did you try that? Maybe reading the part on 'Compiling Kernel Modules', that has EXAMPLES of the makefile needed for the hello world module??? Not meaning to sound nasty, but you posted questions about how to copy/move files, and now you're trying to do kernel programming? You need to learn the basics first.
 
Old 03-08-2012, 08:25 AM   #4
abhishekgit
Member
 
Registered: Jan 2012
Location: India
Distribution: Ubuntu, Gentoo, Fedora, Rhel5,openSUSE
Posts: 165

Original Poster
Rep: Reputation: 12
@TBOne Yes you are correct. Thanks. Actually the basics are the part of my syllabus in college, and i am pretty much acqauinted now to change directory, rename, move and other terminal tasks so i thought this would be a good time to start with kernel. I am referring linux kernel in nutshell book. Do you have any better to suggest? Thanks.
 
Old 03-08-2012, 08:27 AM   #5
abhishekgit
Member
 
Registered: Jan 2012
Location: India
Distribution: Ubuntu, Gentoo, Fedora, Rhel5,openSUSE
Posts: 165

Original Poster
Rep: Reputation: 12
@suicidaleggroll Thanks. I dropped it since i am finding difficult to just download, configure and boot the kernel without making changes to it. I will have to try it after i understand the kernel. I am working on it. Thanks for your time.
 
Old 03-08-2012, 10:26 AM   #6
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 19,272

Rep: Reputation: 4440Reputation: 4440Reputation: 4440Reputation: 4440Reputation: 4440Reputation: 4440Reputation: 4440Reputation: 4440Reputation: 4440Reputation: 4440Reputation: 4440
Quote:
Originally Posted by abhishekgit View Post
@TBOne Yes you are correct. Thanks. Actually the basics are the part of my syllabus in college, and i am pretty much acqauinted now to change directory, rename, move and other terminal tasks so i thought this would be a good time to start with kernel.
Really?? Because just a couple of weeks ago, you did NOT know how to move a file:
https://www.linuxquestions.org/quest...nation-931262/

Before you start kernel programming, you need to learn a LOT of basic concepts. Basics of programming would be first...learning shell scripting would be a good start. Going from "how do you move a file" to "I'm going to write kernel modules", takes more than two weeks.
Quote:
I am referring linux kernel in nutshell book. Do you have any better to suggest? Thanks.
Yes, and I suggested it above. Did you read the link provided??
 
Old 03-08-2012, 12:43 PM   #7
abhishekgit
Member
 
Registered: Jan 2012
Location: India
Distribution: Ubuntu, Gentoo, Fedora, Rhel5,openSUSE
Posts: 165

Original Poster
Rep: Reputation: 12
@TBOne But i just want to see what it looks like. A very straight-forward process, download, configure, install and boot the kernel. That's what i was trying to do. Anyways, i will start with the basic terminal commands as you say. Thanks :-)
 
Old 03-08-2012, 12:59 PM   #8
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,552

Rep: Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112
What are you trying to modify in the kernel? Building custom kernels and installing kernel modules are not things you do when you're a beginner, at all. Hell, I've been using Linux basically every day for the last 8 years and I still don't compile my own kernel or write kernel modules (except for some VERY rare instances). It's not something you need to be concerned with unless you're REALLY digging into the nitty gritty. There are much more important things to educate yourself on before you dive into the kernel.

If you don't know how to use makefiles, you're not ready to mess with the kernel. Give it a few months/years.

Last edited by suicidaleggroll; 03-08-2012 at 01:01 PM.
 
2 members found this post helpful.
Old 03-08-2012, 01:25 PM   #9
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen, DK
Distribution: pclos2017 CentOS6.9 CentOS7.3 + 50+ other Linux OS, for test only.
Posts: 16,742

Rep: Reputation: 3318Reputation: 3318Reputation: 3318Reputation: 3318Reputation: 3318Reputation: 3318Reputation: 3318Reputation: 3318Reputation: 3318Reputation: 3318Reputation: 3318
For the hello.c program, the Makefile is :
Code:
obj-m    := hello.o

KDIR    := /lib/modules/$(shell uname -r)/build
PWD    := $(shell pwd)

default:
	$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
... And better wait some long time before you compile the complete kernel.
At worst, you will not be able to use your OS, if you install it.

.
 
2 members found this post helpful.
Old 03-09-2012, 09:05 AM   #10
abhishekgit
Member
 
Registered: Jan 2012
Location: India
Distribution: Ubuntu, Gentoo, Fedora, Rhel5,openSUSE
Posts: 165

Original Poster
Rep: Reputation: 12
@suicidaleggroll No no...I was trying to write a hello world module but i realized it was beyond my scope, so knowing a few terminal commands, bit of shell scripting and system programming using system calls, I just want to see how it looks like by just downloading the source and building it referring my books. "No modifications at all". Is it so difficult? Just boot from the downloaded source, that's
what i was trying to do. :-)
 
Old 03-10-2012, 11:54 AM   #11
TheIndependentAquarius
Senior Member
 
Registered: Dec 2008
Posts: 4,680
Blog Entries: 29

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
Quote:
Originally Posted by abhishekgit View Post
I was trying to write a hello world module but i realized it was beyond my scope
Everything will be beyond your scope if you don't start from the "start".
 
1 members found this post helpful.
Old 04-06-2012, 03:49 AM   #12
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
This topic has been re-posted in the kernel forum. Discussion follows there: https://www.linuxquestions.org/quest...efiles-933052/.
 
  


Closed Thread


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
Makefiles... ejohns85 Programming 4 07-11-2011 07:50 AM
makefiles wmoti Programming 5 09-21-2005 04:26 AM
Makefiles deveshs Linux - Software 2 05-02-2005 06:26 AM
Those makefiles... boku Programming 10 03-01-2005 09:19 AM
MAKEFILEs shinpadsmt Linux - Newbie 3 02-21-2004 03:52 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:44 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