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

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-memmap/] [src/] [bootloader/] [Makefile] - Blame information for rev 19

Go to most recent revision | 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   = -lnosys
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   = @MAKEFILE_PROGRAM@
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 hex2quartus command.
104
HEX2QUARTUS = scarts-hex2quartus
105
 
106
# The objcopy command.
107
OBJCOPY= @MAKEFILE_OBJCOPY_BINARY@
108
 
109
# The objdump command.
110
OBJDUMP= @MAKEFILE_OBJDUMP_BINARY@
111
 
112
# The command used to delete file.
113
RM     = rm -f
114
 
115
ETAGS = etags
116
ETAGSFLAGS =
117
 
118
CTAGS = ctags
119
CTAGSFLAGS =
120
 
121
## Stable Section: usually no need to be changed. But you can add more.
122
##==========================================================================
123
SHELL   = /bin/sh
124
EMPTY   =
125
SPACE   = $(EMPTY) $(EMPTY)
126
ifeq ($(PROGRAM),)
127
  CUR_PATH_NAMES = $(subst /,$(SPACE),$(subst $(SPACE),_,$(CURDIR)))
128
  PROGRAM = $(word $(words $(CUR_PATH_NAMES)),$(CUR_PATH_NAMES))
129
  ifeq ($(PROGRAM),)
130
    PROGRAM = a.out
131
  endif
132
endif
133
ifeq ($(SRCDIRS),)
134
  SRCDIRS = .
135
endif
136
SOURCES = $(foreach d,$(SRCDIRS),$(wildcard $(addprefix $(d)/*,$(SRCEXTS))))
137
HEADERS = $(foreach d,$(SRCDIRS),$(wildcard $(addprefix $(d)/*,$(HDREXTS))))
138
SRC_CXX = $(filter-out %.c,$(SOURCES))
139
OBJS    = $(addsuffix .o, $(basename $(SOURCES)))
140
DEPS    = $(OBJS:.o=.d)
141
 
142
## Define some useful variables.
143
DEP_OPT = $(shell if `$(CC) --version | grep "GCC" >/dev/null`; then \
144
                  echo "-MM -MP"; else echo "-M"; fi )
145
DEPEND      = $(CC)  $(DEP_OPT)  $(MY_CFLAGS) $(CFLAGS) $(CPPFLAGS)
146
DEPEND.d    = $(subst -g ,,$(DEPEND))
147
COMPILE.c   = $(CC)  $(MY_CFLAGS) $(CFLAGS)   $(CPPFLAGS) -c
148
COMPILE.cxx = $(CXX) $(MY_CFLAGS) $(CXXFLAGS) $(CPPFLAGS) -c
149
LINK.c      = $(CC)  $(MY_CFLAGS) $(CFLAGS)   $(CPPFLAGS) $(LDFLAGS)
150
LINK.cxx    = $(CXX) $(MY_CFLAGS) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS)
151
 
152
.PHONY: all objs tags ctags clean distclean help show
153
 
154
# Delete the default suffixes
155
.SUFFIXES:
156
 
157
all: $(PROGRAM)
158
 
159
# Rules for creating dependency files (.d).
160
#------------------------------------------
161
 
162
%.d:%.c
163
        @echo -n $(dir $<) > $@
164
        @$(DEPEND.d) $< >> $@
165
 
166
%.d:%.C
167
        @echo -n $(dir $<) > $@
168
        @$(DEPEND.d) $< >> $@
169
 
170
%.d:%.cc
171
        @echo -n $(dir $<) > $@
172
        @$(DEPEND.d) $< >> $@
173
 
174
%.d:%.cpp
175
        @echo -n $(dir $<) > $@
176
        @$(DEPEND.d) $< >> $@
177
 
178
%.d:%.CPP
179
        @echo -n $(dir $<) > $@
180
        @$(DEPEND.d) $< >> $@
181
 
182
%.d:%.c++
183
        @echo -n $(dir $<) > $@
184
        @$(DEPEND.d) $< >> $@
185
 
186
%.d:%.cp
187
        @echo -n $(dir $<) > $@
188
        @$(DEPEND.d) $< >> $@
189
 
190
%.d:%.cxx
191
        @echo -n $(dir $<) > $@
192
        @$(DEPEND.d) $< >> $@
193
 
194
# Rules for generating object files (.o).
195
#----------------------------------------
196
objs:$(OBJS)
197
 
198
%.o:%.c
199
        $(COMPILE.c) $< -o $@
200
 
201
%.o:%.C
202
        $(COMPILE.cxx) $< -o $@
203
 
204
%.o:%.cc
205
        $(COMPILE.cxx) $< -o $@
206
 
207
%.o:%.cpp
208
        $(COMPILE.cxx) $< -o $@
209
 
210
%.o:%.CPP
211
        $(COMPILE.cxx) $< -o $@
212
 
213
%.o:%.c++
214
        $(COMPILE.cxx) $< -o $@
215
 
216
%.o:%.cp
217
        $(COMPILE.cxx) $< -o $@
218
 
219
%.o:%.cxx
220
        $(COMPILE.cxx) $< -o $@
221
 
222
# Rules for generating the tags.
223
#-------------------------------------
224
tags: $(HEADERS) $(SOURCES)
225
        $(ETAGS) $(ETAGSFLAGS) $(HEADERS) $(SOURCES)
226
 
227
ctags: $(HEADERS) $(SOURCES)
228
        $(CTAGS) $(CTAGSFLAGS) $(HEADERS) $(SOURCES)
229
 
230
# Rules for generating the executable.
231
#-------------------------------------
232
$(PROGRAM):$(OBJS)
233
ifeq ($(SRC_CXX),)              # C program
234
        $(LINK.c)   $(OBJS) $(MY_LIBS) -o $@
235
        $(OBJCOPY)  -O srec $(PROGRAM) $(PROGRAM).srec
236
        $(OBJDUMP)  -DGlrswxz $(PROGRAM) > $(PROGRAM).txt
237
 
238
        $(OBJCOPY)  --change-section-lma .text=0 $(PROGRAM) $(PROGRAM).tmp
239
        $(OBJCOPY)  -O ihex $(PROGRAM).tmp $(PROGRAM).hex
240
        $(HEX2QUARTUS) < $(PROGRAM).hex > $(PROGRAM).qhex
241
else                            # C++ program
242
        $(LINK.cxx) $(OBJS) $(MY_LIBS) -o $@
243
        $(OBJCOPY)  -O srec $(PROGRAM) $(PROGRAM).srec
244
        $(OBJDUMP)  -DGlrswxz $(PROGRAM) > $(PROGRAM).txt
245
 
246
        $(OBJCOPY)  --change-section-lma .text=0 $(PROGRAM) $(PROGRAM).tmp
247
        $(OBJCOPY)  -O ihex $(PROGRAM).tmp $(PROGRAM).hex
248
        $(HEX2QUARTUS) < $(PROGRAM).hex > $(PROGRAM).qhex
249
endif
250
 
251
ifndef NODEP
252
ifneq ($(DEPS),)
253
  sinclude $(DEPS)
254
endif
255
endif
256
 
257
clean:
258
        $(RM) $(OBJS) $(PROGRAM).i $(PROGRAM).s $(PROGRAM) $(PROGRAM).hex $(PROGRAM).qhex $(PROGRAM).srec $(PROGRAM).tmp $(PROGRAM).txt
259
 
260
distclean: clean
261
        $(RM) $(DEPS) TAGS
262
 
263
# Show help.
264
help:
265
        @echo 'Generic Makefile for C/C++ Programs (gcmakefile) version 0.5'
266
        @echo 'Copyright (C) 2007, 2008 whyglinux '
267
        @echo
268
        @echo 'Usage: make [TARGET]'
269
        @echo 'TARGETS:'
270
        @echo '  all       (=make) compile and link.'
271
        @echo '  NODEP=yes make without generating dependencies.'
272
        @echo '  objs      compile only (no linking).'
273
        @echo '  tags      create tags for Emacs editor.'
274
        @echo '  ctags     create ctags for VI editor.'
275
        @echo '  clean     clean objects and the executable file.'
276
        @echo '  distclean clean objects, the executable and dependencies.'
277
        @echo '  show      show variables (for debug use only).'
278
        @echo '  help      print this message.'
279
        @echo
280
        @echo 'Report bugs to .'
281
 
282
# Show variables (for debug use only.)
283
show:
284
        @echo 'PROGRAM     :' $(PROGRAM)
285
        @echo 'SRCDIRS     :' $(SRCDIRS)
286
        @echo 'HEADERS     :' $(HEADERS)
287
        @echo 'SOURCES     :' $(SOURCES)
288
        @echo 'SRC_CXX     :' $(SRC_CXX)
289
        @echo 'OBJS        :' $(OBJS)
290
        @echo 'DEPS        :' $(DEPS)
291
        @echo 'DEPEND      :' $(DEPEND)
292
        @echo 'COMPILE.c   :' $(COMPILE.c)
293
        @echo 'COMPILE.cxx :' $(COMPILE.cxx)
294
        @echo 'link.c      :' $(LINK.c)
295
        @echo 'link.cxx    :' $(LINK.cxx)
296
 
297
## End of the Makefile ##  Suggestions are welcome  ## All rights reserved ##
298
#############################################################################

powered by: WebSVN 2.1.0

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