From 0913c46d49596ebdf4a3be20fff7b633147f502b Mon Sep 17 00:00:00 2001 From: vamastah Date: Sun, 21 May 2023 00:38:43 +0200 Subject: [PATCH] refactor makefile, add mingw makefile --- .gitignore | 4 ++++ Makefile | 44 ++++++++++---------------------------------- Makefile.mingw | 20 ++++++++++++++++++++ common.mk | 27 +++++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 34 deletions(-) create mode 100644 Makefile.mingw create mode 100644 common.mk diff --git a/.gitignore b/.gitignore index d19b06a..0a65d6a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,11 @@ LOGFILE.TXT +stderr.txt soulfu +soulfu.exe source/soulfu.o *.sdf *.RUN SAVELOG.TXT SAVE*.DAT +CONFIG.DAT +*.dll diff --git a/Makefile b/Makefile index 724e9c8..80bc0eb 100644 --- a/Makefile +++ b/Makefile @@ -1,43 +1,19 @@ -.PHONY: all clean pack +.PHONY: all clean -SDP = sdp/sdp -SLC = slc/slc -SSC = ssc/ssc +PKG ?= pkg-config TARGET = soulfu -DATAFILE = datafile.sdf -DATADIR = datadir SRC = source/soulfu.c -OBJ = $(SRC:.c=.o) -LIB = -lm -lSDL -lSDL_net -lGL -logg -ljpeg -lvorbis -FLAGS = -m32 -g +DEP = $(wildcard source/*.c source/*.h) +LDLIBS = -lm $(shell $(PKG) --libs sdl SDL_net ogg libjpeg vorbis gl) +FLAGS = -m32 -DDEVTOOL -ifdef DEVTOOL -FLAGS += -DDEVTOOL -endif - -all: $(TARGET) $(DATAFILE) +all: $(TARGET) data clean: - rm -rf $(TARGET) $(OBJ) $(DATAFILE) - -pack: $(DATAFILE) - -$(DATAFILE): | $(DATADIR) $(SDP) - $(SSC) -c -i $(DATADIR) - $(SDP) -p -n -i $(DATADIR) -o $(DATAFILE) - -$(SDP): | sdp - make -C sdp - -$(SLC): | slc - make -C slc - -$(SSC): | ssc - make -C ssc + rm -rf $(TARGET) $(DATAFILE) -$(TARGET): $(OBJ) - gcc $(FLAGS) -o $@ -Isource $(LIB) $(OBJ) +$(TARGET): $(DEP) + $(CC) $(FLAGS) -o $@ -Isource $(SRC) $(LDLIBS) -%.o: %.c - gcc $(FLAGS) -c -o $@ -Isource $(LIB) $< +include common.mk diff --git a/Makefile.mingw b/Makefile.mingw new file mode 100644 index 0000000..46cca77 --- /dev/null +++ b/Makefile.mingw @@ -0,0 +1,20 @@ +.PHONY: all clean + +PKG = i686-w64-mingw32-pkg-config +CC = i686-w64-mingw32-gcc + +TARGET = soulfu +SRC = source/soulfu.c +DEP = $(wildcard source/*.c source/*.h) +LDLIBS = $(shell $(PKG) --libs sdl SDL_net ogg libjpeg vorbis) -lopengl32 +FLAGS = -DDEVTOOL + +all: $(TARGET) data + +clean: + rm -rf $(TARGET) $(DATAFILE) + +$(TARGET): $(DEP) + $(CC) $(FLAGS) -o $@ -Isource $(SRC) $(LDLIBS) + +include common.mk diff --git a/common.mk b/common.mk new file mode 100644 index 0000000..87b17aa --- /dev/null +++ b/common.mk @@ -0,0 +1,27 @@ +.PHONY: data + +SDP = sdp/sdp +SLC = slc/slc +SSC = ssc/ssc + +DATAFILE = datafile.sdf +DATADIR = datadir +# do not pack RUN files +DATAEXT = DAT DDD JPG LAN MUS OGG PCX SRC SRF TXT +DATADEP = $(foreach ext,$(DATAEXT),$(wildcard $(DATADIR)/*.$(ext))) + +data: $(DATAFILE) + +# TBD: ssc should compile only things that changed since last build +$(DATAFILE): $(DATADEP) | $(DATADIR) $(SSC) $(SDP) + $(SSC) -c -i $(DATADIR) + $(SDP) -p -n -i $(DATADIR) -o $(DATAFILE) + +$(SDP): | sdp + make -C sdp + +$(SLC): | slc + make -C slc + +$(SSC): | ssc + make -C ssc \ No newline at end of file