Makefile 5.59 KB
Newer Older
1 2 3
# Configuration section
#
# Use environment variables if found, otherwise fallback to sane defaults
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18

# If not explicitely selected (with 'make FPU=1'), compile for FPU emulation
ifeq ($(FPU),)
FPU=0
endif

# To be able to properly handle any combination of (FPU, LEON, release) 
# options, create a SUFFIX (see below) to differentiate output folders
ifeq ($(FPU),1)
FPU_SUFFIX=FPU
else
FPU_SUFFIX=NONFPU
endif

# Build up our settings from our inputs and our environment
19
LEON ?= leon3
20
RTEMS ?= /opt/rtems-4.11-2016.04.01.${FPU_SUFFIX}
21
RTEMS_MAKEFILE_PATH = ${RTEMS}/sparc-rtems4.11/${LEON}
22
RTEMS_LIB=${RTEMS_MAKEFILE_PATH}/lib
23
CROSS_PREFIX=sparc-rtems4.11
24

25 26 27 28
# If not selected, compile debug version of binary (no optimizations)
#ifeq ($(CFG),)
#CFG=debug
#endif
29 30

# The directories containing the source files, separated by ':'
31
#
32
# DEAR USER, YOU MUST EDIT THIS AND ADD YOUR SOURCE FOLDERS
33 34 35 36
VPATH=src

# Your source files: regardless of where they reside in the source tree,
# VPATH will locate them...
37 38 39
#
# DEAR USER, YOU MUST EDIT THIS
SRC= \
40
	init.c \
41
	common.c \
42
	task1.c \
43
	task2.c
44

45 46 47 48 49 50 51 52 53 54
ifeq ($(COVERAGE),1)
SRC += \
	base.c \
	gcc_4_7.c
COVERAGE_SUFFIX=WITH_COVERAGE
else
COVERAGE_SUFFIX=NO_COVERAGE
endif

SUFFIX=$(CFG).$(FPU_SUFFIX).$(LEON).$(COVERAGE_SUFFIX)
55 56 57

# Build a Dependency list and an Object list, by replacing the .c
# extension to .d for dependency files, and .o for object files.
58 59
DEP = $(patsubst %.c, deps.$(SUFFIX)/%.d, ${SRC})
OBJ = $(patsubst %.c, objs.$(SUFFIX)/%.o, ${SRC})
60 61

# Your final binary
62 63
#
# DEAR USER, YOU MUST EDIT THIS
64 65 66 67
TARGET=fputest

# What compiler to use for generating dependencies: 
# it will be invoked with -MM -MP
68
CC = ${RTEMS}/bin/${CROSS_PREFIX}-gcc
69 70 71 72 73 74 75
CDEP = ${CC}

# What include flags to pass to the compiler
INCLUDEFLAGS= -I src

# Compilation flags (common)
COMMON += -B${RTEMS_LIB} -specs bsp_specs -qrtems \
76
	  -mcpu=cypress -DBSP_${LEON} \
77 78 79 80 81 82
	  -ffunction-sections -fdata-sections -Wall \
	  -Wmissing-prototypes -Wimplicit-function-declaration \
	  -Wstrict-prototypes -Wnested-externs

# Separate compile options per configuration
ifeq ($(CFG),debug)
83
CFLAGS += ${COMMON} -g -Wall -D_DEBUG ${INCLUDEFLAGS}
84
else
85
CFLAGS += ${COMMON} -g -O2 -Wall ${INCLUDEFLAGS}
86 87
endif

88 89 90 91 92 93 94 95
ifeq ($(COVERAGE),1)
CFLAGS += -DCOVERAGE_ENABLED
CFLAGS += -fprofile-arcs -ftest-coverage
ifneq ($(CFG),debug)
$(error You are not supposed to use coverage in release builds - read about it e.g. inlining issues, etc)
endif
endif

96 97
# Should we generate native FPU instructions for the SRC or not?
ifeq ($(FPU),0)
98
CFLAGS += -msoft-float
99 100 101 102 103 104
LDFLAGS += -msoft-float
endif

# A common link flag for all configurations
LDFLAGS += ${COMMON} -Wl,--gc-sections

105
all:	inform bin.$(SUFFIX)/${TARGET}
106 107 108 109

inform:
ifneq ($(CFG),release)
ifneq ($(CFG),debug)
110 111 112
	@echo " "
	@echo "Invalid or missing configuration (CFG) "$(CFG)" specified."
	@echo " "
113
	@echo "You must specify a configuration when running make, e.g."
114 115 116 117 118 119 120 121
	@echo " "
	@echo "    make CFG=debug LEON=leon3 FPU=1 V=1"
	@echo " "
	@echo "- Possible choices for CFG are 'release' and 'debug'"
	@echo "- Possible choices for LEON are 'leon2' and 'leon3' (default)"
	@echo "- Possible choices for FPU are '1' (native) and '0' (emulated) (default)"
	@echo "- Possible choices for V are '1' (show commands) and '0' (silent) (default)"
	@echo " "
122 123 124 125 126
	@exit 1
endif
endif


127
bin.$(SUFFIX)/${TARGET}: ${OBJ} | inform
128 129 130 131 132 133 134 135 136 137 138
	@mkdir -p $(dir $@)
ifeq ($(V),1)
	$(CC) -g -o $@ $^ ${LDFLAGS}
else
	@echo [LD] $@
	@$(CC) -g -o $@ $^ ${LDFLAGS}
endif
ifeq ($(CFG),release)
	@${CROSS_PREFIX}-objcopy --only-keep-debug $@ ${@}.debug
	@${CROSS_PREFIX}-strip $@
endif
139
	@echo Built with RTEMS at ${RTEMS_LIB} for ${LEON}.
140

141
objs.$(SUFFIX)/%.o: %.c
142 143 144 145 146 147 148 149
	@mkdir -p $(dir $@)
ifeq ($(V),1)
	$(CC) -c $(CFLAGS) -o $@ $<
else
	@echo [CC] $@
	@$(CC) -c $(CFLAGS) -o $@ $<
endif

150
deps.$(SUFFIX)/%.d: %.c
151 152 153
	@mkdir -p $(dir $@)
	@echo Generating dependencies for $<
	@set -e ; $(CDEP) -MM -MP $(INCLUDEFLAGS) $< > $@.$$$$; \
154
	sed 's,\($*\)\.o[ :]*,objs.$(SUFFIX)\/\1.o $@ : ,g' < $@.$$$$ > $@; \
155 156 157
	rm -f $@.$$$$

clean:
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
	@rm -rf deps.* objs.* bin.* coverage coverage.info

coverage-common:
	$(MAKE) clean
	$(MAKE) CFG=debug LEON=leon3 COVERAGE=1 FPU=1
	# Spawning QEMU with our coverage enabled binary
	~/tool-src/misc/qemu-Leon3/qemu-system-sparc -no-reboot    \
	  -nographic -M leon3_generic -m 64M -kernel  \
	  bin.debug.FPU.leon3.WITH_COVERAGE/fputest -gdb tcp::9976 -S &
	# Spawning GDB and running the coverage script
	sleep 2 ; sparc-rtems4.11-gdb -x contrib/coverage.gdb </dev/null

coverage:	coverage-common
	# Reporting the results
	mkdir -p coverage ;                                             \
	cd coverage ;                                                   \
	ln -s ../src ;                                                  \
	sparc-rtems4.11-gcov ../objs.debug.FPU.leon3.WITH_COV*/*gcda
	@echo
	@echo ==================================================
	@echo The coverage-annotated sources are under coverage/
	@echo ==================================================

coverage-html:	coverage-common
	lcov --gcov-tool sparc-rtems4.11-gcov --capture --directory .   \
	    --output-file coverage.info
	genhtml coverage.info --output-directory coverage
	@echo
	@echo "===================================================="
	@echo "Open coverage/index.html in your browser - e.g. via:"
	@echo
	@echo "    xdg-open coverage/index.html"
	@echo "===================================================="

.PHONY:	clean coverage coverage-html coverage-common
193

194 195 196 197
# Unless "make clean" is called, include the dependency files
# which are auto-generated. Don't fail if they are missing
# (-include), since they will be missing in the first invocation!
ifneq ($(MAKECMDGOALS),clean)
198
ifneq ($(CFG),)
199
-include ${DEP}
200
endif
201
endif