10bbfda8aSnia#
20bbfda8aSnia# Rules for generated source files
30bbfda8aSnia#
40bbfda8aSnia
50bbfda8aSnia
60bbfda8aSnia# Hand-build deftwmrc.c
70bbfda8aSniaset(defc ${CMAKE_CURRENT_BINARY_DIR}/deftwmrc.c)
80bbfda8aSniaset(mkdefc ${TOOLS}/mk_deftwmrc.sh)
90bbfda8aSniaadd_custom_command(OUTPUT ${defc}
100bbfda8aSnia	DEPENDS system.ctwmrc ${mkdefc}
110bbfda8aSnia	COMMAND ${mkdefc} ${CMAKE_CURRENT_SOURCE_DIR}/system.ctwmrc > ${defc}
120bbfda8aSnia)
130bbfda8aSnia
140bbfda8aSnia
150bbfda8aSnia# Hand-build ctwm_atoms.[ch]
160bbfda8aSniaset(ctwm_atoms ctwm_atoms.h ctwm_atoms.c)
170bbfda8aSniaadd_custom_command(OUTPUT ${ctwm_atoms}
180bbfda8aSnia	DEPENDS ctwm_atoms.in ${TOOLS}/mk_atoms.sh
190bbfda8aSnia	COMMAND ${TOOLS}/mk_atoms.sh ${CMAKE_CURRENT_SOURCE_DIR}/ctwm_atoms.in ctwm_atoms CTWM
200bbfda8aSnia)
210bbfda8aSnia
220bbfda8aSnia
230bbfda8aSnia# Generate up the event names lookup source
240bbfda8aSniaset(en_list ${CMAKE_CURRENT_SOURCE_DIR}/event_names.list)
250bbfda8aSniaset(en_out  ${CMAKE_CURRENT_BINARY_DIR}/event_names_table.h)
260bbfda8aSniaset(en_mk   ${TOOLS}/mk_event_names.sh)
270bbfda8aSniaadd_custom_command(OUTPUT ${en_out}
280bbfda8aSnia	DEPENDS ${en_list} ${en_mk}
290bbfda8aSnia	COMMAND ${en_mk} ${en_list} > ${en_out}
300bbfda8aSnia)
310bbfda8aSnia# Have to manually add this, or cmake won't notice that it's needed in
320bbfda8aSnia# time to make it.
330bbfda8aSnia#set_source_files_properties(event_names.c OBJECT_DEPENDS ${en_out})
340bbfda8aSnia# This also seems a blessed hackaround, and avoids having to encode the
350bbfda8aSnia# knowledge of what files #include it.
360bbfda8aSnialist(APPEND CTWMSRC ${CMAKE_CURRENT_BINARY_DIR}/event_names_table.h)
370bbfda8aSnia
380bbfda8aSnia
390bbfda8aSnia# Create function bits
400bbfda8aSniaset(fd_list ${CMAKE_CURRENT_SOURCE_DIR}/functions_defs.list)
410bbfda8aSniaset(fd_mk   ${TOOLS}/mk_function_bits.sh)
420bbfda8aSniaset(fd_h    ${CMAKE_CURRENT_BINARY_DIR}/functions_defs.h)
430bbfda8aSniaset(fdd_h   ${CMAKE_CURRENT_BINARY_DIR}/functions_deferral.h)
440bbfda8aSniaset(fpt_h   ${CMAKE_CURRENT_BINARY_DIR}/functions_parse_table.h)
450bbfda8aSniaset(fde_h   ${CMAKE_CURRENT_BINARY_DIR}/functions_dispatch_execution.h)
460bbfda8aSniaadd_custom_command(
470bbfda8aSnia	OUTPUT ${fd_h} ${fdd_h} ${fpt_h} ${fde_h}
480bbfda8aSnia	DEPENDS ${fd_list} ${fd_mk}
490bbfda8aSnia	COMMAND ${fd_mk} ${fd_list} ${CMAKE_CURRENT_BINARY_DIR}
500bbfda8aSnia)
510bbfda8aSnialist(APPEND CTWMSRC ${fd_h} ${fdd_h} ${fpt_h} ${fde_h})
520bbfda8aSnia
530bbfda8aSnia
540bbfda8aSnia# Setup config header file
550bbfda8aSniaconfigure_file(ctwm_config.h.in ctwm_config.h ESCAPE_QUOTES)
560bbfda8aSnia
570bbfda8aSnia
580bbfda8aSnia# Fill in version info
590bbfda8aSnia
600bbfda8aSnia# Need the VCS bits; add a guard here to prevent dev screwups when
610bbfda8aSnia# working on the build system.
620bbfda8aSniaif(NOT VCS_CHECKS_RUN)
630bbfda8aSnia	message(FATAL_ERROR "Internal error: VCS checks not done yet!")
640bbfda8aSniaendif()
650bbfda8aSnia
660bbfda8aSnia# Building the version.c file happens in 2 steps.  First, an original
670bbfda8aSnia# source file (${version_c_src}) is processed with tools/mk_version_in.sh
680bbfda8aSnia# to write in the ctwm version info found in the VERSION file in the root
690bbfda8aSnia# of the tree.  That's written to an intermediate file (${version_c_in}).
700bbfda8aSnia# Secondly, the intermediate file is processed to store up info about the
710bbfda8aSnia# VCS revision being built from, into the final file (${version_c}) which
720bbfda8aSnia# is actually compiled.
730bbfda8aSnia#
740bbfda8aSnia# A special case occurs when there's no VCS info we can find to work
750bbfda8aSnia# with, AND we have a pregen'd .in file (${vresion_c_gen}); this is
760bbfda8aSnia# commonly the case with a release tarball, where part of the release
770bbfda8aSnia# building process pre-stashes the bzr revision info.  In that case, we
780bbfda8aSnia# swap the original (${version_c_src}) to point to the pregen'd file
790bbfda8aSnia# (which already has the VCS info), and make the second step just cp the
800bbfda8aSnia# intermediate file over.
810bbfda8aSniaset(version_c_src ${CMAKE_CURRENT_SOURCE_DIR}/version.c.in)
820bbfda8aSniaset(version_c_in  ${CMAKE_CURRENT_BINARY_DIR}/version.c.in)
830bbfda8aSniaset(version_c     ${CMAKE_CURRENT_BINARY_DIR}/version.c)
840bbfda8aSnia
850bbfda8aSnia# Maybe a pregen'd
860bbfda8aSniaset(version_c_gen ${GENSRCDIR}/version.c.in)
870bbfda8aSnia
880bbfda8aSnia# Override
890bbfda8aSniaif(FORCE_PREGEN_FILES)
900bbfda8aSnia	set(HAS_BZR 0)
910bbfda8aSnia	set(HAS_GIT 0)
920bbfda8aSniaendif()
930bbfda8aSnia
940bbfda8aSnia# Now, what's our process for going from the intermediate .c.in file to
950bbfda8aSnia# the final .c with the VCS revision info added?  This is the 2nd step in
960bbfda8aSnia# the process, but we describe it first here so we can change where
970bbfda8aSnia# ${version_c_src} points if necessary.
980bbfda8aSniaif(IS_BZR_CO AND HAS_BZR)
990bbfda8aSnia	# We're in a bzr tree, so write in the bzr revision info
1000bbfda8aSnia	set(rw_ver_bzr "${TOOLS}/rewrite_version_bzr.sh")
1010bbfda8aSnia	add_custom_command(OUTPUT ${version_c}
1020bbfda8aSnia		DEPENDS ${version_c_in} ${BZR_DIRSTATE_FILE} ${rw_ver_bzr}
103b18c2d1eSnia		COMMAND env BZR_CMD=${BZR_CMD} ${rw_ver_bzr} < ${version_c_in} > ${version_c}
1040bbfda8aSnia		COMMENT "Generating version.c from current WT state."
1050bbfda8aSnia		WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
1060bbfda8aSnia	)
1070bbfda8aSniaelseif(IS_GIT_CO AND HAS_GIT)
1080bbfda8aSnia	# We're in a git tree, so write in the git revision info
1090bbfda8aSnia	set(rw_ver_git "${TOOLS}/rewrite_version_git.sh")
1100bbfda8aSnia	add_custom_command(OUTPUT ${version_c}
1110bbfda8aSnia		DEPENDS ${version_c_in} ${GIT_INDEX_FILE} ${rw_ver_git}
1120bbfda8aSnia		COMMAND ${rw_ver_git} < ${version_c_in} > ${version_c}
1130bbfda8aSnia		COMMENT "Generating version.c from current git state."
1140bbfda8aSnia		WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
1150bbfda8aSnia	)
1160bbfda8aSniaelseif(EXISTS ${version_c_gen})
1170bbfda8aSnia	# There's a prebuilt one to use; commonly this means we're building
1180bbfda8aSnia	# from a release tarball, and it includes pre-stashed bzr revision
1190bbfda8aSnia	# info about the release.  So, in this case, we replace the original
1200bbfda8aSnia	# source with our pregen'd one (which already has the info in it),
1210bbfda8aSnia	# and just use 'cp' to turn the intermediate .c.in into the final .c.
1220bbfda8aSnia	set(version_c_src ${version_c_gen})
1230bbfda8aSnia
1240bbfda8aSnia	add_custom_command(OUTPUT ${version_c}
1250bbfda8aSnia		DEPENDS ${version_c_in}
1260bbfda8aSnia		COMMAND cp ${version_c_in} ${version_c}
1270bbfda8aSnia		COMMENT "Using pregenerated version.c."
1280bbfda8aSnia	)
1290bbfda8aSniaelse()
1300bbfda8aSnia	# We've got nothing at all, so just NULL out the VCS info; it's all
1310bbfda8aSnia	# we can do.
1320bbfda8aSnia	add_custom_command(OUTPUT ${version_c}
1330bbfda8aSnia		DEPENDS ${version_c_in}
1340bbfda8aSnia		COMMAND sed -e 's/%%VCSTYPE%%/NULL/' -e 's/%%REVISION%%/NULL/'
1350bbfda8aSnia			< ${version_c_in} > ${version_c}
1360bbfda8aSnia		COMMENT "Using null version.c."
1370bbfda8aSnia	)
1380bbfda8aSniaendif()
1390bbfda8aSnia
1400bbfda8aSnia# Now handle the first step; turning the original source .c.in into the
1410bbfda8aSnia# intermediate .c.in with the ctwm version written in.  That's _usually_
1420bbfda8aSnia# starting with the version.c.in in the source tree, but in the "no VCS
1430bbfda8aSnia# info, but we have a pregen'd gen/version.c to use" case above it's the
1440bbfda8aSnia# pregen'd file.
1450bbfda8aSniaadd_custom_command(OUTPUT ${version_c_in}
1460bbfda8aSnia	DEPENDS ${version_c_src} ${CMAKE_CURRENT_SOURCE_DIR}/VERSION
1470bbfda8aSnia	DEPENDS ${TOOLS}/mk_version_in.sh
1480bbfda8aSnia	COMMAND ${TOOLS}/mk_version_in.sh ${version_c_src} > ${version_c_in}
1490bbfda8aSnia	COMMENT "Writing version info into version.c.in"
1500bbfda8aSnia)
1510bbfda8aSnia
1520bbfda8aSnia
1530bbfda8aSnia# Setup a 'version' binary build tool too, for easily printing bits or
1540bbfda8aSnia# wholes of our version.
1550bbfda8aSnia#
1560bbfda8aSnia# Not currently being used, but left as an example of possibilities.  If
1570bbfda8aSnia# we need the version in the build process, we'll get it from the
1580bbfda8aSnia# ${ctwm_version_*} vars now.
1590bbfda8aSnia#add_executable(version ${version_c})
1600bbfda8aSnia#set_target_properties(version PROPERTIES COMPILE_FLAGS "-DBUILD_VERSION_BIN")
161