Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 70 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,28 @@ project(NitroCopy
VERSION 0.0.1
LANGUAGES C
)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# -----------------------------------------------
# Tests
# -----------------------------------------------
include(CTest)
enable_testing()

# -----------------------------------------------
# Determine Git-based version
# -----------------------------------------------
execute_process(
COMMAND git describe --tags --always
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
)

# Fallback to project version if Git info is unavailable
if(NOT GIT_VERSION)
set(GIT_VERSION ${PROJECT_VERSION})
endif()

# -----------------------------------------------
# Compiler settings
Expand All @@ -26,17 +47,56 @@ add_compile_options(
)

# Debug vs release mode
set(CMAKE_C_FLAGS_DEBUG "-O0 -g -DNITRO_DEBUG") # Disable optimisations (o0) and include debug symbols (-g).
set(CMAKE_C_FLAGS_RELEASE "-O2") # Optimise for speed.
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_USE_32BIT_TIME_T")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} -O0 -g -DNITRO_DEBUG") # Disable optimisations (o0) and include debug symbols (-g).
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} -O2") # Optimise for speed.

# -----------------------------------------------
# Include directories
# -----------------------------------------------
include_directories(${CMAKE_SOURCE_DIR}/include)

# -----------------------------------------------
# Determine Git version
# -----------------------------------------------
execute_process(
COMMAND git describe --tags --always
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
)

if(NOT GIT_VERSION)
set(GIT_VERSION ${PROJECT_VERSION})
endif()

# -----------------------------------------------
# Generate version header
# -----------------------------------------------
# Path to build number file
set(BUILD_NUMBER_FILE "${CMAKE_BINARY_DIR}/build_number.txt")

# Initialize file if it doesn't exist
if(NOT EXISTS "${BUILD_NUMBER_FILE}")
file(WRITE "${BUILD_NUMBER_FILE}" "0")
endif()

# Read current build number
file(READ "${BUILD_NUMBER_FILE}" BUILD_NUMBER)
string(STRIP "${BUILD_NUMBER}" BUILD_NUMBER)

# Increment build number
math(EXPR BUILD_NUMBER "${BUILD_NUMBER} + 1")

# Write back new build number
file(WRITE "${BUILD_NUMBER_FILE}" "${BUILD_NUMBER}")

# Export as a cache variable for configure_file
set(NITRO_BUILD_NUMBER "${BUILD_NUMBER}" CACHE INTERNAL "Current build number")
message(STATUS "Build number: ${BUILD_NUMBER}")

set(VERSION_STRING "${GIT_VERSION} (build ${NITRO_BUILD_NUMBER})")

configure_file(
${CMAKE_SOURCE_DIR}/include/nitro_version.h.in
${CMAKE_BINARY_DIR}/include/nitro_version.h
Expand All @@ -49,16 +109,14 @@ include_directories(${CMAKE_BINARY_DIR}/include)
# -----------------------------------------------
# Source files
# -----------------------------------------------
file(GLOB_RECURSE NITRO_SOURCES "src/*.c")
add_subdirectory(src)

# -----------------------------------------------
# Build application
# Custom target for tagging releases
# -----------------------------------------------
add_executable(NitroCopy ${NITRO_SOURCES})

# Link libraries.
target_link_libraries(NitroCopy PRIVATE m)

if (WIN32)
target_link_options(NitroCopy PRIVATE -static -static-libgcc -static-libstdc++)
endif()
add_custom_target(tag_release
COMMAND git tag -a v${PROJECT_VERSION} -m "Release v${PROJECT_VERSION}"
COMMAND git push --tags
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMENT "Tagging release v${PROJECT_VERSION}"
)
1 change: 1 addition & 0 deletions compile_commands.json
10 changes: 10 additions & 0 deletions include/console.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef CONSOLE_H
#define CONSOLE_H

int console_get_width(void);

void console_move_cursor_up(int rows);

void console_clear_from_cursor_down(void);

#endif
28 changes: 28 additions & 0 deletions include/copier.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef COPIER_H
#define COPIER_H

#include <stdio.h>

typedef enum {
COPY_RESUME,
COPY_OVERWRITE,
COPY_SKIP
} copy_existing_action_t;

extern copy_existing_action_t g_default_copy_action;

#define COPY_ACTION_UNSET ((copy_existing_action_t)-1)

typedef void (*ProgressCallback)(void);

int copier_copy(const char* src, const char* dest, size_t total_files, size_t total_bytes, size_t* files_copied, size_t* bytes_copied);

size_t copier_copy_file(const char* src, const char* dest);

int copier_copy_dir(const char* src_dir, const char* dest_dir, size_t* total_files, size_t* total_bytes);

int copier_execute(const char* src, const char* dest);

int copier_get_total_stats(const char* path, size_t* total_files, size_t* total_bytes);

#endif
12 changes: 7 additions & 5 deletions include/compat.h → include/file.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#ifndef COMPAT_H
#define COMPAT_H
#ifndef FILE_COMPAT_H
#define FILE_COMPAT_H

#include <stdio.h>
#include <sys/stat.h>


#if defined(_WIN32)
#include <windows.h>

Expand All @@ -23,9 +21,13 @@ typedef struct {
#endif

DIR* compat_opendir(const char* path);

struct dirent* compat_readdir(DIR* dir);

int compat_closedir(DIR* dir);

int compat_mkdir(const char* path, int mode);
int compat_get_file_stats(const char* path, struct stat* file_stats);

int compat_stat(const char* path, struct stat* file_stats);

#endif
34 changes: 0 additions & 34 deletions include/libnitro.h

This file was deleted.

20 changes: 20 additions & 0 deletions include/logging.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef LOGGING_H
#define LOGGING_H

#define LOG_LEVEL_FATAL 1
#define LOG_LEVEL_ERROR 2
#define LOG_LEVEL_WARN 3
#define LOG_LEVEL_INFO 4
#define LOG_LEVEL_DEBUG 5

void log_fatal(const char* format, ...);

void log_error(const char* format, ...);

void log_warn(const char* format, ...);

void log_info(const char* format, ...);

void log_debug(const char* format, ...);

#endif
6 changes: 0 additions & 6 deletions include/nitro_console_compat.h

This file was deleted.

33 changes: 0 additions & 33 deletions include/nitro_debug.h

This file was deleted.

11 changes: 0 additions & 11 deletions include/nitro_runtime.h

This file was deleted.

3 changes: 2 additions & 1 deletion include/nitro_version.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
#define NITRO_VERSION_MAJOR @PROJECT_VERSION_MAJOR@
#define NITRO_VERSION_MINOR @PROJECT_VERSION_MINOR@
#define NITRO_VERSION_PATCH @PROJECT_VERSION_PATCH@
#define NITRO_BUILD_NUMBER @NITRO_BUILD_NUMBER@

#define NITRO_VERSION_STRING "@PROJECT_VERSION@"
#define NITRO_VERSION_STRING "@VERSION_STRING@"
6 changes: 6 additions & 0 deletions include/runtime.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef RUNTIME_H
#define RUNTIME_H

extern int overwrite;

#endif
18 changes: 18 additions & 0 deletions include/word16.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef WORD16_H
#define WORD16_H

#include <stdio.h>

size_t word16_count(size_t length);

/**
* word16_create(): Create 16 bit words in little endian order, low byte first and high byte second.
*
* @input: The string to create words from.
* @out_words: The pointer to where the words should be stored.
*
* @return THe number of 16-bit words in the input string.
*/
size_t word16_create(const unsigned char* input, size_t length, unsigned short* output);

#endif
26 changes: 26 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
add_subdirectory(fletcher32)
add_subdirectory(getopt)
add_subdirectory(platform)

add_library(logging STATIC logging.c)

add_library(word16 STATIC
word16.c
)

add_library(copier STATIC
copier.c
)
target_link_libraries(copier PUBLIC
fletcher32
console
file
logging
m
)

add_executable(NitroCopy main.c)
target_link_libraries(NitroCopy PUBLIC
getopt
copier
)
Loading