Server/Client build separation
This commit is contained in:
@@ -1,8 +1,18 @@
|
|||||||
# To launch with debug messages: G_MESSAGES_DEBUG=all ./librefront
|
# To launch with debug messages: G_MESSAGES_DEBUG=all ./librefront
|
||||||
|
|
||||||
SRC := $(shell find src -name '*.c')
|
SRC_DIR := src
|
||||||
OBJ := $(patsubst src/%.c, build/%.o, $(SRC))
|
|
||||||
DEP := $(OBJ:.o=.d)
|
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
|
CC := gcc
|
||||||
LD := gcc
|
LD := gcc
|
||||||
@@ -11,30 +21,51 @@ RM := rm -f
|
|||||||
|
|
||||||
DEBUG ?= 1
|
DEBUG ?= 1
|
||||||
|
|
||||||
CFLAGS := -std=$(STD) -Werror -Wextra -Wall -MMD -MP `pkg-config --cflags sdl3 sdl3-image glib-2.0`
|
COMMON_CFLAGS := -std=$(STD) -Werror -Wextra -Wall -MMD -MP -I$(SRC_DIR) `pkg-config --cflags glib-2.0`
|
||||||
LDFLAGS := -std=$(STD) -lm `pkg-config --libs sdl3 sdl3-image glib-2.0`
|
COMMON_LDFLAGS := -std=$(STD) -lm `pkg-config --libs glib-2.0`
|
||||||
|
|
||||||
TARGET := librefront
|
|
||||||
|
|
||||||
ifeq ($(DEBUG),1)
|
ifeq ($(DEBUG),1)
|
||||||
CFLAGS += -g -DDEBUG
|
COMMON_CFLAGS += -g -DDEBUG
|
||||||
LDFLAGS += -g
|
COMMON_LDFLAGS += -g
|
||||||
else
|
else
|
||||||
CFLAGS += -O2 -DNDEBUG
|
COMMON_CFLAGS += -O2 -DNDEBUG
|
||||||
endif
|
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
|
.PHONY: all clean
|
||||||
|
|
||||||
all: $(TARGET)
|
all: $(CLIENT) $(SERVER)
|
||||||
|
|
||||||
$(TARGET): $(OBJ)
|
$(CLIENT): $(COMMON_OBJ) $(CLIENT_OBJ)
|
||||||
$(LD) $^ -o $@ $(LDFLAGS)
|
$(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 $@)
|
@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:
|
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.
@@ -4,7 +4,8 @@
|
|||||||
#include <SDL3/SDL_main.h>
|
#include <SDL3/SDL_main.h>
|
||||||
#include <glib-2.0/glib.h>
|
#include <glib-2.0/glib.h>
|
||||||
|
|
||||||
#include "util.h"
|
#include <common/util.h>
|
||||||
|
|
||||||
#include "gfx_context.h"
|
#include "gfx_context.h"
|
||||||
|
|
||||||
static GfxContext *gfx_ctx;
|
static GfxContext *gfx_ctx;
|
||||||
@@ -3,7 +3,8 @@
|
|||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
#include <glib-2.0/glib.h>
|
#include <glib-2.0/glib.h>
|
||||||
|
|
||||||
#include "util.h"
|
#include <common/world.h>
|
||||||
|
#include <common/util.h>
|
||||||
|
|
||||||
typedef struct GfxContext
|
typedef struct GfxContext
|
||||||
{
|
{
|
||||||
@@ -15,3 +16,5 @@ GfxContext *GfxContext_new ();
|
|||||||
void GfxContext_prerender (GfxContext *self);
|
void GfxContext_prerender (GfxContext *self);
|
||||||
void GfxContext_postrender (GfxContext *self);
|
void GfxContext_postrender (GfxContext *self);
|
||||||
void GfxContext_free (GfxContext *self);
|
void GfxContext_free (GfxContext *self);
|
||||||
|
|
||||||
|
void GfxContext_renderWorld (GfxContext *self, World *world);
|
||||||
@@ -19,14 +19,6 @@ typedef struct MapTile
|
|||||||
gboolean is_defended : 1, is_radiated : 1;
|
gboolean is_defended : 1, is_radiated : 1;
|
||||||
} MapTile;
|
} MapTile;
|
||||||
|
|
||||||
typedef struct Building
|
|
||||||
{
|
|
||||||
MapTile *parent_tile;
|
|
||||||
unsigned int level;
|
|
||||||
|
|
||||||
unsigned int (*at_what_cost) (Building *self, World *world);
|
|
||||||
} Building;
|
|
||||||
|
|
||||||
typedef struct World
|
typedef struct World
|
||||||
{
|
{
|
||||||
unsigned int width, height;
|
unsigned int width, height;
|
||||||
@@ -34,6 +26,15 @@ typedef struct World
|
|||||||
GArray *buildings;
|
GArray *buildings;
|
||||||
} World;
|
} 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);
|
World *World_new (unsigned int width, unsigned int height);
|
||||||
void World_tick (World *self);
|
void World_tick (World *self);
|
||||||
void World_render (World *self, GfxContext *gfx_context);
|
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int main ()
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Server not implemented!\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user