Skip to content
This repository was archived by the owner on Oct 30, 2025. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 117 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# Copyright 2019 The Souper Authors. 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.

# Invoke with `make deps Build=Debug` or `make deps` (defaults to Release)

llvm_branch=tags/RELEASE_700/final
llvm_build_type=$(Build)
alivedir=third_party/alive2
alive_builddir=$(alivedir)/build
hiredis_commit=010756025e8cefd1bc66c6d4ed3b1648ef6f1f95
klee_repo=https://github.com/rsas/klee
klee_branch=pure-bv-qf-llvm-7.0
hiredisdir=third_party/hiredis
kleedir=third_party/klee
llvmdir=third_party/llvm
llvm_installdir=$(llvmdir)/$(llvm_build_type)
llvm_builddir=$(llvmdir)/${llvm_build_type}-build
cmake_flags=-DCMAKE_INSTALL_PREFIX="../../../$(llvm_installdir)" -DLLVM_ENABLE_ASSERTIONS=On -DLLVM_TARGETS_TO_BUILD=host -DCMAKE_BUILD_TYPE="$(llvm_build_type)"
Build=Release
# $(Build) will not be set here if assigned through the command line
# TODO: Make the targets build-type specific, currently you have to nuke third_party for changing build type
NINJA=ninja
# Override NINJA from the command line with something like NINJA="ninja -j1" if you are running out of memory

deps : alive2 llvm hiredis klee
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: let's be consistent and not have any space before the colon.


llvm : third_party/llvm llvm-build
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we shouldn't rely on the order of dependencies here. if you want llvm-build to be executed after third_party/llvm, then i think better to make third_party/llvm a dependency of llvm-build. Parallel make can mess things up otherwise. See: https://stackoverflow.com/questions/9159960/order-of-processing-components-in-makefile/9160175#9160175

# we want these but they don't get installed by default
cp $(llvm_builddir)/bin/llvm-lit $(llvm_installdir)/bin/
cp $(llvm_builddir)/bin/FileCheck $(llvm_installdir)/bin/
cp $(llvm_builddir)/lib/libgtest_main.a $(llvm_installdir)/lib/
cp $(llvm_builddir)/lib/libgtest.a $(llvm_installdir)/lib/

llvm-build:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably needs to be .PHONY to keep llvm-build target always out-of-date.

@echo "Building LLVM"

mkdir -p $(llvm_builddir)

if [ -n "`which ninja`" ]; then\
$(NINJA) -C $(llvm_builddir);\
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need something like set -e, so we abort on the first failure?

$(NINJA) -C $(llvm_builddir) install;\
else\
make -C $(llvm_builddir) -j4;\
make -C $(llvm_builddir) -j4 install;\
fi
alive2 : third_party/alive2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same .PHONY thing as above. There are other targets in this file as well which are not marked as .PHONY. I guess the problem will start appearing when there are files in the filesystem with exact same name as these targets. make won't build these targets because it will think that these targets are already built (even though you want them to be built unconditionally everytime).

@echo "Building alive2"
mkdir -p $(alivedir) $(alive_builddir)
if [ -n "`which ninja`" ]; then\
(cd $(alive_builddir) && cmake ../alive2 -DCMAKE_BUILD_TYPE=$(llvm_build_type) -GNinja) && $(NINJA) -C $(alive_builddir);\
else\
(cd $(alive_builddir) && cmake ../alive2 -DCMAKE_BUILD_TYPE=$(llvm_build_type)) && make -C $(alive_builddir) -j4;\
fi

hiredis : third_party/hiredis
@echo "Installing hiredis"
(cd $(hiredisdir) && git fetch)
mkdir -p $(hiredisdir)/install/include/hiredis
mkdir -p $(hiredisdir)/install/lib
(cd $(hiredisdir) && git checkout $(hiredis_commit) && make libhiredis.a &&\
cp -r hiredis.h async.h read.h sds.h adapters install/include/hiredis &&\
cp libhiredis.a install/lib)

klee : third_party/klee
(cd $(kleedir) && git fetch)


third_party/llvm : patches/disable-instcombine-select-to-logic.patch patches/enable-instcombine-switch.patch
@echo "Fetching LLVM"
mkdir -p third_party/llvm
svn co https://llvm.org/svn/llvm-project/llvm/${llvm_branch} $(llvmdir)
svn co https://llvm.org/svn/llvm-project/cfe/${llvm_branch} $(llvmdir)/tools/clang
svn co https://llvm.org/svn/llvm-project/compiler-rt/${llvm_branch} $(llvmdir)/projects/compiler-rt
svn co https://llvm.org/svn/llvm-project/libcxx/${llvm_branch} $(llvmdir)/projects/libcxx
svn co https://llvm.org/svn/llvm-project/libcxxabi/${llvm_branch} $(llvmdir)/projects/libcxxabi

@echo "Patching LLVM"
# Disable the broken select -> logic optimizations
patch $(llvmdir)/lib/Transforms/InstCombine/InstCombineSelect.cpp < patches/disable-instcombine-select-to-logic.patch
# Apply instcombine switch patch
patch -d $(llvmdir) -p0 -i ../../patches/enable-instcombine-switch.patch

@echo "Configuring LLVM"

mkdir -p $(llvm_builddir)

if [ -n "`which ninja`" ]; then\
(cd $(llvm_builddir) && cmake ../ -G Ninja $(cmake_flags));\
else\
(cd $(llvm_builddir) && cmake ../ $(cmake_flags));\
fi

third_party/alive2 :
@echo "Fetching alive2"
llvm_build_type=$(Build)
mkdir -p third_party/alive2
git clone https://github.com/manasij7479/alive2.git $(alivedir)/alive2

third_party/hiredis :
@echo "Fetching hiredis"
mkdir -p third_party/hiredis
git clone https://github.com/redis/hiredis.git $(hiredisdir)

third_party/klee :
@echo "Fetching KLEE"
git clone -b $(klee_branch) $(klee_repo) $(kleedir)