# This is a basic makefile that uses a flat directory structure. It could be # expanded to support multiple subdirectories and/or libraries # # Compilers to use CC=gcc CPP=g++ AR=ar RANLIB=ranlib ECHOEN=echo -en OIDL2=/opt/gnome/bin/orbit-idl-2 LEX=flex # Flags for the compilers # # Think about those as additionals : # -fvtable-gc # -ffunction-sections # -Wl,--gc-sections # -frepo # CFLAGS= -pipe -Wall -g -O3 -ffast-math CPPFLAGS= -pipe -g -Wall #-O3 -march=pentium4 -mcpu=pentium4 -mfpmath=sse,387 -ffast-math -O3 #-march=pentium4 -mcpu=pentium4 # -fstack-check -fmudflap #-fmudflapth -fmudflapir #-ansi -pedantic #-W #CPPFLAGS= -pipe -Wall -g -ffast-math -O3 -march=pentium4 -mcpu=pentium4 #-mtune=pentium4 # // How can we do this better ? ifneq ($(MAKECMDGOALS),steril) ifneq ($(MAKECMDGOALS),mrproper) ifneq ($(MAKECMDGOALS),clean) ifneq ($(MAKECMDGOALS),distclean) ifneq ($(MAKECMDGOALS),dist) ifneq ($(MAKECMDGOALS),link) ifneq ($(MAKECMDGOALS),links) ifneq ($(NO_DEP_NEEDED),yes) # include dependencies files if it exists -include .depend endif endif endif endif endif endif endif endif # include generated configuration -include $(TOPDIR)/makefile.conf # Flags for the linker CPPLDFLAGS=$(LIBLIBS) $(LIBFLAGS) # Those need the stuff from makefile.conf BINDIR=$(PREFIX)/bin/ SHAREDIR=$(PREFIX)/share/ DOCDIR=$(SHAREDIR)/doc/packages/$(DISTDIR) LIBDIR=$(PREFIX)/lib/ INCDIR=$(PREFIX)/include/ LIB=$(LIBNAME).$(DYN_SUFFIX).$(LIBVERSION) STATLIB=$(LIBNAME).a # Where do we search for libfiles ? LIBINCLUDE=-L$(LIBDIR) -L$(LIBSEARCH) # Where do we search for include files ? INCLUDE=-I . -I $(PREFIX)/include/ $(INCLUDES) -I ./idl DEPFLAG=-MM $(INCLUDE) -I ./include # For displaying purposes #ESC=`echo -en "\033"` ESC=`$(ECHOEN) "\033"` RED="$(ESC)[1;31m" GRN="$(ESC)[1;32m" YEL="$(ESC)[1;33m" BLU="$(ESC)[1;34m" VIO="$(ESC)[1;35m" TUK="$(ESC)[1;36m" WHT="$(ESC)[1;37m" NOR="$(ESC)[m" STERILFILES?=nix STERILDIR?=nix EXTRACLEANFILES?=nix SUBDIR=$(notdir $(PWD)) SUBLIBFILES=$(LIBFILES_$(SUBDIR)) SUBLIBNAME=lib-$(SUBDIR).a SUBLIBFILES=$(foreach subdir,$(SRCDIRS), $(foreach file,$(LIBFILES_$(notdir $(subdir))),$(subdir)/$(file))) SUBLIBBASE=$(basename $(wildcard $(SUBLIBFILES))) SUBLIBFILES=$(foreach subdir,$(SRCDIRS), $(foreach file,$(LIBFILES_$(notdir $(subdir))),$(subdir)/$(file))) #SUBLIBCPPS=$(addsuffix .cpp, $(SUBLIBBASE)) SRCFILES=$(foreach subdir,$(SRCDIRS), $(wildcard $(subdir)/*.cpp)) SUBLIBS=$(foreach subdir,$(SRCDIRS),$(subdir)/lib-$(notdir $(subdir)).a) $(TOPDIR)/makefile.conf: @echo $(RED)You need to run $(TOPDIR)/configure before starting compilation$(NOR) @exit 1 ifeq ($(ROOTDIR),true) lib libs: $(TOPDIR)/lib/$(LIB) $(TOPDIR)/lib/$(STATLIB) $(TOPDIR)/lib/$(LIB): $(SUBLIBFILES) @echo $(BLU)[LD]$(NOR) $(LIB) @$(CPP) $(LIBINCLUDE) $(CPPLDFLAGS)$(LIB) $(SUBLIBFILES) -o $(TOPDIR)/lib/$(LIB) $(TOPDIR)/lib/$(STATLIB): $(SUBLIBFILES) @echo $(BLU)[AR]$(NOR) $(STATLIB) @$(AR) r $(TOPDIR)/lib/$(STATLIB) $(SUBLIBFILES) @$(RANLIB) $(TOPDIR)/lib/$(STATLIB) trans: @make -C $(TRANSDIR) trans merge: @make -C $(TRANSDIR) merge extract: @echo $(YEL)[XGETTEXT]$(NOR) $(SRCFILES) @xgettext --omit-header -C -n -ktrans include/*.h $(SRCFILES) -j -o $(TRANSDIR)/$(TRANSTEMPLATE) endif $(LIBDIR): @echo $(BLU)[MKDIR]$(NOR) $@ @mkdir -p $@ $(INCDIR): @echo $(BLU)[MKDIR]$(NOR) $@ @mkdir -p $@ clean: @echo $(VIO)[CLEAN]$(NOR) $(PWD) @for dir in $(SRCDIRS); do \ (rm -f *.o .depend* $$dir/*.moc.cpp $$dir/*.o $$dir/.depend* $$dir/$(EXTRACLEANFILES)) \ done distclean: steril @echo $(VIO)[DISTCLEAN]$(NOR) $(PWD) @rm -f *.tar.bz2 @rm -f *.tar @rm -f *.tar.rk mrproper steril: clean @echo $(VIO)[STERIL]$(NOR) $(PWD) @rm -rf $(STERILDIRS) @rm -f $(STERILFILES) @for dir in $(SRCDIRS); do \ (rm -f *.a *.s $$dir/*.a $$dir/*.s *.log *.tag) \ done .PHONY: doku docs doc doku docs doc: @rm -f doxygen.log @echo $(BLU)[DOXYGEN]$(NOR) doxygen.conf \> doxygen.log @$(DOXYGEN) doxygen.conf &> doxygen.log # Generic targets for .o files %.o:%.cpp @echo $(TUK)[CPP]$(NOR) $*.o @$(CPP) $(CPPFLAGS) $(INCLUDE) -c $*.cpp -o $*.o %.o:%.cc @echo $(TUK)[CPP]$(NOR) $*.o @$(CPP) $(CPPFLAGS) $(INCLUDE) -c $*.cc -o $*.o %.s:%.cpp @echo $(RED)[CPP -S]$(NOR) $*.s @$(CPP) $(CPPFLAGS) -S $(INCLUDE) -c $*.cpp -o $*.s %.s:%.c @echo $(RED)[CC -S]$(NOR) $*.s @$(CC) $(CFLAGS) -S $(INCLUDE) -c $*.c -o $*.s %.o:%.c @echo $(YEL)[CC]$(NOR) $*.o @$(CC) $(CFLAGS) $(INCLUDE) -c $*.c -o $*.o %.pp:%.cpp @echo $(RED)[CC]$(NOR) $*.o @$(CPP) $(CPPFLAGS) $(INCLUDE) -E -dD -c $*.cpp -o $*.pp %.cc:%.lex $(LEX) -f -o$*.cc $*.lex %.tab.h:%.y $(YACC) -d $*.y .SECONDARY:$(wildcard */*.moc.cpp) define MOC_TEMPLATE $(1)/%.moc.cpp:include/%.h @echo $$(TUK)[MOC]$$(NOR) $$^ @$$(MOC) $$^ > $$@ endef $(foreach dir,$(SRCDIRS), $(eval $(call MOC_TEMPLATE,$(dir)))) ifneq ($(ROOTDIR),true) sublib: $(SUBLIBFILES) @echo $(BLU)[AR]$(NOR) $(SUBLIBNAME) @$(AR) r $(SUBLIBNAME) $(SUBLIBFILES) @$(AR) s $(SUBLIBNAME) dep depend .depend: @echo $(TUK)[CPP -M]$(NOR) \*.cpp @test `(ls -1 *.cpp 2>/dev/null | head -1)` && $(CPP) $(DEPFLAG) *.cpp > .depend 2> .depend.err || touch .depend @echo $(YEL)[CC -M]$(NOR) \*.c @test `(ls -1 *.c 2>/dev/null | head -1)` && $(CC) $(DEPFLAG) *.c >> .depend 2>> .depend.err || touch .depend @echo -n $(RED)[CHECK]$(NOR) .depend.err" " @(test -s .depend.err && echo [$(RED)ERROR$(NOR)]) || echo [$(GRN)OK$(NOR)] else depend dep .depend: @echo $(VIO)[MAKE]$(NOR) $(SRCDIR) @for dir in $(SRCDIRS); do \ (cd $$dir; $(MAKE) depend) \ done @rm -f .depend .depend.err @for dir in $(SRCDIRS); do \ (echo $(TUK)[CPP -M]$(NOR) $$dir/\*.cpp; \ test `(ls -1 $$dir/*.cpp 2>/dev/null | head -1)` && $(CPP) $(DEPFLAG) $$dir/*.cpp 2>> .depend.err | sed -e "s|^[a-zA-Z0-9].*\.o|$$dir/&|" >> .depend || touch .depend; \ echo $(YEL)[CC -M]$(NOR) $$dir/\*.c; \ test `(ls -1 $$dir/*.c 2>/dev/null | head -1)` && $(CC) $(DEPFLAG) $$dir/*.c 2>> .depend.err | sed -e "s|^[a-zA-Z0-9].*\.o|$$dir/&|" >> .depend || touch .depend; \ echo -n $(RED)[CHECK]$(NOR) .depend.err" "; \ (test -s .depend.err && echo [$(RED)ERROR$(NOR)]) || echo [$(GRN)OK$(NOR)] ) \ done endif .PHONY: help lib libs $(DISTDIR) help: @echo @echo $(WHT)Help for iwear $(DISTNAME)$(NOR) @echo @echo Possible Targets \($(GRN)green$(NOR) is default target\) @echo @echo -e $(GRN)lib$(NOR) "\t" Create ./lib/$(LIBNAME).so @echo -e $(TUK)test$(NOR) "\t" Create test program\(s\) in $(SRCDIR) @echo -e $(TUK)help$(NOR) "\t" Display this help screen @echo -e $(TUK)depend$(NOR) "\t" Generate dependencies @echo -e $(TUK)clean$(NOR) "\t" Remove compiler generated files @echo -e $(TUK)steril$(NOR) "\t" Remove all generated files too @echo -e $(RED)link$(NOR) "\t" Create links necessary for linking @echo -e $(RED)dist$(NOR) "\t" Create links necessary for linking @echo $(DISTDIR): distclean @echo $(BLU)[MKDIR]$(NOR) $(DISTDIR) @mkdir -p .$(DISTDIR) @cp -r * .$(DISTDIR) @mv .$(DISTDIR) $(DISTDIR) tar dist: $(DISTDIR) @echo $(BLU)[TAR]$(NOR) $(DISTDIR)-$(LIBVERSION).tar.bz2 @tar cjf $(DISTDIR)-$(LIBVERSION).tar.bz2 $(DISTDIR) @rm -rf $(DISTDIR) rk rkdist: distclean @echo $(BLU)[TAR]$(NOR) $(DISTDIR)-$(LIBVERSION).tar @tar cf $(DISTDIR)-$(LIBVERSION).tar $(DISTDIR) @echo $(BLU)[RK]$(NOR) $(DISTDIR)-$(LIBVERSION).tar.rk @rk -mx $(DISTDIR)-$(LIBVERSION).tar.rk $(DISTDIR)-$(LIBVERSION).tar @rm -f $(DISTDIR)-$(LIBVERSION).tar @rm -rf $(DISTDIR) iwear/iwear.h: @echo $(YEL)Cannot find iwear/iwear.h did you forgot to $(RED)make link$(YEL) in iwear/$(SRCDIR) ?$(NOR) @exit 1 count cnt: @echo $(GRN)[WC]$(NOR) *.cpp *.h @find | egrep ".cpp$$|.h$$" | xargs wc scount scnt: @echo $(GRN)[SLOCCOUNT]$(NOR) *.cpp *.h @sloccount --addlangall . SRCHOME=$(PWD) #XXX Need to check if DISTNAME==* ?? ifdef DISTNAME ifdef LIBNAME .PHONY: lnk links link rechts install rechts lnk links link: $(LIBDIR) $(INCDIR) @echo $(GRN)[LN -s]$(NOR) $(LIB) @cd $(LIBDIR); rm -f $(LIBNAME)* @cd $(LIBDIR) ;ln -sf $(SRCHOME)/lib/$(LIB) @cd $(LIBDIR) ;ln -sf $(LIB) $(LIBNAME).$(DYN_SUFFIX) @echo $(GRN)[LN -s]$(NOR) $(LIBNAME).a @cd $(LIBDIR) ;ln -sf $(SRCHOME)/lib/$(STATLIB) $(LIBNAME).a @echo $(GRN)[LN -s]$(NOR) $(DISTNAME) @cd $(INCDIR); rm -rf $(DISTNAME) @cd $(INCDIR); ln -sf $(SRCHOME)/include/ $(DISTNAME) @mkdir -p $(SHAREDIR)/locale/de_DE/LC_MESSAGES/ @mkdir -p $(SHAREDIR)/locale/ru_RU/LC_MESSAGES/ @mkdir -p $(SHAREDIR)/locale/zh_CN/LC_MESSAGES/ @mkdir -p $(SHAREDIR)/locale/fr_FR/LC_MESSAGES/ @cd $(SHAREDIR)/locale/de_DE/LC_MESSAGES/; ln -sf $(SRCHOME)/share/locale/de_DE/LC_MESSAGES/*.mo . @cd $(SHAREDIR)/locale/ru_RU/LC_MESSAGES/; ln -sf $(SRCHOME)/share/locale/ru_RU/LC_MESSAGES/*.mo . @cd $(SHAREDIR)/locale/zh_CN/LC_MESSAGES/; ln -sf $(SRCHOME)/share/locale/zh_CN/LC_MESSAGES/*.mo . @cd $(SHAREDIR)/locale/fr_FR/LC_MESSAGES/; ln -sf $(SRCHOME)/share/locale/fr_FR/LC_MESSAGES/*.mo . install: lib @echo $(YEL)Removing old files and versions$(NOR) @cd $(LIBDIR); rm -f $(LIBNAME)* @cd $(INCDIR); rm -rf $(DISTNAME) @echo $(YEL)[CP]$(NOR) $(LIB) @cp $(TOPDIR)/lib/$(LIB) $(LIBDIR) @echo $(YEL)[CP]$(NOR) $(STATLIB) @cp $(TOPDIR)/lib/$(STATLIB) $(LIBDIR) @echo $(GRN)[LN -s]$(NOR) $(LIBNAME).$(DYN_SUFFIX) @cd $(LIBDIR); ln -s $(LIB) $(LIBNAME).$(DYN_SUFFIX) @mkdir -p $(INCDIR)/$(DISTNAME)/ @cp include/*.h* $(INCDIR)/$(DISTNAME)/ doc-install: @echo $(YEL)Removing old files and versions$(NOR) @mkdir -p $(DOCDIR) @cd $(DOCDIR); cd ..; rm -rf $(DISTDIR) @echo $(YEL)[CP]$(NOR) doc @cd doc;cp -r html $(DOCDIR)/ @cp COPYING $(DOCDIR) update: cvs update -dP $(MAKE) steril ./configure $(MAKE) -C . dep $(MAKE) -C . lnk $(MAKE) -C . lib endif endif