[Ilugc] Re: make tutorial
Girish Venkatachalam
girishvenkatachalam at gmail.com
Fri Jun 18 17:21:25 IST 2010
To show an image file to X,
showimg::
<TAB>qiv -mtf *png
Also you can call any rule like this.
$ make rule2
when you have two lines like this anywhere in the makefile.
rule2::
<TAB>echo "Rule 2"
-Girish
On Fri, Jun 18, 2010 at 4:59 PM, Girish Venkatachalam
<girishvenkatachalam at gmail.com> wrote:
> Dear all,
>
> This mail is an attempt to teach makefiles in UNIX. Makefiles work the
> same way everywhere even in
> Windoze. There are also several names for the make tool. tmake, pmake,
> gmake, nmake and so on. ;)
>
> But all of them work similarly.
>
> In the BSD world makefiles are more subtle and much shorter. Makefiles
> also work differently in the
> autoconf world with configure script, Makefile.in , Makefile.am and so on.
>
> As you can see it is very complicated, complex and needlessly boring. But
> this does not take away the fact that makefiles are a beautiful thing.
>
> I shall try to illustrate this idea in this mail.
>
> $ make
>
> will try to execute the first rule in the makefile found in the
> current directory.
>
> makefile can be named "makefile" or "Makefile" or "MAKEFILE".
>
> But it almost always is named "Makefile".
>
> A makefile is organized as
>
> rule :: dependency.c dependency.h foo.c ba.c
> <TAB>gcc foo.c ba.c dependency.c -o rule
>
> I think you get the idea.
>
> rule name is also the target name.
>
> In other words, you tell the makefile or in essence the make utility that
> to create the target "rule" you need to execute the line given with
> a <TAB> character
> directly below the rule line.
>
> And you also tell makefile that whenever any of the files
>
> "dependency.c dependency.h foo.c ba.c"
>
> change the target has to be updated.
>
> In other words make helps you keep your targets up-to-date.
>
> But all these are academic words without much meaning to hackers.
>
> So let me now talk in practical lingo.
>
> If you wish to create a mp3 file from a bunch of wav files or
> if you wish to dump a file an image file, you can write rules like these.
>
> out.mp3 : in.wav
> <TAB>ffmpeg -i in.wav out.mp3
>
> You can also call it like this.
>
> createmp3: in.wav
> <TAB>ffmpeg -i in.wav out.mp3
>
> The rule name need not correspond to the target file created.
>
> It is just a name after all like Girish.
>
> And the dependencies can be nil too.
>
> clean::
> <TAB>rm -rf *.o
>
> will remove all the object files unilaterally.
>
> Makefiles are a very powerful UNIX "power tool" and it takes a lot of
> experience and
> knowledge to use it effectively.
>
> I have not been using it well yet.
>
> But remember that there are makefile variables, shell variables,
> makefile if conditions
> and while loops and they should not interfere with shell's if and while .
>
> If you wish to write a shell script like this.
>
> $ for file in `ls /etc/`
> do
> echo $file
> done
>
> in a Makefile they have to be written like this.
>
> printfilesinetc::
> for file in `ls /etc/`; do \
> echo $$file; \
> done
>
> Reason being that the makefile rule line is exactly that. Just one line.
>
> So if you wish to run multiple commands you need to run like this.
>
> <TAB>cd /etc/ && cat passwd
>
> and if you wish to background processes, you write like this:
>
> (rm -rf /tmp&) && \
> echo "started the removal in background"
>
> Also if you wish to avoid echoing of executed rule commands you need
> to prefix a @.
>
> printhello::
> <TAB>echo "hello"
>
> should actually be
>
> printhello::
> <TAB>@echo "hello"
>
> Try it and you will know.
>
> Have fun!
>
> -Girish
>
> --
> Gayatri Hitech
> web: http://gayatri-hitech.com
>
> SpamCheetah Spam filter:
> http://spam-cheetah.com
>
--
Gayatri Hitech
web: http://gayatri-hitech.com
SpamCheetah Spam filter:
http://spam-cheetah.com
More information about the ilugc
mailing list