Hey, this is my first makefile and I've tried to add as many bells and whistles as possible. Basically I've never used most of the GCC commands I've added, so I'm unsure of conflicting flags but didn't see anything in man(1) to suggest they would. Anyway, would like someone to take a look and add suggested improvements or fixes thanks. I haven't tested as I haven't figured out how to make eclipse work for me yet.
edit: Also I'm not sure if lines 8-10 will work as the variables have not been declared yet.
# date: Friday, 12/02/2010
# ============================================================
# ==== CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT ====
# ============================================================
# don't need changing see below for flags and libs
CC= g++ # ONLY change if source allows
RM= rm -fv # force, verbose
CFLAGS= -c $(MYCFLAGS)
LIBS= -lm $(MYLIBS)
CLIBS= -lm $(MYCLIBS)
# compiler flags.
PEDANTIC= -pedantic-errors -ansi # strict
W_OPTS= -Wall
DEBUG= -ggdb
TIME= -ftime-report
# Add options or remove, to enforce behaviour
MYCFLAGS= $(W_OPTS) $(PEDANTIC) $(DEBUG) $(TIME)
MYLIBS=
MYCLIBS=
# possibly needed for future versions
AR= ar rcu
RANLIB= ranlib
MKDIR= mkdir -p
# change to program specific files
MAIN_OBJ= a1.o
CLASS_OBJS= class1.o # add all object files you want here
CLASS_HEAD= class1.h # add all headers you want included here
CLASS_SRC= class.cpp
EXEC= a1
# currently not used, change below end of settings to inlcude
CLASS_OTHERS= # add any others here, such as .c,.a,.cxx etc
#####################################################
# INSTALL NOT IMPLEMENTED YET BUT TEMPLATE INCLUDED #
#####################################################
# Take care if INSTALL_TOP is not an absolute path. #
#####################################################
INSTALL_TOP= /usr
INSTALL_BIN= $(INSTALL_TOP)/bin
INSTALL_INC= $(INSTALL_TOP)/include
INSTALL_LIB= $(INSTALL_TOP)/lib
INSTALL_MAN= $(INSTALL_TOP)/man/man1
INSTALL= install -p
INSTALL_EXEC= $(INSTALL) -m 0755
INSTALL_DATA= $(INSTALL) -m 0644
# if you don't have install you can use cp #
# INSTALL= cp -p
# INSTALL_EXEC= $(INSTALL)
# INSTALL_DATA= $(INSTALL)
# ============================================================
# ==== END OF USER SETTINGS, NO NEED TO CHANGE BELOW THIS ====
# ============================================================
################
# pseudotarget #
################
help :
@echo
@echo type make followed by one of the following
@echo " prog - to create the executable prog"
@echo " clean - to remove all files make creates"
@echo " run - to excute prog. If prog does not exist it creates it first"
@echo
ALL_OBJS= $(MAIN_OBJ) $(CLASS_OBJS)
.SUFFIXES: #remove predefined suffixes
.SUFFIXES: .cpp .o
#######################
# Create object files #
#######################
.cpp.o:
$(CC) $(CFLAGS) $<
#####################
# Create executable #
#####################
$(EXEC) : $(ALL_OBJS)
$(CC) -o $@ $(ALL_OBJS) $(LIBS) $(CLIBS)
###########
# Headers #
###########
$(ALL_OBJS): $(CLASS_HEAD)
###############
# Run program #
###############
run : $(EXEC)
./$(EXEC)
#################
# Clean up junk #
#################
clean :
$(RM) $(ALL_OBJS) $(EXEC)
####################
# Start of Install #
####################
# what to install
TO_BIN= $(EXEC)
TO_INC= $(CLASS_HEAD)
TO_LIB=
TO_MAN=
TO_SRC= $(CLASS_HEAD) $(CLASS_SRC)
# version and release
V= 1.0
R= 1.1
# install is not implemented : but basic template included
# install : prog
# $(MKDIR) $(INSTALL_BIN) $(INSTALL_INC) $(INSTALL_LIB) $(INSTALL_MAN)
# $(INSTALL_EXEC) $(TO_BIN) $(INSTALL_BIN)
# $(INSTALL_DATA) $(TO_INC) $(INSTALL_INC)
# $(INSTALL_DATA) $(TO_LIB) $(INSTALL_LIB)
# cd doc && $(INSTALL_DATA) $(TO_MAN) $(INSTALL_MAN)
# (end of makefile)