diff options
author | danieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7> | 2009-09-01 15:04:40 +0000 |
---|---|---|
committer | danieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7> | 2009-09-01 15:04:40 +0000 |
commit | 990e04bab51bf1c3771938b8f598272c1b31cdca (patch) | |
tree | 8b077d8d3326feeb6736f5eb1fa719103a8822d5 | |
parent | 8f8e244f4f350a53a2a84296a66468b7e5ac4a2b (diff) |
Move dependency tracking from ./configure to Makefile
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11556 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r-- | .Makefile.inc | 37 | ||||
-rwxr-xr-x | configure | 69 | ||||
-rw-r--r-- | make/bsd-dep.mk | 10 | ||||
-rw-r--r-- | make/bsd-real.mk | 25 | ||||
-rwxr-xr-x | make/calcdep.pl | 23 | ||||
-rw-r--r-- | make/gnu-dep.mk | 11 | ||||
-rw-r--r-- | make/gnu-real.mk | 32 | ||||
-rwxr-xr-x | make/unit-cc.pl | 31 |
8 files changed, 167 insertions, 71 deletions
diff --git a/.Makefile.inc b/.Makefile.inc index 76c9b01f9..2e9b3e635 100644 --- a/.Makefile.inc +++ b/.Makefile.inc @@ -6,7 +6,9 @@ # Please do not edit unless you know what you're doing. # -@GNU_ONLY COMPILE_ROOT = $(shell pwd) +@GNU_ONLY MAKESTYLE = gnu +@GNU_ONLY COMPILE_ROOT ?= $(shell pwd) +@BSD_ONLY MAKESTYLE = bsd @BSD_ONLY COMPILE_ROOT != pwd @IFDEF D @@ -21,6 +23,7 @@ NICEFLAGS += -I$(COMPILE_ROOT)/include CC = @CC@ FLAGS = $(NICEFLAGS) -pedantic +PICLDFLAGS = -fPIC -DPIC -shared -export-dynamic LDLIBS = @LDLIBS@ BASE = "@BASE_DIR@" CONPATH = "@CONFIG_DIR@" @@ -28,19 +31,20 @@ MODPATH = "@MODULE_DIR@" BINPATH = "@BINARY_DIR@" LAUNCHDPATH = "/System/Library/LaunchDaemons" LIBPATH = "@LIBRARY_DIR@" -MODULES = @MODULES@ INSTMODE = 0755 +SOCKETENGINE = @SOCKETENGINE@ @GNU_ONLY MAKEFLAGS += --no-print-directory @IFDEF V RUNCC = $(CC) + VERBOSE = -v @ELSE @GNU_ONLY MAKEFLAGS += --silent + @BSD_ONLY MAKE += -s RUNCC = $(COMPILE_ROOT)/make/run-cc.pl $(CC) @ENDIF -@GNU_ONLY export COMPILE_ROOT RUNCC FLAGS NICEFLAGS CC LDLIBS MODULES MODPATH LIBPATH INSTMODE -@BSD_ONLY MAKEARGS = -s 'RUNCC=${RUNCC}' 'FLAGS=${FLAGS}' 'NICEFLAGS=${NICEFLAGS}' 'CC=${CC}' 'LDLIBS=${LDLIBS}' 'MODULES=${MODULES}' 'MODPATH=${MODPATH}' 'LIBPATH=${LIBPATH}' 'INSTMODE=${INSTMODE}' +@DO_EXPORT RUNCC FLAGS NICEFLAGS CC LDLIBS PICLDFLAGS VERBOSE SOCKETENGINE # Default target @@ -48,7 +52,15 @@ INSTMODE = 0755 _all: module @ENDIF -all: ircd mods finishmessage +all: finishmessage + +alldep: $(HEADER) + @echo -n "Generating module dependencies..." + @$(MAKEENV) $(MAKE) -C src -f ../make/$(MAKESTYLE)-dep.mk all + @echo 'done' + +allreal: alldep + @$(MAKEENV) $(MAKE) -C src -f ../make/$(MAKESTYLE)-real.mk all debug: @${MAKE} D=1 all @@ -77,14 +89,7 @@ std-header: @echo "* while you wait for make to run? *" @echo "*************************************" -ircd: $(HEADER) - @${MAKE} -C src $(MAKEARGS) inspircd commands - -mods: $(HEADER) - @${MAKE} -C src/modules $(MAKEARGS) - -# Make this depend on 'ircd' and 'mods', so its always output last even with -j -finishmessage: ircd mods +finishmessage: allreal @echo "" @echo "*************************************" @echo "* BUILD COMPLETE! *" @@ -93,14 +98,15 @@ finishmessage: ircd mods @echo "* make install *" @echo "*************************************" -install: ircd mods@EXTRA_DIR@ +install: allreal@EXTRA_DIR@ @-install -d -m $(INSTMODE) $(BASE) @-install -d -m $(INSTMODE) $(LIBPATH) @-install -d -m $(INSTMODE) $(BINPATH) @-install -d -m $(INSTMODE) $(CONPATH) @-install -d -m $(INSTMODE) $(MODPATH) -install -m $(INSTMODE) @STARTSCRIPT@ $(@DESTINATION@) 2>/dev/null -@INSTALL_LIST@ @echo "" +@INSTALL_LIST@ -install -m $(INSTMODE) src/inspircd $(BINPATH) + @echo "" @echo "*************************************" @echo "* INSTALL COMPLETE! *" @echo "* *" @@ -128,6 +134,7 @@ modclean: rm -f src/modules/*/*.o deinstall: + -rm $(BINPATH)/inspircd @UNINSTALL_LIST@ squeakyclean: distclean @@ -1131,7 +1131,6 @@ my ($mliflags, $mfrules, $mobjs, $mfcount) = ("", "", "", 0); sub writefiles { my($writeheader) = @_; - my $se = ""; # First File.. inspircd_config.h chomp(my $incos = `uname -n -s -r`); chomp(my $version = `sh src/version.sh`); @@ -1196,17 +1195,17 @@ print FILEHANDLE "#define MAXBUF " . ($config{MAXBUF}+2) . "\n"; my $use_hiperf = 0; if (($has_kqueue) && ($config{USE_KQUEUE} eq "y")) { print FILEHANDLE "#define USE_KQUEUE\n"; - $se = "socketengine_kqueue"; + $config{SOCKETENGINE} = "socketengine_kqueue"; $use_hiperf = 1; } if (($has_epoll) && ($config{USE_EPOLL} eq "y")) { print FILEHANDLE "#define USE_EPOLL\n"; - $se = "socketengine_epoll"; + $config{SOCKETENGINE} = "socketengine_epoll"; $use_hiperf = 1; } if (($has_ports) && ($config{USE_PORTS} eq "y")) { print FILEHANDLE "#define USE_PORTS\n"; - $se = "socketengine_ports"; + $config{SOCKETENGINE} = "socketengine_ports"; $use_hiperf = 1; } # user didn't choose either epoll or select for their OS. @@ -1216,12 +1215,12 @@ print FILEHANDLE "#define MAXBUF " . ($config{MAXBUF}+2) . "\n"; if ($config{USE_POLL} eq "y") { print FILEHANDLE "#define USE_POLL\n"; - $se = "socketengine_poll"; + $config{SOCKETENGINE} = "socketengine_poll"; } else { print FILEHANDLE "#define USE_SELECT\n"; - $se = "socketengine_select"; + $config{SOCKETENGINE} = "socketengine_select"; } } print FILEHANDLE "\n#include \"threadengines/threadengine_pthread.h\"\n\n#endif\n"; @@ -1236,7 +1235,7 @@ print FILEHANDLE "#define MAXBUF " . ($config{MAXBUF}+2) . "\n"; #ifndef __CONFIGURATION_SOCKETENGINE__ #define __CONFIGURATION_SOCKETENGINE__ -#include "socketengines/$se.h" +#include "socketengines/$config{SOCKETENGINE}.h" #endif EOF @@ -1303,11 +1302,10 @@ EOF print "Writing \e[1;32m$file\e[0m ...\n"; for my $var (qw( CC FLAGS DEVELOPER LDLIBS BASE_DIR CONFIG_DIR MODULE_DIR BINARY_DIR LIBRARY_DIR - STARTSCRIPT DESTINATION EXTRA_DIR + STARTSCRIPT DESTINATION EXTRA_DIR SOCKETENGINE )) { s/\@$var\@/$config{$var}/g; } - s/\@MODULES\@/$modules/ if defined $modules; s/\@EXECUTABLE\@/$exe/ if defined $exe; s/\@VERSION\@/$version/ if defined $version; s/\@INSTALL_LIST\@/$install_list/ if defined $install_list; @@ -1319,8 +1317,9 @@ EOF s/\@IFNDEF (\S+)/ifndef $1/g; s/\@ELSE/else/g; s/\@ENDIF/endif/g; - s/\@BSD_ONLY .*\n//g; + s/ *\@BSD_ONLY .*\n//g; s/\@GNU_ONLY //g; + s/\@DO_EXPORT (.*)/export $1/g; open MKF, '>GNUmakefile' or die "Can't write to GNUmakefile: $!"; print MKF $_; close MKF; @@ -1330,9 +1329,11 @@ EOF s/\@ELSE/.else/g; s/\@ENDIF/.endif/g; s/\@BSD_ONLY //g; - s/\@GNU_ONLY .*\n//g; + s/ *\@GNU_ONLY .*\n//g; + $mk_tmp = $_; + $mk_tmp =~ s#\@DO_EXPORT (.*)#"MAKEENV += ".join ' ', map "$_='\${$_}'", split /\s/, $1#eg; open MKF, '>BSDmakefile' or die "Can't write to BSDmakefile: $!"; - print MKF $_; + print MKF $mk_tmp; close MKF; } else { open(FILEHANDLE, ">$file") or die("Can't write to $file: $!\n"); @@ -1575,50 +1576,6 @@ sub write_dynamic_makefile $core_files_list{$name} = 1; } } - elsif ($line =~ /\/\* \$ExtraDeps: (.*?) \*\//i) - { - $specialdeps{$name} = $1; - } - elsif ($line =~ /\/\* \$ExtraObjects: (.*?) \*\//i) - { - $extraobjects{$name} = $1; - } - elsif ($line =~ /\/\* \$ExtraBuild: (.*?) \*\//i) - { - $extrabuildlines{$name} = $1; - } - elsif ($line =~ /\/\* \$ExtraSources: (.*?) \*\//i) - { - $extrasources{$name} = $1; - } - elsif ($line =~ /\/\* \$If: (\w+) \*\//i) - { - if (defined $config{$1}) - { - if (($config{$1} !~ /y/i) and ($config{$1} ne "1")) - { - # Skip to 'endif' - while (defined($line = <CPP>)) - { - chomp($line); - die ("\$If buildsystem instruction within another \$If in file $dir/$name") if ($line =~ /\/\* \$If: (\w+) \*\//i); - last if ($line =~ /\/\* \$EndIf \*\//i); - } - } - } - } - elsif ($line =~ /\/\* \$Install: (.*?) \*\//i) - { - if (!exists($existing_install_list{$1})) - { - $existing_install_list{$1} = 1; - my $idir = (split(' ',$1))[1]; - my $ifile = (split(' ',$1))[0]; - $install_list = $install_list . " -install -m \$(INSTMODE) $1\n"; - $ifile =~ s/.*\///g; - $uninstall_list = $uninstall_list . " -rm $idir/$ifile\n"; - } - } elsif ($line =~ /\/\* \$CopyInstall: (.*?) \*\//i) { if (!exists($existing_install_list{$1})) diff --git a/make/bsd-dep.mk b/make/bsd-dep.mk new file mode 100644 index 000000000..5fe31e89f --- /dev/null +++ b/make/bsd-dep.mk @@ -0,0 +1,10 @@ +DFILES != perl -e 'print join " ", grep s/\.cpp/.d/, <*.cpp>, <commands/*.cpp>, <modes/*.cpp>, <modules/*.cpp>' +DFILES += socketengines/$(SOCKETENGINE).d threadengines/threadengine_pthread.d + +all: $(DFILES) + +.SUFFIXES: .d .cpp + +.cpp.d: + @../make/calcdep.pl $< + @echo -n . diff --git a/make/bsd-real.mk b/make/bsd-real.mk new file mode 100644 index 000000000..ea3e1482c --- /dev/null +++ b/make/bsd-real.mk @@ -0,0 +1,25 @@ +CORE_TARGS != perl -e 'print join " ", grep s/\.cpp/.o/, <*.cpp>' +MODE_TARGS != perl -e 'print join " ", grep s/\.cpp/.o/, <modes/*.cpp>' +CMD_TARGS != perl -e 'print join " ", grep s/\.cpp/.so/, <commands/*.cpp>' +MOD_TARGS != perl -e 'print join " ", grep s/\.cpp/.so/, <modules/*.cpp>' +CORE_TARGS += modeclasses.a threadengines/threadengine_pthread.o +CORE_TARGS += socketengines/$(SOCKETENGINE).o + +DFILES != perl -e 'print join " ", grep s/\.cpp/.d/, <*.cpp>, <commands/*.cpp>, <modes/*.cpp>, <modules/*.cpp>' +DFILES += socketengines/$(SOCKETENGINE).d threadengines/threadengine_pthread.d + +all: inspircd commands modules + +commands: $(CMD_TARGS) + +modules: $(MOD_TARGS) + +modeclasses.a: $(MODE_TARGS) + @../make/run-cc.pl ar crs modeclasses.a $(MODE_TARGS) + +inspircd: $(CORE_TARGS) + $(RUNCC) $(FLAGS) -rdynamic -L. -o inspircd $(LDLIBS) $(CORE_TARGS) + +.for FILE in $(DFILES) +.include "$(FILE)" +.endfor diff --git a/make/calcdep.pl b/make/calcdep.pl new file mode 100755 index 000000000..2b6742be3 --- /dev/null +++ b/make/calcdep.pl @@ -0,0 +1,23 @@ +#!/usr/bin/perl +use strict; +BEGIN { push @INC, '..'; } +use make::configure; + +my $file = shift; + +$file =~ /(.*)\.cpp$/ or die "Cannot process $file"; +my $base = $1; + +my $out = "$base.d"; + +open IN, '<', $file or die "Could not read $file: $!"; +open OUT, '>', $out or die "Could not write $out: $!"; + +my $cc_deps = qx($ENV{CC} $ENV{FLAGS} -MM $file); +$cc_deps =~ s/.*?:\s*//; + +my $ext = $file =~ m#(modules|commands)/# ? '.so' : '.o'; +print OUT "$base$ext: $cc_deps"; +print OUT "\t@../make/unit-cc.pl \$(VERBOSE) $file $base$ext\n"; +print OUT "$base.d: $cc_deps"; +print OUT "\t../make/calcdep.pl $file\n"; diff --git a/make/gnu-dep.mk b/make/gnu-dep.mk new file mode 100644 index 000000000..e8c70c0cd --- /dev/null +++ b/make/gnu-dep.mk @@ -0,0 +1,11 @@ +DFILES = $(patsubst %.cpp,%.d,$(wildcard *.cpp)) +DFILES += $(patsubst %.cpp,%.d,$(wildcard commands/*.cpp)) +DFILES += $(patsubst %.cpp,%.d,$(wildcard modes/*.cpp)) +DFILES += $(patsubst %.cpp,%.d,$(wildcard modules/*.cpp)) +DFILES += socketengines/$(SOCKETENGINE).d threadengines/threadengine_pthread.d + +all: $(DFILES) + +%.d: %.cpp + @../make/calcdep.pl $< + @echo -n . diff --git a/make/gnu-real.mk b/make/gnu-real.mk new file mode 100644 index 000000000..263467038 --- /dev/null +++ b/make/gnu-real.mk @@ -0,0 +1,32 @@ +CORE_TARGS = $(patsubst %.cpp,%.o,$(wildcard *.cpp)) +MODE_TARGS = $(patsubst %.cpp,%.o,$(wildcard modes/*.cpp)) +CMD_TARGS = $(patsubst %.cpp,%.so,$(wildcard commands/*.cpp)) +MOD_TARGS = $(patsubst %.cpp,%.so,$(wildcard modules/*.cpp)) + +CORE_TARGS += modeclasses.a threadengines/threadengine_pthread.o +CORE_TARGS += socketengines/$(SOCKETENGINE).o + +DFILES = $(patsubst %.cpp,%.d,$(wildcard *.cpp)) +DFILES += $(patsubst %.cpp,%.d,$(wildcard commands/*.cpp)) +DFILES += $(patsubst %.cpp,%.d,$(wildcard modes/*.cpp)) +DFILES += $(patsubst %.cpp,%.d,$(wildcard modules/*.cpp)) +DFILES += socketengines/$(SOCKETENGINE).d threadengines/threadengine_pthread.d + +all: inspircd commands modules + +commands: $(CMD_TARGS) + +modules: $(MOD_TARGS) + +modeclasses.a: $(MODE_TARGS) + @../make/run-cc.pl ar crs modeclasses.a $(MODE_TARGS) + +inspircd: $(CORE_TARGS) + $(RUNCC) $(FLAGS) -rdynamic -L. -o inspircd $(LDLIBS) $(CORE_TARGS) + +%.d: %.cpp + @../make/calcdep.pl $< + +.PHONY: all commands modules + +-include $(DFILES) diff --git a/make/unit-cc.pl b/make/unit-cc.pl new file mode 100755 index 000000000..5110037ac --- /dev/null +++ b/make/unit-cc.pl @@ -0,0 +1,31 @@ +#!/usr/bin/perl +use strict; +use warnings; +BEGIN { push @INC, '..'; } +use make::configure; + +my $file = shift; +my $verbose; + +if ($file =~ /^-/) { + $_ = $file; + $file = shift; + $verbose = /v/; +} + +my $out = shift; + +my $cflags = nopedantic($file) ? $ENV{NICEFLAGS} : $ENV{FLAGS}; +$cflags .= ' ' . getcompilerflags($file); + +my $flags; +if ($out =~ /\.so$/) { + $flags = join ' ', $cflags, $ENV{PICLDFLAGS}, getlinkerflags($file); +} else { + $flags = "$cflags -c"; +} + +my $execstr = "$ENV{RUNCC} $flags -o $out $file"; +print "$execstr\n" if $verbose; +exec $execstr; +exit 1; |