File: 0005-Add-manpages-for-commands-automatically.patch

package info (click to toggle)
jsonnet 0.20.0%2Bds-3.1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 16,776 kB
  • sloc: cpp: 23,318; python: 1,788; javascript: 1,003; ansic: 885; sh: 745; makefile: 194; java: 140
file content (111 lines) | stat: -rw-r--r-- 4,063 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
From 0ab274c497d2a91a71654b9c6dc8c2c1fa5c63de Mon Sep 17 00:00:00 2001
From: Fukui Daichi <a.dog.will.talk@akane.waseda.jp>
Date: Sun, 23 Feb 2025 08:46:32 +0000
Subject: [PATCH] Add manpages for commands automatically

---
 CMakeLists.txt | 29 +++++++++++++++++++++++++++++
 Makefile       | 23 ++++++++++++++++++++---
 2 files changed, 49 insertions(+), 3 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 77331f6..861044d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -138,3 +138,31 @@ if (BUILD_TESTS)
 endif()


+# Man pages
+find_program(HELP2MAN_BINARY NAMES help2man)
+if (HELP2MAN_BINARY)
+    message(STATUS "help2man found, man pages will be generated.")
+    file(MAKE_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/man/man1)
+    set(CMAKE_INSTALL_MANDIR "share/man" CACHE STRING "Directory for man pages")
+
+    add_custom_command(
+        OUTPUT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/man/man1/jsonnet.1
+        COMMAND ${HELP2MAN_BINARY}
+        ARGS --section=1 --name="Jsonnet data templating language interpreter" --output=${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/man/man1/jsonnet.1 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/jsonnet
+        DEPENDS jsonnet
+    )
+    add_custom_command(
+        OUTPUT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/man/man1/jsonnetfmt.1
+        COMMAND ${HELP2MAN_BINARY}
+        ARGS --section=1 --name="Jsonnet data templating language interpreter" --output=${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/man/man1/jsonnetfmt.1 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/jsonnetfmt
+        DEPENDS jsonnetfmt
+    )
+
+    add_custom_target(jsonnet-man ALL DEPENDS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/man/man1/jsonnet.1)
+    add_custom_target(jsonnetfmt-man ALL DEPENDS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/man/man1/jsonnetfmt.1)
+
+    install(FILES ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/man/man1/jsonnet.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
+    install(FILES ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/man/man1/jsonnetfmt.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
+else()
+    message(STATUS "help2man not found, man pages will not be generated.")
+endif()
diff --git a/Makefile b/Makefile
index 8c602ef..c74d7b0 100644
--- a/Makefile
+++ b/Makefile
@@ -40,6 +40,11 @@ SHARED_LDFLAGS ?= -shared
 VERSION := $(shell grep '\#define.*LIB_JSONNET_VERSION' include/libjsonnet.h | head -n 1 | cut -f 2 -d '"' | sed 's/^v//g' )
 SOVERSION = 0
 
+# Define the help2man command with appropriate options
+HELP2MAN ?= help2man
+
+MAN1_DIR ?= man/man1
+
 ################################################################################
 # End of user-servicable parts
 ################################################################################
@@ -123,15 +128,17 @@ ifeq ($(shell uname -s),Darwin)
 	SONAME = -install_name
 endif
 
-default: jsonnet jsonnetfmt
+default: jsonnet jsonnetfmt man
 
-install: bins libs
+install: bins libs man
 	mkdir -p $(DESTDIR)$(PREFIX)/bin
 	cp $(BINS) $(DESTDIR)$(PREFIX)/bin/
 	mkdir -p $(DESTDIR)$(PREFIX)/lib
 	cp $(LIBS) $(DESTDIR)$(PREFIX)/lib/
 	mkdir -p $(DESTDIR)$(PREFIX)/include
 	cp $(INCS) $(DESTDIR)$(PREFIX)/include/
+	mkdir -p $(DESTDIR)$(PREFIX)/share/$(MAN1_DIR)
+	install -Dm 644 $(addprefix $(MAN1_DIR)/, $(BINS:=.1)) $(DESTDIR)$(PREFIX)/share/$(MAN1_DIR)/
 
 all: $(ALL)
 
@@ -161,6 +168,16 @@ core/desugarer.cpp: core/std.jsonnet.h
 %.o: %.cpp
 	$(CXX) -c $(CXXFLAGS) $< -o $@
 
+# Target to generate the man page
+
+$(MAN1_DIR)/%.1: % | $(MAN1_DIR)
+	$(HELP2MAN) --output=$@ ./$<
+
+man: $(addprefix $(MAN1_DIR)/, $(BINS:=.1))
+
+$(MAN1_DIR):
+	mkdir -p $@
+
 # Commandline executable.
 jsonnet: cmd/jsonnet.cpp cmd/utils.cpp $(LIB_OBJ)
 	$(CXX) $(CXXFLAGS) $(LDFLAGS) $< cmd/utils.cpp $(LIB_SRC:.cpp=.o) -o $@
@@ -224,7 +241,7 @@ $(RELEASE_FILE): bins
 dist: $(RELEASE_FILE)
 
 clean:
-	rm -rvf */*~ *~ .*~ */.*.swp .*.swp $(ALL) *.o core/*.jsonnet.h Makefile.depend *.so.* build jsonnet.egg-info $(RELEASE_FILE)
+	rm -rvf */*~ *~ .*~ */.*.swp .*.swp $(ALL) *.o core/*.jsonnet.h Makefile.depend *.so.* build jsonnet.egg-info $(RELEASE_FILE) man
 
 -include Makefile.depend
 
-- 
2.47.1