From b95d88a5c4f229a93dab7cad2e0f69d4cd2af42b Mon Sep 17 00:00:00 2001 From: Daniel Collins Date: Sun, 21 Oct 2012 12:08:31 +0000 Subject: [PATCH] Generate header dependencies on the fly using gcc -MM. --- Makefile | 22 ++++++++++++++++++---- mkdeps.pl | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 mkdeps.pl diff --git a/Makefile b/Makefile index b6516bf..b2bae55 100644 --- a/Makefile +++ b/Makefile @@ -20,9 +20,16 @@ else DBG_OPT := -Wl,-s endif -CFLAGS := -Wall -D_WIN32_WINNT=0x0500 $(DBG_OPT) -I./include/ +CFLAGS := -Wall -D_WIN32_WINNT=0x0500 $(DBG_OPT) -I./include/ CXXFLAGS := $(CFLAGS) +# Used by mkdeps.pl +# +export CC +export CFLAGS +export CXX +export CXXFLAGS + VERSION := r$(shell svn info | grep Revision | sed -e 's/.*: //') IPXWRAPPER_DEPS := src/ipxwrapper.o src/winsock.o src/ipxwrapper_stubs.o src/log.o src/common.o \ @@ -43,7 +50,7 @@ all: ipxwrapper.dll wsock32.dll mswsock.dll ipxconfig.exe dpwsockx.dll ipxrouter clean: rm -f ipxwrapper.dll wsock32.dll mswsock.dll ipxconfig.exe dpwsockx.dll ipxrouter.exe - rm -f src/*.o src/*_stubs.s version.o + rm -f src/*.o src/*_stubs.s version.o Makefile.dep dist: all mkdir ipxwrapper-$(VERSION) @@ -57,7 +64,14 @@ dist: all rm -r ipxwrapper-$(VERSION)-src/ .SECONDARY: -.PHONY: all clean dist +.PHONY: all clean dist depend + +depend: Makefile.dep + +Makefile.dep: src/*.c src/*.cpp + perl mkdeps.pl + +-include Makefile.dep ipxwrapper.dll: $(IPXWRAPPER_DEPS) echo 'const char *version_string = "$(VERSION)", *compile_time = "'`date`'";' | $(CC) -c -x c -o version.o - @@ -93,5 +107,5 @@ icons/%.o: icons/%.rc icons/%.ico src/%_stubs.o: src/%_stubs.s nasm -f win32 -o $@ $< -src/%.o: src/%.c src/ipxwrapper.h src/config.h src/common.h src/router.h +src/%.o: src/%.c $(CC) $(CFLAGS) -c -o $@ $< diff --git a/mkdeps.pl b/mkdeps.pl new file mode 100644 index 0000000..8cbb723 --- /dev/null +++ b/mkdeps.pl @@ -0,0 +1,34 @@ +# IPXWrapper - Generate Make dependencies +# Copyright (C) 2012 Daniel Collins +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License version 2 as published by +# the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., 51 +# Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +use strict; +use warnings; + +my $cc = $ENV{CC}; +my $cflags = $ENV{CFLAGS}; +my $cxx = $ENV{CXX}; +my $cxxflags = $ENV{CXXFLAGS}; + +open(my $depends, ">Makefile.dep") or die("Cannot open Makefile.dep: $!"); + +foreach my $cmd((map { "$cc $cflags -MM $_" } glob("src/*.c")), (map { "$cxx $cxxflags -MM $_" } glob("src/*.cpp"))) +{ + print "mkdeps.pl: $cmd\n"; + + print {$depends} "src/".qx($cmd)."\n"; +} + +close($depends);