ECE472/572 (UCLX) Assignment 4
Prepare for the lab
Answer these questions while doing this lab – they will help you understand the procedure and better prepare for the tests.
- What is Makefile and what is its basic structure?
- What are the dependencies?
- What are the rules?
- Why preserving tabs ('\t') and not allowing them to be converted to spaces (' ') in the Makefile is important?
- What does Draw Spaces do when activated in gedit? Why it may be useful when editing makefiles?
- Does the file controlling the behavior of make command need to to be named Makefile with capitalized first character? Why so, or why not?
- What are the differences between a compiler and a linker?
- What does ar program do, what are its input file(s), and how its result file is used later?
- What are the differences between a static library and a shared library?
- What are the linker options -L and -l? Why -L option is needed in our project?
- How are Makefile variables declared and used? Why it is convenient to use them?
Creating static libraries and introduction to Makefile
Download and unpack the code.tar.gz
project. Learn how to unpack it using console window utilities rather
than graphical tools. Modify the existing Makefile so that it support
four projects - building tnplib static library and then three programs. You can start with the partialy completed Makefile . The third project is
http_multi.cpp. Compile and run all
programs. Use a Web browser to verify whether they work and what they
do. Be prepared to
answer all questions regarding unpacking and packing the project, and the structure of Makefiles.
- Prepare the gedit text editor to be more useful when editing makefiles:
- sudo apt-get install gedit-plugins
- Run gedit and enable the plugin called Draw Spaces. See: MENU/Edit/Preferences/Plugins tab
- You can disable and re-enable it at any time. If you cannot get used to the new view of your text files, please enable it at least once for a short time when editing the Makefile
- Using a Web browser save the code.tar.gz project into a folder where you want to do your work
- open a console window and go to the folder where you saved the file
- unpack it
- find the name of the folder that was created, and go to the folder
- edit file named http_multi.cpp (create it) and paste contents of http_multi.cpp
- edit Makefile
- modify the Makefile to include the third target project (create appropriate rule entires and modify the rule for all)
- run make all
- start on of the compiled programs
- Verify if the programs do work an d what they do using a Web browser. Location is http://localhost:PORT/
where PORT is the port number for a program (e.g. 80801, or 8082, or 8083)
- create a rule entry for creating the libtnplib.a that depends on tnplib.o
Note: in order to create a library one needs to run:
- ar -rcs libtnplib.a tnplib.o
- In other rules replace dependence from tnplib.o to libtnplib.a
- The linker now should not use tnplib.o but instead the static library -L. -ltnplib
and place it after any other *.o files because of
possible command line argument interpretation error inside g++
- Modify the options for ARFLAGS as necessary close to the top of the file
- Add tnplib as an option to include as a library in the global rule for LDLIB close to the top of the file
- Modify rule clean to remove the compiled library as well
- run make all and inspect the folder
- run make clean and inspect the folder
- run make tar to prepare the file for submission
Drop off the compressed (tar-gzipped) contents of your project folder in the corresponding assignment drop box on