 Hi everyone the game welcome to this session of the LPS today probably will be the last lecture we have covered so many things over the last several weeks started with looking at the Linux then went into programming we started with Perl we covered tickle then we also covered Python and today we are going to talk about make files make files are one of the key utilities for the running a program automatically the reason why we use make files is because we want to capture the dependencies and essentially like use the dependencies to do certain things as well as not do certain things so in a serial processing of five basically if you are doing something 215 and then you are going doing something else and if you if there is an error occurring at one point maybe you need to back out to some some place before you can continue at the same time if you find some error and then you have done some already like few processing steps you do not want to go back all the way to the beginning and then do the first thing all over again I want to capture from the middle wherever it is it is successful from that point onwards you want to move forward and for these kind of things a make file is used there you can capture the the dependencies in a serial fashion basically and then you can use that to your advantage in terms of what needs to be run and what does not need to be run so a make file is providing a way for a separate compilation describe dependencies among the project file and then that is the make utility and use the make utility to do the compilation so in a typical process for compilation you will have like many number of programs like dot fee and they will probably share a common header file on the H common dot H and then now so this is basically in a typical C environment so you have multiple stuff and then basically like they are assembled basically basically and then from the assembler you generate the part or the executable which essentially like I mean now you can link it and then you can run the program so now if you want to change the C but you do not I mean the green dot C but not the blue dot C you do not want to compile the blue or T again so you only want to compile the C the green dot C so a make file once you specify how they are dependent it looks at the timestamp and looks at what changed and if nothing has changed then it won't touch the the particular file so let's look at that so using the make file basically like so make file or make file uppercase aim definitely look at that those are the standard ones even you can do other files also and to run the make it basically simply the make is the command name and then you can say like make minus s by name if the name of the file is not made by otherwise it will just run that make by and then you can also say like make a target me which is the more kind of target that you want to make if the target is not included in the make file itself so a simple make a sample make file we will look at it this is essentially like I mean the main element in the the rule the make file is what is called the rule the rule is simply target call and dependencies and then you can also like use tab for any kind of commands to get the particular file so here is an example so the target is what is called my underscore pro and then the dependencies are eval.o and main.o so the top level we define these two codes now once these dependencies are satisfied which command to run so here we run the g plus plus which is a compiler and then dash o which is the output will be the my part and then the inputs are eval.o and main.o now we go hierarchically and describe each one of the dependencies so for example eval.o the eval.o depends on eval.c and eval.h which is essentially you can think of this as a the green.c and the in the in the previous one this and then eval.h is the error error file and then how do we get to the eval.o basically we do a g plus plus minus compile and then eval.c so this will generate the eval.o now let us look at the main.o the main.o again its components or the dependencies are main.c and eval.h eval.h you notice that they are the same from both sides and now the command to generate the main.o is g plus plus and then we say minus compile minus and then we do main.c so we can also specify the commands using hashes that we already know basically so the syntax is very similar to any other syntax regular c programming syntax we can say so basically like the dash o is the specific executable file name dash p to compile only no linking so the dash o does the compile handling of these two basically so you can also make a miss file with programming constructs such as variables use of variables so here the old way basically on the left hand side that you see essentially there is specify the top level target and then each dependency and then we go ahead and define this and this is exactly the same as previously for the my fog but if you want to use the variable then we can define the variable upfront as a header so for example c is defined as g plus plus obj of the object is eval.o and main.o and then the headers are eval.h basically so now it simply we can say that my frog is eval.o main.o that is the dependencies but the command is essentially like $p which is g plus plus and then the arguments are for the input is basically like $opf which is these two inputs and then we also now go and do the same thing basically for eval.o which is the subsequent target and then the main.o and then here we define basically like the one more additional one which is the $objs its target basically or its dependency is $pf which is the eval.h and essentially like I mean so only like you know eval.h it is present then it starts working on working the way up so this is convenient mainly because now if you want to replace the g plus plus compiler with a cv compiler c compiler then all you got to do is just change that thing and in fact you do not even have to change it inside the move file but just define it like make e equal to cv and then automatically like everything is cv and though they take presents over the variables define inside the move file so fairly simple enough and now there are some implicit rules essentially the implicit rules are standard way for making one type of pipe from another type there are numerous rules for making .o5 from a .p file from a .p file etc and make usually applies the very first rule that you need if you have not defined the rule for a given object file make will apply an implicit rule for it for example our make file be specified basically like eval.o main.o and then we pay like I mean $p and so far $ object and then $ object $ it is so here we omitted the eval.o and main.o the target so it applies the implicit rule and then basically it creates it's equivalent of creating this rule where it's eval.o depends on eval.p and then this is compiles that eval.p and main.o is main.p and then it compiles the main.p so this is the way that the make understands this small make file which indicates it's okay but make sure that if some something that if you are not explicit about it make file will assume and then start this working this way now let's look at another way basically this is the using the percentage percentage .o is percentage .c and then this is a very very succinct way of representing a rule and essentially like I mean again here this is it just replaces all these things with the profit stuff and then works its way to do the make so here you can see that once you specify that and then now basically like you have the same thing but at the same time if you do an empty command then it won't apply the implicit rule so it's as good as specifying a rule and specifying an empty command so just take care if you don't want any rule to be applied then you can specify it as an empty command and that will the implicit rules will not get applied so that's one way to override the implicit now there are some variables you saw like in the previous one you use a dollar less than so those are what is called the automatic variables the automatic variables are used to refer to the specific part of the rule components so we know that basically like target dependency that the general structure of the rule and then followed by a tab and then the commands those are the mostly a shell come out so here you can say basically like eval.o as eval.c and eval.h and then g plus plus is the command and then basically eval.c is the argument so the dollar at will determine the name of the target of the rule in this case it's eval.co and then the dollar less than actually specifies the first dependency this one it is eval.c so now you should go back empty basically when we specify like dollar less than that is the first dependency which is the percentage dot c which is anything dot c now dollar carrot is name of all the dependencies which is in this case it's eval.c and eval.h and then the dollar question mark names of all dependencies that are more than the target so in this case actually like I mean there is nothing in this one so basically like there is nothing that is defined for the dollar question mark now let's look at some of the meek options dash f specifies the file name which is if the meek file itself the name is not just the meek file so if you specify just the meek file then you don't need to specify the dollar dash f otherwise you need to specify dash f and then dash t is essentially using the command called touch to mark the target as after date and then the dash q is also known as question basically it looks for whether the targets are up to date and if it is true then it exists it is 0 and dash n is just the print the command to execute but don't really execute that so if you do like a dash n like make dash n of your make file which is maybe like this it will only like print all the various commands basically like dash c which is like g plus plus minus so prog then it also pair up say g plus plus minus eval.c and then g plus plus minus c mean.c and then it linked it so one thing is like I mean so this is one way to actually just test out whether your dependencies are correct just do a dash n and then one thing to notice basically dash e dash q and dash n cannot be used together so only one of them should be present and then dash s is silent mode that is it runs basically without echoing what is actually wrong and then dash k is it going basically meaning somehow all the prerequisite even is it's not able to link them now in order to make a flow work you need to also specify some pony targets the pony targets are targets that have no dependencies they are used only as names for commands that you want to execute so there are no dependencies basically so your because basically kind of filler you can say for example there is one target called clean which is just to remove all the files so you can also specify in a long form it is dot pony is clean and then clean is you can specify that clearly as the clean is a pony target and then to invoke this you can just say make clean and then it will run that so one thing to notice like I mean I want to mention here once you have this is your make file you can only run subsections of this file for example you can say like make eval.o and then it will only run this command the eval.c eval.h and then g plus plus dash t only it runs starting from the eval.o and then goes down for example it knows the targets basically the dependencies are eval.c and eval.h and then it will run the g plus plus dash t eval.c for eval.h it just looks for that file whether it is certain then response this command but then it goes to the next mean.o mean.o does not is not a dependency it is not a dependency for eval.o so it won't run it will stop there same thing you can run just mean.o and then it will run just that thing and then it will stop only if you specify the target as my cross then it will run everything that too only if there is any change in the eval.o or main.o then it will start running otherwise it will evaluate the dependencies the dependencies are okay basically then it won't even run so here similarly like I mean if you want to just remove the target team with the same machine and then it basically removes all the time and then typical phony targets basically they are like to make all the top level targets so we will call it like phony all and then all is all the targets basically under so if you do a make all it runs basically everything on the team whether everything is okay and then the other phony target is the screen that delete all the files that are normally created by make and then print with this printing print a listing of the source files that have changed. So now another thing is basically the vpath variable this is a variable that defines directories to be searched if a file is not found in the current directory and here you can specify a number of directories separated by columns so for example here vpath equal to dir column dir column therefore also basically the first one is taken as the source and then the second one is actually so path to that particular directory so you can say like vpath dir column dir this is one of them and then you can say like dir column dir two it's another one so similarly we just separated one as many as not and then if you want to specify like a directive like the lower case vpath that's the selective directory struct directory search there you specify a pattern and then what the directory is for example here vpath %.h and then that is in headers direction now similar to vpath there is also a vpath if you want the targets to be stored in the same directory at the dependencies you specify the vpath now there is also some variable modifiers are there essentially the object essentially which is eval.o and me.to and then we do a compile and then you know that the dollar parrot represents all the targets so that's eval.o and main.o now the source that's actually essentially the same as the object only thing is we substitute the .o with .c that's what this intact means so when we specify that here you can just say sources is eval.h basically where those are the source the targets essentially and then the .c is eval.h and then we can also use conditioners to change the name that the make file target gets executed so we can specify specific things basically and then the possible conditioners are if if eq if any q is depth and if m depth and all of them should be closed with an end if and then the complex ones can be you can use it as lf or else so here is one example so here we can specify basically like either it's a gcc or something else some other comparison and for gcc we can specify the libraries as dash, l, d and m where the normal libraries are different. So now if you say basically like if dollar cc gcc that is if eq gcc then like this dollar lives for gcc else it's like this is equal to dollar normal and end so notice that actually there are no tabs at the beginning these are basically just assignment so it automatically like I mean now when you specify the particular target and actual command based on what gets executed it automatically replaces this one of them so that's pretty much what I have on make files if you have any other parts to share please do so with your TA and thanks a lot.