Skip to content

Commit

Permalink
- experimental make cfg /config support: make cfg fore regeneration o…
Browse files Browse the repository at this point in the history
…f the

 "build" config, saved in config.mak. This config is used instead of
 including Makefile.defs each time. The config is also automatically
 generated if missing. The speed improvements are dramatic in most cases:
  make proper 15 times faster, make clean 8 times, make with generated
  config 2.6 times faster then before, make rebuilding only one file 9 times
  faster.
  E.g.: make cfg include_modules=mysql CPU=pentium-m BASEDIR=/tmp/ser
        make install  # builds default ser + mysql, optimized for pentium-m
                      # and installs in /tmp/ser/usr/local/*
        make clean    # cleans default modules + mysql
  • Loading branch information
poandrei committed Jun 28, 2008
1 parent 0bfa3ff commit 7742b1d
Show file tree
Hide file tree
Showing 9 changed files with 273 additions and 79 deletions.
35 changes: 34 additions & 1 deletion INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,27 @@ make mode=debug PROFILE=-pg all

make modules=modules/print modules

- compile by default only the print module, in debuging mode and with
profiling:

make cfg modules=modules/print mode=debug PROFILE=-pg
make all

- compile by default all the usual modules + mysql and postgres, optimized
for pentium-m and for space

make cfg include_modules="mysql postgres" CPU=pentium-m CC_EXTRA_OPTS=-Os
make all

-compile all the "default" modules except textops and vm

make skip_modules="textops vm" modules

- save the above option in the make config, so that all make commands
will use it by default:

make cfg skip_modules="textops vm"

-compile all default modules and include uri_radius (not compiled by default):

make include_modules="uri_radius" modules
Expand Down Expand Up @@ -290,17 +307,32 @@ CC=gcc-3.2 make all

Make targets:

Configure:

make cfg or make config (force config regeneration and store it in config.mak)

Example: make cfg include_modules=mysql mode=debug (all future make
invocations will include the mysql module and will build in debug mode)

Note: if config.mak doesn't exist (e.g. initial checkout or after a make
proper) or if Makefile.defs was changed, the config will be re-generated
automatically by the first make command. For example:
make cfg include_modules=mysql; make all is equivalent to
rm config.mak; make include_modules=mysql.


Clean:

make clean (clean the modules too)
make proper (clean also the dependencies)
make proper (clean also the dependencies and the config)
make distclean (the same as proper)
make mantainer-clean (clean everything, including auto generated files,
tags, *.dbg a.s.o)

Compile:

make proper
optional: make cfg <various cfg. options that should be saved>
make
(or gmake on non-Linux systems)
make modules
Expand Down Expand Up @@ -368,6 +400,7 @@ in make all and /usr/local is the default value of prefix).
Workaround is trivial, use the same parameters in all make commands:
make prefix=/ all
make prefix=/ install
or save the desired prefix in the make config (e.g.: make cfg prefix=/).

That applies to other make parameters as well (for example parameters
"modules" or "excluded_modules").
Expand Down
109 changes: 91 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@
# 2007-03-29 install-modules changed to use make -C modpath install (andrei)
# 2007-05-04 "if ! foo" not supported in standard sh, switched to
# "if foo; then :; else ... ; fi" (andrei)
# 2008-06-23 added 2 new targets: README and man (re-generate the README
# 2008-06-23 added 2 new targets: README and man (re-generate the README
# or manpages for all the modules) (andrei)
# 2008-06-25 make cfg support (use a pre-built cfg.: config.mak) (andrei)

auto_gen=lex.yy.c cfg.tab.c #lexx, yacc etc
auto_gen_others=cfg.tab.h # auto generated, non-c
Expand Down Expand Up @@ -183,6 +184,38 @@ endif
# the rest is excluded because it depends on external libraries
#
static_modules=

ALLDEP=config.mak Makefile Makefile.sources Makefile.rules

#include general defs (like CC, CFLAGS a.s.o)
# hack to force makefile.defs re-inclusion (needed when make calls itself with
# other options -- e.g. make bin)
#makefile_defs=0
#DEFS:=


# try saved cfg, unless we are in the process of building it
ifeq (,$(filter config.mak config cfg,$(MAKECMDGOALS)))
include config.mak
ifeq ($(makefile_defs),1)
$(info config.mak loaded)
# config_make valid & used
config_mak=1
endif
else
ifneq (,$(filter cfg config,$(word 1,$(MAKECMDGOALS))))
# needed here to avoid starting a config submake
# (e.g. rm -f config.mak; make config.mak), which would either require
# double Makefile.defs defines execution (suboptimal), would loose
# $(value ...) expansion or would cause some warning (if Makefile.defs exec.
# is skipped in the "main" makefile invocation).
$(shell rm -rf config.mak)
endif
endif

main_makefile=1
include Makefile.defs

static_modules_path=$(addprefix modules/, $(static_modules))
extra_sources=$(wildcard $(addsuffix /*.c, $(static_modules_path)))
extra_objs=$(extra_sources:.c=.o)
Expand All @@ -197,24 +230,27 @@ export extra_defs
# include_modules
# When group_include is used, we want: include_modules (based on group_include)
# - exclude_modules

ifneq ($(modules_configured),1)
ifneq ($(group_include),)
modules=$(filter-out $(addprefix modules/, \
$(exclude_modules) $(static_modules)), \
$(addprefix modules/, $(include_modules) ))
else
# Standard, old resultant set
modules=$(filter-out $(addprefix modules/, \
$(exclude_modules) $(static_modules)), \
$(wildcard modules/*))
modules:=$(filter-out $(modules), $(addprefix modules/, $(include_modules) )) \
$(modules)
endif
modules_all=$(filter-out CVS, $(wildcard modules/*))
modules_noinc=$(filter-out $(addprefix modules/, \
$(exclude_modules) $(static_modules)), $(modules_all))
modules=$(filter-out $(modules_noinc), \
$(addprefix modules/, $(include_modules) )) $(modules_noinc)
endif # ifneq($(group_include),)
endif # ifneq($(modules_configured),1)
modules_names=$(shell echo $(modules)| \
sed -e 's/modules\/\([^/ ]*\)\/*/\1.so/g' )
modules_basenames=$(shell echo $(modules)| \
sed -e 's/modules\/\([^/ ]*\)\/*/\1/g' )
#modules_names=$(patsubst modules/%, %.so, $(modules))
modules_full_path=$(join $(modules), $(addprefix /, $(modules_names)))
#modules_full_path=$(join $(modules), $(addprefix /, $(modules_names)))


# which utils need compilation (directory path) and which to install
Expand All @@ -230,14 +266,6 @@ share_install= scripts/mysql/my_create.sql \
scripts/mysql/my_drop.sql


ALLDEP=Makefile Makefile.sources Makefile.defs Makefile.rules

#include general defs (like CC, CFLAGS a.s.o)
# hack to force makefile.defs re-inclusion (needed when make calls itself with
# other options -- e.g. make bin)
makefile_defs=0
DEFS:=
include Makefile.defs

NAME=$(MAIN_NAME)

Expand All @@ -262,6 +290,7 @@ ifneq ($(TLS),)
endif

# include the common rules
include Makefile.targets
include Makefile.rules

#extra targets
Expand All @@ -274,12 +303,50 @@ lex.yy.c: cfg.lex cfg.tab.h $(ALLDEP)
cfg.tab.c cfg.tab.h: cfg.y $(ALLDEP)
$(YACC) $(YACC_FLAGS) $<

ifeq ($(config_mak),1)

COREPATH=.
include Makefile.cfg

else
include Makefile.shared

config.mak: Makefile.defs
@echo making config...
@echo "# this file is autogenerated by make cfg" >$@
@echo "# `date`" >>$@
@$(call mapf2,cfg_save_var,saved_fixed_vars,$(@))
@$(call mapf2,cfg_save_var2,saved_chg_vars,$(@))
@echo "override makefile_defs:=1" >>$@
@$(call cfg_save_var2,group_include,$@)
@$(call cfg_save_var2,include_modules,$@)
@$(call cfg_save_var2,static_modules,$@)
@$(call cfg_save_var2,skip_modules,$@)
@$(call cfg_save_var2,exclude_modules,$@)
@$(call cfg_save_var2,modules_all,$@)
@$(call cfg_save_var2,modules_noinc,$@)
@$(call cfg_save_var2,modules,$@)
@echo "modules_configured:=1" >>$@
@echo "DEFS:=\$$(filter-out \$$(DEFS_RM) \$$(extra_defs),\$$(DEFS))" \
"\$$(extra_defs)" >>$@
@echo "CFLAGS:=\$$(filter-out \$$(CFLAGS_RM) \$$(CC_EXTRA_OPTS)," \
"\$$(CFLAGS)) \$$(CC_EXTRA_OPTS)" >>$@

endif # ifeq ($(config_mak),1)

.PHONY: cfg config
cfg config: config.mak

#rm -f config.mak
#$(MAKE) config.mak exported_vars=0

.PHONY: all
all: $(NAME) modules

.PHONY: print-modules
print-modules:
@echo The following modules was chosen to be included: $(include_modules) ; \
@echo The following modules were chosen to be included: \
$(include_modules) ; \
echo ---------------------------------------------------------- ; \
echo The following modules will be excluded: $(exclude_modules) ; \
echo ---------------------------------------------------------- ; \
Expand Down Expand Up @@ -349,6 +416,7 @@ tar:
--exclude=librpath.lst \
--exclude=libiname.lst \
--exclude=makecfg.lst \
--exclude=config.mak \
--exclude=*.[do] \
--exclude=*.so \
--exclude=*.il \
Expand Down Expand Up @@ -516,7 +584,6 @@ install-bin: $(bin_prefix)/$(bin_dir) $(NAME)
$(INSTALL_TOUCH) $(bin_prefix)/$(bin_dir)/$(NAME)
$(INSTALL_BIN) $(NAME) $(bin_prefix)/$(bin_dir)

export INSTALL_TOUCH RELEASE

install-share: $(share_prefix)/$(share_dir)
@for r in $(share_install) "" ; do \
Expand Down Expand Up @@ -638,3 +705,9 @@ clean_libs:
# cleaning in libs always when cleaning ser
clean: clean_libs

proper realclean distclean: clean_cfg

.PHONY: clean_cfg
clean_cfg:
rm -f config.mak

Loading

0 comments on commit 7742b1d

Please sign in to comment.