OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-memmap/] [src/] [make/] [Makefile] - Blame information for rev 8

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 8 jlechner
#############################################################################
2
#
3
# Generic Makefile for C/C++ Program
4
#
5
# License: GPL (General Public License)
6
# Author:  whyglinux 
7
# Date:    2006/03/04 (version 0.1)
8
#          2007/03/24 (version 0.2)
9
#          2007/04/09 (version 0.3)
10
#          2007/06/26 (version 0.4)
11
#          2008/04/05 (version 0.5)
12
#
13
# Description:
14
# ------------
15
# This is an easily customizable makefile template. The purpose is to
16
# provide an instant building environment for C/C++ programs.
17
#
18
# It searches all the C/C++ source files in the specified directories,
19
# makes dependencies, compiles and links to form an executable.
20
#
21
# Besides its default ability to build C/C++ programs which use only
22
# standard C/C++ libraries, you can customize the Makefile to build
23
# those using other libraries. Once done, without any changes you can
24
# then build programs using the same or less libraries, even if source
25
# files are renamed, added or removed. Therefore, it is particularly
26
# convenient to use it to build codes for experimental or study use.
27
#
28
# GNU make is expected to use the Makefile. Other versions of makes
29
# may or may not work.
30
#
31
# Usage:
32
# ------
33
# 1. Copy the Makefile to your program directory.
34
# 2. Customize in the "Customizable Section" only if necessary:
35
#    * to use non-standard C/C++ libraries, set pre-processor or compiler
36
#      options to  and linker ones to 
37
#      (See Makefile.gtk+-2.0 for an example)
38
#    * to search sources in more directories, set to 
39
#    * to specify your favorite program name, set to 
40
# 3. Type make to start building your program.
41
#
42
# Make Target:
43
# ------------
44
# The Makefile provides the following targets to make:
45
#   $ make           compile and link
46
#   $ make NODEP=yes compile and link without generating dependencies
47
#   $ make objs      compile only (no linking)
48
#   $ make tags      create tags for Emacs editor
49
#   $ make ctags     create ctags for VI editor
50
#   $ make clean     clean objects and the executable file
51
#   $ make distclean clean objects, the executable and dependencies
52
#   $ make help      get the usage of the makefile
53
#
54
#===========================================================================
55
 
56
## Customizable Section: adapt those variables to suit your program.
57
##==========================================================================
58
 
59
# The pre-processor and compiler options.
60
MY_CFLAGS = @MAKEFILE_CFLAGS@
61
 
62
# The linker options.
63
MY_LIBS   =
64
 
65
# The pre-processor options used by the cpp (man cpp for more).
66
CPPFLAGS  = -Wall
67
 
68
# The options used in linking as well as in any direct use of ld.
69
LDFLAGS   = @MAKEFILE_LDFLAGS@,-T@MAKEFILE_LINKER_SCRIPT@
70
 
71
# The directories in which source files reside.
72
# If not specified, only the current directory will be serached.
73
SRCDIRS   =
74
 
75
# The executable file name.
76
# If not specified, current directory name or `a.out' will be used.
77
PROGRAM   = main
78
 
79
## Implicit Section: change the following only when necessary.
80
##==========================================================================
81
 
82
# The source file types (headers excluded).
83
# .c indicates C source files, and others C++ ones.
84
SRCEXTS = .c .C .cc .cpp .CPP .c++ .cxx .cp
85
 
86
# The header file types.
87
HDREXTS = .h .H .hh .hpp .HPP .h++ .hxx .hp
88
 
89
# The pre-processor and compiler options.
90
# Users can override those variables from the command line.
91
CFLAGS  =
92
CXXFLAGS=
93
 
94
# The C program compiler.
95
CC     = @MAKEFILE_GCC_BINARY@
96
 
97
# The C++ program compiler.
98
#CXX    = g++
99
 
100
# Un-comment the following line to compile C programs as C++ ones.
101
#CC     = $(CXX)
102
 
103
# The objcopy command.
104
OBJCOPY= @MAKEFILE_OBJCOPY_BINARY@
105
 
106
# The objdump command.
107
OBJDUMP= @MAKEFILE_OBJDUMP_BINARY@
108
 
109
# The command used to delete file.
110
RM     = rm -f
111
 
112
ETAGS = etags
113
ETAGSFLAGS =
114
 
115
CTAGS = ctags
116
CTAGSFLAGS =
117
 
118
## Stable Section: usually no need to be changed. But you can add more.
119
##==========================================================================
120
SHELL   = /bin/sh
121
EMPTY   =
122
SPACE   = $(EMPTY) $(EMPTY)
123
ifeq ($(PROGRAM),)
124
  CUR_PATH_NAMES = $(subst /,$(SPACE),$(subst $(SPACE),_,$(CURDIR)))
125
  PROGRAM = $(word $(words $(CUR_PATH_NAMES)),$(CUR_PATH_NAMES))
126
  ifeq ($(PROGRAM),)
127
    PROGRAM = a.out
128
  endif
129
endif
130
ifeq ($(SRCDIRS),)
131
  SRCDIRS = .
132
endif
133
SOURCES = $(foreach d,$(SRCDIRS),$(wildcard $(addprefix $(d)/*,$(SRCEXTS))))
134
HEADERS = $(foreach d,$(SRCDIRS),$(wildcard $(addprefix $(d)/*,$(HDREXTS))))
135
SRC_CXX = $(filter-out %.c,$(SOURCES))
136
OBJS    = $(addsuffix .o, $(basename $(SOURCES)))
137
DEPS    = $(OBJS:.o=.d)
138
 
139
## Define some useful variables.
140
DEP_OPT = $(shell if `$(CC) --version | grep "GCC" >/dev/null`; then \
141
                  echo "-MM -MP"; else echo "-M"; fi )
142
DEPEND      = $(CC)  $(DEP_OPT)  $(MY_CFLAGS) $(CFLAGS) $(CPPFLAGS)
143
DEPEND.d    = $(subst -g ,,$(DEPEND))
144
COMPILE.c   = $(CC)  $(MY_CFLAGS) $(CFLAGS)   $(CPPFLAGS) -c
145
COMPILE.cxx = $(CXX) $(MY_CFLAGS) $(CXXFLAGS) $(CPPFLAGS) -c
146
LINK.c      = $(CC)  $(MY_CFLAGS) $(CFLAGS)   $(CPPFLAGS) $(LDFLAGS)
147
LINK.cxx    = $(CXX) $(MY_CFLAGS) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS)
148
 
149
.PHONY: all objs tags ctags clean distclean help show
150
 
151
# Delete the default suffixes
152
.SUFFIXES:
153
 
154
all: $(PROGRAM)
155
 
156
# Rules for creating dependency files (.d).
157
#------------------------------------------
158
 
159
%.d:%.c
160
        @echo -n $(dir $<) > $@
161
        @$(DEPEND.d) $< >> $@
162
 
163
%.d:%.C
164
        @echo -n $(dir $<) > $@
165
        @$(DEPEND.d) $< >> $@
166
 
167
%.d:%.cc
168
        @echo -n $(dir $<) > $@
169
        @$(DEPEND.d) $< >> $@
170
 
171
%.d:%.cpp
172
        @echo -n $(dir $<) > $@
173
        @$(DEPEND.d) $< >> $@
174
 
175
%.d:%.CPP
176
        @echo -n $(dir $<) > $@
177
        @$(DEPEND.d) $< >> $@
178
 
179
%.d:%.c++
180
        @echo -n $(dir $<) > $@
181
        @$(DEPEND.d) $< >> $@
182
 
183
%.d:%.cp
184
        @echo -n $(dir $<) > $@
185
        @$(DEPEND.d) $< >> $@
186
 
187
%.d:%.cxx
188
        @echo -n $(dir $<) > $@
189
        @$(DEPEND.d) $< >> $@
190
 
191
# Rules for generating object files (.o).
192
#----------------------------------------
193
objs:$(OBJS)
194
 
195
%.o:%.c
196
        $(COMPILE.c) $< -o $@
197
 
198
%.o:%.C
199
        $(COMPILE.cxx) $< -o $@
200
 
201
%.o:%.cc
202
        $(COMPILE.cxx) $< -o $@
203
 
204
%.o:%.cpp
205
        $(COMPILE.cxx) $< -o $@
206
 
207
%.o:%.CPP
208
        $(COMPILE.cxx) $< -o $@
209
 
210
%.o:%.c++
211
        $(COMPILE.cxx) $< -o $@
212
 
213
%.o:%.cp
214
        $(COMPILE.cxx) $< -o $@
215
 
216
%.o:%.cxx
217
        $(COMPILE.cxx) $< -o $@
218
 
219
# Rules for generating the tags.
220
#-------------------------------------
221
tags: $(HEADERS) $(SOURCES)
222
        $(ETAGS) $(ETAGSFLAGS) $(HEADERS) $(SOURCES)
223
 
224
ctags: $(HEADERS) $(SOURCES)
225
        $(CTAGS) $(CTAGSFLAGS) $(HEADERS) $(SOURCES)
226
 
227
# Rules for generating the executable.
228
#-------------------------------------
229
$(PROGRAM):$(OBJS)
230
ifeq ($(SRC_CXX),)              # C program
231
        $(LINK.c)   $(OBJS) $(MY_LIBS) -o $@
232
        $(OBJCOPY)  -O srec $(PROGRAM) $(PROGRAM).srec
233
        $(OBJDUMP)  -DGlrswxz $(PROGRAM) > $(PROGRAM).txt
234
else                            # C++ program
235
        $(LINK.cxx) $(OBJS) $(MY_LIBS) -o $@
236
        $(OBJCOPY)  -O srec $(PROGRAM) $(PROGRAM).srec
237
        $(OBJDUMP)  -DGlrswxz $(PROGRAM) > $(PROGRAM).txt
238
endif
239
 
240
ifndef NODEP
241
ifneq ($(DEPS),)
242
  sinclude $(DEPS)
243
endif
244
endif
245
 
246
clean:
247
        $(RM) $(OBJS) $(PROGRAM).i $(PROGRAM).s $(PROGRAM) $(PROGRAM).srec $(PROGRAM).txt
248
 
249
distclean: clean
250
        $(RM) $(DEPS) TAGS
251
 
252
# Show help.
253
help:
254
        @echo 'Generic Makefile for C/C++ Programs (gcmakefile) version 0.5'
255
        @echo 'Copyright (C) 2007, 2008 whyglinux '
256
        @echo
257
        @echo 'Usage: make [TARGET]'
258
        @echo 'TARGETS:'
259
        @echo '  all       (=make) compile and link.'
260
        @echo '  NODEP=yes make without generating dependencies.'
261
        @echo '  objs      compile only (no linking).'
262
        @echo '  tags      create tags for Emacs editor.'
263
        @echo '  ctags     create ctags for VI editor.'
264
        @echo '  clean     clean objects and the executable file.'
265
        @echo '  distclean clean objects, the executable and dependencies.'
266
        @echo '  show      show variables (for debug use only).'
267
        @echo '  help      print this message.'
268
        @echo
269
        @echo 'Report bugs to .'
270
 
271
# Show variables (for debug use only.)
272
show:
273
        @echo 'PROGRAM     :' $(PROGRAM)
274
        @echo 'SRCDIRS     :' $(SRCDIRS)
275
        @echo 'HEADERS     :' $(HEADERS)
276
        @echo 'SOURCES     :' $(SOURCES)
277
        @echo 'SRC_CXX     :' $(SRC_CXX)
278
        @echo 'OBJS        :' $(OBJS)
279
        @echo 'DEPS        :' $(DEPS)
280
        @echo 'DEPEND      :' $(DEPEND)
281
        @echo 'COMPILE.c   :' $(COMPILE.c)
282
        @echo 'COMPILE.cxx :' $(COMPILE.cxx)
283
        @echo 'link.c      :' $(LINK.c)
284
        @echo 'link.cxx    :' $(LINK.cxx)
285
 
286
## End of the Makefile ##  Suggestions are welcome  ## All rights reserved ##
287
#############################################################################

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.