From 097baf0284aa7ca8e6bbeef662da78c039e47a46 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Wed, 11 Aug 2010 16:18:27 +0000 Subject: [PATCH] Convert everything to the autotools. Managing source dependencies will be easier. --- .gitignore | 26 ++++++ Makefile | 13 --- Makefile.am | 7 ++ bootstrap | 140 +++++++++++++++++++++++++++++ configure.ac | 85 ++++++++++++++++++ gfx/Makefile | 7 -- gfx/Makefile.am | 3 + gfx/font/{Makefile => Makefile.am} | 0 src/Makefile | 21 ----- src/Makefile.am | 41 +++++++++ src/editor.cpp | 66 ++++++++++++++ tools/{Makefile => Makefile.am} | 0 12 files changed, 368 insertions(+), 41 deletions(-) delete mode 100644 Makefile create mode 100644 Makefile.am create mode 100755 bootstrap create mode 100644 configure.ac delete mode 100644 gfx/Makefile create mode 100644 gfx/Makefile.am rename gfx/font/{Makefile => Makefile.am} (100%) delete mode 100644 src/Makefile create mode 100644 src/Makefile.am create mode 100644 src/editor.cpp rename tools/{Makefile => Makefile.am} (100%) diff --git a/.gitignore b/.gitignore index 6fd83048..1e2a497b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,32 @@ +# Autotools cruft *.o +*.lo +*.a +*.la +*.exe +*.userprefs +*.usertasks +*.pidb +.auto +.libs +.deps +Makefile +Makefile.in +aclocal.m4 +autom4te.cache +config.h.in +config.h +config.log +config.status +configure +libtool +stamp-* +*-stamp +# Our binaries src/test-map +src/editor tools/make-font +# Our data art/*.png art/test/*.png gfx/font/*.png diff --git a/Makefile b/Makefile deleted file mode 100644 index 6a45520e..00000000 --- a/Makefile +++ /dev/null @@ -1,13 +0,0 @@ - -all: - cd src && $(MAKE) all - cd tools && $(MAKE) all - cd art && $(MAKE) all - cd gfx && $(MAKE) all - -clean: - cd gfx && $(MAKE) clean - cd art && $(MAKE) clean - cd tools && $(MAKE) clean - cd src && $(MAKE) clean - diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 00000000..7a4c520a --- /dev/null +++ b/Makefile.am @@ -0,0 +1,7 @@ + +SUBDIRS = src tools art gfx +DIST_SUBDIRS = $(SUBDIRS) + +EXTRA_DIST = bootstrap +AUTOMAKE_OPTIONS = dist-bzip2 + diff --git a/bootstrap b/bootstrap new file mode 100755 index 00000000..5752522e --- /dev/null +++ b/bootstrap @@ -0,0 +1,140 @@ +#! /bin/sh + +# bootstrap: generic bootstrap/autogen.sh script for autotools projects +# +# Copyright (c) 2002-2010 Sam Hocevar +# +# This program is free software. It comes without any warranty, to +# the extent permitted by applicable law. You can redistribute it +# and/or modify it under the terms of the Do What The Fuck You Want +# To Public License, Version 2, as published by Sam Hocevar. See +# http://sam.zoy.org/wtfpl/COPYING for more details. +# +# The latest version of this script can be found at the following place: +# http://caca.zoy.org/wiki/build + +# Die if an error occurs +set -e + +# Guess whether we are using configure.ac or configure.in +if test -f configure.ac; then + conffile="configure.ac" +elif test -f configure.in; then + conffile="configure.in" +else + echo "$0: could not find configure.ac or configure.in" + exit 1 +fi + +# Check for needed features +auxdir="`sed -ne 's/^[ \t]*A._CONFIG_AUX_DIR *([[ ]*\([^] )]*\).*/\1/p' $conffile`" +pkgconfig="`grep '^[ \t]*PKG_PROG_PKG_CONFIG' $conffile >/dev/null 2>&1 && echo yes || echo no`" +libtool="`grep '^[ \t]*A._PROG_LIBTOOL' $conffile >/dev/null 2>&1 && echo yes || echo no`" +header="`grep '^[ \t]*A._CONFIG_HEADER' $conffile >/dev/null 2>&1 && echo yes || echo no`" +makefile="`[ -f Makefile.am ] && echo yes || echo no`" +aclocalflags="`sed -ne 's/^[ \t]*ACLOCAL_AMFLAGS[ \t]*=//p' Makefile.am 2>/dev/null || :`" + +# Check for automake +amvers="no" +for v in 11 10 9 8 7 6 5; do + if automake-1.${v} --version >/dev/null 2>&1; then + amvers="-1.${v}" + break + elif automake1.${v} --version >/dev/null 2>&1; then + amvers="1.${v}" + break + fi +done + +if test "${amvers}" = "no" && automake --version > /dev/null 2>&1; then + amvers="`automake --version | sed -e '1s/[^0-9]*//' -e q`" + if expr "$amvers" "<" "1.5" > /dev/null 2>&1; then + amvers="no" + else + amvers="" + fi +fi + +if test "$amvers" = "no"; then + echo "$0: you need automake version 1.5 or later" + exit 1 +fi + +# Check for autoconf +acvers="no" +for v in "" "259" "253"; do + if autoconf${v} --version >/dev/null 2>&1; then + acvers="${v}" + break + fi +done + +if test "$acvers" = "no"; then + echo "$0: you need autoconf" + exit 1 +fi + +# Check for libtool +if test "$libtool" = "yes"; then + libtoolize="no" + if glibtoolize --version >/dev/null 2>&1; then + libtoolize="glibtoolize" + else + for v in "16" "15" "" "14"; do + if libtoolize${v} --version >/dev/null 2>&1; then + libtoolize="libtoolize${v}" + break + fi + done + fi + + if test "$libtoolize" = "no"; then + echo "$0: you need libtool" + exit 1 + fi +fi + +# Check for pkg-config +if test "$pkgconfig" = "yes"; then + if ! pkg-config --version >/dev/null 2>&1; then + echo "$0: you need pkg-config" + exit 1 + fi +fi + +# Remove old cruft +for x in aclocal.m4 configure config.guess config.log config.sub config.cache config.h.in config.h compile libtool.m4 ltoptions.m4 ltsugar.m4 ltversion.m4 ltmain.sh libtool ltconfig missing mkinstalldirs depcomp install-sh; do rm -f $x autotools/$x; if test -n "$auxdir"; then rm -f "$auxdir/$x"; fi; done +rm -Rf autom4te.cache +if test -n "$auxdir"; then + if test ! -d "$auxdir"; then + mkdir "$auxdir" + fi + aclocalflags="${aclocalflags} -I $auxdir -I ." +fi + +# Explain what we are doing from now +set -x + +# Bootstrap package +if test "$libtool" = "yes"; then + ${libtoolize} --copy --force + if test -n "$auxdir" -a ! "$auxdir" = "." -a -f "ltmain.sh"; then + echo "$0: working around a minor libtool issue" + mv ltmain.sh "$auxdir/" + fi +fi + +aclocal${amvers} ${aclocalflags} +autoconf${acvers} +if test "$header" = "yes"; then + autoheader${acvers} +fi +if test "$makefile" = "yes"; then + #add --include-deps if you want to bootstrap with any other compiler than gcc + #automake${amvers} --add-missing --copy --include-deps + automake${amvers} --foreign --add-missing --copy +fi + +# Remove cruft that we no longer want +rm -Rf autom4te.cache + diff --git a/configure.ac b/configure.ac new file mode 100644 index 00000000..6e12e562 --- /dev/null +++ b/configure.ac @@ -0,0 +1,85 @@ +# $Id$ + +AC_INIT(deushax, 0.0) +AC_PREREQ(2.50) +AC_CONFIG_AUX_DIR(.auto) +AC_CANONICAL_SYSTEM +AM_INIT_AUTOMAKE([no-define tar-ustar]) +dnl AM_MAINTAINER_MODE + +AM_CONFIG_HEADER(config.h) + +AM_PROG_CC_C_O +AC_PROG_CPP +AC_PROG_CXX +AC_PROG_CXXCPP +AC_PROG_RANLIB + +AC_LIBTOOL_WIN32_DLL +AM_PROG_LIBTOOL +AC_LIBTOOL_CXX + +AC_C_CONST +AC_C_INLINE + +dnl AC_PROG_EGREP only exists in autoconf 2.54+, so we use AC_EGREP_CPP right +dnl now otherwise it might be set in an obscure if statement. Same thing for +dnl PKG_PROG_PKG_CONFIG which needs to be called first. +AC_EGREP_CPP(yes, foo) +PKG_PROG_PKG_CONFIG() +m4_pattern_allow([^PKG_CONFIG_LIBDIR$]) +if test "${build}" != "${host}" -a "${PKG_CONFIG_LIBDIR}" = ""; then + export PKG_CONFIG_LIBDIR=/dev/null +fi + +dnl conditional builds +AC_ARG_ENABLE(debug, + [ --enable-debug build debug versions of the library (default no)]) + +AC_CHECK_HEADERS(stdio.h stdarg.h inttypes.h endian.h stdint.h getopt.h) + +# Optimizations +CXXFLAGS="${CXXFLAGS} -g -O2 -fno-strength-reduce -fomit-frame-pointer" +# Code qui fait des warnings == code de porc == deux baffes dans ta gueule +CXXFLAGS="${CXXFLAGS} -Wall -Wextra -Wpointer-arith -Wcast-align -Wcast-qual -Wshadow -Wsign-compare" + +AC_CHECK_LIB(m, sin, MATH_LIBS="${MATH_LIBS} -lm") + +# Use SDL? +ac_cv_my_have_sdl="no" +save_CPPFLAGS="${CPPFLAGS}" +AC_PATH_PROG(SDL_CONFIG, sdl-config, no) +if test "${SDL_CONFIG}" != "no"; then + CPPFLAGS="${CPPFLAGS} `sdl-config --cflags`" +fi +AC_CHECK_HEADERS(SDL_image.h, + [ac_cv_my_have_sdl="yes"], + [ac_cv_my_have_sdl="no"]) +CPPFLAGS="${save_CPPFLAGS}" +if test "${ac_cv_my_have_sdl}" != "no"; then + AC_DEFINE(USE_SDL, 1, Define to 1 to use SDL_image) +fi +AM_CONDITIONAL(USE_SDL, test "${ac_cv_my_have_sdl}" = "yes") + +if test "${ac_cv_my_have_sdl}" = "no" -a "${ac_cv_my_have_imlib2}" = "no"; then + AC_MSG_ERROR([[cannot find SDL_Image or GTK+, please install one of them]]) +fi + +if test "${enable_debug}" = "yes"; then + AC_DEFINE(DEBUG, 1, Define to 1 to activate debug) +fi + +AC_SUBST(MATH_LIBS) + +AC_CONFIG_FILES([ + Makefile + src/Makefile + tools/Makefile + art/Makefile + art/test/Makefile + gfx/Makefile + gfx/font/Makefile +]) + +AC_OUTPUT + diff --git a/gfx/Makefile b/gfx/Makefile deleted file mode 100644 index 34d05722..00000000 --- a/gfx/Makefile +++ /dev/null @@ -1,7 +0,0 @@ - -all: - cd font && $(MAKE) all - -clean: - cd font && $(MAKE) clean - diff --git a/gfx/Makefile.am b/gfx/Makefile.am new file mode 100644 index 00000000..f71b1b6c --- /dev/null +++ b/gfx/Makefile.am @@ -0,0 +1,3 @@ + +SUBDIRS = font + diff --git a/gfx/font/Makefile b/gfx/font/Makefile.am similarity index 100% rename from gfx/font/Makefile rename to gfx/font/Makefile.am diff --git a/src/Makefile b/src/Makefile deleted file mode 100644 index 370e9ce5..00000000 --- a/src/Makefile +++ /dev/null @@ -1,21 +0,0 @@ - -COMMON = test-map.cpp \ - game.cpp tiler.cpp tileset.cpp scene.cpp \ - font.cpp layer.cpp map.cpp joystick.cpp -TEST_SRC = test-map.cpp sdlvideo.cpp $(COMMON) -EDITOR_SRC = editor.cpp gtkvideo.cpp $(COMMON) - -all: test-map - -test-map: $(TEST_SRC:%.cpp=%.o) - g++ -g -Wall -O3 $^ -o $@ `pkg-config --libs sdl gl SDL_image` - -editor-map: $(EDITOR_SRC:%.cpp=%.o) - g++ -g -Wall -O3 $^ -o $@ `pkg-config --libs sdl gl SDL_image` - -%.o: %.cpp - g++ -g -Wall -O3 -c $^ -o $@ `pkg-config --cflags sdl gl SDL_image` - -clean: - rm -f *.o test-map - diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 00000000..dc2a8eac --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,41 @@ + +noinst_PROGRAMS = test-map editor + +noinst_LIBRARIES = libcommon.a + +libcommon_a_SOURCES = \ + game.cpp tiler.cpp tileset.cpp scene.cpp \ + font.cpp layer.cpp map.cpp joystick.cpp +libcommon_a_CXXFLAGS = `pkg-config --cflags sdl gl SDL_image` + +test_map_SOURCES = test-map.cpp sdlvideo.cpp +test_map_CXXFLAGS = `pkg-config --cflags sdl gl SDL_image` +test_map_LDADD = libcommon.a +test_map_LDFLAGS = `pkg-config --libs sdl gl SDL_image` + +editor_SOURCES = editor.cpp gtkvideo.cpp +editor_CXXFLAGS = `pkg-config --cflags sdl gl SDL_image gtk+-2.0 gtkgl-2.0` +editor_LDADD = libcommon.a +editor_LDFLAGS = `pkg-config --libs sdl gl gtk+-2.0 gtkgl-2.0 SDL_image` + +#COMMON = $(libcommon_a_SOURCES) +# +#TEST_SRC = test-map.cpp sdlvideo.cpp $(COMMON) +#EDITOR_SRC = editor.cpp gtkvideo.cpp $(COMMON) +# +#CPPFLAGS = `pkg-config --cflags sdl gl SDL_image gtk+-2.0 gtkgl-2.0` +#CXXFLAGS = -g -O3 -Wall \ +# -Wpointer-arith -Wcast-align -Wcast-qual -Wshadow -Wsign-compare +# +#test-map: $(TEST_SRC:%.cpp=%.o) +# g++ $(CXXFLAGS) $^ -o $@ `pkg-config --libs sdl gl SDL_image` +# +#editor: $(EDITOR_SRC:%.cpp=%.o) +# g++ $(CXXFLAGS) $^ -o $@ `pkg-config --libs sdl gl gtk+-2.0 gtkgl-2.0 SDL_image` +# +#%.o: %.cpp +# g++ -c $^ -o $@ $(CXXFLAGS) $(CPPFLAGS) +# +#clean: +# rm -f *.o test-map editor + diff --git a/src/editor.cpp b/src/editor.cpp new file mode 100644 index 00000000..ee94d588 --- /dev/null +++ b/src/editor.cpp @@ -0,0 +1,66 @@ +#include + +#include +#include + +#include "gtkvideo.h" +#include "game.h" + +#include +#include +#include +#include + +volatile int quit = 0; + +static gint main_quit(GtkWidget *widget, GdkEventExpose *event) +{ + quit = 1; + return FALSE; +} + +int main(int argc, char **argv) +{ + GtkWidget *window, *glarea; + + /* initialize gtk */ + gtk_init(&argc, &argv); + + /* Create new top level window. */ + window = gtk_window_new( GTK_WINDOW_TOPLEVEL); + gtk_window_set_title(GTK_WINDOW(window), "Simple"); + gtk_container_set_border_width(GTK_CONTAINER(window), 10); + + /* Quit form main if got delete event */ + gtk_signal_connect(GTK_OBJECT(window), "delete_event", + GTK_SIGNAL_FUNC(main_quit), NULL); + + + /* You should always delete gtk_gl_area widgets before exit or else + GLX contexts are left undeleted, this may cause problems (=core dump) + in some systems. + Destroy method of objects is not automatically called on exit. + You need to manually enable this feature. Do gtk_quit_add_destroy() + for all your top level windows unless you are certain that they get + destroy signal by other means. + */ + gtk_quit_add_destroy(1, GTK_OBJECT(window)); + + + /* Create new OpenGL widget. */ + GtkVideo *video = new GtkVideo("LOL", 640, 480); + glarea = GTK_WIDGET(video->GetWidget()); + + + /* put glarea into window and show it all */ + gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(glarea)); + gtk_widget_show(GTK_WIDGET(glarea)); + gtk_widget_show(GTK_WIDGET(window)); + + while (!quit) + { + while (g_main_context_iteration(NULL, FALSE)); + } + + return 0; +} diff --git a/tools/Makefile b/tools/Makefile.am similarity index 100% rename from tools/Makefile rename to tools/Makefile.am