Browse Source

generate posix makefile

master
katherine 3 years ago
parent
commit
fa682d949f
Signed by: ageha
GPG Key ID: 2A93AF3EA71C905F
  1. 29
      Makefile
  2. 108
      configure

29
Makefile

@ -1,29 +0,0 @@
CFLAGS+=-Wall -O2 $(shell pkg-config --cflags allegro-5 allegro_image-5 allegro_font-5 allegro_ttf-5)
CFLAGSDEBUG=-Wall -ggdb3 -O0 -DDEBUG $(shell pkg-config --cflags allegro-5 allegro_image-5 allegro_font-5 allegro_ttf-5)
LDFLAGS+=-Wall -O2 $(shell pkg-config --libs allegro-5 allegro_image-5 allegro_font-5 allegro_ttf-5)
LDFLAGSDEBUG=-Wall -ggdb3 -O0 -DDEBUG $(shell pkg-config --libs allegro-5 allegro_image-5 allegro_font-5 allegro_ttf-5)
SRCDIR=./src
OBJDIR=./obj
SRC=$(wildcard $(SRCDIR)/*.c)
OBJ=$(patsubst $(SRCDIR)%.c,$(OBJDIR)%.o,$(SRC))
BIN=gafu
all: $(OBJ)
$(CC) $(LDFLAGS) -o $(BIN) $^
$(OBJ): | $(OBJDIR)
$(OBJDIR)/%.o: $(SRCDIR)/%.c
$(CC) $(CFLAGS) -c -o $@ $<
$(OBJDIR):
mkdir -p $(OBJDIR)
clean:
rm -rf $(OBJDIR) $(BIN)
debug: CFLAGS=$(CFLAGSDEBUG)
debug: LDFLAGS=$(LDFLAGSDEBUG)
debug: all
new: clean all

108
configure vendored

@ -0,0 +1,108 @@
#!/bin/sh
# kinda brittle, this, but mostly works
# just don't use names with whitespaces
target='gafu'
srcdir='src'
sources=`find $srcdir -type f -name '*.c' | sed -e "s/$srcdir\/\(.*\).c/\1.c/"`
objdir='build'
objects=`find $srcdir -type f -name '*.c' | sed -e "s/$srcdir\/\(.*\).c/\1.o/"`
cc='cc'
cflags='-Wall -O2'
cflagsdebug='-std=c99 -Wall -pedantic -ggdb3 -O0 -DDEBUG'
prefix='/usr/local'
ldlibs=''
rls_objects=`printf %s "$objects" | sed -e "s/^/$objdir\/release\//" | tr '\n' ' '`
dbg_objects=`printf %s "$objects" | sed -e "s/^/$objdir\/debug\//" | tr '\n' ' '`
if [ ! `2>/dev/null which pkg-config` ]; then
echo 'err: build requires pkg-config'
exit 1
fi
dgen='gcc'
if [ ! `2>/dev/null which gcc` ]; then
if [ ! `2>/dev/null which clang` ]; then
echo 'err: could not find a suitable ' \
'compiler for calculating dependencies'
exit 1
fi
dgen='clang'
fi
allegcflags=`pkg-config --cflags allegro-5 allegro_image-5 allegro_font-5 allegro_ttf-5 allegro_audio-5 allegro_acodec-5`
if [ $? -ne 0 ]; then
exit 1
fi
allegldlibs=`pkg-config --libs allegro-5 allegro_image-5 allegro_font-5 allegro_ttf-5 allegro_audio-5 allegro_acodec-5`
if [ $? -ne 0 ]; then
exit 1
fi
cflags="$cflags $allegcflags"
cflagsdebug="$cflagsdebug $allegcflags"
ldlibs="$allegldlibs"
if [ -f 'Makefile' ]; then
make clean
fi
{
printf %s\\n '.POSIX:'
printf %s\\n '.SUFFIXES:'
printf %s\\n ''
printf %s\\n "CC = $cc"
printf %s\\n "CFLAGS = $cflags"
printf %s\\n "CFLAGSDEBUG = $cflagsdebug"
printf %s\\n "LDLIBS = $ldlibs"
printf %s\\n "PREFIX = $prefix"
printf %s\\n ''
printf %s\\n "all: $target"
printf %s\\n ''
printf %s\\n "debug: dbg_$target"
printf %s\\n ''
printf %s\\n "install: all"
printf %s\\n ' mkdir -p $(DESTDIR)$(PREFIX)/bin'
printf %s\\n ' mkdir -p $(DESTDIR)$(PREFIX)/share/man/man1'
printf %s\\n " cp -f $target \$(DESTDIR)\$(PREFIX)/bin"
printf %s\\n " gzip < ${target}.1 > \$(DESTDIR)\$(PREFIX)/share/man/man1/${target}.1.gz"
printf %s\\n ''
printf %s\\n "$target: ${objdir}/release $rls_objects"
printf %s\\n " \$(CC) \$(LDFLAGS) -o $target $rls_objects \$(LDLIBS)"
printf %s\\n ''
printf %s\\n "dbg_$target: ${objdir}/debug $dbg_objects"
printf %s\\n " \$(CC) \$(LDFLAGS) -o dbg_$target $dbg_objects \$(LDLIBS)"
printf %s\\n ''
printf %s\\n "${objdir}/release:"
printf %s\\n " mkdir -p ${objdir}/release"
printf %s\\n ''
printf %s\\n "${objdir}/debug:"
printf %s\\n " mkdir -p ${objdir}/debug"
printf %s\\n ''
printf %s\\n 'src/version.h:'
printf %s\\n ' printf "%s\n%s\n\n%s%s%s\n\n%s\n" \'
printf %s\\n ' "#ifndef BUILD_VERSION_H" \'
printf %s\\n ' "#define BUILD_VERSION_H" \'
printf %s\\n ' "#define VERSION \"gafu-" "`git describe --always --tags`" "\"" \'
printf %s\\n ' "#endif" > src/version.h'
printf %s\\n ''
printf %s\\n "$sources" | (while IFS= read -r s; do
$dgen $CFLAGS -MM -MG -MT ${objdir}/release/`printf %s $s | sed -e 's/\.c$/\.o/'` "$srcdir/$s" | sed -e "s/version.h/$srcdir\/version.h/"
printf %s\\n " \$(CC) -c \$(CFLAGS) -o ${objdir}/release/`printf %s $s | sed -e 's/\.c$/\.o/'` ${srcdir}/$s"
done)
printf %s\\n ''
printf %s\\n "$sources" | (while IFS= read -r s; do
$dgen $CFLAGS -MM -MG -MT ${objdir}/debug/`printf %s $s | sed -e 's/\.c$/\.o/'` "$srcdir/$s" | sed -e "s/version.h/$srcdir\/version.h/"
printf %s\\n " \$(CC) -c \$(CFLAGSDEBUG) -o ${objdir}/debug/`printf %s $s | sed -e 's/\.c$/\.o/'` ${srcdir}/$s"
done)
printf %s\\n ''
printf %s\\n 'clean:'
printf %s\\n ' rm -f src/version.h'
printf %s\\n " rm -f $target"
printf %s\\n " rm -f dbg_$target"
printf %s\\n " rm -rf $objdir"
} > Makefile
Loading…
Cancel
Save