Skip to content

Commit

Permalink
Allow a wider range of C file extensions (e.g. .m, .cpp, ...) when li…
Browse files Browse the repository at this point in the history
…nking (gsc -link)
  • Loading branch information
feeley committed Jul 26, 2011
1 parent 394beeb commit 2e89dcd
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 69 deletions.
29 changes: 18 additions & 11 deletions doc/gambit-c.txi
Expand Up @@ -773,14 +773,17 @@ file unless the @samp{-f} option is specified.
@flindex @var{file}.six
@flindex @var{file}.c
In batch mode @code{gsc} takes a set of file names (with either no
extension, or a @samp{.c} extension, or some other extension) on the
extension, or a C file extension, or some other extension) on the
command line and compiles each Scheme file into a C file.
The recognized C file extensions are @samp{.c}, @samp{.C}, @samp{.cc},
@samp{.cp}, @samp{.cpp}, @samp{.CPP}, @samp{.cxx}, @samp{.c++},
@samp{.m}, @samp{.M}, and @samp{.mm}.
The extension can be omitted from @var{file} when the Scheme file has a
@samp{.scm} or @samp{.six} extension. When the extension of the
Scheme file is @samp{.six} the content of the file will be parsed
using the Scheme infix syntax extension (see @ref{Scheme infix syntax
extension}). Otherwise, @code{gsc} will parse the Scheme file using the
normal Scheme prefix syntax. Files with a @samp{.c} extension must
normal Scheme prefix syntax. Files with a C file extension must
have been previously produced by @code{gsc}, with the @samp{-c} option,
and are used by Gambit's linker.

Expand Down Expand Up @@ -1549,7 +1552,10 @@ Gambit @value{VERSION}
@cindex object file

The @var{file}, @var{options}, and @var{output} parameters have the
same meaning as for the @code{compile-file-to-c} procedure. The
same meaning as for the @code{compile-file-to-c} procedure, except that
@var{file} may be a Scheme source file or a
C file possibly generated by the Gambit Scheme compiler (for example
with the @code{compile-file-to-c} procedure). The
@var{cc-options} parameter is a string containing the options to pass
to the C compiler and the @var{ld-options-prelude} and
@var{ld-options} parameters are strings containing the options to pass
Expand All @@ -1561,9 +1567,7 @@ The @code{compile-file} procedure compiles the source file @var{file}
into an object file, which is either a file dynamically loadable using
the @code{load} procedure, or a C linkable object file destined to be
linked with the C linker (for example to create a standalone
executable program). The @var{file} may be a Scheme source file or a
C file possibly generated by the Gambit Scheme compiler (for example
with the @code{compile-file-to-c} procedure). The presence of the
executable program). The presence of the
@code{obj} option in @var{options} will cause the creation of a C
linkable object file and therefore the options
@var{ld-options-prelude} and @var{ld-options} are ignored, otherwise a
Expand Down Expand Up @@ -1631,10 +1635,11 @@ hello
@pindex gsc

The first parameter must be a non empty list of strings naming Scheme
modules to link (extensions must be omitted). An incremental link
modules to link (the file extension may be omitted). An incremental link
file is generated for the modules specified in @var{module-list}. By
default the link file generated is named @samp{@var{last}_.c}, where
@var{last} is the name of the last module. The name of the generated
@var{last} is the name of the last module, without the file extension.
The name of the generated
link file can be specified with the @var{output} parameter. If
@var{output} is a string naming a directory then the link file is
created in that directory. Otherwise the name of the link file is
Expand All @@ -1643,7 +1648,8 @@ created in that directory. Otherwise the name of the link file is
The base link file is specified by the @var{base} parameter, which
must be a string. By default the base link file is the Gambit runtime
library link file @samp{~~lib/_gambc.c}. However, when @var{base} is
supplied the base link file is named @samp{@var{base}.c}.
supplied it is the name of the base link file (the file extension
may be omitted).

The @var{warnings?} parameter controls whether warnings are
generated for undefined references.
Expand Down Expand Up @@ -1685,9 +1691,10 @@ world
@pindex gsc

The first parameter must be a non empty list of strings naming Scheme
modules to link. The first string must be the name of a Scheme module
modules to link (the file extension may be omitted). The first string
must be the name of a Scheme module
or the name of a link file and the remaining strings must name Scheme
modules (in all cases extensions must be omitted). A flat link file
modules. A flat link file
is generated for the modules specified in @var{module-list}. By
default the link file generated is named @samp{@var{last}_.c}, where
@var{last} is the name of the last module. The name of the generated
Expand Down
26 changes: 13 additions & 13 deletions gsc/_gsclib.scm
Expand Up @@ -74,16 +74,14 @@
(##path-strip-directory
(##path-strip-extension filename))
expanded-output)
(c#targ-preferred-c-file-extension))))
(c-filename-no-dir-no-ext
(##path-strip-directory
(##path-strip-extension c-filename))))
(c#targ-preferred-c-file-extension)))))
(and (c#cf filename
#f
options
c-filename
(or mod-name
c-filename-no-dir-no-ext))
(##path-strip-directory
(##path-strip-extension c-filename))))
c-filename)))

(define (compile-file
Expand Down Expand Up @@ -371,9 +369,7 @@
(let* ((out
(if (##eq? output (macro-absent-obj))
(##path-directory
(##path-normalize
(##string-append (##car rev-mods)
(c#targ-preferred-c-file-extension))))
(##path-normalize (##car rev-mods)))
(macro-force-vars (output)
output)))
(baselib
Expand Down Expand Up @@ -411,7 +407,10 @@
expanded-output
(##path-expand
(##path-strip-directory
(##string-append (##car rev-mods) "_.c"))
(##string-append
(##path-strip-extension (##car rev-mods))
"_"
(c#targ-preferred-c-file-extension)))
expanded-output)))
(base-and-mods
(##cons base (##reverse rev-mods))))
Expand Down Expand Up @@ -444,9 +443,7 @@
(let* ((out
(if (##eq? output (macro-absent-obj))
(##path-directory
(##path-normalize
(##string-append (##car rev-mods)
(c#targ-preferred-c-file-extension))))
(##path-normalize (##car rev-mods)))
(macro-force-vars (output)
output)))
(warn?
Expand All @@ -471,7 +468,10 @@
expanded-output
(##path-expand
(##path-strip-directory
(##string-append (##car rev-mods) "_.c"))
(##string-append
(##path-strip-extension (##car rev-mods))
"_"
(c#targ-preferred-c-file-extension)))
expanded-output)))
(mods
(##reverse rev-mods)))
Expand Down
6 changes: 5 additions & 1 deletion gsc/_t-c-1.scm
Expand Up @@ -775,7 +775,11 @@
(string-append module-prefix
(path-strip-directory root)))
(input-files
(map (lambda (x) (string-append x (targ-preferred-c-file-extension))) inputs))
(map (lambda (x)
(if (string=? (path-extension x) "")
(string-append x (targ-preferred-c-file-extension))
x))
inputs))
(input-infos
(map targ-read-linker-info input-files))
(input-mods
Expand Down
87 changes: 43 additions & 44 deletions gsi/main.scm
Expand Up @@ -405,46 +405,44 @@

(if (##memq type '(link exe))

(let ((roots
(and (##pair? rev-gen-c-files)
(let* ((roots
(##map ##path-strip-extension
(##reverse rev-gen-c-files)))
(link-file
(if flat?
(if (and output
(##eq? type 'link))
(link-flat roots
output: output)
(link-flat roots))
(if (and output
(##eq? type 'link))
(if base
(link-incremental
roots
output: output
base: base)
(link-incremental
roots
output: output))
(if base
(link-incremental
roots
base: base)
(link-incremental
roots))))))
(add-gen-c-file link-file)
(if (##eq? type 'exe)
(let ((obj-link-file
(do-compile-file
link-file
(##cons 'obj sym-opts)
#f)))
(add-obj-file obj-link-file)
(add-tmp-file obj-link-file)
(if (##not (##memq 'keep-c sym-opts))
(add-tmp-file link-file))))
roots))))
(let ((gen-c-files
(##reverse rev-gen-c-files)))

(if (##pair? gen-c-files)
(let* ((link-file
(if flat?
(if (and output
(##eq? type 'link))
(link-flat gen-c-files
output: output)
(link-flat gen-c-files))
(if (and output
(##eq? type 'link))
(if base
(link-incremental
gen-c-files
output: output
base: base)
(link-incremental
gen-c-files
output: output))
(if base
(link-incremental
gen-c-files
base: base)
(link-incremental
gen-c-files))))))
(add-gen-c-file link-file)
(if (##eq? type 'exe)
(let ((obj-link-file
(do-compile-file
link-file
(##cons 'obj sym-opts)
#f)))
(add-obj-file obj-link-file)
(add-tmp-file obj-link-file)
(if (##not (##memq 'keep-c sym-opts))
(add-tmp-file link-file))))))

(if (##eq? type 'exe)
(and (##pair? rev-obj-files)
Expand All @@ -461,10 +459,11 @@
expanded-output)))
expanded-output
(##string-append
(if roots
(##car (##reverse roots))
(##path-strip-extension
(##car rev-obj-files)))
(##path-strip-extension
(##car
(if (##pair? gen-c-files)
(##reverse gen-c-files)
rev-obj-files)))
##os-exe-extension-string-saved))))))))

(if flat?
Expand Down

0 comments on commit 2e89dcd

Please sign in to comment.