nsjail/Makefile

116 lines
3.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.
#
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 \
-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 \
-Ikafel/include
2015-05-15 05:44:48 +08:00
2017-09-16 00:12:18 +08:00
CFLAGS += $(COMMON_FLAGS) -std=gnu11
CXXFLAGS += $(COMMON_FLAGS) $(shell pkg-config --cflags protobuf) -std=c++11 -Wno-unused
LDFLAGS += -Wl,-z,now -Wl,-z,relro -pie -Wl,-z,noexecstack -lpthread -lcap $(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_C = nsjail.c caps.c cmdline.c contain.c log.c cgroup.c mount.c net.c pid.c sandbox.c subproc.c user.c util.c uts.c cpu.c
SRCS_CXX = config.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)
2017-09-16 22:39:55 +08:00
OBJS = $(SRCS_C:.c=.o) $(SRCS_CXX:.cc=.o) $(SRCS_PB_CXX:.cc=.o)
2016-03-10 06:51:13 +08:00
ifdef DEBUG
CFLAGS += -g -ggdb -gdwarf-4
CXXFLAGS += -g -ggdb -gdwarf-4
2016-03-10 06:51:13 +08:00
endif
2016-03-09 01:49:06 +08:00
USE_NL3 ?= yes
ifeq ($(USE_NL3), yes)
NL3_EXISTS := $(shell pkg-config --exists libnl-route-3.0 && echo yes)
ifeq ($(NL3_EXISTS), yes)
CFLAGS += -DNSJAIL_NL3_WITH_MACVLAN $(shell pkg-config --cflags libnl-route-3.0)
LDFLAGS += $(shell pkg-config --libs libnl-route-3.0)
endif
endif
.PHONY: all clear depend indent
2015-05-15 05:44:48 +08:00
.c.o: %.c
$(CC) $(CFLAGS) $< -o $@
.cc.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)
$(CXX) -o $(BIN) $(OBJS) $(LIBS) $(LDFLAGS)
2016-09-13 18:10:15 +08:00
kafel/libkafel.a:
ifeq ("$(wildcard kafel/Makefile)","")
git submodule update --init
endif
$(MAKE) -C kafel
2017-09-16 22:43:01 +08:00
$(SRCS_PB_O): $(SRCS_PB_CXX) $(SRCS_PB_H)
2017-09-16 22:39:55 +08:00
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
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)
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
depend:
2017-09-16 06:31:53 +08:00
makedepend -Y -Ykafel/include -- -- $(SRCS_C) $(SRCS_CXX) $(SRCS_PB)
2015-05-15 05:44:48 +08:00
indent:
clang-format --style=WebKit -i -sort-includes *.c *.h $(SRCS_CXX)
indent -linux -l100 -lc100 *.c *.h; rm -f *~
2015-05-15 05:44:48 +08:00
# DO NOT DELETE THIS LINE -- make depend depends on it.
nsjail.o: nsjail.h common.h caps.h cmdline.h log.h net.h subproc.h util.h
2017-07-06 17:37:41 +08:00
caps.o: caps.h common.h log.h util.h
cmdline.o: cmdline.h common.h caps.h config.h log.h mount.h user.h util.h
contain.o: contain.h common.h caps.h cgroup.h cpu.h log.h mount.h net.h pid.h
contain.o: user.h util.h uts.h
2015-05-15 05:44:48 +08:00
log.o: log.h common.h
2016-06-19 19:54:36 +08:00
cgroup.o: cgroup.h common.h log.h util.h
mount.o: mount.h common.h log.h subproc.h util.h
2016-10-18 04:53:31 +08:00
net.o: net.h common.h log.h subproc.h
pid.o: pid.h common.h log.h subproc.h
2017-05-09 00:40:21 +08:00
sandbox.o: sandbox.h common.h kafel/include/kafel.h log.h
2016-06-19 21:50:25 +08:00
subproc.o: subproc.h common.h cgroup.h contain.h log.h net.h sandbox.h user.h
subproc.o: util.h
2016-10-18 04:53:31 +08:00
user.o: user.h common.h log.h subproc.h util.h
2016-03-03 22:37:04 +08:00
util.o: util.h common.h log.h
2016-03-03 23:09:25 +08:00
uts.o: uts.h common.h log.h
cpu.o: cpu.h common.h log.h util.h
2017-09-16 06:31:53 +08:00
config.o: common.h caps.h config.h log.h mount.h user.h util.h config.pb.h
config.pb.o: config.pb.h