Created
March 15, 2017 20:52
-
-
Save hedinasr/2d8026eee57929c4198f71a6037c1e05 to your computer and use it in GitHub Desktop.
Generic Makefile for C++ projects
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
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