Skip to content

Commit

Permalink
Revert "no more makefiles"
Browse files Browse the repository at this point in the history
This reverts commit 223e37a.
  • Loading branch information
geohot committed Nov 20, 2019
1 parent 487fbd0 commit e3a6bde
Show file tree
Hide file tree
Showing 2 changed files with 150 additions and 0 deletions.
62 changes: 62 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
PWD := $(shell pwd)

SRCS := log.capnp car.capnp

GENS := gen/cpp/car.capnp.c++ gen/cpp/log.capnp.c++
JS := gen/js/car.capnp.js gen/js/log.capnp.js

UNAME_M ?= $(shell uname -m)

GENS += gen/c/car.capnp.c gen/c/log.capnp.c gen/c/include/c++.capnp.h gen/c/include/java.capnp.h

ifeq ($(UNAME_M),x86_64)

ifneq (, $(shell which capnpc-java))
GENS += gen/java/Car.java gen/java/Log.java
else
$(warning capnpc-java not found, skipping java build)
endif

endif


ifeq ($(UNAME_M),aarch64)
CAPNPC=PATH=$(PWD)/../phonelibs/capnp-cpp/aarch64/bin/:$$PATH capnpc
else
CAPNPC=capnpc
endif

.PHONY: all
all: $(GENS)
js: $(JS)

.PHONY: clean
clean:
rm -rf gen
rm -rf node_modules
rm -rf package-lock.json

gen/c/%.capnp.c: %.capnp
@echo "[ CAPNPC C ] $@"
mkdir -p gen/c/
$(CAPNPC) '$<' -o c:gen/c/

gen/js/%.capnp.js: %.capnp
@echo "[ CAPNPC JavaScript ] $@"
mkdir -p gen/js/
sh ./generate_javascript.sh

gen/cpp/%.capnp.c++: %.capnp
@echo "[ CAPNPC C++ ] $@"
mkdir -p gen/cpp/
$(CAPNPC) '$<' -o c++:gen/cpp/

gen/java/Car.java gen/java/Log.java: $(SRCS)
@echo "[ CAPNPC java ] $@"
mkdir -p gen/java/
$(CAPNPC) $^ -o java:gen/java

# c-capnproto needs some empty headers
gen/c/include/c++.capnp.h gen/c/include/java.capnp.h:
mkdir -p gen/c/include
touch '$@'
88 changes: 88 additions & 0 deletions messaging/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
CXX := clang++
CC := clang

BASEDIR = ../..
PHONELIBS = ../../phonelibs

CXXFLAGS := -g -O3 -fPIC -std=c++11 -Wall -Wextra -Wshadow -Weffc++ -Wstrict-aliasing -Werror -MMD

LDLIBS=-lm -lstdc++ -lrt -lpthread

UNAME_M := $(shell uname -m)

YAML_FLAGS = -I$(PHONELIBS)/yaml-cpp/include -I../
YAML_LIB = $(abspath $(PHONELIBS)/yaml-cpp/lib/libyaml-cpp.a)

ifeq ($(UNAME_M),aarch64)
LDFLAGS += -llog -lgnustl_shared
ZMQ_LIBS = /usr/lib/libzmq.a
endif
ifeq ($(UNAME_M),x86_64)
ZMQ_FLAGS = -I$(BASEDIR)/phonelibs/zmq/x64/include
ZMQ_LIBS = $(abspath $(BASEDIR)/phonelibs/zmq/x64/lib/libzmq.a)
YAML_DIR = $(PHONELIBS)/yaml-cpp/x64/lib/
YAML_LIB = $(abspath $(PHONELIBS)/yaml-cpp/x64/lib/libyaml-cpp.a)
endif

ifdef ASAN
CXXFLAGS += -fsanitize=address -fno-omit-frame-pointer
LDFLAGS += -fsanitize=address
endif

CXXFLAGS += $(ZMQ_FLAGS) $(YAML_FLAGS)

OBJS := messaging.o impl_zmq.o impl_msgq.o msgq.o
DEPS=$(OBJS:.o=.d)

TEST_OBJS := test_runner.o msgq_tests.o msgq.o
TEST_DEPS=$(TEST_OBJS:.o=.d)

.PRECIOUS: $(OBJS)
.PHONY: all clean test
all: bridge messaging.a messaging_pyx.so messaging.so

test: test_runner
./test_runner

test_runner: $(TEST_OBJS)

demo: messaging.a demo.o
$(CC) $(LDFLAGS) $^ $(LDLIBS) -L. -l:messaging.a -o '$@'

bridge: messaging.a bridge.o
$(CC) $(LDFLAGS) $^ $(LDLIBS) -L. -l:messaging.a -o '$@'

messaging_pyx.so: messaging.a messaging_pyx_setup.py messaging_pyx.pyx messaging.pxd
python3 messaging_pyx_setup.py build_ext --inplace
rm -rf build
rm -f messaging_pyx.cpp

messaging.so: $(OBJS)
@echo "[ LINK ] $@"
mkdir -p libs_so; \
cd libs_so; \
ar -x $(ZMQ_LIBS); \
ar -x $(YAML_LIB);

$(CXX) -shared $(LDFLAGS) $^ $(LDLIBS) libs_so/*.o -o '$@'
chmod 644 '$@'
rm -r libs_so

%.a: $(OBJS)
@echo "[ LINK ] $@"
mkdir -p libs_a; \
cd libs_a; \
ar -x $(ZMQ_LIBS); \
ar -x $(YAML_LIB);

ar rcsD '$@' $^ libs_a/*.o
rm -r libs_a

../services.h: ../services.py ../service_list.yaml
python3 ../services.py > ../services.h

clean:
@echo "[ CLEAN ]"
rm -rf *.so *.a bridge demo libs_a libs_so test_runner $(OBJS) $(DEPS) $(TEST_OBJS) $(TEST_DEPS)

-include $(DEPS)

0 comments on commit e3a6bde

Please sign in to comment.