Switch to CMake

This commit is contained in:
Laria 2022-09-16 23:04:20 +02:00
parent 8ca24bcd49
commit 3aabadbf6d
8 changed files with 65 additions and 125 deletions

22
.gitignore vendored
View file

@ -1,21 +1 @@
*.o
*.trs
*.log
*.test
depcomp
config.status
Makefile.in
missing
test-driver
ar-lib
compile
configure
*.m4
autom4te.cache/
.deps/
Makefile
install-sh
src/libapfl.a
src/apfl
apfl-*.*.*.tar.gz
apfl-*.*.*/
build/

4
CMakeLists.txt Normal file
View file

@ -0,0 +1,4 @@
cmake_minimum_required(VERSION 3.10)
project(apfl VERSION 0.0.1 LANGUAGES C)
enable_testing()
add_subdirectory(src)

View file

@ -1 +0,0 @@
SUBDIRS = src

View file

@ -15,10 +15,11 @@ We have what looks like a working tokenizer and parser and you can evaluate most
Building and running
--------------------
You'll need the GNU autotools and a C11 compatible C compiler, tested with gcc 11.1 on x86-64 Linux. Since only the C standard library is used, it should work pretty much anywhere, though.
You'll need CMake and a C11 compatible C compiler, tested with gcc 11.1 on x86-64 Linux. Since only the C standard library is used, it should work pretty much anywhere, though.
autoreconf --install
./configure
mkdir -p build
cd build
cmake ..
make
./src/apfl [tokenizer|parser|eval]

View file

@ -1,10 +0,0 @@
AC_INIT([apfl], [0.0.1])
AM_INIT_AUTOMAKE([-Wall -Werror foreign])
AC_PROG_CC
AM_PROG_AR
AC_PROG_RANLIB
AC_CONFIG_FILES([
Makefile
src/Makefile
])
AC_OUTPUT

49
src/CMakeLists.txt Normal file
View file

@ -0,0 +1,49 @@
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_EXTENSIONS OFF)
add_library(apfl
alloc.c
bytecode.c
compile.c
context.c
error.c
eval.c
expr.c
format.c
gc.c
hashmap.c
globals.c
matcher.c
messages.c
parser.c
position.c
resizable.c
source_readers.c
scope.c
strings.c
token.c
tokenizer.c
value.c
)
add_executable(apfl-bin main.c)
target_link_libraries(apfl-bin PUBLIC apfl)
set_target_properties(apfl-bin
PROPERTIES RUNTIME_OUTPUT_NAME apfl
)
function(unittest name moresources)
add_executable(${name} test.h ${name}.c ${moresources})
target_link_libraries(${name} PUBLIC apfl)
add_test(NAME ${name} COMMAND ${name})
endfunction()
unittest(tokenizer_test "")
unittest(parser_test "")
unittest(resizable_test "resizable.h")
unittest(hashmap_test "hashmap.h")
install(TARGETS apfl DESTINATION lib)
install(TARGETS apfl-bin DESTINATION bin)
install(FILES apfl.h DESTINATION include)

View file

@ -1,75 +0,0 @@
AM_CFLAGS=--std=c11 -Wall -Werror -Wextra -pedantic
lib_LIBRARIES = libapfl.a
libapfl_a_SOURCES =
libapfl_a_SOURCES += alloc.c
libapfl_a_SOURCES += bytecode.c
libapfl_a_SOURCES += compile.c
libapfl_a_SOURCES += context.c
libapfl_a_SOURCES += error.c
libapfl_a_SOURCES += eval.c
libapfl_a_SOURCES += expr.c
libapfl_a_SOURCES += format.c
libapfl_a_SOURCES += gc.c
libapfl_a_SOURCES += hashmap.c
libapfl_a_SOURCES += globals.c
libapfl_a_SOURCES += matcher.c
libapfl_a_SOURCES += messages.c
libapfl_a_SOURCES += parser.c
libapfl_a_SOURCES += position.c
libapfl_a_SOURCES += resizable.c
libapfl_a_SOURCES += source_readers.c
libapfl_a_SOURCES += scope.c
libapfl_a_SOURCES += strings.c
libapfl_a_SOURCES += token.c
libapfl_a_SOURCES += tokenizer.c
libapfl_a_SOURCES += value.c
apfl_internal_headers =
apfl_internal_headers += alloc.h
apfl_internal_headers += bytecode.h
apfl_internal_headers += compile.h
apfl_internal_headers += context.h
apfl_internal_headers += format.h
apfl_internal_headers += gc.h
apfl_internal_headers += globals.h
apfl_internal_headers += hashmap.h
apfl_internal_headers += matcher.h
apfl_internal_headers += resizable.h
apfl_internal_headers += scope.h
apfl_internal_headers += strings.h
apfl_internal_headers += value.h
EXTRA_DIST = $(apfl_internal_headers) apfl.h
apflincludesdir = $(pkgincludedir)/apfl
apflincludes_HEADERS = apfl.h
bin_PROGRAMS = apfl
apfl_SOURCES = main.c apfl.h
apfl_LDADD = libapfl.a
TESTS =
check_PROGRAMS =
TESTS += tokenizer.test
check_PROGRAMS += tokenizer.test
tokenizer_test_SOURCES = tokenizer_test.c test.h
tokenizer_test_LDADD = libapfl.a
TESTS += parser.test
check_PROGRAMS += parser.test
parser_test_SOURCES = parser_test.c test.h
parser_test_LDADD = libapfl.a
TESTS += resizable.test
check_PROGRAMS += resizable.test
resizable_test_SOURCES = resizable_test.c test.h resizable.h
resizable_test_LDADD = libapfl.a
TESTS += hashmap.test
check_PROGRAMS += hashmap.test
hashmap_test_SOURCES = hashmap_test.c test.h hashmap.h
hashmap_test_LDADD = libapfl.a

View file

@ -1,18 +1,10 @@
#!/bin/sh
set -e
PACKAGE=$(sed -n 's/^PACKAGE\s*=\s*//p' ../Makefile)
VERSION=$(sed -n 's/^VERSION\s*=\s*//p' ../Makefile)
(
cd ..
make dist-gzip
)
cd playground
tar xzf ../../"$PACKAGE-$VERSION".tar.gz
rm -rf dist
mv "$PACKAGE-$VERSION" dist
cd dist
emconfigure ./configure CFLAGS="-O2" LDFLAGS="-sASYNCIFY"
cd src
emmake make -j"$(nproc)" libapfl.a
cd ../..
emcc -sASYNCIFY -O3 -oplayground.js playground.c dist/src/libapfl.a
rm -rf build
mkdir build
cd build
emcmake cmake -DCMAKE_C_FLAGS="-O2" ../../../CMakeLists.txt
emmake make -j"$(nproc)" apfl
cd ..
emcc -sASYNCIFY -O3 -oplayground.js playground.c build/src/libapfl.a