-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.mk
62 lines (49 loc) · 1.5 KB
/
common.mk
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
CC := ~/opt/cross/bin/i686-elf-gcc
makefile := $(lastword $(MAKEFILE_LIST))
is-tty := $(shell stat --format %F -L /proc/$$PPID/fd/1 | \
grep 'character special file')
ifdef is-tty
echo-ok := echo -e '\033[0;32mok\033[0m'
# TODO echo-fail
else
echo-ok := echo ok
# TODO echo-fail
endif
MV := mv -f
LDFLAGS += -nostdlib
CFLAGS += -ffreestanding -std=gnu11
CFLAGS += $(optimization) $(warnings)
# do not add a rule for explicitly building each dependency file
# update dependency file <--> update object file
CPPFLAGS += -MD -MP
CPPFLAGS += $(addprefix -I ,$(includes))
ifdef OPTIMIZATION
optimization := $(OPTIMIZATION)
else
optimization := -O2
endif
includes := include/
warnings := -Wall -Wextra -Wmissing-prototypes \
-pedantic \
-Wredundant-decls -Winline \
-Wconversion -Wstrict-prototypes \
#-Werror
ifdef HOSTED
CPPFLAGS += -DHOSTED
endif
sources := $(wildcard *.c *.S)
objects := $(patsubst %.S,%_asm.o,$(sources:%.c=%.o))
%.o: %.c $(makefile)
@echo -n '$(indentation)compiling $<...'
@$(COMPILE.c) $(OUTPUT_OPTION) $<
@$(echo-ok)
%_asm.o: %.S $(makefile)
@echo -n '$(indentation)assembling $<...'
@$(COMPILE.S) -o $@ $<
@$(echo-ok)
.PHONY: clean
clean:
@echo -n '$(indentation)cleaning...'
@$(RM) *.o *.d *.log *.elf *.img
@$(echo-ok)
-include $(objects:%.o=%.d)