-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
46 lines (33 loc) · 1 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
ifeq ($(TARGET),window)
CC = x86_64-w64-mingw32-gcc
else
CC = gcc
endif
CFLAGS=-I. -g3 -Wall -W -g -O3
BUILD_TARGET ?= picross.exe
BUILD_DIR ?= ./build
SRC_DIR ?= ./src
SRC_FILES := $(wildcard $(SRC_DIR)/*.c)
OBJ_FILES := $(patsubst $(SRC_DIR)/%.c,$(BUILD_DIR)/%.o,$(SRC_FILES))
DEP_FILES := $(OBJ_FILES:.o=.d)
TESTS_TARGET ?= test.out
TESTS_DIR ?= ./tests
TESTS_SRC_FILES := $(shell find $(TESTS_DIR) -name *.c)
TESTS_OBJ_FILES := $(patsubst $(TESTS_DIR)/%.c,$(BUILD_DIR)/%.o,$(TESTS_SRC_FILES))
TESTS_DEP_FILES := $(TESTS_OBJ_FILES:.o=.d)
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c
mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c -o $@ $<
$(BUILD_DIR)/%.o: $(TESTS_DIR)/%.c
mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c -o $@ $<
$(BUILD_DIR)/$(BUILD_TARGET): $(OBJ_FILES)
$(CC) $(OBJS) $(LDFLAGS) -o $@ $^
$(BUILD_DIR)/$(TESTS_TARGET): $(TESTS_OBJ_FILES)
$(CC) $(OBJS) $(LDFLAGS) -o $@ $^
.PHONY: all test clean
all: $(BUILD_DIR)/$(BUILD_TARGET)
test: $(BUILD_DIR)/$(TESTS_TARGET)
clean:
$(RM) -r $(BUILD_DIR)
-include $(DEP_FILES)