[bffb938] | 1 | # |
---|
[c2c9c7e] | 2 | # Shared compiler for all GNU tools configurations |
---|
| 3 | # |
---|
| 4 | # $Id$ |
---|
[bffb938] | 5 | # |
---|
| 6 | |
---|
| 7 | ## |
---|
| 8 | # CFLAGS_OPTIMIZE_V, CFLAGS_DEBUG_V, CFLAGS_PROFILE_V are the values we |
---|
| 9 | # would want the corresponding macros to be set to. |
---|
| 10 | # |
---|
| 11 | # CFLAGS_OPTIMIZE, CFLAGS_DEBUG, CFLAGS_PROFILE are set in the leaf |
---|
| 12 | # Makefiles by the 'debug:' and 'profile:' targets to their _V values. |
---|
| 13 | # |
---|
| 14 | |
---|
| 15 | # default flags |
---|
[a110b68] | 16 | # XCPPFLAGS, XCFLAGS, XCXXFLAGS, XASFLAGS |
---|
| 17 | # are used to add flags from the shell |
---|
| 18 | # cf. make.info ("Implicit rules/variables" for details) |
---|
| 19 | |
---|
[4d20133] | 20 | # NOTE: Should these go to CPPFLAGS ? |
---|
| 21 | CFLAGS_DEFAULT=-g -Wall -ansi -fasm |
---|
| 22 | |
---|
| 23 | # NOTE: CPU_CFLAGS should probably be renamed to CPU_CPPFLAGS |
---|
| 24 | # NOTE: CPU_DEFINES should probably be merged with CPU_CFLAGS |
---|
| 25 | CPPFLAGS = $(CPU_DEFINES) $(CPU_CFLAGS) $(DEFINES) $(XCPPFLAGS) |
---|
| 26 | CFLAGS = $(CFLAGS_DEFAULT) $(XCFLAGS) |
---|
| 27 | CXXFLAGS = $(CFLAGS_DEFAULT) $(XCXXFLAGS) |
---|
[a110b68] | 28 | ASFLAGS = $(CPU_ASFLAGS) $(XASFLAGS) |
---|
[bffb938] | 29 | |
---|
| 30 | ifeq ($(RTEMS_USE_GCC272),yes) |
---|
[6ee6abb] | 31 | ifeq ($(RTEMS_CROSS_TARGET),no) |
---|
| 32 | |
---|
| 33 | ifdef RTEMS_LIBC_DIR |
---|
| 34 | RTEMS_LIBC_INCLUDES := -I$(RTEMS_LIBC_DIR)/include |
---|
| 35 | endif |
---|
| 36 | |
---|
| 37 | # Used for posix bsps |
---|
[a110b68] | 38 | CPPFLAGS += \ |
---|
[72f9937b] | 39 | -I$(PROJECT_INCLUDE) \ |
---|
[a110b68] | 40 | $(RTEMS_LIBC_INCLUDES) |
---|
[6ee6abb] | 41 | else |
---|
| 42 | # Used for embedded bsps |
---|
[bffb938] | 43 | # Ask gcc where it finds its own include files |
---|
[98100d2] | 44 | GCC_INCLUDE=$(shell $(CC) $(CPU_CFLAGS) -print-file-name=include $(GCCSED)) |
---|
[bffb938] | 45 | |
---|
[a110b68] | 46 | CPPFLAGS += -nostdinc \ |
---|
[72f9937b] | 47 | -I$(PROJECT_INCLUDE) \ |
---|
[a110b68] | 48 | -I$(GCC_INCLUDE) \ |
---|
| 49 | -I$(RTEMS_LIBC_DIR)/sys-include \ |
---|
| 50 | -I$(RTEMS_LIBC_DIR)/include |
---|
[6ee6abb] | 51 | endif |
---|
[bffb938] | 52 | |
---|
| 53 | # default location of Standard C Library |
---|
| 54 | ifndef LIBC_LIBC |
---|
| 55 | LIBC_LIBC=$(RTEMS_LIBC_DIR)/lib/libc.a |
---|
| 56 | endif |
---|
| 57 | |
---|
| 58 | ifndef LIBC_LIBM |
---|
| 59 | LIBC_LIBM=$(RTEMS_LIBC_DIR)/lib/libm.a |
---|
| 60 | endif |
---|
| 61 | |
---|
| 62 | else |
---|
[4cc89bd] | 63 | # NOTE: GCCSPECS probably belongs to CPPFLAGS |
---|
| 64 | # Unfortunately, many custom/*.cfg files do not pass CPPFLAGS |
---|
| 65 | # to their gcc-2.8 make-exe rules |
---|
| 66 | GCCSPECS = -B$(PROJECT_RELEASE)/lib/ -specs bsp_specs -qrtems |
---|
| 67 | |
---|
| 68 | CC += $(GCCSPECS) |
---|
| 69 | CXX += $(GCCSPECS) |
---|
| 70 | |
---|
[72f9937b] | 71 | CPPFLAGS += |
---|
[bffb938] | 72 | |
---|
| 73 | # default location of Standard C Library |
---|
| 74 | ifndef LIBC_LIBC |
---|
[98100d2] | 75 | LIBC_LIBC=$(shell $(CC) $(CPU_CFLAGS) -print-file-name=libc.a $(GCCSED)) |
---|
[bffb938] | 76 | endif |
---|
| 77 | |
---|
| 78 | ifndef LIBC_LIBM |
---|
[98100d2] | 79 | LIBC_LIBM=$(shell $(CC) $(CPU_CFLAGS) -print-file-name=libm.a $(GCCSED)) |
---|
[bffb938] | 80 | endif |
---|
| 81 | endif |
---|
| 82 | |
---|
| 83 | # Define this to yes if C++ is included in the development environment. |
---|
| 84 | # This requires that at least the GNU C++ compiler and libg++ be installed. |
---|
| 85 | ifeq ($(RTEMS_HAS_CPLUSPLUS),yes) |
---|
| 86 | CPLUS_LD_LIBS += $(PROJECT_RELEASE)/lib/librtems++$(LIBSUFFIX_VA) |
---|
| 87 | endif |
---|
| 88 | |
---|
[98100d2] | 89 | # debug flag; |
---|
[ac61209b] | 90 | CFLAGS_DEBUG_V+=-Wno-unused |
---|
[bffb938] | 91 | |
---|
[a858910] | 92 | ifeq ($(RTEMS_USE_GCC272),no) |
---|
| 93 | CFLAGS_DEBUG_V+=-qrtems_debug |
---|
| 94 | endif |
---|
| 95 | |
---|
[bffb938] | 96 | # when debugging, optimize flag: typically empty |
---|
| 97 | # some compilers do allow optimization with their "-g" |
---|
[a110b68] | 98 | CFLAGS_DEBUG_OPTIMIZE_V=-g |
---|
[bffb938] | 99 | |
---|
| 100 | # profile flag; use gprof(1) |
---|
| 101 | CFLAGS_PROFILE_V=-pg |
---|
| 102 | |
---|
| 103 | # default is to optimize |
---|
| 104 | CFLAGS_OPTIMIZE=$(CFLAGS_OPTIMIZE_V) |
---|
| 105 | |
---|
| 106 | # dynamic libraries |
---|
[a110b68] | 107 | #CFLAGS_DYNAMIC_V=-fpic |
---|
[bffb938] | 108 | #ASFLAGS_DYNAMIC_V= |
---|
| 109 | |
---|
[a110b68] | 110 | CFLAGS += $(CFLAGS_OPTIMIZE) $(CFLAGS_DEBUG) $(CFLAGS_PROFILE) |
---|
[bffb938] | 111 | |
---|
| 112 | # List of library paths without -L |
---|
| 113 | LD_PATHS= $(PROJECT_RELEASE)/lib |
---|
| 114 | |
---|
| 115 | # libraries you want EVERYONE to link with |
---|
| 116 | #LD_LIBS= |
---|
| 117 | |
---|
| 118 | # ld flag to ensure pure-text |
---|
| 119 | #LDFLAGS_MUST_BE_PURE_V = |
---|
| 120 | |
---|
| 121 | # ld flag for [un]shared objects |
---|
| 122 | #LDFLAGS_STATIC_LIBRARIES_V = |
---|
| 123 | #LDFLAGS_SHARED_LIBRARIES_V = |
---|
| 124 | |
---|
| 125 | # ld flag for incomplete link |
---|
| 126 | LDFLAGS_INCOMPLETE = -r |
---|
| 127 | |
---|
| 128 | # Special linker options when building lib.so |
---|
| 129 | LDFLAGS_DYNAMIC_V = ?? |
---|
| 130 | |
---|
| 131 | # Some dynamic linking systems want the preferred name recorded in the binary |
---|
| 132 | # ref: src/libxil/Makefile |
---|
| 133 | LDFLAGS_DYNAMIC_LIBNAME_V = -h $(DYNAMIC_VERSION_LIBNAME) |
---|
| 134 | |
---|
| 135 | # ld flags for profiling, debugging |
---|
| 136 | LDFLAGS_PROFILE_V = |
---|
| 137 | LDFLAGS_DEBUG_V = |
---|
| 138 | |
---|
| 139 | LDFLAGS=$(LDFLAGS_PROFILE) $(LDFLAGS_DEBUG) $(LD_PATHS:%=-L %) |
---|
| 140 | |
---|
| 141 | # |
---|
| 142 | # Stuff to clean and clobber for the compiler and its tools |
---|
| 143 | # |
---|
| 144 | |
---|
| 145 | CLEAN_CC = a.out *.o *.BAK |
---|
| 146 | CLOBBER_CC = |
---|
| 147 | |
---|
| 148 | # |
---|
| 149 | # Client compiler and support tools |
---|
| 150 | # |
---|
| 151 | |
---|
| 152 | # CPP command to write file to standard output |
---|
[5dd4212] | 153 | CPP=$(CC) -E -ansi -w -Wp,-$$ |
---|
[bffb938] | 154 | |
---|
| 155 | # flags set by cc when running cpp |
---|
[a110b68] | 156 | # NOTE: CPP_CC_FLAGS does not seem to be used anywhere |
---|
| 157 | # CPP_CC_FLAGS=-D__STDC__ |
---|
[bffb938] | 158 | |
---|
| 159 | # egrep regexp to ignore symbol table entries in ar archives. |
---|
| 160 | # Only used to make sure we skip them when coalescing libraries. |
---|
| 161 | # skip __.SYMDEF and empty names (maybe bug in ranlib??). |
---|
| 162 | AR_SYMBOL_TABLE="HIGHLY-UNLIKELY-TO-CONFLICT" |
---|
| 163 | ARFLAGS=ruv |
---|
| 164 | |
---|
| 165 | # |
---|
| 166 | # Command to convert a normal archive to one searchable by $(LD) |
---|
| 167 | # |
---|
[98100d2] | 168 | # NOTE: Obsolete, use $(RANLIB) instead, MKLIB may disappear soon |
---|
| 169 | MKLIB=$(RANLIB) |
---|
[bffb938] | 170 | |
---|
[a110b68] | 171 | |
---|
[bffb938] | 172 | # |
---|
| 173 | # How to compile stuff into ${ARCH} subdirectory |
---|
| 174 | # |
---|
[4d20133] | 175 | # NOTE: we override COMPILE.[c|cc|S] |
---|
| 176 | # because gmake default rules use TARGET_ARCH for different purposes |
---|
[bffb938] | 177 | # |
---|
| 178 | |
---|
[a110b68] | 179 | COMPILE.c=$(CC) $(CPPFLAGS) $(CFLAGS) -c |
---|
| 180 | COMPILE.cc=$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c |
---|
[4d20133] | 181 | COMPILE.S=$(CC) $(ASFLAGS) $(CPPFLAGS) -c |
---|
[bffb938] | 182 | |
---|
| 183 | ${ARCH}/%.o: %.c |
---|
[e81ef51] | 184 | ${COMPILE.c} -o $@ $< |
---|
[bffb938] | 185 | |
---|
| 186 | ${ARCH}/%.o: %.cc |
---|
[6ee6abb] | 187 | ${COMPILE.cc} -o $@ $< |
---|
[bffb938] | 188 | |
---|
[07001360] | 189 | ${ARCH}/%.o: %.cpp |
---|
| 190 | ${COMPILE.cc} -o $@ $< |
---|
| 191 | |
---|
| 192 | ${ARCH}/%.o: %.cxx |
---|
| 193 | ${COMPILE.cc} -o $@ $< |
---|
| 194 | |
---|
| 195 | ${ARCH}/%.o: %.C |
---|
| 196 | ${COMPILE.cc} -o $@ $< |
---|
| 197 | |
---|
[0162910] | 198 | ${ARCH}/%.o: %.S |
---|
[4d20133] | 199 | ${COMPILE.S} -DASM -o $@ $< |
---|
| 200 | |
---|
| 201 | # OBSOLETE: the rule above should be equivalent. |
---|
| 202 | # strip out C++ style comments. |
---|
| 203 | # ${ARCH}/%.o: %.S |
---|
| 204 | # sed -e 's/\/\/.*$$//' < $< | \ |
---|
| 205 | # $(CPP) $(CPPFLAGS) -I. -I$(srcdir) -DASM - >$(ARCH)/$*.i |
---|
| 206 | # $(AS) $(ASFLAGS) -o $@ $(ARCH)/$*.i |
---|
[bffb938] | 207 | |
---|
| 208 | # Make foo.rel from foo.o |
---|
| 209 | ${ARCH}/%.rel: ${ARCH}/%.o |
---|
| 210 | ${LD} $(LDFLAGS_INCOMPLETE) -o $@ $^ |
---|
| 211 | |
---|
| 212 | # create $(ARCH)/pgm from pgm.sh |
---|
[5b8c1b7] | 213 | ${ARCH}/%: %.sh |
---|
[bffb938] | 214 | $(RM) $@ |
---|
| 215 | $(CP) $< $@ |
---|
| 216 | $(CHMOD) +x $@ |
---|
| 217 | |
---|
| 218 | # Dependency files for use by gmake |
---|
| 219 | # NOTE: we don't put in $(TARGET_ARCH) |
---|
| 220 | # so that 'make clean' doesn't blow it away |
---|
| 221 | |
---|
| 222 | DEPEND=Depends-$(TARGET_ARCH:o-%=%) |
---|
| 223 | |
---|
| 224 | CLEAN_DEPEND=$(DEPEND).tmp |
---|
| 225 | CLOBBER_DEPEND=$(DEPEND) |
---|
| 226 | |
---|
| 227 | # We deliberately don't have anything depend on the |
---|
| 228 | # $(DEPEND) file; otherwise it will get rebuilt even |
---|
| 229 | # on 'make clean' |
---|
| 230 | # |
---|
| 231 | |
---|
| 232 | depend: $(C_FILES) $(CC_FILES) $(S_FILES) |
---|
| 233 | ifneq ($(words $(C_FILES) $(CC_FILES) $(S_FILES)), 0) |
---|
| 234 | # Use gcc -M to generate dependencies |
---|
| 235 | # Replace foo.o with $(ARCH)/foo.o |
---|
| 236 | # Replace $(ARCH) value with string $(ARCH) |
---|
| 237 | # so that it will for debug and profile cases |
---|
| 238 | $(COMPILE.c) -M $^ | \ |
---|
| 239 | $(SED) -e 's?^\(.*\)\.o[ ]*:?$$(ARCH)/\1.o:?' \ |
---|
| 240 | -e 's?$(ARCH)/?$$(ARCH)/?' >$(DEPEND).tmp |
---|
| 241 | $(MV) $(DEPEND).tmp $(DEPEND) |
---|
| 242 | endif |
---|
| 243 | |
---|
| 244 | # spell out all the LINK_FILE's, rather than using -lbsp, so |
---|
| 245 | # that $(LINK_FILES) can be a dependency |
---|
| 246 | |
---|
| 247 | # Start file must be one of |
---|
| 248 | # $(PROJECT_RELEASE)/lib/start$(LIB_VARIANT).o |
---|
| 249 | # $(PROJECT_RELEASE)/lib/asmiface$(LIB_VARIANT).o |
---|
| 250 | # It defaults to start.o, but an app can override it. |
---|
| 251 | |
---|
| 252 | ifeq ($(START_BASE),) |
---|
| 253 | START_FILE= |
---|
| 254 | else |
---|
| 255 | START_FILE=$(PROJECT_RELEASE)/lib/$(START_BASE)$(LIB_VARIANT).o |
---|
| 256 | endif |
---|
| 257 | |
---|
| 258 | CONSTRUCTOR= |
---|
| 259 | |
---|
| 260 | LIBC_LOW= |
---|
| 261 | |
---|
[6ee6abb] | 262 | ifndef LIBGCC |
---|
[98100d2] | 263 | LIBGCC = $(shell $(CC) $(CFLAGS) -print-libgcc-file-name $(GCCSED)) |
---|
[6ee6abb] | 264 | endif |
---|
[bffb938] | 265 | |
---|
[98100d2] | 266 | # |
---|
| 267 | # NOTE: a rule to link an rtems' application should look similar to this |
---|
| 268 | # (cf. "make-exe" in make/custom/*.cfg): |
---|
| 269 | # |
---|
| 270 | # gcc27: |
---|
| 271 | # $(PGM): $(LINK_FILES) |
---|
| 272 | # $(LD) $(LDFLAGS) -o $@ $(LINK_OBJS) \ |
---|
[30cde042] | 273 | # --start-group $(LINK_LIBS) --end-group |
---|
[98100d2] | 274 | # |
---|
| 275 | # gcc28: |
---|
| 276 | # $(PGM): $(LINK_FILES) |
---|
[30cde042] | 277 | # $(CC) $(CFLAGS) -o $@ $(LINK_OBJS) $(LINK_LIBS) |
---|
[98100d2] | 278 | # |
---|
| 279 | |
---|
| 280 | LINK_OBJS =\ |
---|
[bffb938] | 281 | $(CONSTRUCTOR) \ |
---|
| 282 | $(OBJS) \ |
---|
[3a8915e] | 283 | $(MANAGERS_NOT_WANTED:%=$(PROJECT_RELEASE)/lib/no-%$(LIB_VARIANT).rel) |
---|
[bffb938] | 284 | |
---|
[98100d2] | 285 | LINK_FILES =\ |
---|
[bffb938] | 286 | $(START_FILE) \ |
---|
[98100d2] | 287 | $(CONSTRUCTOR) \ |
---|
| 288 | $(OBJS) \ |
---|
| 289 | $(MANAGERS_NOT_WANTED:%=$(PROJECT_RELEASE)/lib/no-%$(LIB_VARIANT).rel) \ |
---|
| 290 | $(PROJECT_RELEASE)/lib/librtemsall$(LIBSUFFIX_VA) |
---|
| 291 | |
---|
| 292 | ifeq ($(RTEMS_USE_GCC272),yes) |
---|
| 293 | LINK_LIBS = $(PROJECT_RELEASE)/lib/librtemsall$(LIBSUFFIX_VA) |
---|
| 294 | ifeq ($(RTEMS_CROSS_TARGET),yes) |
---|
| 295 | # NOTE: add libc and libgcc only for embedded targets |
---|
| 296 | # LIBC_LIBM should not be needed by rtems itself. |
---|
| 297 | # FIXME: If a BSP requires libm, its make/custom/*.cfg file should add |
---|
| 298 | # LIBC_LIBM to LINK_LIBS (untested) |
---|
| 299 | LINK_LIBS += $(LIBC_LIBC) $(LIBGCC) |
---|
| 300 | endif |
---|
| 301 | endif |
---|
| 302 | |
---|
| 303 | LINK_LIBS += $(LD_LIBS) |
---|
[bffb938] | 304 | |
---|
| 305 | # |
---|
| 306 | # Allow user to override link commands (to build a prom image, perhaps) |
---|
| 307 | # |
---|
| 308 | ifndef LINKCMDS |
---|
| 309 | LINKCMDS=$(PROJECT_RELEASE)/lib/linkcmds |
---|
| 310 | endif |
---|
| 311 | |
---|
| 312 | |
---|
| 313 | define make-rel |
---|
| 314 | $(LD) $(LDFLAGS_INCOMPLETE) $(XLDFLAGS) -o $@ $(OBJS) |
---|
| 315 | endef |
---|