Two ways to configure make to execute a specific compilation command with specific options are:
- Makefiles
- Environment Variables
Assuming you have a source code file of a C program named prog.c
, to manually configure make
to execute the same compilation command as the one in the lectures follow either of the following ways:
Configuring make Using Makefiles
create a file named Makefile
in the same directory as your program and paste the following text in it
prog: prog.c
clang -ggdb3 -O0 -std=c99 -Wall -Werror prog.c -lcs50 -lm -o prog
NOTE: the second line starts with a tab not spaces
- save the file.
Configuring make Using Environment Variables
Two ways of achieving this are
- temporarily setting the values of some environment variables
- permanently setting the values of these environment variables.
Configuring make Temporarily
Open up a terminal window and execute these commands
export CC="clang"
export CFLAGS="-ggdb3 -O0 -std=c99 -Wall -Werror"
export LDLIBS="-lcs50 -lm"
Configuring make Permanently
Open up the terminal window and execute these commands
cd
sudo gedit .profile
NOTE: if asked to enter a password, enter "crimson"
paste the following lines at the end of the file
export CC="clang"
export CFLAGS="-ggdb3 -O0 -std=c99 -Wall -Werror -Wno-unused-variable"
export LDLIBS="-lcs50 -lm"
log off and log back in
update50
. or, open a separate terminal window and runmake
there.