2015-05-15 05:44:48 +08:00
|
|
|
#
|
|
|
|
# nsjail - Makefile
|
2016-03-09 07:56:20 +08:00
|
|
|
# -----------------------------------------
|
2015-05-15 05:44:48 +08:00
|
|
|
#
|
|
|
|
# Copyright 2014 Google Inc. All Rights Reserved.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
#
|
|
|
|
|
2016-03-01 02:09:39 +08:00
|
|
|
CC ?= gcc
|
2017-09-14 04:03:21 +08:00
|
|
|
CXX ?= g++
|
2016-03-09 01:22:50 +08:00
|
|
|
|
2017-09-14 04:03:21 +08:00
|
|
|
COMMON_FLAGS += -O2 -c \
|
2017-07-15 21:04:25 +08:00
|
|
|
-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 \
|
2017-05-29 00:37:50 +08:00
|
|
|
-Wformat -Wformat=2 -Wformat-security -fPIE \
|
2017-02-08 07:36:32 +08:00
|
|
|
-Wno-format-nonliteral \
|
2017-05-08 21:50:29 +08:00
|
|
|
-Wall -Wextra -Werror \
|
2017-05-29 22:22:31 +08:00
|
|
|
-Ikafel/include
|
2015-05-15 05:44:48 +08:00
|
|
|
|
2017-09-18 18:53:42 +08:00
|
|
|
CXXFLAGS += $(COMMON_FLAGS) $(shell pkg-config --cflags protobuf) \
|
2018-02-09 22:44:29 +08:00
|
|
|
-std=c++14 -fno-exceptions -Wno-unused -Wno-unused-parameter
|
2017-10-27 07:53:05 +08:00
|
|
|
LDFLAGS += -pie -Wl,-z,noexecstack -lpthread $(shell pkg-config --libs protobuf)
|
2016-03-09 01:22:50 +08:00
|
|
|
|
2017-05-26 10:15:45 +08:00
|
|
|
BIN = nsjail
|
2017-05-26 10:25:55 +08:00
|
|
|
LIBS = kafel/libkafel.a
|
2018-02-11 00:49:15 +08:00
|
|
|
SRCS_CXX = caps.cc cgroup.cc cmdline.cc config.cc contain.cc cpu.cc logs.cc mnt.cc net.cc nsjail.cc pid.cc sandbox.cc subproc.cc uts.cc user.cc util.cc
|
2017-09-16 06:31:53 +08:00
|
|
|
SRCS_PROTO = config.proto
|
2017-09-16 22:39:55 +08:00
|
|
|
SRCS_PB_CXX = $(SRCS_PROTO:.proto=.pb.cc)
|
|
|
|
SRCS_PB_H = $(SRCS_PROTO:.proto=.pb.h)
|
2017-09-16 22:43:01 +08:00
|
|
|
SRCS_PB_O = $(SRCS_PROTO:.proto=.pb.o)
|
2018-02-10 01:57:31 +08:00
|
|
|
OBJS = $(SRCS_CXX:.cc=.o) $(SRCS_PB_CXX:.cc=.o)
|
2016-03-10 06:51:13 +08:00
|
|
|
|
|
|
|
ifdef DEBUG
|
2017-09-14 04:03:21 +08:00
|
|
|
CXXFLAGS += -g -ggdb -gdwarf-4
|
2016-03-10 06:51:13 +08:00
|
|
|
endif
|
2016-03-09 01:49:06 +08:00
|
|
|
|
2017-02-14 05:59:24 +08:00
|
|
|
USE_NL3 ?= yes
|
2016-11-21 06:37:38 +08:00
|
|
|
ifeq ($(USE_NL3), yes)
|
2017-05-26 07:22:29 +08:00
|
|
|
NL3_EXISTS := $(shell pkg-config --exists libnl-route-3.0 && echo yes)
|
|
|
|
ifeq ($(NL3_EXISTS), yes)
|
2018-02-10 01:57:31 +08:00
|
|
|
CXXFLAGS += -DNSJAIL_NL3_WITH_MACVLAN $(shell pkg-config --cflags libnl-route-3.0)
|
2017-05-26 07:22:29 +08:00
|
|
|
LDFLAGS += $(shell pkg-config --libs libnl-route-3.0)
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2017-09-17 00:10:28 +08:00
|
|
|
.PHONY: all clean depend indent
|
2017-05-16 01:39:12 +08:00
|
|
|
|
2017-09-14 04:03:21 +08:00
|
|
|
.cc.o: %.cc
|
|
|
|
$(CXX) $(CXXFLAGS) $< -o $@
|
|
|
|
|
2017-09-16 06:31:53 +08:00
|
|
|
all: $(BIN)
|
2015-05-15 05:44:48 +08:00
|
|
|
|
2017-05-29 06:29:52 +08:00
|
|
|
$(BIN): $(LIBS) $(OBJS)
|
2017-09-14 04:03:21 +08:00
|
|
|
$(CXX) -o $(BIN) $(OBJS) $(LIBS) $(LDFLAGS)
|
2016-09-13 18:10:15 +08:00
|
|
|
|
2017-05-29 06:29:52 +08:00
|
|
|
kafel/libkafel.a:
|
2017-05-16 01:39:12 +08:00
|
|
|
ifeq ("$(wildcard kafel/Makefile)","")
|
|
|
|
git submodule update --init
|
|
|
|
endif
|
2017-05-29 06:29:52 +08:00
|
|
|
$(MAKE) -C kafel
|
2017-05-16 01:39:12 +08:00
|
|
|
|
2017-10-01 06:06:36 +08:00
|
|
|
# Sequence of proto deps, which doesn't fit automatic make rules
|
|
|
|
config.o: $(SRCS_PB_O) $(SRCS_PB_H)
|
2017-09-16 22:43:01 +08:00
|
|
|
$(SRCS_PB_O): $(SRCS_PB_CXX) $(SRCS_PB_H)
|
|
|
|
$(SRCS_PB_CXX) $(SRCS_PB_H): $(SRCS_PROTO)
|
2017-09-16 06:31:53 +08:00
|
|
|
protoc --cpp_out=. $(SRCS_PROTO)
|
2017-05-26 07:55:02 +08:00
|
|
|
|
2015-05-15 05:44:48 +08:00
|
|
|
clean:
|
2017-09-16 22:39:55 +08:00
|
|
|
$(RM) core Makefile.bak $(OBJS) $(SRCS_PB_CXX) $(SRCS_PB_H) $(BIN)
|
2017-05-27 08:32:39 +08:00
|
|
|
ifneq ("$(wildcard kafel/Makefile)","")
|
2016-09-13 18:10:15 +08:00
|
|
|
$(MAKE) -C kafel clean
|
2017-05-27 08:32:39 +08:00
|
|
|
endif
|
2015-05-15 05:44:48 +08:00
|
|
|
|
|
|
|
depend:
|
2018-02-10 01:57:31 +08:00
|
|
|
makedepend -Y -Ykafel/include -- -- $(SRCS_CXX) $(SRCS_PB_CXX)
|
2015-05-15 05:44:48 +08:00
|
|
|
|
|
|
|
indent:
|
2018-02-11 03:32:04 +08:00
|
|
|
clang-format -style="{BasedOnStyle: google, IndentWidth: 8, UseTab: Always, IndentCaseLabels: false, ColumnLimit: 100, AlignAfterOpenBracket: false, AllowShortFunctionsOnASingleLine: false}" -i -sort-includes *.h $(SRCS_CXX)
|
2017-10-26 06:34:32 +08:00
|
|
|
clang-format -style="{BasedOnStyle: google, IndentWidth: 4, UseTab: Always, ColumnLimit: 100}" -i $(SRCS_PROTO)
|
2015-05-15 05:44:48 +08:00
|
|
|
|
|
|
|
# DO NOT DELETE THIS LINE -- make depend depends on it.
|
|
|
|
|
2018-02-11 00:49:15 +08:00
|
|
|
caps.o: caps.h nsjail.h logs.h macros.h util.h
|
|
|
|
cgroup.o: cgroup.h nsjail.h logs.h util.h
|
|
|
|
cmdline.o: cmdline.h nsjail.h logs.h caps.h config.h macros.h mnt.h sandbox.h
|
2018-02-10 01:45:50 +08:00
|
|
|
cmdline.o: user.h util.h
|
2018-02-11 00:49:15 +08:00
|
|
|
config.o: caps.h nsjail.h logs.h cmdline.h config.h config.pb.h macros.h
|
|
|
|
config.o: mnt.h user.h util.h
|
|
|
|
contain.o: contain.h nsjail.h logs.h caps.h cgroup.h cpu.h mnt.h net.h pid.h
|
2018-02-10 01:08:11 +08:00
|
|
|
contain.o: user.h uts.h
|
2018-02-11 00:49:15 +08:00
|
|
|
cpu.o: cpu.h nsjail.h logs.h util.h
|
|
|
|
logs.o: logs.h nsjail.h
|
|
|
|
mnt.o: mnt.h nsjail.h logs.h macros.h subproc.h util.h
|
|
|
|
net.o: net.h nsjail.h logs.h subproc.h
|
|
|
|
nsjail.o: nsjail.h logs.h cmdline.h macros.h net.h subproc.h util.h
|
|
|
|
pid.o: pid.h nsjail.h logs.h subproc.h
|
|
|
|
sandbox.o: sandbox.h nsjail.h logs.h kafel/include/kafel.h
|
|
|
|
subproc.o: subproc.h nsjail.h logs.h cgroup.h contain.h macros.h net.h
|
2018-02-10 01:55:42 +08:00
|
|
|
subproc.o: sandbox.h user.h util.h
|
2018-02-11 00:49:15 +08:00
|
|
|
uts.o: uts.h nsjail.h logs.h
|
|
|
|
user.o: user.h nsjail.h logs.h macros.h subproc.h util.h
|
|
|
|
util.o: util.h nsjail.h logs.h macros.h
|
2018-02-10 22:50:12 +08:00
|
|
|
config.pb.o: config.pb.h
|