Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Understanding makefiles in Linux

Posted on 2009-04-10
Medium Priority
Last Modified: 2012-05-06

I'm new to Linux, I'm using FEDORA 10, for no reason at all, somebody recommended to me and that was it. The thing I'm curios about is when you build something using the make command.

I've attached some of the code of this makefile, and looking at it in essence what it's telling me it's that it'll installed in /usr/local/bin, the progs, that are two files, aiod and dsf2info.py.

The thing is that when you use the make command in the local directory where you have download the source files, it builds it there, i.e, if the directory that contains the source files is /home/johndoe/Desktop/aiod for instance it'll create them there. not in the /usr/local/bin that says in the makefile.

Also it generates some *.o, or object files that ,as well as the main program, builds them in the same directory.

the thing is that i don't know is what to do with these files, theses object ones. I have to move the program i've just build in the usr/local/bin otherwise i get "command not found", because it has to be in one of the directories of the $PATH, as for these object files (*.o) I copied them in /usr/local/lib, for a lack of a better place, because i thought this program might need them. I have not tested them throughly so i don't know which features will not work, and i don't know if it'll be due to this object files, so far the program have worked.

Where do i put these files, these object ones, and am i missing some parameter to the make command so it'll build the files in the directory specified in the makefile?


CC      = gcc
# CFLAGS  := -Wall -W -g -DPREP_BUFS
PROGS   = aiod dsf2info.py
LDLIBS  = -laio -lrt -lm
OBJS    = aiod.o affinity.o args.o misc.o async_io.o lat.o sync_io.o
all: depend $(PROGS)
INSTALL	= install
prefix	= /usr/local
bindir	= $(prefix)/bin
install: $(PROGS)
	$(INSTALL) -m755 -d $(DESTDIR)$(bindir)
	$(INSTALL) $(PROGS) $(DESTDIR)$(bindir)
dist: aiod-0.9.tar.bz2
	-rm -f aiod-0.9.tar aiod-0.9.tar.bz2
	-git-archive --format=tar HEAD | bzip2 > aiod-0.9.tar.bz2
	@$(CC) -MM $(CFLAGS) -I.. *.c 1> .depend
clean: docsclean
	-rm -f *.o $(PROGS) .depend
	-rm -f cscope.out tags log
	-rm -f aiod-0.9.tar.bz2 aiod.tar.bz2
	-rm -f instrumentation/*.out
	$(MAKE) -C doc all
	$(MAKE) -C doc clean
aiod: $(OBJS)
dsf2info.py: dsf2info.py.src
	-cp $? $@
ifneq ($(wildcard .depend),)
include .depend

Open in new window

Question by:lguifarro
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Author Comment

ID: 24120974

I've forgot to ask this too

There are some Header Files .h in the source files, I'm assuming that it needs them for the build when you call the make commando, but shouldn't i put these somewhere, like in the usr/nclude, or the /usr/incclude/linux directories????


LVL 14

Assisted Solution

by:Monis Monther
Monis Monther earned 400 total points
ID: 24121610
Hi, A couple of things to note here:

1- Ever thought of using yum instead of installing from source, its a life saver.

2- Since we are talking about installing from source:
a) First did you do a ./configure
This step configures your package for correct paths

b)You can delete all the .o files (object files), you can also do after you finish make install
make clean
This actually deletes the .o files

c)You can delete the source files all together after you finish

Best Regards
LVL 16

Accepted Solution

ai_ja_nai earned 1200 total points
ID: 24122058
ok, here I explain you: makefile and make are a way to install programs by souce. Normalli, when you compile something you invoke the compiler (javac, cc, gcc, etcetcetc) on the source file and you get a binary object in output. There's no absolute theoretical reason why we shouldn't do everything that way. But there's a practical one: when a program is made of hundreds of object files, compiling everything and moving object code around your filesystem one by one by hand can be tedious, long and dangerous (in the way taht if you miss one file the whole thing won't run).

make is just a way to automate the task: you launch fist ./configure script, which checks if all the dependencies are met and if all the necessary software is present; all these checks and additional info on the system will be output in a file that make will look at during compiling. Then, you launch make; make will look for the configuration file and, most important, to the Makefile, which is just a cookbook for the compiler: it tells where are the source files, how to compile them and where to put them once the job is done.

Invoking make alone will just compile everything. To put everything in the right place, you will need to invoke 'make install', which is a funcion of make that will just copy compiled stuff in their place.
LVL 16

Assisted Solution

ai_ja_nai earned 1200 total points
ID: 24122062
One more thing:

>c)You can delete the source files all together after you finish

This is an EXTREMELY WRONG thing to do, because if you delete the place where you compiled your program, you'll loose all the infos that will enable you to uninstall the program. 'make uninstall' is a command available for this purpose, and once you wipe away the information output by configure and the Makefile, the only way to remove your program will be by hand...

Assisted Solution

ewest02 earned 400 total points
ID: 24122526
Most software source packages include some documentation in the form of READMEs, INSTALL, etc text files. These will (hopefully) contain sufficient information about the build/make process for that package. There may or may not be a configure script -- and I am guessing from the contents of your posted makefile, one is not included with this source.

It is many times a Good Thing (tm)  to *test* your freshly built software before installing it. You can set the target installation directory by modifying the "prefix" value. This will vary in specifics from package to package. With a configure script, you can do this on the command line. In your case, just edit the makefile directly.

Suggestion: once you are satisfied with the newly minted binaries and they have been installed in their final resting places, run " make clean" .  If you still have the original source archive in a separate directory, delete the build/staging directory for the package. Otherwise recreate the archive for future reference. Note too, as per some makefiles (eg the one in this posting) there is no " make uninstall" target.

If you want the how' s, why' s and what for' s about GNU make, review the documentation from Paul Smith etal on the GNU make site http://www.gnu.org/software/make/  It is well written and maintained.



Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question