chore(lsm): add example binary support to Makefile
parent
1c421c1e67
commit
1461956d98
24
lsm/Makefile
24
lsm/Makefile
|
@ -9,13 +9,17 @@ SRCS != find '$(SRC_DIR)' -iname '*.c'
|
|||
SRCS_H != find $(INC_DIRS) -iname '*.h'
|
||||
SRCS_H_INTERNAL != find $(SRC_DIR) -iname '*.h'
|
||||
SRCS_TEST != find '$(TEST_DIR)' -iname '*.c'
|
||||
SRCS_EXAMPLE != find '$(EXAMPLE_DIR)' -iname '*.c'
|
||||
|
||||
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
|
||||
OBJS_TEST := $(SRCS_TEST:%=$(BUILD_DIR)/%.o)
|
||||
DEPS := $(SRCS:%=$(BUILD_DIR)/%.d) $(SRCS_TEST:%=$(BUILD_DIR)/%.d)
|
||||
OBJS_EXAMPLE := $(SRCS_EXAMPLE:%=$(BUILD_DIR)/%.o)
|
||||
DEPS := $(SRCS:%=$(BUILD_DIR)/%.d) $(SRCS_TEST:%=$(BUILD_DIR)/%.d) $(SRCS_EXAMPLE:%=$(BUILD_DIR)/%.d)
|
||||
|
||||
BINS_TEST := $(OBJS_TEST:%.c.o=%)
|
||||
BINS_EXAMPLE := $(OBJS_EXAMPLE:%.c.o=%)
|
||||
TARGETS_TEST := $(BINS_TEST:%=test-%)
|
||||
TARGETS_EXAMPLE := $(BINS_EXAMPLE:%=test-%)
|
||||
TARGETS_MEM_TEST := $(BINS_TEST:%=test-mem-%)
|
||||
|
||||
_CFLAGS := $(addprefix -I,$(INC_DIRS)) $(CFLAGS) -Wall -Wextra
|
||||
|
@ -71,14 +75,27 @@ $(BUILD_DIR)/$(TEST_DIR)/%.c.o: $(TEST_DIR)/%.c
|
|||
-I$(dir $(@:$(BUILD_DIR)/$(TEST_DIR)/%=$(SRC_DIR)/%)) \
|
||||
-c $< -o $@
|
||||
|
||||
# =====EXAMPLES=====
|
||||
.PHONY: build-example
|
||||
build-example: $(BINS_EXAMPLE)
|
||||
|
||||
$(BINS_EXAMPLE): %: %.c.o $(LIB)
|
||||
$(CC) \
|
||||
$^ -o $@
|
||||
|
||||
# Example binaries link the resulting library
|
||||
$(BUILD_DIR)/$(EXAMPLE_DIR)/%.c.o: $(EXAMPLE_DIR)/%.c
|
||||
mkdir -p $(dir $@)
|
||||
$(CC) $(_CFLAGS) -I$(PUB_INC_DIR) -c $< -o $@
|
||||
|
||||
# =====MAINTENANCE=====
|
||||
.PHONY: lint
|
||||
lint:
|
||||
clang-format -n --Werror $(SRCS) $(SRCS_H) $(SRCS_H_INTERNAL)
|
||||
clang-format -n --Werror $(SRCS) $(SRCS_H) $(SRCS_H_INTERNAL) $(SRCS_EXAMPLE)
|
||||
|
||||
.PHONY: fmt
|
||||
fmt:
|
||||
clang-format -i $(SRCS) $(SRCS_H) $(SRCS_H_INTERNAL)
|
||||
clang-format -i $(SRCS) $(SRCS_H) $(SRCS_H_INTERNAL) $(SRCS_EXAMPLE)
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
|
@ -89,6 +106,7 @@ clean:
|
|||
bear: clean
|
||||
bear -- make
|
||||
bear --append -- make build-test
|
||||
bear --append -- make build-example
|
||||
|
||||
|
||||
# Make make aware of the .d files
|
||||
|
|
|
@ -3,7 +3,9 @@ LIB_FILENAME = liblsm.a
|
|||
BUILD_DIR = build
|
||||
SRC_DIR = src
|
||||
TEST_DIR = test
|
||||
INC_DIRS = include src/_include
|
||||
EXAMPLE_DIR = example
|
||||
PUB_INC_DIR = include
|
||||
INC_DIRS = $(PUB_INC_DIR) src/_include
|
||||
|
||||
# -MMD: generate a .d file for every source file. This file can be imported by
|
||||
# make and makes make aware that a header file has been changed, ensuring an
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#include "lsm.h"
|
||||
|
||||
int main() { printf("yuh"); }
|
Loading…
Reference in New Issue