diff --git a/build-all.sh b/build-all.sh index 4e93a565..af07c7bb 100755 --- a/build-all.sh +++ b/build-all.sh @@ -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 diff --git a/build-example.sh b/build-example.sh index c998b9b6..296049e1 100755 --- a/build-example.sh +++ b/build-example.sh @@ -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 diff --git a/build-fuzz.sh b/build-fuzz.sh index 950c82d7..48e9ee67 100755 --- a/build-fuzz.sh +++ b/build-fuzz.sh @@ -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 diff --git a/cmd/wuffs-c/genlib.go b/cmd/wuffs-c/genlib.go index 3db4d88c..a7bb1d50 100644 --- a/cmd/wuffs-c/genlib.go +++ b/cmd/wuffs-c/genlib.go @@ -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") } diff --git a/cmd/wuffs-c/internal/cgen/cgen.go b/cmd/wuffs-c/internal/cgen/cgen.go index 5242899f..9d5a4c5d 100644 --- a/cmd/wuffs-c/internal/cgen/cgen.go +++ b/cmd/wuffs-c/internal/cgen/cgen.go @@ -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)) } diff --git a/cmd/wuffs-c/release.go b/cmd/wuffs-c/release.go index 9b7ebfaf..59f26f70 100644 --- a/cmd/wuffs-c/release.go +++ b/cmd/wuffs-c/release.go @@ -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):] diff --git a/cmd/wuffs/gen.go b/cmd/wuffs/gen.go index 88668973..244c4e79 100644 --- a/cmd/wuffs/gen.go +++ b/cmd/wuffs/gen.go @@ -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 { diff --git a/cmd/wuffs/release.go b/cmd/wuffs/release.go index b9724fe7..affe45f7 100644 --- a/cmd/wuffs/release.go +++ b/cmd/wuffs/release.go @@ -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 { diff --git a/example/crc32/crc32.cc b/example/crc32/crc32.cc index 6bb43a77..2222944c 100644 --- a/example/crc32/crc32.cc +++ b/example/crc32/crc32.cc @@ -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) diff --git a/example/gifplayer/gifplayer.c b/example/gifplayer/gifplayer.c index b64489be..3f9fa7a5 100644 --- a/example/gifplayer/gifplayer.c +++ b/example/gifplayer/gifplayer.c @@ -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 diff --git a/example/library/library.c b/example/library/library.c index 723f86ff..bf3fa15e 100644 --- a/example/library/library.c +++ b/example/library/library.c @@ -33,7 +33,12 @@ for a C compiler $CC, such as clang or gcc. #include #include -#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) diff --git a/example/zcat/zcat.c b/example/zcat/zcat.c index 8af3069f..22f8039d 100644 --- a/example/zcat/zcat.c +++ b/example/zcat/zcat.c @@ -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 diff --git a/fuzz/c/std/gif_fuzzer.c b/fuzz/c/std/gif_fuzzer.c index 7e4e2113..627b5b3b 100644 --- a/fuzz/c/std/gif_fuzzer.c +++ b/fuzz/c/std/gif_fuzzer.c @@ -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) { diff --git a/fuzz/c/std/zlib_fuzzer.c b/fuzz/c/std/zlib_fuzzer.c index bb8e8d40..2144b52a 100644 --- a/fuzz/c/std/zlib_fuzzer.c +++ b/fuzz/c/std/zlib_fuzzer.c @@ -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) { diff --git a/release/c/README.md b/release/c/README.md index 84db49cd..18d4e056 100644 --- a/release/c/README.md +++ b/release/c/README.md @@ -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 diff --git a/release/c/wuffs-unsupported-snapshot.h b/release/c/wuffs-unsupported-snapshot.c similarity index 100% rename from release/c/wuffs-unsupported-snapshot.h rename to release/c/wuffs-unsupported-snapshot.c diff --git a/release/c/wuffs-v0.2.h b/release/c/wuffs-v0.2.c similarity index 100% rename from release/c/wuffs-v0.2.h rename to release/c/wuffs-v0.2.c diff --git a/test/c/std/adler32.c b/test/c/std/adler32.c index a3c4863a..039fd503 100644 --- a/test/c/std/adler32.c +++ b/test/c/std/adler32.c @@ -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" diff --git a/test/c/std/crc32.c b/test/c/std/crc32.c index 376aa649..0912942c 100644 --- a/test/c/std/crc32.c +++ b/test/c/std/crc32.c @@ -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" diff --git a/test/c/std/deflate.c b/test/c/std/deflate.c index 6259a3f8..a215bca7 100644 --- a/test/c/std/deflate.c +++ b/test/c/std/deflate.c @@ -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" diff --git a/test/c/std/gif.c b/test/c/std/gif.c index 7736e7a8..0d9483cd 100644 --- a/test/c/std/gif.c +++ b/test/c/std/gif.c @@ -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" diff --git a/test/c/std/gzip.c b/test/c/std/gzip.c index 0274bd45..41097276 100644 --- a/test/c/std/gzip.c +++ b/test/c/std/gzip.c @@ -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" diff --git a/test/c/std/lzw.c b/test/c/std/lzw.c index 21338b6c..0f14f38d 100644 --- a/test/c/std/lzw.c +++ b/test/c/std/lzw.c @@ -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 diff --git a/test/c/std/zlib.c b/test/c/std/zlib.c index 3e620646..03204bd6 100644 --- a/test/c/std/zlib.c +++ b/test/c/std/zlib.c @@ -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"