Generate .c files instead of .h files

The files' contents haven't changed (other than some relative #include's
that refer to other .c files).

Some build systems have difficulty recognizing .h files as things to be
compiled, instead of just things referred to by things to be compiled.
This commit is contained in:
Nigel Tao committed 2018-12-22 15:29:00 +11:00
1 parent b0429923fc
commit 04c91f1410
24 files changed
+40 -49

No files matched your search

+3 -3
View File
@@ -37,7 +37,7 @@
# gcc zcat.c
# ./a.out < ../../test/data/romeo.txt.gz
if [ ! -e release/c/wuffs-unsupported-snapshot.h ]; then
if [ ! -e release/c/wuffs-unsupported-snapshot.c ]; then
echo "$0 should be run from the Wuffs root directory."
exit 1
fi
@@ -48,11 +48,11 @@ wuffs gen
echo "Checking snapshot compiles cleanly (as C)"
gcc -c -Wall -Werror -DWUFFS_IMPLEMENTATION -std=c99 \
release/c/wuffs-unsupported-snapshot.h -o /dev/null
release/c/wuffs-unsupported-snapshot.c -o /dev/null
echo "Checking snapshot compiles cleanly (as C++)"
g++ -c -Wall -Werror -DWUFFS_IMPLEMENTATION -std=c++11 \
release/c/wuffs-unsupported-snapshot.h -o /dev/null
release/c/wuffs-unsupported-snapshot.c -o /dev/null
wuffs genlib -skipgen
wuffs test -skipgen -mimic
+1 -1
View File
@@ -17,7 +17,7 @@
# See build-all.sh for commentary.
if [ ! -e release/c/wuffs-unsupported-snapshot.h ]; then
if [ ! -e release/c/wuffs-unsupported-snapshot.c ]; then
echo "$0 should be run from the Wuffs root directory."
exit 1
fi
+1 -1
View File
@@ -17,7 +17,7 @@
# See build-all.sh for commentary.
if [ ! -e release/c/wuffs-unsupported-snapshot.h ]; then
if [ ! -e release/c/wuffs-unsupported-snapshot.c ]; then
echo "$0 should be run from the Wuffs root directory."
exit 1
fi
+2 -2
View File
@@ -83,11 +83,11 @@ var (
func genObj(outDir string, inDir string, cc string, dynamism string, filenames []string) error {
for _, filename := range filenames {
in := filepath.Join(inDir, filename+".h")
in := filepath.Join(inDir, filename+".c")
out := genlibOutFilename(outDir, dynamism, filename)
args := []string(nil)
args = append(args, "-x", "c", "-O3", "-std=c99", "-DWUFFS_IMPLEMENTATION")
args = append(args, "-O3", "-std=c99", "-DWUFFS_IMPLEMENTATION")
if dynamism == "dynamic" {
args = append(args, "-fPIC", "-DPIC")
}
+2 -2
View File
@@ -416,9 +416,9 @@ func (g *gen) genIncludes(b *buffer) error {
}
sort.Strings(usesList)
b.writes("#include \"./wuffs-base.h\"\n")
b.writes("#include \"./wuffs-base.c\"\n")
for _, use := range usesList {
b.printf("#include \"./wuffs-%s.h\"\n",
b.printf("#include \"./wuffs-%s.c\"\n",
strings.Replace(use, "/", "-", -1))
}
+3 -3
View File
@@ -53,7 +53,7 @@ func doGenrelease(args []string) error {
// Calculate the base directory.
baseDir := ""
for _, filename := range args {
if filepath.Base(filename) != "wuffs-base.h" {
if filepath.Base(filename) != "wuffs-base.c" {
continue
}
baseDir = filepath.Dir(filename)
@@ -188,7 +188,7 @@ func (h *genReleaseHelper) parse(relFilename string, s []byte) error {
f.fragments[1] = s[:i]
}
if relFilename == "wuffs-base.h" && (h.version != cf.Version{}) {
if relFilename == "wuffs-base.c" && (h.version != cf.Version{}) {
if subs, err := h.substituteWuffsVersion(f.fragments[0]); err != nil {
return err
} else {
@@ -254,7 +254,7 @@ func (h *genReleaseHelper) gen(w *bytes.Buffer, relFilename string, which int, d
func (h *genReleaseHelper) substituteWuffsVersion(s []byte) ([]byte, error) {
ret := []byte(nil)
if i := bytes.Index(s, grVOverride); i < 0 {
return nil, fmt.Errorf("could not find %q in %s", grVOverride, "wuffs-base.h")
return nil, fmt.Errorf("could not find %q in %s", grVOverride, "wuffs-base.c")
} else {
ret = append(ret, s[:i]...)
s = s[i+len(grVOverride):]
+4 -9
View File
@@ -199,13 +199,8 @@ func (h *genHelper) genDir(dirname string, qualFilenames []string) error {
}
out := stdout.Bytes()
suffix := lang
if suffix == "c" {
suffix = "h"
}
flatDirname := fmt.Sprintf("wuffs-%s", strings.Replace(dirname, "/", "-", -1))
if err := h.genFile(flatDirname, lang, suffix, out); err != nil {
if err := h.genFile(flatDirname, lang, out); err != nil {
return err
}
}
@@ -237,9 +232,9 @@ func (h *genHelper) genDirDependencies(qualifiedFilenames []string) error {
return h.gen("base", false)
}
func (h *genHelper) genFile(dirname string, lang string, suffix string, out []byte) error {
func (h *genHelper) genFile(dirname string, lang string, out []byte) error {
return writeFile(
filepath.Join(h.wuffsRoot, "gen", lang, filepath.FromSlash(dirname)+"."+suffix),
filepath.Join(h.wuffsRoot, "gen", lang, filepath.FromSlash(dirname)+"."+lang),
out,
)
}
@@ -310,7 +305,7 @@ func (h *genHelper) genWuffs(dirname string, qualifiedFilenames []string) error
}
}
}
return h.genFile(dirname, "wuffs", "wuffs", out.Bytes())
return h.genFile(dirname, "wuffs", out.Bytes())
}
func (h *genHelper) genlibAffected() error {
+4 -13
View File
@@ -28,12 +28,7 @@ import (
func genrelease(wuffsRoot string, langs []string, v cf.Version) error {
revision := findRevision(wuffsRoot)
for _, lang := range langs {
suffix := lang
if suffix == "c" {
suffix = "h"
}
filename, contents, err := genreleaseLang(wuffsRoot, revision, v, lang, suffix)
filename, contents, err := genreleaseLang(wuffsRoot, revision, v, lang)
if err != nil {
return err
}
@@ -44,7 +39,7 @@ func genrelease(wuffsRoot string, langs []string, v cf.Version) error {
return nil
}
func genreleaseLang(wuffsRoot string, revision string, v cf.Version, lang string, suffix string) (filename string, contents []byte, err error) {
func genreleaseLang(wuffsRoot string, revision string, v cf.Version, lang string) (filename string, contents []byte, err error) {
// During a transitional period (starting in November 2018), remove any
// existing wuffs-c generated files that use the old naming scheme (e.g.
// "base.h" or "std/gif.h") instead of the new naming scheme (e.g.
@@ -55,7 +50,7 @@ func genreleaseLang(wuffsRoot string, revision string, v cf.Version, lang string
os.RemoveAll(filepath.Join(baseDir, "std"))
}
qualFilenames, err := findFiles(filepath.Join(wuffsRoot, "gen", lang), "."+suffix)
qualFilenames, err := findFiles(filepath.Join(wuffsRoot, "gen", lang), "."+lang)
if err != nil {
return "", nil, err
}
@@ -81,11 +76,7 @@ func genreleaseLang(wuffsRoot string, revision string, v cf.Version, lang string
if v.Major != 0 || v.Minor != 0 {
base = fmt.Sprintf("wuffs-v%d.%d", v.Major, v.Minor)
}
ext := lang
if ext == "c" {
ext = "h"
}
return filepath.Join(wuffsRoot, "release", lang, base+"."+ext), stdout.Bytes(), nil
return filepath.Join(wuffsRoot, "release", lang, base+"."+lang), stdout.Bytes(), nil
}
func findRevision(wuffsRoot string) string {
+1 -1
View File
@@ -47,7 +47,7 @@ for a C++ compiler $CXX, such as clang++ or g++.
// If building this program in an environment that doesn't easily accommodate
// relative includes, you can use the script/inline-c-relative-includes.go
// program to generate a stand-alone C++ file.
#include "../../release/c/wuffs-unsupported-snapshot.h"
#include "../../release/c/wuffs-unsupported-snapshot.c"
#ifndef SRC_BUFFER_SIZE
#define SRC_BUFFER_SIZE (32 * 1024)
+1 -1
View File
@@ -64,7 +64,7 @@ uint64_t micros_since_start(struct timespec* now) {
// If building this program in an environment that doesn't easily accommodate
// relative includes, you can use the script/inline-c-relative-includes.go
// program to generate a stand-alone C file.
#include "../../release/c/wuffs-unsupported-snapshot.h"
#include "../../release/c/wuffs-unsupported-snapshot.c"
// Limit the input GIF image to (64 MiB - 1 byte) compressed and 4096 × 4096
// pixels uncompressed. This is a limitation of this example program (which
+6 -1
View File
@@ -33,7 +33,12 @@ for a C compiler $CC, such as clang or gcc.
#include <stdlib.h>
#include <unistd.h>
#include "wuffs/release/c/wuffs-unsupported-snapshot.h"
// Wuffs ships as a "single file C library" or "header file library" as per
// https://github.com/nothings/stb/blob/master/docs/stb_howto.txt
//
// By #include'ing it "as is" without #define'ing WUFFS_IMPLEMENTATION, we use
// it as a "foo.h"-like header, instead of a "foo.c"-like implementation.
#include "wuffs/release/c/wuffs-unsupported-snapshot.c"
#define DST_BUFFER_SIZE (1024 * 1024)
+2 -2
View File
@@ -34,7 +34,7 @@ for a C compiler $CC, such as clang or gcc.
#define WUFFS_IMPLEMENTATION
// Defining the WUFFS_CONFIG__MODULE* macros are optional, but it lets users of
// release/c/etc.h whitelist which parts of Wuffs to build. That file contains
// release/c/etc.c whitelist which parts of Wuffs to build. That file contains
// the entire Wuffs standard library, implementing a variety of codecs and file
// formats. Without this macro definition, an optimizing compiler or linker may
// very well discard Wuffs code for unused codecs, but listing the Wuffs
@@ -49,7 +49,7 @@ for a C compiler $CC, such as clang or gcc.
// If building this program in an environment that doesn't easily accommodate
// relative includes, you can use the script/inline-c-relative-includes.go
// program to generate a stand-alone C file.
#include "../../release/c/wuffs-unsupported-snapshot.h"
#include "../../release/c/wuffs-unsupported-snapshot.c"
#ifdef __linux__
#include <linux/prctl.h>
+1 -1
View File
@@ -43,7 +43,7 @@ It should print "PASS", amongst other information, and exit(0).
// If building this program in an environment that doesn't easily accommodate
// relative includes, you can use the script/inline-c-relative-includes.go
// program to generate a stand-alone C file.
#include "../../../release/c/wuffs-unsupported-snapshot.h"
#include "../../../release/c/wuffs-unsupported-snapshot.c"
#include "../fuzzlib/fuzzlib.c"
const char* fuzz(wuffs_base__io_reader src_reader, uint32_t hash) {
+1 -1
View File
@@ -43,7 +43,7 @@ It should print "PASS", amongst other information, and exit(0).
// If building this program in an environment that doesn't easily accommodate
// relative includes, you can use the script/inline-c-relative-includes.go
// program to generate a stand-alone C file.
#include "../../../release/c/wuffs-unsupported-snapshot.h"
#include "../../../release/c/wuffs-unsupported-snapshot.c"
#include "../fuzzlib/fuzzlib.c"
const char* fuzz(wuffs_base__io_reader src_reader, uint32_t hash) {
+1 -1
View File
@@ -4,7 +4,7 @@ library](https://github.com/nothings/stb/blob/master/docs/stb_howto.txt)".
To use Wuffs in your C/C++ project, you just need to copy one file from this
directory, or otherwise integrate that one file into your build system.
Typically, pick the latest version (but not the unsupported snapshot), with a
filename like `wuffs-vMAJOR.MINOR.h` for version MAJOR.MINOR.
filename like `wuffs-vMAJOR.MINOR.c` for version MAJOR.MINOR.
To use that single file as a "foo.c"-like implementation, instead of a
"foo.h"-like header, `#define WUFFS_IMPLEMENTATION` before `#include`'ing or
File renamed without changes.
+1 -1
View File
@@ -59,7 +59,7 @@ the first "./a.out" with "./a.out -bench". Combine these changes with the
// If building this program in an environment that doesn't easily accommodate
// relative includes, you can use the script/inline-c-relative-includes.go
// program to generate a stand-alone C file.
#include "../../../release/c/wuffs-unsupported-snapshot.h"
#include "../../../release/c/wuffs-unsupported-snapshot.c"
#include "../testlib/testlib.c"
#ifdef WUFFS_MIMIC
#include "../mimiclib/deflate-gzip-zlib.c"
+1 -1
View File
@@ -59,7 +59,7 @@ the first "./a.out" with "./a.out -bench". Combine these changes with the
// If building this program in an environment that doesn't easily accommodate
// relative includes, you can use the script/inline-c-relative-includes.go
// program to generate a stand-alone C file.
#include "../../../release/c/wuffs-unsupported-snapshot.h"
#include "../../../release/c/wuffs-unsupported-snapshot.c"
#include "../testlib/testlib.c"
#ifdef WUFFS_MIMIC
#include "../mimiclib/deflate-gzip-zlib.c"
+1 -1
View File
@@ -59,7 +59,7 @@ the first "./a.out" with "./a.out -bench". Combine these changes with the
// If building this program in an environment that doesn't easily accommodate
// relative includes, you can use the script/inline-c-relative-includes.go
// program to generate a stand-alone C file.
#include "../../../release/c/wuffs-unsupported-snapshot.h"
#include "../../../release/c/wuffs-unsupported-snapshot.c"
#include "../testlib/testlib.c"
#ifdef WUFFS_MIMIC
#include "../mimiclib/deflate-gzip-zlib.c"
+1 -1
View File
@@ -60,7 +60,7 @@ the first "./a.out" with "./a.out -bench". Combine these changes with the
// If building this program in an environment that doesn't easily accommodate
// relative includes, you can use the script/inline-c-relative-includes.go
// program to generate a stand-alone C file.
#include "../../../release/c/wuffs-unsupported-snapshot.h"
#include "../../../release/c/wuffs-unsupported-snapshot.c"
#include "../testlib/testlib.c"
#ifdef WUFFS_MIMIC
#include "../mimiclib/gif.c"
+1 -1
View File
@@ -61,7 +61,7 @@ the first "./a.out" with "./a.out -bench". Combine these changes with the
// If building this program in an environment that doesn't easily accommodate
// relative includes, you can use the script/inline-c-relative-includes.go
// program to generate a stand-alone C file.
#include "../../../release/c/wuffs-unsupported-snapshot.h"
#include "../../../release/c/wuffs-unsupported-snapshot.c"
#include "../testlib/testlib.c"
#ifdef WUFFS_MIMIC
#include "../mimiclib/deflate-gzip-zlib.c"
+1 -1
View File
@@ -59,7 +59,7 @@ the first "./a.out" with "./a.out -bench". Combine these changes with the
// If building this program in an environment that doesn't easily accommodate
// relative includes, you can use the script/inline-c-relative-includes.go
// program to generate a stand-alone C file.
#include "../../../release/c/wuffs-unsupported-snapshot.h"
#include "../../../release/c/wuffs-unsupported-snapshot.c"
#include "../testlib/testlib.c"
// ---------------- LZW Tests
+1 -1
View File
@@ -61,7 +61,7 @@ the first "./a.out" with "./a.out -bench". Combine these changes with the
// If building this program in an environment that doesn't easily accommodate
// relative includes, you can use the script/inline-c-relative-includes.go
// program to generate a stand-alone C file.
#include "../../../release/c/wuffs-unsupported-snapshot.h"
#include "../../../release/c/wuffs-unsupported-snapshot.c"
#include "../testlib/testlib.c"
#ifdef WUFFS_MIMIC
#include "../mimiclib/deflate-gzip-zlib.c"