What is a makefile exactly and how we can create one?

Solution 1:

to answer your question I cant give you a one line / paragraph answer because it deals with every thing.Read the first link it have everything you need with examples too.

Good tutorial that can explain everything about make

  • http://mrbook.org/tutorials/make/
  • http://manpages.ubuntu.com/manpages/raring/man1/create_makefile.1.html
  • http://manpages.ubuntu.com/manpages/raring/man1/make.1.html

Solution 2:

A Makefile is used as a "map" for C programs compilation. They work with the make utility, an describe how a program has to be compiled/linked in order to work correctly once turned into a executable file. For global UNIX/shell tasks, you're looking for shell scripts, not makefiles :)

See http://en.wikipedia.org/wiki/Make_(software)#Makefiles for more information about makefiles, and http://en.wikipedia.org/wiki/Shell_script to discover shell scripts.

A basic shell script for what you're trying to do could be :

#!/bin/bash
echo "Hello world, today is $(date +%a)"
gzip -c SOURCE DESTINATION

Store this in a file, and execute it using your shell prompt (bash myscript.sh, sh myscript.sh, ...). You can also make the script executable using :

chmod +x myscript.sh

And then execute it with your default interpretor with :

./myscript.sh