1 |
Donnie Berkholz writes: |
2 |
|
3 |
> You've discovered that to get all the |
4 |
> conditionals right, you need to write a shell parser, or somehow run the |
5 |
> code rather than parsing it to get the result, or punt on the problem. |
6 |
> |
7 |
I've written (a so far) very simple parser to handle the if statments. |
8 |
This does however take for granted that the if statements uses "test" to |
9 |
do for returning True/False. I'm waiting a bit to flesh it out to see if |
10 |
the approach I currently thinking about implementing works. |
11 |
|
12 |
I'm thinking about a structure something like this: |
13 |
|
14 |
I will parse the autoconf file and have all variables stored like this: |
15 |
{"variable" : {"with_a" : "what ever 'variable' was defined as" , "!with_b" |
16 |
: ...}} |
17 |
(Note that with_a == with_a="yes" and !with_b == with_b="no") |
18 |
|
19 |
So when the variable turns up in the automake files it will know what |
20 |
switches can affect that variable and then see what extra files it pulls |
21 |
in. |
22 |
|
23 |
If the variable doesn't pull in files directly (I.E subdirs) I will just |
24 |
scan the automake file in the new subdir(s) and the the files they pull in |
25 |
to that switch/useflag. |
26 |
I will store the information kinda like I do with includes: |
27 |
{"useflag" : [["list of files it pulls in"], {"dict with useflags"}]} |
28 |
|
29 |
The last dict will have the same structure as the first one so I cover |
30 |
nested useflags. |
31 |
Then I will then scan files for includes and link them to deps and use |
32 |
them with the useflags in the ebuild. |
33 |
|
34 |
The problem I have now is those checks in the autoconf files that checks |
35 |
for files/libs on the system. |
36 |
For example: |
37 |
|
38 |
if test "$with_a"; then |
39 |
AC_CHECK_HEADERS([a.h]) |
40 |
AC_CHECK_LIB([a],[new_awesome_call]) |
41 |
if test "$ac_cv_header_aheader_h" = "yes" |
42 |
then |
43 |
dnl this works with every version of "a" |
44 |
dnl Add the basic stuff |
45 |
EXTRA_OBJS="$EXTRA_OBJS a_basic.o" |
46 |
if test "$ac_cv_lib_a_new_awesome_call" = "yes" |
47 |
then |
48 |
dnl goodies supported in the new version |
49 |
EXTRA_OBJS="$EXTRA_OBJS a_extra.o" |
50 |
fi |
51 |
fi |
52 |
fi |
53 |
|
54 |
I might check the header files against a database to see what package they |
55 |
belong to and what version and do it that way. |
56 |
However I have no idea what to do with "AC_CHECK_LIB" that "probes" the |
57 |
lib with a function call to see if it's there. |
58 |
|
59 |
> Here are some ways you could do those things: |
60 |
> |
61 |
> Option 1. (Write a parser) See libbash. Not sure how it will work with |
62 |
> the m4 mixed in, you might need to run autoconf and check the generated |
63 |
> configure script instead. |
64 |
> |
65 |
Most if the shell scripting seem to be kept as a fairly simple level in |
66 |
the autoconf files. Granted to have really good support it should be able |
67 |
to correctly parse all shell scripts. |
68 |
But I hope I can get away with supporting the most common stuff inside if |
69 |
and case statments. |
70 |
|
71 |
> Option 2a. (Run the code) Save code until you get to some variable/macro |
72 |
> you recognize is important because it's used during the build (e.g. |
73 |
> LIBS, *_LIBS), then run everything around it. It may also be useful to |
74 |
> notice when files are mentioned and save a separate list of them. You |
75 |
> might need to trap file access, e.g. using Alex's script for dependency |
76 |
> discovery. |
77 |
> |
78 |
Hmm. I don't really know if running the code is a good idea as stuff that |
79 |
is not installed will be left out I think. |
80 |
Take for example a program with different sound backends. |
81 |
I use OSS4 because my sound card doesn't work with ALSA. So if I run the |
82 |
code it would only detect optional deps for OSS4 and the ALSA checks will |
83 |
fail in the autoconf file and not pull in anything. |
84 |
|
85 |
> Option 3. (Punt) Pretend everything is mandatory. Don't handle USE flags |
86 |
> at all, just put everything as a required dependency. Or, you could |
87 |
> notice that a feature is optional and add a USE flag to build it; but |
88 |
> say that the design of your tool doesn't allow for optional dependency |
89 |
> detection so developers will need to split those out of the full |
90 |
> dependency list. |
91 |
> |
92 |
Well I can definitely have useflags but don't link them to any deps as I |
93 |
can check what can be switched on/off in the autoconf file and then guess |
94 |
if they use any non standard assingments. I.E --with_lib="version2". |
95 |
|
96 |
I would really like my generator guess what deps useflags pull in. |
97 |
But if it's too troublesome I'll skip it for now so it can atleast |
98 |
generate an ebuild that pulls in everything for autoconf projects. |