mirror of
https://github.com/thepigeongenerator/mcaselector-lite.git
synced 2025-12-17 07:55:45 +01:00
use cargo instead of rustc
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
[package]
|
||||
name = "dummy"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
name = "mcaselector-lite"
|
||||
version = "0.0.1"
|
||||
edition = "2024"
|
||||
|
||||
[lib]
|
||||
crate-type = ["staticlib"]
|
||||
@@ -11,5 +11,3 @@ panic = "abort"
|
||||
|
||||
[profile.release]
|
||||
panic = "abort"
|
||||
|
||||
[dependencies]
|
||||
|
||||
37
makefile
37
makefile
@@ -5,27 +5,28 @@
|
||||
# - bear (debug)
|
||||
# - git bash (windows)
|
||||
NAME := mcaselector-lite
|
||||
|
||||
# TODO: use cargo instead of rustc, as then the Cargo.toml file is actually useful (and will help with linting)
|
||||
RUSTC := rustc
|
||||
DEBUG ?= 0
|
||||
ARCH ?= 0
|
||||
|
||||
# C compiler options
|
||||
CC := clang
|
||||
CLANG := c
|
||||
CSTD := c17
|
||||
CFLAGS := -Wall -Wextra -Wpedantic -Wno-pointer-arith -static
|
||||
RSFLAGS := --crate-type=staticlib -C panic=abort
|
||||
LDFLAGS :=
|
||||
DEBUG ?= 0
|
||||
ARCH ?= 0
|
||||
|
||||
# Rust compiler options
|
||||
RUSTC := cargo rustc
|
||||
RSFLAGS :=
|
||||
|
||||
ifeq ($(DEBUG),1)
|
||||
CFLAGS += -DDEBUG -g -Og
|
||||
RSFLAGS += -C debuginfo=2
|
||||
RSOUT := debug
|
||||
PROF := dbg
|
||||
else
|
||||
CFLAGS += -O2 -Werror
|
||||
RSFLAGS += -D warnings
|
||||
RSOUT := release
|
||||
RSFLAGS := --release
|
||||
PROF := rel
|
||||
endif
|
||||
|
||||
@@ -34,10 +35,12 @@ ifeq ($(ARCH),linux-x86_64)
|
||||
CFLAGS += -target x86_64-pc-linux-gnu
|
||||
LDFLAGS += -target x86_64-pc-linux-gnu
|
||||
RSFLAGS += --target=x86_64-unknown-linux-gnu
|
||||
RSOUT := target/x86_64-unknown-linux-gnu/$(RSOUT)
|
||||
else ifeq ($(ARCH),win-x86_64)
|
||||
CFLAGS += -target x86_64-pc-windows-gnu
|
||||
LDFLAGS += -target x86_64-pc-windows-gnu
|
||||
RSFLAGS += --target=x86_64-pc-windows-gnu
|
||||
RSOUT := target/x86_64-pc-windows-gnu/$(RSOUT)
|
||||
EXT := .exe
|
||||
else
|
||||
$(error you must set the ARCH environment variable to one of these: 'linux-x86_64' 'win-x86_64')
|
||||
@@ -49,7 +52,9 @@ C_SRC := $(wildcard src/*.c) $(wildcard src/**/*.c) $(wildcard src/**/**/*.c) $
|
||||
C_OBJ := $(patsubst src/%,obj/$(ARCH)/$(PROF)/%,$(C_SRC:.c=.o))
|
||||
C_DEP := $(C_OBJ:.o=.d)
|
||||
RS_SRC := $(wildcard src/*.rs) $(wildcard src/**/*.rs) $(wildcard src/**/**/*.rs) $(wildcard src/**/**/**/*.rs) $(wildcard src/**/**/**/**/*.rs)
|
||||
RS_OBJ := $(patsubst src/%,obj/$(ARCH)/$(PROF)/%,$(RS_SRC:.rs=.o))
|
||||
RS_LIB := $(RSOUT)/libmcaselector_lite.a
|
||||
RS_DEP := $(RSOUT)/libmcaselector_lite.d
|
||||
RSOUT :=
|
||||
|
||||
DIR := bin/$(ARCH)/$(PROF) $(sort obj/$(ARCH)/$(PROF) $(dir $(C_SRC)) $(dir $(RS_SRC)))
|
||||
DIR_BUILD := bin/$(ARCH)/$(PROF)
|
||||
@@ -65,11 +70,11 @@ run: compile
|
||||
./$(TARGET)
|
||||
compile: compile_commands.json $(DIR) $(TARGET)
|
||||
clean:
|
||||
rm -rf bin/ obj/ compile_commands.json
|
||||
rm -rf bin/ obj/ target/ compile_commands.json
|
||||
# TODO: write a structure for the unit tests in this
|
||||
|
||||
# create the binary (linking step)
|
||||
$(TARGET): $(C_OBJ) $(RS_OBJ)
|
||||
$(TARGET): $(C_OBJ) $(RS_LIB)
|
||||
@$(call wr_colour,"RUSTC: '$(RUSTC)'",94)
|
||||
@$(call wr_colour,"CC: '$(CC)'",94)
|
||||
@$(call wr_colour,"CFLAGS: '$(CFLAGS)'",94)
|
||||
@@ -77,7 +82,7 @@ $(TARGET): $(C_OBJ) $(RS_OBJ)
|
||||
@$(call wr_colour,"LDFLAGS: '$(LDFLAGS)'",94)
|
||||
@$(call wr_colour,"linking to: '$@'",92)
|
||||
|
||||
@$(CC) $(LDFLAGS) -o $@ $(C_OBJ) $(RS_OBJ)
|
||||
@$(CC) $(LDFLAGS) -o $@ $(C_OBJ) $(RS_LIB)
|
||||
@$(call wr_colour,"current profile: '$(PROF)'",93)
|
||||
|
||||
# create .o and .d files for C sources
|
||||
@@ -85,10 +90,9 @@ $(C_OBJ): $(C_SRC)
|
||||
@$(call wr_colour,"compiling $(notdir $@) from $(notdir $<)",92)
|
||||
@$(CC) $(CFLAGS) -c -MD -MP -std=$(CSTD) -x $(CLANG) -o $@ $<
|
||||
|
||||
# create .o files for RUST sources
|
||||
$(RS_OBJ): $(RS_SRC)
|
||||
@$(call wr_colour,"compiling $(notdir $@) from $(notdir $<)",92)
|
||||
@$(RUSTC) $(RSFLAGS) --emit=obj -o $@ $<
|
||||
# create .o and .d files for RUST sources
|
||||
$(RS_LIB): $(RS_SRC)
|
||||
$(RUSTC) $(RSFLAGS)
|
||||
|
||||
# create directories
|
||||
$(DIR):
|
||||
@@ -106,3 +110,4 @@ endif
|
||||
|
||||
# include the dependencies
|
||||
-include $(C_DEP)
|
||||
-include $(RS_DEP)
|
||||
|
||||
Reference in New Issue
Block a user