Compiling and Makefiles


Compiling small programs on Unix/Linux

Using Makefiles to Manage Larger Programs

Longer Makefile Example

This example has four targets: two executables (testpp1a and disassembler), a target that represents both (all), and a target that removes intermediate and final output files (clean).

all:        testpp1a \
            disassembler

testpp1a:   pp1.h \
            printFuncs.h \
            verifyMIPSInstruction.c \
            binToDec.c \
            printDebug.c \
            printError.c \
            testpp1a.c
            gcc verifyMIPSInstruction.c binToDec.c printDebug.c \
                printError.c testpp1a.c -o testpp1a

# The assembler will probably have other source files in addition to these.
disassembler:   disassembler.h \
                printFuncs.h \
                verifyMIPSInstruction.c \
                binToDec.c \
                getRegName.c \
                printDebug.c \
                printError.c \
                disassembler.c
                gcc verifyMIPSInstruction.c binToDec.c getRegName.c \
                    printDebug.c printError.c disassembler.c -o disassembler

clean: 
        rm -rf *.o testpp1a disassembler


Alyce Brady, Kalamazoo College