-
Notifications
You must be signed in to change notification settings - Fork 48
/
rules.mak
79 lines (64 loc) · 1.71 KB
/
rules.mak
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
ifndef SUBDIR
$(error "please define SUBDIR variable")
endif
__OBJECTS1 = $(SOURCES:.c=.o)
__OBJECTS2 = $(__OBJECTS1:.s=.o)
OBJECTS = $(__OBJECTS2:.S=.o)
__OBJECTS = $(addprefix $(SUBOBJDIR)/,$(OBJECTS))
define NL
endef
ifdef PROGRAM
__PROGRAM = $(SUBBINDIR)/$(PROGRAM)
program: $(__PROGRAM) dirs
$(__PROGRAM): $(LIBS) $(__OBJECTS)
mkdir -p $(SUBBINDIR)
$(CC) -o $(__PROGRAM) $(CFLAGS) $(__OBJECTS) $(LIBS) $(LDFLAGS)
@ echo "Created $(__PROGRAM)"
endif
ifdef SHLIB
__SHLIB = $(SUBBINDIR)/$(SHLIB)
shlib: $(__SHLIB) dirs
@echo "$(__SHLIB) is up to date"
$(__SHLIB): $(LIBS) $(__OBJECTS)
mkdir -p $(SUBBINDIR)
$(CC) -shared -o $(__SHLIB) $(CFLAGS) $(__OBJECTS) $(LIBS) $(LDFLAGS)
@ echo "Created $(__SHLIB)"
endif
ifdef ARCHIVE
__ARCHIVE = $(SUBLIBDIR)/$(ARCHIVE)
archive: $(__ARCHIVE) dirs
$(__ARCHIVE): $(__OBJECTS)
mkdir -p $(SUBLIBDIR)
ar rv $(__ARCHIVE) $(__OBJECTS)
@ echo "Created $(__ARCHIVE)"
endif
$(SUBOBJDIR)/%.o: %.c $(DEPENDS)
mkdir -p $(SUBOBJDIR)
$(shell mkdir -p $(shell dirname $@))
$(CC) -c $(CFLAGS) $(DEFINES) $(INCLUDES) -o $@ $<
$(SUBOBJDIR)/%.o: %.s $(DEPENDS)
mkdir -p $(SUBOBJDIR)
$(shell mkdir -p $(shell dirname $@))
$(CC) -c $(CFLAGS) $(DEFINES) $(INCLUDES) -o $@ $<
$(SUBOBJDIR)/%.o: %.S $(DEPENDS)
mkdir -p $(SUBOBJDIR)
$(shell mkdir -p $(shell dirname $@))
$(CC) -c $(CFLAGS) $(DEFINES) $(INCLUDES) -o $@ $<
dirs:
ifdef DIRS
@ $(foreach i, $(DIRS), $(MAKE) -C $(i) $(NL) )
endif
__clean:
sudo rm -rf $(__OBJECTS) $(__PROGRAM) $(__SHLIB) $(__ARCHIVE) $(CLEAN)
ifdef DIRS
@ $(foreach i, $(DIRS), $(MAKE) -C $(i) clean $(NL) )
endif
ifndef REDEFINE_CLEAN
clean: __clean
endif
tests:
ifndef REDEFINE_TESTS
ifdef DIRS
@ $(foreach i, $(DIRS), $(MAKE) -C $(i) tests $(NL) )
endif
endif