nsjail/Makefile

131 lines
4.5 KiB
Makefile
Raw Normal View History

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.
2020-08-15 08:07:30 +08:00
PKG_CONFIG=$(shell command -v pkg-config 2> /dev/null)
ifeq ($(PKG_CONFIG),)
$(error "Install pkg-config to make it work")
endif
2016-03-01 02:09:39 +08:00
CC ?= gcc
CXX ?= g++
2016-03-09 01:22:50 +08:00
COMMON_FLAGS += -O2 -c \
-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 \
2018-06-19 09:58:17 +08:00
-fPIE \
-Wformat -Wformat-security -Wno-format-nonliteral \
2017-05-08 21:50:29 +08:00
-Wall -Wextra -Werror \
-Ikafel/include
2015-05-15 05:44:48 +08:00
CXXFLAGS += $(USER_DEFINES) $(COMMON_FLAGS) $(shell pkg-config --cflags protobuf) \
-std=c++14 -fno-exceptions -Wno-unused -Wno-unused-parameter
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
LIBS = kafel/libkafel.a
SRCS_CXX = caps.cc cgroup.cc cgroup2.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
SRCS_H = $(SRCS_CXX:.cc=.h) macros.h
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
CXXFLAGS += -g -ggdb -gdwarf-4
2016-03-10 06:51:13 +08:00
endif
2016-03-09 01:49:06 +08:00
NL3_EXISTS := $(shell pkg-config --exists libnl-route-3.0 && echo yes)
ifeq ($(NL3_EXISTS), yes)
2019-01-21 01:37:47 +08:00
CXXFLAGS += $(shell pkg-config --cflags libnl-route-3.0)
LDFLAGS += $(shell pkg-config --libs libnl-route-3.0)
endif
2017-09-17 00:10:28 +08:00
.PHONY: all clean depend indent
.o: %.cc
$(CXX) $(CXXFLAGS) $< -o $@
2017-09-16 06:31:53 +08:00
all: $(BIN)
2015-05-15 05:44:48 +08:00
$(BIN): $(LIBS) $(OBJS)
ifneq ($(NL3_EXISTS), yes)
2019-01-21 01:37:47 +08:00
$(warning "============================================================")
$(warning "You probably miss libnl3(-dev)/libnl-route-3(-dev) libraries")
$(warning "============================================================")
endif
$(CXX) -o $(BIN) $(OBJS) $(LIBS) $(LDFLAGS)
2016-09-13 18:10:15 +08:00
.PHONY: kafel_init
kafel_init:
ifeq ("$(wildcard kafel/Makefile)","")
git submodule update --init
endif
kafel/include/kafel.h: kafel_init
# LDFLAGS is unset as a workaround for Kafel using the parent LDFLAGS
# incorrectly.
kafel/libkafel.a: kafel_init
LDFLAGS="" CFLAGS=-fPIE $(MAKE) -C kafel
# Sequence of proto deps, which doesn't fit automatic make rules
$(SRCS_PB_O): $(SRCS_PB_H) $(SRCS_PB_CXX)
2017-09-16 22:43:01 +08:00
$(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
2018-02-14 00:09:31 +08:00
.PHONY: clean
2015-05-15 05:44:48 +08:00
clean:
$(RM) core Makefile.bak $(OBJS) $(SRCS_PB_CXX) $(SRCS_PB_H) $(SRCS_PB_O) $(BIN)
ifneq ("$(wildcard kafel/Makefile)","")
2016-09-13 18:10:15 +08:00
$(MAKE) -C kafel clean
endif
2015-05-15 05:44:48 +08:00
2018-02-14 00:09:31 +08:00
.PHONY: depend
2018-02-17 22:28:13 +08:00
depend: all
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
2018-02-14 00:09:31 +08:00
.PHONY: indent
2015-05-15 05:44:48 +08:00
indent:
clang-format -style="{BasedOnStyle: google, IndentWidth: 8, UseTab: Always, IndentCaseLabels: false, ColumnLimit: 100, AlignAfterOpenBracket: false, AllowShortFunctionsOnASingleLine: false, AlwaysBreakBeforeMultilineStrings: false}" -i -sort-includes $(SRCS_H) $(SRCS_CXX)
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.
caps.o: caps.h nsjail.h logs.h macros.h util.h
cgroup.o: cgroup.h nsjail.h logs.h util.h
cgroup2.o: cgroup2.h nsjail.h logs.h util.h
2018-06-08 00:37:17 +08:00
cmdline.o: cmdline.h nsjail.h caps.h config.h logs.h macros.h mnt.h user.h
cmdline.o: util.h
config.o: config.h nsjail.h caps.h cmdline.h config.pb.h logs.h macros.h
2018-02-17 22:27:27 +08:00
config.o: mnt.h user.h util.h
2019-08-04 15:50:34 +08:00
contain.o: contain.h nsjail.h caps.h cgroup.h cpu.h logs.h macros.h mnt.h
2019-01-01 18:36:02 +08:00
contain.o: net.h pid.h user.h util.h uts.h
cpu.o: cpu.h nsjail.h logs.h util.h
2018-04-13 05:49:10 +08:00
logs.o: logs.h macros.h util.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
2022-11-23 05:15:01 +08:00
nsjail.o: nsjail.h cgroup2.h cmdline.h logs.h macros.h net.h sandbox.h
nsjail.o: subproc.h util.h
pid.o: pid.h nsjail.h logs.h subproc.h
2019-01-22 05:37:30 +08:00
sandbox.o: sandbox.h nsjail.h kafel/include/kafel.h logs.h util.h
2019-08-04 15:50:34 +08:00
subproc.o: subproc.h nsjail.h cgroup.h cgroup2.h contain.h logs.h macros.h
subproc.o: net.h sandbox.h user.h util.h
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-17 22:27:27 +08:00
config.pb.o: config.pb.h