Skip to content

Commit

Permalink
Make pkgconfig.tcl optional, implement it in C
Browse files Browse the repository at this point in the history
  • Loading branch information
chpock committed May 9, 2024
1 parent ef476b2 commit 08864d4
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 27 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
2024-05-10 Konstantin Kushnir <[email protected]>
* Make pkgconfig.tcl file optional, implement it in C

2024-05-06 Konstantin Kushnir <[email protected]>
* Bumped version to 1.6.0
* Fix undefined behaviour
Expand Down
56 changes: 45 additions & 11 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,7 @@ MAKE_SHARED_LIB
MAKE_LIB
EGREP
GREP
COOKFS_PKGCONFIG_USECPKGCONFIG
COOKFS_PKGCONFIG_FEATURE_METADATA
COOKFS_PKGCONFIG_USECFSINDEX
COOKFS_PKGCONFIG_USEXZ
Expand Down Expand Up @@ -787,6 +788,7 @@ enable_tcl_fallback
enable_c_pages
enable_c_fsindex
enable_c_readerchannel
enable_c_pkgconfig
'
ac_precious_vars='build_alias
host_alias
Expand Down Expand Up @@ -1430,6 +1432,7 @@ Optional Features:
--disable-c-pages Use pages handling written in C. Defaults to true
--disable-c-fsindex Use index handling written in C. Defaults to true
--disable-c-readerchannel Use reader handler written in C. Defaults to true
--disable-c-pkgconfig Use pkgconfig written in C. Defaults to true
Optional Packages:
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
Expand Down Expand Up @@ -8632,6 +8635,14 @@ else $as_nop
USECREADERCHAN=yes
fi

# Check whether --enable-c-pkgconfig was given.
if test ${enable_c_pkgconfig+y}
then :
enableval=$enable_c_pkgconfig; USECPKGCONFIG=${enableval}
else $as_nop
USECPKGCONFIG=yes
fi


if test ${INTERNALDEBUG} = yes; then
printf "%s\n" "#define COOKFS_INTERNAL_DEBUG 1" >>confdefs.h
Expand Down Expand Up @@ -8959,17 +8970,10 @@ else
COOKFS_PKGCONFIG_USEBZ2=0
fi







if test ${USECFSINDEX} = yes; then
printf "%s\n" "#define COOKFS_USECFSINDEX 1" >>confdefs.h

COOKFS_PKGCONFIG_USECFSINDEX=1
COOKFS_PKGCONFIG_FEATURE_METADATA=1

vars="fsindex.c fsindexIO.c fsindexCmd.c"
for i in $vars; do
Expand Down Expand Up @@ -9007,12 +9011,42 @@ if test ${USECFSINDEX} = yes; then

else
COOKFS_PKGCONFIG_USECFSINDEX=0

# TODO: move this outside conditions since
# metadata is supported in pure Tcl version as well
COOKFS_PKGCONFIG_FEATURE_METADATA=1
fi

COOKFS_PKGCONFIG_FEATURE_METADATA=1









if test ${USECPKGCONFIG} = yes; then
COOKFS_PKGCONFIG_USECPKGCONFIG=1
printf "%s\n" "#define COOKFS_PKGCONFIG_FEATURE_ASIDE $COOKFS_PKGCONFIG_FEATURE_ASIDE" >>confdefs.h

printf "%s\n" "#define COOKFS_PKGCONFIG_USECPAGES $COOKFS_PKGCONFIG_USECPAGES" >>confdefs.h

printf "%s\n" "#define COOKFS_PKGCONFIG_USECREADERCHAN $COOKFS_PKGCONFIG_USECREADERCHAN" >>confdefs.h

printf "%s\n" "#define COOKFS_PKGCONFIG_USECPKGCONFIG $COOKFS_PKGCONFIG_USECPKGCONFIG" >>confdefs.h

printf "%s\n" "#define COOKFS_PKGCONFIG_USEBZ2 $COOKFS_PKGCONFIG_USEBZ2" >>confdefs.h

printf "%s\n" "#define COOKFS_PKGCONFIG_USEXZ $COOKFS_PKGCONFIG_USEXZ" >>confdefs.h

printf "%s\n" "#define COOKFS_PKGCONFIG_USECFSINDEX $COOKFS_PKGCONFIG_USECFSINDEX" >>confdefs.h

printf "%s\n" "#define COOKFS_PKGCONFIG_FEATURE_METADATA $COOKFS_PKGCONFIG_FEATURE_METADATA" >>confdefs.h


printf "%s\n" "#define COOKFS_USEPKGCONFIG 1" >>confdefs.h

else
COOKFS_PKGCONFIG_USECPKGCONFIG=0
fi



Expand Down
37 changes: 26 additions & 11 deletions configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ AC_ARG_ENABLE(tcl-fallback, [ --enable-tcl-fallback Install Tcl scripts
AC_ARG_ENABLE(c-pages, [ --disable-c-pages Use pages handling written in C. Defaults to true], USECPAGES=${enableval}, USECPAGES=yes)
AC_ARG_ENABLE(c-fsindex, [ --disable-c-fsindex Use index handling written in C. Defaults to true], USECFSINDEX=${enableval}, USECFSINDEX=yes)
AC_ARG_ENABLE(c-readerchannel, [ --disable-c-readerchannel Use reader handler written in C. Defaults to true], USECREADERCHAN=${enableval}, USECREADERCHAN=yes)
AC_ARG_ENABLE(c-pkgconfig, [ --disable-c-pkgconfig Use pkgconfig written in C. Defaults to true], USECPKGCONFIG=${enableval}, USECPKGCONFIG=yes)

if test ${INTERNALDEBUG} = yes; then
AC_DEFINE(COOKFS_INTERNAL_DEBUG)
Expand Down Expand Up @@ -189,27 +190,41 @@ else
COOKFS_PKGCONFIG_USEBZ2=0
fi

AC_SUBST(COOKFS_PKGCONFIG_FEATURE_ASIDE)
AC_SUBST(COOKFS_PKGCONFIG_USECPAGES)
AC_SUBST(COOKFS_PKGCONFIG_USECREADERCHAN)
AC_SUBST(COOKFS_PKGCONFIG_USEBZ2)
AC_SUBST(COOKFS_PKGCONFIG_USEXZ)

if test ${USECFSINDEX} = yes; then
AC_DEFINE(COOKFS_USECFSINDEX)
COOKFS_PKGCONFIG_USECFSINDEX=1
COOKFS_PKGCONFIG_FEATURE_METADATA=1
TEA_ADD_SOURCES([fsindex.c fsindexIO.c fsindexCmd.c])
else
COOKFS_PKGCONFIG_USECFSINDEX=0

# TODO: move this outside conditions since
# metadata is supported in pure Tcl version as well
COOKFS_PKGCONFIG_FEATURE_METADATA=1
fi

COOKFS_PKGCONFIG_FEATURE_METADATA=1

AC_SUBST(COOKFS_PKGCONFIG_FEATURE_ASIDE)
AC_SUBST(COOKFS_PKGCONFIG_USECPAGES)
AC_SUBST(COOKFS_PKGCONFIG_USECREADERCHAN)
AC_SUBST(COOKFS_PKGCONFIG_USEBZ2)
AC_SUBST(COOKFS_PKGCONFIG_USEXZ)
AC_SUBST(COOKFS_PKGCONFIG_USECFSINDEX)
AC_SUBST(COOKFS_PKGCONFIG_FEATURE_METADATA)

if test ${USECPKGCONFIG} = yes; then
COOKFS_PKGCONFIG_USECPKGCONFIG=1
AC_DEFINE_UNQUOTED(COOKFS_PKGCONFIG_FEATURE_ASIDE, $COOKFS_PKGCONFIG_FEATURE_ASIDE)
AC_DEFINE_UNQUOTED(COOKFS_PKGCONFIG_USECPAGES, $COOKFS_PKGCONFIG_USECPAGES)
AC_DEFINE_UNQUOTED(COOKFS_PKGCONFIG_USECREADERCHAN, $COOKFS_PKGCONFIG_USECREADERCHAN)
AC_DEFINE_UNQUOTED(COOKFS_PKGCONFIG_USECPKGCONFIG, $COOKFS_PKGCONFIG_USECPKGCONFIG)
AC_DEFINE_UNQUOTED(COOKFS_PKGCONFIG_USEBZ2, $COOKFS_PKGCONFIG_USEBZ2)
AC_DEFINE_UNQUOTED(COOKFS_PKGCONFIG_USEXZ, $COOKFS_PKGCONFIG_USEXZ)
AC_DEFINE_UNQUOTED(COOKFS_PKGCONFIG_USECFSINDEX, $COOKFS_PKGCONFIG_USECFSINDEX)
AC_DEFINE_UNQUOTED(COOKFS_PKGCONFIG_FEATURE_METADATA, $COOKFS_PKGCONFIG_FEATURE_METADATA)

AC_DEFINE(COOKFS_USEPKGCONFIG)
else
COOKFS_PKGCONFIG_USECPKGCONFIG=0
fi

AC_SUBST(COOKFS_PKGCONFIG_USECPKGCONFIG)

#--------------------------------------------------------------------
# This macro generates a line to use when building a library. It
Expand Down
16 changes: 12 additions & 4 deletions generic/cookfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ Cookfs_Init(Tcl_Interp *interp)
return TCL_ERROR;
}

if (Tcl_PkgProvide(interp, "vfs::" PACKAGE_NAME "::c", PACKAGE_VERSION) != TCL_OK) {
return TCL_ERROR;
}

strcpy(buf, "namespace eval ::cookfs {} ; namespace eval ::cookfs::c {}");
if (Tcl_EvalEx(interp, buf, -1, TCL_EVAL_DIRECT | TCL_EVAL_GLOBAL) != TCL_OK) {
return TCL_ERROR;
Expand Down Expand Up @@ -67,6 +63,18 @@ Cookfs_Init(Tcl_Interp *interp)
return TCL_ERROR;
}

#ifdef COOKFS_USEPKGCONFIG
Tcl_RegisterConfig(interp, PACKAGE_NAME, cookfs_pkgconfig, "iso8859-1");

if (Tcl_PkgProvide(interp, "vfs::" PACKAGE_NAME "::pkgconfig", PACKAGE_VERSION) != TCL_OK) {
return TCL_ERROR;
}
#endif

if (Tcl_PkgProvide(interp, "vfs::" PACKAGE_NAME "::c", PACKAGE_VERSION) != TCL_OK) {
return TCL_ERROR;
}

return TCL_OK;
}

19 changes: 19 additions & 0 deletions generic/cookfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@

#define UNUSED(expr) do { (void)(expr); } while (0)

#ifndef STRINGIFY
# define STRINGIFY(x) STRINGIFY1(x)
# define STRINGIFY1(x) #x
#endif

#include "common.h"
#include "bindata.h"
#include "hashes.h"
Expand All @@ -46,4 +51,18 @@
#include "readerchannelIO.h"
#endif /* COOKFS_USECREADERCHAN */

#ifdef COOKFS_USEPKGCONFIG
static Tcl_Config const cookfs_pkgconfig[] = {
{"package-version", PACKAGE_VERSION},
{"c-pages", STRINGIFY(COOKFS_PKGCONFIG_USECPAGES)},
{"c-fsindex", STRINGIFY(COOKFS_PKGCONFIG_USECFSINDEX)},
{"c-readerchannel", STRINGIFY(COOKFS_PKGCONFIG_USECREADERCHAN)},
{"feature-aside", STRINGIFY(COOKFS_PKGCONFIG_FEATURE_ASIDE)},
{"feature-bzip2", STRINGIFY(COOKFS_PKGCONFIG_USEBZ2)},
{"feature-xz", STRINGIFY(COOKFS_PKGCONFIG_USEXZ)},
{"feature-metadata", STRINGIFY(COOKFS_PKGCONFIG_FEATURE_METADATA)},
{NULL, NULL}
};
#endif /* COOKFS_USEPKGCONFIG */

#endif /* COOKFS_H */
9 changes: 8 additions & 1 deletion pkgIndex.tcl.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ package ifneeded vfs::@PACKAGE_NAME@::tcl::fsindex @PACKAGE_VERSION@ [list sourc
package ifneeded vfs::@PACKAGE_NAME@::tcl::optimize @PACKAGE_VERSION@ [list source [file join $dir optimize.tcl]]
package ifneeded vfs::@PACKAGE_NAME@::asyncworker::process @PACKAGE_VERSION@ [list source [file join $dir asyncworker_process.tcl]]
package ifneeded vfs::@PACKAGE_NAME@::asyncworker::thread @PACKAGE_VERSION@ [list source [file join $dir asyncworker_thread.tcl]]
package ifneeded vfs::@PACKAGE_NAME@::pkgconfig @PACKAGE_VERSION@ [list source [file join $dir pkgconfig.tcl]]

package ifneeded vfs::@PACKAGE_NAME@::pkgconfig @PACKAGE_VERSION@ [list ::apply {{ dir } {
if { @COOKFS_PKGCONFIG_USECPKGCONFIG@ } {
load [file join $dir @PKG_LIB_FILE@] @PACKAGE_NAME@
} else {
source [file join $dir pkgconfig.tcl]
}
}} $dir]

package ifneeded vfs::@PACKAGE_NAME@::c @PACKAGE_VERSION@ [list load [file join $dir @PKG_LIB_FILE@] @PACKAGE_NAME@]
26 changes: 26 additions & 0 deletions tests/pkgconfig.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

tcltest::test cookfsPkgconfig-1 "Check pkgconfig fields and their types" -body {
set result [list {}]
foreach f [lsort [::cookfs::pkgconfig list]] {
set v [::cookfs::pkgconfig get $f]
if { $v in {0 1} } {
set v "bool"
} elseif { [regexp {^\d+\.\d+\.\d+$} $v] } {
set v "version"
} else {
set v "unknown"
}
lappend result "$f $v"
}
lappend result {}
join $result \n
} -result {
c-fsindex bool
c-pages bool
c-readerchannel bool
feature-aside bool
feature-bzip2 bool
feature-metadata bool
feature-xz bool
package-version version
}

0 comments on commit 08864d4

Please sign in to comment.