-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move demos to examples folder, compile multiple targets in that folder
- Loading branch information
Showing
2 changed files
with
26 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,45 @@ | ||
CC = gcc | ||
TARGET = demo | ||
SRC_DIR = src | ||
INC_DIR = include | ||
# This is where the targets will be compiled from | ||
EXAMPLES_DIR = examples | ||
TEST_DIR = test | ||
CFLAGS = -g -I$(INC_DIR) -Wall | ||
LDFLAGS = -lm | ||
DEMO_SRC = main.c | ||
TEST_SRC = test/test.c | ||
SRC = $(wildcard $(SRC_DIR)/*.c) $(DEMO_SRC) | ||
TEST_SRC = $(wildcard $(TEST_DIR)/*.c) | ||
EXAMPLES_SRC = $(wildcard $(EXAMPLES_DIR)/*.c) | ||
# Each demo source gets a target, e.g. examples/01_demo.c -> 01_demo | ||
EXAMPLES = $(patsubst $(EXAMPLES_DIR)/%.c,%,$(EXAMPLES_SRC)) | ||
|
||
# Compare cmd arguments; if `test`, extend it to handle unit tests | ||
# If `test` is passed as a cmd argument, extend flags to handle unit tests | ||
ifeq ($(MAKECMDGOALS), test) | ||
CFLAGS += -DRUN_UNIT_TESTS | ||
SRC = $(wildcard $(SRC_DIR)/*.c) $(TEST_SRC) | ||
TARGET = test/test | ||
SRC = $(wildcard $(SRC_DIR)/*.c) $(TEST_SRC) | ||
else | ||
TARGET = $(EXAMPLES) | ||
SRC = $(wildcard $(SRC_DIR)/*.c) | ||
endif | ||
|
||
OBJECTS = $(SRC:%.c=%.o) | ||
RM = rm -rf | ||
|
||
all: $(TARGET) | ||
# What to do by default (no arguments) | ||
all: $(EXAMPLES) | ||
|
||
$(TARGET): $(OBJECTS) | ||
$(CC) $(OBJECTS) -o $(TARGET) $(LDFLAGS) | ||
$(EXAMPLES): %: $(EXAMPLES_DIR)/%.c $(wildcard $(SRC_DIR)/*.c) | ||
$(CC) $(CFLAGS) $(SRC_DIR)/*.c $< -o $@ $(LDFLAGS) | ||
|
||
%.o: %.cpp | ||
%.o: %.c | ||
$(CC) $(CFLAGS) -c $< -o $@ | ||
|
||
# Phony to always rerun it | ||
.PHONY: test | ||
|
||
test: $(TARGET) | ||
./$(TARGET) | ||
|
||
.PHONY: clean | ||
|
||
RM = rm -rf | ||
clean: | ||
$(RM) $(TARGET) | ||
$(RM) $(SRC_DIR)/*.o | ||
$(RM) $(TARGET).o | ||
$(RM) test/*.o | ||
$(RM) $(EXAMPLES) $(SRC_DIR)/*.o test/*.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters