From 3aabadbf6d49bfb5ddfc6c23bd129d6f2746b484 Mon Sep 17 00:00:00 2001 From: Laria Carolin Chabowski Date: Fri, 16 Sep 2022 23:04:20 +0200 Subject: [PATCH] Switch to CMake --- .gitignore | 22 +------------- CMakeLists.txt | 4 +++ Makefile.am | 1 - README.md | 7 +++-- configure.ac | 10 ------- src/CMakeLists.txt | 49 ++++++++++++++++++++++++++++++ src/Makefile.am | 75 ---------------------------------------------- webpage/build.sh | 22 +++++--------- 8 files changed, 65 insertions(+), 125 deletions(-) create mode 100644 CMakeLists.txt delete mode 100644 Makefile.am delete mode 100644 configure.ac create mode 100644 src/CMakeLists.txt delete mode 100644 src/Makefile.am diff --git a/.gitignore b/.gitignore index 8280e88..567609b 100644 --- a/.gitignore +++ b/.gitignore @@ -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/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..481a930 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_minimum_required(VERSION 3.10) +project(apfl VERSION 0.0.1 LANGUAGES C) +enable_testing() +add_subdirectory(src) diff --git a/Makefile.am b/Makefile.am deleted file mode 100644 index af437a6..0000000 --- a/Makefile.am +++ /dev/null @@ -1 +0,0 @@ -SUBDIRS = src diff --git a/README.md b/README.md index 627aab7..ae00bbd 100644 --- a/README.md +++ b/README.md @@ -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] diff --git a/configure.ac b/configure.ac deleted file mode 100644 index a81df3c..0000000 --- a/configure.ac +++ /dev/null @@ -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 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..e331a21 --- /dev/null +++ b/src/CMakeLists.txt @@ -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) diff --git a/src/Makefile.am b/src/Makefile.am deleted file mode 100644 index 2215616..0000000 --- a/src/Makefile.am +++ /dev/null @@ -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 diff --git a/webpage/build.sh b/webpage/build.sh index b539682..c0c5b77 100755 --- a/webpage/build.sh +++ b/webpage/build.sh @@ -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