Changeset 4952


Ignore:
Timestamp:
Nov 21, 2009, 7:54:02 PM (6 years ago)
Author:
oxygene
Message:

Make the kconfig-style build work in mingw:

  • use relative paths in ldscript.ld and crt0_includes.h
  • avoid use of dd(1) in xcompile
  • build libregex for kconfig, if necessary
  • work around missing utsname on win32
  • unlink targets before rename on win32
  • implement (crude) mkstemp for win32
  • avoid open/read/close, use fopen/fread/fclose instead
  • don't free certain data structures in romcc on win32 to avoid crashes (likely use-after-free())
  • handle "\CRLF" and win32 style absolute paths (X:/ or X:\) in romcc
  • make lzma (part of cbfstool) build on XP
  • implement ntohl/htonl on win32
  • handle CRLF in awk script
  • set larger stack for romcc on win32

Signed-off-by: Patrick Georgi <patrick.georgi@…>
Acked-by: Peter Stuge <peter@…>

Location:
trunk
Files:
2 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Makefile

    r4939 r4952  
    312312
    313313$(obj)/ldoptions: $(obj)/config.h
    314 #       cat $(obj)/config.h  | grep -v \" |grep -v AUTOCONF_INCLUDED | grep \#define | sed s/\#define\ // | sed s/\ /\ =\ / | sed 's/$$/;/' > $(obj)/ldoptions
    315         awk '/^#define ([^"])* ([^"])*$$/ {print $$2 " = " $$3 ";";}' $< > $@
    316 
     314        awk '/^#define ([^"])* ([^"])*$$/ {gsub("\\r","",$$3); print $$2 " = " $$3 ";";}' $< > $@
     315
     316_OS=$(shell uname -s |cut -c-7)
     317STACK=
     318ifeq ($(_OS),MINGW32)
     319        STACK=-Wl,--stack,16384000
     320endif
     321ifeq ($(_OS),CYGWIN_)
     322        STACK=-Wl,--stack,16384000
     323endif
    317324$(obj)/romcc: $(top)/util/romcc/romcc.c
    318325        @printf "    HOSTCC     $(subst $(obj)/,,$(@)) (this may take a while)\n"
    319         $(HOSTCC) -g -O2 -Wall -o $@ $<
     326        $(HOSTCC) -g -O2 $(STACK) -Wall -o $@ $<
    320327
    321328.PHONY: $(PHONY) prepare prepare2 clean distclean doxygen doxy coreboot
  • trunk/src/arch/i386/Makefile.inc

    r4934 r4952  
    4444$(obj)/ldscript.ld: $(ldscripts) $(obj)/ldoptions
    4545        printf 'INCLUDE "ldoptions"\n' > $@
    46         printf '$(foreach ldscript,$(ldscripts),INCLUDE "$(ldscript)"\n)' >> $@
     46        printf '$(foreach ldscript,$(ldscripts),INCLUDE "$(ldscript:$(obj)/%=%)"\n)' >> $@
    4747
    4848$(obj)/crt0_includes.h: $(crt0s)
    49         printf '$(foreach crt0,$(obj)/config.h $(crt0s),#include "$(crt0)"\n)' > $@
     49        printf '$(foreach crt0,config.h $(crt0s),#include "$(crt0:$(obj)/%=%)"\n)' > $@
    5050
    5151$(obj)/mainboard/$(MAINBOARDDIR)/crt0.o: $(obj)/mainboard/$(MAINBOARDDIR)/crt0.s
  • trunk/util/cbfstool/cbfs-mkpayload.c

    r4678 r4952  
    2828#include <getopt.h>
    2929#include <sys/stat.h>
    30 #include <arpa/inet.h>
    3130
    3231#include "common.h"
  • trunk/util/cbfstool/common.h

    r4929 r4952  
    1818
    1919#include <stdint.h>
     20#ifndef WIN32
     21#include <arpa/inet.h>
     22#else
     23#define ntohl(x) (((x)>>24) | ((x)<<24) | (((x)>>8)&0xff00) | (((x)<<8)&0xff0000))
     24#define htonl ntohl
     25#endif
    2026
    2127extern void *offset;
  • trunk/util/cbfstool/lzma/C/Common/Alloc.cpp

    r4250 r4952  
    9797  {
    9898    void *res = ::VirtualAlloc(0, (size + g_LargePageSize - 1) & (~(g_LargePageSize - 1)),
    99         MEM_COMMIT | MEM_LARGE_PAGES, PAGE_READWRITE);
     99        MEM_COMMIT, PAGE_READWRITE);
    100100    if (res != 0)
    101101      return res;
  • trunk/util/kconfig/Makefile

    r4581 r4952  
    44
    55PHONY += oldconfig xconfig gconfig menuconfig config silentoldconfig update-po-config
     6
     7_OS=$(shell uname -s |cut -c-7)
     8regex-objs=
     9ifeq ($(_OS),MINGW32)
     10        regex-objs=regex.o
     11endif
    612
    713Kconfig := src/Kconfig
     
    114120lxdialog += lxdialog/textbox.o lxdialog/yesno.o lxdialog/menubox.o
    115121
    116 conf-objs       := conf.o  zconf.tab.o
    117 mconf-objs      := mconf.o zconf.tab.o $(lxdialog)
     122conf-objs       := conf.o  zconf.tab.o $(regex-objs)
     123mconf-objs      := mconf.o zconf.tab.o $(lxdialog) $(regex-objs)
    118124kxgettext-objs  := kxgettext.o zconf.tab.o
    119125
     
    134140ifeq ($(qconf-target),1)
    135141qconf-cxxobjs   := qconf.o
    136 qconf-objs      := kconfig_load.o zconf.tab.o
     142qconf-objs      := kconfig_load.o zconf.tab.o $(regex-objs)
    137143endif
    138144
    139145ifeq ($(gconf-target),1)
    140 gconf-objs      := gconf.o kconfig_load.o zconf.tab.o
     146gconf-objs      := gconf.o kconfig_load.o zconf.tab.o $(regex-objs)
    141147endif
    142148
     
    307313$(objk)/conf.o: $(srck)/conf.c
    308314        $(HOSTCC) $(HOSTCFLAGS) $(HOST_EXTRACFLAGS) -c -o $@ $<
     315$(objk)/regex.o: $(srck)/regex.c
     316        $(HOSTCC) $(HOSTCFLAGS) $(HOST_EXTRACFLAGS) -DHAVE_STRING_H -c -o $@ $<
    309317
    310318$(objk)/zconf.tab.o: $(objk)/zconf.tab.c $(objk)/lex.zconf.c \
  • trunk/util/kconfig/confdata.c

    r4534 r4952  
    1515#define LKC_DIRECT_LINK
    1616#include "lkc.h"
     17
     18#ifdef WIN32
     19#define mkdir(x,y) mkdir(x)
     20#define UNLINK_IF_NECESSARY(x) unlink(x)
     21#else
     22#define UNLINK_IF_NECESSARY(X)
     23#endif
    1724
    1825static void conf_warning(const char *fmt, ...)
     
    540547                strcat(dirname, basename);
    541548                strcat(dirname, ".old");
     549                UNLINK_IF_NECESSARY(dirname);
    542550                rename(newname, dirname);
    543551                if (rename(tmpname, newname))
     
    776784        if (!name)
    777785                name = "include/linux/autoconf.h";
     786        UNLINK_IF_NECESSARY(name);
    778787        if (rename(".tmpconfig.h", name))
    779788                return 1;
     
    785794         * and this marks the successful completion of the previous steps.
    786795         */
     796        UNLINK_IF_NECESSARY(name);
    787797        if (rename(".tmpconfig", name))
    788798                return 1;
  • trunk/util/kconfig/symbol.c

    r4534 r4952  
    88#include <string.h>
    99#include <regex.h>
     10#ifndef WIN32
    1011#include <sys/utsname.h>
     12#endif
    1113
    1214#define LKC_DIRECT_LINK
     
    4749{
    4850        struct symbol *sym;
     51#ifndef WIN32
    4952        struct utsname uts;
     53#endif
    5054        static bool inited = false;
    5155
     
    5458        inited = true;
    5559
     60#ifndef WIN32
    5661        uname(&uts);
     62#endif
    5763
    5864        sym = sym_lookup("UNAME_RELEASE", 0);
    5965        sym->type = S_STRING;
    6066        sym->flags |= SYMBOL_AUTO;
     67#ifndef WIN32
    6168        sym_add_default(sym, uts.release);
     69#else
     70        sym_add_default(sym, "");
     71#endif
    6272}
    6373
  • trunk/util/options/build_opt_tbl.c

    r4684 r4952  
    2222static unsigned char clip[9]={0,1,3,7,0x0f,0x1f,0x3f,0x7f,0xff};
    2323
     24#ifdef WIN32
     25#include <fcntl.h>
     26char* mkstemp(char* name) {
     27        static char val='0';
     28        char *c=name;
     29        while (*c!='X') c++;
     30        *c=val++;
     31        return open(name,O_CREAT | O_RDWR);
     32}
     33#define UNLINK_IF_NECESSARY(x) unlink(x)
     34#else
     35#define UNLINK_IF_NECESSARY(x)
     36#endif
    2437
    2538/* This routine loops through the entried and tests if any of the fields overlap
     
    532545
    533546                fclose(fp);
     547                UNLINK_IF_NECESSARY(option);
    534548                if (rename(tmpfilename, option)) {
    535549                        fprintf(stderr, "Error - Could not write %s: ", option);
     
    585599                fclose(fp);
    586600
     601                UNLINK_IF_NECESSARY(header);
    587602                if (rename(tmpfilename, header)) {
    588603                        fprintf(stderr, "Error - Could not write %s: ", header);
  • trunk/util/romcc/romcc.c

    r4938 r4952  
    220220{
    221221        char cwd[MAX_CWD_SIZE];
    222         int fd;
    223222        char *buf;
    224223        off_t size, progress;
    225224        ssize_t result;
    226         struct stat stats;
     225        FILE* file;
    227226       
    228227        if (!filename) {
     
    234233        }
    235234        xchdir(dirname);
    236         fd = open(filename, O_RDONLY);
     235        file = fopen(filename, "rb");
    237236        xchdir(cwd);
    238         if (fd < 0) {
     237        if (file == NULL) {
    239238                die("Cannot open '%s' : %s\n",
    240239                        filename, strerror(errno));
    241240        }
    242         result = fstat(fd, &stats);
    243         if (result < 0) {
    244                 die("Cannot stat: %s: %s\n",
    245                         filename, strerror(errno));
    246         }
    247         size = stats.st_size;
     241        fseek(file, 0, SEEK_END);
     242        size = ftell(file);
     243        fseek(file, 0, SEEK_SET);
    248244        *r_size = size +1;
    249245        buf = xmalloc(size +2, filename);
     
    252248        progress = 0;
    253249        while(progress < size) {
    254                 result = read(fd, buf + progress, size - progress);
     250                result = fread(buf + progress, 1, size - progress, file);
    255251                if (result < 0) {
    256252                        if ((errno == EINTR) || (errno == EAGAIN))
     
    261257                progress += result;
    262258        }
    263         result = close(fd);
    264         if (result < 0) {
    265                 die("Close of %s failed: %s\n",
    266                         filename, strerror(errno));
    267         }
     259        fclose(file);
    268260        return buf;
    269261}
     
    38643856                /* Is this an escaped newline? */
    38653857                if (file->join_lines &&
    3866                         (c == '\\') && (pos + size < end) && (pos[1] == '\n'))
     3858                        (c == '\\') && (pos + size < end) && ((pos[1] == '\n') || ((pos[1] == '\r') && (pos[2] == '\n'))))
    38673859                {
     3860                        int cr_offset = ((pos[1] == '\r') && (pos[2] == '\n'))?1:0;
    38683861                        /* At the start of a line just eat it */
    38693862                        if (pos == file->pos) {
    38703863                                file->line++;
    38713864                                file->report_line++;
    3872                                 file->line_start = pos + size + 1;
    3873                         }
    3874                         pos += size + 1;
     3865                                file->line_start = pos + size + 1 + cr_offset;
     3866                        }
     3867                        pos += size + 1 + cr_offset;
    38753868                }
    38763869                /* Do I need to ga any farther? */
     
    50895082                die("cwd buffer to small");
    50905083        }
    5091         if (subdir[0] == '/') {
     5084        if ((subdir[0] == '/') || ((subdir[1] == ':') && ((subdir[2] == '/') || (subdir[2] == '\\')))) {
    50925085                file->dirname = xmalloc(subdir_len + 1, "dirname");
    50935086                memcpy(file->dirname, subdir, subdir_len);
     
    1514915142        }
    1515015143        memset(block, -1, sizeof(*block));
     15144#ifndef WIN32
    1515115145        xfree(block);
     15146#endif
    1515215147}
    1515315148
  • trunk/util/xcompile/xcompile

    r4902 r4952  
    88
    99GCCPREFIX=invalid
    10 TMP=`mktemp /tmp/temp.XXXX`
     10TMP=`mktemp /tmp/temp.XXXX 2>/dev/null || echo /tmp/temp.78gOIUGz`
    1111echo "mov %eax, %eax" > ${TMP}.s
    12 printf "\x7fELF" > ${TMP}.compare
     12printf "\x7fELF\n" > ${TMP}.compare
    1313for gccprefixes in `pwd`/util/crossgcc/xgcc/bin/i386-elf- i386-elf- ""; do
    1414        if which ${gccprefixes}as 2>/dev/null >/dev/null; then
     
    1919        rm -f ${TMP}.o
    2020        if ${gccprefixes}as --32 -o ${TMP}.o ${TMP}.s; then
    21                 dd bs=4 count=1 if=${TMP}.o > ${TMP}.test 2>/dev/null
     21                cut -c-4 ${TMP}.o > ${TMP}.test 2>/dev/null
    2222                if cmp ${TMP}.test ${TMP}.compare; then
    2323                        GCCPREFIX=$gccprefixes
Note: See TracChangeset for help on using the changeset viewer.