Skip to content

Commit

Permalink
Merge pull request #1350 from henryso/fix-1292
Browse files Browse the repository at this point in the history
Added --enable-texlive flag and support for a suffix-less executable.
  • Loading branch information
rpspringuel authored Apr 15, 2017
2 parents e73fed6 + 8093b37 commit 4dd27b1
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 14 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ You need a recent and working [TeXLive](https://www.tug.org/texlive/), on top of
- Switch to TeXLive 2015 (which uses an earlier version of `luaotfload`) to build the docs.
- Upgrade your `luaotfload` to a more recent version (v2.8 or later).

## Building for inclusion in TeXLive

When building gregorio for inclusion in TeXLive, the gregorio executable must not have the version number prefix that is used for other builds. To make this happen, run `configure` with the `--enable-texlive` option and the generated Makefile will create a gregorio executable without the version number prefix (i.e., the executable will simply be named `gregorio`).

## Documentation

You can find documentation and useful links in the [documentation](doc/), on [the main website](http://gregorio-project.github.io/) and on [a wiki](http://gregoriochant.org).
Expand Down
11 changes: 11 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@ AC_ARG_ENABLE([debug], AS_HELP_STRING([--enable-debug@<:@=sanitize,coverage@:>@]
CPPFLAGS+=" -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 "
])

AC_ARG_ENABLE([texlive], AS_HELP_STRING([--enable-texlive], [Enable TeX Live executable name.]), [
AS_IF([test "x$enableval" != "xno"], [
GREGORIO_EXE_SUFFIX=""
], [
GREGORIO_EXE_SUFFIX="-$FILENAME_VERSION"
])
], [
GREGORIO_EXE_SUFFIX="-$FILENAME_VERSION"
])
AC_SUBST(GREGORIO_EXE_SUFFIX)

AC_CONFIG_HEADERS([src/config_.h])
AC_CONFIG_FILES([
Makefile
Expand Down
8 changes: 4 additions & 4 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ AM_CPPFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/src/gabc -I$(top_srcdir)/src/
AM_CFLAGS = $(KPSE_CFLAGS)
LDADD = $(KPSE_LIBS)

bin_PROGRAMS = gregorio-$(FILENAME_VERSION)
gregorio___FILENAME_VERSION__SOURCES = \
bin_PROGRAMS = gregorio$(GREGORIO_EXE_SUFFIX)
gregorio__GREGORIO_EXE_SUFFIX__SOURCES = \
gregorio-utils.c characters.c characters.h messages.c messages.h struct.c \
struct.h struct_iter.h enum_generator.h unicode.c unicode.h sha1.c sha1.h \
support.c support.h config.h bool.h plugins.h utf8strings.h dump/dump.c \
Expand All @@ -47,7 +47,7 @@ gregorio___FILENAME_VERSION__SOURCES = \
@MK@endif

# gabc files
gregorio___FILENAME_VERSION__SOURCES += \
gregorio__GREGORIO_EXE_SUFFIX__SOURCES += \
gabc/gabc-elements-determination.c gabc/gabc-write.c \
gabc/gabc-glyphs-determination.c gabc/gabc.h \
gabc/gabc-score-determination.h gabc/gabc-score-determination.c \
Expand All @@ -72,7 +72,7 @@ if HAVE_RC
gregorio-resources.o: ../windows/gregorio-resources.rc ../windows/gregorio.ico
$(RC) $(RCFLAGS) $< -o $@

gregorio___FILENAME_VERSION__SOURCES += ../windows/gregorio-resources.rc ../windows/gregorio.ico
gregorio__GREGORIO_EXE_SUFFIX__SOURCES += ../windows/gregorio-resources.rc ../windows/gregorio.ico
LDADD += gregorio-resources.o
endif

Expand Down
51 changes: 41 additions & 10 deletions tex/gregoriotex.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ local err, warn, info, log = luatexbase.provides_module({
license = "GPLv3+",
})

local gregorio_exe = 'gregorio-5_0_0-rc1' -- FILENAME_VERSION
local real_gregorio_exe = nil

gregoriotex.module = { err = err, warn = warn, info = info, log = log }

Expand Down Expand Up @@ -120,6 +120,37 @@ local translation_mark = 1
local abovelinestext_mark = 2
log("marker whatsit id is %d", marker_whatsit_id)

local function gregorio_exe()
if real_gregorio_exe == nil then
local exe_version

-- first look for one with the exact version
real_gregorio_exe = 'gregorio-5_0_0-rc1' -- FILENAME_VERSION
exe_version = io.popen(real_gregorio_exe..' --version', 'r')
exe_version = exe_version:read("*line")
if not exe_version then
-- look for suffix-less executable
real_gregorio_exe = 'gregorio'
exe_version = io.popen(real_gregorio_exe..' --version', 'r')
exe_version = exe_version:read("*line")
if not exe_version or string.match(exe_version,"%d+%.%d+%.")
~= string.match(internalversion,"%d+%.%d+%.") then
real_gregorio_exe = nil
err("Unable to find gregorio executable.\n"..
"shell-escape mode may not be activated. Try\n\n"..
"%s --shell-escape %s.tex\n\n"..
"See the documentation of Gregorio or your TeX\n"..
"distribution to automatize it.",
tex.formatname, tex.jobname)
end
end

log("will use %s", real_gregorio_exe)
end

return real_gregorio_exe
end

local function mark(value)
local marker = create_marker()
marker.type = 100
Expand Down Expand Up @@ -740,8 +771,8 @@ local function compile_gabc(gabc_file, gtex_file, glog_file, allow_deprecated)
extra_args = extra_args..' -D'
end

local cmd = string.format("%s %s -W -o %s -l %s '%s'", gregorio_exe, extra_args,
gtex_file, glog_file, gabc_file)
local cmd = string.format("%s %s -W -o %s -l %s '%s'", gregorio_exe(),
extra_args, gtex_file, glog_file, gabc_file)
res = os.execute(cmd)
if res == nil then
err("\nSomething went wrong when executing\n '%s'.\n"
Expand All @@ -766,7 +797,8 @@ local function compile_gabc(gabc_file, gtex_file, glog_file, allow_deprecated)
glog:close()
end
err("\nAn error occured when compiling the score file\n"
.."'%s' with %s.\nPlease check your score file.", gabc_file, gregorio_exe)
.."'%s' with %s.\nPlease check your score file.", gabc_file,
gregorio_exe())
else
-- open the gtex file for writing so that LuaTeX records output to it
-- when the -recorder option is used
Expand Down Expand Up @@ -797,7 +829,7 @@ end
local function include_score(input_file, force_gabccompile, allow_deprecated)
if string.match(input_file, "[#%%]") then
err("GABC filename contains invalid character(s): # %%\n"
.."Rename the file and retry: %s", input_file)
.."Rename the file and retry: %s", input_file)
end
local has_extention = false
local file_dir,input_name
Expand All @@ -806,18 +838,17 @@ local function include_score(input_file, force_gabccompile, allow_deprecated)
has_extention = true
end
if has_extention then
file_dir,input_name = string.match(input_file,
"(.-)([^\\/]-)%.?[^%.\\/]*$")
file_dir,input_name = string.match(input_file, "(.-)([^\\/]-)%.?[^%.\\/]*$")
else
file_dir,input_name = string.match(input_file, "(.-)([^\\/]*)$")
end

local cleaned_filename = input_name:gsub("[%s%+%&%*%?$@:;!\"\'`]", "-")
local gabc_file = string.format("%s%s.gabc", file_dir, input_name)
local gtex_file = string.format("%s%s-%s.gtex", file_dir, cleaned_filename,
internalversion:gsub("%.", "_"))
internalversion:gsub("%.", "_"))
local glog_file = string.format("%s%s-%s.glog", file_dir, cleaned_filename,
internalversion:gsub("%.", "_"))
internalversion:gsub("%.", "_"))
if not lfs.isfile(gtex_file) then
clean_old_gtex_files(file_dir..cleaned_filename)
log("The file %s does not exist. Searching for a gabc file", gtex_file)
Expand Down Expand Up @@ -871,7 +902,7 @@ local function direct_gabc(gabc, header, allow_deprecated)
gabc = gabc:match('^()%s*$') and '' or gabc:match('^%s*(.*%S)')
f:write('name:direct-gabc;\n'..(header or '')..'\n%%\n'..gabc:gsub('\\par ', '\n'))
f:close()
local cmd = string.format('%s -W %s-S -l %s %s', gregorio_exe, deprecated,
local cmd = string.format('%s -W %s-S -l %s %s', gregorio_exe(), deprecated,
snippet_logname, snippet_filename)
local p = io.popen(cmd, 'r')
if p == nil then
Expand Down

0 comments on commit 4dd27b1

Please sign in to comment.