aboutsummaryrefslogtreecommitdiffstats
path: root/src/grt/Makefile.inc
blob: 7edea49607f22c750f72245d86968eb7986183a5 (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
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
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#  -*- Makefile -*- for the GHDL Run Time library.
#  Copyright (C) 2002, 2003, 2004, 2005 Tristan Gingold
#
#  GHDL 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 Foundation; either version 2, or (at your option) any later
#  version.
#
#  GHDL 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 GCC; see the file COPYING.  If not, write to the Free
#  Software Foundation, 59 Temple Place - Suite 330, Boston, MA
#  02111-1307, USA.

# Variables used:
# AR: ar command
# RM
# CC
# GNATMAKE: the GNAT compiler (gnatmake)
# GHDL1: the ghdl compiler
# GRT_RANLIB: the ranlib tool for the grt library.
# grt_libdir: the place to put grt.
# GRTSRCDIR: the source directory of grt.
# target: GCC target
# GRT_FLAGS: common (Ada + C + asm) compilation flags.
# GRT_ADAFLAGS: compilation flags for Ada
#
# LIBBACKTRACE: if set, path to libbacktrace.a (from gcc)

# Convert the target variable into a space separated list of architecture,
# manufacturer, and operating system and assign each of those to its own
# variable.

target1:=$(subst -gnu,,$(target))
targ:=$(subst -, ,$(target1))
arch:=$(word 1,$(targ))
ifeq ($(words $(targ)),2)
  osys:=$(word 2,$(targ))
else
  osys:=$(word 3,$(targ))
endif

GRT_ELF_OPTS:=-Wl,--version-script=@/grt.ver -Wl,--export-dynamic

# Set target files.
ifeq ($(filter-out mingw32 mingw64,$(osys)),)
  GRT_TARGET_OBJS=win32.o clock.o
  GRT_EXTRA_LIB=-ldbghelp
else
  GRT_TARGET_OBJS=jumps.o times.o
  ifeq ($(filter-out linux,$(osys)),)
    GRT_EXTRA_LIB=-ldl -lm $(GRT_ELF_OPTS)
  endif
  ifeq ($(filter-out netbsd freebsd% dragonfly%,$(osys)),)
    GRT_EXTRA_LIB=-lm $(GRT_ELF_OPTS)
  endif
  ifeq ($(filter-out solaris%,$(osys)),)
    GRT_EXTRA_LIB=-ldl -lm
  endif
  ifeq ($(filter-out darwin%,$(osys)),)
    GRT_EXTRA_LIB=
  endif
endif

# Object files (from C) for fst
GRT_FST_OBJS := fstapi.o lz4.o fastlz.o

# Additionnal object files (C or asm files).
GRT_ADD_OBJS:=$(GRT_TARGET_OBJS) grt-cbinding.o grt-cvpi.o $(GRT_FST_OBJS)
GRT_ADD_SHOBJS:=$(patsubst %, pic/%, $(GRT_ADD_OBJS))

# Source files create by grt.
GRT_SRC_DEPS:=grt-backtraces-impl.ads

#GRT_USE_PTHREADS=y
ifeq ($(GRT_USE_PTHREADS),y)
 GRT_CFLAGS+=-DUSE_THREADS
 GRT_ADD_OBJS+=grt-cthreads.o
 GRT_EXTRA_LIB+=-lpthread
endif

GRT_LIBBACKTRACE=
ifneq ($(LIBBACKTRACE),)
  GRT_LIBBACKTRACE=libbacktrace.a
endif

# Configuration pragmas.
# -gnatdY is required to force the use of __gnat_last_chance_handler.
GRT_PRAGMA_FLAG=-gnatec$(GRTSRCDIR)/grt.adc -gnat05 -gnatdY

# Rule to compile an Ada file.
GRT_ADACOMPILE=$(GNATMAKE) -u -c $(GRT_FLAGS) $(GRT_PRAGMA_FLAG)

grt-all: libgrt.a $(GRT_LIBBACKTRACE) grt.lst

libgrt.a: $(GRT_ADD_OBJS) run-bind.o main.o grt-files
	$(RM) -f $@
	$(AR) rcv $@ `sed -e "/^-/d" < grt-files` $(GRT_ADD_OBJS) \
	 run-bind.o main.o
	$(GRT_RANLIB) $@

run-bind.adb: $(GRT_SRC_DEPS) grt-force
	$(GNATMAKE) -c -aI$(GRTSRCDIR) $(GRT_PRAGMA_FLAG) \
	  ghdl_main $(GRT_ADAFLAGS) -cargs $(GRT_FLAGS)
# 	Set No Run-Time flag to suppress references to standard gnat library.
	sed -e '/^P /s/P /P NR /' < ghdl_main.ali > ghdl_main-tmp.ali
	$(MV) ghdl_main-tmp.ali ghdl_main.ali
	gnatbind -Lgrt_ -o run-bind.adb -n ghdl_main.ali

run-bind.o: run-bind.adb
	$(GRT_ADACOMPILE) -o $@ $<

main.o: $(GRTSRCDIR)/main.adb
	$(GRT_ADACOMPILE) -o $@ $<

GRT_C_COMPILE = $(CC) -c $(GRT_FLAGS) -o $@ $<
GRT_C_COMPILE_PIC = $(CC) -c $(GRT_FLAGS) $(PIC_FLAGS) -o $@ $<

jumps.o: $(GRTSRCDIR)/config/jumps.c
	$(GRT_C_COMPILE)

pic/jumps.o: $(GRTSRCDIR)/config/jumps.c
	$(GRT_C_COMPILE_PIC)

win32.o: $(GRTSRCDIR)/config/win32.c
	$(GRT_C_COMPILE)

math.o: $(GRTSRCDIR)/config/math.c
	$(GRT_C_COMPILE)

times.o : $(GRTSRCDIR)/config/times.c
	$(GRT_C_COMPILE)

pic/times.o : $(GRTSRCDIR)/config/times.c
	$(GRT_C_COMPILE_PIC)

clock.o : $(GRTSRCDIR)/config/clock.c
	$(GRT_C_COMPILE)

grt-cbinding.o: $(GRTSRCDIR)/grt-cbinding.c
	$(GRT_C_COMPILE)

pic/grt-cbinding.o: $(GRTSRCDIR)/grt-cbinding.c
	$(GRT_C_COMPILE_PIC)

grt-cvpi.o: $(GRTSRCDIR)/grt-cvpi.c
	$(GRT_C_COMPILE)

pic/grt-cvpi.o: $(GRTSRCDIR)/grt-cvpi.c
	$(GRT_C_COMPILE_PIC)

grt-cthreads.o: $(GRTSRCDIR)/grt-cthreads.c
	$(GRT_C_COMPILE)

fstapi.o: $(GRTSRCDIR)/fst/fstapi.c
	$(GRT_C_COMPILE) -I$(GRTSRCDIR)/fst

pic/fstapi.o: $(GRTSRCDIR)/fst/fstapi.c
	$(GRT_C_COMPILE_PIC) -I$(GRTSRCDIR)/fst

lz4.o: $(GRTSRCDIR)/fst/lz4.c
	$(GRT_C_COMPILE)

pic/lz4.o: $(GRTSRCDIR)/fst/lz4.c
	$(GRT_C_COMPILE_PIC)

fastlz.o: $(GRTSRCDIR)/fst/fastlz.c
	$(GRT_C_COMPILE)

pic/fastlz.o: $(GRTSRCDIR)/fst/fastlz.c
	$(GRT_C_COMPILE_PIC)

chkstk.o: $(GRTSRCDIR)/config/chkstk.S
	$(GRT_C_COMPILE)

grt-backtraces-impl.ads:
ifneq ($(GRT_LIBBACKTRACE),)
	echo "with Grt.Backtraces.Gcc;" > $@
	echo "package Grt.Backtraces.Impl renames Grt.Backtraces.Gcc;" >> $@
else
	echo "with Grt.Backtraces.Jit;" > $@
	echo "package Grt.Backtraces.Impl renames Grt.Backtraces.Jit;" >> $@
endif

grt-disp-config:
	@echo "target: $(target)"
	@echo "targ: $(targ)"
	@echo "arch: $(arch)"
	@echo "osys: $(osys)"

grt-files: run-bind.adb
	sed -e "1,/-- *BEGIN/d" -e "/-- *END/,\$$d" \
	  -e "s/   --   //" < $< > $@

# Remove local files (they are now in the libgrt library).
# Also, remove the -shared option, in order not to build a shared library
#  instead of an executable.
# Also remove -lgnat and its associated -L flags.  This appears to be required
#  with GNAT GPL 2005.
grt-files.in: grt-files
	sed -e "\!^.[/\\]!d" -e "/-shared/d" -e "/-static/d" -e "/-lgnat/d" \
	  -e "\X-L/Xd" < $< > $@

grt.lst: grt-files.in
	echo "@/libgrt.a" > $@
ifdef GRT_EXTRA_LIB
	for i in $(GRT_EXTRA_LIB); do echo $$i >> $@; done
endif
ifneq ($(LIBBACKTRACE),)
	echo "@/libbacktrace.a" >> $@
endif
	cat $< >> $@

ifneq ($(GRT_LIBBACKTRACE),)
$(GRT_LIBBACKTRACE): $(LIBBACKTRACE)
	cp $< $@
endif

grt-install: libgrt.a $(GRT_LIBBACKTRACE) grt.lst
	$(INSTALL_DATA) libgrt.a $(DESTDIR)$(grt_libdir)/libgrt.a
	$(INSTALL_DATA) grt.lst $(DESTDIR)$(grt_libdir)/grt.lst
ifneq ($(GRT_LIBBACKTRACE),)
	$(INSTALL_DATA) $(GRT_LIBBACKTRACE) $(DESTDIR)$(grt_libdir)/libbacktrace.a
endif

grt-force:

grt-clean: grt-force
	$(RM) *.o *.ali run-bind.adb run-bind.ads *.a std_standard.s
	$(RM) grt-files grt-files.in grt.lst

.PHONY: grt-all grt-force grt-clean grt-install