From 67c749060592270c9cd8b4f7dafe7d7c7a61a614 Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Mon, 15 Jun 2020 17:47:36 +0300 Subject: [PATCH 1/1] porting the demo to miniglut --- GNUmakefile | 54 +++++++++++++++++++++++++++++++++++++++++++++--------- src/cfgopt.c | 10 ++++++++++ src/cfgopt.h | 3 +++ 3 files changed, 58 insertions(+), 9 deletions(-) diff --git a/GNUmakefile b/GNUmakefile index 49fb3a1..a6c9936 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -1,4 +1,4 @@ -src = $(wildcard src/*.c) $(wildcard src/scr/*.c) $(wildcard src/sdl/*.c) +src = $(wildcard src/*.c) $(wildcard src/scr/*.c) $(wildcard src/glut/*.c) asmsrc = $(wildcard src/*.asm) obj = $(src:.c=.o) $(asmsrc:.asm=.o) dep = $(obj:.o=.d) @@ -7,40 +7,70 @@ bin = demo asmsrc += cspr/dbgfont.asm cspr/confont.asm bindata = data/loading.img -inc = -I/usr/local/include -Isrc -Isrc/3dgfx -Isrc/scr -Isrc/sdl -Ilibs -Ilibs/imago/src -Ilibs/mikmod/include +inc = -I/usr/local/include -Isrc -Isrc/3dgfx -Isrc/scr -Isrc/glut -Ilibs \ + -Ilibs/imago/src -Ilibs/mikmod/include +def = -DMINIGLUT_USE_LIBC -DMIKMOD_STATIC warn = -pedantic -Wall -Wno-unused-variable -Wno-unused-function +#opt = -O3 -ffast-math +dbg = -g -CFLAGS = $(arch) $(warn) -g $(inc) `sdl-config --cflags` -LDFLAGS = $(arch) -Llibs/imago -Llibs/mikmod -limago -lmikmod $(sdl_ldflags) -lm +CFLAGS = $(arch) $(warn) $(opt) -fno-pie -fno-strict-aliasing $(dbg) $(inc) +LDFLAGS = $(arch) -no-pie -Llibs/imago -Llibs/mikmod -limago -lmikmod \ + $(sndlib_$(sys)) -lm -ifneq ($(shell uname -m), i386) +cpu ?= $(shell uname -m | sed 's/i.86/i386/') + +ifeq ($(cpu), x86_64) arch = -m32 - sdl_ldflags = -L/usr/lib/i386-linux-gnu -lSDL-1.2 +endif + +sys ?= $(shell uname -s | sed 's/MINGW.*/mingw/; s/IRIX.*/IRIX/') +ifeq ($(sys), mingw) + obj = $(src:.c=.w32.o) + + bin = demo_win32.exe + + LDFLAGS += -static-libgcc -lmingw32 -mconsole -lgdi32 -lwinmm \ + -lopengl32 else - sdl_ldflags = `sdl-config --libs` + LDFLAGS += -lGL -lX11 -lpthread endif +sndlib_Linux = -lasound +sndlib_IRIX = -laudio +sndlib_mingw = -ldsound + .PHONY: all all: data $(bin) $(bin): $(obj) imago mikmod $(CC) -o $@ $(obj) $(LDFLAGS) +-include $(dep) + %.o: %.asm nasm -f elf -o $@ $< -src/data.o: src/data.asm $(bindata) +%.w32.o: %.c + $(CC) -o $@ $(CFLAGS) -c $< --include $(dep) +src/data.o: src/data.asm $(bindata) %.d: %.c @echo dep $@ @$(CPP) $(CFLAGS) $< -MM -MT $(@:.d=.o) >$@ +.PHONY: libs +libs: imago anim mikmod + .PHONY: imago imago: $(MAKE) -C libs/imago +.PHONY: anim +anim: + $(MAKE) -C libs/anim + .PHONY: mikmod mikmod: $(MAKE) -C libs/mikmod @@ -48,6 +78,7 @@ mikmod: .PHONY: cleanlibs cleanlibs: $(MAKE) -C libs/imago clean + $(MAKE) -C libs/anim clean $(MAKE) -C libs/mikmod clean .PHONY: clean @@ -61,3 +92,8 @@ cleandep: .PHONY: data data: @tools/procdata + + +.PHONY: crosswin +crosswin: + $(MAKE) CC=i686-w64-mingw32-gcc sys=mingw diff --git a/src/cfgopt.c b/src/cfgopt.c index 2592930..170e47f 100644 --- a/src/cfgopt.c +++ b/src/cfgopt.c @@ -53,6 +53,12 @@ int parse_args(int argc, char **argv) opt.dbginfo = 1; } else if(strcmp(argv[i], "-nodbg") == 0) { opt.dbginfo = 0; +#ifndef MSDOS + } else if(strcmp(argv[i], "-fs") == 0) { + opt.fullscreen = 1; + } else if(strcmp(argv[i], "-win") == 0) { + opt.fullscreen = 0; +#endif } else { fprintf(stderr, "invalid option: %s\n", argv[i]); return -1; @@ -143,6 +149,10 @@ int load_config(const char *fname) opt.vsync = bool_value(value); } else if(strcmp(line, "debug") == 0) { opt.dbginfo = bool_value(value); +#ifndef MSDOS + } else if(strcmp(line, "fullscreen") == 0) { + opt.fullscreen = bool_value(value); +#endif } else { fprintf(stderr, "%s:%d invalid option: %s\n", fname, nline, line); return -1; diff --git a/src/cfgopt.h b/src/cfgopt.h index 5172d20..9fc8c36 100644 --- a/src/cfgopt.h +++ b/src/cfgopt.h @@ -7,6 +7,9 @@ struct options { int mouse, sball; int vsync; int dbginfo; +#ifndef MSDOS + int fullscreen; +#endif }; extern struct options opt; -- 1.7.10.4