Learn how to work with makefiles and make utility
(the manual is here)
by making a "Hello, world"
program.
Check that your filesharing system works.
If you work on Lifa, create the directory for the hello-world-excercise with the command
mkdir --parents ~/public_html/numeric/hello
and make the exercise in that directory.
If you work on your own box create the directory, say "/path_to_numeric/numeric/hello", wherever
you find it suitable and then upload/synchronise the
"/path_to_numeric/numeric" directory with your filesharing system.
The commands in the makefile must be prefixed with the tabulator-sign
(by default) which might not be visible in the nano editor. To make
them visible, create a ~/.nanorc file with the content
(or whatever colors you might prefer) where there is the tabulator
sign (obtained by pressing the tabulator-key on the keyboard)
between the quotes in the second line.
syntax "makefile" "[Mm]akefile"
color white,magenta " "
Another solution
is to use GNU Make version 3.82+ (which is installed on
lifa as ~efb23/bin/make) where the recipe prefix is
controlled by the variable .RECIPEPREFIX. You can then set
it to any character, for example ";" with the command
.RECIPEPREFIX := ;
It seems that on lifa the default value of the TERM
environment variable (which specifies the type of the terminal you are
using) is vt100, which is colorless. In order to have colors
you have to change the value of this variable to xterm. You
have to find out in which file this "vt100" is hiding with the command
and then go to that file and change "vt100" to "xterm".
Most probably you will have to do the following:
grep vt100 .*
On lifa if your shell is csh,
place the following line in your ~/.cshrc file (where
~/ is the alias for your home directory)
setenv TERM xterm
If your shell is bash, place the
following line in your ~/.profile file
export TERM=xterm
You can find out which shell you run with the command
ps -p $$or
echo $0If you run csh, but want to run bash, put the following lines into your
~/.login file.
if ( -f /usr/users/efb23/bin/bash ) then setenv SHELL /usr/users/efb23/bin/bash exec $SHELL --login endif
If syntax highlighting does not work for you on lifa, you can include
(one of) the
following lines in your ~/.nanorc file:
include /usr/share/nano/c.nanorc # c-syntax highlighting
include /usr/share/nano/java.nanorc # java-syntax highlighting
include /usr/share/nano/python.nanorc # python-syntax highlighting
include /usr/share/nano/tex.nanorc # tex-syntax highlighting
include /usr/users/efb23/share/nano/fortran.nanorc # fortran-syntax highlighting
Hello, world
Create a project with the corresponding makefile with the following targets:
The (default) target "A" the prerequisite of which is a text
file, say out.A.txt, (eventually with the text
"hello, your_name"):
A : out.A.txt
The file out.A.txt should be built by
redirecting
the
output from a program, say mainA, which prints
"hello, your_name" on the standard output:
out.A.txt : mainA
./mainA > out.A.txt
The mainA program should be built from a
mainA.c using the recipe
mainA : mainA.c
# without an explicit rule here the following implicit rule applies
# $(LINK.c) $^ $(LDLIBS) -o $@
The matinA.c file should look like this,
#include<stdio.h>
int main(){
printf("hello, your_user_name\n");
return 0;
}
The interpreted languages, like python, would rather run the program via the interpreter,
PYTHON = ~efb23/bin/python3 # python3 version 3.5.1
out.A.txt : mainA.py
$(PYTHON) mainA.py > out.A.txt
where the mainA.py file should look like this,
print("hello, your_user_name")
Target "cleanA" (without prerequisites) that removes all generated files leaving only the essential files:
cleanA :
rm -f mainA out.A.txt
Make sure commands make A and make cleanA
work as intended.
Comment an arbitrary line in the makefile explaining its purpose.
Check
Create a "check" targets that check whether the "A" target has been built correctly. For example,
check: out.A.txt
@echo "checking target A ..."
@echo "hello, $(shell whoami)" > correct.txt
@diff --brief correct.txt out.A.txt
@echo "target A seems to be ok ..."
@rm -f correct.txt