[SOLVED] COP4600 Ex2-Patches, Libraries, and Makefiles

$25

File Name: COP4600_Ex2-Patches,_Libraries,_and_Makefiles.zip
File Size: 423.9 KB

SKU: [Solved] COP4600 Ex2-Patches, Libraries, and Makefiles Category: Tag:
5/5 - (1 vote)

Ex2_-_Patches_Libraries_and_Makefiles

Overview

In this exercise you will learn about patches, libraries and Makefiles. You will first modify the patch you created for Project 0. You will then create a static library that will perform a simple arithmetic operation and finally you will create a Makefile to compile that library.

Structure

The project is broken into three main parts:

  • Modify the patch file from P0.
  • Create a static library.
  • Create a Makefile to re-compile your library.

Patch Files[1]

A patch file is a text file that contains instructions on how to update other files. In Project 0 you modified a certain file(s) to add your name to the boot message. You then rebuilt the kernel and saw that your changes were applied successfully (hopefully)! Finally, you created a patch that contained all the changes. In other words, the patch contained the differences between your modified source and the original clean source you downloaded. Heres an example patch file:

The first 5 lines specify which file to modify. The remainder indicates which lines are removed and inserted. When applying this patch file to a clean source of your file system, the patch program will know exactly what to remove and what to add.

Patches are useful because they only keep track of changes. (Imagine if you had to export the

1.4 GB Reptilian image and upload it to Canvas every time you had to submit something!)

For this exercise you will need to do the following:

  1. Create a patch file to remove the message you added in P0 and insert a new one that prints ### First Last Name (Exercise 2) ### by modifying your P0 patch.

NOTE: You will apply the patch to the kernel source that already contains the changes from P0, so you will need to remove the P0 changes and add the new changes.

  1. You will apply the patch by switching to /usr/rep/src/reptilian-kernel and running:

$ git apply patch_name.diff $ make && sudo make install && sudo make modules_install

  1. Take a screenshot of the boot message showing the modified message.

Libraries[2]

Libraries are simply a collection of previously defined declarations and procedures. If we often use the same subroutines, we can create a library and use it across all our projects. For example, we can use a math library to perform matrix multiplication. You can read about different types of libraries here: http://www.hep.wisc.edu/~pinghc/generate_your_own_library.htm

In this project you will create a simple static library using the following steps:

  1. Create c in /home/reptilian/math. (You will need to create the math directory.)

int mean(int a, int b)

{

return (a + b) / 2;

}

  1. Create the h in /home/reptilian/math.

 

#pragma once

int mean(int a, int b);

 

  1. Compile c and create libmath.a.

$ cc -c mean.c $ ar cr libmath.a mean.o

  1. Create c in /home/reptilian.

 

#include <stdio.h>

#include math/mean.h

int main() {

printf(The average between 3 and 5 is %d
, mean(3, 5)); return 0;

}

  1. Compile and run c.

$ cc -o test test.c -L ./math -lmath $ ./test

  1. Take a screenshot of the output.

Makefiles

Makefiles are used to organize code compilation. Earlier in this exercise you manually entered the commands to create your library but imagine if you had to compile this and 50 other programs! In such a circumstance, Makefiles come in handy. A Makefile contains all the instructions needed to compile programs and can be run with the make command. For this exercise you will create a Makefile in /home/reptilian/math that will compile the library.

Read about Makefile here: http://www.cs.colby.edu/maxwell/courses/tutorials/maketutor/

To test it and make sure it works, delete libmath.a and mean.o, then run make. This should re-create libmath.a and mean.o. Submit the Makefile on Canvas. (You can add the .txt extension if necessary.)

[1] https://www.drupal.org/node/367392,https://en.wikipedia.org/wiki/Patch_(Unix)

[2] https://www.cs.swarthmore.edu/~newhall/unixhelp/howto_C_libraries.html

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] COP4600 Ex2-Patches, Libraries, and Makefiles
$25