LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Regarding makefiles (https://www.linuxquestions.org/questions/linux-newbie-8/regarding-makefiles-933052/)

abhishekgit 03-06-2012 12:35 PM

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

suicidaleggroll 03-06-2012 12:43 PM

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

TB0ne 03-06-2012 12:44 PM

Quote:

Originally Posted by abhishekgit (Post 4620067)
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.

abhishekgit 03-08-2012 07:25 AM

@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.

abhishekgit 03-08-2012 07:27 AM

@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.

TB0ne 03-08-2012 09:26 AM

Quote:

Originally Posted by abhishekgit (Post 4621757)
@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??

abhishekgit 03-08-2012 11:43 AM

@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 :-)

suicidaleggroll 03-08-2012 11:59 AM

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.

knudfl 03-08-2012 12:25 PM

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.

.

abhishekgit 03-09-2012 08:05 AM

@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. :-)

Aquarius_Girl 03-10-2012 10:54 AM

Quote:

Originally Posted by abhishekgit (Post 4622687)
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".

colucix 04-06-2012 02:49 AM

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


All times are GMT -5. The time now is 05:35 PM.