Page principale | Liste des namespaces | Hiérarchie des classes | Liste alphabétique | Liste des classes | Liste des fichiers | Membres de namespace | Membres de classe | Membres de fichier

Buildfile.py

Aller à la documentation de ce fichier.
00001 #!/usr/bin/env python
00002 """
00003    Builfile
00004        Solution pour generer des makefile multiplateforme
00005        Il permet aussi de definir le genre de produit que vous
00006        voulez faire avec le projet:
00007         $ python Buildfile -il
00008                produira un fichier de configuration et un Makefile
00009                qui permettra l'utilisateur d'avoir acces a la sortie
00010                de matrices creuses en images ainsi qu'une sortie LaTeX
00011         $ python Buildfile -p
00012                va produire les librairies dynamiques qui seront utilisees
00013                en Python
00014 """
00015 
00016 import sys, os, re
00017 import getopt
00018 
00019 NOM_EXEC   = "ModelMath"
00020 usage = "Usage : %s arguments\n\
00021     \t--with_python -p   Necessite Boost.Python et Python2.2(au moins) d'installe, creation des librairies pour Python\n\
00022     \t--with_png    -i   Permet de faire une sortie graphique (format PNG) des matrices creuses\n\
00023     \t--with_latex  -l   On pourra sortir un fichier en LaTeX dans le programme\n\
00024     \t--with_html   -w   Sortie d'un fichier HTML (utilise CSS1)" % sys.argv [0]
00025 with_python = 0
00026 with_png    = 0
00027 for_windows = 0
00028 with_latex  = 1
00029 with_html   = 1
00030 
00031 opts = {}
00032 arguments = {}
00033 sources=[]
00034 headers=[]
00035 
00036 # Tout ce qu'il faut pour le makefile
00037 # il se divise en plusieurs sections
00038 dependances = "#------------------------------------------------------\n"
00039 compilo="#------------------------------------------------------\n\
00040 #Compilateur et option\n\
00041 CC=g++\n\
00042 AR=ar\n\
00043 CFLAGS=-Wall -pedantic -O3 -malign-double -ffast-math -std=c++98 -I../include\n"
00044 python="linking=-L/usr/local/lib -lpython2.2 -lboost_python -DBOOST_PYTHON_STATIC_MODULE /usr/local/lib/libboost_python-gcc.a\n\
00045 chemin=-I/usr/local/include/boost-1_32 -I/usr/include/python2.2\n"
00046 wo_python="chemin=\nlinking=\n"
00047 entete="\
00048 #  Makefile genere par Buildfil.py\n\
00049 # Ce logiciel a ete cree pour Modelib (ISIMA/2005)\n\
00050 # http://neuroo.kouette.com/modelib\n\
00051 # Quentin Lequy et Romain Gaucher\n"
00052 machine="#--------------------------------------------------------\n\
00053 %.o : %.cpp\n\
00054     @echo \" obj file:\"$*.cpp\n\
00055     $(CC) -c $(CFLAGS) $*.cpp "
00056 exec_python="$(chemin)\n\
00057 %.so : %.o\n\
00058   @echo \" so file:\"$*.o\n\
00059   @$(CC) -shared $*.o -o $*.so $(linking)\n"
00060 machine2="\n\n$(EXEC) : $(OBJS)\n\
00061     @echo \" exe file:\"$(EXEC)\n\
00062     @$(CC) -o $(EXEC) -g $(OBJS) $(LFLAGS)\n\
00063     @echo \" generate static_lib:\" $(LIBA)\n\
00064     @$(AR) r  $(LIBA) $(OBJS_WITHOUT_MAIN)\n\
00065     @cp -fr $(LIBA) ../bin\n\
00066 \n\
00067 clean:\n\
00068     @echo \"cleaning all files but sources\"\n\
00069     @rm -f $(OBJS) $(EXEC)\n\
00070 \n\
00071 install:\n\
00072     @echo \" writing the path...\"\n\
00073     @export PATH=$PATH:$PWD/../\n\
00074 save:\n\
00075     @cp -fr ./* ../archive/\n\
00076     @rm -fr ../archive/*.o\n\
00077     @rm -f  ../projet.tar.bz2\n\
00078     @tar -cvjf  ../projet.tar.bz2 ../archive\n"
00079 
00080 def usage_error (message, exit_code) :
00081     print '--> ### %s ###' % message
00082     print '--> %s' % usage
00083     sys.exit (exit_code)
00084 
00085 def parse_cmds (opts):
00086     global with_python, with_png, for_windows, with_html, with_latex
00087     option = {}
00088     #print '=)> %s' % opts      
00089     for arg in opts:
00090         if arg in ('-p', '--with_python'):
00091             with_python = 1
00092         elif arg in ('-i','--with_png'):
00093             with_png = 1
00094         elif arg in ('-l','--with_latex'):
00095             with_latex = 1
00096         elif arg in ('-w','--with_html'):
00097             with_html = 1
00098         elif arg in ('-h', '--help'):
00099             print '%s' % usage
00100             sys.exit(1)
00101         else:
00102             str = "option [%s] inconnu" % arg
00103             usage_error(str,0)
00104             
00105     if os.name == "posix" or os.name == "mac" or os.name == "riscos":
00106         for_windows = 0
00107     else:
00108         for_windows = 1
00109     """
00110     print "(%s) - (%s)" % (os.name,os.path)
00111     print "Etat du systeme:"
00112     print "\tWITH_PYTHON = %d" % with_python
00113     print "\tWITH_PNG = %d" % with_png
00114     print "\tFOR_WINDOWS = %d" % for_windows
00115     print "\tWITH_LATEX = %d" % with_latex
00116     print "\tWITH_HTML = %d" % with_html
00117     """
00118 
00119 
00120 def get_files():
00121     # listes les .cpp et .h
00122     global headers, sources
00123     all = {};
00124     dirname = os.getcwd()
00125     all = [f for f in os.listdir(dirname) if os.path.isfile(os.path.join(dirname, f))]
00126     # print all
00127     # construire l'expression reguliere permettant d'avoir les .cpp et .h
00128     old = re.compile("old.(.+)$")
00129     cpp = re.compile("(.+).cpp$")
00130     h   = re.compile("(.+).h$|(.+).cxx$")
00131     for f in all:
00132         if cpp.match(f,re.IGNORECASE) and not old.match(f,re.IGNORECASE):
00133             sources.append(f)
00134         if h.match(f,re.IGNORECASE) and not old.match(f,re.IGNORECASE) and f != NOM_EXEC:
00135             headers.append(f)
00136 
00137     #print headers
00138     #print sources
00139 
00140 
00141 def make_configh():
00142     print "Construction de Config.h"
00143     try:
00144         configh = open("../include/Config.h","w")
00145     except IOError:
00146         print "Impossible d'ecrire le fichier desire"
00147         return 0
00148     else:
00149         configh.write("// Fichier genere automatiquement par Buildfile.\n// Modelib / Programmes lineaires pour C++ et Python\n")
00150         configh.write("#ifndef __CONFIG_H\n#define __CONFIG_H\n\n")
00151         configh.write("#define __no_export\n")
00152         if for_windows:
00153             configh.write("#define WINDOWS_VERSION\n")
00154         if with_png:
00155             configh.write("#define EXPORT_SPARSE_MATRIX_PNG\n")
00156         if with_python:
00157             configh.write("#define COMPILE_FOR_PYTHON\n")
00158         if with_latex:
00159             configh.write("#define USE_LATEX_FORMAT\n")
00160         if with_html:
00161             configh.write("#define USE_HTML_FORMAT\n")
00162   
00163         configh.write("\n\n#endif\n\n")
00164         configh.close()
00165     return 1
00166 
00167 def make_file():
00168     global sources
00169     print "Construction du Makefile"
00170     nom = "Makefile"
00171 
00172     try:
00173         makefile = open(nom,"w")
00174     except IOError:
00175         print "Impossible d'ecrire le fichier desire"
00176         return 0
00177     else:
00178         # mettre les sources suivant les options
00179         makefile.write("#------------------------------------------------------\n");
00180         makefile.write(entete)
00181         makefile.write("#------------------------------------------------------\n");
00182         srcs = "SRCS="
00183         for f in sources:
00184             if with_latex == 0 and f == "latexFile.cpp":
00185                 continue
00186             elif with_png == 0 and f == "Png.cpp":
00187                 continue
00188             elif with_html == 0 and f == "htmlFile.cpp":
00189                 continue
00190             elif f == "Python.cpp" and not with_python:
00191                 continue
00192             else:
00193                 srcs = srcs + f + " "
00194         srcs = srcs + "\n"
00195         makefile.write(srcs)
00196         makefile.write("OBJS=$(patsubst %.cpp, %.o, $(SRCS))\n")
00197         EXEC = "EXEC=%s" % NOM_EXEC
00198         if for_windows:
00199            EXEC = EXEC+".exe"
00200         EXEC = EXEC + "\n"
00201         makefile.write(EXEC)
00202         makefile.write("LIBA=model.a\n")
00203 
00204         # mettre les .o pour la construction de la lib
00205         objs = ""
00206         objs2= ""
00207         for f in sources:
00208             if with_latex == 0 and f == "latexFile.cpp":
00209                 continue
00210             elif with_png == 0 and f == "Png.cpp":
00211                 continue
00212             elif with_html == 0 and f == "htmlFile.cpp":
00213                 continue
00214             elif f == "main.cpp":
00215               continue
00216             elif f == "Python.cpp" and not with_python:
00217               continue
00218             else:
00219                 objs = objs + f + " "
00220 
00221         objs2 = objs.replace(".cpp",".o")
00222         #print objs
00223         objs2 = "OBJS_WITHOUT_MAIN=" + objs2 + "\n"
00224         makefile.write(objs2)
00225         
00226         # Chemins pour python
00227         if with_python:
00228            makefile.write(python)
00229 
00230     # compilo
00231         makefile.write(compilo)
00232         LPFLAG = "LFLAGS=-I../include -lm"
00233         if with_png == 1:
00234             LPFLAG = LPFLAG + " -lpng\n"
00235         else:
00236             LPFLAG = LPFLAG + " \n"
00237         makefile.write(LPFLAG)
00238         # mettre les dependances
00239         makefile.write(dependances)
00240 
00241         # Compilation des .o
00242         makefile.write(machine)
00243     
00244     # Compilation des .so
00245         if with_python:
00246             makefile.write(exec_python)
00247 
00248     # Les autres regles du makefile
00249         makefile.write(machine2)
00250         
00251         makefile.close()
00252         return 1
00253 
00254 def chercher_path():
00255     print os.path
00256     if for_windows == 0:
00257         # a la recherche de GLPSOL et CPLEX
00258         print "UNIX version"
00259 
00260 
00261 # main...
00262 try :
00263     options,arguments = getopt.getopt ( sys.argv[1:] , 'hilpw' ,["help","with_png", "with_latex", "with_python", "with_html"] )
00264 except getopt.GetoptError :
00265     usage_error ("Illegal options", 1)
00266 for option in options:
00267     opts[option[0]] = option[1]
00268 parse_cmds(opts)
00269 get_files()
00270 make_configh()
00271 make_file()
00272 
00273 
00274 #chercher_path()
00275 
00276 
00277 

Généré le Sun Oct 2 19:13:12 2005 pour Modelib par  doxygen 1.4.4