-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
56 lines (39 loc) · 1.26 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
47
48
49
50
51
52
53
54
55
56
.PHONY: all custom lib force clear
CC=g++
OPT=-g
CFLAGS=-c -Wall -std=c++17
SRCPATH:=src/
SRCS:=$(wildcard $(SRCPATH)*.cpp)
OBJS:=$(SRCS:%.cpp=%.o)
HDRS:=$(wildcard $(SRCPATH)*.h)
HDPP:=$(wildcard $(SRCPATH)*.hpp)
LIBS=$(wildcard inc/*)
LIBS_A:=$(addsuffix /liboutput.a,$(LIBS))
# Creates a list of all modules include flags
modulesinc=$(foreach d,$(wildcard $(1:=/inc/*)),$(call modulesinc,$d) -I$(d:=/src))
MOD_INC:=$(call modulesinc,.)
# Include LIBS flags
flagsinc=$(foreach d,$(wildcard $(1:=/inc/*)),$(call flagsinc,$d) $(d:=/makefile.flags))
-include $(call flagsinc,.)
-include makefile.flags
LDFLAGS:=$(LIBS_LD)
INCL=-Isrc -Itest -Iinc $(LIBS_INC) $(MOD_INC)
all: test.exe
custom: mtest.exe
lib: liboutput.a
clear:
$(foreach mod,$(LIBS),$(MAKE) -C $(mod) clear $(newline))
$(RM) src/*.o *.exe liboutput.a test/*.o test/src/*.o
liboutput.a: $(LIBS_A) $(OBJS) $(HDRS) $(HDPP)
$(RM) liboutput.a
ar -qcT liboutput.a $(LIBS_A) $(OBJS)
$(LIBS_A): force
$(MAKE) -C $(dir $@) CFLAGS="$(CFLAGS)" OPT="$(OPT)" lib
test.exe: liboutput.a test/test.o
$(CC) -o test.exe test/test.o liboutput.a $(LDFLAGS)
mtest.exe: liboutput.a test/mtest.o
$(CC) -o mtest.exe test/mtest.o liboutput.a $(LDFLAGS)
%.o: %.cpp
$(CC) $(CFLAGS) $< -o $@ $(INCL) $(OPT)
define newline
endef