# 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 # Flags for the compilers # # Think about those as additionals : # -fvtable-gc # -ffunction-sections # -Wl,--gc-sections # -frepo # CFLAGS= -pipe -Wall -g -O3 CPPFLAGS= -pipe -Wall -g -O3 # Flags for the linker CPPLDFLAGS=$(LIBLIBS) -shared -Wl,-warn-once,-soname, DEPFLAG=-M $(INCLUDE) # // How can we do this better ? ifneq ($(MAKECMDGOALS),steril) ifneq ($(MAKECMDGOALS),mrproper) ifneq ($(MAKECMDGOALS),clean) ifneq ($(MAKECMDGOALS),distclean) ifneq ($(MAKECMDGOALS),dist) # include dependencies files if it exists -include .depend endif endif endif endif endif # include generated configuration -include $(TOPDIR)/makefile.conf # 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).so.$(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) # 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))) 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: $(SUBLIBFILES) # @for dir in $(SRCDIRS); do \ # (cd $$dir;$(MAKE) sublib) \ # done @echo $(BLU)[LD]$(NOR) $(LIB) @$(CPP) $(CPPLDFLAGS)$(LIB) $(SUBLIBFILES) -o $(TOPDIR)/lib/$(LIB) @echo $(BLU)[AR]$(NOR) $(STATLIB) @$(AR) r $(TOPDIR)/lib/$(STATLIB) $(SUBLIBFILES) @$(RANLIB) $(TOPDIR)/lib/$(STATLIB) 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/*.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 %.s:%.cpp @echo $(RED)[CPP -S]$(NOR) $*.o @$(CPP) $(CPPFLAGS) -S $(INCLUDE) -c $*.cpp -o $*.s %.o:%.c @echo $(YEL)[CC]$(NOR) $*.o @$(CC) $(CFLAGS) $(INCLUDE) -c $*.c -o $*.o 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 @ls *.cpp | head -1 | test -s && $(CPP) $(DEPFLAG) *.cpp > .depend 2> .depend.err || touch .depend @echo $(YEL)[CC -M]$(NOR) \*.c @test -s *.c && $(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)] 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 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).so @echo $(GRN)[LN -s]$(NOR) $(LIBNAME).a @cd $(LIBDIR) ;ln -sf $(LIB) $(LIBNAME).a @echo $(GRN)[LN -s]$(NOR) $(DISTNAME) @cd $(INCDIR); rm -rf $(DISTNAME) @cd $(INCDIR); ln -sf $(SRCHOME)/include/ $(DISTNAME) 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 $(GRN)[LN -s]$(NOR) $(LIBNAME).so @cd $(LIBDIR); ln -s $(LIB) $(LIBNAME).so @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 . lnk $(MAKE) -C . lib endif endif