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