Skip to content

Commit

Permalink
Merge pull request #48 from SharkAce/upstream
Browse files Browse the repository at this point in the history
Add cross-compilling with Windows
  • Loading branch information
SharkAce authored Aug 28, 2024
2 parents 11e42b5 + bf9ab60 commit 8770b1f
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 38 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
build
lib

# Prerequisites
*.d

Expand Down
100 changes: 71 additions & 29 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,46 +1,88 @@
CC := g++
APP_NAME := Dungeon-Game
VERSION := 0.0.1
PLATFORM ?= linux

EXEC := debug
BUILD_DIR := build
BUILD_DIR = build/$(PLATFORM)
SRC_DIR := src
LIB_DIR := lib
RES_DIR := res

LIBRARIES := -lsfml-graphics -lsfml-window -lsfml-system -lsfml-audio
WIN64_SFML_URL := https://www.sfml-dev.org/files/SFML-2.6.1-windows-gcc-13.1.0-mingw-64-bit.zip
WIN64_SFML_VER := 2.6.1
WIN64_SFML_DIR := $(LIB_DIR)/SFML-$(WIN64_SFML_VER)

OPTIONS := -Wall -O3
ifeq ($(PLATFORM), linux)
TARGET := $(BUILD_DIR)/$(APP_NAME)
CXX := g++
CXXFLAGS := $(shell pkg-config --cflags sfml-all)
LDFLAGS := $(shell pkg-config --libs sfml-all)

SOURCES := $(shell find src -name '*.cpp')
OBJECTS := $(SOURCES:.cpp=.o)
DEPENDS := $(SOURCES:.cpp=.d)
else ifeq ($(PLATFORM), win64)
TARGET := $(BUILD_DIR)/$(APP_NAME).exe
CXX := x86_64-w64-mingw32-g++
CXXFLAGS := -I $(WIN64_SFML_DIR)/include -DSFML_STATIC
LDFLAGS := -L $(WIN64_SFML_DIR)/lib -lsfml-graphics-s -lsfml-window-s -lsfml-audio-s -lsfml-system-s -lopengl32 -lwinmm -lgdi32 -lopenal32 -lFLAC -lvorbisenc -lvorbisfile -lvorbis -logg -lfreetype -mwindows --static
BUILD_DEP := $(WIN64_SFML_DIR)

.PHONY: all clean audio
else
$(error Unsupported platform: $(PLATFORM))

all: $(BUILD_DIR)/$(EXEC)
endif

$(BUILD_DIR)/$(EXEC): $(OBJECTS)
@mkdir -p $(BUILD_DIR)
$(CC) $(OPTIONS) $^ -o $@ $(LIBRARIES)
SOURCES := $(shell find $(SRC_DIR) -name '*.cpp')
OBJECTS = $(patsubst $(SRC_DIR)/%.cpp,$(BUILD_DIR)/%.o,$(SOURCES))
DEPENDS = $(patsubst $(SRC_DIR)/%.cpp,$(BUILD_DIR)/%.d,$(SOURCES))

-include $(DEPENDS)
.PHONY: all run release clean

%.o : %.cpp Makefile
$(CC) -MMD -MP -c $< -o $@
all: $(TARGET)

clean:
rm -f $(BUILD_DIR)/$(EXEC)
rm -f $(OBJECTS)
rm -f $(DEPENDS)
-include $(DEPENDS)

audio:
rm -f res/sfx.wav
find res/sfx/* | sed "s/.*/file \'&\'/" > audiolist
ffmpeg -f concat -safe 0 -i audiolist -c copy res/sfx.wav
@rm audiolist
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.cpp $(BUILD_DEP)
@mkdir -p $(dir $@)
$(CXX) -MMD -MP -c $< -o $@ $(CXXFLAGS)

$(TARGET): $(OBJECTS)
$(CXX) -o $@ $^ $(LDFLAGS)

$(WIN64_SFML_DIR):
@echo "Downloading SFML..."
@wget -O sfml.zip $(WIN64_SFML_URL)
@echo "Extracting SFML..."
@unzip -q sfml.zip -d $(LIB_DIR)
@rm sfml.zip

# Run in Fullscreen
run:
$(BUILD_DIR)/$(EXEC)
run: $(TARGET)
ifeq ($(PLATFORM), linux)
./$(TARGET)
endif

# Run windowed
runw:
$(BUILD_DIR)/$(EXEC) w
runw: $(TARGET)
ifeq ($(PLATFORM), linux)
./$(TARGET) w
endif

release: $(TARGET)
@mkdir -p release
@cp $(TARGET) release/
@cp -r $(RES_DIR) release/
ifeq ($(PLATFORM), linux)
@tar -czvf release/$(APP_NAME)-$(VERSION).tar.gz -C release $(notdir $(TARGET)) $(RES_DIR)
else ifeq ($(PLATFORM), win64)
@cd release && zip -r $(APP_NAME)-$(VERSION).zip $(notdir $(TARGET)) $(RES_DIR)
endif
@rm release/$(notdir $(TARGET))
@rm -rf release/$(RES_DIR)

clean:
@rm -rf build/*
@rm -rf lib/*
@rm -rf release/*

audio:
rm -f res/sfx.wav
find res/sfx/* | sed "s/.*/file \'&\'/" > /tmp/audiolist
ffmpeg -f concat -safe 0 -i /tmp/audiolist -c copy res/sfx.wav
31 changes: 22 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
# Dungeon-game
Dungeon style game made with sfml

## Dependecies
g++\
Make\
Sfml
## Building

## Screenshot
### Dependecies
- g++
- Make
- Sfml-lib
- MinGW (for building Windows exe)

### Linux
After installing the `sfml` package for your distribution, the application can be compiled with the `make` command.

### Windows (For Windows on Linux)
After installing the `MinGW` set of compilers, a release can be built using the `make release PLATFORM=win64` command. Note that the first time this command is executed, it will download the MinGW version of SFML from the internet.

## Usage
### Linux
After compiling, the application can be started using `make run`.

### Windows
A Windows release can be extracted and then launched by executing the `Dungeon-Game.exe`.

![Tutorial screen](https://github.com/SharkAce/Dungeon-game/blob/main/screenshots/2024-06-12_18.png?raw=true)

## Credit
Sprites : https://0x72.itch.io/16x16-dungeon-tileset \
Font : https://www.1001fonts.com/arcadeclassic-font.html \
Music : https://www.pond5.com/royalty-free-music/item/33253562-dungeon

- Sprites : https://0x72.itch.io/16x16-dungeon-tileset \
- Font : https://www.1001fonts.com/arcadeclassic-font.html \
- Music : https://www.pond5.com/royalty-free-music/item/33253562-dungeon

0 comments on commit 8770b1f

Please sign in to comment.