Solved

Understanding makefiles in Linux

Posted on 2009-04-10
5
662 Views
Last Modified: 2012-05-06
Hello:

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?

Regards

Luis
CC      = gcc

CFLAGS := -Wall -O2 -W -g -DNDEBUG -UPREP_BUFS

# CFLAGS  := -Wall -W -g -DPREP_BUFS

CFLAGS += $(CFLAGS) -I.. -D_GNU_SOURCE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64

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
 

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
 

depend:

	@$(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
 

docs:

	$(MAKE) -C doc all
 

docsclean:

	$(MAKE) -C doc clean
 

aiod: $(OBJS)
 

dsf2info.py: dsf2info.py.src

	-cp $? $@
 

ifneq ($(wildcard .depend),)

include .depend

endif

Open in new window

0
Comment
Question by:lguifarro
5 Comments
 

Author Comment

by:lguifarro
ID: 24120974
Hello:

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

Regards

Luis
0
 
LVL 14

Assisted Solution

by:small_student
small_student earned 100 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
0
 
LVL 16

Accepted Solution

by:
ai_ja_nai earned 300 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.
0
 
LVL 16

Assisted Solution

by:ai_ja_nai
ai_ja_nai earned 300 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...
0
 
LVL 4

Assisted Solution

by:ewest02
ewest02 earned 100 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.

--Eric


0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
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 navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now