-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
82 lines (64 loc) · 1.5 KB
/
Makefile
File metadata and controls
82 lines (64 loc) · 1.5 KB
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
80
81
# Target programs
programs := \
sem_count.x \
sem_buffer.x \
sem_prime.x \
tps.x
# User-level thread library
UTHREADLIB := libuthread
UTHREADPATH := $(UTHREADLIB)
libuthread := $(UTHREADPATH)/$(UTHREADLIB).a
# Default rule
all: $(libuthread) $(programs)
# Avoid builtin rules and variables
MAKEFLAGS += -rR
# Don't print the commands unless explicitely requested with `make V=1`
ifneq ($(V),1)
Q = @
V = 0
endif
# Current directory
CUR_PWD := $(shell pwd)
# Define compilation toolchain
CC = gcc
# General gcc options
CFLAGS := -Wall -Werror
CFLAGS += -pipe
## Debug flag
ifneq ($(D),1)
CFLAGS += -O2
else
CFLAGS += -O0
CFLAGS += -g
endif
# Include path
INCLUDE := -I$(UTHREADPATH)
# Generate dependencies
DEPFLAGS = -MMD -MF $(@:.o=.d)
# Application objects to compile
objs := $(patsubst %.x,%.o,$(programs))
# Include dependencies
deps := $(patsubst %.o,%.d,$(objs))
-include $(deps)
# Rule for libuthread.a
$(libuthread):
@echo "MAKE $@"
$(Q)$(MAKE) V=$(V) D=$(D) -C $(UTHREADPATH)
# Generic rule for linking final applications
%.x: %.o $(libuthread)
@echo "LD $@"
$(Q)$(CC) $(CFLAGS) -o $@ $< -L$(UTHREADPATH) -luthread -lpthread
# Generic rule for compiling objects
%.o: %.c
@echo "CC $@"
$(Q)$(CC) $(CFLAGS) $(INCLUDE) -c -o $@ $< $(DEPFLAGS)
# Generic rule for markdown
%.html: %.md
@echo "MKDN $@"
$(Q)pandoc -s --toc -o $@ $<
# Cleaning rule
clean:
@echo "CLEAN $(CUR_PWD)"
$(Q)$(MAKE) V=$(V) D=$(D) -C $(UTHREADPATH) clean
$(Q)rm -rf $(objs) $(deps) $(programs)
.PHONY: clean $(libuthread)