aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: a21748b8d74ae8eeb03d21a2cc92abf17eaf610b (plain)
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
CC?=gcc
RM:=rm -rf

SRC_DIR:=src
OBJ_DIR:=obj
INC_DIRS=$(addprefix -iquote,include)

PARCINI_SOURCES:=$(wildcard $(SRC_DIR)/*.c)
PARCINI_OBJECTS:=$(PARCINI_SOURCES:%.c=$(OBJ_DIR)/%.o)
BUILD_DIR:=build

test: CFLAGS := -std=c99 -O0 -g -Wall -DDEBUG
test: $(BUILD_DIR) tests/parcini

tests/%: $(OBJ_DIR)/src/tests/%.o $(PARCINI_OBJECTS)
	$(CC) $(LDFLAGS) -o $(BUILD_DIR)/$@ $^
	$(BUILD_DIR)/$@

example: CFLAGS := -std=c99 -O2 -Wall
example: $(OBJ_DIR)/example/example.o $(PARCINI_OBJECTS)
	$(CC) $(LDFLAGS) -o $(BUILD_DIR)/example/$@ $^

$(OBJ_DIR)/%.o: %.c
	$(CC) -c $(CFLAGS) $(INC_DIRS) -o $@ $<

$(BUILD_DIR):
	mkdir -p $(BUILD_DIR)/tests
	mkdir -p $(BUILD_DIR)/example
	mkdir -p $(OBJ_DIR)/src/tests
	mkdir -p $(OBJ_DIR)/example

clean:
	$(RM) $(OBJ_DIR)
	$(RM) $(BUILD_DIR)

.PHONY: clean test

.PRECIOUS: $(OBJ_DIR)/tests/%.o $(OBJ_DIR)/%.o