Skip to content

Commit

Permalink
Move source to src, better build system
Browse files Browse the repository at this point in the history
  • Loading branch information
happyCoder92 committed May 13, 2017
1 parent b54cfec commit cc60cae
Show file tree
Hide file tree
Showing 24 changed files with 153 additions and 126 deletions.
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
*.o

# Generated files
/lexer.h
/lexer.c
/parser.h
/parser.c
/src/lexer.h
/src/lexer.c
/src/parser.h
/src/parser.c

# Backup files
*.bak
Expand Down
91 changes: 5 additions & 86 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Kafel - Makefile
# -----------------------------------------
#
# Copyright 2016 Google Inc. All Rights Reserved.
# Copyright 2017 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.
Expand All @@ -17,90 +17,9 @@
# limitations under the License.
#

OBJCOPY?=objcopy
SUBDIRS:=src tools

CFLAGS+=-std=gnu11 -I./include -Wall -Wextra -Werror
CFLAGS+=-fPIC -fvisibility=hidden
GENERATED_SRCS:=lexer.c parser.c
GENERATED:=lexer.h parser.h ${GENERATED_SRCS}
TEMPORARY:=libkafel_r.o libkafel.o
SYSCALL_LISTS:=amd64_syscalls.c \
arm_syscalls.c
SRCS:=kafel.c \
context.c \
codegen.c \
expression.c \
policy.c \
range_rules.c \
syscall.c \
${GENERATED_SRCS} \
$(SYSCALL_LISTS:%.c=syscalls/%.c)
GENERATED_OBJECTS:=$(GENERATED_SRCS:.c=.o)
OBJECTS:=$(SRCS:.c=.o)
TARGET:=libkafel.so
STATIC_TARGET:=libkafel.a
VERSION:=1
include build/Makefile.mk

ifdef DEBUG
CFLAGS += -g -ggdb -gdwarf-4
else
CFLAGS += -O2
endif

ifdef ASAN
CFLAGS += -fsanitize=address
endif

.PHONY: all clean depend format tools

all: ${TARGET} ${STATIC_TARGET}

tools:
$(MAKE) -C tools

# Hard to fix those in generated code so just disable
${GENERATED_OBJECTS}: CFLAGS+=-Wno-error

clean:
$(RM) Makefile.bak ${GENERATED} ${TEMPORARY} ${OBJECTS} ${TARGET} ${STATIC_TARGET}
$(MAKE) -C tools clean

${TARGET}: ${OBJECTS}
$(CC) -Wl,-soname,${TARGET}.${VERSION} -shared $^ -o $@

${STATIC_TARGET}: ${OBJECTS}
$(LD) -r ${OBJECTS} -o libkafel_r.o
$(OBJCOPY) --localize-hidden libkafel_r.o libkafel.o
$(RM) libkafel_r.o
$(AR) rcs $@ libkafel.o
$(RM) libkafel.o

lexer.h lexer.c: lexer.l
flex $<

parser.h parser.c: parser.y
bison $<

depend:
makedepend -Y. $(SRCS)
$(MAKE) -C tools depend

format:
clang-format -i -style=Google *.c *.h syscalls/*.c
$(MAKE) -C tools format

# DO NOT DELETE THIS LINE -- make depend depends on it.

kafel.o: parser.h context.h policy.h expression.h syscall.h codegen.h
kafel.o: common.h lexer.h
context.o: context.h policy.h expression.h syscall.h common.h
codegen.o: codegen.h context.h policy.h expression.h syscall.h common.h
codegen.o: range_rules.h
expression.o: expression.h common.h
policy.o: policy.h expression.h common.h
range_rules.o: range_rules.h policy.h expression.h common.h syscall.h
syscall.o: syscall.h common.h
lexer.o: parser.h context.h policy.h expression.h syscall.h
parser.o: parser.h context.h policy.h expression.h syscall.h lexer.h
syscalls/amd64_syscalls.o: syscall.h
syscalls/arm_syscalls.o: syscall.h
all: src
# DO NOT DELETE
63 changes: 63 additions & 0 deletions build/Makefile.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#
# Kafel - Makefile skeleton
# -----------------------------------------
#
# Copyright 2017 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.
#

PROJECT_ROOT?=
CFLAGS+=-std=gnu11 -I${PROJECT_ROOT}include -Wall -Wextra -Werror

GENERATED_OBJECTS:=$(GENERATED_SRCS:.c=.o)
OBJECTS:=$(SRCS:.c=.o)

ifdef DEBUG
CFLAGS += -g -ggdb -gdwarf-4
else
CFLAGS += -O2
endif

ifdef ASAN
CFLAGS += -fsanitize=address
endif

.PHONY: all clean depend format $(SUBDIRS)

all: ${TARGET}

$(SUBDIRS):
$(MAKE) -C $@ PROJECT_ROOT=../${PROJECT_ROOT}

clean:
$(RM) Makefile.bak ${GENERATED} ${TEMPORARY} ${OBJECTS} ${TARGET} ${STATIC_TARGET}
for dir in ${SUBDIRS}; do \
$(MAKE) -C $$dir PROJECT_ROOT=../${PROJECT_ROOT} clean; \
done


depend:
makedepend -Y. $(SRCS)
for dir in ${SUBDIRS}; do \
$(MAKE) -C $$dir PROJECT_ROOT=../${PROJECT_ROOT} depend; \
done

format:
ifdef SRCS
clang-format -i -style=Google ${SRCS}
endif
clang-format -i -style=Google *.h || true
for dir in ${SUBDIRS}; do \
$(MAKE) -C $$dir PROJECT_ROOT=../${PROJECT_ROOT} format; \
done
77 changes: 77 additions & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#
# Kafel - Makefile
# -----------------------------------------
#
# Copyright 2016 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.
#

OBJCOPY?=objcopy

CFLAGS+=-fPIC -fvisibility=hidden
GENERATED_SRCS:=lexer.c parser.c
GENERATED:=lexer.h parser.h ${GENERATED_SRCS}
TEMPORARY:=libkafel_r.o libkafel.o
SYSCALL_LISTS:=amd64_syscalls.c \
arm_syscalls.c
SRCS:=kafel.c \
context.c \
codegen.c \
expression.c \
policy.c \
range_rules.c \
syscall.c \
${GENERATED_SRCS} \
$(SYSCALL_LISTS:%.c=syscalls/%.c)
DYNAMIC_TARGET:=${PROJECT_ROOT}libkafel.so
STATIC_TARGET:=${PROJECT_ROOT}libkafel.a
TARGET=${DYNAMIC_TARGET} ${STATIC_TARGET}
VERSION:=1

include ${PROJECT_ROOT}build/Makefile.mk

# Hard to fix those in generated code so just disable
${GENERATED_OBJECTS}: CFLAGS+=-Wno-error

${DYNAMIC_TARGET}: ${OBJECTS}
$(CC) -Wl,-soname,$@.${VERSION} -shared $^ -o $@

${STATIC_TARGET}: ${OBJECTS}
$(LD) -r ${OBJECTS} -o libkafel_r.o
$(OBJCOPY) --localize-hidden libkafel_r.o libkafel.o
$(RM) libkafel_r.o
$(AR) rcs $@ libkafel.o
$(RM) libkafel.o

lexer.h lexer.c: lexer.l
flex $<

parser.h parser.c: parser.y
bison $<

# DO NOT DELETE THIS LINE -- make depend depends on it.

kafel.o: parser.h context.h policy.h expression.h syscall.h codegen.h
kafel.o: common.h lexer.h
context.o: context.h policy.h expression.h syscall.h common.h
codegen.o: codegen.h context.h policy.h expression.h syscall.h common.h
codegen.o: range_rules.h
expression.o: expression.h common.h
policy.o: policy.h expression.h common.h
range_rules.o: range_rules.h policy.h expression.h common.h syscall.h
syscall.o: syscall.h common.h
lexer.o: parser.h context.h policy.h expression.h syscall.h
parser.o: parser.h context.h policy.h expression.h syscall.h lexer.h
syscalls/amd64_syscalls.o: syscall.h
syscalls/arm_syscalls.o: syscall.h
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 2 additions & 12 deletions tools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,7 @@

SUBDIRS:=dump_policy_bpf

.PHONY: all depend format ${SUBDIRS}
include ${PROJECT_ROOT}build/Makefile.mk

all: ${SUBDIRS}
${SUBDIRS}:
$(MAKE) -C $@

depend:
$(MAKE) -C ${SUBDIRS} depend

format:
$(MAKE) -C ${SUBDIRS} format

clean:
${MAKE} -C ${SUBDIRS} clean
# DO NOT DELETE
26 changes: 2 additions & 24 deletions tools/dump_policy_bpf/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,17 @@
# limitations under the License.
#

PROJECT_ROOT:=../../
CFLAGS+=-std=gnu11 -I${PROJECT_ROOT}include -Wall
SRCS:=main.c disasm.c
OBJECTS:=$(SRCS:.c=.o)
TARGET:=dump_policy_bpf
LIBS:=${PROJECT_ROOT}libkafel.a

ifdef DEBUG
CFLAGS += -g -ggdb -gdwarf-4
else
CFLAGS += -O2
endif
include ${PROJECT_ROOT}build/Makefile.mk

ifdef ASAN
CFLAGS += -fsanitize=address
endif

.PHONY: all clean depend format

all: ${TARGET}

clean:
$(RM) Makefile.bak ${OBJECTS} ${TARGET}
CFLAGS+=-Wno-error=type-limits

${TARGET}: ${OBJECTS}
$(CC) ${CFLAGS} $^ ${LIBS} -o $@

depend:
makedepend -Y. $(SRCS)

format:
clang-format -i -style=Google *.c *.h

# DO NOT DELETE THIS LINE -- make depend depends on it.

main.o: disasm.h
Expand Down

0 comments on commit cc60cae

Please sign in to comment.