xref: /aosp_15_r20/external/libpng/scripts/cmake/gensrc.cmake.in (revision a67afe4df73cf47866eedc69947994b8ff839aba)
1*a67afe4dSAndroid Build Coastguard Worker# gensrc.cmake.in
2*a67afe4dSAndroid Build Coastguard Worker# Generate source files with awk, based upon the automake logic.
3*a67afe4dSAndroid Build Coastguard Worker
4*a67afe4dSAndroid Build Coastguard Worker# Copyright (c) 2022-2024 Cosmin Truta
5*a67afe4dSAndroid Build Coastguard Worker# Copyright (c) 2016 Glenn Randers-Pehrson
6*a67afe4dSAndroid Build Coastguard Worker# Written by Roger Leigh, 2016
7*a67afe4dSAndroid Build Coastguard Worker#
8*a67afe4dSAndroid Build Coastguard Worker# Use, modification and distribution are subject to
9*a67afe4dSAndroid Build Coastguard Worker# the same licensing terms and conditions as libpng.
10*a67afe4dSAndroid Build Coastguard Worker# Please see the copyright notice in png.h or visit
11*a67afe4dSAndroid Build Coastguard Worker# http://libpng.org/pub/png/src/libpng-LICENSE.txt
12*a67afe4dSAndroid Build Coastguard Worker#
13*a67afe4dSAndroid Build Coastguard Worker# SPDX-License-Identifier: libpng-2.0
14*a67afe4dSAndroid Build Coastguard Worker
15*a67afe4dSAndroid Build Coastguard Worker# Variables substituted from CMakeLists.txt
16*a67afe4dSAndroid Build Coastguard Workerset(SRCDIR "@CMAKE_CURRENT_SOURCE_DIR@")
17*a67afe4dSAndroid Build Coastguard Workerset(BINDIR "@CMAKE_CURRENT_BINARY_DIR@")
18*a67afe4dSAndroid Build Coastguard Worker
19*a67afe4dSAndroid Build Coastguard Workerset(AWK "@AWK@")
20*a67afe4dSAndroid Build Coastguard Workerset(DFA_XTRA "@DFA_XTRA@")
21*a67afe4dSAndroid Build Coastguard Workerset(PNG_PREFIX "@PNG_PREFIX@")
22*a67afe4dSAndroid Build Coastguard Workerset(PNGLIB_VERSION "@PNGLIB_VERSION@")
23*a67afe4dSAndroid Build Coastguard Worker
24*a67afe4dSAndroid Build Coastguard Workerif(OUTPUT STREQUAL "scripts/pnglibconf.c")
25*a67afe4dSAndroid Build Coastguard Worker  # Generate scripts/pnglibconf.c
26*a67afe4dSAndroid Build Coastguard Worker
27*a67afe4dSAndroid Build Coastguard Worker  file(REMOVE "${BINDIR}/pnglibconf.tf6" "${BINDIR}/pnglibconf.tf7")
28*a67afe4dSAndroid Build Coastguard Worker
29*a67afe4dSAndroid Build Coastguard Worker  execute_process(COMMAND "${CMAKE_COMMAND}" -E echo "com ${PNGLIB_VERSION} STANDARD API DEFINITION"
30*a67afe4dSAndroid Build Coastguard Worker                  COMMAND "${AWK}" -f "${SRCDIR}/scripts/options.awk"
31*a67afe4dSAndroid Build Coastguard Worker                          "out=pnglibconf.tf6" "logunsupported=1" "version=search"
32*a67afe4dSAndroid Build Coastguard Worker                          "${SRCDIR}/pngconf.h" "-"
33*a67afe4dSAndroid Build Coastguard Worker                          "${SRCDIR}/scripts/pnglibconf.dfa"
34*a67afe4dSAndroid Build Coastguard Worker                  WORKING_DIRECTORY "${BINDIR}"
35*a67afe4dSAndroid Build Coastguard Worker                  RESULT_VARIABLE AWK_FAIL)
36*a67afe4dSAndroid Build Coastguard Worker  if(AWK_FAIL)
37*a67afe4dSAndroid Build Coastguard Worker    message(FATAL_ERROR "Failed to generate pnglibconf.tf6")
38*a67afe4dSAndroid Build Coastguard Worker  endif()
39*a67afe4dSAndroid Build Coastguard Worker
40*a67afe4dSAndroid Build Coastguard Worker  execute_process(COMMAND "${AWK}" -f "${SRCDIR}/scripts/options.awk"
41*a67afe4dSAndroid Build Coastguard Worker                  "out=pnglibconf.tf7" "pnglibconf.tf6"
42*a67afe4dSAndroid Build Coastguard Worker                  WORKING_DIRECTORY "${BINDIR}"
43*a67afe4dSAndroid Build Coastguard Worker                  RESULT_VARIABLE AWK_FAIL)
44*a67afe4dSAndroid Build Coastguard Worker  if(AWK_FAIL)
45*a67afe4dSAndroid Build Coastguard Worker    message(FATAL_ERROR "Failed to generate pnglibconf.tf7")
46*a67afe4dSAndroid Build Coastguard Worker  endif()
47*a67afe4dSAndroid Build Coastguard Worker
48*a67afe4dSAndroid Build Coastguard Worker  file(REMOVE "pnglibconf.tf6")
49*a67afe4dSAndroid Build Coastguard Worker  file(MAKE_DIRECTORY "${BINDIR}/scripts")
50*a67afe4dSAndroid Build Coastguard Worker  file(RENAME "pnglibconf.tf7" "${BINDIR}/scripts/pnglibconf.c")
51*a67afe4dSAndroid Build Coastguard Worker
52*a67afe4dSAndroid Build Coastguard Workerelseif(OUTPUT STREQUAL "pnglibconf.c")
53*a67afe4dSAndroid Build Coastguard Worker  # Generate pnglibconf.c
54*a67afe4dSAndroid Build Coastguard Worker
55*a67afe4dSAndroid Build Coastguard Worker  file(REMOVE "${BINDIR}/pnglibconf.tf4" "${BINDIR}/pnglibconf.tf5")
56*a67afe4dSAndroid Build Coastguard Worker
57*a67afe4dSAndroid Build Coastguard Worker  execute_process(COMMAND "${AWK}" -f "${SRCDIR}/scripts/options.awk"
58*a67afe4dSAndroid Build Coastguard Worker                  out=pnglibconf.tf4 version=search
59*a67afe4dSAndroid Build Coastguard Worker                  ${SRCDIR}/pngconf.h ${SRCDIR}/scripts/pnglibconf.dfa
60*a67afe4dSAndroid Build Coastguard Worker                  ${SRCDIR}/pngusr.dfa ${DFA_XTRA}
61*a67afe4dSAndroid Build Coastguard Worker                  WORKING_DIRECTORY "${BINDIR}"
62*a67afe4dSAndroid Build Coastguard Worker                  RESULT_VARIABLE AWK_FAIL)
63*a67afe4dSAndroid Build Coastguard Worker  if(AWK_FAIL)
64*a67afe4dSAndroid Build Coastguard Worker    message(FATAL_ERROR "Failed to generate pnglibconf.tf4")
65*a67afe4dSAndroid Build Coastguard Worker  endif()
66*a67afe4dSAndroid Build Coastguard Worker
67*a67afe4dSAndroid Build Coastguard Worker  execute_process(COMMAND "${AWK}" -f "${SRCDIR}/scripts/options.awk"
68*a67afe4dSAndroid Build Coastguard Worker                  out=pnglibconf.tf5 pnglibconf.tf4
69*a67afe4dSAndroid Build Coastguard Worker                  WORKING_DIRECTORY "${BINDIR}"
70*a67afe4dSAndroid Build Coastguard Worker                  RESULT_VARIABLE AWK_FAIL)
71*a67afe4dSAndroid Build Coastguard Worker  if(AWK_FAIL)
72*a67afe4dSAndroid Build Coastguard Worker    message(FATAL_ERROR "Failed to generate pnglibconf.tf5")
73*a67afe4dSAndroid Build Coastguard Worker  endif()
74*a67afe4dSAndroid Build Coastguard Worker
75*a67afe4dSAndroid Build Coastguard Worker  file(REMOVE "pnglibconf.tf4")
76*a67afe4dSAndroid Build Coastguard Worker  file(MAKE_DIRECTORY "${BINDIR}/scripts")
77*a67afe4dSAndroid Build Coastguard Worker  file(RENAME "pnglibconf.tf5" "${BINDIR}/pnglibconf.c")
78*a67afe4dSAndroid Build Coastguard Worker
79*a67afe4dSAndroid Build Coastguard Workerelseif(OUTPUT STREQUAL "pnglibconf.h")
80*a67afe4dSAndroid Build Coastguard Worker  # Generate pnglibconf.h
81*a67afe4dSAndroid Build Coastguard Worker
82*a67afe4dSAndroid Build Coastguard Worker  file(REMOVE "${BINDIR}/${OUTPUT}")
83*a67afe4dSAndroid Build Coastguard Worker  if(PNG_PREFIX)
84*a67afe4dSAndroid Build Coastguard Worker    file(REMOVE "pnglibconf.tf8")
85*a67afe4dSAndroid Build Coastguard Worker
86*a67afe4dSAndroid Build Coastguard Worker    execute_process(COMMAND "${AWK}" "s==0 && NR>1{print prev}
87*a67afe4dSAndroid Build Coastguard Worker                             s==0{prev=\$0}
88*a67afe4dSAndroid Build Coastguard Worker                             s==1{print \"#define\", \$1, \"${PNG_PREFIX}\" \$1}
89*a67afe4dSAndroid Build Coastguard Worker                             s==2{print \"#define ${PNG_PREFIX}png_\" \$1, \"PNG_\" \$1}
90*a67afe4dSAndroid Build Coastguard Worker                             END{print prev}" s=0 pnglibconf.out s=1 "${BINDIR}/scripts/prefix.out"
91*a67afe4dSAndroid Build Coastguard Worker                             s=2 "${SRCDIR}/scripts/macro.lst"
92*a67afe4dSAndroid Build Coastguard Worker                    OUTPUT_FILE pnglibconf.tf8
93*a67afe4dSAndroid Build Coastguard Worker                    RESULT_VARIABLE AWK_FAIL)
94*a67afe4dSAndroid Build Coastguard Worker    if(AWK_FAIL)
95*a67afe4dSAndroid Build Coastguard Worker      message(FATAL_ERROR "Failed to generate pnglibconf.tf8")
96*a67afe4dSAndroid Build Coastguard Worker    endif()
97*a67afe4dSAndroid Build Coastguard Worker
98*a67afe4dSAndroid Build Coastguard Worker    file(RENAME "pnglibconf.tf8" "${BINDIR}/${OUTPUT}")
99*a67afe4dSAndroid Build Coastguard Worker  else()
100*a67afe4dSAndroid Build Coastguard Worker    execute_process(COMMAND "${CMAKE_COMMAND}" -E copy "${BINDIR}/pnglibconf.out"
101*a67afe4dSAndroid Build Coastguard Worker                                                       "${BINDIR}/${OUTPUT}"
102*a67afe4dSAndroid Build Coastguard Worker                    RESULT_VARIABLE COPY_FAIL)
103*a67afe4dSAndroid Build Coastguard Worker    if(COPY_FAIL)
104*a67afe4dSAndroid Build Coastguard Worker      message(FATAL_ERROR "Failed to create pnglibconf.h")
105*a67afe4dSAndroid Build Coastguard Worker    endif()
106*a67afe4dSAndroid Build Coastguard Worker  endif()
107*a67afe4dSAndroid Build Coastguard Worker
108*a67afe4dSAndroid Build Coastguard Workerelseif(OUTPUT STREQUAL "pngprefix.h")
109*a67afe4dSAndroid Build Coastguard Worker  # Generate pngprefix.h
110*a67afe4dSAndroid Build Coastguard Worker
111*a67afe4dSAndroid Build Coastguard Worker  file(REMOVE "${BINDIR}/${OUTPUT}")
112*a67afe4dSAndroid Build Coastguard Worker
113*a67afe4dSAndroid Build Coastguard Worker  if(PNG_PREFIX)
114*a67afe4dSAndroid Build Coastguard Worker    file(REMOVE "pngprefix.tf1")
115*a67afe4dSAndroid Build Coastguard Worker
116*a67afe4dSAndroid Build Coastguard Worker    execute_process(COMMAND "${AWK}"
117*a67afe4dSAndroid Build Coastguard Worker                            "{print \"#define\", \$1, \"${PNG_PREFIX}\" \$1}"
118*a67afe4dSAndroid Build Coastguard Worker                            "${BINDIR}/scripts/intprefix.out"
119*a67afe4dSAndroid Build Coastguard Worker                    OUTPUT_FILE "pngprefix.tf1"
120*a67afe4dSAndroid Build Coastguard Worker                    RESULT_VARIABLE AWK_FAIL)
121*a67afe4dSAndroid Build Coastguard Worker    if(AWK_FAIL)
122*a67afe4dSAndroid Build Coastguard Worker      message(FATAL_ERROR "Failed to generate pngprefix.tf1")
123*a67afe4dSAndroid Build Coastguard Worker    endif()
124*a67afe4dSAndroid Build Coastguard Worker
125*a67afe4dSAndroid Build Coastguard Worker    file(RENAME "pngprefix.tf1" "${BINDIR}/${OUTPUT}")
126*a67afe4dSAndroid Build Coastguard Worker  else()
127*a67afe4dSAndroid Build Coastguard Worker    file(WRITE "${BINDIR}/${OUTPUT}" "/* No libpng symbol prefix configured. */")
128*a67afe4dSAndroid Build Coastguard Worker  endif()
129*a67afe4dSAndroid Build Coastguard Worker
130*a67afe4dSAndroid Build Coastguard Workerelseif(OUTPUT STREQUAL "scripts/pnglibconf.h.prebuilt")
131*a67afe4dSAndroid Build Coastguard Worker  # Generate scripts/pnglibconf.h.prebuilt (fails build)
132*a67afe4dSAndroid Build Coastguard Worker
133*a67afe4dSAndroid Build Coastguard Worker  message(STATUS "Attempting to build scripts/pnglibconf.h.prebuilt")
134*a67afe4dSAndroid Build Coastguard Worker  message(STATUS "This is a machine generated file, but if you want to make")
135*a67afe4dSAndroid Build Coastguard Worker  message(STATUS "a new one simply build the 'png_genfiles' target, and copy")
136*a67afe4dSAndroid Build Coastguard Worker  message(STATUS "scripts/pnglibconf.out to scripts/pnglibconf.h.prebuilt")
137*a67afe4dSAndroid Build Coastguard Worker  message(STATUS "AND set PNG_ZLIB_VERNUM to 0 (you MUST do this)")
138*a67afe4dSAndroid Build Coastguard Worker  message(FATAL_ERROR "Stopping build")
139*a67afe4dSAndroid Build Coastguard Worker
140*a67afe4dSAndroid Build Coastguard Workerelse()
141*a67afe4dSAndroid Build Coastguard Worker
142*a67afe4dSAndroid Build Coastguard Worker  message(FATAL_ERROR "Unsupported output: ${OUTPUT}")
143*a67afe4dSAndroid Build Coastguard Worker
144*a67afe4dSAndroid Build Coastguard Workerendif()
145