Because LaTeX packages are mentioned and used, I assume the package is a LaTeX package.
If you want to install the package in a TDS compliant tree, the file names of the modules
must be unique, see TDS specification, "2.4 Duplicate filenames":
Names of TEX input files must be unique within each first-level
subdirectory of texmf/tex and texmf/tex/generic, [...]
Also modern TeX distributions support the search in subdirectories since many years.
There is no need to specify the directories for finding the modules.
Then, with unique file names, you can use LaTeX for the module management. Modules in LaTeX are packages. LaTeX does not load a package file twice. At the second loading request it only checks the options. It triggers errors/warnings in the following cases:
- The requested file name (
\RequirePackage or \usepackage) differs from the provided file name (\ProvidesPackage inside the file).
- Later requests come with options that are not present at the first package loading.
- Version management: The date provided in the package (
\ProvidesPackage) is older than the date in the final optional argument of \RequirePackage or \usepackage.
Example for module moda and package pkg. The file name of the module would be
pkg-moda.sty. It contains the line, e.g.:
\ProvidesPackage{pkg-moda}[2012/10/06 v2.4 Module moda for package pkg]
This module is then loaded in other modules or the package via:
\RequirePackage{pkg-moda}
Then LaTeX will load the module the first time only.
If the module should require a certain version, the date can be added:
\RequirePackage{pkg-moda}[2012/10/06]
or
\RequirePackage{pkg-moda}[2010/06/01]
if the versions of pkg-moda since 2010/06/01 implements the needed features.
plain TeX
LaTeX's package management is not provided by plain TeX.
There each module can define a marker that is checked at the beginning of module loading:
% File: pkg-moda.sty
\expandafter\ifx\csname ver@pkg-moda.sty\endcsname\relax
\else
\expandafter\endinput
\fi
\expandafter\def\csname ver@pkg-moda.sty\endcsname{2012/10/06}
- The extension of the file name does not matter. I have used
.sty because
many of my LaTeX packages can also be loaded by plain TeX (or even iniTeX),
the extension comes from the LaTeX requirements for a package.
The marker can be anything, a command that is exclusively defined by the module,
a register that is exclusively allocated by the module, …
In the example above I have used the LaTeX convention:
\ver@<filename> is either the empty macro:
\expandafter\def\csname ver@<filename>\endcsname{}
or it contains the date in form of YYYY/MM/DD, optionally followed by a space and
a version number and a description.
The first check at the beginning of the file stops the further loading of the module, if the marker is already defined.
Also the check can be added before loading the module, e.g.:
\expandafter\ifx\csname ver@pkg-moda.sty\endcsname\relax
\input pkg-moda.sty\relax
\fi
Then the module file is not even opened, when it is already loaded.