Skip to content

Commit

Permalink
move source/bin to bin/ with -DBINDIR
Browse files Browse the repository at this point in the history
for better cross-compilation.
add aarch64 docker files, and cross-compilation support.
  • Loading branch information
rurban committed Feb 29, 2024
1 parent 80fc93b commit 7fd5468
Show file tree
Hide file tree
Showing 22 changed files with 143 additions and 1,262 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
results/
.git/
bin/
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ source/algorithms.lst
/data/rand64/rand64.txt
/data/rand8/rand8.txt
/results/

/bin/
20 changes: 20 additions & 0 deletions Dockerfile.cross-aarch64
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- Dockerfile -*-
# podman/docker build -t smart-aarch64 . -f Dockerfile.cross-aarch64

FROM docker.io/library/debian:11-slim as aarch64
ENV DEBIAN_FRONTEND noninteractive
ENV DEBCONF_NONINTERACTIVE_SEEN true
ENV TZ=UTC

RUN apt-get update
RUN apt-get install -y --no-install-recommends build-essential git \
qemu-system-aarch64 binfmt-support qemu-user qemu-user-binfmt \
gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu libc6-dev-arm64-cross
WORKDIR /app
COPY . .
RUN aarch64-linux-gnu-gcc --version
RUN make CC=aarch64-linux-gnu-gcc
RUN ln -s /usr/aarch64-linux-gnu/sys-root/usr/bin/ld.so /lib/ld-linux-aarch64.so.1
ENV LD_LIBRARY_PATH=LD_LIBRARY_PATH=/usr/aarch64-linux-gnu/sys-root/lib64
RUN make CC=aarch64-linux-gnu-gcc check
CMD [ "bash --login -i" ]
32 changes: 32 additions & 0 deletions Dockerfile.fedora-aarch64
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# -*- Dockerfile -*-
# podman/docker build -t smart-fc-aarch64 . -f Dockerfile.fedora-aarch64
ARG BASE_IMAGE=fedora
#FROM ${BASE_IMAGE}
FROM fedora:39-aarch64

# Test with non-root user.
ENV TEST_USER tester
ENV WORK_DIR "/work"

#RUN uname -a
#RUN echo -e "deltarpm=0\ninstall_weak_deps=0\ntsflags=nodocs" >> /etc/dnf/dnf.conf
# Disable modular repositories to save a running time of "dnf update"
#RUN ls /etc/yum.repos.d/*.repo
#RUN sed -i '/^enabled=1$/ s/1/0/' /etc/yum.repos.d/*-modular.repo || true
#RUN dnf -y update
RUN dnf -y --allowerasing --repo fedora install \
file gcc make redhat-rpm-config sudo
#RUN dnf -y --repo fedora install m4 libtool perl-Text-Diff pkgconf-pkg-config strace gdb
#RUN dnf -y --repo fedora install strace gdb

# Create test user and the environment
RUN useradd "${TEST_USER}"
WORKDIR "${WORK_DIR}"
COPY . .
RUN chown -R "${TEST_USER}:${TEST_USER}" "${WORK_DIR}"

# Enable sudo without password for convenience.
RUN echo "${TEST_USER} ALL = NOPASSWD: ALL" >> /etc/sudoers
#RUN ln -s /usr/aarch64-linux-gnu/sys-root/usr/bin/ld.so /lib/ld-linux-aarch64.so.1

USER "${TEST_USER}"
38 changes: 24 additions & 14 deletions GNUmakefile
Original file line number Diff line number Diff line change
@@ -1,36 +1,46 @@
CC := gcc
uname_m := $(shell $CC -dumpmachine | cut -f1 -d-)
ifneq ($(uname_m),x86_64)
CC := gcc
MACHINE := $(shell uname -m)
ARCH := $(shell ${CC} -dumpmachine | cut -f1 -d-)
ifneq ($(ARCH),x86_64)
CFLAGS := -O3 -Wall
NON_SSE = source/algos/epsm.c source/algos/ssecp.c source/algos/ssef.c
ALGOSRC = $(filter-out $(NON_SSE),$(wildcard source/algos/*.c))
else
CFLAGS := -O3 -march=native -mtune=native -Wall -Wfatal-errors
ALGOSRC = $(wildcard source/algos/*.c)
BINDIR = bin
endif
BINS = $(patsubst source/algos/%,source/bin/%,$(patsubst %.c,%,$(ALGOSRC)))
ifneq ($(ARCH),$(MACHINE))
BINDIR = bin/$(ARCH)
DRV = qemu-$(ARCH)
else
BINDIR = bin
DRV =
endif
BINS = $(patsubst source/algos/%,$(BINDIR)/%,$(patsubst %.c,%,$(ALGOSRC)))
HELPERS = smart show select test textgen compilesm
TESTS = bm mp kmp tbm bom so

all: $(BINS) $(HELPERS)

source/bin/%: source/algos/%.c
$(BINDIR)/%: source/algos/%.c
@test -d $(BINDIR) || mkdir $(BINDIR)
$(CC) $(CFLAGS) $< -o $@
./%: source/%.c source/*.h
$(CC) $(CFLAGS) $< -std=gnu99 -o $@ -lm
$(CC) $(CFLAGS) -DBINDIR="\"$(BINDIR)\"" $< -std=gnu99 -o $@ -lm
select: source/selectAlgo.c
$(CC) $(CFLAGS) $< -o $@
$(CC) $(CFLAGS) -DBINDIR="\"$(BINDIR)\"" $< -o $@

.PHONY: check clean all
check: all
./select -which | grep br
-cp source/bin/br source/bin/br1
./select -add br1
-rm source/bin/br1
./select -none $(TESTS)
./smart -text rand32
$(DRV) ./select -which | grep br
-cp $(BINDOR)/br $(BINDOR)/br1
$(DRV) ./select -add br1
-rm $(BINDOR)/br1
$(DRV) ./select -none $(TESTS)
$(DRV) ./smart -text rand32
for t in $(TESTS); do echo $$t; ./test $$t; done
./select -all block bmh2 bmh4 dfdm sbdm faoso2 blim ssecp
$(DRV) ./select -all block bmh2 bmh4 dfdm sbdm faoso2 blim ssecp

clean:
rm $(BINS) $(HELPERS)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The release of smart will be available [here](https://github.com/smart-tool/smar
The documentation about smart is available [here](https://www.dmi.unict.it/faro/smart/howto.php)

## How to compile it from source
To compile the source just download (or clone) this repository and run the file build.sh from terminal (with **./build.sh**), it will compile the smart binaries and all the algorithms (the algorithms binaries will be created into source/bin/).
To compile the source just download (or clone) this repository and run the file build.sh from terminal (with **./build.sh**), it will compile the smart binaries and all the algorithms (the algorithms binaries will be created into bin/).

## Reference

Expand Down
File renamed without changes.
24 changes: 16 additions & 8 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/bin/sh
./logo
CC="${CC:-gcc}"
uname_p="$(uname -p)"
if [ $uname_p = x86_64 ]
MACHINE=`uname -m`
ARCH=`${CC} -dumpmachine | cut -f1 -d-`
if [ $MACHINE = x86_64 ]
then
CFLAGS="-march=native -mtune=native"
# we don't care that much about windows non-compat warnings yet
Expand All @@ -15,19 +16,26 @@ then
esac
SSE2="-msse2"
fi
BINDIR=bin
DRV=
if [ "$ARCH" != "MACHINE" ]; then
CROSS=1
BINDIR=bin/$ARCH
DRV="qemu-$(ARCH) "
fi
echo " Compiling smart.c..................................[OK]"
$CC source/smart.c -O3 $CFLAGS $SSE2 -o smart -lm -std=gnu99
$CC source/smart.c -O3 $CFLAGS $SSE2 -o smart -lm -std=gnu99 -DBINDIR="\"$BINDIR\""
echo " Compiling show.c...................................[OK]"
$CC source/show.c -O3 $CFLAGS $SSE2 -o show
echo " Compiling selectAlgo.c.............................[OK]"
$CC source/selectAlgo.c -O3 $CFLAGS -o select
$CC source/selectAlgo.c -O3 $CFLAGS -o select -DBINDIR="\"$BINDIR\""
echo " Compiling test.c...................................[OK]"
$CC source/test.c -O3 $CFLAGS -o test
$CC source/test.c -O3 $CFLAGS -o test -DBINDIR="\"$BINDIR\""
echo " Generating random text buffers....................."
$CC source/textgen.c -o textgen -std=gnu99
./textgen
$DRV./textgen
echo " Compiling all string matching algorithms..........."
$CC source/compilesm.c -o compilesm -std=gnu99
./compilesm
$CC source/compilesm.c -o compilesm -std=gnu99 -DBINDIR="\"$BINDIR\""
$DRV./compilesm
echo " "
echo " "
Binary file removed source/a.out
Binary file not shown.
176 changes: 0 additions & 176 deletions source/algorithms_new.h

This file was deleted.

Loading

0 comments on commit 7fd5468

Please sign in to comment.