Skip to content

Commit a09c048

Browse files
committed
Quite a few improvements
- Improve project structure - Update LICENSE date - Add --render command - Add MAN page - Add automatic versioning
1 parent 3949c50 commit a09c048

File tree

7 files changed

+263
-105
lines changed

7 files changed

+263
-105
lines changed

src/.astylerc renamed to .astylerc

File renamed without changes.

LICENSE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2014 Arvid Gerstmann
3+
Copyright (c) 2016 Arvid Gerstmann
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1818
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
21+
SOFTWARE.

Makefile

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# General
2+
CC = clang
3+
LD = clang
4+
RM = rm -rf
5+
RMDIR = rmdir
6+
INSTALL = install
7+
DEBUG = -ggdb -O0 -march=native -ftrapv
8+
9+
## CHANGE THIS ##
10+
TARGET = tldr
11+
SRCDIR = src
12+
OBJDIR = obj
13+
BINDIR = .
14+
MANDIR = man
15+
## CHANGE THIS ##
16+
17+
# CFLAGS, LDFLAGS, CPPFLAGS, PREFIX can be overriden on CLI
18+
CFLAGS := $(DEBUG)
19+
CPPFLAGS :=
20+
LDFLAGS :=
21+
PREFIX := /usr/local
22+
TARGET_ARCH :=
23+
24+
25+
# Compiler Flags
26+
ALL_CFLAGS := $(CFLAGS)
27+
ALL_CFLAGS += -Wall -Wextra -pedantic -ansi
28+
ALL_CFLAGS += -fno-strict-aliasing
29+
ALL_CFLAGS += -Wuninitialized -Winit-self -Wfloat-equal
30+
ALL_CFLAGS += -Wundef -Wshadow -Wc++-compat -Wcast-qual -Wcast-align
31+
ALL_CFLAGS += -Wconversion -Wsign-conversion -Wjump-misses-init
32+
ALL_CFLAGS += -Wno-multichar -Wpacked -Wstrict-overflow -Wvla
33+
ALL_CFLAGS += -Wformat -Wno-format-zero-length -Wstrict-prototypes
34+
ALL_CFLAGS += -Wno-unknown-warning-option
35+
36+
# Version Generation
37+
VER := $(shell git describe --tags --always --dirty)
38+
39+
# Preprocessor Flags
40+
ALL_CPPFLAGS := $(CPPFLAGS) -DVERSION='"$(VER)"'
41+
ALL_CPPFLAGS += $(shell pkg-config --cflags libzip)
42+
ALL_CPPFLAGS += -I/usr/include
43+
ALL_CPPFLAGS += -I/usr/local/include
44+
ALL_CPPFLAGS += -I/usr/local/opt/curl/include
45+
ALL_CPPFLAGS += -I/usr/local/opt/libzip/include
46+
47+
# Linker Flags
48+
ALL_LDFLAGS := $(LDFLAGS) -L/usr/lib
49+
ALL_LDFLAGS += -L/usr/local/lib
50+
ALL_LDFLAGS += -L/usr/local/opt/curl/lib
51+
ALL_LDFLAGS += -L/usr/local/opt/libzip/lib
52+
ALL_LDLIBS := -lc -lm -lcurl -lzip
53+
54+
55+
# Source, Binaries, Dependencies
56+
SRC := $(shell find $(SRCDIR) -type f -name '*.c')
57+
OBJ := $(patsubst $(SRCDIR)/%,$(OBJDIR)/%,$(SRC:.c=.o))
58+
DEP := $(OBJ:.o=.d)
59+
BIN := $(BINDIR)/$(TARGET)
60+
-include $(DEP)
61+
62+
# Man Pages
63+
MANSRC := $(shell find $(MANDIR) -type f -name '*.1')
64+
MANPATH := $(PREFIX)/share/man/man1
65+
66+
67+
# Verbosity Control, ala automake
68+
V = 0
69+
70+
# Verbosity for CC
71+
REAL_CC := $(CC)
72+
CC_0 = @echo "CC $<"; $(REAL_CC)
73+
CC_1 = $(REAL_CC)
74+
CC = $(CC_$(V))
75+
76+
# Verbosity for LD
77+
REAL_LD := $(LD)
78+
LD_0 = @echo "LD $@"; $(REAL_LD)
79+
LD_1 = $(REAL_LD)
80+
LD = $(LD_$(V))
81+
82+
# Verbosity for RM
83+
REAL_RM := $(RM)
84+
RM_0 = @echo "Cleaning..."; $(REAL_RM)
85+
RM_1 = $(REAL_RM)
86+
RM = $(RM_$(V))
87+
88+
# Verbosity for RMDIR
89+
REAL_RMDIR := $(RMDIR)
90+
RMDIR_0 = @$(REAL_RMDIR)
91+
RMDIR_1 = $(REAL_RMDIR)
92+
RMDIR = $(RMDIR_$(V))
93+
94+
95+
96+
# Build Rules
97+
.PHONY: clean format
98+
.DEFAULT_GOAL := all
99+
100+
all: setup $(BIN)
101+
setup: dir
102+
remake: clean all
103+
104+
dir:
105+
@mkdir -p $(OBJDIR)
106+
@mkdir -p $(BINDIR)
107+
108+
109+
$(BIN): $(OBJ)
110+
$(LD) $(ALL_LDFLAGS) $^ $(ALL_LDLIBS) -o $@
111+
112+
$(OBJDIR)/%.o: $(SRCDIR)/%.c
113+
$(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) -c -MMD -MP -o $@ $<
114+
115+
116+
install: $(BIN) $(MANSRC)
117+
$(INSTALL) -d $(PREFIX)/bin
118+
$(INSTALL) $(BIN) $(PREFIX)/bin
119+
$(INSTALL) -d $(MANPATH)
120+
$(INSTALL) $(MANSRC) $(MANPATH)
121+
122+
clean:
123+
$(RM) $(OBJ) $(DEP) $(BIN)
124+
$(RMDIR) $(OBJDIR) $(BINDIR) 2> /dev/null; true
125+
126+
format:
127+
astyle --options=.astylerc $(SRCDIR)/*.c
128+

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ To build the latest version from source:
2424
if [[ "`uname`" == "Darwin" ]]; then brew install curl libzip pkg-config; fi
2525
if [[ "`uname`" == "Linux" ]]; then apt-get install libcurl4-openssl-dev libzip-dev pkg-config; fi
2626
git clone https://github.com/tldr-pages/tldr-cpp-client.git tldr-c-client
27-
cd tldr-c-client/src
27+
cd tldr-c-client
2828
make
2929
make install
3030
```
@@ -45,25 +45,27 @@ Building the `tldr` client is pretty straightforward.
4545

4646
#### Compiling
4747

48-
The [`Makefile`](https://github.com/tldr-pages/tldr-cpp-client/blob/master/src/Makefile) in the `src` directory has all you need
49-
for builing the project.
48+
The [`Makefile`](https://github.com/tldr-pages/tldr-cpp-client/blob/master/Makefile)
49+
in the root directory has all you need for builing the project.
50+
51+
Just call `make` and `tldr` will build itself.
5052

5153
```
52-
cd src
5354
make
5455
```
5556

5657
## Usage
5758

5859
```
59-
usage: tldr [-v] [<command>] <search>
60+
usage: ./tldr [-v] [OPTION]... SEARCH
6061
6162
available commands:
6263
-v print verbose output
6364
--version print version and exit
6465
-h, --help print this help and exit
6566
-u, --update update local database
6667
-c, --clear-cache clear local database
67-
-p, --platform=<platform> select platform, supported are linux / osx / common
68+
-p, --platform=PLATFORM select platform, supported are linux / osx / sunos / common
69+
-r, --render=PATH render a local page for testing purposes
6870
```
6971

man/tldr.1

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
.\" Manpage for tldr.
2+
.\" Contact [email protected] to correct errors or typos.
3+
.mso www.tmac
4+
.TH TLDR 1
5+
.SH NAME
6+
tldr \- A collection of simplified and community-driven man pages.
7+
.SH SYNOPSIS
8+
.B tldr
9+
[\fB\-v\fR]
10+
[\fIOPTION\fR]... \fISEARCH\fR
11+
.SH DESCRIPTION
12+
tldr is a collection of simplified and community-driven man pages, for commonly
13+
used commandline tools.
14+
.SH OPTIONS
15+
.TP
16+
.BR \-v
17+
verbose output
18+
.TP
19+
.BR \-\-version
20+
output version information and exit
21+
.TP
22+
.BR \-h ", " \-\-help
23+
display help and exit
24+
.TP
25+
.BR \-u ", " \-\-update
26+
update local database and exit
27+
.TP
28+
.BR \-c ", " \-\-clear-cache
29+
remove local database and exit
30+
.TP
31+
.BR \-p ", " \-\-platform=\fIPLATFORM\fR
32+
select platform, supported are \fIlinux\fR / \fIosx\fR / \fIsunos\fR / \fIcommon\fR
33+
.TP
34+
.BR \-r ", " \-\-render=\fIPATH\fR
35+
render a local page for testing purposes
36+
.SH EXIT STATUS
37+
0 on success, any other positive value otherwise
38+
.SH SEE ALSO
39+
The source is available at:
40+
.URL "https://github.com/tldr-pages/tldr-cpp-client" "" ""
41+
.SH REPORTING BUGS
42+
Report bugs through the Github repository:
43+
.URL "https://github.com/tldr-pages/tldr-cpp-client" "" "."
44+
.SH COPYRIGHT
45+
The MIT License (MIT)
46+
47+
Copyright (c) 2016 Arvid Gerstmann.
48+

src/Makefile

Lines changed: 0 additions & 62 deletions
This file was deleted.

0 commit comments

Comments
 (0)