# Qualify and canonicalize paths.
SOURCES := $$(call QUALIFY_PATH,$${DIR},$${SOURCES})
SOURCES := $$(call CANONICAL_PATH,$${SOURCES})
+ ALL_SRCS += $$(SOURCES)
+
SRC_INCDIRS := $$(call QUALIFY_PATH,$${DIR},$${SRC_INCDIRS})
SRC_INCDIRS := $$(call CANONICAL_PATH,$${SRC_INCDIRS})
--- /dev/null
+#!/usr/bin/env perl
+######################################################################
+#
+# Copyright (C) 2021 Alan DeKok <aland@freeradius.org>
+#
+# $Id$
+#
+######################################################################
+
+use strict;
+use warnings;
+use Data::Dumper;
+
+my %id2name;
+my %name2id;
+
+my %section_id2name;
+my %section_name2id;
+
+my $status = 0;
+
+sub process {
+ my $file = shift;
+ my $name = $file;
+
+ $name =~ s,.*/,,;
+ $name =~ s/libfreeradius-//;
+ $name =~ s/\.mk//;
+
+ open(my $FILE, "<", $file) or die "Failed to open $file: $!\n";
+
+ my $line = 0;
+ while (<$FILE>) {
+ next if ! /LOG_ID/;
+
+ if (/^\s*LOG_ID_LIB/) {
+ my @fields = split /\s+/;
+ my $id = $fields[2];
+
+ if (defined $id2name{$id}) {
+ print STDERR "ID $id is defined in both $id2name{$id} and $name\n";
+ $status = 1;
+ last;
+ }
+
+ if (defined $name2id{$name}) {
+ print STDERR "Library '$name' is defined as two different IDs $name2id{$name} and $id\n";
+ $status = 1;
+ last;
+ }
+
+ $id2name{$id} = $name;
+ $name2id{$name} = $id;
+ next;
+ }
+
+ if (/DEFINE_LOG_ID_SECTION/) {
+ my @fields = split /,/;
+
+ my $section = $fields[1];
+ $section =~ s/\s+//g;
+
+ my $id = $fields[2];
+ $id =~ s/\s+//g;
+
+ if (defined $section_id2name{$name}{$id}) {
+ print STDERR "ID $id is defined in both $section_id2name{$name}{$id} and $name\n";
+ $status = 1;
+ last;
+ }
+
+ if (defined $section_name2id{$name}{$section}) {
+ print STDERR "Library name $name defines '$section' as two different IDs $section_name2id{$name}{$section} and $id\n";
+ $status = 1;
+ last;
+ }
+
+ $section_id2name{$name}{$id} = $section;
+ $section_name2id{$name}{$section} = $id;
+ next;
+ }
+ }
+
+ close $FILE;
+}
+
+foreach my $file (@ARGV) {
+ $file =~ s,//,/,g;
+
+ process($file);
+}
+
+exit $status;
--- /dev/null
+#!/usr/bin/env perl
+######################################################################
+#
+# Copyright (C) 2021 Alan DeKok <aland@freeradius.org>
+#
+# $Id$
+#
+# Updates log IDs
+#
+#
+######################################################################
+
+use strict;
+use warnings;
+use Data::Dumper;
+
+my $status = 0;
+my $max_id;
+my $regex;
+
+sub process {
+ my $file = shift;
+
+ open(my $FILE, "<", $file) or die "Failed to open $file: $!\n";
+ open(my $OUTPUT, ">", "$file.tmp") or die "Failed to create $file.tmp: $!\n";
+
+ while (<$FILE>) {
+ #
+ # Change the various non-ID messages to ID-based messages
+ #
+ # Allow "R" variants of the macros, and DEBUG(2,3,4)
+ #
+ if (s/^(\s*R?(DEBUG|P?ERROR|INFO)[0-9]?)\((\s*0\s*,)?/${1}_ID\(\@/g) {
+ s/_ID\(\@/\($max_id, /;
+ $max_id++;
+ }
+
+ print $OUTPUT $_;
+ }
+
+ close $FILE;
+ close $OUTPUT;
+
+ rename "$file.tmp", $file;
+}
+
+sub read_max_id {
+ my $file = shift;
+
+ open(my $FILE, "<", $file) or die "Failed opening $file";
+ while (<$FILE>) {
+ next if /\s*#/;
+
+ /(\d+)/; # get digits
+
+ $max_id = $1;
+ last;
+ }
+
+ close $FILE;
+}
+
+sub write_max_id {
+ my $file = shift;
+
+ open(my $FILE, "<", $file) or die "Failed opening $file";
+ open(my $OUTPUT, ">", "$file.tmp") or die "Failed opening $file.tmp";
+
+ while (<$FILE>) {
+ if (/\s*#/) {
+ print $OUTPUT $_;
+ next;
+ }
+
+ s/(\d+)/$max_id/;
+ print $OUTPUT $_;
+ last;
+ }
+
+ close $FILE;
+ close $OUTPUT;
+
+ rename "$file.tmp", $file;
+}
+
+read_max_id("scripts/build/max_id.txt");
+
+foreach my $file (@ARGV) {
+ $file =~ s,//,/,g;
+
+ next if $file !~ /\.[ch]$/;
+
+ process($file);
+}
+
+write_max_id("scripts/build/max_id.txt") if ($status == 0);
+
+exit $status;
--- /dev/null
+.PHONY: logid.help
+logid.help:
+ @echo ""
+ @echo "Make targets:"
+ @echo " logid.check - check and verify log IDs"
+ @echo " logid.update - update log IDs"
+
+LOGID_FILES := $(shell grep -l LOG_ID ${ALL_MAKEFILES})
+
+logid.check: $(LOGID_FILES)
+ @./scripts/build/logid-check.pl $^
+
+logid.update: $(ALL_SRCS)
+ @./scripts/build/logid-update.pl $^