1个不稳定版本
0.1.2 | 2023年2月21日 |
---|---|
0.1.1 |
|
0.1.0 |
|
#1034 in 开发工具
6KB
make-makefile
简单的Makefile生成器
Usage: mm [OPTIONS]
Options:
-n, --name <NAME> Name of the project
-k, --kind <KIND> Binary or library [default: bin] [possible values: bin, lib]
-h, --help Print help
-V, --version Print version
安装
如果你已经安装了cargo
包管理器,则可以运行该命令。
cargo install make-makefile
或者你可以在发布页面上下载。
生成模板
mm
会在你的项目目录中生成Makefile
模板。
你可以将{PROGRAM}
修改为你的项目名称。
mm
#The Target
#For Binary: <name>, For Library: lib<name>.a
NAME := {PROGRAM}
#Source Files
SOURCES := main.c \
#The Directories, Source, Includes, Dependencies
TESTDIR := test
BONUSDIR := bonus
SRCDIR := src
INCDIR := inc
DEPDIR := dep
BLDDIR := obj
#Dependencies
DEPLIBS :=
DEPDIRS :=
#Compiler, Linker, Flags
CC := cc
# DEBUG := -g
# SANITIZE := -fsanitize=address
CFLAGS := -Wall -Wextra -Werror
#-------------------------------------------------------------------------------
#DO NOT EDIT BELOW THIS LINE
#-------------------------------------------------------------------------------
TARGET := $(suffix $(NAME))
CEXT := c
OEXT := o
INC := -I$(INCDIR) $(addprefix -I$(DEPDIR)/, $(DEPDIRS))
LIB := $(addprefix -l, $(DEPLIBS))
LID := $(addprefix -L$(DEPDIR)/, $(DEPDIRS))
SRCS := $(addprefix $(SRCDIR)/,$(SOURCES))
OBJS := $(patsubst $(SRCDIR)/%,$(BLDDIR)/%,$(SRCS:.$(CEXT)=.$(OEXT)))
#Defauilt Make
all: $(NAME)
bonus:
@make -C $(BONUSDIR)
@cp $(BONUSDIR)/$(NAME) ./
#Remake
re: fclean all
#Make the Directories
directories:
@mkdir -p $(BLDDIR)
#Dependencies
depend:
@for ddir in $(addprefix $(DEPDIR)/, $(DEPDIRS)); do \
make -s -C $$ddir; \
done
#Clean only Objects
clean:
@for ddir in $(addprefix $(DEPDIR)/, $(DEPDIRS)); do \
make -s -C $$ddir clean; \
done
@$(RM) -rf $(BLDDIR)
#Full Clean, Objects and Binaries
fclean: clean
@for ddir in $(addprefix $(DEPDIR)/, $(DEPDIRS)); do \
make -s -C $$ddir fclean; \
done
@$(RM) -rf $(NAME)
#Link
$(NAME): $(OBJS)
@for ddir in $(addprefix $(DEPDIR)/, $(DEPDIRS)); do \
make -s -C $$ddir; \
done
ifeq ($(TARGET), .a)
$(AR) -rc $@ $^
else
$(CC) $(SANITIZE) $(DEBUG) $(INC) -o $(NAME) $^ $(LID) $(LIB)
endif
#Compile
$(BLDDIR)/%.$(OEXT): $(SRCDIR)/%.$(CEXT)
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) $(SANITIZE) $(DEBUG) $(INC) -c -o $@ $<
#Non-File Targets
.PHONY: all re clean fclean bonus directories depend
命名规范
mm --name hello
#The Target
#For Binary: <name>, For Library: lib<name>.a
NAME := hello
类型选项
二进制模板
mm --name hello --kind=bin
#The Target
#For Binary: <name>, For Library: lib<name>.a
NAME := hello
库模板
mm --name hello --kind=lib
#The Target
#For Binary: <name>, For Library: lib<name>.a
NAME := libhello.a
依赖关系
~1.2–1.7MB
~33K SLoC