1#
2# SPDX-License-Identifier: BSD-3-Clause
3#
4# Copyright © 2023 Keith Packard
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:
9#
10# 1. Redistributions of source code must retain the above copyright
11#    notice, this list of conditions and the following disclaimer.
12#
13# 2. Redistributions in binary form must reproduce the above
14#    copyright notice, this list of conditions and the following
15#    disclaimer in the documentation and/or other materials provided
16#    with the distribution.
17#
18# 3. Neither the name of the copyright holder nor the names of its
19#    contributors may be used to endorse or promote products derived
20#    from this software without specific prior written permission.
21#
22# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
33# OF THE POSSIBILITY OF SUCH DAMAGE.
34#
35
36CFLAGS=-Os \
37    -march=armv7-m \
38    --specs=picolibc.specs \
39    --oslib=semihost \
40    --crt0=hosted \
41    -Wl,--defsym=__flash=0 \
42    -Wl,--defsym=__flash_size=0x00200000 \
43    -Wl,--defsym=__ram=0x20000000 \
44    -Wl,--defsym=__ram_size=0x200000
45
46QEMU=qemu-system-arm -chardev stdio,id=stdio0 -semihosting-config enable=on,chardev=stdio0 -monitor none -serial none -machine mps2-an385,accel=tcg -nographic -kernel
47
48DCFLAGS=$(CFLAGS) -DPICOLIBC_DOUBLE_PRINTF_SCANF
49FCFLAGS=$(CFLAGS) -DPICOLIBC_FLOAT_PRINTF_SCANF
50LCFLAGS=$(CFLAGS) -DPICOLIBC_LONG_LONG_PRINTF_SCANF
51ICFLAGS=$(CFLAGS) -DPICOLIBC_INTEGER_PRINTF_SCANF
52MCFLAGS=$(CFLAGS) -DPICOLIBC_MINIMAL_PRINTF_SCANF
53
54CC=arm-none-eabi-gcc
55
56LOG=printf.log printf-float.log printf-long-long.log printf-integer.log printf-minimal.log
57
58ALL=printf.elf printf-float.elf printf-long-long.elf printf-integer.elf printf-minimal.elf
59
60all: $(LOG)
61
62printf.log: printf.elf
63	(arm-none-eabi-size $^; $(QEMU) $^) > $@
64
65printf.elf: printf.c
66	$(CC) $(DCFLAGS) -o $@ $^
67
68printf-float.log: printf-float.elf
69	(arm-none-eabi-size $^; $(QEMU) $^) > $@
70
71printf-float.elf: printf.c
72	$(CC) $(FCFLAGS) -o $@ $^
73
74printf-long-long.log: printf-long-long.elf
75	(arm-none-eabi-size $^; $(QEMU) $^) > $@
76
77printf-long-long.elf: printf.c
78	$(CC) $(LCFLAGS) -o $@ $^
79
80printf-integer.log: printf-integer.elf
81	(arm-none-eabi-size $^; $(QEMU) $^) > $@
82
83printf-integer.elf: printf.c
84	$(CC) $(ICFLAGS) -o $@ $^
85
86printf-minimal.log: printf-minimal.elf
87	(arm-none-eabi-size $^; $(QEMU) $^) > $@
88
89printf-minimal.elf: printf.c
90	$(CC) $(MCFLAGS) -o $@ $^
91
92clean:
93	rm -f $(ALL) $(LOG)
94