1#!/bin/env python
2#
3# script to generate ldf_jb2.mak
4# whose source sometimes changes
5
6# $Id: gen_ldf_jb2.py 8022 2007-06-05 22:23:38Z giles $
7
8import time, glob
9import os.path
10
11outfile="ldf_jb2.mak"
12
13license = """#    Copyright (C) %d Artifex Software, Inc.  All rights reserved.
14#
15# This software is provided AS-IS with no warranty, either express or
16# implied.
17#
18# This software is distributed under license and may not be copied,
19# modified or distributed except as expressly authorized under the terms
20# of the license contained in the file LICENSE in this distribution.
21#
22# For more information about licensing, please refer to
23# http://www.ghostscript.com/licensing/. For information on
24# commercial licensing, go to http://www.artifex.com/licensing/ or
25# contact Artifex Software, Inc., 101 Lucas Valley Road #110,
26# San Rafael, CA  94903, U.S.A., +1(415)492-9861.
27
28# $Id: gen_ldf_jb2.py 8022 2007-06-05 22:23:38Z giles $
29""" % time.gmtime().tm_year
30
31comment = """
32# makefile for Luratech ldf_jb2 library code.
33# Users of this makefile must define the following:
34#       SHARE_JBIG2 - whether to compile in or link to the library
35#       JBIG2SRCDIR - the library source directory
36#
37# gs.mak and friends define the following:
38#       JBIG2OBJDIR - the output obj directory
39#       JBIG2GENDIR - generated (.dev) file directory
40#       LDF_JB2I_ - include path for the library
41#       JB2CF_ - cflags for building the library
42#
43# We define the ldf_jb2.dev target and its dependencies
44#
45# This partial makefile compiles the ldf_jb2 library for use in
46# Ghostscript.
47"""
48
49common = """
50LDF_JB2_MAK=$(GLSRC)%s
51
52LDF_JB2_SRC=$(JBIG2SRCDIR)$(D)
53LDF_JB2_GEN=$(JBIG2OBJDIR)$(D)
54LDF_JB2_OBJ=$(JBIG2OBJDIR)$(D)
55
56# paths to source directories
57LDF_JB2_COMMON=$(JBIG2SRCDIR)$(D)source$(D)common$(D)
58LDF_JB2_COMPRESS=$(JBIG2SRCDIR)$(D)source$(D)compress$(D)
59""" % outfile
60
61dev = """
62ldf_jb2_OBJS=$(ldf_jb2_common_OBJS) $(ldf_jb2_compress_OBJS)
63ldf_jb2_HDRS=$(ldf_jb2_common_HDRS) $(ldf_jb2_compress_HDRS)
64
65# switch in the selected library .dev
66$(LDF_JB2_GEN)ldf_jb2.dev : $(TOP_MAKEFILES) $(LDF_JB2_MAK) $(LDF_JB2_GEN)ldf_jb2_$(SHARE_JBIG2).dev
67	$(CP_) $(LDF_JB2_GEN)ldf_jb2_$(SHARE_JBIG2).dev $(LDF_JB2_GEN)ldf_jb2.dev
68
69# external link .dev
70$(LDF_JB2_GEN)ldf_jb2_1.dev : $(TOP_MAKEFILES) $(LDF_JB2_MAK) $(ECHOGS_XE)
71	$(SETMOD) $(LDF_JB2_GEN)ldf_jb2_1 -lib ldf_jb2
72
73# compile our own .dev
74$(LDF_JB2_GEN)ldf_jb2_0.dev : $(TOP_MAKEFILES) $(LDF_JB2_MAK) $(ECHOGS_XE) $(ldf_jb2_OBJS)
75	$(SETMOD) $(LDF_JB2_GEN)ldf_jb2_0 $(ldf_jb2_common_OBJS)
76	$(ADDMOD) $(LDF_JB2_GEN)ldf_jb2_0 $(ldf_jb2_compress_OBJS)
77
78# define our specific compiler
79LDF_JB2_CC=$(CC_) $(I_)$(LDF_JB2I_) $(II)$(LDF_JB2_COMMON) $(II)$(LDF_JB2_COMPRESS)$(_I) $(JB2CF_)
80LDF_JB2_O=$(O_)$(LDF_JB2_OBJ)
81
82LDF_JB2_DEP=$(AK) $(LDF_JB2_MAK)
83"""
84
85common_srcs = glob.glob("ldf_jb2/source/common/*.c")
86common_srcs.sort()
87common_hdrs = glob.glob("ldf_jb2/source/common/*.h")
88common_hdrs.sort()
89compress_srcs = glob.glob("ldf_jb2/source/compress/*.c")
90compress_srcs.sort()
91compress_hdrs = glob.glob("ldf_jb2/source/compress/*.h")
92compress_srcs.sort()
93
94source = """
95# source files to build from the CSDK source
96"""
97
98source += """
99ldf_jb2_common_OBJS = \\
100"""
101for file in common_srcs:
102    name = os.path.splitext(os.path.basename(file))[0]
103    source += "\t$(LDF_JB2_OBJ)%s.$(OBJ)" % name
104    if file != common_srcs[-1]: source += "\t\t\\"
105    source += "\n"
106
107source += """
108ldf_jb2_compress_OBJS = \\
109"""
110for file in compress_srcs:
111    name = os.path.splitext(os.path.basename(file))[0]
112    source += "\t$(LDF_JB2_OBJ)%s.$(OBJ)" % name
113    if file != compress_srcs[-1]: source += "\t\t\\"
114    source += "\n"
115
116source += """
117ldf_jb2_common_HDRS = \\
118"""
119for file in common_hdrs:
120    source += "\t$(LDF_JB2_COMMON)%s" % os.path.basename(file)
121    if file != common_hdrs[-1]: source += "\t\t\\"
122    source += "\n"
123
124source += """
125ldf_jb2_compress_HDRS = \\
126"""
127for file in compress_hdrs:
128    source += "\t$(LDF_JB2_COMPRESS)%s" % os.path.basename(file)
129    if file != compress_hdrs[-1]: source += "\t\t\\"
130    source += "\n"
131
132
133rules = """
134# explicit rules for building each source file
135# for simplicity we have every source file depend on all headers
136
137"""
138
139for file in common_srcs:
140    cfile = os.path.basename(file)
141    name = os.path.splitext(cfile)[0]
142    rules += "$(LDF_JB2_OBJ)%s.$(OBJ)" % name
143    rules += " : $(LDF_JB2_COMMON)%s" % cfile
144    rules += " $(LDF_JB2_DEP) $(ldf_jb2_HDRS)\n"
145    rules += "\t$(LDF_JB2_CC) $(LDF_JB2_O)%s.$(OBJ)" % name
146    rules += " $(C_) $(LDF_JB2_COMMON)%s\n" % cfile
147    rules += "\n"
148
149for file in compress_srcs:
150    cfile = os.path.basename(file)
151    name = os.path.splitext(cfile)[0]
152    rules += "$(LDF_JB2_OBJ)%s.$(OBJ)" % name
153    rules += " : $(LDF_JB2_COMPRESS)%s" % cfile
154    rules += " $(LDF_JB2_DEP) $(ldf_jb2_HDRS)\n"
155    rules += "\t$(LDF_JB2_CC) $(LDF_JB2_O)%s.$(OBJ)" % name
156    rules += " $(C_) $(LDF_JB2_COMPRESS)%s\n" % cfile
157    rules += "\n"
158
159
160
161print license + comment + common
162print source
163print dev
164print rules
165print "# end of file"
166