#
# Copyright (C) 1996 by Raphael Quinet.  All rights reserved.
#
# Permission to use, copy, modify, and distribute this software and
# its documentation for any purpose and without fee is hereby
# granted, provided that the above copyright notice appear in all
# copies and that both that copyright notice and this permission
# notice appear in supporting documentation.  If more than a few
# lines of this code are used in a program which displays a copyright
# notice or credit notice, the following acknowledgment must also be
# displayed on the same screen: "This product includes software
# developed by Raphael Quinet for use in the Quake Editing Utilities
# project."  THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR
# IMPLIED WARRANTY.
#
# More information about the QEU project can be found on the WWW:
# "http://www.montefiore.ulg.ac.be/~quinet/games/editing.html" or by
# mail: Raphael Quinet, 9 rue des Martyrs, B-4550 Nandrin, Belgium.
#

#
# Define your C compiler here: cc, gcc, bcc or other.
#
CC = gcc

#
# Options for your C compiler.
#
CFLAGS = -O2 -ansi -Wall
#CFLAGS = -g -ansi -Wall -DDEBUG

# File prefixes:
# q_*  the core of QEU: file management functions, object structures, etc.
# f_*  Filters for various file formats (PACK, WAD, WAD2, ...).
# g_*  Graphics stuff.

PROGS = unpak repak unwad2 rewad2 unwad rewad unbsp sprview
PROGS.DOS = unpak.exe repak.exe unwad2.exe rewad2.exe unwad.exe rewad.exe unbsp.exe sprview.exe

SRCS1 = q_misc.c q_files.c f_pack.c unpak.c
OBJS1 = $(SRCS1:.c=.o)

SRCS2 = q_misc.c q_files.c f_pack.c repak.c
OBJS2 = $(SRCS2:.c=.o)

SRCS3 = q_misc.c q_files.c f_wad2.c f_bitmap.c unwad2.c
OBJS3 = $(SRCS3:.c=.o)

SRCS4 = q_misc.c q_files.c f_wad2.c f_bitmap.c rewad2.c
OBJS4 = $(SRCS4:.c=.o)

SRCS5 = q_misc.c q_files.c f_wad.c unwad.c
OBJS5 = $(SRCS5:.c=.o)

SRCS6 = q_misc.c q_files.c f_wad.c rewad.c
OBJS6 = $(SRCS6:.c=.o)

SRCS7 = q_misc.c q_files.c f_bsp.c unbsp.c
OBJS7 = $(SRCS7:.c=.o)

SRCSS = q_misc.c q_files.c f_bitmap.c f_sprite.c sprview.c
OBJSS = $(SRCSS:.c=.o)

LIBS =

all.dos: $(PROGS.DOS)

all: $(PROGS)

# temporary
sprview: $(OBJSS)
	$(CC) $(CFLAGS) -o sprview $(OBJSS) $(LIBS)

sprview.exe: sprview
	del sprview.exe
	strip sprview
	coff2exe sprview

unpak: $(OBJS1)
	$(CC) $(CFLAGS) -o unpak $(OBJS1) $(LIBS)

unpak.exe: unpak
	del unpak.exe
	strip unpak
	coff2exe unpak

repak: $(OBJS2)
	$(CC) $(CFLAGS) -o repak $(OBJS2) $(LIBS)

repak.exe: repak
	del repak.exe
	strip repak
	coff2exe repak

unwad2: $(OBJS3)
	$(CC) $(CFLAGS) -o unwad2 $(OBJS3) $(LIBS)

unwad2.exe: unwad2
	del unwad2.exe
	strip unwad2
	coff2exe unwad2

rewad2: $(OBJS4)
	$(CC) $(CFLAGS) -o rewad2 $(OBJS4) $(LIBS)

rewad2.exe: rewad2
	del rewad2.exe
	strip rewad2
	coff2exe rewad2

unwad: $(OBJS5)
	$(CC) $(CFLAGS) -o unwad $(OBJS5) $(LIBS)

unwad.exe: unwad
	del unwad.exe
	strip unwad
	coff2exe unwad

rewad: $(OBJS6)
	$(CC) $(CFLAGS) -o rewad $(OBJS6) $(LIBS)

rewad.exe: rewad
	del rewad.exe
	strip rewad
	coff2exe rewad

unbsp: $(OBJS7)
	$(CC) $(CFLAGS) -o unbsp $(OBJS7) $(LIBS)

unbsp.exe: unbsp
	del unbsp.exe
	strip unbsp
	coff2exe unbsp

clean:
	$(RM) *.o *~ *.bak

distclean: clean
	$(RM) $(PROGS)

clean.dos:
	-del *.o
	-del *.obj

lint:
	$(LINT) $(SRCS1) $(LIBS)
	$(LINT) $(SRCS2) $(LIBS)
	$(LINT) $(SRCS3) $(LIBS)
	$(LINT) $(SRCS4) $(LIBS)
	$(LINT) $(SRCS5) $(LIBS)
	$(LINT) $(SRCS6) $(LIBS)
	$(LINT) $(SRCS7) $(LIBS)

check:
	@echo There are some problems left in these files:
	@grep \\\/\\\*\! *.[ch]

check.dos:
	@echo There are some problems left in these files:
	@grep /\\\*! *.h
	@grep /\\\*! *.c

depend:
	(sed '/^# DO NOT DELETE THIS LINE/q' Makefile && \
	 for i in $(SRCS1) $(SRCS2) $(SRCS3) $(SRCS4) ;\
	 do /lib/cpp -D__UNIX__ -M $$i ;\
	 done | sed 's/:[       ]\.\//: /; /\/usr\/include/d; s/        / /g' \
	 | sort | uniq
	) > Makefile.new
	mv Makefile Makefile.bak
	mv Makefile.new Makefile

# DO NOT DELETE THIS LINE -- make depend depends on it.
