0

I used to do C programming in Linux. Now,I got MacBook and I want to do programming on the Mac.

How should I change the following makefile ?

# Makefile

OBJS = main

$(OBJS): $(OBJS).o
#   gcc -O2 -Wall $(OBJS).c -o $(OBJS)  -I/usr/local/include  -L/usr/local/lib64   -leggx -lX11 -lm
    gcc $(OBJS).c -o $(OBJS)  -I/usr/local/include  -L/usr/local/lib64   -leggx -lX11 -lm

$(OBJS).o: $(OBJS).c
    gcc -c $(OBJS).c

.PHONY: clean
clean:
     rm -f $(OBJS) $(OBJS).o 
Edric
  • 24,639
  • 13
  • 81
  • 91
  • 2
    Perhaps you don't have to? What problems do you have with the makefile in its current form? What happens when you use it and run `make`? – Some programmer dude Dec 18 '19 at 13:16
  • 1
    Please [edit] your question and explain why you need to change the Makefile. Do you get an error message? – Bodo Dec 18 '19 at 13:16
  • Thank you for your comments. I am trying to compile my c program code .The error I get is " fatal error: eggx.h file not found'.EGGX is a graphic library which is used as a header file in my program.I thought that it's a problem of makefile ,so i requested a help here. – Roman Kshetri Dec 18 '19 at 13:33
  • 1
    Why did you revert the grammatical fixes? – jww Dec 18 '19 at 14:34
  • I am sorry, its by a mistake. – Roman Kshetri Dec 19 '19 at 12:43

1 Answers1

1

You will want to review at least the following:

  • do you want to continue to use gcc as your compiler, or move to Apple's clang

  • if you want to use X11, you will need to install XQuartz and add the following options:

    X11FLAGS=-I /opt/X11/include X11LIBS=-L /opt/X11/lib -lx11

  • you can remove /usr/local/lib64 because macOS doesn't use that

  • you will want to decide it you are going to use a package manager, such as homebrew because Apple doesn't provide one. Associated with that, you may want to use pkgconfig from homebrew to automate your compiler and linker flags and switches.

You may also find this helpful, and this.


I modified the Makefile included in the egg package to look like this and it compiles and builds fine on my Mac under macOS Mojave:

CC    = gcc
CFLAGS = -O2 -Wall
DESTDIR =
USERCC   = gcc
USERCCFLAGS = -O2 -Wall
USERFC   = gfortran
USERFCFLAGS = -O2 -Wall

IINC  = -I/opt/X11/include
LLIB  = -L /opt/X11/lib

PREFIX = /usr/local

INCDIR = $(PREFIX)/include
LIBDIR = $(PREFIX)/lib
BINDIR = $(PREFIX)/bin

LOCALINC = -I$(INCDIR)
LOCALLIB = -L$(LIBDIR)

LLINKS = -leggx -lX11 -lm

DEFS = $(VDEFS) $(TDEFS) $(UDEFS) $(PDEFS) $(XDEFS)

all:: _xslave_ mkexheader exec_xslave.h lib egg

install:: lib egg
    if [ ! -d $(DESTDIR)$(LIBDIR) ];then sh install-sh -d $(DESTDIR)$(LIBDIR); fi
    if [ ! -d $(DESTDIR)$(INCDIR) ];then sh install-sh -d $(DESTDIR)$(INCDIR); fi
    if [ ! -d $(DESTDIR)$(BINDIR) ];then sh install-sh -d $(DESTDIR)$(BINDIR); fi
    sh install-sh -m 644 libeggx.a $(DESTDIR)$(LIBDIR)
    sh install-sh -m 644 eggx*.h $(DESTDIR)$(INCDIR)
    sh install-sh -m 755 egg $(DESTDIR)$(BINDIR)
    ranlib $(DESTDIR)$(LIBDIR)/libeggx.a

.c.o:   ; $(CC) $(CFLAGS) $(IINC) $(DEFS) -c $*.c

_xslave_: _xslave_.o _eggx_scrollbar.o
    $(CC) $(CFLAGS) _xslave_.o _eggx_scrollbar.o -o _xslave_ $(LLIB) -lX11

mkexheader: mkexheader.o
    $(CC) $(CFLAGS) mkexheader.o -o mkexheader

exec_xslave.h: mkexheader _xslave_
    ./mkexheader _xslave_ > exec_xslave.h

eggx_base.o: exec_xslave.h

lib:: eggx_base.o eggx_color.o
    ar cruv libeggx.a eggx_base.o eggx_color.o
    ranlib libeggx.a

egg:: egg.sh
    cat egg.sh > egg
    rm -f egg.t
    for i in USERCC "x@@$(USERCC)" USERFC "x@@$(USERFC)" \
      USERCCFLAGS "x@@$(USERCCFLAGS)" USERFCFLAGS "x@@$(USERFCFLAGS)" \
      IINC "x@@$(IINC)" LLIB "x@@$(LLIB)" LOCALINC "x@@$(LOCALINC)" \
      LOCALLIB "x@@$(LOCALLIB)" LLINKS "x@@$(LLINKS)" ; do { \
      if [ -f egg.t ] ; then \
        if [ "$$i" = "x@@" ] ; then \
          cat egg.t | sed -e "s|@@@TARGET@@@||" > egg ; \
        else \
          cat egg.t | sed -e "s|@@@TARGET@@@|$$i|" | sed -e 's|x@@||' > egg ; \
        fi ; \
        rm -f egg.t ; \
      else \
        cat egg | sed -e "s|@$$i@|@@@TARGET@@@|" > egg.t ; \
      fi ; \
    } done
    chmod 755 egg

clean::
    rm -f *.o *.exe egg egg.t libeggx.a _xslave_ mkexheader exec_xslave.h

If you saved the tarball of eggx in directory HOME/eggx, you would need to do this:

cd $HOME/eggx
tar -xvf eggx-0.93r5.tar
cd eggx-0.93r5

Then copy the modified Makefile from above and save it in that directory as Makefile. Now just run:

make

and it should all build fine.

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • Comments are not for extended discussion; this conversation has been [moved to chat](https://chat.stackoverflow.com/rooms/204584/discussion-on-answer-by-mark-setchell-how-to-change-the-following-makefile-so-th). – Samuel Liew Dec 19 '19 at 23:48