]> piware.de Git - learn-rust.git/blobdiff - call-c-from-rust/Makefile
Initial libmount function call from Rust
[learn-rust.git] / call-c-from-rust / Makefile
index 583e2f2ff345b1df003117a3bf18418b1601b2b9..cbeefdd888c5aab771bb9475593d717fd61aa873 100644 (file)
@@ -1,7 +1,7 @@
 CFLAGS += $(shell pkg-config --cflags mount)
 LIBMOUNT = $(shell pkg-config --libs mount)
 
-all: c-mounts c-langinfo
+all: c-mounts c-langinfo target/debug/learning-c-from-rust
 
 c-mounts: c-mounts.o
        $(CC) -Wall -o $@ $^ $(LIBMOUNT)
@@ -9,13 +9,25 @@ c-mounts: c-mounts.o
 c-langinfo: c-langinfo.o
        $(CC) -Wall -o $@ $^
 
+# HACK: does not find stdarg.h (through stdio.h), missing size_t
+# also avoid hundreds of "should have an upper camel case name" warnings
+src/libmount.rs:
+       sed 's/#include.*stdio.h.*/typedef unsigned long size_t;/' /usr/include/libmount/libmount.h > libmount-hack.h
+       bindgen libmount-hack.h -- -I/usr/include/linux/ > $@.tmp
+       (echo '#![allow(non_camel_case_types,non_upper_case_globals,dead_code)]'; cat $@.tmp) > $@
+       rm libmount-hack.h $@.tmp
+
+target/debug/learning-c-from-rust: src/libmount.rs src/main.rs
+       cargo build
+
 clean:
-       rm -f c-mounts c-langinfo *.o
+       rm -f c-mounts c-langinfo *.o src/libmount.rs
 
 run: all
        LANG=en_US.UTF-8 ./c-langinfo
        LANG=en_GB.UTF-8 ./c-langinfo
        LANG=en_IE.UTF-8 ./c-langinfo
        ./c-mounts
+       target/debug/learning-c-from-rust
 
 .PHONY: clean run