From cb4fea2e01e6923a016fdc57c48ee9d4045d8428 Mon Sep 17 00:00:00 2001
From: Luke Shumaker <lukeshu@lukeshu.com>
Date: Mon, 15 May 2017 19:09:00 -0400
Subject: sd_messages: fix

---
 sd_messages/Makefile        |  2 +-
 sd_messages/messages.go.gen | 48 +++++++++++++++++++++++++++++++++------------
 2 files changed, 36 insertions(+), 14 deletions(-)

(limited to 'sd_messages')

diff --git a/sd_messages/Makefile b/sd_messages/Makefile
index 512d27c..4cf4640 100644
--- a/sd_messages/Makefile
+++ b/sd_messages/Makefile
@@ -27,7 +27,7 @@ SD_MESSAGES_H ?= /usr/include/systemd/sd-messages.h
 files.src.gen += messages.go
 
 $(srcdir)/messages.go: $(srcdir)/messages.go.gen $(SD_MESSAGES_H)
-	cd $(@D) && ./$(<F) $(SD_MESSAGES_H) | gofmt > $(@F)
+	cd $(@D) && ./$(<F) $(SD_MESSAGES_H) > $(@F)
 
 # footer
 ifneq ($(topsrcdir),)
diff --git a/sd_messages/messages.go.gen b/sd_messages/messages.go.gen
index 423829b..3314df3 100755
--- a/sd_messages/messages.go.gen
+++ b/sd_messages/messages.go.gen
@@ -1,17 +1,39 @@
-#!/usr/bin/sed -rnf
-1apackage foo
-1aconst (
-/^#define\s+SD_MESSAGE_/ {
+#!/usr/bin/env bash
+# Copyright (C) 2017 Luke Shumaker <lukeshu@sbcglobal.net>
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
 
-	s/^#define\s+SD_MESSAGE_(\S*)/\1 =/
+{
+	printf '//'
+	printf ' %q' "$0" "$@"
+	printf '\n// MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT\n\n'
+	sed -rn '
+		1apackage sd_messages
+		1aimport "git.lukeshu.com/go/libsystemd/sd_id128"
+		1avar (
+		/^#define\s+SD_MESSAGE_/ {
 
-	s/SD_ID128_MAKE\(/ID128{0x/
-	s/,/,0x/g
-	s/\)/}/
+			s/^#define\s+SD_MESSAGE_(\S*)/\1 =/
 
-	s/(^|_)([A-Z])([A-Z]*)/\U\2\L\3/g
+			s/SD_ID128_MAKE\(/sd_id128.ID128{0x/
+			s/,/,0x/g
+			s/\)/}/
 
-	p
-}
-/^$/p
-$a)
+			s/(^|_)([A-Z])([A-Z]*)/\U\2\L\3/g
+
+			p
+		}
+		/^$/p
+		$a)
+		' "$@"
+} | gofmt
-- 
cgit v1.2.3-2-g168b