WIP: Generate Rust sysexits bindings without bindgen #129
30
Makefile
30
Makefile
|
@ -18,21 +18,17 @@ PREFIX ?= /usr/local
|
||||||
|
|
||||||
MANDIR != [ $(PREFIX) = / ] && printf '/usr/share/man\n' \
|
MANDIR != [ $(PREFIX) = / ] && printf '/usr/share/man\n' \
|
||||||
|| printf '/share/man\n'
|
|| printf '/share/man\n'
|
||||||
SYSEXITS != printf '\043include <sysexits.h>\n' | cpp -M - | sed 's/ /\n/g' \
|
|
||||||
| sed -n 's/sysexits\.h//p' || printf 'include\n'
|
|
||||||
|
|
||||||
CC ?= cc
|
CC ?= cc
|
||||||
RUSTC ?= rustc
|
RUSTC ?= rustc
|
||||||
RUSTLIBS = --extern getopt=build/o/libgetopt.rlib \
|
RUSTLIBS = --extern getopt=build/o/libgetopt.rlib \
|
||||||
--extern sysexits=build/o/libsysexits.rlib \
|
--extern sysexits=build/o/libsysexits.rlib \
|
||||||
--extern strerror=build/o/libstrerror.rlib
|
--extern strerror=build/o/libstrerror.rlib
|
||||||
CFLAGS += -I$(SYSEXITS)
|
CFLAGS += -Ibuild/include
|
||||||
|
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
all: docs dj false fop hru intcmp mm npc rpn scrut str strcmp swab true
|
all: docs dj false fop hru intcmp mm npc rpn scrut str strcmp swab true
|
||||||
|
|
||||||
# keep build/include until bindgen(1) has stdin support
|
|
||||||
# https://github.com/rust-lang/rust-bindgen/issues/2703
|
|
||||||
build:
|
build:
|
||||||
mkdir -p build/bin build/docs build/include build/lib build/o build/test
|
mkdir -p build/bin build/docs build/include build/lib build/o build/test
|
||||||
|
|
||||||
|
@ -65,6 +61,12 @@ docs: docs/ build
|
||||||
rustlibs: build/o/libsysexits.rlib build/o/libgetopt.rlib \
|
rustlibs: build/o/libsysexits.rlib build/o/libgetopt.rlib \
|
||||||
build/o/libstrerror.rlib
|
build/o/libstrerror.rlib
|
||||||
|
|
||||||
|
build/include/sysexits.h: build include/sysexits.h.template
|
||||||
|
cpp -dM -include sysexits.h /dev/null \
|
||||||
|
| grep '^.define EX_' >$@ \
|
||||||
|
|| cpp -dM -include stdlib.h include/sysexits.h.template \
|
||||||
|
| grep -e '^.define EX_' -e '^.define EXIT_' >$@
|
||||||
|
|
||||||
build/o/libgetopt.rlib: build src/getopt-rs/lib.rs
|
build/o/libgetopt.rlib: build src/getopt-rs/lib.rs
|
||||||
$(RUSTC) $(RUSTFLAGS) --crate-type=lib --crate-name=getopt \
|
$(RUSTC) $(RUSTFLAGS) --crate-type=lib --crate-name=getopt \
|
||||||
-o $@ src/getopt-rs/lib.rs
|
-o $@ src/getopt-rs/lib.rs
|
||||||
|
@ -73,12 +75,10 @@ build/o/libstrerror.rlib: build src/strerror.rs
|
||||||
$(RUSTC) $(RUSTFLAGS) --crate-type=lib -o $@ \
|
$(RUSTC) $(RUSTFLAGS) --crate-type=lib -o $@ \
|
||||||
src/strerror.rs
|
src/strerror.rs
|
||||||
|
|
||||||
# bandage solution until bindgen(1) gets stdin support
|
build/o/libsysexits.rlib: build build/include/sysexits.h
|
||||||
build/o/libsysexits.rlib: build $(SYSEXITS)sysexits.h
|
<build/include/sysexits.h \
|
||||||
printf '\043define EXIT_FAILURE 1\n' | cat - $(SYSEXITS)sysexits.h \
|
awk '{ print "pub const " $$2 ": i32 = " $$3 ";"; }' \
|
||||||
> build/include/sysexits.h
|
| $(RUSTC) $(RUSTFLAGS) --crate-type lib -o $@ -
|
||||||
bindgen --default-macro-constant-type signed --use-core --formatter=none \
|
|
||||||
build/include/sysexits.h | $(RUSTC) $(RUSTFLAGS) --crate-type lib -o $@ -
|
|
||||||
|
|
||||||
.PHONY: dj
|
.PHONY: dj
|
||||||
dj: build/bin/dj
|
dj: build/bin/dj
|
||||||
|
@ -113,7 +113,7 @@ build/bin/mm: src/mm.c build
|
||||||
.PHONY: npc
|
.PHONY: npc
|
||||||
npc: build/bin/npc
|
npc: build/bin/npc
|
||||||
build/bin/npc: src/npc.c build
|
build/bin/npc: src/npc.c build
|
||||||
$(CC) $(CFLAGAS) -o $@ src/npc.c
|
$(CC) $(CFLAGS) -o $@ src/npc.c
|
||||||
|
|
||||||
.PHONY: rpn
|
.PHONY: rpn
|
||||||
rpn: build/bin/rpn
|
rpn: build/bin/rpn
|
||||||
|
@ -137,10 +137,8 @@ build/bin/strcmp: src/strcmp.c build
|
||||||
|
|
||||||
.PHONY: swab
|
.PHONY: swab
|
||||||
swab: build/bin/swab
|
swab: build/bin/swab
|
||||||
build/bin/swab: src/swab.rs build build/o/libsysexits.rlib
|
build/bin/swab: src/swab.rs build rustlibs
|
||||||
$(RUSTC) $(RUSTFLAGS) --extern getopt=build/o/libgetopt.rlib \
|
$(RUSTC) $(RUSTFLAGS) $(RUSTLIBS) -o $@ src/swab.rs
|
||||||
--extern sysexits=build/o/libsysexits.rlib \
|
|
||||||
-o $@ src/swab.rs
|
|
||||||
|
|
||||||
.PHONY: true
|
.PHONY: true
|
||||||
true: build/bin/true
|
true: build/bin/true
|
||||||
|
|
Loading…
Reference in New Issue
Block a user