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