Skip to content

Commit

Permalink
Add Makefiles, ifdeffed hackery, etc. for Windows build
Browse files Browse the repository at this point in the history
  • Loading branch information
ec429 committed Jul 17, 2014
1 parent 25b1df6 commit 762157a
Show file tree
Hide file tree
Showing 22 changed files with 153 additions and 20 deletions.
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ events.c: dat/events mkevents.py
./mkevents.py c >events.c

widgets.o: widgets.c widgets.h bits.h render.h
$(CC) $(CFLAGS) $(CPPFLAGS) $(SDLFLAGS) -o $@ -c $<

save/%.sav: save/%.sav.in gensave.py
./gensave.py --salt $< <$< >$@
Expand Down Expand Up @@ -103,3 +102,9 @@ static: all
mkdir static
cp -r art dat lib map save stats *.o static/
make -C static -f lib/Makefile -B harris

windows: all
mkdir windows
cp -r art dat map save stats *.c *.h *.o *.py windows/
cp lib-w/* windows/
make -C windows -f Makefile.w32 -B
11 changes: 11 additions & 0 deletions bits.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,14 @@ int gacid(const char from[8], acid *buf)
}
return(0);
}

#ifdef WINDOWS /* doesn't have strndup, we need to implement one */
char *strndup(const char *s, size_t size)
{
char *rv=(char *)malloc(size+1);
if(rv==NULL) return(NULL);
strncpy(rv, s, size);
rv[size]=0;
return(rv);
}
#endif
4 changes: 4 additions & 0 deletions bits.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ void free_string(string *s); // frees a string (is just free(s->buf); really)

void pacid(acid id, char buf[9]); // print an a/c id as hex
int gacid(const char from[8], acid *buf); // parse an a/c id from hex

#ifdef WINDOWS /* doesn't have strndup, we need to implement one */
char *strndup(const char *s, size_t size);
#endif
22 changes: 21 additions & 1 deletion gensave.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/python

import sys, zlib
import sys, zlib, struct

def multiply(line):
if len(line) > 1:
Expand All @@ -20,6 +20,8 @@ def genids(line, i):
else:
return line

windows = '--windows' in sys.argv

salt = ''
if '--salt' in sys.argv:
sarg = sys.argv.index('--salt')
Expand All @@ -29,8 +31,26 @@ def genids(line, i):
sys.stderr.write('--salt requires argument!\n')
sys.exit(1)

def float_to_hex(value):
f = float(value)
bytes = struct.pack('>d', f)
i, = struct.unpack('>q', bytes)
return '%016x'%i

for line in sys.stdin.readlines():
lines = multiply(line)
for i,line in enumerate(lines):
line = genids(line, i)
if windows and ':' in line:
to_conv = {'Confid':(0,),
'Morale':(0,),
'IClass':(1,),
'Targets init':(0,1,2,3),
'Targ':(1,2,3,4),}
tag, values = line.rstrip('\n').split(':', 1)
values = values.split(',')
if tag in to_conv:
for pos in to_conv[tag]:
values[pos] = float_to_hex(values[pos])
line = ':'.join((tag, ','.join(values))) + '\n'
sys.stdout.write(line)
12 changes: 12 additions & 0 deletions harris.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,10 @@ unsigned char tnav[128][128]; // Recognisability of terrain. High for rivers, e
unsigned int mainsizex=default_w, mainsizey=default_h;
bool fullscreen=false;

#ifndef WINDOWS
bool localdat=false, localsav=false;
char *cwd;
#endif

game state;

Expand All @@ -123,6 +125,7 @@ int main(int argc, char *argv[])

for(int arg=1;arg<argc;arg++)
{
#ifndef WINDOWS
if(strcmp(argv[arg], "--localdat")==0)
{
localdat=true;
Expand All @@ -136,29 +139,34 @@ int main(int argc, char *argv[])
localdat=localsav=true;
}
else
#endif
{
fprintf(stderr, "Unrecognised argument '%s'\n", argv[arg]);
return(2);
}
}

#ifndef WINDOWS
char cwd_buf[1024];
if(!(cwd=getcwd(cwd_buf, 1024)))
{
perror("getcwd");
return(1);
}
#endif

SDL_Init(SDL_INIT_VIDEO);

// Load data files
fprintf(stderr, "Loading data files...\n");

#ifndef WINDOWS
if(chdir(localdat?cwd:DATIDIR))
{
perror("Failed to enter data dir: chdir");
return(1);
}
#endif

// Set icon - must come before SDL_image usage and SDL_SetVideoMode
SDL_Surface *icon=SDL_LoadBMP("art/icon.bmp");
Expand Down Expand Up @@ -366,6 +374,7 @@ int main(int argc, char *argv[])
srand(0);
fprintf(stderr, "Game state allocated\n");

#ifndef WINDOWS
if(localsav)
{
if(chdir(cwd))
Expand Down Expand Up @@ -413,6 +422,7 @@ int main(int argc, char *argv[])
return(1);
}
}
#endif

fprintf(stderr, "Instantiating GUI elements...\n");
atg_canvas *canvas=atg_create_canvas_with_opts(1, 1, (atg_colour){0, 0, 0, ATG_ALPHA_OPAQUE}, SDL_RESIZABLE);
Expand Down Expand Up @@ -451,11 +461,13 @@ int main(int argc, char *argv[])
}
fprintf(stderr, "Instantiated %d screens\n", NUM_SCREENS);

#ifndef WINDOWS
if(chdir(localdat?cwd:DATIDIR)) // may need to load from $DATIDIR/save/
{
perror("Failed to enter data dir: chdir");
return(1);
}
#endif

screen_id current=SCRN_MAINMENU, old;

Expand Down
4 changes: 4 additions & 0 deletions history.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ int hist_append(history *hist, const char line[HIST_LINE])
int hist_save(history hist, FILE *out)
{
if(!out) return(1);
#ifdef WINDOWS
fprintf(out, "History:%lu\n", (unsigned long)hist.nents);
#else
fprintf(out, "History:%zu\n", hist.nents);
#endif
for(size_t i=0;i<hist.nents;i++)
{
char *line=hist.ents[i];
Expand Down
Binary file added lib-w/LiberationMono-Regular.ttf
Binary file not shown.
47 changes: 47 additions & 0 deletions lib-w/Makefile.w32
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Makefile for Harris Windows build

# Warning! Doesn't track all dependencies, so call on a clean tree or use -B!

CC := i586-mingw32msvc-gcc
CFLAGS := -Wall -Wextra -Werror --std=gnu99 -fgnu89-inline -g -L. -Wfatal-errors
CPPFLAGS := -DWINDOWS
LIBS := -latg -lm
SDLFLAGS := `/usr/i586-mingw32msvc/bin/sdl-config --cflags` -I/usr/i586-mingw32msvc/include/SDL
SDL := `/usr/i586-mingw32msvc/bin/sdl-config --libs` -lSDL_ttf -lSDL_gfx -lSDL_image

INTEL_OBJS := intel_bombers.o intel_fighters.o intel_targets.o
SCREEN_OBJS := main_menu.o setup_game.o setup_difficulty.o load_game.o save_game.o control.o run_raid.o raid_results.o post_raid.o $(INTEL_OBJS)
OBJS := weather.o bits.o rand.o geom.o widgets.o date.o history.o routing.o saving.o render.o events.o ui.o load_data.o dclass.o $(SCREEN_OBJS)
INCLUDES := $(OBJS:.o=.h) types.h globals.h version.h
SAVES := save/qstart.sav save/civ.sav save/abd.sav save/ruhr.sav

all: harris.exe $(SAVES) dat/targets dat/cities/Lubeck.pbm dat/cities/Peenemunde.pbm

harris.exe: harris.o $(OBJS)
$(CC) $(CFLAGS) $(CPPFLAGS) $(SDLFLAGS) $(LDFLAGS) $(OBJS) $(LIBS) $(SDL) harris.o -o $@

harris.o: harris.c $(INCLUDES)
$(CC) $(CFLAGS) $(CPPFLAGS) $(SDLFLAGS) -o $@ -c $<

events.h: dat/events mkevents.py
./mkevents.py h >events.h

events.c: dat/events mkevents.py
./mkevents.py c >events.c

save/%.sav: save/%.sav.in gensave.py
./gensave.py --windows --salt $< <$< >$@

dat/targets: FORCE
sed -i dat/targets -e 's/ö/o/g' -e 's/ü/u/g' -e 's/Ø/O/g'

dat/cities/Lubeck.pbm: dat/cities/Lübeck.pbm
cp dat/cities/Lübeck.pbm dat/cities/Lubeck.pbm

dat/cities/Peenemunde.pbm: dat/cities/Peenemünde.pbm
cp dat/cities/Peenemünde.pbm dat/cities/Peenemunde.pbm

%.o: %.c %.h
$(CC) $(CFLAGS) $(CPPFLAGS) $(SDLFLAGS) -o $@ -c $<

FORCE:
Binary file added lib-w/SDL.dll
Binary file not shown.
Binary file added lib-w/SDL_image.dll
Binary file not shown.
Binary file added lib-w/SDL_ttf.dll
Binary file not shown.
Binary file added lib-w/jpeg.dll
Binary file not shown.
Binary file added lib-w/libSDL_gfx-13.dll
Binary file not shown.
Binary file added lib-w/libatg.dll
Binary file not shown.
Binary file added lib-w/libfreetype-6.dll
Binary file not shown.
Binary file added lib-w/libpng12-0.dll
Binary file not shown.
Binary file added lib-w/libtiff-3.dll
Binary file not shown.
Binary file added lib-w/zlib1.dll
Binary file not shown.
17 changes: 12 additions & 5 deletions load_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@
#include "ui.h"
#include "widgets.h"

#ifdef WINDOWS /* I hate having to put in these ugly warts */
#define ssize_t int
#define zn "%n"
#else
#define zn "%zn"
#endif

int load_bombers(void)
{
FILE *typefp=fopen("dat/bombers", "r");
Expand All @@ -43,7 +50,7 @@ int load_bombers(void)
this.manu=(char *)malloc(strcspn(next, ":")+1);
ssize_t db;
int e;
if((e=sscanf(next, "%[^:]:%[^:]:%u:%u:%u:%u:%u:%u:%u:%u:%u:%u:%u:%zn", this.manu, this.name, &this.cost, &this.speed, &this.alt, &this.cap, &this.svp, &this.defn, &this.fail, &this.accu, &this.range, &this.blat, &this.blon, &db))!=13)
if((e=sscanf(next, "%[^:]:%[^:]:%u:%u:%u:%u:%u:%u:%u:%u:%u:%u:%u:"zn, this.manu, this.name, &this.cost, &this.speed, &this.alt, &this.cap, &this.svp, &this.defn, &this.fail, &this.accu, &this.range, &this.blat, &this.blon, &db))!=13)
{
fprintf(stderr, "Malformed `bombers' line `%s'\n", next);
fprintf(stderr, " sscanf returned %d\n", e);
Expand Down Expand Up @@ -166,7 +173,7 @@ int load_fighters(void)
this.manu=(char *)malloc(strcspn(next, ":")+1);
ssize_t db;
int e;
if((e=sscanf(next, "%[^:]:%[^:]:%u:%u:%u:%u:%hhu:%zn", this.manu, this.name, &this.cost, &this.speed, &this.arm, &this.mnv, &this.radpri, &db))!=7)
if((e=sscanf(next, "%[^:]:%[^:]:%u:%u:%u:%u:%hhu:"zn, this.manu, this.name, &this.cost, &this.speed, &this.arm, &this.mnv, &this.radpri, &db))!=7)
{
fprintf(stderr, "Malformed `fighters' line `%s'\n", next);
fprintf(stderr, " sscanf returned %d\n", e);
Expand Down Expand Up @@ -270,7 +277,7 @@ int load_ftrbases(void)
// LAT:LONG:ENTRY:EXIT
ssize_t db;
int e;
if((e=sscanf(next, "%u:%u:%zn", &this.lat, &this.lon, &db))!=2)
if((e=sscanf(next, "%u:%u:"zn, &this.lat, &this.lon, &db))!=2)
{
fprintf(stderr, "Malformed `ftrbases' line `%s'\n", next);
fprintf(stderr, " sscanf returned %d\n", e);
Expand Down Expand Up @@ -321,7 +328,7 @@ int load_targets(void)
this.p_intel=NULL;
ssize_t db;
int e;
if((e=sscanf(next, "%[^:]:%u:%u:%u:%u:%u:%zn", this.name, &this.prod, &this.flak, &this.esiz, &this.lat, &this.lon, &db))!=6)
if((e=sscanf(next, "%[^:]:%u:%u:%u:%u:%u:"zn, this.name, &this.prod, &this.flak, &this.esiz, &this.lat, &this.lon, &db))!=6)
{
fprintf(stderr, "Malformed `targets' line `%s'\n", next);
fprintf(stderr, " sscanf returned %d\n", e);
Expand Down Expand Up @@ -580,7 +587,7 @@ int load_flaksites(void)
// STRENGTH:LAT:LONG:ENTRY:RADAR:EXIT
ssize_t db;
int e;
if((e=sscanf(next, "%u:%u:%u:%zn", &this.strength, &this.lat, &this.lon, &db))!=3)
if((e=sscanf(next, "%u:%u:%u:"zn, &this.strength, &this.lat, &this.lon, &db))!=3)
{
fprintf(stderr, "Malformed `flak' line `%s'\n", next);
fprintf(stderr, " sscanf returned %d\n", e);
Expand Down
Loading

0 comments on commit 762157a

Please sign in to comment.