Hello there, you beautiful people.
And welcome to this video where we're going to be learning how to turn source code into run programs
with our own little modifications.
So in this video, you're going to learn how to download source code, edit it and use the new C compiler
to turn that code into reasonable binary programs.
You're also going to learn how to install software from source code using the make command.
And we're also going to modify the code slightly so that we can see that it is indeed our modified code
that is being installed.
And by the end of the video you should have a much better understanding of the awesomeness of open source
free software, and you should also know how to compile software from source code for yourself.
So let's go ahead and get right into it.
All right.
So here we are again on the new org website and we can see on the software tab here that we can get
each of the packages scrolling down to the bottom.
That comes with the new operating system.
Now, all the source code for the commands that we've run so far, such as the fine command, the RLS
command and so on, can all be found in this core utils package over here.
So let's go ahead and download this package and take a look at it.
So to do that, we click on the link and it will open up another page.
And if we scroll down to the download section here, it'll give us a couple of links and it tells us
that the stable source releases can be found at this link and the test source releases can be found
at this link.
Now the difference between the stable and test is that stable source releases are known to work.
They've been tested, whereas test source releases maybe where they're trying out new things and you
know, it's not fully stable.
It might it's not final.
Right.
So we're going to try out the stable source.
I'm going to click on that link.
And we can see here that we get a bunch of packages, a bunch of bundles that are that are in a list
format.
And the most recent versions are towards the bottom of the list.
So if we scroll down as far as we can to the bottom of the list, we'll see we get core utils version
8.28.
And what we're going to click on is the one that ends in dot z.
So not the one that ends in dot z cig just the one that ends in dot x z.
So if I go ahead and click on that right now, we'll see that.
We see a pop up come here and I'm going to click Save File, I'm going to click.
Okay.
And that has been saved in our downloads folder.
So if I just if I head over to our downloads folder right now in the terminal and you can see at the
minute I'm in our home directory, I go to the downloads folder and list it out and you can see that
we have got this core utils version 8.2 8xz.
Now that's a compressed tar archive that's been compressed using the x z compression algorithm.
So if I look at that, we'll see with the find command, we'll see that it's x, z, compressed data.
Now X Z is just a compression algorithm, just like the B zip or the GZIP compression algorithms that
we touched on in the file compression and archiving video very briefly, because it's not one of the
more common algorithms, but we can unpack it using the TAA Command.
So let's just do that.
What we can do is we can type TAR and as you know, how to how to extract a file, you give it the X
and F options and then you tell it which archive.
But to extract through the zip compression algorithm, you need to give it the capital j option.
So the lower case j option is for B zip two, but the capital j option is for x zip.
And if you want more information on this, check out the file compression and archiving cheat sheet
that I gave you in the appropriate video.
Okay.
So if we go ahead and press enter, we'll see that we didn't get any information because we didn't give
the talk about the V option.
But if now I use LZ, we'll see that we've now got a new folder called Core Utils 8.28.
So if we see the internet, so we see the intercall utils and take a look, we can see that we've got
a whole bunch of stuff in there.
Okay?
But we can specifically pay attention to this CRC directory now that CRC is short for source and that's
where the source code is kept.
So if we seed into CRC and take a look by clicking the screen, take a look, we can see that we've
got a whole bunch of files in here.
Let's pipe that ls data into the less command.
First of all.
Now, now this makes a bit easier to scroll up and down and you see now we can see that we get loads
of files that end in dot C.
Now that dot C indicates to us that these files are all written in the C programming language, which
is a very common programming language that the new software is written in, given the date of when it
was written being in, you know, the 1980s, 1990s.
So let's take a look at the code behind the LS command.
For example, we could lhs let's just grep out ls we can see that we've got this ls dot c file going
on here.
So let's take a look at it.
Nano ls dot C and there we are.
This is actually the source code in here.
This is all the source code and we maximize it a bit.
The source code for the LS command.
So isn't that awesome right now?
If you had the time, the ability and the intention, you could go through this code and study exactly
what it was doing, which is one of the freedoms that the free software movement aims to.
I give you.
But we can actually also modify this code and recompile it into a running software, which is what we're
going to do now.
Now, this isn't a course on C programming, but in every C program there is a function in there called
the main function, and it's a very important function that always runs.
Okay.
Now I'm going to modify that function so that whenever LHS runs, the computer will print out.
Hello there, you beautiful people onto the screen.
Okay, so I'm going to type a bit of code into the main function that makes that happen.
Now, after preparing a bit for this lecture, I found that the main function in this file starts at
about line 1443.
So if we use Nano's, go to line function using the control and underscore option.
If I put in line one, four, four, three and press enter, you can see that we've ended up at the
main function magic.
So I'm going to line the code right at the top here that does that printing stuff.
So print F and I'm going to put in there.
Hello there, you beautiful people.
And make sure that it ends on a new line with the backslash n character right there.
And I'm just going to tab this over.
It doesn't make a difference, but you know that that's a bit nicer and let's try and get rid of this
extra space at the end line.
It doesn't matter.
But okay, there we are.
So we've put in the function there.
Hello there.
Beautiful people with a new line character.
So the line, it goes to a new line.
Now, if we save the file with control and O and we exit with control of X, we've now modified the
LS commands code, so that's pretty cool.
But now how do we turn this code into a reasonable program and install it on our computer?
Well, because they're written in C, the code needs to be compiled into machine language before it
can be run.
And for that we need a compiler and more specifically a compiler for the C programming language.
Now the new C compiler or CC is the compiler that's used on GNU Linux Systems and we can get it by entering
the following command and that following command is sudo apt get install DCC now for now, I don't want
you to worry too much about this because we'll be explaining in great detail later on what this command
actually means and we'll be doing it in this section of the course.
But in short, what we're doing is we're telling the computer to look on the software repositories available
for Ubuntu and download and install the new C compiler or GCC package.
Again, this will become much clearer in the next few videos, but just type it as I have done so here
and when you're happy press enter and because we've used sudo it will ask us for our password just like
when we've used sudo before.
So I'm just going to enter that in there hopefully correctly.
Fingers crossed.
Nope.
Let's try it again.
There we go.
And now it's saying, hey, we've got to install a whole bunch of packages in order to get this GCC
package.
And it's going to be about 72 megabytes of additional disk space.
Do you want to continue now?
I can just type.
Yes, I'm just going to type.
Why press enter and it's going to go ahead and do that.
And this might take a bit of while depending on your Internet connection, but it appears to have downloaded
it in my case and now it's just doing the installation.
It's going to start unpacking each of those different packages that it's download and we are actually
seeing an installation process happen right now.
We will look into this a lot more in more detail later on in the course, but you can see that we didn't
have to download any wizard and click next, next, next, next, next, agree to any terms of conditions
or anything like that.
Because all of this software is under the new public license and it all gives you the same, same,
uh, different, uh, the same freedoms as each other.
So now that's gone ahead and installed, we didn't have to do anything.
We've now installed the new C compiler and a whole bunch of other stuff.
So now we're ready to compile our code.
Okay, so let's turn our attention to our beautiful source code.
Now, because different computers have different architectures, we need to configure the installation
of this code to our specific machine.
And there's a script that comes with that called Configure.
Now we're in the source, we're in the source folder here.
So let's just go back up the folder with CD, dot, dot to go back up a folder, clear the screen and
take another look.
And you can see here there's a script called Configure and we know it's a script because it's green.
Okay, so let's run that by typing, bash configure and we press enter.
And what this is doing is it's configuring the new C compiler, the GTC, to get make sure that when
it compiles all this, the software that we tell it to, it's going to do it in a way that's appropriate
for our computer's architecture.
And it's making the appropriate adjustments.
And the important thing that this configure script does besides configuring the new C compiler is that
it creates a new file called the Makefile.
Now the Makefile is responsible for the installation of this new software package, but to make the
Makefile work, which is a massive tongue twister, by the way, we need a new command called Make.
So when this thing has finished configuring, we're going to install the make command in a very similar
way to the we just installed the new.
C compiler.
So if we just sit tight here for a second while we see all this beautiful text flying up the screen,
it looks pretty awesome, though, right?
It's like something you might see on like a unlike a film with hackers, you know, and stuff like that.
And it's we're literally doing that right now.
So so be very proud of yourself.
Okay.
So now that's finished.
If we just take a look in this directory, we should be able to see this new file here called the Makefile.
Now, the Makefile is an important file, but we need to to be able to run that.
We need to have the main command.
So to get that we're going to type sudo apt get install make and when we press enter, it's going to
go through a very similar process of installation and now that's all installed very quick, very easy
to install that one.
Okay.
So now when we're in the same folder as the Makefile, if we just run the make command, you can see
that it's going to go through and it's going to compile all of the all of the C files that it finds
have not been compiled recently in.
There are still some changes outstanding, which is effectively all of the C code in this folder, including
our LS file.
So what this is doing is it's compiling it all into, into machine code, into binary code that can
be run on the computer.
Okay.
So this is what's necessary when you run a compiled language like the C programming language.
So when that's done, we'll be able to install the newly compiled programs.
But I'm going to cut the video here to save time and, you know, stop you waiting around too much.
Okay.
Now that's completed.
So what's happened is we found the code for the LZ command.
Okay?
We edited that code, and then we installed something called the new C compiler, which is what's required
to turn that code into machine code that the computer needs in order to run.
Okay.
So what we did is we installed the C compiler and we had to configure that compiler before it would
could work correctly for our computers specific requirements.
So we configure the compiler and then when it was configured, we've just run it using the make command
to make sure that every single bit of code is now turned into machine code.
Okay.
So the only step that remains now that we've got this machine code is to install that machine code in
the required places on our path for it to actually work.
And the way that we can do that is using the pseudo sudo make install command.
So if I click the screen type sudo make install, what it's doing is it's installing all of the stuff
like that.
And that was very, very quick.
We've now installed each of the different pieces of software that came with this version 8.28 of the
core UTILS package.
Okay.
So let's take a look at how that works.
Okay.
So if we just close our terminal and re-open it again, then now if we run the LZ command, we can see
that it says hello there, you beautiful people, every time that it runs because we modified our code
and installed it.
How awesome is that?
Right.
So hooray for open source and free software.
So this is actually a much faster process in reality than what I've showed you here.
So to change back, we would just re-edit the source code, recompile with make, then reinstall with
make install.
So if I head back to our ad downloads, it's actually a much faster process when you get a bit better
with it.
So here we are.
We're in our core utils file.
We're going to go over to our source code folder that we're in there.
Okay.
So let's go to Nano.
LZ C, let's head over to line 1443 and we're going to delete this, this line that I put in there,
save the file.
Okay?
Now if I just clear the screen now all we have to do is do make and sudo make install.
Oh because I'm in the wrong folder.
There we go.
Make and sudo make install.
Okay.
So now notice how the make command is just really compiling the RLS command because it notices that's
what's different.
Let me run with our end to my password there so it can install it.
And now when I close the terminal and reopen it and use the LZ command, now it's back to normal.
So you see how much faster that was, right?
Once we've configured the C compiler once or at least for F for the package, it's really fast to just
go and edit, edit it thereafter.
That's because the main command knew as well that it only needed to recompile the code that was affected
by our change, not the whole package which was new to the system the first time we did it.
Okay, so make is a very clever program and as I say, now that we've installed the new version of the
LZ program, now the hello the You Beautiful People message has disappeared and it's back the way that
it was.
So there you are you beautiful people in this video you've seen her to access source code from the dot
org website.
How to modify that source code and how to use, configure, make and make install to install the new
software.
Now the great thing is you can access and modify the source code for everything on a GNU Linux operating
system.
And if you care to exercise it, you have absolute power over how your computer works.
So hopefully you can see how having open source free software running on your computer is a great asset.
And you also that you can appreciate the effort that the pioneers of such a system took to build it.
But the process that we went through in this video is relatively lengthy, and sometimes you just want
to install software and get on with what you were doing.
So for this, there are massive bodies of maintained and pre compiled code in what are known as the
software repositories.
And we use the repositories in this section actually to install the new C compiler.
And the make command and software repositories are what you'll use to install software 99% of the time
and they come with so many really cool features.
So now that you understand that, yes, you can look up source code and modify how your computer works
however you like manually.
Let's take a look at how the software repositories which give you access to a massive library of software
that is priority pre compiled and ready to go.
So have a look at how they work as well.
So for all that goodness, I'll see you in the next video.