1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
|
#!/usr/bin/env python3
#
# Copyright (C) 2011-2022 ABINIT Group (Yann Pouillon)
#
# This file is part of the ABINIT software document. For license information,
# please see the COPYING file in the top-level directory of the ABINIT source
# distribution.
#
from __future__ import print_function, division, absolute_import #, unicode_literals
try:
from ConfigParser import ConfigParser,NoOptionError
except ImportError:
from configparser import ConfigParser,NoOptionError
from time import gmtime,strftime
import os
import re
import sys
class MyConfigParser(ConfigParser):
def optionxform(self,option):
return str(option)
# ---------------------------------------------------------------------------- #
#
# Templates
#
doc_makefile = """\
# -*- Automake -*-
# Makefile for the Abinit Documentation
# Generated by %s on %s
#
# IMPORTANT NOTE
#
# Any manual change to this file will systematically be overwritten.
# Please modify the %s script or its config file instead.
#
%s%s
all-local: doc-build-stamp
if DO_BUILD_TEX
doc-build-stamp:%s
touch doc-build-stamp%s
else
doc-build-stamp:
cd .. && make built-docs-stamp @SET_MAKE@
endif
abidocdir = $(docdir)/%s
nobase%s_abidoc_DATA =%s%s%s
"""
man_makefile = """\
# -*- Automake -*-
# Makefile for the Abinit Documentation
# Generated by %s on %s
#
# IMPORTANT NOTE
#
# Any manual change to this file will systematically be overwritten.
# Please modify the %s script or its config file instead.
#
dist_man1_MANS = %s
all-local: doc-build-stamp
doc-build-stamp:
touch doc-build-stamp
CLEANFILES = doc-build-stamp
"""
top_makefile = """\
# -*- Automake -*-
# Makefile for the Abinit Documentation
# Generated by %s on %s
#
# IMPORTANT NOTE
#
# Any manual change to this file will systematically be overwritten.
# Please modify the %s script or its config file instead.
#
SUBDIRS =%s
EXTRA_DIST = built-docs.tgz config/gnu config/m4 config/util rules.am
%s
"""
doc_rules = open("rules.am", "rt").read()
# ---------------------------------------------------------------------------- #
#
# Subroutines
#
# Makefile contents
def makefile_src(name,stamp,dir_name,files,docs=None,flags=None):
doc_flags = ""
doc_files = ""
doc_deps = ""
doc_tgts = ""
doc_dist = ""
doc_clean = ""
doc_clean1 = ""
doc_clean2 = ""
doc_clean3 = ""
dist_tag = ""
if ( docs is None ):
doc_files = " \\\n " + " \\\n ".join(files)
dist_tag = "_dist"
else:
if ( not flags is None ):
doc_flags = "TEXFLAGS_EXTRA = %s\n\n" % (flags)
tmp_docs = list(docs.keys())
tmp_docs.sort()
for doc in tmp_docs:
doc_name,doc_type = doc.split(".")
if ( doc_type == "gv" ):
doc_ext = "pdf"
elif ( doc_type == "md" ):
doc_ext = "html"
elif ( doc_type == "tex" ):
doc_ext = "pdf"
doc_clean1 = "\n\trm -f *.aux *.blg *.ilg *.log *.nav *.snm *.tmp *.toc *.vrb"
doc_clean1 += "\n\trm -f \\\n\t *Notes.bib \\\n\t %s.fdb_latexmk \\\n\t %s.fls \\\n\t %s.out" % \
(doc_name,doc_name,doc_name)
doc_clean2 += "\n\trm -f %s.dvi" % (doc_name)
else:
print("Error: unknown document type '%s'" % (doc_type))
sys.exit(1)
doc_files += " \\\n %s.%s" % (doc_name,doc_ext)
doc_tgts += " \\\n %s.%s" % (doc_name,doc_ext)
doc_deps += "\n\n%s.%s: \\\n %s" % (doc_name,doc_ext,doc)
doc_dist += " \\\n %s" % (doc)
doc_clean2 += "\n\trm -f %s.%s" % (doc_name,doc_ext)
if ( len(docs[doc]) > 0 ):
doc_deps += " \\\n " + " \\\n ".join(docs[doc])
for src in docs[doc]:
if ( not re.search("\\.%s$" % (doc_ext),src) ):
doc_dist += " \\\n %s" % (src)
if ( len(files) > 0 ):
doc_dist += " \\\n " + " \\\n ".join(files)
if ( doc_clean1 != "" ):
doc_clean += "\nmostlyclean-local: %s\n" % (doc_clean1)
doc_clean += "\nclean-local:\n\trm -f doc-build-stamp"
if ( doc_clean2 != "" ):
doc_clean += "%s\n" % (doc_clean2)
if ( len(doc_dist) > 0 ):
doc_dist = "\nEXTRA_DIST =%s\n" % (doc_dist)
doc_files += "\n"
return doc_makefile % \
(name,stamp,name,doc_flags,doc_rules,doc_tgts,doc_deps,dir_name,dist_tag,
doc_files,doc_clean,doc_dist)
# ---------------------------------------------------------------------------- #
#
# Main program
#
# Initial setup
my_name = "make-makefiles-doc"
my_configs = ["config/specs/documents.conf"]
my_doctypes = {
"gv":"pdf",
"md":"html",
"tex":"pdf"}
# Check if we are in the top of the ABINIT source tree
if ( not os.path.exists("configure.ac") or
not os.path.exists("config/specs/documents.conf") ):
print("%s: You must be in the top of an Abinit Documentation source tree." % my_name)
print("%s: Aborting now." % my_name)
sys.exit(1)
# Read config file(s)
for cnf_file in my_configs:
if ( os.path.exists(cnf_file) ):
if ( re.search("\.cf$",cnf_file) ):
exec(compile(open(cnf_file).read(), cnf_file, 'exec'))
else:
print("%s: Could not find config file (%s)." % (my_name,cnf_file))
print("%s: Aborting now." % my_name)
sys.exit(2)
# What time is it?
now = strftime("%Y/%m/%d %H:%M:%S +0000",gmtime())
# Prepare regexps
olddir = re.compile(",.*")
tmpdir = re.compile("tmp-*")
vimswp = re.compile("\..*\.swp")
# Init document list
cnf = MyConfigParser()
cnf.read(my_configs[0])
doc_list = cnf.sections()
doc_list.sort()
all_docs = {}
# Process each document
for doc_dir in doc_list:
# Work directly from there
os.chdir(doc_dir)
# Extract document information
dir_type = cnf.get(doc_dir,"type")
# Filter documents according to their types
all_docs[doc_dir] = []
if ( dir_type == "data" ):
if ( cnf.has_option(doc_dir,"ignore") ):
ign_list = cnf.get(doc_dir,"ignore").split()
else:
ign_list = []
ign_list += ["Makefile.am","Makefile.in","Makefile"]
dat_files = []
for root,dirs,files in os.walk("."):
# We don't want to distribute nor install temporary directories
dirs = [item for item in dirs if (not olddir.match(item)) and (not tmpdir.match(item))]
# Get rid of ignored files
files = [item for item in files if (not item in ign_list) and (not vimswp.match(item))]
files.sort()
# Just add files as raw data
dat_files += [os.path.join(root,item) for item in files]
makefile_data = makefile_src(my_name,now,doc_dir,dat_files)
elif ( dir_type == "source" ):
if ( cnf.has_option(doc_dir,"texflags") ):
doc_flags = cnf.get(doc_dir,"texflags")
else:
doc_flags = None
dat_files = []
if ( cnf.has_option(doc_dir,"extra") ):
dat_files = cnf.get(doc_dir,"extra").split()
doc_files = {}
for doc in cnf.get(doc_dir,"docs").split():
doc_specs = cnf.get(doc_dir,doc).split()
doc_files["%s.%s" % (doc,doc_specs[0])] = doc_specs[1:]
all_docs[doc_dir].append("%s.%s" % (doc,my_doctypes[doc_specs[0]]))
makefile_data = makefile_src(my_name,now,doc_dir,dat_files,doc_files,doc_flags)
elif ( dir_type == "manual" ):
makefile_data = man_makefile % (my_name,now,my_name,cnf.get(doc_dir,"mans"))
else:
raise ValueError("processing of document type '%s' not implemented" % \
(dir_type))
# Write makefile
open("Makefile.am", "wt").write(makefile_data)
# Got back one level
os.chdir("..")
# Write top makefile
tar_deps = ""
tar_tgts = ""
tar_files = ""
for doc_dir in doc_list:
tar_deps += " \\\n %s/doc-build-stamp" % (doc_dir)
tar_tgts += "\n%s/doc-build-stamp:\n\tcd %s && $(MAKE) doc-build-stamp @SET_MAKE@\n" % \
(doc_dir,doc_dir)
for doc_file in all_docs[doc_dir]:
tar_files += " \\\n\t %s" % (os.path.join(doc_dir,doc_file))
doc_tarball = "if DO_BUILD_TEX\n\nbuilt-docs-tarball:%s\n\ttar czf built-docs.tgz%s\n%s\nelse\n\nall-local: built-docs-stamp\n\ninstall-data-local: built-docs-stamp\n\nbuilt-docs-stamp: built-docs.tgz\n\ttar xmzf $(top_srcdir)/built-docs.tgz\n\ttouch built-docs-stamp\n\nbuilt-docs-tarball:\n\t@echo \"Please install Graphviz and LaTeX to build the documentation\"\n\nCLEANFILES = built-docs-stamp\n\nendif" % \
(tar_deps,tar_files,tar_tgts)
open("Makefile.am", "wt").write(top_makefile % \
(my_name,now,my_name," \\\n " + " \\\n ".join(doc_list),doc_tarball))
|