Makefiles: added basic dependency tracking, and tidied-up a bit.

This commit is contained in:
Ozkan Sezer 2022-06-28 03:02:56 +03:00
parent c1c9f3b7fe
commit 09216eb65f
4 changed files with 86 additions and 114 deletions

View file

@ -52,7 +52,7 @@ PKG_CONFIG ?= pkg-config
CPUFLAGS=
LDFLAGS =
DFLAGS ?=
CFLAGS ?= -Wall -Wno-trigraphs
CFLAGS ?= -Wall -Wno-trigraphs -MMD
CFLAGS += $(call check_gcc,-std=gnu11,)
CFLAGS += $(CPUFLAGS)
ifneq ($(DEBUG),0)
@ -62,7 +62,7 @@ do_strip=
else
DFLAGS += -DNDEBUG
CFLAGS += -O2
# -fno-asynchronous-unwind-tables
#CFLAGS += -fno-asynchronous-unwind-tables
CFLAGS += $(call check_gcc,-fweb,)
CFLAGS += $(call check_gcc,-frename-registers,)
cmd_strip=$(STRIP) $(1)
@ -185,23 +185,8 @@ COMMON_LIBS:= -lm -lGL
LIBS := $(COMMON_LIBS) $(NET_LIBS) $(CODECLIBS)
# ---------------------------
# targets
# ---------------------------
.PHONY: clean debug release
DEFAULT_TARGET := quakespasm
# ---------------------------
# rules
# ---------------------------
%.o: %.c
$(CC) $(DFLAGS) -c $(CFLAGS) $(SDL_CFLAGS) -o $@ $<
# ----------------------------------------------------------------------------
# objects
# ----------------------------------------------------------------------------
# ---------------------------
MUSIC_OBJS:= bgmusic.o \
snd_codec.o \
@ -223,7 +208,6 @@ SYSOBJ_GL_VID:= gl_vidsdl.o
SYSOBJ_NET := net_bsd.o net_udp.o
SYSOBJ_SYS := pl_linux.o sys_sdl_unix.o
SYSOBJ_MAIN:= main_sdl.o
SYSOBJ_RES :=
GLOBJS = \
gl_refrag.o \
@ -287,24 +271,32 @@ OBJS := strlcat.o \
sv_user.o \
world.o \
zone.o \
$(SYSOBJ_SYS) $(SYSOBJ_MAIN) $(SYSOBJ_RES)
$(SYSOBJ_SYS) $(SYSOBJ_MAIN)
# ------------------------
# Linux build rules
# ------------------------
# ---------------------------
# targets / rules
# ---------------------------
.PHONY: clean debug release
DEFAULT_TARGET := quakespasm
all: $(DEFAULT_TARGET)
%.o: %.c
$(CC) $(DFLAGS) -c $(CFLAGS) $(SDL_CFLAGS) -o $@ $<
quakespasm: $(OBJS)
$(LINKER) $(OBJS) $(LDFLAGS) $(LIBS) $(SDL_LIBS) -o $@
$(call do_strip,$@)
image.o: lodepng.c lodepng.h stb_image_write.h
release: quakespasm
debug:
$(error Use "make DEBUG=1")
clean:
rm -f $(shell find . \( -name '*~' -o -name '#*#' -o -name '*.o' -o -name '*.res' -o -name $(DEFAULT_TARGET) \) -print)
$(RM) *.o *.d $(DEFAULT_TARGET)
install: quakespasm
cp quakespasm /usr/local/games/quake
sinclude $(OBJS:.o=.d)

View file

@ -49,12 +49,12 @@ CC ?= gcc
LINKER = $(CC)
LIPO ?= lipo
STRIP ?= strip
STRIP ?= strip -S
CPUFLAGS=
LDFLAGS =
DFLAGS ?=
CFLAGS ?= -Wall
CFLAGS ?= -Wall -MMD
# @rpath can be used when targeting 10.5+
USE_RPATH=0
# require 10.5 for 64 bit builds
@ -96,7 +96,7 @@ do_strip=
else
DFLAGS += -DNDEBUG
CFLAGS += -O2
# -fno-asynchronous-unwind-tables
#CFLAGS += -fno-asynchronous-unwind-tables
CFLAGS += $(call check_gcc,-fweb,)
CFLAGS += $(call check_gcc,-frename-registers,)
cmd_strip=$(STRIP) $(1)
@ -216,27 +216,8 @@ COMMON_LIBS:= -Wl,-framework,IOKit -Wl,-framework,OpenGL
LIBS := $(COMMON_LIBS) $(NET_LIBS) $(CODEC_LINK) $(CODECLIBS)
# ---------------------------
# targets
# ---------------------------
.PHONY: clean debug release
DEFAULT_TARGET := quakespasm
# ---------------------------
# rules
# ---------------------------
%.o: %.c
$(CC) $(DFLAGS) -c $(CFLAGS) $(SDL_CFLAGS) -o $@ $<
%.o: %.m
$(CC) $(DFLAGS) -c $(CFLAGS) $(SDL_CFLAGS) -o $@ $<
%.o: ../MacOSX/%.m
$(CC) $(DFLAGS) -c -I../MacOSX $(CFLAGS) $(SDL_CFLAGS) -o $@ $<
# ----------------------------------------------------------------------------
# objects
# ----------------------------------------------------------------------------
# ---------------------------
MUSIC_OBJS:= bgmusic.o \
snd_codec.o \
@ -322,21 +303,34 @@ OBJS := strlcat.o \
sv_user.o \
world.o \
zone.o \
$(SYSOBJ_SYS) $(SYSOBJ_LAUNCHER) $(SYSOBJ_MAIN)
$(SYSOBJ_SYS) \
$(SYSOBJ_LAUNCHER) $(SYSOBJ_MAIN)
# ------------------------
# darwin build rules
# ------------------------
# ---------------------------
# targets / rules
# ---------------------------
.PHONY: clean debug release
DEFAULT_TARGET := quakespasm
all: $(DEFAULT_TARGET)
%.o: %.c
$(CC) $(DFLAGS) -c $(CFLAGS) $(SDL_CFLAGS) -o $@ $<
%.o: %.m
$(CC) $(DFLAGS) -c $(CFLAGS) $(SDL_CFLAGS) -o $@ $<
%.o: ../MacOSX/%.m
$(CC) $(DFLAGS) -c -I../MacOSX $(CFLAGS) $(SDL_CFLAGS) -o $@ $<
quakespasm: $(OBJS)
$(LINKER) $(OBJS) $(LDFLAGS) $(LIBS) $(SDL_LIBS) -o $@
$(call do_strip,$@)
image.o: lodepng.c lodepng.h stb_image_write.h
release: quakespasm
debug:
$(error Use "make DEBUG=1")
clean:
rm -f $(shell find . \( -name '*~' -o -name '#*#' -o -name '*.o' -o -name '*.res' -o -name $(DEFAULT_TARGET) \) -print)
$(RM) *.o *.d $(DEFAULT_TARGET)
sinclude $(OBJS:.o=.d)

View file

@ -49,7 +49,7 @@ STRIP = strip
CPUFLAGS=
LDFLAGS = -m32 -mwindows -static-libgcc
DFLAGS ?=
CFLAGS ?= -m32 -Wall -Wno-trigraphs
CFLAGS ?= -m32 -Wall -Wno-trigraphs -MMD
CFLAGS += $(call check_gcc,-std=gnu11,)
CFLAGS += $(CPUFLAGS)
ifneq ($(DEBUG),0)
@ -59,7 +59,7 @@ do_strip=
else
DFLAGS += -DNDEBUG
CFLAGS += -O2
# -fno-asynchronous-unwind-tables
#CFLAGS += -fno-asynchronous-unwind-tables
CFLAGS += $(call check_gcc,-fweb,)
CFLAGS += $(call check_gcc,-frename-registers,)
cmd_strip=$(STRIP) $(1)
@ -175,25 +175,8 @@ COMMON_LIBS:= -lopengl32 -lwinmm
LIBS := $(COMMON_LIBS) $(NET_LIBS) $(CODEC_LINK) $(CODECLIBS)
# ---------------------------
# targets
# ---------------------------
.PHONY: clean debug release
DEFAULT_TARGET := quakespasm.exe
# ---------------------------
# rules
# ---------------------------
%.o: %.c
$(CC) $(DFLAGS) -c $(CFLAGS) $(SDL_CFLAGS) -o $@ $<
%.res: ../Windows/%.rc
$(WINDRES) -I../Windows --output-format=coff --target=pe-i386 -o $@ $<
# ----------------------------------------------------------------------------
# objects
# ----------------------------------------------------------------------------
# ---------------------------
MUSIC_OBJS:= bgmusic.o \
snd_codec.o \
@ -279,21 +262,31 @@ OBJS := strlcat.o \
sv_user.o \
world.o \
zone.o \
$(SYSOBJ_SYS) $(SYSOBJ_MAIN) $(SYSOBJ_RES)
$(SYSOBJ_SYS) $(SYSOBJ_MAIN)
# ------------------------
# MinGW build rules
# ------------------------
# ---------------------------
# targets / rules
# ---------------------------
quakespasm.exe: $(OBJS)
$(LINKER) $(OBJS) $(LDFLAGS) $(LIBS) $(SDL_LIBS) -o $@
.PHONY: clean debug release
DEFAULT_TARGET := quakespasm.exe
all: $(DEFAULT_TARGET)
%.o: %.c
$(CC) $(DFLAGS) -c $(CFLAGS) $(SDL_CFLAGS) -o $@ $<
%.res: ../Windows/%.rc
$(WINDRES) -I../Windows --output-format=coff --target=pe-i386 -o $@ $<
quakespasm.exe: $(OBJS) $(SYSOBJ_RES)
$(LINKER) $(OBJS) $(SYSOBJ_RES) $(LDFLAGS) $(LIBS) $(SDL_LIBS) -o $@
$(call do_strip,$@)
image.o: lodepng.c lodepng.h stb_image_write.h
release: quakespasm.exe
debug:
$(error Use "make DEBUG=1")
clean:
rm -f $(shell find . \( -name '*~' -o -name '#*#' -o -name '*.o' -o -name '*.res' -o -name $(DEFAULT_TARGET) \) -print)
$(RM) *.o *.d *.res $(DEFAULT_TARGET)
sinclude $(OBJS:.o=.d)

View file

@ -47,7 +47,7 @@ STRIP = strip
CPUFLAGS=
LDFLAGS = -m64 -mwindows -static-libgcc
DFLAGS ?=
CFLAGS ?= -m64 -Wall -Wno-trigraphs
CFLAGS ?= -m64 -Wall -Wno-trigraphs -MMD
CFLAGS += $(call check_gcc,-std=gnu11,)
CFLAGS += $(CPUFLAGS)
ifneq ($(DEBUG),0)
@ -57,7 +57,7 @@ do_strip=
else
DFLAGS += -DNDEBUG
CFLAGS += -O2
# -fno-asynchronous-unwind-tables
#CFLAGS += -fno-asynchronous-unwind-tables
CFLAGS += $(call check_gcc,-fweb,)
CFLAGS += $(call check_gcc,-frename-registers,)
cmd_strip=$(STRIP) $(1)
@ -168,25 +168,8 @@ COMMON_LIBS:= -lopengl32 -lwinmm
LIBS := $(COMMON_LIBS) $(NET_LIBS) $(CODEC_LINK) $(CODECLIBS)
# ---------------------------
# targets
# ---------------------------
.PHONY: clean debug release
DEFAULT_TARGET := quakespasm.exe
# ---------------------------
# rules
# ---------------------------
%.o: %.c
$(CC) $(DFLAGS) -c $(CFLAGS) $(SDL_CFLAGS) -o $@ $<
%.res: ../Windows/%.rc
$(WINDRES) -I../Windows --output-format=coff --target=pe-x86-64 -o $@ $<
# ----------------------------------------------------------------------------
# objects
# ----------------------------------------------------------------------------
# ---------------------------
MUSIC_OBJS:= bgmusic.o \
snd_codec.o \
@ -272,21 +255,31 @@ OBJS := strlcat.o \
sv_user.o \
world.o \
zone.o \
$(SYSOBJ_SYS) $(SYSOBJ_MAIN) $(SYSOBJ_RES)
$(SYSOBJ_SYS) $(SYSOBJ_MAIN)
# ------------------------
# MinGW-w64 build rules
# ------------------------
# ---------------------------
# targets / rules
# ---------------------------
quakespasm.exe: $(OBJS)
$(LINKER) $(OBJS) $(LDFLAGS) $(LIBS) $(SDL_LIBS) -o $@
.PHONY: clean debug release
DEFAULT_TARGET := quakespasm.exe
all: $(DEFAULT_TARGET)
%.o: %.c
$(CC) $(DFLAGS) -c $(CFLAGS) $(SDL_CFLAGS) -o $@ $<
%.res: ../Windows/%.rc
$(WINDRES) -I../Windows --output-format=coff --target=pe-x86-64 -o $@ $<
quakespasm.exe: $(OBJS) $(SYSOBJ_RES)
$(LINKER) $(OBJS) $(SYSOBJ_RES) $(LDFLAGS) $(LIBS) $(SDL_LIBS) -o $@
$(call do_strip,$@)
image.o: lodepng.c lodepng.h stb_image_write.h
release: quakespasm.exe
debug:
$(error Use "make DEBUG=1")
clean:
rm -f $(shell find . \( -name '*~' -o -name '#*#' -o -name '*.o' -o -name '*.res' -o -name $(DEFAULT_TARGET) \) -print)
$(RM) *.o *.d *.res $(DEFAULT_TARGET)
sinclude $(OBJS:.o=.d)