diff --git a/.gitignore b/.gitignore index 66520950..24bcf5eb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,46 @@ -*.o crnlib/crunch + +*.swp +*.swo +*.o +*.dSYM +*.obj +*.swp +*.swo +/aclocal.m4 +/autom4te.cache/ +/compile +/config.guess +/config.log +/config.status +/config.sub +/configure.scan +/configure +/depcomp +/install-sh +/missing +Makefile +Makefile.in +m4/!ax_check_gl.m4.m4 +m4/!ax_save_flags_with_prefix.m4 +m4/!ax_save_flags_with_prefix.m4 +m4/*.m4 +config.h.* +/config.h +*.la +*.lo +.dirstamp +/ltmain.sh +/stamp-h1 +/test-driver +/test-suite.log +/libtool +.libs/ +.deps +/ar-lib +/autoscan.log +/test/tests +/test/tests.log +/test/tests.trs +/Makefile +crunchcli diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 00000000..b2b1efe9 --- /dev/null +++ b/Makefile.am @@ -0,0 +1,294 @@ +ACLOCAL_AMFLAGS = -I m4 + +AM_CXXFLAGS = -fomit-frame-pointer \ + -fexpensive-optimizations \ + -O3 \ + -Wextra \ + -Wall \ + -DNDEBUG \ + -g \ + -fexceptions \ + -Wno-unused-value \ + -Wno-unused \ + -fno-strict-aliasing \ + -ffast-math \ + -fno-math-errno \ + -I./crnlib + +EXTRA_DIST = README.md CHANGELOG.md license.txt autogen.sh + +# lib +lib_LTLIBRARIES = libcrnlib.la +libcrnlib_la_LDFLAGS = -no-defined -version-info 0:1:0 \ + -lpthread +libcrnlib_la_SOURCES = crnlib/crn_arealist.cpp \ + crnlib/crn_assert.cpp \ + crnlib/crn_checksum.cpp \ + crnlib/crn_colorized_console.cpp \ + crnlib/crn_command_line_params.cpp \ + crnlib/crn_comp.cpp \ + crnlib/crn_console.cpp \ + crnlib/crn_core.cpp \ + crnlib/crn_data_stream.cpp \ + crnlib/crn_dds_comp.cpp \ + crnlib/crn_decomp.cpp \ + crnlib/crn_dxt1.cpp \ + crnlib/crn_dxt5a.cpp \ + crnlib/crn_dxt.cpp \ + crnlib/crn_dxt_endpoint_refiner.cpp \ + crnlib/crn_dxt_fast.cpp \ + crnlib/crn_dxt_hc_common.cpp \ + crnlib/crn_dxt_hc.cpp \ + crnlib/crn_dxt_image.cpp \ + crnlib/crn_dynamic_string.cpp \ + crnlib/crn_etc.cpp \ + crnlib/crn_file_utils.cpp \ + crnlib/crn_find_files.cpp \ + crnlib/crn_hash.cpp \ + crnlib/crn_hash_map.cpp \ + crnlib/crn_huffman_codes.cpp \ + crnlib/crn_image_utils.cpp \ + crnlib/crn_jpgd.cpp \ + crnlib/crn_jpge.cpp \ + crnlib/crn_ktx_texture.cpp \ + crnlib/crnlib.cpp \ + crnlib/crn_lzma_codec.cpp \ + crnlib/crn_math.cpp \ + crnlib/crn_mem.cpp \ + crnlib/crn_miniz.cpp \ + crnlib/crn_mipmapped_texture.cpp \ + crnlib/crn_pixel_format.cpp \ + crnlib/crn_platform.cpp \ + crnlib/crn_prefix_coding.cpp \ + crnlib/crn_qdxt1.cpp \ + crnlib/crn_qdxt5.cpp \ + crnlib/crn_rand.cpp \ + crnlib/crn_resample_filters.cpp \ + crnlib/crn_resampler.cpp \ + crnlib/crn_rg_etc1.cpp \ + crnlib/crn_ryg_dxt.cpp \ + crnlib/crn_sparse_bit_array.cpp \ + crnlib/crn_stb_image.cpp \ + crnlib/crn_strutils.cpp \ + crnlib/crn_symbol_codec.cpp \ + crnlib/crn_texture_comp.cpp \ + crnlib/crn_texture_conversion.cpp \ + crnlib/crn_texture_file_types.cpp \ + crnlib/crn_threaded_resampler.cpp \ + crnlib/crn_threading_pthreads.cpp \ + crnlib/crn_timer.cpp \ + crnlib/crn_utils.cpp \ + crnlib/crn_value.cpp \ + crnlib/crn_vector.cpp \ + crnlib/crn_zeng.cpp \ + crnlib/lzma_7zBuf2.cpp \ + crnlib/lzma_7zBuf.cpp \ + crnlib/lzma_7zCrc.cpp \ + crnlib/lzma_7zFile.cpp \ + crnlib/lzma_7zStream.cpp \ + crnlib/lzma_Alloc.cpp \ + crnlib/lzma_Bcj2.cpp \ + crnlib/lzma_Bra86.cpp \ + crnlib/lzma_Bra.cpp \ + crnlib/lzma_BraIA64.cpp \ + crnlib/lzma_LzFind.cpp \ + crnlib/lzma_LzmaDec.cpp \ + crnlib/lzma_LzmaEnc.cpp \ + crnlib/lzma_LzmaLib.cpp + +# define the target to install header files to system when do 'make install' +crnlibdir=$(includedir)/crnlib +crnlib_HEADERS = crnlib/crn_arealist.h \ + crnlib/crn_assert.h \ + crnlib/crn_atomics.h \ + crnlib/crn_buffer_stream.h \ + crnlib/crn_cfile_stream.h \ + crnlib/crn_checksum.h \ + crnlib/crn_clusterizer.h \ + crnlib/crn_color.h \ + crnlib/crn_colorized_console.h \ + crnlib/crn_command_line_params.h \ + crnlib/crn_comp.h \ + crnlib/crn_console.h \ + crnlib/crn_core.h \ + crnlib/crn_data_stream.h \ + crnlib/crn_dds_comp.h \ + crnlib/crn_dxt1.h \ + crnlib/crn_dxt5a.h \ + crnlib/crn_dxt_endpoint_refiner.h \ + crnlib/crn_dxt_fast.h \ + crnlib/crn_dxt.h \ + crnlib/crn_dxt_hc_common.h \ + crnlib/crn_dxt_hc.h \ + crnlib/crn_dxt_image.h \ + crnlib/crn_dynamic_stream.h \ + crnlib/crn_dynamic_string.h \ + crnlib/crn_etc.h \ + crnlib/crn_file_utils.h \ + crnlib/crn_find_files.h \ + crnlib/crn_freeimage_image_utils.h \ + crnlib/crn_hash.h \ + crnlib/crn_hash_map.h \ + crnlib/crn_helpers.h \ + crnlib/crn_huffman_codes.h \ + crnlib/crn_image.h \ + crnlib/crn_image_utils.h \ + crnlib/crn_intersect.h \ + crnlib/crn_jpgd.h \ + crnlib/crn_jpge.h \ + crnlib/crn_ktx_texture.h \ + crnlib/crn_lzma_codec.h \ + crnlib/crn_math.h \ + crnlib/crn_matrix.h \ + crnlib/crn_mem.h \ + crnlib/crn_miniz.h \ + crnlib/crn_mipmapped_texture.h \ + crnlib/crn_packed_uint.h \ + crnlib/crn_pixel_format.h \ + crnlib/crn_platform.h \ + crnlib/crn_prefix_coding.h \ + crnlib/crn_qdxt1.h \ + crnlib/crn_qdxt5.h \ + crnlib/crn_radix_sort.h \ + crnlib/crn_rand.h \ + crnlib/crn_ray.h \ + crnlib/crn_rect.h \ + crnlib/crn_resample_filters.h \ + crnlib/crn_resampler.h \ + crnlib/crn_rg_etc1.h \ + crnlib/crn_sparse_array.h \ + crnlib/crn_sparse_bit_array.h \ + crnlib/crn_strutils.h \ + crnlib/crn_symbol_codec.h \ + crnlib/crn_texture_comp.h \ + crnlib/crn_texture_conversion.h \ + crnlib/crn_texture_file_types.h \ + crnlib/crn_threaded_clusterizer.h \ + crnlib/crn_threaded_resampler.h \ + crnlib/crn_threading.h \ + crnlib/crn_threading_null.h \ + crnlib/crn_threading_pthreads.h \ + crnlib/crn_timer.h \ + crnlib/crn_traits.h \ + crnlib/crn_tree_clusterizer.h \ + crnlib/crn_types.h \ + crnlib/crn_utils.h \ + crnlib/crn_vec.h \ + crnlib/crn_vec_interval.h \ + crnlib/crn_vector2d.h \ + crnlib/crn_vector.h \ + crnlib/crn_winhdr.h \ + crnlib/crn_zeng.h \ + crnlib/lzma_7zBuf.h \ + crnlib/lzma_7zCrc.h \ + crnlib/lzma_7zFile.h \ + crnlib/lzma_7zVersion.h \ + crnlib/lzma_Alloc.h \ + crnlib/lzma_Bcj2.h \ + crnlib/lzma_Bra.h \ + crnlib/lzma_CpuArch.h \ + crnlib/lzma_LzFind.h \ + crnlib/lzma_LzHash.h \ + crnlib/lzma_LzmaDec.h \ + crnlib/lzma_LzmaEnc.h \ + crnlib/lzma_LzmaLib.h \ + crnlib/lzma_MyVersion.h \ + crnlib/lzma_Types.h + +# cli +bin_PROGRAMS = crunchcli +crunchcli_SOURCES = crunch/crunch.cpp \ + crunch/corpus_gen.cpp \ + crunch/corpus_test.cpp \ + crnlib/crn_arealist.cpp \ + crnlib/crn_assert.cpp \ + crnlib/crn_checksum.cpp \ + crnlib/crn_colorized_console.cpp \ + crnlib/crn_command_line_params.cpp \ + crnlib/crn_comp.cpp \ + crnlib/crn_console.cpp \ + crnlib/crn_core.cpp \ + crnlib/crn_data_stream.cpp \ + crnlib/crn_dds_comp.cpp \ + crnlib/crn_decomp.cpp \ + crnlib/crn_dxt1.cpp \ + crnlib/crn_dxt5a.cpp \ + crnlib/crn_dxt.cpp \ + crnlib/crn_dxt_endpoint_refiner.cpp \ + crnlib/crn_dxt_fast.cpp \ + crnlib/crn_dxt_hc_common.cpp \ + crnlib/crn_dxt_hc.cpp \ + crnlib/crn_dxt_image.cpp \ + crnlib/crn_dynamic_string.cpp \ + crnlib/crn_etc.cpp \ + crnlib/crn_file_utils.cpp \ + crnlib/crn_find_files.cpp \ + crnlib/crn_hash.cpp \ + crnlib/crn_hash_map.cpp \ + crnlib/crn_huffman_codes.cpp \ + crnlib/crn_image_utils.cpp \ + crnlib/crn_jpgd.cpp \ + crnlib/crn_jpge.cpp \ + crnlib/crn_ktx_texture.cpp \ + crnlib/crnlib.cpp \ + crnlib/crn_lzma_codec.cpp \ + crnlib/crn_math.cpp \ + crnlib/crn_mem.cpp \ + crnlib/crn_miniz.cpp \ + crnlib/crn_mipmapped_texture.cpp \ + crnlib/crn_pixel_format.cpp \ + crnlib/crn_platform.cpp \ + crnlib/crn_prefix_coding.cpp \ + crnlib/crn_qdxt1.cpp \ + crnlib/crn_qdxt5.cpp \ + crnlib/crn_rand.cpp \ + crnlib/crn_resample_filters.cpp \ + crnlib/crn_resampler.cpp \ + crnlib/crn_rg_etc1.cpp \ + crnlib/crn_ryg_dxt.cpp \ + crnlib/crn_sparse_bit_array.cpp \ + crnlib/crn_stb_image.cpp \ + crnlib/crn_strutils.cpp \ + crnlib/crn_symbol_codec.cpp \ + crnlib/crn_texture_comp.cpp \ + crnlib/crn_texture_conversion.cpp \ + crnlib/crn_texture_file_types.cpp \ + crnlib/crn_threaded_resampler.cpp \ + crnlib/crn_threading_pthreads.cpp \ + crnlib/crn_timer.cpp \ + crnlib/crn_utils.cpp \ + crnlib/crn_value.cpp \ + crnlib/crn_vector.cpp \ + crnlib/crn_zeng.cpp \ + crnlib/lzma_7zBuf2.cpp \ + crnlib/lzma_7zBuf.cpp \ + crnlib/lzma_7zCrc.cpp \ + crnlib/lzma_7zFile.cpp \ + crnlib/lzma_7zStream.cpp \ + crnlib/lzma_Alloc.cpp \ + crnlib/lzma_Bcj2.cpp \ + crnlib/lzma_Bra86.cpp \ + crnlib/lzma_Bra.cpp \ + crnlib/lzma_BraIA64.cpp \ + crnlib/lzma_LzFind.cpp \ + crnlib/lzma_LzmaDec.cpp \ + crnlib/lzma_LzmaEnc.cpp \ + crnlib/lzma_LzmaLib.cpp + +crunchcli_CXXFLAGS = -fomit-frame-pointer \ + -fexpensive-optimizations \ + -O3 \ + -Wextra \ + -Wall \ + -DNDEBUG \ + -g \ + -fexceptions \ + -Wno-unused-value \ + -Wno-unused \ + -fno-strict-aliasing \ + -ffast-math \ + -fno-math-errno \ + -I./inc \ + -I./crunch \ + -I./crnlib +crunchcli_LDFLAGS = -lpthread diff --git a/README.md b/README.md index a5efc28b..8d9b49af 100644 --- a/README.md +++ b/README.md @@ -313,3 +313,14 @@ From the root directory, run: ```c emcc -O3 emscripten/crn.cpp -I./inc -s EXPORTED_FUNCTIONS="['_malloc', '_free', '_crn_get_width', '_crn_get_height', '_crn_get_levels', '_crn_get_dxt_format', '_crn_get_bytes_per_block', '_crn_get_uncompressed_size', '_crn_decompress']" -s NO_EXIT_RUNTIME=1 -s NO_FILESYSTEM=1 -s ELIMINATE_DUPLICATE_FUNCTIONS=1 -s ALLOW_MEMORY_GROWTH=1 --memory-init-file 0 -o crunch.js ``` + +## Build on Linux/macOS + +For convenient instead of directly using `crnlib/Makefile` (in which we left it intact for reference and just in case of direct use although not complete solution) to build `crunch` tool, you can execute the following sequence of commands on Linux/macOS to build `crunch` tool as well as static/shared libraries along with header files to be installed on your system. + +* `./autogen.sh` +* `./configure` +* `make -j4` or `make` +* `sudo make install` + +Thus you can integrate crunch with your own engine/project dynamically, or statically. Note that due to the way autotools behave, we generate the binary tool namely `crunchcli` instead of `crunch` to satisfy the build process (as there is crunch directory inside). So instead of executing `crunch ....` you do `crunchcli ...` instead. But you can rename it freely. diff --git a/autogen.sh b/autogen.sh new file mode 100755 index 00000000..022b4cd1 --- /dev/null +++ b/autogen.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +cd $(dirname "$0") +autoreconf --install diff --git a/configure.ac b/configure.ac new file mode 100644 index 00000000..d87e6d52 --- /dev/null +++ b/configure.ac @@ -0,0 +1,78 @@ +dnl Build system for Unix/macOS. +dnl For Windows, please use visual studio to build, not this autotools + +AC_PREREQ([2.69]) +AC_INIT([crnlib], [1.04], [info@binomial.info]) +AC_CONFIG_MACRO_DIR([m4]) +AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects]) +AC_CONFIG_HEADERS([config.h]) +AC_CANONICAL_HOST + +AM_PROG_AR + +AM_ENABLE_SHARED +AM_ENABLE_STATIC + +AC_CHECK_HEADERS([limits.h \ + malloc.h \ + memory.h \ + stddef.h \ + stdlib.h \ + string.h \ + termios.h \ + unistd.h \ + utime.h \ + cstring \ + math.h \ + assert.h \ + deque \ + sys/timex.h \ + memory.h \ + stdarg.h \ + termios.h \ + unistd.h \ + sys/sysinfo.h \ + process.h \ + sys/stat.h \ + sys/utime.h \ + fnmatch.h \ + dirent.h \ + pthread.h \ + locale \ + limits.h \ + algorithm \ + errno.h \ + map \ + setjmp.h \ + libgen.h \ + minmax.h \ + new \ + intrin.h \ + semaphore.h]) + +LT_INIT + +# Checks for programs. +AC_PROG_CXX +AC_PROG_INSTALL +AC_PROG_MAKE_SET + +# Checks for libraries. +# FIXME: Replace `main' with a function in `-lpthread': +AC_CHECK_LIB([pthread], [pthread_mutex_lock]) + +# Checks for typedefs, structures, and compiler characteristics. +AC_CHECK_HEADER_STDBOOL +AC_C_INLINE +AC_TYPE_SIZE_T +AC_CHECK_TYPES([ptrdiff_t]) + +# Checks for library functions. +AC_FUNC_ERROR_AT_LINE +AC_FUNC_MALLOC +AC_FUNC_MKTIME +AC_FUNC_REALLOC +AC_CHECK_FUNCS([floor gettimeofday memchr memmove memset mkdir pow realpath sqrt strchr strtol utime]) + +AC_CONFIG_FILES([Makefile]) +AC_OUTPUT diff --git a/crnlib/crn_vector.cpp b/crnlib/crn_vector.cpp index 8c21125d..df58ace9 100644 --- a/crnlib/crn_vector.cpp +++ b/crnlib/crn_vector.cpp @@ -22,8 +22,9 @@ namespace crnlib return true; size_t new_capacity = min_new_capacity; - if ((grow_hint) && (!math::is_power_of_2(new_capacity))) - new_capacity = math::next_pow2(new_capacity); + // FIXED: workaround casting to uint64 to avoid ambigous function call + if ((grow_hint) && (!math::is_power_of_2((uint64)new_capacity))) + new_capacity = math::next_pow2((uint64)new_capacity); CRNLIB_ASSERT(new_capacity && (new_capacity > m_capacity));