makefile for C++


# PATH
srcdir=src/
bindir=bin/
docdir=doc/
savedir=save/

# VAR
CC=g++ -Wall -ansi -pedantic
OPTIONS=-lm
CP=cp
MKDIR=mkdir
MV=mv
RM=rm -f
SRC=$(wildcard $(srcdir)*.cpp)
HEAD=$(filter-out $(srcdir)main.h, $(SRC:.cpp=.h))
OBJ=$(subst $(srcdir), $(bindir), $(SRC:.cpp=.o))
PROG=$(bindir)prog


# PHONY
.PHONY : clean doc run

# ALL
all : dir $(PROG)

$(PROG) : $(OBJ)
$(CC) $^ -o $@ $(OPTIONS)

$(bindir)%.o : $(srcdir)%.cpp
$(CC) -c $< -o $@

# DIR
dir :
-$(MKDIR) -p $(bindir)

# RUN
run :
./$(PROG)

# CLEAN
clean :
$(RM) -r $(bindir)
$(RM) -r $(docdir)
$(RM) *~ *.bak *.old *.gch
$(RM) $(srcdir)*~ $(srcdir)*.bak $(srcdir)*.old $(srcdir)*.gch

# DOXYGEN
doc :
doxygen Doxyfile
i hope you like it, do you think i can upagde?
Why is dir a target?

No C++11.

No header dependencies.
Last edited on
I have never made makefiles, I've just used other people's, but I just wanted to comment:
@kbw: modern g++ versions use g++14 as the default. Guess Hugues could set -std=g++17 to be truly up to date (although some things are still experimental in -std=c++17, afaik).

But I guess explicitly listing C++1X is better to prevent confusion if an older compiler tries to build your project.
Last edited on
Topic archived. No new replies allowed.