~ubuntu-branches/ubuntu/oneiric/oss4/oneiric-proposed

« back to all changes in this revision

Viewing changes to setup/dirsetup.c

  • Committer: Bazaar Package Importer
  • Author(s): Stefano Rivera
  • Date: 2011-06-16 20:37:48 UTC
  • mfrom: (5.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110616203748-jbrxik6ql33z54co
Tags: 4.2-build2004-1ubuntu1
* Merge from Debian unstable.
  - Supports our current kernel (LP: #746048)
  Remaining changes:
  - debian/oss4-dkms.dkms.in: s/source/build/ in Kernel headers paths.
* ld-as-needed.patch: Re-order CC arguments to enable building with ld
  --as-needed (LP: #770972)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *
 
3
 * This file is part of Open Sound System.
 
4
 *
 
5
 * Copyright (C) 4Front Technologies 1996-2008.
 
6
 *
 
7
 * This this source file is released under GPL v2 license (no other versions).
 
8
 * See the COPYING file included in the main directory of this source
 
9
 * distribution for the license terms and conditions.
 
10
 *
 
11
 */
 
12
 
 
13
#include <stdio.h>
 
14
#include <stdlib.h>
 
15
#include <unistd.h>
 
16
#include <string.h>
 
17
#include <fcntl.h>
 
18
#include <sys/types.h>
 
19
#include <sys/stat.h>
 
20
#include <dirent.h>
 
21
#include <time.h>
 
22
 
 
23
#if PATH_MAX == -1                                      
 
24
#undef PATH_MAX                                           
 
25
#endif
 
26
#ifndef PATH_MAX                                          
 
27
#define PATH_MAX 1024                                     
 
28
#endif
 
29
 
 
30
char *srcdir = NULL, *blddir = NULL;
 
31
int verbose = 0, copy_files = 0;
 
32
struct stat bld_stat, src_stat;
 
33
 
 
34
static void
 
35
copy_file (char *sname, char *tname, char *pname, int native_make)
 
36
{
 
37
  char *p;
 
38
  int in_fd, out_fd, l;
 
39
 
 
40
  unsigned char buf[4096];
 
41
 
 
42
  if (strcmp (pname, ".depend") == 0)
 
43
    return;
 
44
 
 
45
  if (!native_make)
 
46
    if (strncmp (pname, "Makefile", 8) == 0)
 
47
      return;
 
48
 
 
49
  if (strlen (pname) > 6)
 
50
    {
 
51
      p = pname + strlen (pname) - 6;   /* Seek to the _cfg.[c-h] suffix */
 
52
      if (strcmp (p, "_cfg.c") == 0)
 
53
        return;
 
54
      if (strcmp (p, "_cfg.h") == 0)
 
55
        return;
 
56
    }
 
57
 
 
58
  if (!copy_files)
 
59
  {
 
60
     symlink (sname, tname);
 
61
     return;
 
62
  }
 
63
 
 
64
  if ((in_fd=open(sname, O_RDONLY, 0))==-1)
 
65
     {
 
66
             perror(sname);
 
67
             exit(-1);
 
68
     }
 
69
 
 
70
  if ((out_fd=creat(tname, 0644))==-1)
 
71
     {
 
72
             perror(tname);
 
73
             exit(-1);
 
74
     }
 
75
 
 
76
  while ((l=read(in_fd, buf, sizeof(buf)))>0)
 
77
  {
 
78
          if (write(out_fd, buf, l)!=l)
 
79
             {
 
80
                     perror(tname);
 
81
                     exit(-1);
 
82
             }
 
83
  }
 
84
 
 
85
  if (l==-1)
 
86
     {
 
87
             perror(sname);
 
88
             exit(-1);
 
89
     }
 
90
 
 
91
  close(in_fd);
 
92
  close(out_fd);
 
93
}
 
94
 
 
95
static void
 
96
copy_tree (char *fromdir, char *tgtdir, int native_make)
 
97
{
 
98
  DIR *dir;
 
99
  struct dirent *de;
 
100
  struct stat st;
 
101
 
 
102
  if (tgtdir != NULL)
 
103
    {
 
104
      mkdir (tgtdir, 0700);
 
105
    }
 
106
 
 
107
  if ((dir = opendir (fromdir)) == NULL)
 
108
    {
 
109
      fprintf (stderr, "Bad source directory %s\n", fromdir);
 
110
      return;
 
111
    }
 
112
 
 
113
  while ((de = readdir (dir)) != NULL)
 
114
    {
 
115
      char sname[PATH_MAX+20], tname[PATH_MAX+20];
 
116
 
 
117
      sprintf (sname, "%s/%s", fromdir, de->d_name);
 
118
      if (tgtdir != NULL)
 
119
        sprintf (tname, "%s/%s", tgtdir, de->d_name);
 
120
      else
 
121
        sprintf (tname, "%s", de->d_name);
 
122
 
 
123
      if (stat (sname, &st) == -1)
 
124
        {
 
125
          perror (sname);
 
126
          exit (-1);
 
127
        }
 
128
 
 
129
      if ((st.st_dev == bld_stat.st_dev) && (st.st_ino == bld_stat.st_ino)) continue;
 
130
      if ((st.st_dev == src_stat.st_dev) && (st.st_ino == src_stat.st_ino)) continue;
 
131
 
 
132
      if (S_ISDIR (st.st_mode))
 
133
        {
 
134
          if (de->d_name[0] != '.')
 
135
            {
 
136
              char tmp[PATH_MAX+20];
 
137
              int is_native = 0;
 
138
              struct stat st2;
 
139
 
 
140
              sprintf (tmp, "%s/.nativemake", sname);
 
141
              if (stat (tmp, &st2) != -1)
 
142
                is_native = 1;
 
143
 
 
144
              sprintf (tmp, "%s/.nocopy", sname);
 
145
              if (stat (tmp, &st2) == -1)
 
146
                copy_tree (sname, tname, is_native);
 
147
            }
 
148
        }
 
149
      else
 
150
        {
 
151
          copy_file (sname, tname, de->d_name, native_make);
 
152
        }
 
153
    }
 
154
 
 
155
  closedir (dir);
 
156
}
 
157
 
 
158
int
 
159
main (int argc, char *argv[])
 
160
{
 
161
  int i;
 
162
  FILE *f;
 
163
 
 
164
  time_t t;
 
165
  struct tm *tm;
 
166
 
 
167
  if (argc < 3)
 
168
    {
 
169
      fprintf (stderr, "%s: Bad usage\n", argv[0]);
 
170
      exit (-1);
 
171
    }
 
172
 
 
173
  srcdir = argv[1];
 
174
  blddir = argv[2];
 
175
 
 
176
  if (stat (blddir, &bld_stat) == -1)
 
177
    {
 
178
      perror (blddir);
 
179
      exit (-1);
 
180
    }
 
181
 
 
182
  if (stat (srcdir, &src_stat) == -1)
 
183
    {
 
184
      perror (srcdir);
 
185
      exit (-1);
 
186
    }
 
187
 
 
188
  for (i = 3; i < argc; i++)
 
189
    {
 
190
      if (strcmp (argv[i], "-v") == 0)
 
191
        {
 
192
          verbose++;
 
193
          continue;
 
194
        }
 
195
 
 
196
      if (strcmp (argv[i], "-c") == 0)
 
197
        {
 
198
          copy_files = 1;
 
199
          continue;
 
200
        }
 
201
    }
 
202
 
 
203
  f = fopen (".nocopy", "w");
 
204
  fclose (f);
 
205
  copy_tree (srcdir, NULL, 0);
 
206
 
 
207
#if 0
 
208
  if ((f = fopen ("timestamp.h", "w")) == NULL)
 
209
    {
 
210
      perror ("timestamp.h");
 
211
      exit (-1);
 
212
    }
 
213
 
 
214
  time (&t);
 
215
  tm = gmtime (&t);
 
216
  fprintf (f, "#define OSS_COMPILE_DATE \"%04d%02d%02d%02d%02d\"\n",
 
217
           tm->tm_year + 1900,
 
218
           tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min);
 
219
 
 
220
  fclose (f);
 
221
#endif
 
222
 
 
223
  exit (0);
 
224
}