-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile-cygwin
260 lines (218 loc) · 8.8 KB
/
Makefile-cygwin
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
#=======================================================================
#//! \file
#//! \section common_makefile_cygwin_general General file information
#//! \author Dirk Osswald
#//! \date 2006-12-18
#//!
#//! \brief
#//! Makefile with common stuff specific for cygwin target platform.
#//! (Works also on linux platforms)
#//!
#//! This Makefile is intended to be included by other makefiles and
#//! contains common variable, function and target settings specific for the
#//! cygwin platform on x86 PC
#//!
#//! \section common_makefile_cygwin_variables Makefile variables
#//! This makefile relies on the following variables beeing set:
#//! - SRCDIR - directory for source files like e.g. \c "." or \c "src"
#//! - OBJDIR - directory for object files like e.g. \c "obj"
#//! - BINDIR - directory for binary files (.elf, .hex, .srec, .lst, .map) like e.g. \c "bin"
#//! - DEPDIR - directory for dependency files like e.g. \c ".dep"
#//! - OPT - Optimization level like e.g. \c "0".."3" or \c "s"
#//! - EXTRAINCDIRS - List of include directories for compiler (without "-I") like e.g \c "some_path"
#//! - EXTRACDEFS - Extra defines for preprocessor / C compiler
#//! - EXTRACFLAGS - Extra options for c compiler, like e.g. additional defines
#//! - EXTRACPPDEFS - Extra defines for preprocessor / C++ compiler
#//! - EXTRACPPFLAGS - Extra options for c++ compiler
#//! - EXTRALDFLAGS - Extra options for linker like section commands or Library directories
#//! - EXTRALIBS - List of libraries for linker (without -l prefix and .a/.lib suffix)
#//! - EXTRALINTARGS - Extra arguments for lint
#//!
#//! Other variables are set to usefull default values here but could be
#//! redefined after including this Makefile-avr:
#//! - DBG_FMT - debug info format like e.g. \c "dwarf-2"
#//! - CSTANDARD - Compiler flag to set the C Standard level like e.g. \c "-std=gnu99"
#//! - GENDEPFLAGS - Options that make gcc generate dependencies in DEPDIR
#//! - CFLAGS, CPPFLAGS, ASFLAGS, LDFLAGS, ALL_CFLAGS, ALL_CPPFLAGS, ALL_ASFLAGS
#//!
#//! \section common_makefile_cygwin_targets Makefile targets
#//! - \b \c cygwin_clean : clean up generated program files in ${OBJDIR}, ${DEPDIR} and ${BINDIR}
#//!
#//! \section common_makefile_cygwin_links Links
#//! - The online documentation for \c gnu \c make can be found at
#//! <a href="http://www.gnu.org/software/make/manual/make.html">
#//! http://www.gnu.org/software/make/manual/make.html</a>
#//!
#//! \section common_makefile_cygwin_copyright Copyright
#//!
#//! Copyright (c) 2006 SCHUNK GmbH & Co. KG
#//!
#//! <HR>
#//! \internal
#//!
#//! \subsection common_makefile_cygwin_details SVN related, detailed file specific information:
#//! $LastChangedBy: Osswald2 $
#//! $LastChangedDate: 2009-08-31 09:21:03 +0200 (Mo, 31 Aug 2009) $
#//! \par SVN file revision:
#//! $Id: Makefile-cygwin 4762 2009-08-31 07:21:03Z Osswald2 $
#//!
#//! \subsection common_makefile_cygwin_changelog Changelog of this file:
#//! \include Makefile-cygwin.log
#//!
#=======================================================================
#//! \cond ignore_me doxygen cannot parse Makefiles, so just ignore it
########################################################################
# first some variables
## define the C compiler, if not set by the environment
ifndef CC
export CC = gcc
endif
## define the C++ compiler, if not set by the environment
ifndef CPPC
export CPPC = g++
endif
#----------------------------
# common settings
# Debugging format.
ifeq (${OSNAME},linux)
# FIXed: On real Linux DBG_FMT should be empty since the normal debug flag is just -g
DBG_FMT =
else
DBG_FMT = gdb
endif
# Compiler flag to set the C Standard level.
# c89 = "ANSI" C
# gnu89 = c89 plus GCC extensions
# c99 = ISO C99 standard (not yet fully implemented)
# gnu99 = c99 plus GCC extensions
CSTANDARD = -std=gnu99
# Place -D or -U options here for C sources
CDEFS = ${EXTRACDEFS}
# Place -D or -U options here for C++ sources
CPPDEFS = ${EXTRACPPDEFS}
#CPPDEFS += -D__STDC_LIMIT_MACROS
#CPPDEFS += -D__STDC_CONSTANT_MACROS
# Compiler flags to generate dependency files.
GENDEPFLAGS = -MD -MP -MF ${DEPDIR}/$(@F).d
#---------------- Compiler Options C ----------------
# -g*: generate debugging information
# -O*: optimization level
# -f...: tuning, see GCC manual and avr-libc documentation
# -Wall...: warning level
# -Wa,...: tell GCC to pass this to the assembler.
# -adhlns...: create assembler listing
CFLAGS = -g$(DBG_FMT)
CFLAGS += $(CDEFS)
CFLAGS += -O$(OPT)
#CFLAGS += -mint8
#CFLAGS += -mshort-calls
#CFLAGS += -funsigned-char
CFLAGS += -funsigned-bitfields
CFLAGS += -fpack-struct
CFLAGS += -fshort-enums
#CFLAGS += -fno-unit-at-a-time
CFLAGS += -Wall
CFLAGS += -Wstrict-prototypes
CFLAGS += -Wundef
#CFLAGS += -Wunreachable-code
#CFLAGS += -Wsign-compare
#CFLAGS += -Wa,-adhlns=$(<:%.c=$(BINDIR)/%.lst)
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
CFLAGS += $(CSTANDARD)
CFLAGS += ${EXTRACFLAGS}
#---------------- Compiler Options C++ ----------------
CPPFLAGS = -g$(DBG_FMT)
CPPFLAGS += $(CPPDEFS)
CPPFLAGS += -O$(OPT)
#CPPFLAGS += -mint8
#CPPFLAGS += -mshort-calls
#CPPFLAGS += -funsigned-char
#CPPFLAGS += -funsigned-bitfields
#CPPFLAGS += -fpack-struct
#CPPFLAGS += -fshort-enums
#CPPFLAGS += -fno-exceptions
#CPPFLAGS += -fno-unit-at-a-time
CPPFLAGS += -Wall
#CPPFLAGS += -Wstrict-prototypes
CFLAGS += -Wundef
#CPPFLAGS += -Wunreachable-code
#CPPFLAGS += -Wsign-compare
#CPPFLAGS += -Wa,-adhlns=$(<:%.cpp=$(BINDIR)/%.lst)
CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
#CPPFLAGS += $(CSTANDARD)
CPPFLAGS += ${EXTRACPPFLAGS}
#---------------- Assembler Options ----------------
# -Wa,...: tell GCC to pass this to the assembler.
# -ahlms: create listing
# -gstabs: have the assembler create line number information; note that
# for use in COFF files, additional information about filenames
# and function names needs to be present in the assembler source
# files -- see avr-libc docs [FIXME: not yet described there]
ASFLAGS = -Wa,-adhlns=$(<:%.S=$(BINDIR)/%.lst),-gstabs
#---------------- Linker Options ----------------
# -Wl,...: tell GCC to pass this to linker.
# -Map: create map file
# --cref: add cross reference to map file
#LDFLAGS = -Wl,-Map=${BINDIR}/$(@F).map,--cref
LDFLAGS += ${EXTRALDFLAGS}
LDFLAGS += $(patsubst %,-l%,$(EXTRALIBS))
# Combine all necessary flags and optional flags.
# Add target processor to flags.
ALL_CFLAGS = -I. $(CFLAGS) $(GENDEPFLAGS)
ifeq (${OSNAME},linux)
# FIXed: On real Linux this settings seems to work better:
ALL_CPPFLAGS = -I. $(CPPFLAGS) $(GENDEPFLAGS)
else
ALL_CPPFLAGS = -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS)
endif
ALL_ASFLAGS = -I. -x assembler-with-cpp $(ASFLAGS)
ALL_IFLAGS = -I. $(CFLAGS)
#
########################################################################
########################################################################
# functions
#
########################################################################
########################################################################
# Generic rules:
include ${COMMON_DIR}/Makefile-rules
# Linking:
${BINDIR}/%:
${CC} ${ALL_CFLAGS} $^ -o $@ $(LDFLAGS)
.PHONY: cygwin_clean
cygwin_clean: rules_clean
ifeq (${OSNAME},linux)
rm -f `find ${BINDIR}/ -type f -executable`
else
rm -f ${BINDIR}/*.exe
endif
## lint (static C checking)
# (this does not work very well (yet), but you gotta start somewhere...)
.PHONY: lint
lint:
# # -unrecogcomments : since splint gets confused by @{ doxygen comments in winavr include files
splint -I/usr/include/w32api ${patsubst %,-I%,${EXTRAINCDIRS}} ${CDEFS} ${EXTRALINTARGS} ${SRCDIR}/*.c
#
########################################################################
########################################################################
#
# Create binary files directory
$(shell mkdir $(BINDIR) 2>/dev/null)
#
########################################################################
########################################################################
# Handling of automatically generated dependency files.
# Create dependency files directory
$(shell mkdir -p ${DEPDIR})
# now we include the dependencies
-include $(wildcard ${DEPDIR}/*.d)
#
########################################################################
#-----------------------------------------------------------------------
# emacs settings:
# Local Variables:
# mode: Makefile
# End:
#-----------------------------------------------------------------------
#//! \endcond
########################################################################