• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 677
  • Last Modified:

Understanding makefiles in Linux


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

4 Solutions
lguifarroAuthor Commented:

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


Monis MontherSystem ArchitectCommented:
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
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.
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...
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

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now