summaryrefslogtreecommitdiff
path: root/api_examples/Makefile
blob: 98506a07d0e3e238d993a90608456b7ff5fb4c78 (plain)
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
#
# (C) Copyright 2007 Semihalf
#
# See file CREDITS for list of people who contributed to this
# project.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundatio; either version 2 of
# the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA
#

ifeq ($(ARCH),ppc)
LOAD_ADDR = 0x40000
endif
ifeq ($(ARCH),arm)
LOAD_ADDR = 0x1000000
endif

include $(TOPDIR)/config.mk

# Resulting ELF and binary exectuables will be named demo and demo.bin
OUTPUT-$(CONFIG_API) = $(obj)demo

#CFLAGS += -v

SOBJS-$(CONFIG_API) += crt0.o
COBJS-$(CONFIG_API) += demo.o
ifeq ($(ARCH),ppc)
SOBJS-$(CONFIG_API) += ppcstring.o
endif

OUTPUT	:= $(OUTPUT-y)
COBJS	:= $(COBJS-y)
SOBJS	:= $(SOBJS-y)

LIB	= $(obj)libglue.a
LIBCOBJS-$(CONFIG_API) += glue.o
LIBCOBJS-$(CONFIG_API) += crc32.o
LIBCOBJS-$(CONFIG_API) += ctype.o
LIBCOBJS-$(CONFIG_API) += string.o
LIBCOBJS-$(CONFIG_API) += vsprintf.o
LIBCOBJS-$(CONFIG_API) += libgenwrap.o
LIBCOBJS := $(LIBCOBJS-y)

LIBOBJS	+= $(addprefix $(obj),$(SOBJS))
LIBOBJS	+= $(addprefix $(obj),$(LIBCOBJS))

SRCS	+= $(COBJS:.o=.c)
SRCS	+= $(LIBCOBJS:.o=.c)
SRCS	+= $(SOBJS:.o=.S)
OBJS	:= $(addprefix $(obj),$(COBJS))

gcclibdir := $(shell dirname `$(CC) -print-libgcc-file-name`)

CPPFLAGS += -I..

all:	$(obj).depend $(OBJS) $(LIB) $(OUTPUT)

#########################################################################
$(LIB):	$(obj).depend $(LIBOBJS)
		$(AR) $(ARFLAGS) $@ $(LIBOBJS)

$(OUTPUT):
$(obj)%:	$(obj)%.o $(LIB)
		$(LD) $(obj)crt0.o -Ttext $(LOAD_ADDR) \
			-o $@ $< $(LIB) \
			-L$(gcclibdir) -lgcc
		$(OBJCOPY) -O binary $@ $(OUTPUT).bin 2>/dev/null

$(obj)crc32.c:
	@rm -f $(obj)crc32.c
	ln -s $(src)../lib_generic/crc32.c $(obj)crc32.c

$(obj)ctype.c:
	@rm -f $(obj)ctype.c
	ln -s $(src)../lib_generic/ctype.c $(obj)ctype.c

$(obj)string.c:
	@rm -f $(obj)string.c
	ln -s $(src)../lib_generic/string.c $(obj)string.c

$(obj)vsprintf.c:
	@rm -f $(obj)vsprintf.c
	ln -s $(src)../lib_generic/vsprintf.c $(obj)vsprintf.c

ifeq ($(ARCH),ppc)
$(obj)ppcstring.S:
	@rm -f $(obj)ppcstring.S
	ln -s $(src)../lib_ppc/ppcstring.S $(obj)ppcstring.S
endif

#########################################################################

# defines $(obj).depend target
include $(SRCTREE)/rules.mk

sinclude $(obj).depend

#########################################################################