Ticket #12433: makemakefile.py.patch

File makemakefile.py.patch, 6.7 KB (added by jdemeyer, 10 years ago)

New / modified patch to src/makemakefile.py. For easier review only; do not apply.

  • makemakefile.py

    old new  
    22# This python script is called by configure to generate the makefile
    33# for zn_poly.
    44#
     5# Patched for Sage's 'spkg-install' to
     6# - respect the environment settings of CC, CPP, CXX, AR and RANLIB, and use
     7#   these as well as CFLAGS, CPPFLAGS, CXXFLAGS and LDFLAGS with their usual
     8#   meaning (i.e., CXX and not CPP for the C++ compiler, likewise CXXFLAGS
     9#   instead of CPPFLAGS, CPPFLAGS for C preprocessor flags, and LDFLAGS in
     10#   every link command using the compiler driver);
     11# - support passing CPPFLAGS and CXXFLAGS (via '--cppflags=...' and
     12#   '--cxxflags=...');
     13# - build a 64-bit shared library (.dylib) on Darwin / MacOS X by adding the
     14#   target 'libzn_poly.dylib64'.  (This is meanwhile superfluous, since
     15#   LDFLAGS are used in the receipt for libzn_poly.dylib as well.)
     16# - support a variable SONAME_FLAG (defaulting to '-soname', otherwise taken
     17#   from the environment (e.g. '-h' for the Sun linker);
     18# - support a variable SHARED_FLAG (defaulting to '-shared'), which could
     19#   later be used to unify the .so and .dylib targets.  (An SO_EXTENSION
     20#   variable isn't supported / used yet.)
    521
    622# --------------------------------------------------------------------------
    723# various lists of modules
     
    7288parser = OptionParser()
    7389parser.add_option("--prefix", dest="prefix", default="/usr/local")
    7490parser.add_option("--cflags", dest="cflags", default="-O2")
     91parser.add_option("--cppflags", dest="cppflags", default="")
     92parser.add_option("--cxxflags", dest="cxxflags", default="-O2")
    7593parser.add_option("--ldflags", dest="ldflags", default="")
    7694parser.add_option("--gmp-prefix", dest="gmp_prefix", default="/usr/local")
    7795parser.add_option("--ntl-prefix", dest="ntl_prefix", default="/usr/local")
     
    93111   flint_lib_dir = options.flint_prefix + "/lib"
    94112
    95113cflags = options.cflags
     114cppflags = options.cppflags # C preprocessor flags
     115cxxflags = options.cxxflags # C++ compiler flags
    96116ldflags = options.ldflags
    97117prefix = options.prefix
    98118
     119# Note: This should be put into / added to cppflags:
    99120includes = "-I" + gmp_include_dir + " -I./include"
     121# Note: This should be put into / added to ldflags:
    100122libs = "-L" + gmp_lib_dir + " -lgmp -lm"
    101123
    102124if options.use_flint:
     
    104126   libs = libs + " -L" + flint_lib_dir + " -lflint"
    105127   cflags = cflags + " -std=c99 -DZNP_USE_FLINT"
    106128
     129# Note: These also belong to CPPFLAGS and LDFLAGS, respectively:
     130# (But we currently don't use NTL in Sage's zn_poly installation anyway.)
    107131cpp_includes = includes + " -I" + ntl_include_dir
    108132cpp_libs = libs + " -L" + ntl_lib_dir + " -lntl"
    109133
     
    118142print "# by makemakefile.py on " + time.strftime("%a, %d %b %Y %H:%M:%S +0000",
    119143                                                 time.gmtime())
    120144print "#"
     145print "# (makemakefile.py patched for Sage, 04/2012)"
    121146print
    122147
    123148print
    124 print "CC = gcc"
     149print "CC ?= gcc"
     150print "CPP ?= cpp"
    125151print "CFLAGS = " + cflags
     152print "CPPFLAGS = " + cppflags
    126153print "LDFLAGS = " + ldflags
    127 print "INCLUDES = " + includes
    128 print "LIBS = " + libs
     154print "INCLUDES = " + includes # These are options to the C preprocessor.
     155print "LIBS = " + libs # These are linker options passed to the compiler.
     156print
     157print "AR ?= ar"
     158print "RANLIB ?= ranlib"
     159print
     160print "SHARED_FLAG ?= -shared"
     161print "SONAME_FLAG ?= -soname" # '-h' for the Sun/Solaris linker
    129162
    130163print
    131 print "CPP = g++"
    132 print "CPPFLAGS = " + cflags
     164print "CXX ?= g++"             # The C++ compiler.
     165print "CXXFLAGS = " + cxxflags # Options passed to the C++ compiler.
    133166print "CPP_INCLUDES = " + cpp_includes
    134167print "CPP_LIBS = " + cpp_libs
    135168
     
    185218print "##### library targets"
    186219print
    187220print "libzn_poly.a: $(LIBOBJS)"
    188 print "\tar -r libzn_poly.a $(LIBOBJS)"
    189 print "\tranlib libzn_poly.a"
     221print "\t$(AR) -r libzn_poly.a $(LIBOBJS)"
     222print "\t$(RANLIB) libzn_poly.a"
    190223print
     224print "# TODO: Put '-single_module -fPIC -dynamiclib' into $(SHARED_FLAG)"
     225print "#       and use that; also support $(SO_EXTENSION)..."
    191226print "libzn_poly.dylib: $(LIBOBJS)"
    192 print "\t$(CC) -single_module -fPIC -dynamiclib -o libzn_poly.dylib " \
     227print "\t$(CC) $(LDFLAGS) -single_module -fPIC -dynamiclib -o libzn_poly.dylib " \
    193228      "$(LIBOBJS) $(LIBS)"
    194229print
     230print "# Left for compatibility with previous versions of Sage's 'spkg-install':"
     231print "libzn_poly.dylib64: $(LIBOBJS)"
     232print "\t$(CC) -m64 -single_module -fPIC -dynamiclib -o libzn_poly.dylib $(LIBOBJS) $(LIBS)"
     233print
    195234print "libzn_poly.so: $(LIBOBJS)"
    196 print "\t$(CC) -shared -Wl,-soname,libzn_poly-`cat VERSION`.so " \
     235print "\t$(CC) $(SHARED_FLAG) $(LDFLAGS) -Wl,$(SONAME_FLAG),libzn_poly-`cat VERSION`.so " \
    197236      "-o libzn_poly-`cat VERSION`.so $(LIBOBJS) $(LIBS)"
    198 print "\t ln -sf libzn_poly-`cat VERSION`.so libzn_poly.so"
     237print "\tln -sf libzn_poly-`cat VERSION`.so libzn_poly.so"
    199238
    200239print
    201240print
     
    210249print
    211250for x in prof_progs:
    212251   print "%s-main.o: %s-main.c $(HEADERS)" % (x, x)
    213    print "\t$(CC) $(CFLAGS) $(INCLUDES) -DNDEBUG -o %s-main.o -c %s-main.c" \
     252   print "\t$(CC) $(CFLAGS) $(CPPFLAGS) $(INCLUDES) -DNDEBUG -o %s-main.o -c %s-main.c" \
    214253         % (x, x)
    215254   print
    216255   print "%s: %s-main.o $(PROFOBJS)" % (x, x)
     
    218257         % (x, x)
    219258   print
    220259   print "%s-main-ntl.o: %s-main.c $(HEADERS)" % (x, x)
    221    print "\t$(CC) $(CFLAGS) $(INCLUDES) -DPROFILE_NTL -DNDEBUG " \
     260   print "\t$(CC) $(CFLAGS) $(CPPFLAGS) $(INCLUDES) -DPROFILE_NTL -DNDEBUG " \
    222261         "-o %s-main-ntl.o -c %s-main.c" % (x, x)
    223262   print
    224263   print "%s-ntl: %s-main-ntl.o $(CPP_PROFOBJS)" % (x, x)
    225    print "\t$(CPP) $(CPPFLAGS) $(LDFLAGS) -o %s-ntl %s-main-ntl.o " \
     264   print "\t$(CXX) $(CXXFLAGS) $(LDFLAGS) -o %s-ntl %s-main-ntl.o " \
    226265         "$(CPP_PROFOBJS) $(CPP_LIBS)" % (x, x)
    227266   print
    228267
     
    249288for x in lib_modules + test_modules + testprof_modules + demo_progs:
    250289   print
    251290   print "%s-DEBUG.o: %s.c $(HEADERS)" % (x, x)
    252    print "\t$(CC) -g $(CFLAGS) $(INCLUDES) -DDEBUG -o %s-DEBUG.o -c %s.c" \
     291   print "\t$(CC) -g $(CFLAGS) $(CPPFLAGS) $(INCLUDES) -DDEBUG -o %s-DEBUG.o -c %s.c" \
    253292         % (x, x)
    254293
    255294print
     
    259298                       tune_modules + demo_progs:
    260299   print
    261300   print "%s.o: %s.c $(HEADERS)" % (x, x)
    262    print "\t$(CC) $(CFLAGS) $(INCLUDES) -DNDEBUG -o %s.o -c %s.c" % (x, x)
     301   print "\t$(CC) $(CFLAGS) $(CPPFLAGS) $(INCLUDES) -DNDEBUG -o %s.o -c %s.c" % (x, x)
    263302
    264303print
    265304print
     
    267306for x in cpp_prof_modules:
    268307   print
    269308   print "%s.o: %s.c $(HEADERS)" % (x, x)
    270    print "\t$(CPP) $(CPPFLAGS) $(CPP_INCLUDES) -DNDEBUG -o %s.o -c %s.c" \
     309   print "\t$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(CPP_INCLUDES) -DNDEBUG -o %s.o -c %s.c" \
    271310         % (x, x)
    272311
    273312