Skip to content

Instantly share code, notes, and snippets.

@hedinasr
Created March 15, 2017 20:52
Show Gist options
  • Save hedinasr/2d8026eee57929c4198f71a6037c1e05 to your computer and use it in GitHub Desktop.
Save hedinasr/2d8026eee57929c4198f71a6037c1e05 to your computer and use it in GitHub Desktop.
Generic Makefile for C++ projects
ECHO = printf
CAT = cat
RM = rm
FIND = find
UNAME = $(shell uname)
CPPFLAGS = -ggdb -Wall -pedantic -ansi
LDFLAGS =
CC = g++
LD = g++
SRCD = src
INCD = include
OBJD = obj
BIND = bin
LIBD =
LIBS =
EXEC = <exec_name>
SRCS = $(wildcard $(SRCD)/*.cpp)
OBJ = $(SRCS:.cpp=.o)
OBJS := $(addprefix $(OBJD)/, $(notdir $(OBJ)))
default: $(BIND)/$(EXEC)
$(BIND)/$(EXEC): $(OBJS)
@$(ECHO) "Linking ..\n"
$(LD) -o $@ $^ $(LDFLAGS) $(LIBD) $(LIBS) -Wl,-rpath ./
$(OBJD)/%.o: $(SRCD)/%.cpp
@$(ECHO) "Compiling source file ..\n"
$(CC) -o $@ -c $< $(CPPFLAGS) -I$(INCD)
clean:
@$(FIND) $(OBJD) -name *.o -delete
mrproper: clean
@$(RM) -f $(BIND)/$(EXEC)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment