nsjail/Makefile

132 lines
3.8 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
2016-03-09 01:22:50 +08:00
2017-05-29 00:46:38 +08:00
EXTRA_CFLAGS := $(CFLAGS)
2016-03-10 06:51:13 +08:00
CFLAGS += -O2 -c -std=gnu11 \
2015-05-15 05:44:48 +08:00
-D_GNU_SOURCE \
-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-26 10:15:45 +08:00
-Ikafel/include \
-Iprotobuf-c-text/protobuf-c-text
2015-05-15 05:44:48 +08:00
2016-03-09 08:11:05 +08:00
LDFLAGS += -Wl,-z,now -Wl,-z,relro -pie -Wl,-z,noexecstack
2016-03-09 01:22:50 +08:00
2017-05-26 10:15:45 +08:00
BIN = nsjail
LIBS = kafel/libkafel.a
2017-05-26 07:44:16 +08:00
SRCS = nsjail.c cmdline.c config.c contain.c log.c cgroup.c mount.c net.c pid.c sandbox.c subproc.c user.c util.c uts.c
2016-03-10 06:51:13 +08:00
OBJS = $(SRCS:.c=.o)
ifdef DEBUG
CFLAGS += -g -ggdb -gdwarf-4
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
2017-05-26 10:15:45 +08:00
USE_PROTOBUF ?= yes
ifeq ($(USE_PROTOBUF), yes)
PROTOBUF_EXISTS := $(shell pkg-config --exists libprotobuf-c && echo yes)
2017-05-26 10:15:45 +08:00
ifeq ($(PROTOBUF_EXISTS), yes)
2017-05-26 07:55:02 +08:00
PROTO_DEPS = config.pb-c.h config.pb-c.c
SRCS += config.pb-c.c
2017-05-26 10:15:45 +08:00
CFLAGS += -DNSJAIL_WITH_PROTOBUF $(shell pkg-config --cflags libprotobuf-c)
LIBS += protobuf-c-text/protobuf-c-text/.libs/libprotobuf-c-text.a
LDFLAGS += $(shell pkg-config --libs libprotobuf-c)
2016-03-01 05:12:01 +08:00
endif
endif
2016-03-01 05:12:01 +08:00
2017-05-26 10:15:45 +08:00
.PHONY: all clear depend indent kafel protobuf-c-text
2015-05-15 05:44:48 +08:00
.c.o: %.c
$(CC) $(CFLAGS) $< -o $@
2017-05-26 10:15:45 +08:00
all: $(PROTO_DEPS) protobuf-c-text kafel $(BIN)
ifneq ($(PROTOBUF_EXISTS), yes)
$(info *********************************************************)
$(info * Code compiled without libprotobuf-c/libprotobuf-c-dev *)
$(info * The --config commandline option will be unavailable *)
$(info *********************************************************)
endif
2015-05-15 05:44:48 +08:00
2016-09-13 18:10:15 +08:00
$(BIN): $(OBJS) $(LIBS)
$(CC) -o $(BIN) $(OBJS) $(LIBS) $(LDFLAGS)
kafel:
ifeq ("$(wildcard kafel/Makefile)","")
git submodule update --init
endif
2017-05-26 10:15:45 +08:00
protobuf-c-text:
ifeq ("$(wildcard protobuf-c-text/configure)","")
git submodule update --init
endif
2016-09-13 18:10:15 +08:00
kafel/libkafel.a:
$(MAKE) -C kafel
2015-05-15 05:44:48 +08:00
2017-05-26 10:15:45 +08:00
protobuf-c-text/protobuf-c-text/.libs/libprotobuf-c-text.a:
2017-05-29 00:46:38 +08:00
sh -c "cd protobuf-c-text; CFLAGS=\"$(EXTRA_CFLAGS)\" ./autogen.sh;"
2017-05-26 10:15:45 +08:00
$(MAKE) -C protobuf-c-text
2017-05-26 07:55:02 +08:00
$(PROTO_DEPS): config.proto
protoc-c --c_out=. config.proto
2015-05-15 05:44:48 +08:00
clean:
$(RM) core Makefile.bak $(OBJS) $(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-05-08 21:50:29 +08:00
makedepend -Y -Ykafel/include -- -- $(SRCS)
2015-05-15 05:44:48 +08:00
indent:
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.
2016-03-03 22:37:04 +08:00
nsjail.o: nsjail.h common.h cmdline.h log.h net.h subproc.h
2017-05-27 05:07:47 +08:00
cmdline.o: cmdline.h common.h config.h log.h mount.h util.h user.h
2017-05-27 07:16:12 +08:00
config.o: common.h config.h log.h mount.h user.h util.h
contain.o: contain.h common.h cgroup.h log.h mount.h net.h pid.h user.h
contain.o: 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
config.pb-c.o: config.pb-c.h