Created
October 12, 2022 02:39
-
-
Save jacksonhorton/741f640dd4101d6b3f820e16a7cf8e3e to your computer and use it in GitHub Desktop.
Makefile for a main.cpp file with one class header/implementation dependency
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This makefile is for a main file with one external header and implementation file (.h/.cpp) | |
## Variables | |
# target is the name of the binary executable | |
TARGET=main | |
# class is the name of the class to include in the target.cpp file | |
CLASS=Vector | |
# compiler is g++ | |
CC=g++ | |
# compile with all warnings and extras | |
CFLAGS=-g -Wall -Wextra | |
## Targets | |
# compile everything | |
all: $(TARGET) | |
# this target compiles the binary executable; it requires all of the object code files from the headers and other files | |
$(TARGET): $(TARGET).o $(CLASS).o | |
$(CC) $(CFLAGS) -o $(TARGET) $(TARGET).o $(CLASS).o | |
$(TARGET).o: $(TARGET).cpp $(CLASS).cpp | |
$(CC) $(CFLAGS) -c $(TARGET).cpp | |
$(CLASS).o: $(CLASS).cpp | |
$(CC) $(CFLAGS) -c $(CLASS).cpp | |
# remove all temp files, machine code, binary files, etc. | |
clean: | |
$(RM) *.o *~ *# $(TARGET) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment