first makefile

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# 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) 
Last edited on
Also anyone know how to turn an auto-managed CDT project under eclipse into a self-managed ?
Last edited on
Topic archived. No new replies allowed.