Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8715471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:51:10+00:00 2026-06-13T05:51:10+00:00

I’m a student in computer engineering and I have yet another C program to

  • 0

I’m a student in computer engineering and I have yet another C program to implement.
Until now I always create a new Makefile from my previous projects and this take time to setup every time.
Is there a Makefile canvas I could use that is so powerful that all I would need to provide is the name of the c files containing a main function?

My idea would be that for each new project, I create a folder containing that Makefile, a bin folder and an src folder. I would then edit some variables to the Makefile (the C files containing a main() function) and then make would automatically build everything up, taking dependencies into account.

Do you know if such a Makefile exists?

[edit via Alexandre C.] : Automake/Autoconf are overkills for these kind of projects which use only standards libraries and run on standard unix os’.
For the projects we need to implement, dependencies (for the files to be linked) can always be deduces from the “.h” includes and there is generally very few files involved.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T05:51:11+00:00Added an answer on June 13, 2026 at 5:51 am

    I came up with the following solution:

    # Author Matthieu Sieben (http://matthieusieben.com)
    # Version 23/10/2012
    #
    # This Makefile is licensed under the Creative Commons Attribution
    # Partage dans les Mêmes Conditions 2.0 Belgique License.
    # To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/2.0/be/.
    # Use at your own risk.
    #
    # Use Makefile.inc to write you own rules or to overwrite the default values defined here.
    
    SRCDIR  = ./src
    BINDIR  = ./bin
    
    SHELL   = /bin/bash
    CC      = /usr/bin/gcc
    LIBS    =
    CFLAGS  = -Wall -Wextra -Werror
    LDFLAGS =
    
    .PHONY: default all clean distclean
    .SUFFIXES: .c .o
    
    # make "all" the default target
    default: all
    
    -include Makefile.inc
    -include Makefile.d
    
    CFLAGS += -I$(SRCDIR)
    ifeq ($(DEBUG), 1)
        CFLAGS += -DDEBUG=1 -ggdb
    else
        CFLAGS += -DDEBUG=0 -O2
        LDFLAGS += -O2
    endif
    
    %.o: %.c
        @echo "  Compiling `basename $<`";
        @$(CC) $(CFLAGS) -o $@ -c $<;
    
    clean:
        @echo "Cleaning compiled files";
        @find $(SRCDIR) -name "*.o" -exec rm {} \;
        @[ -e Makefile.d ] && rm Makefile.d;
    
    distclean: clean
        @echo "Removing executables";
        @find $(BINDIR) -type f -exec rm {} \;
    
    Makefile.d: $(shell find $(SRCDIR) -type f -name "*.c")
        @echo "Building dependencies";
        @for file in `find $(SRCDIR) -name "*.c" -print`; do\
            $(CC) $(CFLAGS) -MM -MT $${file/%.c/.o} $$file | tr -d "\n\\" >> Makefile.d.tmp;\
            echo -e "\n" >> Makefile.d.tmp;\
        done;\
        for file in `find $(SRCDIR) -name "*.c" -exec grep -Hs "main(" {} \; | cut -f1 -d':'`; do\
            execname=`basename $$file .c`;\
            objs="$${file/%.c/.o}";\
            for header in `$(CC) $(CFLAGS) -MM $$file | tr " " "\n" | grep ".h$$" | sort | uniq | tr "\n" " "`; do\
                if [ -f $${header/%.h/.c} ]; then\
                    objs+=" $${header/%.h/.o}";\
                fi;\
                for obj in `grep "^$${header/%.h/.o}" Makefile.d.tmp | tr " " "\n" | grep ".h$$" | tr "\n" " "`; do\
                    if [ -f $${obj/%.h/.c} ]; then\
                        objs+=" $${obj/%.h/.o}";\
                    fi;\
                done;\
            done;\
            objs=`echo -n "$$objs"  | tr " " "\n" | sort | uniq | tr "\n" " "`;\
            echo "all: $$execname" >> Makefile.d.tmp;\
            echo "$$execname: $(BINDIR)/$$execname" >> Makefile.d.tmp;\
            echo "$(BINDIR)/$$execname: $$objs" >> Makefile.d.tmp;\
            echo "  @echo \"Linking $$execname\";" >> Makefile.d.tmp;\
            echo "  @\$$(CC) \$$(LDFLAGS) -o \$$@ $$objs \$$(LIBS);" >> Makefile.d.tmp;\
            echo >> Makefile.d.tmp;\
        done;\
        mv Makefile.d.tmp $@;\
    

    It is not very robust, so feel free to provide an amelioration. Here is how it works.
    The idea here is, for each .c file in $(SRCDIR), look for those containing a main function (grep "main(" src/*.c). Then, for each local include #include "myfile.h" add myfile.o into the object list for that executable and then write the lines above in Makefile.d

    Edit
    This new version of the script supports dependencies for the linking of bin files.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
Basically, what I'm trying to create is a page of div tags, each has
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.