Makefiles on UH ITS RedHat Linux

  1. 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.
  2. 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
  3. Make sure you can compile and run the file aloha.c without using a makefile. See the Software Instructions webpage for details.
  4. Make a copy of makefile-aloha to a file called makefile with the cp command: cp makefile-aloha makefile
    cp makefile-aloha makefile
  5. Run the commands in the makefile with the make command: make
    make
  6. The commands in the makefile will be displayed on the screen:
    gcc -c aloha.c
    gcc aloha.o -o program

    commands in the makefile
  7. Type the "dot-slash" (./) and then the executable file's name: ./program
    And you will see the output of your program.
    run program
  8. 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
  9. Make a copy of makefile-double to a file called makefile with the cp command: cp makefile-double makefile
    cp makefile-double makefile
  10. 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


    make
  11. Type the "dot-slash" (./) and then the executable file's name: ./program
    And you will see the output of your program.
    run program
  12. If you want to use a makefile, which has a different name than "makefile", use the following command:
    make -f myMakeFile