首页 > > 详细

Operating System辅导:COMP202 Make A Difference辅导data structure编程

Make,Make,Makefile。

Introduction

Make is a system utility for building software. After editing a source file, the programmer runs make on the project. Make examines the modification date-time stamp of the source files and works out what commands need to be executed in order to bring the entire project up to date. Make is more efficient than a shell script that compiles everything, because make won’t recompile source files unnecessarily. However, make has some limitations that can, at times, be frustrating.

In this lab assignment, you will develop an implementation of make with a difference. Your make program will still have the basic functionality of make, but it will have some different capabilities that set it apart. Because it is an assignment to be completed in four weeks, there will also be some advanced features of make (particularly the advanced macros) that you do not implement.

However, perhaps one day some of the ideas in this lab may be incorporated into make - in that case, your work may help make a difference to make! Even if that never happens, you will learn about system calls, implement some interesting ideas and become an accomplished C systems programmer.

Because the program you will develop is a different make, we have named it dmake. When explaining the command line, we will use this name even though you can use any name you wish during your development and testing.

Overview and learning outcomes

The primary goal of this lab is for you to gain experience with Unix system calls. For this reason, we will in some cases specify that your program must use a particular system call or one of a group of related system calls. In other cases, we leave it to you to discover the relevant system calls. In all cases, we expect you to read the Unix manual pages as a primary source of information about the parameters and usage of the various system calls. You may access the manual pages on the Internet, but the definitive version for our system is on the system itself and is accessed through the man command. You are responsible to ensure that you are not misled by documentation that may refer to a different operating system.

The learning outcomes of this lab include the following:

  • Ability to write a significant systems program in C
  • Ability to understand Unix man pages and use them as an information source
  • Ability to choose systems calls appropriate to a task
  • Ability to employ systems calls and library calls to achieve a systems task

As with other labs in COMP202, there is an auto-marker for each lab stage that tests your submission, awards a mark and provides feedback. The lab command functions for this lab in the same way as it did for the first lab.

Incremental development

In this lab you are incrementally developing your implementation of dmake. The features that you develop for stage 1 should remain in your solution for later stages so that your final solution has all the capabilities of all the stages. Instead of having different programs for each stage, you will have one program that behaves differently depending on the command line options. You should periodically test your submissions for later stages as submissions for the earlier stages to ensure that you have not broken the earlier features.

Fetching your lab stage

Use the lab command to fetch sample test files for each stage. Refer to this lab specification for the requirements of each lab stage and also to the marking guide that is downloaded with each stage.

Stage 1: Reading and parsing the make file

The first task for dmake is to read the make input file and parse it into an internal representation that can be processed in later stages. To verify that you have parsed the input correctly, you are required to dump the parsed information in a specific debugging syntax.

We do not specify the internal representation that you should use, but we encourage good design. Specifically, we encourage simplicity, ease of programming, and ease of future extensions. It is likely that you will use familiar C constructs such as arrays, structs, character strings, and pointers. Your program should contain suitable comments describing the internal representation of the make file.

You should also consider Some Important Comments on Code Style and Systems Programming Style guidelines.

The system make command reads its input file from Makefile by default. We encourage you to use the system make command to manage your source compilations for this project, so we specify the default input file for dmake as Dmakefile to avoid confusion.

The input file is a text file. Some lines of the input file are empty, some are comments, and the remaining lines are (in this stage) rules. Rules commence with a rule header line that defines targets and dependencies. Each rule contains zero or more commands that are to be executed if the rule fires - i.e. if the targets need to be created or updated.

The syntax of each type of line is as follows. The syntax for dmake is similar to make, but is not the same.

  • Continuation of a line is indicated by a backslash () as the last character. Continuation means that the following line is joined to the end of the current line after removing the backslash, and then the result is treated as a single line. There may be multiple lines of continuation. Continuation may be applied to any type of line: command, header or command.

  • Empty lines contain only zero or more white-space characters - tabs and/or spaces. Empty lines are ignored completely. However, an empty line after a continuation becomes part of the previous line.

  • Comment lines have the character ‘#’ as the first non-white-space character on the line. (White-space characters are tab and space). Comment lines are completely ignored by the parser.

  • Rule header lines commence with a non-white-space character (other than ‘#’) in the first position of the line, and they have a colon (‘:’) somewhere in the line. The contents of dependency lines are file names. The file name(s) appearing before the colon are target(s) - they are the file(s) that the dmake rule is designed to create. The file names appearing after the colon are the dependencies - the files that are required in order to execute the command(s) that create the target(s).

  • Command lines commence with one or more white-space characters (tab or space). Each command line indicates a Unix command that is to be executed. The leading white space should be removed from the command.

For example, consider the following Dmakefile:

# This is a comment project: project.c defs.h     gcc -o project project.c 

In this simple dmake input file, there is a single comment line and an empty line - both are ignored by the parser. There is also one rule. The rule header indicates that the file project is the target and it depends on project.c and defs.h. The command line provides a gcc command that could be used to create or update the file project from the files project.c and defs.h. In general, rules may have one or more targets, zero or more dependencies and zero or more commands.

It is useful for a systems program such as dmake to have a debug option that reports the internal operation of the program. Indeed, the Linux make command has such an option. However, dmake’s debug option (-z) will behave differently. The debug output from dmake will be appropriate to the lab†⁳⁩⁴⁰⁡㉮⁤⁰⁣⁥⹤㱭⽡㹥മ਼㰯㸾䄍 ⁦⁡†⁥⁳⁲⁡⁥⁲⹤†⁰⁴㩵㱧⼠㹵൴ੰ㱵㸠ൔ੨⁥†⁤㱡㸠䵦⁳⁥†⁲⁴⁴⁴‬″⁥⁰⁥⹮㱤⽩㸠൤੥⁢⁵⁧†㱯㹰䅵⁴⁴⁵†‮‬†⁡⁥⁲†⁴⹥㱲⽲㹴൥ੳ⁴′‮⁥㱲㸠″†⁨⁥⁳⹬⁥䤠⁳Ⱜ†⁴‮⁤⁨†††††⁴⁣⁥‮⁴⁥⹩⁳䄠Ⱐ⁣†⁲⁡⁦⁩†⁳†⁲‾‾⁡⁨ⱱ⁵⁳ †⁕⁥
⁧⁡⁳⁩†⁣⸠㰳⼠㸠൴੨㱥⼠㹩൸ਠ㱭㉮⁵㴩∠⵲㉳ⵥ䐠ⵣⵡⴼ⵩ⴊ≔㹨㉥㨠⁤䑥†⁡†⁲⁥㱨⼠㉳㸠൴੨㱥㹳䕴†⁥††⁥⁧⁰††⁥…⹯⁲⁤‱⁤※⁣⁳⁧㱥㸠㱩⽴㹴㩨†䥦⁲†⁹⁩†⁦†⁡⁴†⁢⁴⁦⁴†⁸⁡⁩⁨⁥⹵⁩⁴⁴Ⱐ⁤⁧⁡†⁴⁴⹯⁲䄮‾‾†ⱬ⁥⁡⁴⁰⁲⁩⁳⁥⁵⁦⁗⁴⹯㱰⽴㹯൮ਬ㰠㉭⁡㴠≷ⵥ㍡ⵤ䔠ⵥ≰㹴⁳㌠㩣䕮⁦㱮⽧㉤㹭ൡ੫㱥㹷††⁥㱴㹵㱥⽳㹵⁲⁲⁲†⁴⁴⁴⁤⁵⁴⸍ 䤠†‾⁰⁲⁵⁳⹥㰠⽳㹭൰੬㱥㉯⁵㵵≴⵳㐠ⵥ⵰≥㹲†㑩㩮†⁴㰨⽳㉥㸠ൢ੥㱬㹷⁔†⁴⁥⁵⁵㱴㹩㱤⽥㸠⁢⁳⁥†⁤ⁱ⁹†⁳⁴†⹩䙥ⱡ⁴⁹⁰⁴⁥⁡†䍴⁨†Ⱐ⁥⁣†♳㬠⁵⁳⁨⁴⁰⁡⁴†⁲Ⱐ†⁩⁵†⁵⁰⁲⁴⁵⁡⁲⁡⁴⁤†⁵⁥⁥⁴⹲⁵⁳Ɐ⁧⁴⁣††⁵⵴⁰†⁥⁦†⁥†⁴⁤⁣⹯䘠⁤†Ɐ⁵⁲†††Ⱐ⁳⁥⁆⁰⁨⡥⁵†⥴⁩††⁥††⁳⁳⁹⁩⁩⁴⹡㱣⽥㹦൲੯㱭㹴⁣†⁡㱧㹴㰯⽬㸠†‼⁹⁡⁥†⁥†⁤⁣⁲⁳⁲⁲†⸠⁧⁥†⁥⁲⁡⁳⁴ⱦ⁩⁩†⁲⁤⁵††⁩
⁨⁦⁥⁦⁴⁥⁢††⁥⹹㰠⽬㹮g lines and arbitrarily large files.

Examples:

$ dmake -z1 

This command reads Dmakefile and prints out the stage 1 debug report for that input file.

$ dmake -f Dmakefile2 -z1 

This command reads Dmakefile2 and prints out the stage 1 debug report for that input file.

Marking

The auto-marker will test your submission for this stage with the test files provided to you and with additional hidden test files. Some tests will be performed using the -f option and some will be performed by using an input file with the name Dmakefile. Therefore, your program must support both modes of operation. You may assume that the hidden test files have similar features as the test files that are provided to you - for example, instances of comments, of rules with and without commands, and both small and large files, and errors. While there are additional features that are introduced in later stages, your program will never be auto-marked using the -z1 option with those additional features. This means that, in later stages, you can add those features to the -z1 debug output (if you wish) without being concerned about failing the stage 1 tests because those features will not be tested with the -z1 option.

When your dmake program is executed with the -z1 option, it should print out the -z1 debugging output and then terminate. It

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!