Makefiles on UH ITS RedHat Linux
-
The make command will execute the commands listed in a file called makefile.
(Note that there is no ".txt" or any other extension on this file.)
make itself is a utility program that automates the steps necessary to do something like compile a program.
See the instructions below on how to create a makefile and use a makefile.
-
Download these files and save them on UH ITS Linux
(or copy and paste the text of the files using a Linux editor, such as vi):
aloha.c
and
makefile-aloha
-
Make sure you can compile and run the file aloha.c
without using a makefile.
See the Software Instructions webpage for details.
-
Make a copy of makefile-aloha
to a file called makefile
with the cp command: cp makefile-aloha makefile
-
Run the commands in the makefile with the make command: make
-
The commands in the makefile will be displayed on the screen:
gcc -c aloha.c
gcc aloha.o -o program
-
Type the "dot-slash" (./) and then the executable file's name: ./program
And you will see the output of your program.
-
Next, let's try a makefile that links and compiles muliple files!
Download these files and save them on UH ITS Linux
(or copy and paste the text of the files using a Linux editor, such as vi):
inputdouble.c,
getdouble.c,
getdouble.h,
and
makefile-double
-
Make a copy of makefile-double
to a file called makefile
with the cp command: cp makefile-double makefile
-
Run the commands in the makefile with the make command: make
The commands in the makefile will be displayed on the screen:
gcc -c inputdouble.c
gcc -c getdouble.c
gcc inputdouble.o getdouble.o -o program -lm
-
Type the "dot-slash" (./) and then the executable file's name: ./program
And you will see the output of your program.
-
If you want to use a makefile, which has a different name than "makefile",
use the following command:
make -f myMakeFile