~nerosnm/oslog

a95e7078a0e929aedff5549172023a100db7aabf — Søren Mortensen 3 years ago f0e0a11
Rework oslog-sys configuration and paths to allow for `cargo package`

Signed-off-by: Søren Mortensen <soren@sorenmortensen.com>
4 files changed, 27 insertions(+), 19 deletions(-)

M liboslog/Makefile
M oslog-sys/build.rs
M oslog-sys/include/oslog-sys.h
A oslog-sys/liboslog
M liboslog/Makefile => liboslog/Makefile +17 -14
@@ 1,36 1,39 @@
CC=clang
CFLAGS=-I$(IDIR)
CFLAGS=-I$(INC_DIR)

IDIR=include
INC_DIR=include

_DEPS = oslog.h
DEPS = $(patsubst %,$(IDIR)/%,$(_DEPS))
DEPS = $(patsubst %,$(INC_DIR)/%,$(_DEPS))

ODIR=obj
OBJ_DIR=obj

_OBJ = oslog.o
OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ))
OBJ = $(patsubst %,$(OBJ_DIR)/%,$(_OBJ))

SDIR=src
SRC_DIR=src

_SRC = oslog.c
SRC = $(patsubst %,$(SDIR)/%,$(_SRC))
SRC = $(patsubst %,$(SRC_DIR)/%,$(_SRC))

OUTDIR=out
OUT_DIR=out

$(ODIR)/%.o: $(SDIR)/%.c $(DEPS)
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c $(DEPS)
	@echo "[Compile]" $<
	@mkdir -p $(OBJ_DIR)
	@$(CC) -c -o $@ $< $(CFLAGS)

$(OUTDIR)/liboslog.a: $(OBJ)
$(OUT_DIR)/liboslog.a: $(OBJ)
	@echo "[Link (Static)]" $<
	@mkdir -p $(OUTDIR)
	@mkdir -p $(OUT_DIR)
	@ar rcs $@ $^

.PHONY: clean
$(OUT_DIR):
	@mkdir -p $(OUT_DIR)

.PHONY: clean $(OBJ_DIR) $(OUT_DIR)

clean:
	rm -f $(ODIR)/*.o *~ $(INCDIR)/*~
	rm -rf out
	rm -f $(OBJ_DIR)/*.o $(OUT_DIR)/*.a

all: liboslog.a

M oslog-sys/build.rs => oslog-sys/build.rs +8 -4
@@ 13,15 13,19 @@ use std::path::PathBuf;
use std::process::Command;

fn main() {
    let liboslog_dir = concat!(env!("CARGO_MANIFEST_DIR"), "/../liboslog");
    let liboslog_dir = "liboslog";

    let out_dir = env::var("OUT_DIR").unwrap();
    let out_dir_argument = format!("OUT_DIR={}", out_dir);
    let obj_dir_argument = format!("OBJ_DIR={}/obj", out_dir);
    
    Command::new("make")
        .args(&[&*out_dir_argument, &*obj_dir_argument])
        .current_dir(PathBuf::from(liboslog_dir))
        .status()
        .unwrap();
        .status().unwrap();

    println!("cargo:rustc-link-search=native={}/out/", liboslog_dir);
    println!("cargo:rustc-link-lib=static=oslog");
    println!("cargo:rustc-link-search=native={}", out_dir);

    let bindings = bindgen::Builder::default()
        // The input header we would like to generate

M oslog-sys/include/oslog-sys.h => oslog-sys/include/oslog-sys.h +1 -1
@@ 6,4 6,4 @@
//  Copyright © 2018 Søren Mortensen. All rights reserved.
//

#include "../../liboslog/include/oslog.h"
#include "../liboslog/include/oslog.h"

A oslog-sys/liboslog => oslog-sys/liboslog +1 -0
@@ 0,0 1,1 @@
../liboslog/
\ No newline at end of file