Basic apis' ready

This commit is contained in:
Hizenberg469
2025-01-13 23:52:04 +05:30
parent 4c58e94a4a
commit 8200e46baa
4 changed files with 192 additions and 14 deletions

View File

@@ -3,7 +3,7 @@ CFG ?= debug
# Config specific settings
ifeq ($(CFG),debug)
CFLAGS += -DDEBUG
CFLAGS += -g -DDEBUG
else
CFLAGS += -O3 -DNDEBUG
endif
@@ -22,13 +22,18 @@ endif
rule : dep | inform
BUILD_DIR = build/$(CFG)
OBJS_DIR = $(BUILD_DIR)/objs
BUILD_DIR=bin/$(CFG)
OBJS_DIR=objs/$(CFG)
LIBDIR=lib/${CFG}
SRCDIR=src
#--------------------------------------------------
BINARY=$(BUILD_DIR)/fsm
CODEDIRS=. ./src
APP=$(BUILD_DIR)/app
APP_OBJECT=$(OBJS_DIR)/app.o
FSMLIB_NAME=fsm
FSMLIB=$(LIBDIR)/lib$(FSMLIB_NAME)
CODEDIRS=./src
INCDIRS=. ./include/ # can be list
CC=gcc
@@ -36,7 +41,7 @@ OPT=-O0
#generate files that encode make rules for the .h dependencies
DEPFLAGS=-MP -MD
#automatically add the -I onto each include directory
CFLAGS=-Wall -Wextra -g $(foreach D,$(INCDIRS),-I$(D)) $(OPT) $(DEPFLAGS)
CFLAGS+=-Wall -Wextra $(foreach D,$(INCDIRS),-I$(D)) $(OPT) $(DEPFLAGS)
# for-style iteration (foreach) and regular expression completions (wildcard)
CFILES=$(foreach D, $(CODEDIRS),$(wildcard $(D)/*.c))
@@ -44,18 +49,31 @@ CFILES=$(foreach D, $(CODEDIRS),$(wildcard $(D)/*.c))
OBJECTS=$(patsubst %.c,$(OBJS_DIR)/%.o,$(CFILES))
DEPFILES=$(patsubst %.c,$(OBJS_DIR)/%.d,$(CFILES))
all: $(BINARY)
all: $(FSMLIB) $(APP) | create_dir
$(BINARY): $(OBJECTS)
$(CC) -o $@ $^
create_dir:
mkdir -p $(BUILD_DIR)
mkdir -p $(OBJS_DIR)
mkdir -p $(LIBDIR)
$(APP): $(APP_OBJECT) | create_dir
$(CC) -o $@ $^ -L $(LIBDIR) -l$(FSMLIB_NAME)
$(FSMLIB): $(OBJECTS) | create_dir
ar cr $(LIBDIR)/${FSMLIB}.a ${OBJECTS}
# only want the .c file dependency here, thus $< instead of $^.
#
%.o:%.c
$(OBJS_DIR)/%.o:$(SRCDIR)/%.c | create_dir
$(CC) $(CFLAGS) -c -o $@ $<
$(OBJS_DIR)/%.o:%.c | create_dir
$(CC) $(CFLAGS) -c -o $@ $<
clean:
rm -rf $(BINARY) $(OBJECTS) $(DEPFILES)
rm -rf $(APP) $(APP_OBJECT) $(OBJECTS) $(DEPFILES)
rm -rf $(BUILD_DIR) $(OBJS_DIR) $(LIBDIR)
# shell commands are a set of keystrokes away
distribute: clean