changeset 23:c3622b53a23e

Clean up the build system.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 23 May 2010 22:59:25 +0300
parents 885458f0d56e
children 78235ee17b69
files COMPILING Makefile Makefile.inc configure.c endianchk.c nykyaeka/Makefile nykyaeka/Makefile.in oldchsool/Makefile oldchsool/Makefile.in peluce/Makefile peluce/Makefile.in pwplib/Makefile pwplib/Makefile.in pwpzax/Makefile
diffstat 14 files changed, 184 insertions(+), 308 deletions(-) [+]
line wrap: on
line diff
--- a/COMPILING	Sun May 23 20:22:57 2010 +0300
+++ b/COMPILING	Sun May 23 22:59:25 2010 +0300
@@ -1,18 +1,11 @@
+Requirements
+============
+
+* A working C compiler (preferably GCC3 or later)
+* Make (GNU Make 3.81 or later works at least)
+* POSIX-ish platform for building (Windows targets
+  can be built via cross-compilation.)
+
 Quick and dirty guide to make it:
 
-- Just type make and follow the instructions
-- Or just do make <your desired systype>
-
-The available systypes are: unix, linux, hpux, cygwin, win32
-
-The experience on previous versions of pwplib also suggests succesful
-compilation on the following platforms:
-   - Solaris/SPARC (without sound support; also with native compiler)
-   - AIX/PowerPC (without sound support; also with native compiler)
-
-We hope to support even more platforms (such as msdos, palmos,
-macos and msx) in the future.
-
-We will release a final version sometimes after the party (Proxy 2001),
-hopefully with tested+easier compilation.
-
+Just type make and follow the instructions
--- a/Makefile	Sun May 23 20:22:57 2010 +0300
+++ b/Makefile	Sun May 23 22:59:25 2010 +0300
@@ -1,46 +1,78 @@
-all: pwplib.a
-	cd peluce; make
-	cd nykyaeka; make
-	cd oldchsool; make
+### Global settings
+CFLAGS=-g -W -Wall -O3
+LDFLAGS=
+
+### Subdirectories to build
+SUBDIRS=pwplib peluce nykyaeka oldchsool pwpzax
 
-./configure:
-	$(CC) configure.c -o configure
+### Show some help
+help:
+	@if test ! -f config.mak; then \
+	echo "PWPLib build system"; \
+	echo "Usage: make <target>"; \
+	echo ""; \
+	echo "sdl        - LibSDL video/audio for POSIX style systems"; \
+	echo "unix       - Terminal only POSIX style systems"; \
+	echo "linux      - Like unix, but with Linux console and OSS audio support"; \
+	echo "hpux       - HP-UX (untested now)"; \
+	echo "sdl-win32  - LibSDL for Win32, cross compilation via MinGW toolchain"; \
+	echo "sdl-win64  - Like above, but for Win64 via MinGW64"; \
+	echo ""; \
+	else \
+	echo "Configured as:"; \
+	cat config.mak; \
+	echo "To build: 'make all'"; \
+	echo "To reconfigure: 'make clean' or 'make <target>'"; \
+	fi
 
-pwplib/Makefile: ./configure
-	./configure
-	exit 123
+endianchk: endianchk.c
+	$(CC) -o $@ $<
 
-pwplib.a: pwplib/Makefile
-	cd pwplib; make
+config.mak:
+	@echo "" > $@
+	@echo "# Build target: $(XTARGET)" >> $@
+	@echo "CC=$(CC)" >> $@
+	@echo "CFLAGS=$(CFLAGS) $(XCFLAGS)" >> $@
+	@echo "LDFLAGS=$(LDFLAGS) $(XLDFLAGS)" >> $@
+	@echo "" >> $@
+
+### Build sub targets	
+all:
+	@for subdir in $(SUBDIRS); do $(MAKE) -C "$$subdir"; done
+
+pwplib.a:
+	$(MAKE) -C pwplib
 
 clean:
-	rm -f *~ ./configure ./configure.exe
-	cd pwplib; make clean; rm -f Makefile
-	cd peluce; make clean; rm -f Makefile
-	cd nykyaeka; make clean; rm -f Makefile
-	cd oldchsool; make clean; rm -f Makefile
+	@for subdir in $(SUBDIRS); do $(MAKE) -C "$$subdir" clean; done
+	$(RM) config.mak endianchk
 
-linux: ./configure
-	./configure linux
-	make all
+### Major targets
+unix: endianchk
+	$(RM) config.mak && endianflags=`./endianchk` && \
+	$(MAKE) config.mak XTARGET="$@" XCFLAGS="-DUNIX $$endianflags" XLDFLAGS="-lm" && \
+	$(MAKE) all
 
-sdl: ./configure
-	./configure sdl
-	make all
+hpux:
+	$(RM) config.mak && \
+	$(MAKE) config.mak XTARGET="$@" XCFLAGS="-DUNIX -DBIG_ENDIAN -DDRIVE_HPUX" XLDFLAGS="-lm" && \
+	$(MAKE) all
 
-unix: ./configure
-	./configure unix
-	make all
-
-hpux: ./configure
-	./configure hpux
-	make all
+linux: endianchk
+	$(RM) config.mak && endianflags=`./endianchk` && \
+	$(MAKE) config.mak XTARGET="$@" XCFLAGS="-DUNIX -DDRIVE_LINUXCON -DDRIVE_OSS $$endianflags" XLDFLAGS="-lm" && \
+	$(MAKE) all
 
-cygwin: ./configure
-	./configure cygwin
-	make all
+sdl: endianchk
+	$(RM) config.mak && endianflags=`./endianchk` && \
+	$(MAKE) config.mak XTARGET="$@" XCFLAGS="-DUNIX -DDRIVE_SDL $$endianflags `sdl-config --cflags`" XLDFLAGS="`sdl-config --libs` -lm" && \
+	$(MAKE) all
 
-win32: ./configure
-	./configure win32
-	make all
+sdl-win32: endianchk
+	$(RM) config.mak && \
+	$(MAKE) config.mak CC=i586-mingw32msvc-gcc AR=i586-mingw32msvc-ar \
+	XTARGET="$@" XCFLAGS="-DUNIX -DDRIVE_SDL `sdl-config --cflags`" XLDFLAGS="`sdl-config --libs`" && \
+	$(MAKE) all
 
+.dummy:
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Makefile.inc	Sun May 23 22:59:25 2010 +0300
@@ -0,0 +1,12 @@
+CFLAGS += -I../pwplib
+LDFLAGS +=
+
+%.o: %.c %.h
+	$(CC) $(CFLAGS) -c -o $@ $<
+
+%.o: %.c
+	$(CC) $(CFLAGS) -c -o $@ $<
+
+clean:
+	$(RM) $(TARGETS) *.o *.exe
+
--- a/configure.c	Sun May 23 20:22:57 2010 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,184 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-
-/*
- *	WE BE ELEET ENOUGH NOT TO HASSLE WITH PHUKKEN
- *	BOURNE SHELL SCRIPTAHS
- */
-
-const char*pwplogo=
-"\033[2J\033[H\n"
-"   \033[36;46mMMmmmmmmMM\033[0m\n"
-"       \033[36;46mMM\033[0m\n"
-"    \033[31;41mxxxxxxxxxxxx\033[0m\n"
-"    \033[31;41mxxxxxxxxxxxxxxxxxxx\033[0m\n"
-"   \033[31;41mxxxxxxxxx\033[0m\n"
-"   \033[33;43mZZZZZ\033[34;44m....\033[0m        %%%%%%%%%  %%%        %%%  %%%%%%%%%\n"
-"  \033[37;47m@@@@\033[34;44m......\033[0m        %%%%%%%%%. %%%....... %%%. %%%%%%%%%....\n"
-"  \033[37;47m@@@@\033[34;44m....\033[37mo\033[34m.\033[0m   .....%%%   %%%  %%%   %%%  %%%  %%%   %%%\n"
-" \033[37;47m@@@@@@@\033[34;44m....\033[0m        %%%   %%%  %%%   %%%  %%%  %%%   %%%\n"
-" \033[37;47m@@@@@@@@@@@\033[0m        %%%%  %%%  %%%   %%%  %%%  %%%%  %%%\n"
-" \033[37;47m@@@@@@@@@@@@@\033[0m      %%%%  %%%  %%%   %%%  %%%  %%%%  %%%\n"
-" \033[37;47m@@@@@@@@@@@@@@@\033[0m    %%%%%%%%%  %%%   %%%  %%%  %%%%%%%%%\n"
-"  \033[37;47m@@@@\033[0m              %%%%%%%%%  %%%   %%%  %%%  %%%%%%%%%\n"
-"  \033[37;47m@@@@@@\033[0m            %%%        %%%%% %%%  %%%  %%%\n"
-"  \033[37;47m@@@@@@@@@@\033[0m  \033[31;41mxx\033[0m    %%%        %%%%% %%%  %%%  %%%\n"
-"  \033[37;47m@@@@@@@@@@@@@@\033[0m    %%%        %%%%% %%%% %%%  %%%\n"
-"   \033[37;47m@@@@@@@@@@@\033[0m      %%%        %%%%% %%%% %%%  %%%\n"
-"   \033[37;47m@@@@@@@@@\033[0m   .....%%%....... %%%%%%%%%%%%%%. %%%..........\n"
-"     \033[37;47m@@@@@\033[0m          %%%        %%%%%%%%%%%%%%  %%%\n"
-"     \033[37;47m@@@@\033[0m\n\n";
-
-
-char*prods[] = { "pwplib", "peluce", "nykyaeka", "oldchsool", NULL };
-
-void printconfig_win32native(f,name,mingwdir,mingwgcclib)
-     FILE*f; char*name,*mingwdir,*mingwgcclib;
-{
-    if(strcmp(name,"pwplib")) {
-
-    fprintf(f,"\n\n"
-             "%s: $(OBJS)\n"
-             "\tld -Bdynamic -o %s.exe %s/lib/crt2.o "
-                  "-L%s/lib -L%s $(OBJS) ../pwplib.a "
-                  "-lgcc -lmoldname -lmsvcrt -lkernel32 "
-                  "-lwinmm -lmingw32\n"
-             "\tstrip %s.exe\n"
-             "\tupx %s.exe\n\n",
-
-             name,
-             name,mingwdir,
-             mingwdir,mingwgcclib,
-             name,name);
-   }
-
-   fprintf(f,"%%.o: %%.c\n"
-             "\tgcc -O2 -mno-cygwin -I../pwplib -c -o $@ -DDRIVE_WIN32 $(@:.o=.c)\n\n");
-}
-
-char*systype;
-
-int cpu_is_little_endian()
-{
-   int numeric=1;
-   char*s=(char*)&numeric;
-   return (int)(*s);
-}
-
-void printconfig_unix(f,name,ccinvo,ldflags)
-     FILE*f; char*name,*ccinvo,*ldflags;
-{
-   if(strcmp(name,"pwplib")) {
-
-   fprintf(f,"\n\n"
-             "%s: $(OBJS) ../pwplib.a\n"
-             "\t%s -o $@ $+ %s\n\n",
-             name,ccinvo,ldflags);
-   }
-
-   fprintf(f,"%%.o: %%.c\n"
-             "\t%s -I../pwplib -c -o $@ $(@:.o=.c)\n\n",
-             ccinvo);
-}
-
-void print_valid_systypes()
-{
-   puts("* Valid systypes are:\n"
-        "  linux  - linux with oss & vcsa console (host endian check)\n"
-        "  sdl    - generic unix with SDL library (host endian check)\n"
-        "  unix   - generic unix without sound support (host endian check)\n"
-        "  hpux   - hp-ux (big-endian unix with native sound support)\n"
-        "  cygwin - windows pc system with cygwin\n"
-        "  win32  - native win32 binary (cygwin + mingw32 libraries)\n\n");
-}
-
-void makeconfig(prodname,systype)
-     char*prodname,*systype;
-{
-    char makefile_in[32],makefile[32];
-    FILE *f_in,*f;
-
-    printf("* Writing makefile for %s\n",prodname);
-
-    sprintf(makefile_in,"%s/Makefile.in",prodname);
-    sprintf(makefile,   "%s/Makefile",   prodname);
-
-    f_in = fopen(makefile_in,"r");
-    f    = fopen(makefile,   "w");
-
-    if(f==NULL) { puts("* Error writing Makefile\n"); exit(1); }
-    if(f_in==NULL) { puts("* Error reading Makefile.in\n"); exit(1); }
-
-    {int c;
-     while((c=fgetc(f_in))!=EOF) { fputc(c,f); }}
-
-    if(!strcmp(systype,"unix"))
-    {
-       if(!cpu_is_little_endian())
-       printconfig_unix(f,prodname,"gcc -O2 -DUNIX -DBIG_ENDIAN","-lm"); else
-       printconfig_unix(f,prodname,"gcc -O2 -DUNIX","-lm");
-    }
-    else
-    if(!strcmp(systype,"hpux"))
-       printconfig_unix(f,prodname,"gcc -O2 -DUNIX -DBIG_ENDIAN -DDRIVE_HPUX","-lm");
-    else
-    if(!strcmp(systype,"linux"))
-    {
-       if(!cpu_is_little_endian())
-       printconfig_unix(f,prodname,"gcc -O2 -DUNIX -DDRIVE_OSS -DDRIVE_LINUXCON -DBIG_ENDIAN","-lm");else
-       printconfig_unix(f,prodname,"gcc -O2 -DUNIX -DDRIVE_OSS -DDRIVE_LINUXCON","-lm");
-    }
-    else
-    if(!strcmp(systype,"sdl"))
-    {
-       if(!cpu_is_little_endian())
-       printconfig_unix(f,prodname,"gcc -O2 -DUNIX -DDRIVE_SDL -DBIG_ENDIAN `sdl-config --cflags`","-lm `sdl-config --libs`");else
-       printconfig_unix(f,prodname,"gcc -O2 -DUNIX -DDRIVE_SDL `sdl-config --cflags`","-lm `sdl-config --libs`");
-    }
-    else
-    if(!strcmp(systype,"cygwin")) 
-       printconfig_unix(f,prodname,"gcc -O2 -DDRIVE_WIN32","-lm -lwinmm");   
-    else
-    if(!strcmp(systype,"win32"))
-      printconfig_win32native
-      (f,prodname,"/usr/local/mingw",
-       "/usr/local/mingw/lib/gcc-lib/mingw32/2.95.3-4");
-    else
-    {
-       puts("* Invalid systype!"); print_valid_systypes();
-       exit(1);
-    }
-
-    fclose(f_in);
-    fclose(f);
-}
-
-int main(argc,argv)
-    int argc; char**argv;
-{
-    puts(pwplogo);
-
-    if(argc<=1)
-    {
-       printf("* Usage: %s systype\n",argv[0]);
-       print_valid_systypes();
-       exit(0);
-    }
-     else systype=argv[1];
-
-    {char**p=prods;
-     while(*p!=NULL)
-     {
-        makeconfig(*p,systype);
-        p++;
-     }
-    }
-
-    puts("* Finished writing makefiles! Now 'make'\n");
-
-    return 0;
-}
-
-
-
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/endianchk.c	Sun May 23 22:59:25 2010 +0300
@@ -0,0 +1,11 @@
+#include <stdio.h>
+
+int main(int argc, char *argv[])
+{
+    int val = 1, ret;
+    char *s = (char *) &val;
+    ret = (int)(*s);
+    printf("%s\n", ret ? "-DLITTLE_ENDIAN" : "-DBIG_ENDIAN");
+    return 0;
+}
+         
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nykyaeka/Makefile	Sun May 23 22:59:25 2010 +0300
@@ -0,0 +1,21 @@
+include ../config.mak
+
+TARGETS=nykyaeka$(BINEXT)
+
+all: $(TARGETS)
+
+OBJS=sprites.o main.o musa.o planes.o landscro.o ../pwplib.a
+
+include ../Makefile.inc
+
+sprites.o: sprites.c sprites.h font.h
+	$(CC) $(CFLAGS) -c -o $@ $<
+
+musa.o: musa.c musa.h
+
+%.h: %.pl
+	perl $< > $@
+
+nykyaeka$(BINEXT): $(OBJS)
+	$(CC) $(CFLAGS) -o $@ $+ $(LDFLAGS)
+
--- a/nykyaeka/Makefile.in	Sun May 23 20:22:57 2010 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,15 +0,0 @@
-all: nykyaeka
-
-############################
-
-OBJS= sprites.o main.o musa.o planes.o landscro.o
-
-sprites.o: sprites.c sprites.h font.h
-
-musa.o: musa.c musa.h
-
-%.h: %.pl
-	perl $< > $@
-
-clean:
-	$(RM) *.o *~ nykyaeka *.exe
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/oldchsool/Makefile	Sun May 23 22:59:25 2010 +0300
@@ -0,0 +1,18 @@
+include ../config.mak
+
+TARGETS=oldchsool$(BINEXT)
+
+all: $(TARGETS)
+
+OBJS=sprites.o main.o musa.o planes.o landscro.o ../pwplib.a
+
+include ../Makefile.inc
+
+%.h: %.pl
+	perl $< > $@
+
+sprites.o: sprites.c sprites.h font.h
+	$(CC) $(CFLAGS) -c -o $@ $<
+
+oldchsool$(BINEXT): $(OBJS)
+	$(CC) $(CFLAGS) -o $@ $+ $(LDFLAGS)
--- a/oldchsool/Makefile.in	Sun May 23 20:22:57 2010 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,23 +0,0 @@
-all: oldchsool
-
-OBJS      = sprites.o main.o musa.o planes.o landscro.o
-
-############################
-
-sprites.o: sprites.c sprites.h font.h
-
-sprites.h: sprites.pl
-	./sprites.pl > sprites.h
-
-musa.o: musa.c musa.h
-
-musa.h: musa.pl
-	./musa.pl > musa.h
-
-font.h: font.pl
-	./font.pl > font.h
-
-clean:
-	rm -rf *.o *~ oldchsool *.exe
-
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/peluce/Makefile	Sun May 23 22:59:25 2010 +0300
@@ -0,0 +1,19 @@
+include ../config.mak
+
+TARGETS=peluce$(BINEXT)
+
+all: $(TARGETS)
+
+OBJS=main.o planes.o font.o sprites.o musa.o landscroll.o ../pwplib.a
+
+include ../Makefile.inc
+
+font.h: font-gen.pl
+	perl $< > $@
+
+sprites.o: sprites.c sprites.h
+	$(CC) $(CFLAGS) -c -o $@ $<
+
+peluce$(BINEXT): $(OBJS)
+	$(CC) $(CFLAGS) -o $@ $+ $(LDFLAGS)
+
--- a/peluce/Makefile.in	Sun May 23 20:22:57 2010 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,16 +0,0 @@
-CC = gcc -O2
-
-all: peluce
-
-############################
-
-OBJS= main.o planes.o font.o sprites.o musa.o landscroll.o ../pwplib.a
-
-font.h: font-gen.pl
-	./font-gen.pl > $@
-
-sprites.o: sprites.c sprites.h
-	$(CC) $< -c -o $@
-
-clean:
-	$(RM) peluce *.o *~ *.exe
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pwplib/Makefile	Sun May 23 22:59:25 2010 +0300
@@ -0,0 +1,16 @@
+include ../config.mak
+
+TARGETS=../pwplib.a
+
+OBJS=pwplib.o snd-w32.o win32con.o setup.o gb.o \
+	locale.o convert.o attrconv.o rastconv.o tty.o \
+	sdl.o linuxcon.o snd-sdl.o snd-oss.o snd-hpux.o \
+	lossy.o pvp.o glyphgen.o colorterm.o decterm.o dumbterm.o
+
+all: $(TARGETS)
+
+../pwplib.a: $(OBJS)
+	$(AR) rc $@ $+
+
+include ../Makefile.inc
+
--- a/pwplib/Makefile.in	Sun May 23 20:22:57 2010 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,19 +0,0 @@
-##################################################
-
-OBJS=pwplib.o snd-w32.o win32con.o setup.o gb.o \
-     locale.o convert.o attrconv.o rastconv.o tty.o \
-     sdl.o linuxcon.o snd-sdl.o snd-oss.o snd-hpux.o lossy.o pvp.o \
-     glyphgen.o colorterm.o decterm.o dumbterm.o
-
-all: ../pwplib.a
-
-### pwplib #######################################
-
-../pwplib.a: $(OBJS)
-	$(AR) r ../pwplib.a $(OBJS)
-
-### pwplib stuff #################################
-
-clean:
-	rm -f *.o *~ ../pwplib.a
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pwpzax/Makefile	Sun May 23 22:59:25 2010 +0300
@@ -0,0 +1,11 @@
+include ../config.mak
+
+TARGETS=zaxplay
+
+all: $(TARGETS)
+
+include ../Makefile.inc
+
+zaxplay: zaxplay.c
+	$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)
+