Skip to content

Commit

Permalink
feat: refactor features, add options to build with animate/gui
Browse files Browse the repository at this point in the history
  • Loading branch information
jgabaut committed Aug 29, 2024
1 parent 52bb5e5 commit 2173258
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 34 deletions.
7 changes: 7 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ AM_LDFLAGS = -s
# Compiler flags
AM_CFLAGS = $(S4C_CFLAGS) -O2 -Werror -Wpedantic -Wall

if S4C_ANIMATE_BUILD
AM_CFLAGS += -DS4C_HAS_ANIMATE
if S4C_RAYLIB_BUILD
AM_CFLAGS += -DS4C_RAYLIB_EXTENSION
else
Expand All @@ -49,6 +51,11 @@ endif
if S4C_RL_QUIETER_BUILD
AM_CFLAGS += -DS4C_RL_QUIETER
endif
endif # S4C_ANIMATE_BUILD

if S4C_GUI_BUILD
AM_CFLAGS += -DS4C_HAS_GUI
endif # S4C_GUI_BUILD

libs4c.o: $(lib_SOURCES)
@echo -e "\033[1;35m[Makefile]\e[0m Building \"$@\":"
Expand Down
46 changes: 29 additions & 17 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,35 @@ build_windows=no
build_mac=no
echo "Host os: $host_os"

AC_ARG_ENABLE([raylib],
[AS_HELP_STRING([--enable-raylib], [Enable s4raylib extension header])],
[enable_raylib=$enableval],
[enable_raylib=no])
AM_CONDITIONAL([S4C_RAYLIB_BUILD], [test "$enable_raylib" = "yes"])
AC_ARG_ENABLE([animate],
[AS_HELP_STRING([--enable-animate], [Enable animate extension header])],
[enable_animate=$enableval],
[enable_animate=yes])
AM_CONDITIONAL([S4C_ANIMATE_BUILD], [test "$enable_animate" = "yes"])

AC_ARG_ENABLE([quieter],
[AS_HELP_STRING([--enable-quieter], [Enable s4raylib quieter output extension])],
[enable_quieter=$enableval],
AC_ARG_ENABLE([gui],
[AS_HELP_STRING([--enable-gui], [Enable gui extension header])],
[enable_gui=$enableval],
[enable_gui=no])
AM_CONDITIONAL([S4C_GUI_BUILD], [test "$enable_gui" = "yes"])

AC_ARG_ENABLE([animate_raylib],
[AS_HELP_STRING([--enable-animate-raylib], [Enable animate raylib extension header])],
[enable_animate_raylib=$enableval],
[enable_animate_raylib=no])
AM_CONDITIONAL([S4C_RAYLIB_BUILD], [test "$enable_animate_raylib" = "yes"])

AC_ARG_ENABLE([animate_quieter],
[AS_HELP_STRING([--enable-animate-quieter], [Enable animate raylib quieter output extension])],
[enable_animate_quieter=$enableval],
[enable_quieter=no])
AM_CONDITIONAL([S4C_RL_QUIETER_BUILD], [test "$enable_quieter" = "yes"])
AM_CONDITIONAL([S4C_RL_QUIETER_BUILD], [test "$enable_animate_quieter" = "yes"])

AC_ARG_ENABLE([exp],
[AS_HELP_STRING([--enable-exp], [Enable experimental extensions])],
[enable_exp=$enableval],
[enable_exp=no])
AM_CONDITIONAL([S4C_EXPERIMENTAL_BUILD], [test "$enable_exp" = "yes"])
AC_ARG_ENABLE([animate_exp],
[AS_HELP_STRING([--enable-animate_exp], [Enable animate experimental extensions])],
[enable_animate_exp=$enableval],
[enable_animate_exp=no])
AM_CONDITIONAL([S4C_EXPERIMENTAL_BUILD], [test "$enable_animate_exp" = "yes"])

# Define the include and library paths based on the host system
case "${host_os}" in
Expand All @@ -36,7 +48,7 @@ case "${host_os}" in
build_windows=yes
# mingw32 specific flags
AC_SUBST([CCOMP], ["/usr/bin/x86_64-w64-mingw32-gcc"])
if test "$enable_raylib" = "yes"; then
if test "$enable_animate_raylib" = "yes"; then
echo "Building with raylib header"
AC_SUBST([S4C_CFLAGS], ["-I/usr/x86_64-w64-mingw32/include -static -fstack-protector"])
AC_SUBST([S4C_LDFLAGS], ["-L/usr/x86_64-w64-mingw32/lib -lraylib -lm -lgdi32 -lwinmm"])
Expand All @@ -54,7 +66,7 @@ case "${host_os}" in
echo "Building for macos: [$host_cpu-$host_vendor-$host_os]"
build_mac=yes
# macOS specific flags
if test "$enable_raylib" = "yes"; then
if test "$enable_animate_raylib" = "yes"; then
echo "Building with raylib header"
AC_SUBST([S4C_CFLAGS], ["-I/opt/homebrew/opt/raylib/include"])
AC_SUBST([S4C_LDFLAGS], ["-L/opt/homebrew/opt/raylib/lib -lraylib -lm"])
Expand All @@ -72,7 +84,7 @@ case "${host_os}" in
echo "Building for Linux: [$host_cpu-$host_vendor-$host_os]"
build_linux=yes
# Linux specific flags
if test "$enable_raylib" = "yes"; then
if test "$enable_animate_raylib" = "yes"; then
echo "Building with raylib header"
AC_SUBST([S4C_CFLAGS], [""])
AC_SUBST([S4C_LDFLAGS], ["-lraylib -lm"])
Expand Down
4 changes: 3 additions & 1 deletion s4c-animate/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

All previous APIs will still be available in the new module, but some macros may be renamed to better namespace the new module.

A list of all updated identifiers follows.
Most of the names have been reused in the new module and will have the same use, but be relative to the whole project rather than just the animate module.

A list of all updated identifiers follows.

```c
S4C_MAJOR // Dropped
Expand All @@ -22,4 +23,5 @@
s4c_echoVersionToFile() // Renamed to s4c_animate_echoVersionToFile()
S4C_ECHOVERSION() // Renamed to S4C_ANIMATE_ECHOVERSION()
S4C_PRINTVERSION() // Renamed to S4C_ANIMATE_PRINTVERSION()
s4c_dbg_features() // Renamed to s4c_animate_dbg_features()
```
14 changes: 7 additions & 7 deletions s4c-animate/animate.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ const int int_s4c_animate_version(void) {
}

/**
* Prints enabled s4c features to stderr.
* Prints enabled s4c-animate features to stderr.
*/
void s4c_dbg_features(void)
void s4c_animate_dbg_features(void)
{
#ifdef S4C_RAYLIB_EXTENSION
bool s4c_raylib_extension = true;
Expand Down Expand Up @@ -94,22 +94,22 @@ void s4c_dbg_features(void)
return;
} else {
if (s4c_raylib_extension) {
fprintf(stderr, "raylib%s", (total_enabled > 1 ? ", " : ""));
fprintf(stderr, "animate-raylib%s", (total_enabled > 1 ? ", " : ""));
total_enabled -= 1;
}
if (s4c_ncurses_extension) {
fprintf(stderr, "ncurses%s", (total_enabled > 1 ? ", " : ""));
fprintf(stderr, "animate-ncurses%s", (total_enabled > 1 ? ", " : ""));
total_enabled -= 1;
}
if (s4c_raylib_quieter) {
fprintf(stderr, "quieter%s", (total_enabled > 1 ? ", " : ""));
fprintf(stderr, "animate-quieter%s", (total_enabled > 1 ? ", " : ""));
total_enabled -= 1;
}
if (s4c_ncurses_unchecked) {
fprintf(stderr, "unchecked%s", (total_enabled > 1 ? ", " : ""));
fprintf(stderr, "animate-unchecked%s", (total_enabled > 1 ? ", " : ""));
}
if (s4c_experimental) {
fprintf(stderr, "exper");
fprintf(stderr, "animate-exper");
}
fprintf(stderr, "}\n");
}
Expand Down
2 changes: 1 addition & 1 deletion s4c-animate/animate.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void s4c_animate_echoVersionToFile(FILE* f);
*/
const int int_s4c_animate_version(void);

void s4c_dbg_features(void);
void s4c_animate_dbg_features(void);

#define MAX_COLORS 256
#define S4C_PALETTEFILE_MAX_COLOR_NAME_LEN 256 /**< Defines max size for the name strings in palette.gpl.*/
Expand Down
101 changes: 94 additions & 7 deletions src/s4c.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,93 @@ void s4c_echoVersionToFile(FILE* f) {
fprintf(f,"%s\n",S4C_VERSION);
}

/**
* Prints enabled s4c features to stderr.
*/
void s4c_dbg_features(void)
{
#ifdef S4C_HAS_ANIMATE
bool s4c_has_animate = true;
#else
bool s4c_has_animate = false;
#endif
#ifdef S4C_HAS_GUI
bool s4c_has_gui = true;
#else
bool s4c_has_gui = false;
#endif
#ifdef S4C_RAYLIB_EXTENSION
bool s4c_raylib_extension = true;
bool s4c_ncurses_extension = false;
#else
bool s4c_raylib_extension = false;
bool s4c_ncurses_extension = true;
#endif
#ifdef S4C_RL_QUIETER
bool s4c_raylib_quieter = true;
#else
bool s4c_raylib_quieter = false;
#endif
#ifdef S4C_UNCHECKED
bool s4c_ncurses_unchecked = true;
#else
bool s4c_ncurses_unchecked = false;
#endif
#ifdef S4C_EXPERIMENTAL
bool s4c_experimental = true;
#else
bool s4c_experimental = false;
#endif
bool features[7] = {
[0] = s4c_has_animate,
[1] = s4c_has_gui,
[2] = s4c_ncurses_extension,
[3] = s4c_ncurses_unchecked,
[4] = s4c_raylib_extension,
[5] = s4c_raylib_quieter,
[6] = s4c_experimental,
};
int total_enabled = 0;
for (int i=0; i<7; i++) {
if (features[i]) {
total_enabled += 1;
}
}
fprintf(stderr, "[S4C] Enabled features: {");
if (total_enabled == 0) {
fprintf(stderr, "none}\n");
return;
} else {
if (s4c_has_animate) {
fprintf(stderr, "animate%s", (total_enabled > 1 ? ", " : ""));
total_enabled -= 1;
}
if (s4c_has_gui) {
fprintf(stderr, "gui%s", (total_enabled > 1 ? ", " : ""));
total_enabled -= 1;
}
if (s4c_raylib_extension) {
fprintf(stderr, "animate-raylib%s", (total_enabled > 1 ? ", " : ""));
total_enabled -= 1;
}
if (s4c_ncurses_extension) {
fprintf(stderr, "animate-ncurses%s", (total_enabled > 1 ? ", " : ""));
total_enabled -= 1;
}
if (s4c_raylib_quieter) {
fprintf(stderr, "animate-quieter%s", (total_enabled > 1 ? ", " : ""));
total_enabled -= 1;
}
if (s4c_ncurses_unchecked) {
fprintf(stderr, "animate-unchecked%s", (total_enabled > 1 ? ", " : ""));
}
if (s4c_experimental) {
fprintf(stderr, "animate-exper");
}
fprintf(stderr, "}\n");
}
}

#ifdef S4C_ANIMATE_H
/**
* Prints formatted animate version.
Expand Down Expand Up @@ -97,9 +184,9 @@ const char *string_s4c_animate_version(void)
}

/**
* Prints enabled s4c features to stderr.
* Prints enabled s4c-animate features to stderr.
*/
void s4c_dbg_features(void)
void s4c_animate_dbg_features(void)
{
#ifdef S4C_RAYLIB_EXTENSION
bool s4c_raylib_extension = true;
Expand Down Expand Up @@ -142,22 +229,22 @@ void s4c_dbg_features(void)
return;
} else {
if (s4c_raylib_extension) {
fprintf(stderr, "raylib%s", (total_enabled > 1 ? ", " : ""));
fprintf(stderr, "animate-raylib%s", (total_enabled > 1 ? ", " : ""));
total_enabled -= 1;
}
if (s4c_ncurses_extension) {
fprintf(stderr, "ncurses%s", (total_enabled > 1 ? ", " : ""));
fprintf(stderr, "animate-ncurses%s", (total_enabled > 1 ? ", " : ""));
total_enabled -= 1;
}
if (s4c_raylib_quieter) {
fprintf(stderr, "quieter%s", (total_enabled > 1 ? ", " : ""));
fprintf(stderr, "animate-quieter%s", (total_enabled > 1 ? ", " : ""));
total_enabled -= 1;
}
if (s4c_ncurses_unchecked) {
fprintf(stderr, "unchecked%s", (total_enabled > 1 ? ", " : ""));
fprintf(stderr, "animate-unchecked%s", (total_enabled > 1 ? ", " : ""));
}
if (s4c_experimental) {
fprintf(stderr, "exper");
fprintf(stderr, "animate-exper");
}
fprintf(stderr, "}\n");
}
Expand Down
8 changes: 7 additions & 1 deletion src/s4c.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ void s4c_echoVersionToFile(FILE* f);
#define S4C_PRINTVERSION() s4c_printVersionToFile(stdout); //Prints formatted version to stdout
#define S4C_ECHOVERSION() s4c_echoVersionToFile(stdout); //Prints version to stdout

void s4c_dbg_features(void);

#ifdef S4C_HAS_ANIMATE
#ifndef S4C_ANIMATE_H
#define S4C_ANIMATE_H
#include <stdio.h>
Expand Down Expand Up @@ -99,7 +102,7 @@ const int int_s4c_animate_version(void);
*/
const char *string_s4c_animate_version(void);

void s4c_dbg_features(void);
void s4c_animate_dbg_features(void);

#define MAX_COLORS 256
#define S4C_PALETTEFILE_MAX_COLOR_NAME_LEN 256 /**< Defines max size for the name strings in palette.gpl.*/
Expand Down Expand Up @@ -281,8 +284,10 @@ int s4rl_draw_s4c_sprite_at_rect(S4C_Sprite sprite, Rectangle rect, int pixelSiz
#endif // S4C_RAYLIB_EXTENSION

#endif // S4C_ANIMATE_H
#endif // S4C_HAS_ANIMATE

#ifndef S4C_RAYLIB_EXTENSION // At the moment, this conflicts.
#ifdef S4C_HAS_GUI
#ifndef S4C_GUI_H_
#define S4C_GUI_H_
#include <stdlib.h>
Expand Down Expand Up @@ -497,6 +502,7 @@ void free_ToggleMenu(ToggleMenu toggle_menu);
#endif // TOGGLE_H_

#endif // S4C_GUI_H_
#endif // S4C_HAS_GUI
#endif // S4C_RAYLIB_EXTENSION

#endif // S4C_H_

0 comments on commit 2173258

Please sign in to comment.