1# SPDX-License-Identifier: BSD-2-Clause-FreeBSD
2#
3# Copyright 2018-2019 Dimitar Dimitrov <dimitar@dinux.eu>
4# All rights reserved.
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# 1. Redistributions of source code must retain the above copyright
10#    notice, this list of conditions and the following disclaimer.
11# 2. Redistributions in binary form must reproduce the above copyright
12#    notice, this list of conditions and the following disclaimer in the
13#    documentation and/or other materials provided with the distribution.
14#
15# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
26VPATH = @srcdir@ @srcdir@/..
27
28srcdir = @srcdir@
29objdir = .
30srcroot = $(srcdir)/../..
31objroot = $(objdir)/../..
32top_srcdir = @top_srcdir@
33
34prefix = @prefix@
35exec_prefix = @exec_prefix@
36
37host_alias = @host_alias@
38target_alias = @target_alias@
39
40bindir = @bindir@
41libdir = @libdir@
42includedir = @includedir@
43tooldir = $(exec_prefix)/$(target_alias)
44
45# Multilib support variables.
46# TOP is used instead of MULTI{BUILD,SRC}TOP.
47MULTIDIRS =
48MULTISUBDIR =
49
50SHELL =	/bin/sh
51
52mkinstalldirs = $(SHELL) $(top_srcdir)/../../mkinstalldirs
53
54CC = @CC@
55
56AS = @AS@
57
58AR = @AR@
59
60LD = @LD@
61
62RANLIB = @RANLIB@
63
64OBJDUMP = `t='$(program_transform_name)'; echo objdump | sed -e $$t`
65OBJCOPY = `t='$(program_transform_name)'; echo objcopy | sed -e $$t`
66
67# linker scripts
68SCRIPTS = `ls ${srcdir}/ldscripts/*.x`
69
70# object files needed
71OBJS = \
72	do_global_dtors.o gettimeofday.o \
73	isatty.o putnum.o raise.o \
74	inbyte.o outbyte.o sbrk.o stat.o syscalls.o \
75	do_global_dtors.o
76
77# Object files specific to particular targets.
78EVALOBJS = ${OBJS}
79
80CRTOBJS = crt0.o crt0-minrt.o
81OUTPUTS = libgloss.a $(CRTOBJS)
82
83INCLUDES = -I$(srcdir)/..
84
85# Note that when building the library, ${MULTILIB} is not the way multilib
86# options are passed; they're passed in $(CFLAGS).
87CFLAGS_FOR_TARGET = ${MULTILIB} ${INCLUDES}
88LDFLAGS_FOR_TARGET = ${MULTILIB}
89
90.c.o:
91	$(CC) $(CFLAGS_FOR_TARGET) -Os $(INCLUDES) -c $(CFLAGS) $<
92
93.C.o:
94	$(CC) $(CFLAGS_FOR_TARGET) -Os $(INCLUDES) -c $(CFLAGS) $<
95.s.o:
96	$(AS) $(ASFLAGS_FOR_TARGET) $(INCLUDES) $(ASFLAGS) -o $*.o $<
97
98#
99# GCC knows to run the preprocessor on .S files before it assembles them.
100#
101.S.o:
102	$(CC) $(CFLAGS_FOR_TARGET) $(INCLUDES) $(CFLAGS) -c $<
103
104all: ${OUTPUTS} copy_scripts_to_objdir
105
106copy_scripts_to_objdir: $(srcdir)/ldscripts/gen-ld-scripts.sh
107	cp $(SCRIPTS) $(objdir)
108
109#
110# here's where we build the library for each target
111#
112
113libgloss.a: $(EVALOBJS)
114	${AR} ${ARFLAGS} $@ $(EVALOBJS)
115	${RANLIB} $@
116
117# C Runtime Library startup code.
118crt0.o: $(srcdir)/crt0.S
119	$(CC) $(CFLAGS_FOR_TARGET) $(INCLUDES) $(CFLAGS) $< -c -o $@
120
121crt0-minrt.o: $(srcdir)/crt0.S
122	$(CC) $(CFLAGS_FOR_TARGET) $(INCLUDES) $(CFLAGS) -DMINRT $< -c -o $@
123
124doc:
125
126clean mostlyclean:
127	rm -f $(OUTPUTS) *.i *~ *.o *-test *.srec *.dis *.map *.x
128
129distclean maintainer-clean realclean: clean
130	rm -f Makefile config.status $(OUTPUTS)
131
132.PHONY: install info install-info clean-info
133install: $(OUTPUTS) $(srcdir)/ldscripts/gen-ld-scripts.sh
134	for outputs in ${OUTPUTS}; do\
135	 ${INSTALL_DATA} $${outputs} ${DESTDIR}${tooldir}/lib${MULTISUBDIR}/$${outputs}; \
136	done
137	for s in $(SCRIPTS); do \
138	  b=`basename $$s`; \
139	  ${INSTALL_DATA} $$s ${DESTDIR}${tooldir}/lib${MULTISUBDIR}/$$b ;\
140	done
141	${mkinstalldirs} ${DESTDIR}${tooldir}/lib${MULTISUBDIR}/device-specs; \
142	for s in ${srcdir}/device-specs/*; do \
143	  b=`basename $$s`; \
144	  $(INSTALL_DATA) $$s $(DESTDIR)$(tooldir)/lib${MULTISUBDIR}/device-specs/$$b ;\
145	done
146
147info:
148install-info:
149clean-info:
150
151Makefile: $(srcdir)/Makefile.in config.status @host_makefile_frag_path@
152	$(SHELL) config.status
153
154config.status: $(srcdir)/configure
155	$(SHELL) config.status --recheck
156