MchlSkhrv / Shutterstock

Have you been told to «clone the repo and build it» and don’t know what to do next? We will show you how to run this program on GitHub on Linux, even if you are a beginner.

The instructions that make up a computer program are written, edited, and stored in text files. Then a program called a compiler processes these files. This produces an executable version of the program. The text files of instructions are called source code. The version of a program that can run on a computer is called a binary or executable file.

This is a simplified version of events, but it paints a correct — if generalized — picture. In practice, you will find all kinds of variations of this model. Sometimes other programs generate text files. In other cases, the source code is executed inside the interpreter and doesn’t need to be compiled, etc.

However, one universal truth in all software projects is this: source code files are crown jewels and must be taken care of just as carefully.

Version control programs

All source code files in a project are called a code base. Large projects often have many developers working on the code base. Every code change should be tracked and identified. If necessary, the changes must be reversible. If different developers make changes to the same source code file, their changes should be merged.

So it’s not surprising that there are programs called version control systems to make it easier to manage changes to a codebase. Version control systems store all previous versions of each file in the code base, and each change is recorded, commented, and tracked.

Little thing called Git

Linus Torvalds, the creator of the Linux kernel, developed a version control program called Git to administer the code base of the Linux kernel. It is now the world’s most widely used version control software. Millions of people use it literally.

With Git, a project’s codebase is stored in repositories . In addition to local repositories, which are located on the developers’ computers and possibly on a central server on the network, it is good practice to have a remote or remote repository.

And this is where GitHub comes in.

GitHub

GitHub was created as a result of success git . The founders saw an emerging need to securely host remote git repositories. They launched a business that provides a cloud platform that allows development teams to host remote repositories. As of April 2019, there are over 100 million repositories hosted on GitHub.

If the application is an open source project, there is a very high chance that it will be hosted on GitHub. There are other repository platforms available such as BitBucket and GitLab, but GitHub has the lion’s share of open source repositories.

Anatomy of a repository

A GitHub repository consists of folders containing files such as all important source code files. There are usually many other types of files in the repository. These can be documentation files, man pages, software license files, build instructions, and shell script files. There are no rules as to what a repository should or should contain, but there are conventions.

If you know how to navigate one kitchen, you can navigate any kitchen. It’s the same with repositories. Once you understand the conventions, you will know where to go to find what you need.

So how do you get a copy of the repository on your computer, and how do you compile the program into a binary executable?

readme file

It is traditional to include a readme file in the repository. This may be called readme, Readme or README. May have a «.md» extension or no extension at all.

Let’s take a look at the GitHub repository for the Atom editor. You see a long list of folders and files. Scroll down and you will see the contents of the README.md file.

GitHub automatically places the content of the readme file on the first page of the repository. If the readme file has a «.md» extension, it will contain Markdown markup language. This allows developers to use style elements such as fonts, bullets, and images.

Section of the readme.md file for the atom editor on github.

Typically, the readme file has sections that explain what a project is, what a model license is, who supports the project, how to get involved, and how to build and run the application.

If it doesn’t list actual assembly instructions, it will tell you where to find that information. Other information useful for building the application, such as required build tools and other dependencies, may be listed here, or a link may lead you to that information.

Box storage

Our mission is to clone the boxes repository and then build the app boxes .

The repository follows the same pattern as Atom. There is a list of folders and files, and below is the contents of the readme file. It follows the standard vault layout, but it’s a smaller project so there are fewer folders and files.

The readme file is also shorter. It has a Development section. There is a link in this section titled «Creating from Source». If we follow this link, we should find the information we need.

Link to assembly instructions for the application box.

Usually light navigation is required to navigate the repository and find the information you need, but it’s not difficult. Read everything on the repository page carefully. Sometimes the information is there, but may not be displayed in a conspicuous place.

Dependencies

The Build from Source page has a Build on Linux section, which is exactly what we need. It says that we must have the C , Bison and Flex compiler installed.

Required set of tools to create a box application

The build instructions say to run the command make so we also need make .

Tools needed to build this application: C compiler, Bison, Flex, make and Git (for cloning the repository to your computer).

This article was researched on computers with Ubuntu, Fedora and Manjaro Linux distributions. No distribution had all of these tools installed—something had to be installed on each of them.

Installing the Toolkit

Ubuntu should have installed Git, Flex, Bison and make . Here are the commands:

  sudo apt-get установить git 

"sudo apt-get install git" in a terminal window.

  sudo apt-get install flex 

"sudo apt-get install flex" in a terminal window.

  sudo apt-get устанавливает бизонов 

"sudo apt-get install bison" in a terminal window.

  sudo apt-get install make 

"sudo apt-get install make" in a terminal window.

Fedora should have installed Flex, Bison, and make . Here are the commands:

  sudo dnf install flex 

"sudo dnf install flex" in terminal window

  sudo dnf установить бизона 

"sudo dnf install bison" in a terminal window.

  sudo dnf установить make 

"sudo dnf install make" in a terminal window.

Manjaro was supposed to have a GCC compiler, Flex and Bison. Here are the commands:

  sudo pacman -сю gcc 

"sudo pacman -Syu gcc" in a terminal window.

  судо пакман -сю флекс 

  Судо Пакман -Сю Бизон 

"sudo pacman -Syu Bison" in a terminal window.

Cloning a repository

Each GitHub repository has a specific web address that Git uses to clone the repository to your computer. There is a green button on the main page of the crate repository that says «Clone or Download».

The

Click the button to see the web address. This is the address we need to pass to the command git when cloning a repository.

Change to the directory where we want to clone the repository and then use this command. If your terminal window supports it, you can copy and paste the web address into the command. Press Ctrl + Shift + V to paste into the GNOME Terminal window.

"git clone https://github.com/ascii-boxes/boxes.git" in a terminal window.

Git clones the remote repository and creates a local one on your machine. It tells us that it clones into a directory called «boxes».

Cloned repository in a terminal window.

The box directory is created in the directory from which you git command git . If we switch to the box directory and look at the contents, we will see the same list of files and folders that we saw on the GitHub page.

The contents of the box store in the terminal window.

Big! We have successfully cloned the source code and other files to our computer. Now we need to build the application.

Application assembly

To create an application, we must follow the instructions in the GitHub repository. Sometimes we run a certain shell file and others we run make . The following build instructions told us to run make .

Utility make reads and executes a set of instructions from a makefile. These instructions tell you how to compile the program and link it together. make passes instructions to the compiler and other build tools.

The command we were told to use would call make twice. First call make creates an application, and the second runs a test suite.

The command we were told to use the build instructions:

  сделать && сделать тест 

"make && make test" in a terminal window.

Many lines of output scroll quickly in the terminal window. After about a minute, you will return to the command line.

Application Drawer Deployment

The application has been built and we have an executable. Now we have to copy the binary to the /usr/bin/ directory. This allows the shell to find it when we try to use it.

For some applications, this may be all you need to do. In other cases, you may need to copy additional files, such as man pages and configuration files, to locations on the file system. The last one is what we need to do with our new app because it was in the build instructions.

Commands for copying files from GitHub.

Use sudo to run these commands. The first command copies the man page to the man1 directory:

  sudo cp doc / boxes.1 / usr / share / man / man1 

"sudo cp doc /boxes.1 /usr/share/man/man1" in a terminal window.

Then copy the global configuration file to a directory in /usr/share/:

  sudo cp boxes-config / usr / share / boxes 

Finally, copy the binary to /usr/bin:

  sudo cp src / boxes / usr / bin 

"sudo cp src /boxes/usr/bin" in a terminal window.

Application testing

Let’s see if everything works! Try opening the man page for the command boxes .

  человек коробки 

This is reassuring! You see a man page that tells you how to use the command boxes .

The Box Man page in a terminal window.

Press «Q» to exit the man system and try using the command boxes .

  эхо How-To Geek |  ящики 

And we get the answer:

output boxes in the terminal window.

It may seem a bit daunting given all your efforts, but the point of this exercise was to help you check out a repository from GitHub and create an application.

Team boxes allows you to wrap text that is passed to it in a wide variety of frames. Some of them can be used as comments in source files. The above format works, for example, as a comment in a C source file. Others are purely decorative. Option -d (design) allows you to select the frame style.

  эхо How-To Geek |  коробки -d Whirly 
  эхо How-To Geek |  коробки -d c-cmt2 

"echo How-To Geek | boxes -d whirly" in a terminal window.

There is a long list of designs you can choose from. To see them all, use this command:

  коробки -l |  Меньше 

Assembly completed

The steps to build from source are usually simple:

If there are steps in the build instructions that are unclear, see if the project has a forum or community that you can post a question to. If the app has a website, it might have a Contact page. The developer who maintains the box project has their email on the «About Us» page on the box site. This is a generous gesture on his part, typical of the wider open source community.

Похожие записи