Skip to content

Commit a32f22c

Browse files
add most of the build infrastructure for libgfortran.
on a few platforms this also needs libquadmath. libgfortran.spec is unfortunately MD because of the libquadmath part. adjust libbacktrace to allow it to be built into libgfortran directly. NFC intended here for normal builds.
1 parent f89b0f6 commit a32f22c

42 files changed

Lines changed: 682 additions & 11 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
1-
# $NetBSD: Makefile,v 1.3 2016/03/16 05:42:07 mrg Exp $
1+
# $NetBSD: Makefile,v 1.4 2026/01/18 08:07:06 mrg Exp $
22

33
LIBISPRIVATE= yes
44

5-
.include <bsd.init.mk>
5+
LIB= backtrace
66

7-
LIB= backtrace
7+
.include "Makefile.sources"
88

9-
DIST= ${GCCDIST}
10-
GNUHOSTDIST= ${DIST}
9+
SRCS= ${BACKTRACE_SRCS}
1110

12-
SRCS= dwarf.c elf.c fileline.c mmap.c mmapio.c nounwind.c \
13-
posix.c print.c state.c
14-
15-
CPPFLAGS+= -I${DIST}/include -I${DIST}/libgcc
16-
CPPFLAGS+= -I${.CURDIR}/arch/${GCC_MACHINE_ARCH}
11+
.for _s in ${BACKTRACE_SRCS}
12+
CPPFLAGS.${_s}+= ${BACKTRACE_CPPFLAGS}
13+
.endfor
1714

1815
.include <bsd.lib.mk>
1916

20-
.PATH: ${DIST}/libbacktrace
17+
.PATH: ${GCCDIST}/libbacktrace
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# $NetBSD: Makefile.sources,v 1.1 2026/01/18 08:07:06 mrg Exp $
2+
3+
BACKTRACE_SRCS= backtrace.c dwarf.c elf.c fileline.c mmap.c mmapio.c \
4+
posix.c print.c simple.c sort.c state.c
5+
BACKTRACE_CPPFLAGS= -I${GCCDIST}/../lib/libbacktrace/arch/${GCC_MACHINE_ARCH} \
6+
-I${GCCDIST}/libbacktrace \
7+
-I${GCCDIST}/include \
8+
-I${GCCDIST}/libgcc \
9+
-I${.CURDIR}/arch/${GCC_MACHINE_ARCH}
10+
11+
.PATH: ${GCCDIST}/libbacktrace
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
# $NetBSD: Makefile,v 1.1 2026/01/18 08:07:00 mrg Exp $
2+
3+
# XXX libgfortran also has a libcaf_single thing in here.
4+
5+
# This needs to be before bsd.init.mk
6+
.if defined(BSD_MK_COMPAT_FILE)
7+
.include <${BSD_MK_COMPAT_FILE}>
8+
.endif
9+
10+
.include <bsd.init.mk>
11+
12+
LIB= gfortran
13+
14+
# Match GCC 14.
15+
SHLIB_MAJOR= 5
16+
SHLIB_MINOR= 0
17+
18+
DIST= ${GCCDIST}
19+
GNUHOSTDIST= ${DIST}
20+
GFORTRAN= ${DIST}/libgfortran
21+
22+
# These are earlier than included file paths, to avoid getting eg
23+
# libbacktrace's read.c instead of io/read.c.
24+
.PATH: ${DIST}/libgfortran
25+
.PATH: ${DIST}/libgfortran/generated
26+
.PATH: ${DIST}/libgfortran/intrinsics
27+
.PATH: ${DIST}/libgfortran/runtime
28+
.PATH: ${DIST}/libgfortran/io
29+
.PATH: ${DIST}/libgfortran/ieee
30+
.PATH: ${.CURDIR}/arch/${GCC_MACHINE_ARCH}
31+
32+
# remove prefixes, .inc and .h files
33+
GFORTRAN_SRCS= ${G_libgfortran_la_SOURCES:C,^.*/,,:C,.*\.inc$,,:C,.*\.h$,,}
34+
35+
.include "../Makefile.gthr"
36+
.include "${.CURDIR}/arch/${GCC_MACHINE_ARCH}/defs.mk"
37+
.include "../libbacktrace/Makefile.sources"
38+
39+
GFORTRAN_BACKTRACE_SRCS= ${BACKTRACE_SRCS:backtrace.c=libbacktrace-backtrace.c}
40+
41+
BUILDSYMLINKS+= ${GNUHOSTDIST}/libbacktrace/backtrace.c libbacktrace-backtrace.c
42+
43+
# gcc builddir before libgcc
44+
# libgcc builddir after libgcc
45+
46+
.if ${HAVE_QUADMATH} != no
47+
CPPFLAGS_QUADMATH=-I${DIST}/libquadmath
48+
.else
49+
CPPFLAGS_QUADMATH=
50+
.endif
51+
52+
.for _s in ${GFORTRAN_SRCS}
53+
CPPFLAGS.${_s}+= -I. \
54+
-I${.CURDIR}/arch/${GCC_MACHINE_ARCH} \
55+
-I${GFORTRAN} \
56+
-I${GFORTRAN}/io \
57+
-I${DIST}/gcc \
58+
-I${DIST}/gcc/config \
59+
${CPPFLAGS_QUADMATH} \
60+
-I${DIST}/libgcc \
61+
-I${DIST}/libbacktrace \
62+
-I${DIST}/../lib/libbacktrace/arch/${GCC_MACHINE_ARCH} \
63+
-I${.CURDIR}/arch/${GCC_MACHINE_ARCH}
64+
.endfor
65+
66+
.for _s in ${GFORTRAN_BACKTRACE_SRCS}
67+
CPPFLAGS.${_s}+= -I. \
68+
${BACKTRACE_CPPFLAGS}
69+
.endfor
70+
71+
SRCS= ${GFORTRAN_SRCS} ${GFORTRAN_BACKTRACE_SRCS}
72+
73+
FFLAGS+= -I. -fno-repack-arrays -fno-underscoring -I${.CURDIR}/arch/${GCC_MACHINE_ARCH}
74+
75+
LIBDPLIBS+= m ${NETBSDSRCDIR}/lib/libm
76+
.if ${HAVE_QUADMATH} != no
77+
LIBDPLIBS+= quadmath ${.CURDIR}/../libquadmath
78+
.endif
79+
80+
DPSRCS+= kinds.h kinds.inc c99_protos.inc fpu-target.inc \
81+
selected_int_kind.inc selected_real_kind.inc
82+
83+
${GFORTRAN_SRCS:M*.F90}: ${DPSRCS}
84+
85+
INTLIST='1 2 4 8 16'
86+
REALLIST='4 8 10 16'
87+
88+
fpu-target.h: ${GFORTRAN}/${G_FPU_HOST_HEADER}
89+
cp ${GFORTRAN}/${G_FPU_HOST_HEADER} $@
90+
91+
fpu-target.inc: fpu-target.h ${DIST}/gcc/fortran/libgfortran.h
92+
${TOOL_GREP} -h '^#define GFC_FPE_' ${.ALLSRC} > ${.TARGET}
93+
94+
c99_protos.inc: ${GFORTRAN}/c99_protos.h
95+
${TOOL_GREP} '^#' < ${.ALLSRC} > ${.TARGET} || rm ${.TARGET}
96+
LIBS+= ${BACKENDOBJ}/libbackend.a
97+
kinds.h: ${GFORTRAN}/mk-kinds-h.sh
98+
${HOST_SH} ${GFORTRAN}/mk-kinds-h.sh \
99+
${INTLIST} \
100+
${REALLIST} \
101+
"${FC} ${FFLAGS}" \
102+
no > \
103+
${.TARGET} || rm ${.TARGET}
104+
105+
kinds.inc: kinds.h ${GFORTRAN}/kinds-override.h
106+
cat kinds.h ${GFORTRAN}/kinds-override.h | \
107+
${TOOL_GREP} '^#' | \
108+
${TOOL_GREP} -v include > \
109+
${.TARGET} || rm ${.TARGET}
110+
111+
selected_int_kind.inc: ${GFORTRAN}/mk-sik-inc.sh
112+
${HOST_SH} ${GFORTRAN}/mk-sik-inc.sh \
113+
${INTLIST} \
114+
"${FC} ${FFLAGS}" > \
115+
${.TARGET} || rm ${.TARGET}
116+
117+
selected_real_kind.inc: ${GFORTRAN}/mk-srk-inc.sh
118+
${HOST_SH} ${GFORTRAN}/mk-srk-inc.sh \
119+
${REALLIST} \
120+
"${FC} ${FFLAGS}" > \
121+
${.TARGET} || rm ${.TARGET}
122+
123+
fpu.c: fpu-target.h
124+
125+
COPTS.date_and_time.c+= ${CC_WNO_FORMAT_TRUNCATION}
126+
COPTS.list_read.c+= -Wno-error=pointer-arith
127+
COPTS.transfer.c+= -Wno-error=pointer-arith
128+
COPTS.write.c+= -Wno-error=pointer-arith
129+
130+
# ieee_arithmetic needs ieee_exceptions.mod to be already built
131+
ieee_arithmetic.o ieee_arithmetic.pico ieee_arithmetic.po ieee_arithmetic.go: ieee_exceptions.pico ieee_exceptions.po ieee_exceptions.o ieee_exceptions.go
132+
133+
# these .mod's gets built multiple times, so serialise those
134+
.for _mod in ieee_arithmetic ieee_exceptions ieee_features
135+
${_mod}.mod: ${_mod}.o
136+
${_mod}.o: ${_mod}.pico
137+
${_mod}.pico: ${_mod}.po
138+
${_mod}.po: ${_mod}.go
139+
.endfor
140+
141+
CLEANFILES+= fpu-target.h fpu-target.inc c99_protos.inc \
142+
kinds.h kinds.inc \
143+
selected_int_kind.inc selected_real_kind.inc \
144+
ieee_arithmetic.mod ieee_exceptions.mod ieee_features.mod
145+
146+
.for _f in ${G_i_matmul_c:C,^.*/,,}
147+
FOPTS.${_f}+= -ffast-math -ftree-vectorize -funroll-loops --param max-unroll-times=4
148+
.endfor
149+
150+
#.if ${MACHINE} == "amd64"
151+
.for _f in ${G_i_matmulavx128_c:C,^.*/,,}
152+
FOPTS.${_f}+= -ffast-math -ftree-vectorize -funroll-loops --param max-unroll-times=4 -mprefer-avx128
153+
.endfor
154+
#.endif
155+
156+
.for _f in ${G_i_matmull_c:C,^.*/,,}
157+
FOPTS.${_f}+= -funroll-loops
158+
.endfor
159+
160+
.for _f in ${G_gfor_specific_src:C,^.*/,,}
161+
FOPTS.${_f}+= -fallow-leading-underscore -fbuilding-libgfortran
162+
.endfor
163+
164+
.for _f in selected_real_kind.f90 selected_int_kind.f90
165+
FOPTS.${_f}+= -fallow-leading-underscore -fbuilding-libgfortran
166+
.endfor
167+
168+
.for _f in ${G_gfor_ieee_src:C,^.*/,,}
169+
FOPTS.${_f}+= -Wno-unused-dummy-argument -Wno-c-binding-type -ffree-line-length-0 -fallow-leading-underscore -fsignaling-nans -fbuilding-libgfortran
170+
.endfor
171+
172+
.for _f in ${G_gfor_ieee_helper_src:C,^.*/,,}
173+
FOPTS.${_f}+= -fsignaling-nans
174+
.endfor
175+
176+
# Don't install these more than once.
177+
.ifndef MLIBDIR
178+
INCS= ${G_nodist_finclude_HEADERS}
179+
INCSDIR= ${GCC_INCSDIR}/finclude
180+
181+
# This is where GCC looks for it.
182+
FILES= libgfortran.spec
183+
FILESDIR= ${LIBDIR}
184+
.endif
185+
186+
.include <bsd.lib.mk>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# This file is automatically generated. DO NOT EDIT!
2+
# Generated from: NetBSD: mknative-gcc,v 1.123 2026/01/17 23:43:46 mrg Exp
3+
# Generated from: NetBSD: mknative.common,v 1.16 2018/04/15 15:13:37 christos Exp
4+
#
5+
#
6+
# This spec file is read by gfortran when linking.
7+
# It is used to specify the libraries we need to link in, in the right
8+
# order.
9+
#
10+
11+
%rename lib liborig
12+
*lib: -lm %(liborig)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# This file is automatically generated. DO NOT EDIT!
2+
# Generated from: NetBSD: mknative-gcc,v 1.123 2026/01/17 23:43:46 mrg Exp
3+
# Generated from: NetBSD: mknative.common,v 1.16 2018/04/15 15:13:37 christos Exp
4+
#
5+
#
6+
# This spec file is read by gfortran when linking.
7+
# It is used to specify the libraries we need to link in, in the right
8+
# order.
9+
#
10+
11+
%rename lib liborig
12+
*lib: -lm %(liborig)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# This file is automatically generated. DO NOT EDIT!
2+
# Generated from: NetBSD: mknative-gcc,v 1.123 2026/01/17 23:43:46 mrg Exp
3+
# Generated from: NetBSD: mknative.common,v 1.16 2018/04/15 15:13:37 christos Exp
4+
#
5+
#
6+
# This spec file is read by gfortran when linking.
7+
# It is used to specify the libraries we need to link in, in the right
8+
# order.
9+
#
10+
11+
%rename lib liborig
12+
*lib: -lm %(liborig)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# This file is automatically generated. DO NOT EDIT!
2+
# Generated from: NetBSD: mknative-gcc,v 1.123 2026/01/17 23:43:46 mrg Exp
3+
# Generated from: NetBSD: mknative.common,v 1.16 2018/04/15 15:13:37 christos Exp
4+
#
5+
#
6+
# This spec file is read by gfortran when linking.
7+
# It is used to specify the libraries we need to link in, in the right
8+
# order.
9+
#
10+
11+
%rename lib liborig
12+
*lib: -lm %(liborig)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# This file is automatically generated. DO NOT EDIT!
2+
# Generated from: NetBSD: mknative-gcc,v 1.123 2026/01/17 23:43:46 mrg Exp
3+
# Generated from: NetBSD: mknative.common,v 1.16 2018/04/15 15:13:37 christos Exp
4+
#
5+
#
6+
# This spec file is read by gfortran when linking.
7+
# It is used to specify the libraries we need to link in, in the right
8+
# order.
9+
#
10+
11+
%rename lib liborig
12+
*lib: -lm %(liborig)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# This file is automatically generated. DO NOT EDIT!
2+
# Generated from: NetBSD: mknative-gcc,v 1.123 2026/01/17 23:43:46 mrg Exp
3+
# Generated from: NetBSD: mknative.common,v 1.16 2018/04/15 15:13:37 christos Exp
4+
#
5+
#
6+
# This spec file is read by gfortran when linking.
7+
# It is used to specify the libraries we need to link in, in the right
8+
# order.
9+
#
10+
11+
%rename lib liborig
12+
*lib: -lm %(liborig)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# This file is automatically generated. DO NOT EDIT!
2+
# Generated from: NetBSD: mknative-gcc,v 1.123 2026/01/17 23:43:46 mrg Exp
3+
# Generated from: NetBSD: mknative.common,v 1.16 2018/04/15 15:13:37 christos Exp
4+
#
5+
#
6+
# This spec file is read by gfortran when linking.
7+
# It is used to specify the libraries we need to link in, in the right
8+
# order.
9+
#
10+
11+
%rename lib liborig
12+
*lib: -lm %(liborig)

0 commit comments

Comments
 (0)