diff --git a/.github/workflows/windows-msvc.yml b/.github/workflows/windows-msvc.yml
index b748e62d6..134e7f18c 100644
--- a/.github/workflows/windows-msvc.yml
+++ b/.github/workflows/windows-msvc.yml
@@ -204,7 +204,6 @@ jobs:
- name: Upload testsuite-${{ matrix.arch }}-${{ matrix.target }}.log
uses: actions/upload-artifact@v4
- if: failure()
with:
name: testsuite-${{ matrix.arch }}-${{ matrix.target }}.log
path: ${{ env.GITHUB_WORKSPACE }}/tests/testsuite.log
diff --git a/.github/workflows/windows-msys1.yml b/.github/workflows/windows-msys1.yml
index 67f3801c6..661344910 100644
--- a/.github/workflows/windows-msys1.yml
+++ b/.github/workflows/windows-msys1.yml
@@ -229,7 +229,6 @@ jobs:
- name: Upload testsuite-${{ matrix.target }}.log
uses: actions/upload-artifact@v4
- if: failure()
with:
name: testsuite-${{ matrix.target }}.log
path: ${{ env.GITHUB_WORKSPACE }}/_build/tests/testsuite.log
diff --git a/.github/workflows/windows-msys2.yml b/.github/workflows/windows-msys2.yml
index 59ba117b5..f2b5c13e9 100644
--- a/.github/workflows/windows-msys2.yml
+++ b/.github/workflows/windows-msys2.yml
@@ -102,7 +102,6 @@ jobs:
- name: Upload testsuite-${{matrix.sys}}-${{matrix.target}}.log
uses: actions/upload-artifact@v4
- if: failure()
with:
name: testsuite-${{matrix.sys}}-${{matrix.target}}.log
path: ${{ env.GITHUB_WORKSPACE }}/_build/tests/testsuite.log
diff --git a/cobc/cobc.c b/cobc/cobc.c
index 36e2a6f65..5a1bedbe1 100644
--- a/cobc/cobc.c
+++ b/cobc/cobc.c
@@ -255,11 +255,12 @@ FILE *cb_storage_file = NULL;
FILE *cb_listing_file = NULL;
FILE *cb_depend_file = NULL;
const char *cb_ebcdic_table = NULL;
-int cb_depend_output = 0;
-int cb_depend_output_only = 0;
-int cb_depend_add_phony = 0;
-int cb_depend_keep_missing = 0;
-int cb_depend_target_auto = 0;
+int cb_depend_output = 0;
+int cb_depend_output_only = 0;
+int cb_depend_add_phony = 0;
+int cb_depend_keep_missing = 0;
+int cb_depend_target_auto = 0;
+int cb_flag_copybook_deps = 0;
/* set by option -fttitle=
*/
char *cb_listing_with_title = NULL;
@@ -632,6 +633,7 @@ static const struct option long_options[] = {
{"MP", CB_NO_ARG, NULL, CB_FLAG_GETOPT_DEPEND_ADD_PHONY},
{"MG", CB_NO_ARG, NULL, CB_FLAG_GETOPT_DEPEND_KEEP_MISSING},
{"MD", CB_NO_ARG, NULL, CB_FLAG_GETOPT_DEPEND_ON_THE_SIDE},
+ {"fcopybook-deps", CB_NO_ARG, &cb_flag_copybook_deps, 1},
{"coverage", CB_NO_ARG, &cb_coverage_enabled, 1},
{"P", CB_OP_ARG, NULL, 'P'},
{"Xref", CB_NO_ARG, NULL, 'X'},
@@ -3019,7 +3021,7 @@ remove_trailing_slash (char *data)
}
}
-static int
+static COB_INLINE COB_A_INLINE int
string_is_dash (const char *s)
{
return (strcmp (s, COB_DASH) == 0);
@@ -3036,33 +3038,33 @@ add_depend_target (const char *s)
const size_t new_len = strlen (s);
const size_t buff_len = orig_len + 1 + new_len + 1;
cb_depend_target = cobc_realloc (cb_depend_target, buff_len);
- memset (cb_depend_target + orig_len, ' ', 1);
+ *(cb_depend_target + orig_len) = ' ';
memcpy (cb_depend_target + orig_len + 1, s, new_len);
- memset (cb_depend_target + orig_len + 1 + new_len, 0, 1);
+ *(cb_depend_target + orig_len + 1 + new_len) = '\0';
}
}
static void
add_depend_escape_target (const char *s)
{
- int i, len, nchars;
- len = strlen (s);
- nchars = 0;
- for (i=0; i0; i--){
- char c = file[i];
- if (c == '.'){
- int newlen = i+extlen+1;
- char* new_file = cobc_malloc(newlen);
+ const int len = strlen (file);
+ const int extlen = strlen (ext);
+ for (i=len; i>0; i--) {
+ const char c = file[i];
+ if (c == '.') {
+ const int newlen = i+extlen+1;
+ char *new_file = cobc_malloc(newlen);
memcpy (new_file, file, i);
memcpy (new_file+i, ext, extlen+1);
return new_file;
}
- if (c == '/') break;
+ if (c == '/') {
+ break;
+ }
}
return cobc_main_stradd_dup (file, ext);
}
@@ -4150,7 +4154,7 @@ process_command_line (const int argc, char **argv)
}
}
- if (cb_flag_copybook_deps){
+ if (cb_flag_copybook_deps) {
/* same as -M, but only COPYBOOK names */
cb_depend_output = 1;
cb_depend_output_only = 1;
@@ -4159,11 +4163,11 @@ process_command_line (const int argc, char **argv)
cb_compile_level = CB_LEVEL_PREPROCESS;
}
if (!cb_depend_output &&
- ( cb_depend_filename || cb_depend_add_phony || cb_depend_target
- || cb_depend_keep_missing) ){
+ (cb_depend_filename || cb_depend_add_phony || cb_depend_target
+ || cb_depend_keep_missing)) {
cobc_err_exit ("dependency options require -M or -MD");
}
- if (cb_depend_output_only && cb_compile_level != CB_LEVEL_PREPROCESS){
+ if (cb_depend_output_only && cb_compile_level != CB_LEVEL_PREPROCESS) {
cobc_err_exit ("-M is compatible only with -E. Use -MD instead.");
}
@@ -4221,21 +4225,21 @@ process_command_line (const int argc, char **argv)
}
#endif
- if (cb_depend_target_auto){
- if (!cb_depend_filename){
- if (output_name){
+ if (cb_depend_target_auto) {
+ if (!cb_depend_filename) {
+ if (output_name) {
cb_depend_filename =
file_replace_extension (output_name, ".d");
}
}
}
- if (cb_depend_output_only){
- if (cb_depend_filename){
- if (output_name){
+ if (cb_depend_output_only) {
+ if (cb_depend_filename) {
+ if (output_name) {
cb_depend_output_only = 0;
}
} else {
- if (output_name){
+ if (output_name) {
cb_depend_filename = output_name;
output_name = NULL;
} else
@@ -4252,8 +4256,8 @@ process_command_line (const int argc, char **argv)
cobc_main_free (output_name_buff);
}
- if (cb_depend_filename){
- if (string_is_dash(cb_depend_filename)){
+ if (cb_depend_filename) {
+ if (string_is_dash(cb_depend_filename)) {
cb_depend_file = stdout;
} else {
cb_depend_file = fopen (cb_depend_filename, "w");
@@ -4485,7 +4489,7 @@ process_filename (const char *filename)
char *full_path;
#endif
- if ( string_is_dash (filename) ) {
+ if (string_is_dash (filename)) {
if (cobc_seen_stdin == 0) {
cobc_seen_stdin = 1;
file_is_stdin = 1;
@@ -5327,8 +5331,7 @@ preprocess (struct filename *fn)
if (output_name
|| cb_compile_level > CB_LEVEL_PREPROCESS
- || cb_depend_output_only
- ) {
+ || cb_depend_output_only) {
if (cb_unix_lf) {
ppout = fopen(fn->preprocess, "wb");
} else {
@@ -9288,13 +9291,15 @@ process_file (struct filename *fn, int status)
cobc_set_listing_header_code ();
}
- if (cb_depend_output){
+ if (cb_depend_output) {
struct cb_text_list *l;
- const char* sep = " \\\n";
+ const char *sep = " \\\n";
FILE *file = NULL;
- if (cb_flag_copybook_deps) sep = "";
- if (cb_depend_file){
+ if (cb_flag_copybook_deps) {
+ sep = "";
+ }
+ if (cb_depend_file) {
file = cb_depend_file;
} else {
const char *basename = file_basename (fn->source, NULL);
@@ -9302,7 +9307,7 @@ process_file (struct filename *fn, int status)
file = fopen (d_name, "w");
}
- if (cb_depend_target){
+ if (cb_depend_target) {
fprintf (file, "%s:%s", cb_depend_target, sep);
} else {
const char *basename = file_basename (fn->source, NULL);
@@ -9314,12 +9319,12 @@ process_file (struct filename *fn, int status)
fprintf (file, " %s%s", l->text, l->next ? sep : "\n\n");
}
/* These lines should only be added with -MP */
- if (cb_depend_add_phony){
+ if (cb_depend_add_phony) {
for (l = cb_depend_list; l; l = l->next) {
fprintf (file, "%s:\n", l->text);
}
}
- if (!cb_depend_file){
+ if (!cb_depend_file) {
fclose (file);
}
@@ -9601,7 +9606,7 @@ main (int argc, char **argv)
}
/* Output dependency list */
- if (cb_depend_file && cb_depend_file != stdout){
+ if (cb_depend_file && cb_depend_file != stdout) {
fclose (cb_depend_file);
}
diff --git a/cobc/cobc.h b/cobc/cobc.h
index 237c92124..2c1bcf2ca 100644
--- a/cobc/cobc.h
+++ b/cobc/cobc.h
@@ -473,9 +473,9 @@ extern int cb_saveargc;
extern FILE *cb_listing_file;
extern FILE *cb_src_list_file;
extern FILE *cb_depend_file;
-extern int cb_depend_output;
-extern int cb_depend_keep_missing;
-extern int cb_depend_keep_system;
+extern int cb_depend_output;
+extern int cb_depend_keep_missing;
+extern int cb_flag_copybook_deps;
extern struct cb_text_list *cb_depend_list;
extern struct cb_text_list *cb_copy_list;
extern struct cb_text_list *cb_include_file_list;
diff --git a/cobc/flag.def b/cobc/flag.def
index ec2d60719..17271b4b9 100644
--- a/cobc/flag.def
+++ b/cobc/flag.def
@@ -149,9 +149,6 @@ CB_FLAG (cb_flag_stack_extended, 1, "stack-extended",
CB_FLAG_ON (cb_flag_fast_compare, 0, "fast-compare",
_(" -fno-fast-compare disables inline comparisions"))
-CB_FLAG (cb_flag_copybook_deps, 0, "copybook-deps",
- _(" -fcopybook-deps output copybook names as dependencies"))
-
/* Normal flags */
CB_FLAG_ON (cb_flag_remove_unreachable, 1, "remove-unreachable",
diff --git a/cobc/help.c b/cobc/help.c
index a2278ef5f..53077416f 100644
--- a/cobc/help.c
+++ b/cobc/help.c
@@ -143,6 +143,7 @@ cobc_print_usage_common_options (void)
puts (_(" -MG output missing dependencies without complaining"));
puts (_(" -MD output dependencies in .d files while compiling"));
puts (_(" -ext add file extension for resolving COPY"));
+ puts (_(" -fcopybook-deps output copybook names as dependencies"));
putchar ('\n');
}
diff --git a/cobc/pplex.l b/cobc/pplex.l
index 7a0a670e2..a0276ec82 100644
--- a/cobc/pplex.l
+++ b/cobc/pplex.l
@@ -159,7 +159,6 @@ static int fill_continued_alnums = 1; /* whether continued alphanumeric
spaces up to text column */
static int emit_area_a_tokens = 0;
-
static char display_msg[PPLEX_BUFF_LEN];
static struct copy_info *copy_stack = NULL;
@@ -1655,20 +1654,6 @@ ppcopy (const char *name, const char *lib, struct cb_replace_list *replace_list)
plexbuff1 = cobc_malloc ((size_t)COB_SMALL_BUFF);
}
- if (cb_depend_output && cb_flag_copybook_deps){
-
- if (lib) {
- snprintf (plexbuff1, (size_t)COB_SMALL_MAX, "%s%c%s",
- lib, SLASH_CHAR, name);
- plexbuff1[COB_SMALL_MAX] = 0;
- } else {
- strcpy (plexbuff1, name);
- }
- cb_depend_list =
- pp_text_list_add (cb_depend_list, plexbuff1,
- strlen (plexbuff1));
- }
-
/* TODO: open with path relative to the current file's path,
if any (applies both to with and without "lib") */
@@ -1731,6 +1716,12 @@ ppcopy (const char *name, const char *lib, struct cb_replace_list *replace_list)
filename = cb_copy_find_file (plexbuff1, has_ext);
}
+ if (cb_depend_output && cb_flag_copybook_deps) {
+ cb_depend_list =
+ pp_text_list_add (cb_depend_list, filename,
+ strlen (filename));
+ }
+
/* expected case: filename found */
if (likely (filename)) {
if (ppopen (filename, replace_list) == 0) {
@@ -2821,6 +2812,12 @@ pp_text_list_add (struct cb_text_list *list, const char *text,
struct cb_text_list *p;
void *tp;
+ for (p = list; p; p = p->next) {
+ if (!strncmp(text, p->text, size + 1)) {
+ return list;
+ }
+ }
+
p = cobc_plex_malloc (sizeof (struct cb_text_list));
tp = cobc_plex_malloc (size + 1);
memcpy (tp, text, size);
diff --git a/tests/testsuite.src/used_binaries.at b/tests/testsuite.src/used_binaries.at
index 1862b07a9..ac4782a0b 100644
--- a/tests/testsuite.src/used_binaries.at
+++ b/tests/testsuite.src/used_binaries.at
@@ -1151,63 +1151,69 @@ AT_CLEANUP
AT_SETUP([output dependencies])
+# AT_KEYWORDS([])
AT_CAPTURE_FILE([compiler.output])
-# AT_KEYWORDS([])
+
AT_DATA([prog.cob], [
- IDENTIFICATION DIVISION.
- PROGRAM-ID. prog.
- DATA DIVISION.
- WORKING-STORAGE SECTION.
- COPY COPY1.
- PROCEDURE DIVISION.
- MAIN-PROC SECTION.
- 00.
- COPY COPY2.
- END-PROC SECTION.
- COPY COPY3 in "sub".
- EX.
- STOP RUN.
+ IDENTIFICATION DIVISION.
+ PROGRAM-ID. prog.
+ DATA DIVISION.
+ WORKING-STORAGE SECTION.
+ COPY COPY1.
+ PROCEDURE DIVISION.
+ MAIN-PROC SECTION.
+ 00.
+ COPY COPY3.
+ COPY COPY3.CPY.
+ END-PROC SECTION.
+ COPY COPY4 in "sub".
+ EX.
+ STOP RUN.
])
AT_CHECK([mkdir -p sub])
-AT_DATA([COPY1.CPY], [])
-AT_DATA([COPY2.CPY], [ DISPLAY "Hello".
+AT_DATA([COPY1.CPY], [ COPY COPY2.
+])
+AT_DATA([COPY2.CPY], [])
+AT_DATA([COPY3.CPY], [ DISPLAY "Hello".
])
-AT_DATA([sub/COPY3.CPY], [])
+AT_DATA([sub/COPY4.CPY], [])
-AT_CHECK([$COMPILE_ONLY prog.cob])
+AT_CHECK([$COMPILE prog.cob])
-AT_CHECK([$COMPILE_ONLY -M prog.cob prog.cob > compiler.output], [0])
+AT_CHECK([$COMPILE -M prog.cob prog.cob > compiler.output], [0])
AT_CHECK([$SED "s/prog.$COB_OBJECT_EXT/prog.COB_OBJECT_EXT/g;s/sub\\\\/sub\//g" compiler.output], [0],
[prog.COB_OBJECT_EXT: \
prog.cob \
COPY1.CPY \
COPY2.CPY \
- sub/COPY3.CPY
+ COPY3.CPY \
+ sub/COPY4.CPY
prog.COB_OBJECT_EXT: \
prog.cob \
COPY1.CPY \
COPY2.CPY \
- sub/COPY3.CPY
+ COPY3.CPY \
+ sub/COPY4.CPY
])
-AT_CHECK([$COMPILE_ONLY -M -MF prog.dep prog.cob])
-
+AT_CHECK([$COMPILE -M -MF prog.dep prog.cob])
AT_CHECK([$SED "s/prog.$COB_OBJECT_EXT/prog.COB_OBJECT_EXT/g;s/sub\\\\/sub\//g" prog.dep], [0],
[prog.COB_OBJECT_EXT: \
prog.cob \
COPY1.CPY \
COPY2.CPY \
- sub/COPY3.CPY
+ COPY3.CPY \
+ sub/COPY4.CPY
])
-AT_CHECK([$COMPILE_ONLY -M -fcopybook-deps prog.cob > compiler.output], [0])
+AT_CHECK([$COMPILE -M -fcopybook-deps prog.cob > compiler.output], [0])
AT_CHECK([$SED "s/prog.$COB_OBJECT_EXT/prog.COB_OBJECT_EXT/g;s/sub\\\\/sub\//g" compiler.output], [0],
-[prog.COB_OBJECT_EXT: COPY1 COPY2 sub/COPY3
+[prog.COB_OBJECT_EXT: COPY1.CPY COPY2.CPY COPY3.CPY sub/COPY4.CPY
])
@@ -1217,20 +1223,22 @@ AT_CHECK([$SED "s/prog.$COB_MODULE_EXT/prog.COB_MODULE_EXT/g;s/sub\\\\/sub\//g"
prog.cob \
COPY1.CPY \
COPY2.CPY \
- sub/COPY3.CPY
+ COPY3.CPY \
+ sub/COPY4.CPY
])
AT_CHECK([test -f prog.c], [1])
AT_CHECK([test -f prog.o], [1])
-AT_CHECK([$COMPILE_ONLY -M -MQ '$(target)#toto' prog.cob > compiler.output], [0])
+AT_CHECK([$COMPILE -M -MQ '$(target)#toto' prog.cob > compiler.output], [0])
AT_CHECK([$SED "s/sub\\\\/sub\//g" compiler.output], [0],
[$$(target)\#toto: \
prog.cob \
COPY1.CPY \
COPY2.CPY \
- sub/COPY3.CPY
+ COPY3.CPY \
+ sub/COPY4.CPY
])
@@ -1238,43 +1246,42 @@ AT_CHECK([rm -f prog.d])
AT_CAPTURE_FILE([prog.d])
AT_CHECK([$COMPILE -MD prog.cob])
-
AT_CHECK([$SED "s/prog.$COB_OBJECT_EXT/prog.COB_OBJECT_EXT/g;s/sub\\\\/sub\//g" prog.d], [0],
[prog.COB_OBJECT_EXT: \
prog.cob \
COPY1.CPY \
COPY2.CPY \
- sub/COPY3.CPY
+ COPY3.CPY \
+ sub/COPY4.CPY
])
AT_CHECK([$COMPILE -MD -o sub/prog.exe prog.cob])
-
AT_CHECK([test -f sub/prog.exe])
-
AT_CHECK([$SED "s/prog.$COB_OBJECT_EXT/prog.COB_OBJECT_EXT/g;s/sub\\\\/sub\//g" sub/prog.d], [0],
[prog.COB_OBJECT_EXT: \
prog.cob \
COPY1.CPY \
COPY2.CPY \
- sub/COPY3.CPY
+ COPY3.CPY \
+ sub/COPY4.CPY
])
-AT_CHECK([rm sub/COPY3.CPY])
-
-AT_CHECK([$COMPILE_ONLY -M prog.cob > compiler.output 2> compiler.error], [1], [], [])
+AT_CHECK([rm sub/COPY4.CPY])
+AT_CHECK([$COMPILE -M prog.cob > compiler.output 2> compiler.error], [1], [], [])
AT_CHECK([$SED "s/prog.$COB_OBJECT_EXT/prog.COB_OBJECT_EXT/g" compiler.output], [0],
[prog.COB_OBJECT_EXT: \
prog.cob \
COPY1.CPY \
- COPY2.CPY
+ COPY2.CPY \
+ COPY3.CPY
])
AT_CHECK([$SED "s/sub\\\\/sub\//g" compiler.error], [0],
-[prog.cob:12: error: sub/COPY3: No such file or directory
+[prog.cob:13: error: sub/COPY4: No such file or directory
])
AT_CHECK([$COMPILE_ONLY -M -MG prog.cob > compiler.output], [0])
@@ -1283,9 +1290,11 @@ AT_CHECK([$SED "s/prog.$COB_OBJECT_EXT/prog.COB_OBJECT_EXT/g;s/sub\\\\/sub\//g"
prog.cob \
COPY1.CPY \
COPY2.CPY \
- sub/COPY3.CPY
+ COPY3.CPY \
+ sub/COPY4.CPY
])
+
AT_DATA([prog.cob], [
IDENTIFICATION DIVISION.
PROGRAM-ID. prog.