From 1eac16f1e95811125759fd3ed0ec18ebe5030f57 Mon Sep 17 00:00:00 2001 From: Petr Penzin Date: Sat, 16 Mar 2024 22:05:20 -0700 Subject: [PATCH 01/10] CMake project and BProcessInfo Add top level CMake file. Implement checking and setting flags. Add BProcessInfor compilation. --- C/CMakeLists.txt | 3 +++ CMakeLists.txt | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 C/CMakeLists.txt create mode 100644 CMakeLists.txt diff --git a/C/CMakeLists.txt b/C/CMakeLists.txt new file mode 100644 index 0000000..f424940 --- /dev/null +++ b/C/CMakeLists.txt @@ -0,0 +1,3 @@ +add_executable(BProcessInfo + BProcessInfo.c +) diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..119d227 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,36 @@ +cmake_minimum_required(VERSION 3.11) + +project(BToolkit + VERSION 6.0.4 + DESCRIPTION "The BToolkit, a toolkit supporting software development with the B-method." + LANGUAGES C +) + +# Test compiler flags +include(CheckCCompilerFlag) + +# TODO better flag dispatch? +# - Function/loop for repeated check and set? +# - This is GCC/Clang focused + +CHECK_C_COMPILER_FLAG(-pedantic USE_PEDANTIC) +if(USE_PEDANTIC) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic") +endif() + +CHECK_C_COMPILER_FLAG(-pipe USE_PIPE) +if(USE_PIPE) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pipe") +endif() + +# This is better add on directoris that need it +# CHECK_C_COMPILER_FLAG(-fcommon USE_FCOMMON) +# if(USE_FCOMMON) +# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fcommon") +# endif() + +# TODO macros for OS_VERSION, OS_SUB_VERSION, RELEASE_VERSION, BSERVER_VERSION, +# etc + +add_subdirectory(C) + From 8bc2ec54705cd7bc98d07d2a06f68a3b7473b4e3 Mon Sep 17 00:00:00 2001 From: Petr Penzin Date: Mon, 18 Mar 2024 18:28:55 -0700 Subject: [PATCH 02/10] Add more build targets A bit of output directory structure. Add more utility targets. Some OS-specific settings. --- C/CMakeLists.txt | 38 ++++++++++++++++++++++++++++++++++++++ CMakeLists.txt | 16 +++++++++++++--- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/C/CMakeLists.txt b/C/CMakeLists.txt index f424940..9d649ca 100644 --- a/C/CMakeLists.txt +++ b/C/CMakeLists.txt @@ -1,3 +1,41 @@ +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/BLIB) + add_executable(BProcessInfo BProcessInfo.c ) + +add_executable(BToolkit + BToolkit.c +) + +add_executable(BUnlock + BUnlock.c +) + +add_executable(BSession + BSession.c +) + +add_executable(CheckRenameLib + CheckRenameLib.c +) + +add_executable(CreHtml + CreHtml.c +) + +add_executable(CreHtmlc + CreHtmlc.c +) + +add_executable(Greplace + Greplace.c +) + +add_executable(LatexProofFilter + LatexProofFilter.c +) + +add_executable(CheckAnnot + Proof.c +) diff --git a/CMakeLists.txt b/CMakeLists.txt index 119d227..3343ca4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,8 @@ include(CheckCCompilerFlag) # TODO better flag dispatch? # - Function/loop for repeated check and set? -# - This is GCC/Clang focused +# - Scripts set optimization levels differently for different files, is that +# needed with modern compilers (and especially with -pedantic)? CHECK_C_COMPILER_FLAG(-pedantic USE_PEDANTIC) if(USE_PEDANTIC) @@ -29,8 +30,17 @@ endif() # set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fcommon") # endif() -# TODO macros for OS_VERSION, OS_SUB_VERSION, RELEASE_VERSION, BSERVER_VERSION, -# etc +add_compile_definitions(RELEASE_VERSION BSERVER_VERSION) + +# FIXME the scripts define a number of architectures, likely a lot of those +# would be hard to find and may not have a CMake port. Platform detection +# section attempts to deal with that one OS at a time, rather than porting all +# settings over to CMake + +if (CMAKE_SYSTEM_NAME STREQUAL "Linux") + add_compile_definitions(linux _BSD_SOURCE POSIX_SOURCE LINUX_VERSION LINUX_SUB_VERSION) +else() +endif() add_subdirectory(C) From 1b71a2d2a6d00194b587350b7223be81d8531241 Mon Sep 17 00:00:00 2001 From: Petr Penzin Date: Mon, 18 Mar 2024 19:09:34 -0700 Subject: [PATCH 03/10] Add more C targets to CMake Note: there are some files in the C dir still not in any target. --- C/CMakeLists.txt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/C/CMakeLists.txt b/C/CMakeLists.txt index 9d649ca..595d262 100644 --- a/C/CMakeLists.txt +++ b/C/CMakeLists.txt @@ -39,3 +39,15 @@ add_executable(LatexProofFilter add_executable(CheckAnnot Proof.c ) + +add_executable(WaitX + WaitX.c +) + +add_executable(Unix2Dos + Unix2Dos.c +) + +add_executable(Dos2Unix + Dos2Unix.c +) From a7a2129b22a3b576a917515d7a5c6f591add0b3c Mon Sep 17 00:00:00 2001 From: Petr Penzin Date: Mon, 18 Mar 2024 22:29:30 -0700 Subject: [PATCH 04/10] Build `b` and `bmotif` object Enable building core `b` executable and `bmotif` object library. --- BEESRC/CMakeLists.txt | 62 +++++++++++++++++++++++++++++++++++++++++++ CMakeLists.txt | 1 + 2 files changed, 63 insertions(+) create mode 100644 BEESRC/CMakeLists.txt diff --git a/BEESRC/CMakeLists.txt b/BEESRC/CMakeLists.txt new file mode 100644 index 0000000..6f7f15e --- /dev/null +++ b/BEESRC/CMakeLists.txt @@ -0,0 +1,62 @@ +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) + +# Disambiguate files by creating separate include directories +set(B_CORE_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include.B-Core) +set(BMOTIF_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include.motif) + +# Copy files during configuration step +configure_file(itfmch.c.B-Core ${B_CORE_INCLUDE_DIR}/itfmch.c COPYONLY) +configure_file(natmch.c.B-Core ${B_CORE_INCLUDE_DIR}/natmch.c COPYONLY) +configure_file(filmch.c.B-Core ${B_CORE_INCLUDE_DIR}/filmch.c COPYONLY) +configure_file(themch.c.B-Core ${B_CORE_INCLUDE_DIR}/themch.c COPYONLY) +configure_file(prfmch.c.B-Core ${B_CORE_INCLUDE_DIR}/prfmch.c COPYONLY) +configure_file(tolmch.c.B-Core ${B_CORE_INCLUDE_DIR}/tolmch.c COPYONLY) +configure_file(symmch.c.B-Core ${B_CORE_INCLUDE_DIR}/symmch.c COPYONLY) +configure_file(strmch.c.B-Core ${B_CORE_INCLUDE_DIR}/strmch.c COPYONLY) +configure_file(lexmch.c.B-Core ${B_CORE_INCLUDE_DIR}/lexmch.c COPYONLY) +configure_file(frmmch.c.B-Core ${B_CORE_INCLUDE_DIR}/frmmch.c COPYONLY) +configure_file(errmch.c.B-Core ${B_CORE_INCLUDE_DIR}/errmch.c COPYONLY) +configure_file(macmch.c.B-Core ${B_CORE_INCLUDE_DIR}/macmch.c COPYONLY) +configure_file(rulmch.c.B-Core ${B_CORE_INCLUDE_DIR}/rulmch.c COPYONLY) +configure_file(resmch.c.B-Core ${B_CORE_INCLUDE_DIR}/resmch.c COPYONLY) +configure_file(hypmch.c.B-Core ${B_CORE_INCLUDE_DIR}/hypmch.c COPYONLY) +configure_file(tacmch.c.B-Core ${B_CORE_INCLUDE_DIR}/tacmch.c COPYONLY) +configure_file(nodmch.c.B-Core ${B_CORE_INCLUDE_DIR}/nodmch.c COPYONLY) +configure_file(golmch.c.B-Core ${B_CORE_INCLUDE_DIR}/golmch.c COPYONLY) +configure_file(seqmch.c.B-Core ${B_CORE_INCLUDE_DIR}/seqmch.c COPYONLY) + +add_executable(b + b.c +) + +target_include_directories(b PRIVATE ${B_CORE_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) + +configure_file(itfmch.c.motif ${BMOTIF_INCLUDE_DIR}/itfmch.c COPYONLY) +configure_file(natmch.c.motif ${BMOTIF_INCLUDE_DIR}/natmch.c COPYONLY) +configure_file(filmch.c.motif ${BMOTIF_INCLUDE_DIR}/filmch.c COPYONLY) +configure_file(themch.c.motif ${BMOTIF_INCLUDE_DIR}/themch.c COPYONLY) +configure_file(prfmch.c.motif ${BMOTIF_INCLUDE_DIR}/prfmch.c COPYONLY) +configure_file(tolmch.c.motif ${BMOTIF_INCLUDE_DIR}/tolmch.c COPYONLY) +configure_file(symmch.c.motif ${BMOTIF_INCLUDE_DIR}/symmch.c COPYONLY) +configure_file(strmch.c.motif ${BMOTIF_INCLUDE_DIR}/strmch.c COPYONLY) +configure_file(lexmch.c.motif ${BMOTIF_INCLUDE_DIR}/lexmch.c COPYONLY) +configure_file(frmmch.c.motif ${BMOTIF_INCLUDE_DIR}/frmmch.c COPYONLY) +configure_file(errmch.c.motif ${BMOTIF_INCLUDE_DIR}/errmch.c COPYONLY) +configure_file(macmch.c.motif ${BMOTIF_INCLUDE_DIR}/macmch.c COPYONLY) +configure_file(rulmch.c.motif ${BMOTIF_INCLUDE_DIR}/rulmch.c COPYONLY) +configure_file(resmch.c.motif ${BMOTIF_INCLUDE_DIR}/resmch.c COPYONLY) +configure_file(hypmch.c.motif ${BMOTIF_INCLUDE_DIR}/hypmch.c COPYONLY) +configure_file(tacmch.c.motif ${BMOTIF_INCLUDE_DIR}/tacmch.c COPYONLY) +configure_file(nodmch.c.motif ${BMOTIF_INCLUDE_DIR}/nodmch.c COPYONLY) +configure_file(golmch.c.motif ${BMOTIF_INCLUDE_DIR}/golmch.c COPYONLY) +configure_file(seqmch.c.motif ${BMOTIF_INCLUDE_DIR}/seqmch.c COPYONLY) + +find_package(Motif REQUIRED) + +add_library(bmotif OBJECT + bmotif.c +) + +target_compile_definitions(bmotif PUBLIC BTOOL_FLAG BTOOLM_FLAG) +target_include_directories(bmotif PUBLIC ${BMOTIF_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${MOTIF_INCLUDE_DIR}) + diff --git a/CMakeLists.txt b/CMakeLists.txt index 3343ca4..106008f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,4 +43,5 @@ else() endif() add_subdirectory(C) +add_subdirectory(BEESRC) From 9e55bc3dd9f841910caddec2a44acd34417ca20e Mon Sep 17 00:00:00 2001 From: Petr Penzin Date: Mon, 18 Mar 2024 23:24:27 -0700 Subject: [PATCH 05/10] Running `BTool` and `b` Get `BTool` and `b` to run. Link against motif and X11, toggle building cuserid, add a placeholder for its link flag. Copy both SYMBOL files. Add a default version. --- BEESRC/CMakeLists.txt | 13 ++++++++++--- C/CMakeLists.txt | 15 +++++++++++++++ CMakeLists.txt | 4 ++++ SRC/CMakeLists.txt | 3 +++ 4 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 SRC/CMakeLists.txt diff --git a/BEESRC/CMakeLists.txt b/BEESRC/CMakeLists.txt index 6f7f15e..9729f95 100644 --- a/BEESRC/CMakeLists.txt +++ b/BEESRC/CMakeLists.txt @@ -51,12 +51,19 @@ configure_file(nodmch.c.motif ${BMOTIF_INCLUDE_DIR}/nodmch.c COPYONLY) configure_file(golmch.c.motif ${BMOTIF_INCLUDE_DIR}/golmch.c COPYONLY) configure_file(seqmch.c.motif ${BMOTIF_INCLUDE_DIR}/seqmch.c COPYONLY) +find_package(X11 REQUIRED) find_package(Motif REQUIRED) +if (NOT X11_Xt_FOUND) + message(FATAL_ERROR "X Toolkit is required") +endif() -add_library(bmotif OBJECT +add_executable(BTool bmotif.c ) -target_compile_definitions(bmotif PUBLIC BTOOL_FLAG BTOOLM_FLAG) -target_include_directories(bmotif PUBLIC ${BMOTIF_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${MOTIF_INCLUDE_DIR}) +target_compile_definitions(BTool PUBLIC BTOOL_FLAG BTOOLM_FLAG) +target_include_directories(BTool PUBLIC ${BMOTIF_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${MOTIF_INCLUDE_DIR}) +target_link_libraries(BTool PUBLIC BToolkitlm_globals ${MOTIF_LIBRARIES} ${X11_LIBRARIES} ${X11_Xt_LIB} ${CUSERID_LINK_FLAG}) +# Copy symbol file +configure_file(SYMBOL ${CMAKE_BINARY_DIR}/BPLAT/SYMBOL COPYONLY) diff --git a/C/CMakeLists.txt b/C/CMakeLists.txt index 595d262..754c05b 100644 --- a/C/CMakeLists.txt +++ b/C/CMakeLists.txt @@ -51,3 +51,18 @@ add_executable(Unix2Dos add_executable(Dos2Unix Dos2Unix.c ) + +add_library(BToolkitlm_globals OBJECT + BToolkitlm_globals.c +) +target_compile_definitions(BToolkitlm_globals PUBLIC + BTOOL_FLAG + BTOOLM_FLAG +) + +if (BUILD_CUSERID) + add_library(cuserid OBJECT + cuserid.c + ) +endif() + diff --git a/CMakeLists.txt b/CMakeLists.txt index 106008f..9f99d0a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,10 +38,14 @@ add_compile_definitions(RELEASE_VERSION BSERVER_VERSION) # settings over to CMake if (CMAKE_SYSTEM_NAME STREQUAL "Linux") + set(BUILD_CUSERID OFF) add_compile_definitions(linux _BSD_SOURCE POSIX_SOURCE LINUX_VERSION LINUX_SUB_VERSION) else() + set(BUILD_CUSERID ON) + add_compile_definitions(UNKNOWN_VERSION UNKNOWN_SUB_VERSION) endif() add_subdirectory(C) add_subdirectory(BEESRC) +add_subdirectory(SRC) diff --git a/SRC/CMakeLists.txt b/SRC/CMakeLists.txt new file mode 100644 index 0000000..f12fe9d --- /dev/null +++ b/SRC/CMakeLists.txt @@ -0,0 +1,3 @@ +# Copy symbol file +configure_file(AMNSYMBOL ${CMAKE_BINARY_DIR}/BPLAT/AMNSYMBOL COPYONLY) + From 84c2581724d7877dbebe3c9b4e504f1be615ad68 Mon Sep 17 00:00:00 2001 From: Petr Penzin Date: Tue, 19 Mar 2024 19:47:33 -0700 Subject: [PATCH 06/10] Add pblatform and lex files Add bplatform executable and utilities generated by Flex. Define a few binary directories in the top level CMakeLists.txt. --- BEESRC/CMakeLists.txt | 34 ++++++++++++++++++++++++++++++++- C/CMakeLists.txt | 2 +- CMakeLists.txt | 5 +++++ LEX/CMakeLists.txt | 44 +++++++++++++++++++++++++++++++++++++++++++ SRC/CMakeLists.txt | 2 +- 5 files changed, 84 insertions(+), 3 deletions(-) create mode 100644 LEX/CMakeLists.txt diff --git a/BEESRC/CMakeLists.txt b/BEESRC/CMakeLists.txt index 9729f95..2df3696 100644 --- a/BEESRC/CMakeLists.txt +++ b/BEESRC/CMakeLists.txt @@ -3,6 +3,7 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) # Disambiguate files by creating separate include directories set(B_CORE_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include.B-Core) set(BMOTIF_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include.motif) +set(BPLATFORM_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include.bplatform) # Copy files during configuration step configure_file(itfmch.c.B-Core ${B_CORE_INCLUDE_DIR}/itfmch.c COPYONLY) @@ -31,6 +32,7 @@ add_executable(b target_include_directories(b PRIVATE ${B_CORE_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) +# Copy files for BTool build configure_file(itfmch.c.motif ${BMOTIF_INCLUDE_DIR}/itfmch.c COPYONLY) configure_file(natmch.c.motif ${BMOTIF_INCLUDE_DIR}/natmch.c COPYONLY) configure_file(filmch.c.motif ${BMOTIF_INCLUDE_DIR}/filmch.c COPYONLY) @@ -66,4 +68,34 @@ target_include_directories(BTool PUBLIC ${BMOTIF_INCLUDE_DIR} ${CMAKE_CURRENT_SO target_link_libraries(BTool PUBLIC BToolkitlm_globals ${MOTIF_LIBRARIES} ${X11_LIBRARIES} ${X11_Xt_LIB} ${CUSERID_LINK_FLAG}) # Copy symbol file -configure_file(SYMBOL ${CMAKE_BINARY_DIR}/BPLAT/SYMBOL COPYONLY) +configure_file(SYMBOL ${BPLATFORM_BINARY_DIR}/SYMBOL COPYONLY) + +# Copy files for bplatform build (note the suffix is actually 'release') +configure_file(itfmch.c.release ${BPLATFORM_INCLUDE_DIR}/itfmch.c COPYONLY) +configure_file(natmch.c.release ${BPLATFORM_INCLUDE_DIR}/natmch.c COPYONLY) +configure_file(filmch.c.release ${BPLATFORM_INCLUDE_DIR}/filmch.c COPYONLY) +configure_file(themch.c.release ${BPLATFORM_INCLUDE_DIR}/themch.c COPYONLY) +configure_file(prfmch.c.release ${BPLATFORM_INCLUDE_DIR}/prfmch.c COPYONLY) +configure_file(tolmch.c.release ${BPLATFORM_INCLUDE_DIR}/tolmch.c COPYONLY) +configure_file(symmch.c.release ${BPLATFORM_INCLUDE_DIR}/symmch.c COPYONLY) +configure_file(strmch.c.release ${BPLATFORM_INCLUDE_DIR}/strmch.c COPYONLY) +configure_file(lexmch.c.release ${BPLATFORM_INCLUDE_DIR}/lexmch.c COPYONLY) +configure_file(frmmch.c.release ${BPLATFORM_INCLUDE_DIR}/frmmch.c COPYONLY) +configure_file(errmch.c.release ${BPLATFORM_INCLUDE_DIR}/errmch.c COPYONLY) +configure_file(macmch.c.release ${BPLATFORM_INCLUDE_DIR}/macmch.c COPYONLY) +configure_file(rulmch.c.release ${BPLATFORM_INCLUDE_DIR}/rulmch.c COPYONLY) +configure_file(resmch.c.release ${BPLATFORM_INCLUDE_DIR}/resmch.c COPYONLY) +configure_file(hypmch.c.release ${BPLATFORM_INCLUDE_DIR}/hypmch.c COPYONLY) +configure_file(tacmch.c.release ${BPLATFORM_INCLUDE_DIR}/tacmch.c COPYONLY) +configure_file(nodmch.c.release ${BPLATFORM_INCLUDE_DIR}/nodmch.c COPYONLY) +configure_file(golmch.c.release ${BPLATFORM_INCLUDE_DIR}/golmch.c COPYONLY) +configure_file(seqmch.c.release ${BPLATFORM_INCLUDE_DIR}/seqmch.c COPYONLY) + +add_executable(bplatform + bplatform.c +) +target_include_directories(bplatform PUBLIC ${BPLATFORM_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) +target_compile_definitions(bplatform PUBLIC bplatform) +set_target_properties(bplatform PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${BPLATFORM_BINARY_DIR} +) diff --git a/C/CMakeLists.txt b/C/CMakeLists.txt index 754c05b..9c6907d 100644 --- a/C/CMakeLists.txt +++ b/C/CMakeLists.txt @@ -1,4 +1,4 @@ -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/BLIB) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BLIB_BINARY_DIR}) add_executable(BProcessInfo BProcessInfo.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 9f99d0a..00bdecc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,7 +45,12 @@ else() add_compile_definitions(UNKNOWN_VERSION UNKNOWN_SUB_VERSION) endif() +# Binary directories +set(BPLATFORM_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/BPLAT) +set(BLIB_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/BLIB) + add_subdirectory(C) add_subdirectory(BEESRC) add_subdirectory(SRC) +add_subdirectory(LEX) diff --git a/LEX/CMakeLists.txt b/LEX/CMakeLists.txt new file mode 100644 index 0000000..145f543 --- /dev/null +++ b/LEX/CMakeLists.txt @@ -0,0 +1,44 @@ +find_package(FLEX REQUIRED) +# TODO scripts try to increase input buffer sizes, but currently those +# variables are not found in the output + +# There is a number of identically built utilities +set(FLEX_UTILS + AFilter + DFilter + Deannot + Doc_Latexer + EFilter + IFilter + Latex_Index + NLFilter + Post_Latexer_0 + Pre_GML_0 + Pre_GML_1 + Pre_GML_2 + Pre_GML_3 + Pre_GML_4 + Pre_GML_5 + SFilter + TransCFilter + Html1 + Html2 + Html3 + Html4 + Html5 +) + +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BLIB_BINARY_DIR}) + +# Repeat the same build steps +foreach(U IN LISTS FLEX_UTILS) + FLEX_TARGET(${U}C ${U}.lex ${CMAKE_CURRENT_BINARY_DIR}/${U}.c + COMPILE_FLAGS -n + ) + + add_executable(${U} + ${FLEX_${U}C_OUTPUTS} + ) + target_link_libraries(${U} PUBLIC ${FLEX_LIBRARIES}) +endforeach() + diff --git a/SRC/CMakeLists.txt b/SRC/CMakeLists.txt index f12fe9d..cd78702 100644 --- a/SRC/CMakeLists.txt +++ b/SRC/CMakeLists.txt @@ -1,3 +1,3 @@ # Copy symbol file -configure_file(AMNSYMBOL ${CMAKE_BINARY_DIR}/BPLAT/AMNSYMBOL COPYONLY) +configure_file(AMNSYMBOL ${BPLATFORM_BINARY_DIR}/AMNSYMBOL COPYONLY) From 1e73b19512a85fb1cf9900c68e857d5b21434be3 Mon Sep 17 00:00:00 2001 From: Petr Penzin Date: Tue, 19 Mar 2024 20:13:30 -0700 Subject: [PATCH 07/10] Add better handling for cuserid Either build the file or (potentially) use system library. System library path will be needed for BSD support. --- BEESRC/CMakeLists.txt | 2 +- CMakeLists.txt | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/BEESRC/CMakeLists.txt b/BEESRC/CMakeLists.txt index 2df3696..edf521f 100644 --- a/BEESRC/CMakeLists.txt +++ b/BEESRC/CMakeLists.txt @@ -65,7 +65,7 @@ add_executable(BTool target_compile_definitions(BTool PUBLIC BTOOL_FLAG BTOOLM_FLAG) target_include_directories(BTool PUBLIC ${BMOTIF_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${MOTIF_INCLUDE_DIR}) -target_link_libraries(BTool PUBLIC BToolkitlm_globals ${MOTIF_LIBRARIES} ${X11_LIBRARIES} ${X11_Xt_LIB} ${CUSERID_LINK_FLAG}) +target_link_libraries(BTool PUBLIC BToolkitlm_globals ${MOTIF_LIBRARIES} ${X11_LIBRARIES} ${X11_Xt_LIB} ${CUSERID_LIB}) # Copy symbol file configure_file(SYMBOL ${BPLATFORM_BINARY_DIR}/SYMBOL COPYONLY) diff --git a/CMakeLists.txt b/CMakeLists.txt index 00bdecc..3e4d7a4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,6 +45,14 @@ else() add_compile_definitions(UNKNOWN_VERSION UNKNOWN_SUB_VERSION) endif() +# Resolve what should be on link line for cuserid() +set(CUSERID_TARGET cuserid) +if (BUILD_CUSERID) + set(CUSERID_LIB ${CUSERID_TARGET}) +else() + set(CUSERID_LIB ${CUSERID_SYS_LIB}) +endif() + # Binary directories set(BPLATFORM_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/BPLAT) set(BLIB_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/BLIB) From 68c7958d31589bd538d4e5b3e2a06ae5eec5b96e Mon Sep 17 00:00:00 2001 From: Petr Penzin Date: Tue, 19 Mar 2024 23:14:46 -0700 Subject: [PATCH 08/10] Build BMotif Add parts of executable as libraries. Finally use -fcommon flag. --- BEESRC/BTL_PRF/CDE/C/CMakeLists.txt | 15 ++++++++++ BEESRC/CMakeLists.txt | 17 ++++++++++++ C/CMakeLists.txt | 13 +++++++++ CMakeLists.txt | 10 +++---- MOTIF/CFG_DEP_BASE/CDE/C/CMakeLists.txt | 24 ++++++++++++++++ MOTIF/CMakeLists.txt | 37 +++++++++++++++++++++++++ 6 files changed, 111 insertions(+), 5 deletions(-) create mode 100644 BEESRC/BTL_PRF/CDE/C/CMakeLists.txt create mode 100644 MOTIF/CFG_DEP_BASE/CDE/C/CMakeLists.txt create mode 100644 MOTIF/CMakeLists.txt diff --git a/BEESRC/BTL_PRF/CDE/C/CMakeLists.txt b/BEESRC/BTL_PRF/CDE/C/CMakeLists.txt new file mode 100644 index 0000000..5f0bf4c --- /dev/null +++ b/BEESRC/BTL_PRF/CDE/C/CMakeLists.txt @@ -0,0 +1,15 @@ +add_library(BTL_PRF OBJECT + btl_prf_ffnc_ctx.c + btl_prf_ffnc_obj.c + prf_seq_stp_ffnc_ctx.c + prf_seq_stp_ffnc_obj.c + btl_proof_seq_ctx.c + btl_proof_seq_obj.c + btl_proof_str_ctx.c + btl_proof_str_obj.c + btl_proof_file_dump.c + btl_proof.c + btl_proofCtx.c +) +target_compile_definitions(BTL_PRF PUBLIC bmotif) +target_compile_options(BTL_PRF PUBLIC ${ALLOW_COMMON_FLAG}) diff --git a/BEESRC/CMakeLists.txt b/BEESRC/CMakeLists.txt index edf521f..05dce57 100644 --- a/BEESRC/CMakeLists.txt +++ b/BEESRC/CMakeLists.txt @@ -5,6 +5,8 @@ set(B_CORE_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include.B-Core) set(BMOTIF_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include.motif) set(BPLATFORM_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include.bplatform) +add_subdirectory(BTL_PRF/CDE/C) + # Copy files during configuration step configure_file(itfmch.c.B-Core ${B_CORE_INCLUDE_DIR}/itfmch.c COPYONLY) configure_file(natmch.c.B-Core ${B_CORE_INCLUDE_DIR}/natmch.c COPYONLY) @@ -99,3 +101,18 @@ target_compile_definitions(bplatform PUBLIC bplatform) set_target_properties(bplatform PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${BPLATFORM_BINARY_DIR} ) + +add_library(BM OBJECT + appmch.motif.c + motif.c + bmotif_sub.c + bmotif.c +) +target_compile_definitions(BM PUBLIC + bmotif + BTOOLKIT_FLAG + BTOOL_FLAG + BTOOLM_FLAG +) +target_include_directories(BM PUBLIC ${BMOTIF_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${MOTIF_INCLUDE_DIR}) +target_compile_options(BM PUBLIC ${ALLOW_COMMON_FLAG}) diff --git a/C/CMakeLists.txt b/C/CMakeLists.txt index 9c6907d..34f3434 100644 --- a/C/CMakeLists.txt +++ b/C/CMakeLists.txt @@ -66,3 +66,16 @@ if (BUILD_CUSERID) ) endif() +find_package(Motif REQUIRED) + +add_library(ClientSocket OBJECT + ClientSocket.c +) +target_compile_definitions(ClientSocket PUBLIC + bmotif + BTOOLKIT_FLAG + BTOOL_FLAG + BTOOLM_FLAG +) +target_include_directories(ClientSocket PUBLIC ${MOTIF_INCLUDE_DIR}) +target_compile_options(ClientSocket PUBLIC ${ALLOW_COMMON_FLAG}) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3e4d7a4..a40ca87 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,11 +24,10 @@ if(USE_PIPE) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pipe") endif() -# This is better add on directoris that need it -# CHECK_C_COMPILER_FLAG(-fcommon USE_FCOMMON) -# if(USE_FCOMMON) -# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fcommon") -# endif() +CHECK_C_COMPILER_FLAG(-fcommon USE_FCOMMON) +if(USE_FCOMMON) + set(ALLOW_COMMON_FLAG -fcommon) +endif() add_compile_definitions(RELEASE_VERSION BSERVER_VERSION) @@ -61,4 +60,5 @@ add_subdirectory(C) add_subdirectory(BEESRC) add_subdirectory(SRC) add_subdirectory(LEX) +add_subdirectory(MOTIF) diff --git a/MOTIF/CFG_DEP_BASE/CDE/C/CMakeLists.txt b/MOTIF/CFG_DEP_BASE/CDE/C/CMakeLists.txt new file mode 100644 index 0000000..ad83bb1 --- /dev/null +++ b/MOTIF/CFG_DEP_BASE/CDE/C/CMakeLists.txt @@ -0,0 +1,24 @@ +add_library(CFG_DEP_BASE OBJECT + Abs2Conc_ffnc_obj.c + Bit_TYPE.c + Bool_TYPE.c + CfgDepBase.c + CfgDepBaseCtx.c + CfgDepBase_Vffnc.c + CfgDepBase_file_dump.c + CfgDepBase_seq_obj.c + CfgDepBase_set_obj.c + CfgDepBase_str_obj.c + CfgDepCtx.c + Construct_ffnc_obj.c + GENState_ffnc_obj.c + MRIState_ffnc_obj.c + Seqstr_ffnc_obj.c + String_ffnc_obj.c + Scalar_TYPE.c + String_TYPE.c + basic_io.c + file_dump.c +) +target_compile_definitions(CFG_DEP_BASE PUBLIC bmotif) + diff --git a/MOTIF/CMakeLists.txt b/MOTIF/CMakeLists.txt new file mode 100644 index 0000000..f441dc3 --- /dev/null +++ b/MOTIF/CMakeLists.txt @@ -0,0 +1,37 @@ +add_subdirectory(CFG_DEP_BASE/CDE/C) + +find_package(X11 REQUIRED) +find_package(Motif REQUIRED) +if (NOT X11_Xt_FOUND) + message(FATAL_ERROR "X Toolkit is required") +endif() + +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BLIB_BINARY_DIR}) + +add_executable(BMotif + B_Motif.c + BMotif_globals.c + BMotif_browser.c + BMotif_fifo.c + BMotif_init.c + BMotif_io.c + BMotif_utils.c + BMotif_widgets.c + BMotif_displaystate.c +) + +target_compile_definitions(BMotif PUBLIC + bmotif + BTOOLKIT_FLAG + BTOOL_FLAG + BTOOLM_FLAG +) + +target_compile_options(BMotif PUBLIC ${ALLOW_COMMON_FLAG}) +target_include_directories(BMotif PUBLIC ${MOTIF_INCLUDE_DIR}) +target_link_libraries(BMotif PUBLIC BM ClientSocket BToolkitlm_globals CFG_DEP_BASE BTL_PRF ${MOTIF_LIBRARIES} ${X11_LIBRARIES} ${X11_Xt_LIB} ${CUSERID_LIB}) + +# Copy resource files +configure_file(BMotif.resources ${CMAKE_BINARY_DIR}/XBMotif COPYONLY) +configure_file(BMotif.resources.mono ${CMAKE_BINARY_DIR}/XBMotif.mono COPYONLY) + From 22859f01776f20432da34cee1f50820054d97022 Mon Sep 17 00:00:00 2001 From: Petr Penzin Date: Wed, 20 Mar 2024 22:22:34 -0700 Subject: [PATCH 09/10] Copy SCRIPTS contents using CMake Generate a custom target and a set of custom commands to copy scripts over to BLIB destination directory. --- CMakeLists.txt | 1 + SCRIPTS/CMakeLists.txt | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 SCRIPTS/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index a40ca87..b3037ac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,4 +61,5 @@ add_subdirectory(BEESRC) add_subdirectory(SRC) add_subdirectory(LEX) add_subdirectory(MOTIF) +add_subdirectory(SCRIPTS) diff --git a/SCRIPTS/CMakeLists.txt b/SCRIPTS/CMakeLists.txt new file mode 100644 index 0000000..d8ca5cc --- /dev/null +++ b/SCRIPTS/CMakeLists.txt @@ -0,0 +1,40 @@ +set(SCRIPT_NAMES + BLatex + BRead + BTDECCO + Bkit.sty + Bbrowser + Beditor + Bnetscape + Bprintdvi + CheckFileDiff + CheckFileExists + ClearBerr + CreSLIBC + CreateCom + DispFile + ExportFile + FindFile + KillEditor + LIB_Addunderscore + LIB_Check + LIB_NoRename + LIB_Rename + LatexFile + LinkCFile + ExeFile + TransCFile +) +list(TRANSFORM SCRIPT_NAMES PREPEND ${BLIB_BINARY_DIR}/ OUTPUT_VARIABLE SCRIPT_DESTINATIONS) + +add_custom_target(copy-scripts ALL DEPENDS ${SCRIPT_DESTINATIONS}) + +foreach(S IN LISTS SCRIPT_NAMES) + set(IN_PATH ${CMAKE_CURRENT_SOURCE_DIR}/${S}) + set(OUT_PATH ${BLIB_BINARY_DIR}/${S}) + add_custom_command(OUTPUT ${OUT_PATH} + COMMAND ${CMAKE_COMMAND} -E copy ${IN_PATH} ${OUT_PATH} + DEPENDS ${IN_PATH} + ) +endforeach() + From 8af35f07461d8c8d31d06738519cba151fb36c0c Mon Sep 17 00:00:00 2001 From: Petr Penzin Date: Tue, 26 Mar 2024 22:24:23 -0700 Subject: [PATCH 10/10] Add library copy targets Provide targets that would copy standard library into CMake's binary directory. --- CMakeLists.txt | 10 ++- LIB/CMakeLists.txt | 125 +++++++++++++++++++++++++++++++++++++ cmake/copy-if-exists.cmake | 3 + 3 files changed, 137 insertions(+), 1 deletion(-) create mode 100644 LIB/CMakeLists.txt create mode 100644 cmake/copy-if-exists.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index b3037ac..eddf312 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,9 @@ project(BToolkit LANGUAGES C ) +# FIXME scripts set this unconditionally, may warrant some investigation +set(WITH_BSERVER ON CACHE BOOL "Build with BSERVER support" FORCE) + # Test compiler flags include(CheckCCompilerFlag) @@ -29,7 +32,11 @@ if(USE_FCOMMON) set(ALLOW_COMMON_FLAG -fcommon) endif() -add_compile_definitions(RELEASE_VERSION BSERVER_VERSION) +add_compile_definitions(RELEASE_VERSION) + +if(WITH_BSERVER) + add_compile_definitions(BSERVER_VERSION) +endif() # FIXME the scripts define a number of architectures, likely a lot of those # would be hard to find and may not have a CMake port. Platform detection @@ -62,4 +69,5 @@ add_subdirectory(SRC) add_subdirectory(LEX) add_subdirectory(MOTIF) add_subdirectory(SCRIPTS) +add_subdirectory(LIB) diff --git a/LIB/CMakeLists.txt b/LIB/CMakeLists.txt new file mode 100644 index 0000000..470075a --- /dev/null +++ b/LIB/CMakeLists.txt @@ -0,0 +1,125 @@ +# Copy standard library +# +# TODO this is likely better to be split into separate dirctories where every +# directory is copied verbatim instead of this custom process +# +# TODO script has more special cases (are those needed)?: +# - Optional "BOOSTER" set of files +# - What happens if BSERVER is not enabled? + +set(ANL_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ANL) +set(C_DIR ${CMAKE_CURRENT_SOURCE_DIR}/CDE/C) +set(CFG_DIR ${CMAKE_CURRENT_SOURCE_DIR}/CFG) +set(TYP_DIR ${CMAKE_CURRENT_SOURCE_DIR}/TYP) + +set(STD_LIB_NAMES + Bit_TYPE + Bit_TYPE_Ops + BitsNContext + Bool_TYPE + Bool_TYPE_Ops + Char_TYPE + Char_TYPE_Ops + Int_TYPE + Int_TYPE_Ops + Rename_Bit_String + Rename_File_io + Rename_Narr + Rename_Nfnc + Rename_Nseq + Rename_Nvar + Rename_SocketClient + Rename_SocketServer + Rename_SharedSocketServer + Rename_Timer + Rename_Varr + Rename_Vffnc + Rename_Vfnc + Rename_Vseq + Rename_Vvar + Rename_ffnc_ctx + Rename_ffnc_obj + Rename_file_dump + Rename_fnc_ctx + Rename_fnc_obj + Rename_fstr_ctx + Rename_fstr_obj + Rename_seq_ctx + Rename_seq_obj + Rename_set + Rename_set_ctx + Rename_set_obj + Rename_str_ctx + Rename_str_obj + Rename_token_io + Scalar_TYPE + Scalar_TYPE_Ops + String_TYPE + String_TYPE_Ops + basic_io + file_dump + system +) + +set(BSERVER_LIB_NAMES + IntegrityCheck +) + +if (WITH_BSERVER) + list(APPEND STD_LIB_NAMES ${BSERVER_LIB_NAMES}) +endif() + +# Copy standard library to binary directory +add_custom_target(copy-std-lib ALL) + +# TODO scipt also copies HTML help files, not sure that is necessary until install stage + +set(LIB_BINARY_DIR ${CMAKE_BINARY_DIR}/BLIB/LIB) +set(LIB_ANL_DIR ${LIB_BINARY_DIR}/ANL) +set(LIB_C_DIR ${LIB_BINARY_DIR}/CDE/C) +set(LIB_CFG_DIR ${LIB_BINARY_DIR}/CFG) +set(LIB_TYP_DIR ${LIB_BINARY_DIR}/TYP) + +foreach(S IN LISTS STD_LIB_NAMES) + add_custom_target(copy-std-lib-${S} DEPENDS + ${LIB_ANL_DIR}/${S}.mch.anl + ${LIB_C_DIR}/${S}.c + ${LIB_C_DIR}/${S}.g + ${LIB_C_DIR}/${S}.h + ${LIB_CFG_DIR}/${S}.mch + ${LIB_TYP_DIR}/${S}.mri.typ + ) + add_custom_command(OUTPUT ${LIB_ANL_DIR}/${S}.mch.anl + COMMAND ${CMAKE_COMMAND} -E copy ${ANL_DIR}/${S}.mch.anl ${LIB_ANL_DIR}/${S}.mch.anl + DEPENDS ${ANL_DIR}/${S}.mch.anl + ) + add_custom_command(OUTPUT ${LIB_C_DIR}/${S}.c + COMMAND ${CMAKE_COMMAND} -E copy ${C_DIR}/${S}.c ${LIB_C_DIR}/${S}.c + DEPENDS ${C_DIR}/${S}.c + ) + add_custom_command(OUTPUT ${LIB_C_DIR}/${S}.g + COMMAND ${CMAKE_COMMAND} -E copy ${C_DIR}/${S}.g ${LIB_C_DIR}/${S}.g + DEPENDS ${C_DIR}/${S}.g + ) + add_custom_command(OUTPUT ${LIB_C_DIR}/${S}.h + COMMAND ${CMAKE_COMMAND} -E copy ${C_DIR}/${S}.h ${LIB_C_DIR}/${S}.h + DEPENDS ${C_DIR}/${S}.h + ) + # .ldf files are only copied if they exist (see comment above about directories) + add_custom_command(TARGET copy-std-lib-${S} POST_BUILD + COMMAND ${CMAKE_COMMAND} + "-DSOURCE=${C_DIR}/${S}.ldf" + "-DDESTINATION=${LIB_C_DIR}" + -P ${CMAKE_SOURCE_DIR}/cmake/copy-if-exists.cmake + ) + add_custom_command(OUTPUT ${LIB_CFG_DIR}/${S}.mch + COMMAND ${CMAKE_COMMAND} -E copy ${CFG_DIR}/${S}.mch ${LIB_CFG_DIR}/${S}.mch + DEPENDS ${CFG_DIR}/${S}.mch + ) + add_custom_command(OUTPUT ${LIB_TYP_DIR}/${S}.mri.typ + COMMAND ${CMAKE_COMMAND} -E copy ${TYP_DIR}/${S}.mri.typ ${LIB_TYP_DIR}/${S}.mri.typ + DEPENDS ${TYP_DIR}/${S}.mri.typ + ) + add_dependencies(copy-std-lib copy-std-lib-${S}) +endforeach() + diff --git a/cmake/copy-if-exists.cmake b/cmake/copy-if-exists.cmake new file mode 100644 index 0000000..afb6332 --- /dev/null +++ b/cmake/copy-if-exists.cmake @@ -0,0 +1,3 @@ +if(EXISTS "${SOURCE}") + file(COPY "${SOURCE}" DESTINATION "${DESTINATION}") +endif()