Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install build rules #381

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletions Makefile.macros
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@
# - libfoo_TEST_EXTRA_LDFLAGS:
# additional LDFLAGS to be passed to link each test binary;
# use this to pull in external libraries (not built in this project)
# - libfoo_SOVERSION:
# SOVERSION that is recorded in linker options whenever a binary
# is dynamically linked against this library
# Should be increased for every incompatible ABI change if library
# is deemed to be ABI-stable).
# REQUIRED if shared library builds are enabled
# - libfoo_VERSION:
# Detailed version of library. Should be increased with every
# feature addition if library is assumed to be forward-ABI-compatible
# REQUIRED if shared library builds are enabled
#
# Depending on configuration builds only static or both
# static and dynamic library. Depending on configuration
Expand Down
34 changes: 22 additions & 12 deletions Makefile.rules
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ EXECUTABLES += $(TARGET_EXECUTABLES) $(TEST_EXECUTABLES) $(COVERAGE_EXECUTABLES)

GENERATED_FILES += $(EXECUTABLES)

all: $(SHARED_LIBRARIES) $(STATIC_LIBRARIES) $(EXECUTABLES)
all: $(SHARED_LIBRARIES) $(STATIC_LIBRARIES) $(EXECUTABLES) $(PKGCONFIG_FILES)

# commands for generating various types of targets

Expand All @@ -25,27 +25,34 @@ $(BUILD_OUT_PREFIX)%.la: %.cpp
$(CXX) -c $(CXXFLAGS) $(CPPFLAGS) -o $@ $<

# static libraries
$(BUILD_OUT_PREFIX)%.a: BASENAME=$(patsubst %.a, %, $@)
$(BUILD_OUT_PREFIX)%.a: BASENAME=$(patsubst $(BUILD_OUT_PREFIX)%.a, %, $@)
$(BUILD_OUT_PREFIX)%.a:
@mkdir -p $(dir $@)
rm -f $@
ar cqv $@ $^
ranlib $@

# dynamic libraries
$(BUILD_OUT_PREFIX)%.so: BASENAME=$(patsubst %.so,%,$@)
$(BUILD_OUT_PREFIX)%.so: BASENAME=$(patsubst $(BUILD_OUT_PREFIX)%.so,%,$@)
$(BUILD_OUT_PREFIX)%.so:
@mkdir -p $(dir $@)
rm -rf $@ $@.$($(BASENAME)_VERSION) $@.$($(BASENAME)_SOVERSION)
$(DYNAMIC_MODULE_LINK) -o $@.$($(BASENAME)_VERSION) $^ -Wl,-soname -Wl,$@.$($(BASENAME)_SOVERSION) $(LIBS)
ln -sf $@.$($(BASENAME)_VERSION) $@.$($(BASENAME)_SOVERSION)
ln -sf $@.$($(BASENAME)_VERSION) $@
$(DYNAMIC_MODULE_LINK) -o $@.$($(BASENAME)_VERSION) $^ -Wl,-soname -Wl,$(BASENAME).so.$($(BASENAME)_SOVERSION) $(LIBS)
ln -sf $(BASENAME).so.$($(BASENAME)_VERSION) $@.$($(BASENAME)_SOVERSION)
ln -sf $(BASENAME).so.$($(BASENAME)_VERSION) $@

# binaries
$(EXECUTABLES):
@mkdir -p $(dir $@)
$(EXECUTABLE_LINK) -o $@ $(filter %.la, $^) $(filter %.lo, $^) $(LDFLAGS) $(LIBS)

################################################################################
# pkgconfig substitution rules

$(BUILD_OUT_PREFIX)%.pc: %.pc.in
@mkdir -p $(dir $@)
sed -e "s!@libdir@!$(libdir)!" -e "s!@includedir@!$(includedir)!" <$^ >$@

################################################################################
# Installation rules

Expand All @@ -68,11 +75,12 @@ install-static: $(STATIC_LIBRARIES)
$(INSTALL) -m 644 -v $$file $(DESTDIR)$(libdir)/ ; \
done

install-shared: $(patsubst %.so,install-shared-%,$(SHARED_LIBRARIES))
install-shared: $(patsubst $(BUILD_OUT_PREFIX)%.so,install-shared-%,$(SHARED_LIBRARIES))
install-shared-%: BASENAME=$(patsubst install-shared-%,%,$@)
install-shared-%:
echo "$@"
mkdir -p $(DESTDIR)$(libdir)/
$(INSTALL) -m 755 -v $(BASENAME).so.$($(BASENAME)_VERSION) $(DESTDIR)$(libdir)/
$(INSTALL) -m 755 -v $(BUILD_OUT_PREFIX)$(BASENAME).so.$($(BASENAME)_VERSION) $(DESTDIR)$(libdir)/
$(RM) -rf $(DESTDIR)$(libdir)/$(BASENAME).so $(DESTDIR)$(libdir)/$(BASENAME).so.$($(BASENAME)_SOVERSION)
ln -sf $(BASENAME).so.$($(BASENAME)_VERSION) $(DESTDIR)$(libdir)/$(BASENAME).so
ln -sf $(BASENAME).so.$($(BASENAME)_VERSION) $(DESTDIR)$(libdir)/$(BASENAME).so.$($(BASENAME)_SOVERSION)
Expand Down Expand Up @@ -151,24 +159,26 @@ $(BUILD_OUT_PREFIX)%.coverage.la: %.cpp
$(COVERAGE_TESTS): $(BUILD_OUT_PREFIX)%.coverage : $(BUILD_OUT_PREFIX)%.coverage.la
$(COVERAGE_TESTS): LDFLAGS += -pthread $(COVERAGEFLAGS)

coverage: $(COVERAGE_TESTS) .PHONY
coverage: $(COVERAGE_TESTS)
for CTEST in $(COVERAGE_TESTS) ; do $$CTEST ; done
mkdir -p $(BUILD_OUT_PREFIX)coverage
gcovr $(BUILD_OUT_PREFIX) --html-details -o $(BUILD_OUT_PREFIX)coverage/coverage.html

endif

.PHONY: coverage

################################################################################
# Documentation rules

docclean:
rm -rf doc
rm -rf docs

docs: .PHONY
docs:
mkdir -p docs
doxygen doxygen.conf

.PHONY:
.PHONY: docs

#################################################################################
# Clang format rules
Expand Down
35 changes: 35 additions & 0 deletions configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ set -eu
# Default values for all tunables.
TARGET="release"
ENABLE_ASSERTS="no"
ENABLE_SHARED="no"
LLVM_CONFIG_BIN="llvm-config-16"
ENABLE_COVERAGE="no"
ENABLE_HLS=
CIRCT_PATH=
ENABLE_MLIR=
MLIR_PATH=
MLIR_LDFLAGS=
INSTALL=install
prefix="/usr/local"
includedir=""
libdir=""

function usage()
{
Expand All @@ -27,6 +32,7 @@ function usage()
echo " --enable-mlir PATH Sets the path to the MLIR RVSDG Dialect and enables"
echo " building the MLIR backend and frontend. [${MLIR_PATH}]"
echo " --enable-coverage Enable test coverage computation target."
echo " --enable-shared Enable building shared libraries."
echo " --help Prints this message and stops."
echo
echo "Influential variables that can be set:"
Expand All @@ -51,6 +57,10 @@ while [[ "$#" -ge 1 ]] ; do
ENABLE_ASSERTS="yes"
shift
;;
--enable-shared)
ENABLE_SHARED="yes"
shift
;;
--llvm-config)
shift
LLVM_CONFIG_BIN="$1"
Expand All @@ -70,6 +80,18 @@ while [[ "$#" -ge 1 ]] ; do
usage >&2
exit 1
;;
--prefix=*)
Copy link
Collaborator

Choose a reason for hiding this comment

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

These flags are not mentioned in the help text, is that on purpose?
Also, the use of --flag=<value> instead of --flag <value> is different from the others, is this due to Debian standards for configure scripts or something?

Anyway, it might be a good argument for rewriting the configure-script in python with argparse to get more general parsing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

"--flag=X" vs. "--flag X": This is really annoying, I figured that meta-buildsystems kind of expect both to work with --flag=X being used more often (most standard packaging scripts). Ideally, both should work but TBH I don't want the feature creep of fully reimpleminting autoconf & friends.
Rewriting in python: opens a different of issues depending on it as build-time requirement. Depending on where and how things are built, it is "#!/usr/bin/python", "#!/usr/bin/python3" "#!/bin/env python" "#!/bin/env python3" and if things turn ugly it is "#!/bin/env python2.7".... posix sh sucks badly from ergonomic point of view, but at least is realible.
Documentation is missing, will fix.

Copy link
Owner

Choose a reason for hiding this comment

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

As talked offline, we leave it as it is right now. I am not happy with the parameter syntax mix, but if that is what is needed right now, then let's go ahead. Just add the documentation and we can merge this one.

prefix="${1#--prefix=}"
shift
;;
--includedir=*)
includedir="${1#--includedir=}"
shift
;;
--libdir=*)
libdir="${1#--libdir=}"
shift
;;
*=*)
VARNAME=${1%%=*}
VARVAL=${1#*=}
Expand All @@ -83,6 +105,13 @@ while [[ "$#" -ge 1 ]] ; do
esac
done

if [ "${includedir}" == "" ] ; then
includedir="${prefix}/include"
fi

if [ "${libdir}" == "" ] ; then
libdir="${prefix}/lib"
fi

CXXFLAGS_COMMON="--std=c++17 -Wall -Wpedantic -Wextra -Wno-unused-parameter -Werror -Wfatal-errors -gdwarf-4 -g"
CPPFLAGS_COMMON="-I. -Itests"
Expand Down Expand Up @@ -138,6 +167,12 @@ MLIR_PATH=${MLIR_PATH}
MLIR_LDFLAGS=${MLIR_LDFLAGS}
LLVMCONFIG=${LLVM_CONFIG_BIN}
ENABLE_COVERAGE=${ENABLE_COVERAGE}
ENABLE_SHARED=${ENABLE_SHARED}

INSTALL=${INSTALL}
prefix=${prefix}
libdir=${libdir}
includedir=${includedir}
EOF
if [ ! -z "${CXX-}" ] ; then
echo "CXX=${CXX}"
Expand Down
5 changes: 5 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
jlm (0.0.1) UNRELEASED; urgency=medium

* Initial packaging

-- Helge Bahmann <[email protected]> Sun, 04 Feb 2024 17:20:30 +0100
1 change: 1 addition & 0 deletions debian/compat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10
43 changes: 43 additions & 0 deletions debian/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Source: jlm
Priority: optional
Maintainer: Helge Bahmann <[email protected]>
Build-Depends: debhelper (>= 9)
Standards-Version: 3.9.8
Section: libs

Package: libjlmutil-dev
Section: libdevel
Architecture: any
Depends: libjlmutil0 (= ${binary:Version}), ${misc:Depends}
Description: Common utilities for jlm.
Common utilities for jlm.
.
Provides shared utility library for other jlm libraries.

Package: libjlmutil0
Architecture: any
Depends: ${misc:Depends}, ${shlibs:Depends}
Description: Common utilities for jlm.
Common utilities for jlm.
.
Provides shared utility library for other jlm libraries.

Package: librvsdg-dev
Section: libdevel
Architecture: any
Depends: librvsdg0 (= ${binary:Version}), ${misc:Depends}, libjlmutil-dev
Description: RVSDG compiler IR library.
RVSDG compiler IR library.
.
Library that implements the RVSDG (regionalized value state dependence
graph) compiler intermediate representation.

Package: librvsdg0
Architecture: any
Depends: ${misc:Depends}, ${shlibs:Depends}
Description: RVSDG compiler IR library.
RVSDG compiler IR library.
.
Library that implements the RVSDG (regionalized value state dependence
graph) compiler intermediate representation.

4 changes: 4 additions & 0 deletions debian/libjlmutil-dev.install
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
usr/include/jlm/util/*
usr/lib/*/libjlmutil.so
usr/lib/*/libjlmutil.a
usr/lib/*/pkgconfig/libjlmutil.pc
1 change: 1 addition & 0 deletions debian/libjlmutil0.install
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
usr/lib/*/libjlmutil.so.0*
4 changes: 4 additions & 0 deletions debian/librvsdg-dev.install
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
usr/include/jlm/rvsdg/*
usr/lib/*/librvsdg.so
usr/lib/*/librvsdg.a
usr/lib/*/pkgconfig/librvsdg.pc
1 change: 1 addition & 0 deletions debian/librvsdg0.install
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
usr/lib/*/librvsdg.so.0*
14 changes: 14 additions & 0 deletions debian/rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/make -f
%:
dh $@

.PHONY: override_dh_strip override_dh_auto_configure

override_dh_auto_clean:
rm -rf build build-* docs

override_dh_auto_configure:
./configure.sh --enable-shared --prefix=/usr --libdir=/usr/lib/$(DEB_HOST_MULTIARCH)

override_dh_strip:
dh_strip --automatic-dbgsym
1 change: 1 addition & 0 deletions debian/source/format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.0 (native)
1 change: 1 addition & 0 deletions debian/source/options
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tar-ignore = ".git/*"
6 changes: 4 additions & 2 deletions jlm/hls/Makefile.sub
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ libhls_TESTS += \

libhls_TEST_LIBS += \
libhls \
libllvm \
libjlmllvm \
librvsdg \
libutil \
libjlmutil \
libjlmtest \

libhls_TEST_EXTRA_LDFLAGS = $(shell $(LLVMCONFIG) --ldflags --libs --system-libs)
libhls_VERSION = 0.0.1
libhls_SOVERSION = 0

$(eval $(call common_library,libhls))
18 changes: 10 additions & 8 deletions jlm/llvm/Makefile.sub
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2019 Nico Reißmann <[email protected]>
# See COPYING for terms of redistribution.

libllvm_SOURCES = \
libjlmllvm_SOURCES = \
jlm/llvm/backend/jlm2llvm/instruction.cpp \
jlm/llvm/backend/jlm2llvm/jlm2llvm.cpp \
jlm/llvm/backend/jlm2llvm/type.cpp \
Expand Down Expand Up @@ -61,7 +61,7 @@ libllvm_SOURCES = \
jlm/llvm/opt/reduction.cpp \
jlm/llvm/opt/unroll.cpp \

libllvm_HEADERS = \
libjlmllvm_HEADERS = \
jlm/llvm/opt/unroll.hpp \
jlm/llvm/opt/DeadNodeElimination.hpp \
jlm/llvm/opt/inlining.hpp \
Expand Down Expand Up @@ -124,7 +124,7 @@ libllvm_HEADERS = \
jlm/llvm/backend/jlm2llvm/instruction.hpp \
jlm/llvm/backend/jlm2llvm/context.hpp \

libllvm_TESTS += \
libjlmllvm_TESTS += \
tests/jlm/llvm/backend/llvm/r2j/test-empty-gamma \
tests/jlm/llvm/backend/llvm/r2j/test-partial-gamma \
tests/jlm/llvm/backend/llvm/r2j/test-recursive-data \
Expand Down Expand Up @@ -180,12 +180,14 @@ libllvm_TESTS += \
tests/jlm/llvm/opt/test-push \
tests/jlm/llvm/opt/test-unroll \

libllvm_TEST_LIBS = \
libjlmllvm_TEST_LIBS = \
libjlmtest \
libllvm \
libjlmllvm \
librvsdg \
libutil \
libjlmutil \

libllvm_TEST_EXTRA_LDFLAGS = $(shell $(LLVMCONFIG) --ldflags --libs --system-libs)
libjlmllvm_TEST_EXTRA_LDFLAGS = $(shell $(LLVMCONFIG) --ldflags --libs --system-libs)
libjlmllvm_VERSION = 0.0.1
libjlmllvm_SOVERSION = 0

$(eval $(call common_library,libllvm))
$(eval $(call common_library,libjlmllvm))
2 changes: 1 addition & 1 deletion jlm/llvm/ir/operators/operators.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2680,7 +2680,7 @@ class Memcpy final : public jlm::rvsdg::simple_op
};

/*
FIXME: This function should be in librvsdg and not in libllvm.
FIXME: This function should be in librvsdg and not in libjlmllvm.
*/
static inline jlm::rvsdg::node *
input_node(const jlm::rvsdg::input * input)
Expand Down
7 changes: 5 additions & 2 deletions jlm/mlir/Makefile.sub
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ libmlir_TESTS += \

libmlir_TEST_LIBS += \
libmlir \
libllvm \
libjlmllvm \
librvsdg \
libutil \
libjlmutil \
libjlmtest \

libmlir_TEST_EXTRA_LDFLAGS = \
Expand All @@ -27,4 +27,7 @@ libmlir_TEST_EXTRA_LDFLAGS = \
-lMLIRJLM \
-lMLIRRVSDG \

libmlir_VERSION = 0.0.1
libmlir_SOVERSION = 0

$(eval $(call common_library,libmlir))
7 changes: 6 additions & 1 deletion jlm/rvsdg/Makefile.sub
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ librvsdg_TESTS = \
librvsdg_TEST_LIBS = \
libjlmtest \
librvsdg \
libutil \
libjlmutil \

librvsdg_VERSION = 0.0.1
librvsdg_SOVERSION = 0

$(eval $(call common_library,librvsdg))

PKGCONFIG_FILES += $(BUILD_OUT_PREFIX)jlm/rvsdg/librvsdg.pc
10 changes: 10 additions & 0 deletions jlm/rvsdg/librvsdg.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
libdir = @libdir@
includedir = @includedir@

Name: librvsdg
Description: rvsdg representation library
Version: 0.0.1
URL: https://github.com/phate/jlm
Libs: -L${libdir} -lrvsdg
Requires: libjlmutil
Cflags: -I${includedir}
Loading
Loading