| 1 |
# Top level -*- makefile -*- fragment for Cobol |
| 2 |
# Copyright (C) 2021-2025 Free Software Foundation, Inc. |
| 3 |
|
| 4 |
# This file is part of GCC. |
| 5 |
|
| 6 |
# GCC is free software; you can redistribute it and/or modify |
| 7 |
# it under the terms of the GNU General Public License as published by |
| 8 |
# the Free Software Foundation; either version 3, or (at your option) |
| 9 |
# any later version. |
| 10 |
|
| 11 |
# GCC is distributed in the hope that it will be useful, |
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
# GNU General Public License for more details. |
| 15 |
|
| 16 |
# You should have received a copy of the GNU General Public License |
| 17 |
# along with GCC; see the file COPYING3. If not see |
| 18 |
# <http://www.gnu.org/licenses/>. |
| 19 |
|
| 20 |
# This file provides the language dependent support in the main Makefile. |
| 21 |
# Each language makefile fragment must provide the following targets: |
| 22 |
# |
| 23 |
# foo.all.cross, foo.start.encap, foo.rest.encap, |
| 24 |
# foo.install-common, foo.install-man, foo.install-info, foo.install-pdf, |
| 25 |
# foo.install-html, foo.info, foo.dvi, foo.pdf, foo.html, foo.uninstall, |
| 26 |
# foo.mostlyclean, foo.clean, foo.distclean, |
| 27 |
# foo.maintainer-clean, foo.stage1, foo.stage2, foo.stage3, foo.stage4 |
| 28 |
# |
| 29 |
# where `foo' is the name of the language. |
| 30 |
# |
| 31 |
# It should also provide rules for: |
| 32 |
# |
| 33 |
# - making any compiler driver (eg: g++) |
| 34 |
# - the compiler proper (eg: cc1plus) |
| 35 |
# - define the names for selecting the language in LANGUAGES. |
| 36 |
|
| 37 |
# Use strict warnings for this front end. |
| 38 |
cobol-warn = $(STRICT_WARN) |
| 39 |
|
| 40 |
GCOBOL_INSTALL_NAME := $(shell echo gcobol|sed '$(program_transform_name)') |
| 41 |
GCOBOLIO_INSTALL_NAME := $(shell echo gcobol-io|sed '$(program_transform_name)') |
| 42 |
GCOBOL_TARGET_INSTALL_NAME := $(target_noncanonical)-$(shell echo gcobol|sed '$(program_transform_name)') |
| 43 |
|
| 44 |
GCOBC_INSTALL_NAME := $(shell echo gcobc|sed '$(program_transform_name)') |
| 45 |
GCOBC_TARGET_INSTALL_NAME := $(target_noncanonical)-$(shell echo gcobc|sed '$(program_transform_name)') |
| 46 |
|
| 47 |
GCOBOL_HTML_FILES = $(addprefix $(build_htmldir)/gcobol/,gcobol.html gcobol-io.html) |
| 48 |
|
| 49 |
cobol: cobol1$(exeext) |
| 50 |
cobol.serial = cobol1$(exeext) |
| 51 |
.PHONY: cobol |
| 52 |
|
| 53 |
LIB_SOURCE ?= $(srcdir)/../libgcobol |
| 54 |
|
| 55 |
YFLAGS = -Werror -Wmidrule-values -Wno-yacc \ |
| 56 |
--debug --verbose |
| 57 |
|
| 58 |
LFLAGS = -d -Ca |
| 59 |
|
| 60 |
# |
| 61 |
# These are the object files for creating the cobol1 compiler: |
| 62 |
# |
| 63 |
cobol1_OBJS = \ |
| 64 |
cobol/cdf.o \ |
| 65 |
cobol/cdf-copy.o \ |
| 66 |
cobol/cobol1.o \ |
| 67 |
cobol/convert.o \ |
| 68 |
cobol/except.o \ |
| 69 |
cobol/genutil.o \ |
| 70 |
cobol/genapi.o \ |
| 71 |
cobol/genmath.o \ |
| 72 |
cobol/gengen.o \ |
| 73 |
cobol/lexio.o \ |
| 74 |
cobol/parse.o \ |
| 75 |
cobol/scan.o \ |
| 76 |
cobol/structs.o \ |
| 77 |
cobol/symbols.o \ |
| 78 |
cobol/symfind.o \ |
| 79 |
cobol/util.o \ |
| 80 |
cobol/charmaps.o \ |
| 81 |
cobol/valconv.o \ |
| 82 |
$(END) |
| 83 |
|
| 84 |
# |
| 85 |
# There is source code in libgcobol/charmaps.cc and |
| 86 |
# libgcobol/valconv.cc that needs to be compiled into both libgcobol |
| 87 |
# and cobol1. We copy those two source code files from libgcobol to |
| 88 |
# build/gcc/cobol to avoid the nightmare of one file appearing in more |
| 89 |
# than one place. For simplicity, we make those compilations dependent |
| 90 |
# on all of the libgcobol/*.h files, which might lead to the occasional |
| 91 |
# unnecessary compilation. The impact of that is negligible. |
| 92 |
# |
| 93 |
# Various #includes in the files copied from gcc/libgcobol need to be modified |
| 94 |
# so that the .h files can be found. |
| 95 |
|
| 96 |
cobol/charmaps.cc cobol/valconv.cc: cobol/%.cc: $(LIB_SOURCE)/%.cc |
| 97 |
sed -e '/^#include/s,"\([^"]*[^g"].h\)","../../libgcobol/\1",' $^ > $@ |
| 98 |
|
| 99 |
LIB_SOURCE_H=$(wildcard $(LIB_SOURCE)/*.h) |
| 100 |
|
| 101 |
cobol/charmaps.o: cobol/charmaps.cc $(LIB_SOURCE_H) |
| 102 |
|
| 103 |
cobol/valconv.o: cobol/valconv.cc $(LIB_SOURCE_H) |
| 104 |
|
| 105 |
# |
| 106 |
# These are the object files for creating the gcobol "driver" |
| 107 |
# |
| 108 |
GCOBOL_D_OBJS = $(GCC_OBJS) cobol/gcobolspec.o |
| 109 |
|
| 110 |
# |
| 111 |
# These get combined to provide a dependency relationship that ensures all |
| 112 |
# of the "generated-files" are generated before we need them. See the root |
| 113 |
# Makefile.in code that looks like this: |
| 114 |
# ALL_HOST_FRONTEND_OBJS = $(foreach v,$(CONFIG_LANGUAGES),$($(v)_OBJS)) |
| 115 |
# |
| 116 |
cobol_OBJS = \ |
| 117 |
$(cobol1_OBJS) \ |
| 118 |
cobol/gcobolspec.o \ |
| 119 |
$(END) |
| 120 |
|
| 121 |
# |
| 122 |
# Frankly, I can't figure out what this does: |
| 123 |
# |
| 124 |
CFLAGS-cobol/gcobolspec.o += $(DRIVER_DEFINES) |
| 125 |
|
| 126 |
# |
| 127 |
# This controls the build of the gcobol "driver" |
| 128 |
# |
| 129 |
gcobol$(exeext): \ |
| 130 |
$(GCOBOL_D_OBJS) \ |
| 131 |
$(EXTRA_GCC_OBJS) \ |
| 132 |
libcommon-target.a \ |
| 133 |
$(LIBDEPS) |
| 134 |
+$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \ |
| 135 |
$(GCOBOL_D_OBJS) $(EXTRA_GCC_OBJS) libcommon-target.a \ |
| 136 |
$(EXTRA_GCC_LIBS) $(LIBS) |
| 137 |
|
| 138 |
# Create a version of the gcobol driver which calls the cross-compiler. |
| 139 |
gcobol-cross$(exeext): gcobol$(exeext) |
| 140 |
-rm -f gcobol-cross$(exeext) |
| 141 |
cp gcobol$(exeext) gcobol-cross$(exeext) |
| 142 |
|
| 143 |
# |
| 144 |
# These control the build of the cobol1 source-to-GENERIC converter |
| 145 |
# |
| 146 |
|
| 147 |
# First, files needed for parsing: |
| 148 |
|
| 149 |
cobol/parse.cc: cobol/parse.y |
| 150 |
$(BISON) -o $@ $(YFLAGS) \ |
| 151 |
--defines=cobol/parse.h \ |
| 152 |
--report-file=cobol/parser.out $< |
| 153 |
|
| 154 |
cobol/cdf.cc: cobol/cdf.y |
| 155 |
$(BISON) -o $@ $(YFLAGS) \ |
| 156 |
--defines=cobol/cdf.h --report-file=cobol/cdf.out $< |
| 157 |
|
| 158 |
# See "Trailing context is getting confused with trailing optional patterns" |
| 159 |
# in Flex manual. We suppress those messages, as a convenience. |
| 160 |
FLEX_WARNING = warning, dangerous trailing context |
| 161 |
|
| 162 |
cobol/scan.cc: cobol/scan.l |
| 163 |
$(FLEX) -o$@ $(LFLAGS) $< 2>$@~ || { cat $@~ >&1; exit 1; } |
| 164 |
awk '! /$(FLEX_WARNING)/ {print > "/dev/stderr"; nerr++} \ |
| 165 |
END {print "$(FLEX):", NR, "messages" > "/dev/stderr"}' $@~ |
| 166 |
@rm $@~ |
| 167 |
|
| 168 |
|
| 169 |
# To establish prerequisites for parse.o, cdf.o, and scan.o, |
| 170 |
# 1. capture the "make -n" output |
| 171 |
# 2. eliminate compiler options, leaving only preprocessor options (-D and -I) |
| 172 |
# 3. add -E -MM |
| 173 |
# |
| 174 |
# The below lists of include files for the the generated files is |
| 175 |
# postprocessed: the files are one per line, used "realpath |
| 176 |
# --relative-to=$PWD" to rationalize them, and sorted. We include |
| 177 |
# parse.cc in the list for scan.o because that's the one make(1) knows about. |
| 178 |
|
| 179 |
cobol/cdf.o: cobol/cdf.cc \ |
| 180 |
$(srcdir)/cobol/cbldiag.h \ |
| 181 |
$(srcdir)/cobol/cdfval.h \ |
| 182 |
$(srcdir)/cobol/copybook.h \ |
| 183 |
$(srcdir)/cobol/exceptg.h \ |
| 184 |
$(srcdir)/cobol/symbols.h \ |
| 185 |
$(srcdir)/cobol/util.h \ |
| 186 |
$(srcdir)/../libgcobol/common-defs.h \ |
| 187 |
$(srcdir)/../libgcobol/ec.h \ |
| 188 |
$(srcdir)/../libgcobol/exceptl.h |
| 189 |
|
| 190 |
cobol/parse.o: cobol/parse.cc \ |
| 191 |
$(srcdir)/cobol/cbldiag.h \ |
| 192 |
$(srcdir)/cobol/cdfval.h \ |
| 193 |
$(srcdir)/cobol/cobol-system.h \ |
| 194 |
$(srcdir)/cobol/exceptg.h \ |
| 195 |
$(srcdir)/cobol/genapi.h \ |
| 196 |
$(srcdir)/cobol/inspect.h \ |
| 197 |
$(srcdir)/cobol/parse_ante.h \ |
| 198 |
$(srcdir)/cobol/parse_util.h \ |
| 199 |
$(srcdir)/cobol/symbols.h \ |
| 200 |
$(srcdir)/cobol/util.h \ |
| 201 |
$(srcdir)/hwint.h \ |
| 202 |
$(srcdir)/system.h \ |
| 203 |
$(srcdir)/../include/ansidecl.h \ |
| 204 |
$(srcdir)/../include/filenames.h \ |
| 205 |
$(srcdir)/../include/hashtab.h \ |
| 206 |
$(srcdir)/../include/libiberty.h \ |
| 207 |
$(srcdir)/../include/safe-ctype.h \ |
| 208 |
$(srcdir)/../libgcobol/common-defs.h \ |
| 209 |
$(srcdir)/../libgcobol/ec.h \ |
| 210 |
$(srcdir)/../libgcobol/exceptl.h \ |
| 211 |
$(srcdir)/../libgcobol/io.h \ |
| 212 |
auto-host.h \ |
| 213 |
config.h |
| 214 |
|
| 215 |
cobol/scan.o: cobol/scan.cc \ |
| 216 |
$(srcdir)/cobol/cbldiag.h \ |
| 217 |
$(srcdir)/cobol/cdfval.h \ |
| 218 |
$(srcdir)/cobol/cobol-system.h \ |
| 219 |
$(srcdir)/cobol/copybook.h \ |
| 220 |
$(srcdir)/cobol/dts.h \ |
| 221 |
$(srcdir)/cobol/exceptg.h \ |
| 222 |
$(srcdir)/cobol/inspect.h \ |
| 223 |
$(srcdir)/cobol/lexio.h \ |
| 224 |
$(srcdir)/cobol/scan_ante.h \ |
| 225 |
$(srcdir)/cobol/scan_post.h \ |
| 226 |
$(srcdir)/cobol/symbols.h \ |
| 227 |
$(srcdir)/cobol/util.h \ |
| 228 |
$(srcdir)/hwint.h \ |
| 229 |
$(srcdir)/system.h \ |
| 230 |
$(srcdir)/../include/ansidecl.h \ |
| 231 |
$(srcdir)/../include/filenames.h \ |
| 232 |
$(srcdir)/../include/hashtab.h \ |
| 233 |
$(srcdir)/../include/libiberty.h \ |
| 234 |
$(srcdir)/../include/safe-ctype.h \ |
| 235 |
$(srcdir)/../libgcobol/common-defs.h \ |
| 236 |
$(srcdir)/../libgcobol/ec.h \ |
| 237 |
$(srcdir)/../libgcobol/exceptl.h \ |
| 238 |
$(srcdir)/../libgcobol/io.h \ |
| 239 |
auto-host.h \ |
| 240 |
config.h \ |
| 241 |
cobol/cdf.cc \ |
| 242 |
cobol/parse.cc |
| 243 |
|
| 244 |
# |
| 245 |
# The src<foo> targets are executed if |
| 246 |
# ‘--enable-generated-files-in-srcdir’ was specified as a configure |
| 247 |
# option. |
| 248 |
# |
| 249 |
# srcextra copies generated dependencies into the source |
| 250 |
# directory. This is used for files such as Flex/Bison output: files |
| 251 |
# that are not version-controlled but should be included in any |
| 252 |
# release tarballs. |
| 253 |
# |
| 254 |
# Although versioned snapshots require Flex to be installed, they do |
| 255 |
# not require Bison. Release tarballs always include Flex/Bison |
| 256 |
# output, and do not require those tools to be installed. |
| 257 |
# |
| 258 |
cobol.srcextra: cobol/parse.cc cobol/cdf.cc cobol/scan.cc |
| 259 |
-for i in $^ cobol/parse.h cobol/cdf.h; do \ |
| 260 |
sed -e '/^#line/s,"\(.*gcc/\)\?cobol/\([^/]*\.\([ylh]\|cc\)\)","\2",' $$i \ |
| 261 |
> $(srcdir)/$$i; done |
| 262 |
|
| 263 |
# And the cobol1 front end |
| 264 |
|
| 265 |
cobol1$(exeext): $(cobol1_OBJS) $(BACKEND) $(LIBDEPS) attribs.o $(cobol.prev) |
| 266 |
@$(call LINK_PROGRESS,$(INDEX.cobol),start) |
| 267 |
+$(LLINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) attribs.o -o $@ \ |
| 268 |
$(cobol1_OBJS) $(BACKEND) $(LIBS) $(BACKENDLIBS) |
| 269 |
@$(call LINK_PROGRESS,$(INDEX.cobol),end) |
| 270 |
|
| 271 |
cobol.all.cross: gcobol-cross$(exeext) |
| 272 |
|
| 273 |
cobol.start.encap: gcobol$(exeext) |
| 274 |
|
| 275 |
cobol.rest.encap: |
| 276 |
|
| 277 |
cobol.install-common: installdirs |
| 278 |
-rm -f $(DESTDIR)$(bindir)/$(GCOBOL_INSTALL_NAME)$(exeext) |
| 279 |
-rm -f $(DESTDIR)$(bindir)/$(GCOBC_INSTALL_NAME)$(exeext) |
| 280 |
$(INSTALL_PROGRAM) gcobol$(exeext) $(DESTDIR)$(bindir)/$(GCOBOL_INSTALL_NAME)$(exeext) |
| 281 |
$(INSTALL_PROGRAM) cobol1$(exeext) $(DESTDIR)$(libexecsubdir)/ |
| 282 |
$(INSTALL) -m 755 $(srcdir)/cobol/gcobc $(DESTDIR)$(bindir)/$(GCOBC_INSTALL_NAME)$(exeext) |
| 283 |
-if test -f cobol1$(exeext); then \ |
| 284 |
if test -f gcobol-cross$(exeext); then \ |
| 285 |
:; \ |
| 286 |
else \ |
| 287 |
rm -f $(DESTDIR)$(bindir)/$(GCOBOL_TARGET_INSTALL_NAME)$(exeext); \ |
| 288 |
rm -f $(DESTDIR)$(bindir)/$(GCOBC_TARGET_INSTALL_NAME)$(exeext); \ |
| 289 |
( cd $(DESTDIR)$(bindir) && \ |
| 290 |
$(LN) $(GCOBOL_INSTALL_NAME)$(exeext) $(GCOBOL_TARGET_INSTALL_NAME)$(exeext) && \ |
| 291 |
$(LN) $(GCOBC_INSTALL_NAME)$(exeext) $(GCOBC_TARGET_INSTALL_NAME)$(exeext) ); \ |
| 292 |
fi; \ |
| 293 |
fi |
| 294 |
mkdir -p $(DESTDIR)$(datadir)/gcobol/udf |
| 295 |
$(INSTALL_DATA) $(srcdir)/cobol/udf/* $(DESTDIR)$(datadir)/gcobol/udf/ |
| 296 |
|
| 297 |
cobol.install-man: installdirs |
| 298 |
$(INSTALL_DATA) $(srcdir)/cobol/gcobol.1 $(DESTDIR)$(man1dir)/$(GCOBOL_INSTALL_NAME)$(man1ext) |
| 299 |
$(INSTALL_DATA) $(srcdir)/cobol/gcobol.3 $(DESTDIR)$(man3dir)/$(GCOBOLIO_INSTALL_NAME)$(man3ext) |
| 300 |
|
| 301 |
cobol.install-info: |
| 302 |
|
| 303 |
cobol.install-pdf: installdirs gcobol.pdf gcobol-io.pdf |
| 304 |
mkdir -p $(DESTDIR)$(datadir)/gcobol/pdf |
| 305 |
$(INSTALL_DATA) gcobol.pdf gcobol-io.pdf $(DESTDIR)$(pdfdir)/ |
| 306 |
|
| 307 |
cobol.install-plugin: |
| 308 |
|
| 309 |
cobol.install-html: installdirs $(GCOBOL_HTML_FILES) |
| 310 |
$(INSTALL_DATA) $(GCOBOL_HTML_FILES) $(DESTDIR)$(htmldir)/ |
| 311 |
|
| 312 |
cobol.info: |
| 313 |
cobol.srcinfo: |
| 314 |
|
| 315 |
cobol.dvi: |
| 316 |
cobol.srcdvi: |
| 317 |
|
| 318 |
cobol.pdf: gcobol.pdf gcobol-io.pdf |
| 319 |
cobol.srcpdf: gcobol.pdf gcobol-io.pdf |
| 320 |
ln $^ $(srcdir)/cobol/ |
| 321 |
|
| 322 |
gcobol.pdf: $(srcdir)/cobol/gcobol.1 |
| 323 |
groff -mdoc -T pdf $^ > $@~ |
| 324 |
@mv $@~ $@ |
| 325 |
gcobol-io.pdf: $(srcdir)/cobol/gcobol.3 |
| 326 |
groff -mdoc -T pdf $^ > $@~ |
| 327 |
@mv $@~ $@ |
| 328 |
|
| 329 |
cobol.html: $(GCOBOL_HTML_FILES) |
| 330 |
cobol.srchtml: $(GCOBOL_HTML_FILES) |
| 331 |
ln $^ $(srcdir)/cobol/ |
| 332 |
|
| 333 |
$(build_htmldir)/gcobol/gcobol.html: $(srcdir)/cobol/gcobol.1 |
| 334 |
$(mkinstalldirs) $(build_htmldir)/gcobol |
| 335 |
mandoc -T html $^ > $@~ |
| 336 |
@mv $@~ $@ |
| 337 |
$(build_htmldir)/gcobol/gcobol-io.html: $(srcdir)/cobol/gcobol.3 |
| 338 |
$(mkinstalldirs) $(build_htmldir)/gcobol |
| 339 |
mandoc -T html $^ > $@~ |
| 340 |
@mv $@~ $@ |
| 341 |
|
| 342 |
# "make uninstall" is not expected to work. It's not clear how to name |
| 343 |
# the installed location of the cobol1 compiler. |
| 344 |
cobol.uninstall: |
| 345 |
rm -rf $(DESTDIR)$(bindir)/$(GCOBOL_INSTALL_NAME)$(exeext) \ |
| 346 |
$(DESTDIR)$(bindir)/$(GCOBC_INSTALL_NAME) \ |
| 347 |
$(DESTDIR)$(datadir)/gcobol/ \ |
| 348 |
$(DESTDIR)$(man1dir)/$(GCOBOL_INSTALL_NAME)$(man1ext) \ |
| 349 |
$(DESTDIR)$(man3dir)/$(GCOBOLIO_INSTALL_NAME)$(man3ext) |
| 350 |
|
| 351 |
cobol.man: |
| 352 |
cobol.srcman: |
| 353 |
|
| 354 |
cobol.mostlyclean: |
| 355 |
|
| 356 |
gcobol.clean: |
| 357 |
# This is intended for non-general use. It is a last-ditch effort to flush |
| 358 |
# out all oject files and executable code for gcobol and libgcobol, causing |
| 359 |
# a complete rebuild of all executable code. |
| 360 |
rm -fr gcobol cobol1 cobol/* \ |
| 361 |
../*/libgcobol/* |
| 362 |
|
| 363 |
cobol.clean: |
| 364 |
rm -fr gcobol cobol1 cobol/* |
| 365 |
|
| 366 |
cobol.distclean: |
| 367 |
|
| 368 |
cobol.maintainer-clean: |
| 369 |
|
| 370 |
# The main makefile has already created stage?/cobol. |
| 371 |
cobol.stage1: stage1-start |
| 372 |
-mv cobol/*$(objext) stage1/cobol |
| 373 |
cobol.stage2: stage2-start |
| 374 |
-mv cobol/*$(objext) stage2/cobol |
| 375 |
cobol.stage3: stage3-start |
| 376 |
-mv cobol/*$(objext) stage3/cobol |
| 377 |
cobol.stage4: stage4-start |
| 378 |
-mv cobol/*$(objext) stage4/cobol |
| 379 |
cobol.stageprofile: stageprofile-start |
| 380 |
-mv cobol/*$(objext) stageprofile/cobol |
| 381 |
cobol.stagefeedback: stagefeedback-start |
| 382 |
-mv cobol/*$(objext) stagefeedback/cobol |
| 383 |
|
| 384 |
selftest-cobol: |
| 385 |
|
| 386 |
lang_checks += check-cobol |
| 387 |
|