Server/Client build separation

This commit is contained in:
2025-09-09 09:09:42 +02:00
parent 167bc496db
commit c05350ef67
11 changed files with 71 additions and 28 deletions
+48 -17
View File
@@ -1,8 +1,18 @@
# To launch with debug messages: G_MESSAGES_DEBUG=all ./librefront
SRC := $(shell find src -name '*.c')
OBJ := $(patsubst src/%.c, build/%.o, $(SRC))
DEP := $(OBJ:.o=.d)
SRC_DIR := src
COMMON_SRC := $(shell find $(SRC_DIR)/common -name '*.c')
SERVER_SRC := $(shell find $(SRC_DIR)/server -name '*.c')
CLIENT_SRC := $(shell find $(SRC_DIR)/client -name '*.c')
COMMON_OBJ := $(patsubst $(SRC_DIR)/%.c, build/%.o, $(COMMON_SRC))
SERVER_OBJ := $(patsubst $(SRC_DIR)/%.c, build/%.o, $(SERVER_SRC))
CLIENT_OBJ := $(patsubst $(SRC_DIR)/%.c, build/%.o, $(CLIENT_SRC))
COMMON_DEP := $(COMMON_OBJ:.o=.d)
SERVER_DEP := $(SERVER_OBJ:.o=.d)
CLIENT_DEP := $(CLIENT_OBJ:.o=.d)
CC := gcc
LD := gcc
@@ -11,30 +21,51 @@ RM := rm -f
DEBUG ?= 1
CFLAGS := -std=$(STD) -Werror -Wextra -Wall -MMD -MP `pkg-config --cflags sdl3 sdl3-image glib-2.0`
LDFLAGS := -std=$(STD) -lm `pkg-config --libs sdl3 sdl3-image glib-2.0`
TARGET := librefront
COMMON_CFLAGS := -std=$(STD) -Werror -Wextra -Wall -MMD -MP -I$(SRC_DIR) `pkg-config --cflags glib-2.0`
COMMON_LDFLAGS := -std=$(STD) -lm `pkg-config --libs glib-2.0`
ifeq ($(DEBUG),1)
CFLAGS += -g -DDEBUG
LDFLAGS += -g
COMMON_CFLAGS += -g -DDEBUG
COMMON_LDFLAGS += -g
else
CFLAGS += -O2 -DNDEBUG
COMMON_CFLAGS += -O2 -DNDEBUG
endif
CLIENT_CFLAGS := $(COMMON_CFLAGS) `pkg-config --cflags sdl3 sdl3-image`
CLIENT_LDFLAGS := $(COMMON_LDFLAGS) `pkg-config --libs sdl3 sdl3-image`
SERVER_CFLAGS := $(COMMON_CFLAGS)
SERVER_LDFLAGS := $(COMMON_LDFLAGS)
CLIENT := librefront
SERVER := librefront-headless
.PHONY: all clean
all: $(TARGET)
all: $(CLIENT) $(SERVER)
$(TARGET): $(OBJ)
$(LD) $^ -o $@ $(LDFLAGS)
$(CLIENT): $(COMMON_OBJ) $(CLIENT_OBJ)
$(LD) $^ -o $@ $(CLIENT_LDFLAGS)
build/%.o: src/%.c
$(SERVER): $(COMMON_OBJ) $(SERVER_OBJ)
$(LD) $^ -o $@ $(SERVER_LDFLAGS)
build/common/%.o: $(SRC_DIR)/common/%.c
@mkdir -p $(dir $@)
$(CC) -c $< -o $@ $(CFLAGS)
$(CC) -c $< -o $@ $(COMMON_CFLAGS)
build/client/%.o: $(SRC_DIR)/client/%.c
@mkdir -p $(dir $@)
$(CC) -c $< -o $@ $(CLIENT_CFLAGS)
build/server/%.o: $(SRC_DIR)/server/%.c
@mkdir -p $(dir $@)
$(CC) -c $< -o $@ $(SERVER_CFLAGS)
clean:
$(RM) -r build/ $(TARGET) $(OBJ) $(DEP) perf.data* massif.out*
$(RM) -r build/ $(CLIENT) $(SERVER) perf.data* massif.out*
-include $(DEP)
-include $(COMMON_DEP)
-include $(CLIENT_DEP)
-include $(SERVER_DEP)
Binary file not shown.
+2 -1
View File
@@ -4,7 +4,8 @@
#include <SDL3/SDL_main.h>
#include <glib-2.0/glib.h>
#include "util.h"
#include <common/util.h>
#include "gfx_context.h"
static GfxContext *gfx_ctx;
@@ -3,7 +3,8 @@
#include <SDL3/SDL.h>
#include <glib-2.0/glib.h>
#include "util.h"
#include <common/world.h>
#include <common/util.h>
typedef struct GfxContext
{
@@ -15,3 +16,5 @@ GfxContext *GfxContext_new ();
void GfxContext_prerender (GfxContext *self);
void GfxContext_postrender (GfxContext *self);
void GfxContext_free (GfxContext *self);
void GfxContext_renderWorld (GfxContext *self, World *world);
View File
View File
+10 -9
View File
@@ -19,14 +19,6 @@ typedef struct MapTile
gboolean is_defended : 1, is_radiated : 1;
} MapTile;
typedef struct Building
{
MapTile *parent_tile;
unsigned int level;
unsigned int (*at_what_cost) (Building *self, World *world);
} Building;
typedef struct World
{
unsigned int width, height;
@@ -34,6 +26,15 @@ typedef struct World
GArray *buildings;
} World;
typedef struct Building Building; // Typedef is needed to avoid circular dependency
struct Building
{
MapTile *parent_tile;
unsigned int level;
unsigned int (*at_what_cost) (Building *self, World *world);
};
World *World_new (unsigned int width, unsigned int height);
void World_tick (World *self);
void World_render (World *self, GfxContext *gfx_context);
+7
View File
@@ -0,0 +1,7 @@
#include <stdio.h>
int main ()
{
fprintf(stderr, "Server not implemented!\n");
return -1;
}