porting the demo to miniglut
authorJohn Tsiombikas <nuclear@member.fsf.org>
Mon, 15 Jun 2020 14:47:36 +0000 (17:47 +0300)
committerJohn Tsiombikas <nuclear@member.fsf.org>
Mon, 15 Jun 2020 14:47:36 +0000 (17:47 +0300)
GNUmakefile
src/cfgopt.c
src/cfgopt.h

index 49fb3a1..a6c9936 100644 (file)
@@ -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)
 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
 
 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
 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
        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
 else
-       sdl_ldflags = `sdl-config --libs`
+       LDFLAGS += -lGL -lX11 -lpthread
 endif
 
 endif
 
+sndlib_Linux = -lasound
+sndlib_IRIX = -laudio
+sndlib_mingw = -ldsound
+
 .PHONY: all
 all: data $(bin)
 
 $(bin): $(obj) imago mikmod
        $(CC) -o $@ $(obj) $(LDFLAGS)
 
 .PHONY: all
 all: data $(bin)
 
 $(bin): $(obj) imago mikmod
        $(CC) -o $@ $(obj) $(LDFLAGS)
 
+-include $(dep)
+
 %.o: %.asm
        nasm -f elf -o $@ $<
 
 %.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) >$@
 
 
 %.d: %.c
        @echo dep $@
        @$(CPP) $(CFLAGS) $< -MM -MT $(@:.d=.o) >$@
 
+.PHONY: libs
+libs: imago anim mikmod
+
 .PHONY: imago
 imago:
        $(MAKE) -C libs/imago
 
 .PHONY: imago
 imago:
        $(MAKE) -C libs/imago
 
+.PHONY: anim
+anim:
+       $(MAKE) -C libs/anim
+
 .PHONY: mikmod
 mikmod:
        $(MAKE) -C libs/mikmod
 .PHONY: mikmod
 mikmod:
        $(MAKE) -C libs/mikmod
@@ -48,6 +78,7 @@ mikmod:
 .PHONY: cleanlibs
 cleanlibs:
        $(MAKE) -C libs/imago clean
 .PHONY: cleanlibs
 cleanlibs:
        $(MAKE) -C libs/imago clean
+       $(MAKE) -C libs/anim clean
        $(MAKE) -C libs/mikmod clean
 
 .PHONY: clean
        $(MAKE) -C libs/mikmod clean
 
 .PHONY: clean
@@ -61,3 +92,8 @@ cleandep:
 .PHONY: data
 data:
        @tools/procdata
 .PHONY: data
 data:
        @tools/procdata
+
+
+.PHONY: crosswin
+crosswin:
+       $(MAKE) CC=i686-w64-mingw32-gcc sys=mingw
index 2592930..170e47f 100644 (file)
@@ -53,6 +53,12 @@ int parse_args(int argc, char **argv)
                                opt.dbginfo = 1;
                        } else if(strcmp(argv[i], "-nodbg") == 0) {
                                opt.dbginfo = 0;
                                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;
                        } 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);
                        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;
                } else {
                        fprintf(stderr, "%s:%d invalid option: %s\n", fname, nline, line);
                        return -1;
index 5172d20..9fc8c36 100644 (file)
@@ -7,6 +7,9 @@ struct options {
        int mouse, sball;
        int vsync;
        int dbginfo;
        int mouse, sball;
        int vsync;
        int dbginfo;
+#ifndef MSDOS
+       int fullscreen;
+#endif
 };
 
 extern struct options opt;
 };
 
 extern struct options opt;