Skip to main content

Makefile

 You may have seen file named Makefile or you may have type command like make, make install. so what is this file Makefile and what are this command. let's discuss about it.

What is Makefile?

-> Makefile is Magical file which contains some shell command. if you type make {command} then it will execute make file.

let's dive in little deep,

create file named Makefile , (use tabs while indentation)

hello:

    echo"hello world"

now type make in terminal

format of Makefile,

target : prerequisites

    command

    command

where target is command which can be triggered using make.

first: first.o

cc first.o -o first # third

first.o: first.c

cc -c first.c -o first.o # second

first.c:

echo "int main() { return 0; }" > first.c # first

clear:

rm -rf first first.o first.c

when we type make, commands in Makefile execute line by line,

here it started with first(target) then it needed first.o(prerequisite) so now it is finding first.o 

next line it find first.o(target) then it needed first.c (prerequisite) so now it is finding first.c

next line it find first.c and there are not any prerequisite for it so it will execute command of it

then it will go up for first.o(target) because it find prerequisite for it which is first.c and execute commands of it then it will go up one more time for first. and this is how it works.

now if you run make clear it will delete all files which are created.

Why use Makefile?

-> when you're working on some project no matter it is big or small but if you use Makefile it will reduce your some work which you need to repeat while you compile your program . also make is used to build executable programs and libraries from source code.


Even you can install dependency using Makefile like below,

packages:

echo "installing packages"

sudo apt install {package-name}

help:

echo "packages: install all packages"


There is lot about Makefile which i can't cover in one post, but now you have basic idea of Makefile, so you can create Makefile.

[Note: there can be some indentation error in above code so you should  type it yourself ]  

Thank You 😊😊

Comments

Post a Comment

Popular posts from this blog

Products Which I like

Induction Buy now Induction Buy now

Pascal's Triangle

 Pascal's Triangle Introduction In mathematics, Pascal’s triangle is triangular array of binomial coefficient. below you can see how it looks like… 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 How to Build it? First of all start with “1” and second rows as “1 1” then we can clearly see every element in next rows(except 1) if sum of two elements from above row. (i.e, 1+1=2, 1+2=3, 1+3=4) and with this rules we can create pascal’s triangle of n rows. Below is visual of how it will look like, Formula let’s take 0th row as first row and 0th column as first column, so we can get each value using formula where n is row number and k is column number. so for finding 1st(0 indexed) element in 2nd row we can write 2C1 which will give 2. There is one another technique, in which we need to solve (x + y)^n for nth row, if we solve (x +y)² then we will get 2nd row as coefficient of x and y in this solved formula which is x² + 2xy + y² . coefficients are (...