Skip to content

Commit

Permalink
Configure build script for the examples
Browse files Browse the repository at this point in the history
  • Loading branch information
61315 committed Feb 11, 2022
1 parent 93aaf63 commit cbe5bb1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.vscode
**/build
**/build
**/lib
37 changes: 28 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,33 +1,52 @@
.POSIX:
CC = clang
CPPFLAGS := -MMD -MP -DSYNTH_LIB_ALONE
CFLAGS := -Wall -Wextra -std=c99 -pedantic -Ofast
LDFLAGS = -s
# LDLIBS =
# PREFIX = /usr/local

TARGET_LIB := libresynthesizer.a

LIB_DIR := lib
BUILD_DIR := build
SRC_DIRS := resynthesizer
SRC_DIR := resynthesizer

SRCS := $(shell find $(SRC_DIRS) -name '*.c')
SRCS := $(shell find $(SRC_DIR) -name '*.c')
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
DEPS := $(OBJS:.o=.d)

INC_DIRS := $(shell find $(SRC_DIRS) -type d)
INC_DIRS := $(shell find $(SRC_DIR) -type d)
INC_FLAGS := $(addprefix -I,$(INC_DIRS))

CPPFLAGS := $(INC_FLAGS) -MMD -MP
CFLAGS := -DSYNTH_LIB_ALONE -g2 -Wall -Wextra -std=c99 -pedantic -Ofast
TARGET_LIB := $(LIB_DIR)/libresynthesizer.a

EXAMPLE_DIR := examples
EXAMPLE_SRCS := $(shell find $(EXAMPLE_DIR) -name '*.c')
EXAMPLES := $(basename $(EXAMPLE_SRCS))

# -g -Wall -Wextra -Werror -std=c99 -pedantic-errors
# TODO: Try both -Werror and -pedantic-errors after all the chores are done.

$(BUILD_DIR)/$(TARGET_LIB): $(OBJS)
all: $(EXAMPLES)
@echo "\033[1;92mDone!\033[0m"

$(EXAMPLES): $(TARGET_LIB) $(EXAMPLE_SRCS)
@echo "\033[1;92mBuilding $@\033[0m"
mkdir -p $(dir $@)
$(CC) $(CFLAGS) -o $@ $@.c $(LDFLAGS) $(INC_FLAGS) $(TARGET_LIB)

$(TARGET_LIB): $(OBJS)
@echo "\033[1;92mBuilding $@\033[0m"
mkdir -p $(dir $@)
ar rvs $@ $^

$(BUILD_DIR)/%.c.o: %.c
@echo "\033[1;92mBuilding $@\033[0m"
mkdir -p $(dir $@)
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@

.PHONY: clean

clean:
$(RM) -r $(BUILD_DIR)
$(RM) -r $(BUILD_DIR) $(LIB_DIR) $(EXAMPLES)

-include $(DEPS)

0 comments on commit cbe5bb1

Please sign in to comment.