You are suppose to know how to write a Makefile already. If you don't, you should learn it as soon as possible because your Makefile must work in all your programming assignment submissions. There are a few tutorials on make on the web. Here are links to some of them. I have not really read through these pages so I cannot guarantee their correctness.
There is an example of a simple Makefile below.
Please be aware that if you transfer a Makefile from a Windows environment to a UNIX environment, chances are, it will not work. The reason is that a line in a text file in Windows ends with "\r\n" while a line in a text file in UNIX ends with just "\n". The extra "\r" can confuse make on UNIX machines. But I'm sure you can write a small program to fix that.
Compiling Your Code
For this class, you must write your program in C and you must use gcc as your compiler. You are also required to run the gcc command with the -g -Wall commandline options. The -g commandline option turns debugging to make your program debuggable and the -Wall commandline option turns on most of the useful gcc warnings. Compiling with this option will find many simple mistakes in your programs. If your program needs it, you should also link to the multithreading library that came with the system. (You are not permitted to include any library that was not installed in the 32-bit Ubuntu 16.04 system.)
For warmup1 and warmup2, you must use the gcc compiler that came with the 32-bit Ubuntu 16.04 system. Please understand that we will not accept any other compiler to be used to compiler your program for grading. If you code only works when it is compiled with a different version of the gcc compiler, you will not get any credit for it. To see what version of gcc you are running, please run the following command in a Terminal window:
gcc --versionOn a 32-bit Ubuntu 16.04 system, you should see that you are running gcc version 5.4.0. If you have accidentically upgraded your system and end up with a different version of gcc, please contact the instructor. Most likely, you will have to delete your 32-bit Ubuntu 16.04 system and reinstall everything to make sure that the grader will be able to compile your code!
If your program cannot be compiled with a required compiler and run on a required system, your program will not be graded (and it will get a grade of zero). Please understand that we are not permitted to write code for you (or fix your code to get it compiled).
Since grading of all programming assignments must be done on a 32-bit Ubuntu 16.04 machine running inside VirtualBox/VagrantBox, it's imperative that you make sure that your code can be compiled and run on a 32-bit Ubuntu 16.04 machine running inside VirtualBox/VagrantBox. Please understand that even if your code runs perfectly on some other systems, we cannot give you any partial credit for that.
We will evaluate your submission by copying all the files you have submitted into an empty directory on the grader's 32-bit Ubuntu 16.04 machine running inside VirtualBox/VagrantBox and then type the following command:
makeIf an individual programming assignment spec has a more specific way of producing the required executables (which is typically the case), you must follow it. Minor variation (such as using gmake) is allowed, but you must describe in details how to compile your code near the top of your README file. The grader is not allowed to use a visual tool or an IDE to compile your code. If this does not produce the desired executable(s), you will probably lose a lot of points. You may lose quite a few points if the grader has to debug and modify your Makefile in order to get your code to compile. How many points you will lose depends on how hard it is for the grader to get your Makefile to work. You will receive a score of zero if we cannot find a way to compile your code without modifying your source code.
Here are some additional requirements (sorry about redundancy with the programming assignment specs):
When you compile, if you get warning messages saying that certain .c or .h file has no newline at end of file, then it's cause by the same problem (i.e., you have created these files in Windows). Please run "dos2unix" to convert such a DOS/Windows text file into a Unix text file.
A README file is the documentation of your submission. The filename you must use for a README is "x-README.txt" where "x" is an appropriate name for the assignment. You must download a README file template from the respective spec, edit it with a text editor by supplying all the required information, and then include it with your submission. You must not delete any line from the README file template or the grader will have to deduct points.
Such a README file includes the following sections:
For warmup assignments, there is no requirement to use a fancy Makefile. You can just use a simple Makefile that contains 2 lines. The first line is the "target line" and it looks like:
target: fileswhere target is the "target" of your "make" command and files is a space-separated list of source files and header files that make up your program.
For example, if you need to type "make foo" to create your executable, then "foo" is the "target". Typically, the "target" is the name of your executable file. If you need "foo.c", "bar.c", and "bar.h" in order to build the foo executable, then the first line of your Makefile can look like:
foo: foo.c bar.c bar.hThe way you should read the above line is, "The foo target depends on foo.c bar.c bar.h." The idea here is that if any of files the target depends on changes and if you type "make target", the command in the line immediately follow the target line will get executed. There must be no blank character at the beginning of a target line.
The 2nd line is a line of command and it must begin with a <TAB> character and follow by a Unix/Linux command. Our simple Makefile can look like:
foo: foo.c bar.c bar.h gcc -g -Wall -o foo foo.c bar.cThe leading blank space you see in front of the 2nd line must be a <TAB> character or this won't work! Also, there must be no intervening line between the target line and line of command. Using the above Makefile, if you type "make foo" and if foo.c, bar.c, or bar.h has changed, the "make" program will run the "gcc -g -Wall -o foo foo.c bar.c" command. (The command doesn't even need to have anything to do with compiling a program!)
In general, there can be multiple sections in a Makefile and a target can depend on other targets in another section of the Makefile (therefore, we can have a tree of dependencies). Each section starts with a target line and followed by one or more lines of commands. The target line must be have no leading space characters and each line of command must begin with a <TAB> character and you cannot have a blank link within a section. When you type "make target", the "make" program search the Makefile for a section whose target line contains the target of your "make" command, check the dependencies, and execute the corresponding lines of commands. For more details, please check out the recommanded tutorials mentioned at the top of this web page.
All warmup assignments also require that when you type "make clean", you must delete all generated binary files when you typed "make target" where "target" is the name of your executable file. In that case, your minimum "Makefile" must also contain a second section whose target is "clean" that depends on nothing and the command to execute should delete all generated binary files. The following is an example of such a file:
foo: foo.c bar.c bar.h g++ -g -Wall -std=c++11 -o foo foo.c bar.c clean: rm -f foo *.oIf you type "make clean", it will delete the file "foo" and all the files with a ".o" filename extension. If you create additional binary files (such as ".gch" files) when you "make", you must change the last line so that they also get deleted when you type "make clean".
How do you make sure that make would work? It's actually very simple.