Skip to content

Instantly share code, notes, and snippets.

@IggyBlob
Created November 27, 2017 12:19
Show Gist options
  • Save IggyBlob/3be154d803419cabc9e08b18fae9465c to your computer and use it in GitHub Desktop.
Save IggyBlob/3be154d803419cabc9e08b18fae9465c to your computer and use it in GitHub Desktop.
ifeq ($(OS),Windows_NT)
EXEEXT = .exe
else
EXEEXT =
endif
TARGET = myprog$(EXEEXT)
# compiler settings
CC = g++-7
CCFLAGS = -g -std=c++17 -Wall -Wextra -Wconversion -Wpedantic
# linker/loader settings
LD = g++-7
LDFLAGS = #-static # link all libraries statically
# names of all .cpp and .o files
CFILES = $(wildcard *.cpp) # $(..) works for gmake only
OFILES = $(CFILES:.cpp=.o) # $(..) works for gmake only
# name of file containing all generated dependencies
DEPENDFILE = .depend
# rule how to compile .o files from .c files
%.o: %.cpp
$(CC) $(CCFLAGS) -c $<
.PHONY: all run depend clean
all: $(TARGET)
# main target: prg is the name of the executable to build
$(TARGET): $(OFILES)
$(LD) -o $@ $(OFILES) $(LDFLAGS)
# execute target
run: $(TARGET)
@./$(TARGET)
# clean up directory
clean:
$(RM) $(TARGET) *.o core *.bak *~
# create dependencies using gcc -MM
depend:
$(CC) $(CCFLAGS) -MM $(CFILES) > $(DEPENDFILE)
-include $(DEPENDFILE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment