Skip to content

Commit

Permalink
Enhance: update README & workflows
Browse files Browse the repository at this point in the history
* Update README: add install, usage, and example sections.
* Update Makefile: static link on macOS.
* Update workflows: add x86_64 & arm64 macOS.
  • Loading branch information
redraiment committed Aug 15, 2024
1 parent d24fe9b commit 60ac539
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 24 deletions.
19 changes: 13 additions & 6 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
fail-fast: false
matrix:
build: [linux-gnu, linux-musl, macos]
build: [linux-gnu, linux-musl, macos-arm64, macos-x86_64]
include:
- BUILD: linux-gnu
OS: ubuntu-latest
Expand All @@ -24,9 +24,14 @@ jobs:
TOOLCHAIN: stable
TARGET: x86_64-unknown-linux-musl

- BUILD: macos
- BUILD: macos-arm64
OS: macos-latest
TOOLCHAIN: stable
TARGET: arm64-apple-darwin

- BUILD: macos-x86_64
OS: macos-13
TOOLCHAIN: stable
TARGET: x86_64-apple-darwin

steps:
Expand All @@ -39,17 +44,19 @@ jobs:
shell: bash
run: echo "RELEASE_VERSION=${GITHUB_REF:11}" >> $GITHUB_ENV

- name: Install libraries
- name: Install Linux libraries
if: matrix.TARGET == 'x86_64-unknown-linux-gnu' || matrix.TARGET == 'x86_64-unknown-linux-musl'
run: |
sudo apt-get update
sudo apt-get install --no-install-recommends -y pkg-config libpng-dev libjpeg-dev
sudo apt-get install --no-install-recommends -y \
pkg-config libpng-dev libjpeg-dev
- name: Install musl-tools
- name: Install Linux musl-tools
if: matrix.TARGET == 'x86_64-unknown-linux-musl'
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends --allow-unauthenticated musl-tools
sudo apt-get install -y --no-install-recommends \
--allow-unauthenticated musl-tools
- name: Build
run: make
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ on:
branches: [ "main" ]

jobs:
linux:
name: Linux Release
Linux:
name: Linux
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -17,11 +17,12 @@ jobs:
- name: prepare
run: |
sudo apt-get update
sudo apt-get install --no-install-recommends -y pkg-config libpng-dev libjpeg-dev
sudo apt-get install --no-install-recommends -y \
pkg-config libpng-dev libjpeg-dev
- name: make
run: make
MacOS:
name: MacOS Release
name: MacOS
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
Expand Down
16 changes: 8 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ endif

CC ?= gcc
PREFIX ?= /usr/local
CFLAGS ?=
LIBS ?=

QUIRC = quirc/lib
OBJS = \
Expand All @@ -33,22 +31,24 @@ OBJS = \
src/jpg_reader.o
TARGET = qrscan

OS := $(shell uname -s)
ifeq ($(OS),Darwin)
CFLAGS += -I$(QUIRC) $(shell $(PKG_CONFIG) --cflags --static libpng libjpeg)
LDFLAGS += -lz -lm
ifeq ($(shell uname -s),Darwin)
GROUP = staff
LDFLAGS =
LDFLAGS += $(shell $(PKG_CONFIG) --variable=libdir --static libpng)/libpng.a
LDFLAGS += $(shell $(PKG_CONFIG) --variable=libdir --static libjpeg)/libjpeg.a
else
GROUP = root
LDFLAGS = -static
LDFLAGS += -static $(shell $(PKG_CONFIG) --libs --static libpng libjpeg)
endif

.PHONY: all install uninstall clean

all: $(OBJS)
$(CC) $^ $(LIBS) $(LDFLAGS) $(shell $(PKG_CONFIG) --libs --static libpng libjpeg) -lm -O2 -Wall -fPIC -o $(TARGET)
$(CC) $^ $(LDFLAGS) -O2 -Wall -fPIC -o $(TARGET)

.c.o:
$(CC) $< $(CFLAGS) $(shell $(PKG_CONFIG) --cflags --static libpng libjpeg) -c -I$(QUIRC) -o $@
$(CC) $< $(CFLAGS) -c -o $@

install: all
install -o root -g $(GROUP) -m 0755 $(TARGET) $(PREFIX)/bin
Expand Down
70 changes: 64 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,85 @@
qrscan
====

Scan a QR code in the terminal using a given image.
![Continuous Integration](https://github.com/redraiment/qrcode/actions/workflows/ci.yml/badge.svg) ![Continuous Deployment](https://github.com/redraiment/qrcode/actions/workflows/cd.yml/badge.svg)

Scan a QR code in the terminal using a given (PNG or JPEG) image.

## Install

### Pre-built binaries (Recommends)

Download the appropriate binary from the [latest release](https://github.com/redraiment/qrscan/releases/latest).

### Build on Debian/Ubuntu Linux

This requires pkg-config, libpng, and libjpeg.

```sh
sudo apt install --no-install-recommends -y pkg-config libpng-dev libjpeg-dev
git clone --recurse-submodules https://github.com/redraiment/qrscan.git
cd qrscan
make
sudo make install
```

This requires: pkg-config, libpng, libjpeg.
### Build on MacOS

This requires pkg-config, libpng, and libjpeg.

```sh
brew install pkg-config libpng libjpeg
git clone --recurse-submodules https://github.com/redraiment/qrscan.git
cd qrscan
make
sudo make install
```

## Usage

Scan a given image file (possible format: png, jpg)
`qrscan [OPTIONS] [PNG|JPG|-]`

### Image Options

* `--png`, `--jpg`: the format of the input file, inferred from the extension by default.
* `-c`, `--count`: suppress normal output, instead print a count of QR-Code.
* `-n NUM`, `--index NUM`: Output the NUM QR-Code value only.

### Other Options

* `-v`, `--version`: show the version and exit.
* `-h`, `--help`: show help message and exit.

## Examples

1) Read from image file:

```sh
qrscan image.png
```

2) Read from stdin:

```sh
cat image.jpg | qrscan --jpg -
```

3) Count QR-Code in image:

```sh
qrscan path/to/file
qrscan -c image.png
```

# Or read from stdin
4) Read the second QR-Code in image:

cat path/to/file | qrscan -
```sh
qrscan -2 image.png
# Or
qrscan -n 2 image.png
```

# License

`qrscan` is open-source software, released under the MIT License.

Feel free to explore, learn, and extend to suit your needs.

0 comments on commit 60ac539

Please sign in to comment.