Makefile.RCCrc4_GR740 4.09 KB
Newer Older
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
# Configuration section
#
# Use environment variables if found, otherwise fallback to sane defaults

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

ifeq ($(SMP),)
SMP=_smp
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
LEON ?= gr740
CROSS_PREFIX ?= sparc-gaisler-rtems5
RTEMS ?= /opt/rcc-1.3-rc4

# If not selected, compile debug version of binary (no optimizations)
#ifeq ($(CFG),)
#CFG=debug
#endif

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

# Your source files: regardless of where they reside in the source tree,
# VPATH will locate them...
#
# DEAR USER, YOU MUST EDIT THIS
SRC= \
	init.c \
	task1.c \
	task2.c \
	common.c \
	memcheck.c

SUFFIX=$(CFG).$(FPU_SUFFIX).$(LEON)

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

# Your final binary
#
# DEAR USER, YOU MUST EDIT THIS
TARGET=fputest

# What compiler to use for generating dependencies: 
# it will be invoked with -MM -MP
CC = ${RTEMS}/bin/${CROSS_PREFIX}-gcc
CDEP = ${CC}

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

COMMON += -mcpu=leon3 -qbsp=${LEON}${SMP} -Wall \
	  -Wmissing-prototypes -Wimplicit-function-declaration \
	  -Wstrict-prototypes -Wnested-externs

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

# Should we generate native FPU instructions for the SRC or not?
ifeq ($(FPU),0)
CFLAGS += -msoft-float
LDFLAGS += -msoft-float
endif

# A common link flag for all configurations
LDFLAGS += ${COMMON}

all:	inform bin.$(SUFFIX)/${TARGET}

inform:
ifneq ($(CFG),release)
ifneq ($(CFG),debug)
	@echo " "
	@echo "Invalid or missing configuration (CFG) "$(CFG)" specified."
	@echo " "
	@echo "You must specify a configuration when running make, e.g."
	@echo " "
	@echo "    make CFG=debug LEON=leon3mp FPU=1 V=1"
	@echo " "
	@echo "- Possible choices for CFG are 'release' and 'debug'"
	@echo "- Possible choices for LEON are 'leon2', 'leon3mp' and 'ngmp' (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 " "
	@exit 1
endif
endif


bin.$(SUFFIX)/${TARGET}: ${OBJ} | inform
	@mkdir -p $(dir $@)
ifeq ($(V),1)
	$(CC) -g -o $@ $^ ${LDFLAGS}
else
	@echo [LD] $@
	@$(CC) -g -o $@ $^ ${LDFLAGS}
endif
ifeq ($(CFG),release)
	@${RTEMS}/bin/${CROSS_PREFIX}-objcopy --only-keep-debug $@ ${@}.debug
	@${RTEMS}/bin/${CROSS_PREFIX}-strip $@
endif
	@echo Built with RTEMS at ${RTEMS_LIB} for ${LEON}.

objs.$(SUFFIX)/%.o: %.c | src/version.h
	@mkdir -p $(dir $@)
ifeq ($(V),1)
	$(CC) -c $(CFLAGS) -o $@ $<
else
	@echo [CC] $@
	@$(CC) -c $(CFLAGS) -o $@ $<
endif

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

src/version.h:	$(patsubst %, src/%, ${SRC}) Makefile
	@/bin/echo -en '#ifndef __VERSION_H__\n' > $@
	@/bin/echo -en "#define __VERSION_H__\n" >> $@
	@/bin/echo -en 'const char version[] = "1.' >> $@
	@git log --oneline | wc -l | tr -d '\n' >> $@
	@/bin/echo -n " (" >> $@
	@git log --oneline | head -1 | cut -d\  -f1 | tr -d '\n' >> $@
	@/bin/echo ')";' >> $@
	@/bin/echo -en "#endif\n" >> $@

clean:
	@rm -rf deps.* objs.* bin.*

# 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)
ifneq ($(CFG),)
-include ${DEP}
endif
endif