-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
66 lines (53 loc) · 1.67 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
57
58
59
60
61
62
63
64
65
66
CFLAGS = -g3 -O2 -Wall -pipe -fno-strict-aliasing
OBJECTS = program_options.o eth_print.o ip_print.o \
netif.o etherif.o arp.o udp_print.o tcp_print.o \
mbuf.o ip.o udp.o checksum.o ip_cmd.o hwaddr_cmd.o \
route_cmd.o nc_cmd.o shell.o main.o
PROGRAM = unet
LDLIBS =
CPPFLAGS += $(EXTRA_CPPFLAGS)
LDFLAGS += $(EXTRA_LDFLAGS)
build_image := cakturkunet
docker = docker run --rm -it -u $(shell id -u):$(shell id -g) \
-v $(shell pwd):/build:Z -w /build ${build_image}
ifndef ($(findstring $(MAKEFLAGS),s),s)
ifndef V
E_CC = @echo ' CC '$@;
E_LD = @echo ' LD '$@;
endif
endif
ifndef BUILD_IN_DOCKER
all: $(PROGRAM)
else
all: build_in_docker
endif
${build_image}.created:
docker build -f Dockerfile.build -t ${build_image} .
@touch ${build_image}.created
build_in_docker: ${build_image}.created
@echo "Building in Docker"
@${docker} make $(PROGRAM) EXTRA_LDFLAGS=-static
dep_files := $(foreach f, $(OBJECTS),$(dir $f).depend/$(notdir $f).d)
dep_dirs := $(addsuffix .depend,$(sort $(dir $(OBJECTS))))
$(dep_dirs):
@mkdir -p $@
missing_dep_dirs := $(filter-out $(wildcard $(dep_dirs)),$(dep_dirs))
dep_file = $(dir $@).depend/$(notdir $@).d
dep_args = -MF $(dep_file) -MQ $@ -MMD -MP
dep_files_present := $(wildcard $(dep_files))
ifneq ($(dep_files_present),)
include $(dep_files_present)
endif
%.o: %.c $(missing_dep_dirs)
$(E_CC)$(CC) $(CFLAGS) $(CPPFLAGS) -c $(dep_args) $< -o $@
$(PROGRAM): $(OBJECTS)
$(E_LD)$(CC) $(CFLAGS) $(LDFLAGS) -o $(PROGRAM) $(OBJECTS) $(LDLIBS)
.PHONY: clean check build_in_docker
clean:
-$(RM) -r $(PROGRAM) $(OBJECTS) *~ core.* $(dep_dirs)
check:
ifndef BUILD_IN_DOCKER
@$(MAKE) -C t/ check
else
@${docker} make check EXTRA_LDFLAGS=-static
endif